21 uses uConsts, uTeams; |
21 uses uConsts, uTeams; |
22 {$INCLUDE options.inc} |
22 {$INCLUDE options.inc} |
23 |
23 |
24 procedure AddAmmoStore(s: shortstring); |
24 procedure AddAmmoStore(s: shortstring); |
25 procedure AssignStores; |
25 procedure AssignStores; |
26 procedure AddAmmo(Hedgehog: pointer; ammo: TAmmoType); |
26 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType); |
27 function HHHasAmmo(Hedgehog: pointer; Ammo: TAmmoType): boolean; |
27 function HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean; |
28 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt); |
28 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt); |
29 procedure OnUsedAmmo(var Hedgehog: THedgehog); |
29 procedure OnUsedAmmo(var Hedgehog: THedgehog); |
|
30 procedure ApplyAmmoChanges(var Hedgehog: THedgehog); |
|
31 procedure SwitchNotHoldedAmmo(var Hedgehog: THedgehog); |
30 |
32 |
31 implementation |
33 implementation |
32 uses uMisc, uGears; |
34 uses uMisc, uGears, uWorld, uLocale; |
33 type TAmmoCounts = array[TAmmoType] of Longword; |
35 type TAmmoCounts = array[TAmmoType] of Longword; |
34 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo; |
36 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo; |
35 StoreCnt: Longword = 0; |
37 StoreCnt: Longword = 0; |
36 |
38 |
37 procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts); |
39 procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts); |
89 if Hedgehogs[i].Gear <> nil then |
91 if Hedgehogs[i].Gear <> nil then |
90 Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore); |
92 Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore); |
91 end |
93 end |
92 end; |
94 end; |
93 |
95 |
94 procedure AddAmmo(Hedgehog: pointer; ammo: TAmmoType); |
96 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType); |
95 var ammos: TAmmoCounts; |
97 var ammos: TAmmoCounts; |
96 slot, ami: LongInt; |
98 slot, ami: LongInt; |
97 hhammo: PHHAmmo; |
99 hhammo: PHHAmmo; |
98 begin |
100 begin |
99 FillChar(ammos, sizeof(ammos), 0); |
101 FillChar(ammos, sizeof(ammos), 0); |
100 hhammo:= PHedgehog(Hedgehog)^.Ammo; |
102 hhammo:= Hedgehog.Ammo; |
101 |
103 |
102 for slot:= 0 to cMaxSlotIndex do |
104 for slot:= 0 to cMaxSlotIndex do |
103 for ami:= 0 to cMaxSlotAmmoIndex do |
105 for ami:= 0 to cMaxSlotAmmoIndex do |
104 if hhammo^[slot, ami].Count > 0 then |
106 if hhammo^[slot, ami].Count > 0 then |
105 ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count; |
107 ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count; |
116 b:= false; |
118 b:= false; |
117 ami:= 0; |
119 ami:= 0; |
118 while (not b) and (ami < cMaxSlotAmmoIndex) do |
120 while (not b) and (ami < cMaxSlotAmmoIndex) do |
119 if (Ammo^[Slot, ami].Count = 0) |
121 if (Ammo^[Slot, ami].Count = 0) |
120 and (Ammo^[Slot, ami + 1].Count > 0) then b:= true |
122 and (Ammo^[Slot, ami + 1].Count > 0) then b:= true |
121 else inc(ami); |
123 else inc(ami); |
122 if b then // there's a free item in ammo stack |
124 if b then // there's a free item in ammo stack |
123 begin |
125 begin |
124 Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1]; |
126 Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1]; |
125 Ammo^[Slot, ami + 1].Count:= 0 |
127 Ammo^[Slot, ami + 1].Count:= 0 |
126 end; |
128 end; |
141 if Count = 0 then PackAmmo(Ammo, CurSlot) |
143 if Count = 0 then PackAmmo(Ammo, CurSlot) |
142 end |
144 end |
143 end |
145 end |
144 end; |
146 end; |
145 |
147 |
146 function HHHasAmmo(Hedgehog: pointer; Ammo: TAmmoType): boolean; |
148 function HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean; |
147 var slot, ami: LongInt; |
149 var slot, ami: LongInt; |
148 begin |
150 begin |
149 Slot:= Ammoz[Ammo].Slot; |
151 Slot:= Ammoz[Ammo].Slot; |
150 ami:= 0; |
152 ami:= 0; |
151 while (ami <= cMaxSlotAmmoIndex) do |
153 while (ami <= cMaxSlotAmmoIndex) do |
152 begin |
154 begin |
153 with PHedgehog(Hedgehog)^.Ammo^[Slot, ami] do |
155 with Hedgehog.Ammo^[Slot, ami] do |
154 if (AmmoType = Ammo) and (Count > 0) then exit(true); |
156 if (AmmoType = Ammo) and (Count > 0) then exit(true); |
155 inc(ami) |
157 inc(ami) |
156 end; |
158 end; |
157 HHHasAmmo:= false |
159 HHHasAmmo:= false |
158 end; |
160 end; |
159 |
161 |
|
162 procedure ApplyAmmoChanges(var Hedgehog: THedgehog); |
|
163 var s: shortstring; |
|
164 begin |
|
165 TargetPoint.X:= NoPointX; |
|
166 |
|
167 with Hedgehog do |
|
168 begin |
|
169 if (Ammo^[CurSlot, CurAmmo].Count = 0)then |
|
170 begin |
|
171 CurAmmo:= 0; |
|
172 CurSlot:= 0; |
|
173 while (CurSlot <= cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do inc(CurSlot) |
|
174 end; |
|
175 |
|
176 with Ammo^[CurSlot, CurAmmo] do |
|
177 begin |
|
178 CurMinAngle:= Ammoz[AmmoType].minAngle; |
|
179 if Ammoz[AmmoType].maxAngle <> 0 then CurMaxAngle:= Ammoz[AmmoType].maxAngle |
|
180 else CurMaxAngle:= cMaxAngle; |
|
181 with Hedgehog.Gear^ do |
|
182 begin |
|
183 if Angle < CurMinAngle then Angle:= CurMinAngle; |
|
184 if Angle > CurMaxAngle then Angle:= CurMaxAngle; |
|
185 end; |
|
186 |
|
187 s:= trammo[Ammoz[AmmoType].NameId]; |
|
188 if Count <> AMMO_INFINITE then |
|
189 s:= s + ' (' + IntToStr(Count) + ')'; |
|
190 if (Propz and ammoprop_Timerable) <> 0 then |
|
191 s:= s + ', ' + inttostr(Timer div 1000) + ' ' + trammo[sidSeconds]; |
|
192 AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo); |
|
193 if (Propz and ammoprop_NeedTarget) <> 0 |
|
194 then begin |
|
195 Gear^.State:= Gear^.State or gstHHChooseTarget; |
|
196 isCursorVisible:= true |
|
197 end else begin |
|
198 Gear^.State:= Gear^.State and not gstHHChooseTarget; |
|
199 isCursorVisible:= false |
|
200 end; |
|
201 ShowCrosshair:= (Propz and ammoprop_NoCrosshair) = 0 |
|
202 end |
|
203 end |
|
204 end; |
|
205 |
|
206 procedure SwitchNotHoldedAmmo(var Hedgehog: THedgehog); |
|
207 begin |
|
208 with Hedgehog do |
|
209 if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0 then |
|
210 begin |
|
211 CurAmmo:= 0; |
|
212 CurSlot:= 0; |
|
213 while (CurSlot <= cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do inc(CurSlot) |
|
214 end |
|
215 end; |
|
216 |
160 end. |
217 end. |