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