Basic save support in engine
authorunc0rr
Thu, 29 Jun 2006 18:27:53 +0000
changeset 72 aeb2ac1878dc
parent 71 5f56c6979496
child 73 fe1c62875a19
Basic save support in engine
hedgewars/CCHandlers.inc
hedgewars/hwengine.dpr
hedgewars/uConsts.pas
hedgewars/uGame.pas
hedgewars/uIO.pas
hedgewars/uMisc.pas
hedgewars/uTeams.pas
--- a/hedgewars/CCHandlers.inc	Wed Jun 28 18:27:42 2006 +0000
+++ b/hedgewars/CCHandlers.inc	Thu Jun 29 18:27:53 2006 +0000
@@ -49,7 +49,7 @@
 procedure chAddTeam(var s: shortstring);
 begin
 if isDeveloperMode then AddTeam;
-if GameType = gmtDemo then CurrentTeam.ExtDriven:= true
+if GameType in [gmtDemo, gmtSave] then CurrentTeam.ExtDriven:= true
 end;
 
 procedure chTeamLocal(var s: shortstring);
--- a/hedgewars/hwengine.dpr	Wed Jun 28 18:27:42 2006 +0000
+++ b/hedgewars/hwengine.dpr	Thu Jun 29 18:27:53 2006 +0000
@@ -86,6 +86,11 @@
               ResetKbd;
               SoundLoad;
               PlayMusic;
+              if GameType = gmtSave then
+                 begin
+                 isSEBackup:= isSoundEnabled;
+                 isSoundEnabled:= false
+                 end;
               GameState:= gsGame
               end;
      gsGame : begin
--- a/hedgewars/uConsts.pas	Wed Jun 28 18:27:42 2006 +0000
+++ b/hedgewars/uConsts.pas	Thu Jun 29 18:27:53 2006 +0000
@@ -38,7 +38,7 @@
 type TStuff     = (sHorizont, sSky, sConsoleBG, sPowerBar, sQuestion, sWindBar,
                    sWindL, sWindR, sRopeNode);
      TGameState = (gsLandGen, gsStart, gsGame, gsConsole, gsExit);
-     TGameType  = (gmtLocal, gmtDemo, gmtNet);
+     TGameType  = (gmtLocal, gmtDemo, gmtNet, gmtSave);
      TPathType  = (ptData, ptGraphics, ptThemes, ptThemeCurrent, ptTeams, ptMaps,
                    ptMapCurrent, ptDemos, ptSounds, ptGraves, ptFonts, ptForts);
      TSprite    = (sprWater, sprCloud, sprBomb, sprBigDigit, sprFrame,
--- a/hedgewars/uGame.pas	Wed Jun 28 18:27:42 2006 +0000
+++ b/hedgewars/uGame.pas	Thu Jun 29 18:27:53 2006 +0000
@@ -41,7 +41,7 @@
 ////////////////////
    implementation
 ////////////////////
-uses uMisc, uConsts, uWorld, uKeys, uTeams, uIO, uAI, uGears;
+uses uMisc, uConsts, uWorld, uKeys, uTeams, uIO, uAI, uGears, uConsole;
 
 procedure DoGameTick(Lag: integer);
 const SendEmptyPacketTicks: LongWord = 0;
@@ -63,7 +63,8 @@
    inc(SendEmptyPacketTicks, Lag)
    end;
 
-if Lag > 100 then Lag:= 100;
+if Lag > 100 then Lag:= 100
+else if GameType = gmtSave then Lag:= 1000;
 
 for i:= 1 to Lag do
     if not CurrentTeam.ExtDriven then
@@ -78,10 +79,15 @@
           case GameType of
                gmtNet: break;
                gmtDemo: begin
-                        SendIPC('q');
+                        ParseCommand('/quit');
                         GameState:= gsExit;
                         exit
-                        end
+                        end;
+               gmtSave: begin
+                        RestoreTeamsFromSave;
+                        isSoundEnabled:= isSEBackup;
+                        GameType:= gmtLocal
+                        end;
                end
           else ProcessGears
        end;
--- a/hedgewars/uIO.pas	Wed Jun 28 18:27:42 2006 +0000
+++ b/hedgewars/uIO.pas	Thu Jun 29 18:27:53 2006 +0000
@@ -96,6 +96,7 @@
                'L': GameType:= gmtLocal;
                'D': GameType:= gmtDemo;
                'N': GameType:= gmtNet;
+               'S': GameType:= gmtSave;
                else OutError(errmsgIncorrectUse + ' IPC "T" :' + s[2], true) end;
      else
      inc(cmdendpos);
--- a/hedgewars/uMisc.pas	Wed Jun 28 18:27:42 2006 +0000
+++ b/hedgewars/uMisc.pas	Thu Jun 29 18:27:53 2006 +0000
@@ -39,6 +39,7 @@
     isTerminated    : boolean = false;
     isInLag         : boolean = false;
     isSoundEnabled  : boolean = true;
+    isSEBackup      : boolean = true;
     isInMultiShoot  : boolean = false;
 
     GameState     : TGameState = Low(TGameState);
--- a/hedgewars/uTeams.pas	Wed Jun 28 18:27:42 2006 +0000
+++ b/hedgewars/uTeams.pas	Thu Jun 29 18:27:53 2006 +0000
@@ -79,6 +79,7 @@
 procedure OnUsedAmmo(Ammo: PHHAmmo);
 function  TeamSize(p: PTeam): Longword;
 procedure RecountTeamHealth(team: PTeam);
+procedure RestoreTeamsFromSave;
 
 implementation
 uses uMisc, uStore, uWorld, uIO, uAI;
@@ -311,6 +312,17 @@
 AddGear(0, 0, gtTeamHealthSorter, 0)
 end;
 
+procedure RestoreTeamsFromSave;
+var p: PTeam;
+begin
+p:= TeamsList;
+while p <> nil do
+      begin
+      p.ExtDriven:= false;
+      p:= p.Next
+      end;
+end;
+
 initialization
 
 finalization