hedgewars/uGearsHedgehog.pas
changeset 10015 4feced261c68
parent 9998 736015b847e3
parent 9954 bf51bc7e2808
child 10105 8c5fa1d15bd5
equal deleted inserted replaced
10014:56d2f2d5aad8 10015:4feced261c68
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uGearsHedgehog;
    21 unit uGearsHedgehog;
    22 interface
    22 interface
    23 uses uTypes, uGearsHandlersMess; 
    23 uses uTypes, uGearsHandlersMess;
    24 
    24 
    25 procedure doStepHedgehog(Gear: PGear);
    25 procedure doStepHedgehog(Gear: PGear);
    26 procedure AfterAttack;
    26 procedure AfterAttack;
    27 procedure HedgehogStep(Gear: PGear);
    27 procedure HedgehogStep(Gear: PGear);
    28 procedure doStepHedgehogMoving(Gear: PGear);
    28 procedure doStepHedgehogMoving(Gear: PGear);
   124             LoadHedgehogHat(HHGear^.Hedgehog^, 'Reserved/chef')
   124             LoadHedgehogHat(HHGear^.Hedgehog^, 'Reserved/chef')
   125         else if prevAmmo = amKnife then
   125         else if prevAmmo = amKnife then
   126             LoadHedgehogHat(HHGear^.Hedgehog^, Hat);
   126             LoadHedgehogHat(HHGear^.Hedgehog^, Hat);
   127         end;
   127         end;
   128     // Try again in the next slot
   128     // Try again in the next slot
   129     if (CurAmmoType = prevAmmo) and (slot < cMaxSlotIndex) then 
   129     if (CurAmmoType = prevAmmo) and (slot < cMaxSlotIndex) then
   130         begin
   130         begin
   131         inc(slot);
   131         inc(slot);
   132         HHGear^.MsgParam:= slot;
   132         HHGear^.MsgParam:= slot;
   133         ChangeAmmo(HHGear)
   133         ChangeAmmo(HHGear)
   134         end
   134         end
   414                                  end;
   414                                  end;
   415                     //amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
   415                     //amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
   416                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 0);
   416                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 0);
   417                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
   417                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
   418             end;
   418             end;
   419             if altUse and (newGear <> nil) and 
   419             if altUse and (newGear <> nil) and
   420                ((CurAmmoGear = nil) or (CurAmmoGear^.AmmoType <> amJetpack) or (Gear^.Message and gmPrecise = 0)) then
   420                ((CurAmmoGear = nil) or (CurAmmoGear^.AmmoType <> amJetpack) or (Gear^.Message and gmPrecise = 0)) then
   421                begin
   421                begin
   422                newGear^.dX:= newDx / newGear^.Density;
   422                newGear^.dX:= newDx / newGear^.Density;
   423                newGear^.dY:= newDY / newGear^.Density
   423                newGear^.dY:= newDY / newGear^.Density
   424                end;
   424                end;
   468 
   468 
   469             if (newGear <> nil) and ((Ammoz[newGear^.AmmoType].Ammo.Propz and ammoprop_SetBounce) <> 0) then
   469             if (newGear <> nil) and ((Ammoz[newGear^.AmmoType].Ammo.Propz and ammoprop_SetBounce) <> 0) then
   470                 begin
   470                 begin
   471                 elastic:=  int2hwfloat(CurWeapon^.Bounciness) / _1000;
   471                 elastic:=  int2hwfloat(CurWeapon^.Bounciness) / _1000;
   472 
   472 
   473                 if elastic < _1 then
   473             if elastic < _1 then
   474                     newGear^.Elasticity:= newGear^.Elasticity * elastic
   474                 newGear^.Elasticity:= newGear^.Elasticity * elastic
   475                 else if elastic > _1 then
   475             else if elastic > _1 then
   476                     newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic);
   476                 newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic);
   477     (* Experimented with friction modifier. Didn't seem helpful
   477 (* Experimented with friction modifier. Didn't seem helpful
   478                 fric:= int2hwfloat(CurWeapon^.Bounciness) / _250;
   478             fric:= int2hwfloat(CurWeapon^.Bounciness) / _250;
   479                 if fric < _1 then newGear^.Friction:= newGear^.Friction * fric
   479             if fric < _1 then newGear^.Friction:= newGear^.Friction * fric
   480                 else if fric > _1 then newGear^.Friction:= _1 - ((_1-newGear^.Friction) / fric)*)
   480             else if fric > _1 then newGear^.Friction:= _1 - ((_1-newGear^.Friction) / fric)*)
   481                 end;
   481             end;
   482 
   482 
   483 
   483 
   484             uStats.AmmoUsed(CurAmmoType);
   484             uStats.AmmoUsed(CurAmmoType);
   485 
   485 
   486             if not (SpeechText = '') then
   486             if not (SpeechText = '') then
   494                     end;
   494                     end;
   495                 SpeechText:= ''
   495                 SpeechText:= ''
   496                 end;
   496                 end;
   497 
   497 
   498             Power:= 0;
   498             Power:= 0;
   499             if (CurAmmoGear <> nil)
   499             if (CurAmmoGear <> nil) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then
   500                 and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then
   500                 begin
   501                 begin
   501                 if CurAmmoType in [amRope,amResurrector] then
   502                 if CurAmmoType in [amRope,amResurrector] then Message:= Message or gmAttack;
   502                     Message:= Message or gmAttack;
   503                 CurAmmoGear^.Message:= Message
   503                 CurAmmoGear^.Message:= Message
   504                 end
   504                 end
   505             else
   505             else
   506                 begin
   506                 begin
   507                 if not CurrentTeam^.ExtDriven
   507                 if (not CurrentTeam^.ExtDriven) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then
   508                 and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then
       
   509                     SendIPC(_S'a');
   508                     SendIPC(_S'a');
   510                 AfterAttack;
   509                 AfterAttack;
   511                 end
   510                 end
   512             end
   511             end
   513         else
   512         else
   829 
   828 
   830 procedure HedgehogChAngle(HHGear: PGear);
   829 procedure HedgehogChAngle(HHGear: PGear);
   831 var da: LongWord;
   830 var da: LongWord;
   832 begin
   831 begin
   833 with HHGear^.Hedgehog^ do
   832 with HHGear^.Hedgehog^ do
   834     if (((CurAmmoType = amRope) or ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amRope))) and 
   833     if (((CurAmmoType = amRope) or ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amRope))) and
   835             ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving))
   834             ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving))
   836     or ((CurAmmoType = amPortalGun) and ((HHGear^.State and gstMoving) <> 0)) then
   835     or ((CurAmmoType = amPortalGun) and ((HHGear^.State and gstMoving) <> 0)) then
   837         da:= 2
   836         da:= 2
   838     else da:= 1;
   837     else da:= 1;
   839 
   838 
   876             doStepFallingGear(Gear);
   875             doStepFallingGear(Gear);
   877             Gear^.dX:= Gear^.dX * _0_8
   876             Gear^.dX:= Gear^.dX * _0_8
   878             end;
   877             end;
   879         if (land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0) then
   878         if (land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0) then
   880             Gear^.dY:= _0;
   879             Gear^.dY:= _0;
   881         Gear^.State:= Gear^.State and not gstCollision 
   880         Gear^.State:= Gear^.State and (not gstCollision)
   882         end;
   881         end;
   883     Gear^.State:= Gear^.State or gstMoving;
   882     Gear^.State:= Gear^.State or gstMoving;
   884     if (Gear^.State and gstHHDriven <> 0) and
   883     if (Gear^.State and gstHHDriven <> 0) and
   885        (not CurrentTeam^.ExtDriven) and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > _0_003) then
   884        (not CurrentTeam^.ExtDriven) and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > _0_003) then
   886         begin
   885         begin
   902         end
   901         end
   903     end
   902     end
   904 else
   903 else
   905     begin
   904     begin
   906     land:= TestCollisionYwithGear(Gear, 1);
   905     land:= TestCollisionYwithGear(Gear, 1);
   907     if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0) 
   906     if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0)
   908     and ((land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0)) 
   907     and ((land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0))
   909     and ((Gear^.State and gstHHJumping) <> 0) then
   908     and ((Gear^.State and gstHHJumping) <> 0) then
   910         SetLittle(Gear^.dX);
   909         SetLittle(Gear^.dX);
   911 
   910 
   912     if not Gear^.dY.isNegative then
   911     if not Gear^.dY.isNegative then
   913         begin
   912         begin
   931                 end;
   930                 end;
   932             Gear^.State:= Gear^.State and (not (gstHHJumping or gstHHHJump));
   931             Gear^.State:= Gear^.State and (not (gstHHJumping or gstHHHJump));
   933             if (land and lfBouncy = 0) or (Gear^.dX.QWordValue < _0_02.QWordValue) then
   932             if (land and lfBouncy = 0) or (Gear^.dX.QWordValue < _0_02.QWordValue) then
   934                 Gear^.dY:= _0
   933                 Gear^.dY:= _0
   935             end;
   934             end;
   936         Gear^.State:= Gear^.State and not gstCollision 
   935         Gear^.State:= Gear^.State and (not gstCollision)
   937         end
   936         end
   938     else
   937     else
   939         Gear^.dY:= Gear^.dY + cGravity;
   938         Gear^.dY:= Gear^.dY + cGravity;
   940 
   939 
   941     if ((Gear^.State and gstMoving) <> 0) then
   940     if ((Gear^.State and gstMoving) <> 0) then
  1056             begin
  1055             begin
  1057             CheckHHDamage(Gear);
  1056             CheckHHDamage(Gear);
  1058             Gear^.dY:= _0;
  1057             Gear^.dY:= _0;
  1059             Gear^.Y:= Gear^.Y + _1
  1058             Gear^.Y:= Gear^.Y + _1
  1060             end;
  1059             end;
  1061         Gear^.State:= Gear^.State and not gstCollision 
  1060         Gear^.State:= Gear^.State and (not gstCollision)
  1062         end;
  1061         end;
  1063 
  1062 
  1064     // could become nil if ai's hog fails to respawn in ai survival
  1063     // could become nil if ai's hog fails to respawn in ai survival
  1065     if Gear = nil then exit;
  1064     if Gear = nil then exit;
  1066     // hide target cursor if current hog is drowning
  1065     // hide target cursor if current hog is drowning
  1094 Hedgehog:= HHGear^.Hedgehog;
  1093 Hedgehog:= HHGear^.Hedgehog;
  1095 if not isInMultiShoot then
  1094 if not isInMultiShoot then
  1096     AllInactive:= false
  1095     AllInactive:= false
  1097 else if Hedgehog^.CurAmmoType in [amShotgun, amDEagle, amSniperRifle] then
  1096 else if Hedgehog^.CurAmmoType in [amShotgun, amDEagle, amSniperRifle] then
  1098     HHGear^.Message:= 0;
  1097     HHGear^.Message:= 0;
       
  1098 
       
  1099 if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Utility) <> 0) and isInMultiShoot then
       
  1100     AllInactive:= true
       
  1101 else if not isInMultiShoot then
       
  1102     AllInactive:= false;
  1099 
  1103 
  1100 if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then
  1104 if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then
  1101     begin
  1105     begin
  1102     if (Hedgehog^.CurAmmoType = amKnife) then
  1106     if (Hedgehog^.CurAmmoType = amKnife) then
  1103        LoadHedgehogHat(Hedgehog^, Hedgehog^.Hat);
  1107        LoadHedgehogHat(Hedgehog^, Hedgehog^.Hat);
  1342 CheckGearDrowning(Gear);
  1346 CheckGearDrowning(Gear);
  1343 if Gear = nil then exit;
  1347 if Gear = nil then exit;
  1344 tX:= Gear^.X;
  1348 tX:= Gear^.X;
  1345 if WorldWrap(Gear) then
  1349 if WorldWrap(Gear) then
  1346     begin
  1350     begin
  1347     if (WorldEdge <> weBounce) and (Gear = CurrentHedgehog^.Gear) and 
  1351     if (WorldEdge <> weBounce) and (Gear = CurrentHedgehog^.Gear) and
  1348        (CurAmmoGear <> nil) and (CurAmmoGear^.Kind =gtRope) and (CurAmmoGear^.Elasticity <> _0) then
  1352        (CurAmmoGear <> nil) and (CurAmmoGear^.Kind =gtRope) and (CurAmmoGear^.Elasticity <> _0) then
  1349        CurAmmoGear^.PortalCounter:= 1;
  1353        CurAmmoGear^.PortalCounter:= 1;
  1350     if (WorldEdge = weWrap) and ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0))  then
  1354     if (WorldEdge = weWrap) and ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0))  then
  1351         begin
  1355         begin
  1352         Gear^.X:= tX;
  1356         Gear^.X:= tX;