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