hedgewars/uAmmos.pas
changeset 7439 0a494f951dcf
parent 7426 55b49cc1f33a
child 7754 e81dc9bef8b8
--- a/hedgewars/uAmmos.pas	Thu Jul 26 11:01:32 2012 +0200
+++ b/hedgewars/uAmmos.pas	Thu Jul 26 11:10:56 2012 +0200
@@ -32,6 +32,7 @@
 procedure SetAmmoReinforcement(var s: shortstring);
 procedure AssignStores;
 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; amt: LongWord);
 procedure SetAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
 function  HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): LongWord;
 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
@@ -188,7 +189,7 @@
         end
 end;
 
-procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; amt: LongWord);
 var cnt: LongWord;
     a: PAmmo;
 begin
@@ -199,11 +200,16 @@
     cnt:= 0;
 if (cnt <> AMMO_INFINITE) then
     begin
-    inc(cnt, Ammoz[ammo].NumberInCase);
+    inc(cnt, amt);
     SetAmmo(Hedgehog, ammo, cnt)
     end
 end;
 
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+begin
+    AddAmmo(Hedgehog, ammo, Ammoz[ammo].NumberInCase);
+end;
+
 procedure SetAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
 var ammos: TAmmoCounts;
     slot, ami: LongInt;
@@ -297,22 +303,23 @@
 
 procedure ApplyAngleBounds(var Hedgehog: THedgehog; AmmoType: TAmmoType);
 begin
-with Hedgehog do
-    begin
-    CurMinAngle:= Ammoz[AmmoType].minAngle;
-    if Ammoz[AmmoType].maxAngle <> 0 then
-        CurMaxAngle:= Ammoz[AmmoType].maxAngle
-    else
-        CurMaxAngle:= cMaxAngle;
+if Hedgehog.Gear <> nil then
+    with Hedgehog do
+        begin
+        CurMinAngle:= Ammoz[AmmoType].minAngle;
+        if Ammoz[AmmoType].maxAngle <> 0 then
+            CurMaxAngle:= Ammoz[AmmoType].maxAngle
+        else
+            CurMaxAngle:= cMaxAngle;
 
-    with Hedgehog.Gear^ do
-        begin
-        if Angle < CurMinAngle then
-            Angle:= CurMinAngle;
-        if Angle > CurMaxAngle then
-            Angle:= CurMaxAngle;
+        with Hedgehog.Gear^ do
+            begin
+            if Angle < CurMinAngle then
+                Angle:= CurMinAngle;
+            if Angle > CurMaxAngle then
+                Angle:= CurMaxAngle;
+            end
         end
-    end
 end;
 
 procedure SwitchToFirstLegalAmmo(var Hedgehog: THedgehog);
@@ -367,19 +374,19 @@
     with CurWeapon^ do
         begin
         s:= trammo[Ammoz[AmmoType].NameId];
-        if (Count <> AMMO_INFINITE) and not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0)) then
+        if (Count <> AMMO_INFINITE) and (not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0))) then
             s:= s + ' (' + IntToStr(Count) + ')';
         if (Propz and ammoprop_Timerable) <> 0 then
             s:= s + ', ' + IntToStr(Timer div 1000) + ' ' + trammo[sidSeconds];
         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
         if (Propz and ammoprop_NeedTarget) <> 0 then
             begin
-            Gear^.State:= Gear^.State or      gstHHChooseTarget;
+            if Gear <> nil then Gear^.State:= Gear^.State or      gstHHChooseTarget;
             isCursorVisible:= true
             end
         else
             begin
-            Gear^.State:= Gear^.State and not gstHHChooseTarget;
+            if Gear <> nil then Gear^.State:= Gear^.State and (not gstHHChooseTarget);
             isCursorVisible:= false
             end;
         end