diff --git a/data/ship/cfg/TR2X_gameflow.json5 b/data/ship/cfg/TR2X_gameflow.json5 index c3a14de4..02ebe1fa 100644 --- a/data/ship/cfg/TR2X_gameflow.json5 +++ b/data/ship/cfg/TR2X_gameflow.json5 @@ -376,7 +376,7 @@ "OSD_GIVE_ITEM_CHEAT": "Lara's backpack just got way heavier!", "OSD_HEAL_ALREADY_FULL_HP": "Lara's already at full health", "OSD_HEAL_SUCCESS": "Healed Lara back to full health", - "OSD_INVALID_ITEM": "Invalid item: %s", + "OSD_INVALID_ITEM": "Unknown item: %s", "OSD_INVALID_LEVEL": "Invalid level", "OSD_INVALID_OBJECT": "Invalid object", "OSD_INVALID_ROOM": "Invalid room: %d. Valid rooms are 0-%d", diff --git a/meson.build b/meson.build index 38fa8fa7..54bcf2cb 100644 --- a/meson.build +++ b/meson.build @@ -85,6 +85,7 @@ dll_sources = [ 'src/decomp/effects.c', 'src/decomp/stats.c', 'src/game/background.c', + 'src/game/backpack.c', 'src/game/box.c', 'src/game/camera.c', 'src/game/clock.c', diff --git a/src/game/backpack.c b/src/game/backpack.c new file mode 100644 index 00000000..e2d0ac63 --- /dev/null +++ b/src/game/backpack.c @@ -0,0 +1,8 @@ +#include "game/inventory/backpack.h" + +#include + +bool Backpack_AddItem(const GAME_OBJECT_ID object_id) +{ + return Inv_AddItem(object_id); +} diff --git a/src/game/console.c b/src/game/console.c index e9e79211..b19e6fe9 100644 --- a/src/game/console.c +++ b/src/game/console.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -97,16 +98,18 @@ static COMMAND_RESULT M_Eval(const char *const cmdline) if (cur_cmd == NULL) { break; } - if (strstr(cmdline, cur_cmd->prefix) != cmdline) { + + char regex[strlen(cur_cmd->prefix) + 13]; + sprintf(regex, "^(%s)(\\s+.*)?$", cur_cmd->prefix); + if (!String_Match(cmdline, regex)) { continue; } - if (cmdline[strlen(cur_cmd->prefix)] == ' ') { - args = cmdline + strlen(cur_cmd->prefix) + 1; - } else if (cmdline[strlen(cur_cmd->prefix)] == '\0') { - args = ""; + args = strstr(cmdline, " "); + if (args != NULL) { + args++; } else { - continue; + args = ""; } matching_cmd = cur_cmd; diff --git a/src/game/console_cmd.c b/src/game/console_cmd.c index 76610f84..40108451 100644 --- a/src/game/console_cmd.c +++ b/src/game/console_cmd.c @@ -19,6 +19,7 @@ #include "lara/lara_misc.h" #include +#include #include #include #include @@ -31,12 +32,10 @@ static bool M_CanTargetObject(GAME_OBJECT_ID object_id); static bool M_CanTargetObjectCreature(GAME_OBJECT_ID object_id); -static bool M_CanTargetObjectPickup(GAME_OBJECT_ID object_id); static bool M_IsFloatRound(float num); static COMMAND_RESULT Console_Cmd_Teleport(const char *args); static COMMAND_RESULT Console_Cmd_Fly(const char *const args); static COMMAND_RESULT Console_Cmd_FlipMap(const char *args); -static COMMAND_RESULT Console_Cmd_GiveItem(const char *args); static COMMAND_RESULT Console_Cmd_Kill(const char *args); static COMMAND_RESULT Console_Cmd_EndLevel(const char *args); static COMMAND_RESULT Console_Cmd_StartLevel(const char *args); @@ -60,11 +59,6 @@ static bool M_CanTargetObjectCreature(const GAME_OBJECT_ID object_id) || Object_IsObjectType(object_id, g_FriendObjects); } -static bool M_CanTargetObjectPickup(const GAME_OBJECT_ID object_id) -{ - return Object_IsObjectType(object_id, g_PickupObjects); -} - static inline bool M_IsFloatRound(const float num) { return (fabsf(num) - roundf(num)) < 0.0001f; @@ -337,65 +331,6 @@ static COMMAND_RESULT Console_Cmd_Kill(const char *args) } } -static COMMAND_RESULT Console_Cmd_GiveItem(const char *args) -{ - if (g_GameInfo.current_level.type == GFL_TITLE - || g_GameInfo.current_level.type == GFL_DEMO - || g_GameInfo.current_level.type == GFL_CUTSCENE) { - return CR_UNAVAILABLE; - } - - if (g_LaraItem == NULL) { - return CR_UNAVAILABLE; - } - - if (String_Equivalent(args, "keys")) { - return Lara_Cheat_GiveAllKeys() ? CR_SUCCESS : CR_FAILURE; - } - - if (String_Equivalent(args, "guns")) { - return Lara_Cheat_GiveAllGuns() ? CR_SUCCESS : CR_FAILURE; - } - - if (String_Equivalent(args, "all")) { - return Lara_Cheat_GiveAllItems() ? CR_SUCCESS : CR_FAILURE; - } - - int32_t num = 1; - if (sscanf(args, "%d ", &num) == 1) { - args = strstr(args, " "); - if (!args) { - return CR_BAD_INVOCATION; - } - args++; - } - - if (String_Equivalent(args, "")) { - return CR_BAD_INVOCATION; - } - - bool found = false; - int32_t match_count = 0; - GAME_OBJECT_ID *matching_objs = - Object_IdsFromName(args, &match_count, M_CanTargetObjectPickup); - for (int32_t i = 0; i < match_count; i++) { - const GAME_OBJECT_ID object_id = matching_objs[i]; - if (g_Objects[object_id].loaded) { - Inv_AddItemNTimes(object_id, num); - Console_Log(GS(OSD_GIVE_ITEM), Object_GetName(object_id)); - found = true; - } - } - Memory_FreePointer(&matching_objs); - - if (!found) { - Console_Log(GS(OSD_INVALID_ITEM), args); - return CR_FAILURE; - } - - return CR_SUCCESS; -} - static COMMAND_RESULT Console_Cmd_EndLevel(const char *const args) { if (strcmp(args, "") == 0) { @@ -540,8 +475,6 @@ static COMMAND_RESULT Console_Cmd_Abortion(const char *const args) CONSOLE_COMMAND *g_ConsoleCommands[] = { &(CONSOLE_COMMAND) { .prefix = "tp", .proc = Console_Cmd_Teleport }, &(CONSOLE_COMMAND) { .prefix = "fly", .proc = Console_Cmd_Fly }, - &(CONSOLE_COMMAND) { .prefix = "give", .proc = Console_Cmd_GiveItem }, - &(CONSOLE_COMMAND) { .prefix = "gimme", .proc = Console_Cmd_GiveItem }, &(CONSOLE_COMMAND) { .prefix = "flip", .proc = Console_Cmd_FlipMap }, &(CONSOLE_COMMAND) { .prefix = "flipmap", .proc = Console_Cmd_FlipMap }, &(CONSOLE_COMMAND) { .prefix = "kill", .proc = Console_Cmd_Kill }, @@ -560,5 +493,6 @@ CONSOLE_COMMAND *g_ConsoleCommands[] = { &g_Console_Cmd_Pos, &g_Console_Cmd_Heal, &g_Console_Cmd_SetHealth, + &g_Console_Cmd_GiveItem, NULL, }; diff --git a/src/game/game_string.def b/src/game/game_string.def index 6200cebd..70f7ddc6 100644 --- a/src/game/game_string.def +++ b/src/game/game_string.def @@ -6,7 +6,6 @@ GS_DEFINE(OSD_POS_SET_ROOM, "Teleported to room: %d") GS_DEFINE(OSD_POS_SET_ROOM_FAIL, "Failed to teleport to room: %d") GS_DEFINE(OSD_POS_SET_ITEM, "Teleported to object: %s") GS_DEFINE(OSD_POS_SET_ITEM_FAIL, "Failed to teleport to object: %s") -GS_DEFINE(OSD_GIVE_ITEM, "Added %s to Lara's inventory") GS_DEFINE(OSD_GIVE_ITEM_ALL_KEYS, "Surprise! Every key item Lara needs is now in her backpack.") GS_DEFINE(OSD_GIVE_ITEM_ALL_GUNS, "Lock'n'load - Lara's armed to the teeth!") GS_DEFINE(OSD_GIVE_ITEM_CHEAT, "Lara's backpack just got way heavier!") @@ -20,7 +19,6 @@ GS_DEFINE(OSD_KILL, "Bye-bye!") GS_DEFINE(OSD_KILL_FAIL, "No enemy nearby...") GS_DEFINE(OSD_COMPLETE_LEVEL, "Level complete!") GS_DEFINE(OSD_PLAY_LEVEL, "Loading %s") -GS_DEFINE(OSD_INVALID_ITEM, "Invalid item: %s") GS_DEFINE(OSD_INVALID_ROOM, "Invalid room: %d. Valid rooms are 0-%d") GS_DEFINE(OSD_INVALID_OBJECT, "Invalid object") GS_DEFINE(OSD_OBJECT_NOT_FOUND, "Object not found") diff --git a/subprojects/libtrx b/subprojects/libtrx index 712366cf..616e230b 160000 --- a/subprojects/libtrx +++ b/subprojects/libtrx @@ -1 +1 @@ -Subproject commit 712366cf915288e14b2a4cd8743572489ae12cc2 +Subproject commit 616e230b3d5d4a2f2e926e82826712e536813710