Lua: Fix SetAmmoDelay not working properly when called after initialization
authorWuzzy <Wuzzy2@mail.ru>
Wed, 16 Jan 2019 23:50:35 +0100
changeset 14619 03033213e800
parent 14618 7c5a9c1b9d4e
child 14620 5c52013fd0aa
Lua: Fix SetAmmoDelay not working properly when called after initialization
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Wed Jan 16 23:43:23 2019 +0100
+++ b/ChangeLog.txt	Wed Jan 16 23:50:35 2019 +0100
@@ -82,6 +82,7 @@
  + SpeedShoppa/TargetPractice libraries: Remove custom hog and team info settings
  + Params explode, poison in the SpawnFake*Crate functions now optional and default to false
  + New global: InitHealth: Initial hog health value from game scheme (read-only)
+ * Fix SetAmmoDelay not working properly when called after onGameStart
 
 ====================== 0.9.25 ======================
 HIGHLIGHTS:
--- a/hedgewars/uScript.pas	Wed Jan 16 23:43:23 2019 +0100
+++ b/hedgewars/uScript.pas	Wed Jan 16 23:50:35 2019 +0100
@@ -109,7 +109,7 @@
 procedure ScriptPrepareAmmoStore; forward;
 procedure ScriptApplyAmmoStore; forward;
 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward;
-procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte); forward;
+procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: LongWord); forward;
 
 var LuaDebugInfo: lua_Debug;
 
@@ -4097,17 +4097,22 @@
 ScriptAmmoReinforcement[ord(ammo)]:= inttostr(reinforcement)[1];
 end;
 
-procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: Byte);
+procedure ScriptSetAmmoDelay(ammo : TAmmoType; delay: LongWord);
 begin
 // change loadout string if ammo store has not been initialized yet
 if (StoreCnt = 0) then
-begin
+    begin
     if (delay <= 9) then
         ScriptAmmoDelay[ord(ammo)]:= inttostr(delay)[1];
-end
+    end
 // change 'live' delay values
 else if (CurrentTeam <> nil) then
-        ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay;
+    begin
+    ammoz[ammo].SkipTurns:= CurrentTeam^.Clan^.TurnNumber + delay;
+    if ammoz[ammo].SkipTurns > 0 then
+        dec(ammoz[ammo].SkipTurns);
+    AmmoMenuInvalidated:= true;
+    end;
 end;
 
 procedure ScriptApplyAmmoStore;