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