From 451e6199991ee43141e04dcb824a44d56791652a Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 21 Sep 2024 01:16:00 +0200 Subject: [PATCH] console/cmd: move /kill to libtrx --- data/ship/cfg/TR1X_gameflow.json5 | 2 + data/ship/cfg/TR1X_gameflow_demo_pc.json5 | 2 + data/ship/cfg/TR1X_gameflow_ub.json5 | 2 + meson.build | 1 - src/game/console/cmd/kill.c | 112 ---------------------- src/game/console/cmd/kill.h | 5 - src/game/console/setup.c | 2 +- src/game/creature.c | 10 ++ src/game/game_string.def | 4 - src/game/items.c | 5 + src/game/objects/common.c | 8 ++ src/game/objects/common.h | 1 + subprojects/libtrx | 2 +- 13 files changed, 32 insertions(+), 124 deletions(-) delete mode 100644 src/game/console/cmd/kill.c delete mode 100644 src/game/console/cmd/kill.h diff --git a/data/ship/cfg/TR1X_gameflow.json5 b/data/ship/cfg/TR1X_gameflow.json5 index 9d5b0db55..30554c14c 100644 --- a/data/ship/cfg/TR1X_gameflow.json5 +++ b/data/ship/cfg/TR1X_gameflow.json5 @@ -721,6 +721,7 @@ "OSD_HEAL_SUCCESS": "Healed Lara back to full health", "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", "OSD_KILL": "Bye-bye!", "OSD_KILL_ALL": "Poof! %d enemies gone!", @@ -729,6 +730,7 @@ "OSD_LOAD_GAME": "Loaded game from save slot %d", "OSD_LOAD_GAME_FAIL_INVALID_SLOT": "Invalid save slot %d", "OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT": "Save slot %d is not available", + "OSD_OBJECT_NOT_FOUND": "Object not found", "OSD_PERSPECTIVE_FILTER_OFF": "Perspective filter disabled", "OSD_PERSPECTIVE_FILTER_ON": "Perspective filter enabled", "OSD_PLAY_LEVEL": "Loading %s", diff --git a/data/ship/cfg/TR1X_gameflow_demo_pc.json5 b/data/ship/cfg/TR1X_gameflow_demo_pc.json5 index 472a79b55..71f058c81 100644 --- a/data/ship/cfg/TR1X_gameflow_demo_pc.json5 +++ b/data/ship/cfg/TR1X_gameflow_demo_pc.json5 @@ -216,6 +216,7 @@ "OSD_HEAL_SUCCESS": "Healed Lara back to full health", "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", "OSD_KILL": "Bye-bye!", "OSD_KILL_ALL": "Poof! %d enemies gone!", @@ -224,6 +225,7 @@ "OSD_LOAD_GAME": "Loaded game from save slot %d", "OSD_LOAD_GAME_FAIL_INVALID_SLOT": "Invalid save slot %d", "OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT": "Save slot %d is not available", + "OSD_OBJECT_NOT_FOUND": "Object not found", "OSD_PERSPECTIVE_FILTER_OFF": "Perspective filter disabled", "OSD_PERSPECTIVE_FILTER_ON": "Perspective filter enabled", "OSD_PLAY_LEVEL": "Loading %s", diff --git a/data/ship/cfg/TR1X_gameflow_ub.json5 b/data/ship/cfg/TR1X_gameflow_ub.json5 index c69f87e54..695edc409 100644 --- a/data/ship/cfg/TR1X_gameflow_ub.json5 +++ b/data/ship/cfg/TR1X_gameflow_ub.json5 @@ -288,6 +288,7 @@ "OSD_HEAL_SUCCESS": "Healed Lara back to full health", "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", "OSD_KILL": "Bye-bye!", "OSD_KILL_ALL": "Poof! %d enemies gone!", @@ -296,6 +297,7 @@ "OSD_LOAD_GAME": "Loaded game from save slot %d", "OSD_LOAD_GAME_FAIL_INVALID_SLOT": "Invalid save slot %d", "OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT": "Save slot %d is not available", + "OSD_OBJECT_NOT_FOUND": "Object not found", "OSD_PERSPECTIVE_FILTER_OFF": "Perspective filter disabled", "OSD_PERSPECTIVE_FILTER_ON": "Perspective filter enabled", "OSD_PLAY_LEVEL": "Loading %s", diff --git a/meson.build b/meson.build index 10948991f..03b5536d6 100644 --- a/meson.build +++ b/meson.build @@ -110,7 +110,6 @@ sources = [ 'src/game/console/cmd/flipmap.c', 'src/game/console/cmd/fly.c', 'src/game/console/cmd/fps.c', - 'src/game/console/cmd/kill.c', 'src/game/console/cmd/load_game.c', 'src/game/console/cmd/play_demo.c', 'src/game/console/cmd/play_level.c', diff --git a/src/game/console/cmd/kill.c b/src/game/console/cmd/kill.c deleted file mode 100644 index 1581b9812..000000000 --- a/src/game/console/cmd/kill.c +++ /dev/null @@ -1,112 +0,0 @@ -#include "game/console/cmd/kill.h" - -#include "game/game_string.h" -#include "game/items.h" -#include "game/lara.h" -#include "game/lara/lara_cheat.h" -#include "game/objects/common.h" -#include "game/objects/names.h" -#include "game/sound.h" -#include "global/vars.h" - -#include -#include -#include - -static bool M_CanTargetObject_Enemy(GAME_OBJECT_ID object_id); -static COMMAND_RESULT M_Entrypoint(const char *args); - -static bool M_CanTargetObject_Enemy(const GAME_OBJECT_ID object_id) -{ - return Object_IsObjectType(object_id, g_EnemyObjects); -} - -static COMMAND_RESULT M_Entrypoint(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; - } - - // kill all the enemies in the level - if (String_Equivalent(args, "all")) { - int32_t num = 0; - for (int16_t item_num = 0; item_num < Item_GetTotalCount(); - item_num++) { - if (Lara_Cheat_KillEnemy(item_num)) { - num++; - } - } - - if (num == 0) { - Console_Log(GS(OSD_KILL_ALL_FAIL), num); - return CR_FAILURE; - } - - Sound_Effect(SFX_EXPLOSION_CHEAT, &g_LaraItem->pos, SPM_NORMAL); - Console_Log(GS(OSD_KILL_ALL), num); - return CR_SUCCESS; - } - - // kill all the enemies around Lara within one tile, or a single nearest - // enemy - if (String_Equivalent(args, "")) { - bool found = false; - while (true) { - const int16_t best_item_num = Lara_GetNearestEnemy(); - if (best_item_num == NO_ITEM) { - break; - } - - ITEM_INFO *const item = &g_Items[best_item_num]; - const int32_t distance = Item_GetDistance(item, &g_LaraItem->pos); - found |= Lara_Cheat_KillEnemy(best_item_num); - if (distance >= WALL_L) { - break; - } - } - - if (!found) { - Console_Log(GS(OSD_KILL_FAIL)); - return CR_FAILURE; - } - - Console_Log(GS(OSD_KILL)); - return CR_SUCCESS; - } - - // kill a single enemy type - { - int32_t match_count = 0; - GAME_OBJECT_ID *matching_objs = - Object_IdsFromName(args, &match_count, M_CanTargetObject_Enemy); - int32_t num = 0; - for (int32_t i = 0; i < match_count; i++) { - const GAME_OBJECT_ID object_id = matching_objs[i]; - for (int16_t item_num = 0; item_num < Item_GetTotalCount(); - item_num++) { - if (g_Items[item_num].object_id == object_id - && Lara_Cheat_KillEnemy(item_num)) { - num++; - } - } - } - Memory_FreePointer(&matching_objs); - - if (!match_count) { - return CR_BAD_INVOCATION; - } - if (num == 0) { - Console_Log(GS(OSD_KILL_ALL_FAIL)); - return CR_FAILURE; - } - Console_Log(GS(OSD_KILL_ALL), num); - return CR_SUCCESS; - } -} - -CONSOLE_COMMAND g_Console_Cmd_Kill = { - .prefix = "kill", - .proc = M_Entrypoint, -}; diff --git a/src/game/console/cmd/kill.h b/src/game/console/cmd/kill.h deleted file mode 100644 index 3766fe1f8..000000000 --- a/src/game/console/cmd/kill.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -extern CONSOLE_COMMAND g_Console_Cmd_Kill; diff --git a/src/game/console/setup.c b/src/game/console/setup.c index 368ec1783..3cc728d26 100644 --- a/src/game/console/setup.c +++ b/src/game/console/setup.c @@ -9,7 +9,6 @@ #include "game/console/cmd/flipmap.h" #include "game/console/cmd/fly.h" #include "game/console/cmd/fps.h" -#include "game/console/cmd/kill.h" #include "game/console/cmd/load_game.h" #include "game/console/cmd/play_demo.h" #include "game/console/cmd/play_level.h" @@ -22,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/src/game/creature.c b/src/game/creature.c index 2a6a1ddde..b2cd50c06 100644 --- a/src/game/creature.c +++ b/src/game/creature.c @@ -817,3 +817,13 @@ static bool M_TestSwitchOrKill( Item_Kill(item_num); return false; } + +bool Creature_IsEnemy(const ITEM_INFO *const item) +{ + return Object_IsObjectType(item->object_id, g_EnemyObjects); +} + +bool Creature_IsAlly(const ITEM_INFO *const item) +{ + return Object_IsObjectType(item->object_id, g_AllyObjects); +} diff --git a/src/game/game_string.def b/src/game/game_string.def index 59689b140..1b948f8e6 100644 --- a/src/game/game_string.def +++ b/src/game/game_string.def @@ -153,10 +153,6 @@ GS_DEFINE(OSD_FLIPMAP_ON, "Flipmap set to ON") GS_DEFINE(OSD_FLIPMAP_OFF, "Flipmap set to OFF") GS_DEFINE(OSD_FLIPMAP_FAIL_ALREADY_ON, "Flipmap is already ON") GS_DEFINE(OSD_FLIPMAP_FAIL_ALREADY_OFF, "Flipmap is already OFF") -GS_DEFINE(OSD_KILL_ALL, "Poof! %d enemies gone!") -GS_DEFINE(OSD_KILL_ALL_FAIL, "Uh-oh, there are no enemies left to kill...") -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_TEXTURE_FILTER_SET, "Texture filter set to %s") diff --git a/src/game/items.c b/src/game/items.c index f8d594275..e956ac683 100644 --- a/src/game/items.c +++ b/src/game/items.c @@ -838,3 +838,8 @@ bool Item_TestFrameRange(ITEM_INFO *item, int16_t start, int16_t end) item->frame_num, g_Anims[item->anim_num].frame_base + start, g_Anims[item->anim_num].frame_base + end); } + +ITEM_INFO *Item_Get(const int16_t item_num) +{ + return &g_Items[item_num]; +} diff --git a/src/game/objects/common.c b/src/game/objects/common.c index 879fa80db..9d9e43b2b 100644 --- a/src/game/objects/common.c +++ b/src/game/objects/common.c @@ -52,6 +52,14 @@ const GAME_OBJECT_ID g_EnemyObjects[] = { // clang-format on }; +const GAME_OBJECT_ID g_AllyObjects[] = { + // clang-format off + O_LARA, + NO_OBJECT, + // Lara's social skills: still loading... + // clang-format on +}; + const GAME_OBJECT_ID g_BossObjects[] = { // clang-format off O_TREX, diff --git a/src/game/objects/common.h b/src/game/objects/common.h index f022dc98c..5ebd5d8f9 100644 --- a/src/game/objects/common.h +++ b/src/game/objects/common.h @@ -10,6 +10,7 @@ typedef struct GAME_OBJECT_PAIR { } GAME_OBJECT_PAIR; extern const GAME_OBJECT_ID g_EnemyObjects[]; +extern const GAME_OBJECT_ID g_AllyObjects[]; extern const GAME_OBJECT_ID g_BossObjects[]; extern const GAME_OBJECT_ID g_PlaceholderObjects[]; extern const GAME_OBJECT_ID g_PickupObjects[]; diff --git a/subprojects/libtrx b/subprojects/libtrx index e37658930..41cd1a09e 160000 --- a/subprojects/libtrx +++ b/subprojects/libtrx @@ -1 +1 @@ -Subproject commit e376589305ba378c34fafcdf143d07d2f14a8b77 +Subproject commit 41cd1a09e3ea1c445df702cd9fa0d7682761459f