hedgewars/uAmmos.pas
author unc0rr
Sat, 09 Dec 2006 19:47:31 +0000
changeset 293 00a532e8808e
parent 288 929c44745fd9
child 295 8834f3cb620e
permissions -rw-r--r--
Some Z-ordering
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
288
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     1
unit uAmmos;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     2
interface
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     3
uses uConsts;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     4
{$INCLUDE options.inc}
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     5
type PHHAmmo = ^THHAmmo;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     6
     THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     7
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     8
procedure AddAmmoStore(s: shortstring);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
     9
procedure AssignStores;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    10
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    11
implementation
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    12
uses uMisc, uTeams;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    13
var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    14
    StoreCnt: Longword = 0;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    15
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    16
procedure AddAmmoStore(s: shortstring);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    17
var mi: array[0..cMaxSlotIndex] of byte;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    18
    a: TAmmoType;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    19
    cnt: Longword;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    20
    tmp: PHHAmmo;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    21
begin
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    22
TryDo(byte(s[0]) = byte(ord(High(TAmmoType)) + 1), 'Invalid ammo scheme (incompatible frontend)', true);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    23
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    24
inc(StoreCnt);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    25
TryDo(StoreCnt <= cMaxHHs, 'Ammo stores overflow', true);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    26
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    27
new(StoresList[Pred(StoreCnt)]);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    28
tmp:= StoresList[Pred(StoreCnt)];
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    29
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    30
FillChar(mi, sizeof(mi), 0);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    31
for a:= Low(TAmmoType) to High(TAmmoType) do
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    32
    begin
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    33
    cnt:= byte(s[ord(a) + 1]) - byte('0');
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    34
    if cnt > 0 then
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    35
       begin
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    36
       if cnt >= 9 then cnt:= AMMO_INFINITE;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    37
       TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    38
       tmp[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    39
       tmp[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnt;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    40
       inc(mi[Ammoz[a].Slot])
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    41
       end
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    42
    end;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    43
end;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    44
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    45
function GetAmmoByNum(num: Longword): PHHAmmo;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    46
begin
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    47
TryDo(num < StoreCnt, 'Invalid store number', true);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    48
Result:= StoresList[num]
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    49
end;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    50
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    51
procedure AssignStores;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    52
var tteam: PTeam;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    53
    i: Longword;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    54
begin
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    55
tteam:= TeamsList;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    56
while tteam <> nil do
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    57
      begin
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    58
      for i:= 0 to cMaxHHIndex do
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    59
          if tteam.Hedgehogs[i].Gear <> nil then
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    60
             tteam.Hedgehogs[i].Ammo:= GetAmmoByNum(tteam.Hedgehogs[i].AmmoStore);
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    61
      tteam:= tteam.Next
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    62
      end
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    63
end;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    64
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents:
diff changeset
    65
end.