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