# How to manage different speed of actions in RogueLike games?

How to manage different speed of actions in RogueLike games?

What I mean is that turn based games may have actors acting at different "speed", depending on the action and some other characteristics. The actors then effectively do more actions/turns than others if they have greater speed, or not.

How to determine when an actor should be able to act (turn scheduling?)?

It looks like there is different ways to do it? Can you explain some with algorithms?

• I have a feeling that if you described out in detail the features that you want, an algorithm will become obvious. – Tetrad May 15 '12 at 16:29
• As Tetrad said, plus what do you mean by "speed of actions"? Roguelikes are typically turn-based so I can't see how this could apply to them. – Laurent Couvidou May 15 '12 at 17:44
• Even in turn based games, some entities will move faster or slower then others, having more or less turns compared to the others. I fixed the question. – Klaim May 16 '12 at 1:56
• @Patrick Hughes Nethack, one of the oldest and most popular roguelikes, has a very important speed attribute. nethackwiki.com/wiki/Speed – Harry Stern May 16 '12 at 17:50
• @HarryStern I've been playing poorly all this time? That might explain a few things... =) – Patrick Hughes May 16 '12 at 17:52

## 5 Answers

In my roguelike game Tyrant I used a system of action points and speed ratings.

Basically:

• Most actions had a AP cost of 100
• Most creatures have a speed of 100

Then the game loop would go as follows.

• Hero takes an action.
• Elapsed time is calculated as hero action AP cost * 100 / hero speed
• All creatures get given APs equal to creature speed * elapsed time / 100
• Creatures take actions and have APs subtracted until their APs are <= 0
• Repeat

This system worked very nicely overall, example nice features:

• If you have a very fast hero (perhaps due to a magic speed bonus), you can get several moves in before an individual creature can move (it's APs would be negative for a few turns because the elapsed time would be small)
• You can make some actions more or less expensive by varying the AP cost
• You can delay creatures by subtracting APs, or give them a sudden one-off boost by adding APs
• Trying to wrap my head around this. If you have 1 player and 4 players. Doesnt this make the last player stack elapse time more and more. Allowing him to take maybe 4 actions and the second time around 8 in a row ?? – Dr.Denis McCracleJizz Feb 18 '15 at 16:06

Action points. Give each entity a "speed" so that faster actors get more points each turn. Make each action take a specific number of points to complete, and subtract that number from the player's points for that turn when he takes an action. If an action takes more points than the player has left, mark it as "partially completed", and let him finish it next turn.

Do you mean having actions take multiple turns (i.e., sleeping for 50 turns straight)?

What I would do is keep an object, player.currentAction. currentAction might contain how many turns the action would require, what the resolution of the action is, and a list of states that cancel the action (in danger, being attacked, too hot, etc). Each turn, before we checked for player input, we would check to see if the player was currently in the middle of an action, then do something like something like...

if(!player.currentAction.interrupted())
{
if(player.currentAction.complete() == true)
{
player.currentAction.doAction(); //Some actions, like casting a spell, would have something happen here. Others, like sleeping, may or may not, depending on how you coded it.
player.currentAction = null;
}
else player.currentAction.decreaseTimer(); //Decrease our timer by one.
}
else
{
player.currentAction.interrupt(); //Let the player know he's been interrupted. Bungle the spell, cancel sleep, etc.
player.currentAction = null;
}


You can go with action points but no turns per se but ticks, which are much smaller. Suppose every actor has action point accumulation speed (e.g. 2 AP per tick). It starts an action worth, say, 10 AP. The game advances 5 ticks forward (because this is how much it takes for the actor to pay action's AP price).

When there are several actors. The game advances tick by tick until somebody has payed AP price at wich point this action is executed.

The approach is similar to @mikera's, only there are no negative APs.

• This is far messier, as you need to store the "intended" action of the creature. Some actions depend on state that may change before the mob has accumulated enough points. – Warwick Allison May 19 '12 at 21:39
• Maybe it's not perfect, but it reflects real life, when you decide to hit, you first swing and then hit - so it's decision-preparation-action, which is what this system allows. Also this allows to choose block action based on actual situation. – zzandy May 22 '12 at 9:13
• I prefer going the other direction: mob picks an action with cost of n-ticks and then cannot pick a new action until n-ticks elapse. It can be implemented as a single value that is decremented on each tick. – kitsu.eb Jul 26 '16 at 15:35

High Resolution Time

If punch takes 400 turns, and kick takes 1000 turns, I can punch you at least twice before you kick me, and I can punch you 5 times by the time you kick me twice.

By making things take lots of turns, you have a lot of control over how long things take.