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