author | unc0rr |
Thu, 07 Jun 2007 18:09:54 +0000 | |
changeset 539 | 6a9bf1852bbc |
parent 538 | 74219eadab5e |
child 540 | b06c5aace2fa |
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 |
351 | 281 |
Result^.Radius:= 10; |
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; |
|
4 | 291 |
end; |
351 | 292 |
InsertGearToList(Result); |
293 |
AddGear:= Result |
|
4 | 294 |
end; |
295 |
||
296 |
procedure DeleteGear(Gear: PGear); |
|
48 | 297 |
var team: PTeam; |
307 | 298 |
t: Longword; |
4 | 299 |
begin |
503 | 300 |
DeleteCI(Gear); |
522 | 301 |
if Gear^.Surf <> nil then |
302 |
begin |
|
303 |
SDL_FreeSurface(Gear^.Surf); |
|
304 |
Gear^.Surf:= nil |
|
305 |
end; |
|
351 | 306 |
if Gear^.Kind = gtHedgehog then |
4 | 307 |
if CurAmmoGear <> nil then |
308 |
begin |
|
351 | 309 |
Gear^.Message:= gm_Destroy; |
310 |
CurAmmoGear^.Message:= gm_Destroy; |
|
4 | 311 |
exit |
47 | 312 |
end else |
313 |
begin |
|
498 | 314 |
if not (hwRound(Gear^.Y) < cWaterLine) then |
307 | 315 |
begin |
351 | 316 |
t:= max(Gear^.Damage, Gear^.Health); |
498 | 317 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtHealthTag, t, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
307 | 318 |
inc(StepDamage, t) |
319 |
end; |
|
351 | 320 |
team:= PHedgehog(Gear^.Hedgehog)^.Team; |
321 |
if CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear = Gear then |
|
145 | 322 |
FreeActionsList; // to avoid ThinkThread on drawned gear |
351 | 323 |
PHedgehog(Gear^.Hedgehog)^.Gear:= nil; |
307 | 324 |
inc(KilledHHs); |
48 | 325 |
RecountTeamHealth(team); |
47 | 326 |
end; |
357 | 327 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear');{$ENDIF} |
82 | 328 |
if CurAmmoGear = Gear then CurAmmoGear:= nil; |
4 | 329 |
if FollowGear = Gear then FollowGear:= nil; |
294 | 330 |
RemoveGearFromList(Gear); |
4 | 331 |
Dispose(Gear) |
332 |
end; |
|
333 |
||
334 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
335 |
var Gear: PGear; |
|
336 |
begin |
|
351 | 337 |
CheckNoDamage:= true; |
4 | 338 |
Gear:= GearsList; |
339 |
while Gear <> nil do |
|
340 |
begin |
|
351 | 341 |
if Gear^.Kind = gtHedgehog then |
342 |
if Gear^.Damage <> 0 then |
|
4 | 343 |
begin |
351 | 344 |
CheckNoDamage:= false; |
345 |
inc(StepDamage, Gear^.Damage); |
|
346 |
if Gear^.Health < Gear^.Damage then Gear^.Health:= 0 |
|
522 | 347 |
else dec(Gear^.Health, Gear^.Damage); |
348 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12, |
|
498 | 349 |
gtHealthTag, Gear^.Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
351 | 350 |
RenderHealth(PHedgehog(Gear^.Hedgehog)^); |
351 |
RecountTeamHealth(PHedgehog(Gear^.Hedgehog)^.Team); |
|
352 |
||
353 |
Gear^.Damage:= 0 |
|
4 | 354 |
end; |
351 | 355 |
Gear:= Gear^.NextGear |
83 | 356 |
end; |
4 | 357 |
end; |
358 |
||
522 | 359 |
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); |
360 |
begin |
|
529 | 361 |
if cAltDamage then |
362 |
AddGear(X, Y, gtSmallDamage, Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
|
522 | 363 |
end; |
364 |
||
4 | 365 |
procedure ProcessGears; |
371 | 366 |
const delay: LongInt = cInactDelay; |
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
367 |
step: (stDelay, stChDmg, stChWin, stSpawn, stNTurn) = stDelay; |
4 | 368 |
var Gear, t: PGear; |
369 |
begin |
|
370 |
AllInactive:= true; |
|
371 |
t:= GearsList; |
|
372 |
while t<>nil do |
|
373 |
begin |
|
374 |
Gear:= t; |
|
351 | 375 |
t:= Gear^.NextGear; |
376 |
if Gear^.Active then Gear^.doStep(Gear); |
|
4 | 377 |
end; |
89 | 378 |
|
4 | 379 |
if AllInactive then |
15 | 380 |
case step of |
381 |
stDelay: begin |
|
382 |
dec(delay); |
|
383 |
if delay = 0 then |
|
384 |
begin |
|
385 |
inc(step); |
|
386 |
delay:= cInactDelay |
|
387 |
end |
|
388 |
end; |
|
389 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
351 | 390 |
stChWin: if not CheckForWin then inc(step) else step:= stDelay; |
15 | 391 |
stSpawn: begin |
392 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
393 |
inc(step) |
|
394 |
end; |
|
395 |
stNTurn: begin |
|
351 | 396 |
//AwareOfExplosion(0, 0, 0); |
15 | 397 |
if isInMultiShoot then isInMultiShoot:= false |
307 | 398 |
else begin |
351 | 399 |
with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do |
307 | 400 |
if MaxStepDamage < StepDamage then MaxStepDamage:= StepDamage; |
401 |
StepDamage:= 0; |
|
351 | 402 |
ParseCommand('/nextturn', true); |
307 | 403 |
end; |
15 | 404 |
step:= Low(step) |
405 |
end; |
|
406 |
end; |
|
407 |
||
4 | 408 |
if TurnTimeLeft > 0 then |
409 |
if CurrentTeam <> nil then |
|
351 | 410 |
if CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil then |
411 |
if ((CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.State and gstAttacking) = 0) |
|
4 | 412 |
and not isInMultiShoot then dec(TurnTimeLeft); |
351 | 413 |
|
515 | 414 |
inc(GameTicks) |
4 | 415 |
end; |
416 |
||
417 |
procedure SetAllToActive; |
|
418 |
var t: PGear; |
|
419 |
begin |
|
420 |
AllInactive:= false; |
|
421 |
t:= GearsList; |
|
351 | 422 |
while t <> nil do |
4 | 423 |
begin |
351 | 424 |
t^.Active:= true; |
425 |
t:= t^.NextGear |
|
4 | 426 |
end |
427 |
end; |
|
428 |
||
429 |
procedure SetAllHHToActive; |
|
430 |
var t: PGear; |
|
431 |
begin |
|
432 |
AllInactive:= false; |
|
433 |
t:= GearsList; |
|
351 | 434 |
while t <> nil do |
4 | 435 |
begin |
351 | 436 |
if t^.Kind = gtHedgehog then t^.Active:= true; |
437 |
t:= t^.NextGear |
|
4 | 438 |
end |
439 |
end; |
|
440 |
||
292 | 441 |
procedure DrawHH(Gear: PGear; Surface: PSDL_Surface); |
371 | 442 |
var t: LongInt; |
292 | 443 |
begin |
503 | 444 |
DrawHedgehog(hwRound(Gear^.X) - 15 + WorldDx, hwRound(Gear^.Y) - 18 + WorldDy, |
351 | 445 |
hwSign(Gear^.dX), 0, |
446 |
PHedgehog(Gear^.Hedgehog)^.visStepPos div 2, |
|
292 | 447 |
Surface); |
448 |
||
351 | 449 |
with PHedgehog(Gear^.Hedgehog)^ do |
538 | 450 |
if (Gear^.State{ and not gstAnimation}) = 0 then |
292 | 451 |
begin |
351 | 452 |
t:= hwRound(Gear^.Y) - cHHRadius - 10 + WorldDy; |
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
453 |
if (cTagsMask and 1) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
454 |
begin |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
455 |
dec(t, HealthTag^.h + 2); |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
456 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, HealthTag, Surface) |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
457 |
end; |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
458 |
if (cTagsMask and 2) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
459 |
begin |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
460 |
dec(t, NameTag^.h + 2); |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
461 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, NameTag, Surface) |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
462 |
end; |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
463 |
if (cTagsMask and 4) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
464 |
begin |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
465 |
dec(t, Team^.NameTag^.h + 2); |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
466 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTag, Surface) |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
467 |
end |
292 | 468 |
end else // Current hedgehog |
538 | 469 |
if (Gear^.State and gstHHDriven) <> 0 then |
292 | 470 |
begin |
351 | 471 |
if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then |
472 |
DrawSprite(sprFinger, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 64 + WorldDy, |
|
292 | 473 |
GameTicks div 32 mod 16, Surface); |
351 | 474 |
if (Gear^.State and (gstMoving or gstDrowning or gstFalling)) = 0 then |
475 |
if (Gear^.State and gstHHThinking) <> 0 then |
|
476 |
DrawGear(sQuestion, hwRound(Gear^.X) - 10 + WorldDx, hwRound(Gear^.Y) - cHHRadius - 34 + WorldDy, Surface) |
|
292 | 477 |
else |
351 | 478 |
if ShowCrosshair and ((Gear^.State and gstAttacked) = 0) then |
479 |
DrawSurfSprite(Round(hwRound(Gear^.X) + hwSign(Gear^.dX) * Sin(Gear^.Angle*pi/cMaxAngle)*60) + WorldDx - 11, |
|
480 |
Round(hwRound(Gear^.Y) - Cos(Gear^.Angle*pi/cMaxAngle)*60) + WorldDy - 12, |
|
371 | 481 |
24, (18 + hwSign(Gear^.dX) * LongInt(((Gear^.Angle * 72 div cMaxAngle) + 1) div 2) mod 18) mod 18, |
351 | 482 |
Team^.CrosshairSurf, Surface); |
292 | 483 |
end; |
484 |
end; |
|
485 |
||
4 | 486 |
procedure DrawGears(Surface: PSDL_Surface); |
487 |
var Gear: PGear; |
|
488 |
i: Longword; |
|
371 | 489 |
roplen: LongInt; |
4 | 490 |
|
371 | 491 |
procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt); |
492 |
var eX, eY, dX, dY: LongInt; |
|
493 |
i, sX, sY, x, y, d: LongInt; |
|
366 | 494 |
b: boolean; |
4 | 495 |
begin |
37 | 496 |
if (X1 = X2) and (Y1 = Y2) then |
497 |
begin |
|
351 | 498 |
OutError('WARNING: zero length rope line!', false); |
37 | 499 |
exit |
500 |
end; |
|
366 | 501 |
eX:= 0; |
502 |
eY:= 0; |
|
503 |
dX:= X2 - X1; |
|
504 |
dY:= Y2 - Y1; |
|
505 |
||
506 |
if (dX > 0) then sX:= 1 |
|
507 |
else |
|
508 |
if (dX < 0) then |
|
509 |
begin |
|
510 |
sX:= -1; |
|
511 |
dX:= -dX |
|
512 |
end else sX:= dX; |
|
513 |
||
514 |
if (dY > 0) then sY:= 1 |
|
515 |
else |
|
516 |
if (dY < 0) then |
|
4 | 517 |
begin |
366 | 518 |
sY:= -1; |
519 |
dY:= -dY |
|
520 |
end else sY:= dY; |
|
521 |
||
522 |
if (dX > dY) then d:= dX |
|
523 |
else d:= dY; |
|
524 |
||
525 |
x:= X1; |
|
526 |
y:= Y1; |
|
527 |
||
528 |
for i:= 0 to d do |
|
529 |
begin |
|
530 |
inc(eX, dX); |
|
531 |
inc(eY, dY); |
|
532 |
b:= false; |
|
533 |
if (eX > d) then |
|
35 | 534 |
begin |
366 | 535 |
dec(eX, d); |
536 |
inc(x, sX); |
|
537 |
b:= true |
|
35 | 538 |
end; |
366 | 539 |
if (eY > d) then |
35 | 540 |
begin |
366 | 541 |
dec(eY, d); |
542 |
inc(y, sY); |
|
543 |
b:= true |
|
35 | 544 |
end; |
366 | 545 |
if b then |
546 |
begin |
|
547 |
inc(roplen); |
|
548 |
if (roplen mod 4) = 0 then DrawGear(sRopeNode, x - 2, y - 2, Surface) |
|
549 |
end |
|
4 | 550 |
end |
366 | 551 |
end; |
4 | 552 |
|
553 |
begin |
|
554 |
Gear:= GearsList; |
|
555 |
while Gear<>nil do |
|
556 |
begin |
|
351 | 557 |
case Gear^.Kind of |
558 |
gtCloud: DrawSprite(sprCloud , hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
|
559 |
gtAmmo_Bomb: DrawSprite(sprBomb , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
|
292 | 560 |
gtHedgehog: DrawHH(Gear, Surface); |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
366
diff
changeset
|
561 |
gtAmmo_Grenade: DrawSprite(sprGrenade , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
522 | 562 |
gtHealthTag, |
563 |
gtSmallDamage: if Gear^.Surf <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Surf, Surface); |
|
351 | 564 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear^.Hedgehog)^.Team^.GraveRect, hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
565 |
gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
566 |
gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
|
4 | 567 |
gtRope: begin |
35 | 568 |
roplen:= 0; |
4 | 569 |
if RopePoints.Count > 0 then |
570 |
begin |
|
571 |
i:= 0; |
|
572 |
while i < Pred(RopePoints.Count) do |
|
573 |
begin |
|
351 | 574 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
575 |
hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
4 | 576 |
inc(i) |
577 |
end; |
|
351 | 578 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
579 |
hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy); |
|
580 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
|
581 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
582 |
DrawSprite(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx - 16, hwRound(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
|
4 | 583 |
end else |
35 | 584 |
begin |
351 | 585 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
586 |
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
|
587 |
DrawSprite(sprRopeHook, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
35 | 588 |
end; |
4 | 589 |
end; |
351 | 590 |
gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
591 |
gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420) |
|
592 |
then DrawSprite(sprMineOff , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface) |
|
593 |
else DrawSprite(sprMineOn , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
|
594 |
gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1, Surface); |
|
595 |
gtCase: case Gear^.Pos of |
|
596 |
posCaseAmmo : DrawSprite(sprCase, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0, Surface); |
|
597 |
posCaseHealth: DrawSprite(sprFAid, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
|
42 | 598 |
end; |
351 | 599 |
gtClusterBomb: DrawSprite(sprClusterBomb, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
600 |
gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0, Surface); |
|
601 |
gtFlame: DrawSprite(sprFlame, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy,(GameTicks div 128 + Gear^.Angle) mod 8, Surface); |
|
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
366
diff
changeset
|
602 |
gtAirBomb: DrawSprite(sprAirBomb , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
408 | 603 |
gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 0, Surface) |
534 | 604 |
else DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 1, Surface); |
605 |
gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, 0, Surface); |
|
4 | 606 |
end; |
351 | 607 |
Gear:= Gear^.NextGear |
4 | 608 |
end; |
609 |
end; |
|
610 |
||
611 |
procedure FreeGearsList; |
|
612 |
var t, tt: PGear; |
|
613 |
begin |
|
614 |
tt:= GearsList; |
|
615 |
GearsList:= nil; |
|
616 |
while tt<>nil do |
|
617 |
begin |
|
618 |
t:= tt; |
|
351 | 619 |
tt:= tt^.NextGear; |
4 | 620 |
Dispose(t) |
621 |
end; |
|
622 |
end; |
|
623 |
||
10 | 624 |
procedure AddMiscGears; |
371 | 625 |
var i: LongInt; |
4 | 626 |
begin |
498 | 627 |
AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000); |
22 | 628 |
if (GameFlags and gfForts) = 0 then |
629 |
for i:= 0 to 3 do |
|
498 | 630 |
FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048); |
4 | 631 |
end; |
632 |
||
293 | 633 |
procedure AddClouds; |
371 | 634 |
var i: LongInt; |
360 | 635 |
dx, dy: hwFloat; |
293 | 636 |
begin |
637 |
for i:= 0 to cCloudsNumber do |
|
360 | 638 |
begin |
639 |
dx.isNegative:= random(2) = 1; |
|
640 |
dx.QWordValue:= random(214748364); |
|
641 |
dy.isNegative:= (i and 1) = 1; |
|
642 |
dy.QWordValue:= 21474836 + random(64424509); |
|
643 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, |
|
644 |
gtCloud, random(4), dx, dy, 0) |
|
645 |
end |
|
293 | 646 |
end; |
647 |
||
371 | 648 |
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); |
4 | 649 |
var Gear: PGear; |
506 | 650 |
dmg, dmgRadius: LongInt; |
4 | 651 |
begin |
652 |
TargetPoint.X:= NoPointX; |
|
653 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
498 | 654 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0, _0, _0, 0); |
355 | 655 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false); |
506 | 656 |
if (Mask and EXPLAllDamageInRadius)=0 then dmgRadius:= Radius shl 1 |
657 |
else dmgRadius:= Radius; |
|
4 | 658 |
Gear:= GearsList; |
659 |
while Gear <> nil do |
|
660 |
begin |
|
506 | 661 |
dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
538 | 662 |
if (dmg > 1) and |
522 | 663 |
((Gear^.State and gstNoDamage) = 0) then |
4 | 664 |
begin |
355 | 665 |
dmg:= dmg div 2; |
351 | 666 |
case Gear^.Kind of |
10 | 667 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
668 |
gtMine, |
79 | 669 |
gtCase, |
670 |
gtFlame: begin |
|
355 | 671 |
{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF} |
522 | 672 |
if (Mask and EXPLNoDamage) = 0 then |
673 |
begin |
|
674 |
inc(Gear^.Damage, dmg); |
|
675 |
if Gear^.Kind = gtHedgehog then |
|
676 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear) |
|
677 |
end; |
|
351 | 678 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then |
42 | 679 |
begin |
506 | 680 |
DeleteCI(Gear); |
498 | 681 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - int2hwFloat(X)); |
682 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - int2hwFloat(Y)); |
|
503 | 683 |
Gear^.State:= Gear^.State or gstMoving; |
351 | 684 |
Gear^.Active:= true; |
42 | 685 |
FollowGear:= Gear |
686 |
end; |
|
4 | 687 |
end; |
51 | 688 |
gtGrave: begin |
351 | 689 |
Gear^.dY:= - _0_004 * dmg; |
690 |
Gear^.Active:= true; |
|
51 | 691 |
end; |
4 | 692 |
end; |
693 |
end; |
|
351 | 694 |
Gear:= Gear^.NextGear |
80 | 695 |
end; |
506 | 696 |
if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius); |
498 | 697 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
4 | 698 |
end; |
699 |
||
506 | 700 |
procedure ShotgunShot(Gear: PGear); |
701 |
var t: PGear; |
|
702 |
dmg: integer; |
|
522 | 703 |
hh: PHedgehog; |
506 | 704 |
begin |
509 | 705 |
Gear^.Radius:= cShotgunRadius; |
522 | 706 |
hh:= Gear^.Hedgehog; |
506 | 707 |
t:= GearsList; |
708 |
while t <> nil do |
|
709 |
begin |
|
710 |
dmg:= min(Gear^.Radius + t^.Radius - hwRound(Distance(Gear^.X - t^.X, Gear^.Y - t^.Y)), 25); |
|
538 | 711 |
if dmg > 0 then |
506 | 712 |
case t^.Kind of |
713 |
gtHedgehog, |
|
714 |
gtMine, |
|
715 |
gtCase: begin |
|
716 |
inc(t^.Damage, dmg); |
|
522 | 717 |
if t^.Kind = gtHedgehog then |
718 |
begin |
|
531 | 719 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, t); |
522 | 720 |
inc(hh^.DamageGiven, dmg) |
721 |
end; |
|
506 | 722 |
DeleteCI(t); |
723 |
t^.dX:= t^.dX + SignAs(Gear^.dX * dmg * _0_01 + cHHKick, t^.X - Gear^.X); |
|
724 |
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; |
|
725 |
t^.State:= t^.State or gstMoving; |
|
726 |
t^.Active:= true; |
|
727 |
FollowGear:= t |
|
728 |
end; |
|
729 |
gtGrave: begin |
|
730 |
t^.dY:= - _0_1; |
|
731 |
t^.Active:= true |
|
732 |
end; |
|
733 |
end; |
|
734 |
t:= t^.NextGear |
|
735 |
end; |
|
509 | 736 |
DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) |
506 | 737 |
end; |
738 |
||
371 | 739 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
53 | 740 |
var t: PGearArray; |
371 | 741 |
i: LongInt; |
307 | 742 |
hh: PHedgehog; |
38 | 743 |
begin |
53 | 744 |
t:= CheckGearsCollision(Ammo); |
351 | 745 |
i:= t^.Count; |
746 |
hh:= Ammo^.Hedgehog; |
|
53 | 747 |
while i > 0 do |
748 |
begin |
|
749 |
dec(i); |
|
351 | 750 |
if (t^.ar[i]^.State and gstNoDamage) = 0 then |
751 |
case t^.ar[i]^.Kind of |
|
53 | 752 |
gtHedgehog, |
753 |
gtMine, |
|
754 |
gtCase: begin |
|
351 | 755 |
inc(t^.ar[i]^.Damage, Damage); |
522 | 756 |
if t^.ar[i]^.Kind = gtHedgehog then |
757 |
begin |
|
758 |
AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]); |
|
759 |
inc(hh^.DamageGiven, Damage) |
|
760 |
end; |
|
538 | 761 |
DeleteCI(t^.ar[i]); |
351 | 762 |
t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01; |
763 |
t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01; |
|
764 |
t^.ar[i]^.Active:= true; |
|
503 | 765 |
t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving; |
351 | 766 |
FollowGear:= t^.ar[i] |
53 | 767 |
end; |
768 |
end |
|
126 | 769 |
end; |
770 |
SetAllToActive |
|
38 | 771 |
end; |
772 |
||
4 | 773 |
procedure AssignHHCoords; |
82 | 774 |
var Team: PTeam; |
371 | 775 |
i, t: LongInt; |
4 | 776 |
begin |
82 | 777 |
Team:= TeamsList; |
778 |
t:= 0; |
|
779 |
while Team <> nil do |
|
4 | 780 |
begin |
82 | 781 |
for i:= 0 to cMaxHHIndex do |
351 | 782 |
with Team^.Hedgehogs[i] do |
82 | 783 |
if Gear <> nil then |
784 |
if (GameFlags and gfForts) = 0 then FindPlace(Gear, false, 0, 2048) |
|
785 |
else FindPlace(Gear, false, t, t + 1024); |
|
786 |
inc(t, 1024); |
|
351 | 787 |
Team:= Team^.Next |
4 | 788 |
end |
789 |
end; |
|
790 |
||
371 | 791 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
10 | 792 |
var t: PGear; |
793 |
begin |
|
794 |
t:= GearsList; |
|
795 |
rX:= sqr(rX); |
|
796 |
rY:= sqr(rY); |
|
797 |
while t <> nil do |
|
798 |
begin |
|
351 | 799 |
if (t <> Gear) and (t^.Kind = Kind) then |
498 | 800 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
351 | 801 |
exit(t); |
802 |
t:= t^.NextGear |
|
10 | 803 |
end; |
351 | 804 |
CheckGearNear:= nil |
15 | 805 |
end; |
806 |
||
79 | 807 |
procedure AmmoFlameWork(Ammo: PGear); |
808 |
var t: PGear; |
|
809 |
begin |
|
810 |
t:= GearsList; |
|
811 |
while t <> nil do |
|
812 |
begin |
|
351 | 813 |
if (t^.Kind = gtHedgehog) and (t^.Y < Ammo^.Y) then |
498 | 814 |
if not (hwSqr(Ammo^.X - t^.X) + hwSqr(Ammo^.Y - t^.Y - int2hwFloat(cHHRadius)) * 2 > _2) then |
79 | 815 |
begin |
351 | 816 |
inc(t^.Damage, 5); |
817 |
t^.dX:= t^.dX + (t^.X - Ammo^.X) * _0_02; |
|
818 |
t^.dY:= - _0_25; |
|
819 |
t^.Active:= true; |
|
79 | 820 |
DeleteCI(t); |
821 |
FollowGear:= t |
|
822 |
end; |
|
351 | 823 |
t:= t^.NextGear |
79 | 824 |
end; |
825 |
end; |
|
826 |
||
371 | 827 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
16 | 828 |
var t: PGear; |
829 |
begin |
|
830 |
t:= GearsList; |
|
831 |
rX:= sqr(rX); |
|
832 |
rY:= sqr(rY); |
|
833 |
while t <> nil do |
|
834 |
begin |
|
351 | 835 |
if t^.Kind in Kind then |
498 | 836 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
351 | 837 |
exit(t); |
838 |
t:= t^.NextGear |
|
16 | 839 |
end; |
351 | 840 |
CheckGearsNear:= nil |
16 | 841 |
end; |
842 |
||
843 |
function CountGears(Kind: TGearType): Longword; |
|
844 |
var t: PGear; |
|
351 | 845 |
Result: Longword; |
16 | 846 |
begin |
847 |
Result:= 0; |
|
848 |
t:= GearsList; |
|
849 |
while t <> nil do |
|
850 |
begin |
|
351 | 851 |
if t^.Kind = Kind then inc(Result); |
852 |
t:= t^.NextGear |
|
16 | 853 |
end; |
351 | 854 |
CountGears:= Result |
16 | 855 |
end; |
856 |
||
15 | 857 |
procedure SpawnBoxOfSmth; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
858 |
var t: LongInt; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
859 |
i: TAmmoType; |
15 | 860 |
begin |
295 | 861 |
if (CountGears(gtCase) >= 5) or (getrandom(cCaseFactor) <> 0) then exit; |
498 | 862 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
295 | 863 |
case getrandom(2) of |
864 |
0: begin |
|
351 | 865 |
FollowGear^.Health:= 25; |
866 |
FollowGear^.Pos:= posCaseHealth |
|
295 | 867 |
end; |
868 |
1: begin |
|
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
869 |
t:= 0; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
870 |
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
|
871 |
inc(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
872 |
t:= GetRandom(t); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
873 |
i:= Low(TAmmoType); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
874 |
dec(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
875 |
while t >= 0 do |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
876 |
begin |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
877 |
inc(i); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
878 |
dec(t, Ammoz[i].Probability) |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
879 |
end; |
351 | 880 |
FollowGear^.Pos:= posCaseAmmo; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
881 |
FollowGear^.State:= Longword(i) |
295 | 882 |
end; |
883 |
end; |
|
70 | 884 |
FindPlace(FollowGear, true, 0, 2048) |
885 |
end; |
|
886 |
||
371 | 887 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); |
70 | 888 |
|
371 | 889 |
function CountNonZeroz(x, y, r: LongInt): LongInt; |
890 |
var i: LongInt; |
|
891 |
Result: LongInt; |
|
70 | 892 |
begin |
893 |
Result:= 0; |
|
894 |
if (y and $FFFFFC00) <> 0 then exit; |
|
895 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
351 | 896 |
if Land[y, i] <> 0 then inc(Result); |
897 |
CountNonZeroz:= Result |
|
70 | 898 |
end; |
899 |
||
495 | 900 |
var x: LongInt; |
371 | 901 |
y, sy: LongInt; |
386 | 902 |
ar: array[0..511] of TPoint; |
903 |
ar2: array[0..1023] of TPoint; |
|
392 | 904 |
cnt, cnt2: Longword; |
905 |
delta: LongInt; |
|
70 | 906 |
begin |
386 | 907 |
delta:= 250; |
908 |
cnt2:= 0; |
|
16 | 909 |
repeat |
392 | 910 |
x:= Left + LongInt(GetRandom(Delta)); |
70 | 911 |
repeat |
386 | 912 |
inc(x, Delta); |
70 | 913 |
cnt:= 0; |
351 | 914 |
y:= -Gear^.Radius * 2; |
70 | 915 |
while y < 1023 do |
16 | 916 |
begin |
70 | 917 |
repeat |
918 |
inc(y, 2); |
|
351 | 919 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0); |
70 | 920 |
sy:= y; |
921 |
repeat |
|
922 |
inc(y); |
|
351 | 923 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0); |
924 |
if (y - sy > Gear^.Radius * 2) |
|
70 | 925 |
and (y < 1023) |
351 | 926 |
and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
70 | 927 |
begin |
928 |
ar[cnt].X:= x; |
|
351 | 929 |
if withFall then ar[cnt].Y:= sy + Gear^.Radius |
930 |
else ar[cnt].Y:= y - Gear^.Radius; |
|
70 | 931 |
inc(cnt) |
932 |
end; |
|
386 | 933 |
inc(y, 45) |
16 | 934 |
end; |
70 | 935 |
if cnt > 0 then |
936 |
with ar[GetRandom(cnt)] do |
|
937 |
begin |
|
386 | 938 |
ar2[cnt2].x:= x; |
939 |
ar2[cnt2].y:= y; |
|
940 |
inc(cnt2) |
|
70 | 941 |
end |
386 | 942 |
until (x + Delta > Right); |
943 |
dec(Delta, 60) |
|
944 |
until (cnt2 > 0) or (Delta < 70); |
|
945 |
if cnt2 > 0 then |
|
946 |
with ar2[GetRandom(cnt2)] do |
|
947 |
begin |
|
498 | 948 |
Gear^.X:= int2hwFloat(x); |
949 |
Gear^.Y:= int2hwFloat(y); |
|
386 | 950 |
{$IFDEF DEBUGFILE} |
951 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
952 |
{$ENDIF} |
|
953 |
end |
|
954 |
else |
|
955 |
begin |
|
956 |
OutError('Can''t find place for Gear', false); |
|
957 |
DeleteGear(Gear) |
|
958 |
end |
|
10 | 959 |
end; |
960 |
||
4 | 961 |
initialization |
962 |
||
963 |
finalization |
|
95 | 964 |
FreeGearsList; |
4 | 965 |
|
966 |
end. |