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