I'm working on a new combat system that will be able to play host to multiple people. I also would like for it to allow newcomers to enter the fray should they stumble upon the battle. So I need to design a proc that will be able to index and re-index combatants within the turn order list based on their speed. Is this possible? Or is there perhaps a more efficient and practical way to go about this? Any prod in the right direction would be really helpful.
Jul 14 2018, 3:17 pm
Best response
|
|
There are some "list sorting" libraries out there that let you sort lists according to whatever ordering you want. Swapping elements in a list by index is done with list.Swap().
|
In response to Kaiochao
|
|
Kaiochao wrote:
There are some "list sorting" libraries out there that let you sort lists according to whatever ordering you want. Swapping elements in a list by index is done with list.Swap(). Thank you so much. I shall look into this. |
So I've been toying with deadron's "List" library as it was the simplest for me to grasp, but it sorts in an ascending manner. I need the list to descend based on their speed. Is there a quick way for me to inverse the list returned by his proc, or do I need to re-write his proc alltogether?
Edit:This is currently what I'm working with, but it seems to only transfer the indices of the list and not the actual mobs within. obj/engagement |
Deadron's List library adds a dd_SortValue() proc to all datums that you can override to give things a different order. In your case, you'd override that on your mobs to return their speed. Something like this:
mob/dd_SortValue() return speed
Of course, this is just an example, and it's very limiting because mobs can only be sorted by speed. I recommend Theodis's QuickSort library, which includes a sorting proc that takes another proc as an argument that is used for comparing two objects. For example: // Some proc to compare two mobs by speed: |
In response to Kaiochao
|
|
Kaiochao wrote:
Deadron's List library adds a dd_SortValue() proc to all datums that you can override to give things a different order. In your case, you'd override that on your mobs to return their speed. Something like this: > mob/dd_SortValue() return speed Of course, this is just an example, and it's very limiting because mobs can only be sorted by speed. > // Some proc to compare two mobs by speed: This helped me a ton, thank you. |