Skip to content

Commit

Permalink
tr2/inventory: support automatic key item selection
Browse files Browse the repository at this point in the history
This allows the inventory to open on the correct key item based upon
the receptacle Lara is currently trying to use.

Resolves #1884.
  • Loading branch information
lahm86 committed Nov 12, 2024
1 parent 01f040d commit a9803a0
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr2-0.6...develop) - ××××-××-××
- added support for custom levels to enforce values for any config setting (#1846)
- added an option to fix inventory item usage duplication (#1586)
- added optional automatic key/puzzle inventory item pre-selection (#1884)
- fixed depth problems when drawing certain rooms (#1853, regression from 0.6)
- fixed Lara getting stuck in her hit animation if she is hit while mounting the boat or skidoo (#1606)
- fixed being unable to go from surface swimming to underwater swimming without first stopping (#1863, regression from 0.6)
Expand Down
1 change: 1 addition & 0 deletions docs/tr2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ decompilation process. We recognize that there is much work to be done.
#### Gameplay
- added an option to fix M16 accuracy while running
- added optional rendering of pickups in the UI as 3D meshes
- added optional automatic key/puzzle inventory item pre-selection
- changed inventory to pause the music rather than muting it
- fixed killing the T-Rex with a grenade launcher crashing the game
- fixed secret rewards not displaying shotgun ammo
Expand Down
3 changes: 3 additions & 0 deletions src/libtrx/game/objects/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const GAME_OBJECT_PAIR g_KeyItemToReceptacleMap[] = {
{ O_PUZZLE_OPTION_4, O_PUZZLE_HOLE_4 },
#if TR_VERSION == 1
{ O_LEADBAR_OPTION, O_MIDAS_TOUCH },
#elif TR_VERSION == 2
{ O_KEY_OPTION_2, O_DETONATOR_1 },
{ O_KEY_OPTION_2, O_DETONATOR_2 },
#endif
{ NO_OBJECT, NO_OBJECT },
// clang-format on
Expand Down
1 change: 1 addition & 0 deletions src/tr2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct {
bool fix_m16_accuracy;
bool enable_cheats;
bool fix_item_duplication_glitch;
bool enable_auto_item_selection;
} gameplay;

struct {
Expand Down
1 change: 1 addition & 0 deletions src/tr2/config_map.def
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CFG_BOOL(g_Config, gameplay.fix_m16_accuracy, true)
CFG_BOOL(g_Config, gameplay.enable_cheats, false)
CFG_BOOL(g_Config, gameplay.fix_item_duplication_glitch, false)
CFG_BOOL(g_Config, gameplay.enable_auto_item_selection, true)
CFG_BOOL(g_Config, visuals.enable_3d_pickups, true)
CFG_ENUM(g_Config, rendering.screenshot_format, SCREENSHOT_FORMAT_JPEG, SCREENSHOT_FORMAT)
CFG_INT32(g_Config, rendering.turbo_speed, 0)
Expand Down
12 changes: 12 additions & 0 deletions src/tr2/game/inventory/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "global/vars.h"

#include <libtrx/game/objects/names.h>
#include <libtrx/game/objects/vars.h>

#include <stdio.h>

Expand Down Expand Up @@ -819,6 +820,17 @@ int32_t __cdecl Inv_Display(int32_t inventory_mode)
return 0;
}

int32_t Inv_DisplayKeys(const GAME_OBJECT_ID receptacle_type_id)
{
if (g_Config.gameplay.enable_auto_item_selection) {
const GAME_OBJECT_ID object_id = Object_GetCognateInverse(
receptacle_type_id, g_KeyItemToReceptacleMap);
Inv_Ring_SetRequestedObjectID(object_id);
}

return Inv_Display(INV_KEYS_MODE);
}

void __cdecl Inv_SelectMeshes(INVENTORY_ITEM *const inv_item)
{
switch (inv_item->object_id) {
Expand Down
1 change: 1 addition & 0 deletions src/tr2/game/inventory/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
void __cdecl Inv_InitColors(void);
void __cdecl Inv_Construct(void);
int32_t __cdecl Inv_Display(int32_t inventory_mode);
int32_t Inv_DisplayKeys(GAME_OBJECT_ID receptacle_type_id);
void __cdecl Inv_SelectMeshes(INVENTORY_ITEM *inv_item);
int32_t __cdecl Inv_AnimateInventoryItem(INVENTORY_ITEM *inv_item);
void __cdecl Inv_DrawInventoryItem(INVENTORY_ITEM *inv_item);
Expand Down
29 changes: 29 additions & 0 deletions src/tr2/game/inventory/ring.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "game/inventory/ring.h"

#include "game/inventory/backpack.h"
#include "game/math_misc.h"
#include "game/output.h"
#include "global/funcs.h"
Expand All @@ -13,6 +14,32 @@
#define RING_CAMERA_HEIGHT (-256)
#define RING_CAMERA_Y_OFFSET (-96)

static GAME_OBJECT_ID m_RequestedObjectID = NO_OBJECT;

static void M_HandleRequestedObject(RING_INFO *ring);

static void M_HandleRequestedObject(RING_INFO *const ring)
{
if (m_RequestedObjectID == NO_OBJECT) {
return;
}

for (int32_t i = 0; i < ring->number_of_objects; i++) {
const GAME_OBJECT_ID item_id = ring->list[i]->object_id;
if (item_id == m_RequestedObjectID && Inv_RequestItem(item_id) > 0) {
ring->current_object = i;
break;
}
}

m_RequestedObjectID = NO_OBJECT;
}

void Inv_Ring_SetRequestedObjectID(const GAME_OBJECT_ID object_id)
{
m_RequestedObjectID = object_id;
}

void __cdecl Inv_Ring_Init(
RING_INFO *const ring, const RING_TYPE type, INVENTORY_ITEM **const list,
const int16_t qty, const int16_t current, IMOTION_INFO *const imo)
Expand All @@ -24,6 +51,8 @@ void __cdecl Inv_Ring_Init(
ring->radius = 0;
ring->angle_adder = 0x10000 / qty;

M_HandleRequestedObject(ring);

if (g_Inv_Mode == INV_TITLE_MODE) {
ring->camera_pitch = 1024;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/tr2/game/inventory/ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "global/types.h"

void Inv_Ring_SetRequestedObjectID(const GAME_OBJECT_ID object_id);
void __cdecl Inv_Ring_Init(
RING_INFO *ring, RING_TYPE type, INVENTORY_ITEM **list, int16_t qty,
int16_t current, IMOTION_INFO *imo);
Expand Down
2 changes: 1 addition & 1 deletion src/tr2/game/objects/general/detonator.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void __cdecl Detonator_Collision(
}

if (g_Inv_Chosen == NO_OBJECT) {
Inv_Display(INV_KEYS_MODE);
Inv_DisplayKeys(item->object_id);
}

if (g_Inv_Chosen != O_KEY_OPTION_2) {
Expand Down
2 changes: 1 addition & 1 deletion src/tr2/game/objects/general/keyhole.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void __cdecl Keyhole_Collision(
}

if (g_Inv_Chosen == NO_OBJECT) {
Inv_Display(INV_KEYS_MODE);
Inv_DisplayKeys(item->object_id);
if (g_Inv_Chosen == NO_OBJECT && g_Inv_KeyObjectsCount > 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tr2/game/objects/general/puzzle_hole.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void __cdecl PuzzleHole_Collision(
}

if (g_Inv_Chosen == NO_OBJECT) {
Inv_Display(INV_KEYS_MODE);
Inv_DisplayKeys(item->object_id);
if (g_Inv_Chosen == NO_OBJECT && g_Inv_KeyObjectsCount > 0) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions tools/tr2/config/TR2X_ConfigTool/Resources/Lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"Title": "Fix item duplication glitch",
"Description": "Fixes the ability to duplicate usage of key items in the inventory."
},
"enable_auto_item_selection": {
"Title": "Key item pre-selection",
"Description": "When Lara presses action against a keyhole or puzzle slot, and she has the corresponding item in the inventory, that item will be pre-selected."
},
"screenshot_format": {
"Title": "Screenshot format",
"Description": "Screenshot file format."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
"ID": "gameplay_options",
"Image": "Graphics/graphic4.jpg",
"Properties": [

{
"Field": "enable_auto_item_selection",
"DataType": "Bool",
"DefaultValue": true
}
]
},
{
Expand Down

0 comments on commit a9803a0

Please sign in to comment.