hedgewars/HHHandlers.inc
changeset 2948 3f21a9dc93d0
parent 2940 c02119eee12a
child 2972 82828fd23dea
equal deleted inserted replaced
2947:803b277e4894 2948:3f21a9dc93d0
    21 var slot, i: Longword;
    21 var slot, i: Longword;
    22 begin
    22 begin
    23 slot:= Gear^.MsgParam;
    23 slot:= Gear^.MsgParam;
    24 
    24 
    25 with PHedgehog(Gear^.Hedgehog)^ do
    25 with PHedgehog(Gear^.Hedgehog)^ do
    26 	begin
    26     begin
    27 	Gear^.Message:= Gear^.Message and not gm_Slot;
    27     Gear^.Message:= Gear^.Message and not gm_Slot;
    28 
    28 
    29 	if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0)
    29     if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0)
    30 		or (MultiShootAttacks > 0)
    30         or (MultiShootAttacks > 0)
    31 		or ((Gear^.State and gstHHDriven) = 0) then exit;
    31         or ((Gear^.State and gstHHDriven) = 0) then exit;
    32 
    32 
    33 	Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
    33     Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
    34 
    34 
    35 	if CurSlot = slot then
    35     if CurSlot = slot then
    36 		begin
    36         begin
    37 		i:= 0;
    37         i:= 0;
    38 		repeat
    38         repeat
    39 		inc(CurAmmo);
    39         inc(CurAmmo);
    40 		if (CurAmmo > cMaxSlotAmmoIndex) then
    40         if (CurAmmo > cMaxSlotAmmoIndex) then
    41 			begin
    41             begin
    42 			CurAmmo:= 0;
    42             CurAmmo:= 0;
    43 			inc(i);
    43             inc(i);
    44 			TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
    44             TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
    45 			end;
    45             end;
    46 		until (Ammo^[slot, CurAmmo].Count > 0) and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, CurAmmo].AmmoType].SkipTurns)
    46         until (Ammo^[slot, CurAmmo].Count > 0) and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, CurAmmo].AmmoType].SkipTurns)
    47 		end else
    47         end else
    48 		begin
    48         begin
    49 		i:= 0;
    49         i:= 0;
    50 		// check whether there is ammo in slot
    50         // check whether there is ammo in slot
    51 		while (i <= cMaxSlotAmmoIndex)
    51         while (i <= cMaxSlotAmmoIndex)
    52 		  and ((Ammo^[slot, i].Count = 0)
    52           and ((Ammo^[slot, i].Count = 0)
    53 		       or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) do inc(i);
    53                or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) do inc(i);
    54 
    54 
    55 		if i <= cMaxSlotAmmoIndex then
    55         if i <= cMaxSlotAmmoIndex then
    56 			begin
    56             begin
    57 			CurSlot:= slot;
    57             CurSlot:= slot;
    58 			CurAmmo:= i
    58             CurAmmo:= i
    59 			end
    59             end
    60 		end
    60         end
    61 	end
    61     end
    62 end;
    62 end;
    63 
    63 
    64 procedure HHSetWeapon(Gear: PGear);
    64 procedure HHSetWeapon(Gear: PGear);
    65 var t: LongInt;
    65 var t: LongInt;
    66     weap: TAmmoType;
    66     weap: TAmmoType;
    74 t:= cMaxSlotAmmoIndex;
    74 t:= cMaxSlotAmmoIndex;
    75 
    75 
    76 Gear^.Message:= Gear^.Message and not gm_Weapon;
    76 Gear^.Message:= Gear^.Message and not gm_Weapon;
    77 
    77 
    78 with PHedgehog(Gear^.Hedgehog)^ do
    78 with PHedgehog(Gear^.Hedgehog)^ do
    79 	while (Ammo^[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do
    79     while (Ammo^[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do
    80 		begin
    80         begin
    81 		ChangeAmmo(Gear);
    81         ChangeAmmo(Gear);
    82 		dec(t)
    82         dec(t)
    83 		end;
    83         end;
    84 
    84 
    85 ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
    85 ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
    86 end;
    86 end;
    87 
    87 
    88 procedure HHSetTimer(Gear: PGear);
    88 procedure HHSetTimer(Gear: PGear);
    89 begin
    89 begin
    90 Gear^.Message:= Gear^.Message and not gm_Timer;
    90 Gear^.Message:= Gear^.Message and not gm_Timer;
    91 with PHedgehog(Gear^.Hedgehog)^ do
    91 with PHedgehog(Gear^.Hedgehog)^ do
    92 	if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then
    92     if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then
    93 		begin
    93         begin
    94 		Ammo^[CurSlot, CurAmmo].Timer:= 1000 * Gear^.MsgParam;
    94         Ammo^[CurSlot, CurAmmo].Timer:= 1000 * Gear^.MsgParam;
    95 		with CurrentTeam^ do
    95         with CurrentTeam^ do
    96 			ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
    96             ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
    97 		end;
    97         end;
    98 end;
    98 end;
    99 
    99 
   100 
   100 
   101 procedure Attack(Gear: PGear);
   101 procedure Attack(Gear: PGear);
   102 var xx, yy: hwFloat;
   102 var xx, yy: hwFloat;
   163                          amWhip: begin
   163                          amWhip: begin
   164                                  CurAmmoGear:= AddGear(hwRound(X) + hwSign(dX) * 10, hwRound(Y), gtWhip, 0, SignAs(_1, dX), - _0_8, 0);
   164                                  CurAmmoGear:= AddGear(hwRound(X) + hwSign(dX) * 10, hwRound(Y), gtWhip, 0, SignAs(_1, dX), - _0_8, 0);
   165                                  PlaySound(sndWhipCrack)
   165                                  PlaySound(sndWhipCrack)
   166                                  end;
   166                                  end;
   167                   amBaseballBat: begin
   167                   amBaseballBat: begin
   168 								 CurAmmoGear:= AddGear(hwRound(X) + hwSign(dX) * 10, hwRound(Y), gtShover, gsttmpFlag, xx * _0_5, yy * _0_5, 0);
   168                                  CurAmmoGear:= AddGear(hwRound(X) + hwSign(dX) * 10, hwRound(Y), gtShover, gsttmpFlag, xx * _0_5, yy * _0_5, 0);
   169 								 PlaySound(sndBaseballBat)
   169                                  PlaySound(sndBaseballBat)
   170 								 end;
   170                                  end;
   171                     amParachute: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtParachute, 0, _0, _0, 0);
   171                     amParachute: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtParachute, 0, _0, _0, 0);
   172                     amAirAttack: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 0, _0, _0, 0);
   172                     amAirAttack: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 0, _0, _0, 0);
   173                    amMineStrike: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 1, _0, _0, 0);
   173                    amMineStrike: AddGear(Ammo^[CurSlot, CurAmmo].Pos, 0, gtAirAttack, 1, _0, _0, 0);
   174                     amBlowTorch: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtBlowTorch, 0, SignAs(_0_5, dX), _0, 0);
   174                     amBlowTorch: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtBlowTorch, 0, SignAs(_0_5, dX), _0, 0);
   175                        amGirder: CurAmmoGear:= AddGear(0, 0, gtGirder, Ammo^[CurSlot, CurAmmo].Pos, _0, _0, 0);
   175                        amGirder: CurAmmoGear:= AddGear(0, 0, gtGirder, Ammo^[CurSlot, CurAmmo].Pos, _0, _0, 0);
   176                      amTeleport: CurAmmoGear:= AddGear(0, 0, gtTeleport, 0, _0, _0, 0);
   176                      amTeleport: CurAmmoGear:= AddGear(0, 0, gtTeleport, 0, _0, _0, 0);
   177                        amSwitch: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtSwitcher, 0, _0, _0, 0);
   177                        amSwitch: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtSwitcher, 0, _0, _0, 0);
   178                        amMortar: begin
   178                        amMortar: begin
   179 				playSound(sndMortar);
   179                 playSound(sndMortar);
   180 				FollowGear:= AddGear(hwRound(X), hwRound(Y), gtMortar,  0, xx*cMaxPower/cPowerDivisor, yy*cMaxPower/cPowerDivisor, 0);
   180                 FollowGear:= AddGear(hwRound(X), hwRound(Y), gtMortar,  0, xx*cMaxPower/cPowerDivisor, yy*cMaxPower/cPowerDivisor, 0);
   181 				 end;
   181                  end;
   182                       amRCPlane: begin
   182                       amRCPlane: begin
   183                                  CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtRCPlane,  0, xx * cMaxPower / cPowerDivisor / 4, yy * cMaxPower / cPowerDivisor / 4, 0);
   183                                  CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtRCPlane,  0, xx * cMaxPower / cPowerDivisor / 4, yy * cMaxPower / cPowerDivisor / 4, 0);
   184                                  CurAmmoGear^.SoundChannel:= LoopSound(sndRCPlane, nil)
   184                                  CurAmmoGear^.SoundChannel:= LoopSound(sndRCPlane, nil)
   185                                  end;
   185                                  end;
   186                        amKamikaze: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtKamikaze, 0, xx * _0_5, yy * _0_5, 0);
   186                        amKamikaze: CurAmmoGear:= AddGear(hwRound(X), hwRound(Y), gtKamikaze, 0, xx * _0_5, yy * _0_5, 0);
   235 
   235 
   236 procedure AfterAttack;
   236 procedure AfterAttack;
   237 var s: shortstring;
   237 var s: shortstring;
   238 begin
   238 begin
   239 with CurrentHedgehog^.Gear^,
   239 with CurrentHedgehog^.Gear^,
   240 		CurrentHedgehog^ do
   240         CurrentHedgehog^ do
   241 	begin
   241     begin
   242 	State:= State and not gstAttacking;
   242     State:= State and not gstAttacking;
   243 	if ((Ammo^[CurSlot, CurAmmo].Propz) and ammoprop_Utility) = 0 then
   243     if ((Ammo^[CurSlot, CurAmmo].Propz) and ammoprop_Utility) = 0 then
   244 		begin
   244         begin
   245 		Inc(MultiShootAttacks);
   245         Inc(MultiShootAttacks);
   246 		
   246         
   247 		if (Ammo^[CurSlot, CurAmmo].NumPerTurn >= MultiShootAttacks) then
   247         if (Ammo^[CurSlot, CurAmmo].NumPerTurn >= MultiShootAttacks) then
   248 			begin
   248             begin
   249 			s:= inttostr(Ammo^[CurSlot, CurAmmo].NumPerTurn + 1 - MultiShootAttacks);
   249             s:= inttostr(Ammo^[CurSlot, CurAmmo].NumPerTurn + 1 - MultiShootAttacks);
   250 			AddCaption(format(trmsg[sidRemaining], s), cWhiteColor, capgrpAmmostate);
   250             AddCaption(format(trmsg[sidRemaining], s), cWhiteColor, capgrpAmmostate);
   251 			end;
   251             end;
   252 		
   252         
   253 		if (Ammo^[CurSlot, CurAmmo].NumPerTurn >= MultiShootAttacks) or
   253         if (Ammo^[CurSlot, CurAmmo].NumPerTurn >= MultiShootAttacks) or
   254 			((GameFlags and gfMultiWeapon) <> 0) then
   254             ((GameFlags and gfMultiWeapon) <> 0) then
   255 			begin
   255             begin
   256 			isInMultiShoot:= true
   256             isInMultiShoot:= true
   257 			end
   257             end
   258 		else
   258         else
   259 			begin
   259             begin
   260 			TurnTimeLeft:= Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].TimeAfterTurn;
   260             TurnTimeLeft:= Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].TimeAfterTurn;
   261 			State:= State or gstAttacked;
   261             State:= State or gstAttacked;
   262 			OnUsedAmmo(CurrentHedgehog^);
   262             OnUsedAmmo(CurrentHedgehog^);
   263 			end;
   263             end;
   264 		end
   264         end
   265 	else
   265     else
   266 		begin
   266         begin
   267 		OnUsedAmmo(CurrentHedgehog^);
   267         OnUsedAmmo(CurrentHedgehog^);
   268 		ApplyAmmoChanges(CurrentHedgehog^);
   268         ApplyAmmoChanges(CurrentHedgehog^);
   269 		end;
   269         end;
   270 	AttackBar:= 0;
   270     AttackBar:= 0;
   271 	end
   271     end
   272 end;
   272 end;
   273 
   273 
   274 ////////////////////////////////////////////////////////////////////////////////
   274 ////////////////////////////////////////////////////////////////////////////////
   275 procedure doStepHedgehogDead(Gear: PGear);
   275 procedure doStepHedgehogDead(Gear: PGear);
   276 const frametime = 200;
   276 const frametime = 200;
   277       timertime = frametime * 6;
   277       timertime = frametime * 6;
   278 begin
   278 begin
   279 if PHedgehog(Gear^.Hedgehog)^.Unplaced then exit;
   279 if PHedgehog(Gear^.Hedgehog)^.Unplaced then exit;
   280 if Gear^.Timer > 1 then
   280 if Gear^.Timer > 1 then
   281 	begin
   281     begin
   282 	AllInactive:= false;
   282     AllInactive:= false;
   283 	dec(Gear^.Timer);
   283     dec(Gear^.Timer);
   284 	if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
   284     if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
   285 	end else
   285     end else
   286 if Gear^.Timer = 1 then
   286 if Gear^.Timer = 1 then
   287 	begin
   287     begin
   288 	Gear^.State:= Gear^.State or gstNoDamage;
   288     Gear^.State:= Gear^.State or gstNoDamage;
   289 	doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, EXPLAutoSound);
   289     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, EXPLAutoSound);
   290 	AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
   290     AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
   291 	DeleteGear(Gear);
   291     DeleteGear(Gear);
   292 	SetAllToActive
   292     SetAllToActive
   293 	end else // Gear^.Timer = 0
   293     end else // Gear^.Timer = 0
   294 	begin
   294     begin
   295 	AllInactive:= false;
   295     AllInactive:= false;
   296 	Gear^.Z:= cCurrHHZ;
   296     Gear^.Z:= cCurrHHZ;
   297 	RemoveGearFromList(Gear);
   297     RemoveGearFromList(Gear);
   298 	InsertGearToList(Gear);
   298     InsertGearToList(Gear);
   299 	PlaySound(sndByeBye, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   299     PlaySound(sndByeBye, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   300 	Gear^.Pos:= 0;
   300     Gear^.Pos:= 0;
   301 	Gear^.Timer:= timertime
   301     Gear^.Timer:= timertime
   302 	end
   302     end
   303 end;
   303 end;
   304 
   304 
   305 ////////////////////////////////////////////////////////////////////////////////
   305 ////////////////////////////////////////////////////////////////////////////////
   306 procedure PickUp(HH, Gear: PGear);
   306 procedure PickUp(HH, Gear: PGear);
   307 var s: shortstring;
   307 var s: shortstring;
   308     a: TAmmoType;
   308     a: TAmmoType;
   309 	i: Integer;
   309     i: Integer;
   310 begin
   310 begin
   311 Gear^.Message:= gm_Destroy;
   311 Gear^.Message:= gm_Destroy;
   312 PlaySound(sndShotgunReload);
   312 PlaySound(sndShotgunReload);
   313 case Gear^.Pos of
   313 case Gear^.Pos of
   314        posCaseUtility,
   314        posCaseUtility,
   332                     s:= '+' + s;
   332                     s:= '+' + s;
   333                     AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Clan^.Color, capgrpAmmoinfo);
   333                     AddCaption(s, PHedgehog(HH^.Hedgehog)^.Team^.Clan^.Color, capgrpAmmoinfo);
   334                     RenderHealth(PHedgehog(HH^.Hedgehog)^);
   334                     RenderHealth(PHedgehog(HH^.Hedgehog)^);
   335                     RecountTeamHealth(PHedgehog(HH^.Hedgehog)^.Team);
   335                     RecountTeamHealth(PHedgehog(HH^.Hedgehog)^.Team);
   336 
   336 
   337 					i:= 0;
   337                     i:= 0;
   338 					while i < Gear^.Health do
   338                     while i < Gear^.Health do
   339 						begin
   339                         begin
   340 						AddVisualGear(hwRound(HH^.X), hwRound(HH^.Y), vgtHealth);
   340                         AddVisualGear(hwRound(HH^.X), hwRound(HH^.Y), vgtHealth);
   341 						inc(i, 5);
   341                         inc(i, 5);
   342 						end;
   342                         end;
   343                     end;
   343                     end;
   344      end
   344      end
   345 end;
   345 end;
   346 
   346 
   347 const StepTicks: LongWord = 0;
   347 const StepTicks: LongWord = 0;
   363           else exit;
   363           else exit;
   364           StepTicks:= 200;
   364           StepTicks:= 200;
   365           exit
   365           exit
   366           end;
   366           end;
   367 
   367 
   368 	if ((Gear^.Message and gm_Animate) <> 0) then
   368     if ((Gear^.Message and gm_Animate) <> 0) then
   369 		begin
   369         begin
   370 		Gear^.Message:= 0;
   370         Gear^.Message:= 0;
   371 		Gear^.State:= Gear^.State or gstAnimation;
   371         Gear^.State:= Gear^.State or gstAnimation;
   372 		Gear^.Tag:= Gear^.MsgParam;
   372         Gear^.Tag:= Gear^.MsgParam;
   373 		Gear^.Timer:= 0;
   373         Gear^.Timer:= 0;
   374 		Gear^.Pos:= 0
   374         Gear^.Pos:= 0
   375 		end;
   375         end;
   376 
   376 
   377    if ((Gear^.Message and gm_LJump ) <> 0) then
   377    if ((Gear^.Message and gm_LJump ) <> 0) then
   378       begin
   378       begin
   379       Gear^.Message:= Gear^.Message and not gm_LJump;
   379       Gear^.Message:= Gear^.Message and not gm_LJump;
   380       DeleteCI(Gear);
   380       DeleteCI(Gear);
   480 
   480 
   481 procedure HedgehogChAngle(Gear: PGear);
   481 procedure HedgehogChAngle(Gear: PGear);
   482 var da: LongWord;
   482 var da: LongWord;
   483 begin
   483 begin
   484 with PHedgehog(Gear^.Hedgehog)^ do
   484 with PHedgehog(Gear^.Hedgehog)^ do
   485 	if (Ammo^[CurSlot, CurAmmo].AmmoType = amRope)
   485     if (Ammo^[CurSlot, CurAmmo].AmmoType = amRope)
   486 	and ((Gear^.State and (gstMoving or gstHHJumping)) = gstMoving) then da:= 2 else da:= 1;
   486     and ((Gear^.State and (gstMoving or gstHHJumping)) = gstMoving) then da:= 2 else da:= 1;
   487 
   487 
   488 if (((Gear^.Message and gm_Precise) = 0) or ((GameTicks mod 5) = 1)) then
   488 if (((Gear^.Message and gm_Precise) = 0) or ((GameTicks mod 5) = 1)) then
   489 	if ((Gear^.Message and gm_Up) <> 0) and (Gear^.Angle >= CurMinAngle + da) then dec(Gear^.Angle, da)
   489     if ((Gear^.Message and gm_Up) <> 0) and (Gear^.Angle >= CurMinAngle + da) then dec(Gear^.Angle, da)
   490 	else
   490     else
   491 	if ((Gear^.Message and gm_Down) <> 0) and (Gear^.Angle + da <= CurMaxAngle) then inc(Gear^.Angle, da)
   491     if ((Gear^.Message and gm_Down) <> 0) and (Gear^.Angle + da <= CurMaxAngle) then inc(Gear^.Angle, da)
   492 end;
   492 end;
   493 
   493 
   494 procedure doStepHedgehog(Gear: PGear); forward;
   494 procedure doStepHedgehog(Gear: PGear); forward;
   495 ////////////////////////////////////////////////////////////////////////////////
   495 ////////////////////////////////////////////////////////////////////////////////
   496 procedure doStepHedgehogMoving(Gear: PGear);
   496 procedure doStepHedgehogMoving(Gear: PGear);
   581    end;
   581    end;
   582 
   582 
   583 if (hwAbs(Gear^.dY) > _0) and (Gear^.FlightTime > 0) then
   583 if (hwAbs(Gear^.dY) > _0) and (Gear^.FlightTime > 0) then
   584     begin
   584     begin
   585     inc(Gear^.FlightTime, 1);
   585     inc(Gear^.FlightTime, 1);
   586 	if Gear^.FlightTime = 2000 then
   586     if Gear^.FlightTime = 2000 then
   587 		begin
   587         begin
   588 		AddCaption(GetEventString(eidHomerun), cWhiteColor, capgrpMessage);
   588         AddCaption(GetEventString(eidHomerun), cWhiteColor, capgrpMessage);
   589 		PlaySound(sndHomerun)
   589         PlaySound(sndHomerun)
   590 		end;
   590         end;
   591 	end
   591     end
   592 else
   592 else
   593     begin
   593     begin
   594     Gear^.FlightTime:= 0;
   594     Gear^.FlightTime:= 0;
   595 	end;
   595     end;
   596 
   596 
   597 end;
   597 end;
   598 
   598 
   599 procedure doStepHedgehogDriven(Gear: PGear);
   599 procedure doStepHedgehogDriven(Gear: PGear);
   600 var t: PGear;
   600 var t: PGear;
   601 	wasJumping: boolean;
   601     wasJumping: boolean;
   602 begin
   602 begin
   603 if not isInMultiShoot then
   603 if not isInMultiShoot then
   604    AllInactive:= false
   604    AllInactive:= false
   605 else
   605 else
   606    Gear^.Message:= 0;
   606    Gear^.Message:= 0;
   607 
   607 
   608 if (TurnTimeLeft = 0) or (Gear^.Damage > 0) then
   608 if (TurnTimeLeft = 0) or (Gear^.Damage > 0) then
   609 	begin
   609     begin
   610 	TurnTimeLeft:= 0;
   610     TurnTimeLeft:= 0;
   611 	isCursorVisible:= false;
   611     isCursorVisible:= false;
   612 	Gear^.State:= Gear^.State and not (gstHHDriven or gstAnimation or gstAttacking);
   612     Gear^.State:= Gear^.State and not (gstHHDriven or gstAnimation or gstAttacking);
   613 	AttackBar:= 0;
   613     AttackBar:= 0;
   614 	if Gear^.Damage > 0 then
   614     if Gear^.Damage > 0 then
   615 		Gear^.State:= Gear^.State and not (gstHHJumping or gstHHHJump);
   615         Gear^.State:= Gear^.State and not (gstHHJumping or gstHHHJump);
   616 	exit
   616     exit
   617 	end;
   617     end;
   618 
   618 
   619 if (Gear^.State and gstAnimation) <> 0 then
   619 if (Gear^.State and gstAnimation) <> 0 then
   620 	begin
   620     begin
   621 	Gear^.Message:= 0;
   621     Gear^.Message:= 0;
   622 	if (Gear^.Pos = Wavez[TWave(Gear^.Tag)].VoiceDelay) and (Gear^.Timer = 0) then PlaySound(Wavez[TWave(Gear^.Tag)].Voice, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   622     if (Gear^.Pos = Wavez[TWave(Gear^.Tag)].VoiceDelay) and (Gear^.Timer = 0) then PlaySound(Wavez[TWave(Gear^.Tag)].Voice, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   623 	inc(Gear^.Timer);
   623     inc(Gear^.Timer);
   624 	if Gear^.Timer = Wavez[TWave(Gear^.Tag)].Interval then
   624     if Gear^.Timer = Wavez[TWave(Gear^.Tag)].Interval then
   625 		begin
   625         begin
   626 		Gear^.Timer:= 0;
   626         Gear^.Timer:= 0;
   627 		inc(Gear^.Pos);
   627         inc(Gear^.Pos);
   628 		if Gear^.Pos = Wavez[TWave(Gear^.Tag)].FramesCount then
   628         if Gear^.Pos = Wavez[TWave(Gear^.Tag)].FramesCount then
   629 			Gear^.State:= Gear^.State and not gstAnimation
   629             Gear^.State:= Gear^.State and not gstAnimation
   630 		end;
   630         end;
   631 	exit
   631     exit
   632 	end;
   632     end;
   633 
   633 
   634 if ((Gear^.State and gstMoving) <> 0)
   634 if ((Gear^.State and gstMoving) <> 0)
   635     or (StepTicks = cHHStepTicks)
   635     or (StepTicks = cHHStepTicks)
   636 	or (CurAmmoGear <> nil) then // we are moving
   636     or (CurAmmoGear <> nil) then // we are moving
   637 	begin
   637     begin
   638 	with PHedgehog(Gear^.Hedgehog)^ do
   638     with PHedgehog(Gear^.Hedgehog)^ do
   639 		if (CurAmmoGear = nil)
   639         if (CurAmmoGear = nil)
   640 		and (Gear^.dY > _0_39)
   640         and (Gear^.dY > _0_39)
   641 		and (Ammo^[CurSlot, CurAmmo].AmmoType = amParachute) then Gear^.Message:= Gear^.Message or gm_Attack;
   641         and (Ammo^[CurSlot, CurAmmo].AmmoType = amParachute) then Gear^.Message:= Gear^.Message or gm_Attack;
   642 	// check for case with ammo
   642     // check for case with ammo
   643 	t:= CheckGearNear(Gear, gtCase, 36, 36);
   643     t:= CheckGearNear(Gear, gtCase, 36, 36);
   644 	if t <> nil then
   644     if t <> nil then
   645 		PickUp(Gear, t)
   645         PickUp(Gear, t)
   646 	end;
   646     end;
   647 
   647 
   648 if (CurAmmoGear = nil) then
   648 if (CurAmmoGear = nil) then
   649 	if (((Gear^.Message and gm_Attack) <> 0)
   649     if (((Gear^.Message and gm_Attack) <> 0)
   650 		or ((Gear^.State and gstAttacking) <> 0)) then
   650         or ((Gear^.State and gstAttacking) <> 0)) then
   651 		Attack(Gear) // should be before others to avoid desync with '/put' msg and changing weapon msgs
   651         Attack(Gear) // should be before others to avoid desync with '/put' msg and changing weapon msgs
   652 	else
   652     else
   653 else with PHedgehog(Gear^.Hedgehog)^ do
   653 else with PHedgehog(Gear^.Hedgehog)^ do
   654 	 if ((CurAmmoGear^.Ammo^.Propz and ammoprop_AltAttack) <> 0)
   654      if ((CurAmmoGear^.Ammo^.Propz and ammoprop_AltAttack) <> 0)
   655 		and ((Gear^.Message and gm_LJump) <> 0)
   655         and ((Gear^.Message and gm_LJump) <> 0)
   656 		and (((Ammo^[CurSlot, CurAmmo].Propz) and ammoprop_AltUse) <> 0) then
   656         and (((Ammo^[CurSlot, CurAmmo].Propz) and ammoprop_AltUse) <> 0) then
   657 		begin
   657         begin
   658 		Gear^.Message:= Gear^.Message and not gm_LJump;
   658         Gear^.Message:= Gear^.Message and not gm_LJump;
   659 		Attack(Gear)
   659         Attack(Gear)
   660 		end;
   660         end;
   661 
   661 
   662 if (CurAmmoGear = nil)
   662 if (CurAmmoGear = nil)
   663 	or ((CurAmmoGear^.Ammo^.Propz and ammoprop_AltAttack) <> 0) then
   663     or ((CurAmmoGear^.Ammo^.Propz and ammoprop_AltAttack) <> 0) then
   664 	begin
   664     begin
   665 	if ((Gear^.Message and gm_Slot) <> 0) then
   665     if ((Gear^.Message and gm_Slot) <> 0) then
   666 		begin
   666         begin
   667 		ChangeAmmo(Gear);
   667         ChangeAmmo(Gear);
   668 		ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
   668         ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
   669 		end;
   669         end;
   670 
   670 
   671 	if ((Gear^.Message and gm_Weapon) <> 0) then HHSetWeapon(Gear);
   671     if ((Gear^.Message and gm_Weapon) <> 0) then HHSetWeapon(Gear);
   672 
   672 
   673 	if ((Gear^.Message and gm_Timer) <> 0) then HHSetTimer(Gear);
   673     if ((Gear^.Message and gm_Timer) <> 0) then HHSetTimer(Gear);
   674 	end;
   674     end;
   675 
   675 
   676 if CurAmmoGear <> nil then
   676 if CurAmmoGear <> nil then
   677    begin
   677    begin
   678    CurAmmoGear^.Message:= Gear^.Message;
   678    CurAmmoGear^.Message:= Gear^.Message;
   679    exit
   679    exit
   681 
   681 
   682 if not isInMultiShoot then
   682 if not isInMultiShoot then
   683    HedgehogChAngle(Gear);
   683    HedgehogChAngle(Gear);
   684 
   684 
   685 if (Gear^.State and gstMoving) <> 0 then
   685 if (Gear^.State and gstMoving) <> 0 then
   686 	begin
   686     begin
   687 	wasJumping:= ((Gear^.State and gstHHJumping) <> 0);
   687     wasJumping:= ((Gear^.State and gstHHJumping) <> 0);
   688 
   688 
   689 	if ((Gear^.Message and gm_HJump) <> 0) and
   689     if ((Gear^.Message and gm_HJump) <> 0) and
   690 		wasJumping and
   690         wasJumping and
   691 		((Gear^.State and gstHHHJump) = 0) then
   691         ((Gear^.State and gstHHHJump) = 0) then
   692 		if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then
   692         if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then
   693 			begin
   693             begin
   694 			Gear^.State:= Gear^.State or gstHHHJump;
   694             Gear^.State:= Gear^.State or gstHHHJump;
   695 			Gear^.dY:= -_0_25;
   695             Gear^.dY:= -_0_25;
   696 			if not cArtillery then Gear^.dX:= -SignAs(_0_02, Gear^.dX);
   696             if not cArtillery then Gear^.dX:= -SignAs(_0_02, Gear^.dX);
   697 			PlaySound(sndJump2, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack)
   697             PlaySound(sndJump2, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack)
   698 			end;
   698             end;
   699 
   699 
   700 	Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
   700     Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
   701 
   701 
   702 	if (not cArtillery) and wasJumping and
   702     if (not cArtillery) and wasJumping and
   703 		TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
   703         TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
   704 
   704 
   705 	doStepHedgehogMoving(Gear);
   705     doStepHedgehogMoving(Gear);
   706 
   706 
   707 	if ((Gear^.State and (gstMoving or gstDrowning)) = 0) then
   707     if ((Gear^.State and (gstMoving or gstDrowning)) = 0) then
   708 		begin
   708         begin
   709 		AddGearCI(Gear);
   709         AddGearCI(Gear);
   710 		if wasJumping then
   710         if wasJumping then
   711 			StepTicks:= 410
   711             StepTicks:= 410
   712 		else
   712         else
   713 			StepTicks:= 95
   713             StepTicks:= 95
   714 		end;
   714         end;
   715 	exit
   715     exit
   716 	end;
   716     end;
   717 
   717 
   718 	if not isInMultiShoot then
   718     if not isInMultiShoot then
   719 		begin
   719         begin
   720 		if StepTicks > 0 then dec(StepTicks);
   720         if StepTicks > 0 then dec(StepTicks);
   721 		if (StepTicks = 0) then HedgehogStep(Gear)
   721         if (StepTicks = 0) then HedgehogStep(Gear)
   722 		end
   722         end
   723 end;
   723 end;
   724 
   724 
   725 ////////////////////////////////////////////////////////////////////////////////
   725 ////////////////////////////////////////////////////////////////////////////////
   726 procedure doStepHedgehogFree(Gear: PGear);
   726 procedure doStepHedgehogFree(Gear: PGear);
   727 var prevState: Longword;
   727 var prevState: Longword;
   729 prevState:= Gear^.State;
   729 prevState:= Gear^.State;
   730 
   730 
   731 doStepHedgehogMoving(Gear);
   731 doStepHedgehogMoving(Gear);
   732 
   732 
   733 if (Gear^.State and (gstMoving or gstDrowning)) <> 0 then
   733 if (Gear^.State and (gstMoving or gstDrowning)) <> 0 then
   734 	begin
   734     begin
   735 	if Gear^.Damage > 0 then CalcRotationDirAngle(Gear);
   735     if Gear^.Damage > 0 then CalcRotationDirAngle(Gear);
   736 	AllInactive:= false;
   736     AllInactive:= false;
   737 	exit
   737     exit
   738 	end;
   738     end;
   739 
   739 
   740 if (Gear^.Health = 0) then
   740 if (Gear^.Health = 0) then
   741 	begin
   741     begin
   742 	if PrvInactive then
   742     if PrvInactive then
   743 		begin
   743         begin
   744 		Gear^.Timer:= 0;
   744         Gear^.Timer:= 0;
   745 		Gear^.State:= Gear^.State or gstHHDeath;
   745         Gear^.State:= Gear^.State or gstHHDeath;
   746 		Gear^.doStep:= @doStepHedgehogDead;
   746         Gear^.doStep:= @doStepHedgehogDead;
   747 		FollowGear:= Gear;
   747         FollowGear:= Gear;
   748 		PrvInactive:= false;
   748         PrvInactive:= false;
   749 		AllInactive:= false;
   749         AllInactive:= false;
   750 
   750 
   751 		// Death message
   751         // Death message
   752 		AddCaption(Format(GetEventString(eidDied), PHedgehog(Gear^.Hedgehog)^.Name), cWhiteColor, capgrpMessage);
   752         AddCaption(Format(GetEventString(eidDied), PHedgehog(Gear^.Hedgehog)^.Name), cWhiteColor, capgrpMessage);
   753 		end;
   753         end;
   754 	exit
   754     exit
   755 	end;
   755     end;
   756 
   756 
   757 if ((Gear^.State and gstWait) = 0) and
   757 if ((Gear^.State and gstWait) = 0) and
   758 	(prevState <> Gear^.State) then
   758     (prevState <> Gear^.State) then
   759 	begin
   759     begin
   760 	Gear^.State:= gstWait;
   760     Gear^.State:= gstWait;
   761 	Gear^.Timer:= 150
   761     Gear^.Timer:= 150
   762 	end else
   762     end else
   763 	begin
   763     begin
   764 	if Gear^.Timer = 0 then
   764     if Gear^.Timer = 0 then
   765 		begin
   765         begin
   766 		Gear^.State:= 0;
   766         Gear^.State:= 0;
   767 		Gear^.Active:= false;
   767         Gear^.Active:= false;
   768 		AddGearCI(Gear);
   768         AddGearCI(Gear);
   769 		exit
   769         exit
   770 		end else dec(Gear^.Timer)
   770         end else dec(Gear^.Timer)
   771 	end;
   771     end;
   772 
   772 
   773 AllInactive:= false
   773 AllInactive:= false
   774 end;
   774 end;
   775 
   775 
   776 ////////////////////////////////////////////////////////////////////////////////
   776 ////////////////////////////////////////////////////////////////////////////////
   777 procedure doStepHedgehog(Gear: PGear);
   777 procedure doStepHedgehog(Gear: PGear);
   778 begin
   778 begin
   779 if (Gear^.Message and gm_Destroy) <> 0 then
   779 if (Gear^.Message and gm_Destroy) <> 0 then
   780 	begin
   780     begin
   781 	DeleteGear(Gear);
   781     DeleteGear(Gear);
   782 	exit
   782     exit
   783 	end;
   783     end;
   784 
   784 
   785 if (Gear^.State and gstHHDriven) = 0 then
   785 if (Gear^.State and gstHHDriven) = 0 then
   786 	doStepHedgehogFree(Gear)
   786     doStepHedgehogFree(Gear)
   787 else
   787 else
   788 	begin
   788     begin
   789 	with PHedgehog(Gear^.Hedgehog)^ do
   789     with PHedgehog(Gear^.Hedgehog)^ do
   790 		if Team^.hasGone then TeamGoneEffect(Team^);
   790         if Team^.hasGone then TeamGoneEffect(Team^);
   791 	doStepHedgehogDriven(Gear)
   791     doStepHedgehogDriven(Gear)
   792 	end;
   792     end;
   793 end;
   793 end;