Hi everyone, I'm in the process of trying to build a classic turn-based RPG. Since random, turn-based battles are the meat and potatoes of this, I'm working on getting my battle system up and running before I do anything else. I prototyped the basics, and it's easy enough to get a system in place where I just take turns between players and enemies, but I want to determine the order of turns per round based on a unit's speed stat - including re-calculating the turn order every round based on things like whether or not a unit died / fled (and thus the turn is skipped) or if they've been hastened/slowed.
From what I've been able to gather, the best way to accomplish this is through an array. I've been trying to wrap my head around them, and the way I currently envision it functioning is that at the start of the layout and then any given turn, I call a function to set each cell to a unit's speed stat based on the order of highest to lowest, and then draw the order of turns from the array. Once all player unit actions have been selected, it switches into a combat round where all units (player and enemy) take their turns in the order they were assigned.
The problem I'm running into is I can't seem to figure out how to actually sort the cells from high to low. I know that I can draw the max and minimum speeds from a list of all units in the battle, but I'm not sure how to go about retrieving anything in-between. The 'sort' action for the array doesn't seem to work either.
If anyone could help me figure that out, it'd be much appreciated! Bonus points if you happen to have any ideas how I'd distribute those turns to each unit after the fact, though I figure I'll cross that bridge when I come to it. <img src="smileys/smiley17.gif" border="0" align="middle" />