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