/*
* slot: Entity variable reserved for this move's timer.
* seconds: Minimum time between uses.
* fallback: Animation to use while the move is cooling down.
*/
void dc_move_cooldown(int slot, int seconds, int fallback) {
void acting_entity = getlocalvar("self");
int now = openborvariant("elapsed_time");
void ready_at = getentityvar(acting_entity, slot);
// An unused timer allows the first attempt immediately.
if(ready_at == NULL()) {
ready_at = 0;
}
if(now < ready_at) {
// Return to idle or substitute another attack.
if(fallback == openborconstant("ANI_IDLE")){
setidle(acting_entity, fallback, 1);
} else {
performattack(acting_entity, fallback, 1);
}
return;
}
// Allow this attempt and record when the move becomes available.
int next_time = now + seconds * openborvariant("game_speed");
setentityvar(acting_entity, slot, next_time);
}