Take sacrifices into account for the “Stupid” taunt
authorWuzzy <almikes@aol.com>
Thu, 20 Apr 2017 00:04:35 +0200
changeset 12292 93434ab299a0
parent 12291 e2b30aba00e1
child 12293 6383323fdd2c
Take sacrifices into account for the “Stupid” taunt
ChangeLog.txt
hedgewars/uGearsHandlersMess.pas
hedgewars/uStats.pas
hedgewars/uTypes.pas
--- a/ChangeLog.txt	Wed Apr 19 22:26:24 2017 +0200
+++ b/ChangeLog.txt	Thu Apr 20 00:04:35 2017 +0200
@@ -36,6 +36,7 @@
  * Fixed Hedgehogs getting hurt while firing deagle / sniper rifle bullet in certains situations
  * Fixed hedgehogs saying “Missed” when drowning enemy without dealing damage
  * Fixed enemy saying "Missed” when giving poison without direct damage
+ * Fixed hedgehogs not saying “Stupid” and not displaying announcer message for inflicting self-harm
  * Fixed incorrect time box tooltip when in Sudden Death
  * Various other fixes
 
--- a/hedgewars/uGearsHandlersMess.pas	Wed Apr 19 22:26:24 2017 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Thu Apr 20 00:04:35 2017 +0200
@@ -3141,6 +3141,7 @@
                 end;
         s:= ansistring(Gear^.Hedgehog^.Name);
         AddCaption(FormatA(GetEventString(eidKamikaze), s), cWhiteColor, capgrpMessage);
+        uStats.HedgehogSacrificed(Gear^.Hedgehog);
         AfterAttack;
         HHGear^.Message:= HHGear^.Message or gmDestroy;
         DeleteGear(Gear);
@@ -4836,6 +4837,7 @@
             begin
             Gear^.Y:= Gear^.Y + _50;
             OnUsedAmmo(CurrentHedgehog^);
+            uStats.HedgehogSacrificed(CurrentHedgehog);
             if CurrentHedgehog^.Gear <> nil then
                 begin
                 // Drown the hedgehog.  Could also just delete it, but hey, this gets a caption
@@ -4859,6 +4861,7 @@
         begin
         Gear^.Y:= Gear^.Y + _50;
         OnUsedAmmo(CurrentHedgehog^);
+        uStats.HedgehogSacrificed(CurrentHedgehog);
         if CurrentHedgehog^.Gear <> nil then
             begin
             // Drown the hedgehog.  Could also just delete it, but hey, this gets a caption
--- a/hedgewars/uStats.pas	Wed Apr 19 22:26:24 2017 +0200
+++ b/hedgewars/uStats.pas	Thu Apr 20 00:04:35 2017 +0200
@@ -31,6 +31,7 @@
 
 procedure AmmoUsed(am: TAmmoType);
 procedure HedgehogPoisoned(Gear: PGear; Attacker: PHedgehog);
+procedure HedgehogSacrificed(Hedgehog: PHedgehog);
 procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean);
 procedure Skipped;
 procedure TurnReaction;
@@ -75,6 +76,11 @@
     inc(PoisonTotal)
 end;
 
+procedure HedgehogSacrificed(Hedgehog: PHedgehog);
+begin
+    Hedgehog^.stats.Sacrificed:= true
+end;
+
 procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean);
 begin
 if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then
@@ -119,6 +125,7 @@
 
 procedure TurnReaction;
 var i, t: LongInt;
+    killsCheck: LongInt;
     s: ansistring;
 begin
 //TryDo(not bBetweenTurns, 'Engine bug: TurnReaction between turns', true);
@@ -128,13 +135,18 @@
     begin
     s:= ansistring(CurrentHedgehog^.Name);
     inc(CurrentHedgehog^.stats.FinishedTurns);
+    // If the hog sacrificed (=kamikaze/piano) itself, this needs to be taken into accounts for the reactions later
+    if (CurrentHedgehog^.stats.Sacrificed) then
+        killsCheck:= 1
+    else
+        killsCheck:= 0;
 
     // First blood (first damage, poison or kill)
     if ((DamageTotal > 0) or (KillsTotal > 0) or (PoisonTotal > 0)) and ((CurrentHedgehog^.stats.DamageGiven = DamageTotal) and (CurrentHedgehog^.stats.StepKills = KillsTotal) and (PoisonTotal = PoisonTurn + PoisonClan)) then
         AddVoice(sndFirstBlood, CurrentTeam^.voicepack)
 
-    // Hog hurts, poisons or kills itself
-    else if (CurrentHedgehog^.stats.StepDamageRecv > 0) or (CurrentHedgehog^.stats.StepPoisoned) or (CurrentHedgehog^.Gear = nil) then
+    // Hog hurts, poisons or kills itself (except sacrifice)
+    else if (CurrentHedgehog^.stats.Sacrificed = false) and ((CurrentHedgehog^.stats.StepDamageRecv > 0) or (CurrentHedgehog^.stats.StepPoisoned) or (CurrentHedgehog^.Gear = nil)) then
         begin
         AddVoice(sndStupid, PreviousTeam^.voicepack);
         // Message for hurting itself only (not drowning)
@@ -142,8 +154,8 @@
             AddCaption(FormatA(GetEventString(eidHurtSelf), s), cWhiteColor, capgrpMessage);
         end
 
-    // Hog hurts, poisons or kills own team/clan member
-    else if (DamageClan <> 0) or (KillsClan <> 0) or (PoisonClan <> 0) then
+    // Hog hurts, poisons or kills own team/clan member. Sacrifice is taken into account
+    else if (DamageClan <> 0) or (KillsClan > killsCheck) or (PoisonClan <> 0) then
         if (DamageTurn > DamageClan) or (Kills > KillsClan) then
             if random(2) = 0 then
                 AddVoice(sndNutter, CurrentTeam^.voicepack)
@@ -156,15 +168,22 @@
                 AddVoice(sndTraitor, vpHurtSameClan)
 
     // Hog hurts, kills or poisons enemy
-    else if (CurrentHedgehog^.stats.StepDamageGiven <> 0) or (CurrentHedgehog^.stats.StepKills <> 0) or (PoisonTurn <> 0) then
-        if Kills > 0 then
+    else if (CurrentHedgehog^.stats.StepDamageGiven <> 0) or (CurrentHedgehog^.stats.StepKills > killsCheck) or (PoisonTurn <> 0) then
+        if Kills > killsCheck then
             AddVoice(sndEnemyDown, CurrentTeam^.voicepack)
         else
             AddVoice(sndRegret, vpHurtEnemy)
 
     // Missed shot
-    else if AmmoDamagingUsed and (Kills = 0) and (PoisonTurn = 0) and (PoisonClan = 0) and (DamageTurn = 0) then
-        AddVoice(sndMissed, PreviousTeam^.voicepack)
+    else if AmmoDamagingUsed and (Kills <= killsCheck) and (PoisonTurn = 0) and (PoisonClan = 0) and (DamageTurn = 0) then
+        // Chance to call hedgehog stupid if sacrificed for nothing
+        if CurrentHedgehog^.stats.Sacrificed then
+            if random(2) = 0 then
+                AddVoice(sndMissed, PreviousTeam^.voicepack)
+            else
+                AddVoice(sndStupid, PreviousTeam^.voicepack)
+        else
+            AddVoice(sndMissed, PreviousTeam^.voicepack)
 
     // Timeout
     else if (AmmoUsedCount > 0) and (not isTurnSkipped) then
--- a/hedgewars/uTypes.pas	Wed Apr 19 22:26:24 2017 +0200
+++ b/hedgewars/uTypes.pas	Thu Apr 20 00:04:35 2017 +0200
@@ -329,7 +329,8 @@
         StepDamageRecv,
         StepDamageGiven,
         StepKills: Longword;
-        StepPoisoned: boolean;
+        StepPoisoned,
+        Sacrificed: boolean;
         MaxStepDamageRecv,
         MaxStepDamageGiven,
         MaxStepKills: Longword;