author | unc0rr |
Mon, 24 Jul 2006 14:03:51 +0000 | |
changeset 83 | 207c85fbef51 |
parent 82 | 2f4f3236cccc |
child 89 | f9db56409a86 |
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; |
|
327 |
if AllInactive then |
|
15 | 328 |
case step of |
329 |
stDelay: begin |
|
330 |
dec(delay); |
|
331 |
if delay = 0 then |
|
332 |
begin |
|
333 |
inc(step); |
|
334 |
delay:= cInactDelay |
|
335 |
end |
|
336 |
end; |
|
337 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
338 |
stSpawn: begin |
|
339 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
340 |
inc(step) |
|
341 |
end; |
|
342 |
stNTurn: begin |
|
74 | 343 |
AwareOfExplosion(0, 0, 0); |
15 | 344 |
if isInMultiShoot then isInMultiShoot:= false |
345 |
else ParseCommand('/nextturn'); |
|
346 |
step:= Low(step) |
|
347 |
end; |
|
348 |
end; |
|
349 |
||
4 | 350 |
if TurnTimeLeft > 0 then |
351 |
if CurrentTeam <> nil then |
|
352 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then |
|
353 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0) |
|
354 |
and not isInMultiShoot then dec(TurnTimeLeft); |
|
74 | 355 |
|
4 | 356 |
inc(GameTicks); |
357 |
{$IFDEF COUNTTICKS} |
|
358 |
asm |
|
359 |
push eax |
|
360 |
push edx |
|
361 |
rdtsc |
|
362 |
sub eax, [tickcntA] |
|
363 |
sbb edx, [tickcntB] |
|
364 |
add [cntSecTicks], eax |
|
365 |
pop edx |
|
366 |
pop eax |
|
367 |
end; |
|
368 |
if (GameTicks and 1023) = 0 then |
|
369 |
begin |
|
370 |
cntTicks:= cntSecTicks shr 10; |
|
371 |
{$IFDEF DEBUGFILE} |
|
372 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
373 |
{$ENDIF} |
|
374 |
cntSecTicks:= 0 |
|
375 |
end; |
|
376 |
{$ENDIF} |
|
377 |
end; |
|
378 |
||
379 |
procedure SetAllToActive; |
|
380 |
var t: PGear; |
|
381 |
begin |
|
382 |
AllInactive:= false; |
|
383 |
t:= GearsList; |
|
384 |
while t<>nil do |
|
385 |
begin |
|
386 |
t.Active:= true; |
|
387 |
t:= t.NextGear |
|
388 |
end |
|
389 |
end; |
|
390 |
||
391 |
procedure SetAllHHToActive; |
|
392 |
var t: PGear; |
|
393 |
begin |
|
394 |
AllInactive:= false; |
|
395 |
t:= GearsList; |
|
396 |
while t<>nil do |
|
397 |
begin |
|
398 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
399 |
t:= t.NextGear |
|
400 |
end |
|
401 |
end; |
|
402 |
||
403 |
procedure DrawGears(Surface: PSDL_Surface); |
|
404 |
var Gear: PGear; |
|
405 |
i: Longword; |
|
35 | 406 |
roplen: real; |
4 | 407 |
|
408 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
35 | 409 |
const nodlen = 5; |
410 |
var i, x, y: integer; |
|
411 |
t, k, ladd: real; |
|
4 | 412 |
begin |
37 | 413 |
if (X1 = X2) and (Y1 = Y2) then |
414 |
begin |
|
83 | 415 |
OutError('WARNING: zero length rope line!'); |
37 | 416 |
exit |
417 |
end; |
|
4 | 418 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
419 |
begin |
|
420 |
if X1 > X2 then |
|
421 |
begin |
|
422 |
i:= X1; |
|
423 |
X1:= X2; |
|
424 |
X2:= i; |
|
425 |
i:= Y1; |
|
426 |
Y1:= Y2; |
|
427 |
Y2:= i |
|
428 |
end; |
|
429 |
k:= (Y2 - Y1) / (X2 - X1); |
|
35 | 430 |
ladd:= sqrt(1 + sqr(k)); |
4 | 431 |
if X1 < 0 then |
432 |
begin |
|
433 |
t:= Y1 - 2 - k * X1; |
|
434 |
X1:= 0 |
|
435 |
end else t:= Y1 - 2; |
|
436 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
35 | 437 |
for x:= X1 to X2 do |
438 |
begin |
|
439 |
roplen:= roplen + ladd; |
|
440 |
if roplen > nodlen then |
|
441 |
begin |
|
442 |
DrawGear(sRopeNode, x - 2, round(t) - 2, Surface); |
|
443 |
roplen:= roplen - nodlen; |
|
444 |
end; |
|
445 |
t:= t + k; |
|
446 |
end; |
|
4 | 447 |
end else |
448 |
begin |
|
449 |
if Y1 > Y2 then |
|
450 |
begin |
|
451 |
i:= X1; |
|
452 |
X1:= X2; |
|
453 |
X2:= i; |
|
454 |
i:= Y1; |
|
455 |
Y1:= Y2; |
|
456 |
Y2:= i |
|
457 |
end; |
|
458 |
k:= (X2 - X1) / (Y2 - Y1); |
|
35 | 459 |
ladd:= sqrt(1 + sqr(k)); |
4 | 460 |
if Y1 < 0 then |
461 |
begin |
|
462 |
t:= X1 - 2 - k * Y1; |
|
463 |
Y1:= 0 |
|
464 |
end else t:= X1 - 2; |
|
465 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
35 | 466 |
for y:= Y1 to Y2 do |
467 |
begin |
|
468 |
roplen:= roplen + ladd; |
|
469 |
if roplen > nodlen then |
|
470 |
begin |
|
471 |
DrawGear(sRopeNode, round(t) - 2, y - 2, Surface); |
|
472 |
roplen:= roplen - nodlen; |
|
473 |
end; |
|
474 |
t:= t + k; |
|
475 |
end; |
|
4 | 476 |
end |
477 |
end; |
|
478 |
||
479 |
begin |
|
480 |
Gear:= GearsList; |
|
481 |
while Gear<>nil do |
|
482 |
begin |
|
483 |
case Gear.Kind of |
|
484 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
485 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
486 |
gtHedgehog: DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, Sign(Gear.dX), |
|
487 |
0, PHedgehog(Gear.Hedgehog).visStepPos div 2, |
|
488 |
Surface); |
|
489 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
|
490 |
gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true); |
|
491 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
|
492 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 493 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 494 |
gtRope: begin |
35 | 495 |
roplen:= 0; |
4 | 496 |
if RopePoints.Count > 0 then |
497 |
begin |
|
498 |
i:= 0; |
|
499 |
while i < Pred(RopePoints.Count) do |
|
500 |
begin |
|
501 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
502 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
503 |
inc(i) |
|
504 |
end; |
|
505 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
506 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
35 | 507 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
508 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 509 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
510 |
end else |
|
35 | 511 |
begin |
512 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
513 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 514 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
35 | 515 |
end; |
4 | 516 |
end; |
9 | 517 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 518 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
519 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
520 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
46 | 521 |
gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 25 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface); |
42 | 522 |
gtCase: case Gear.Pos of |
523 |
posCaseAmmo : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface); |
|
75 | 524 |
posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 24 + WorldDx, Round(Gear.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
42 | 525 |
end; |
78 | 526 |
gtClusterBomb: DrawSprite(sprClusterBomb, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
527 |
gtCluster: DrawSprite(sprClusterParticle, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, 0, Surface); |
|
79 | 528 |
gtFlame: DrawSprite(sprFlame, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy,(GameTicks div 128 + Gear.Angle) mod 8, Surface); |
4 | 529 |
end; |
530 |
Gear:= Gear.NextGear |
|
531 |
end; |
|
532 |
end; |
|
533 |
||
534 |
procedure FreeGearsList; |
|
535 |
var t, tt: PGear; |
|
536 |
begin |
|
537 |
tt:= GearsList; |
|
538 |
GearsList:= nil; |
|
539 |
while tt<>nil do |
|
540 |
begin |
|
541 |
t:= tt; |
|
542 |
tt:= tt.NextGear; |
|
543 |
Dispose(t) |
|
544 |
end; |
|
545 |
end; |
|
546 |
||
10 | 547 |
procedure AddMiscGears; |
70 | 548 |
var i: integer; |
4 | 549 |
begin |
74 | 550 |
for i:= 0 to cCloudsNumber do |
551 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), |
|
552 |
(0.5-random)*0.02, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); |
|
83 | 553 |
AddGear(0, 0, gtATStartGame, 0, 0, 0, 2000); |
22 | 554 |
if (GameFlags and gfForts) = 0 then |
555 |
for i:= 0 to 3 do |
|
70 | 556 |
FindPlace(AddGear(0, 0, gtMine, 0), false, 0, 2048); |
4 | 557 |
end; |
558 |
||
559 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
|
560 |
var Gear: PGear; |
|
561 |
dmg: integer; |
|
562 |
begin |
|
563 |
TargetPoint.X:= NoPointX; |
|
564 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
565 |
DrawExplosion(X, Y, Radius); |
|
9 | 566 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 567 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
568 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
569 |
Gear:= GearsList; |
|
570 |
while Gear <> nil do |
|
571 |
begin |
|
572 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
573 |
if dmg > 0 then |
|
574 |
begin |
|
575 |
dmg:= dmg shr 1; |
|
576 |
case Gear.Kind of |
|
10 | 577 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
578 |
gtMine, |
79 | 579 |
gtCase, |
580 |
gtFlame: begin |
|
39 | 581 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear.Damage, dmg); |
42 | 582 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear.Kind <> gtHedgehog) then |
583 |
begin |
|
70 | 584 |
Gear.dX:= Gear.dX + dmg / 200 * Sign(Gear.X - X); |
585 |
Gear.dY:= Gear.dY + dmg / 200 * Sign(Gear.Y - Y); |
|
42 | 586 |
Gear.Active:= true; |
587 |
FollowGear:= Gear |
|
588 |
end; |
|
4 | 589 |
end; |
51 | 590 |
gtGrave: begin |
591 |
Gear.dY:= - dmg / 250; |
|
592 |
Gear.Active:= true; |
|
593 |
end; |
|
4 | 594 |
end; |
595 |
end; |
|
596 |
Gear:= Gear.NextGear |
|
80 | 597 |
end; |
598 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
4 | 599 |
end; |
600 |
||
75 | 601 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 602 |
var t: PGearArray; |
603 |
i: integer; |
|
38 | 604 |
begin |
53 | 605 |
t:= CheckGearsCollision(Ammo); |
606 |
i:= t.Count; |
|
607 |
while i > 0 do |
|
608 |
begin |
|
609 |
dec(i); |
|
79 | 610 |
if (t.ar[i].State and gstNoDamage) = 0 then |
611 |
case t.ar[i].Kind of |
|
53 | 612 |
gtHedgehog, |
613 |
gtMine, |
|
614 |
gtCase: begin |
|
75 | 615 |
inc(t.ar[i].Damage, Damage); |
53 | 616 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
617 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
618 |
t.ar[i].Active:= true; |
|
619 |
DeleteCI(t.ar[i]); |
|
620 |
FollowGear:= t.ar[i] |
|
621 |
end; |
|
622 |
end |
|
79 | 623 |
end |
38 | 624 |
end; |
625 |
||
4 | 626 |
procedure AssignHHCoords; |
82 | 627 |
var Team: PTeam; |
628 |
i, t: integer; |
|
4 | 629 |
begin |
82 | 630 |
Team:= TeamsList; |
631 |
t:= 0; |
|
632 |
while Team <> nil do |
|
4 | 633 |
begin |
82 | 634 |
for i:= 0 to cMaxHHIndex do |
635 |
with Team.Hedgehogs[i] do |
|
636 |
if Gear <> nil then |
|
637 |
if (GameFlags and gfForts) = 0 then FindPlace(Gear, false, 0, 2048) |
|
638 |
else FindPlace(Gear, false, t, t + 1024); |
|
639 |
inc(t, 1024); |
|
640 |
Team:= Team.Next |
|
4 | 641 |
end |
642 |
end; |
|
643 |
||
15 | 644 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; |
10 | 645 |
var t: PGear; |
646 |
begin |
|
647 |
t:= GearsList; |
|
648 |
rX:= sqr(rX); |
|
649 |
rY:= sqr(rY); |
|
650 |
while t <> nil do |
|
651 |
begin |
|
652 |
if (t <> Gear) and (t.Kind = Kind) then |
|
653 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then |
|
654 |
begin |
|
15 | 655 |
Result:= t; |
10 | 656 |
exit |
657 |
end; |
|
658 |
t:= t.NextGear |
|
659 |
end; |
|
15 | 660 |
Result:= nil |
661 |
end; |
|
662 |
||
79 | 663 |
procedure AmmoFlameWork(Ammo: PGear); |
664 |
var t: PGear; |
|
665 |
begin |
|
666 |
t:= GearsList; |
|
667 |
while t <> nil do |
|
668 |
begin |
|
669 |
if (t.Kind = gtHedgehog) and (t.Y < Ammo.Y) then |
|
670 |
if sqr(Ammo.X - t.X) + sqr(Ammo.Y - t.Y - cHHRadius) * 2 <= sqr(4) then |
|
671 |
begin |
|
672 |
inc(t.Damage, 5); |
|
673 |
t.dX:= t.dX + (t.X - Ammo.X) * 0.02; |
|
674 |
t.dY:= - 0.25; |
|
675 |
t.Active:= true; |
|
676 |
DeleteCI(t); |
|
677 |
FollowGear:= t |
|
678 |
end; |
|
679 |
t:= t.NextGear |
|
680 |
end; |
|
681 |
end; |
|
682 |
||
16 | 683 |
function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear; |
684 |
var t: PGear; |
|
685 |
begin |
|
686 |
t:= GearsList; |
|
687 |
rX:= sqr(rX); |
|
688 |
rY:= sqr(rY); |
|
689 |
while t <> nil do |
|
690 |
begin |
|
691 |
if t.Kind in Kind then |
|
692 |
if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then |
|
693 |
begin |
|
694 |
Result:= t; |
|
695 |
exit |
|
696 |
end; |
|
697 |
t:= t.NextGear |
|
698 |
end; |
|
699 |
Result:= nil |
|
700 |
end; |
|
701 |
||
702 |
function CountGears(Kind: TGearType): Longword; |
|
703 |
var t: PGear; |
|
704 |
begin |
|
705 |
Result:= 0; |
|
706 |
t:= GearsList; |
|
707 |
while t <> nil do |
|
708 |
begin |
|
709 |
if t.Kind = Kind then inc(Result); |
|
710 |
t:= t.NextGear |
|
711 |
end; |
|
712 |
end; |
|
713 |
||
15 | 714 |
procedure SpawnBoxOfSmth; |
715 |
begin |
|
70 | 716 |
if (CountGears(gtCase) > 2) or (getrandom(3) <> 0) then exit; |
717 |
FollowGear:= AddGear(0, 0, gtCase, 0); |
|
718 |
FollowGear.Health:= 25; |
|
719 |
FollowGear.Pos:= posCaseHealth; |
|
720 |
FindPlace(FollowGear, true, 0, 2048) |
|
721 |
end; |
|
722 |
||
723 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); |
|
724 |
||
725 |
function CountNonZeroz(x, y, r: integer): integer; |
|
726 |
var i: integer; |
|
727 |
begin |
|
728 |
Result:= 0; |
|
729 |
if (y and $FFFFFC00) <> 0 then exit; |
|
730 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
731 |
if Land[y, i] <> 0 then inc(Result) |
|
732 |
end; |
|
733 |
||
734 |
var fx, x: integer; |
|
735 |
y, sy: integer; |
|
736 |
ar: array[0..512] of TPoint; |
|
737 |
cnt, delta: Longword; |
|
738 |
begin |
|
739 |
fx:= Left + integer(GetRandom(Right - Left)); |
|
740 |
x:= fx; |
|
741 |
delta:= 130; |
|
16 | 742 |
repeat |
70 | 743 |
repeat |
744 |
inc(x, Gear.Radius); |
|
745 |
if x > Right then x:= Left + (x mod (Right - left)); |
|
746 |
cnt:= 0; |
|
747 |
y:= -Gear.Radius * 2; |
|
748 |
while y < 1023 do |
|
16 | 749 |
begin |
70 | 750 |
repeat |
751 |
inc(y, 2); |
|
752 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) = 0); |
|
753 |
sy:= y; |
|
754 |
repeat |
|
755 |
inc(y); |
|
756 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) <> 0); |
|
757 |
if (y - sy > Gear.Radius * 2) |
|
758 |
and (y < 1023) |
|
759 |
and (CheckGearsNear(x, y - Gear.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
|
760 |
begin |
|
761 |
ar[cnt].X:= x; |
|
762 |
if withFall then ar[cnt].Y:= sy + Gear.Radius |
|
763 |
else ar[cnt].Y:= y - Gear.Radius; |
|
764 |
inc(cnt) |
|
765 |
end; |
|
766 |
inc(y, 80) |
|
16 | 767 |
end; |
70 | 768 |
if cnt > 0 then |
769 |
with ar[GetRandom(cnt)] do |
|
770 |
begin |
|
771 |
Gear.X:= x; |
|
772 |
Gear.Y:= y; |
|
773 |
{$IFDEF DEBUGFILE} |
|
774 |
AddFileLog('Assigned Gear ' + inttostr(integer(Gear)) + |
|
775 |
' coordinates (' + inttostr(x) + |
|
776 |
',' + inttostr(y) + ')'); |
|
777 |
{$ENDIF} |
|
778 |
exit |
|
779 |
end |
|
780 |
until (x - Gear.Radius < fx) and (x + Gear.Radius > fx); |
|
781 |
dec(Delta, 20) |
|
782 |
until (Delta < 70); |
|
783 |
OutError('Couldn''t find place for Gear ' + inttostr(integer(Gear)), false); |
|
784 |
DeleteGear(Gear) |
|
10 | 785 |
end; |
786 |
||
4 | 787 |
initialization |
788 |
||
789 |
finalization |
|
790 |
FreeGearsList |
|
791 |
||
792 |
end. |