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