author | unc0rr |
Wed, 01 Feb 2006 20:42:53 +0000 | |
changeset 57 | e1a77ae57065 |
parent 56 | a29135563e94 |
child 64 | 9df467527ae5 |
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; |
|
76 |
||
77 |
implementation |
|
57 | 78 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, uLand, uIO, uLandGraphics; |
4 | 79 |
var GearsList: PGear = nil; |
80 |
RopePoints: record |
|
81 |
Count: Longword; |
|
82 |
HookAngle: integer; |
|
83 |
ar: array[0..300] of record |
|
84 |
X, Y: real; |
|
85 |
dLen: real; |
|
86 |
b: boolean; |
|
87 |
end; |
|
88 |
end; |
|
89 |
||
90 |
procedure DeleteGear(Gear: PGear); forward; |
|
91 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward; |
|
53 | 92 |
procedure AmmoShove(Ammo: PGear; Power: integer); forward; |
17 | 93 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; forward; |
15 | 94 |
procedure SpawnBoxOfSmth; forward; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset
|
95 |
procedure AfterAttack; forward; |
4 | 96 |
|
97 |
{$INCLUDE GSHandlers.inc} |
|
98 |
{$INCLUDE HHHandlers.inc} |
|
99 |
||
100 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
101 |
doStepCloud, |
|
102 |
doStepBomb, |
|
103 |
doStepHedgehog, |
|
104 |
doStepGrenade, |
|
105 |
doStepHealthTag, |
|
106 |
doStepGrave, |
|
107 |
doStepUFO, |
|
108 |
doStepShotgunShot, |
|
109 |
doStepActionTimer, |
|
110 |
doStepPickHammer, |
|
111 |
doStepRope, |
|
9 | 112 |
doStepSmokeTrace, |
10 | 113 |
doStepExplosion, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
114 |
doStepMine, |
37 | 115 |
doStepCase, |
39 | 116 |
doStepDEagleShot, |
49 | 117 |
doStepDynamite, |
118 |
doStepTeamHealthSorter |
|
4 | 119 |
); |
120 |
||
121 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; |
|
122 |
begin |
|
123 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF} |
|
124 |
New(Result); |
|
125 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: handle = '+inttostr(integer(Result)));{$ENDIF} |
|
126 |
FillChar(Result^, sizeof(TGear), 0); |
|
127 |
Result.X:= X; |
|
128 |
Result.Y:= Y; |
|
129 |
Result.Kind := Kind; |
|
130 |
Result.State:= State; |
|
131 |
Result.Active:= true; |
|
132 |
Result.dX:= dX; |
|
133 |
Result.dY:= dY; |
|
134 |
Result.doStep:= doStepHandlers[Kind]; |
|
135 |
Result.CollIndex:= High(Longword); |
|
136 |
if CurrentTeam <> nil then |
|
137 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]; |
|
138 |
case Kind of |
|
139 |
gtAmmo_Bomb: begin |
|
53 | 140 |
Result.Radius:= 4; |
4 | 141 |
Result.Elasticity:= 0.6; |
142 |
Result.Friction:= 0.995; |
|
143 |
Result.Timer:= Timer |
|
144 |
end; |
|
145 |
gtHedgehog: begin |
|
53 | 146 |
Result.Radius:= cHHRadius; |
4 | 147 |
Result.Elasticity:= 0.002; |
148 |
Result.Friction:= 0.999; |
|
149 |
end; |
|
150 |
gtAmmo_Grenade: begin |
|
53 | 151 |
Result.Radius:= 4; |
4 | 152 |
end; |
153 |
gtHealthTag: begin |
|
154 |
Result.Timer:= 1500; |
|
155 |
end; |
|
156 |
gtGrave: begin |
|
53 | 157 |
Result.Radius:= 10; |
4 | 158 |
Result.Elasticity:= 0.6; |
159 |
end; |
|
160 |
gtUFO: begin |
|
53 | 161 |
Result.Radius:= 5; |
4 | 162 |
Result.Timer:= 500; |
163 |
Result.Elasticity:= 0.9 |
|
164 |
end; |
|
165 |
gtShotgunShot: begin |
|
166 |
Result.Timer:= 900; |
|
53 | 167 |
Result.Radius:= 2 |
4 | 168 |
end; |
169 |
gtActionTimer: begin |
|
170 |
Result.Timer:= Timer |
|
171 |
end; |
|
172 |
gtPickHammer: begin |
|
53 | 173 |
Result.Radius:= 10; |
4 | 174 |
Result.Timer:= 4000 |
175 |
end; |
|
176 |
gtSmokeTrace: begin |
|
9 | 177 |
Result.X:= Result.X - 16; |
178 |
Result.Y:= Result.Y - 16; |
|
179 |
Result.State:= 8 |
|
4 | 180 |
end; |
181 |
gtRope: begin |
|
53 | 182 |
Result.Radius:= 3; |
4 | 183 |
Result.Friction:= 500; |
184 |
RopePoints.Count:= 0; |
|
185 |
end; |
|
9 | 186 |
gtExplosion: begin |
187 |
Result.X:= Result.X - 25; |
|
188 |
Result.Y:= Result.Y - 25; |
|
189 |
end; |
|
10 | 190 |
gtMine: begin |
53 | 191 |
Result.Radius:= 3; |
10 | 192 |
Result.Elasticity:= 0.55; |
193 |
Result.Friction:= 0.995; |
|
194 |
Result.Timer:= 3000; |
|
195 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
196 |
gtCase: begin |
53 | 197 |
Result.Radius:= 14; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
198 |
Result.Elasticity:= 0.6 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
199 |
end; |
37 | 200 |
gtDEagleShot: begin |
53 | 201 |
Result.Radius:= 1; |
202 |
Result.Radius:= 1; |
|
38 | 203 |
Result.Health:= 50 |
37 | 204 |
end; |
39 | 205 |
gtDynamite: begin |
53 | 206 |
Result.Radius:= 3; |
56 | 207 |
Result.Elasticity:= 0.55; |
39 | 208 |
Result.Friction:= 0.03; |
209 |
Result.Timer:= 5000; |
|
210 |
end; |
|
4 | 211 |
end; |
212 |
if GearsList = nil then GearsList:= Result |
|
213 |
else begin |
|
214 |
GearsList.PrevGear:= Result; |
|
215 |
Result.NextGear:= GearsList; |
|
216 |
GearsList:= Result |
|
217 |
end |
|
218 |
end; |
|
219 |
||
220 |
procedure DeleteGear(Gear: PGear); |
|
48 | 221 |
var team: PTeam; |
4 | 222 |
begin |
53 | 223 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
4 | 224 |
if Gear.Kind = gtHedgehog then |
225 |
if CurAmmoGear <> nil then |
|
226 |
begin |
|
227 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
228 |
Gear.Message:= gm_Destroy; |
|
229 |
CurAmmoGear.Message:= gm_Destroy; |
|
230 |
exit |
|
47 | 231 |
end else |
232 |
begin |
|
48 | 233 |
team:= PHedgehog(Gear.Hedgehog).Team; |
47 | 234 |
PHedgehog(Gear.Hedgehog).Gear:= nil; |
48 | 235 |
RecountTeamHealth(team); |
47 | 236 |
end; |
4 | 237 |
if CurAmmoGear = Gear then |
238 |
CurAmmoGear:= nil; |
|
239 |
if FollowGear = Gear then FollowGear:= nil; |
|
240 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
241 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; |
|
242 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear |
|
243 |
else begin |
|
244 |
GearsList:= Gear^.NextGear; |
|
245 |
if GearsList <> nil then GearsList.PrevGear:= nil |
|
246 |
end; |
|
247 |
Dispose(Gear) |
|
248 |
end; |
|
249 |
||
250 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
251 |
var Gear: PGear; |
|
252 |
begin |
|
253 |
Result:= true; |
|
254 |
Gear:= GearsList; |
|
255 |
while Gear <> nil do |
|
256 |
begin |
|
257 |
if Gear.Kind = gtHedgehog then |
|
258 |
if Gear.Damage <> 0 then |
|
259 |
begin |
|
260 |
Result:= false; |
|
261 |
if Gear.Health < Gear.Damage then Gear.Health:= 0 |
|
262 |
else dec(Gear.Health, Gear.Damage); |
|
263 |
AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog; |
|
264 |
RenderHealth(PHedgehog(Gear.Hedgehog)^); |
|
47 | 265 |
RecountTeamHealth(PHedgehog(Gear.Hedgehog)^.Team); |
4 | 266 |
|
267 |
Gear.Damage:= 0 |
|
268 |
end; |
|
269 |
Gear:= Gear.NextGear |
|
49 | 270 |
end |
4 | 271 |
end; |
272 |
||
273 |
procedure ProcessGears; |
|
274 |
const delay: integer = cInactDelay; |
|
15 | 275 |
step: (stDelay, stChDmg, stSpawn, stNTurn) = stDelay; |
4 | 276 |
var Gear, t: PGear; |
277 |
{$IFDEF COUNTTICKS} |
|
278 |
tickcntA, tickcntB: LongWord; |
|
279 |
const cntSecTicks: LongWord = 0; |
|
280 |
{$ENDIF} |
|
281 |
begin |
|
282 |
{$IFDEF COUNTTICKS} |
|
283 |
asm |
|
284 |
push eax |
|
285 |
push edx |
|
286 |
rdtsc |
|
287 |
mov tickcntA, eax |
|
288 |
mov tickcntB, edx |
|
289 |
pop edx |
|
290 |
pop eax |
|
291 |
end; |
|
292 |
{$ENDIF} |
|
293 |
AllInactive:= true; |
|
294 |
t:= GearsList; |
|
295 |
while t<>nil do |
|
296 |
begin |
|
297 |
Gear:= t; |
|
298 |
t:= Gear.NextGear; |
|
299 |
if Gear.Active then Gear.doStep(Gear); |
|
300 |
end; |
|
301 |
if AllInactive then |
|
15 | 302 |
case step of |
303 |
stDelay: begin |
|
304 |
dec(delay); |
|
305 |
if delay = 0 then |
|
306 |
begin |
|
307 |
inc(step); |
|
308 |
delay:= cInactDelay |
|
309 |
end |
|
310 |
end; |
|
311 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
312 |
stSpawn: begin |
|
313 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
314 |
inc(step) |
|
315 |
end; |
|
316 |
stNTurn: begin |
|
317 |
if isInMultiShoot then isInMultiShoot:= false |
|
318 |
else ParseCommand('/nextturn'); |
|
319 |
step:= Low(step) |
|
320 |
end; |
|
321 |
end; |
|
322 |
||
4 | 323 |
if TurnTimeLeft > 0 then |
324 |
if CurrentTeam <> nil then |
|
325 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then |
|
326 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0) |
|
327 |
and not isInMultiShoot then dec(TurnTimeLeft); |
|
328 |
inc(GameTicks); |
|
329 |
{$IFDEF COUNTTICKS} |
|
330 |
asm |
|
331 |
push eax |
|
332 |
push edx |
|
333 |
rdtsc |
|
334 |
sub eax, [tickcntA] |
|
335 |
sbb edx, [tickcntB] |
|
336 |
add [cntSecTicks], eax |
|
337 |
pop edx |
|
338 |
pop eax |
|
339 |
end; |
|
340 |
if (GameTicks and 1023) = 0 then |
|
341 |
begin |
|
342 |
cntTicks:= cntSecTicks shr 10; |
|
343 |
{$IFDEF DEBUGFILE} |
|
344 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
345 |
{$ENDIF} |
|
346 |
cntSecTicks:= 0 |
|
347 |
end; |
|
348 |
{$ENDIF} |
|
349 |
end; |
|
350 |
||
351 |
procedure SetAllToActive; |
|
352 |
var t: PGear; |
|
353 |
begin |
|
354 |
AllInactive:= false; |
|
355 |
t:= GearsList; |
|
356 |
while t<>nil do |
|
357 |
begin |
|
358 |
t.Active:= true; |
|
359 |
t:= t.NextGear |
|
360 |
end |
|
361 |
end; |
|
362 |
||
363 |
procedure SetAllHHToActive; |
|
364 |
var t: PGear; |
|
365 |
begin |
|
366 |
AllInactive:= false; |
|
367 |
t:= GearsList; |
|
368 |
while t<>nil do |
|
369 |
begin |
|
370 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
371 |
t:= t.NextGear |
|
372 |
end |
|
373 |
end; |
|
374 |
||
375 |
procedure DrawGears(Surface: PSDL_Surface); |
|
376 |
var Gear: PGear; |
|
377 |
i: Longword; |
|
35 | 378 |
roplen: real; |
4 | 379 |
|
380 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
35 | 381 |
const nodlen = 5; |
382 |
var i, x, y: integer; |
|
383 |
t, k, ladd: real; |
|
4 | 384 |
begin |
37 | 385 |
if (X1 = X2) and (Y1 = Y2) then |
386 |
begin |
|
387 |
{$IFDEF DEBUGFILE}AddFileLog('zero length rope line!!!!!');{$ENDIF} |
|
388 |
exit |
|
389 |
end; |
|
4 | 390 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
391 |
begin |
|
392 |
if X1 > X2 then |
|
393 |
begin |
|
394 |
i:= X1; |
|
395 |
X1:= X2; |
|
396 |
X2:= i; |
|
397 |
i:= Y1; |
|
398 |
Y1:= Y2; |
|
399 |
Y2:= i |
|
400 |
end; |
|
401 |
k:= (Y2 - Y1) / (X2 - X1); |
|
35 | 402 |
ladd:= sqrt(1 + sqr(k)); |
4 | 403 |
if X1 < 0 then |
404 |
begin |
|
405 |
t:= Y1 - 2 - k * X1; |
|
406 |
X1:= 0 |
|
407 |
end else t:= Y1 - 2; |
|
408 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
35 | 409 |
for x:= X1 to X2 do |
410 |
begin |
|
411 |
roplen:= roplen + ladd; |
|
412 |
if roplen > nodlen then |
|
413 |
begin |
|
414 |
DrawGear(sRopeNode, x - 2, round(t) - 2, Surface); |
|
415 |
roplen:= roplen - nodlen; |
|
416 |
end; |
|
417 |
t:= t + k; |
|
418 |
end; |
|
4 | 419 |
end else |
420 |
begin |
|
421 |
if Y1 > Y2 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:= (X2 - X1) / (Y2 - Y1); |
|
35 | 431 |
ladd:= sqrt(1 + sqr(k)); |
4 | 432 |
if Y1 < 0 then |
433 |
begin |
|
434 |
t:= X1 - 2 - k * Y1; |
|
435 |
Y1:= 0 |
|
436 |
end else t:= X1 - 2; |
|
437 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
35 | 438 |
for y:= Y1 to Y2 do |
439 |
begin |
|
440 |
roplen:= roplen + ladd; |
|
441 |
if roplen > nodlen then |
|
442 |
begin |
|
443 |
DrawGear(sRopeNode, round(t) - 2, y - 2, Surface); |
|
444 |
roplen:= roplen - nodlen; |
|
445 |
end; |
|
446 |
t:= t + k; |
|
447 |
end; |
|
4 | 448 |
end |
449 |
end; |
|
450 |
||
451 |
begin |
|
452 |
Gear:= GearsList; |
|
453 |
while Gear<>nil do |
|
454 |
begin |
|
455 |
case Gear.Kind of |
|
456 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
457 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
458 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, Sign(Gear.dX), |
|
459 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2, |
|
460 |
Surface); |
|
461 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
462 |
gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true); |
|
463 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
|
464 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 465 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 466 |
gtRope: begin |
35 | 467 |
roplen:= 0; |
4 | 468 |
if RopePoints.Count > 0 then |
469 |
begin |
|
470 |
i:= 0; |
|
471 |
while i < Pred(RopePoints.Count) do |
|
472 |
begin |
|
473 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
474 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
475 |
inc(i) |
|
476 |
end; |
|
477 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
478 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
35 | 479 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
480 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 481 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
482 |
end else |
|
35 | 483 |
begin |
484 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
485 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 486 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
35 | 487 |
end; |
4 | 488 |
end; |
9 | 489 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 490 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
491 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
492 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
46 | 493 |
gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 25 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface); |
42 | 494 |
gtCase: case Gear.Pos of |
495 |
posCaseAmmo : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface); |
|
496 |
posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 6) and $F, Surface); |
|
497 |
end; |
|
4 | 498 |
end; |
499 |
Gear:= Gear.NextGear |
|
500 |
end; |
|
501 |
end; |
|
502 |
||
503 |
procedure FreeGearsList; |
|
504 |
var t, tt: PGear; |
|
505 |
begin |
|
506 |
tt:= GearsList; |
|
507 |
GearsList:= nil; |
|
508 |
while tt<>nil do |
|
509 |
begin |
|
510 |
t:= tt; |
|
511 |
tt:= tt.NextGear; |
|
512 |
Dispose(t) |
|
513 |
end; |
|
514 |
end; |
|
515 |
||
10 | 516 |
procedure AddMiscGears; |
517 |
var i, x, y: integer; |
|
4 | 518 |
begin |
519 |
for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01); |
|
520 |
AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3; |
|
22 | 521 |
if (GameFlags and gfForts) = 0 then |
522 |
begin |
|
523 |
for i:= 0 to 3 do |
|
524 |
begin |
|
525 |
GetHHPoint(x, y); |
|
526 |
AddGear(X, Y + 9, gtMine, 0); |
|
527 |
end; |
|
528 |
end; |
|
4 | 529 |
end; |
530 |
||
531 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
|
532 |
var Gear: PGear; |
|
533 |
dmg: integer; |
|
534 |
begin |
|
535 |
TargetPoint.X:= NoPointX; |
|
536 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
537 |
DrawExplosion(X, Y, Radius); |
|
9 | 538 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 539 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
540 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
541 |
Gear:= GearsList; |
|
542 |
while Gear <> nil do |
|
543 |
begin |
|
544 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
545 |
if dmg > 0 then |
|
546 |
begin |
|
547 |
dmg:= dmg shr 1; |
|
548 |
case Gear.Kind of |
|
10 | 549 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
550 |
gtMine, |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
551 |
gtCase: begin |
39 | 552 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear.Damage, dmg); |
42 | 553 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear.Kind <> gtHedgehog) then |
554 |
begin |
|
555 |
Gear.dX:= Gear.dX + dmg / 200 * sign(Gear.X - X); |
|
556 |
Gear.dY:= Gear.dY + dmg / 200 * sign(Gear.Y - Y); |
|
557 |
Gear.Active:= true; |
|
558 |
FollowGear:= Gear |
|
559 |
end; |
|
4 | 560 |
end; |
51 | 561 |
gtGrave: begin |
562 |
Gear.dY:= - dmg / 250; |
|
563 |
Gear.Active:= true; |
|
564 |
end; |
|
4 | 565 |
end; |
566 |
end; |
|
567 |
Gear:= Gear.NextGear |
|
568 |
end |
|
569 |
end; |
|
570 |
||
53 | 571 |
procedure AmmoShove(Ammo: PGear; Power: integer); |
572 |
var t: PGearArray; |
|
573 |
i: integer; |
|
38 | 574 |
begin |
53 | 575 |
t:= CheckGearsCollision(Ammo); |
576 |
i:= t.Count; |
|
577 |
while i > 0 do |
|
578 |
begin |
|
579 |
dec(i); |
|
580 |
case t.ar[i].Kind of |
|
581 |
gtHedgehog, |
|
582 |
gtMine, |
|
583 |
gtCase: begin |
|
584 |
inc(t.ar[i].Damage, Power); |
|
585 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
|
586 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
587 |
t.ar[i].Active:= true; |
|
588 |
DeleteCI(t.ar[i]); |
|
589 |
FollowGear:= t.ar[i] |
|
590 |
end; |
|
591 |
end |
|
592 |
end |
|
38 | 593 |
end; |
594 |
||
4 | 595 |
procedure AssignHHCoords; |
596 |
var Gear: PGear; |
|
597 |
pX, pY: integer; |
|
598 |
begin |
|
599 |
Gear:= GearsList; |
|
600 |
while Gear <> nil do |
|
601 |
begin |
|
602 |
if Gear.Kind = gtHedgehog then |
|
603 |
begin |
|
604 |
GetHHPoint(pX, pY); |
|
37 | 605 |
{$IFDEF DEBUGFILE}AddFileLog('HH at ('+inttostr(pX)+','+inttostr(pY)+')');{$ENDIF} |
4 | 606 |
Gear.X:= pX; |
607 |
Gear.Y:= pY |
|
608 |
end; |
|
609 |
Gear:= Gear.NextGear |
|
610 |
end |
|
611 |
end; |
|
612 |
||
15 | 613 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; |
10 | 614 |
var t: PGear; |
615 |
begin |
|
616 |
t:= GearsList; |
|
617 |
rX:= sqr(rX); |
|
618 |
rY:= sqr(rY); |
|
619 |
while t <> nil do |
|
620 |
begin |
|
621 |
if (t <> Gear) and (t.Kind = Kind) then |
|
622 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then |
|
623 |
begin |
|
15 | 624 |
Result:= t; |
10 | 625 |
exit |
626 |
end; |
|
627 |
t:= t.NextGear |
|
628 |
end; |
|
15 | 629 |
Result:= nil |
630 |
end; |
|
631 |
||
16 | 632 |
function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear; |
633 |
var t: PGear; |
|
634 |
begin |
|
635 |
t:= GearsList; |
|
636 |
rX:= sqr(rX); |
|
637 |
rY:= sqr(rY); |
|
638 |
while t <> nil do |
|
639 |
begin |
|
640 |
if t.Kind in Kind then |
|
641 |
if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then |
|
642 |
begin |
|
643 |
Result:= t; |
|
644 |
exit |
|
645 |
end; |
|
646 |
t:= t.NextGear |
|
647 |
end; |
|
648 |
Result:= nil |
|
649 |
end; |
|
650 |
||
651 |
function CountGears(Kind: TGearType): Longword; |
|
652 |
var t: PGear; |
|
653 |
begin |
|
654 |
Result:= 0; |
|
655 |
t:= GearsList; |
|
656 |
while t <> nil do |
|
657 |
begin |
|
658 |
if t.Kind = Kind then inc(Result); |
|
659 |
t:= t.NextGear |
|
660 |
end; |
|
661 |
end; |
|
662 |
||
15 | 663 |
procedure SpawnBoxOfSmth; |
16 | 664 |
var i, x, y, k: integer; |
665 |
b: boolean; |
|
15 | 666 |
begin |
43 | 667 |
if (CountGears(gtCase) > 1) or (getrandom(3) <> 0) then exit; |
16 | 668 |
k:= 7; |
669 |
repeat |
|
670 |
x:= getrandom(2000) + 24; |
|
671 |
b:= false; |
|
672 |
y:= -1; |
|
22 | 673 |
while (y < 1023) and not b do |
16 | 674 |
begin |
675 |
inc(y); |
|
22 | 676 |
i:= x - 13; |
53 | 677 |
while (i <= x + 13) and not b do // 13 is gtCase Radius-1 |
16 | 678 |
begin |
22 | 679 |
if Land[y, i] <> 0 then |
680 |
begin |
|
681 |
b:= true; |
|
682 |
end; |
|
16 | 683 |
inc(i) |
684 |
end; |
|
685 |
end; |
|
686 |
if b then |
|
687 |
b:= CheckGearsNear(x, y, [gtMine, gtHedgehog, gtCase], 70, 70) = nil; |
|
688 |
dec(k) |
|
689 |
until (k = 0) or b; |
|
42 | 690 |
if b then |
691 |
begin |
|
692 |
FollowGear:= AddGear(x, -30, gtCase, 0); |
|
693 |
FollowGear.Health:= 25; |
|
694 |
FollowGear.Pos:= posCaseHealth |
|
695 |
end; |
|
10 | 696 |
end; |
697 |
||
4 | 698 |
initialization |
699 |
||
700 |
finalization |
|
701 |
FreeGearsList |
|
702 |
||
703 |
end. |