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