author | unc0rr |
Wed, 24 Jan 2007 22:05:05 +0000 | |
changeset 364 | 52cb4d6f84b7 |
parent 360 | ab6a94334d6d |
child 366 | dc50b7933390 |
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; |
|
360 | 640 |
dx, dy: hwFloat; |
293 | 641 |
begin |
642 |
for i:= 0 to cCloudsNumber do |
|
360 | 643 |
begin |
644 |
dx.isNegative:= random(2) = 1; |
|
645 |
dx.QWordValue:= random(214748364); |
|
646 |
dy.isNegative:= (i and 1) = 1; |
|
647 |
dy.QWordValue:= 21474836 + random(64424509); |
|
648 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, |
|
649 |
gtCloud, random(4), dx, dy, 0) |
|
650 |
end |
|
293 | 651 |
end; |
652 |
||
4 | 653 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
654 |
var Gear: PGear; |
|
655 |
dmg: integer; |
|
656 |
begin |
|
657 |
TargetPoint.X:= NoPointX; |
|
658 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
305 | 659 |
if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius); |
351 | 660 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0, 0, 0, 0); |
355 | 661 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false); |
4 | 662 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
663 |
Gear:= GearsList; |
|
664 |
while Gear <> nil do |
|
665 |
begin |
|
351 | 666 |
dmg:= Radius - hwRound(Distance(Gear^.X - X, Gear^.Y - Y)); |
4 | 667 |
if dmg > 0 then |
668 |
begin |
|
355 | 669 |
dmg:= dmg div 2; |
351 | 670 |
case Gear^.Kind of |
10 | 671 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
672 |
gtMine, |
79 | 673 |
gtCase, |
674 |
gtFlame: begin |
|
355 | 675 |
{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF} |
351 | 676 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear^.Damage, dmg); |
677 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then |
|
42 | 678 |
begin |
355 | 679 |
Gear^.dX:= Gear^.dX + (_0_005 * dmg + cHHKick) * hwSign(Gear^.X - X); |
680 |
Gear^.dY:= Gear^.dY + (_0_005 * dmg + cHHKick) * hwSign(Gear^.Y - Y); |
|
351 | 681 |
Gear^.Active:= true; |
42 | 682 |
FollowGear:= Gear |
683 |
end; |
|
4 | 684 |
end; |
51 | 685 |
gtGrave: begin |
351 | 686 |
Gear^.dY:= - _0_004 * dmg; |
687 |
Gear^.Active:= true; |
|
51 | 688 |
end; |
4 | 689 |
end; |
690 |
end; |
|
351 | 691 |
Gear:= Gear^.NextGear |
80 | 692 |
end; |
351 | 693 |
//uAIMisc.AwareOfExplosion(0, 0, 0) |
4 | 694 |
end; |
695 |
||
75 | 696 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 697 |
var t: PGearArray; |
698 |
i: integer; |
|
307 | 699 |
hh: PHedgehog; |
38 | 700 |
begin |
53 | 701 |
t:= CheckGearsCollision(Ammo); |
351 | 702 |
i:= t^.Count; |
703 |
hh:= Ammo^.Hedgehog; |
|
53 | 704 |
while i > 0 do |
705 |
begin |
|
706 |
dec(i); |
|
351 | 707 |
if (t^.ar[i]^.State and gstNoDamage) = 0 then |
708 |
case t^.ar[i]^.Kind of |
|
53 | 709 |
gtHedgehog, |
710 |
gtMine, |
|
711 |
gtCase: begin |
|
351 | 712 |
inc(t^.ar[i]^.Damage, Damage); |
713 |
inc(hh^.DamageGiven, Damage); |
|
714 |
t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01; |
|
715 |
t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01; |
|
716 |
t^.ar[i]^.Active:= true; |
|
717 |
DeleteCI(t^.ar[i]); |
|
718 |
FollowGear:= t^.ar[i] |
|
53 | 719 |
end; |
720 |
end |
|
126 | 721 |
end; |
722 |
SetAllToActive |
|
38 | 723 |
end; |
724 |
||
4 | 725 |
procedure AssignHHCoords; |
82 | 726 |
var Team: PTeam; |
727 |
i, t: integer; |
|
4 | 728 |
begin |
82 | 729 |
Team:= TeamsList; |
730 |
t:= 0; |
|
731 |
while Team <> nil do |
|
4 | 732 |
begin |
82 | 733 |
for i:= 0 to cMaxHHIndex do |
351 | 734 |
with Team^.Hedgehogs[i] do |
82 | 735 |
if Gear <> nil then |
736 |
if (GameFlags and gfForts) = 0 then FindPlace(Gear, false, 0, 2048) |
|
737 |
else FindPlace(Gear, false, t, t + 1024); |
|
738 |
inc(t, 1024); |
|
351 | 739 |
Team:= Team^.Next |
4 | 740 |
end |
741 |
end; |
|
742 |
||
15 | 743 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; |
10 | 744 |
var t: PGear; |
745 |
begin |
|
746 |
t:= GearsList; |
|
747 |
rX:= sqr(rX); |
|
748 |
rY:= sqr(rY); |
|
749 |
while t <> nil do |
|
750 |
begin |
|
351 | 751 |
if (t <> Gear) and (t^.Kind = Kind) then |
752 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > 1) then |
|
753 |
exit(t); |
|
754 |
t:= t^.NextGear |
|
10 | 755 |
end; |
351 | 756 |
CheckGearNear:= nil |
15 | 757 |
end; |
758 |
||
79 | 759 |
procedure AmmoFlameWork(Ammo: PGear); |
760 |
var t: PGear; |
|
761 |
begin |
|
762 |
t:= GearsList; |
|
763 |
while t <> nil do |
|
764 |
begin |
|
351 | 765 |
if (t^.Kind = gtHedgehog) and (t^.Y < Ammo^.Y) then |
766 |
if not (hwSqr(Ammo^.X - t^.X) + hwSqr(Ammo^.Y - t^.Y - cHHRadius) * 2 > 2) then |
|
79 | 767 |
begin |
351 | 768 |
inc(t^.Damage, 5); |
769 |
t^.dX:= t^.dX + (t^.X - Ammo^.X) * _0_02; |
|
770 |
t^.dY:= - _0_25; |
|
771 |
t^.Active:= true; |
|
79 | 772 |
DeleteCI(t); |
773 |
FollowGear:= t |
|
774 |
end; |
|
351 | 775 |
t:= t^.NextGear |
79 | 776 |
end; |
777 |
end; |
|
778 |
||
16 | 779 |
function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear; |
780 |
var t: PGear; |
|
781 |
begin |
|
782 |
t:= GearsList; |
|
783 |
rX:= sqr(rX); |
|
784 |
rY:= sqr(rY); |
|
785 |
while t <> nil do |
|
786 |
begin |
|
351 | 787 |
if t^.Kind in Kind then |
788 |
if not (hwSqr(mX - t^.X) / rX + hwSqr(mY - t^.Y) / rY > 1) then |
|
789 |
exit(t); |
|
790 |
t:= t^.NextGear |
|
16 | 791 |
end; |
351 | 792 |
CheckGearsNear:= nil |
16 | 793 |
end; |
794 |
||
795 |
function CountGears(Kind: TGearType): Longword; |
|
796 |
var t: PGear; |
|
351 | 797 |
Result: Longword; |
16 | 798 |
begin |
799 |
Result:= 0; |
|
800 |
t:= GearsList; |
|
801 |
while t <> nil do |
|
802 |
begin |
|
351 | 803 |
if t^.Kind = Kind then inc(Result); |
804 |
t:= t^.NextGear |
|
16 | 805 |
end; |
351 | 806 |
CountGears:= Result |
16 | 807 |
end; |
808 |
||
15 | 809 |
procedure SpawnBoxOfSmth; |
810 |
begin |
|
295 | 811 |
if (CountGears(gtCase) >= 5) or (getrandom(cCaseFactor) <> 0) then exit; |
351 | 812 |
FollowGear:= AddGear(0, 0, gtCase, 0, 0, 0, 0); |
295 | 813 |
case getrandom(2) of |
814 |
0: begin |
|
351 | 815 |
FollowGear^.Health:= 25; |
816 |
FollowGear^.Pos:= posCaseHealth |
|
295 | 817 |
end; |
818 |
1: begin |
|
351 | 819 |
FollowGear^.Pos:= posCaseAmmo; |
820 |
FollowGear^.State:= Longword(amMineStrike) |
|
295 | 821 |
end; |
822 |
end; |
|
70 | 823 |
FindPlace(FollowGear, true, 0, 2048) |
824 |
end; |
|
825 |
||
826 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); |
|
827 |
||
828 |
function CountNonZeroz(x, y, r: integer): integer; |
|
829 |
var i: integer; |
|
351 | 830 |
Result: integer; |
70 | 831 |
begin |
832 |
Result:= 0; |
|
833 |
if (y and $FFFFFC00) <> 0 then exit; |
|
834 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
351 | 835 |
if Land[y, i] <> 0 then inc(Result); |
836 |
CountNonZeroz:= Result |
|
70 | 837 |
end; |
838 |
||
839 |
var fx, x: integer; |
|
840 |
y, sy: integer; |
|
841 |
ar: array[0..512] of TPoint; |
|
842 |
cnt, delta: Longword; |
|
843 |
begin |
|
844 |
fx:= Left + integer(GetRandom(Right - Left)); |
|
845 |
x:= fx; |
|
846 |
delta:= 130; |
|
16 | 847 |
repeat |
70 | 848 |
repeat |
351 | 849 |
inc(x, Gear^.Radius); |
70 | 850 |
if x > Right then x:= Left + (x mod (Right - left)); |
851 |
cnt:= 0; |
|
351 | 852 |
y:= -Gear^.Radius * 2; |
70 | 853 |
while y < 1023 do |
16 | 854 |
begin |
70 | 855 |
repeat |
856 |
inc(y, 2); |
|
351 | 857 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0); |
70 | 858 |
sy:= y; |
859 |
repeat |
|
860 |
inc(y); |
|
351 | 861 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0); |
862 |
if (y - sy > Gear^.Radius * 2) |
|
70 | 863 |
and (y < 1023) |
351 | 864 |
and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
70 | 865 |
begin |
866 |
ar[cnt].X:= x; |
|
351 | 867 |
if withFall then ar[cnt].Y:= sy + Gear^.Radius |
868 |
else ar[cnt].Y:= y - Gear^.Radius; |
|
70 | 869 |
inc(cnt) |
870 |
end; |
|
871 |
inc(y, 80) |
|
16 | 872 |
end; |
70 | 873 |
if cnt > 0 then |
874 |
with ar[GetRandom(cnt)] do |
|
875 |
begin |
|
351 | 876 |
Gear^.X:= x; |
877 |
Gear^.Y:= y; |
|
70 | 878 |
{$IFDEF DEBUGFILE} |
357 | 879 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
70 | 880 |
{$ENDIF} |
881 |
exit |
|
882 |
end |
|
351 | 883 |
until (x - Gear^.Radius < fx) and (x + Gear^.Radius > fx); |
70 | 884 |
dec(Delta, 20) |
885 |
until (Delta < 70); |
|
357 | 886 |
OutError('Couldn''t find place for Gear', false); |
70 | 887 |
DeleteGear(Gear) |
10 | 888 |
end; |
889 |
||
4 | 890 |
initialization |
891 |
||
892 |
finalization |
|
95 | 893 |
FreeGearsList; |
4 | 894 |
|
895 |
end. |