hedgewars/uAmmos.pas
changeset 3346 967fd96f7373
parent 3319 af0d256205c1
child 3405 8fdb08497bf1
equal deleted inserted replaced
3345:25ad24233e77 3346:967fd96f7373
    23 uses uConsts, uTeams, uStats;
    23 uses uConsts, uTeams, uStats;
    24 
    24 
    25 procedure initModule;
    25 procedure initModule;
    26 procedure freeModule;
    26 procedure freeModule;
    27 
    27 
    28 procedure AddAmmoStore(s: shortstring);
    28 procedure AddAmmoStore;
       
    29 procedure SetAmmoLoadout(s: shortstring);
       
    30 procedure SetAmmoProbability(s: shortstring);
       
    31 procedure SetAmmoDelay(s: shortstring);
       
    32 procedure SetAmmoReinforcement(s: shortstring);
    29 procedure AssignStores;
    33 procedure AssignStores;
    30 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
    34 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
    31 function  HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean;
    35 function  HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean;
    32 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
    36 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
    33 procedure OnUsedAmmo(var Hedgehog: THedgehog);
    37 procedure OnUsedAmmo(var Hedgehog: THedgehog);
    45 uses uMisc, uGears, uWorld, uLocale, uConsole;
    49 uses uMisc, uGears, uWorld, uLocale, uConsole;
    46 
    50 
    47 type TAmmoCounts = array[TAmmoType] of Longword;
    51 type TAmmoCounts = array[TAmmoType] of Longword;
    48 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    52 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    49     StoreCnt: Longword;
    53     StoreCnt: Longword;
       
    54     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
    50 
    55 
    51 procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts);
    56 procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts);
    52 var mi: array[0..cMaxSlotIndex] of byte;
    57 var mi: array[0..cMaxSlotIndex] of byte;
    53     a: TAmmoType;
    58     a: TAmmoType;
    54 begin
    59 begin
    79        inc(mi[Ammoz[a].Slot])
    84        inc(mi[Ammoz[a].Slot])
    80        end
    85        end
    81     end
    86     end
    82 end;
    87 end;
    83 
    88 
    84 procedure AddAmmoStore(s: shortstring);
    89 procedure AddAmmoStore;
    85 const probability: array [0..8] of LongWord = (0,20,30,60,100,200,400,600,800);
    90 const probability: array [0..8] of LongWord = (0,20,30,60,100,200,400,600,800);
    86 var cnt: Longword;
    91 var cnt: Longword;
    87     a: TAmmoType;
    92     a: TAmmoType;
    88     ammos: TAmmoCounts;
    93     ammos: TAmmoCounts;
    89     substr: shortstring; // TEMPORARY
    94     substr: shortstring; // TEMPORARY
    90 begin
    95 begin
    91 TryDo(byte(s[0]) = byte(ord(High(TAmmoType))) * 4, 'Invalid ammo scheme (incompatible frontend; got: ' + inttostr(byte(s[0]) div 4) + ', expected: ' + inttostr(ord(High(TAmmoType))) + ')', true);
    96 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);
    92 
    97 
    93 // FIXME - TEMPORARY hardcoded check on shoppa pending creation of crate *type* probability editor
    98 // FIXME - TEMPORARY hardcoded check on shoppa pending creation of crate *type* probability editor
    94 substr:= Copy(s,1,15);
    99 substr:= Copy(ammoLoadout,1,15);
    95 if (substr = '000000990000009') or 
   100 if (substr = '000000990000009') or 
    96    (substr = '000000990000000') then
   101    (substr = '000000990000000') then
    97     shoppa:= true;
   102     shoppa:= true;
    98 
   103 
    99 inc(StoreCnt);
   104 inc(StoreCnt);
   103 
   108 
   104 for a:= Low(TAmmoType) to High(TAmmoType) do
   109 for a:= Low(TAmmoType) to High(TAmmoType) do
   105     begin
   110     begin
   106     if a <> amNothing then
   111     if a <> amNothing then
   107         begin
   112         begin
   108         Ammoz[a].Probability:= probability[byte(s[ord(a) + ord(High(TAmmoType))]) - byte('0')];
   113         Ammoz[a].Probability:= probability[byte(ammoProbability[ord(a)]) - byte('0')];
   109         Ammoz[a].SkipTurns:= (byte(s[ord(a) + ord(High(TAmmoType)) + ord(High(TAmmoType))]) - byte('0'));
   114         Ammoz[a].SkipTurns:= (byte(ammoDelay[ord(a)]) - byte('0'));
   110         Ammoz[a].NumberInCase:= (byte(s[ord(a) + ord(High(TAmmoType)) + ord(High(TAmmoType)) + ord(High(TAmmoType))]) - byte('0'));
   115         Ammoz[a].NumberInCase:= (byte(ammoReinforcement[ord(a)]) - byte('0'));
   111         if (TrainingFlags and tfIgnoreDelays) <> 0 then Ammoz[a].SkipTurns:= 0;
   116         if (TrainingFlags and tfIgnoreDelays) <> 0 then Ammoz[a].SkipTurns:= 0;
   112         cnt:= byte(s[ord(a)]) - byte('0');
   117         cnt:= byte(ammoLoadout[ord(a)]) - byte('0');
   113         // avoid things we already have infinite number
   118         // avoid things we already have infinite number
   114         if cnt = 9 then
   119         if cnt = 9 then
   115             begin
   120             begin
   116             cnt:= AMMO_INFINITE;
   121             cnt:= AMMO_INFINITE;
   117             Ammoz[a].Probability:= 0
   122             Ammoz[a].Probability:= 0
   355 
   360 
   356 for t:= Low(TAmmoType) to High(TAmmoType) do
   361 for t:= Low(TAmmoType) to High(TAmmoType) do
   357     if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0
   362     if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0
   358 end;
   363 end;
   359 
   364 
       
   365 procedure SetAmmoLoadout(s: shortstring);
       
   366 begin
       
   367     ammoLoadout:= s;
       
   368 end;
       
   369 
       
   370 procedure SetAmmoProbability(s: shortstring);
       
   371 begin
       
   372     ammoProbability:= s;
       
   373 end;
       
   374 
       
   375 procedure SetAmmoDelay(s: shortstring);
       
   376 begin
       
   377     ammoDelay:= s;
       
   378 end;
       
   379 
       
   380 procedure SetAmmoReinforcement(s: shortstring);
       
   381 begin
       
   382     ammoReinforcement:= s;
       
   383 end;
       
   384 
   360 // Restore indefinitely disabled weapons and initial weapon counts.  Only used for hog placement right now
   385 // Restore indefinitely disabled weapons and initial weapon counts.  Only used for hog placement right now
   361 procedure ResetWeapons;
   386 procedure ResetWeapons;
   362 var i, slot, a: Longword;
   387 var i, slot, a: Longword;
   363     t: TAmmoType;
   388     t: TAmmoType;
   364 begin
   389 begin
   376 end;
   401 end;
   377 
   402 
   378 procedure initModule;
   403 procedure initModule;
   379 begin
   404 begin
   380     shoppa:= false;
   405     shoppa:= false;
   381     StoreCnt:= 0
   406     StoreCnt:= 0;
       
   407     ammoLoadout:= '';
       
   408     ammoProbability:= '';
       
   409     ammoDelay:= '';
       
   410     ammoReinforcement:= ''
   382 end;
   411 end;
   383 
   412 
   384 procedure freeModule;
   413 procedure freeModule;
   385 var i: LongWord;
   414 var i: LongWord;
   386 begin
   415 begin