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