Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Add /set, move /heal to libtrx #243

Merged
merged 3 commits into from
Sep 19, 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 @@ -11,6 +11,7 @@
- `/give`
- `/kill`
- `/flip`
- `/set`
- added an ability to remap the console key (#163)
- added `/tp` console command's ability to teleport to specific items
- added `/fly` console command's ability to open nearest doors
Expand Down
5 changes: 5 additions & 0 deletions data/ship/cfg/TR2X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,14 @@
},

"game_strings": {
"MISC_OFF": "Off",
"MISC_ON": "On",
"OSD_COMMAND_BAD_INVOCATION": "Invalid invocation: %s",
"OSD_COMMAND_UNAVAILABLE": "This command is not currently available",
"OSD_COMPLETE_LEVEL": "Level complete!",
"OSD_CONFIG_OPTION_GET": "%s is currently set to %s",
"OSD_CONFIG_OPTION_SET": "%s changed to %s",
"OSD_CONFIG_OPTION_UNKNOWN_OPTION": "Unknown option: %s",
"OSD_CURRENT_HEALTH_GET": "Current Lara's health: %d",
"OSD_CURRENT_HEALTH_SET": "Lara's health set to %d",
"OSD_DOOR_CLOSE": "Close Sesame!",
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ dll_sources = [
'src/game/lara/lara_look.c',
'src/game/lara/lara_misc.c',
'src/game/lara/lara_state.c',
'src/game/lara/misc.c',
'src/game/level.c',
'src/game/los.c',
'src/game/lot.c',
Expand Down
13 changes: 13 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ bool Config_Write(void)
File_CreateDirectory(DIR_CONFIG);
return ConfigFile_Write(m_ConfigPath, &Config_Dump);
}

void Config_Sanitize(void)
{
}

void Config_ApplyChanges(void)
{
}

const CONFIG_OPTION *Config_GetOptionMap(void)
{
return g_ConfigOptionMap;
}
5 changes: 5 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <libtrx/config/config_option.h>

#include <stdbool.h>

typedef struct {
Expand All @@ -14,3 +16,6 @@ extern CONFIG g_Config;

bool Config_Read(void);
bool Config_Write(void);
void Config_Sanitize(void);
void Config_ApplyChanges(void);
const CONFIG_OPTION *Config_GetOptionMap(void);
29 changes: 4 additions & 25 deletions src/game/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "global/vars.h"
#include "lara/lara_misc.h"

#include <libtrx/game/console/commands/config.h>
#include <libtrx/game/console/commands/heal.h>
#include <libtrx/game/console/commands/pos.h>
#include <libtrx/game/console/commands/set_health.h>
#include <libtrx/game/console/common.h>
Expand All @@ -32,7 +34,6 @@ static bool Console_Cmd_CanTargetObjectCreature(GAME_OBJECT_ID object_id);
static bool Console_Cmd_CanTargetObjectPickup(GAME_OBJECT_ID object_id);
static bool Console_Cmd_IsFloatRound(float num);
static COMMAND_RESULT Console_Cmd_Teleport(const char *args);
static COMMAND_RESULT Console_Cmd_Heal(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);
Expand Down Expand Up @@ -199,29 +200,6 @@ static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
return CR_BAD_INVOCATION;
}

static COMMAND_RESULT Console_Cmd_Heal(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 (g_LaraItem->hit_points == LARA_MAX_HITPOINTS) {
Console_Log(GS(OSD_HEAL_ALREADY_FULL_HP));
return CR_SUCCESS;
}

g_LaraItem->hit_points = LARA_MAX_HITPOINTS;
Lara_Extinguish();
Console_Log(GS(OSD_HEAL_SUCCESS));
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Fly(const char *const args)
{
if (g_GameInfo.current_level.type == GFL_TITLE
Expand Down Expand Up @@ -561,7 +539,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 = "heal", .proc = Console_Cmd_Heal },
&(CONSOLE_COMMAND) { .prefix = "fly", .proc = Console_Cmd_Fly },
&(CONSOLE_COMMAND) { .prefix = "give", .proc = Console_Cmd_GiveItem },
&(CONSOLE_COMMAND) { .prefix = "gimme", .proc = Console_Cmd_GiveItem },
Expand All @@ -579,7 +556,9 @@ CONSOLE_COMMAND *g_ConsoleCommands[] = {
&(CONSOLE_COMMAND) { .prefix = "abortion", .proc = Console_Cmd_Abortion },
&(CONSOLE_COMMAND) { .prefix = "natlastinks",
.proc = Console_Cmd_Abortion },
&g_Console_Cmd_Config,
&g_Console_Cmd_Pos,
&g_Console_Cmd_Heal,
&g_Console_Cmd_SetHealth,
NULL,
};
2 changes: 0 additions & 2 deletions src/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@ 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_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")
4 changes: 2 additions & 2 deletions src/game/lara/common.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "game/lara/common.h"

#include "global/vars.h"

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

ITEM_INFO *Lara_GetItem(void)
{
return g_LaraItem;
Expand Down
5 changes: 0 additions & 5 deletions src/game/lara/common.h

This file was deleted.

21 changes: 0 additions & 21 deletions src/game/lara/lara_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1802,27 +1802,6 @@ void __cdecl Lara_WaterCurrent(COLL_INFO *const coll)
coll->old = item->pos;
}

void __cdecl Lara_Extinguish(void)
{
if (!g_Lara.burn) {
return;
}

g_Lara.burn = 0;

// put out flame objects
int16_t fx_num = g_NextEffectActive;
while (fx_num != NO_ITEM) {
FX_INFO *const fx = &g_Effects[fx_num];
const int16_t next_fx_num = fx->next_active;
if (fx->object_id == O_FLAME && fx->counter < 0) {
fx->counter = 0;
Effect_Kill(fx_num);
}
fx_num = next_fx_num;
}
}

void __cdecl Lara_CatchFire(void)
{
if (g_Lara.burn || g_Lara.water_status == LWS_CHEAT) {
Expand Down
1 change: 0 additions & 1 deletion src/game/lara/lara_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ void __cdecl Lara_SwimCollision(ITEM_INFO *item, COLL_INFO *coll);

void __cdecl Lara_WaterCurrent(COLL_INFO *coll);

void __cdecl Lara_Extinguish(void);
void __cdecl Lara_CatchFire(void);

void __cdecl Lara_TouchLava(ITEM_INFO *item);
25 changes: 25 additions & 0 deletions src/game/lara/misc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "game/effects.h"
#include "global/vars.h"

#include <libtrx/game/lara/misc.h>

void __cdecl Lara_Extinguish(void)
{
if (!g_Lara.burn) {
return;
}

g_Lara.burn = 0;

// put out flame objects
int16_t fx_num = g_NextEffectActive;
while (fx_num != NO_ITEM) {
FX_INFO *const fx = &g_Effects[fx_num];
const int16_t next_fx_num = fx->next_active;
if (fx->object_id == O_FLAME && fx->counter < 0) {
fx->counter = 0;
Effect_Kill(fx_num);
}
fx_num = next_fx_num;
}
}
3 changes: 2 additions & 1 deletion tools/additional_lint
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
from libtrx.cli.additional_lint import run_script
from tr2x.paths import TR2X_REPO_DIR

run_script()
run_script(root_dir=TR2X_REPO_DIR)
Loading