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