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