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