author | unc0rr |
Sat, 11 Apr 2009 10:40:41 +0000 | |
changeset 1954 | 038c18bc58a1 |
parent 1922 | 88cdabb51995 |
child 1964 | dc9ea05c9d2f |
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); |
1922 | 30 |
procedure ApplyAngleBounds(var Hedgehog: THedgehog); |
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 |
|
36 |
implementation |
|
783 | 37 |
uses uMisc, uGears, uWorld, uLocale, uConsole; |
295 | 38 |
type TAmmoCounts = array[TAmmoType] of Longword; |
288 | 39 |
var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo; |
40 |
StoreCnt: Longword = 0; |
|
41 |
||
295 | 42 |
procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts); |
288 | 43 |
var mi: array[0..cMaxSlotIndex] of byte; |
44 |
a: TAmmoType; |
|
295 | 45 |
begin |
46 |
FillChar(mi, sizeof(mi), 0); |
|
47 |
FillChar(Ammo^, sizeof(Ammo^), 0); |
|
48 |
for a:= Low(TAmmoType) to High(TAmmoType) do |
|
49 |
if cnts[a] > 0 then |
|
50 |
begin |
|
51 |
TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); |
|
351 | 52 |
Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; |
53 |
Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnts[a]; |
|
295 | 54 |
inc(mi[Ammoz[a].Slot]) |
55 |
end |
|
56 |
end; |
|
57 |
||
58 |
procedure AddAmmoStore(s: shortstring); |
|
59 |
var cnt: Longword; |
|
60 |
a: TAmmoType; |
|
61 |
ammos: TAmmoCounts; |
|
288 | 62 |
begin |
63 |
TryDo(byte(s[0]) = byte(ord(High(TAmmoType)) + 1), 'Invalid ammo scheme (incompatible frontend)', true); |
|
64 |
||
65 |
inc(StoreCnt); |
|
66 |
TryDo(StoreCnt <= cMaxHHs, 'Ammo stores overflow', true); |
|
67 |
||
68 |
new(StoresList[Pred(StoreCnt)]); |
|
69 |
||
70 |
for a:= Low(TAmmoType) to High(TAmmoType) do |
|
71 |
begin |
|
72 |
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
|
73 |
if cnt = 9 then |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
74 |
begin |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
75 |
cnt:= AMMO_INFINITE; |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
76 |
Ammoz[a].Probability:= 0 |
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1850
diff
changeset
|
77 |
end; |
1895 | 78 |
if ((a = amLowGravity) and ((GameFlags and gfLowGravity) <> 0)) or |
79 |
((a = amInvulnerable) and ((GameFlags and gfInvulnerable) <> 0)) or |
|
80 |
((a = amLaserSight) and ((GameFlags and gfLaserSight) <> 0)) then |
|
81 |
begin |
|
82 |
cnt:= 0; |
|
83 |
Ammoz[a].Probability:= 0 |
|
84 |
end; |
|
295 | 85 |
ammos[a]:= cnt |
288 | 86 |
end; |
295 | 87 |
|
88 |
FillAmmoStore(StoresList[Pred(StoreCnt)], ammos) |
|
288 | 89 |
end; |
90 |
||
91 |
function GetAmmoByNum(num: Longword): PHHAmmo; |
|
92 |
begin |
|
93 |
TryDo(num < StoreCnt, 'Invalid store number', true); |
|
351 | 94 |
exit(StoresList[num]) |
288 | 95 |
end; |
96 |
||
97 |
procedure AssignStores; |
|
547 | 98 |
var t: LongInt; |
288 | 99 |
i: Longword; |
100 |
begin |
|
547 | 101 |
for t:= 0 to Pred(TeamsCount) do |
102 |
with TeamsArray[t]^ do |
|
288 | 103 |
begin |
104 |
for i:= 0 to cMaxHHIndex do |
|
547 | 105 |
if Hedgehogs[i].Gear <> nil then |
106 |
Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore); |
|
288 | 107 |
end |
108 |
end; |
|
109 |
||
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
110 |
procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType); |
295 | 111 |
var ammos: TAmmoCounts; |
371 | 112 |
slot, ami: LongInt; |
295 | 113 |
hhammo: PHHAmmo; |
114 |
begin |
|
115 |
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
|
116 |
hhammo:= Hedgehog.Ammo; |
295 | 117 |
|
118 |
for slot:= 0 to cMaxSlotIndex do |
|
119 |
for ami:= 0 to cMaxSlotAmmoIndex do |
|
351 | 120 |
if hhammo^[slot, ami].Count > 0 then |
121 |
ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count; |
|
295 | 122 |
|
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
|
295 | 129 |
FillAmmoStore(hhammo, ammos) |
130 |
end; |
|
131 |
||
371 | 132 |
procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt); |
133 |
var ami: LongInt; |
|
295 | 134 |
b: boolean; |
135 |
begin |
|
136 |
repeat |
|
137 |
b:= false; |
|
138 |
ami:= 0; |
|
139 |
while (not b) and (ami < cMaxSlotAmmoIndex) do |
|
351 | 140 |
if (Ammo^[Slot, ami].Count = 0) |
141 |
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
|
142 |
else inc(ami); |
295 | 143 |
if b then // there's a free item in ammo stack |
144 |
begin |
|
351 | 145 |
Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1]; |
146 |
Ammo^[Slot, ami + 1].Count:= 0 |
|
295 | 147 |
end; |
148 |
until not b; |
|
149 |
end; |
|
150 |
||
534 | 151 |
procedure OnUsedAmmo(var Hedgehog: THedgehog); |
295 | 152 |
begin |
534 | 153 |
with Hedgehog do |
971
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
154 |
begin |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
155 |
with Ammo^[CurSlot, CurAmmo] do |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
156 |
if Count <> AMMO_INFINITE then |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
157 |
begin |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
158 |
dec(Count); |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
159 |
if Count = 0 then |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
160 |
begin |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
161 |
PackAmmo(Ammo, CurSlot); |
1922 | 162 |
SwitchNotHeldAmmo(Hedgehog) |
971
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
163 |
end |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
164 |
end |
d2c49b730771
Fix a bug with automatic weapon switching when attacking from rope
unc0rr
parents:
941
diff
changeset
|
165 |
end |
295 | 166 |
end; |
167 |
||
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
168 |
function HHHasAmmo(var Hedgehog: THedgehog; Ammo: TAmmoType): boolean; |
371 | 169 |
var slot, ami: LongInt; |
295 | 170 |
begin |
171 |
Slot:= Ammoz[Ammo].Slot; |
|
172 |
ami:= 0; |
|
351 | 173 |
while (ami <= cMaxSlotAmmoIndex) do |
295 | 174 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
exit((Count > 0) and (Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns)); |
295 | 178 |
inc(ami) |
351 | 179 |
end; |
180 |
HHHasAmmo:= false |
|
295 | 181 |
end; |
182 |
||
1922 | 183 |
procedure ApplyAngleBounds(var Hedgehog: THedgehog); |
184 |
begin |
|
185 |
with Hedgehog do |
|
186 |
with Ammo^[CurSlot, CurAmmo] do |
|
187 |
begin |
|
188 |
CurMinAngle:= Ammoz[AmmoType].minAngle; |
|
189 |
if Ammoz[AmmoType].maxAngle <> 0 then |
|
190 |
CurMaxAngle:= Ammoz[AmmoType].maxAngle |
|
191 |
else |
|
192 |
CurMaxAngle:= cMaxAngle; |
|
193 |
||
194 |
with Hedgehog.Gear^ do |
|
195 |
begin |
|
196 |
if Angle < CurMinAngle then Angle:= CurMinAngle; |
|
197 |
if Angle > CurMaxAngle then Angle:= CurMaxAngle; |
|
198 |
end |
|
199 |
end |
|
200 |
end; |
|
201 |
||
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
202 |
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
|
203 |
var s: shortstring; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
204 |
begin |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
205 |
TargetPoint.X:= NoPointX; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
206 |
|
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
207 |
with Hedgehog do |
1922 | 208 |
begin |
209 |
if (Ammo^[CurSlot, CurAmmo].Count = 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 |
||
216 |
ApplyAngleBounds(Hedgehog); |
|
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
217 |
|
1922 | 218 |
with Ammo^[CurSlot, CurAmmo] do |
219 |
begin |
|
220 |
s:= trammo[Ammoz[AmmoType].NameId]; |
|
221 |
if Count <> AMMO_INFINITE then |
|
222 |
s:= s + ' (' + IntToStr(Count) + ')'; |
|
223 |
if (Propz and ammoprop_Timerable) <> 0 then |
|
224 |
s:= s + ', ' + inttostr(Timer div 1000) + ' ' + trammo[sidSeconds]; |
|
225 |
AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo); |
|
226 |
if (Propz and ammoprop_NeedTarget) <> 0 |
|
227 |
then begin |
|
228 |
Gear^.State:= Gear^.State or gstHHChooseTarget; |
|
229 |
isCursorVisible:= true |
|
230 |
end else begin |
|
231 |
Gear^.State:= Gear^.State and not gstHHChooseTarget; |
|
232 |
isCursorVisible:= false |
|
233 |
end; |
|
234 |
ShowCrosshair:= (Propz and ammoprop_NoCrosshair) = 0 |
|
235 |
end |
|
236 |
end |
|
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
237 |
end; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
238 |
|
1922 | 239 |
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
|
240 |
begin |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
241 |
with Hedgehog do |
1909 | 242 |
if ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0) or |
1915 | 243 |
(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
|
244 |
begin |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
245 |
CurAmmo:= 0; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
246 |
CurSlot:= 0; |
1909 | 247 |
while (CurSlot <= cMaxSlotIndex) and |
248 |
(Ammo^[CurSlot, CurAmmo].Count = 0) and |
|
1915 | 249 |
(Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) |
1909 | 250 |
do inc(CurSlot) |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
251 |
end |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
252 |
end; |
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
547
diff
changeset
|
253 |
|
783 | 254 |
procedure SetWeapon(weap: TAmmoType); |
255 |
begin |
|
1850 | 256 |
ParseCommand('/setweap ' + char(weap), true) |
783 | 257 |
end; |
258 |
||
1784 | 259 |
procedure DisableSomeWeapons; |
260 |
var i, slot, a: Longword; |
|
261 |
t: TAmmoType; |
|
262 |
begin |
|
263 |
for i:= 0 to Pred(StoreCnt) do |
|
264 |
for slot:= 0 to cMaxSlotIndex do |
|
265 |
begin |
|
266 |
for a:= 0 to cMaxSlotAmmoIndex do |
|
267 |
with StoresList[i]^[slot, a] do |
|
268 |
if (Propz and ammoprop_NotBorder) <> 0 then Count:= 0; |
|
269 |
||
270 |
PackAmmo(StoresList[i], slot) |
|
271 |
end; |
|
272 |
||
273 |
for t:= Low(TAmmoType) to High(TAmmoType) do |
|
274 |
if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0 |
|
275 |
end; |
|
276 |
||
288 | 277 |
end. |