hedgewars/uGearsHedgehog.pas
branchios-develop
changeset 13418 ba39a1d396c0
parent 13404 3d6aae2ae698
child 13468 f1d349a52bc7
equal deleted inserted replaced
13416:6e8b807bda4b 13418:ba39a1d396c0
    45     t: byte;
    45     t: byte;
    46 begin
    46 begin
    47     t:= 0;
    47     t:= 0;
    48     while (TeamsArray[t] <> CurrentTeam) do inc(t);
    48     while (TeamsArray[t] <> CurrentTeam) do inc(t);
    49 
    49 
    50     SendHogSpeech(#1 + char(t) + 'AFK');
    50     AddChatString(#2 + FormatA(trmsg[sidAutoSkip], CurrentTeam^.TeamName));
    51 
    51 
    52     ParseCommand('/skip', true)
    52     ParseCommand('/skip', true)
    53 end;
    53 end;
    54 
    54 
    55 // Shouldn't more of this ammo switching stuff be moved to uAmmos ?
    55 // Shouldn't more of this ammo switching stuff be moved to uAmmos ?
    74     while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do
    74     while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do
    75         inc(ammoidx);
    75         inc(ammoidx);
    76 
    76 
    77     if (MultiShootAttacks > 0) then
    77     if (MultiShootAttacks > 0) then
    78         begin
    78         begin
    79         if (CurAmmoType = amSniperRifle) and ((GameFlags and gfArtillery) = 0) then
    79         if (Effects[heArtillery] = 2) then
    80             cArtillery := false;
    80             Effects[heArtillery]:= 0;
    81         if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0 then
    81         if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0 then
    82             begin
    82             begin
    83             MultiShootAttacks:= Ammoz[CurAmmoType].Ammo.NumPerTurn;
    83             MultiShootAttacks:= Ammoz[CurAmmoType].Ammo.NumPerTurn;
    84             AfterAttack
    84             AfterAttack
    85             end
    85             end
   139 s:= false;
   139 s:= false;
   140 
   140 
   141 weap:= TAmmoType(HHGear^.MsgParam);
   141 weap:= TAmmoType(HHGear^.MsgParam);
   142 Hedgehog:= HHGear^.Hedgehog;
   142 Hedgehog:= HHGear^.Hedgehog;
   143 
   143 
       
   144 HHGear^.Message:= HHGear^.Message and (not gmWeapon);
       
   145 
       
   146 // Special case: amNothing unselects weapon
       
   147 if weap = amNothing then
       
   148     begin
       
   149     HHGear^.Hedgehog^.CurAmmoType:= amNothing;
       
   150     ApplyAmmoChanges(HHGear^.Hedgehog^);
       
   151     exit
       
   152     end;
       
   153 
   144 if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then
   154 if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then
   145     exit; // weapon is not activated yet
   155     exit; // weapon is not activated yet
   146 
   156 
   147 HHGear^.MsgParam:= Ammoz[weap].Slot;
   157 HHGear^.MsgParam:= Ammoz[weap].Slot;
   148 
   158 
   149 t:= cMaxSlotAmmoIndex;
   159 t:= cMaxSlotAmmoIndex;
   150 
       
   151 HHGear^.Message:= HHGear^.Message and (not gmWeapon);
       
   152 
   160 
   153 prevState:= HHGear^.State;
   161 prevState:= HHGear^.State;
   154 newState:= prevState;
   162 newState:= prevState;
   155 with Hedgehog^ do
   163 with Hedgehog^ do
   156     while (CurAmmoType <> weap) and (t >= 0) do
   164     while (CurAmmoType <> weap) and (t >= 0) do
   259             yy:= -AngleCos(Angle);
   267             yy:= -AngleCos(Angle);
   260 
   268 
   261             lx:= X + int2hwfloat(round(GetLaunchX(CurAmmoType, hwSign(dX), Angle)));
   269             lx:= X + int2hwfloat(round(GetLaunchX(CurAmmoType, hwSign(dX), Angle)));
   262             ly:= Y + int2hwfloat(round(GetLaunchY(CurAmmoType, Angle)));
   270             ly:= Y + int2hwfloat(round(GetLaunchY(CurAmmoType, Angle)));
   263 
   271 
   264             if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then
   272             if ((Gear^.State and gstHHHJump) <> 0) and (Effects[heArtillery] = 0) then
   265                 xx:= - xx;
   273                 xx:= - xx;
   266             if Ammoz[CurAmmoType].Ammo.AttackVoice <> sndNone then
   274             if Ammoz[CurAmmoType].Ammo.AttackVoice <> sndNone then
   267                 AddVoice(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack);
   275                 AddVoice(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack);
   268 
   276 
   269 // Initiating alt attack
   277 // Initiating alt attack
   313                                  newGear:= AddGear(hwRound(lx), hwRound(ly), gtKnife,    0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, 0);
   321                                  newGear:= AddGear(hwRound(lx), hwRound(ly), gtKnife,    0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, 0);
   314                                  newGear^.State:= newGear^.State or gstMoving;
   322                                  newGear^.State:= newGear^.State or gstMoving;
   315                                  newGear^.Radius:= 4 // temporarily shrink so it doesn't instantly embed in the ground
   323                                  newGear^.Radius:= 4 // temporarily shrink so it doesn't instantly embed in the ground
   316                                  end;
   324                                  end;
   317                        amDEagle: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtDEagleShot, 0, xx * _0_5, yy * _0_5, 0);
   325                        amDEagle: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtDEagleShot, 0, xx * _0_5, yy * _0_5, 0);
       
   326                       amMinigun: begin
       
   327                                  PlaySound(sndMinigun);
       
   328                                  newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtMinigun, 0, xx * _0_5, yy * _0_5, 0);
       
   329                                  end;
   318                       amSineGun: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtSineGunShot, 0, xx * _0_5, yy * _0_5, 0);
   330                       amSineGun: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtSineGunShot, 0, xx * _0_5, yy * _0_5, 0);
   319                     amPortalGun: begin
   331                     amPortalGun: begin
   320                                  newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtPortal, 0, xx * _0_6, yy * _0_6,
   332                                  newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtPortal, 0, xx * _0_6, yy * _0_6,
   321                                  // set selected color
   333                                  // set selected color
   322                                  CurWeapon^.Pos);
   334                                  CurWeapon^.Pos);
   464                    amSeduction, amBallgun,
   476                    amSeduction, amBallgun,
   465                      amJetpack, amBirdy,
   477                      amJetpack, amBirdy,
   466                 amFlamethrower, amLandGun,
   478                 amFlamethrower, amLandGun,
   467                  amResurrector, //amStructure,
   479                  amResurrector, //amStructure,
   468                       amTardis, amPiano,
   480                       amTardis, amPiano,
   469                       amIceGun, amRubber: CurAmmoGear:= newGear;
   481                       amIceGun, amRubber,
       
   482                       amMinigun: CurAmmoGear:= newGear;
   470             end;
   483             end;
   471             if CurAmmoType = amCake then FollowGear:= newGear;
   484             if CurAmmoType = amCake then FollowGear:= newGear;
   472             if CurAmmoType = amAirMine then newGear^.Hedgehog:= nil;
   485             if CurAmmoType = amAirMine then newGear^.Hedgehog:= nil;
   473 
   486 
   474             if ((CurAmmoType = amMine) or (CurAmmoType = amSMine) or (CurAmmoType = amAirMine)) and (GameFlags and gfInfAttack <> 0) then
   487             if ((CurAmmoType = amMine) or (CurAmmoType = amSMine) or (CurAmmoType = amAirMine)) and (GameFlags and gfInfAttack <> 0) then
   714         end;
   727         end;
   715 end;
   728 end;
   716 
   729 
   717 ////////////////////////////////////////////////////////////////////////////////
   730 ////////////////////////////////////////////////////////////////////////////////
   718 procedure PickUp(HH, Gear: PGear);
   731 procedure PickUp(HH, Gear: PGear);
   719 var s: ansistring;
   732 var ag, gi: PGear;
   720     i: LongInt;
       
   721     vga: PVisualGear;
       
   722     ag, gi: PGear;
       
   723 begin
   733 begin
   724 if Gear^.State and gstFrozen <> 0 then exit;
   734 if Gear^.State and gstFrozen <> 0 then exit;
   725 
   735 
   726 Gear^.Message:= gmDestroy;
   736 Gear^.Message:= gmDestroy;
   727 if (Gear^.Pos and posCaseExplode) <> 0 then
   737 if (Gear^.Pos and posCaseExplode) <> 0 then
   746                         AddRandomness(GameTicks);
   756                         AddRandomness(GameTicks);
   747 
   757 
   748                         gi := GearsList;
   758                         gi := GearsList;
   749                         while gi <> nil do
   759                         while gi <> nil do
   750                             begin
   760                             begin
   751                             if (gi^.Kind = gtGenericFaller) and (gi^.State and gstInvisible <> 0) then
   761                             if (gi^.Kind = gtGenericFaller) and (gi^.Tag = 1) then
   752                                 begin
   762                                 begin
   753                                 gi^.Active:= true;
   763                                 gi^.Active:= true;
   754                                 gi^.State:= gi^.State or gstTmpFlag;
   764                                 gi^.State:= gi^.State or gstTmpFlag;
   755                                 gi^.X:= int2hwFloat(GetRandom(rightX-leftX)+leftX);
   765                                 gi^.X:= int2hwFloat(GetRandom(rightX-leftX)+leftX);
   756                                 gi^.Y:= int2hwFloat(GetRandom(LAND_HEIGHT-topY)+topY);
   766                                 gi^.Y:= int2hwFloat(GetRandom(LAND_HEIGHT-topY)+topY);
   766                     end;
   776                     end;
   767      posCaseHealth: begin
   777      posCaseHealth: begin
   768                     PlaySound(sndShotgunReload);
   778                     PlaySound(sndShotgunReload);
   769                     inc(HH^.Health, Gear^.Health);
   779                     inc(HH^.Health, Gear^.Health);
   770                     HH^.Hedgehog^.Effects[hePoisoned] := 0;
   780                     HH^.Hedgehog^.Effects[hePoisoned] := 0;
   771                     s:= IntToStr(Gear^.Health);
       
   772                     AddCaption(FormatA(trmsg[sidHealthGain], s), HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
       
   773                     RenderHealth(HH^.Hedgehog^);
   781                     RenderHealth(HH^.Hedgehog^);
   774                     RecountTeamHealth(HH^.Hedgehog^.Team);
   782                     RecountTeamHealth(HH^.Hedgehog^.Team);
   775 
   783                     HHHeal(HH^.Hedgehog, Gear^.Health, true);
   776                     i:= 0;
       
   777                     while (i < Gear^.Health) and (i <= 1000) do
       
   778                         begin
       
   779                         vga:= AddVisualGear(hwRound(HH^.X), hwRound(HH^.Y), vgtStraightShot);
       
   780                         if vga <> nil then
       
   781                             with vga^ do
       
   782                                 begin
       
   783                                 Tint:= $00FF00FF;
       
   784                                 State:= ord(sprHealth)
       
   785                                 end;
       
   786                         inc(i, 5);
       
   787                         end;
       
   788                     end;
   784                     end;
   789      end
   785      end
   790 end;
   786 end;
   791 
   787 
   792 procedure HedgehogStep(Gear: PGear);
   788 procedure HedgehogStep(Gear: PGear);
   793 var PrevdX: LongInt;
   789 var PrevdX: LongInt;
   794     CurWeapon: PAmmo;
   790     CurWeapon: PAmmo;
   795     portals: PGearArrayS;
       
   796 begin
   791 begin
   797 CurWeapon:= GetCurAmmoEntry(Gear^.Hedgehog^);
   792 CurWeapon:= GetCurAmmoEntry(Gear^.Hedgehog^);
   798 if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then
   793 if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then
   799     begin
   794     begin
   800     if isCursorVisible then
   795     if isCursorVisible then
   833                     Gear^.Y:= Gear^.Y - _1;
   828                     Gear^.Y:= Gear^.Y - _1;
   834             if (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) = 0) and
   829             if (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) = 0) and
   835                (TestCollisionYwithGear(Gear, -1) = 0) then
   830                (TestCollisionYwithGear(Gear, -1) = 0) then
   836                 begin
   831                 begin
   837                 Gear^.dY:= -_0_15;
   832                 Gear^.dY:= -_0_15;
   838                 if not cArtillery then
   833                 if Gear^.Hedgehog^.Effects[heArtillery] = 0 then
   839                     Gear^.dX:= SignAs(_0_15, Gear^.dX);
   834                     Gear^.dX:= SignAs(_0_15, Gear^.dX);
   840                 Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   835                 Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   841                 PlaySoundV(sndJump1, Gear^.Hedgehog^.Team^.voicepack);
   836                 PlaySoundV(sndJump1, Gear^.Hedgehog^.Team^.voicepack);
   842         exit
   837         exit
   843         end;
   838         end;
   853         Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   848         Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   854         PlaySoundV(sndJump3, Gear^.Hedgehog^.Team^.voicepack);
   849         PlaySoundV(sndJump3, Gear^.Hedgehog^.Team^.voicepack);
   855         exit
   850         exit
   856         end;
   851         end;
   857 
   852 
   858     if (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.State and gstMoving = 0) then
   853     if (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.State and gstMoving = 0) and 
   859         begin
   854 		(CheckGearNear(Gear, gtPortal, 26, 26) <> nil) then 
   860         // slightly inefficient since it doesn't halt after one portal, maybe could add a param to GearsNear for number desired.
   855 		Gear^.PortalCounter:= 0;
   861         portals:= GearsNear(Gear^.X, Gear^.Y, gtPortal, 26);
       
   862         if portals.size = 0 then Gear^.PortalCounter:= 0
       
   863         end;
       
   864     PrevdX:= hwSign(Gear^.dX);
   856     PrevdX:= hwSign(Gear^.dX);
   865     if (Gear^.Message and gmLeft  )<>0 then
   857     if (Gear^.Message and gmLeft  )<>0 then
   866         Gear^.dX:= -cLittle else
   858         Gear^.dX:= -cLittle else
   867     if (Gear^.Message and gmRight )<>0 then
   859     if (Gear^.Message and gmRight )<>0 then
   868         Gear^.dX:=  cLittle
   860         Gear^.dX:=  cLittle
   878         end;
   870         end;
   879     DeleteCI(Gear); // must be after exit!! (see previous line)
   871     DeleteCI(Gear); // must be after exit!! (see previous line)
   880 
   872 
   881     Gear^.Hedgehog^.visStepPos:= (Gear^.Hedgehog^.visStepPos + 1) and 7;
   873     Gear^.Hedgehog^.visStepPos:= (Gear^.Hedgehog^.visStepPos + 1) and 7;
   882 
   874 
   883     if (not cArtillery or
   875     if ((Gear^.Hedgehog^.Effects[heArtillery] = 0) or
   884            ((CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtBlowTorch))) and
   876            ((CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtBlowTorch))) and
   885        ((Gear^.Message and gmPrecise) = 0) then
   877        ((Gear^.Message and gmPrecise) = 0) then
   886         MakeHedgehogsStep(Gear);
   878         MakeHedgehogsStep(Gear);
   887 
   879 
   888     SetAllHHToActive(false);
   880     SetAllHHToActive(false);
  1047 
  1039 
  1048         CheckHHDamage(Gear);
  1040         CheckHHDamage(Gear);
  1049 
  1041 
  1050         if (land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0) then
  1042         if (land and lfBouncy = 0) or (Gear^.State and gstCollision <> 0) then
  1051             begin
  1043             begin
  1052             if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery)
  1044             if ((Gear^.State and gstHHHJump) <> 0) and (Gear^.Hedgehog^.Effects[heArtillery] = 0)
  1053             and (Gear^.dX.QWordValue < _0_02.QWordValue) then
  1045             and (Gear^.dX.QWordValue < _0_02.QWordValue) then
  1054                 begin
  1046                 begin
  1055                 if land and lfBouncy <> 0 then
  1047                 if land and lfBouncy <> 0 then
  1056                     Gear^.dY:= _0;
  1048                     Gear^.dY:= _0;
  1057                 Gear^.dX.isNegative:= not Gear^.dX.isNegative // landing after high jump
  1049                 Gear^.dX.isNegative:= not Gear^.dX.isNegative // landing after high jump
  1352     if ((HHGear^.Message and gmHJump) <> 0) and wasJumping and ((HHGear^.State and gstHHHJump) = 0) then
  1344     if ((HHGear^.Message and gmHJump) <> 0) and wasJumping and ((HHGear^.State and gstHHHJump) = 0) then
  1353         if (not (hwAbs(HHGear^.dX) > cLittle)) and (HHGear^.dY < -_0_02) then
  1345         if (not (hwAbs(HHGear^.dX) > cLittle)) and (HHGear^.dY < -_0_02) then
  1354             begin
  1346             begin
  1355             HHGear^.State:= HHGear^.State or gstHHHJump;
  1347             HHGear^.State:= HHGear^.State or gstHHHJump;
  1356             HHGear^.dY:= -_0_25;
  1348             HHGear^.dY:= -_0_25;
  1357             if not cArtillery then
  1349             if (Hedgehog^.Effects[heArtillery] = 0) then
  1358                 HHGear^.dX:= -SignAs(_0_02, HHGear^.dX);
  1350                 HHGear^.dX:= -SignAs(_0_02, HHGear^.dX);
  1359             PlaySoundV(sndJump2, Hedgehog^.Team^.voicepack)
  1351             PlaySoundV(sndJump2, Hedgehog^.Team^.voicepack)
  1360             end;
  1352             end;
  1361 
  1353 
  1362     HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
  1354     HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
  1363 
  1355 
  1364     if (not cArtillery) and wasJumping and (TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0) then
  1356     if (Hedgehog^.Effects[heArtillery] = 0) and wasJumping and (TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0) then
  1365         SetLittle(HHGear^.dX);
  1357         SetLittle(HHGear^.dX);
  1366 
  1358 
  1367     if Hedgehog^.Gear <> nil then
  1359     if Hedgehog^.Gear <> nil then
  1368         doStepHedgehogMoving(HHGear);
  1360         doStepHedgehogMoving(HHGear);
  1369 
  1361 
  1472     tdX, tdY, slope: hwFloat;
  1464     tdX, tdY, slope: hwFloat;
  1473     land: Word; *)
  1465     land: Word; *)
  1474 var slope: hwFloat;
  1466 var slope: hwFloat;
  1475 begin
  1467 begin
  1476     if (Gear^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0)
  1468     if (Gear^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0)
  1477     and (Gear^.State and (gstHHJumping or gstHHHJump or gstAttacking) = 0)
  1469     and (Gear^.State and (gstHHJumping or gstHHHJump or gstAttacking or gstAnimation) = 0)
  1478     and ((Gear^.Hedgehog = nil) or ((Gear^.Hedgehog^.Effects[heFrozen] = 0) or (Gear^.Hedgehog^.Effects[heFrozen] > 255)))
  1470     and ((Gear^.Hedgehog = nil) or ((Gear^.Hedgehog^.Effects[heFrozen] = 0) or (Gear^.Hedgehog^.Effects[heFrozen] > 255)))
  1479     and (not Gear^.dY.isNegative) and TurnClockActive and (TestCollisionYwithGear(Gear, 1) and lfIce <> 0) then
  1471     and (not Gear^.dY.isNegative) and TurnClockActive and (TestCollisionYwithGear(Gear, 1) and lfIce <> 0) then
  1480         begin
  1472         begin
  1481         slope:= CalcSlopeBelowGear(Gear);
  1473         slope:= CalcSlopeBelowGear(Gear);
  1482         if slope.QWordValue > 730144440 then // ignore mild slopes
  1474         if slope.QWordValue > 730144440 then // ignore mild slopes