hedgewars/uGearsUtils.pas
changeset 12712 31f7e0a31736
parent 12656 161c10db4f27
child 12735 83d62800d215
--- a/hedgewars/uGearsUtils.pas	Wed Oct 18 20:33:20 2017 -0400
+++ b/hedgewars/uGearsUtils.pas	Fri Oct 20 13:27:48 2017 +0200
@@ -47,6 +47,7 @@
 function  GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): PGearArrayS;
 procedure SpawnBoxOfSmth;
 procedure ShotgunShot(Gear: PGear);
+function  CanUseTardis(HHGear: PGear): boolean;
 
 procedure SetAllToActive;
 procedure SetAllHHToActive(Ice: boolean);
@@ -1172,6 +1173,35 @@
     DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius)
 end;
 
+// Returns true if the given hog gear can use the tardis
+function CanUseTardis(HHGear: PGear): boolean;
+var usable: boolean;
+    i, j, cnt: LongInt;
+    HH: PHedgehog;
+begin
+(*
+    Conditions for not activating.
+    1. Hog is last of his clan
+    2. Sudden Death is in play
+    3. Hog is a king
+*)
+    usable:= true;
+    HH:= HHGear^.Hedgehog;
+    if HHGear <> nil then
+    if (HHGear = nil) or (HH^.King) or (SuddenDeathDmg) then
+        usable:= false;
+    cnt:= 0;
+    for j:= 0 to Pred(HH^.Team^.Clan^.TeamsNumber) do
+        for i:= 0 to Pred(HH^.Team^.Clan^.Teams[j]^.HedgehogsNumber) do
+            if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil)
+            and ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0)
+            and (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health > HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then
+                inc(cnt);
+    if (cnt < 2) then
+        usable:= false;
+    CanUseTardis:= usable;
+end;
+
 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt);
 var t: PGearArray;
     Gear: PGear;