Creating turn order

Started by
6 comments, last by stycho 16 years, 5 months ago
I am making a turn based rpg and I need a way to create turn order in battle based on a "speed" variable. It needs to be flexible and work with any enemies that are randomly generated. Thanks!
Advertisement
Place all actors in container, sort by speed.

Sorry, that's the obvious and naive answer based on the terribly limited info given... Care to be more descriptive in your requirements?
Ha, sorry for the limited info. I was getting kicked out of my computer lab at the time of writing it. I am using c++ to write a tactical rpg and after the battle function is called in my game, I need to be able to create a turn order based on speed, whether you've taken your whole turn or just did half of it(moving is half and attacking/casting/items is the other half), spells to raise you speed, and maybe other stuff too. I hope thats a little clearer. So, taking half your turn or not taking it at all will mean you can get your next turn sooner. I have racked my mind trying to figure it out and I am just lost. Thanks!
It seems like you might be able to use a temp Speed variable for each character, which can be changed on a by-turn basis. Then, before every action/turn, the temp Speed variables are compared to see who goes first. But maybe I'm not understanding the question.

Hope that helps,
Brian
<hl>My Blog
I would give each actor a 'speed' score based on turn, spells, items, etc. For example:

1 actor has...
Boots of Given'er +100 speed
20 x 2 agility = +40 speed
+500 speed for taking half turn
or what ever you can think of.

so 640 'speed' points in total

Then like Telastyn said put them in a container and sort by the speed score
So, you want essentially the standard tactical RPG turn design?

The trick I think is to not think of the variable as speed, but as delay (the inverse). For now, assume low speed is faster. If A.Spd = 60 and B.Spd = 100 then the times go: a(60), b(100), a(120), a(180), b(200). Taking half speed would delay only half as much for the next turn.

If you want more speed to mean faster, then you need some sort of method to invert the speed into a delay. It's late so my math skills are a little off so I can't think of anything off hand that doesn't involve some arbitrary maximum that will change the ratio of speeds kinda oddly... perhaps someone else can help with that.
The way I see it, speed means one of two things:

A: You get your turn before everyone else, but everyone still takes the same number of turns when it's all said and done.

B: Your speed increases how often your turn comes up, allowing you to take more actions.

Obviously, these will have two separate implementations.

For A, the first thing is to define what a "Round" is. A round is a set of time for which each character takes one action. The round just checks the list of objects that have turns, checks which one both has the highest speed AND hasn't taken their turn yet, and gives them a turn. Once the turn is done, set them to "Have Moved" or whatever, and loop again. If speed ever changes, or something is added to the list, then assuming the loop is checking list size, as well as the speed numbers for each iteration, it should take into account any changes. Once everyone has had their turn, everyone gets their turns reset, and the loop starts again.

B is a little more complicated. The way I would do it is that, in addition to speed, each object also has a "Readiness" gauge. When the gauge fills to 100, they get their turn. When they take a "full" turn, it's reduced to 0. Any "fractions" of a turn (like half a turn) can reduce it by less (say, to 50). The game loop checks each object to see if its readiness gauge is at 100. If so, that turn is executed, and the loop reiterates. If none are found (they're all less than 100), then it just reiterates. Every time it loops, everyone gets some number added to their gauge determined by their speed (for example, a speed of 20 might give you 20 points every iteration. This means your bar fills up faster than someone who only gets 10). In this way, faster objects have their bars fill up quicker, and thus get their turns more often. If speed changes during combat, it'll just get added in as normal, provided you design it right.
Thank you everyone. Andorien, the second way is the way I originally wanted to do it but couldn't figured it out so resorted to the first one. Now I think I get it and will try to program it. I'll probably be back soon...

This topic is closed to new replies.

Advertisement