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