- A good implementation of shotgun
authorunc0rr
Sat, 05 May 2007 16:04:55 +0000
changeset 506 0889d833d47e
parent 505 fcba7d7aea0d
child 507 38ee23c7c8c2
- A good implementation of shotgun - Small fixes for previous commit
hedgewars/GSHandlers.inc
hedgewars/uAI.pas
hedgewars/uGears.pas
--- a/hedgewars/GSHandlers.inc	Fri May 04 19:59:51 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Sat May 05 16:04:55 2007 +0000
@@ -290,8 +290,9 @@
 CheckCollision(Gear);
 if (Gear^.State and gstCollision) <> 0 then
    begin
-   AmmoShove(Gear, 25, 25);
-   doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, EXPLNoDamage or EXPLDoNotTouchHH);
+   Gear^.X:= Gear^.X + Gear^.dX * 8;
+   Gear^.Y:= Gear^.Y + Gear^.dY * 8;
+   ShotgunShot(Gear);
    DeleteGear(Gear);
    AfterAttack;
    exit
@@ -758,7 +759,6 @@
       if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick, false);
       if Gear^.Timer = 0 then
          begin
-         DeleteCI(Gear);
          doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, EXPLAutoSound);
          DeleteGear(Gear)
          end;
@@ -917,7 +917,7 @@
    end else begin
    if Gear^.Timer > 0 then dec(Gear^.Timer)
       else begin
-      doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 2, 0);
+//      doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 2, 0);
       dec(Gear^.Health);
       Gear^.Timer:= 1250 - Gear^.Angle * 12
       end
--- a/hedgewars/uAI.pas	Fri May 04 19:59:51 2007 +0000
+++ b/hedgewars/uAI.pas	Sat May 05 16:04:55 2007 +0000
@@ -25,7 +25,7 @@
 
 implementation
 uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc,
-     uAmmos, uConsole{$IFDEF UNIX}, cthreads{$ENDIF};
+     uAmmos, uConsole, uCollisions{$IFDEF UNIX}, cthreads{$ENDIF};
 
 var BestActions: TActions;
     ThinkThread: THandle = 0;
@@ -277,6 +277,8 @@
 begin
 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
 Me^.State:= Me^.State or gstHHThinking;
 Me^.Message:= 0;
 StopThinking:= false;
--- a/hedgewars/uGears.pas	Fri May 04 19:59:51 2007 +0000
+++ b/hedgewars/uGears.pas	Sat May 05 16:04:55 2007 +0000
@@ -91,6 +91,7 @@
 procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); forward;
 procedure HedgehogStep(Gear: PGear); forward;
 procedure HedgehogChAngle(Gear: PGear); forward;
+procedure ShotgunShot(Gear: PGear); forward;
 
 {$INCLUDE GSHandlers.inc}
 {$INCLUDE HHHandlers.inc}
@@ -651,18 +652,18 @@
 
 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord);
 var Gear: PGear;
-    dmg: LongInt;
+    dmg, dmgRadius: LongInt;
 begin
 TargetPoint.X:= NoPointX;
 {$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF}
-if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius);
 if Radius = 50 then AddGear(X, Y, gtExplosion, 0, _0, _0, 0);
 if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false);
-if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1;
+if (Mask and EXPLAllDamageInRadius)=0 then dmgRadius:= Radius shl 1
+                                      else dmgRadius:= Radius;
 Gear:= GearsList;
 while Gear <> nil do
       begin
-      dmg:= Radius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
+      dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
       if dmg > 0 then
          begin
          dmg:= dmg div 2;
@@ -675,6 +676,7 @@
                           if (Mask and EXPLNoDamage) = 0 then inc(Gear^.Damage, dmg);
                           if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then
                              begin
+                             DeleteCI(Gear);
                              Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - int2hwFloat(X));
                              Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - int2hwFloat(Y));
                              Gear^.State:= Gear^.State or gstMoving;
@@ -690,9 +692,42 @@
          end;
       Gear:= Gear^.NextGear
       end;
+if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius);
 uAIMisc.AwareOfExplosion(0, 0, 0)
 end;
 
+procedure ShotgunShot(Gear: PGear);
+var t: PGear;
+    dmg: integer;
+begin
+Gear^.Radius:= 22;
+t:= GearsList;
+while t <> nil do
+    begin
+    dmg:= min(Gear^.Radius + t^.Radius - hwRound(Distance(Gear^.X - t^.X, Gear^.Y - t^.Y)), 25);
+    if dmg >= 0 then
+       case t^.Kind of
+           gtHedgehog,
+               gtMine,
+               gtCase: begin
+                       inc(t^.Damage, dmg);
+                       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;
+                       t^.State:= t^.State or gstMoving;
+                       t^.Active:= true;
+                       FollowGear:= t
+                       end;
+              gtGrave: begin
+                       t^.dY:= - _0_1;
+                       t^.Active:= true
+                       end;
+           end;
+    t:= t^.NextGear
+    end;
+DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 22)
+end;
+
 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt);
 var t: PGearArray;
     i: LongInt;