Skip to content

Commit

Permalink
tr1/lara/state: check for responsive state changes
Browse files Browse the repository at this point in the history
This augments the config options for responsive jumping and swimming to
verify that relevant state changes exist in Lara's animation set.

Resolves LostArtefacts#2397.
  • Loading branch information
lahm86 committed Jan 27, 2025
1 parent 0943f2d commit 4ce54ad
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- fixed header and arrows disappearing when the inventory ring rotates (#2352, regression from 4.4)
- fixed Story So Far feature not playing opening FMVs from the current level (#2360, regression from 4.2)
- fixed `/demo` command crashing the game if no demos are present (regression from 4.1)
- fixed Lara not being able to jump or stop swimming if the related responsive config options are enabled, but enhanced animations are not injected (#2397, regression from 4.6)
- improved pause screen compatibility with PS1 (#2248)

## [4.7.1](https://github.com/LostArtefacts/TRX/compare/tr1-4.7...tr1-4.7.1) - 2024-12-21
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/lara/enum_tr1.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef enum {
LA_SIDE_STEP_RIGHT = 67,
LA_LAND_FAR = 24,
LA_GRAB_LEDGE = 96,
LA_SWIM_FORWARD = 86,
LA_SWIM_GLIDE = 87,
LA_FALL_BACK = 93,
LA_HANG = 96,
Expand Down
36 changes: 32 additions & 4 deletions src/tr1/game/lara/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ void (*g_LaraStateRoutines[])(ITEM *item, COLL_INFO *coll) = {
};

static bool m_JumpPermitted = true;
static bool m_EnableResponsiveJumping = false;
static bool m_EnableResponsiveSwimming = false;

static int16_t M_FloorFront(ITEM *item, PHD_ANGLE ang, int32_t dist);
static bool M_HasResponsiveState(LARA_ANIMATION anim_idx);

static int16_t M_FloorFront(ITEM *item, PHD_ANGLE ang, int32_t dist)
{
Expand All @@ -62,6 +65,32 @@ static int16_t M_FloorFront(ITEM *item, PHD_ANGLE ang, int32_t dist)
return height;
}

static bool M_HasResponsiveState(const LARA_ANIMATION anim_idx)
{
const OBJECT *const object = Object_GetObject(O_LARA);
if (!object->loaded) {
return false;
}

const ANIM *const anim = Object_GetAnim(object, anim_idx);
for (int32_t i = 0; i < anim->num_changes; i++) {
const ANIM_CHANGE *const change = Anim_GetChange(anim->change_idx + i);
if (change->goal_anim_state == LS_RESPONSIVE) {
return true;
}
}

return false;
}

void Lara_State_Initialise(void)
{
m_EnableResponsiveJumping =
g_Config.gameplay.enable_tr2_jumping && M_HasResponsiveState(LA_RUN);
m_EnableResponsiveSwimming = g_Config.gameplay.enable_tr2_swim_cancel
&& M_HasResponsiveState(LA_SWIM_FORWARD);
}

void Lara_State_Walk(ITEM *item, COLL_INFO *coll)
{
if (item->hit_points <= 0) {
Expand Down Expand Up @@ -140,9 +169,8 @@ void Lara_State_Run(ITEM *item, COLL_INFO *coll)
}

if (g_Input.jump && m_JumpPermitted && !item->gravity) {
item->goal_anim_state = g_Config.gameplay.enable_tr2_jumping
? LS_RESPONSIVE
: LS_JUMP_FORWARD;
item->goal_anim_state =
m_EnableResponsiveJumping ? LS_RESPONSIVE : LS_JUMP_FORWARD;
} else if (g_Input.forward) {
if (g_Lara.water_status == LWS_WADE) {
item->goal_anim_state = LS_WADE;
Expand Down Expand Up @@ -1101,7 +1129,7 @@ void Lara_State_Swim(ITEM *item, COLL_INFO *coll)

if (!g_Input.jump) {
item->goal_anim_state =
g_Config.gameplay.enable_tr2_swim_cancel ? LS_RESPONSIVE : LS_GLIDE;
m_EnableResponsiveSwimming ? LS_RESPONSIVE : LS_GLIDE;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/tr1/game/lara/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

extern void (*g_LaraStateRoutines[])(ITEM *item, COLL_INFO *coll);

void Lara_State_Initialise(void);

void Lara_State_Walk(ITEM *item, COLL_INFO *coll);
void Lara_State_Run(ITEM *item, COLL_INFO *coll);
void Lara_State_Stop(ITEM *item, COLL_INFO *coll);
Expand Down
3 changes: 3 additions & 0 deletions src/tr1/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "game/inventory_ring/vars.h"
#include "game/items.h"
#include "game/lara/common.h"
#include "game/lara/state.h"
#include "game/lot.h"
#include "game/music.h"
#include "game/objects/creatures/mutant.h"
Expand Down Expand Up @@ -866,6 +867,8 @@ static void M_CompleteSetup(const GAME_FLOW_LEVEL *const level)
Item_Initialise(i);
}

Lara_State_Initialise();

// Configure enemies who carry and drop items
Carrier_InitialiseLevel(level);

Expand Down

0 comments on commit 4ce54ad

Please sign in to comment.