Skip to content

Commit

Permalink
items: add Item_TestFrameRange function
Browse files Browse the repository at this point in the history
Resolves LostArtefacts#1011.

Fixes Lara not stepping back down one click with her right foot.
Resolves LostArtefacts#1014.
  • Loading branch information
walkawayy committed Sep 28, 2023
1 parent b73b3b8 commit f35063c
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/game/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
52 changes: 43 additions & 9 deletions src/game/lara/lara_col.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
#include <stddef.h>
#include <stdint.h>

#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,
Expand Down Expand Up @@ -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);
Expand All @@ -109,15 +134,19 @@ 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);
}
}

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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/game/lara/lara_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
16 changes: 10 additions & 6 deletions src/game/objects/creatures/torso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

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

Expand Down

0 comments on commit f35063c

Please sign in to comment.