Make transition functions more robust

This commit is contained in:
Joshalosh 2023-10-01 17:47:52 +11:00
parent 3f8f46027b
commit ca63d3b4bb

View File

@ -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;
}
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;
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