Quote from: Snarky on Sun 22/10/2023 11:39:00What I don't quite understand is how, having sorted the speeds, you are then able to tell which unit corresponds to each element in the sorted array and should move first. Do you do a lookup to find which unit has the particular speed? That adds another layer of inefficiency, if so. And what if multiple units have the same speed? (Edit: Ah, I see that you edited your post right before I finished this, and in fact can not tell.)
Precisely my point. I only noticed after I tried your solution. I have a very nicely arranged array where I do not know which value goes with which character!
Quote from: Snarky on Sun 22/10/2023 11:39:00Also, one tip: It's a great benefit if you can use the same struct both for heroes and enemies, since that means you can, among other things, store them in a common array, which lets you easily do things like sort them or run through them one by one. And you wouldn't need separate .herospeed and .enemyspeed properties (and many other stat properties that are probably duplicated); instead you could just have one .speed property, and a single flag like bool isHero to tell them apart.
Yes. This is so true . I have fixed all my code so that I now have a single struct where I previously had three. It makes things so much more convenient. I think this is also going to help me with the sorting problem.
Quote from: eri0o on Sun 22/10/2023 12:10:55I really think you don't need to sort, just pick the unit with the maximum speed of a group and then remove it from the group - this should make it easier to add additional conditionals, like, maybe flying units goes first indifferent from speed.
Anyway, if your units all share a same index and you want to sort by speed and you have int sort working, a common trick is instead sorting "val= speed*256 + unit_index" and then later just filtering the index out by using "unit_index= val&0xFF".
Agreed. That should work provided I remember to "put the character back in" once each round of individual turns is complete. I also get what Snarky is saying.
I still have a bit of thinking to do to make things work exactly as I want, but you guys have placed me on the right track. I might revisit this post in the coming days if I need further advice. For the time being, thank you so much!!!