What is a turn?

Solution 1:

First, see the wiki page for Character sheet, in the Speed section: Speed determines how many 'actions' you can do in a turn. At 100% global speed you can do one action, at 200% global speed you can do two actions, and so on. Global speed is modified by the additive movement/spell/attack/mental speeds. So if your character has a global speed of 200%, a movement speed of 0%, and an attack speed of -100%, then each movement takes half a turn, while each attack takes a full turn.

Second, see the page for Speed. To determine when Actors get to take an action, the game gives them 1000 energy points per turn (EPT). A regular attack costs 1000 energy points per hit (EPH). So an actor with a 100% global speed, and no attack speed or weapon speed modifiers will spend all of their energy in one attack. Increasing global speed increases the amount of energy you get per turn, e.g., 140% global speed means you get 1400 EPT. Increasing weapon speed or attack speed reduces EPH: EPH = 1000 / ((1 + attack speed) * weapon speed). For example, a 110% sword wielded by a character with -30% attack speed will have EPH = 1000 / (0.7 * 1.1) = 1000 / 0.77 = 1299. If that character has a global speed of 140%, they would get 1400 EPT. After spending 1299 on an attack, they would be left with 101 energy. Next turn they would get another 1400 energy, attack, and be left with 202...after 14 turns they store up enough energy for two attacks in one turn.

So if you have a buff that lasts X turns, increasing your speed sufficiently will let you get more actions before the buff ends.

You can test it yourself by starting the game as an Archer. Walk up to an enemy and use your Wild infusion talent. Your character will get a "Pain suppression" status effect with a 5 on it because the Wild talent is an instant that lasts for this turn and 4 more. Then use the Archer's Disengage talent on the enemy. Disengage is a full-turn action, so you will see that the Pain suppression has 4 turns left. Disengage gives your character a Wild Speed status for 3 turns. Wild speed makes you move ~150% faster. Now count how many steps you can take before the pain suppression ends. I just checked and was able to take 9 steps. In comparison, if I triggered the Wild infusion talent without Disengage, then I could only take 5 steps before pain suppression ended.


To see the turns/energy in the source code, in the current version (1.5.10) look at GameEnergyBased.lua. Line 95 defines tickLevel, which loops through an array of entities on the level, gives each entity "energy_per_tick" (aka EPT), and then calls the entity's act function (i.e., asks for an action) at line 129. Then line 65 of NPC.lua explains that the NPC act function gets called by tickLevel, and the act function calls doAI (i.e., choosing a specific action) in a while loop as long as the NPC has enough energy.

If config.settings.log_detail_ai > 2, then the NPC act function prints logs that contain the current turn and the energy before and after the chosen action.

To make sure the game actually means a "turn" and not an action for the buff effects, I looked at the wild infusion. It has an inscription_data that is a generic "resolvers" function that returns a dur[ation] between 2 and 4. When a player dwarf is created, here is the line that gives them such an infusion with duration 4. When you use an infusion or rune, your character learns a talent. Using that talent creates a timed temporary effect that counts down (in timedEffects) before your character acts, in the actBase function, after regenerating resources like health and checking for suffocation.

Unfortunately, then the code gets tricky. The actBase function is called before act in tickLevel (which applies to entities in a "level"). There are actually two energy variables, one for actBase and one for act. So tick calls tickLevel, which calls actBase and then, if the entity has enough energy, it calls act. If that entity is the player character, the game pauses for input and I'm not sure how the code flow goes from there.

Solution 2:

Essentially, a turn is "however long your action takes". In particular, it is independent of real time - you can let the game sit as long as you want, and it will wait for you. More precisely (after skimming the source code), various actions take different amounts of energy. The actors, including your character, gain some energy (how much depends on factors such as their speed) on each internal tick. When you have accumulated enough energy to do something, the game pauses (i.e. no more ticks) until you have acted.

Solution 3:

You're on the right track: each action takes a fixed amount of time. In the very basic sense they are 0 (instant) or 1 turn.

Then you get into modifiers. Say your movement speed is 120% of normal and a creature is at 100%. You'll move 12 tiles for every 10 that he moves, meaning you can eventually outrun him.

To your latter example, you get more actions per turn. It's very noticeable with a Movement infusion (where you might get 400 or 500% movement speed). Watch the monsters as you run away.

Global speed works the same way but also applies to attacking, casting and all other actions you might take, and stacks up with movement speed.