Tags with current damage
authorunc0rr
Sat, 26 May 2007 16:49:37 +0000
changeset 522 ca089787f59d
parent 521 bc8fd78d7598
child 523 eddcef907b28
Tags with current damage
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uAI.pas
hedgewars/uConsts.pas
hedgewars/uGears.pas
--- a/hedgewars/GSHandlers.inc	Thu May 24 20:33:07 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Sat May 26 16:49:37 2007 +0000
@@ -38,8 +38,14 @@
 end;
 
 procedure CheckHHDamage(Gear: PGear);
+var dmg: Longword;
 begin
-if _0_4 < Gear^.dY then Gear^.Damage:= Gear^.Damage + 1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70);
+if _0_4 < Gear^.dY then
+   begin
+   dmg:= 1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70);
+   inc(Gear^.Damage, dmg);
+   AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y) + cHHRadius, dmg, Gear);
+   end
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -169,12 +175,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepHealthTagWork(Gear: PGear);
 begin
-AllInactive:= false;
+if Gear^.Kind = gtHealthTag then
+   AllInactive:= false;
 dec(Gear^.Timer);
-Gear^.Y:= Gear^.Y - _0_08;
+Gear^.Y:= Gear^.Y + Gear^.dY;
 if Gear^.Timer = 0 then
    begin
-   PHedgehog(Gear^.Hedgehog)^.Gear^.Active:= true; // to let current hh die
+   if Gear^.Kind = gtHealthTag then
+      PHedgehog(Gear^.Hedgehog)^.Gear^.Active:= true; // to let current hh die
    DeleteGear(Gear)
    end
 end;
@@ -189,12 +197,24 @@
 
 procedure doStepHealthTag(Gear: PGear);
 var s: shortstring;
+    font: THWFont;
 begin
 AllInactive:= false;
+if Gear^.Kind = gtHealthTag then
+   begin
+   font:= fnt16;
+   Gear^.dY:= -_0_08
+   end else
+   begin
+   font:= fntSmall;
+   Gear^.dY:= -_0_02
+   end;
+
 str(Gear^.State, s);
-Gear^.Surf:= RenderString(s, PHedgehog(Gear^.Hedgehog)^.Team^.Color, fnt16);
+Gear^.Surf:= RenderString(s, PHedgehog(Gear^.Hedgehog)^.Team^.Color, font);
 if hwRound(Gear^.Y) < cWaterLine then Gear^.doStep:= @doStepHealthTagWork
-                                 else Gear^.doStep:= @doStepHealthTagWorkUnderWater
+                                 else Gear^.doStep:= @doStepHealthTagWorkUnderWater;
+Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Surf^.h)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/hedgewars/HHHandlers.inc	Thu May 24 20:33:07 2007 +0000
+++ b/hedgewars/HHHandlers.inc	Sat May 26 16:49:37 2007 +0000
@@ -391,6 +391,7 @@
       begin
       if AllInactive then
          begin
+         Gear^.State:= Gear^.State or gstNoDamage;
          doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, EXPLAutoSound);
          AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
          DeleteGear(Gear);
--- a/hedgewars/uAI.pas	Thu May 24 20:33:07 2007 +0000
+++ b/hedgewars/uAI.pas	Sat May 26 16:49:37 2007 +0000
@@ -281,7 +281,7 @@
 if ((Me^.State and (gstAttacking or gstHHJumping or gstFalling or gstMoving)) <> 0)
    or isInMultiShoot then exit;
 
-DeleteCI(Me); // don't let collision info in Land to confuse AI
+//DeleteCI(Me); // this might break demo 
 Me^.State:= Me^.State or gstHHThinking;
 Me^.Message:= 0;
 
--- a/hedgewars/uConsts.pas	Thu May 24 20:33:07 2007 +0000
+++ b/hedgewars/uConsts.pas	Sat May 26 16:49:37 2007 +0000
@@ -47,7 +47,7 @@
                    gtTeamHealthSorter, gtClusterBomb, gtCluster, gtShover, gtFlame,
                    gtFirePunch, gtATStartGame, gtATSmoothWindCh, gtATFinishGame,
                    gtParachute, gtAirAttack, gtAirBomb, gtBlowTorch, gtGirder,
-                   gtTeleport);
+                   gtTeleport, gtSmallDamage);
 
      TGearsType = set of TGearType;
 
@@ -60,7 +60,7 @@
                    amBaseballBat, amParachute, amAirAttack, amMineStrike, amBlowTorch,
                    amGirder, amTeleport);
 
-     THWFont    = (fnt16, fntBig);
+     THWFont    = (fnt16, fntBig, fntSmall);
 
      TCapGroup  = (capgrpGameState, capgrpAmmoinfo, capgrpNetSay, capgrpVolume);
 
@@ -198,6 +198,10 @@
                                          (Handle: nil;
                                           Height: 24;
                                           style: TTF_STYLE_NORMAL;
+                                          Name: 'DejaVuSans.ttf'),
+                                         (Handle: nil;
+                                          Height: 10;
+                                          style: TTF_STYLE_NORMAL;
                                           Name: 'DejaVuSans.ttf')
                                          );
 
--- a/hedgewars/uGears.pas	Thu May 24 20:33:07 2007 +0000
+++ b/hedgewars/uGears.pas	Sat May 26 16:49:37 2007 +0000
@@ -92,6 +92,7 @@
 procedure HedgehogStep(Gear: PGear); forward;
 procedure HedgehogChAngle(Gear: PGear); forward;
 procedure ShotgunShot(Gear: PGear); forward;
+procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); forward;
 
 {$INCLUDE GSHandlers.inc}
 {$INCLUDE HHHandlers.inc}
@@ -127,7 +128,8 @@
                                                                @doStepAirBomb,
                                                                @doStepBlowTorch,
                                                                @doStepGirder,
-                                                               @doStepTeleport
+                                                               @doStepTeleport,
+                                                               @doStepHealthTag
                                                                );
 
 procedure InsertGearToList(Gear: PGear);
@@ -204,7 +206,7 @@
                 end;
    gtHealthTag: begin
                 Result^.Timer:= 1500;
-                Result^.Z:= 2000;
+                Result^.Z:= 2001;
                 end;
        gtGrave: begin
                 Result^.Radius:= 10;
@@ -281,6 +283,10 @@
                 Result^.Radius:= cHHRadius + cBlowTorchC;
                 Result^.Timer:= 7500;
                 end;
+ gtSmallDamage: begin
+                Result^.Timer:= 1100;
+                Result^.Z:= 2000;
+                end;
      end;
 InsertGearToList(Result);
 AddGear:= Result
@@ -291,7 +297,11 @@
     t: Longword;
 begin
 DeleteCI(Gear);
-if Gear^.Surf <> nil then SDL_FreeSurface(Gear^.Surf);
+if Gear^.Surf <> nil then
+   begin
+   SDL_FreeSurface(Gear^.Surf);
+   Gear^.Surf:= nil
+   end;
 if Gear^.Kind = gtHedgehog then
    if CurAmmoGear <> nil then
       begin
@@ -333,8 +343,8 @@
             CheckNoDamage:= false;
             inc(StepDamage, Gear^.Damage);
             if Gear^.Health < Gear^.Damage then Gear^.Health:= 0
-                                         else dec(Gear^.Health, Gear^.Damage);
-            AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12 - PHedgehog(Gear^.Hedgehog)^.HealthTag^.h,
+                                           else dec(Gear^.Health, Gear^.Damage);
+            AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12,
                     gtHealthTag, Gear^.Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
             RenderHealth(PHedgehog(Gear^.Hedgehog)^);
             RecountTeamHealth(PHedgehog(Gear^.Hedgehog)^.Team);
@@ -345,6 +355,11 @@
       end;
 end;
 
+procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear);
+begin
+AddGear(X, Y, gtSmallDamage, Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
+end;
+
 procedure ProcessGears;
 const delay: LongInt = cInactDelay;
       step: (stDelay, stChDmg, stChWin, stSpawn, stNTurn) = stDelay;
@@ -532,7 +547,8 @@
        gtAmmo_Bomb: DrawSprite(sprBomb , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface);
         gtHedgehog: DrawHH(Gear, Surface);
     gtAmmo_Grenade: DrawSprite(sprGrenade , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface);
-       gtHealthTag: if Gear^.Surf <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Surf, Surface);
+       gtHealthTag,
+     gtSmallDamage: if Gear^.Surf <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Surf, Surface);
            gtGrave: DrawSpriteFromRect(PHedgehog(Gear^.Hedgehog)^.Team^.GraveRect, hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface);
              gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface);
       gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface);
@@ -630,7 +646,8 @@
 while Gear <> nil do
       begin
       dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
-      if dmg > 0 then
+      if (dmg > 0) and
+         ((Gear^.State and gstNoDamage) = 0) then
          begin
          dmg:= dmg div 2;
          case Gear^.Kind of
@@ -639,7 +656,12 @@
                   gtCase,
                  gtFlame: begin
                           {$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF}
-                          if (Mask and EXPLNoDamage) = 0 then inc(Gear^.Damage, dmg);
+                          if (Mask and EXPLNoDamage) = 0 then
+                             begin
+                             inc(Gear^.Damage, dmg);
+                             if Gear^.Kind = gtHedgehog then
+                                AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear)
+                             end;
                           if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then
                              begin
                              DeleteCI(Gear);
@@ -665,8 +687,10 @@
 procedure ShotgunShot(Gear: PGear);
 var t: PGear;
     dmg: integer;
+    hh: PHedgehog;
 begin
 Gear^.Radius:= cShotgunRadius;
+hh:= Gear^.Hedgehog;
 t:= GearsList;
 while t <> nil do
     begin
@@ -677,6 +701,11 @@
                gtMine,
                gtCase: begin
                        inc(t^.Damage, dmg);
+                       if t^.Kind = gtHedgehog then
+                          begin
+                          AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear);
+                          inc(hh^.DamageGiven, dmg)
+                          end;
                        DeleteCI(t);
                        t^.dX:= t^.dX + SignAs(Gear^.dX * dmg * _0_01 + cHHKick, t^.X - Gear^.X);
                        t^.dY:= t^.dY + Gear^.dY * dmg * _0_01;
@@ -711,7 +740,11 @@
                gtMine,
                gtCase: begin
                        inc(t^.ar[i]^.Damage, Damage);
-                       inc(hh^.DamageGiven, Damage);
+                       if t^.ar[i]^.Kind = gtHedgehog then
+                          begin
+                          AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]);
+                          inc(hh^.DamageGiven, Damage)
+                          end;
                        t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01;
                        t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01;
                        t^.ar[i]^.Active:= true;