hedgewars/uAmmos.pas
changeset 2431 23242609c44b
parent 2409 dbf195c3e09c
child 2432 1a0bb82d55f0
--- a/hedgewars/uAmmos.pas	Mon Oct 12 16:50:42 2009 +0000
+++ b/hedgewars/uAmmos.pas	Mon Oct 12 16:53:01 2009 +0000
@@ -221,10 +221,10 @@
 		begin
 		CurAmmo:= 0;
 		CurSlot:= 0;
-		while (CurSlot < cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do 
-                        inc(CurSlot)
+		while (CurSlot <= cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do inc(CurSlot);
+		TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true)
 		end;
-                
+
         //bad things could happen here in case CurSlot is overflowing
 	ApplyAngleBounds(Hedgehog, Ammo^[CurSlot, CurAmmo].AmmoType);
 
@@ -255,15 +255,17 @@
 procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog);
 begin
 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)
+	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
 end;