Make transition functions more robust

This commit is contained in:
Joshalosh 2023-10-01 17:47:52 +11:00 committed by doyle
parent 00365ec86f
commit 4f4868efb0

View File

@ -733,17 +733,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