I'm working on an SRPG with a tactical map and a turn based battle system. However, rather than having each "side" get a turn during which they move all their units, I'm going with an initiative based system where each unit on the battlefield gets an individual turn based on an individual initiative score. Each unit gets an initiative score from 1-10 with 10 being the fastest unit. That score is subtracted from 20 with the result being n. The unit the gets a turn every nth round.
I just started implementing code to determine (and eventually display) the turn order. I had planned to keep a container of references which would be sorted and could simply be iterated over as turns were taken. The front end of this is fine. For a unit with a score of 8 you insert a reference every 12th round. But obviously I'm not going to keep references all the way out to infinity. I'm going to have to store the turn order to some point, say 50 rounds from current, and as turns are take I'm going to have to go back in and extend it further. How to I, then, accurately track the "remainders" between a units last turn and next when they go over the "line", so to speak. If a unit is going to have a turn every 15 rounds, and I'm keeping track up to 50, then where do I store those 10 rounds between 45 and 60 that will be left off? I could have each unit maintain a "remainder" variable, but that seems potentially messy...
Thus, I'm starting to think that's not the best implementation. My next thought was just have each unit maintain a list of when it will take its next N turns, then iterate over the units and store the order. This seems like it would work quite well, except that I predict I'll have to do a lot of extra searching and sorting this way. Of course, I probably won't do enough searching and sorting to impact performance even in the worst case...
I think in typing this I've convinced myself of implementation number two... but I think I'm going to post this anyway, as I would love to hear some different thoughts if anyone has any. This just seemed like such a trivial problem but I've extended quite a bit of thought energy on it...