author | unc0rr |
Sun, 23 Jul 2006 21:22:44 +0000 | |
changeset 82 | 2f4f3236cccc |
parent 81 | d74e0e914b50 |
child 83 | 207c85fbef51 |
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 |
* |
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
unit uGears; |
|
35 |
interface |
|
36 |
uses SDLh, uConsts; |
|
37 |
{$INCLUDE options.inc} |
|
38 |
const AllInactive: boolean = false; |
|
39 |
||
40 |
type PGear = ^TGear; |
|
41 |
TGearStepProcedure = procedure (Gear: PGear); |
|
42 |
TGear = record |
|
43 |
NextGear, PrevGear: PGear; |
|
44 |
Active: Boolean; |
|
45 |
State : Cardinal; |
|
46 |
X : Real; |
|
47 |
Y : Real; |
|
48 |
dX: Real; |
|
49 |
dY: Real; |
|
42 | 50 |
Kind: TGearType; |
51 |
Pos: Longword; |
|
4 | 52 |
doStep: TGearStepProcedure; |
53 | 53 |
Radius: integer; |
4 | 54 |
Angle, Power : Cardinal; |
55 |
DirAngle: real; |
|
56 |
Timer : LongWord; |
|
57 |
Elasticity: Real; |
|
58 |
Friction : Real; |
|
59 |
Message : Longword; |
|
60 |
Hedgehog: pointer; |
|
38 | 61 |
Health, Damage: integer; |
4 | 62 |
CollIndex: Longword; |
6 | 63 |
Tag: integer; |
4 | 64 |
end; |
65 |
||
17 | 66 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; |
4 | 67 |
procedure ProcessGears; |
68 |
procedure SetAllToActive; |
|
69 |
procedure SetAllHHToActive; |
|
70 |
procedure DrawGears(Surface: PSDL_Surface); |
|
71 |
procedure FreeGearsList; |
|
10 | 72 |
procedure AddMiscGears; |
4 | 73 |
procedure AssignHHCoords; |
74 |
||
75 |
var CurAmmoGear: PGear = nil; |
|
68 | 76 |
GearsList: PGear = nil; |
70 | 77 |
|
4 | 78 |
implementation |
81 | 79 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, |
80 |
uLand, uIO, uLandGraphics, uAIMisc, uLocale; |
|
68 | 81 |
var RopePoints: record |
4 | 82 |
Count: Longword; |
83 |
HookAngle: integer; |
|
84 |
ar: array[0..300] of record |
|
85 |
X, Y: real; |
|
86 |
dLen: real; |
|
87 |
b: boolean; |
|
88 |
end; |
|
89 |
end; |
|
90 |
||
91 |
procedure DeleteGear(Gear: PGear); forward; |
|
92 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward; |
|
75 | 93 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); forward; |
79 | 94 |
procedure AmmoFlameWork(Ammo: PGear); forward; |
17 | 95 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; forward; |
15 | 96 |
procedure SpawnBoxOfSmth; forward; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset
|
97 |
procedure AfterAttack; forward; |
70 | 98 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); forward; |
4 | 99 |
|
100 |
{$INCLUDE GSHandlers.inc} |
|
101 |
{$INCLUDE HHHandlers.inc} |
|
102 |
||
103 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
104 |
doStepCloud, |
|
105 |
doStepBomb, |
|
106 |
doStepHedgehog, |
|
107 |
doStepGrenade, |
|
108 |
doStepHealthTag, |
|
109 |
doStepGrave, |
|
110 |
doStepUFO, |
|
111 |
doStepShotgunShot, |
|
112 |
doStepActionTimer, |
|
113 |
doStepPickHammer, |
|
114 |
doStepRope, |
|
9 | 115 |
doStepSmokeTrace, |
10 | 116 |
doStepExplosion, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
117 |
doStepMine, |
37 | 118 |
doStepCase, |
39 | 119 |
doStepDEagleShot, |
49 | 120 |
doStepDynamite, |
78 | 121 |
doStepTeamHealthSorter, |
122 |
doStepBomb, |
|
79 | 123 |
doStepCluster, |
124 |
doStepShover, |
|
82 | 125 |
doStepFlame, |
126 |
doStepFirePunch |
|
4 | 127 |
); |
128 |
||
129 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; |
|
79 | 130 |
const Counter: Longword = 0; |
4 | 131 |
begin |
79 | 132 |
inc(Counter); |
4 | 133 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF} |
134 |
New(Result); |
|
135 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: handle = '+inttostr(integer(Result)));{$ENDIF} |
|
136 |
FillChar(Result^, sizeof(TGear), 0); |
|
137 |
Result.X:= X; |
|
138 |
Result.Y:= Y; |
|
139 |
Result.Kind := Kind; |
|
140 |
Result.State:= State; |
|
141 |
Result.Active:= true; |
|
142 |
Result.dX:= dX; |
|
143 |
Result.dY:= dY; |
|
144 |
Result.doStep:= doStepHandlers[Kind]; |
|
145 |
Result.CollIndex:= High(Longword); |
|
146 |
if CurrentTeam <> nil then |
|
147 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]; |
|
148 |
case Kind of |
|
149 |
gtAmmo_Bomb: begin |
|
53 | 150 |
Result.Radius:= 4; |
4 | 151 |
Result.Elasticity:= 0.6; |
152 |
Result.Friction:= 0.995; |
|
153 |
Result.Timer:= Timer |
|
154 |
end; |
|
155 |
gtHedgehog: begin |
|
53 | 156 |
Result.Radius:= cHHRadius; |
4 | 157 |
Result.Elasticity:= 0.002; |
70 | 158 |
Result.Friction:= 0.999; |
64 | 159 |
Result.Angle:= cMaxAngle div 2; |
4 | 160 |
end; |
161 |
gtAmmo_Grenade: begin |
|
53 | 162 |
Result.Radius:= 4; |
4 | 163 |
end; |
164 |
gtHealthTag: begin |
|
165 |
Result.Timer:= 1500; |
|
166 |
end; |
|
167 |
gtGrave: begin |
|
53 | 168 |
Result.Radius:= 10; |
4 | 169 |
Result.Elasticity:= 0.6; |
170 |
end; |
|
171 |
gtUFO: begin |
|
53 | 172 |
Result.Radius:= 5; |
4 | 173 |
Result.Timer:= 500; |
174 |
Result.Elasticity:= 0.9 |
|
175 |
end; |
|
176 |
gtShotgunShot: begin |
|
177 |
Result.Timer:= 900; |
|
53 | 178 |
Result.Radius:= 2 |
4 | 179 |
end; |
180 |
gtActionTimer: begin |
|
181 |
Result.Timer:= Timer |
|
182 |
end; |
|
183 |
gtPickHammer: begin |
|
53 | 184 |
Result.Radius:= 10; |
4 | 185 |
Result.Timer:= 4000 |
186 |
end; |
|
187 |
gtSmokeTrace: begin |
|
9 | 188 |
Result.X:= Result.X - 16; |
189 |
Result.Y:= Result.Y - 16; |
|
190 |
Result.State:= 8 |
|
4 | 191 |
end; |
192 |
gtRope: begin |
|
53 | 193 |
Result.Radius:= 3; |
4 | 194 |
Result.Friction:= 500; |
195 |
RopePoints.Count:= 0; |
|
196 |
end; |
|
9 | 197 |
gtExplosion: begin |
198 |
Result.X:= Result.X - 25; |
|
199 |
Result.Y:= Result.Y - 25; |
|
200 |
end; |
|
10 | 201 |
gtMine: begin |
53 | 202 |
Result.Radius:= 3; |
10 | 203 |
Result.Elasticity:= 0.55; |
204 |
Result.Friction:= 0.995; |
|
205 |
Result.Timer:= 3000; |
|
206 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
207 |
gtCase: begin |
75 | 208 |
Result.Radius:= 16; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
209 |
Result.Elasticity:= 0.6 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
210 |
end; |
37 | 211 |
gtDEagleShot: begin |
53 | 212 |
Result.Radius:= 1; |
213 |
Result.Radius:= 1; |
|
38 | 214 |
Result.Health:= 50 |
37 | 215 |
end; |
39 | 216 |
gtDynamite: begin |
53 | 217 |
Result.Radius:= 3; |
56 | 218 |
Result.Elasticity:= 0.55; |
39 | 219 |
Result.Friction:= 0.03; |
220 |
Result.Timer:= 5000; |
|
221 |
end; |
|
78 | 222 |
gtClusterBomb: begin |
223 |
Result.Radius:= 4; |
|
224 |
Result.Elasticity:= 0.6; |
|
225 |
Result.Friction:= 0.995; |
|
226 |
Result.Timer:= Timer |
|
227 |
end; |
|
79 | 228 |
gtFlame: begin |
229 |
Result.Angle:= Counter mod 64; |
|
230 |
Result.Radius:= 1; |
|
231 |
Result.Health:= 2; |
|
232 |
Result.dY:= (getrandom - 0.8) * 0.03; |
|
233 |
Result.dX:= (getrandom - 0.5) * 0.4 |
|
234 |
end; |
|
82 | 235 |
gtFirePunch: begin |
236 |
Result.Radius:= 15; |
|
237 |
Result.Tag:= Y |
|
238 |
end; |
|
4 | 239 |
end; |
240 |
if GearsList = nil then GearsList:= Result |
|
241 |
else begin |
|
242 |
GearsList.PrevGear:= Result; |
|
243 |
Result.NextGear:= GearsList; |
|
244 |
GearsList:= Result |
|
245 |
end |
|
246 |
end; |
|
247 |
||
248 |
procedure DeleteGear(Gear: PGear); |
|
48 | 249 |
var team: PTeam; |
4 | 250 |
begin |
53 | 251 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
4 | 252 |
if Gear.Kind = gtHedgehog then |
253 |
if CurAmmoGear <> nil then |
|
254 |
begin |
|
255 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
256 |
Gear.Message:= gm_Destroy; |
|
257 |
CurAmmoGear.Message:= gm_Destroy; |
|
258 |
exit |
|
47 | 259 |
end else |
260 |
begin |
|
48 | 261 |
team:= PHedgehog(Gear.Hedgehog).Team; |
47 | 262 |
PHedgehog(Gear.Hedgehog).Gear:= nil; |
48 | 263 |
RecountTeamHealth(team); |
47 | 264 |
end; |
82 | 265 |
if CurAmmoGear = Gear then CurAmmoGear:= nil; |
4 | 266 |
if FollowGear = Gear then FollowGear:= nil; |
267 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
268 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; |
|
269 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear |
|
270 |
else begin |
|
271 |
GearsList:= Gear^.NextGear; |
|
272 |
if GearsList <> nil then GearsList.PrevGear:= nil |
|
273 |
end; |
|
274 |
Dispose(Gear) |
|
275 |
end; |
|
276 |
||
277 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
278 |
var Gear: PGear; |
|
279 |
begin |
|
280 |
Result:= true; |
|
281 |
Gear:= GearsList; |
|
282 |
while Gear <> nil do |
|
283 |
begin |
|
284 |
if Gear.Kind = gtHedgehog then |
|
285 |
if Gear.Damage <> 0 then |
|
286 |
begin |
|
287 |
Result:= false; |
|
288 |
if Gear.Health < Gear.Damage then Gear.Health:= 0 |
|
289 |
else dec(Gear.Health, Gear.Damage); |
|
290 |
AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog; |
|
291 |
RenderHealth(PHedgehog(Gear.Hedgehog)^); |
|
47 | 292 |
RecountTeamHealth(PHedgehog(Gear.Hedgehog)^.Team); |
4 | 293 |
|
294 |
Gear.Damage:= 0 |
|
295 |
end; |
|
296 |
Gear:= Gear.NextGear |
|
49 | 297 |
end |
4 | 298 |
end; |
299 |
||
300 |
procedure ProcessGears; |
|
301 |
const delay: integer = cInactDelay; |
|
15 | 302 |
step: (stDelay, stChDmg, stSpawn, stNTurn) = stDelay; |
4 | 303 |
var Gear, t: PGear; |
304 |
{$IFDEF COUNTTICKS} |
|
305 |
tickcntA, tickcntB: LongWord; |
|
306 |
const cntSecTicks: LongWord = 0; |
|
307 |
{$ENDIF} |
|
308 |
begin |
|
309 |
{$IFDEF COUNTTICKS} |
|
310 |
asm |
|
311 |
push eax |
|
312 |
push edx |
|
313 |
rdtsc |
|
314 |
mov tickcntA, eax |
|
315 |
mov tickcntB, edx |
|
316 |
pop edx |
|
317 |
pop eax |
|
318 |
end; |
|
319 |
{$ENDIF} |
|
320 |
AllInactive:= true; |
|
321 |
t:= GearsList; |
|
322 |
while t<>nil do |
|
323 |
begin |
|
324 |
Gear:= t; |
|
325 |
t:= Gear.NextGear; |
|
326 |
if Gear.Active then Gear.doStep(Gear); |
|
327 |
end; |
|
328 |
if AllInactive then |
|
15 | 329 |
case step of |
330 |
stDelay: begin |
|
331 |
dec(delay); |
|
332 |
if delay = 0 then |
|
333 |
begin |
|
334 |
inc(step); |
|
335 |
delay:= cInactDelay |
|
336 |
end |
|
337 |
end; |
|
338 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
339 |
stSpawn: begin |
|
340 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
341 |
inc(step) |
|
342 |
end; |
|
343 |
stNTurn: begin |
|
74 | 344 |
AwareOfExplosion(0, 0, 0); |
15 | 345 |
if isInMultiShoot then isInMultiShoot:= false |
346 |
else ParseCommand('/nextturn'); |
|
347 |
step:= Low(step) |
|
348 |
end; |
|
349 |
end; |
|
350 |
||
4 | 351 |
if TurnTimeLeft > 0 then |
352 |
if CurrentTeam <> nil then |
|
353 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then |
|
354 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0) |
|
355 |
and not isInMultiShoot then dec(TurnTimeLeft); |
|
74 | 356 |
|
4 | 357 |
inc(GameTicks); |
358 |
{$IFDEF COUNTTICKS} |
|
359 |
asm |
|
360 |
push eax |
|
361 |
push edx |
|
362 |
rdtsc |
|
363 |
sub eax, [tickcntA] |
|
364 |
sbb edx, [tickcntB] |
|
365 |
add [cntSecTicks], eax |
|
366 |
pop edx |
|
367 |
pop eax |
|
368 |
end; |
|
369 |
if (GameTicks and 1023) = 0 then |
|
370 |
begin |
|
371 |
cntTicks:= cntSecTicks shr 10; |
|
372 |
{$IFDEF DEBUGFILE} |
|
373 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
374 |
{$ENDIF} |
|
375 |
cntSecTicks:= 0 |
|
376 |
end; |
|
377 |
{$ENDIF} |
|
378 |
end; |
|
379 |
||
380 |
procedure SetAllToActive; |
|
381 |
var t: PGear; |
|
382 |
begin |
|
383 |
AllInactive:= false; |
|
384 |
t:= GearsList; |
|
385 |
while t<>nil do |
|
386 |
begin |
|
387 |
t.Active:= true; |
|
388 |
t:= t.NextGear |
|
389 |
end |
|
390 |
end; |
|
391 |
||
392 |
procedure SetAllHHToActive; |
|
393 |
var t: PGear; |
|
394 |
begin |
|
395 |
AllInactive:= false; |
|
396 |
t:= GearsList; |
|
397 |
while t<>nil do |
|
398 |
begin |
|
399 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
400 |
t:= t.NextGear |
|
401 |
end |
|
402 |
end; |
|
403 |
||
404 |
procedure DrawGears(Surface: PSDL_Surface); |
|
405 |
var Gear: PGear; |
|
406 |
i: Longword; |
|
35 | 407 |
roplen: real; |
4 | 408 |
|
409 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
35 | 410 |
const nodlen = 5; |
411 |
var i, x, y: integer; |
|
412 |
t, k, ladd: real; |
|
4 | 413 |
begin |
37 | 414 |
if (X1 = X2) and (Y1 = Y2) then |
415 |
begin |
|
416 |
{$IFDEF DEBUGFILE}AddFileLog('zero length rope line!!!!!');{$ENDIF} |
|
417 |
exit |
|
418 |
end; |
|
4 | 419 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
420 |
begin |
|
421 |
if X1 > X2 then |
|
422 |
begin |
|
423 |
i:= X1; |
|
424 |
X1:= X2; |
|
425 |
X2:= i; |
|
426 |
i:= Y1; |
|
427 |
Y1:= Y2; |
|
428 |
Y2:= i |
|
429 |
end; |
|
430 |
k:= (Y2 - Y1) / (X2 - X1); |
|
35 | 431 |
ladd:= sqrt(1 + sqr(k)); |
4 | 432 |
if X1 < 0 then |
433 |
begin |
|
434 |
t:= Y1 - 2 - k * X1; |
|
435 |
X1:= 0 |
|
436 |
end else t:= Y1 - 2; |
|
437 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
35 | 438 |
for x:= X1 to X2 do |
439 |
begin |
|
440 |
roplen:= roplen + ladd; |
|
441 |
if roplen > nodlen then |
|
442 |
begin |
|
443 |
DrawGear(sRopeNode, x - 2, round(t) - 2, Surface); |
|
444 |
roplen:= roplen - nodlen; |
|
445 |
end; |
|
446 |
t:= t + k; |
|
447 |
end; |
|
4 | 448 |
end else |
449 |
begin |
|
450 |
if Y1 > Y2 then |
|
451 |
begin |
|
452 |
i:= X1; |
|
453 |
X1:= X2; |
|
454 |
X2:= i; |
|
455 |
i:= Y1; |
|
456 |
Y1:= Y2; |
|
457 |
Y2:= i |
|
458 |
end; |
|
459 |
k:= (X2 - X1) / (Y2 - Y1); |
|
35 | 460 |
ladd:= sqrt(1 + sqr(k)); |
4 | 461 |
if Y1 < 0 then |
462 |
begin |
|
463 |
t:= X1 - 2 - k * Y1; |
|
464 |
Y1:= 0 |
|
465 |
end else t:= X1 - 2; |
|
466 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
35 | 467 |
for y:= Y1 to Y2 do |
468 |
begin |
|
469 |
roplen:= roplen + ladd; |
|
470 |
if roplen > nodlen then |
|
471 |
begin |
|
472 |
DrawGear(sRopeNode, round(t) - 2, y - 2, Surface); |
|
473 |
roplen:= roplen - nodlen; |
|
474 |
end; |
|
475 |
t:= t + k; |
|
476 |
end; |
|
4 | 477 |
end |
478 |
end; |
|
479 |
||
480 |
begin |
|
481 |
Gear:= GearsList; |
|
482 |
while Gear<>nil do |
|
483 |
begin |
|
484 |
case Gear.Kind of |
|
485 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
486 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
487 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, Sign(Gear.dX), |
|
488 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2, |
|
489 |
Surface); |
|
490 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
491 |
gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true); |
|
492 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
|
493 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 494 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 495 |
gtRope: begin |
35 | 496 |
roplen:= 0; |
4 | 497 |
if RopePoints.Count > 0 then |
498 |
begin |
|
499 |
i:= 0; |
|
500 |
while i < Pred(RopePoints.Count) do |
|
501 |
begin |
|
502 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
503 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
504 |
inc(i) |
|
505 |
end; |
|
506 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
507 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
35 | 508 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
509 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 510 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
511 |
end else |
|
35 | 512 |
begin |
513 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
514 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 515 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
35 | 516 |
end; |
4 | 517 |
end; |
9 | 518 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 519 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
520 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
521 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
46 | 522 |
gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 25 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface); |
42 | 523 |
gtCase: case Gear.Pos of |
524 |
posCaseAmmo : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface); |
|
75 | 525 |
posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 24 + WorldDx, Round(Gear.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
42 | 526 |
end; |
78 | 527 |
gtClusterBomb: DrawSprite(sprClusterBomb, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
528 |
gtCluster: DrawSprite(sprClusterParticle, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, 0, Surface); |
|
79 | 529 |
gtFlame: DrawSprite(sprFlame, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy,(GameTicks div 128 + Gear.Angle) mod 8, Surface); |
4 | 530 |
end; |
531 |
Gear:= Gear.NextGear |
|
532 |
end; |
|
533 |
end; |
|
534 |
||
535 |
procedure FreeGearsList; |
|
536 |
var t, tt: PGear; |
|
537 |
begin |
|
538 |
tt:= GearsList; |
|
539 |
GearsList:= nil; |
|
540 |
while tt<>nil do |
|
541 |
begin |
|
542 |
t:= tt; |
|
543 |
tt:= tt.NextGear; |
|
544 |
Dispose(t) |
|
545 |
end; |
|
546 |
end; |
|
547 |
||
10 | 548 |
procedure AddMiscGears; |
70 | 549 |
var i: integer; |
4 | 550 |
begin |
74 | 551 |
for i:= 0 to cCloudsNumber do |
552 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), |
|
553 |
(0.5-random)*0.02, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); |
|
4 | 554 |
AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3; |
22 | 555 |
if (GameFlags and gfForts) = 0 then |
556 |
for i:= 0 to 3 do |
|
70 | 557 |
FindPlace(AddGear(0, 0, gtMine, 0), false, 0, 2048); |
4 | 558 |
end; |
559 |
||
560 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
|
561 |
var Gear: PGear; |
|
562 |
dmg: integer; |
|
563 |
begin |
|
564 |
TargetPoint.X:= NoPointX; |
|
565 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
566 |
DrawExplosion(X, Y, Radius); |
|
9 | 567 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 568 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
569 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
570 |
Gear:= GearsList; |
|
571 |
while Gear <> nil do |
|
572 |
begin |
|
573 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
574 |
if dmg > 0 then |
|
575 |
begin |
|
576 |
dmg:= dmg shr 1; |
|
577 |
case Gear.Kind of |
|
10 | 578 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
579 |
gtMine, |
79 | 580 |
gtCase, |
581 |
gtFlame: begin |
|
39 | 582 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear.Damage, dmg); |
42 | 583 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear.Kind <> gtHedgehog) then |
584 |
begin |
|
70 | 585 |
Gear.dX:= Gear.dX + dmg / 200 * Sign(Gear.X - X); |
586 |
Gear.dY:= Gear.dY + dmg / 200 * Sign(Gear.Y - Y); |
|
42 | 587 |
Gear.Active:= true; |
588 |
FollowGear:= Gear |
|
589 |
end; |
|
4 | 590 |
end; |
51 | 591 |
gtGrave: begin |
592 |
Gear.dY:= - dmg / 250; |
|
593 |
Gear.Active:= true; |
|
594 |
end; |
|
4 | 595 |
end; |
596 |
end; |
|
597 |
Gear:= Gear.NextGear |
|
80 | 598 |
end; |
599 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
4 | 600 |
end; |
601 |
||
75 | 602 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 603 |
var t: PGearArray; |
604 |
i: integer; |
|
38 | 605 |
begin |
53 | 606 |
t:= CheckGearsCollision(Ammo); |
607 |
i:= t.Count; |
|
608 |
while i > 0 do |
|
609 |
begin |
|
610 |
dec(i); |
|
79 | 611 |
if (t.ar[i].State and gstNoDamage) = 0 then |
612 |
case t.ar[i].Kind of |
|
53 | 613 |
gtHedgehog, |
614 |
gtMine, |
|
615 |
gtCase: begin |
|
75 | 616 |
inc(t.ar[i].Damage, Damage); |
53 | 617 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
618 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
619 |
t.ar[i].Active:= true; |
|
620 |
DeleteCI(t.ar[i]); |
|
621 |
FollowGear:= t.ar[i] |
|
622 |
end; |
|
623 |
end |
|
79 | 624 |
end |
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 |
|
791 |
FreeGearsList |
|
792 |
||
793 |
end. |