26 FillChar(Ammo^, sizeof(Ammo^), 0); |
26 FillChar(Ammo^, sizeof(Ammo^), 0); |
27 for a:= Low(TAmmoType) to High(TAmmoType) do |
27 for a:= Low(TAmmoType) to High(TAmmoType) do |
28 if cnts[a] > 0 then |
28 if cnts[a] > 0 then |
29 begin |
29 begin |
30 TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); |
30 TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); |
31 Ammo[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; |
31 Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; |
32 Ammo[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnts[a]; |
32 Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnts[a]; |
33 inc(mi[Ammoz[a].Slot]) |
33 inc(mi[Ammoz[a].Slot]) |
34 end |
34 end |
35 end; |
35 end; |
36 |
36 |
37 procedure AddAmmoStore(s: shortstring); |
37 procedure AddAmmoStore(s: shortstring); |
57 end; |
57 end; |
58 |
58 |
59 function GetAmmoByNum(num: Longword): PHHAmmo; |
59 function GetAmmoByNum(num: Longword): PHHAmmo; |
60 begin |
60 begin |
61 TryDo(num < StoreCnt, 'Invalid store number', true); |
61 TryDo(num < StoreCnt, 'Invalid store number', true); |
62 Result:= StoresList[num] |
62 exit(StoresList[num]) |
63 end; |
63 end; |
64 |
64 |
65 procedure AssignStores; |
65 procedure AssignStores; |
66 var tteam: PTeam; |
66 var tteam: PTeam; |
67 i: Longword; |
67 i: Longword; |
68 begin |
68 begin |
69 tteam:= TeamsList; |
69 tteam:= TeamsList; |
70 while tteam <> nil do |
70 while tteam <> nil do |
71 begin |
71 begin |
72 for i:= 0 to cMaxHHIndex do |
72 for i:= 0 to cMaxHHIndex do |
73 if tteam.Hedgehogs[i].Gear <> nil then |
73 if tteam^.Hedgehogs[i].Gear <> nil then |
74 tteam.Hedgehogs[i].Ammo:= GetAmmoByNum(tteam.Hedgehogs[i].AmmoStore); |
74 tteam^.Hedgehogs[i].Ammo:= GetAmmoByNum(tteam^.Hedgehogs[i].AmmoStore); |
75 tteam:= tteam.Next |
75 tteam:= tteam^.Next |
76 end |
76 end |
77 end; |
77 end; |
78 |
78 |
79 procedure AddAmmo(Hedgehog: pointer; ammo: TAmmoType); |
79 procedure AddAmmo(Hedgehog: pointer; ammo: TAmmoType); |
80 var ammos: TAmmoCounts; |
80 var ammos: TAmmoCounts; |
81 slot, ami: integer; |
81 slot, ami: integer; |
82 hhammo: PHHAmmo; |
82 hhammo: PHHAmmo; |
83 begin |
83 begin |
84 FillChar(ammos, sizeof(ammos), 0); |
84 FillChar(ammos, sizeof(ammos), 0); |
85 hhammo:= PHedgehog(Hedgehog).Ammo; |
85 hhammo:= PHedgehog(Hedgehog)^.Ammo; |
86 |
86 |
87 for slot:= 0 to cMaxSlotIndex do |
87 for slot:= 0 to cMaxSlotIndex do |
88 for ami:= 0 to cMaxSlotAmmoIndex do |
88 for ami:= 0 to cMaxSlotAmmoIndex do |
89 if hhammo[slot, ami].Count > 0 then |
89 if hhammo^[slot, ami].Count > 0 then |
90 ammos[hhammo[slot, ami].AmmoType]:= hhammo[slot, ami].Count; |
90 ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count; |
91 |
91 |
92 if ammos[ammo] <> AMMO_INFINITE then inc(ammos[ammo]); |
92 if ammos[ammo] <> AMMO_INFINITE then inc(ammos[ammo]); |
93 FillAmmoStore(hhammo, ammos) |
93 FillAmmoStore(hhammo, ammos) |
94 end; |
94 end; |
95 |
95 |
99 begin |
99 begin |
100 repeat |
100 repeat |
101 b:= false; |
101 b:= false; |
102 ami:= 0; |
102 ami:= 0; |
103 while (not b) and (ami < cMaxSlotAmmoIndex) do |
103 while (not b) and (ami < cMaxSlotAmmoIndex) do |
104 if (Ammo[Slot, ami].Count = 0) |
104 if (Ammo^[Slot, ami].Count = 0) |
105 and (Ammo[Slot, ami + 1].Count > 0) then b:= true |
105 and (Ammo^[Slot, ami + 1].Count > 0) then b:= true |
106 else inc(ami); |
106 else inc(ami); |
107 if b then // there's a free item in ammo stack |
107 if b then // there's a free item in ammo stack |
108 begin |
108 begin |
109 Ammo[Slot, ami]:= Ammo[Slot, ami + 1]; |
109 Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1]; |
110 Ammo[Slot, ami + 1].Count:= 0 |
110 Ammo^[Slot, ami + 1].Count:= 0 |
111 end; |
111 end; |
112 until not b; |
112 until not b; |
113 end; |
113 end; |
114 |
114 |
115 procedure OnUsedAmmo(Ammo: PHHAmmo); |
115 procedure OnUsedAmmo(Ammo: PHHAmmo); |
116 var s, a: Longword; |
116 var s, a: Longword; |
117 begin |
117 begin |
118 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
118 with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do |
119 begin |
119 begin |
120 if CurAmmoGear = nil then begin s:= CurSlot; a:= CurAmmo end |
120 if CurAmmoGear = nil then begin s:= CurSlot; a:= CurAmmo end |
121 else begin s:= AltSlot; a:= AltAmmo end; |
121 else begin s:= AltSlot; a:= AltAmmo end; |
122 with Ammo[s, a] do |
122 with Ammo^[s, a] do |
123 if Count <> AMMO_INFINITE then |
123 if Count <> AMMO_INFINITE then |
124 begin |
124 begin |
125 dec(Count); |
125 dec(Count); |
126 if Count = 0 then PackAmmo(Ammo, CurSlot) |
126 if Count = 0 then PackAmmo(Ammo, CurSlot) |
127 end |
127 end |
131 function HHHasAmmo(Hedgehog: pointer; Ammo: TAmmoType): boolean; |
131 function HHHasAmmo(Hedgehog: pointer; Ammo: TAmmoType): boolean; |
132 var slot, ami: integer; |
132 var slot, ami: integer; |
133 begin |
133 begin |
134 Slot:= Ammoz[Ammo].Slot; |
134 Slot:= Ammoz[Ammo].Slot; |
135 ami:= 0; |
135 ami:= 0; |
136 Result:= false; |
136 while (ami <= cMaxSlotAmmoIndex) do |
137 while (not Result) and (ami <= cMaxSlotAmmoIndex) do |
|
138 begin |
137 begin |
139 with PHedgehog(Hedgehog).Ammo[Slot, ami] do |
138 with PHedgehog(Hedgehog)^.Ammo^[Slot, ami] do |
140 if (AmmoType = Ammo) and (Count > 0) then Result:= true; |
139 if (AmmoType = Ammo) and (Count > 0) then exit(true); |
141 inc(ami) |
140 inc(ami) |
142 end |
141 end; |
|
142 HHHasAmmo:= false |
143 end; |
143 end; |
144 |
144 |
145 end. |
145 end. |