From ca63d3b4bbfdb3a0db3d62d9c6f332d3515ff1e0 Mon Sep 17 00:00:00 2001 From: Joshalosh Date: Sun, 1 Oct 2023 17:47:52 +1100 Subject: [PATCH] Make transition functions more robust --- feely_pona_game.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/feely_pona_game.cpp b/feely_pona_game.cpp index 8a37eaa..df120b5 100644 --- a/feely_pona_game.cpp +++ b/feely_pona_game.cpp @@ -725,17 +725,35 @@ static bool FP_Game_CanEntityAttack(FP_GameEntity *entity, uint64_t current_time 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; + switch (entity->type) { + case FP_EntityType_Terry: { + if (desired_state == FP_EntityTerryState_Attack) { + if (!FP_Game_CanEntityAttack(entity, game->clock_ms)) { + // NOTE: Cooldown not met do not transition + return; + } + entity->last_attack_timestamp = game->clock_ms; } + } break; - entity->last_attack_timestamp = game->clock_ms; + case FP_EntityType_Smoochie: { + if (desired_state == FP_EntitySmoochieState_Attack) { + if (!FP_Game_CanEntityAttack(entity, game->clock_ms)) { + // NOTE: Cooldown not met do not transition + return; + } + entity->last_attack_timestamp = game->clock_ms; + } + } break; + + case FP_EntityType_Clinger: { + if (desired_state == FP_EntityClingerState_Attack) { + 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