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