author | unc0rr |
Tue, 05 Dec 2006 17:27:27 +0000 | |
changeset 288 | 929c44745fd9 |
parent 283 | 28d105f378f1 |
child 292 | 0ca921ca7557 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
47 | 3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 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 |
|
4 | 8 |
* |
183 | 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. |
|
4 | 13 |
* |
183 | 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 |
|
4 | 17 |
*) |
18 |
||
19 |
unit uGears; |
|
20 |
interface |
|
21 |
uses SDLh, uConsts; |
|
22 |
{$INCLUDE options.inc} |
|
23 |
const AllInactive: boolean = false; |
|
24 |
||
25 |
type PGear = ^TGear; |
|
26 |
TGearStepProcedure = procedure (Gear: PGear); |
|
27 |
TGear = record |
|
28 |
NextGear, PrevGear: PGear; |
|
29 |
Active: Boolean; |
|
188 | 30 |
State : Longword; |
108 | 31 |
X : Double; |
32 |
Y : Double; |
|
33 |
dX: Double; |
|
34 |
dY: Double; |
|
42 | 35 |
Kind: TGearType; |
36 |
Pos: Longword; |
|
4 | 37 |
doStep: TGearStepProcedure; |
53 | 38 |
Radius: integer; |
188 | 39 |
Angle, Power : Longword; |
107 | 40 |
DirAngle: Double; |
4 | 41 |
Timer : LongWord; |
108 | 42 |
Elasticity: Double; |
43 |
Friction : Double; |
|
4 | 44 |
Message : Longword; |
45 |
Hedgehog: pointer; |
|
38 | 46 |
Health, Damage: integer; |
4 | 47 |
CollIndex: Longword; |
6 | 48 |
Tag: integer; |
95 | 49 |
Surf: PSDL_Surface; |
4 | 50 |
end; |
51 |
||
188 | 52 |
function AddGear(X, Y: integer; Kind: TGearType; State: Longword; const dX: Double=0.0; dY: Double=0.0; Timer: LongWord=0): PGear; |
4 | 53 |
procedure ProcessGears; |
54 |
procedure SetAllToActive; |
|
55 |
procedure SetAllHHToActive; |
|
56 |
procedure DrawGears(Surface: PSDL_Surface); |
|
57 |
procedure FreeGearsList; |
|
10 | 58 |
procedure AddMiscGears; |
4 | 59 |
procedure AssignHHCoords; |
60 |
||
61 |
var CurAmmoGear: PGear = nil; |
|
68 | 62 |
GearsList: PGear = nil; |
70 | 63 |
|
4 | 64 |
implementation |
81 | 65 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, |
145 | 66 |
uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI; |
68 | 67 |
var RopePoints: record |
4 | 68 |
Count: Longword; |
69 |
HookAngle: integer; |
|
70 |
ar: array[0..300] of record |
|
107 | 71 |
X, Y: Double; |
72 |
dLen: Double; |
|
4 | 73 |
b: boolean; |
74 |
end; |
|
75 |
end; |
|
76 |
||
77 |
procedure DeleteGear(Gear: PGear); forward; |
|
78 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward; |
|
75 | 79 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); forward; |
79 | 80 |
procedure AmmoFlameWork(Ammo: PGear); forward; |
17 | 81 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; forward; |
15 | 82 |
procedure SpawnBoxOfSmth; forward; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset
|
83 |
procedure AfterAttack; forward; |
70 | 84 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); forward; |
4 | 85 |
|
86 |
{$INCLUDE GSHandlers.inc} |
|
87 |
{$INCLUDE HHHandlers.inc} |
|
88 |
||
89 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
90 |
doStepCloud, |
|
91 |
doStepBomb, |
|
92 |
doStepHedgehog, |
|
93 |
doStepGrenade, |
|
94 |
doStepHealthTag, |
|
95 |
doStepGrave, |
|
96 |
doStepUFO, |
|
97 |
doStepShotgunShot, |
|
98 |
doStepPickHammer, |
|
99 |
doStepRope, |
|
9 | 100 |
doStepSmokeTrace, |
10 | 101 |
doStepExplosion, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
102 |
doStepMine, |
37 | 103 |
doStepCase, |
39 | 104 |
doStepDEagleShot, |
49 | 105 |
doStepDynamite, |
78 | 106 |
doStepTeamHealthSorter, |
107 |
doStepBomb, |
|
79 | 108 |
doStepCluster, |
109 |
doStepShover, |
|
82 | 110 |
doStepFlame, |
83 | 111 |
doStepFirePunch, |
112 |
doStepActionTimer, |
|
113 |
doStepActionTimer, |
|
211 | 114 |
doStepActionTimer, |
263 | 115 |
doStepParachute, |
116 |
doStepAirAttack, |
|
117 |
doStepAirBomb |
|
4 | 118 |
); |
119 |
||
188 | 120 |
function AddGear(X, Y: integer; Kind: TGearType; State: Longword; const dX: Double=0.0; dY: Double=0.0; Timer: LongWord=0): PGear; |
79 | 121 |
const Counter: Longword = 0; |
4 | 122 |
begin |
79 | 123 |
inc(Counter); |
108 | 124 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF} |
4 | 125 |
New(Result); |
126 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: handle = '+inttostr(integer(Result)));{$ENDIF} |
|
127 |
FillChar(Result^, sizeof(TGear), 0); |
|
128 |
Result.X:= X; |
|
129 |
Result.Y:= Y; |
|
130 |
Result.Kind := Kind; |
|
131 |
Result.State:= State; |
|
132 |
Result.Active:= true; |
|
133 |
Result.dX:= dX; |
|
134 |
Result.dY:= dY; |
|
135 |
Result.doStep:= doStepHandlers[Kind]; |
|
136 |
Result.CollIndex:= High(Longword); |
|
83 | 137 |
Result.Timer:= Timer; |
4 | 138 |
if CurrentTeam <> nil then |
139 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]; |
|
140 |
case Kind of |
|
141 |
gtAmmo_Bomb: begin |
|
53 | 142 |
Result.Radius:= 4; |
4 | 143 |
Result.Elasticity:= 0.6; |
144 |
Result.Friction:= 0.995; |
|
145 |
end; |
|
146 |
gtHedgehog: begin |
|
53 | 147 |
Result.Radius:= cHHRadius; |
149 | 148 |
Result.Elasticity:= 0.35; |
70 | 149 |
Result.Friction:= 0.999; |
64 | 150 |
Result.Angle:= cMaxAngle div 2; |
4 | 151 |
end; |
152 |
gtAmmo_Grenade: begin |
|
53 | 153 |
Result.Radius:= 4; |
4 | 154 |
end; |
155 |
gtHealthTag: begin |
|
156 |
Result.Timer:= 1500; |
|
157 |
end; |
|
158 |
gtGrave: begin |
|
53 | 159 |
Result.Radius:= 10; |
4 | 160 |
Result.Elasticity:= 0.6; |
161 |
end; |
|
162 |
gtUFO: begin |
|
53 | 163 |
Result.Radius:= 5; |
4 | 164 |
Result.Timer:= 500; |
165 |
Result.Elasticity:= 0.9 |
|
166 |
end; |
|
167 |
gtShotgunShot: begin |
|
168 |
Result.Timer:= 900; |
|
53 | 169 |
Result.Radius:= 2 |
4 | 170 |
end; |
171 |
gtPickHammer: begin |
|
53 | 172 |
Result.Radius:= 10; |
4 | 173 |
Result.Timer:= 4000 |
174 |
end; |
|
175 |
gtSmokeTrace: begin |
|
9 | 176 |
Result.X:= Result.X - 16; |
177 |
Result.Y:= Result.Y - 16; |
|
178 |
Result.State:= 8 |
|
4 | 179 |
end; |
180 |
gtRope: begin |
|
53 | 181 |
Result.Radius:= 3; |
4 | 182 |
Result.Friction:= 500; |
183 |
RopePoints.Count:= 0; |
|
184 |
end; |
|
9 | 185 |
gtExplosion: begin |
186 |
Result.X:= Result.X - 25; |
|
187 |
Result.Y:= Result.Y - 25; |
|
188 |
end; |
|
10 | 189 |
gtMine: begin |
53 | 190 |
Result.Radius:= 3; |
10 | 191 |
Result.Elasticity:= 0.55; |
192 |
Result.Friction:= 0.995; |
|
193 |
Result.Timer:= 3000; |
|
194 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
195 |
gtCase: begin |
75 | 196 |
Result.Radius:= 16; |
145 | 197 |
Result.Elasticity:= 0.4 |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
198 |
end; |
37 | 199 |
gtDEagleShot: begin |
53 | 200 |
Result.Radius:= 1; |
201 |
Result.Radius:= 1; |
|
38 | 202 |
Result.Health:= 50 |
37 | 203 |
end; |
39 | 204 |
gtDynamite: begin |
53 | 205 |
Result.Radius:= 3; |
56 | 206 |
Result.Elasticity:= 0.55; |
39 | 207 |
Result.Friction:= 0.03; |
208 |
Result.Timer:= 5000; |
|
209 |
end; |
|
78 | 210 |
gtClusterBomb: begin |
211 |
Result.Radius:= 4; |
|
212 |
Result.Elasticity:= 0.6; |
|
213 |
Result.Friction:= 0.995; |
|
214 |
end; |
|
79 | 215 |
gtFlame: begin |
216 |
Result.Angle:= Counter mod 64; |
|
217 |
Result.Radius:= 1; |
|
218 |
Result.Health:= 2; |
|
219 |
Result.dY:= (getrandom - 0.8) * 0.03; |
|
220 |
Result.dX:= (getrandom - 0.5) * 0.4 |
|
221 |
end; |
|
82 | 222 |
gtFirePunch: begin |
223 |
Result.Radius:= 15; |
|
224 |
Result.Tag:= Y |
|
225 |
end; |
|
263 | 226 |
gtAirBomb: begin |
227 |
Result.Radius:= 3; |
|
228 |
end; |
|
4 | 229 |
end; |
230 |
if GearsList = nil then GearsList:= Result |
|
231 |
else begin |
|
232 |
GearsList.PrevGear:= Result; |
|
233 |
Result.NextGear:= GearsList; |
|
234 |
GearsList:= Result |
|
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
188
diff
changeset
|
235 |
end |
4 | 236 |
end; |
237 |
||
238 |
procedure DeleteGear(Gear: PGear); |
|
48 | 239 |
var team: PTeam; |
4 | 240 |
begin |
53 | 241 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
95 | 242 |
if Gear.Surf <> nil then SDL_FreeSurface(Gear.Surf); |
4 | 243 |
if Gear.Kind = gtHedgehog then |
244 |
if CurAmmoGear <> nil then |
|
245 |
begin |
|
246 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
247 |
Gear.Message:= gm_Destroy; |
|
248 |
CurAmmoGear.Message:= gm_Destroy; |
|
249 |
exit |
|
47 | 250 |
end else |
251 |
begin |
|
263 | 252 |
if Gear.Y >= cWaterLine then |
253 |
AddGear(Round(Gear.X), Round(Gear.Y), gtHealthTag, max(Gear.Damage, Gear.Health)).Hedgehog:= Gear.Hedgehog; |
|
48 | 254 |
team:= PHedgehog(Gear.Hedgehog).Team; |
145 | 255 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear = Gear then |
256 |
FreeActionsList; // to avoid ThinkThread on drawned gear |
|
263 | 257 |
PHedgehog(Gear.Hedgehog).Gear:= nil; |
48 | 258 |
RecountTeamHealth(team); |
47 | 259 |
end; |
95 | 260 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} |
82 | 261 |
if CurAmmoGear = Gear then CurAmmoGear:= nil; |
4 | 262 |
if FollowGear = Gear then FollowGear:= nil; |
263 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; |
|
264 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear |
|
265 |
else begin |
|
266 |
GearsList:= Gear^.NextGear; |
|
267 |
if GearsList <> nil then GearsList.PrevGear:= nil |
|
268 |
end; |
|
269 |
Dispose(Gear) |
|
270 |
end; |
|
271 |
||
272 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
273 |
var Gear: PGear; |
|
274 |
begin |
|
275 |
Result:= true; |
|
276 |
Gear:= GearsList; |
|
277 |
while Gear <> nil do |
|
278 |
begin |
|
279 |
if Gear.Kind = gtHedgehog then |
|
280 |
if Gear.Damage <> 0 then |
|
281 |
begin |
|
282 |
Result:= false; |
|
283 |
if Gear.Health < Gear.Damage then Gear.Health:= 0 |
|
284 |
else dec(Gear.Health, Gear.Damage); |
|
285 |
AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog; |
|
286 |
RenderHealth(PHedgehog(Gear.Hedgehog)^); |
|
47 | 287 |
RecountTeamHealth(PHedgehog(Gear.Hedgehog)^.Team); |
4 | 288 |
|
289 |
Gear.Damage:= 0 |
|
290 |
end; |
|
291 |
Gear:= Gear.NextGear |
|
83 | 292 |
end; |
4 | 293 |
end; |
294 |
||
295 |
procedure ProcessGears; |
|
296 |
const delay: integer = cInactDelay; |
|
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
297 |
step: (stDelay, stChDmg, stChWin, stSpawn, stNTurn) = stDelay; |
4 | 298 |
var Gear, t: PGear; |
299 |
{$IFDEF COUNTTICKS} |
|
300 |
tickcntA, tickcntB: LongWord; |
|
301 |
const cntSecTicks: LongWord = 0; |
|
302 |
{$ENDIF} |
|
303 |
begin |
|
304 |
{$IFDEF COUNTTICKS} |
|
305 |
asm |
|
306 |
push eax |
|
307 |
push edx |
|
308 |
rdtsc |
|
309 |
mov tickcntA, eax |
|
310 |
mov tickcntB, edx |
|
311 |
pop edx |
|
312 |
pop eax |
|
313 |
end; |
|
314 |
{$ENDIF} |
|
315 |
AllInactive:= true; |
|
316 |
t:= GearsList; |
|
317 |
while t<>nil do |
|
318 |
begin |
|
319 |
Gear:= t; |
|
320 |
t:= Gear.NextGear; |
|
321 |
if Gear.Active then Gear.doStep(Gear); |
|
322 |
end; |
|
89 | 323 |
|
4 | 324 |
if AllInactive then |
15 | 325 |
case step of |
326 |
stDelay: begin |
|
327 |
dec(delay); |
|
328 |
if delay = 0 then |
|
329 |
begin |
|
330 |
inc(step); |
|
331 |
delay:= cInactDelay |
|
332 |
end |
|
333 |
end; |
|
334 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
335 |
stChWin: if not CheckForWin then inc(step) else step:= stDelay; |
15 | 336 |
stSpawn: begin |
337 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
338 |
inc(step) |
|
339 |
end; |
|
340 |
stNTurn: begin |
|
74 | 341 |
AwareOfExplosion(0, 0, 0); |
15 | 342 |
if isInMultiShoot then isInMultiShoot:= false |
343 |
else ParseCommand('/nextturn'); |
|
344 |
step:= Low(step) |
|
345 |
end; |
|
346 |
end; |
|
347 |
||
4 | 348 |
if TurnTimeLeft > 0 then |
349 |
if CurrentTeam <> nil then |
|
350 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then |
|
351 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0) |
|
352 |
and not isInMultiShoot then dec(TurnTimeLeft); |
|
74 | 353 |
|
4 | 354 |
inc(GameTicks); |
355 |
{$IFDEF COUNTTICKS} |
|
356 |
asm |
|
357 |
push eax |
|
358 |
push edx |
|
359 |
rdtsc |
|
360 |
sub eax, [tickcntA] |
|
361 |
sbb edx, [tickcntB] |
|
362 |
add [cntSecTicks], eax |
|
363 |
pop edx |
|
364 |
pop eax |
|
365 |
end; |
|
366 |
if (GameTicks and 1023) = 0 then |
|
367 |
begin |
|
368 |
cntTicks:= cntSecTicks shr 10; |
|
369 |
{$IFDEF DEBUGFILE} |
|
370 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
371 |
{$ENDIF} |
|
372 |
cntSecTicks:= 0 |
|
373 |
end; |
|
374 |
{$ENDIF} |
|
375 |
end; |
|
376 |
||
377 |
procedure SetAllToActive; |
|
378 |
var t: PGear; |
|
379 |
begin |
|
380 |
AllInactive:= false; |
|
381 |
t:= GearsList; |
|
382 |
while t<>nil do |
|
383 |
begin |
|
384 |
t.Active:= true; |
|
385 |
t:= t.NextGear |
|
386 |
end |
|
387 |
end; |
|
388 |
||
389 |
procedure SetAllHHToActive; |
|
390 |
var t: PGear; |
|
391 |
begin |
|
392 |
AllInactive:= false; |
|
393 |
t:= GearsList; |
|
394 |
while t<>nil do |
|
395 |
begin |
|
396 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
397 |
t:= t.NextGear |
|
398 |
end |
|
399 |
end; |
|
400 |
||
401 |
procedure DrawGears(Surface: PSDL_Surface); |
|
402 |
var Gear: PGear; |
|
403 |
i: Longword; |
|
107 | 404 |
roplen: Double; |
4 | 405 |
|
406 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
35 | 407 |
const nodlen = 5; |
408 |
var i, x, y: integer; |
|
107 | 409 |
t, k, ladd: Double; |
4 | 410 |
begin |
37 | 411 |
if (X1 = X2) and (Y1 = Y2) then |
412 |
begin |
|
83 | 413 |
OutError('WARNING: zero length rope line!'); |
37 | 414 |
exit |
415 |
end; |
|
4 | 416 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
417 |
begin |
|
418 |
if X1 > X2 then |
|
419 |
begin |
|
420 |
i:= X1; |
|
421 |
X1:= X2; |
|
422 |
X2:= i; |
|
423 |
i:= Y1; |
|
424 |
Y1:= Y2; |
|
425 |
Y2:= i |
|
426 |
end; |
|
427 |
k:= (Y2 - Y1) / (X2 - X1); |
|
35 | 428 |
ladd:= sqrt(1 + sqr(k)); |
4 | 429 |
if X1 < 0 then |
430 |
begin |
|
431 |
t:= Y1 - 2 - k * X1; |
|
432 |
X1:= 0 |
|
433 |
end else t:= Y1 - 2; |
|
434 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
35 | 435 |
for x:= X1 to X2 do |
436 |
begin |
|
437 |
roplen:= roplen + ladd; |
|
438 |
if roplen > nodlen then |
|
439 |
begin |
|
440 |
DrawGear(sRopeNode, x - 2, round(t) - 2, Surface); |
|
441 |
roplen:= roplen - nodlen; |
|
442 |
end; |
|
443 |
t:= t + k; |
|
444 |
end; |
|
4 | 445 |
end else |
446 |
begin |
|
447 |
if Y1 > Y2 then |
|
448 |
begin |
|
449 |
i:= X1; |
|
450 |
X1:= X2; |
|
451 |
X2:= i; |
|
452 |
i:= Y1; |
|
453 |
Y1:= Y2; |
|
454 |
Y2:= i |
|
455 |
end; |
|
456 |
k:= (X2 - X1) / (Y2 - Y1); |
|
35 | 457 |
ladd:= sqrt(1 + sqr(k)); |
4 | 458 |
if Y1 < 0 then |
459 |
begin |
|
460 |
t:= X1 - 2 - k * Y1; |
|
461 |
Y1:= 0 |
|
462 |
end else t:= X1 - 2; |
|
463 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
35 | 464 |
for y:= Y1 to Y2 do |
465 |
begin |
|
466 |
roplen:= roplen + ladd; |
|
467 |
if roplen > nodlen then |
|
468 |
begin |
|
469 |
DrawGear(sRopeNode, round(t) - 2, y - 2, Surface); |
|
470 |
roplen:= roplen - nodlen; |
|
471 |
end; |
|
472 |
t:= t + k; |
|
473 |
end; |
|
4 | 474 |
end |
475 |
end; |
|
476 |
||
477 |
begin |
|
478 |
Gear:= GearsList; |
|
479 |
while Gear<>nil do |
|
480 |
begin |
|
481 |
case Gear.Kind of |
|
482 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
483 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
108 | 484 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, hwSign(Gear.dX), |
4 | 485 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2, |
486 |
Surface); |
|
487 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
95 | 488 |
gtHealthTag: if Gear.Surf <> nil then DrawCentered(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.Surf, Surface); |
4 | 489 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
490 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 491 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 492 |
gtRope: begin |
35 | 493 |
roplen:= 0; |
4 | 494 |
if RopePoints.Count > 0 then |
495 |
begin |
|
496 |
i:= 0; |
|
497 |
while i < Pred(RopePoints.Count) do |
|
498 |
begin |
|
499 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
500 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
501 |
inc(i) |
|
502 |
end; |
|
503 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
504 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
35 | 505 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
506 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 507 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
508 |
end else |
|
35 | 509 |
begin |
510 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
511 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 512 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
35 | 513 |
end; |
4 | 514 |
end; |
9 | 515 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 516 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
517 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
518 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
46 | 519 |
gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 25 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface); |
42 | 520 |
gtCase: case Gear.Pos of |
521 |
posCaseAmmo : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface); |
|
75 | 522 |
posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 24 + WorldDx, Round(Gear.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
42 | 523 |
end; |
78 | 524 |
gtClusterBomb: DrawSprite(sprClusterBomb, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
525 |
gtCluster: DrawSprite(sprClusterParticle, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, 0, Surface); |
|
79 | 526 |
gtFlame: DrawSprite(sprFlame, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy,(GameTicks div 128 + Gear.Angle) mod 8, Surface); |
263 | 527 |
gtAirBomb: DrawSprite(sprAirBomb , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
283 | 528 |
gtAirAttack: DrawSprite(sprAirplane, Round(Gear.X) - 60 + WorldDx, Round(Gear.Y) - 25 + WorldDy, 0, Surface); |
4 | 529 |
end; |
530 |
Gear:= Gear.NextGear |
|
531 |
end; |
|
532 |
end; |
|
533 |
||
534 |
procedure FreeGearsList; |
|
535 |
var t, tt: PGear; |
|
536 |
begin |
|
537 |
tt:= GearsList; |
|
538 |
GearsList:= nil; |
|
539 |
while tt<>nil do |
|
540 |
begin |
|
541 |
t:= tt; |
|
542 |
tt:= tt.NextGear; |
|
543 |
Dispose(t) |
|
544 |
end; |
|
545 |
end; |
|
546 |
||
10 | 547 |
procedure AddMiscGears; |
70 | 548 |
var i: integer; |
4 | 549 |
begin |
74 | 550 |
for i:= 0 to cCloudsNumber do |
551 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), |
|
95 | 552 |
(0.5-random)*0.1, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); |
83 | 553 |
AddGear(0, 0, gtATStartGame, 0, 0, 0, 2000); |
22 | 554 |
if (GameFlags and gfForts) = 0 then |
555 |
for i:= 0 to 3 do |
|
70 | 556 |
FindPlace(AddGear(0, 0, gtMine, 0), false, 0, 2048); |
4 | 557 |
end; |
558 |
||
559 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
|
560 |
var Gear: PGear; |
|
561 |
dmg: integer; |
|
562 |
begin |
|
563 |
TargetPoint.X:= NoPointX; |
|
564 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
565 |
DrawExplosion(X, Y, Radius); |
|
9 | 566 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 567 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
568 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
569 |
Gear:= GearsList; |
|
570 |
while Gear <> nil do |
|
571 |
begin |
|
572 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
573 |
if dmg > 0 then |
|
574 |
begin |
|
575 |
dmg:= dmg shr 1; |
|
576 |
case Gear.Kind of |
|
10 | 577 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
578 |
gtMine, |
79 | 579 |
gtCase, |
580 |
gtFlame: begin |
|
39 | 581 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear.Damage, dmg); |
42 | 582 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear.Kind <> gtHedgehog) then |
583 |
begin |
|
108 | 584 |
Gear.dX:= Gear.dX + dmg / 200 * hwSign(Gear.X - X); |
585 |
Gear.dY:= Gear.dY + dmg / 200 * hwSign(Gear.Y - Y); |
|
42 | 586 |
Gear.Active:= true; |
587 |
FollowGear:= Gear |
|
588 |
end; |
|
4 | 589 |
end; |
51 | 590 |
gtGrave: begin |
591 |
Gear.dY:= - dmg / 250; |
|
592 |
Gear.Active:= true; |
|
593 |
end; |
|
4 | 594 |
end; |
595 |
end; |
|
596 |
Gear:= Gear.NextGear |
|
80 | 597 |
end; |
598 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
4 | 599 |
end; |
600 |
||
75 | 601 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 602 |
var t: PGearArray; |
603 |
i: integer; |
|
38 | 604 |
begin |
53 | 605 |
t:= CheckGearsCollision(Ammo); |
606 |
i:= t.Count; |
|
607 |
while i > 0 do |
|
608 |
begin |
|
609 |
dec(i); |
|
79 | 610 |
if (t.ar[i].State and gstNoDamage) = 0 then |
611 |
case t.ar[i].Kind of |
|
53 | 612 |
gtHedgehog, |
613 |
gtMine, |
|
614 |
gtCase: begin |
|
75 | 615 |
inc(t.ar[i].Damage, Damage); |
53 | 616 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
617 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
618 |
t.ar[i].Active:= true; |
|
619 |
DeleteCI(t.ar[i]); |
|
620 |
FollowGear:= t.ar[i] |
|
621 |
end; |
|
622 |
end |
|
126 | 623 |
end; |
624 |
SetAllToActive |
|
38 | 625 |
end; |
626 |
||
4 | 627 |
procedure AssignHHCoords; |
82 | 628 |
var Team: PTeam; |
629 |
i, t: integer; |
|
4 | 630 |
begin |
82 | 631 |
Team:= TeamsList; |
632 |
t:= 0; |
|
633 |
while Team <> nil do |
|
4 | 634 |
begin |
82 | 635 |
for i:= 0 to cMaxHHIndex do |
636 |
with Team.Hedgehogs[i] do |
|
637 |
if Gear <> nil then |
|
638 |
if (GameFlags and gfForts) = 0 then FindPlace(Gear, false, 0, 2048) |
|
639 |
else FindPlace(Gear, false, t, t + 1024); |
|
640 |
inc(t, 1024); |
|
641 |
Team:= Team.Next |
|
4 | 642 |
end |
643 |
end; |
|
644 |
||
15 | 645 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; |
10 | 646 |
var t: PGear; |
647 |
begin |
|
648 |
t:= GearsList; |
|
649 |
rX:= sqr(rX); |
|
650 |
rY:= sqr(rY); |
|
651 |
while t <> nil do |
|
652 |
begin |
|
653 |
if (t <> Gear) and (t.Kind = Kind) then |
|
654 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then |
|
655 |
begin |
|
15 | 656 |
Result:= t; |
10 | 657 |
exit |
658 |
end; |
|
659 |
t:= t.NextGear |
|
660 |
end; |
|
15 | 661 |
Result:= nil |
662 |
end; |
|
663 |
||
79 | 664 |
procedure AmmoFlameWork(Ammo: PGear); |
665 |
var t: PGear; |
|
666 |
begin |
|
667 |
t:= GearsList; |
|
668 |
while t <> nil do |
|
669 |
begin |
|
670 |
if (t.Kind = gtHedgehog) and (t.Y < Ammo.Y) then |
|
671 |
if sqr(Ammo.X - t.X) + sqr(Ammo.Y - t.Y - cHHRadius) * 2 <= sqr(4) then |
|
672 |
begin |
|
673 |
inc(t.Damage, 5); |
|
674 |
t.dX:= t.dX + (t.X - Ammo.X) * 0.02; |
|
675 |
t.dY:= - 0.25; |
|
676 |
t.Active:= true; |
|
677 |
DeleteCI(t); |
|
678 |
FollowGear:= t |
|
679 |
end; |
|
680 |
t:= t.NextGear |
|
681 |
end; |
|
682 |
end; |
|
683 |
||
16 | 684 |
function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear; |
685 |
var t: PGear; |
|
686 |
begin |
|
687 |
t:= GearsList; |
|
688 |
rX:= sqr(rX); |
|
689 |
rY:= sqr(rY); |
|
690 |
while t <> nil do |
|
691 |
begin |
|
692 |
if t.Kind in Kind then |
|
693 |
if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then |
|
694 |
begin |
|
695 |
Result:= t; |
|
696 |
exit |
|
697 |
end; |
|
698 |
t:= t.NextGear |
|
699 |
end; |
|
700 |
Result:= nil |
|
701 |
end; |
|
702 |
||
703 |
function CountGears(Kind: TGearType): Longword; |
|
704 |
var t: PGear; |
|
705 |
begin |
|
706 |
Result:= 0; |
|
707 |
t:= GearsList; |
|
708 |
while t <> nil do |
|
709 |
begin |
|
710 |
if t.Kind = Kind then inc(Result); |
|
711 |
t:= t.NextGear |
|
712 |
end; |
|
713 |
end; |
|
714 |
||
15 | 715 |
procedure SpawnBoxOfSmth; |
716 |
begin |
|
70 | 717 |
if (CountGears(gtCase) > 2) or (getrandom(3) <> 0) then exit; |
718 |
FollowGear:= AddGear(0, 0, gtCase, 0); |
|
719 |
FollowGear.Health:= 25; |
|
720 |
FollowGear.Pos:= posCaseHealth; |
|
721 |
FindPlace(FollowGear, true, 0, 2048) |
|
722 |
end; |
|
723 |
||
724 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); |
|
725 |
||
726 |
function CountNonZeroz(x, y, r: integer): integer; |
|
727 |
var i: integer; |
|
728 |
begin |
|
729 |
Result:= 0; |
|
730 |
if (y and $FFFFFC00) <> 0 then exit; |
|
731 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
732 |
if Land[y, i] <> 0 then inc(Result) |
|
733 |
end; |
|
734 |
||
735 |
var fx, x: integer; |
|
736 |
y, sy: integer; |
|
737 |
ar: array[0..512] of TPoint; |
|
738 |
cnt, delta: Longword; |
|
739 |
begin |
|
740 |
fx:= Left + integer(GetRandom(Right - Left)); |
|
741 |
x:= fx; |
|
742 |
delta:= 130; |
|
16 | 743 |
repeat |
70 | 744 |
repeat |
745 |
inc(x, Gear.Radius); |
|
746 |
if x > Right then x:= Left + (x mod (Right - left)); |
|
747 |
cnt:= 0; |
|
748 |
y:= -Gear.Radius * 2; |
|
749 |
while y < 1023 do |
|
16 | 750 |
begin |
70 | 751 |
repeat |
752 |
inc(y, 2); |
|
753 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) = 0); |
|
754 |
sy:= y; |
|
755 |
repeat |
|
756 |
inc(y); |
|
757 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) <> 0); |
|
758 |
if (y - sy > Gear.Radius * 2) |
|
759 |
and (y < 1023) |
|
760 |
and (CheckGearsNear(x, y - Gear.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
|
761 |
begin |
|
762 |
ar[cnt].X:= x; |
|
763 |
if withFall then ar[cnt].Y:= sy + Gear.Radius |
|
764 |
else ar[cnt].Y:= y - Gear.Radius; |
|
765 |
inc(cnt) |
|
766 |
end; |
|
767 |
inc(y, 80) |
|
16 | 768 |
end; |
70 | 769 |
if cnt > 0 then |
770 |
with ar[GetRandom(cnt)] do |
|
771 |
begin |
|
772 |
Gear.X:= x; |
|
773 |
Gear.Y:= y; |
|
774 |
{$IFDEF DEBUGFILE} |
|
775 |
AddFileLog('Assigned Gear ' + inttostr(integer(Gear)) + |
|
776 |
' coordinates (' + inttostr(x) + |
|
777 |
',' + inttostr(y) + ')'); |
|
778 |
{$ENDIF} |
|
779 |
exit |
|
780 |
end |
|
781 |
until (x - Gear.Radius < fx) and (x + Gear.Radius > fx); |
|
782 |
dec(Delta, 20) |
|
783 |
until (Delta < 70); |
|
784 |
OutError('Couldn''t find place for Gear ' + inttostr(integer(Gear)), false); |
|
785 |
DeleteGear(Gear) |
|
10 | 786 |
end; |
787 |
||
4 | 788 |
initialization |
789 |
||
790 |
finalization |
|
95 | 791 |
FreeGearsList; |
4 | 792 |
|
793 |
end. |