Fix GetAmmo getting wrong ammo count
authorWuzzy <Wuzzy2@mail.ru>
Sun, 08 Jul 2018 02:06:08 +0200
changeset 13455 38814954a248
parent 13454 794dcf69a5aa
child 13456 7a0a56c52fd2
Fix GetAmmo getting wrong ammo count
hedgewars/uAmmos.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
--- a/hedgewars/uAmmos.pas	Sun Jul 08 01:30:13 2018 +0200
+++ b/hedgewars/uAmmos.pas	Sun Jul 08 02:06:08 2018 +0200
@@ -52,11 +52,10 @@
 implementation
 uses uVariables, uCommands, uUtils, uCaptions, uDebug, uScript;
 
-type TAmmoCounts = array[TAmmoType] of Longword;
-     TAmmoArray = array[TAmmoType] of TAmmo;
+type TAmmoArray = array[TAmmoType] of TAmmo;
 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
-    InitialCounts: array[0..Pred(cMaxHHs)] of TAmmoCounts;
+    InitialCountsLocal: array[0..Pred(cMaxHHs)] of TAmmoCounts;
 
 procedure FillAmmoStore(Ammo: PHHAmmo; var newAmmo: TAmmoArray);
 var mi: array[0..cMaxSlotIndex] of byte;
@@ -139,9 +138,15 @@
     else
         ammos[a]:= AMMO_INFINITE;
     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
-        InitialCounts[Pred(StoreCnt)][a]:= cnt
+        begin
+        InitialCountsLocal[Pred(StoreCnt)][a]:= cnt;
+        InitialAmmoCounts[a]:= cnt;
+        end
     else
-        InitialCounts[Pred(StoreCnt)][a]:= ammos[a];
+        begin
+        InitialCountsLocal[Pred(StoreCnt)][a]:= ammos[a];
+        InitialAmmoCounts[a]:= ammos[a];
+        end
     end;
 
     for a:= Low(TAmmoType) to High(TAmmoType) do
@@ -457,7 +462,7 @@
                 if (Propz and ammoprop_NotBorder) <> 0 then
                     begin
                     Count:= 0;
-                    InitialCounts[i][AmmoType]:= 0
+                    InitialCountsLocal[i][AmmoType]:= 0
                     end;
 
         PackAmmo(StoresList[i], slot)
@@ -505,7 +510,7 @@
 for i:= 0 to Pred(StoreCnt) do
     begin
     for a:= Low(TAmmoType) to High(TAmmoType) do
-        newAmmos[a].Count:= InitialCounts[i][a];
+        newAmmos[a].Count:= InitialCountsLocal[i][a];
     FillAmmoStore(StoresList[i], newAmmos);
     end;
 
@@ -545,7 +550,7 @@
         ammoDelay:= ammoDelay + '0';
         ammoReinforcement:= ammoReinforcement + '0'
         end;
-    FillChar(InitialCounts, sizeof(InitialCounts), 0)
+    FillChar(InitialCountsLocal, sizeof(InitialCountsLocal), 0)
 end;
 
 procedure freeModule;
--- a/hedgewars/uScript.pas	Sun Jul 08 01:30:13 2018 +0200
+++ b/hedgewars/uScript.pas	Sun Jul 08 02:06:08 2018 +0200
@@ -2604,7 +2604,7 @@
         if at >= 0 then
             begin
             // Ammo count
-            i:= Ammoz[TAmmoType(at)].Ammo.Count;
+            i:= InitialAmmoCounts[TAmmoType(at)];
             if i = AMMO_INFINITE then
                 i:= 9;
             lua_pushnumber(L, i);
--- a/hedgewars/uVariables.pas	Sun Jul 08 01:30:13 2018 +0200
+++ b/hedgewars/uVariables.pas	Sun Jul 08 02:06:08 2018 +0200
@@ -816,9 +816,11 @@
             PosSprite: TSprite;
             ejectX, ejectY: Longint;
             end;
+    TAmmoCounts = array[TAmmoType] of Longword;
 
 var
     Ammoz: array [TAmmoType] of TAmmozRec;
+    InitialAmmoCounts: TAmmoCounts;
 
 const
     AmmozInit: array [TAmmoType] of TAmmozRec = (