Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
authornemo
Sun, 15 Jan 2012 22:01:50 -0500
changeset 6578 d4ad42283125
parent 6576 d998c378dac3
child 6579 fc52f7c22c9b
Also allow lua to change gfPerHogAmmo/gfSharedAmmo even if lua does not define new ammo stores
hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Sun Jan 15 23:54:06 2012 +0100
+++ b/hedgewars/uScript.pas	Sun Jan 15 22:01:50 2012 -0500
@@ -1643,6 +1643,7 @@
 end;
 
 procedure ScriptOnGameInit;
+var i, j, k: LongInt;
 begin
 // not required if there is no script to run
 if not ScriptLoaded then
@@ -1704,6 +1705,29 @@
     ParseCommand('theme ' + ScriptGetString('Theme'), true);
 LuaGoals:= ScriptGetString('Goals');
 
+// Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
+k:= 0;
+if (GameFlags and gfSharedAmmo) <> 0 then
+    for i:= 0 to Pred(ClansCount) do
+        for j:= 0 to Pred(ClansArray[i]^.TeamsNumber) do
+            for k:= 0 to Pred(ClansArray[i]^.Teams[j]^.HedgehogsNumber) do
+                ClansArray[i]^.Teams[j]^.Hedgehogs[k].AmmoStore:= i
+else if (GameFlags and gfPerHogAmmo) <> 0 then
+    for i:= 0 to Pred(TeamsCount) do
+        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
+            begin
+            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= k;
+            if StoreCnt-1 < k then AddAmmoStore;
+            inc(k)
+            end
+else 
+    for i:= 0 to Pred(TeamsCount) do
+        begin
+        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
+            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= k;
+        if StoreCnt-1 < k then AddAmmoStore;
+        inc(k)
+        end;
 if ScriptExists('onAmmoStoreInit') then
     begin
     ScriptPrepareAmmoStore;