author | unc0rr |
Wed, 12 Jul 2006 15:39:58 +0000 | |
changeset 78 | 66bb79dd248d |
parent 75 | d2b737858ff7 |
child 79 | 29b477319854 |
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 | 53 |
Radius: integer; |
4 | 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; |
|
68 | 76 |
GearsList: PGear = nil; |
70 | 77 |
|
4 | 78 |
implementation |
74 | 79 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, uLand, uIO, uLandGraphics, uAIMisc; |
68 | 80 |
var RopePoints: record |
4 | 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; |
|
75 | 92 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); 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; |
70 | 96 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); forward; |
4 | 97 |
|
98 |
{$INCLUDE GSHandlers.inc} |
|
99 |
{$INCLUDE HHHandlers.inc} |
|
100 |
||
101 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
102 |
doStepCloud, |
|
103 |
doStepBomb, |
|
104 |
doStepHedgehog, |
|
105 |
doStepGrenade, |
|
106 |
doStepHealthTag, |
|
107 |
doStepGrave, |
|
108 |
doStepUFO, |
|
109 |
doStepShotgunShot, |
|
110 |
doStepActionTimer, |
|
111 |
doStepPickHammer, |
|
112 |
doStepRope, |
|
9 | 113 |
doStepSmokeTrace, |
10 | 114 |
doStepExplosion, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
115 |
doStepMine, |
37 | 116 |
doStepCase, |
39 | 117 |
doStepDEagleShot, |
49 | 118 |
doStepDynamite, |
78 | 119 |
doStepTeamHealthSorter, |
120 |
doStepBomb, |
|
121 |
doStepCluster |
|
4 | 122 |
); |
123 |
||
124 |
function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; |
|
125 |
begin |
|
126 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+')');{$ENDIF} |
|
127 |
New(Result); |
|
128 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: handle = '+inttostr(integer(Result)));{$ENDIF} |
|
129 |
FillChar(Result^, sizeof(TGear), 0); |
|
130 |
Result.X:= X; |
|
131 |
Result.Y:= Y; |
|
132 |
Result.Kind := Kind; |
|
133 |
Result.State:= State; |
|
134 |
Result.Active:= true; |
|
135 |
Result.dX:= dX; |
|
136 |
Result.dY:= dY; |
|
137 |
Result.doStep:= doStepHandlers[Kind]; |
|
138 |
Result.CollIndex:= High(Longword); |
|
139 |
if CurrentTeam <> nil then |
|
140 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]; |
|
141 |
case Kind of |
|
142 |
gtAmmo_Bomb: begin |
|
53 | 143 |
Result.Radius:= 4; |
4 | 144 |
Result.Elasticity:= 0.6; |
145 |
Result.Friction:= 0.995; |
|
146 |
Result.Timer:= Timer |
|
147 |
end; |
|
148 |
gtHedgehog: begin |
|
53 | 149 |
Result.Radius:= cHHRadius; |
4 | 150 |
Result.Elasticity:= 0.002; |
70 | 151 |
Result.Friction:= 0.999; |
64 | 152 |
Result.Angle:= cMaxAngle div 2; |
4 | 153 |
end; |
154 |
gtAmmo_Grenade: begin |
|
53 | 155 |
Result.Radius:= 4; |
4 | 156 |
end; |
157 |
gtHealthTag: begin |
|
158 |
Result.Timer:= 1500; |
|
159 |
end; |
|
160 |
gtGrave: begin |
|
53 | 161 |
Result.Radius:= 10; |
4 | 162 |
Result.Elasticity:= 0.6; |
163 |
end; |
|
164 |
gtUFO: begin |
|
53 | 165 |
Result.Radius:= 5; |
4 | 166 |
Result.Timer:= 500; |
167 |
Result.Elasticity:= 0.9 |
|
168 |
end; |
|
169 |
gtShotgunShot: begin |
|
170 |
Result.Timer:= 900; |
|
53 | 171 |
Result.Radius:= 2 |
4 | 172 |
end; |
173 |
gtActionTimer: begin |
|
174 |
Result.Timer:= Timer |
|
175 |
end; |
|
176 |
gtPickHammer: begin |
|
53 | 177 |
Result.Radius:= 10; |
4 | 178 |
Result.Timer:= 4000 |
179 |
end; |
|
180 |
gtSmokeTrace: begin |
|
9 | 181 |
Result.X:= Result.X - 16; |
182 |
Result.Y:= Result.Y - 16; |
|
183 |
Result.State:= 8 |
|
4 | 184 |
end; |
185 |
gtRope: begin |
|
53 | 186 |
Result.Radius:= 3; |
4 | 187 |
Result.Friction:= 500; |
188 |
RopePoints.Count:= 0; |
|
189 |
end; |
|
9 | 190 |
gtExplosion: begin |
191 |
Result.X:= Result.X - 25; |
|
192 |
Result.Y:= Result.Y - 25; |
|
193 |
end; |
|
10 | 194 |
gtMine: begin |
53 | 195 |
Result.Radius:= 3; |
10 | 196 |
Result.Elasticity:= 0.55; |
197 |
Result.Friction:= 0.995; |
|
198 |
Result.Timer:= 3000; |
|
199 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
200 |
gtCase: begin |
75 | 201 |
Result.Radius:= 16; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
202 |
Result.Elasticity:= 0.6 |
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
203 |
end; |
37 | 204 |
gtDEagleShot: begin |
53 | 205 |
Result.Radius:= 1; |
206 |
Result.Radius:= 1; |
|
38 | 207 |
Result.Health:= 50 |
37 | 208 |
end; |
39 | 209 |
gtDynamite: begin |
53 | 210 |
Result.Radius:= 3; |
56 | 211 |
Result.Elasticity:= 0.55; |
39 | 212 |
Result.Friction:= 0.03; |
213 |
Result.Timer:= 5000; |
|
214 |
end; |
|
78 | 215 |
gtClusterBomb: begin |
216 |
Result.Radius:= 4; |
|
217 |
Result.Elasticity:= 0.6; |
|
218 |
Result.Friction:= 0.995; |
|
219 |
Result.Timer:= Timer |
|
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); |
|
48 | 231 |
var team: PTeam; |
4 | 232 |
begin |
53 | 233 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
4 | 234 |
if Gear.Kind = gtHedgehog then |
235 |
if CurAmmoGear <> nil then |
|
236 |
begin |
|
237 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
238 |
Gear.Message:= gm_Destroy; |
|
239 |
CurAmmoGear.Message:= gm_Destroy; |
|
240 |
exit |
|
47 | 241 |
end else |
242 |
begin |
|
48 | 243 |
team:= PHedgehog(Gear.Hedgehog).Team; |
47 | 244 |
PHedgehog(Gear.Hedgehog).Gear:= nil; |
48 | 245 |
RecountTeamHealth(team); |
47 | 246 |
end; |
4 | 247 |
if CurAmmoGear = Gear then |
248 |
CurAmmoGear:= nil; |
|
249 |
if FollowGear = Gear then FollowGear:= nil; |
|
250 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
251 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; |
|
252 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear |
|
253 |
else begin |
|
254 |
GearsList:= Gear^.NextGear; |
|
255 |
if GearsList <> nil then GearsList.PrevGear:= nil |
|
256 |
end; |
|
257 |
Dispose(Gear) |
|
258 |
end; |
|
259 |
||
260 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
261 |
var Gear: PGear; |
|
262 |
begin |
|
263 |
Result:= true; |
|
264 |
Gear:= GearsList; |
|
265 |
while Gear <> nil do |
|
266 |
begin |
|
267 |
if Gear.Kind = gtHedgehog then |
|
268 |
if Gear.Damage <> 0 then |
|
269 |
begin |
|
270 |
Result:= false; |
|
271 |
if Gear.Health < Gear.Damage then Gear.Health:= 0 |
|
272 |
else dec(Gear.Health, Gear.Damage); |
|
273 |
AddGear(Round(Gear.X), Round(Gear.Y) - 32, gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog; |
|
274 |
RenderHealth(PHedgehog(Gear.Hedgehog)^); |
|
47 | 275 |
RecountTeamHealth(PHedgehog(Gear.Hedgehog)^.Team); |
4 | 276 |
|
277 |
Gear.Damage:= 0 |
|
278 |
end; |
|
279 |
Gear:= Gear.NextGear |
|
49 | 280 |
end |
4 | 281 |
end; |
282 |
||
283 |
procedure ProcessGears; |
|
284 |
const delay: integer = cInactDelay; |
|
15 | 285 |
step: (stDelay, stChDmg, stSpawn, stNTurn) = stDelay; |
4 | 286 |
var Gear, t: PGear; |
287 |
{$IFDEF COUNTTICKS} |
|
288 |
tickcntA, tickcntB: LongWord; |
|
289 |
const cntSecTicks: LongWord = 0; |
|
290 |
{$ENDIF} |
|
291 |
begin |
|
292 |
{$IFDEF COUNTTICKS} |
|
293 |
asm |
|
294 |
push eax |
|
295 |
push edx |
|
296 |
rdtsc |
|
297 |
mov tickcntA, eax |
|
298 |
mov tickcntB, edx |
|
299 |
pop edx |
|
300 |
pop eax |
|
301 |
end; |
|
302 |
{$ENDIF} |
|
303 |
AllInactive:= true; |
|
304 |
t:= GearsList; |
|
305 |
while t<>nil do |
|
306 |
begin |
|
307 |
Gear:= t; |
|
308 |
t:= Gear.NextGear; |
|
309 |
if Gear.Active then Gear.doStep(Gear); |
|
310 |
end; |
|
311 |
if AllInactive then |
|
15 | 312 |
case step of |
313 |
stDelay: begin |
|
314 |
dec(delay); |
|
315 |
if delay = 0 then |
|
316 |
begin |
|
317 |
inc(step); |
|
318 |
delay:= cInactDelay |
|
319 |
end |
|
320 |
end; |
|
321 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
322 |
stSpawn: begin |
|
323 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
324 |
inc(step) |
|
325 |
end; |
|
326 |
stNTurn: begin |
|
74 | 327 |
AwareOfExplosion(0, 0, 0); |
15 | 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); |
|
74 | 339 |
|
4 | 340 |
inc(GameTicks); |
341 |
{$IFDEF COUNTTICKS} |
|
342 |
asm |
|
343 |
push eax |
|
344 |
push edx |
|
345 |
rdtsc |
|
346 |
sub eax, [tickcntA] |
|
347 |
sbb edx, [tickcntB] |
|
348 |
add [cntSecTicks], eax |
|
349 |
pop edx |
|
350 |
pop eax |
|
351 |
end; |
|
352 |
if (GameTicks and 1023) = 0 then |
|
353 |
begin |
|
354 |
cntTicks:= cntSecTicks shr 10; |
|
355 |
{$IFDEF DEBUGFILE} |
|
356 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
357 |
{$ENDIF} |
|
358 |
cntSecTicks:= 0 |
|
359 |
end; |
|
360 |
{$ENDIF} |
|
361 |
end; |
|
362 |
||
363 |
procedure SetAllToActive; |
|
364 |
var t: PGear; |
|
365 |
begin |
|
366 |
AllInactive:= false; |
|
367 |
t:= GearsList; |
|
368 |
while t<>nil do |
|
369 |
begin |
|
370 |
t.Active:= true; |
|
371 |
t:= t.NextGear |
|
372 |
end |
|
373 |
end; |
|
374 |
||
375 |
procedure SetAllHHToActive; |
|
376 |
var t: PGear; |
|
377 |
begin |
|
378 |
AllInactive:= false; |
|
379 |
t:= GearsList; |
|
380 |
while t<>nil do |
|
381 |
begin |
|
382 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
383 |
t:= t.NextGear |
|
384 |
end |
|
385 |
end; |
|
386 |
||
387 |
procedure DrawGears(Surface: PSDL_Surface); |
|
388 |
var Gear: PGear; |
|
389 |
i: Longword; |
|
35 | 390 |
roplen: real; |
4 | 391 |
|
392 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
35 | 393 |
const nodlen = 5; |
394 |
var i, x, y: integer; |
|
395 |
t, k, ladd: real; |
|
4 | 396 |
begin |
37 | 397 |
if (X1 = X2) and (Y1 = Y2) then |
398 |
begin |
|
399 |
{$IFDEF DEBUGFILE}AddFileLog('zero length rope line!!!!!');{$ENDIF} |
|
400 |
exit |
|
401 |
end; |
|
4 | 402 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
403 |
begin |
|
404 |
if X1 > X2 then |
|
405 |
begin |
|
406 |
i:= X1; |
|
407 |
X1:= X2; |
|
408 |
X2:= i; |
|
409 |
i:= Y1; |
|
410 |
Y1:= Y2; |
|
411 |
Y2:= i |
|
412 |
end; |
|
413 |
k:= (Y2 - Y1) / (X2 - X1); |
|
35 | 414 |
ladd:= sqrt(1 + sqr(k)); |
4 | 415 |
if X1 < 0 then |
416 |
begin |
|
417 |
t:= Y1 - 2 - k * X1; |
|
418 |
X1:= 0 |
|
419 |
end else t:= Y1 - 2; |
|
420 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
35 | 421 |
for x:= X1 to X2 do |
422 |
begin |
|
423 |
roplen:= roplen + ladd; |
|
424 |
if roplen > nodlen then |
|
425 |
begin |
|
426 |
DrawGear(sRopeNode, x - 2, round(t) - 2, Surface); |
|
427 |
roplen:= roplen - nodlen; |
|
428 |
end; |
|
429 |
t:= t + k; |
|
430 |
end; |
|
4 | 431 |
end else |
432 |
begin |
|
433 |
if Y1 > Y2 then |
|
434 |
begin |
|
435 |
i:= X1; |
|
436 |
X1:= X2; |
|
437 |
X2:= i; |
|
438 |
i:= Y1; |
|
439 |
Y1:= Y2; |
|
440 |
Y2:= i |
|
441 |
end; |
|
442 |
k:= (X2 - X1) / (Y2 - Y1); |
|
35 | 443 |
ladd:= sqrt(1 + sqr(k)); |
4 | 444 |
if Y1 < 0 then |
445 |
begin |
|
446 |
t:= X1 - 2 - k * Y1; |
|
447 |
Y1:= 0 |
|
448 |
end else t:= X1 - 2; |
|
449 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
35 | 450 |
for y:= Y1 to Y2 do |
451 |
begin |
|
452 |
roplen:= roplen + ladd; |
|
453 |
if roplen > nodlen then |
|
454 |
begin |
|
455 |
DrawGear(sRopeNode, round(t) - 2, y - 2, Surface); |
|
456 |
roplen:= roplen - nodlen; |
|
457 |
end; |
|
458 |
t:= t + k; |
|
459 |
end; |
|
4 | 460 |
end |
461 |
end; |
|
462 |
||
463 |
begin |
|
464 |
Gear:= GearsList; |
|
465 |
while Gear<>nil do |
|
466 |
begin |
|
467 |
case Gear.Kind of |
|
468 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
469 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
470 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, Sign(Gear.dX), |
|
471 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2, |
|
472 |
Surface); |
|
473 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
474 |
gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true); |
|
475 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
|
476 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 477 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 478 |
gtRope: begin |
35 | 479 |
roplen:= 0; |
4 | 480 |
if RopePoints.Count > 0 then |
481 |
begin |
|
482 |
i:= 0; |
|
483 |
while i < Pred(RopePoints.Count) do |
|
484 |
begin |
|
485 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
486 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
487 |
inc(i) |
|
488 |
end; |
|
489 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
490 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
35 | 491 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
492 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 493 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
494 |
end else |
|
35 | 495 |
begin |
496 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
497 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 498 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
35 | 499 |
end; |
4 | 500 |
end; |
9 | 501 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 502 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
503 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
504 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
46 | 505 |
gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 25 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface); |
42 | 506 |
gtCase: case Gear.Pos of |
507 |
posCaseAmmo : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface); |
|
75 | 508 |
posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 24 + WorldDx, Round(Gear.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
42 | 509 |
end; |
78 | 510 |
gtClusterBomb: DrawSprite(sprClusterBomb, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
511 |
gtCluster: DrawSprite(sprClusterParticle, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, 0, Surface); |
|
4 | 512 |
end; |
513 |
Gear:= Gear.NextGear |
|
514 |
end; |
|
515 |
end; |
|
516 |
||
517 |
procedure FreeGearsList; |
|
518 |
var t, tt: PGear; |
|
519 |
begin |
|
520 |
tt:= GearsList; |
|
521 |
GearsList:= nil; |
|
522 |
while tt<>nil do |
|
523 |
begin |
|
524 |
t:= tt; |
|
525 |
tt:= tt.NextGear; |
|
526 |
Dispose(t) |
|
527 |
end; |
|
528 |
end; |
|
529 |
||
10 | 530 |
procedure AddMiscGears; |
70 | 531 |
var i: integer; |
4 | 532 |
begin |
74 | 533 |
for i:= 0 to cCloudsNumber do |
534 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), |
|
535 |
(0.5-random)*0.02, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); |
|
4 | 536 |
AddGear(0, 0, gtActionTimer, gtsStartGame, 0, 0, 2000).Health:= 3; |
22 | 537 |
if (GameFlags and gfForts) = 0 then |
538 |
for i:= 0 to 3 do |
|
70 | 539 |
FindPlace(AddGear(0, 0, gtMine, 0), false, 0, 2048); |
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 |
|
70 | 566 |
Gear.dX:= Gear.dX + dmg / 200 * Sign(Gear.X - X); |
567 |
Gear.dY:= Gear.dY + dmg / 200 * Sign(Gear.Y - Y); |
|
42 | 568 |
Gear.Active:= true; |
569 |
FollowGear:= Gear |
|
570 |
end; |
|
4 | 571 |
end; |
51 | 572 |
gtGrave: begin |
573 |
Gear.dY:= - dmg / 250; |
|
574 |
Gear.Active:= true; |
|
575 |
end; |
|
4 | 576 |
end; |
577 |
end; |
|
578 |
Gear:= Gear.NextGear |
|
579 |
end |
|
580 |
end; |
|
581 |
||
75 | 582 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 583 |
var t: PGearArray; |
584 |
i: integer; |
|
64 | 585 |
Gear: PGear; |
38 | 586 |
begin |
53 | 587 |
t:= CheckGearsCollision(Ammo); |
588 |
i:= t.Count; |
|
589 |
while i > 0 do |
|
590 |
begin |
|
591 |
dec(i); |
|
592 |
case t.ar[i].Kind of |
|
593 |
gtHedgehog, |
|
594 |
gtMine, |
|
595 |
gtCase: begin |
|
75 | 596 |
inc(t.ar[i].Damage, Damage); |
53 | 597 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
598 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
599 |
t.ar[i].Active:= true; |
|
600 |
DeleteCI(t.ar[i]); |
|
601 |
FollowGear:= t.ar[i] |
|
602 |
end; |
|
603 |
end |
|
64 | 604 |
end; |
605 |
Gear:= GearsList; |
|
606 |
while Gear <> nil do |
|
607 |
begin |
|
608 |
if Round(sqrt(sqr(Gear.X - Ammo.X) + sqr(Gear.Y - Ammo.Y))) < 50 then // why 50? |
|
609 |
Gear.Active:= true; |
|
610 |
Gear:= Gear.NextGear |
|
611 |
end |
|
38 | 612 |
end; |
613 |
||
4 | 614 |
procedure AssignHHCoords; |
615 |
var Gear: PGear; |
|
616 |
begin |
|
617 |
Gear:= GearsList; |
|
618 |
while Gear <> nil do |
|
619 |
begin |
|
620 |
if Gear.Kind = gtHedgehog then |
|
70 | 621 |
FindPlace(Gear, false, 0, 2048); |
4 | 622 |
Gear:= Gear.NextGear |
623 |
end |
|
624 |
end; |
|
625 |
||
15 | 626 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; |
10 | 627 |
var t: PGear; |
628 |
begin |
|
629 |
t:= GearsList; |
|
630 |
rX:= sqr(rX); |
|
631 |
rY:= sqr(rY); |
|
632 |
while t <> nil do |
|
633 |
begin |
|
634 |
if (t <> Gear) and (t.Kind = Kind) then |
|
635 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then |
|
636 |
begin |
|
15 | 637 |
Result:= t; |
10 | 638 |
exit |
639 |
end; |
|
640 |
t:= t.NextGear |
|
641 |
end; |
|
15 | 642 |
Result:= nil |
643 |
end; |
|
644 |
||
16 | 645 |
function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear; |
646 |
var t: PGear; |
|
647 |
begin |
|
648 |
t:= GearsList; |
|
649 |
rX:= sqr(rX); |
|
650 |
rY:= sqr(rY); |
|
651 |
while t <> nil do |
|
652 |
begin |
|
653 |
if t.Kind in Kind then |
|
654 |
if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then |
|
655 |
begin |
|
656 |
Result:= t; |
|
657 |
exit |
|
658 |
end; |
|
659 |
t:= t.NextGear |
|
660 |
end; |
|
661 |
Result:= nil |
|
662 |
end; |
|
663 |
||
664 |
function CountGears(Kind: TGearType): Longword; |
|
665 |
var t: PGear; |
|
666 |
begin |
|
667 |
Result:= 0; |
|
668 |
t:= GearsList; |
|
669 |
while t <> nil do |
|
670 |
begin |
|
671 |
if t.Kind = Kind then inc(Result); |
|
672 |
t:= t.NextGear |
|
673 |
end; |
|
674 |
end; |
|
675 |
||
15 | 676 |
procedure SpawnBoxOfSmth; |
677 |
begin |
|
70 | 678 |
if (CountGears(gtCase) > 2) or (getrandom(3) <> 0) then exit; |
679 |
FollowGear:= AddGear(0, 0, gtCase, 0); |
|
680 |
FollowGear.Health:= 25; |
|
681 |
FollowGear.Pos:= posCaseHealth; |
|
682 |
FindPlace(FollowGear, true, 0, 2048) |
|
683 |
end; |
|
684 |
||
685 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); |
|
686 |
||
687 |
function CountNonZeroz(x, y, r: integer): integer; |
|
688 |
var i: integer; |
|
689 |
begin |
|
690 |
Result:= 0; |
|
691 |
if (y and $FFFFFC00) <> 0 then exit; |
|
692 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
693 |
if Land[y, i] <> 0 then inc(Result) |
|
694 |
end; |
|
695 |
||
696 |
var fx, x: integer; |
|
697 |
y, sy: integer; |
|
698 |
ar: array[0..512] of TPoint; |
|
699 |
cnt, delta: Longword; |
|
700 |
begin |
|
701 |
fx:= Left + integer(GetRandom(Right - Left)); |
|
702 |
x:= fx; |
|
703 |
delta:= 130; |
|
16 | 704 |
repeat |
70 | 705 |
repeat |
706 |
inc(x, Gear.Radius); |
|
707 |
if x > Right then x:= Left + (x mod (Right - left)); |
|
708 |
cnt:= 0; |
|
709 |
y:= -Gear.Radius * 2; |
|
710 |
while y < 1023 do |
|
16 | 711 |
begin |
70 | 712 |
repeat |
713 |
inc(y, 2); |
|
714 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) = 0); |
|
715 |
sy:= y; |
|
716 |
repeat |
|
717 |
inc(y); |
|
718 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) <> 0); |
|
719 |
if (y - sy > Gear.Radius * 2) |
|
720 |
and (y < 1023) |
|
721 |
and (CheckGearsNear(x, y - Gear.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
|
722 |
begin |
|
723 |
ar[cnt].X:= x; |
|
724 |
if withFall then ar[cnt].Y:= sy + Gear.Radius |
|
725 |
else ar[cnt].Y:= y - Gear.Radius; |
|
726 |
inc(cnt) |
|
727 |
end; |
|
728 |
inc(y, 80) |
|
16 | 729 |
end; |
70 | 730 |
if cnt > 0 then |
731 |
with ar[GetRandom(cnt)] do |
|
732 |
begin |
|
733 |
Gear.X:= x; |
|
734 |
Gear.Y:= y; |
|
735 |
{$IFDEF DEBUGFILE} |
|
736 |
AddFileLog('Assigned Gear ' + inttostr(integer(Gear)) + |
|
737 |
' coordinates (' + inttostr(x) + |
|
738 |
',' + inttostr(y) + ')'); |
|
739 |
{$ENDIF} |
|
740 |
exit |
|
741 |
end |
|
742 |
until (x - Gear.Radius < fx) and (x + Gear.Radius > fx); |
|
743 |
dec(Delta, 20) |
|
744 |
until (Delta < 70); |
|
745 |
OutError('Couldn''t find place for Gear ' + inttostr(integer(Gear)), false); |
|
746 |
DeleteGear(Gear) |
|
10 | 747 |
end; |
748 |
||
4 | 749 |
initialization |
750 |
||
751 |
finalization |
|
752 |
FreeGearsList |
|
753 |
||
754 |
end. |