From: Ketmar Dark Date: Sat, 2 Sep 2017 00:39:31 +0000 (+0300) Subject: saving all panels to savegame, 'cause why not X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=91adc12c8717ef13ca9e86ed040a42c3c0d73ca7;p=d2df-sdl.git saving all panels to savegame, 'cause why not --- diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 642beaa..577891f 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -3028,255 +3028,210 @@ begin end; end; -procedure g_Map_SaveState(Var Mem: TBinMemoryWriter); + +procedure g_Map_SaveState (var Mem: TBinMemoryWriter); var dw: DWORD; b: Byte; str: String; boo: Boolean; - procedure SavePanelArray(var panels: TPanelArray); + procedure savePanels (); var PAMem: TBinMemoryWriter; - i: Integer; + pan: TPanel; begin - // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé: - PAMem := TBinMemoryWriter.Create((Length(panels)+1) * 40); + // Ñîçäàåì íîâûé ñïèñîê ñîõðàíÿåìûõ ïàíåëåé + PAMem := TBinMemoryWriter.Create((Length(panByGUID)+1) * 40); - i := 0; - while i < Length(panels) do + for pan in panByGUID do begin - if true{panels[i].SaveIt} then + if true{pan.SaveIt} then begin - // ID ïàíåëè: - PAMem.WriteInt(i); - // Ñîõðàíÿåì ïàíåëü: - panels[i].SaveState(PAMem); + // ID ïàíåëè + //PAMem.WriteInt(i); + // Ñîõðàíÿåì ïàíåëü + pan.SaveState(PAMem); end; - Inc(i); end; - // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé: + // Ñîõðàíÿåì ýòîò ñïèñîê ïàíåëåé PAMem.SaveToMemory(Mem); PAMem.Free(); end; - procedure SaveFlag(flag: PFlag); + procedure SaveFlag (flag: PFlag); begin - // Ñèãíàòóðà ôëàãà: + // Ñèãíàòóðà ôëàãà dw := FLAG_SIGNATURE; // 'FLAG' Mem.WriteDWORD(dw); - // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà: + // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà Mem.WriteByte(flag^.RespawnType); - // Ñîñòîÿíèå ôëàãà: + // Ñîñòîÿíèå ôëàãà Mem.WriteByte(flag^.State); - // Íàïðàâëåíèå ôëàãà: - if flag^.Direction = D_LEFT then - b := 1 - else // D_RIGHT - b := 2; + // Íàïðàâëåíèå ôëàãà + if flag^.Direction = D_LEFT then b := 1 else b := 2; // D_RIGHT Mem.WriteByte(b); - // Îáúåêò ôëàãà: + // Îáúåêò ôëàãà Obj_SaveState(@flag^.Obj, Mem); end; begin Mem := TBinMemoryWriter.Create(1024 * 1024); // 1 MB -///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: ///// -// Ñîõðàíÿåì ïàíåëè ñòåí è äâåðåé: - SavePanelArray(gWalls); -// Ñîõðàíÿåì ïàíåëè ôîíà: - SavePanelArray(gRenderBackgrounds); -// Ñîõðàíÿåì ïàíåëè ïåðåäíåãî ïëàíà: - SavePanelArray(gRenderForegrounds); -// Ñîõðàíÿåì ïàíåëè âîäû: - SavePanelArray(gWater); -// Ñîõðàíÿåì ïàíåëè êèñëîòû-1: - SavePanelArray(gAcid1); -// Ñîõðàíÿåì ïàíåëè êèñëîòû-2: - SavePanelArray(gAcid2); -// Ñîõðàíÿåì ïàíåëè ñòóïåíåé: - SavePanelArray(gSteps); -// Ñîõðàíÿåì ïàíåëè ëèôòîâ: - SavePanelArray(gLifts); -///// ///// - -///// Ñîõðàíÿåì ìóçûêó: ///// -// Ñèãíàòóðà ìóçûêè: + ///// Ñîõðàíÿåì ñïèñêè ïàíåëåé: ///// + savePanels(); + ///// ///// + + ///// Ñîõðàíÿåì ìóçûêó: ///// + // Ñèãíàòóðà ìóçûêè: dw := MUSIC_SIGNATURE; // 'MUSI' Mem.WriteDWORD(dw); -// Íàçâàíèå ìóçûêè: + // Íàçâàíèå ìóçûêè: Assert(gMusic <> nil, 'g_Map_SaveState: gMusic = nil'); - if gMusic.NoMusic then - str := '' - else - str := gMusic.Name; + if gMusic.NoMusic then str := '' else str := gMusic.Name; Mem.WriteString(str, 64); -// Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè: + // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè dw := gMusic.GetPosition(); Mem.WriteDWORD(dw); -// Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå: + // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå boo := gMusic.SpecPause; Mem.WriteBoolean(boo); -///// ///// + ///// ///// -///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: ///// + ///// Ñîõðàíÿåì êîëè÷åñòâî ìîíñòðîâ: ///// Mem.WriteInt(gTotalMonsters); -///// ///// + ///// ///// -//// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: ///// + //// Ñîõðàíÿåì ôëàãè, åñëè ýòî CTF: ///// if gGameSettings.GameMode = GM_CTF then begin - // Ôëàã Êðàñíîé êîìàíäû: + // Ôëàã Êðàñíîé êîìàíäû SaveFlag(@gFlags[FLAG_RED]); - // Ôëàã Ñèíåé êîìàíäû: + // Ôëàã Ñèíåé êîìàíäû SaveFlag(@gFlags[FLAG_BLUE]); end; -///// ///// + ///// ///// -///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: ///// + ///// Ñîõðàíÿåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: ///// if gGameSettings.GameMode in [GM_TDM, GM_CTF] then begin - // Î÷êè Êðàñíîé êîìàíäû: + // Î÷êè Êðàñíîé êîìàíäû Mem.WriteSmallInt(gTeamStat[TEAM_RED].Goals); - // Î÷êè Ñèíåé êîìàíäû: + // Î÷êè Ñèíåé êîìàíäû Mem.WriteSmallInt(gTeamStat[TEAM_BLUE].Goals); end; -///// ///// + ///// ///// end; -procedure g_Map_LoadState(Var Mem: TBinMemoryReader); + +procedure g_Map_LoadState (var Mem: TBinMemoryReader); var dw: DWORD; b: Byte; str: String; boo: Boolean; - procedure LoadPanelArray(var panels: TPanelArray); + procedure loadPanels (); var PAMem: TBinMemoryReader; - i, id: Integer; + pan: TPanel; begin - // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé: + // Çàãðóæàåì òåêóùèé ñïèñîê ïàíåëåé PAMem := TBinMemoryReader.Create(); PAMem.LoadFromMemory(Mem); - for i := 0 to Length(panels)-1 do + for pan in panByGUID do begin - if true{panels[i].SaveIt} then + if true{pan.SaveIt} then begin - // ID ïàíåëè: - PAMem.ReadInt(id); - if id <> i then - begin - raise EBinSizeError.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID'); - end; - // Çàãðóæàåì ïàíåëü: - panels[i].LoadState(PAMem); - if (panels[i].arrIdx <> i) then raise Exception.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx'); - if (panels[i].proxyId >= 0) then mapGrid.proxyEnabled[panels[i].proxyId] := panels[i].Enabled; + // ID ïàíåëè: + //PAMem.ReadInt(id); + { + if id <> i then raise EBinSizeError.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel ID'); + } + // Çàãðóæàåì ïàíåëü + pan.LoadState(PAMem); + //if (panels[i].arrIdx <> i) then raise Exception.Create('g_Map_LoadState: LoadPanelArray: Wrong Panel arrIdx'); + if (pan.proxyId >= 0) then mapGrid.proxyEnabled[pan.proxyId] := pan.Enabled; end; end; - // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí: + // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí PAMem.Free(); end; procedure LoadFlag(flag: PFlag); begin - // Ñèãíàòóðà ôëàãà: + // Ñèãíàòóðà ôëàãà Mem.ReadDWORD(dw); - if dw <> FLAG_SIGNATURE then // 'FLAG' - begin - raise EBinSizeError.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature'); - end; - // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà: + // 'FLAG' + if dw <> FLAG_SIGNATURE then raise EBinSizeError.Create('g_Map_LoadState: LoadFlag: Wrong Flag Signature'); + // Âðåìÿ ïåðåïîÿâëåíèÿ ôëàãà Mem.ReadByte(flag^.RespawnType); - // Ñîñòîÿíèå ôëàãà: + // Ñîñòîÿíèå ôëàãà Mem.ReadByte(flag^.State); - // Íàïðàâëåíèå ôëàãà: + // Íàïðàâëåíèå ôëàãà Mem.ReadByte(b); - if b = 1 then - flag^.Direction := D_LEFT - else // b = 2 - flag^.Direction := D_RIGHT; - // Îáúåêò ôëàãà: + if b = 1 then flag^.Direction := D_LEFT else flag^.Direction := D_RIGHT; // b = 2 + // Îáúåêò ôëàãà Obj_LoadState(@flag^.Obj, Mem); end; begin - if Mem = nil then - Exit; + if Mem = nil then Exit; + + ///// Çàãðóæàåì ñïèñêè ïàíåëåé: ///// + loadPanels(); + ///// ///// -///// Çàãðóæàåì ñïèñêè ïàíåëåé: ///// -// Çàãðóæàåì ïàíåëè ñòåí è äâåðåé: - LoadPanelArray(gWalls); -// Çàãðóæàåì ïàíåëè ôîíà: - LoadPanelArray(gRenderBackgrounds); -// Çàãðóæàåì ïàíåëè ïåðåäíåãî ïëàíà: - LoadPanelArray(gRenderForegrounds); -// Çàãðóæàåì ïàíåëè âîäû: - LoadPanelArray(gWater); -// Çàãðóæàåì ïàíåëè êèñëîòû-1: - LoadPanelArray(gAcid1); -// Çàãðóæàåì ïàíåëè êèñëîòû-2: - LoadPanelArray(gAcid2); -// Çàãðóæàåì ïàíåëè ñòóïåíåé: - LoadPanelArray(gSteps); -// Çàãðóæàåì ïàíåëè ëèôòîâ: - LoadPanelArray(gLifts); -///// ///// - -// Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó: + // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó g_GFX_Init(); //mapCreateGrid(); -///// Çàãðóæàåì ìóçûêó: ///// -// Ñèãíàòóðà ìóçûêè: + ///// Çàãðóæàåì ìóçûêó: ///// + // Ñèãíàòóðà ìóçûêè Mem.ReadDWORD(dw); - if dw <> MUSIC_SIGNATURE then // 'MUSI' - begin - raise EBinSizeError.Create('g_Map_LoadState: Wrong Music Signature'); - end; -// Íàçâàíèå ìóçûêè: + // 'MUSI' + if dw <> MUSIC_SIGNATURE then raise EBinSizeError.Create('g_Map_LoadState: Wrong Music Signature'); + // Íàçâàíèå ìóçûêè Assert(gMusic <> nil, 'g_Map_LoadState: gMusic = nil'); Mem.ReadString(str); -// Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè: + // Ïîçèöèÿ ïðîèãðûâàíèÿ ìóçûêè Mem.ReadDWORD(dw); -// Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå: + // Ñòîèò ëè ìóçûêà íà ñïåö-ïàóçå Mem.ReadBoolean(boo); -// Çàïóñêàåì ýòó ìóçûêó: + // Çàïóñêàåì ýòó ìóçûêó gMusic.SetByName(str); gMusic.SpecPause := boo; gMusic.Play(); gMusic.Pause(True); gMusic.SetPosition(dw); -///// ///// + ///// ///// -///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: ///// + ///// Çàãðóæàåì êîëè÷åñòâî ìîíñòðîâ: ///// Mem.ReadInt(gTotalMonsters); -///// ///// + ///// ///// -//// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: ///// + //// Çàãðóæàåì ôëàãè, åñëè ýòî CTF: ///// if gGameSettings.GameMode = GM_CTF then begin - // Ôëàã Êðàñíîé êîìàíäû: + // Ôëàã Êðàñíîé êîìàíäû LoadFlag(@gFlags[FLAG_RED]); - // Ôëàã Ñèíåé êîìàíäû: + // Ôëàã Ñèíåé êîìàíäû LoadFlag(@gFlags[FLAG_BLUE]); end; -///// ///// + ///// ///// -///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: ///// + ///// Çàãðóæàåì êîëè÷åñòâî ïîáåä, åñëè ýòî TDM/CTF: ///// if gGameSettings.GameMode in [GM_TDM, GM_CTF] then begin - // Î÷êè Êðàñíîé êîìàíäû: + // Î÷êè Êðàñíîé êîìàíäû Mem.ReadSmallInt(gTeamStat[TEAM_RED].Goals); - // Î÷êè Ñèíåé êîìàíäû: + // Î÷êè Ñèíåé êîìàíäû Mem.ReadSmallInt(gTeamStat[TEAM_BLUE].Goals); end; -///// ///// + ///// ///// end; diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index 7e6a135..6bf2c23 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -785,7 +785,7 @@ begin Mem.ReadBoolean(mMovingActive); positionChanged(); - mapGrid.proxyEnabled[proxyId] := FEnabled; + //mapGrid.proxyEnabled[proxyId] := FEnabled; // done in g_map.pas end; end.