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