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