author | unc0rr |
Tue, 28 Nov 2006 17:14:39 +0000 | |
changeset 282 | b1e3387389b6 |
parent 263 | 36379e6abcdd |
child 283 | 28d105f378f1 |
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); |
4 | 528 |
end; |
529 |
Gear:= Gear.NextGear |
|
530 |
end; |
|
531 |
end; |
|
532 |
||
533 |
procedure FreeGearsList; |
|
534 |
var t, tt: PGear; |
|
535 |
begin |
|
536 |
tt:= GearsList; |
|
537 |
GearsList:= nil; |
|
538 |
while tt<>nil do |
|
539 |
begin |
|
540 |
t:= tt; |
|
541 |
tt:= tt.NextGear; |
|
542 |
Dispose(t) |
|
543 |
end; |
|
544 |
end; |
|
545 |
||
10 | 546 |
procedure AddMiscGears; |
70 | 547 |
var i: integer; |
4 | 548 |
begin |
74 | 549 |
for i:= 0 to cCloudsNumber do |
550 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), |
|
95 | 551 |
(0.5-random)*0.1, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); |
83 | 552 |
AddGear(0, 0, gtATStartGame, 0, 0, 0, 2000); |
22 | 553 |
if (GameFlags and gfForts) = 0 then |
554 |
for i:= 0 to 3 do |
|
70 | 555 |
FindPlace(AddGear(0, 0, gtMine, 0), false, 0, 2048); |
4 | 556 |
end; |
557 |
||
558 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
|
559 |
var Gear: PGear; |
|
560 |
dmg: integer; |
|
561 |
begin |
|
562 |
TargetPoint.X:= NoPointX; |
|
563 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
564 |
DrawExplosion(X, Y, Radius); |
|
9 | 565 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 566 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
567 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
568 |
Gear:= GearsList; |
|
569 |
while Gear <> nil do |
|
570 |
begin |
|
571 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
572 |
if dmg > 0 then |
|
573 |
begin |
|
574 |
dmg:= dmg shr 1; |
|
575 |
case Gear.Kind of |
|
10 | 576 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
577 |
gtMine, |
79 | 578 |
gtCase, |
579 |
gtFlame: begin |
|
39 | 580 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear.Damage, dmg); |
42 | 581 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear.Kind <> gtHedgehog) then |
582 |
begin |
|
108 | 583 |
Gear.dX:= Gear.dX + dmg / 200 * hwSign(Gear.X - X); |
584 |
Gear.dY:= Gear.dY + dmg / 200 * hwSign(Gear.Y - Y); |
|
42 | 585 |
Gear.Active:= true; |
586 |
FollowGear:= Gear |
|
587 |
end; |
|
4 | 588 |
end; |
51 | 589 |
gtGrave: begin |
590 |
Gear.dY:= - dmg / 250; |
|
591 |
Gear.Active:= true; |
|
592 |
end; |
|
4 | 593 |
end; |
594 |
end; |
|
595 |
Gear:= Gear.NextGear |
|
80 | 596 |
end; |
597 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
4 | 598 |
end; |
599 |
||
75 | 600 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 601 |
var t: PGearArray; |
602 |
i: integer; |
|
38 | 603 |
begin |
53 | 604 |
t:= CheckGearsCollision(Ammo); |
605 |
i:= t.Count; |
|
606 |
while i > 0 do |
|
607 |
begin |
|
608 |
dec(i); |
|
79 | 609 |
if (t.ar[i].State and gstNoDamage) = 0 then |
610 |
case t.ar[i].Kind of |
|
53 | 611 |
gtHedgehog, |
612 |
gtMine, |
|
613 |
gtCase: begin |
|
75 | 614 |
inc(t.ar[i].Damage, Damage); |
53 | 615 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
616 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
617 |
t.ar[i].Active:= true; |
|
618 |
DeleteCI(t.ar[i]); |
|
619 |
FollowGear:= t.ar[i] |
|
620 |
end; |
|
621 |
end |
|
126 | 622 |
end; |
623 |
SetAllToActive |
|
38 | 624 |
end; |
625 |
||
4 | 626 |
procedure AssignHHCoords; |
82 | 627 |
var Team: PTeam; |
628 |
i, t: integer; |
|
4 | 629 |
begin |
82 | 630 |
Team:= TeamsList; |
631 |
t:= 0; |
|
632 |
while Team <> nil do |
|
4 | 633 |
begin |
82 | 634 |
for i:= 0 to cMaxHHIndex do |
635 |
with Team.Hedgehogs[i] do |
|
636 |
if Gear <> nil then |
|
637 |
if (GameFlags and gfForts) = 0 then FindPlace(Gear, false, 0, 2048) |
|
638 |
else FindPlace(Gear, false, t, t + 1024); |
|
639 |
inc(t, 1024); |
|
640 |
Team:= Team.Next |
|
4 | 641 |
end |
642 |
end; |
|
643 |
||
15 | 644 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; |
10 | 645 |
var t: PGear; |
646 |
begin |
|
647 |
t:= GearsList; |
|
648 |
rX:= sqr(rX); |
|
649 |
rY:= sqr(rY); |
|
650 |
while t <> nil do |
|
651 |
begin |
|
652 |
if (t <> Gear) and (t.Kind = Kind) then |
|
653 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then |
|
654 |
begin |
|
15 | 655 |
Result:= t; |
10 | 656 |
exit |
657 |
end; |
|
658 |
t:= t.NextGear |
|
659 |
end; |
|
15 | 660 |
Result:= nil |
661 |
end; |
|
662 |
||
79 | 663 |
procedure AmmoFlameWork(Ammo: PGear); |
664 |
var t: PGear; |
|
665 |
begin |
|
666 |
t:= GearsList; |
|
667 |
while t <> nil do |
|
668 |
begin |
|
669 |
if (t.Kind = gtHedgehog) and (t.Y < Ammo.Y) then |
|
670 |
if sqr(Ammo.X - t.X) + sqr(Ammo.Y - t.Y - cHHRadius) * 2 <= sqr(4) then |
|
671 |
begin |
|
672 |
inc(t.Damage, 5); |
|
673 |
t.dX:= t.dX + (t.X - Ammo.X) * 0.02; |
|
674 |
t.dY:= - 0.25; |
|
675 |
t.Active:= true; |
|
676 |
DeleteCI(t); |
|
677 |
FollowGear:= t |
|
678 |
end; |
|
679 |
t:= t.NextGear |
|
680 |
end; |
|
681 |
end; |
|
682 |
||
16 | 683 |
function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear; |
684 |
var t: PGear; |
|
685 |
begin |
|
686 |
t:= GearsList; |
|
687 |
rX:= sqr(rX); |
|
688 |
rY:= sqr(rY); |
|
689 |
while t <> nil do |
|
690 |
begin |
|
691 |
if t.Kind in Kind then |
|
692 |
if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then |
|
693 |
begin |
|
694 |
Result:= t; |
|
695 |
exit |
|
696 |
end; |
|
697 |
t:= t.NextGear |
|
698 |
end; |
|
699 |
Result:= nil |
|
700 |
end; |
|
701 |
||
702 |
function CountGears(Kind: TGearType): Longword; |
|
703 |
var t: PGear; |
|
704 |
begin |
|
705 |
Result:= 0; |
|
706 |
t:= GearsList; |
|
707 |
while t <> nil do |
|
708 |
begin |
|
709 |
if t.Kind = Kind then inc(Result); |
|
710 |
t:= t.NextGear |
|
711 |
end; |
|
712 |
end; |
|
713 |
||
15 | 714 |
procedure SpawnBoxOfSmth; |
715 |
begin |
|
70 | 716 |
if (CountGears(gtCase) > 2) or (getrandom(3) <> 0) then exit; |
717 |
FollowGear:= AddGear(0, 0, gtCase, 0); |
|
718 |
FollowGear.Health:= 25; |
|
719 |
FollowGear.Pos:= posCaseHealth; |
|
720 |
FindPlace(FollowGear, true, 0, 2048) |
|
721 |
end; |
|
722 |
||
723 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); |
|
724 |
||
725 |
function CountNonZeroz(x, y, r: integer): integer; |
|
726 |
var i: integer; |
|
727 |
begin |
|
728 |
Result:= 0; |
|
729 |
if (y and $FFFFFC00) <> 0 then exit; |
|
730 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
731 |
if Land[y, i] <> 0 then inc(Result) |
|
732 |
end; |
|
733 |
||
734 |
var fx, x: integer; |
|
735 |
y, sy: integer; |
|
736 |
ar: array[0..512] of TPoint; |
|
737 |
cnt, delta: Longword; |
|
738 |
begin |
|
739 |
fx:= Left + integer(GetRandom(Right - Left)); |
|
740 |
x:= fx; |
|
741 |
delta:= 130; |
|
16 | 742 |
repeat |
70 | 743 |
repeat |
744 |
inc(x, Gear.Radius); |
|
745 |
if x > Right then x:= Left + (x mod (Right - left)); |
|
746 |
cnt:= 0; |
|
747 |
y:= -Gear.Radius * 2; |
|
748 |
while y < 1023 do |
|
16 | 749 |
begin |
70 | 750 |
repeat |
751 |
inc(y, 2); |
|
752 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) = 0); |
|
753 |
sy:= y; |
|
754 |
repeat |
|
755 |
inc(y); |
|
756 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) <> 0); |
|
757 |
if (y - sy > Gear.Radius * 2) |
|
758 |
and (y < 1023) |
|
759 |
and (CheckGearsNear(x, y - Gear.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
|
760 |
begin |
|
761 |
ar[cnt].X:= x; |
|
762 |
if withFall then ar[cnt].Y:= sy + Gear.Radius |
|
763 |
else ar[cnt].Y:= y - Gear.Radius; |
|
764 |
inc(cnt) |
|
765 |
end; |
|
766 |
inc(y, 80) |
|
16 | 767 |
end; |
70 | 768 |
if cnt > 0 then |
769 |
with ar[GetRandom(cnt)] do |
|
770 |
begin |
|
771 |
Gear.X:= x; |
|
772 |
Gear.Y:= y; |
|
773 |
{$IFDEF DEBUGFILE} |
|
774 |
AddFileLog('Assigned Gear ' + inttostr(integer(Gear)) + |
|
775 |
' coordinates (' + inttostr(x) + |
|
776 |
',' + inttostr(y) + ')'); |
|
777 |
{$ENDIF} |
|
778 |
exit |
|
779 |
end |
|
780 |
until (x - Gear.Radius < fx) and (x + Gear.Radius > fx); |
|
781 |
dec(Delta, 20) |
|
782 |
until (Delta < 70); |
|
783 |
OutError('Couldn''t find place for Gear ' + inttostr(integer(Gear)), false); |
|
784 |
DeleteGear(Gear) |
|
10 | 785 |
end; |
786 |
||
4 | 787 |
initialization |
788 |
||
789 |
finalization |
|
95 | 790 |
FreeGearsList; |
4 | 791 |
|
792 |
end. |