hedgewars/uAmmos.pas
branchexperimental3D
changeset 4812 f924be23ffb4
parent 4808 7c3e5b52344a
child 4976 088d40d8aba2
equal deleted inserted replaced
4347:0ddb100fea61 4812:f924be23ffb4
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uAmmos;
    21 unit uAmmos;
    22 interface
    22 interface
    23 uses uConsts, uTeams, uStats;
    23 uses uConsts, uTypes;
    24 
    24 
    25 procedure initModule;
    25 procedure initModule;
    26 procedure freeModule;
    26 procedure freeModule;
    27 
    27 
    28 procedure AddAmmoStore;
    28 procedure AddAmmoStore;
    45 function  GetAmmoEntry(var Hedgehog: THedgehog): PAmmo;
    45 function  GetAmmoEntry(var Hedgehog: THedgehog): PAmmo;
    46 
    46 
    47 var StoreCnt: Longword;
    47 var StoreCnt: Longword;
    48 
    48 
    49 implementation
    49 implementation
    50 uses uMisc, uGears, uWorld, uLocale, uConsole, uMobile;
    50 uses uLocale, uMobile, uVariables, uCommands, uUtils, uCaptions, uDebug;
    51 
    51 
    52 type TAmmoCounts = array[TAmmoType] of Longword;
    52 type TAmmoCounts = array[TAmmoType] of Longword;
    53 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    53 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    54     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
    54     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
    55     InitialCounts: array[0..Pred(cMaxHHs)] of TAmmoCounts;
    55     InitialCounts: array[0..Pred(cMaxHHs)] of TAmmoCounts;
    66     begin
    66     begin
    67     if cnts[a] > 0 then
    67     if cnts[a] > 0 then
    68        begin
    68        begin
    69        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
    69        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
    70        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
    70        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
    71        with Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]] do
    71        with Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]] do Count:= cnts[a];
    72            begin
       
    73            Count:= cnts[a];
       
    74            if (TotalRounds < 0) and ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then Count:= AMMO_INFINITE;
       
    75            end;
       
    76        inc(mi[Ammoz[a].Slot])
       
    77        end
       
    78     else if (TotalRounds < 0) and ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
       
    79        begin
       
    80        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
       
    81        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
       
    82 
       
    83        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= AMMO_INFINITE;
       
    84 
       
    85        inc(mi[Ammoz[a].Slot])
    72        inc(mi[Ammoz[a].Slot])
    86        end
    73        end
    87     end
    74     end
    88 end;
    75 end;
    89 
    76 
   105     if a <> amNothing then
    92     if a <> amNothing then
   106         begin
    93         begin
   107         Ammoz[a].Probability:= probability[byte(ammoProbability[ord(a)]) - byte('0')];
    94         Ammoz[a].Probability:= probability[byte(ammoProbability[ord(a)]) - byte('0')];
   108         Ammoz[a].SkipTurns:= (byte(ammoDelay[ord(a)]) - byte('0'));
    95         Ammoz[a].SkipTurns:= (byte(ammoDelay[ord(a)]) - byte('0'));
   109         Ammoz[a].NumberInCase:= (byte(ammoReinforcement[ord(a)]) - byte('0'));
    96         Ammoz[a].NumberInCase:= (byte(ammoReinforcement[ord(a)]) - byte('0'));
   110         if (TrainingFlags and tfIgnoreDelays) <> 0 then Ammoz[a].SkipTurns:= 0;
       
   111         cnt:= byte(ammoLoadout[ord(a)]) - byte('0');
    97         cnt:= byte(ammoLoadout[ord(a)]) - byte('0');
   112         // avoid things we already have infinite number
    98         // avoid things we already have infinite number
   113         if cnt = 9 then
    99         if cnt = 9 then
   114             begin
   100             begin
   115             cnt:= AMMO_INFINITE;
   101             cnt:= AMMO_INFINITE;
   132         if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0) and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then
   118         if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0) and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then
   133             Ammoz[a].SkipTurns:= 1;
   119             Ammoz[a].SkipTurns:= 1;
   134 
   120 
   135         if ((GameFlags and gfPlaceHog) <> 0) and
   121         if ((GameFlags and gfPlaceHog) <> 0) and
   136             (a <> amTeleport) and (a <> amSkip) and
   122             (a <> amTeleport) and (a <> amSkip) and
   137             (Ammoz[a].SkipTurns < 10000) then inc(Ammoz[a].SkipTurns,10000)
   123             (Ammoz[a].SkipTurns < 10000) then inc(Ammoz[a].SkipTurns,10000);
       
   124 	if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then ammos[a]:= AMMO_INFINITE
   138         end 
   125         end 
   139     else ammos[a]:= AMMO_INFINITE;
   126     else ammos[a]:= AMMO_INFINITE;
   140     InitialCounts[Pred(StoreCnt)][a]:= ammos[a];
   127     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then 
       
   128     	InitialCounts[Pred(StoreCnt)][a]:= cnt
       
   129     else
       
   130     	InitialCounts[Pred(StoreCnt)][a]:= ammos[a];
   141     end;
   131     end;
   142 FillAmmoStore(StoresList[Pred(StoreCnt)], ammos)
   132 FillAmmoStore(StoresList[Pred(StoreCnt)], ammos)
   143 end;
   133 end;
   144 
   134 
   145 function GetAmmoByNum(num: Longword): PHHAmmo;
   135 function GetAmmoByNum(num: Longword): PHHAmmo;
   327 
   317 
   328     ApplyAngleBounds(Hedgehog, CurWeapon^.AmmoType);
   318     ApplyAngleBounds(Hedgehog, CurWeapon^.AmmoType);
   329 
   319 
   330     with CurWeapon^ do
   320     with CurWeapon^ do
   331         begin
   321         begin
   332         if AmmoType <> amNothing then
   322         s:= trammo[Ammoz[AmmoType].NameId];
   333             begin
   323         if (Count <> AMMO_INFINITE) and not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0)) then
   334             s:= trammo[Ammoz[AmmoType].NameId];
   324             s:= s + ' (' + IntToStr(Count) + ')';
   335             if (Count <> AMMO_INFINITE) and not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0)) then
   325         if (Propz and ammoprop_Timerable) <> 0 then
   336                 s:= s + ' (' + IntToStr(Count) + ')';
   326             s:= s + ', ' + IntToStr(Timer div 1000) + ' ' + trammo[sidSeconds];
   337             if (Propz and ammoprop_Timerable) <> 0 then
   327         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
   338                 s:= s + ', ' + inttostr(Timer div 1000) + ' ' + trammo[sidSeconds];
       
   339             AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
       
   340             end;
       
   341         if (Propz and ammoprop_NeedTarget) <> 0
   328         if (Propz and ammoprop_NeedTarget) <> 0
   342             then begin
   329             then begin
   343             Gear^.State:= Gear^.State or      gstHHChooseTarget;
   330             Gear^.State:= Gear^.State or      gstHHChooseTarget;
   344             isCursorVisible:= true
   331             isCursorVisible:= true
   345             end else begin
   332             end else begin
   425 
   412 
   426 for a:= Low(TAmmoType) to High(TAmmoType) do
   413 for a:= Low(TAmmoType) to High(TAmmoType) do
   427     if Ammoz[a].SkipTurns >= 10000 then dec(Ammoz[a].SkipTurns,10000)
   414     if Ammoz[a].SkipTurns >= 10000 then dec(Ammoz[a].SkipTurns,10000)
   428 end;
   415 end;
   429 
   416 
       
   417 
       
   418 
       
   419 procedure chAddAmmoStore(var descr: shortstring);
       
   420 begin
       
   421 descr:= ''; // avoid compiler hint
       
   422 AddAmmoStore
       
   423 end;
       
   424 
   430 procedure initModule;
   425 procedure initModule;
   431 begin
   426 begin
       
   427     RegisterVariable('ammloadt', vtCommand, @SetAmmoLoadout, false);
       
   428     RegisterVariable('ammdelay', vtCommand, @SetAmmoDelay, false);
       
   429     RegisterVariable('ammprob',  vtCommand, @SetAmmoProbability, false);
       
   430     RegisterVariable('ammreinf', vtCommand, @SetAmmoReinforcement, false);
       
   431     RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
       
   432 
   432     StoreCnt:= 0;
   433     StoreCnt:= 0;
   433     ammoLoadout:= '';
   434     ammoLoadout:= '';
   434     ammoProbability:= '';
   435     ammoProbability:= '';
   435     ammoDelay:= '';
   436     ammoDelay:= '';
   436     ammoReinforcement:= '';
   437     ammoReinforcement:= '';