author | displacer |
Thu, 16 Aug 2007 12:42:22 +0000 | |
changeset 570 | f674e8e5bf28 |
parent 568 | d0690b7aa808 |
child 590 | e816adf4a27f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2004-2007 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 |
|
351 | 21 |
uses SDLh, uConsts, uFloat; |
4 | 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; |
351 | 31 |
X : hwFloat; |
32 |
Y : hwFloat; |
|
33 |
dX: hwFloat; |
|
34 |
dY: hwFloat; |
|
42 | 35 |
Kind: TGearType; |
36 |
Pos: Longword; |
|
4 | 37 |
doStep: TGearStepProcedure; |
371 | 38 |
Radius: LongInt; |
188 | 39 |
Angle, Power : Longword; |
351 | 40 |
DirAngle: hwFloat; |
4 | 41 |
Timer : LongWord; |
351 | 42 |
Elasticity: hwFloat; |
43 |
Friction : hwFloat; |
|
4 | 44 |
Message : Longword; |
45 |
Hedgehog: pointer; |
|
371 | 46 |
Health, Damage: LongInt; |
511 | 47 |
CollisionIndex: LongInt; |
371 | 48 |
Tag: LongInt; |
95 | 49 |
Surf: PSDL_Surface; |
293 | 50 |
Z: Longword; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
51 |
IntersectGear: PGear; |
4 | 52 |
end; |
53 |
||
371 | 54 |
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
4 | 55 |
procedure ProcessGears; |
56 |
procedure SetAllToActive; |
|
57 |
procedure SetAllHHToActive; |
|
58 |
procedure DrawGears(Surface: PSDL_Surface); |
|
59 |
procedure FreeGearsList; |
|
10 | 60 |
procedure AddMiscGears; |
293 | 61 |
procedure AddClouds; |
4 | 62 |
procedure AssignHHCoords; |
294 | 63 |
procedure InsertGearToList(Gear: PGear); |
64 |
procedure RemoveGearFromList(Gear: PGear); |
|
4 | 65 |
|
66 |
var CurAmmoGear: PGear = nil; |
|
68 | 67 |
GearsList: PGear = nil; |
307 | 68 |
KilledHHs: Longword = 0; |
70 | 69 |
|
4 | 70 |
implementation |
81 | 71 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, |
295 | 72 |
uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos; |
68 | 73 |
var RopePoints: record |
4 | 74 |
Count: Longword; |
371 | 75 |
HookAngle: LongInt; |
4 | 76 |
ar: array[0..300] of record |
351 | 77 |
X, Y: hwFloat; |
78 |
dLen: hwFloat; |
|
4 | 79 |
b: boolean; |
80 |
end; |
|
81 |
end; |
|
307 | 82 |
StepDamage: Longword = 0; |
4 | 83 |
|
84 |
procedure DeleteGear(Gear: PGear); forward; |
|
371 | 85 |
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward; |
86 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward; |
|
79 | 87 |
procedure AmmoFlameWork(Ammo: PGear); forward; |
371 | 88 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward; |
15 | 89 |
procedure SpawnBoxOfSmth; forward; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset
|
90 |
procedure AfterAttack; forward; |
371 | 91 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); forward; |
302 | 92 |
procedure HedgehogStep(Gear: PGear); forward; |
303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset
|
93 |
procedure HedgehogChAngle(Gear: PGear); forward; |
506 | 94 |
procedure ShotgunShot(Gear: PGear); forward; |
522 | 95 |
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); forward; |
4 | 96 |
|
97 |
{$INCLUDE GSHandlers.inc} |
|
98 |
{$INCLUDE HHHandlers.inc} |
|
99 |
||
100 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
351 | 101 |
@doStepCloud, |
102 |
@doStepBomb, |
|
103 |
@doStepHedgehog, |
|
104 |
@doStepGrenade, |
|
105 |
@doStepHealthTag, |
|
106 |
@doStepGrave, |
|
107 |
@doStepUFO, |
|
108 |
@doStepShotgunShot, |
|
109 |
@doStepPickHammer, |
|
110 |
@doStepRope, |
|
111 |
@doStepSmokeTrace, |
|
112 |
@doStepExplosion, |
|
113 |
@doStepMine, |
|
114 |
@doStepCase, |
|
115 |
@doStepDEagleShot, |
|
116 |
@doStepDynamite, |
|
117 |
@doStepTeamHealthSorter, |
|
118 |
@doStepBomb, |
|
119 |
@doStepCluster, |
|
120 |
@doStepShover, |
|
121 |
@doStepFlame, |
|
122 |
@doStepFirePunch, |
|
123 |
@doStepActionTimer, |
|
124 |
@doStepActionTimer, |
|
125 |
@doStepActionTimer, |
|
126 |
@doStepParachute, |
|
127 |
@doStepAirAttack, |
|
128 |
@doStepAirBomb, |
|
409 | 129 |
@doStepBlowTorch, |
520 | 130 |
@doStepGirder, |
522 | 131 |
@doStepTeleport, |
534 | 132 |
@doStepHealthTag, |
133 |
@doStepSwitcher |
|
4 | 134 |
); |
135 |
||
294 | 136 |
procedure InsertGearToList(Gear: PGear); |
137 |
var tmp: PGear; |
|
138 |
begin |
|
139 |
if GearsList = nil then |
|
140 |
GearsList:= Gear |
|
141 |
else begin |
|
142 |
// WARNING: this code assumes that the first gears added to the list are clouds (have maximal Z) |
|
143 |
tmp:= GearsList; |
|
351 | 144 |
while (tmp <> nil) and (tmp^.Z < Gear^.Z) do |
145 |
tmp:= tmp^.NextGear; |
|
294 | 146 |
|
351 | 147 |
if tmp^.PrevGear <> nil then tmp^.PrevGear^.NextGear:= Gear; |
148 |
Gear^.PrevGear:= tmp^.PrevGear; |
|
149 |
tmp^.PrevGear:= Gear; |
|
150 |
Gear^.NextGear:= tmp; |
|
294 | 151 |
if GearsList = tmp then GearsList:= Gear |
152 |
end |
|
153 |
end; |
|
154 |
||
155 |
procedure RemoveGearFromList(Gear: PGear); |
|
156 |
begin |
|
351 | 157 |
if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
158 |
if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear |
|
294 | 159 |
else begin |
351 | 160 |
GearsList:= Gear^.NextGear; |
161 |
if GearsList <> nil then GearsList^.PrevGear:= nil |
|
294 | 162 |
end; |
163 |
end; |
|
164 |
||
371 | 165 |
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
79 | 166 |
const Counter: Longword = 0; |
351 | 167 |
var Result: PGear; |
4 | 168 |
begin |
79 | 169 |
inc(Counter); |
108 | 170 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF} |
4 | 171 |
New(Result); |
357 | 172 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: type = ' + inttostr(ord(Kind)));{$ENDIF} |
4 | 173 |
FillChar(Result^, sizeof(TGear), 0); |
498 | 174 |
Result^.X:= int2hwFloat(X); |
175 |
Result^.Y:= int2hwFloat(Y); |
|
351 | 176 |
Result^.Kind := Kind; |
177 |
Result^.State:= State; |
|
178 |
Result^.Active:= true; |
|
179 |
Result^.dX:= dX; |
|
180 |
Result^.dY:= dY; |
|
181 |
Result^.doStep:= doStepHandlers[Kind]; |
|
511 | 182 |
Result^.CollisionIndex:= -1; |
351 | 183 |
Result^.Timer:= Timer; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
184 |
|
4 | 185 |
if CurrentTeam <> nil then |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
186 |
begin |
351 | 187 |
Result^.Hedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]); |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
188 |
Result^.IntersectGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
189 |
end; |
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
190 |
|
4 | 191 |
case Kind of |
351 | 192 |
gtCloud: Result^.Z:= High(Result^.Z); |
4 | 193 |
gtAmmo_Bomb: begin |
351 | 194 |
Result^.Radius:= 4; |
195 |
Result^.Elasticity:= _0_6; |
|
196 |
Result^.Friction:= _0_995; |
|
4 | 197 |
end; |
198 |
gtHedgehog: begin |
|
351 | 199 |
Result^.Radius:= cHHRadius; |
200 |
Result^.Elasticity:= _0_35; |
|
201 |
Result^.Friction:= _0_999; |
|
202 |
Result^.Angle:= cMaxAngle div 2; |
|
203 |
Result^.Z:= cHHZ; |
|
4 | 204 |
end; |
205 |
gtAmmo_Grenade: begin |
|
351 | 206 |
Result^.Radius:= 4; |
4 | 207 |
end; |
208 |
gtHealthTag: begin |
|
351 | 209 |
Result^.Timer:= 1500; |
522 | 210 |
Result^.Z:= 2001; |
4 | 211 |
end; |
212 |
gtGrave: begin |
|
351 | 213 |
Result^.Radius:= 10; |
214 |
Result^.Elasticity:= _0_6; |
|
4 | 215 |
end; |
216 |
gtUFO: begin |
|
351 | 217 |
Result^.Radius:= 5; |
218 |
Result^.Timer:= 500; |
|
219 |
Result^.Elasticity:= _0_9 |
|
4 | 220 |
end; |
221 |
gtShotgunShot: begin |
|
351 | 222 |
Result^.Timer:= 900; |
223 |
Result^.Radius:= 2 |
|
4 | 224 |
end; |
225 |
gtPickHammer: begin |
|
351 | 226 |
Result^.Radius:= 10; |
227 |
Result^.Timer:= 4000 |
|
4 | 228 |
end; |
229 |
gtSmokeTrace: begin |
|
498 | 230 |
Result^.X:= Result^.X - _16; |
231 |
Result^.Y:= Result^.Y - _16; |
|
351 | 232 |
Result^.State:= 8 |
4 | 233 |
end; |
234 |
gtRope: begin |
|
351 | 235 |
Result^.Radius:= 3; |
498 | 236 |
Result^.Friction:= _450; |
4 | 237 |
RopePoints.Count:= 0; |
238 |
end; |
|
9 | 239 |
gtExplosion: begin |
498 | 240 |
Result^.X:= Result^.X - _25; |
241 |
Result^.Y:= Result^.Y - _25; |
|
9 | 242 |
end; |
10 | 243 |
gtMine: begin |
503 | 244 |
Result^.State:= Result^.State or gstMoving; |
351 | 245 |
Result^.Radius:= 3; |
246 |
Result^.Elasticity:= _0_55; |
|
247 |
Result^.Friction:= _0_995; |
|
248 |
Result^.Timer:= 3000; |
|
10 | 249 |
end; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
250 |
gtCase: begin |
351 | 251 |
Result^.Radius:= 16; |
252 |
Result^.Elasticity:= _0_4 |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
253 |
end; |
37 | 254 |
gtDEagleShot: begin |
351 | 255 |
Result^.Radius:= 1; |
256 |
Result^.Health:= 50 |
|
37 | 257 |
end; |
39 | 258 |
gtDynamite: begin |
351 | 259 |
Result^.Radius:= 3; |
260 |
Result^.Elasticity:= _0_55; |
|
261 |
Result^.Friction:= _0_03; |
|
262 |
Result^.Timer:= 5000; |
|
39 | 263 |
end; |
78 | 264 |
gtClusterBomb: begin |
351 | 265 |
Result^.Radius:= 4; |
266 |
Result^.Elasticity:= _0_6; |
|
267 |
Result^.Friction:= _0_995; |
|
78 | 268 |
end; |
79 | 269 |
gtFlame: begin |
351 | 270 |
Result^.Angle:= Counter mod 64; |
271 |
Result^.Radius:= 1; |
|
272 |
Result^.Health:= 2; |
|
273 |
Result^.dY:= (getrandom - _0_8) * _0_03; |
|
274 |
Result^.dX:= (getrandom - _0_5) * _0_4 |
|
79 | 275 |
end; |
82 | 276 |
gtFirePunch: begin |
351 | 277 |
Result^.Radius:= 15; |
278 |
Result^.Tag:= Y |
|
82 | 279 |
end; |
302 | 280 |
gtAirBomb: begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
281 |
Result^.Radius:= 5; |
302 | 282 |
end; |
283 |
gtBlowTorch: begin |
|
511 | 284 |
Result^.Radius:= cHHRadius + cBlowTorchC; |
351 | 285 |
Result^.Timer:= 7500; |
302 | 286 |
end; |
522 | 287 |
gtSmallDamage: begin |
288 |
Result^.Timer:= 1100; |
|
289 |
Result^.Z:= 2000; |
|
290 |
end; |
|
540 | 291 |
gtSwitcher: begin |
292 |
Result^.Z:= cCurrHHZ |
|
293 |
end; |
|
4 | 294 |
end; |
351 | 295 |
InsertGearToList(Result); |
296 |
AddGear:= Result |
|
4 | 297 |
end; |
298 |
||
299 |
procedure DeleteGear(Gear: PGear); |
|
48 | 300 |
var team: PTeam; |
307 | 301 |
t: Longword; |
4 | 302 |
begin |
503 | 303 |
DeleteCI(Gear); |
522 | 304 |
if Gear^.Surf <> nil then |
305 |
begin |
|
306 |
SDL_FreeSurface(Gear^.Surf); |
|
307 |
Gear^.Surf:= nil |
|
308 |
end; |
|
351 | 309 |
if Gear^.Kind = gtHedgehog then |
4 | 310 |
if CurAmmoGear <> nil then |
311 |
begin |
|
351 | 312 |
Gear^.Message:= gm_Destroy; |
313 |
CurAmmoGear^.Message:= gm_Destroy; |
|
4 | 314 |
exit |
47 | 315 |
end else |
316 |
begin |
|
498 | 317 |
if not (hwRound(Gear^.Y) < cWaterLine) then |
307 | 318 |
begin |
351 | 319 |
t:= max(Gear^.Damage, Gear^.Health); |
498 | 320 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtHealthTag, t, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
307 | 321 |
inc(StepDamage, t) |
322 |
end; |
|
351 | 323 |
team:= PHedgehog(Gear^.Hedgehog)^.Team; |
324 |
if CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear = Gear then |
|
145 | 325 |
FreeActionsList; // to avoid ThinkThread on drawned gear |
351 | 326 |
PHedgehog(Gear^.Hedgehog)^.Gear:= nil; |
307 | 327 |
inc(KilledHHs); |
48 | 328 |
RecountTeamHealth(team); |
47 | 329 |
end; |
357 | 330 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear');{$ENDIF} |
82 | 331 |
if CurAmmoGear = Gear then CurAmmoGear:= nil; |
4 | 332 |
if FollowGear = Gear then FollowGear:= nil; |
294 | 333 |
RemoveGearFromList(Gear); |
4 | 334 |
Dispose(Gear) |
335 |
end; |
|
336 |
||
337 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
338 |
var Gear: PGear; |
|
339 |
begin |
|
351 | 340 |
CheckNoDamage:= true; |
4 | 341 |
Gear:= GearsList; |
342 |
while Gear <> nil do |
|
343 |
begin |
|
351 | 344 |
if Gear^.Kind = gtHedgehog then |
345 |
if Gear^.Damage <> 0 then |
|
4 | 346 |
begin |
351 | 347 |
CheckNoDamage:= false; |
348 |
inc(StepDamage, Gear^.Damage); |
|
349 |
if Gear^.Health < Gear^.Damage then Gear^.Health:= 0 |
|
522 | 350 |
else dec(Gear^.Health, Gear^.Damage); |
351 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12, |
|
498 | 352 |
gtHealthTag, Gear^.Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
351 | 353 |
RenderHealth(PHedgehog(Gear^.Hedgehog)^); |
354 |
RecountTeamHealth(PHedgehog(Gear^.Hedgehog)^.Team); |
|
355 |
||
356 |
Gear^.Damage:= 0 |
|
4 | 357 |
end; |
351 | 358 |
Gear:= Gear^.NextGear |
83 | 359 |
end; |
4 | 360 |
end; |
361 |
||
522 | 362 |
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); |
363 |
begin |
|
529 | 364 |
if cAltDamage then |
365 |
AddGear(X, Y, gtSmallDamage, Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
|
522 | 366 |
end; |
367 |
||
4 | 368 |
procedure ProcessGears; |
371 | 369 |
const delay: LongInt = cInactDelay; |
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
370 |
step: (stDelay, stChDmg, stChWin, stSpawn, stNTurn) = stDelay; |
4 | 371 |
var Gear, t: PGear; |
372 |
begin |
|
373 |
AllInactive:= true; |
|
374 |
t:= GearsList; |
|
375 |
while t<>nil do |
|
376 |
begin |
|
377 |
Gear:= t; |
|
351 | 378 |
t:= Gear^.NextGear; |
379 |
if Gear^.Active then Gear^.doStep(Gear); |
|
4 | 380 |
end; |
89 | 381 |
|
4 | 382 |
if AllInactive then |
15 | 383 |
case step of |
384 |
stDelay: begin |
|
385 |
dec(delay); |
|
386 |
if delay = 0 then |
|
387 |
begin |
|
388 |
inc(step); |
|
389 |
delay:= cInactDelay |
|
390 |
end |
|
391 |
end; |
|
392 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
351 | 393 |
stChWin: if not CheckForWin then inc(step) else step:= stDelay; |
15 | 394 |
stSpawn: begin |
395 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
396 |
inc(step) |
|
397 |
end; |
|
398 |
stNTurn: begin |
|
351 | 399 |
//AwareOfExplosion(0, 0, 0); |
15 | 400 |
if isInMultiShoot then isInMultiShoot:= false |
307 | 401 |
else begin |
351 | 402 |
with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do |
307 | 403 |
if MaxStepDamage < StepDamage then MaxStepDamage:= StepDamage; |
404 |
StepDamage:= 0; |
|
351 | 405 |
ParseCommand('/nextturn', true); |
307 | 406 |
end; |
15 | 407 |
step:= Low(step) |
408 |
end; |
|
409 |
end; |
|
410 |
||
4 | 411 |
if TurnTimeLeft > 0 then |
412 |
if CurrentTeam <> nil then |
|
351 | 413 |
if CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil then |
414 |
if ((CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.State and gstAttacking) = 0) |
|
4 | 415 |
and not isInMultiShoot then dec(TurnTimeLeft); |
351 | 416 |
|
515 | 417 |
inc(GameTicks) |
4 | 418 |
end; |
419 |
||
420 |
procedure SetAllToActive; |
|
421 |
var t: PGear; |
|
422 |
begin |
|
423 |
AllInactive:= false; |
|
424 |
t:= GearsList; |
|
351 | 425 |
while t <> nil do |
4 | 426 |
begin |
351 | 427 |
t^.Active:= true; |
428 |
t:= t^.NextGear |
|
4 | 429 |
end |
430 |
end; |
|
431 |
||
432 |
procedure SetAllHHToActive; |
|
433 |
var t: PGear; |
|
434 |
begin |
|
435 |
AllInactive:= false; |
|
436 |
t:= GearsList; |
|
351 | 437 |
while t <> nil do |
4 | 438 |
begin |
351 | 439 |
if t^.Kind = gtHedgehog then t^.Active:= true; |
440 |
t:= t^.NextGear |
|
4 | 441 |
end |
442 |
end; |
|
443 |
||
292 | 444 |
procedure DrawHH(Gear: PGear; Surface: PSDL_Surface); |
371 | 445 |
var t: LongInt; |
292 | 446 |
begin |
503 | 447 |
DrawHedgehog(hwRound(Gear^.X) - 15 + WorldDx, hwRound(Gear^.Y) - 18 + WorldDy, |
351 | 448 |
hwSign(Gear^.dX), 0, |
449 |
PHedgehog(Gear^.Hedgehog)^.visStepPos div 2, |
|
292 | 450 |
Surface); |
451 |
||
351 | 452 |
with PHedgehog(Gear^.Hedgehog)^ do |
538 | 453 |
if (Gear^.State{ and not gstAnimation}) = 0 then |
292 | 454 |
begin |
351 | 455 |
t:= hwRound(Gear^.Y) - cHHRadius - 10 + WorldDy; |
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
456 |
if (cTagsMask and 1) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
457 |
begin |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
458 |
dec(t, HealthTag^.h + 2); |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
459 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, HealthTag, Surface) |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
460 |
end; |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
461 |
if (cTagsMask and 2) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
462 |
begin |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
463 |
dec(t, NameTag^.h + 2); |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
464 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, NameTag, Surface) |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
465 |
end; |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
466 |
if (cTagsMask and 4) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
467 |
begin |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
468 |
dec(t, Team^.NameTag^.h + 2); |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
469 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTag, Surface) |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
470 |
end |
292 | 471 |
end else // Current hedgehog |
538 | 472 |
if (Gear^.State and gstHHDriven) <> 0 then |
292 | 473 |
begin |
351 | 474 |
if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then |
475 |
DrawSprite(sprFinger, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 64 + WorldDy, |
|
292 | 476 |
GameTicks div 32 mod 16, Surface); |
542 | 477 |
if (Gear^.State and (gstMoving or gstDrowning)) = 0 then |
351 | 478 |
if (Gear^.State and gstHHThinking) <> 0 then |
479 |
DrawGear(sQuestion, hwRound(Gear^.X) - 10 + WorldDx, hwRound(Gear^.Y) - cHHRadius - 34 + WorldDy, Surface) |
|
292 | 480 |
else |
351 | 481 |
if ShowCrosshair and ((Gear^.State and gstAttacked) = 0) then |
482 |
DrawSurfSprite(Round(hwRound(Gear^.X) + hwSign(Gear^.dX) * Sin(Gear^.Angle*pi/cMaxAngle)*60) + WorldDx - 11, |
|
483 |
Round(hwRound(Gear^.Y) - Cos(Gear^.Angle*pi/cMaxAngle)*60) + WorldDy - 12, |
|
371 | 484 |
24, (18 + hwSign(Gear^.dX) * LongInt(((Gear^.Angle * 72 div cMaxAngle) + 1) div 2) mod 18) mod 18, |
351 | 485 |
Team^.CrosshairSurf, Surface); |
292 | 486 |
end; |
487 |
end; |
|
488 |
||
4 | 489 |
procedure DrawGears(Surface: PSDL_Surface); |
490 |
var Gear: PGear; |
|
491 |
i: Longword; |
|
371 | 492 |
roplen: LongInt; |
4 | 493 |
|
371 | 494 |
procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt); |
495 |
var eX, eY, dX, dY: LongInt; |
|
496 |
i, sX, sY, x, y, d: LongInt; |
|
366 | 497 |
b: boolean; |
4 | 498 |
begin |
37 | 499 |
if (X1 = X2) and (Y1 = Y2) then |
500 |
begin |
|
351 | 501 |
OutError('WARNING: zero length rope line!', false); |
37 | 502 |
exit |
503 |
end; |
|
366 | 504 |
eX:= 0; |
505 |
eY:= 0; |
|
506 |
dX:= X2 - X1; |
|
507 |
dY:= Y2 - Y1; |
|
508 |
||
509 |
if (dX > 0) then sX:= 1 |
|
510 |
else |
|
511 |
if (dX < 0) then |
|
512 |
begin |
|
513 |
sX:= -1; |
|
514 |
dX:= -dX |
|
515 |
end else sX:= dX; |
|
516 |
||
517 |
if (dY > 0) then sY:= 1 |
|
518 |
else |
|
519 |
if (dY < 0) then |
|
4 | 520 |
begin |
366 | 521 |
sY:= -1; |
522 |
dY:= -dY |
|
523 |
end else sY:= dY; |
|
524 |
||
525 |
if (dX > dY) then d:= dX |
|
526 |
else d:= dY; |
|
527 |
||
528 |
x:= X1; |
|
529 |
y:= Y1; |
|
530 |
||
531 |
for i:= 0 to d do |
|
532 |
begin |
|
533 |
inc(eX, dX); |
|
534 |
inc(eY, dY); |
|
535 |
b:= false; |
|
536 |
if (eX > d) then |
|
35 | 537 |
begin |
366 | 538 |
dec(eX, d); |
539 |
inc(x, sX); |
|
540 |
b:= true |
|
35 | 541 |
end; |
366 | 542 |
if (eY > d) then |
35 | 543 |
begin |
366 | 544 |
dec(eY, d); |
545 |
inc(y, sY); |
|
546 |
b:= true |
|
35 | 547 |
end; |
366 | 548 |
if b then |
549 |
begin |
|
550 |
inc(roplen); |
|
551 |
if (roplen mod 4) = 0 then DrawGear(sRopeNode, x - 2, y - 2, Surface) |
|
552 |
end |
|
4 | 553 |
end |
366 | 554 |
end; |
4 | 555 |
|
556 |
begin |
|
557 |
Gear:= GearsList; |
|
558 |
while Gear<>nil do |
|
559 |
begin |
|
351 | 560 |
case Gear^.Kind of |
561 |
gtCloud: DrawSprite(sprCloud , hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
|
562 |
gtAmmo_Bomb: DrawSprite(sprBomb , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
|
292 | 563 |
gtHedgehog: DrawHH(Gear, Surface); |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
366
diff
changeset
|
564 |
gtAmmo_Grenade: DrawSprite(sprGrenade , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
522 | 565 |
gtHealthTag, |
566 |
gtSmallDamage: if Gear^.Surf <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Surf, Surface); |
|
351 | 567 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear^.Hedgehog)^.Team^.GraveRect, hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
568 |
gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
4 | 569 |
gtRope: begin |
35 | 570 |
roplen:= 0; |
4 | 571 |
if RopePoints.Count > 0 then |
572 |
begin |
|
573 |
i:= 0; |
|
574 |
while i < Pred(RopePoints.Count) do |
|
575 |
begin |
|
351 | 576 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
577 |
hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
4 | 578 |
inc(i) |
579 |
end; |
|
351 | 580 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
581 |
hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy); |
|
582 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
|
583 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
584 |
DrawSprite(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx - 16, hwRound(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
|
4 | 585 |
end else |
35 | 586 |
begin |
351 | 587 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
588 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
366
diff
changeset
|
589 |
DrawSprite(sprRopeHook, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
35 | 590 |
end; |
4 | 591 |
end; |
568 | 592 |
gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
351 | 593 |
gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
594 |
gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420) |
|
595 |
then DrawSprite(sprMineOff , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface) |
|
596 |
else DrawSprite(sprMineOn , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
|
597 |
gtCase: case Gear^.Pos of |
|
598 |
posCaseAmmo : DrawSprite(sprCase, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0, Surface); |
|
599 |
posCaseHealth: DrawSprite(sprFAid, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
|
42 | 600 |
end; |
568 | 601 |
gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1, Surface); |
351 | 602 |
gtClusterBomb: DrawSprite(sprClusterBomb, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
603 |
gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0, Surface); |
|
604 |
gtFlame: DrawSprite(sprFlame, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy,(GameTicks div 128 + Gear^.Angle) mod 8, Surface); |
|
568 | 605 |
gtParachute: DrawSprite(sprParachute, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 48 + WorldDy, 0, Surface); |
408 | 606 |
gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 0, Surface) |
534 | 607 |
else DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 1, Surface); |
568 | 608 |
gtAirBomb: DrawSprite(sprAirBomb , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
534 | 609 |
gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, 0, Surface); |
4 | 610 |
end; |
351 | 611 |
Gear:= Gear^.NextGear |
4 | 612 |
end; |
613 |
end; |
|
614 |
||
615 |
procedure FreeGearsList; |
|
616 |
var t, tt: PGear; |
|
617 |
begin |
|
618 |
tt:= GearsList; |
|
619 |
GearsList:= nil; |
|
620 |
while tt<>nil do |
|
621 |
begin |
|
622 |
t:= tt; |
|
351 | 623 |
tt:= tt^.NextGear; |
4 | 624 |
Dispose(t) |
625 |
end; |
|
626 |
end; |
|
627 |
||
10 | 628 |
procedure AddMiscGears; |
371 | 629 |
var i: LongInt; |
4 | 630 |
begin |
498 | 631 |
AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000); |
22 | 632 |
if (GameFlags and gfForts) = 0 then |
633 |
for i:= 0 to 3 do |
|
498 | 634 |
FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048); |
4 | 635 |
end; |
636 |
||
293 | 637 |
procedure AddClouds; |
371 | 638 |
var i: LongInt; |
360 | 639 |
dx, dy: hwFloat; |
293 | 640 |
begin |
641 |
for i:= 0 to cCloudsNumber do |
|
360 | 642 |
begin |
643 |
dx.isNegative:= random(2) = 1; |
|
644 |
dx.QWordValue:= random(214748364); |
|
645 |
dy.isNegative:= (i and 1) = 1; |
|
646 |
dy.QWordValue:= 21474836 + random(64424509); |
|
647 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, |
|
648 |
gtCloud, random(4), dx, dy, 0) |
|
649 |
end |
|
293 | 650 |
end; |
651 |
||
371 | 652 |
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); |
4 | 653 |
var Gear: PGear; |
506 | 654 |
dmg, dmgRadius: LongInt; |
4 | 655 |
begin |
656 |
TargetPoint.X:= NoPointX; |
|
657 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
498 | 658 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0, _0, _0, 0); |
355 | 659 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false); |
506 | 660 |
if (Mask and EXPLAllDamageInRadius)=0 then dmgRadius:= Radius shl 1 |
661 |
else dmgRadius:= Radius; |
|
4 | 662 |
Gear:= GearsList; |
663 |
while Gear <> nil do |
|
664 |
begin |
|
506 | 665 |
dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
538 | 666 |
if (dmg > 1) and |
522 | 667 |
((Gear^.State and gstNoDamage) = 0) then |
4 | 668 |
begin |
355 | 669 |
dmg:= dmg div 2; |
351 | 670 |
case Gear^.Kind of |
10 | 671 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
672 |
gtMine, |
79 | 673 |
gtCase, |
674 |
gtFlame: begin |
|
355 | 675 |
{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF} |
522 | 676 |
if (Mask and EXPLNoDamage) = 0 then |
677 |
begin |
|
678 |
inc(Gear^.Damage, dmg); |
|
679 |
if Gear^.Kind = gtHedgehog then |
|
680 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear) |
|
681 |
end; |
|
351 | 682 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then |
42 | 683 |
begin |
506 | 684 |
DeleteCI(Gear); |
498 | 685 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - int2hwFloat(X)); |
686 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - int2hwFloat(Y)); |
|
503 | 687 |
Gear^.State:= Gear^.State or gstMoving; |
351 | 688 |
Gear^.Active:= true; |
42 | 689 |
FollowGear:= Gear |
690 |
end; |
|
4 | 691 |
end; |
51 | 692 |
gtGrave: begin |
351 | 693 |
Gear^.dY:= - _0_004 * dmg; |
694 |
Gear^.Active:= true; |
|
51 | 695 |
end; |
4 | 696 |
end; |
697 |
end; |
|
351 | 698 |
Gear:= Gear^.NextGear |
80 | 699 |
end; |
506 | 700 |
if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius); |
498 | 701 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
4 | 702 |
end; |
703 |
||
506 | 704 |
procedure ShotgunShot(Gear: PGear); |
705 |
var t: PGear; |
|
706 |
dmg: integer; |
|
522 | 707 |
hh: PHedgehog; |
506 | 708 |
begin |
509 | 709 |
Gear^.Radius:= cShotgunRadius; |
522 | 710 |
hh:= Gear^.Hedgehog; |
506 | 711 |
t:= GearsList; |
712 |
while t <> nil do |
|
713 |
begin |
|
714 |
dmg:= min(Gear^.Radius + t^.Radius - hwRound(Distance(Gear^.X - t^.X, Gear^.Y - t^.Y)), 25); |
|
538 | 715 |
if dmg > 0 then |
506 | 716 |
case t^.Kind of |
717 |
gtHedgehog, |
|
718 |
gtMine, |
|
719 |
gtCase: begin |
|
720 |
inc(t^.Damage, dmg); |
|
522 | 721 |
if t^.Kind = gtHedgehog then |
722 |
begin |
|
531 | 723 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, t); |
522 | 724 |
inc(hh^.DamageGiven, dmg) |
725 |
end; |
|
506 | 726 |
DeleteCI(t); |
727 |
t^.dX:= t^.dX + SignAs(Gear^.dX * dmg * _0_01 + cHHKick, t^.X - Gear^.X); |
|
728 |
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; |
|
729 |
t^.State:= t^.State or gstMoving; |
|
730 |
t^.Active:= true; |
|
731 |
FollowGear:= t |
|
732 |
end; |
|
733 |
gtGrave: begin |
|
734 |
t^.dY:= - _0_1; |
|
735 |
t^.Active:= true |
|
736 |
end; |
|
737 |
end; |
|
738 |
t:= t^.NextGear |
|
739 |
end; |
|
509 | 740 |
DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) |
506 | 741 |
end; |
742 |
||
371 | 743 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
53 | 744 |
var t: PGearArray; |
371 | 745 |
i: LongInt; |
307 | 746 |
hh: PHedgehog; |
38 | 747 |
begin |
53 | 748 |
t:= CheckGearsCollision(Ammo); |
351 | 749 |
i:= t^.Count; |
750 |
hh:= Ammo^.Hedgehog; |
|
53 | 751 |
while i > 0 do |
752 |
begin |
|
753 |
dec(i); |
|
351 | 754 |
if (t^.ar[i]^.State and gstNoDamage) = 0 then |
755 |
case t^.ar[i]^.Kind of |
|
53 | 756 |
gtHedgehog, |
757 |
gtMine, |
|
758 |
gtCase: begin |
|
351 | 759 |
inc(t^.ar[i]^.Damage, Damage); |
522 | 760 |
if t^.ar[i]^.Kind = gtHedgehog then |
761 |
begin |
|
762 |
AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]); |
|
763 |
inc(hh^.DamageGiven, Damage) |
|
764 |
end; |
|
538 | 765 |
DeleteCI(t^.ar[i]); |
351 | 766 |
t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01; |
767 |
t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01; |
|
768 |
t^.ar[i]^.Active:= true; |
|
503 | 769 |
t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving; |
351 | 770 |
FollowGear:= t^.ar[i] |
53 | 771 |
end; |
772 |
end |
|
126 | 773 |
end; |
774 |
SetAllToActive |
|
38 | 775 |
end; |
776 |
||
4 | 777 |
procedure AssignHHCoords; |
547 | 778 |
var i, t, p: LongInt; |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
779 |
ar: array[0..Pred(cMaxHHs)] of PGear; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
780 |
Count: Longword; |
4 | 781 |
begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
782 |
if (GameFlags and gfForts) <> 0 then |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
783 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
784 |
t:= 0; |
547 | 785 |
for p:= 0 to Pred(TeamsCount) do |
786 |
with TeamsArray[p]^ do |
|
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
787 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
788 |
for i:= 0 to cMaxHHIndex do |
547 | 789 |
with Hedgehogs[i] do |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
790 |
if Gear <> nil then FindPlace(Gear, false, t, t + 1024); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
791 |
inc(t, 1024); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
792 |
end |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
793 |
end else // mix hedgehogs |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
794 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
795 |
Count:= 0; |
547 | 796 |
for p:= 0 to Pred(TeamsCount) do |
797 |
with TeamsArray[p]^ do |
|
4 | 798 |
begin |
82 | 799 |
for i:= 0 to cMaxHHIndex do |
547 | 800 |
with Hedgehogs[i] do |
82 | 801 |
if Gear <> nil then |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
802 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
803 |
ar[Count]:= Gear; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
804 |
inc(Count) |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
805 |
end; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
806 |
end; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
807 |
|
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
808 |
while (Count > 0) do |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
809 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
810 |
i:= GetRandom(Count); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
811 |
FindPlace(ar[i], false, 0, 2048); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
812 |
ar[i]:= ar[Count - 1]; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
813 |
dec(Count) |
4 | 814 |
end |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
815 |
end |
4 | 816 |
end; |
817 |
||
371 | 818 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
10 | 819 |
var t: PGear; |
820 |
begin |
|
821 |
t:= GearsList; |
|
822 |
rX:= sqr(rX); |
|
823 |
rY:= sqr(rY); |
|
824 |
while t <> nil do |
|
825 |
begin |
|
351 | 826 |
if (t <> Gear) and (t^.Kind = Kind) then |
498 | 827 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
351 | 828 |
exit(t); |
829 |
t:= t^.NextGear |
|
10 | 830 |
end; |
351 | 831 |
CheckGearNear:= nil |
15 | 832 |
end; |
833 |
||
79 | 834 |
procedure AmmoFlameWork(Ammo: PGear); |
835 |
var t: PGear; |
|
836 |
begin |
|
837 |
t:= GearsList; |
|
838 |
while t <> nil do |
|
839 |
begin |
|
351 | 840 |
if (t^.Kind = gtHedgehog) and (t^.Y < Ammo^.Y) then |
498 | 841 |
if not (hwSqr(Ammo^.X - t^.X) + hwSqr(Ammo^.Y - t^.Y - int2hwFloat(cHHRadius)) * 2 > _2) then |
79 | 842 |
begin |
351 | 843 |
inc(t^.Damage, 5); |
844 |
t^.dX:= t^.dX + (t^.X - Ammo^.X) * _0_02; |
|
845 |
t^.dY:= - _0_25; |
|
846 |
t^.Active:= true; |
|
79 | 847 |
DeleteCI(t); |
848 |
FollowGear:= t |
|
849 |
end; |
|
351 | 850 |
t:= t^.NextGear |
79 | 851 |
end; |
852 |
end; |
|
853 |
||
371 | 854 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
16 | 855 |
var t: PGear; |
856 |
begin |
|
857 |
t:= GearsList; |
|
858 |
rX:= sqr(rX); |
|
859 |
rY:= sqr(rY); |
|
860 |
while t <> nil do |
|
861 |
begin |
|
351 | 862 |
if t^.Kind in Kind then |
498 | 863 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
351 | 864 |
exit(t); |
865 |
t:= t^.NextGear |
|
16 | 866 |
end; |
351 | 867 |
CheckGearsNear:= nil |
16 | 868 |
end; |
869 |
||
870 |
function CountGears(Kind: TGearType): Longword; |
|
871 |
var t: PGear; |
|
351 | 872 |
Result: Longword; |
16 | 873 |
begin |
874 |
Result:= 0; |
|
875 |
t:= GearsList; |
|
876 |
while t <> nil do |
|
877 |
begin |
|
351 | 878 |
if t^.Kind = Kind then inc(Result); |
879 |
t:= t^.NextGear |
|
16 | 880 |
end; |
351 | 881 |
CountGears:= Result |
16 | 882 |
end; |
883 |
||
15 | 884 |
procedure SpawnBoxOfSmth; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
885 |
var t: LongInt; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
886 |
i: TAmmoType; |
15 | 887 |
begin |
295 | 888 |
if (CountGears(gtCase) >= 5) or (getrandom(cCaseFactor) <> 0) then exit; |
498 | 889 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
295 | 890 |
case getrandom(2) of |
891 |
0: begin |
|
351 | 892 |
FollowGear^.Health:= 25; |
893 |
FollowGear^.Pos:= posCaseHealth |
|
295 | 894 |
end; |
895 |
1: begin |
|
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
896 |
t:= 0; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
897 |
for i:= Low(TAmmoType) to High(TAmmoType) do |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
898 |
inc(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
899 |
t:= GetRandom(t); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
900 |
i:= Low(TAmmoType); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
901 |
dec(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
902 |
while t >= 0 do |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
903 |
begin |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
904 |
inc(i); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
905 |
dec(t, Ammoz[i].Probability) |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
906 |
end; |
351 | 907 |
FollowGear^.Pos:= posCaseAmmo; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
908 |
FollowGear^.State:= Longword(i) |
295 | 909 |
end; |
910 |
end; |
|
70 | 911 |
FindPlace(FollowGear, true, 0, 2048) |
912 |
end; |
|
913 |
||
371 | 914 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); |
70 | 915 |
|
371 | 916 |
function CountNonZeroz(x, y, r: LongInt): LongInt; |
917 |
var i: LongInt; |
|
918 |
Result: LongInt; |
|
70 | 919 |
begin |
920 |
Result:= 0; |
|
921 |
if (y and $FFFFFC00) <> 0 then exit; |
|
922 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
351 | 923 |
if Land[y, i] <> 0 then inc(Result); |
924 |
CountNonZeroz:= Result |
|
70 | 925 |
end; |
926 |
||
495 | 927 |
var x: LongInt; |
371 | 928 |
y, sy: LongInt; |
386 | 929 |
ar: array[0..511] of TPoint; |
930 |
ar2: array[0..1023] of TPoint; |
|
392 | 931 |
cnt, cnt2: Longword; |
932 |
delta: LongInt; |
|
70 | 933 |
begin |
386 | 934 |
delta:= 250; |
935 |
cnt2:= 0; |
|
16 | 936 |
repeat |
392 | 937 |
x:= Left + LongInt(GetRandom(Delta)); |
70 | 938 |
repeat |
386 | 939 |
inc(x, Delta); |
70 | 940 |
cnt:= 0; |
351 | 941 |
y:= -Gear^.Radius * 2; |
70 | 942 |
while y < 1023 do |
16 | 943 |
begin |
70 | 944 |
repeat |
945 |
inc(y, 2); |
|
351 | 946 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0); |
70 | 947 |
sy:= y; |
948 |
repeat |
|
949 |
inc(y); |
|
351 | 950 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0); |
951 |
if (y - sy > Gear^.Radius * 2) |
|
70 | 952 |
and (y < 1023) |
351 | 953 |
and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
70 | 954 |
begin |
955 |
ar[cnt].X:= x; |
|
351 | 956 |
if withFall then ar[cnt].Y:= sy + Gear^.Radius |
957 |
else ar[cnt].Y:= y - Gear^.Radius; |
|
70 | 958 |
inc(cnt) |
959 |
end; |
|
386 | 960 |
inc(y, 45) |
16 | 961 |
end; |
70 | 962 |
if cnt > 0 then |
963 |
with ar[GetRandom(cnt)] do |
|
964 |
begin |
|
386 | 965 |
ar2[cnt2].x:= x; |
966 |
ar2[cnt2].y:= y; |
|
967 |
inc(cnt2) |
|
70 | 968 |
end |
386 | 969 |
until (x + Delta > Right); |
970 |
dec(Delta, 60) |
|
971 |
until (cnt2 > 0) or (Delta < 70); |
|
972 |
if cnt2 > 0 then |
|
973 |
with ar2[GetRandom(cnt2)] do |
|
974 |
begin |
|
498 | 975 |
Gear^.X:= int2hwFloat(x); |
976 |
Gear^.Y:= int2hwFloat(y); |
|
386 | 977 |
{$IFDEF DEBUGFILE} |
978 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
979 |
{$ENDIF} |
|
980 |
end |
|
981 |
else |
|
982 |
begin |
|
983 |
OutError('Can''t find place for Gear', false); |
|
984 |
DeleteGear(Gear) |
|
985 |
end |
|
10 | 986 |
end; |
987 |
||
4 | 988 |
initialization |
989 |
||
990 |
finalization |
|
95 | 991 |
FreeGearsList; |
4 | 992 |
|
993 |
end. |