hedgewars/HHHandlers.inc
changeset 3943 9835060e5c01
parent 3915 c05855146440
child 3945 c3d5eace0a32
--- a/hedgewars/HHHandlers.inc	Sun Oct 10 17:13:20 2010 +0200
+++ b/hedgewars/HHHandlers.inc	Sun Oct 10 12:08:16 2010 -0400
@@ -42,7 +42,8 @@
 
 // Shouldn't more of this ammo switching stuff be moved to uAmmos ?
 procedure ChangeAmmo(Gear: PGear);
-var slot, ammoidx, i: Longword;
+var slot, i: Longword;
+    ammoidx: LongInt;
 begin
 slot:= Gear^.MsgParam;
 
@@ -73,7 +74,8 @@
             TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
             end;
         until (Ammo^[slot, ammoidx].Count > 0) and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns)
-        end else
+        end 
+    else
         begin
         i:= 0;
         // check whether there is ammo in slot
@@ -82,8 +84,9 @@
                or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) do inc(i);
 
         if i <= cMaxSlotAmmoIndex then ammoidx:= i
+        else ammoidx:= -1
         end;
-        CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
+        if ammoidx >= 0 then CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
     end
 end;