Skip to content

Commit

Permalink
tr1/objects/common: fix using key items on consumed slots
Browse files Browse the repository at this point in the history
This fixes being able to re-use a key on already used keyholes, using a
puzzle item while Lara is still in the placement animation, and the
lead bar while she is still converting another one.

Resolves LostArtefacts#2256.
  • Loading branch information
lahm86 committed Jan 11, 2025
1 parent 8b17453 commit 603cc5d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- fixed wrong underwater caustics speed with the turbo cheat (#2231)
- fixed 1-frame UI flicker on pause screen exit confirmation
- fixed blood spawning on Lara from gunshots using incorrect positioning data (#2253)
- fixed being able to use keys and puzzle items in keyholes/slots that have already been used (#2256, regression from 4.0)
- 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/objects/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef struct {
void (*draw_routine)(ITEM *item);
void (*collision)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
const OBJECT_BOUNDS *(*bounds)(void);
bool (*is_usable)(int16_t item_num);
int16_t anim_idx;
int16_t hit_points;
int16_t pivot_length;
Expand Down
3 changes: 3 additions & 0 deletions src/tr1/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ int16_t Object_FindReceptacle(GAME_OBJECT_ID object_id)
ITEM *item = &g_Items[item_num];
if (item->object_id == receptacle_to_check) {
const OBJECT *const obj = &g_Objects[item->object_id];
if (obj->is_usable != NULL && !obj->is_usable(item_num)) {
continue;
}
if (Lara_TestPosition(item, obj->bounds())) {
return item_num;
}
Expand Down
8 changes: 8 additions & 0 deletions src/tr1/game/objects/general/keyhole.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static const OBJECT_BOUNDS m_KeyHoleBounds = {

static void M_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
static const OBJECT_BOUNDS *M_Bounds(void);
static bool M_IsUsable(int16_t item_num);

static void M_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll)
{
Expand Down Expand Up @@ -62,11 +63,18 @@ static const OBJECT_BOUNDS *M_Bounds(void)
return &m_KeyHoleBounds;
}

static bool M_IsUsable(const int16_t item_num)
{
const ITEM *const item = Item_Get(item_num);
return item->status == IS_INACTIVE;
}

void KeyHole_Setup(OBJECT *obj)
{
obj->collision = M_Collision;
obj->save_flags = 1;
obj->bounds = M_Bounds;
obj->is_usable = M_IsUsable;
}

bool KeyHole_Trigger(int16_t item_num)
Expand Down
8 changes: 8 additions & 0 deletions src/tr1/game/objects/general/puzzle_hole.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,25 @@ static const OBJECT_BOUNDS m_PuzzleHoleBounds = {
};

static const OBJECT_BOUNDS *M_Bounds(void);
static bool M_IsUsable(int16_t item_num);

static const OBJECT_BOUNDS *M_Bounds(void)
{
return &m_PuzzleHoleBounds;
}

static bool M_IsUsable(const int16_t item_num)
{
const ITEM *const item = Item_Get(item_num);
return item->status == IS_INACTIVE;
}

void PuzzleHole_Setup(OBJECT *obj)
{
obj->collision = PuzzleHole_Collision;
obj->save_flags = 1;
obj->bounds = M_Bounds;
obj->is_usable = M_IsUsable;
}

void PuzzleHole_SetupDone(OBJECT *obj)
Expand Down
1 change: 1 addition & 0 deletions src/tr1/game/objects/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ void Object_SetupAllObjects(void)
obj->draw_routine = Object_DrawAnimatingItem;
obj->ceiling_height_func = NULL;
obj->floor_height_func = NULL;
obj->is_usable = NULL;
obj->pivot_length = 0;
obj->radius = DEFAULT_RADIUS;
obj->shadow_size = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/tr1/game/objects/traps/midas_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ static const OBJECT_BOUNDS *M_Bounds(void)
return &m_MidasTouch_Bounds;
}

static bool M_IsUsable(const int16_t item_num)
{
return g_LaraItem->current_anim_state != LS_USE_MIDAS;
}

void MidasTouch_Setup(OBJECT *obj)
{
obj->collision = MidasTouch_Collision;
obj->draw_routine = Object_DrawDummyItem;
obj->bounds = M_Bounds;
obj->is_usable = M_IsUsable;
}

void MidasTouch_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll)
Expand Down

0 comments on commit 603cc5d

Please sign in to comment.