hedgewars/uAmmos.pas
branchui-scaling
changeset 15283 c4fd2813b127
parent 15246 4aa19b21707d
child 15364 114b036522a6
--- a/hedgewars/uAmmos.pas	Wed May 16 18:22:28 2018 +0200
+++ b/hedgewars/uAmmos.pas	Wed Jul 31 23:14:27 2019 +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;
@@ -79,7 +78,6 @@
 end;
 
 procedure AddAmmoStore;
-const probability: array [0..8] of LongWord = (0,20,30,60,100,200,400,600,800);
 var cnt: Longword;
     a: TAmmoType;
     ammos: TAmmoCounts;
@@ -99,7 +97,7 @@
     begin
     if a <> amNothing then
         begin
-        Ammoz[a].Probability:= probability[byte(ammoProbability[ord(a)]) - byte('0')];
+        Ammoz[a].Probability:= probabilityLevels[byte(ammoProbability[ord(a)]) - byte('0')];
         Ammoz[a].SkipTurns:= (byte(ammoDelay[ord(a)]) - byte('0'));
         Ammoz[a].NumberInCase:= (byte(ammoReinforcement[ord(a)]) - byte('0'));
         cnt:= byte(ammoLoadout[ord(a)]) - byte('0');
@@ -118,31 +116,42 @@
         or ((a = amInvulnerable) and ((GameFlags and gfInvulnerable) <> 0))
         or ((a = amLaserSight) and ((GameFlags and gfLaserSight) <> 0))
         or ((a = amVampiric) and ((GameFlags and gfVampiric) <> 0))
-        or ((a = amExtraTime) and (cHedgehogTurnTime >= 1000000)) then
+        or ((a = amExtraTime) and (cHedgehogTurnTime >= 1000000))
+        // Always remove creeper because it's unfinished.
+        // TODO: Re-enable creeper when creeper is done
+        or (a = amCreeper) then
             begin
             cnt:= 0;
             Ammoz[a].Probability:= 0
             end;
         ammos[a]:= cnt;
 
-        if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)
-        and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then
-            Ammoz[a].SkipTurns:= 1;
-
-        if ((GameFlags and gfPlaceHog) <> 0)
+        if (((GameFlags and gfPlaceHog) <> 0)
+        or (((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)))
         and (a <> amTeleport) and (a <> amSkip)
         and (Ammoz[a].SkipTurns < 10000) then
             inc(Ammoz[a].SkipTurns,10000);
-    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
+    if (((GameFlags and gfPlaceHog) <> 0)
+    or (((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)))
+    and (a = amTeleport) then
         ammos[a]:= AMMO_INFINITE
         end
 
     else
         ammos[a]:= AMMO_INFINITE;
-    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
-        InitialCounts[Pred(StoreCnt)][a]:= cnt
+
+    if (((GameFlags and gfPlaceHog) <> 0)
+    or (((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)))
+    and (a = amTeleport) then
+        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
@@ -156,7 +165,7 @@
 
 function GetAmmoByNum(num: LongInt): PHHAmmo;
 begin
-    if checkFails(num < StoreCnt, 'Invalid store number', true) then
+    if checkFails(num < StoreCnt, 'Invalid ammo store number', true) then
         GetAmmoByNum:= nil
     else
         GetAmmoByNum:= StoresList[num]
@@ -395,7 +404,9 @@
     CurWeapon:= GetCurAmmoEntry(Hedgehog);
     OldWeapon:= GetCurAmmoEntry(Hedgehog);
 
-    if (CurWeapon^.Count = 0) then
+    if (Hedgehog.Gear^.State and gstHHDriven) = 0 then
+        Hedgehog.CurAmmoType:= amNothing
+    else if (CurWeapon^.Count = 0) then
         SwitchToFirstLegalAmmo(Hedgehog)
     else if CurWeapon^.AmmoType = amNothing then
         Hedgehog.CurAmmoType:= amNothing;
@@ -418,7 +429,8 @@
             s:= s + ansistring(' (' + IntToStr(Count) + ')');
         if (Propz and ammoprop_Timerable) <> 0 then
             s:= s + ansistring(', ' + IntToStr(Timer div 1000) + ' ') + trammo[sidSeconds];
-        AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
+        if (Hedgehog.Gear^.State and gstHHDriven) <> 0 then
+            AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
         if (Propz and ammoprop_NeedTarget) <> 0 then
             begin
             if Gear <> nil then Gear^.State:= Gear^.State or      gstChooseTarget;
@@ -458,7 +470,7 @@
                 if (Propz and ammoprop_NotBorder) <> 0 then
                     begin
                     Count:= 0;
-                    InitialCounts[i][AmmoType]:= 0
+                    InitialCountsLocal[i][AmmoType]:= 0
                     end;
 
         PackAmmo(StoresList[i], slot)
@@ -489,7 +501,7 @@
     ammoReinforcement:= s;
 end;
 
-// Restore indefinitely disabled weapons and initial weapon counts.  Only used for hog placement right now
+// Restore indefinitely disabled weapons and initial weapon counts.
 procedure ResetWeapons;
 var i, t: Longword;
     a: TAmmoType;
@@ -506,7 +518,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;
 
@@ -546,7 +558,7 @@
         ammoDelay:= ammoDelay + '0';
         ammoReinforcement:= ammoReinforcement + '0'
         end;
-    FillChar(InitialCounts, sizeof(InitialCounts), 0)
+    FillChar(InitialCountsLocal, sizeof(InitialCountsLocal), 0)
 end;
 
 procedure freeModule;