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