From 3379fec640960d887455b28dd22e30e02cdacb23 Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Sun, 5 Jan 2025 14:17:23 +0000 Subject: [PATCH] tr2: migrate to Item_TestFrameEqual This updates frame index tests for items to use Item_TestFrameEqual and Item_TestFrameRange. --- src/tr2/decomp/flares.c | 4 +- src/tr2/decomp/flares.h | 1 + src/tr2/game/gun/gun_rifle.c | 12 ++- src/tr2/game/lara/col.c | 87 ++++++++++++++----- src/tr2/game/lara/misc.c | 2 +- src/tr2/game/lara/state.c | 56 +++++++----- .../game/objects/creatures/bird_guardian.c | 3 +- src/tr2/game/objects/creatures/dragon.c | 3 +- src/tr2/game/objects/general/detonator.c | 10 ++- src/tr2/game/objects/general/gong_bonger.c | 7 +- src/tr2/game/objects/traps/dart_emitter.c | 2 +- 11 files changed, 124 insertions(+), 63 deletions(-) diff --git a/src/tr2/decomp/flares.c b/src/tr2/decomp/flares.c index 7c9df4b27..bff769b18 100644 --- a/src/tr2/decomp/flares.c +++ b/src/tr2/decomp/flares.c @@ -280,8 +280,8 @@ void Flare_Undraw(void) if (Item_TestAnimEqual(g_LaraItem, LA_FLARE_THROW)) { g_Lara.flare_control_left = 0; - if (frame_num_2 - >= g_Anims[LA_FLARE_THROW].frame_base + LF_FL_THROW_FT - 1) { + if (Item_TestFrameRange( + g_LaraItem, LF_FL_THROW_FT - 1, LF_FL_THROW_END)) { g_Lara.gun_type = g_Lara.last_gun_type; g_Lara.request_gun_type = g_Lara.last_gun_type; g_Lara.gun_status = LGS_ARMLESS; diff --git a/src/tr2/decomp/flares.h b/src/tr2/decomp/flares.h index edd7f2b00..23b360321 100644 --- a/src/tr2/decomp/flares.h +++ b/src/tr2/decomp/flares.h @@ -5,6 +5,7 @@ typedef enum { LF_FL_HOLD_FT = 1, LF_FL_THROW_FT = 32, + LF_FL_THROW_END = 35, LF_FL_DRAW_FT = 39, LF_FL_IGNITE_FT = 23, LF_FL_2_HOLD_FT = 15, diff --git a/src/tr2/game/gun/gun_rifle.c b/src/tr2/game/gun/gun_rifle.c index fa3e57af7..86b92b5ac 100644 --- a/src/tr2/game/gun/gun_rifle.c +++ b/src/tr2/game/gun/gun_rifle.c @@ -15,6 +15,10 @@ #include #include +#define GUN_RIFLE_EQUIP_FRAME 1 +#define GUN_RIFLE_DRAW_FRAME 10 +#define GUN_RIFLE_UNDRAW_FRAME 21 + static bool m_M16Firing = false; static bool m_HarpoonFired = false; @@ -256,7 +260,7 @@ void Gun_Rifle_Draw(const LARA_GUN_TYPE weapon_type) if (item->current_anim_state == LA_G_AIM || item->current_anim_state == LA_G_UAIM) { Gun_Rifle_Ready(weapon_type); - } else if (item->frame_num - g_Anims[item->anim_num].frame_base == 10) { + } else if (Item_TestFrameEqual(item, GUN_RIFLE_DRAW_FRAME)) { Gun_Rifle_DrawMeshes(weapon_type); } else if (g_Lara.water_status == LWS_UNDERWATER) { item->goal_anim_state = LA_G_UAIM; @@ -293,7 +297,7 @@ void Gun_Rifle_Undraw(const LARA_GUN_TYPE weapon_type) g_Lara.right_arm.lock = 0; } else if ( item->current_anim_state == LA_G_UNDRAW - && item->frame_num - g_Anims[item->anim_num].frame_base == 21) { + && Item_TestFrameEqual(item, GUN_RIFLE_UNDRAW_FRAME)) { Gun_Rifle_UndrawMeshes(weapon_type); } @@ -344,7 +348,7 @@ void Gun_Rifle_Animate(const LARA_GUN_TYPE weapon_type) break; case LA_G_RECOIL: - if (item->frame_num - g_Anims[item->anim_num].frame_base == 0) { + if (Item_TestFrameEqual(item, 0)) { item->goal_anim_state = LA_G_UNAIM; if (g_Lara.water_status != LWS_UNDERWATER && !running && !m_HarpoonFired) { @@ -396,7 +400,7 @@ void Gun_Rifle_Animate(const LARA_GUN_TYPE weapon_type) break; case LA_G_URECOIL: - if (item->frame_num - g_Anims[item->anim_num].frame_base == 0) { + if (Item_TestFrameEqual(item, 0)) { item->goal_anim_state = LA_G_UUNAIM; if ((g_Lara.water_status == LWS_UNDERWATER || running) && !m_HarpoonFired) { diff --git a/src/tr2/game/lara/col.c b/src/tr2/game/lara/col.c index 31c346dfb..060f96839 100644 --- a/src/tr2/game/lara/col.c +++ b/src/tr2/game/lara/col.c @@ -14,6 +14,39 @@ #include #include +#define LF_WALK_STEP_L_START 29 +#define LF_WALK_STEP_L_MID 44 +#define LF_WALK_STEP_L_NEAR_END 45 +#define LF_WALK_STEP_L_END 47 +#define LF_WALK_STEP_R_START 22 +#define LF_WALK_STEP_R_NEAR_END 27 +#define LF_WALK_STEP_R_END 28 +#define LF_WALK_STEP_R_2_START 48 +#define LF_WALK_STEP_R_2_END 57 + +#define LF_RUN_L_START 0 +#define LF_RUN_L_HEEL_GROUND 3 +#define LF_RUN_L_END 9 +#define LF_RUN_R_START 10 +#define LF_RUN_R_FOOT_GROUND 14 +#define LF_RUN_R_END 21 + +#define LF_BACK_R_START 26 +#define LF_BACK_R_END 55 + +#define LF_WADE_L_START 0 +#define LF_WADE_L_END 9 +#define LF_WADE_R_START 10 +#define LF_WADE_R_END 21 + +#define LF_WADE_STEP_L_START 3 +#define LF_WADE_STEP_L_END 14 + +#define LF_HANG 21 +#define LF_CLIMB_L_SHIFT_START 28 +#define LF_CLIMB_L_SHIFT_END 29 +#define LF_CLIMB_R_SHIFT 57 + void Lara_CollideStop(ITEM *const item, const COLL_INFO *const coll) { switch (coll->old_anim_state) { @@ -223,11 +256,13 @@ void Lara_Col_Walk(ITEM *item, COLL_INFO *coll) } if (Lara_DeflectEdge(item, coll)) { - if (item->frame_num >= 29 && item->frame_num <= 47) { + if (Item_TestFrameRange( + item, LF_WALK_STEP_L_START, LF_WALK_STEP_L_END)) { Item_SwitchToAnim(item, LA_WALK_STOP_LEFT, 0); } else if ( - (item->frame_num >= 22 && item->frame_num <= 28) - || (item->frame_num >= 48 && item->frame_num <= 57)) { + Item_TestFrameRange(item, LF_WALK_STEP_R_START, LF_WALK_STEP_R_END) + || Item_TestFrameRange( + item, LF_WALK_STEP_R_2_START, LF_WALK_STEP_R_2_END)) { Item_SwitchToAnim(item, LA_WALK_STOP_RIGHT, 0); } else { Lara_CollideStop(item, coll); @@ -239,7 +274,8 @@ void Lara_Col_Walk(ITEM *item, COLL_INFO *coll) } if (coll->side_mid.floor > STEP_L / 2) { - if (item->frame_num >= 28 && item->frame_num <= 45) { + if (Item_TestFrameRange( + item, LF_WALK_STEP_R_END, LF_WALK_STEP_L_NEAR_END)) { Item_SwitchToAnim(item, LA_WALK_DOWN_LEFT, 0); } else { Item_SwitchToAnim(item, LA_WALK_DOWN_RIGHT, 0); @@ -248,7 +284,8 @@ void Lara_Col_Walk(ITEM *item, COLL_INFO *coll) if (coll->side_mid.floor >= -STEPUP_HEIGHT && coll->side_mid.floor < -STEP_L / 2) { - if (item->frame_num >= 27 && item->frame_num <= 44) { + if (Item_TestFrameRange( + item, LF_WALK_STEP_R_NEAR_END, LF_WALK_STEP_L_MID)) { Item_SwitchToAnim(item, LA_WALK_UP_STEP_LEFT, 0); } else { Item_SwitchToAnim(item, LA_WALK_UP_STEP_RIGHT, 0); @@ -285,11 +322,11 @@ void Lara_Col_Run(ITEM *item, COLL_INFO *coll) if (!Item_TestAnimEqual(item, LA_RUN_START) && Lara_TestWall(item, STEP_L, 0, -STEP_L * 5 / 2)) { item->current_anim_state = LS_SPLAT; - if (item->frame_num >= 0 && item->frame_num <= 9) { + if (Item_TestFrameRange(item, LF_RUN_L_START, LF_RUN_L_END)) { Item_SwitchToAnim(item, LA_WALL_SMASH_LEFT, 0); return; } - if (item->frame_num >= 10 && item->frame_num <= 21) { + if (Item_TestFrameRange(item, LF_RUN_R_START, LF_RUN_R_END)) { Item_SwitchToAnim(item, LA_WALL_SMASH_RIGHT, 0); return; } @@ -308,7 +345,8 @@ void Lara_Col_Run(ITEM *item, COLL_INFO *coll) || coll->side_front.floor >= -STEP_L / 2)) { coll->side_mid.floor = 0; } else { - if (item->frame_num >= 3 && item->frame_num <= 14) { + if (Item_TestFrameRange( + item, LF_RUN_L_HEEL_GROUND, LF_RUN_R_FOOT_GROUND)) { Item_SwitchToAnim(item, LA_RUN_UP_STEP_LEFT, 0); } else { Item_SwitchToAnim(item, LA_RUN_UP_STEP_RIGHT, 0); @@ -501,7 +539,7 @@ void Lara_Col_Hang(ITEM *item, COLL_INFO *coll) || coll->hit_static) { if (g_Lara.climb_status && Item_TestAnimEqual(item, LA_REACH_TO_HANG) - && item->frame_num == g_Anims[item->anim_num].frame_base + 21 + && Item_TestFrameEqual(item, LF_HANG) && coll->side_mid.ceiling <= -256) { item->goal_anim_state = LS_HANG; item->current_anim_state = LS_HANG; @@ -515,7 +553,7 @@ void Lara_Col_Hang(ITEM *item, COLL_INFO *coll) } else if ( g_Input.back && g_Lara.climb_status && Item_TestAnimEqual(item, LA_REACH_TO_HANG) - && item->frame_num == g_Anims[item->anim_num].frame_base + 21) { + && Item_TestFrameEqual(item, LF_HANG)) { item->goal_anim_state = LS_HANG; item->current_anim_state = LS_HANG; Item_SwitchToAnim(item, LA_LADDER_DOWN_HANGING, 0); @@ -629,7 +667,7 @@ void Lara_Col_Back(ITEM *item, COLL_INFO *coll) if (coll->side_mid.floor > STEP_L / 2 && coll->side_mid.floor < STEPUP_HEIGHT) { - if (item->frame_num >= 964 && item->frame_num <= 993) { + if (Item_TestFrameRange(item, LF_BACK_R_START, LF_BACK_R_END)) { Item_SwitchToAnim(item, LA_WALK_DOWN_BACK_RIGHT, 0); } else { Item_SwitchToAnim(item, LA_WALK_DOWN_BACK_LEFT, 0); @@ -903,13 +941,15 @@ void Lara_Col_Wade(ITEM *item, COLL_INFO *coll) if (Lara_DeflectEdge(item, coll)) { item->rot.z = 0; if (coll->side_front.type != COLL_NONE - && coll->side_front.floor < -STEP_L * 5 / 2) { + && coll->side_front.floor < -STEP_L * 5 / 2 + && coll->old_anim_state == LS_WADE + && Item_TestAnimEqual(item, LA_WADE)) { item->current_anim_state = LS_SPLAT; - if (item->frame_num >= 0 && item->frame_num <= 9) { + if (Item_TestFrameRange(item, LF_WADE_L_START, LF_WADE_L_END)) { Item_SwitchToAnim(item, LA_WALL_SMASH_LEFT, 0); return; } - if (item->frame_num >= 10 && item->frame_num <= 21) { + if (Item_TestFrameRange(item, LF_WADE_R_START, LF_WADE_R_END)) { Item_SwitchToAnim(item, LA_WALL_SMASH_RIGHT, 0); return; } @@ -923,7 +963,8 @@ void Lara_Col_Wade(ITEM *item, COLL_INFO *coll) if (coll->side_mid.floor >= -STEPUP_HEIGHT && coll->side_mid.floor < -STEP_L / 2) { - if (item->frame_num >= 3 && item->frame_num <= 14) { + if (Item_TestFrameRange( + item, LF_WADE_STEP_L_START, LF_WADE_STEP_L_END)) { Item_SwitchToAnim(item, LA_RUN_UP_STEP_LEFT, 0); } else { Item_SwitchToAnim(item, LA_RUN_UP_STEP_RIGHT, 0); @@ -1108,12 +1149,12 @@ void Lara_Col_Climbing(ITEM *item, COLL_INFO *coll) } int32_t yshift; - int32_t frame_rel = item->frame_num - g_Anims[item->anim_num].frame_base; - if (frame_rel == 0) { + if (Item_TestFrameEqual(item, 0)) { yshift = 0; - } else if (frame_rel == 28 || frame_rel == 29) { + } else if (Item_TestFrameRange( + item, LF_CLIMB_L_SHIFT_START, LF_CLIMB_L_SHIFT_END)) { yshift = -STEP_L; - } else if (frame_rel == 57) { + } else if (Item_TestFrameEqual(item, LF_CLIMB_R_SHIFT)) { yshift = -STEP_L * 2; } else { return; @@ -1165,12 +1206,12 @@ void Lara_Col_ClimbDown(ITEM *item, COLL_INFO *coll) } int32_t yshift; - int32_t frame_rel = item->frame_num - g_Anims[item->anim_num].frame_base; - if (frame_rel == 0) { + if (Item_TestFrameEqual(item, 0)) { yshift = 0; - } else if (frame_rel >= 28 && frame_rel <= 29) { + } else if (Item_TestFrameRange( + item, LF_CLIMB_L_SHIFT_START, LF_CLIMB_L_SHIFT_END)) { yshift = STEP_L; - } else if (frame_rel == 57) { + } else if (Item_TestFrameEqual(item, LF_CLIMB_R_SHIFT)) { yshift = STEP_L * 2; } else { return; diff --git a/src/tr2/game/lara/misc.c b/src/tr2/game/lara/misc.c index 5f16ffe6b..da399acf9 100644 --- a/src/tr2/game/lara/misc.c +++ b/src/tr2/game/lara/misc.c @@ -432,7 +432,7 @@ void Lara_HangTest(ITEM *item, COLL_INFO *coll) } if (Item_TestAnimEqual(item, LA_REACH_TO_HANG) - && item->frame_num == g_Anims[item->anim_num].frame_base + 21 + && Item_TestFrameEqual(item, LF_HANG) && Lara_TestClimbStance(item, coll)) { item->goal_anim_state = LS_CLIMB_STANCE; } diff --git a/src/tr2/game/lara/state.c b/src/tr2/game/lara/state.c index e211c48fc..615a9db50 100644 --- a/src/tr2/game/lara/state.c +++ b/src/tr2/game/lara/state.c @@ -16,6 +16,21 @@ #include #define LF_ROLL 2 +#define LF_FLARE_PICKUP_END 89 +#define LF_UW_FLARE_PICKUP_END 35 +#define LF_SHARK_DEATH_END 56 +#define LF_SHARK_DEATH_TIMER_DELAY 25 +#define LF_TREX_DEATH_TIMER_DELAY 45 +#define LF_YETI_DEATH_TIMER_DELAY 70 +#define LF_DRAGON_DAGGER_PULLED 1 +#define LF_DRAGON_DAGGER_STORED 180 +#define LF_DRAGON_DAGGER_ANIM_END 239 +#define LF_START_HOUSE_BEGIN 1 +#define LF_START_HOUSE_DAGGER_STORED 401 +#define LF_START_HOUSE_END 427 +#define LF_SHOWER_START 1 +#define LF_SHOWER_SHOTGUN_PICKUP 316 +#define LF_SHOWER_END 349 static bool m_JumpPermitted = true; @@ -588,7 +603,10 @@ void Lara_State_Pickup(ITEM *item, COLL_INFO *coll) void Lara_State_PickupFlare(ITEM *item, COLL_INFO *coll) { Lara_State_Pickup(item, coll); - if (item->frame_num == g_Anims[item->anim_num].frame_end - 1) { + const int16_t frame_num = Item_TestAnimEqual(item, LA_FLARE_PICKUP) + ? LF_FLARE_PICKUP_END + : LF_UW_FLARE_PICKUP_END; + if (Item_TestFrameEqual(item, frame_num)) { g_Lara.gun_status = LGS_ARMLESS; } } @@ -711,7 +729,7 @@ void Lara_State_Extra_YetiKill(ITEM *item, COLL_INFO *coll) g_Camera.target_angle = CAM_YETI_KILL_ANGLE; g_Camera.target_distance = CAM_YETI_KILL_DISTANCE; g_Lara.hit_direction = -1; - if (item->frame_num < g_Anims[item->anim_num].frame_end - 30) { + if (Item_TestFrameRange(item, 0, LF_YETI_DEATH_TIMER_DELAY)) { g_Lara.death_timer = 1; } } @@ -722,15 +740,15 @@ void Lara_State_Extra_SharkKill(ITEM *item, COLL_INFO *coll) g_Camera.target_distance = CAM_SHARK_KILL_DISTANCE; g_Lara.hit_direction = -1; - if (item->frame_num == g_Anims[item->anim_num].frame_end) { - int32_t water_height = Room_GetWaterHeight( + if (Item_TestFrameEqual(item, LF_SHARK_DEATH_END)) { + const int32_t water_height = Room_GetWaterHeight( item->pos.x, item->pos.y, item->pos.z, item->room_num); if (water_height != NO_HEIGHT && water_height < item->pos.y - 100) { item->pos.y -= 5; } } - if (item->frame_num < g_Anims[item->anim_num].frame_end - 30) { + if (Item_TestFrameRange(item, 0, LF_SHARK_DEATH_TIMER_DELAY)) { g_Lara.death_timer = 1; } } @@ -754,24 +772,20 @@ void Lara_State_Extra_DinoKill(ITEM *item, COLL_INFO *coll) g_Camera.target_angle = CAM_TREX_KILL_ANGLE; g_Camera.target_elevation = CAM_TREX_KILL_ELEVATION; g_Lara.hit_direction = -1; - if (item->frame_num < g_Anims[item->anim_num].frame_end - 30) { + if (Item_TestFrameRange(item, 0, LF_TREX_DEATH_TIMER_DELAY)) { g_Lara.death_timer = 1; } } void Lara_State_Extra_PullDagger(ITEM *item, COLL_INFO *coll) { - int32_t frame_num_rel = - item->frame_num - g_Anims[item->anim_num].frame_base; - if (frame_num_rel == 1) { + if (Item_TestFrameEqual(item, LF_DRAGON_DAGGER_PULLED)) { Music_PlaySynced(MX_DAGGER_PULL); - } else if (frame_num_rel == 180) { + } else if (Item_TestFrameEqual(item, LF_DRAGON_DAGGER_STORED)) { g_Lara.mesh_ptrs[LM_HAND_R] = g_Meshes[g_Objects[O_LARA].mesh_idx + LM_HAND_R]; Inv_AddItem(O_PUZZLE_ITEM_2); - } - - if (item->frame_num == g_Anims[item->anim_num].frame_end) { + } else if (Item_TestFrameEqual(item, LF_DRAGON_DAGGER_ANIM_END)) { item->rot.y += PHD_90; const ITEM *const dragon_bones = Item_Find(O_DRAGON_BONES_2); @@ -788,19 +802,17 @@ void Lara_State_Extra_StartAnim(ITEM *item, COLL_INFO *coll) void Lara_State_Extra_StartHouse(ITEM *item, COLL_INFO *coll) { - int32_t frame_num_rel = - item->frame_num - g_Anims[item->anim_num].frame_base; - if (frame_num_rel == 1) { + if (Item_TestFrameEqual(item, LF_START_HOUSE_BEGIN)) { Music_PlaySynced(MX_REVEAL_2); g_Lara.mesh_ptrs[LM_HAND_R] = g_Meshes[g_Objects[O_LARA_EXTRA].mesh_idx + LM_HAND_R]; g_Lara.mesh_ptrs[LM_HIPS] = g_Meshes[g_Objects[O_LARA_EXTRA].mesh_idx]; - } else if (frame_num_rel == 401) { + } else if (Item_TestFrameEqual(item, LF_START_HOUSE_DAGGER_STORED)) { g_Lara.mesh_ptrs[LM_HAND_R] = g_Meshes[g_Objects[O_LARA].mesh_idx + LM_HAND_R]; g_Lara.mesh_ptrs[LM_HIPS] = g_Meshes[g_Objects[O_LARA].mesh_idx]; Inv_AddItem(O_PUZZLE_ITEM_1); - } else if (item->frame_num == g_Anims[item->anim_num].frame_end) { + } else if (Item_TestFrameEqual(item, LF_START_HOUSE_END)) { g_Camera.type = CAM_CHASE; Viewport_AlterFOV(-1); } @@ -810,9 +822,7 @@ void Lara_State_Extra_FinalAnim(ITEM *item, COLL_INFO *coll) { item->hit_points = 1000; - int32_t frame_num_rel = - item->frame_num - g_Anims[item->anim_num].frame_base; - if (frame_num_rel == 1) { + if (Item_TestFrameEqual(item, LF_SHOWER_START)) { g_Lara.back_gun = 0; g_Lara.mesh_ptrs[LM_HAND_R] = g_Meshes[g_Objects[O_LARA].mesh_idx + LM_HAND_R]; @@ -821,10 +831,10 @@ void Lara_State_Extra_FinalAnim(ITEM *item, COLL_INFO *coll) g_Lara.mesh_ptrs[LM_HIPS] = g_Meshes[g_Objects[O_LARA_EXTRA].mesh_idx + LM_HIPS]; Music_PlaySynced(MX_CUTSCENE_BATH); - } else if (frame_num_rel == 316) { + } else if (Item_TestFrameEqual(item, LF_SHOWER_SHOTGUN_PICKUP)) { g_Lara.mesh_ptrs[LM_HAND_R] = g_Meshes[g_Objects[O_LARA_SHOTGUN].mesh_idx + LM_HAND_R]; - } else if (item->frame_num == g_Anims[item->anim_num].frame_end - 1) { + } else if (Item_TestFrameEqual(item, LF_SHOWER_END)) { g_LevelComplete = true; } } diff --git a/src/tr2/game/objects/creatures/bird_guardian.c b/src/tr2/game/objects/creatures/bird_guardian.c index 018a4f472..73d25bef4 100644 --- a/src/tr2/game/objects/creatures/bird_guardian.c +++ b/src/tr2/game/objects/creatures/bird_guardian.c @@ -19,6 +19,7 @@ #define BIRD_GUARDIAN_ATTACK_1_RANGE SQUARE(WALL_L) // = 1048576 #define BIRD_GUARDIAN_ATTACK_2_RANGE SQUARE(WALL_L * 2) // = 4194304 #define BIRD_GUARDIAN_PUNCH_DAMAGE 200 +#define BIRD_GUARDIAN_DEATH_FRAME 158 // clang-format on typedef enum { @@ -192,7 +193,7 @@ void BirdGuardian_Control(const int16_t item_num) item->current_anim_state = BIRD_GUARDIAN_STATE_DEATH; } - if (item->frame_num == g_Anims[item->anim_num].frame_end) { + if (Item_TestFrameEqual(item, BIRD_GUARDIAN_DEATH_FRAME)) { g_LevelComplete = true; } } diff --git a/src/tr2/game/objects/creatures/dragon.c b/src/tr2/game/objects/creatures/dragon.c index 184e9b3aa..485ce2b01 100644 --- a/src/tr2/game/objects/creatures/dragon.c +++ b/src/tr2/game/objects/creatures/dragon.c @@ -199,8 +199,7 @@ void Dragon_Collision( if (g_Input.action && item->object_id == O_DRAGON_BACK && (Item_TestAnimEqual(item, DRAGON_ANIM_DEAD) || (Item_TestAnimEqual(item, DRAGON_ANIM_RESURRECT) - && item->frame_num - g_Anims[item->anim_num].frame_base - <= DRAGON_ALMOST_LIVE)) + && Item_TestFrameRange(item, 0, DRAGON_ALMOST_LIVE))) && !lara_item->gravity && shift <= DRAGON_MID && shift > DRAGON_CLOSE - 350 && side_shift > -350 && side_shift < 350 && angle > PHD_90 - 30 * PHD_DEGREE diff --git a/src/tr2/game/objects/general/detonator.c b/src/tr2/game/objects/general/detonator.c index 6347c8e9b..1ad042964 100644 --- a/src/tr2/game/objects/general/detonator.c +++ b/src/tr2/game/objects/general/detonator.c @@ -11,6 +11,10 @@ #include "game/sound.h" #include "global/vars.h" +#define EXPLOSION_START_FRAME 76 +#define EXPLOSION_END_FRAME 99 +#define EXPLOSION_ACTION_FRAME 80 + static XYZ_32 m_DetonatorPosition = { .x = 0, .y = 0, .z = 0 }; static int16_t m_GongBounds[12] = { @@ -73,13 +77,11 @@ void Detonator_Control(const int16_t item_num) ITEM *const item = Item_Get(item_num); Item_Animate(item); - const int32_t frame_num = - item->frame_num - g_Anims[item->anim_num].frame_base; - if (frame_num > 75 && frame_num < 100) { + if (Item_TestFrameRange(item, EXPLOSION_START_FRAME, EXPLOSION_END_FRAME)) { Output_AddDynamicLight(item->pos.x, item->pos.y, item->pos.z, 13, 11); } - if (frame_num == 80) { + if (Item_TestFrameEqual(item, EXPLOSION_ACTION_FRAME)) { g_Camera.bounce = -150; Sound_Effect(SFX_EXPLOSION_1, NULL, SPM_ALWAYS); } diff --git a/src/tr2/game/objects/general/gong_bonger.c b/src/tr2/game/objects/general/gong_bonger.c index d15c6eea6..f8d0cb9b8 100644 --- a/src/tr2/game/objects/general/gong_bonger.c +++ b/src/tr2/game/objects/general/gong_bonger.c @@ -5,6 +5,9 @@ #include "game/room.h" #include "global/vars.h" +#define GONG_BONGER_STRIKE_FRAME 41 +#define GONG_BONGER_END_FRAME 79 + static void M_ActivateHeavyTriggers(int16_t item_num); static void M_ActivateHeavyTriggers(const int16_t item_num) @@ -27,12 +30,12 @@ void GongBonger_Control(const int16_t item_num) ITEM *const item = Item_Get(item_num); Item_Animate(item); - if (item->frame_num - g_Anims[item->anim_num].frame_base == 41) { + if (Item_TestFrameEqual(item, GONG_BONGER_STRIKE_FRAME)) { Music_Play(MX_REVEAL_1, MPM_ALWAYS); g_Camera.bounce -= 50; } - if (item->frame_num == g_Anims[item->anim_num].frame_end) { + if (Item_TestFrameEqual(item, GONG_BONGER_END_FRAME)) { M_ActivateHeavyTriggers(item_num); } } diff --git a/src/tr2/game/objects/traps/dart_emitter.c b/src/tr2/game/objects/traps/dart_emitter.c index 888461997..e9e47bc1b 100644 --- a/src/tr2/game/objects/traps/dart_emitter.c +++ b/src/tr2/game/objects/traps/dart_emitter.c @@ -68,7 +68,7 @@ void DartEmitter_Control(const int16_t item_num) } if (item->current_anim_state == DART_EMITTER_STATE_FIRE - && item->frame_num == g_Anims[item->anim_num].frame_base) { + && Item_TestFrameEqual(item, 0)) { M_CreateDart(item); }