hedgewars/HHHandlers.inc
changeset 32 78bff13b11c0
parent 16 b6f4b413dd41
child 37 2b7f2a43b999
--- a/hedgewars/HHHandlers.inc	Tue Dec 27 10:20:55 2005 +0000
+++ b/hedgewars/HHHandlers.inc	Wed Dec 28 22:18:11 2005 +0000
@@ -31,6 +31,78 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *)
 
+procedure Attack(Gear: PGear);
+var xx, yy: real;
+begin
+with Gear^,
+     CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
+     begin
+     {$IFDEF DEBUGFILE}AddFileLog('Attack: Gear.State = '+inttostr(State)+' CurAmmoGear = '+inttostr(longword(CurAmmoGear)));{$ENDIF}
+     if CurAmmoGear <> nil then
+        begin
+        Message:= Message and not gm_Attack;
+        if not CurrentTeam.ExtDriven then SendIPC('a')
+        end;
+     if (((State and (gstHHDriven or gstAttacking)) = (gstHHDriven or gstAttacking))and
+        ((State and (gstAttacked or gstMoving or gstHHChooseTarget)) = 0)and
+        (((State and gstFalling  ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0))and
+        (((State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0)))and
+        (CurAmmoGear = nil) then
+        begin
+        if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) <> 0 then
+           begin
+           StopTPUSound;
+           PlaySound(sndThrowRelease);
+           end;
+        xx:= Sign(dX)*Sin(Angle*pi/cMaxAngle);
+        yy:= -Cos(Angle*pi/cMaxAngle);
+             case Ammo[CurSlot, CurAmmo].AmmoType of
+                      amBazooka: FollowGear:= AddGear(round(X), round(Y), gtAmmo_Grenade, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor);
+                      amGrenade: FollowGear:= AddGear(round(X), round(Y), gtAmmo_Bomb,    0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, Ammo[CurSlot, CurAmmo].Timer);
+                          amUFO: FollowGear:= AddGear(round(X), round(Y), gtUFO,          0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor);
+                      amShotgun: begin
+                                 PlaySound(sndShotgunReload);
+                                 FollowGear:= AddGear(round(X + xx*20), round(Y + yy*20), gtShotgunShot,  0, xx * 0.5, 0.5 * yy);
+                                 end;
+                         amSkip: TurnTimeLeft:= 0;
+                   amPickHammer: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y) + cHHHalfHeight, gtPickHammer, 0);
+                         amRope: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y), gtRope, 0, xx, yy);
+                         amMine: AddGear(round(X) + Sign(dX) * 7, round(Y), gtMine, 0, Sign(dX) * 0.01, 0, 3000);
+                  end;
+        Power:= 0;
+        if CurAmmoGear <> nil then
+           begin
+           CurAmmoGear.Message:= Gear.Message;
+           exit
+           end else
+           begin
+           Message:= Message and not gm_Attack;
+           if not CurrentTeam.ExtDriven then SendIPC('a')
+           end;
+        AfterAttack
+        end
+     end
+end;
+
+procedure AfterAttack;
+begin
+with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^,
+     CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
+     begin
+        Inc(AttacksNum);
+        State:= State and not gstAttacking;
+        if Ammo[CurSlot, CurAmmo].NumPerTurn >= AttacksNum then isInMultiShoot:= true
+           else begin
+           TurnTimeLeft:= Ammoz[Ammo[CurSlot, CurAmmo].AmmoType].TimeAfterTurn;
+           State:= State or gstAttacked;
+           OnUsedAmmo(Ammo)
+           end;
+     AttackBar:= 0
+     end
+end;
+
+
+
 procedure doStepHedgehog(Gear: PGear); forward;
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepHedgehogDriven(Gear: PGear);
@@ -64,15 +136,13 @@
    end;
 
 if (Gear.Message and gm_Attack)<>0 then
-   if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0)and(CurAmmoGear = nil) then
+   if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0) then
       with PHedgehog(Gear.Hedgehog)^ do
-//        if ((Gear.State and gstFalling  ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0)
-//        and((Gear.State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0) then
             begin
             Gear.State:= Gear.State or gstAttacking;
-            if Gear.Power = cMaxPower then ParseCommand('-attack')
+            if Gear.Power = cMaxPower then Gear.Message:= Gear.Message and not gm_Attack
                else begin
-               if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Gear.Power:= cMaxPower
+               if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Attack(Gear)
                   else begin
                   if Gear.Power = 0 then
                      begin
@@ -84,6 +154,7 @@
                end;
             end else Gear.Message:= Gear.Message and not gm_Attack;
 
+if ((Gear.State and gstAttacking) <> 0) and ((Gear.Message and gm_Attack) = 0) then Attack(Gear);
 
 if (Gear.State and gstFalling) <> 0 then
    begin