# HG changeset patch # User unc0rr # Date 1255366685 0 # Node ID 1a0bb82d55f070f3f1479388c44ca440230e8dd7 # Parent 23242609c44b4a185d5c94f40b243e4d244a7ae6 Switch to first legal ammo when hedgehog can't hold current one diff -r 23242609c44b -r 1a0bb82d55f0 hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Mon Oct 12 16:53:01 2009 +0000 +++ b/hedgewars/uAmmos.pas Mon Oct 12 16:58:05 2009 +0000 @@ -209,6 +209,32 @@ end end; +procedure SwitchToFirstLegalAmmo(var Hedgehog: THedgehog); +begin +with Hedgehog do + begin + CurAmmo:= 0; + CurSlot:= 0; + while (CurSlot <= cMaxSlotIndex) and + ((Ammo^[CurSlot, CurAmmo].Count = 0) or + (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) + do + begin + while (CurAmmo <= cMaxSlotAmmoIndex) and + ((Ammo^[CurSlot, CurAmmo].Count = 0) or + (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) + do inc(CurAmmo); + + if (CurAmmo > cMaxSlotAmmoIndex) then + begin + CurAmmo:= 0; + inc(CurSlot) + end + end; + TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true) + end +end; + procedure ApplyAmmoChanges(var Hedgehog: THedgehog); var s: shortstring; begin @@ -218,12 +244,7 @@ begin if (Ammo^[CurSlot, CurAmmo].Count = 0) then - begin - CurAmmo:= 0; - CurSlot:= 0; - while (CurSlot <= cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do inc(CurSlot); - TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true) - end; + SwitchToFirstLegalAmmo(Hedgehog); //bad things could happen here in case CurSlot is overflowing ApplyAngleBounds(Hedgehog, Ammo^[CurSlot, CurAmmo].AmmoType); @@ -257,16 +278,7 @@ with Hedgehog do if ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0) or (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then - begin - CurAmmo:= 0; - CurSlot:= 0; - while (CurSlot <= cMaxSlotIndex) and - ((Ammo^[CurSlot, CurAmmo].Count = 0) or - (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) - do - inc(CurSlot); - TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true) - end + SwitchToFirstLegalAmmo(Hedgehog); end; procedure SetWeapon(weap: TAmmoType);