author | unc0rr |
Tue, 18 Aug 2009 09:59:19 +0000 | |
changeset 2325 | b07e87f6430f |
parent 2246 | 4f138785a3ff |
child 2357 | babe1a55e284 |
permissions | -rw-r--r-- |
393 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2006-2008 Andrey Korotaev <unC0Rr@gmail.com> |
393 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
288 | 19 |
unit uAmmos; |
20 |
interface |
|
534 | 21 |
uses uConsts, uTeams; |
288 | 22 |
{$INCLUDE options.inc} |
23 |
||
24 |
procedure AddAmmoStore(s: shortstring); |
|
25 |
procedure AssignStores; |
|
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
26 |
procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType); |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
27 |
function HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean; |
371 | 28 |
procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt); |
534 | 29 |
procedure OnUsedAmmo(var Hedgehog: THedgehog); |
1964 | 30 |
procedure ApplyAngleBounds(var Hedgehog: THedgehog; AmmoType: TAmmoType); |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
31 |
procedure ApplyAmmoChanges(var Hedgehog: THedgehog); |
1922 | 32 |
procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog); |
783 | 33 |
procedure SetWeapon(weap: TAmmoType); |
1784 | 34 |
procedure DisableSomeWeapons; |
288 | 35 |
|
1966 | 36 |
var shoppa: Boolean = false; |
37 |
||
288 | 38 |
implementation |
783 | 39 |
uses uMisc, uGears, uWorld, uLocale, uConsole; |
295 | 40 |
type TAmmoCounts = array[TAmmoType] of Longword; |
288 | 41 |
var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo; |
42 |
StoreCnt: Longword = 0; |
|
43 |
||
295 | 44 |
procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts); |
288 | 45 |
var mi: array[0..cMaxSlotIndex] of byte; |
46 |
a: TAmmoType; |
|
295 | 47 |
begin |
48 |
FillChar(mi, sizeof(mi), 0); |
|
49 |
FillChar(Ammo^, sizeof(Ammo^), 0); |
|
50 |
for a:= Low(TAmmoType) to High(TAmmoType) do |
|
51 |
if cnts[a] > 0 then |
|
52 |
begin |
|
53 |
TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); |
|
351 | 54 |
Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; |
55 |
Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnts[a]; |
|
295 | 56 |
inc(mi[Ammoz[a].Slot]) |
57 |
end |
|
58 |
end; |
|
59 |
||
60 |
procedure AddAmmoStore(s: shortstring); |
|
61 |
var cnt: Longword; |
|
62 |
a: TAmmoType; |
|
63 |
ammos: TAmmoCounts; |
|
2017 | 64 |
substr: shortstring; // TEMPORARY |
288 | 65 |
begin |
66 |
TryDo(byte(s[0]) = byte(ord(High(TAmmoType)) + 1), 'Invalid ammo scheme (incompatible frontend)', true); |
|
67 |
||
2145 | 68 |
// FIXME - TEMPORARY hardcoded check on shoppa pending creation of probability editor |
2017 | 69 |
substr:= Copy(s,1,15); |
70 |
if (substr = '000000990000009') or |
|
71 |
(substr = '000000990000000') then |
|
1966 | 72 |
shoppa:= true; |
2017 | 73 |
for a:= Low(TAmmoType) to High(TAmmoType) do |
74 |
if (ord(a) > 14) and (s[ord(a)+1] <> '0') then shoppa:= false; // TEMPORARY etc - this just avoids updating every time new wep is added |
|
288 | 75 |
inc(StoreCnt); |
76 |
TryDo(StoreCnt <= cMaxHHs, 'Ammo stores overflow', true); |
|
77 |
||
78 |
new(StoresList[Pred(StoreCnt)]); |
|
79 |
||
80 |
for a:= Low(TAmmoType) to High(TAmmoType) do |
|
81 |
begin |
|
82 |
cnt:= byte(s[ord(a) + 1]) - byte('0'); |
|
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
83 |
if cnt = 9 then |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
84 |
begin |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
85 |
cnt:= AMMO_INFINITE; |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
86 |
Ammoz[a].Probability:= 0 |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
87 |
end; |
1895 | 88 |
if ((a = amLowGravity) and ((GameFlags and gfLowGravity) <> 0)) or |
89 |
((a = amInvulnerable) and ((GameFlags and gfInvulnerable) <> 0)) or |
|
2017 | 90 |
((a = amLaserSight) and ((GameFlags and gfLaserSight) <> 0)) or |
91 |
((a = amVampiric) and ((GameFlags and gfVampiric) <> 0)) then |
|
1895 | 92 |
begin |
93 |
cnt:= 0; |
|
94 |
Ammoz[a].Probability:= 0 |
|
1966 | 95 |
end |
2145 | 96 |
else if shoppa then // FIXME - TEMPORARY REMOVE WHEN CRATE PROBABILITY IS ADDED |
2073 | 97 |
if cnt <> AMMO_INFINITE then |
2128 | 98 |
begin |
2061
0f99aa28b9f4
Should disable construction in the shoppa hack, I think. Construction is annoying
nemo
parents:
2017
diff
changeset
|
99 |
if a = amGirder then |
0f99aa28b9f4
Should disable construction in the shoppa hack, I think. Construction is annoying
nemo
parents:
2017
diff
changeset
|
100 |
Ammoz[a].Probability:= 0 |
0f99aa28b9f4
Should disable construction in the shoppa hack, I think. Construction is annoying
nemo
parents:
2017
diff
changeset
|
101 |
else |
2246 | 102 |
begin |
2073 | 103 |
Ammoz[a].Probability:= 100; |
2246 | 104 |
Ammoz[a].NumberInCase:= 1; |
105 |
end |
|
2128 | 106 |
end; |
295 | 107 |
ammos[a]:= cnt |
288 | 108 |
end; |
295 | 109 |
|
110 |
FillAmmoStore(StoresList[Pred(StoreCnt)], ammos) |
|
288 | 111 |
end; |
112 |
||
113 |
function GetAmmoByNum(num: Longword): PHHAmmo; |
|
114 |
begin |
|
115 |
TryDo(num < StoreCnt, 'Invalid store number', true); |
|
351 | 116 |
exit(StoresList[num]) |
288 | 117 |
end; |
118 |
||
119 |
procedure AssignStores; |
|
547 | 120 |
var t: LongInt; |
288 | 121 |
i: Longword; |
122 |
begin |
|
547 | 123 |
for t:= 0 to Pred(TeamsCount) do |
124 |
with TeamsArray[t]^ do |
|
288 | 125 |
begin |
126 |
for i:= 0 to cMaxHHIndex do |
|
547 | 127 |
if Hedgehogs[i].Gear <> nil then |
128 |
Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore); |
|
288 | 129 |
end |
130 |
end; |
|
131 |
||
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
132 |
procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType); |
295 | 133 |
var ammos: TAmmoCounts; |
371 | 134 |
slot, ami: LongInt; |
295 | 135 |
hhammo: PHHAmmo; |
136 |
begin |
|
137 |
FillChar(ammos, sizeof(ammos), 0); |
|
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
138 |
hhammo:= Hedgehog.Ammo; |
295 | 139 |
|
140 |
for slot:= 0 to cMaxSlotIndex do |
|
141 |
for ami:= 0 to cMaxSlotAmmoIndex do |
|
351 | 142 |
if hhammo^[slot, ami].Count > 0 then |
143 |
ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count; |
|
295 | 144 |
|
941
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
145 |
if ammos[ammo] <> AMMO_INFINITE then |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
146 |
begin |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
147 |
inc(ammos[ammo], Ammoz[ammo].NumberInCase); |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
148 |
if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
149 |
end; |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
150 |
|
295 | 151 |
FillAmmoStore(hhammo, ammos) |
152 |
end; |
|
153 |
||
371 | 154 |
procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt); |
155 |
var ami: LongInt; |
|
295 | 156 |
b: boolean; |
157 |
begin |
|
158 |
repeat |
|
159 |
b:= false; |
|
160 |
ami:= 0; |
|
161 |
while (not b) and (ami < cMaxSlotAmmoIndex) do |
|
351 | 162 |
if (Ammo^[Slot, ami].Count = 0) |
163 |
and (Ammo^[Slot, ami + 1].Count > 0) then b:= true |
|
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
164 |
else inc(ami); |
2221 | 165 |
if b then // there is a free item in ammo stack |
295 | 166 |
begin |
351 | 167 |
Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1]; |
168 |
Ammo^[Slot, ami + 1].Count:= 0 |
|
295 | 169 |
end; |
170 |
until not b; |
|
171 |
end; |
|
172 |
||
534 | 173 |
procedure OnUsedAmmo(var Hedgehog: THedgehog); |
295 | 174 |
begin |
534 | 175 |
with Hedgehog do |
971
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
176 |
begin |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
177 |
with Ammo^[CurSlot, CurAmmo] do |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
178 |
if Count <> AMMO_INFINITE then |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
179 |
begin |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
180 |
dec(Count); |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
181 |
if Count = 0 then |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
182 |
begin |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
183 |
PackAmmo(Ammo, CurSlot); |
1922 | 184 |
SwitchNotHeldAmmo(Hedgehog) |
971
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
185 |
end |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
186 |
end |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
187 |
end |
295 | 188 |
end; |
189 |
||
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
190 |
function HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean; |
371 | 191 |
var slot, ami: LongInt; |
295 | 192 |
begin |
193 |
Slot:= Ammoz[Ammo].Slot; |
|
194 |
ami:= 0; |
|
351 | 195 |
while (ami <= cMaxSlotAmmoIndex) do |
295 | 196 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
197 |
with Hedgehog.Ammo^[Slot, ami] do |
941
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
198 |
if (AmmoType = Ammo) then |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
199 |
exit((Count > 0) and (Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns)); |
295 | 200 |
inc(ami) |
351 | 201 |
end; |
202 |
HHHasAmmo:= false |
|
295 | 203 |
end; |
204 |
||
1964 | 205 |
procedure ApplyAngleBounds(var Hedgehog: THedgehog; AmmoType: TAmmoType); |
1922 | 206 |
begin |
207 |
with Hedgehog do |
|
1964 | 208 |
begin |
209 |
CurMinAngle:= Ammoz[AmmoType].minAngle; |
|
210 |
if Ammoz[AmmoType].maxAngle <> 0 then |
|
211 |
CurMaxAngle:= Ammoz[AmmoType].maxAngle |
|
212 |
else |
|
213 |
CurMaxAngle:= cMaxAngle; |
|
214 |
||
215 |
with Hedgehog.Gear^ do |
|
1922 | 216 |
begin |
1964 | 217 |
if Angle < CurMinAngle then Angle:= CurMinAngle; |
218 |
if Angle > CurMaxAngle then Angle:= CurMaxAngle; |
|
1922 | 219 |
end |
1964 | 220 |
end |
1922 | 221 |
end; |
222 |
||
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
223 |
procedure ApplyAmmoChanges(var Hedgehog: THedgehog); |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
224 |
var s: shortstring; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
225 |
begin |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
226 |
TargetPoint.X:= NoPointX; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
227 |
|
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
228 |
with Hedgehog do |
1922 | 229 |
begin |
230 |
if (Ammo^[CurSlot, CurAmmo].Count = 0) then |
|
231 |
begin |
|
232 |
CurAmmo:= 0; |
|
233 |
CurSlot:= 0; |
|
234 |
while (CurSlot <= cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do inc(CurSlot) |
|
235 |
end; |
|
236 |
||
1964 | 237 |
ApplyAngleBounds(Hedgehog, Ammo^[CurSlot, CurAmmo].AmmoType); |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
238 |
|
1922 | 239 |
with Ammo^[CurSlot, CurAmmo] do |
240 |
begin |
|
241 |
s:= trammo[Ammoz[AmmoType].NameId]; |
|
2176 | 242 |
if (Count <> AMMO_INFINITE) and not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0)) then |
1922 | 243 |
s:= s + ' (' + IntToStr(Count) + ')'; |
244 |
if (Propz and ammoprop_Timerable) <> 0 then |
|
245 |
s:= s + ', ' + inttostr(Timer div 1000) + ' ' + trammo[sidSeconds]; |
|
246 |
AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo); |
|
247 |
if (Propz and ammoprop_NeedTarget) <> 0 |
|
248 |
then begin |
|
249 |
Gear^.State:= Gear^.State or gstHHChooseTarget; |
|
250 |
isCursorVisible:= true |
|
251 |
end else begin |
|
252 |
Gear^.State:= Gear^.State and not gstHHChooseTarget; |
|
253 |
isCursorVisible:= false |
|
254 |
end; |
|
255 |
ShowCrosshair:= (Propz and ammoprop_NoCrosshair) = 0 |
|
256 |
end |
|
257 |
end |
|
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
258 |
end; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
259 |
|
1922 | 260 |
procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog); |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
261 |
begin |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
262 |
with Hedgehog do |
1909 | 263 |
if ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0) or |
1915 | 264 |
(Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
265 |
begin |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
266 |
CurAmmo:= 0; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
267 |
CurSlot:= 0; |
1909 | 268 |
while (CurSlot <= cMaxSlotIndex) and |
269 |
(Ammo^[CurSlot, CurAmmo].Count = 0) and |
|
1915 | 270 |
(Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) |
1909 | 271 |
do inc(CurSlot) |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
272 |
end |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
273 |
end; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
274 |
|
783 | 275 |
procedure SetWeapon(weap: TAmmoType); |
276 |
begin |
|
1850 | 277 |
ParseCommand('/setweap ' + char(weap), true) |
783 | 278 |
end; |
279 |
||
1784 | 280 |
procedure DisableSomeWeapons; |
281 |
var i, slot, a: Longword; |
|
282 |
t: TAmmoType; |
|
283 |
begin |
|
284 |
for i:= 0 to Pred(StoreCnt) do |
|
285 |
for slot:= 0 to cMaxSlotIndex do |
|
286 |
begin |
|
287 |
for a:= 0 to cMaxSlotAmmoIndex do |
|
288 |
with StoresList[i]^[slot, a] do |
|
289 |
if (Propz and ammoprop_NotBorder) <> 0 then Count:= 0; |
|
290 |
||
291 |
PackAmmo(StoresList[i], slot) |
|
292 |
end; |
|
293 |
||
294 |
for t:= Low(TAmmoType) to High(TAmmoType) do |
|
295 |
if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0 |
|
296 |
end; |
|
297 |
||
288 | 298 |
end. |