hedgewars/uGearsHedgehog.pas
branchwebgl
changeset 9127 e350500c4edb
parent 8833 c13ebed437cb
parent 9080 9b42757d7e71
child 9160 fc46e75f6b72
equal deleted inserted replaced
8860:bde641cf53c8 9127:e350500c4edb
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
   255             if  (CurAmmoGear <> nil)
   255             if  (CurAmmoGear <> nil)
   256             and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)
   256             and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)
   257             and ((Gear^.Message and gmLJump) <> 0)
   257             and ((Gear^.Message and gmLJump) <> 0)
   258             and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
   258             and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
   259                 begin
   259                 begin
   260                 newDx:= dX;
   260                 if (CurAmmoGear^.AmmoType = amJetpack) and (Gear^.Message and gmPrecise <> 0) then
   261                 newDy:= dY;
   261                     begin
       
   262                     newDx:= xx*cMaxPower/cPowerDivisor;
       
   263                     newDy:= yy*cMaxPower/cPowerDivisor
       
   264                     end
       
   265                 else
       
   266                     begin
       
   267                     newDx:= dX;
       
   268                     newDy:= dY
       
   269                     end;
   262                 altUse:= true
   270                 altUse:= true
   263                 end
   271                 end
   264             else
   272             else
   265                 begin
   273                 begin
   266                 newDx:= xx*Power/cPowerDivisor;
   274                 newDx:= xx*Power/cPowerDivisor;
   383                                  end;
   391                                  end;
   384                     //amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
   392                     //amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
   385                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
   393                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
   386                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
   394                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
   387             end;
   395             end;
   388             if altUse and (newGear <> nil) then
   396             if altUse and (newGear <> nil) and 
       
   397                ((CurAmmoGear = nil) or (CurAmmoGear^.AmmoType <> amJetpack) or (Gear^.Message and gmPrecise = 0)) then
   389                begin
   398                begin
   390                newGear^.dX:= newDx / newGear^.Density;
   399                newGear^.dX:= newDx / newGear^.Density;
   391                newGear^.dY:= newDY / newGear^.Density
   400                newGear^.dY:= newDY / newGear^.Density
   392                end;
   401                end;
       
   402             if (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack) and
       
   403                (Gear^.Message and gmPrecise <> 0) and (hwRound(Y) > cWaterLine) then
       
   404                 newGear^.State:= newGear^.State or gstSubmersible;
   393 
   405 
   394             case CurAmmoType of
   406             case CurAmmoType of
   395                      amGrenade, amMolotov,
   407                      amGrenade, amMolotov,
   396                  amClusterBomb, amGasBomb,
   408                  amClusterBomb, amGasBomb,
   397                      amBazooka, amSnowball,
   409                      amBazooka, amSnowball,
   511             OnUsedAmmo(CurrentHedgehog^);
   523             OnUsedAmmo(CurrentHedgehog^);
   512             if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) and (((GameFlags and gfInfAttack) = 0) or PlacingHogs) then
   524             if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) and (((GameFlags and gfInfAttack) = 0) or PlacingHogs) then
   513                 begin
   525                 begin
   514                 if TagTurnTimeLeft = 0 then
   526                 if TagTurnTimeLeft = 0 then
   515                     TagTurnTimeLeft:= TurnTimeLeft;
   527                     TagTurnTimeLeft:= TurnTimeLeft;
   516                 TurnTimeLeft:=(Ammoz[a].TimeAfterTurn * cGetAwayTime) div 100;
   528                 if (CurAmmoGear <> nil) and (CurAmmoGear^.State and gstSubmersible <> 0) and (hwRound(CurAmmoGear^.Y) > cWaterLine) then
       
   529                      TurnTimeLeft:=(Ammoz[a].TimeAfterTurn * cGetAwayTime) div 25
       
   530                 else TurnTimeLeft:=(Ammoz[a].TimeAfterTurn * cGetAwayTime) div 100;
   517                 end;
   531                 end;
   518             if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) and (HHGear <> nil) then
   532             if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) and (HHGear <> nil) then
   519                 HHGear^.State:= HHGear^.State or gstAttacked;
   533                 HHGear^.State:= HHGear^.State or gstAttacked;
   520             if (Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then
   534             if (Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then
   521                 ApplyAmmoChanges(CurrentHedgehog^)
   535                 ApplyAmmoChanges(CurrentHedgehog^)
   544     if (Gear^.Timer mod frametime) = 0 then
   558     if (Gear^.Timer mod frametime) = 0 then
   545         inc(Gear^.Pos)
   559         inc(Gear^.Pos)
   546     end
   560     end
   547 else if Gear^.Timer = 1 then
   561 else if Gear^.Timer = 1 then
   548     begin
   562     begin
       
   563     Gear^.Hedgehog^.Effects[heFrozen]:= 0;
   549     Gear^.State:= Gear^.State or gstNoDamage;
   564     Gear^.State:= Gear^.State or gstNoDamage;
   550     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, CurrentHedgehog, EXPLAutoSound);
   565     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, CurrentHedgehog, EXPLAutoSound);
   551     AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
   566     AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
   552     DeleteGear(Gear);
   567     DeleteGear(Gear);
   553     SetAllToActive
   568     SetAllToActive
   795     if ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amRope) and ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving))
   810     if ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amRope) and ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving))
   796     or ((CurAmmoType = amPortalGun) and ((HHGear^.State and gstMoving) <> 0)) then
   811     or ((CurAmmoType = amPortalGun) and ((HHGear^.State and gstMoving) <> 0)) then
   797         da:= 2
   812         da:= 2
   798     else da:= 1;
   813     else da:= 1;
   799 
   814 
   800 if (((HHGear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then
   815 if ((HHGear^.Message and gmPrecise = 0) or ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack))) or (GameTicks mod 5 = 1) then
   801     if ((HHGear^.Message and gmUp) <> 0) and (HHGear^.Angle >= CurMinAngle + da) then
   816     if ((HHGear^.Message and gmUp) <> 0) and (HHGear^.Angle >= CurMinAngle + da) then
   802         dec(HHGear^.Angle, da)
   817         dec(HHGear^.Angle, da)
   803     else
   818     else
   804         if ((HHGear^.Message and gmDown) <> 0) and (HHGear^.Angle + da <= CurMaxAngle) then
   819         if ((HHGear^.Message and gmDown) <> 0) and (HHGear^.Angle + da <= CurMaxAngle) then
   805             inc(HHGear^.Angle, da)
   820             inc(HHGear^.Angle, da)
   958 if (not isFalling)
   973 if (not isFalling)
   959   and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   974   and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   960     begin
   975     begin
   961     Gear^.State:= Gear^.State and (not gstWinner);
   976     Gear^.State:= Gear^.State and (not gstWinner);
   962     Gear^.State:= Gear^.State and (not gstMoving);
   977     Gear^.State:= Gear^.State and (not gstMoving);
   963     while (TestCollisionYWithGear(Gear,1) = 0) and (not CheckGearDrowning(Gear)) do
   978     while (TestCollisionYWithGear(Gear,1) = 0) and (not CheckGearDrowning(Gear)) and (Gear <> nil) do
   964         Gear^.Y:= Gear^.Y+_1;
   979         Gear^.Y:= Gear^.Y + _1;
       
   980 
       
   981     // could become nil in CheckGearDrowning if ai's hog fails to respawn in ai survival
       
   982     if Gear = nil then exit;
   965     SetLittle(Gear^.dX);
   983     SetLittle(Gear^.dX);
   966     Gear^.dY:= _0
   984     Gear^.dY:= _0
   967     end
   985     end
   968 else
   986 else
   969     Gear^.State:= Gear^.State or gstMoving;
   987     Gear^.State:= Gear^.State or gstMoving;
   979         begin
   997         begin
   980         CheckHHDamage(Gear);
   998         CheckHHDamage(Gear);
   981         Gear^.dY:= _0;
   999         Gear^.dY:= _0;
   982         Gear^.Y:= Gear^.Y + _1
  1000         Gear^.Y:= Gear^.Y + _1
   983         end;
  1001         end;
       
  1002 
   984     CheckGearDrowning(Gear);
  1003     CheckGearDrowning(Gear);
       
  1004     // could become nil if ai's hog fails to respawn in ai survival
       
  1005     if Gear = nil then exit;
   985     // hide target cursor if current hog is drowning
  1006     // hide target cursor if current hog is drowning
   986     if (Gear^.State and gstDrowning) <> 0 then
  1007     if (Gear^.State and gstDrowning) <> 0 then
   987         if (CurrentHedgehog^.Gear = Gear) then
  1008         if (CurrentHedgehog^.Gear = Gear) then
   988             isCursorVisible:= false
  1009             isCursorVisible:= false
   989     end;
  1010     end;
  1061         and (HHGear^.dY > _0_39)
  1082         and (HHGear^.dY > _0_39)
  1062         and (CurAmmoType = amParachute) then
  1083         and (CurAmmoType = amParachute) then
  1063             HHGear^.Message:= HHGear^.Message or gmAttack;
  1084             HHGear^.Message:= HHGear^.Message or gmAttack;
  1064     // check for case with ammo
  1085     // check for case with ammo
  1065     t:= CheckGearNear(HHGear, gtCase, 36, 36);
  1086     t:= CheckGearNear(HHGear, gtCase, 36, 36);
  1066     if t <> nil then
  1087     if (t <> nil) and (t^.State and gstFrozen = 0) then
  1067         PickUp(HHGear, t)
  1088         PickUp(HHGear, t)
  1068     end;
  1089     end;
  1069 
  1090 
  1070 if (CurAmmoGear = nil) then
  1091 if (CurAmmoGear = nil) then
  1071     if (((HHGear^.Message and gmAttack) <> 0)
  1092     if (((HHGear^.Message and gmAttack) <> 0)