diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f329a98..aae8ebf50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - added detection for animation commands to play SFX on land, water or both (#999) - added support for customizable enemy item drops via the gameflow (#967) - fixed baddies dropping duplicate guns (only affects mods) (#1000) +- fixed Lara never using the step back down right animation (#1014) - improved frame scheduling to use less CPU (#985) ## [2.16](https://github.com/LostArtefacts/TR1X/compare/2.15.3...2.16) - 2023-09-20 diff --git a/src/game/items.c b/src/game/items.c index 0f5f26cf8..4fcf8b917 100644 --- a/src/game/items.c +++ b/src/game/items.c @@ -637,8 +637,12 @@ bool Item_GetAnimChange(ITEM_INFO *item, ANIM_STRUCT *anim) if (change->goal_anim_state == item->goal_anim_state) { ANIM_RANGE_STRUCT *range = &g_AnimRanges[change->range_index]; for (int j = 0; j < change->number_ranges; j++, range++) { - if (item->frame_number >= range->start_frame - && item->frame_number <= range->end_frame) { + if (Item_TestFrameRange( + item, + range->start_frame + - g_Anims[item->anim_number].frame_base, + range->end_frame + - g_Anims[item->anim_number].frame_base)) { item->anim_number = range->link_anim_num; item->frame_number = range->link_frame_num; return true; @@ -769,3 +773,9 @@ bool Item_TestFrameEqual(ITEM_INFO *item, int16_t frame) { return item->frame_number == g_Anims[item->anim_number].frame_base + frame; } + +bool Item_TestFrameRange(ITEM_INFO *item, int16_t start, int16_t end) +{ + return item->frame_number >= g_Anims[item->anim_number].frame_base + start + && item->frame_number <= g_Anims[item->anim_number].frame_base + end; +} diff --git a/src/game/items.h b/src/game/items.h index 2c5562b3f..4d7eba8e7 100644 --- a/src/game/items.h +++ b/src/game/items.h @@ -48,3 +48,4 @@ int32_t Item_GetFrames(ITEM_INFO *item, int16_t *frmptr[], int32_t *rate); void Item_TakeDamage(ITEM_INFO *item, int16_t damage, bool hit_status); bool Item_TestFrameEqual(ITEM_INFO *item, int16_t frame); +bool Item_TestFrameRange(ITEM_INFO *item, int16_t start, int16_t end); diff --git a/src/game/lara/lara_col.c b/src/game/lara/lara_col.c index 1c222c4ce..1ce533650 100644 --- a/src/game/lara/lara_col.c +++ b/src/game/lara/lara_col.c @@ -14,6 +14,26 @@ #include #include +#define LF_WALK_STEP_L_START 0 +#define LF_WALK_STEP_L_NEAR_END 5 +#define LF_WALK_STEP_L_END 6 +#define LF_WALK_STEP_R_START 7 +#define LF_WALK_STEP_R_MID 22 +#define LF_WALK_STEP_R_NEAR_END 23 +#define LF_WALK_STEP_R_END 25 +#define LF_WALK_STEP_L_2_START 26 +#define LF_WALK_STEP_L_2_END 35 + +#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 + void (*g_LaraCollisionRoutines[])(ITEM_INFO *item, COLL_INFO *coll) = { Lara_Col_Walk, Lara_Col_Run, Lara_Col_Stop, Lara_Col_ForwardJump, Lara_Col_Pose, Lara_Col_FastBack, @@ -93,11 +113,16 @@ void Lara_Col_Walk(ITEM_INFO *item, COLL_INFO *coll) } if (Lara_DeflectEdge(item, coll)) { - if (item->frame_number >= 29 && item->frame_number <= 47) { + if (item->current_anim_state == LS_WALK + && Item_TestFrameRange( + item, LF_WALK_STEP_R_START, LF_WALK_STEP_R_END)) { Item_SwitchToAnim(item, LA_STOP_RIGHT, 0); } else if ( - (item->frame_number >= 22 && item->frame_number <= 28) - || (item->frame_number >= 48 && item->frame_number <= 57)) { + item->current_anim_state == LS_WALK + && (Item_TestFrameRange( + item, LF_WALK_STEP_L_START, LF_WALK_STEP_L_END) + || Item_TestFrameRange( + item, LF_WALK_STEP_L_2_START, LF_WALK_STEP_L_2_END))) { Item_SwitchToAnim(item, LA_STOP_LEFT, 0); } else { Item_SwitchToAnim(item, LA_STOP, 0); @@ -109,7 +134,9 @@ void Lara_Col_Walk(ITEM_INFO *item, COLL_INFO *coll) } if (coll->mid_floor > STEP_L / 2) { - if (item->frame_number >= 28 && item->frame_number <= 45) { + if (item->current_anim_state == LS_WALK + && Item_TestFrameRange( + item, LF_WALK_STEP_L_END, LF_WALK_STEP_R_NEAR_END)) { Item_SwitchToAnim(item, LA_WALK_STEP_DOWN_RIGHT, 0); } else { Item_SwitchToAnim(item, LA_WALK_STEP_DOWN_LEFT, 0); @@ -117,7 +144,9 @@ void Lara_Col_Walk(ITEM_INFO *item, COLL_INFO *coll) } if (coll->mid_floor >= -STEPUP_HEIGHT && coll->mid_floor < -STEP_L / 2) { - if (item->frame_number >= 27 && item->frame_number <= 44) { + if (item->current_anim_state == LS_WALK + && Item_TestFrameRange( + item, LF_WALK_STEP_L_NEAR_END, LF_WALK_STEP_R_MID)) { Item_SwitchToAnim(item, LA_WALK_STEP_UP_RIGHT, 0); } else { Item_SwitchToAnim(item, LA_WALK_STEP_UP_LEFT, 0); @@ -158,11 +187,13 @@ void Lara_Col_Run(ITEM_INFO *item, COLL_INFO *coll) if (coll->front_type == HT_WALL && coll->front_floor < -(STEP_L * 5) / 2) { item->current_anim_state = LS_SPLAT; - if (item->frame_number >= 0 && item->frame_number <= 9) { + if (item->current_anim_state == LS_RUN + && Item_TestFrameRange(item, LF_RUN_L_START, LF_RUN_L_END)) { Item_SwitchToAnim(item, LA_HIT_WALL_LEFT, 0); return; } - if (item->frame_number >= 10 && item->frame_number <= 21) { + if (item->current_anim_state == LS_RUN + && Item_TestFrameRange(item, LF_RUN_R_START, LF_RUN_R_END)) { Item_SwitchToAnim(item, LA_HIT_WALL_RIGHT, 0); return; } @@ -175,7 +206,9 @@ void Lara_Col_Run(ITEM_INFO *item, COLL_INFO *coll) } if (coll->mid_floor >= -STEPUP_HEIGHT && coll->mid_floor < -STEP_L / 2) { - if (item->frame_number >= 3 && item->frame_number <= 14) { + if (item->current_anim_state == LS_RUN + && Item_TestFrameRange( + item, LF_RUN_L_HEEL_GROUND, LF_RUN_R_FOOT_GROUND)) { Item_SwitchToAnim(item, LA_RUN_STEP_UP_LEFT, 0); } else { Item_SwitchToAnim(item, LA_RUN_STEP_UP_RIGHT, 0); @@ -472,7 +505,8 @@ void Lara_Col_Back(ITEM_INFO *item, COLL_INFO *coll) } if (coll->mid_floor > STEP_L / 2 && coll->mid_floor < (STEP_L * 3) / 2) { - if (item->frame_number >= 964 && item->frame_number <= 993) { + if (item->current_anim_state == LS_BACK + && Item_TestFrameRange(item, LF_BACK_R_START, LF_BACK_R_END)) { Item_SwitchToAnim(item, LA_BACK_STEP_DOWN_RIGHT, 0); } else { Item_SwitchToAnim(item, LA_BACK_STEP_DOWN_LEFT, 0); diff --git a/src/game/lara/lara_state.c b/src/game/lara/lara_state.c index a0f119745..b0a06ccc5 100644 --- a/src/game/lara/lara_state.c +++ b/src/game/lara/lara_state.c @@ -126,7 +126,8 @@ void Lara_State_Run(ITEM_INFO *item, COLL_INFO *coll) item->anim_number - g_Objects[item->object_number].anim_index; if (anim == LA_RUN_START) { m_JumpPermitted = false; - } else if (anim != LA_RUN || Item_TestFrameEqual(item, LF_JUMP_READY - 1)) { + } else if ( + anim != LA_RUN || Item_TestFrameEqual(item, LF_JUMP_READY - 1)) { m_JumpPermitted = true; } } diff --git a/src/game/objects/common.c b/src/game/objects/common.c index 6ec475a22..4596212eb 100644 --- a/src/game/objects/common.c +++ b/src/game/objects/common.c @@ -67,8 +67,9 @@ void Object_DrawPickupItem(ITEM_INFO *item) // Save the frame number. int16_t old_frame_number = item->frame_number; // Modify item to be the anim for inv item and animation 0. - item->anim_number = g_Objects[item_num_option].anim_index; - item->frame_number = g_Anims[item->anim_number].frame_base; + Item_SwitchToAnim( + item, g_Objects[item_num_option].anim_index, + g_Anims[item->anim_number].frame_base); OBJECT_INFO *object = &g_Objects[item_num_option]; diff --git a/src/game/objects/creatures/torso.c b/src/game/objects/creatures/torso.c index 050bff2b5..bd14e566b 100644 --- a/src/game/objects/creatures/torso.c +++ b/src/game/objects/creatures/torso.c @@ -29,6 +29,10 @@ #define TORSO_HITPOINTS 500 #define TORSO_RADIUS (WALL_L / 3) // = 341 #define TORSO_SMARTNESS 0x7FFF +#define TORSO_FRAME_TURN_L_START 14 +#define TORSO_FRAME_TURN_L_END 22 +#define TORSO_FRAME_TURN_R_START 17 +#define TORSO_FRAME_TURN_R_END 22 typedef enum { TORSO_EMPTY = 0, @@ -154,9 +158,9 @@ void Torso_Control(int16_t item_num) case TORSO_TURN_L: if (!torso->flags) { torso->flags = item->frame_number; - } else if ( - item->frame_number - torso->flags > 13 - && item->frame_number - torso->flags < 23) { + } else if (Item_TestFrameRange( + item, TORSO_FRAME_TURN_L_START, + TORSO_FRAME_TURN_L_END)) { item->pos.y_rot -= PHD_DEGREE * 9; } @@ -168,9 +172,9 @@ void Torso_Control(int16_t item_num) case TORSO_TURN_R: if (!torso->flags) { torso->flags = item->frame_number; - } else if ( - item->frame_number - torso->flags > 16 - && item->frame_number - torso->flags < 23) { + } else if (Item_TestFrameRange( + item, TORSO_FRAME_TURN_R_START, + TORSO_FRAME_TURN_R_END)) { item->pos.y_rot += PHD_DEGREE * 14; }