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

Move /hp and /pos console commands to libtrx #1527

Merged
merged 3 commits into from
Sep 18, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- fixed `/tp` console command not always picking the closest item (#1486, regression from 4.1)
- fixed `/tp` console command reporting teleport fails as success (#1484, regression from 4.1)
- fixed `/tp` console command allowing teleporting to consumed savegame crystals (#1518)
- fixed `/hp` console command taking arbitrary integers
- fixed `/set` console command not sanitizing numeric values (#1515)
- fixed console commands causing improper ring shutdown with selected inventory item (#1460, regression from 3.0)
- fixed console input immediately ending demo (#1480, regression from 4.1)
Expand Down
334 changes: 167 additions & 167 deletions data/ship/cfg/TR1X_gameflow.json5

Large diffs are not rendered by default.

334 changes: 167 additions & 167 deletions data/ship/cfg/TR1X_gameflow_demo_pc.json5

Large diffs are not rendered by default.

334 changes: 167 additions & 167 deletions data/ship/cfg/TR1X_gameflow_ub.json5

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/game/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "config.h"
#include "game/clock.h"
#include "game/console_cmd.h"
#include "game/game_string.h"
#include "game/input.h"
#include "game/output.h"
Expand All @@ -12,6 +11,7 @@
#include "global/const.h"
#include "global/types.h"

#include <libtrx/game/console/common.h>
#include <libtrx/log.h>

#include <SDL2/SDL_keycode.h>
Expand Down Expand Up @@ -53,6 +53,8 @@ static void Console_UpdatePromptTextstring(void);
static void Console_UpdateCaretTextstring(void);
static COMMAND_RESULT Console_Eval(const char *const cmdline);

extern CONSOLE_COMMAND *g_ConsoleCommands[];

static void Console_UpdatePromptTextstring(void)
{
Text_ChangeText(m_Prompt.prompt_ts, m_Prompt.text);
Expand All @@ -74,8 +76,12 @@ static COMMAND_RESULT Console_Eval(const char *const cmdline)
const char *args = NULL;
const CONSOLE_COMMAND *matching_cmd = NULL;

for (CONSOLE_COMMAND *cur_cmd = &g_ConsoleCommands[0];
cur_cmd->prefix != NULL; cur_cmd++) {
for (int32_t i = 0;; i++) {
CONSOLE_COMMAND *const cur_cmd = g_ConsoleCommands[i];
if (cur_cmd == NULL) {
break;
}

if (strstr(cmdline, cur_cmd->prefix) != cmdline) {
continue;
}
Expand Down
109 changes: 33 additions & 76 deletions src/game/console_cmd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "game/console_cmd.h"

#include "config.h"
#include "config_map.h"
#include "game/clock.h"
Expand All @@ -23,6 +21,9 @@
#include "global/types.h"
#include "global/vars.h"

#include <libtrx/game/console/commands/pos.h>
#include <libtrx/game/console/commands/set_health.h>
#include <libtrx/game/console/common.h>
#include <libtrx/memory.h>
#include <libtrx/strings.h>

Expand All @@ -39,9 +40,7 @@ static bool Console_Cmd_GetCurrentValue(
static bool Console_Cmd_SetCurrentValue(const char *key, const char *new_value);
static bool Console_Cmd_IsFloatRound(const float num);
static COMMAND_RESULT Console_Cmd_Fps(const char *const args);
static COMMAND_RESULT Console_Cmd_Pos(const char *const args);
static COMMAND_RESULT Console_Cmd_Teleport(const char *const args);
static COMMAND_RESULT Console_Cmd_SetHealth(const char *const args);
static COMMAND_RESULT Console_Cmd_Heal(const char *const args);
static COMMAND_RESULT Console_Cmd_Fly(const char *const args);
static COMMAND_RESULT Console_Cmd_Speed(const char *const args);
Expand Down Expand Up @@ -91,22 +90,6 @@ static COMMAND_RESULT Console_Cmd_Fps(const char *const args)
return CR_BAD_INVOCATION;
}

static COMMAND_RESULT Console_Cmd_Pos(const char *const args)
{
if (!g_Objects[O_LARA].loaded) {
return CR_UNAVAILABLE;
}

Console_Log(
GS(OSD_POS_GET), g_LaraItem->room_num,
g_LaraItem->pos.x / (float)WALL_L, g_LaraItem->pos.y / (float)WALL_L,
g_LaraItem->pos.z / (float)WALL_L,
g_LaraItem->rot.x * 360.0f / (float)PHD_ONE,
g_LaraItem->rot.y * 360.0f / (float)PHD_ONE,
g_LaraItem->rot.z * 360.0f / (float)PHD_ONE);
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
{
if (g_GameInfo.current_level_type == GFL_TITLE
Expand Down Expand Up @@ -232,33 +215,6 @@ static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
return CR_BAD_INVOCATION;
}

static COMMAND_RESULT Console_Cmd_SetHealth(const char *const 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_Objects[O_LARA].loaded) {
return CR_UNAVAILABLE;
}

if (String_Equivalent(args, "")) {
Console_Log(GS(OSD_CURRENT_HEALTH_GET), g_LaraItem->hit_points);
return CR_SUCCESS;
}

int32_t hp;
if (sscanf(args, "%d", &hp) != 1) {
return CR_BAD_INVOCATION;
}

g_LaraItem->hit_points = hp;
Console_Log(GS(OSD_CURRENT_HEALTH_SET), hp);
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Heal(const char *const args)
{
if (g_GameInfo.current_level_type == GFL_TITLE
Expand Down Expand Up @@ -871,33 +827,34 @@ static COMMAND_RESULT Console_Cmd_Abortion(const char *args)
return CR_SUCCESS;
}

CONSOLE_COMMAND g_ConsoleCommands[] = {
{ .prefix = "fps", .proc = Console_Cmd_Fps },
{ .prefix = "pos", .proc = Console_Cmd_Pos },
{ .prefix = "tp", .proc = Console_Cmd_Teleport },
{ .prefix = "hp", .proc = Console_Cmd_SetHealth },
{ .prefix = "heal", .proc = Console_Cmd_Heal },
{ .prefix = "fly", .proc = Console_Cmd_Fly },
{ .prefix = "speed", .proc = Console_Cmd_Speed },
{ .prefix = "vsync", .proc = Console_Cmd_VSync },
{ .prefix = "braid", .proc = Console_Cmd_Braid },
{ .prefix = "wireframe", .proc = Console_Cmd_Wireframe },
{ .prefix = "cheats", .proc = Console_Cmd_Cheats },
{ .prefix = "give", .proc = Console_Cmd_GiveItem },
{ .prefix = "gimme", .proc = Console_Cmd_GiveItem },
{ .prefix = "set", .proc = Console_Cmd_Set },
{ .prefix = "flip", .proc = Console_Cmd_FlipMap },
{ .prefix = "flipmap", .proc = Console_Cmd_FlipMap },
{ .prefix = "kill", .proc = Console_Cmd_Kill },
{ .prefix = "endlevel", .proc = Console_Cmd_EndLevel },
{ .prefix = "play", .proc = Console_Cmd_StartLevel },
{ .prefix = "level", .proc = Console_Cmd_StartLevel },
{ .prefix = "load", .proc = Console_Cmd_LoadGame },
{ .prefix = "save", .proc = Console_Cmd_SaveGame },
{ .prefix = "demo", .proc = Console_Cmd_StartDemo },
{ .prefix = "title", .proc = Console_Cmd_ExitToTitle },
{ .prefix = "exit", .proc = Console_Cmd_ExitGame },
{ .prefix = "abortion", .proc = Console_Cmd_Abortion },
{ .prefix = "natlastinks", .proc = Console_Cmd_Abortion },
{ .prefix = NULL, .proc = NULL },
CONSOLE_COMMAND *g_ConsoleCommands[] = {
&(CONSOLE_COMMAND) { .prefix = "fps", .proc = Console_Cmd_Fps },
&(CONSOLE_COMMAND) { .prefix = "tp", .proc = Console_Cmd_Teleport },
&(CONSOLE_COMMAND) { .prefix = "heal", .proc = Console_Cmd_Heal },
&(CONSOLE_COMMAND) { .prefix = "fly", .proc = Console_Cmd_Fly },
&(CONSOLE_COMMAND) { .prefix = "speed", .proc = Console_Cmd_Speed },
&(CONSOLE_COMMAND) { .prefix = "vsync", .proc = Console_Cmd_VSync },
&(CONSOLE_COMMAND) { .prefix = "braid", .proc = Console_Cmd_Braid },
&(CONSOLE_COMMAND) { .prefix = "wireframe", .proc = Console_Cmd_Wireframe },
&(CONSOLE_COMMAND) { .prefix = "cheats", .proc = Console_Cmd_Cheats },
&(CONSOLE_COMMAND) { .prefix = "give", .proc = Console_Cmd_GiveItem },
&(CONSOLE_COMMAND) { .prefix = "gimme", .proc = Console_Cmd_GiveItem },
&(CONSOLE_COMMAND) { .prefix = "set", .proc = Console_Cmd_Set },
&(CONSOLE_COMMAND) { .prefix = "flip", .proc = Console_Cmd_FlipMap },
&(CONSOLE_COMMAND) { .prefix = "flipmap", .proc = Console_Cmd_FlipMap },
&(CONSOLE_COMMAND) { .prefix = "kill", .proc = Console_Cmd_Kill },
&(CONSOLE_COMMAND) { .prefix = "endlevel", .proc = Console_Cmd_EndLevel },
&(CONSOLE_COMMAND) { .prefix = "play", .proc = Console_Cmd_StartLevel },
&(CONSOLE_COMMAND) { .prefix = "level", .proc = Console_Cmd_StartLevel },
&(CONSOLE_COMMAND) { .prefix = "load", .proc = Console_Cmd_LoadGame },
&(CONSOLE_COMMAND) { .prefix = "save", .proc = Console_Cmd_SaveGame },
&(CONSOLE_COMMAND) { .prefix = "demo", .proc = Console_Cmd_StartDemo },
&(CONSOLE_COMMAND) { .prefix = "title", .proc = Console_Cmd_ExitToTitle },
&(CONSOLE_COMMAND) { .prefix = "exit", .proc = Console_Cmd_ExitGame },
&(CONSOLE_COMMAND) { .prefix = "abortion", .proc = Console_Cmd_Abortion },
&(CONSOLE_COMMAND) { .prefix = "natlastinks",
.proc = Console_Cmd_Abortion },
&g_Console_Cmd_Pos,
&g_Console_Cmd_SetHealth,
NULL,
};
17 changes: 0 additions & 17 deletions src/game/console_cmd.h

This file was deleted.

2 changes: 2 additions & 0 deletions src/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ void Game_ProcessInput(void);
void Game_DrawScene(bool draw_overlay);

GAMEFLOW_COMMAND Game_MainMenu(void);

bool Game_IsPlayable(void);
15 changes: 15 additions & 0 deletions src/game/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,18 @@ GAMEFLOW_COMMAND Game_Stop(void)
return (GAMEFLOW_COMMAND) { .action = GF_EXIT_TO_TITLE };
}
}

bool Game_IsPlayable(void)
{
if (g_GameInfo.current_level_type == GFL_TITLE
|| g_GameInfo.current_level_type == GFL_DEMO
|| g_GameInfo.current_level_type == GFL_CUTSCENE) {
return false;
}

if (!g_Objects[O_LARA].loaded) {
return false;
}

return true;
}
2 changes: 2 additions & 0 deletions src/game/game_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
void GameString_Init(void)
{
#include "game_string.def"

#include <libtrx/game/game_string.def>
}

void GameString_Shutdown(void)
Expand Down
3 changes: 0 additions & 3 deletions src/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ GS_DEFINE(OSD_FLY_MODE_ON, "Fly mode enabled")
GS_DEFINE(OSD_FLY_MODE_OFF, "Fly mode disabled")
GS_DEFINE(OSD_FPS_GET, "FPS currently set to %d")
GS_DEFINE(OSD_FPS_SET, "FPS set to %d")
GS_DEFINE(OSD_POS_GET, "Room: %d\nPosition: %.3f, %.3f, %.3f\nRotation: %.3f,%.3f,%.3f")
GS_DEFINE(OSD_POS_SET_POS, "Teleported to position: %.3f %.3f %.3f")
GS_DEFINE(OSD_POS_SET_POS_FAIL, "Failed to teleport to position: %.3f %.3f %.3f")
GS_DEFINE(OSD_POS_SET_ROOM, "Teleported to room: %d")
Expand Down Expand Up @@ -193,8 +192,6 @@ GS_DEFINE(OSD_LOAD_GAME_FAIL_INVALID_SLOT, "Invalid save slot %d")
GS_DEFINE(OSD_SAVE_GAME, "Saved game to save slot %d")
GS_DEFINE(OSD_SAVE_GAME_FAIL, "Cannot save the game in the current state")
GS_DEFINE(OSD_SAVE_GAME_FAIL_INVALID_SLOT, "Invalid save slot %d")
GS_DEFINE(OSD_CURRENT_HEALTH_GET, "Current Lara's health: %d")
GS_DEFINE(OSD_CURRENT_HEALTH_SET, "Lara's health set to %d")
GS_DEFINE(OSD_HEAL_ALREADY_FULL_HP, "Lara's already at full health")
GS_DEFINE(OSD_HEAL_SUCCESS, "Healed Lara back to full health")
GS_DEFINE(OSD_CONFIG_OPTION_GET, "%s is currently set to %s")
Expand Down
5 changes: 5 additions & 0 deletions src/game/lara/lara.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#define LARA_MOVE_SPEED 16
#define LARA_UW_DAMAGE 5

ITEM_INFO *Lara_GetItem(void)
{
return g_LaraItem;
}

void Lara_Control(void)
{
COLL_INFO coll = { 0 };
Expand Down
5 changes: 5 additions & 0 deletions src/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ const GAME_OBJECT_PAIR g_ItemToInvObjectMap[] = {
// clang-format on
};

OBJECT_INFO *Object_GetObject(GAME_OBJECT_ID object_id)
{
return &g_Objects[object_id];
}

GAME_OBJECT_ID Object_GetCognate(
GAME_OBJECT_ID key_id, const GAME_OBJECT_PAIR *test_map)
{
Expand Down
Loading
Loading