hedgewars/uAmmos.pas
changeset 6924 57b66ee3bff3
parent 6898 344b0dbd9690
child 6990 40e5af28d026
equal deleted inserted replaced
6923:d2405a6a86f5 6924:57b66ee3bff3
    30 procedure SetAmmoProbability(var s: shortstring);
    30 procedure SetAmmoProbability(var s: shortstring);
    31 procedure SetAmmoDelay(var s: shortstring);
    31 procedure SetAmmoDelay(var s: shortstring);
    32 procedure SetAmmoReinforcement(var s: shortstring);
    32 procedure SetAmmoReinforcement(var s: shortstring);
    33 procedure AssignStores;
    33 procedure AssignStores;
    34 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
    34 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
    35 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
    35 procedure SetAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
    36 function  HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): LongWord;
    36 function  HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): LongWord;
    37 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
    37 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
    38 procedure OnUsedAmmo(var Hedgehog: THedgehog);
    38 procedure OnUsedAmmo(var Hedgehog: THedgehog);
    39 procedure ApplyAngleBounds(var Hedgehog: THedgehog; AmmoType: TAmmoType);
    39 procedure ApplyAngleBounds(var Hedgehog: THedgehog; AmmoType: TAmmoType);
    40 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
    40 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
    41 procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog);
    41 procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog);
    42 procedure SetWeapon(weap: TAmmoType);
    42 procedure SetWeapon(weap: TAmmoType);
    43 procedure DisableSomeWeapons;
    43 procedure DisableSomeWeapons;
    44 procedure ResetWeapons;
    44 procedure ResetWeapons;
    45 function  GetAmmoByNum(num: Longword): PHHAmmo;
    45 function  GetAmmoByNum(num: Longword): PHHAmmo;
    46 function  GetAmmoEntry(var Hedgehog: THedgehog): PAmmo;
    46 function  GetCurAmmoEntry(var Hedgehog: THedgehog): PAmmo;
    47 function  GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
    47 function  GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
    48 
    48 
    49 var StoreCnt: Longword;
    49 var StoreCnt: Longword;
    50 
    50 
    51 implementation
    51 implementation
   147 begin
   147 begin
   148 TryDo(num < StoreCnt, 'Invalid store number', true);
   148 TryDo(num < StoreCnt, 'Invalid store number', true);
   149 exit(StoresList[num])
   149 exit(StoresList[num])
   150 end;
   150 end;
   151 
   151 
   152 function GetAmmoEntry(var Hedgehog: THedgehog): PAmmo;
   152 function GetCurAmmoEntry(var Hedgehog: THedgehog): PAmmo;
   153 begin
   153 begin
   154 GetAmmoEntry:= GetAmmoEntry(Hedgehog, Hedgehog.CurAmmoType)
   154 GetCurAmmoEntry:= GetAmmoEntry(Hedgehog, Hedgehog.CurAmmoType)
   155 end;
   155 end;
   156 
   156 
   157 function GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
   157 function GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
   158 var ammoidx, slot: LongWord;
   158 var ammoidx, slot: LongWord;
   159 begin
   159 begin
   198 else
   198 else
   199     cnt:= 0;
   199     cnt:= 0;
   200 if (cnt <> AMMO_INFINITE) then
   200 if (cnt <> AMMO_INFINITE) then
   201     begin
   201     begin
   202     inc(cnt, Ammoz[ammo].NumberInCase);
   202     inc(cnt, Ammoz[ammo].NumberInCase);
   203     AddAmmo(Hedgehog, ammo, cnt)
   203     SetAmmo(Hedgehog, ammo, cnt)
   204     end
   204     end
   205 end;
   205 end;
   206 
   206 
   207 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
   207 procedure SetAmmo(var Hedgehog: THedgehog; ammo: TAmmoType; cnt: LongWord);
   208 var ammos: TAmmoCounts;
   208 var ammos: TAmmoCounts;
   209     slot, ami: LongInt;
   209     slot, ami: LongInt;
   210     hhammo: PHHAmmo;
   210     hhammo: PHHAmmo;
   211     CurWeapon: PAmmo;
   211     CurWeapon: PAmmo;
   212 begin
   212 begin
   222 
   222 
   223 ammos[ammo]:= cnt;
   223 ammos[ammo]:= cnt;
   224 if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE;
   224 if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE;
   225 
   225 
   226 FillAmmoStore(hhammo, ammos);
   226 FillAmmoStore(hhammo, ammos);
   227 CurWeapon:= GetAmmoEntry(Hedgehog);
   227 CurWeapon:= GetCurAmmoEntry(Hedgehog);
   228 with Hedgehog, CurWeapon^ do
   228 with Hedgehog, CurWeapon^ do
   229     if (Count = 0) or (AmmoType = amNothing) then
   229     if (Count = 0) or (AmmoType = amNothing) then
   230         begin
   230         begin
   231         PackAmmo(Ammo, Ammoz[AmmoType].Slot);
   231         PackAmmo(Ammo, Ammoz[AmmoType].Slot);
   232         CurAmmoType:= amNothing
   232         CurAmmoType:= amNothing
   256 end;
   256 end;
   257 
   257 
   258 procedure OnUsedAmmo(var Hedgehog: THedgehog);
   258 procedure OnUsedAmmo(var Hedgehog: THedgehog);
   259 var CurWeapon: PAmmo;
   259 var CurWeapon: PAmmo;
   260 begin
   260 begin
   261 CurWeapon:= GetAmmoEntry(Hedgehog);
   261 CurWeapon:= GetCurAmmoEntry(Hedgehog);
   262 with Hedgehog do
   262 with Hedgehog do
   263     begin
   263     begin
   264 
   264 
   265     MultiShootAttacks:= 0;
   265     MultiShootAttacks:= 0;
   266     with CurWeapon^ do
   266     with CurWeapon^ do
   350 
   350 
   351 with Hedgehog do
   351 with Hedgehog do
   352     begin
   352     begin
   353     Timer:= 10;
   353     Timer:= 10;
   354 
   354 
   355     CurWeapon:= GetAmmoEntry(Hedgehog);
   355     CurWeapon:= GetCurAmmoEntry(Hedgehog);
   356 
   356 
   357     if (CurWeapon^.Count = 0) then
   357     if (CurWeapon^.Count = 0) then
   358         SwitchToFirstLegalAmmo(Hedgehog)
   358         SwitchToFirstLegalAmmo(Hedgehog)
   359     else if CurWeapon^.AmmoType = amNothing then
   359     else if CurWeapon^.AmmoType = amNothing then
   360         Hedgehog.CurAmmoType:= amNothing;
   360         Hedgehog.CurAmmoType:= amNothing;
   361 
   361 
   362     CurWeapon:= GetAmmoEntry(Hedgehog);
   362     CurWeapon:= GetCurAmmoEntry(Hedgehog);
   363 
   363 
   364     ApplyAngleBounds(Hedgehog, CurWeapon^.AmmoType);
   364     ApplyAngleBounds(Hedgehog, CurWeapon^.AmmoType);
   365 
   365 
   366     with CurWeapon^ do
   366     with CurWeapon^ do
   367         begin
   367         begin