mirror of
https://github.com/LostArtefacts/TR2X.git
synced 2024-11-23 13:59:45 +00:00
console/cmd: move /save and /load to libtrx
This commit is contained in:
parent
0eced943bb
commit
b0afdcd851
@ -387,6 +387,7 @@
|
||||
"OSD_KILL_ALL_FAIL": "Uh-oh, there are no enemies left to kill...",
|
||||
"OSD_KILL_FAIL": "No enemy nearby...",
|
||||
"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_PLAY_LEVEL": "Loading %s",
|
||||
@ -399,6 +400,7 @@
|
||||
"OSD_POS_SET_ROOM_FAIL": "Failed to teleport to room: %d",
|
||||
"OSD_SAVE_GAME": "Saved game to save slot %d",
|
||||
"OSD_SAVE_GAME_FAIL": "Cannot save the game in the current state",
|
||||
"OSD_SAVE_GAME_FAIL_INVALID_SLOT": "Invalid save slot %d",
|
||||
"OSD_SOUND_AVAILABLE_SAMPLES": "Available sounds: %s",
|
||||
"OSD_SOUND_PLAYING_SAMPLE": "Playing sound %d",
|
||||
"OSD_UNKNOWN_COMMAND": "Unknown command: %s",
|
||||
|
@ -92,8 +92,6 @@ dll_sources = [
|
||||
'src/game/clock.c',
|
||||
'src/game/collide.c',
|
||||
'src/game/console/cmd/flipmap.c',
|
||||
'src/game/console/cmd/load_game.c',
|
||||
'src/game/console/cmd/save_game.c',
|
||||
'src/game/console/common.c',
|
||||
'src/game/console/setup.c',
|
||||
'src/game/creature.c',
|
||||
@ -156,6 +154,7 @@ dll_sources = [
|
||||
'src/game/requester.c',
|
||||
'src/game/room.c',
|
||||
'src/game/room_draw.c',
|
||||
'src/game/savegame/common.c',
|
||||
'src/game/shell.c',
|
||||
'src/game/sound.c',
|
||||
'src/game/text.c',
|
||||
|
@ -1,39 +0,0 @@
|
||||
#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 COMMAND_CONTEXT *ctx);
|
||||
|
||||
static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *const ctx)
|
||||
{
|
||||
int32_t slot_num;
|
||||
if (!String_ParseInteger(ctx->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,
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <libtrx/game/console/common.h>
|
||||
|
||||
extern CONSOLE_COMMAND g_Console_Cmd_LoadGame;
|
@ -1,48 +0,0 @@
|
||||
#include "game/console/cmd/save_game.h"
|
||||
|
||||
#include "decomp/decomp.h"
|
||||
#include "game/game_string.h"
|
||||
#include "game/gameflow/gameflow_new.h"
|
||||
#include "global/funcs.h"
|
||||
#include "global/vars.h"
|
||||
|
||||
#include <libtrx/strings.h>
|
||||
|
||||
static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *ctx);
|
||||
|
||||
static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *const ctx)
|
||||
{
|
||||
int32_t slot_num;
|
||||
if (!String_ParseInteger(ctx->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_BAD_INVOCATION;
|
||||
}
|
||||
|
||||
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_LaraItem == NULL || g_LaraItem->hit_points <= 0) {
|
||||
return CR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
CreateSaveGameInfo();
|
||||
S_SaveGame(&g_SaveGame, sizeof(SAVEGAME_INFO), slot_idx);
|
||||
GetSavedGamesList(&g_LoadGameRequester);
|
||||
Console_Log(GS(OSD_SAVE_GAME), slot_num);
|
||||
return CR_SUCCESS;
|
||||
}
|
||||
|
||||
CONSOLE_COMMAND g_Console_Cmd_SaveGame = {
|
||||
.prefix = "save",
|
||||
.proc = M_Entrypoint,
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <libtrx/game/console/common.h>
|
||||
|
||||
extern CONSOLE_COMMAND g_Console_Cmd_SaveGame;
|
@ -1,8 +1,6 @@
|
||||
#include "game/console/setup.h"
|
||||
|
||||
#include "game/console/cmd/flipmap.h"
|
||||
#include "game/console/cmd/load_game.h"
|
||||
#include "game/console/cmd/save_game.h"
|
||||
|
||||
#include <libtrx/game/console/cmd/config.h>
|
||||
#include <libtrx/game/console/cmd/die.h>
|
||||
@ -13,9 +11,11 @@
|
||||
#include <libtrx/game/console/cmd/give_item.h>
|
||||
#include <libtrx/game/console/cmd/heal.h>
|
||||
#include <libtrx/game/console/cmd/kill.h>
|
||||
#include <libtrx/game/console/cmd/load_game.h>
|
||||
#include <libtrx/game/console/cmd/play_demo.h>
|
||||
#include <libtrx/game/console/cmd/play_level.h>
|
||||
#include <libtrx/game/console/cmd/pos.h>
|
||||
#include <libtrx/game/console/cmd/save_game.h>
|
||||
#include <libtrx/game/console/cmd/set_health.h>
|
||||
#include <libtrx/game/console/cmd/sfx.h>
|
||||
#include <libtrx/game/console/cmd/teleport.h>
|
||||
|
23
src/game/savegame/common.c
Normal file
23
src/game/savegame/common.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include "global/funcs.h"
|
||||
#include "global/vars.h"
|
||||
|
||||
#include <libtrx/game/savegame.h>
|
||||
#include <libtrx/log.h>
|
||||
|
||||
int32_t Savegame_GetSlotCount(void)
|
||||
{
|
||||
return MAX_SAVE_SLOTS;
|
||||
}
|
||||
|
||||
bool Savegame_IsSlotFree(const int32_t slot_idx)
|
||||
{
|
||||
return g_SavedLevels[slot_idx] == 0;
|
||||
}
|
||||
|
||||
bool Savegame_Save(const int32_t slot_idx)
|
||||
{
|
||||
CreateSaveGameInfo();
|
||||
S_SaveGame(&g_SaveGame, sizeof(SAVEGAME_INFO), slot_idx);
|
||||
GetSavedGamesList(&g_LoadGameRequester);
|
||||
return true;
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit 02ec3a8e2d55307d4996a762a350140ccbc0b68a
|
||||
Subproject commit e770eacfb36bb671b637f8855e7a019fc048d8ea
|
Loading…
Reference in New Issue
Block a user