Only play sndThisOneIsMine if crate drops close to hog
authorWuzzy <Wuzzy2@mail.ru>
Sun, 28 Oct 2018 00:24:27 +0200
changeset 14043 e155b300d49f
parent 14042 fe2b6f3f2559
child 14044 bbecf663d599
Only play sndThisOneIsMine if crate drops close to hog
ChangeLog.txt
hedgewars/uGearsUtils.pas
--- a/ChangeLog.txt	Sat Oct 27 21:51:57 2018 +0200
+++ b/ChangeLog.txt	Sun Oct 28 00:24:27 2018 +0200
@@ -7,6 +7,7 @@
  + Rework team rankings
  + Tied teams now rank equally
  + Help button in main menu
+ + 14 new hedgehog taunts
  + Many new Lua API features
  * Functionality of controllers restored
  * Fix at least 2 crashes
@@ -53,6 +54,7 @@
  + New default brown clan color for better contrast
  + Allow to change volume during pause
  + Add sounds: flamethrower, landspray, idle freezer, shorykuen hit
+ + Add taunts: Amazing, Brilliant, Bugger, Drat, Excellent, Fire, Gonnagetyou, Grenade, Ohdear, Runaway, Solong, Thisoneismine, Whatthe, Watchthis
  * Fix extreme amounts of droplets when shooting with minigun into ocean world edge
  * Fix some flakes disappearing in world wrap worlds while moving camera
  * Fix invisible projectile timer, attack bar, target on other side of wrap world edge
--- a/hedgewars/uGearsUtils.pas	Sat Oct 27 21:51:57 2018 +0200
+++ b/hedgewars/uGearsUtils.pas	Sun Oct 28 00:24:27 2018 +0200
@@ -1544,8 +1544,12 @@
 end;
 
 procedure SpawnBoxOfSmth;
-var t, aTot, uTot, a, h: LongInt;
+const
+    // Max. distance between hog and crate for sndThisOneIsMine taunt
+    ThisOneIsMineDistance : LongInt = 130;
+var t, aTot, uTot, a, h, d, minD: LongInt;
     i: TAmmoType;
+    gi, closestHog: PGear;
 begin
 if (PlacingHogs) or
     (cCaseFactor = 0)
@@ -1621,12 +1625,39 @@
     begin
     FindPlace(FollowGear, true, 0, LAND_WIDTH);
 
+    // Taunt
     if (FollowGear <> nil) then
-        if random(3) = 0 then
-            // TODO: Play this when a crate drops close to a hog, not randomly
-            AddVoice(sndThisOneIsMine, CurrentTeam^.voicepack)
+        begin
+        // Look for hog closest to the crate (on the X axis)
+        gi := GearsList;
+        minD := LAND_WIDTH + ThisOneIsMineDistance + 1;
+        closestHog:= nil;
+        while gi <> nil do
+            begin
+            if (gi^.Kind = gtHedgehog) then
+                begin
+                // Y axis is ignored to simplify calculations
+                d := hwRound(hwAbs(gi^.X - FollowGear^.X));
+                if d < minD then
+                    begin
+                    minD := d;
+                    closestHog:= gi;
+                    end;
+                end;
+            gi := gi^.NextGear;
+            end;
+
+        // Is closest hog close enough to the crate (on the X axis)?
+        if (closestHog <> nil) and (closestHog^.Hedgehog <> nil) and (minD <= ThisOneIsMineDistance) then
+            // If so, there's a chance for a special taunt
+            if random(3) > 0 then
+                AddVoice(sndThisOneIsMine, closestHog^.Hedgehog^.Team^.voicepack)
+            else
+                AddVoice(sndReinforce, CurrentTeam^.voicepack)
         else
+        // Default crate drop taunt
             AddVoice(sndReinforce, CurrentTeam^.voicepack);
+        end;
     end
 end;