--- a/hedgewars/uAmmos.pas Tue Jun 21 16:43:05 2011 +0400
+++ b/hedgewars/uAmmos.pas Thu Jun 23 21:19:43 2011 +0400
@@ -32,6 +32,7 @@
procedure SetAmmoReinforcement(s: shortstring);
procedure AssignStores;
procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
function HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean;
procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
procedure OnUsedAmmo(var Hedgehog: THedgehog);
@@ -43,6 +44,7 @@
procedure ResetWeapons;
function GetAmmoByNum(num: Longword): PHHAmmo;
function GetAmmoEntry(var Hedgehog: THedgehog): PAmmo;
+function GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
var StoreCnt: Longword;
@@ -139,13 +141,18 @@
end;
function GetAmmoEntry(var Hedgehog: THedgehog): PAmmo;
+begin
+GetAmmoEntry:= GetAmmoEntry(Hedgehog, Hedgehog.CurAmmoType)
+end;
+
+function GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
var ammoidx, slot: LongWord;
begin
with Hedgehog do
begin
- slot:= Ammoz[CurAmmoType].Slot;
+ slot:= Ammoz[am].Slot;
ammoidx:= 0;
- while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do inc(ammoidx);
+ while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> am) do inc(ammoidx);
GetAmmoEntry:= @Ammo^[slot, ammoidx];
end
end;
@@ -170,6 +177,17 @@
end;
procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
+var cnt: LongWord;
+begin
+cnt:= GetAmmoEntry(Hedgehog, ammo)^.Count;
+if cnt <> AMMO_INFINITE then
+ begin
+ inc(cnt, Ammoz[ammo].NumberInCase);
+ AddAmmo(Hedgehog, ammo, cnt)
+ end
+end;
+
+procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
var ammos: TAmmoCounts;
slot, ami: LongInt;
hhammo: PHHAmmo;
@@ -184,11 +202,8 @@
if hhammo^[slot, ami].Count > 0 then
ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count;
-if ammos[ammo] <> AMMO_INFINITE then
- begin
- inc(ammos[ammo], Ammoz[ammo].NumberInCase);
- if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE
- end;
+ammos[ammo]:= cnt;
+if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE;
FillAmmoStore(hhammo, ammos)
end;