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 /give and /kill to libtrx; restructure console commands #1533

Merged
merged 3 commits into from
Sep 21, 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
2 changes: 2 additions & 0 deletions data/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions data/ship/cfg/TR1X_gameflow_demo_pc.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions data/ship/cfg/TR1X_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand All @@ -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",
Expand Down
22 changes: 20 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,31 @@ sources = [
'src/config.c',
'src/config_map.c',
'src/game/anim.c',
'src/game/backpack.c',
'src/game/box.c',
'src/game/camera.c',
'src/game/carrier.c',
'src/game/clock.c',
'src/game/collide.c',
'src/game/console.c',
'src/game/console_cmd.c',
'src/game/console/cmd/braid.c',
'src/game/console/cmd/cheats.c',
'src/game/console/cmd/die.c',
'src/game/console/cmd/end_level.c',
'src/game/console/cmd/exit_game.c',
'src/game/console/cmd/exit_to_title.c',
'src/game/console/cmd/flipmap.c',
'src/game/console/cmd/fly.c',
'src/game/console/cmd/fps.c',
'src/game/console/cmd/load_game.c',
'src/game/console/cmd/play_demo.c',
'src/game/console/cmd/play_level.c',
'src/game/console/cmd/save_game.c',
'src/game/console/cmd/speed.c',
'src/game/console/cmd/teleport.c',
'src/game/console/cmd/vsync.c',
'src/game/console/cmd/wireframe.c',
'src/game/console/common.c',
'src/game/console/setup.c',
'src/game/creature.c',
'src/game/effect_routines/bubbles.c',
'src/game/effect_routines/chain_block.c',
Expand Down
8 changes: 8 additions & 0 deletions src/game/backpack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "game/inventory.h"

#include <libtrx/game/backpack.h>

bool Backpack_AddItem(const GAME_OBJECT_ID object_id)
{
return Inv_AddItem(object_id);
}
2 changes: 1 addition & 1 deletion src/game/clock.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "game/clock.h"

#include "config.h"
#include "game/console.h"
#include "game/console/common.h"
#include "game/game_string.h"
#include "global/const.h"

Expand Down
18 changes: 18 additions & 0 deletions src/game/console/cmd/braid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "game/console/cmd/braid.h"

#include "config.h"

#include <libtrx/game/console/cmd/config.h>

static COMMAND_RESULT M_Entrypoint(const char *const args);

static COMMAND_RESULT M_Entrypoint(const char *const args)
{
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(&g_Config.enable_braid), args);
}

CONSOLE_COMMAND g_Console_Cmd_Braid = {
.prefix = "braid",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/braid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_Braid;
18 changes: 18 additions & 0 deletions src/game/console/cmd/cheats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "game/console/cmd/cheats.h"

#include "config.h"

#include <libtrx/game/console/cmd/config.h>

static COMMAND_RESULT M_Entrypoint(const char *const args);

static COMMAND_RESULT M_Entrypoint(const char *const args)
{
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(&g_Config.enable_cheats), args);
}

CONSOLE_COMMAND g_Console_Cmd_Cheats = {
.prefix = "cheats",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/cheats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_Cheats;
32 changes: 32 additions & 0 deletions src/game/console/cmd/die.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "game/console/cmd/die.h"

#include "game/effects.h"
#include "game/effects/exploding_death.h"
#include "game/objects/common.h"
#include "game/sound.h"
#include "global/vars.h"

static COMMAND_RESULT M_Entrypoint(const char *args);

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

if (g_LaraItem->hit_points <= 0) {
return CR_UNAVAILABLE;
}

Effect_ExplodingDeath(g_Lara.item_num, -1, 0);
Sound_Effect(SFX_EXPLOSION_CHEAT, &g_LaraItem->pos, SPM_NORMAL);
Sound_Effect(SFX_LARA_FALL, &g_LaraItem->pos, SPM_NORMAL);
g_LaraItem->hit_points = 0;
g_LaraItem->flags |= IS_INVISIBLE;
return CR_SUCCESS;
}

CONSOLE_COMMAND g_Console_Cmd_Die = {
.prefix = "abortion|natlastinks",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/die.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_Die;
22 changes: 22 additions & 0 deletions src/game/console/cmd/end_level.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "game/console/cmd/end_level.h"

#include "game/lara/lara_cheat.h"

#include <libtrx/strings.h>

static COMMAND_RESULT M_Entrypoint(const char *args);

static COMMAND_RESULT M_Entrypoint(const char *const args)
{
if (!String_Equivalent(args, "")) {
return CR_BAD_INVOCATION;
}

Lara_Cheat_EndLevel();
return CR_SUCCESS;
}

CONSOLE_COMMAND g_Console_Cmd_EndLevel = {
.prefix = "endlevel",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/end_level.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_EndLevel;
17 changes: 17 additions & 0 deletions src/game/console/cmd/exit_game.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "game/console/cmd/exit_game.h"

#include "global/vars.h"

static COMMAND_RESULT M_Entrypoint(const char *args);

static COMMAND_RESULT M_Entrypoint(const char *args)
{
g_GameInfo.override_gf_command =
(GAMEFLOW_COMMAND) { .action = GF_EXIT_GAME };
return CR_SUCCESS;
}

CONSOLE_COMMAND g_Console_Cmd_ExitGame = {
.prefix = "exit",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/exit_game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_ExitGame;
17 changes: 17 additions & 0 deletions src/game/console/cmd/exit_to_title.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "game/console/cmd/exit_to_title.h"

#include "global/vars.h"

static COMMAND_RESULT M_Entrypoint(const char *args);

static COMMAND_RESULT M_Entrypoint(const char *args)
{
g_GameInfo.override_gf_command =
(GAMEFLOW_COMMAND) { .action = GF_EXIT_TO_TITLE };
return CR_SUCCESS;
}

CONSOLE_COMMAND g_Console_Cmd_ExitToTitle = {
.prefix = "title",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/exit_to_title.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_ExitToTitle;
41 changes: 41 additions & 0 deletions src/game/console/cmd/flipmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "game/console/cmd/flipmap.h"

#include "game/game_string.h"
#include "game/room.h"
#include "global/vars.h"

#include <libtrx/strings.h>

static COMMAND_RESULT M_Entrypoint(const char *args);

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;
}

bool new_state;
if (String_Equivalent(args, "")) {
new_state = !g_FlipStatus;
} else if (!String_ParseBool(args, &new_state)) {
return CR_BAD_INVOCATION;
}

if (g_FlipStatus == new_state) {
Console_Log(
new_state ? GS(OSD_FLIPMAP_FAIL_ALREADY_ON)
: GS(OSD_FLIPMAP_FAIL_ALREADY_OFF));
return CR_SUCCESS;
}

Room_FlipMap();
Console_Log(new_state ? GS(OSD_FLIPMAP_ON) : GS(OSD_FLIPMAP_OFF));
return CR_SUCCESS;
}

CONSOLE_COMMAND g_Console_Cmd_FlipMap = {
.prefix = "flip|flipmap",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/flipmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_FlipMap;
22 changes: 22 additions & 0 deletions src/game/console/cmd/fly.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "game/console/cmd/fly.h"

#include "game/game.h"
#include "game/game_string.h"
#include "game/lara/lara_cheat.h"

static COMMAND_RESULT M_Entrypoint(const char *const args);

static COMMAND_RESULT M_Entrypoint(const char *const args)
{
if (!Game_IsPlayable()) {
return CR_UNAVAILABLE;
}
Console_Log(GS(OSD_FLY_MODE_ON));
Lara_Cheat_EnterFlyMode();
return CR_SUCCESS;
}

CONSOLE_COMMAND g_Console_Cmd_Fly = {
.prefix = "fly",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/fly.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_Fly;
18 changes: 18 additions & 0 deletions src/game/console/cmd/fps.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "game/console/cmd/fps.h"

#include "config.h"

#include <libtrx/game/console/cmd/config.h>

static COMMAND_RESULT M_Entrypoint(const char *const args);

static COMMAND_RESULT M_Entrypoint(const char *const args)
{
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(&g_Config.rendering.fps), args);
}

CONSOLE_COMMAND g_Console_Cmd_FPS = {
.prefix = "fps",
.proc = M_Entrypoint,
};
5 changes: 5 additions & 0 deletions src/game/console/cmd/fps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

extern CONSOLE_COMMAND g_Console_Cmd_FPS;
Loading
Loading