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