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