hedgewars/uAmmos.pas
changeset 3966 cbec77b5f706
parent 3952 d6412423da45
parent 3960 ada50f8d4186
child 4102 96efb3bbf8e3
equal deleted inserted replaced
3952:d6412423da45 3966:cbec77b5f706
    51 uses uMisc, uGears, uWorld, uLocale, uConsole, uMobile;
    51 uses uMisc, uGears, uWorld, uLocale, uConsole, uMobile;
    52 
    52 
    53 type TAmmoCounts = array[TAmmoType] of Longword;
    53 type TAmmoCounts = array[TAmmoType] of Longword;
    54 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    54 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    55     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
    55     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
       
    56     InitialCounts: array[0..Pred(cMaxHHs)] of TAmmoCounts;
    56 
    57 
    57 procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts);
    58 procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts);
    58 var mi: array[0..cMaxSlotIndex] of byte;
    59 var mi: array[0..cMaxSlotIndex] of byte;
    59     a: TAmmoType;
    60     a: TAmmoType;
    60 begin
    61 begin
    66     begin
    67     begin
    67     if cnts[a] > 0 then
    68     if cnts[a] > 0 then
    68        begin
    69        begin
    69        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
    70        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
    70        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
    71        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
    71 
    72        with Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]] do
    72        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnts[a];
    73            begin
    73        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].InitialCount:= cnts[a];
    74            Count:= cnts[a];
    74 
    75            if (TotalRounds < 0) and ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then Count:= AMMO_INFINITE;
    75        if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
    76            end;
    76            Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= AMMO_INFINITE;
       
    77        inc(mi[Ammoz[a].Slot])
    77        inc(mi[Ammoz[a].Slot])
    78        end
    78        end
    79     else if (TotalRounds < 0) and ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
    79     else if (TotalRounds < 0) and ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
    80        begin
    80        begin
    81        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
    81        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
    82        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
    82        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
    83 
    83 
    84        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= AMMO_INFINITE;
    84        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= AMMO_INFINITE;
    85        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].InitialCount:= 0;
       
    86 
    85 
    87        inc(mi[Ammoz[a].Slot])
    86        inc(mi[Ammoz[a].Slot])
    88        end
    87        end
    89     end
    88     end
    90 end;
    89 end;
   142             Ammoz[a].SkipTurns:= 1;
   141             Ammoz[a].SkipTurns:= 1;
   143 
   142 
   144         if ((GameFlags and gfPlaceHog) <> 0) and
   143         if ((GameFlags and gfPlaceHog) <> 0) and
   145             (a <> amTeleport) and (a <> amSkip) and
   144             (a <> amTeleport) and (a <> amSkip) and
   146             (Ammoz[a].SkipTurns < 10000) then inc(Ammoz[a].SkipTurns,10000)
   145             (Ammoz[a].SkipTurns < 10000) then inc(Ammoz[a].SkipTurns,10000)
   147         end else
   146         end 
   148         ammos[a]:= AMMO_INFINITE
   147     else ammos[a]:= AMMO_INFINITE;
       
   148     InitialCounts[Pred(StoreCnt)][a]:= ammos[a];
   149     end;
   149     end;
   150 
       
   151 FillAmmoStore(StoresList[Pred(StoreCnt)], ammos)
   150 FillAmmoStore(StoresList[Pred(StoreCnt)], ammos)
   152 end;
   151 end;
   153 
   152 
   154 function GetAmmoByNum(num: Longword): PHHAmmo;
   153 function GetAmmoByNum(num: Longword): PHHAmmo;
   155 begin
   154 begin
   382         for a:= 0 to cMaxSlotAmmoIndex do
   381         for a:= 0 to cMaxSlotAmmoIndex do
   383             with StoresList[i]^[slot, a] do
   382             with StoresList[i]^[slot, a] do
   384                 if (Propz and ammoprop_NotBorder) <> 0 then
   383                 if (Propz and ammoprop_NotBorder) <> 0 then
   385                     begin
   384                     begin
   386                     Count:= 0;
   385                     Count:= 0;
   387                     InitialCount:= 0
   386                     InitialCounts[i][AmmoType]:= 0
   388                     end;
   387                     end;
   389 
   388 
   390         PackAmmo(StoresList[i], slot)
   389         PackAmmo(StoresList[i], slot)
   391         end;
   390         end;
   392 
   391 
   414     ammoReinforcement:= s;
   413     ammoReinforcement:= s;
   415 end;
   414 end;
   416 
   415 
   417 // Restore indefinitely disabled weapons and initial weapon counts.  Only used for hog placement right now
   416 // Restore indefinitely disabled weapons and initial weapon counts.  Only used for hog placement right now
   418 procedure ResetWeapons;
   417 procedure ResetWeapons;
   419 var i, slot, a: Longword;
   418 var i, t: Longword;
   420     t: TAmmoType;
   419     a: TAmmoType;
   421 begin
   420 begin
   422 for i:= 0 to Pred(StoreCnt) do
   421 for t:= 0 to Pred(TeamsCount) do
   423     for slot:= 0 to cMaxSlotIndex do
   422    with TeamsArray[t]^ do
   424         begin
   423       for i:= 0 to cMaxHHIndex do
   425         for a:= 0 to cMaxSlotAmmoIndex do
   424           if Hedgehogs[i].Gear <> nil then
   426             with StoresList[i]^[slot, a] do
   425              FillAmmoStore(Hedgehogs[i].Ammo, InitialCounts[Hedgehogs[i].AmmoStore]);
   427                 Count:= InitialCount;
   426 
   428 
   427 for a:= Low(TAmmoType) to High(TAmmoType) do
   429         PackAmmo(StoresList[i], slot)
   428     if Ammoz[a].SkipTurns >= 10000 then dec(Ammoz[a].SkipTurns,10000)
   430         end;
       
   431 for t:= Low(TAmmoType) to High(TAmmoType) do
       
   432     if Ammoz[t].SkipTurns >= 10000 then dec(Ammoz[t].SkipTurns,10000);
       
   433 end;
   429 end;
   434 
   430 
   435 procedure initModule;
   431 procedure initModule;
   436 begin
   432 begin
   437     shoppa:= false;
   433     shoppa:= false;
   438     StoreCnt:= 0;
   434     StoreCnt:= 0;
   439     ammoLoadout:= '';
   435     ammoLoadout:= '';
   440     ammoProbability:= '';
   436     ammoProbability:= '';
   441     ammoDelay:= '';
   437     ammoDelay:= '';
   442     ammoReinforcement:= ''
   438     ammoReinforcement:= '';
       
   439     FillChar(InitialCounts, sizeof(InitialCounts), 0)
   443 end;
   440 end;
   444 
   441 
   445 procedure freeModule;
   442 procedure freeModule;
   446 var i: LongWord;
   443 var i: LongWord;
   447 begin
   444 begin