Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

object/names: move name management to libtrx #274

Merged
merged 3 commits into from
Sep 29, 2024
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
8 changes: 4 additions & 4 deletions data/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@
"O_FLARE_ITEM": "Flare",
"O_DETAIL_OPTION": "Detail Option",
"O_SOUND_OPTION": "Sound Option",
"O_CONTROL_OPTION": "Control Option",
"O_CONTROL_OPTION": "Controls Option",
"O_GAMMA_OPTION": "Gamma Option",
"O_PISTOL_OPTION": "Pistol Option",
"O_SHOTGUN_OPTION": "Shotgun Option",
"O_MAGNUM_OPTION": "Magnum Option",
"O_UZI_OPTION": "Uzi Option",
"O_MAGNUM_OPTION": "Magnums Option",
"O_UZI_OPTION": "Uzis Option",
"O_HARPOON_OPTION": "Harpoon Option",
"O_M16_OPTION": "M16 Option",
"O_GRENADE_OPTION": "Grenade Launcher Option",
Expand Down Expand Up @@ -327,7 +327,7 @@
"O_M16_FLASH": "M16 Flash",
"O_BODY_PART": "Body Part",
"O_CAMERA_TARGET": "Camera Target",
"O_WATERFALL": "Waterfall",
"O_WATERFALL": "Waterfall Mist",
"O_MISSILE_HARPOON": "Missile Harpoon",
"O_MISSILE_FLAME": "Missile Flame",
"O_MISSILE_KNIFE": "Missile Knife",
Expand Down
2 changes: 1 addition & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,7 @@ typedef enum { // decompiled
} LARA_MESH;

typedef enum { // decompiled
O_NONE = -1,
NO_OBJECT = -1,
O_LARA = 0,
O_LARA_PISTOLS = 1,
O_LARA_HAIR = 2,
Expand Down
3 changes: 1 addition & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ dll_sources = [
'src/game/objects/general/body_part.c',
'src/game/objects/general/door.c',
'src/game/objects/general/final_level_counter.c',
'src/game/objects/names.c',
'src/game/objects/traps/ember_emitter.c',
'src/game/objects/traps/flame_emitter.c',
'src/game/objects/vars.c',
Expand Down Expand Up @@ -170,7 +169,7 @@ dll_sources = [
'src/game/ui/widgets/label.c',
'src/game/ui/widgets/prompt.c',
'src/game/ui/widgets/window.c',
'src/global/enum_str.c',
'src/global/enum_map.c',
'src/global/vars.c',
'src/inject_exec.c',
'src/inject_util.c',
Expand Down
1 change: 0 additions & 1 deletion src/config_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <libtrx/config/map.h>
// import order guard

#include "global/enum_str.h"
#include "global/types.h"

const CONFIG_OPTION g_ConfigOptionMap[] = {
Expand Down
46 changes: 1 addition & 45 deletions src/game/gameflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#include "game/game.h"
#include "game/gun/gun.h"
#include "game/inventory/backpack.h"
#include "game/objects/names.h"
#include "game/overlay.h"
#include "game/requester.h"
#include "gameflow/gameflow_new.h"
#include "global/funcs.h"
#include "global/vars.h"

#include <libtrx/benchmark.h>
#include <libtrx/game/objects/names.h>
#include <libtrx/memory.h>
#include <libtrx/virtual_file.h>

Expand Down Expand Up @@ -334,50 +334,6 @@ int32_t __cdecl GF_LoadScriptFile(const char *const fname)

g_GameFlow.level_complete_track = MX_END_OF_LEVEL;

g_Inv_Item_Stopwatch.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_STATISTICS];
g_Inv_Item_Pistols.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_PISTOLS];
g_Inv_Item_Flare.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_FLARE];
g_Inv_Item_Shotgun.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_SHOTGUN];
g_Inv_Item_Magnums.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_MAGNUMS];
g_Inv_Item_Uzis.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_UZIS];
g_Inv_Item_Harpoon.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_HARPOON];
g_Inv_Item_M16.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_M16];
g_Inv_Item_Grenade.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_GRENADE];
g_Inv_Item_PistolAmmo.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_PISTOL_AMMO];
g_Inv_Item_ShotgunAmmo.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_SHOTGUN_AMMO];
g_Inv_Item_MagnumAmmo.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_MAGNUM_AMMO];
g_Inv_Item_UziAmmo.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_UZI_AMMO];
g_Inv_Item_HarpoonAmmo.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_HARPOON_AMMO];
g_Inv_Item_M16Ammo.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_M16_AMMO];
g_Inv_Item_GrenadeAmmo.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_GRENADE_AMMO];
g_Inv_Item_SmallMedi.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_SMALL_MEDIPACK];
g_Inv_Item_LargeMedi.string =
g_GF_GameStrings[GF_S_GAME_INV_ITEM_LARGE_MEDIPACK];
g_Inv_Item_Pickup1.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_PICKUP];
g_Inv_Item_Pickup2.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_PICKUP];
g_Inv_Item_Puzzle1.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_PUZZLE];
g_Inv_Item_Puzzle2.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_PUZZLE];
g_Inv_Item_Puzzle3.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_PUZZLE];
g_Inv_Item_Puzzle4.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_PUZZLE];
g_Inv_Item_Key1.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_KEY];
g_Inv_Item_Key2.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_KEY];
g_Inv_Item_Key3.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_KEY];
g_Inv_Item_Key4.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_KEY];

g_Inv_Item_Passport.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_GAME];
g_Inv_Item_Graphics.string = g_GF_PCStrings[GF_S_PC_DETAIL_LEVELS];

g_Inv_Item_Sound.string = g_GF_PCStrings[GF_S_PC_SOUND];
g_Inv_Item_Controls.string = g_GF_PCStrings[GF_S_PC_CONTROLS];
g_Inv_Item_Photo.string = g_GF_GameStrings[GF_S_GAME_INV_ITEM_LARA_HOME];

Requester_SetHeading(
&g_LoadGameRequester, g_GF_GameStrings[GF_S_GAME_PASSPORT_SELECT_LEVEL],
0, 0, 0);
Expand Down
142 changes: 136 additions & 6 deletions src/game/gameflow/gameflow_new.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "game/gameflow/gameflow_new.h"

#include "game/game_string.h"
#include "game/objects/names.h"
#include "global/enum_str.h"
#include "global/types.h"
#include "global/vars.h"

#include <libtrx/enum_map.h>
#include <libtrx/game/gameflow/types.h>
#include <libtrx/game/objects/names.h>
#include <libtrx/log.h>

#include <assert.h>
Expand All @@ -21,10 +21,10 @@ static void M_LoadGameStrings(const int32_t level_num);

static void M_LoadObjectString(const char *const key, const char *const value)
{
const GAME_OBJECT_ID object =
ENUM_STRING_GET(GAME_OBJECT_ID, key, NO_OBJECT);
if (object != NO_OBJECT) {
Object_SetName(object, value);
const GAME_OBJECT_ID object_id =
ENUM_MAP_GET(GAME_OBJECT_ID, key, NO_OBJECT);
if (object_id != NO_OBJECT) {
Object_SetName(object_id, value);
}
}

Expand Down Expand Up @@ -83,8 +83,138 @@ static void M_LoadGameStrings(const int32_t level_num)

void GF_N_LoadStrings(const int32_t level_num)
{
Object_ResetNames();

M_LoadObjectStrings(level_num);
M_LoadGameStrings(level_num);

struct {
GAME_OBJECT_ID object_id;
GF_GAME_STRING game_string;
} game_string_defs[] = {
{ O_COMPASS_OPTION, GF_S_GAME_INV_ITEM_STATISTICS },
{ O_COMPASS_ITEM, GF_S_GAME_INV_ITEM_STATISTICS },
{ O_PISTOL_ITEM, GF_S_GAME_INV_ITEM_PISTOLS },
{ O_PISTOL_OPTION, GF_S_GAME_INV_ITEM_PISTOLS },
{ O_FLARE_ITEM, GF_S_GAME_INV_ITEM_FLARE },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot an entry for: { O_FLARE_OPTION, ...}, so it falls back to OBJ_NAME_DEFINE(O_FLARES_OPTION, "Flare Option") in libtrx include/libtrx/game/objects/names_tr2.def

{ O_FLARES_OPTION, GF_S_GAME_INV_ITEM_FLARE },
{ O_SHOTGUN_ITEM, GF_S_GAME_INV_ITEM_SHOTGUN },
{ O_SHOTGUN_OPTION, GF_S_GAME_INV_ITEM_SHOTGUN },
{ O_MAGNUM_ITEM, GF_S_GAME_INV_ITEM_MAGNUMS },
{ O_MAGNUM_OPTION, GF_S_GAME_INV_ITEM_MAGNUMS },
{ O_UZI_ITEM, GF_S_GAME_INV_ITEM_UZIS },
{ O_UZI_OPTION, GF_S_GAME_INV_ITEM_UZIS },
{ O_HARPOON_ITEM, GF_S_GAME_INV_ITEM_HARPOON },
{ O_HARPOON_OPTION, GF_S_GAME_INV_ITEM_HARPOON },
{ O_M16_ITEM, GF_S_GAME_INV_ITEM_M16 },
{ O_M16_OPTION, GF_S_GAME_INV_ITEM_M16 },
{ O_GRENADE_ITEM, GF_S_GAME_INV_ITEM_GRENADE },
{ O_GRENADE_OPTION, GF_S_GAME_INV_ITEM_GRENADE },
{ O_PISTOL_AMMO_ITEM, GF_S_GAME_INV_ITEM_PISTOL_AMMO },
{ O_PISTOL_AMMO_OPTION, GF_S_GAME_INV_ITEM_PISTOL_AMMO },
{ O_SHOTGUN_AMMO_ITEM, GF_S_GAME_INV_ITEM_SHOTGUN_AMMO },
{ O_SHOTGUN_AMMO_OPTION, GF_S_GAME_INV_ITEM_SHOTGUN_AMMO },
{ O_MAGNUM_AMMO_ITEM, GF_S_GAME_INV_ITEM_MAGNUM_AMMO },
{ O_MAGNUM_AMMO_OPTION, GF_S_GAME_INV_ITEM_MAGNUM_AMMO },
{ O_UZI_AMMO_ITEM, GF_S_GAME_INV_ITEM_UZI_AMMO },
{ O_UZI_AMMO_OPTION, GF_S_GAME_INV_ITEM_UZI_AMMO },
{ O_HARPOON_AMMO_ITEM, GF_S_GAME_INV_ITEM_HARPOON_AMMO },
{ O_HARPOON_AMMO_OPTION, GF_S_GAME_INV_ITEM_HARPOON_AMMO },
{ O_M16_AMMO_ITEM, GF_S_GAME_INV_ITEM_M16_AMMO },
{ O_M16_AMMO_OPTION, GF_S_GAME_INV_ITEM_M16_AMMO },
{ O_GRENADE_AMMO_ITEM, GF_S_GAME_INV_ITEM_GRENADE_AMMO },
{ O_GRENADE_AMMO_OPTION, GF_S_GAME_INV_ITEM_GRENADE_AMMO },
{ O_SMALL_MEDIPACK_ITEM, GF_S_GAME_INV_ITEM_SMALL_MEDIPACK },
{ O_SMALL_MEDIPACK_OPTION, GF_S_GAME_INV_ITEM_SMALL_MEDIPACK },
{ O_LARGE_MEDIPACK_ITEM, GF_S_GAME_INV_ITEM_LARGE_MEDIPACK },
{ O_LARGE_MEDIPACK_OPTION, GF_S_GAME_INV_ITEM_LARGE_MEDIPACK },
{ O_PICKUP_ITEM_1, GF_S_GAME_INV_ITEM_PICKUP },
{ O_PICKUP_OPTION_1, GF_S_GAME_INV_ITEM_PICKUP },
{ O_PICKUP_ITEM_2, GF_S_GAME_INV_ITEM_PICKUP },
{ O_PICKUP_OPTION_2, GF_S_GAME_INV_ITEM_PICKUP },
{ O_PUZZLE_ITEM_1, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_PUZZLE_OPTION_1, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_PUZZLE_ITEM_2, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_PUZZLE_OPTION_2, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_PUZZLE_ITEM_3, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_PUZZLE_OPTION_3, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_PUZZLE_ITEM_4, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_PUZZLE_OPTION_4, GF_S_GAME_INV_ITEM_PUZZLE },
{ O_KEY_ITEM_1, GF_S_GAME_INV_ITEM_KEY },
{ O_KEY_OPTION_1, GF_S_GAME_INV_ITEM_KEY },
{ O_KEY_ITEM_2, GF_S_GAME_INV_ITEM_KEY },
{ O_KEY_OPTION_2, GF_S_GAME_INV_ITEM_KEY },
{ O_KEY_ITEM_3, GF_S_GAME_INV_ITEM_KEY },
{ O_KEY_OPTION_3, GF_S_GAME_INV_ITEM_KEY },
{ O_KEY_ITEM_4, GF_S_GAME_INV_ITEM_KEY },
{ O_KEY_OPTION_4, GF_S_GAME_INV_ITEM_KEY },
{ O_PASSPORT_OPTION, GF_S_GAME_INV_ITEM_GAME },
{ O_PASSPORT_CLOSED, GF_S_GAME_INV_ITEM_GAME },
{ O_PHOTO_OPTION, GF_S_GAME_INV_ITEM_LARA_HOME },
{ NO_OBJECT, -1 },
};

for (int32_t i = 0; game_string_defs[i].object_id != NO_OBJECT; i++) {
const char *const new_name =
g_GF_GameStrings[game_string_defs[i].game_string];
if (new_name != NULL) {
Object_SetName(game_string_defs[i].object_id, new_name);
}
}

struct {
GAME_OBJECT_ID object_id;
GF_PC_STRING pc_string;
} pc_string_defs[] = {
{ O_DETAIL_OPTION, GF_S_PC_DETAIL_LEVELS },
{ O_SOUND_OPTION, GF_S_PC_SOUND },
{ O_CONTROL_OPTION, GF_S_PC_CONTROLS },
{ NO_OBJECT, -1 },
};

for (int32_t i = 0; pc_string_defs[i].object_id != NO_OBJECT; i++) {
const char *const new_name =
g_GF_PCStrings[pc_string_defs[i].pc_string];
if (new_name != NULL) {
Object_SetName(pc_string_defs[i].object_id, new_name);
}
}

struct {
GAME_OBJECT_ID object_id;
char **strings;
} level_item_defs[] = {
{ O_PUZZLE_ITEM_1, g_GF_Puzzle1Strings },
{ O_PUZZLE_ITEM_2, g_GF_Puzzle2Strings },
{ O_PUZZLE_ITEM_3, g_GF_Puzzle3Strings },
{ O_PUZZLE_ITEM_4, g_GF_Puzzle4Strings },
{ O_KEY_ITEM_1, g_GF_Key1Strings },
{ O_KEY_ITEM_2, g_GF_Key2Strings },
{ O_KEY_ITEM_3, g_GF_Key3Strings },
{ O_KEY_ITEM_4, g_GF_Key4Strings },
{ O_PICKUP_ITEM_1, g_GF_Pickup1Strings },
{ O_PICKUP_ITEM_2, g_GF_Pickup2Strings },
{ O_PUZZLE_OPTION_1, g_GF_Puzzle1Strings },
{ O_PUZZLE_OPTION_2, g_GF_Puzzle2Strings },
{ O_PUZZLE_OPTION_3, g_GF_Puzzle3Strings },
{ O_PUZZLE_OPTION_4, g_GF_Puzzle4Strings },
{ O_KEY_OPTION_1, g_GF_Key1Strings },
{ O_KEY_OPTION_2, g_GF_Key2Strings },
{ O_KEY_OPTION_3, g_GF_Key3Strings },
{ O_KEY_OPTION_4, g_GF_Key4Strings },
{ O_PICKUP_OPTION_1, g_GF_Pickup1Strings },
{ O_PICKUP_OPTION_2, g_GF_Pickup2Strings },
{ NO_OBJECT, NULL },
};

if (level_num >= 0 && level_num < g_GameFlow.num_levels) {
for (int32_t i = 0; level_item_defs[i].object_id != NO_OBJECT; i++) {
const char *const new_name = level_item_defs[i].strings[level_num];
if (new_name != NULL) {
Object_SetName(level_item_defs[i].object_id, new_name);
}
}
}
}

void Gameflow_OverrideCommand(const GAMEFLOW_COMMAND command)
Expand Down
49 changes: 4 additions & 45 deletions src/game/inventory/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "global/types.h"
#include "global/vars.h"

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

#include <stdio.h>

#define TITLE_RING_OBJECTS 3
Expand Down Expand Up @@ -1127,52 +1129,9 @@ void __cdecl Inv_RingIsNotOpen(RING_INFO *const ring)
void __cdecl Inv_RingNotActive(const INVENTORY_ITEM *const inv_item)
{
if (g_Inv_ItemText[0] == NULL) {
switch (inv_item->object_id) {
case O_PASSPORT_OPTION:
break;
case O_PUZZLE_OPTION_1:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Puzzle1Strings[g_CurrentLevel]);
break;
case O_PUZZLE_OPTION_2:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Puzzle2Strings[g_CurrentLevel]);
break;
case O_PUZZLE_OPTION_3:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Puzzle3Strings[g_CurrentLevel]);
break;
case O_PUZZLE_OPTION_4:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Puzzle4Strings[g_CurrentLevel]);
break;
case O_KEY_OPTION_1:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Key1Strings[g_CurrentLevel]);
break;
case O_KEY_OPTION_2:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Key2Strings[g_CurrentLevel]);
break;
case O_KEY_OPTION_3:
if (inv_item->object_id != O_PASSPORT_OPTION) {
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Key3Strings[g_CurrentLevel]);
break;
case O_KEY_OPTION_4:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Key4Strings[g_CurrentLevel]);
break;
case O_PICKUP_OPTION_1:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Pickup1Strings[g_CurrentLevel]);
break;
case O_PICKUP_OPTION_2:
g_Inv_ItemText[0] =
Text_Create(0, -16, 0, g_GF_Pickup2Strings[g_CurrentLevel]);
break;
default:
g_Inv_ItemText[0] = Text_Create(0, -16, 0, inv_item->string);
break;
Text_Create(0, -16, 0, Object_GetName(inv_item->object_id));
}

if (g_Inv_ItemText[0]) {
Expand Down
Loading
Loading