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