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