hedgewars/uAmmos.pas
changeset 11532 bf86c6cb9341
parent 11046 47a8c19ecb60
child 11534 0ead3a2e0309
equal deleted inserted replaced
11531:d1cf1ff6cabb 11532:bf86c6cb9341
    68 FillChar(Ammo^, sizeof(Ammo^), 0);
    68 FillChar(Ammo^, sizeof(Ammo^), 0);
    69 for a:= Low(TAmmoType) to High(TAmmoType) do
    69 for a:= Low(TAmmoType) to High(TAmmoType) do
    70     begin
    70     begin
    71     if newAmmo[a].Count > 0 then
    71     if newAmmo[a].Count > 0 then
    72         begin
    72         begin
    73         TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
    73         if checkFails(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true) then exit;
    74         Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= newAmmo[a];
    74         Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= newAmmo[a];
    75         inc(mi[Ammoz[a].Slot])
    75         inc(mi[Ammoz[a].Slot])
    76         end
    76         end
    77     end;
    77     end;
    78 AmmoMenuInvalidated:= true;
    78 AmmoMenuInvalidated:= true;
    83 var cnt: Longword;
    83 var cnt: Longword;
    84     a: TAmmoType;
    84     a: TAmmoType;
    85     ammos: TAmmoCounts;
    85     ammos: TAmmoCounts;
    86     newAmmos: TAmmoArray;
    86     newAmmos: TAmmoArray;
    87 begin
    87 begin
    88 TryDo((byte(ammoLoadout[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoProbability[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoDelay[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoReinforcement[0]) = byte(ord(High(TAmmoType)))), 'Incomplete or missing ammo scheme set (incompatible frontend or demo/save?)', true);
    88     if checkFails((byte(ammoLoadout[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoProbability[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoDelay[0]) = byte(ord(High(TAmmoType)))) and (byte(ammoReinforcement[0]) = byte(ord(High(TAmmoType))))
       
    89                   , 'Incomplete or missing ammo scheme set (incompatible frontend or demo/save?)'
       
    90                   , true)
       
    91     then exit;
    89 
    92 
    90 inc(StoreCnt);
    93 inc(StoreCnt);
    91 TryDo(StoreCnt <= cMaxHHs, 'Ammo stores overflow', true);
    94 if checkFails(StoreCnt <= cMaxHHs, 'Ammo stores overflow', true) then exit;
    92 
    95 
    93 new(StoresList[Pred(StoreCnt)]);
    96 new(StoresList[Pred(StoreCnt)]);
    94 
    97 
    95 for a:= Low(TAmmoType) to High(TAmmoType) do
    98 for a:= Low(TAmmoType) to High(TAmmoType) do
    96     begin
    99     begin
   151 FillAmmoStore(StoresList[Pred(StoreCnt)], newAmmos)
   154 FillAmmoStore(StoresList[Pred(StoreCnt)], newAmmos)
   152 end;
   155 end;
   153 
   156 
   154 function GetAmmoByNum(num: LongInt): PHHAmmo;
   157 function GetAmmoByNum(num: LongInt): PHHAmmo;
   155 begin
   158 begin
   156     TryDo(num < StoreCnt, 'Invalid store number', true);
   159     if checkFails(num < StoreCnt, 'Invalid store number', true) then
   157     GetAmmoByNum:= StoresList[num]
   160         GetAmmoByNum:= nil
       
   161     else
       
   162         GetAmmoByNum:= StoresList[num]
   158 end;
   163 end;
   159 
   164 
   160 function GetCurAmmoEntry(var Hedgehog: THedgehog): PAmmo;
   165 function GetCurAmmoEntry(var Hedgehog: THedgehog): PAmmo;
   161 begin
   166 begin
   162     GetCurAmmoEntry:= GetAmmoEntry(Hedgehog, Hedgehog.CurAmmoType)
   167     GetCurAmmoEntry:= GetAmmoEntry(Hedgehog, Hedgehog.CurAmmoType)
   362             begin
   367             begin
   363             ammoidx:= 0;
   368             ammoidx:= 0;
   364             inc(slot)
   369             inc(slot)
   365             end
   370             end
   366         end;
   371         end;
   367     TryDo(slot <= cMaxSlotIndex, 'Ammo slot index overflow', true);
   372     if checkFails(slot <= cMaxSlotIndex, 'Ammo slot index overflow', true) then exit;
   368     CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
   373     CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
   369     end
   374     end
   370 end;
   375 end;
   371 
   376 
   372 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
   377 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);