move onNewTurn, onGameTick and onGameTick20 to try and avoid ParseCommand breakage after nextturn call. Needs testing, but should be safe for most scripts. Also fix locale loading.
authornemo
Tue, 01 Jan 2013 14:21:51 -0500
changeset 8349 a1dbe148f10f
parent 8348 c039ac6f33e0
child 8351 f895be37b607
move onNewTurn, onGameTick and onGameTick20 to try and avoid ParseCommand breakage after nextturn call. Needs testing, but should be safe for most scripts. Also fix locale loading.
hedgewars/uGears.pas
hedgewars/uTeams.pas
share/hedgewars/Data/Maps/Basketball/map.lua
share/hedgewars/Data/Maps/CTF_Blizzard/map.lua
share/hedgewars/Data/Maps/Control/map.lua
share/hedgewars/Data/Maps/Knockball/map.lua
share/hedgewars/Data/Maps/TrophyRace/map.lua
share/hedgewars/Data/Scripts/Locale.lua
--- a/hedgewars/uGears.pas	Sun Dec 30 03:00:51 2012 +0100
+++ b/hedgewars/uGears.pas	Tue Jan 01 14:21:51 2013 -0500
@@ -78,6 +78,7 @@
     stSpawn, stNTurn);
     upd: Longword;
     snowLeft,snowRight: LongInt;
+    NewTurnTick: LongWord;
     //SDMusic: shortstring;
 
 // For better maintainability the step handlers of gears are stored in
@@ -189,6 +190,10 @@
     i, AliveCount: LongInt;
     s: shortstring;
 begin
+ScriptCall('onGameTick');
+if GameTicks mod 20 = 0 then ScriptCall('onGameTick20');
+if GameTicks = NewTurnTick then ScriptCall('onNewTurn');
+
 PrvInactive:= AllInactive;
 AllInactive:= true;
 
@@ -383,7 +388,8 @@
                 SwitchHedgehog;
 
                 AfterSwitchHedgehog;
-                bBetweenTurns:= false
+                bBetweenTurns:= false;
+                NewTurnTick:= GameTicks + 1
                 end;
             step:= Low(step)
             end;
@@ -470,8 +476,6 @@
         inc(hiTicks) // we do not recieve a message for this
     end;
 AddRandomness(CheckSum);
-ScriptCall('onGameTick');
-if GameTicks mod 20 = 0 then ScriptCall('onGameTick20');
 
 inc(GameTicks)
 end;
@@ -1396,6 +1400,7 @@
     upd:= 0;
 
     //SDMusic:= 'hell.ogg';
+    NewTurnTick:= $FFFFFFFF;
 end;
 
 procedure freeModule;
--- a/hedgewars/uTeams.pas	Sun Dec 30 03:00:51 2012 +0100
+++ b/hedgewars/uTeams.pas	Tue Jan 01 14:21:51 2013 -0500
@@ -325,7 +325,6 @@
 {$IFDEF SDL13}
 uTouch.NewTurnBeginning();
 {$ENDIF}
-ScriptCall('onNewTurn');
 end;
 
 function AddTeam(TeamColor: Longword): PTeam;
--- a/share/hedgewars/Data/Maps/Basketball/map.lua	Sun Dec 30 03:00:51 2012 +0100
+++ b/share/hedgewars/Data/Maps/Basketball/map.lua	Tue Jan 01 14:21:51 2013 -0500
@@ -1,6 +1,6 @@
 -- Hedgewars - Basketball for 2+ Players
 
-loadfile(GetDataPath() .. "Scripts/Locale.lua")()
+HedgewarsScriptLoad("Scripts/Locale.lua")()
 
 local score = {[0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0}
 
--- a/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Sun Dec 30 03:00:51 2012 +0100
+++ b/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Tue Jan 01 14:21:51 2013 -0500
@@ -91,7 +91,7 @@
 -- add support for more players
 -- re-enable sudden death, but set water rise to 0
 
-loadfile(GetDataPath() .. "Scripts/Locale.lua")()
+HedgewarsScriptLoad("Scripts/Locale.lua")()
 
 ---------------------------------------------------------------
 ----------lots of bad variables and things
--- a/share/hedgewars/Data/Maps/Control/map.lua	Sun Dec 30 03:00:51 2012 +0100
+++ b/share/hedgewars/Data/Maps/Control/map.lua	Tue Jan 01 14:21:51 2013 -0500
@@ -49,7 +49,7 @@
 --script begins
 -----------------
 
-loadfile(GetDataPath() .. "Scripts/Locale.lua")()
+HedgewarsScriptLoad("Scripts/Locale.lua")()
 
 ---------------------------------------------------------------
 ----------lots of bad variables and things
--- a/share/hedgewars/Data/Maps/Knockball/map.lua	Sun Dec 30 03:00:51 2012 +0100
+++ b/share/hedgewars/Data/Maps/Knockball/map.lua	Tue Jan 01 14:21:51 2013 -0500
@@ -1,6 +1,6 @@
 -- Hedgewars - Knockball for 2+ Players
 
-loadfile(GetDataPath() .. "Scripts/Locale.lua")()
+HedgewarsScriptLoad("Scripts/Locale.lua")()
 
 local score = {[0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0}
 
--- a/share/hedgewars/Data/Maps/TrophyRace/map.lua	Sun Dec 30 03:00:51 2012 +0100
+++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua	Tue Jan 01 14:21:51 2013 -0500
@@ -1,6 +1,6 @@
 -- Hedgewars - Roperace for 2+ Players
 
-loadfile(GetDataPath() .. "Scripts/Locale.lua")()
+HedgewarsScriptLoad("Scripts/Locale.lua")()
 
 -- store number of hedgehogs
 local numhhs = 0
--- a/share/hedgewars/Data/Scripts/Locale.lua	Sun Dec 30 03:00:51 2012 +0100
+++ b/share/hedgewars/Data/Scripts/Locale.lua	Tue Jan 01 14:21:51 2013 -0500
@@ -1,11 +1,11 @@
 -- Library for localizing strings in lua scripts
 
-local lang = loadfile(GetUserDataPath() .. "Locale/" .. tostring(L) .. ".lua")
+local lang = HedgewarsScriptLoad("Locale/" .. tostring(L) .. ".lua")
 
 if lang ~= nil then
     lang()
 else
-    lang = loadfile(GetDataPath() .. "Locale/" .. tostring(L) .. ".lua")
+    lang = HedgewarsScriptLoad("Locale/" .. tostring(L) .. ".lua")
     if lang ~= nil then
         lang()
     end