fp: Add cooldowns to attacks

This commit is contained in:
2023-10-01 16:47:40 +11:00
committed by doyle
parent dce637d804
commit 00365ec86f
4 changed files with 68 additions and 37 deletions
+26
View File
@@ -723,3 +723,29 @@ FP_GameFindClosestEntityResult FP_Game_FindClosestEntityWithType(FP_Game *game,
return result;
}
static bool FP_Game_CanEntityAttack(FP_GameEntity *entity, uint64_t current_time_ms)
{
bool result = (current_time_ms - entity->last_attack_timestamp) >= entity->attack_cooldown_ms;
return result;
}
static void FP_Game_EntityTransitionState(FP_Game *game, FP_GameEntity *entity, uint32_t desired_state)
{
switch (desired_state) {
case FP_EntityClingerState_Attack: {
if (entity->type == FP_EntityType_ClubTerry) {
break;
}
if (!FP_Game_CanEntityAttack(entity, game->clock_ms)) {
// NOTE: Cooldown not met do not transition
return;
}
entity->last_attack_timestamp = game->clock_ms;
} break;
}
// NOTE: If no returns are hit above we proceed with the state change
entity->action.next_state = desired_state;
}