index a7477581a189541fd1de6a9ea8f0530f44d99ef8..003c58b4df7f5be2923be888ebe0bdb3881ded3f 100644 (file)
--- a/src/game/g_saveload.pas
+++ b/src/game/g_saveload.pas
interface
uses
interface
uses
- SysUtils, Classes,
- e_graphics, g_phys, g_textures;
+ SysUtils, Classes, g_phys, g_textures;
function g_GetSaveName (n: Integer; out valid: Boolean): AnsiString;
function g_GetSaveName (n: Integer; out valid: Boolean): AnsiString;
uses
MAPDEF, utils, xstreams,
g_game, g_items, g_map, g_monsters, g_triggers,
uses
MAPDEF, utils, xstreams,
g_game, g_items, g_map, g_monsters, g_triggers,
- g_basic, g_main, Math, wadreader,
+ g_basic, Math, wadreader,
g_weapons, g_player, g_console,
g_weapons, g_player, g_console,
- e_log, g_language;
+ e_log, e_res, g_language, g_options;
const
SAVE_SIGNATURE = $56534644; // 'DFSV'
const
SAVE_SIGNATURE = $56534644; // 'DFSV'
function buildSaveName (n: Integer): AnsiString;
begin
function buildSaveName (n: Integer): AnsiString;
begin
- result := '';
- if (n < 0) or (n > 65535) then exit;
- result := formatstrf('%sSAVGAME%s.DAT', [DataDir, n]);
+ result := 'SAVGAME' + IntToStr(n) + '.DAT'
end;
end;
try
// Îòêðûâàåì ôàéë ñîõðàíåíèé
filename := buildSaveName(n);
try
// Îòêðûâàåì ôàéë ñîõðàíåíèé
filename := buildSaveName(n);
- st := openDiskFileRO(filename);
+ st := e_OpenResourceRO(SaveDirs, filename);
try
if not utils.checkSign(st, 'DFSV') then
begin
try
if not utils.checkSign(st, 'DFSV') then
begin
begin
result := false;
try
begin
result := false;
try
- st := createDiskFile(filename);
+ st := e_CreateResource(SaveDirs, filename);
try
utils.writeSign(st, 'DFSV');
utils.writeInt(st, Byte(SAVE_VERSION));
try
utils.writeSign(st, 'DFSV');
utils.writeInt(st, Byte(SAVE_VERSION));
//if (Length(gCurrentMapFileName) <> 0) then e_LogWritefln('SAVE: current map is ''%s''...', [gCurrentMapFileName]);
utils.writeStr(st, gCurrentMapFileName);
// Ïóòü ê êàðòå
//if (Length(gCurrentMapFileName) <> 0) then e_LogWritefln('SAVE: current map is ''%s''...', [gCurrentMapFileName]);
utils.writeStr(st, gCurrentMapFileName);
// Ïóòü ê êàðòå
- utils.writeStr(st, gGameSettings.WAD);
+ utils.writeStr(st, ExtractFileName(gGameSettings.WAD));
// Èìÿ êàðòû
utils.writeStr(st, g_ExtractFileName(gMapInfo.Map));
// Êîëè÷åñòâî èãðîêîâ
// Èìÿ êàðòû
utils.writeStr(st, g_ExtractFileName(gMapInfo.Map));
// Êîëè÷åñòâî èãðîêîâ
// Ëèìèò âðåìåíè
utils.writeInt(st, Word(gGameSettings.TimeLimit));
// Ëèìèò î÷êîâ
// Ëèìèò âðåìåíè
utils.writeInt(st, Word(gGameSettings.TimeLimit));
// Ëèìèò î÷êîâ
- utils.writeInt(st, Word(gGameSettings.GoalLimit));
+ utils.writeInt(st, Word(gGameSettings.ScoreLimit));
// Ëèìèò æèçíåé
utils.writeInt(st, Byte(gGameSettings.MaxLives));
// Èãðîâûå îïöèè
// Ëèìèò æèçíåé
utils.writeInt(st, Byte(gGameSettings.MaxLives));
// Èãðîâûå îïöèè
e_WriteLog('SaveState Error: '+e.message, TMsgType.Warning);
if deleteOnError then DeleteFile(filename);
{$IF DEFINED(D2F_DEBUG)}e_WriteStackTrace(e.message);{$ENDIF}
e_WriteLog('SaveState Error: '+e.message, TMsgType.Warning);
if deleteOnError then DeleteFile(filename);
{$IF DEFINED(D2F_DEBUG)}e_WriteStackTrace(e.message);{$ENDIF}
+e_WriteStackTrace(e.message);
result := false;
end;
end;
result := false;
end;
end;
WAD_Path, Map_Name: AnsiString;
nPlayers: Integer;
Game_Type, Game_Mode, Game_MaxLives: Byte;
WAD_Path, Map_Name: AnsiString;
nPlayers: Integer;
Game_Type, Game_Mode, Game_MaxLives: Byte;
- Game_TimeLimit, Game_GoalLimit: Word;
+ Game_TimeLimit, Game_ScoreLimit: Word;
Game_Time, Game_Options: Cardinal;
Game_CoopMonstersKilled,
Game_CoopSecretsFound,
Game_Time, Game_Options: Cardinal;
Game_CoopMonstersKilled,
Game_CoopSecretsFound,
result := false;
try
result := false;
try
- st := openDiskFileRO(filename);
+ st := e_OpenResourceRO(SaveDirs, filename);
try
if not utils.checkSign(st, 'DFSV') then raise XStreamError.Create('invalid save game signature');
if (utils.readByte(st) <> SAVE_VERSION) then raise XStreamError.Create('invalid save game version');
e_WriteLog('Loading saved game...', TMsgType.Notify);
try
if not utils.checkSign(st, 'DFSV') then raise XStreamError.Create('invalid save game signature');
if (utils.readByte(st) <> SAVE_VERSION) then raise XStreamError.Create('invalid save game version');
e_WriteLog('Loading saved game...', TMsgType.Notify);
- {$IF DEFINED(D2F_DEBUG)}try{$ENDIF}
+{$IF DEFINED(D2F_DEBUG)}
+ try
+{$ENDIF}
//g_Game_Free(false); // don't free textures for the same map
g_Game_ClearLoading();
g_Game_SetLoadingText(_lc[I_LOAD_SAVE_FILE], 0, False);
//g_Game_Free(false); // don't free textures for the same map
g_Game_ClearLoading();
g_Game_SetLoadingText(_lc[I_LOAD_SAVE_FILE], 0, False);
// Ëèìèò âðåìåíè
Game_TimeLimit := utils.readWord(st);
// Ëèìèò î÷êîâ
// Ëèìèò âðåìåíè
Game_TimeLimit := utils.readWord(st);
// Ëèìèò î÷êîâ
- Game_GoalLimit := utils.readWord(st);
+ Game_ScoreLimit := utils.readWord(st);
// Ëèìèò æèçíåé
Game_MaxLives := utils.readByte(st);
// Èãðîâûå îïöèè
// Ëèìèò æèçíåé
Game_MaxLives := utils.readByte(st);
// Èãðîâûå îïöèè
gGameSettings.GameMode := Game_Mode;
gSwitchGameMode := Game_Mode;
gGameSettings.TimeLimit := Game_TimeLimit;
gGameSettings.GameMode := Game_Mode;
gSwitchGameMode := Game_Mode;
gGameSettings.TimeLimit := Game_TimeLimit;
- gGameSettings.GoalLimit := Game_GoalLimit;
+ gGameSettings.ScoreLimit := Game_ScoreLimit;
gGameSettings.MaxLives := IfThen(Game_Mode = GM_CTF, 0, Game_MaxLives);
gGameSettings.Options := Game_Options;
end;
g_Game_ExecuteEvent('ongamestart');
gGameSettings.MaxLives := IfThen(Game_Mode = GM_CTF, 0, Game_MaxLives);
gGameSettings.Options := Game_Options;
end;
g_Game_ExecuteEvent('ongamestart');
- // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ
- g_Game_SetupScreenSize();
-
// Çàãðóçêà è çàïóñê êàðòû
// Çàãðóçêà è çàïóñê êàðòû
- if not g_Game_StartMap(WAD_Path+':\'+Map_Name, True, curmapfile) then
- begin
- g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WAD_Path + ':\' + Map_Name]));
- exit;
- end;
+ //FIXME: save/load `asMegawad`
+ if not g_Game_StartMap(false{asMegawad}, WAD_Path+':\'+Map_Name, True, curmapfile) then
+ raise Exception.Create(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WAD_Path + ':\' + Map_Name]));
// Íàñòðîéêè èãðîêîâ è áîòîâ
g_Player_Init();
// Íàñòðîéêè èãðîêîâ è áîòîâ
g_Player_Init();
// done
gLoadGameMode := false;
result := true;
// done
gLoadGameMode := false;
result := true;
- {$IF DEFINED(D2F_DEBUG)}
+{$IF DEFINED(D2F_DEBUG)}
except
begin
errpos := LongWord(st.position);
raise;
end;
end;
except
begin
errpos := LongWord(st.position);
raise;
end;
end;
- {$ENDIF}
+{$ENDIF}
finally
st.Free();
end;
finally
st.Free();
end;
function g_SaveGame (n: Integer; const aname: AnsiString): Boolean;
begin
function g_SaveGame (n: Integer; const aname: AnsiString): Boolean;
begin
- result := false;
- if (n < 0) or (n > 65535) then exit;
result := g_SaveGameTo(buildSaveName(n), aname, true);
end;
function g_LoadGame (n: Integer): Boolean;
begin
result := g_SaveGameTo(buildSaveName(n), aname, true);
end;
function g_LoadGame (n: Integer): Boolean;
begin
- result := false;
- if (n < 0) or (n > 65535) then exit;
result := g_LoadGameFrom(buildSaveName(n));
end;
result := g_LoadGameFrom(buildSaveName(n));
end;