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