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