Skip to content

Commit

Permalink
tr1/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 LostArtefacts#1884.
  • Loading branch information
lahm86 committed Nov 12, 2024
1 parent e1f77f9 commit 66b57aa
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- added support for custom levels to enforce values for any config setting (#1846)
- added support for key/puzzle/pickup descriptions, allowing players to examine said items in the inventory (#1821)
- added an option to fix inventory item usage duplication (#1586)
- added optional automatic key/puzzle inventory item pre-selection (#1884)
- changed OpenGL backend to use version 3.3, with fallback to 2.1 if initialization fails (#1738)
- changed text backend to accept named sequences. Currently supported sequences (limited by the sprites available in OG):
- `\{umlaut}`
Expand Down
1 change: 1 addition & 0 deletions docs/tr1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ Not all options are turned on by default. Refer to `TR1X_ConfigTool.exe` for det
- added weapons to Lara's empty holsters on pickup
- added options to quiet or mute music while underwater
- added a photo mode feature
- added optional automatic key/puzzle inventory item pre-selection
- changed weapon pickup behavior when unarmed to set any weapon as the default weapon, not just pistols
- fixed keys and items not working when drawing guns immediately after using them
- fixed counting the secret in The Great Pyramid
Expand Down
1 change: 1 addition & 0 deletions src/tr1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct {
bool enable_skybox;
bool enable_ps1_crystals;
bool enable_item_examining;
bool enable_auto_item_selection;

struct {
int32_t layout;
Expand Down
1 change: 1 addition & 0 deletions src/tr1/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ CFG_BOOL(g_Config, enable_ps1_crystals, true)
CFG_BOOL(g_Config, ui.enable_game_ui, true)
CFG_BOOL(g_Config, ui.enable_photo_mode_ui, true)
CFG_BOOL(g_Config, enable_item_examining, true)
CFG_BOOL(g_Config, enable_auto_item_selection, true)
1 change: 1 addition & 0 deletions src/tr1/game/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdint.h>

bool Inv_Display(const INV_MODE inv_mode);
bool Inv_DisplayKeys(GAME_OBJECT_ID receptacle_type_id);

bool Inv_AddItem(GAME_OBJECT_ID object_id);
void Inv_AddItemNTimes(GAME_OBJECT_ID object_id, int32_t qty);
Expand Down
14 changes: 14 additions & 0 deletions src/tr1/game/inventory/inventory.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "config.h"
#include "game/inventory/inventory_ring.h"
#include "game/inventory/inventory_vars.h"
#include "game/phase/phase.h"
#include "game/phase/phase_inventory.h"
#include "global/types.h"

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

bool Inv_Display(const INV_MODE inv_mode)
Expand All @@ -16,3 +19,14 @@ bool Inv_Display(const INV_MODE inv_mode)
Phase_Set(PHASE_INVENTORY, args);
return true;
}

bool Inv_DisplayKeys(const GAME_OBJECT_ID receptacle_type_id)
{
if (g_Config.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);
}
27 changes: 27 additions & 0 deletions src/tr1/game/inventory/inventory_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ static TEXTSTRING *m_InvUpArrow2 = NULL;
static TEXTSTRING *m_ExamineItemText = NULL;
static TEXTSTRING *m_UseItemText = NULL;

static GAME_OBJECT_ID m_RequestedObjectID = NO_OBJECT;

static TEXTSTRING *M_InitExamineText(
int32_t x_pos, const char *role_str, const char *input_str);
static void M_HandleRequestedObject(RING_INFO *ring);

static TEXTSTRING *M_InitExamineText(
const int32_t x_pos, const char *const role_str,
Expand All @@ -47,6 +50,28 @@ static TEXTSTRING *M_InitExamineText(
return text;
}

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 Inv_Ring_Init(
RING_INFO *ring, int16_t type, INVENTORY_ITEM **list, int16_t qty,
int16_t current, IMOTION_INFO *imo)
Expand All @@ -58,6 +83,8 @@ void Inv_Ring_Init(
ring->current_object = current;
ring->angle_adder = 0x10000 / qty;

M_HandleRequestedObject(ring);

if (g_InvMode == INV_TITLE_MODE) {
ring->camera_pitch = 1024;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/tr1/game/inventory/inventory_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void Inv_Ring_ResetItem(INVENTORY_ITEM *inv_item);
bool Inv_Ring_CanExamine(void);
void Inv_Ring_InitExamineOverlay(void);
void Inv_Ring_RemoveExamineOverlay(void);
void Inv_Ring_SetRequestedObjectID(GAME_OBJECT_ID object_id);

void Inv_Ring_GetView(RING_INFO *ring, XYZ_32 *view_pos, XYZ_16 *view_rot);
void Inv_Ring_Light(RING_INFO *ring);
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/objects/general/keyhole.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void M_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll)
return;
}

Inv_Display(INV_KEYS_MODE);
Inv_DisplayKeys(item->object_id);
}

static const OBJECT_BOUNDS *M_Bounds(void)
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/objects/general/puzzle_hole.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ void PuzzleHole_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll)
return;
}

Inv_Display(INV_KEYS_MODE);
Inv_DisplayKeys(item->object_id);
}
2 changes: 1 addition & 1 deletion src/tr1/game/objects/traps/midas_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ void MidasTouch_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll)
return;
}

Inv_Display(INV_KEYS_MODE);
Inv_DisplayKeys(item->object_id);
}
4 changes: 4 additions & 0 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@
"Title": "Animated interactions",
"Description": "Makes Lara walk to pickups and switches when nearby instead of teleporting to them."
},
"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."
},
"enable_deaths_counter": {
"Title": "Count number of deaths",
"Description": "Enables showing a deaths counter in the compass and in the level statistics. Death count is updated in the currently loaded save as soon as Lara dies."
Expand Down
4 changes: 4 additions & 0 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@
"walk_to_items": {
"Title": "Interacciones animadas",
"Description": "Hace que Lara camine hacia los objetos recogibles y los interruptores cuando están cerca en lugar de teletransportarse hacia ellos."
},
"enable_auto_item_selection": {
"Title": "Preselección de elementos clave",
"Description": "Cuando Lara presiona la acción contra el ojo de una cerradura o la ranura de un rompecabezas y tiene el elemento correspondiente en el inventario, ese elemento será preseleccionado."
}
}
}
4 changes: 4 additions & 0 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@
"Title": "Interactions animées - Placement automatique",
"Description": "Fait marcher Lara vers les collectibles et les interrupteurs à proximité, au lieu de se téléporter vers eux."
},
"enable_auto_item_selection": {
"Title": "Présélection des éléments clés",
"Description": "Lorsque Lara appuie sur un trou de serrure ou un emplacement de puzzle et qu'elle a l'objet correspondant dans son inventaire, cet objet sera présélectionné."
},
"enable_deaths_counter": {
"Title": "Compteur du nombres de morts",
"Description": "Permet d'afficher un compteur de décès dans la boussole et dans les statistiques de niveau. Le nombre de morts est mis à jour dans la sauvegarde actuellement chargée dès que Lara meurt."
Expand Down
4 changes: 4 additions & 0 deletions tools/tr1/config/TR1X_ConfigTool/Resources/Lang/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@
"Title": "Interazioni animate",
"Description": "Fa in modo che Lara si avvicini agli oggetti, alle leve e agli interruttori quando questi sono nelle vicinanze, invece di teletrasportarsi."
},
"enable_auto_item_selection": {
"Title": "Preselezione degli elementi chiave",
"Description": "Quando Lara preme l'azione contro il buco della serratura o la fessura di un puzzle e ha l'oggetto corrispondente nell'inventario, quell'oggetto verrà preselezionato."
},
"enable_deaths_counter": {
"Title": "Conta il numero di morti",
"Description": "Permette di mostrare il conteggio delle morti nella bussola e nelle statistiche del livello. Il conteggio delle morti viene aggiornato nel salvataggio attualmente caricato ogni volta che Lara muore."
Expand Down
5 changes: 5 additions & 0 deletions tools/tr1/config/TR1X_ConfigTool/Resources/specification.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@
"DataType": "Bool",
"DefaultValue": false
},
{
"Field": "enable_auto_item_selection",
"DataType": "Bool",
"DefaultValue": true
},
{
"Field": "enable_deaths_counter",
"DataType": "Bool",
Expand Down

0 comments on commit 66b57aa

Please sign in to comment.