author | unc0rr |
Fri, 21 Jul 2006 20:37:44 +0000 | |
changeset 81 | d74e0e914b50 |
parent 80 | 3c3dc6a148ca |
child 82 | 2f4f3236cccc |
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, |
|
125 |
doStepFlame |
|
4 | 126 |
); |
127 |
||
128 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; |
|
79 | 129 |
const Counter: Longword = 0; |
4 | 130 |
begin |
79 | 131 |
inc(Counter); |
4 | 132 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF} |
133 |
New(Result); |
|
134 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: handle = '+inttostr(integer(Result)));{$ENDIF} |
|
135 |
FillChar(Result^, sizeof(TGear), 0); |
|
136 |
Result.X:= X; |
|
137 |
Result.Y:= Y; |
|
138 |
Result.Kind := Kind; |
|
139 |
Result.State:= State; |
|
140 |
Result.Active:= true; |
|
141 |
Result.dX:= dX; |
|
142 |
Result.dY:= dY; |
|
143 |
Result.doStep:= doStepHandlers[Kind]; |
|
144 |
Result.CollIndex:= High(Longword); |
|
145 |
if CurrentTeam <> nil then |
|
146 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]; |
|
147 |
case Kind of |
|
148 |
gtAmmo_Bomb: begin |
|
53 | 149 |
Result.Radius:= 4; |
4 | 150 |
Result.Elasticity:= 0.6; |
151 |
Result.Friction:= 0.995; |
|
152 |
Result.Timer:= Timer |
|
153 |
end; |
|
154 |
gtHedgehog: begin |
|
53 | 155 |
Result.Radius:= cHHRadius; |
4 | 156 |
Result.Elasticity:= 0.002; |
70 | 157 |
Result.Friction:= 0.999; |
64 | 158 |
Result.Angle:= cMaxAngle div 2; |
4 | 159 |
end; |
160 |
gtAmmo_Grenade: begin |
|
53 | 161 |
Result.Radius:= 4; |
4 | 162 |
end; |
163 |
gtHealthTag: begin |
|
164 |
Result.Timer:= 1500; |
|
165 |
end; |
|
166 |
gtGrave: begin |
|
53 | 167 |
Result.Radius:= 10; |
4 | 168 |
Result.Elasticity:= 0.6; |
169 |
end; |
|
170 |
gtUFO: begin |
|
53 | 171 |
Result.Radius:= 5; |
4 | 172 |
Result.Timer:= 500; |
173 |
Result.Elasticity:= 0.9 |
|
174 |
end; |
|
175 |
gtShotgunShot: begin |
|
176 |
Result.Timer:= 900; |
|
53 | 177 |
Result.Radius:= 2 |
4 | 178 |
end; |
179 |
gtActionTimer: begin |
|
180 |
Result.Timer:= Timer |
|
181 |
end; |
|
182 |
gtPickHammer: begin |
|
53 | 183 |
Result.Radius:= 10; |
4 | 184 |
Result.Timer:= 4000 |
185 |
end; |
|
186 |
gtSmokeTrace: begin |
|
9 | 187 |
Result.X:= Result.X - 16; |
188 |
Result.Y:= Result.Y - 16; |
|
189 |
Result.State:= 8 |
|
4 | 190 |
end; |
191 |
gtRope: begin |
|
53 | 192 |
Result.Radius:= 3; |
4 | 193 |
Result.Friction:= 500; |
194 |
RopePoints.Count:= 0; |
|
195 |
end; |
|
9 | 196 |
gtExplosion: begin |
197 |
Result.X:= Result.X - 25; |
|
198 |
Result.Y:= Result.Y - 25; |
|
199 |
end; |
|
10 | 200 |
gtMine: begin |
53 | 201 |
Result.Radius:= 3; |
10 | 202 |
Result.Elasticity:= 0.55; |
203 |
Result.Friction:= 0.995; |
|
204 |
Result.Timer:= 3000; |
|
205 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
206 |
gtCase: begin |
75 | 207 |
Result.Radius:= 16; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
208 |
Result.Elasticity:= 0.6 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
209 |
end; |
37 | 210 |
gtDEagleShot: begin |
53 | 211 |
Result.Radius:= 1; |
212 |
Result.Radius:= 1; |
|
38 | 213 |
Result.Health:= 50 |
37 | 214 |
end; |
39 | 215 |
gtDynamite: begin |
53 | 216 |
Result.Radius:= 3; |
56 | 217 |
Result.Elasticity:= 0.55; |
39 | 218 |
Result.Friction:= 0.03; |
219 |
Result.Timer:= 5000; |
|
220 |
end; |
|
78 | 221 |
gtClusterBomb: begin |
222 |
Result.Radius:= 4; |
|
223 |
Result.Elasticity:= 0.6; |
|
224 |
Result.Friction:= 0.995; |
|
225 |
Result.Timer:= Timer |
|
226 |
end; |
|
79 | 227 |
gtFlame: begin |
228 |
Result.Angle:= Counter mod 64; |
|
229 |
Result.Radius:= 1; |
|
230 |
Result.Health:= 2; |
|
231 |
Result.dY:= (getrandom - 0.8) * 0.03; |
|
232 |
Result.dX:= (getrandom - 0.5) * 0.4 |
|
233 |
end; |
|
4 | 234 |
end; |
235 |
if GearsList = nil then GearsList:= Result |
|
236 |
else begin |
|
237 |
GearsList.PrevGear:= Result; |
|
238 |
Result.NextGear:= GearsList; |
|
239 |
GearsList:= Result |
|
240 |
end |
|
241 |
end; |
|
242 |
||
243 |
procedure DeleteGear(Gear: PGear); |
|
48 | 244 |
var team: PTeam; |
4 | 245 |
begin |
53 | 246 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
4 | 247 |
if Gear.Kind = gtHedgehog then |
248 |
if CurAmmoGear <> nil then |
|
249 |
begin |
|
250 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
251 |
Gear.Message:= gm_Destroy; |
|
252 |
CurAmmoGear.Message:= gm_Destroy; |
|
253 |
exit |
|
47 | 254 |
end else |
255 |
begin |
|
48 | 256 |
team:= PHedgehog(Gear.Hedgehog).Team; |
47 | 257 |
PHedgehog(Gear.Hedgehog).Gear:= nil; |
48 | 258 |
RecountTeamHealth(team); |
47 | 259 |
end; |
4 | 260 |
if CurAmmoGear = Gear then |
261 |
CurAmmoGear:= nil; |
|
262 |
if FollowGear = Gear then FollowGear:= nil; |
|
263 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
264 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; |
|
265 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear |
|
266 |
else begin |
|
267 |
GearsList:= Gear^.NextGear; |
|
268 |
if GearsList <> nil then GearsList.PrevGear:= nil |
|
269 |
end; |
|
270 |
Dispose(Gear) |
|
271 |
end; |
|
272 |
||
273 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
274 |
var Gear: PGear; |
|
275 |
begin |
|
276 |
Result:= true; |
|
277 |
Gear:= GearsList; |
|
278 |
while Gear <> nil do |
|
279 |
begin |
|
280 |
if Gear.Kind = gtHedgehog then |
|
281 |
if Gear.Damage <> 0 then |
|
282 |
begin |
|
283 |
Result:= false; |
|
284 |
if Gear.Health < Gear.Damage then Gear.Health:= 0 |
|
285 |
else dec(Gear.Health, Gear.Damage); |
|
286 |
AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog; |
|
287 |
RenderHealth(PHedgehog(Gear.Hedgehog)^); |
|
47 | 288 |
RecountTeamHealth(PHedgehog(Gear.Hedgehog)^.Team); |
4 | 289 |
|
290 |
Gear.Damage:= 0 |
|
291 |
end; |
|
292 |
Gear:= Gear.NextGear |
|
49 | 293 |
end |
4 | 294 |
end; |
295 |
||
296 |
procedure ProcessGears; |
|
297 |
const delay: integer = cInactDelay; |
|
15 | 298 |
step: (stDelay, stChDmg, stSpawn, stNTurn) = stDelay; |
4 | 299 |
var Gear, t: PGear; |
300 |
{$IFDEF COUNTTICKS} |
|
301 |
tickcntA, tickcntB: LongWord; |
|
302 |
const cntSecTicks: LongWord = 0; |
|
303 |
{$ENDIF} |
|
304 |
begin |
|
305 |
{$IFDEF COUNTTICKS} |
|
306 |
asm |
|
307 |
push eax |
|
308 |
push edx |
|
309 |
rdtsc |
|
310 |
mov tickcntA, eax |
|
311 |
mov tickcntB, edx |
|
312 |
pop edx |
|
313 |
pop eax |
|
314 |
end; |
|
315 |
{$ENDIF} |
|
316 |
AllInactive:= true; |
|
317 |
t:= GearsList; |
|
318 |
while t<>nil do |
|
319 |
begin |
|
320 |
Gear:= t; |
|
321 |
t:= Gear.NextGear; |
|
322 |
if Gear.Active then Gear.doStep(Gear); |
|
323 |
end; |
|
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; |
|
335 |
stSpawn: begin |
|
336 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
337 |
inc(step) |
|
338 |
end; |
|
339 |
stNTurn: begin |
|
74 | 340 |
AwareOfExplosion(0, 0, 0); |
15 | 341 |
if isInMultiShoot then isInMultiShoot:= false |
342 |
else ParseCommand('/nextturn'); |
|
343 |
step:= Low(step) |
|
344 |
end; |
|
345 |
end; |
|
346 |
||
4 | 347 |
if TurnTimeLeft > 0 then |
348 |
if CurrentTeam <> nil then |
|
349 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then |
|
350 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0) |
|
351 |
and not isInMultiShoot then dec(TurnTimeLeft); |
|
74 | 352 |
|
4 | 353 |
inc(GameTicks); |
354 |
{$IFDEF COUNTTICKS} |
|
355 |
asm |
|
356 |
push eax |
|
357 |
push edx |
|
358 |
rdtsc |
|
359 |
sub eax, [tickcntA] |
|
360 |
sbb edx, [tickcntB] |
|
361 |
add [cntSecTicks], eax |
|
362 |
pop edx |
|
363 |
pop eax |
|
364 |
end; |
|
365 |
if (GameTicks and 1023) = 0 then |
|
366 |
begin |
|
367 |
cntTicks:= cntSecTicks shr 10; |
|
368 |
{$IFDEF DEBUGFILE} |
|
369 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
370 |
{$ENDIF} |
|
371 |
cntSecTicks:= 0 |
|
372 |
end; |
|
373 |
{$ENDIF} |
|
374 |
end; |
|
375 |
||
376 |
procedure SetAllToActive; |
|
377 |
var t: PGear; |
|
378 |
begin |
|
379 |
AllInactive:= false; |
|
380 |
t:= GearsList; |
|
381 |
while t<>nil do |
|
382 |
begin |
|
383 |
t.Active:= true; |
|
384 |
t:= t.NextGear |
|
385 |
end |
|
386 |
end; |
|
387 |
||
388 |
procedure SetAllHHToActive; |
|
389 |
var t: PGear; |
|
390 |
begin |
|
391 |
AllInactive:= false; |
|
392 |
t:= GearsList; |
|
393 |
while t<>nil do |
|
394 |
begin |
|
395 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
396 |
t:= t.NextGear |
|
397 |
end |
|
398 |
end; |
|
399 |
||
400 |
procedure DrawGears(Surface: PSDL_Surface); |
|
401 |
var Gear: PGear; |
|
402 |
i: Longword; |
|
35 | 403 |
roplen: real; |
4 | 404 |
|
405 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
35 | 406 |
const nodlen = 5; |
407 |
var i, x, y: integer; |
|
408 |
t, k, ladd: real; |
|
4 | 409 |
begin |
37 | 410 |
if (X1 = X2) and (Y1 = Y2) then |
411 |
begin |
|
412 |
{$IFDEF DEBUGFILE}AddFileLog('zero length rope line!!!!!');{$ENDIF} |
|
413 |
exit |
|
414 |
end; |
|
4 | 415 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
416 |
begin |
|
417 |
if X1 > X2 then |
|
418 |
begin |
|
419 |
i:= X1; |
|
420 |
X1:= X2; |
|
421 |
X2:= i; |
|
422 |
i:= Y1; |
|
423 |
Y1:= Y2; |
|
424 |
Y2:= i |
|
425 |
end; |
|
426 |
k:= (Y2 - Y1) / (X2 - X1); |
|
35 | 427 |
ladd:= sqrt(1 + sqr(k)); |
4 | 428 |
if X1 < 0 then |
429 |
begin |
|
430 |
t:= Y1 - 2 - k * X1; |
|
431 |
X1:= 0 |
|
432 |
end else t:= Y1 - 2; |
|
433 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
35 | 434 |
for x:= X1 to X2 do |
435 |
begin |
|
436 |
roplen:= roplen + ladd; |
|
437 |
if roplen > nodlen then |
|
438 |
begin |
|
439 |
DrawGear(sRopeNode, x - 2, round(t) - 2, Surface); |
|
440 |
roplen:= roplen - nodlen; |
|
441 |
end; |
|
442 |
t:= t + k; |
|
443 |
end; |
|
4 | 444 |
end else |
445 |
begin |
|
446 |
if Y1 > Y2 then |
|
447 |
begin |
|
448 |
i:= X1; |
|
449 |
X1:= X2; |
|
450 |
X2:= i; |
|
451 |
i:= Y1; |
|
452 |
Y1:= Y2; |
|
453 |
Y2:= i |
|
454 |
end; |
|
455 |
k:= (X2 - X1) / (Y2 - Y1); |
|
35 | 456 |
ladd:= sqrt(1 + sqr(k)); |
4 | 457 |
if Y1 < 0 then |
458 |
begin |
|
459 |
t:= X1 - 2 - k * Y1; |
|
460 |
Y1:= 0 |
|
461 |
end else t:= X1 - 2; |
|
462 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
35 | 463 |
for y:= Y1 to Y2 do |
464 |
begin |
|
465 |
roplen:= roplen + ladd; |
|
466 |
if roplen > nodlen then |
|
467 |
begin |
|
468 |
DrawGear(sRopeNode, round(t) - 2, y - 2, Surface); |
|
469 |
roplen:= roplen - nodlen; |
|
470 |
end; |
|
471 |
t:= t + k; |
|
472 |
end; |
|
4 | 473 |
end |
474 |
end; |
|
475 |
||
476 |
begin |
|
477 |
Gear:= GearsList; |
|
478 |
while Gear<>nil do |
|
479 |
begin |
|
480 |
case Gear.Kind of |
|
481 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
482 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
483 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, Sign(Gear.dX), |
|
484 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2, |
|
485 |
Surface); |
|
486 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
487 |
gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true); |
|
488 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
|
489 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 490 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 491 |
gtRope: begin |
35 | 492 |
roplen:= 0; |
4 | 493 |
if RopePoints.Count > 0 then |
494 |
begin |
|
495 |
i:= 0; |
|
496 |
while i < Pred(RopePoints.Count) do |
|
497 |
begin |
|
498 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
499 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
500 |
inc(i) |
|
501 |
end; |
|
502 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
503 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
35 | 504 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
505 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 506 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
507 |
end else |
|
35 | 508 |
begin |
509 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
510 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 511 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
35 | 512 |
end; |
4 | 513 |
end; |
9 | 514 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 515 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
516 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
517 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
46 | 518 |
gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 25 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface); |
42 | 519 |
gtCase: case Gear.Pos of |
520 |
posCaseAmmo : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface); |
|
75 | 521 |
posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 24 + WorldDx, Round(Gear.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
42 | 522 |
end; |
78 | 523 |
gtClusterBomb: DrawSprite(sprClusterBomb, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
524 |
gtCluster: DrawSprite(sprClusterParticle, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, 0, Surface); |
|
79 | 525 |
gtFlame: DrawSprite(sprFlame, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy,(GameTicks div 128 + Gear.Angle) mod 8, Surface); |
4 | 526 |
end; |
527 |
Gear:= Gear.NextGear |
|
528 |
end; |
|
529 |
end; |
|
530 |
||
531 |
procedure FreeGearsList; |
|
532 |
var t, tt: PGear; |
|
533 |
begin |
|
534 |
tt:= GearsList; |
|
535 |
GearsList:= nil; |
|
536 |
while tt<>nil do |
|
537 |
begin |
|
538 |
t:= tt; |
|
539 |
tt:= tt.NextGear; |
|
540 |
Dispose(t) |
|
541 |
end; |
|
542 |
end; |
|
543 |
||
10 | 544 |
procedure AddMiscGears; |
70 | 545 |
var i: integer; |
4 | 546 |
begin |
74 | 547 |
for i:= 0 to cCloudsNumber do |
548 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), |
|
549 |
(0.5-random)*0.02, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); |
|
4 | 550 |
AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3; |
22 | 551 |
if (GameFlags and gfForts) = 0 then |
552 |
for i:= 0 to 3 do |
|
70 | 553 |
FindPlace(AddGear(0, 0, gtMine, 0), false, 0, 2048); |
4 | 554 |
end; |
555 |
||
556 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
|
557 |
var Gear: PGear; |
|
558 |
dmg: integer; |
|
559 |
begin |
|
560 |
TargetPoint.X:= NoPointX; |
|
561 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
562 |
DrawExplosion(X, Y, Radius); |
|
9 | 563 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 564 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
565 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
566 |
Gear:= GearsList; |
|
567 |
while Gear <> nil do |
|
568 |
begin |
|
569 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
570 |
if dmg > 0 then |
|
571 |
begin |
|
572 |
dmg:= dmg shr 1; |
|
573 |
case Gear.Kind of |
|
10 | 574 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
575 |
gtMine, |
79 | 576 |
gtCase, |
577 |
gtFlame: begin |
|
39 | 578 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear.Damage, dmg); |
42 | 579 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear.Kind <> gtHedgehog) then |
580 |
begin |
|
70 | 581 |
Gear.dX:= Gear.dX + dmg / 200 * Sign(Gear.X - X); |
582 |
Gear.dY:= Gear.dY + dmg / 200 * Sign(Gear.Y - Y); |
|
42 | 583 |
Gear.Active:= true; |
584 |
FollowGear:= Gear |
|
585 |
end; |
|
4 | 586 |
end; |
51 | 587 |
gtGrave: begin |
588 |
Gear.dY:= - dmg / 250; |
|
589 |
Gear.Active:= true; |
|
590 |
end; |
|
4 | 591 |
end; |
592 |
end; |
|
593 |
Gear:= Gear.NextGear |
|
80 | 594 |
end; |
595 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
4 | 596 |
end; |
597 |
||
75 | 598 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 599 |
var t: PGearArray; |
600 |
i: integer; |
|
38 | 601 |
begin |
53 | 602 |
t:= CheckGearsCollision(Ammo); |
603 |
i:= t.Count; |
|
604 |
while i > 0 do |
|
605 |
begin |
|
606 |
dec(i); |
|
79 | 607 |
if (t.ar[i].State and gstNoDamage) = 0 then |
608 |
case t.ar[i].Kind of |
|
53 | 609 |
gtHedgehog, |
610 |
gtMine, |
|
611 |
gtCase: begin |
|
75 | 612 |
inc(t.ar[i].Damage, Damage); |
53 | 613 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
614 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
615 |
t.ar[i].Active:= true; |
|
616 |
DeleteCI(t.ar[i]); |
|
617 |
FollowGear:= t.ar[i] |
|
618 |
end; |
|
619 |
end |
|
79 | 620 |
end |
38 | 621 |
end; |
622 |
||
4 | 623 |
procedure AssignHHCoords; |
624 |
var Gear: PGear; |
|
625 |
begin |
|
626 |
Gear:= GearsList; |
|
627 |
while Gear <> nil do |
|
628 |
begin |
|
629 |
if Gear.Kind = gtHedgehog then |
|
70 | 630 |
FindPlace(Gear, false, 0, 2048); |
4 | 631 |
Gear:= Gear.NextGear |
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 |
|
781 |
FreeGearsList |
|
782 |
||
783 |
end. |