tr2/inventory: support automatic key item selection

This allows the inventory to open on the correct key item based upon
the receptacle Lara is currently trying to use.

Resolves #1884.
This commit is contained in:
lahm86 2024-11-12 17:34:40 +00:00
parent 01f040d9b8
commit a9803a0bca
14 changed files with 62 additions and 4 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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 {

View file

@ -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)

View file

@ -29,6 +29,7 @@
#include "global/vars.h"
#include <libtrx/game/objects/names.h>
#include <libtrx/game/objects/vars.h>
#include <stdio.h>
@ -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) {

View file

@ -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);

View file

@ -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"
@ -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)
@ -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 {

View file

@ -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);

View file

@ -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) {

View file

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

View file

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

View file

@ -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."

View file

@ -44,7 +44,11 @@
"ID": "gameplay_options",
"Image": "Graphics/graphic4.jpg",
"Properties": [
{
"Field": "enable_auto_item_selection",
"DataType": "Bool",
"DefaultValue": true
}
]
},
{