hedgewars/HHHandlers.inc
changeset 32 78bff13b11c0
parent 16 b6f4b413dd41
child 37 2b7f2a43b999
equal deleted inserted replaced
31:99888245a4e8 32:78bff13b11c0
    29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    32  *)
    32  *)
    33 
    33 
       
    34 procedure Attack(Gear: PGear);
       
    35 var xx, yy: real;
       
    36 begin
       
    37 with Gear^,
       
    38      CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
       
    39      begin
       
    40      {$IFDEF DEBUGFILE}AddFileLog('Attack: Gear.State = '+inttostr(State)+' CurAmmoGear = '+inttostr(longword(CurAmmoGear)));{$ENDIF}
       
    41      if CurAmmoGear <> nil then
       
    42         begin
       
    43         Message:= Message and not gm_Attack;
       
    44         if not CurrentTeam.ExtDriven then SendIPC('a')
       
    45         end;
       
    46      if (((State and (gstHHDriven or gstAttacking)) = (gstHHDriven or gstAttacking))and
       
    47         ((State and (gstAttacked or gstMoving or gstHHChooseTarget)) = 0)and
       
    48         (((State and gstFalling  ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0))and
       
    49         (((State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0)))and
       
    50         (CurAmmoGear = nil) then
       
    51         begin
       
    52         if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) <> 0 then
       
    53            begin
       
    54            StopTPUSound;
       
    55            PlaySound(sndThrowRelease);
       
    56            end;
       
    57         xx:= Sign(dX)*Sin(Angle*pi/cMaxAngle);
       
    58         yy:= -Cos(Angle*pi/cMaxAngle);
       
    59              case Ammo[CurSlot, CurAmmo].AmmoType of
       
    60                       amBazooka: FollowGear:= AddGear(round(X), round(Y), gtAmmo_Grenade, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor);
       
    61                       amGrenade: FollowGear:= AddGear(round(X), round(Y), gtAmmo_Bomb,    0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, Ammo[CurSlot, CurAmmo].Timer);
       
    62                           amUFO: FollowGear:= AddGear(round(X), round(Y), gtUFO,          0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor);
       
    63                       amShotgun: begin
       
    64                                  PlaySound(sndShotgunReload);
       
    65                                  FollowGear:= AddGear(round(X + xx*20), round(Y + yy*20), gtShotgunShot,  0, xx * 0.5, 0.5 * yy);
       
    66                                  end;
       
    67                          amSkip: TurnTimeLeft:= 0;
       
    68                    amPickHammer: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y) + cHHHalfHeight, gtPickHammer, 0);
       
    69                          amRope: CurAmmoGear:= AddGear(round(Gear.X), round(Gear.Y), gtRope, 0, xx, yy);
       
    70                          amMine: AddGear(round(X) + Sign(dX) * 7, round(Y), gtMine, 0, Sign(dX) * 0.01, 0, 3000);
       
    71                   end;
       
    72         Power:= 0;
       
    73         if CurAmmoGear <> nil then
       
    74            begin
       
    75            CurAmmoGear.Message:= Gear.Message;
       
    76            exit
       
    77            end else
       
    78            begin
       
    79            Message:= Message and not gm_Attack;
       
    80            if not CurrentTeam.ExtDriven then SendIPC('a')
       
    81            end;
       
    82         AfterAttack
       
    83         end
       
    84      end
       
    85 end;
       
    86 
       
    87 procedure AfterAttack;
       
    88 begin
       
    89 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^,
       
    90      CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
       
    91      begin
       
    92         Inc(AttacksNum);
       
    93         State:= State and not gstAttacking;
       
    94         if Ammo[CurSlot, CurAmmo].NumPerTurn >= AttacksNum then isInMultiShoot:= true
       
    95            else begin
       
    96            TurnTimeLeft:= Ammoz[Ammo[CurSlot, CurAmmo].AmmoType].TimeAfterTurn;
       
    97            State:= State or gstAttacked;
       
    98            OnUsedAmmo(Ammo)
       
    99            end;
       
   100      AttackBar:= 0
       
   101      end
       
   102 end;
       
   103 
       
   104 
       
   105 
    34 procedure doStepHedgehog(Gear: PGear); forward;
   106 procedure doStepHedgehog(Gear: PGear); forward;
    35 ////////////////////////////////////////////////////////////////////////////////
   107 ////////////////////////////////////////////////////////////////////////////////
    36 procedure doStepHedgehogDriven(Gear: PGear);
   108 procedure doStepHedgehogDriven(Gear: PGear);
    37 const StepTicks: LongWord = 0;
   109 const StepTicks: LongWord = 0;
    38 var t: PGear;
   110 var t: PGear;
    62    CurAmmoGear.Message:= Gear.Message;
   134    CurAmmoGear.Message:= Gear.Message;
    63    exit
   135    exit
    64    end;
   136    end;
    65 
   137 
    66 if (Gear.Message and gm_Attack)<>0 then
   138 if (Gear.Message and gm_Attack)<>0 then
    67    if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0)and(CurAmmoGear = nil) then
   139    if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0) then
    68       with PHedgehog(Gear.Hedgehog)^ do
   140       with PHedgehog(Gear.Hedgehog)^ do
    69 //        if ((Gear.State and gstFalling  ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0)
       
    70 //        and((Gear.State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0) then
       
    71             begin
   141             begin
    72             Gear.State:= Gear.State or gstAttacking;
   142             Gear.State:= Gear.State or gstAttacking;
    73             if Gear.Power = cMaxPower then ParseCommand('-attack')
   143             if Gear.Power = cMaxPower then Gear.Message:= Gear.Message and not gm_Attack
    74                else begin
   144                else begin
    75                if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Gear.Power:= cMaxPower
   145                if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Attack(Gear)
    76                   else begin
   146                   else begin
    77                   if Gear.Power = 0 then
   147                   if Gear.Power = 0 then
    78                      begin
   148                      begin
    79                      AttackBar:= CurrentTeam.AttackBar;
   149                      AttackBar:= CurrentTeam.AttackBar;
    80                      PlaySound(sndThrowPowerUp)
   150                      PlaySound(sndThrowPowerUp)
    82                   inc(Gear.Power)
   152                   inc(Gear.Power)
    83                   end
   153                   end
    84                end;
   154                end;
    85             end else Gear.Message:= Gear.Message and not gm_Attack;
   155             end else Gear.Message:= Gear.Message and not gm_Attack;
    86 
   156 
       
   157 if ((Gear.State and gstAttacking) <> 0) and ((Gear.Message and gm_Attack) = 0) then Attack(Gear);
    87 
   158 
    88 if (Gear.State and gstFalling) <> 0 then
   159 if (Gear.State and gstFalling) <> 0 then
    89    begin
   160    begin
    90    // it could be the source to trick: double-backspace jump -> vertical wall
   161    // it could be the source to trick: double-backspace jump -> vertical wall
    91    // collision - > (abs(Gear.dX) < 0.0000002) -> backspace -> even more high jump
   162    // collision - > (abs(Gear.dX) < 0.0000002) -> backspace -> even more high jump