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;
|
|
50 |
Kind : TGearType;
|
|
51 |
doStep: TGearStepProcedure;
|
|
52 |
HalfWidth, HalfHeight: integer;
|
|
53 |
Angle, Power : Cardinal;
|
|
54 |
DirAngle: real;
|
|
55 |
Timer : LongWord;
|
|
56 |
Elasticity: Real;
|
|
57 |
Friction : Real;
|
|
58 |
Message : Longword;
|
|
59 |
Hedgehog: pointer;
|
|
60 |
Health, Damage: LongWord;
|
|
61 |
CollIndex: Longword;
|
6
|
62 |
Tag: integer;
|
4
|
63 |
end;
|
|
64 |
|
|
65 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear;
|
|
66 |
procedure ProcessGears;
|
|
67 |
procedure SetAllToActive;
|
|
68 |
procedure SetAllHHToActive;
|
|
69 |
procedure DrawGears(Surface: PSDL_Surface);
|
|
70 |
procedure FreeGearsList;
|
10
|
71 |
procedure AddMiscGears;
|
4
|
72 |
procedure AssignHHCoords;
|
|
73 |
|
|
74 |
var CurAmmoGear: PGear = nil;
|
|
75 |
|
|
76 |
implementation
|
|
77 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, uLand;
|
|
78 |
var GearsList: PGear = nil;
|
|
79 |
RopePoints: record
|
|
80 |
Count: Longword;
|
|
81 |
HookAngle: integer;
|
|
82 |
ar: array[0..300] of record
|
|
83 |
X, Y: real;
|
|
84 |
dLen: real;
|
|
85 |
b: boolean;
|
|
86 |
end;
|
|
87 |
end;
|
|
88 |
|
|
89 |
procedure DeleteGear(Gear: PGear); forward;
|
|
90 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward;
|
10
|
91 |
function isGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): boolean; forward;
|
4
|
92 |
|
|
93 |
{$INCLUDE GSHandlers.inc}
|
|
94 |
{$INCLUDE HHHandlers.inc}
|
|
95 |
|
|
96 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = (
|
|
97 |
doStepCloud,
|
|
98 |
doStepBomb,
|
|
99 |
doStepHedgehog,
|
|
100 |
doStepGrenade,
|
|
101 |
doStepHealthTag,
|
|
102 |
doStepGrave,
|
|
103 |
doStepUFO,
|
|
104 |
doStepShotgunShot,
|
|
105 |
doStepActionTimer,
|
|
106 |
doStepPickHammer,
|
|
107 |
doStepRope,
|
9
|
108 |
doStepSmokeTrace,
|
10
|
109 |
doStepExplosion,
|
|
110 |
doStepMine
|
4
|
111 |
);
|
|
112 |
|
|
113 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear;
|
|
114 |
begin
|
|
115 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF}
|
|
116 |
New(Result);
|
|
117 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: handle = '+inttostr(integer(Result)));{$ENDIF}
|
|
118 |
FillChar(Result^, sizeof(TGear), 0);
|
|
119 |
Result.X:= X;
|
|
120 |
Result.Y:= Y;
|
|
121 |
Result.Kind := Kind;
|
|
122 |
Result.State:= State;
|
|
123 |
Result.Active:= true;
|
|
124 |
Result.dX:= dX;
|
|
125 |
Result.dY:= dY;
|
|
126 |
Result.doStep:= doStepHandlers[Kind];
|
|
127 |
Result.CollIndex:= High(Longword);
|
|
128 |
if CurrentTeam <> nil then
|
|
129 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog];
|
|
130 |
case Kind of
|
|
131 |
gtAmmo_Bomb: begin
|
|
132 |
Result.HalfWidth:= 4;
|
|
133 |
Result.HalfHeight:= 4;
|
|
134 |
Result.Elasticity:= 0.6;
|
|
135 |
Result.Friction:= 0.995;
|
|
136 |
Result.Timer:= Timer
|
|
137 |
end;
|
|
138 |
gtHedgehog: begin
|
|
139 |
Result.HalfWidth:= 6;
|
|
140 |
Result.HalfHeight:= cHHHalfHeight;
|
|
141 |
Result.Elasticity:= 0.002;
|
|
142 |
Result.Friction:= 0.999;
|
|
143 |
end;
|
|
144 |
gtAmmo_Grenade: begin
|
|
145 |
Result.HalfWidth:= 4;
|
|
146 |
Result.HalfHeight:= 4;
|
|
147 |
end;
|
|
148 |
gtHealthTag: begin
|
|
149 |
Result.Timer:= 1500;
|
|
150 |
end;
|
|
151 |
gtGrave: begin
|
|
152 |
Result.HalfWidth:= 10;
|
|
153 |
Result.HalfHeight:= 10;
|
|
154 |
Result.Elasticity:= 0.6;
|
|
155 |
end;
|
|
156 |
gtUFO: begin
|
|
157 |
Result.HalfWidth:= 5;
|
|
158 |
Result.HalfHeight:= 2;
|
|
159 |
Result.Timer:= 500;
|
|
160 |
Result.Elasticity:= 0.9
|
|
161 |
end;
|
|
162 |
gtShotgunShot: begin
|
|
163 |
Result.Timer:= 900;
|
|
164 |
Result.HalfWidth:= 2;
|
|
165 |
Result.HalfHeight:= 2
|
|
166 |
end;
|
|
167 |
gtActionTimer: begin
|
|
168 |
Result.Timer:= Timer
|
|
169 |
end;
|
|
170 |
gtPickHammer: begin
|
|
171 |
Result.HalfWidth:= 10;
|
|
172 |
Result.HalfHeight:= 2;
|
|
173 |
Result.Timer:= 4000
|
|
174 |
end;
|
|
175 |
gtSmokeTrace: begin
|
9
|
176 |
Result.X:= Result.X - 16;
|
|
177 |
Result.Y:= Result.Y - 16;
|
|
178 |
Result.State:= 8
|
4
|
179 |
end;
|
|
180 |
gtRope: begin
|
|
181 |
Result.HalfWidth:= 3;
|
|
182 |
Result.HalfHeight:= 3;
|
|
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
|
|
191 |
Result.HalfWidth:= 3;
|
|
192 |
Result.HalfHeight:= 3;
|
|
193 |
Result.Elasticity:= 0.55;
|
|
194 |
Result.Friction:= 0.995;
|
|
195 |
Result.Timer:= 3000;
|
|
196 |
end;
|
4
|
197 |
end;
|
|
198 |
if GearsList = nil then GearsList:= Result
|
|
199 |
else begin
|
|
200 |
GearsList.PrevGear:= Result;
|
|
201 |
Result.NextGear:= GearsList;
|
|
202 |
GearsList:= Result
|
|
203 |
end
|
|
204 |
end;
|
|
205 |
|
|
206 |
procedure DeleteGear(Gear: PGear);
|
|
207 |
begin
|
|
208 |
if Gear.CollIndex < High(Longword) then DeleteCR(Gear);
|
|
209 |
if Gear.Kind = gtHedgehog then
|
|
210 |
if CurAmmoGear <> nil then
|
|
211 |
begin
|
|
212 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF}
|
|
213 |
Gear.Message:= gm_Destroy;
|
|
214 |
CurAmmoGear.Message:= gm_Destroy;
|
|
215 |
exit
|
|
216 |
end else PHedgehog(Gear.Hedgehog).Gear:= nil;
|
|
217 |
if CurAmmoGear = Gear then
|
|
218 |
CurAmmoGear:= nil;
|
|
219 |
if FollowGear = Gear then FollowGear:= nil;
|
|
220 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF}
|
|
221 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear;
|
|
222 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear
|
|
223 |
else begin
|
|
224 |
GearsList:= Gear^.NextGear;
|
|
225 |
if GearsList <> nil then GearsList.PrevGear:= nil
|
|
226 |
end;
|
|
227 |
Dispose(Gear)
|
|
228 |
end;
|
|
229 |
|
|
230 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs
|
|
231 |
var Gear: PGear;
|
|
232 |
begin
|
|
233 |
Result:= true;
|
|
234 |
Gear:= GearsList;
|
|
235 |
while Gear <> nil do
|
|
236 |
begin
|
|
237 |
if Gear.Kind = gtHedgehog then
|
|
238 |
if Gear.Damage <> 0 then
|
|
239 |
begin
|
|
240 |
Result:= false;
|
|
241 |
if Gear.Health < Gear.Damage then Gear.Health:= 0
|
|
242 |
else dec(Gear.Health, Gear.Damage);
|
|
243 |
AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog;
|
|
244 |
RenderHealth(PHedgehog(Gear.Hedgehog)^);
|
|
245 |
|
|
246 |
Gear.Damage:= 0
|
|
247 |
end;
|
|
248 |
Gear:= Gear.NextGear
|
|
249 |
end;
|
|
250 |
end;
|
|
251 |
|
|
252 |
procedure ProcessGears;
|
|
253 |
const delay: integer = cInactDelay;
|
|
254 |
var Gear, t: PGear;
|
|
255 |
{$IFDEF COUNTTICKS}
|
|
256 |
tickcntA, tickcntB: LongWord;
|
|
257 |
const cntSecTicks: LongWord = 0;
|
|
258 |
{$ENDIF}
|
|
259 |
begin
|
|
260 |
{$IFDEF COUNTTICKS}
|
|
261 |
asm
|
|
262 |
push eax
|
|
263 |
push edx
|
|
264 |
rdtsc
|
|
265 |
mov tickcntA, eax
|
|
266 |
mov tickcntB, edx
|
|
267 |
pop edx
|
|
268 |
pop eax
|
|
269 |
end;
|
|
270 |
{$ENDIF}
|
|
271 |
AllInactive:= true;
|
|
272 |
t:= GearsList;
|
|
273 |
while t<>nil do
|
|
274 |
begin
|
|
275 |
Gear:= t;
|
|
276 |
t:= Gear.NextGear;
|
|
277 |
if Gear.Active then Gear.doStep(Gear);
|
|
278 |
end;
|
|
279 |
if AllInactive then
|
|
280 |
if (delay > 0)and not isInMultiShoot then
|
|
281 |
begin
|
|
282 |
if delay = cInactDelay then SetAllToActive;
|
|
283 |
dec(delay)
|
|
284 |
end
|
|
285 |
else begin
|
|
286 |
delay:= cInactDelay;
|
|
287 |
if CheckNoDamage then
|
|
288 |
if isInMultiShoot then isInMultiShoot:= false
|
|
289 |
else ParseCommand('/nextturn');
|
|
290 |
end;
|
|
291 |
if TurnTimeLeft > 0 then
|
|
292 |
if CurrentTeam <> nil then
|
|
293 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then
|
|
294 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0)
|
|
295 |
and not isInMultiShoot then dec(TurnTimeLeft);
|
|
296 |
inc(GameTicks);
|
|
297 |
{$IFDEF COUNTTICKS}
|
|
298 |
asm
|
|
299 |
push eax
|
|
300 |
push edx
|
|
301 |
rdtsc
|
|
302 |
sub eax, [tickcntA]
|
|
303 |
sbb edx, [tickcntB]
|
|
304 |
add [cntSecTicks], eax
|
|
305 |
pop edx
|
|
306 |
pop eax
|
|
307 |
end;
|
|
308 |
if (GameTicks and 1023) = 0 then
|
|
309 |
begin
|
|
310 |
cntTicks:= cntSecTicks shr 10;
|
|
311 |
{$IFDEF DEBUGFILE}
|
|
312 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks');
|
|
313 |
{$ENDIF}
|
|
314 |
cntSecTicks:= 0
|
|
315 |
end;
|
|
316 |
{$ENDIF}
|
|
317 |
end;
|
|
318 |
|
|
319 |
procedure SetAllToActive;
|
|
320 |
var t: PGear;
|
|
321 |
begin
|
|
322 |
AllInactive:= false;
|
|
323 |
t:= GearsList;
|
|
324 |
while t<>nil do
|
|
325 |
begin
|
|
326 |
t.Active:= true;
|
|
327 |
t:= t.NextGear
|
|
328 |
end
|
|
329 |
end;
|
|
330 |
|
|
331 |
procedure SetAllHHToActive;
|
|
332 |
var t: PGear;
|
|
333 |
begin
|
|
334 |
AllInactive:= false;
|
|
335 |
t:= GearsList;
|
|
336 |
while t<>nil do
|
|
337 |
begin
|
|
338 |
if t.Kind = gtHedgehog then t.Active:= true;
|
|
339 |
t:= t.NextGear
|
|
340 |
end
|
|
341 |
end;
|
|
342 |
|
|
343 |
procedure DrawGears(Surface: PSDL_Surface);
|
|
344 |
var Gear: PGear;
|
|
345 |
i: Longword;
|
|
346 |
|
|
347 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer);
|
|
348 |
var i: integer;
|
|
349 |
t, k: real;
|
|
350 |
r: TSDL_Rect;
|
|
351 |
begin
|
|
352 |
if abs(X1 - X2) > abs(Y1 - Y2) then
|
|
353 |
begin
|
|
354 |
if X1 > X2 then
|
|
355 |
begin
|
|
356 |
i:= X1;
|
|
357 |
X1:= X2;
|
|
358 |
X2:= i;
|
|
359 |
i:= Y1;
|
|
360 |
Y1:= Y2;
|
|
361 |
Y2:= i
|
|
362 |
end;
|
|
363 |
k:= (Y2 - Y1) / (X2 - X1);
|
|
364 |
if X1 < 0 then
|
|
365 |
begin
|
|
366 |
t:= Y1 - 2 - k * X1;
|
|
367 |
X1:= 0
|
|
368 |
end else t:= Y1 - 2;
|
|
369 |
if X2 > cScreenWidth then X2:= cScreenWidth;
|
|
370 |
r.x:= X1;
|
|
371 |
while r.x <= X2 do
|
|
372 |
begin
|
|
373 |
r.y:= round(t);
|
|
374 |
r.w:= 4;
|
|
375 |
r.h:= 4;
|
|
376 |
SDL_FillRect(Surface, @r, cWhiteColor);
|
|
377 |
t:= t + k*3;
|
|
378 |
inc(r.x, 3)
|
|
379 |
end;
|
|
380 |
end else
|
|
381 |
begin
|
|
382 |
if Y1 > Y2 then
|
|
383 |
begin
|
|
384 |
i:= X1;
|
|
385 |
X1:= X2;
|
|
386 |
X2:= i;
|
|
387 |
i:= Y1;
|
|
388 |
Y1:= Y2;
|
|
389 |
Y2:= i
|
|
390 |
end;
|
|
391 |
k:= (X2 - X1) / (Y2 - Y1);
|
|
392 |
if Y1 < 0 then
|
|
393 |
begin
|
|
394 |
t:= X1 - 2 - k * Y1;
|
|
395 |
Y1:= 0
|
|
396 |
end else t:= X1 - 2;
|
|
397 |
if Y2 > cScreenHeight then Y2:= cScreenHeight;
|
|
398 |
r.y:= Y1;
|
|
399 |
while r.y <= Y2 do
|
|
400 |
begin
|
|
401 |
r.x:= round(t);
|
|
402 |
r.w:= 4;
|
|
403 |
r.h:= 4;
|
|
404 |
SDL_FillRect(Surface, @r, cWhiteColor);
|
|
405 |
t:= t + k*3;
|
|
406 |
inc(r.y, 3)
|
|
407 |
end;
|
|
408 |
end
|
|
409 |
end;
|
|
410 |
|
|
411 |
begin
|
|
412 |
Gear:= GearsList;
|
|
413 |
while Gear<>nil do
|
|
414 |
begin
|
|
415 |
case Gear.Kind of
|
|
416 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
|
|
417 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface);
|
|
418 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, Sign(Gear.dX),
|
|
419 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2,
|
|
420 |
Surface);
|
|
421 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface);
|
|
422 |
gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true);
|
|
423 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface);
|
|
424 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface);
|
9
|
425 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
|
4
|
426 |
gtRope: begin
|
|
427 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy,
|
|
428 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy);
|
|
429 |
if RopePoints.Count > 0 then
|
|
430 |
begin
|
|
431 |
i:= 0;
|
|
432 |
while i < Pred(RopePoints.Count) do
|
|
433 |
begin
|
|
434 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy,
|
|
435 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy);
|
|
436 |
inc(i)
|
|
437 |
end;
|
|
438 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy,
|
|
439 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy);
|
|
440 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface);
|
|
441 |
end else
|
|
442 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface);
|
|
443 |
end;
|
9
|
444 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface);
|
10
|
445 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420)
|
|
446 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface)
|
|
447 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface);
|
4
|
448 |
end;
|
|
449 |
Gear:= Gear.NextGear
|
|
450 |
end;
|
|
451 |
end;
|
|
452 |
|
|
453 |
procedure FreeGearsList;
|
|
454 |
var t, tt: PGear;
|
|
455 |
begin
|
|
456 |
tt:= GearsList;
|
|
457 |
GearsList:= nil;
|
|
458 |
while tt<>nil do
|
|
459 |
begin
|
|
460 |
t:= tt;
|
|
461 |
tt:= tt.NextGear;
|
|
462 |
try
|
|
463 |
Dispose(t)
|
|
464 |
except OutError(errmsgDynamicVar) end;
|
|
465 |
end;
|
|
466 |
end;
|
|
467 |
|
10
|
468 |
procedure AddMiscGears;
|
|
469 |
var i, x, y: integer;
|
4
|
470 |
begin
|
|
471 |
for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -128, gtCloud, random(4), (0.5-random)*0.01);
|
|
472 |
AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3;
|
10
|
473 |
for i:= 0 to 3 do
|
|
474 |
begin
|
|
475 |
GetHHPoint(x, y);
|
|
476 |
AddGear(X, Y + 9, gtMine, 0);
|
|
477 |
end;
|
4
|
478 |
end;
|
|
479 |
|
|
480 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord);
|
|
481 |
var Gear: PGear;
|
|
482 |
dmg: integer;
|
|
483 |
begin
|
|
484 |
TargetPoint.X:= NoPointX;
|
|
485 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF}
|
|
486 |
DrawExplosion(X, Y, Radius);
|
9
|
487 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0);
|
4
|
488 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion);
|
|
489 |
if (Mask and EXPLNoDamage)<>0 then exit;
|
|
490 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1;
|
|
491 |
Gear:= GearsList;
|
|
492 |
while Gear <> nil do
|
|
493 |
begin
|
|
494 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y)));
|
|
495 |
if dmg > 0 then
|
|
496 |
begin
|
|
497 |
dmg:= dmg shr 1;
|
|
498 |
case Gear.Kind of
|
10
|
499 |
gtHedgehog,
|
|
500 |
gtMine: begin
|
4
|
501 |
inc(Gear.Damage, dmg);
|
|
502 |
Gear.dX:= Gear.dX + dmg / 200 * sign(Gear.X - X);
|
|
503 |
Gear.dY:= Gear.dY + dmg / 200 * sign(Gear.Y - Y);
|
|
504 |
FollowGear:= Gear
|
|
505 |
end;
|
|
506 |
gtGrave: Gear.dY:= - dmg / 250;
|
|
507 |
end;
|
|
508 |
end;
|
|
509 |
Gear:= Gear.NextGear
|
|
510 |
end
|
|
511 |
end;
|
|
512 |
|
|
513 |
procedure AssignHHCoords;
|
|
514 |
var Gear: PGear;
|
|
515 |
pX, pY: integer;
|
|
516 |
begin
|
|
517 |
Gear:= GearsList;
|
|
518 |
while Gear <> nil do
|
|
519 |
begin
|
|
520 |
if Gear.Kind = gtHedgehog then
|
|
521 |
begin
|
|
522 |
GetHHPoint(pX, pY);
|
|
523 |
Gear.X:= pX;
|
|
524 |
Gear.Y:= pY
|
|
525 |
end;
|
|
526 |
Gear:= Gear.NextGear
|
|
527 |
end
|
|
528 |
end;
|
|
529 |
|
10
|
530 |
function isGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): boolean;
|
|
531 |
var t: PGear;
|
|
532 |
begin
|
|
533 |
t:= GearsList;
|
|
534 |
rX:= sqr(rX);
|
|
535 |
rY:= sqr(rY);
|
|
536 |
while t <> nil do
|
|
537 |
begin
|
|
538 |
if (t <> Gear) and (t.Kind = Kind) then
|
|
539 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then
|
|
540 |
begin
|
|
541 |
Result:= true;
|
|
542 |
exit
|
|
543 |
end;
|
|
544 |
t:= t.NextGear
|
|
545 |
end;
|
|
546 |
Result:= false
|
|
547 |
end;
|
|
548 |
|
4
|
549 |
initialization
|
|
550 |
|
|
551 |
finalization
|
|
552 |
FreeGearsList
|
|
553 |
|
|
554 |
end.
|