author | unc0rr |
Wed, 06 Jun 2007 21:27:12 +0000 | |
changeset 538 | 74219eadab5e |
parent 534 | 92fb2b0d5117 |
child 539 | 6a9bf1852bbc |
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 |
538 | 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 |
538 | 460 |
if (Gear^.State and gstHHDriven) <> 0 then |
292 | 461 |
begin |
351 | 462 |
if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then |
463 |
DrawSprite(sprFinger, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 64 + WorldDy, |
|
292 | 464 |
GameTicks div 32 mod 16, Surface); |
351 | 465 |
if (Gear^.State and (gstMoving or gstDrowning or gstFalling)) = 0 then |
466 |
if (Gear^.State and gstHHThinking) <> 0 then |
|
467 |
DrawGear(sQuestion, hwRound(Gear^.X) - 10 + WorldDx, hwRound(Gear^.Y) - cHHRadius - 34 + WorldDy, Surface) |
|
292 | 468 |
else |
351 | 469 |
if ShowCrosshair and ((Gear^.State and gstAttacked) = 0) then |
470 |
DrawSurfSprite(Round(hwRound(Gear^.X) + hwSign(Gear^.dX) * Sin(Gear^.Angle*pi/cMaxAngle)*60) + WorldDx - 11, |
|
471 |
Round(hwRound(Gear^.Y) - Cos(Gear^.Angle*pi/cMaxAngle)*60) + WorldDy - 12, |
|
371 | 472 |
24, (18 + hwSign(Gear^.dX) * LongInt(((Gear^.Angle * 72 div cMaxAngle) + 1) div 2) mod 18) mod 18, |
351 | 473 |
Team^.CrosshairSurf, Surface); |
292 | 474 |
end; |
475 |
end; |
|
476 |
||
4 | 477 |
procedure DrawGears(Surface: PSDL_Surface); |
478 |
var Gear: PGear; |
|
479 |
i: Longword; |
|
371 | 480 |
roplen: LongInt; |
4 | 481 |
|
371 | 482 |
procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt); |
483 |
var eX, eY, dX, dY: LongInt; |
|
484 |
i, sX, sY, x, y, d: LongInt; |
|
366 | 485 |
b: boolean; |
4 | 486 |
begin |
37 | 487 |
if (X1 = X2) and (Y1 = Y2) then |
488 |
begin |
|
351 | 489 |
OutError('WARNING: zero length rope line!', false); |
37 | 490 |
exit |
491 |
end; |
|
366 | 492 |
eX:= 0; |
493 |
eY:= 0; |
|
494 |
dX:= X2 - X1; |
|
495 |
dY:= Y2 - Y1; |
|
496 |
||
497 |
if (dX > 0) then sX:= 1 |
|
498 |
else |
|
499 |
if (dX < 0) then |
|
500 |
begin |
|
501 |
sX:= -1; |
|
502 |
dX:= -dX |
|
503 |
end else sX:= dX; |
|
504 |
||
505 |
if (dY > 0) then sY:= 1 |
|
506 |
else |
|
507 |
if (dY < 0) then |
|
4 | 508 |
begin |
366 | 509 |
sY:= -1; |
510 |
dY:= -dY |
|
511 |
end else sY:= dY; |
|
512 |
||
513 |
if (dX > dY) then d:= dX |
|
514 |
else d:= dY; |
|
515 |
||
516 |
x:= X1; |
|
517 |
y:= Y1; |
|
518 |
||
519 |
for i:= 0 to d do |
|
520 |
begin |
|
521 |
inc(eX, dX); |
|
522 |
inc(eY, dY); |
|
523 |
b:= false; |
|
524 |
if (eX > d) then |
|
35 | 525 |
begin |
366 | 526 |
dec(eX, d); |
527 |
inc(x, sX); |
|
528 |
b:= true |
|
35 | 529 |
end; |
366 | 530 |
if (eY > d) then |
35 | 531 |
begin |
366 | 532 |
dec(eY, d); |
533 |
inc(y, sY); |
|
534 |
b:= true |
|
35 | 535 |
end; |
366 | 536 |
if b then |
537 |
begin |
|
538 |
inc(roplen); |
|
539 |
if (roplen mod 4) = 0 then DrawGear(sRopeNode, x - 2, y - 2, Surface) |
|
540 |
end |
|
4 | 541 |
end |
366 | 542 |
end; |
4 | 543 |
|
544 |
begin |
|
545 |
Gear:= GearsList; |
|
546 |
while Gear<>nil do |
|
547 |
begin |
|
351 | 548 |
case Gear^.Kind of |
549 |
gtCloud: DrawSprite(sprCloud , hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
|
550 |
gtAmmo_Bomb: DrawSprite(sprBomb , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
|
292 | 551 |
gtHedgehog: DrawHH(Gear, Surface); |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
366
diff
changeset
|
552 |
gtAmmo_Grenade: DrawSprite(sprGrenade , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
522 | 553 |
gtHealthTag, |
554 |
gtSmallDamage: if Gear^.Surf <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Surf, Surface); |
|
351 | 555 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear^.Hedgehog)^.Team^.GraveRect, hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
556 |
gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
557 |
gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
|
4 | 558 |
gtRope: begin |
35 | 559 |
roplen:= 0; |
4 | 560 |
if RopePoints.Count > 0 then |
561 |
begin |
|
562 |
i:= 0; |
|
563 |
while i < Pred(RopePoints.Count) do |
|
564 |
begin |
|
351 | 565 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
566 |
hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
4 | 567 |
inc(i) |
568 |
end; |
|
351 | 569 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
570 |
hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy); |
|
571 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
|
572 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
573 |
DrawSprite(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx - 16, hwRound(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
|
4 | 574 |
end else |
35 | 575 |
begin |
351 | 576 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
577 |
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
|
578 |
DrawSprite(sprRopeHook, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
35 | 579 |
end; |
4 | 580 |
end; |
351 | 581 |
gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
582 |
gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420) |
|
583 |
then DrawSprite(sprMineOff , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface) |
|
584 |
else DrawSprite(sprMineOn , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
|
585 |
gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1, Surface); |
|
586 |
gtCase: case Gear^.Pos of |
|
587 |
posCaseAmmo : DrawSprite(sprCase, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0, Surface); |
|
588 |
posCaseHealth: DrawSprite(sprFAid, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
|
42 | 589 |
end; |
351 | 590 |
gtClusterBomb: DrawSprite(sprClusterBomb, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface); |
591 |
gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0, Surface); |
|
592 |
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
|
593 |
gtAirBomb: DrawSprite(sprAirBomb , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface); |
408 | 594 |
gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 0, Surface) |
534 | 595 |
else DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 1, Surface); |
596 |
gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, 0, Surface); |
|
4 | 597 |
end; |
351 | 598 |
Gear:= Gear^.NextGear |
4 | 599 |
end; |
600 |
end; |
|
601 |
||
602 |
procedure FreeGearsList; |
|
603 |
var t, tt: PGear; |
|
604 |
begin |
|
605 |
tt:= GearsList; |
|
606 |
GearsList:= nil; |
|
607 |
while tt<>nil do |
|
608 |
begin |
|
609 |
t:= tt; |
|
351 | 610 |
tt:= tt^.NextGear; |
4 | 611 |
Dispose(t) |
612 |
end; |
|
613 |
end; |
|
614 |
||
10 | 615 |
procedure AddMiscGears; |
371 | 616 |
var i: LongInt; |
4 | 617 |
begin |
498 | 618 |
AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000); |
22 | 619 |
if (GameFlags and gfForts) = 0 then |
620 |
for i:= 0 to 3 do |
|
498 | 621 |
FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048); |
4 | 622 |
end; |
623 |
||
293 | 624 |
procedure AddClouds; |
371 | 625 |
var i: LongInt; |
360 | 626 |
dx, dy: hwFloat; |
293 | 627 |
begin |
628 |
for i:= 0 to cCloudsNumber do |
|
360 | 629 |
begin |
630 |
dx.isNegative:= random(2) = 1; |
|
631 |
dx.QWordValue:= random(214748364); |
|
632 |
dy.isNegative:= (i and 1) = 1; |
|
633 |
dy.QWordValue:= 21474836 + random(64424509); |
|
634 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, |
|
635 |
gtCloud, random(4), dx, dy, 0) |
|
636 |
end |
|
293 | 637 |
end; |
638 |
||
371 | 639 |
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); |
4 | 640 |
var Gear: PGear; |
506 | 641 |
dmg, dmgRadius: LongInt; |
4 | 642 |
begin |
643 |
TargetPoint.X:= NoPointX; |
|
644 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
498 | 645 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0, _0, _0, 0); |
355 | 646 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false); |
506 | 647 |
if (Mask and EXPLAllDamageInRadius)=0 then dmgRadius:= Radius shl 1 |
648 |
else dmgRadius:= Radius; |
|
4 | 649 |
Gear:= GearsList; |
650 |
while Gear <> nil do |
|
651 |
begin |
|
506 | 652 |
dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
538 | 653 |
if (dmg > 1) and |
522 | 654 |
((Gear^.State and gstNoDamage) = 0) then |
4 | 655 |
begin |
355 | 656 |
dmg:= dmg div 2; |
351 | 657 |
case Gear^.Kind of |
10 | 658 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
659 |
gtMine, |
79 | 660 |
gtCase, |
661 |
gtFlame: begin |
|
355 | 662 |
{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF} |
522 | 663 |
if (Mask and EXPLNoDamage) = 0 then |
664 |
begin |
|
665 |
inc(Gear^.Damage, dmg); |
|
666 |
if Gear^.Kind = gtHedgehog then |
|
667 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear) |
|
668 |
end; |
|
351 | 669 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then |
42 | 670 |
begin |
506 | 671 |
DeleteCI(Gear); |
498 | 672 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - int2hwFloat(X)); |
673 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - int2hwFloat(Y)); |
|
503 | 674 |
Gear^.State:= Gear^.State or gstMoving; |
351 | 675 |
Gear^.Active:= true; |
42 | 676 |
FollowGear:= Gear |
677 |
end; |
|
4 | 678 |
end; |
51 | 679 |
gtGrave: begin |
351 | 680 |
Gear^.dY:= - _0_004 * dmg; |
681 |
Gear^.Active:= true; |
|
51 | 682 |
end; |
4 | 683 |
end; |
684 |
end; |
|
351 | 685 |
Gear:= Gear^.NextGear |
80 | 686 |
end; |
506 | 687 |
if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius); |
498 | 688 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
4 | 689 |
end; |
690 |
||
506 | 691 |
procedure ShotgunShot(Gear: PGear); |
692 |
var t: PGear; |
|
693 |
dmg: integer; |
|
522 | 694 |
hh: PHedgehog; |
506 | 695 |
begin |
509 | 696 |
Gear^.Radius:= cShotgunRadius; |
522 | 697 |
hh:= Gear^.Hedgehog; |
506 | 698 |
t:= GearsList; |
699 |
while t <> nil do |
|
700 |
begin |
|
701 |
dmg:= min(Gear^.Radius + t^.Radius - hwRound(Distance(Gear^.X - t^.X, Gear^.Y - t^.Y)), 25); |
|
538 | 702 |
if dmg > 0 then |
506 | 703 |
case t^.Kind of |
704 |
gtHedgehog, |
|
705 |
gtMine, |
|
706 |
gtCase: begin |
|
707 |
inc(t^.Damage, dmg); |
|
522 | 708 |
if t^.Kind = gtHedgehog then |
709 |
begin |
|
531 | 710 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, t); |
522 | 711 |
inc(hh^.DamageGiven, dmg) |
712 |
end; |
|
506 | 713 |
DeleteCI(t); |
714 |
t^.dX:= t^.dX + SignAs(Gear^.dX * dmg * _0_01 + cHHKick, t^.X - Gear^.X); |
|
715 |
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; |
|
716 |
t^.State:= t^.State or gstMoving; |
|
717 |
t^.Active:= true; |
|
718 |
FollowGear:= t |
|
719 |
end; |
|
720 |
gtGrave: begin |
|
721 |
t^.dY:= - _0_1; |
|
722 |
t^.Active:= true |
|
723 |
end; |
|
724 |
end; |
|
725 |
t:= t^.NextGear |
|
726 |
end; |
|
509 | 727 |
DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) |
506 | 728 |
end; |
729 |
||
371 | 730 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
53 | 731 |
var t: PGearArray; |
371 | 732 |
i: LongInt; |
307 | 733 |
hh: PHedgehog; |
38 | 734 |
begin |
53 | 735 |
t:= CheckGearsCollision(Ammo); |
351 | 736 |
i:= t^.Count; |
737 |
hh:= Ammo^.Hedgehog; |
|
53 | 738 |
while i > 0 do |
739 |
begin |
|
740 |
dec(i); |
|
351 | 741 |
if (t^.ar[i]^.State and gstNoDamage) = 0 then |
742 |
case t^.ar[i]^.Kind of |
|
53 | 743 |
gtHedgehog, |
744 |
gtMine, |
|
745 |
gtCase: begin |
|
351 | 746 |
inc(t^.ar[i]^.Damage, Damage); |
522 | 747 |
if t^.ar[i]^.Kind = gtHedgehog then |
748 |
begin |
|
749 |
AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]); |
|
750 |
inc(hh^.DamageGiven, Damage) |
|
751 |
end; |
|
538 | 752 |
DeleteCI(t^.ar[i]); |
351 | 753 |
t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01; |
754 |
t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01; |
|
755 |
t^.ar[i]^.Active:= true; |
|
503 | 756 |
t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving; |
351 | 757 |
FollowGear:= t^.ar[i] |
53 | 758 |
end; |
759 |
end |
|
126 | 760 |
end; |
761 |
SetAllToActive |
|
38 | 762 |
end; |
763 |
||
4 | 764 |
procedure AssignHHCoords; |
82 | 765 |
var Team: PTeam; |
371 | 766 |
i, t: LongInt; |
4 | 767 |
begin |
82 | 768 |
Team:= TeamsList; |
769 |
t:= 0; |
|
770 |
while Team <> nil do |
|
4 | 771 |
begin |
82 | 772 |
for i:= 0 to cMaxHHIndex do |
351 | 773 |
with Team^.Hedgehogs[i] do |
82 | 774 |
if Gear <> nil then |
775 |
if (GameFlags and gfForts) = 0 then FindPlace(Gear, false, 0, 2048) |
|
776 |
else FindPlace(Gear, false, t, t + 1024); |
|
777 |
inc(t, 1024); |
|
351 | 778 |
Team:= Team^.Next |
4 | 779 |
end |
780 |
end; |
|
781 |
||
371 | 782 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
10 | 783 |
var t: PGear; |
784 |
begin |
|
785 |
t:= GearsList; |
|
786 |
rX:= sqr(rX); |
|
787 |
rY:= sqr(rY); |
|
788 |
while t <> nil do |
|
789 |
begin |
|
351 | 790 |
if (t <> Gear) and (t^.Kind = Kind) then |
498 | 791 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
351 | 792 |
exit(t); |
793 |
t:= t^.NextGear |
|
10 | 794 |
end; |
351 | 795 |
CheckGearNear:= nil |
15 | 796 |
end; |
797 |
||
79 | 798 |
procedure AmmoFlameWork(Ammo: PGear); |
799 |
var t: PGear; |
|
800 |
begin |
|
801 |
t:= GearsList; |
|
802 |
while t <> nil do |
|
803 |
begin |
|
351 | 804 |
if (t^.Kind = gtHedgehog) and (t^.Y < Ammo^.Y) then |
498 | 805 |
if not (hwSqr(Ammo^.X - t^.X) + hwSqr(Ammo^.Y - t^.Y - int2hwFloat(cHHRadius)) * 2 > _2) then |
79 | 806 |
begin |
351 | 807 |
inc(t^.Damage, 5); |
808 |
t^.dX:= t^.dX + (t^.X - Ammo^.X) * _0_02; |
|
809 |
t^.dY:= - _0_25; |
|
810 |
t^.Active:= true; |
|
79 | 811 |
DeleteCI(t); |
812 |
FollowGear:= t |
|
813 |
end; |
|
351 | 814 |
t:= t^.NextGear |
79 | 815 |
end; |
816 |
end; |
|
817 |
||
371 | 818 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
16 | 819 |
var t: PGear; |
820 |
begin |
|
821 |
t:= GearsList; |
|
822 |
rX:= sqr(rX); |
|
823 |
rY:= sqr(rY); |
|
824 |
while t <> nil do |
|
825 |
begin |
|
351 | 826 |
if t^.Kind in Kind then |
498 | 827 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
351 | 828 |
exit(t); |
829 |
t:= t^.NextGear |
|
16 | 830 |
end; |
351 | 831 |
CheckGearsNear:= nil |
16 | 832 |
end; |
833 |
||
834 |
function CountGears(Kind: TGearType): Longword; |
|
835 |
var t: PGear; |
|
351 | 836 |
Result: Longword; |
16 | 837 |
begin |
838 |
Result:= 0; |
|
839 |
t:= GearsList; |
|
840 |
while t <> nil do |
|
841 |
begin |
|
351 | 842 |
if t^.Kind = Kind then inc(Result); |
843 |
t:= t^.NextGear |
|
16 | 844 |
end; |
351 | 845 |
CountGears:= Result |
16 | 846 |
end; |
847 |
||
15 | 848 |
procedure SpawnBoxOfSmth; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
849 |
var t: LongInt; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
850 |
i: TAmmoType; |
15 | 851 |
begin |
295 | 852 |
if (CountGears(gtCase) >= 5) or (getrandom(cCaseFactor) <> 0) then exit; |
498 | 853 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
295 | 854 |
case getrandom(2) of |
855 |
0: begin |
|
351 | 856 |
FollowGear^.Health:= 25; |
857 |
FollowGear^.Pos:= posCaseHealth |
|
295 | 858 |
end; |
859 |
1: begin |
|
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
860 |
t:= 0; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
861 |
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
|
862 |
inc(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
863 |
t:= GetRandom(t); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
864 |
i:= Low(TAmmoType); |
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 |
while t >= 0 do |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
867 |
begin |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
868 |
inc(i); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
869 |
dec(t, Ammoz[i].Probability) |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
870 |
end; |
351 | 871 |
FollowGear^.Pos:= posCaseAmmo; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
872 |
FollowGear^.State:= Longword(i) |
295 | 873 |
end; |
874 |
end; |
|
70 | 875 |
FindPlace(FollowGear, true, 0, 2048) |
876 |
end; |
|
877 |
||
371 | 878 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); |
70 | 879 |
|
371 | 880 |
function CountNonZeroz(x, y, r: LongInt): LongInt; |
881 |
var i: LongInt; |
|
882 |
Result: LongInt; |
|
70 | 883 |
begin |
884 |
Result:= 0; |
|
885 |
if (y and $FFFFFC00) <> 0 then exit; |
|
886 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
351 | 887 |
if Land[y, i] <> 0 then inc(Result); |
888 |
CountNonZeroz:= Result |
|
70 | 889 |
end; |
890 |
||
495 | 891 |
var x: LongInt; |
371 | 892 |
y, sy: LongInt; |
386 | 893 |
ar: array[0..511] of TPoint; |
894 |
ar2: array[0..1023] of TPoint; |
|
392 | 895 |
cnt, cnt2: Longword; |
896 |
delta: LongInt; |
|
70 | 897 |
begin |
386 | 898 |
delta:= 250; |
899 |
cnt2:= 0; |
|
16 | 900 |
repeat |
392 | 901 |
x:= Left + LongInt(GetRandom(Delta)); |
70 | 902 |
repeat |
386 | 903 |
inc(x, Delta); |
70 | 904 |
cnt:= 0; |
351 | 905 |
y:= -Gear^.Radius * 2; |
70 | 906 |
while y < 1023 do |
16 | 907 |
begin |
70 | 908 |
repeat |
909 |
inc(y, 2); |
|
351 | 910 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0); |
70 | 911 |
sy:= y; |
912 |
repeat |
|
913 |
inc(y); |
|
351 | 914 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0); |
915 |
if (y - sy > Gear^.Radius * 2) |
|
70 | 916 |
and (y < 1023) |
351 | 917 |
and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
70 | 918 |
begin |
919 |
ar[cnt].X:= x; |
|
351 | 920 |
if withFall then ar[cnt].Y:= sy + Gear^.Radius |
921 |
else ar[cnt].Y:= y - Gear^.Radius; |
|
70 | 922 |
inc(cnt) |
923 |
end; |
|
386 | 924 |
inc(y, 45) |
16 | 925 |
end; |
70 | 926 |
if cnt > 0 then |
927 |
with ar[GetRandom(cnt)] do |
|
928 |
begin |
|
386 | 929 |
ar2[cnt2].x:= x; |
930 |
ar2[cnt2].y:= y; |
|
931 |
inc(cnt2) |
|
70 | 932 |
end |
386 | 933 |
until (x + Delta > Right); |
934 |
dec(Delta, 60) |
|
935 |
until (cnt2 > 0) or (Delta < 70); |
|
936 |
if cnt2 > 0 then |
|
937 |
with ar2[GetRandom(cnt2)] do |
|
938 |
begin |
|
498 | 939 |
Gear^.X:= int2hwFloat(x); |
940 |
Gear^.Y:= int2hwFloat(y); |
|
386 | 941 |
{$IFDEF DEBUGFILE} |
942 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
943 |
{$ENDIF} |
|
944 |
end |
|
945 |
else |
|
946 |
begin |
|
947 |
OutError('Can''t find place for Gear', false); |
|
948 |
DeleteGear(Gear) |
|
949 |
end |
|
10 | 950 |
end; |
951 |
||
4 | 952 |
initialization |
953 |
||
954 |
finalization |
|
95 | 955 |
FreeGearsList; |
4 | 956 |
|
957 |
end. |