Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set
authorWuzzy <Wuzzy2@mail.ru>
Mon, 03 Sep 2018 20:01:50 +0200
changeset 13752 f1c66a34f2fe
parent 13751 5985ee7a4922
child 13753 885404cdf07a
Lua: Fix LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT being broken if onVisualGearAdd is set Fixes bug #585
ChangeLog.txt
hedgewars/uLand.pas
hedgewars/uScript.pas
--- a/ChangeLog.txt	Mon Sep 03 12:59:54 2018 +0200
+++ b/ChangeLog.txt	Mon Sep 03 20:01:50 2018 +0200
@@ -134,6 +134,7 @@
  * Animate library: Remove defunct follow argument for AnimVisualGear
  * Changed global: lfCurrentHog becomes lfCurHogCrate
  * Fixed variable: TotalRounds was -1 (instead of 0) in first real round after hog placement phase
+ * Fixed variables: LeftX, RightX, TopY, LAND_WIDTH, LAND_HEIGHT were broken if onVisualGearAdd was defined
  * AI sometimes intentionally shot hedgehogs with aihDoesntMatter set
 
 ====================== 0.9.24.1 ====================
--- a/hedgewars/uLand.pas	Mon Sep 03 12:59:54 2018 +0200
+++ b/hedgewars/uLand.pas	Mon Sep 03 20:01:50 2018 +0200
@@ -873,6 +873,7 @@
 if (WorldEdge <> weNone) and (not hasBorder) then
     InitWorldEdges();
 
+ScriptSetMapGlobals;
 end;
 
 procedure GenPreview(out Preview: TPreview);
@@ -889,6 +890,8 @@
         OutError('Unknown mapgen', true);
     end;
 
+    ScriptSetMapGlobals;
+
     // strict scaling needed here since preview assumes a rectangle
     rh:= max(LAND_HEIGHT,2048);
     rw:= max(LAND_WIDTH,4096);
@@ -938,6 +941,8 @@
         OutError('Unknown mapgen', true);
     end;
 
+    ScriptSetMapGlobals;
+
     // strict scaling needed here since preview assumes a rectangle
     rh:= max(LAND_HEIGHT, 2048);
     rw:= max(LAND_WIDTH, 4096);
--- a/hedgewars/uScript.pas	Mon Sep 03 12:59:54 2018 +0200
+++ b/hedgewars/uScript.pas	Mon Sep 03 20:01:50 2018 +0200
@@ -40,6 +40,7 @@
 procedure ScriptOnScreenResize;
 procedure ScriptSetInteger(name : shortstring; value : LongInt);
 procedure ScriptSetString(name : shortstring; value : shortstring);
+procedure ScriptSetMapGlobals;
 
 procedure ScriptCall(fname : shortstring);
 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
@@ -99,7 +100,6 @@
     ScriptAmmoDelay : shortstring;
     ScriptAmmoReinforcement : shortstring;
     ScriptLoaded : boolean;
-    mapDims : boolean;
     PointsBuffer: shortstring;
     PrevCursorX, PrevCursorY: LongInt;
     PendingTurnTimeLeft, PendingReadyTimeLeft: LongWord;
@@ -3540,7 +3540,6 @@
 
 ScriptSetInteger('ClansCount', ClansCount);
 ScriptSetInteger('TeamsCount', TeamsCount);
-mapDims:= false
 end;
 
 
@@ -3709,21 +3708,21 @@
     PrevCursorY:= NoPointX
     end;
 
-if not mapDims then
-    begin
-    mapDims:= true;
-    ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
-    ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
-    ScriptSetInteger('LeftX', leftX);
-    ScriptSetInteger('RightX', rightX);
-    ScriptSetInteger('TopY', topY)
-    end;
 if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then
     ScriptSetInteger('CurrentHedgehog', CurrentHedgehog^.Gear^.UID)
 else
     ScriptSetNil('CurrentHedgehog');
 end;
 
+procedure ScriptSetMapGlobals;
+begin
+ScriptSetInteger('LAND_WIDTH', LAND_WIDTH);
+ScriptSetInteger('LAND_HEIGHT', LAND_HEIGHT);
+ScriptSetInteger('LeftX', leftX);
+ScriptSetInteger('RightX', rightX);
+ScriptSetInteger('TopY', topY);
+end;
+
 procedure GetGlobals;
 var currentTTL, currentRTL, newTTL, newRTL: LongInt;
 begin
@@ -4382,7 +4381,6 @@
 
 procedure initModule;
 begin
-mapDims:= false;
 PointsBuffer:= '';
 PrevCursorX:= NoPointX;
 PrevCursorY:= NoPointX;