This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
console/cmd: follow libtrx folder structure
- Loading branch information
Showing
38 changed files
with
716 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "game/console/cmd/die.h" | ||
|
||
#include "decomp/effects.h" | ||
#include "game/sound.h" | ||
#include "global/vars.h" | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *args); | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *const args) | ||
{ | ||
if (!g_Objects[O_LARA].loaded) { | ||
return CR_UNAVAILABLE; | ||
} | ||
|
||
if (g_LaraItem->hit_points <= 0) { | ||
return CR_UNAVAILABLE; | ||
} | ||
|
||
Sound_Effect(SFX_LARA_FALL, &g_LaraItem->pos, SPM_NORMAL); | ||
Effect_ExplodingDeath(g_Lara.item_num, -1, 1); | ||
|
||
g_LaraItem->hit_points = 0; | ||
g_LaraItem->flags |= IF_INVISIBLE; | ||
return CR_SUCCESS; | ||
} | ||
|
||
CONSOLE_COMMAND g_Console_Cmd_Die = { | ||
.prefix = "abortion|natlastinks", | ||
.proc = M_Entrypoint, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "game/console/cmd/end_level.h" | ||
|
||
#include "game/lara/lara_cheat.h" | ||
|
||
#include <string.h> | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *args); | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *const args) | ||
{ | ||
if (strcmp(args, "") == 0) { | ||
Lara_Cheat_EndLevel(); | ||
return CR_SUCCESS; | ||
} | ||
return CR_FAILURE; | ||
} | ||
|
||
CONSOLE_COMMAND g_Console_Cmd_EndLevel = { | ||
.prefix = "endlevel", | ||
.proc = M_Entrypoint, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#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 *const args) | ||
{ | ||
g_GF_OverrideDir = GFD_EXIT_GAME; | ||
return CR_SUCCESS; | ||
} | ||
|
||
CONSOLE_COMMAND g_Console_Cmd_ExitGame = { | ||
.prefix = "exit", | ||
.proc = M_Entrypoint, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#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 *const args) | ||
{ | ||
g_GF_OverrideDir = GFD_EXIT_TO_TITLE; | ||
return CR_SUCCESS; | ||
} | ||
|
||
CONSOLE_COMMAND g_Console_Cmd_ExitToTitle = { | ||
.prefix = "title", | ||
.proc = M_Entrypoint, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "game/console/cmd/flipmap.h" | ||
|
||
#include "game/game_string.h" | ||
#include "game/gameflow/gameflow_new.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 *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; | ||
} | ||
|
||
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "game/console/cmd/fly.h" | ||
|
||
#include "game/game.h" | ||
#include "game/lara/lara_cheat.h" | ||
#include "global/vars.h" | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *args); | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *const args) | ||
{ | ||
if (!Game_IsPlayable()) { | ||
return CR_UNAVAILABLE; | ||
} | ||
Lara_Cheat_EnterFlyMode(); | ||
return CR_SUCCESS; | ||
} | ||
|
||
CONSOLE_COMMAND g_Console_Cmd_Fly = { | ||
.prefix = "fly", | ||
.proc = M_Entrypoint, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include "game/console/cmd/kill.h" | ||
|
||
#include "game/creature.h" | ||
#include "game/game_string.h" | ||
#include "game/items.h" | ||
#include "game/lara/lara_cheat.h" | ||
#include "game/lara/lara_control.h" | ||
#include "game/objects/names.h" | ||
#include "game/objects/vars.h" | ||
#include "global/vars.h" | ||
|
||
#include <libtrx/game/objects/common.h> | ||
#include <libtrx/game/objects/ids.h> | ||
#include <libtrx/memory.h> | ||
#include <libtrx/strings.h> | ||
|
||
static bool M_CanTargetObjectCreature(GAME_OBJECT_ID object_id); | ||
static COMMAND_RESULT M_Entrypoint(const char *args); | ||
|
||
static bool M_CanTargetObjectCreature(const GAME_OBJECT_ID object_id) | ||
{ | ||
return Object_IsObjectType(object_id, g_EnemyObjects) | ||
|| Object_IsObjectType(object_id, g_FriendObjects); | ||
} | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *const args) | ||
{ | ||
// kill all the enemies in the level | ||
if (String_Equivalent(args, "all")) { | ||
int32_t num_killed = 0; | ||
for (int16_t item_num = 0; item_num < Item_GetTotalCount(); | ||
item_num++) { | ||
const ITEM_INFO *const item = &g_Items[item_num]; | ||
if (!Creature_IsEnemy(item)) { | ||
continue; | ||
} | ||
if (Lara_Cheat_KillEnemy(item_num)) { | ||
num_killed++; | ||
} | ||
} | ||
|
||
if (num_killed == 0) { | ||
Console_Log(GS(OSD_KILL_ALL_FAIL)); | ||
return CR_FAILURE; | ||
} | ||
|
||
Console_Log(GS(OSD_KILL_ALL), num_killed); | ||
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; | ||
} | ||
|
||
const 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 | ||
{ | ||
bool matches_found = false; | ||
int32_t num_killed = 0; | ||
int32_t match_count = 0; | ||
GAME_OBJECT_ID *matching_objs = | ||
Object_IdsFromName(args, &match_count, M_CanTargetObjectCreature); | ||
|
||
for (int16_t item_num = 0; item_num < Item_GetTotalCount(); | ||
item_num++) { | ||
const ITEM_INFO *const item = &g_Items[item_num]; | ||
|
||
bool is_matched = false; | ||
for (int32_t i = 0; i < match_count; i++) { | ||
if (matching_objs[i] == item->object_id) { | ||
is_matched = true; | ||
break; | ||
} | ||
} | ||
if (!is_matched) { | ||
continue; | ||
} | ||
matches_found = true; | ||
|
||
if (Lara_Cheat_KillEnemy(item_num)) { | ||
num_killed++; | ||
} | ||
} | ||
Memory_FreePointer(&matching_objs); | ||
|
||
if (!matches_found) { | ||
Console_Log(GS(OSD_INVALID_OBJECT), args); | ||
return CR_FAILURE; | ||
} | ||
if (num_killed == 0) { | ||
Console_Log(GS(OSD_OBJECT_NOT_FOUND), args); | ||
return CR_FAILURE; | ||
} | ||
Console_Log(GS(OSD_KILL_ALL), num_killed); | ||
return CR_SUCCESS; | ||
} | ||
} | ||
|
||
CONSOLE_COMMAND g_Console_Cmd_Kill = { | ||
.prefix = "kill", | ||
.proc = M_Entrypoint, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_Kill; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "game/console/cmd/load_game.h" | ||
|
||
#include "game/game_string.h" | ||
#include "global/vars.h" | ||
|
||
#include <libtrx/strings.h> | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *args); | ||
|
||
static COMMAND_RESULT M_Entrypoint(const char *const args) | ||
{ | ||
int32_t slot_num; | ||
if (!String_ParseInteger(args, &slot_num)) { | ||
return CR_BAD_INVOCATION; | ||
} | ||
|
||
// convert 1-indexing to 0-indexing | ||
const int32_t slot_idx = slot_num - 1; | ||
|
||
if (slot_idx < 0 || slot_idx >= MAX_SAVE_SLOTS) { | ||
Console_Log(GS(OSD_INVALID_SAVE_SLOT), slot_num); | ||
return CR_FAILURE; | ||
} | ||
|
||
// TODO: replace this with a proper status check | ||
if (g_SavedLevels[slot_idx] <= 0) { | ||
Console_Log(GS(OSD_LOAD_GAME_FAIL_UNAVAILABLE_SLOT), slot_num); | ||
return CR_FAILURE; | ||
} | ||
|
||
g_GF_OverrideDir = GFD_START_SAVED_GAME | slot_idx; | ||
Console_Log(GS(OSD_LOAD_GAME), slot_num); | ||
return CR_SUCCESS; | ||
} | ||
|
||
CONSOLE_COMMAND g_Console_Cmd_LoadGame = { | ||
.prefix = "load", | ||
.proc = M_Entrypoint, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_LoadGame; |
Oops, something went wrong.