Page 1 of 1
Can someone please explain to me how Energy works?
Posted: Fri Feb 14, 2014 2:44 am
by sbrow
I'm trying to make a mod that has an Action Points based turns system, similar to Fallout. I've been playing around with the code, and cannot for the life of me figure out how to make it work the way I want it to. If I knew more about how the energy based system works it would probably be of great help.
Re: Can someone please explain to me how Energy works?
Posted: Fri Feb 14, 2014 2:47 am
by The Revanchist
I'll be honest with you, I'm not a resident expert on those background things.
However,
this topic here might have something of value. It's concerned with game mechanics for combat in general.
Re: Can someone please explain to me how Energy works?
Posted: Sat Feb 15, 2014 4:34 am
by Castler
GameEnergyBased:tick handles energy.
- The game is organized into game turns (sometimes called ticks).
- Each entity has an energy value.
- Every game turn (every tick), each entity gains a certain amount of energy (called energy_per_tick).
- Once an entity's energy is at least energy_to_act, the entity gets to act: the player gets to input a command, an NPC's AI picks an action, etc. The act method can also perform any per-turn updates (cooldowns, status effects wearing off, etc. - but see below).
- After finishing the action, the act method calls useEnergy.
Additional customization is possible:
- Entities' speed can affect how quickly they gain energy, allowing some characters to be faster than others. (Check energy.mod and global_speed in GameEnergyBased:tick.)
- useEnergy defaults to subtracting energy_to_act, but it can take a parameter to allow some actions to cost more energy than others. (For example, ToME has speed modifiers for movement, combat, and spells, so it multiplies energy_to_act by the appropriate modifier for each action.)
- Along with tracking energy and calling act, T-Engine tracks energyBase and calls actBase. These function the same as energy and act but are unmodified by entities' speed. ToME uses these so that cooldowns and status effects occur by strict game turns instead of faster characters getting faster cooldowns.
By default, energy_to_act is 1000, energy_per_tick is 100, and useEnergy sets energy back to 0, so each entity gets a turn every 10 game ticks. Variations are possible:
- If you set energy_to_act to 1 and set energy_per_tick to 5, then characters will get 5 actions per turn.
- If you set energy_to_act to 1 and energy_per_tick to 1 but set each entity's energy.mod to 5-10, then characters get 5-10 action points per turn, and calling useEnergy with different values can make different actions require different numbers of action points. I think this is what you want.
If you do this, make sure that your NPC:act lets NPCs continue acting as long as they have energy.
ToME's does, but the example module's doesn't.
I'm most familiar with how energy works for actors. Non-actor entities (objects, etc.) can get turns too, but their behavior may be different.