hedgewars/HHHandlers.inc
changeset 538 74219eadab5e
parent 534 92fb2b0d5117
child 540 b06c5aace2fa
equal deleted inserted replaced
537:4d2e60623e44 538:74219eadab5e
   252    if (Gear^.Message and gm_Down  )<>0 then if Gear^.Angle < CurMaxAngle then inc(Gear^.Angle);
   252    if (Gear^.Message and gm_Down  )<>0 then if Gear^.Angle < CurMaxAngle then inc(Gear^.Angle);
   253 end;
   253 end;
   254 
   254 
   255 procedure doStepHedgehog(Gear: PGear); forward;
   255 procedure doStepHedgehog(Gear: PGear); forward;
   256 ////////////////////////////////////////////////////////////////////////////////
   256 ////////////////////////////////////////////////////////////////////////////////
   257 procedure doStepHedgehogDriven(Gear: PGear);
   257 procedure doStepHedgehogMoving(Gear: PGear);
   258 var t: PGear;
       
   259 begin
       
   260 if isInMultiShoot and (Gear^.Damage = 0) then
       
   261    begin
       
   262    exit
       
   263    end;
       
   264 AllInactive:= false;
       
   265 
       
   266 if (TurnTimeLeft = 0) or (Gear^.Damage > 0) then
       
   267    begin
       
   268    TurnTimeLeft:= 0;
       
   269    Gear^.State:= Gear^.State and not gstHHDriven;
       
   270    if Gear^.Damage > 0 then
       
   271       Gear^.State:= Gear^.State and not (gstHHJumping or gstHHHJump);
       
   272    exit
       
   273    end;
       
   274    
       
   275 if ((Gear^.State and (gstFalling or gstMoving)) <> 0)
       
   276    or (StepTicks = cHHStepTicks)
       
   277    or (CurAmmoGear <> nil) then // we're moving
       
   278    begin
       
   279    // check for case with ammo
       
   280    t:= CheckGearNear(Gear, gtCase, 36, 36);
       
   281    if t <> nil then
       
   282       PickUp(Gear, t)
       
   283    end;
       
   284 
       
   285 if CurAmmoGear <> nil then
       
   286    begin
       
   287    CurAmmoGear^.Message:= Gear^.Message;
       
   288    exit
       
   289    end;
       
   290 
       
   291 if ((Gear^.Message and gm_Attack) <> 0) or
       
   292    ((Gear^.State and gstAttacking) <> 0)then Attack(Gear);
       
   293 
       
   294 if (Gear^.State and (gstFalling or gstMoving)) <> 0 then
       
   295    begin
       
   296    if ((Gear^.Message and gm_HJump) <> 0) and
       
   297       ((Gear^.State and gstHHJumping) <> 0) and
       
   298       ((Gear^.State and gstHHHJump) = 0) then
       
   299       if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then
       
   300          begin
       
   301          Gear^.State:= Gear^.State or gstHHHJump;
       
   302          Gear^.dY:= -_0_25;
       
   303          Gear^.dX:= SignAs(_0_02, Gear^.dX)
       
   304          end;
       
   305    Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
       
   306    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
       
   307    Gear^.X:= Gear^.X + Gear^.dX;
       
   308    Gear^.dY:= Gear^.dY + cGravity;
       
   309    if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0;
       
   310    Gear^.Y:= Gear^.Y + Gear^.dY;
       
   311    if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then
       
   312       begin
       
   313       CheckHHDamage(Gear);
       
   314       if ((hwAbs(Gear^.dX) + hwAbs(Gear^.dY)) < _0_55)
       
   315          and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX);
       
   316       Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping or gstHHHJump);
       
   317       AddGearCI(Gear);
       
   318       StepTicks:= 300;
       
   319       Gear^.dY:= _0
       
   320       end;
       
   321    CheckGearDrowning(Gear);
       
   322    exit
       
   323    end ;//else if Gear^.CollIndex = High(Longword) then AddIntersectorsCR(Gear);
       
   324 
       
   325    HedgehogChAngle(Gear);
       
   326    if StepTicks > 0 then dec(StepTicks);
       
   327    if (StepTicks = 0) then HedgehogStep(Gear)
       
   328 end;
       
   329 
       
   330 ////////////////////////////////////////////////////////////////////////////////
       
   331 procedure doStepHedgehogFree(Gear: PGear);
       
   332 var prevState: Longword;
   258 var prevState: Longword;
   333 begin
   259 begin
   334 prevState:= Gear^.State;
   260 prevState:= Gear^.State;
   335 if not TestCollisionYKick(Gear, 1) then
   261 if not TestCollisionYKick(Gear, 1) then
   336    begin
   262    begin
   337    if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then Gear^.dY:= _0;
   263    if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then Gear^.dY:= _0;
   338    Gear^.State:= Gear^.State or gstFalling or gstMoving;
   264    Gear^.State:= Gear^.State or gstFalling or gstMoving;
   339    Gear^.dY:= Gear^.dY + cGravity
   265    Gear^.dY:= Gear^.dY + cGravity
   340    end else begin
   266    end else
       
   267    if (not Gear^.dY.isNegative) then
       
   268    begin
   341    CheckHHDamage(Gear);
   269    CheckHHDamage(Gear);
   342    if ((hwAbs(Gear^.dX) + hwAbs(Gear^.dY)) < _0_55)
   270    if ((hwAbs(Gear^.dX) + hwAbs(Gear^.dY)) < _0_55)
   343       and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX);
   271       and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX);
   344    Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping);
   272 
       
   273    Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping or gstHHHJump);
       
   274 
   345    if Gear^.dY > _0 then Gear^.dY:= _0;
   275    if Gear^.dY > _0 then Gear^.dY:= _0;
   346    if ((Gear^.State and gstMoving) <> 0) then Gear^.dX:= Gear^.dX * Gear^.Friction
   276    if ((Gear^.State and gstMoving) <> 0) then Gear^.dX:= Gear^.dX * Gear^.Friction
   347    end;
   277    end;
   348 
   278 
   349 if (Gear^.State <> 0) then DeleteCI(Gear);
   279 if (Gear^.State <> 0) then DeleteCI(Gear);
   350 
   280                 
   351 if (Gear^.State and gstMoving) <> 0 then
   281 if (Gear^.State and gstMoving) <> 0 then
   352    if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then
   282    if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then
   353       if ((Gear^.State and gstFalling) = 0) then
   283       if ((Gear^.State and gstFalling) = 0) then
   354          if hwAbs(Gear^.dX) > _0_01 then
   284          if hwAbs(Gear^.dX) > _0_01 then
   355             if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_96; Gear^.Y:= Gear^.Y - _1 end else
   285             if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_96; Gear^.Y:= Gear^.Y - _1 end else
   364                                         end
   294                                         end
   365             else begin
   295             else begin
   366                  Gear^.State:= Gear^.State and not gstMoving;
   296                  Gear^.State:= Gear^.State and not gstMoving;
   367                  SetLittle(Gear^.dX)
   297                  SetLittle(Gear^.dX)
   368                  end
   298                  end
   369          else Gear^.dX:= -Gear^.Elasticity * Gear^.dX;
   299          else if hwAbs(Gear^.dX) > cLittle then Gear^.dX:= -Gear^.Elasticity * Gear^.dX
       
   300                                            else SetLittle(Gear^.dX);
   370 
   301 
   371 if ((Gear^.State and gstFalling) = 0)and
   302 if ((Gear^.State and gstFalling) = 0)and
   372    (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   303    (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   373    begin
   304    begin
   374    Gear^.State:= Gear^.State and not gstMoving;
   305    Gear^.State:= Gear^.State and not gstMoving;
   387       begin
   318       begin
   388       CheckHHDamage(Gear);
   319       CheckHHDamage(Gear);
   389       Gear^.dY:= _0;
   320       Gear^.dY:= _0;
   390       Gear^.Y:= Gear^.Y + _1
   321       Gear^.Y:= Gear^.Y + _1
   391       end;
   322       end;
   392    end else
   323    CheckGearDrowning(Gear)
       
   324    end
       
   325 end;
       
   326 
       
   327 procedure doStepHedgehogDriven(Gear: PGear);
       
   328 var t: PGear;
       
   329 begin
       
   330 if isInMultiShoot and (Gear^.Damage = 0) then
       
   331    begin
       
   332    exit
       
   333    end;
       
   334 AllInactive:= false;
       
   335 
       
   336 if (TurnTimeLeft = 0) or (Gear^.Damage > 0) then
       
   337    begin
       
   338    TurnTimeLeft:= 0;
       
   339    Gear^.State:= Gear^.State and not gstHHDriven;
       
   340    if Gear^.Damage > 0 then
       
   341       Gear^.State:= Gear^.State and not (gstHHJumping or gstHHHJump);
       
   342    exit
       
   343    end;
       
   344    
       
   345 if ((Gear^.State and (gstFalling or gstMoving)) <> 0)
       
   346    or (StepTicks = cHHStepTicks)
       
   347    or (CurAmmoGear <> nil) then // we're moving
       
   348    begin
       
   349    // check for case with ammo
       
   350    t:= CheckGearNear(Gear, gtCase, 36, 36);
       
   351    if t <> nil then
       
   352       PickUp(Gear, t)
       
   353    end;
       
   354 
       
   355 if CurAmmoGear <> nil then
       
   356    begin
       
   357    CurAmmoGear^.Message:= Gear^.Message;
       
   358    exit
       
   359    end;
       
   360 
       
   361 if ((Gear^.Message and gm_Attack) <> 0) or
       
   362    ((Gear^.State and gstAttacking) <> 0)then Attack(Gear);
       
   363 
       
   364 if (Gear^.State and (gstFalling or gstMoving)) <> 0 then
       
   365    begin
       
   366    if ((Gear^.Message and gm_HJump) <> 0) and
       
   367       ((Gear^.State and gstHHJumping) <> 0) and
       
   368       ((Gear^.State and gstHHHJump) = 0) then
       
   369       if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then
       
   370          begin
       
   371          Gear^.State:= Gear^.State or gstHHHJump;
       
   372          Gear^.dY:= -_0_25;
       
   373          Gear^.dX:= SignAs(_0_02, Gear^.dX)
       
   374          end;
       
   375    Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
       
   376 
       
   377 
       
   378    if ((Gear^.State and gstHHJumping) <> 0) and
       
   379       TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
       
   380 
       
   381    doStepHedgehogMoving(Gear);
       
   382    
       
   383    if (Gear^.State and (gstFalling or gstMoving)) = 0 then
       
   384       begin
       
   385       AddGearCI(Gear);
       
   386       StepTicks:= 300
       
   387       end;
       
   388    exit
       
   389    end;
       
   390 
       
   391    HedgehogChAngle(Gear);
       
   392    if StepTicks > 0 then dec(StepTicks);
       
   393    if (StepTicks = 0) then HedgehogStep(Gear)
       
   394 end;
       
   395 
       
   396 ////////////////////////////////////////////////////////////////////////////////
       
   397 procedure doStepHedgehogFree(Gear: PGear);
       
   398 var prevState: Longword;
       
   399 begin
       
   400 prevState:= Gear^.State;
       
   401 
       
   402 doStepHedgehogMoving(Gear);
       
   403 
       
   404 if (Gear^.State and gstMoving) = 0 then
   393    if Gear^.Health = 0 then
   405    if Gear^.Health = 0 then
   394       begin
   406       begin
   395       if AllInactive then
   407       if AllInactive then
   396          begin
   408          begin
   397          Gear^.State:= Gear^.State or gstNoDamage;
   409          Gear^.State:= Gear^.State or gstNoDamage;
   404       exit
   416       exit
   405       end;
   417       end;
   406 
   418 
   407 AllInactive:= false;
   419 AllInactive:= false;
   408 
   420 
   409 if (not CheckGearDrowning(Gear)) and
   421 if ((Gear^.State and gstMoving) = 0) then
   410    ((Gear^.State and gstMoving) = 0) then
       
   411    if ((Gear^.State and gstAnimation) = 0) and
   422    if ((Gear^.State and gstAnimation) = 0) and
   412       (prevState <> Gear^.State) then
   423       (prevState <> Gear^.State) then
   413       begin
   424       begin
   414       Gear^.State:= gstAnimation;
   425       Gear^.State:= gstAnimation;
   415       Gear^.Timer:= 150
   426       Gear^.Timer:= 150