Skip to content

Commit

Permalink
console/cmd: move /hp to libtrx
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 17, 2024
1 parent 132efe8 commit 560a13a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 32 deletions.
31 changes: 2 additions & 29 deletions src/game/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#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 @@ -40,7 +41,6 @@ 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_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 @@ -215,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 @@ -857,7 +830,6 @@ static COMMAND_RESULT Console_Cmd_Abortion(const char *args)
CONSOLE_COMMAND *g_ConsoleCommands[] = {
&(CONSOLE_COMMAND) { .prefix = "fps", .proc = Console_Cmd_Fps },
&(CONSOLE_COMMAND) { .prefix = "tp", .proc = Console_Cmd_Teleport },
&(CONSOLE_COMMAND) { .prefix = "hp", .proc = Console_Cmd_SetHealth },
&(CONSOLE_COMMAND) { .prefix = "heal", .proc = Console_Cmd_Heal },
&(CONSOLE_COMMAND) { .prefix = "fly", .proc = Console_Cmd_Fly },
&(CONSOLE_COMMAND) { .prefix = "speed", .proc = Console_Cmd_Speed },
Expand All @@ -883,5 +855,6 @@ CONSOLE_COMMAND *g_ConsoleCommands[] = {
&(CONSOLE_COMMAND) { .prefix = "natlastinks",
.proc = Console_Cmd_Abortion },
&g_Console_Cmd_Pos,
&g_Console_Cmd_SetHealth,
NULL,
};
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: 0 additions & 2 deletions src/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -192,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
2 changes: 1 addition & 1 deletion subprojects/libtrx

0 comments on commit 560a13a

Please sign in to comment.