Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inventory: support automatic key item selection #1885

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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/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);
}
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/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
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
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