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