author | unc0rr |
Mon, 09 Jun 2008 20:34:45 +0000 | |
changeset 984 | dd5f16f69926 |
parent 982 | bbf382a5fe73 |
child 987 | 0fcd3fadda41 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
883 | 3 |
* Copyright (c) 2004-2008 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; |
|
868 | 24 |
PrvInactive: boolean = false; |
4 | 25 |
|
26 |
type PGear = ^TGear; |
|
27 |
TGearStepProcedure = procedure (Gear: PGear); |
|
28 |
TGear = record |
|
29 |
NextGear, PrevGear: PGear; |
|
30 |
Active: Boolean; |
|
930 | 31 |
Ammo : PAmmo; |
188 | 32 |
State : Longword; |
351 | 33 |
X : hwFloat; |
34 |
Y : hwFloat; |
|
35 |
dX: hwFloat; |
|
36 |
dY: hwFloat; |
|
42 | 37 |
Kind: TGearType; |
38 |
Pos: Longword; |
|
4 | 39 |
doStep: TGearStepProcedure; |
371 | 40 |
Radius: LongInt; |
188 | 41 |
Angle, Power : Longword; |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
42 |
DirAngle: real; |
4 | 43 |
Timer : LongWord; |
351 | 44 |
Elasticity: hwFloat; |
45 |
Friction : hwFloat; |
|
783 | 46 |
Message, MsgParam : Longword; |
4 | 47 |
Hedgehog: pointer; |
371 | 48 |
Health, Damage: LongInt; |
511 | 49 |
CollisionIndex: LongInt; |
371 | 50 |
Tag: LongInt; |
762 | 51 |
Tex: PTexture; |
293 | 52 |
Z: Longword; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
53 |
IntersectGear: PGear; |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
593
diff
changeset
|
54 |
TriggerId: Longword; |
4 | 55 |
end; |
56 |
||
371 | 57 |
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
4 | 58 |
procedure ProcessGears; |
59 |
procedure SetAllToActive; |
|
60 |
procedure SetAllHHToActive; |
|
956 | 61 |
procedure DrawGears; |
4 | 62 |
procedure FreeGearsList; |
10 | 63 |
procedure AddMiscGears; |
4 | 64 |
procedure AssignHHCoords; |
294 | 65 |
procedure InsertGearToList(Gear: PGear); |
66 |
procedure RemoveGearFromList(Gear: PGear); |
|
4 | 67 |
|
68 |
var CurAmmoGear: PGear = nil; |
|
68 | 69 |
GearsList: PGear = nil; |
307 | 70 |
KilledHHs: Longword = 0; |
70 | 71 |
|
4 | 72 |
implementation |
81 | 73 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, |
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset
|
74 |
uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers, GL, |
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset
|
75 |
uStats; |
789 | 76 |
|
77 |
const MAXROPEPOINTS = 300; |
|
68 | 78 |
var RopePoints: record |
4 | 79 |
Count: Longword; |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
80 |
HookAngle: GLfloat; |
789 | 81 |
ar: array[0..MAXROPEPOINTS] of record |
351 | 82 |
X, Y: hwFloat; |
83 |
dLen: hwFloat; |
|
4 | 84 |
b: boolean; |
85 |
end; |
|
86 |
end; |
|
87 |
||
88 |
procedure DeleteGear(Gear: PGear); forward; |
|
371 | 89 |
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward; |
90 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward; |
|
79 | 91 |
procedure AmmoFlameWork(Ammo: PGear); forward; |
371 | 92 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward; |
15 | 93 |
procedure SpawnBoxOfSmth; forward; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset
|
94 |
procedure AfterAttack; forward; |
371 | 95 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); forward; |
302 | 96 |
procedure HedgehogStep(Gear: PGear); forward; |
303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset
|
97 |
procedure HedgehogChAngle(Gear: PGear); forward; |
506 | 98 |
procedure ShotgunShot(Gear: PGear); forward; |
522 | 99 |
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); forward; |
4 | 100 |
|
101 |
{$INCLUDE GSHandlers.inc} |
|
102 |
{$INCLUDE HHHandlers.inc} |
|
103 |
||
104 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
351 | 105 |
@doStepBomb, |
106 |
@doStepHedgehog, |
|
107 |
@doStepGrenade, |
|
108 |
@doStepHealthTag, |
|
109 |
@doStepGrave, |
|
110 |
@doStepUFO, |
|
111 |
@doStepShotgunShot, |
|
112 |
@doStepPickHammer, |
|
113 |
@doStepRope, |
|
114 |
@doStepSmokeTrace, |
|
115 |
@doStepExplosion, |
|
116 |
@doStepMine, |
|
117 |
@doStepCase, |
|
118 |
@doStepDEagleShot, |
|
119 |
@doStepDynamite, |
|
120 |
@doStepTeamHealthSorter, |
|
121 |
@doStepBomb, |
|
122 |
@doStepCluster, |
|
123 |
@doStepShover, |
|
124 |
@doStepFlame, |
|
125 |
@doStepFirePunch, |
|
126 |
@doStepActionTimer, |
|
127 |
@doStepActionTimer, |
|
128 |
@doStepActionTimer, |
|
129 |
@doStepParachute, |
|
130 |
@doStepAirAttack, |
|
131 |
@doStepAirBomb, |
|
409 | 132 |
@doStepBlowTorch, |
520 | 133 |
@doStepGirder, |
522 | 134 |
@doStepTeleport, |
534 | 135 |
@doStepHealthTag, |
590 | 136 |
@doStepSwitcher, |
924 | 137 |
@doStepCase, |
925 | 138 |
@doStepMortar, |
984 | 139 |
@doStepWhip, |
140 |
@doStepKamikaze |
|
4 | 141 |
); |
142 |
||
294 | 143 |
procedure InsertGearToList(Gear: PGear); |
803 | 144 |
var tmp, ptmp: PGear; |
294 | 145 |
begin |
146 |
if GearsList = nil then |
|
147 |
GearsList:= Gear |
|
148 |
else begin |
|
149 |
tmp:= GearsList; |
|
803 | 150 |
ptmp:= GearsList; |
151 |
while (tmp <> nil) and (tmp^.Z <= Gear^.Z) do |
|
152 |
begin |
|
153 |
ptmp:= tmp; |
|
154 |
tmp:= tmp^.NextGear |
|
155 |
end; |
|
294 | 156 |
|
803 | 157 |
if ptmp <> nil then |
158 |
begin |
|
159 |
Gear^.NextGear:= ptmp^.NextGear; |
|
160 |
Gear^.PrevGear:= ptmp; |
|
161 |
if ptmp^.NextGear <> nil then ptmp^.NextGear^.PrevGear:= Gear; |
|
162 |
ptmp^.NextGear:= Gear |
|
163 |
end |
|
164 |
else GearsList:= Gear |
|
294 | 165 |
end |
166 |
end; |
|
167 |
||
168 |
procedure RemoveGearFromList(Gear: PGear); |
|
169 |
begin |
|
351 | 170 |
if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear; |
171 |
if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear |
|
809 | 172 |
else GearsList:= Gear^.NextGear |
294 | 173 |
end; |
174 |
||
371 | 175 |
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
79 | 176 |
const Counter: Longword = 0; |
351 | 177 |
var Result: PGear; |
4 | 178 |
begin |
79 | 179 |
inc(Counter); |
108 | 180 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF} |
4 | 181 |
New(Result); |
357 | 182 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: type = ' + inttostr(ord(Kind)));{$ENDIF} |
4 | 183 |
FillChar(Result^, sizeof(TGear), 0); |
498 | 184 |
Result^.X:= int2hwFloat(X); |
185 |
Result^.Y:= int2hwFloat(Y); |
|
351 | 186 |
Result^.Kind := Kind; |
187 |
Result^.State:= State; |
|
188 |
Result^.Active:= true; |
|
189 |
Result^.dX:= dX; |
|
190 |
Result^.dY:= dY; |
|
191 |
Result^.doStep:= doStepHandlers[Kind]; |
|
511 | 192 |
Result^.CollisionIndex:= -1; |
351 | 193 |
Result^.Timer:= Timer; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
194 |
|
4 | 195 |
if CurrentTeam <> nil then |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
196 |
begin |
602 | 197 |
Result^.Hedgehog:= CurrentHedgehog; |
198 |
Result^.IntersectGear:= CurrentHedgehog^.Gear |
|
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
199 |
end; |
802
ed5450a89b96
Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
789
diff
changeset
|
200 |
|
4 | 201 |
case Kind of |
915 | 202 |
gtAmmo_Bomb, |
203 |
gtClusterBomb: begin |
|
351 | 204 |
Result^.Radius:= 4; |
205 |
Result^.Elasticity:= _0_6; |
|
206 |
Result^.Friction:= _0_995; |
|
4 | 207 |
end; |
208 |
gtHedgehog: begin |
|
351 | 209 |
Result^.Radius:= cHHRadius; |
210 |
Result^.Elasticity:= _0_35; |
|
211 |
Result^.Friction:= _0_999; |
|
212 |
Result^.Angle:= cMaxAngle div 2; |
|
213 |
Result^.Z:= cHHZ; |
|
4 | 214 |
end; |
215 |
gtAmmo_Grenade: begin |
|
351 | 216 |
Result^.Radius:= 4; |
4 | 217 |
end; |
218 |
gtHealthTag: begin |
|
351 | 219 |
Result^.Timer:= 1500; |
522 | 220 |
Result^.Z:= 2001; |
4 | 221 |
end; |
222 |
gtGrave: begin |
|
351 | 223 |
Result^.Radius:= 10; |
224 |
Result^.Elasticity:= _0_6; |
|
4 | 225 |
end; |
226 |
gtUFO: begin |
|
351 | 227 |
Result^.Radius:= 5; |
228 |
Result^.Timer:= 500; |
|
229 |
Result^.Elasticity:= _0_9 |
|
4 | 230 |
end; |
231 |
gtShotgunShot: begin |
|
351 | 232 |
Result^.Timer:= 900; |
233 |
Result^.Radius:= 2 |
|
4 | 234 |
end; |
235 |
gtPickHammer: begin |
|
351 | 236 |
Result^.Radius:= 10; |
237 |
Result^.Timer:= 4000 |
|
4 | 238 |
end; |
239 |
gtSmokeTrace: begin |
|
498 | 240 |
Result^.X:= Result^.X - _16; |
241 |
Result^.Y:= Result^.Y - _16; |
|
351 | 242 |
Result^.State:= 8 |
4 | 243 |
end; |
244 |
gtRope: begin |
|
351 | 245 |
Result^.Radius:= 3; |
498 | 246 |
Result^.Friction:= _450; |
4 | 247 |
RopePoints.Count:= 0; |
248 |
end; |
|
9 | 249 |
gtExplosion: begin |
498 | 250 |
Result^.X:= Result^.X - _25; |
251 |
Result^.Y:= Result^.Y - _25; |
|
9 | 252 |
end; |
10 | 253 |
gtMine: begin |
503 | 254 |
Result^.State:= Result^.State or gstMoving; |
915 | 255 |
Result^.Radius:= 2; |
351 | 256 |
Result^.Elasticity:= _0_55; |
257 |
Result^.Friction:= _0_995; |
|
258 |
Result^.Timer:= 3000; |
|
10 | 259 |
end; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
260 |
gtCase: begin |
351 | 261 |
Result^.Radius:= 16; |
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
595
diff
changeset
|
262 |
Result^.Elasticity:= _0_3 |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
263 |
end; |
37 | 264 |
gtDEagleShot: begin |
351 | 265 |
Result^.Radius:= 1; |
266 |
Result^.Health:= 50 |
|
37 | 267 |
end; |
39 | 268 |
gtDynamite: begin |
351 | 269 |
Result^.Radius:= 3; |
270 |
Result^.Elasticity:= _0_55; |
|
271 |
Result^.Friction:= _0_03; |
|
272 |
Result^.Timer:= 5000; |
|
39 | 273 |
end; |
910 | 274 |
gtCluster: Result^.Radius:= 2; |
878 | 275 |
gtShover: Result^.Radius:= 20; |
79 | 276 |
gtFlame: begin |
351 | 277 |
Result^.Angle:= Counter mod 64; |
278 |
Result^.Radius:= 1; |
|
279 |
Result^.Health:= 2; |
|
280 |
Result^.dY:= (getrandom - _0_8) * _0_03; |
|
281 |
Result^.dX:= (getrandom - _0_5) * _0_4 |
|
79 | 282 |
end; |
82 | 283 |
gtFirePunch: begin |
351 | 284 |
Result^.Radius:= 15; |
285 |
Result^.Tag:= Y |
|
82 | 286 |
end; |
302 | 287 |
gtAirBomb: begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
288 |
Result^.Radius:= 5; |
302 | 289 |
end; |
290 |
gtBlowTorch: begin |
|
511 | 291 |
Result^.Radius:= cHHRadius + cBlowTorchC; |
351 | 292 |
Result^.Timer:= 7500; |
302 | 293 |
end; |
522 | 294 |
gtSmallDamage: begin |
295 |
Result^.Timer:= 1100; |
|
296 |
Result^.Z:= 2000; |
|
297 |
end; |
|
540 | 298 |
gtSwitcher: begin |
299 |
Result^.Z:= cCurrHHZ |
|
300 |
end; |
|
593 | 301 |
gtTarget: begin |
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
595
diff
changeset
|
302 |
Result^.Radius:= 16; |
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
595
diff
changeset
|
303 |
Result^.Elasticity:= _0_3 |
593 | 304 |
end; |
924 | 305 |
gtMortar: begin |
306 |
Result^.Elasticity:= _0_2; |
|
307 |
Result^.Friction:= _0_08 |
|
308 |
end; |
|
925 | 309 |
gtWhip: Result^.Radius:= 20; |
984 | 310 |
gtKamikaze: begin |
311 |
Result^.Health:= 2048; |
|
312 |
Result^.Radius:= 20 |
|
313 |
end; |
|
4 | 314 |
end; |
351 | 315 |
InsertGearToList(Result); |
316 |
AddGear:= Result |
|
4 | 317 |
end; |
318 |
||
319 |
procedure DeleteGear(Gear: PGear); |
|
48 | 320 |
var team: PTeam; |
307 | 321 |
t: Longword; |
4 | 322 |
begin |
503 | 323 |
DeleteCI(Gear); |
762 | 324 |
|
325 |
if Gear^.Tex <> nil then |
|
522 | 326 |
begin |
762 | 327 |
FreeTexture(Gear^.Tex); |
328 |
Gear^.Tex:= nil |
|
522 | 329 |
end; |
762 | 330 |
|
351 | 331 |
if Gear^.Kind = gtHedgehog then |
4 | 332 |
if CurAmmoGear <> nil then |
333 |
begin |
|
351 | 334 |
Gear^.Message:= gm_Destroy; |
335 |
CurAmmoGear^.Message:= gm_Destroy; |
|
4 | 336 |
exit |
47 | 337 |
end else |
338 |
begin |
|
498 | 339 |
if not (hwRound(Gear^.Y) < cWaterLine) then |
307 | 340 |
begin |
351 | 341 |
t:= max(Gear^.Damage, Gear^.Health); |
867 | 342 |
Gear^.Damage:= t; |
498 | 343 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtHealthTag, t, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
867 | 344 |
uStats.HedgehogDamaged(Gear) |
307 | 345 |
end; |
351 | 346 |
team:= PHedgehog(Gear^.Hedgehog)^.Team; |
602 | 347 |
if CurrentHedgehog^.Gear = Gear then |
145 | 348 |
FreeActionsList; // to avoid ThinkThread on drawned gear |
351 | 349 |
PHedgehog(Gear^.Hedgehog)^.Gear:= nil; |
307 | 350 |
inc(KilledHHs); |
48 | 351 |
RecountTeamHealth(team); |
47 | 352 |
end; |
357 | 353 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear');{$ENDIF} |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
593
diff
changeset
|
354 |
if Gear^.TriggerId <> 0 then TickTrigger(Gear^.TriggerId); |
82 | 355 |
if CurAmmoGear = Gear then CurAmmoGear:= nil; |
4 | 356 |
if FollowGear = Gear then FollowGear:= nil; |
294 | 357 |
RemoveGearFromList(Gear); |
4 | 358 |
Dispose(Gear) |
359 |
end; |
|
360 |
||
361 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
362 |
var Gear: PGear; |
|
363 |
begin |
|
351 | 364 |
CheckNoDamage:= true; |
4 | 365 |
Gear:= GearsList; |
366 |
while Gear <> nil do |
|
867 | 367 |
begin |
368 |
if Gear^.Kind = gtHedgehog then |
|
369 |
if Gear^.Damage <> 0 then |
|
370 |
begin |
|
371 |
CheckNoDamage:= false; |
|
372 |
uStats.HedgehogDamaged(Gear); |
|
351 | 373 |
|
867 | 374 |
if Gear^.Health < Gear^.Damage then |
375 |
Gear^.Health:= 0 |
|
376 |
else |
|
377 |
dec(Gear^.Health, Gear^.Damage); |
|
378 |
||
379 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12, |
|
380 |
gtHealthTag, Gear^.Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
|
381 |
RenderHealth(PHedgehog(Gear^.Hedgehog)^); |
|
382 |
RecountTeamHealth(PHedgehog(Gear^.Hedgehog)^.Team); |
|
383 |
||
384 |
Gear^.Damage:= 0 |
|
385 |
end; |
|
386 |
Gear:= Gear^.NextGear |
|
387 |
end; |
|
4 | 388 |
end; |
389 |
||
522 | 390 |
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); |
391 |
begin |
|
529 | 392 |
if cAltDamage then |
393 |
AddGear(X, Y, gtSmallDamage, Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
|
522 | 394 |
end; |
395 |
||
4 | 396 |
procedure ProcessGears; |
614 | 397 |
const delay: LongWord = 0; |
869 | 398 |
step: (stDelay, stChDmg, stTurnReact, |
399 |
stAfterDelay, stChWin, stSpawn, stNTurn) = stDelay; |
|
4 | 400 |
var Gear, t: PGear; |
401 |
begin |
|
868 | 402 |
PrvInactive:= AllInactive; |
4 | 403 |
AllInactive:= true; |
404 |
t:= GearsList; |
|
405 |
while t<>nil do |
|
406 |
begin |
|
407 |
Gear:= t; |
|
351 | 408 |
t:= Gear^.NextGear; |
409 |
if Gear^.Active then Gear^.doStep(Gear); |
|
4 | 410 |
end; |
89 | 411 |
|
4 | 412 |
if AllInactive then |
15 | 413 |
case step of |
414 |
stDelay: begin |
|
415 |
if delay = 0 then |
|
416 |
delay:= cInactDelay |
|
614 | 417 |
else |
418 |
dec(delay); |
|
419 |
||
420 |
if delay = 0 then |
|
421 |
inc(step) |
|
15 | 422 |
end; |
423 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset
|
424 |
stTurnReact: begin |
855
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset
|
425 |
if not isInMultiShoot then |
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset
|
426 |
begin |
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset
|
427 |
uStats.TurnReaction; |
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset
|
428 |
inc(step) |
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset
|
429 |
end else |
8842c71d16bf
- Fix too long delay between shotgun and deagle shots
unc0rr
parents:
854
diff
changeset
|
430 |
inc(step, 2); |
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset
|
431 |
end; |
815 | 432 |
stAfterDelay: begin |
433 |
if delay = 0 then |
|
434 |
delay:= cInactDelay |
|
435 |
else |
|
436 |
dec(delay); |
|
437 |
||
438 |
if delay = 0 then |
|
439 |
inc(step) |
|
440 |
end; |
|
869 | 441 |
stChWin: if not CheckForWin then inc(step) else step:= stDelay; |
15 | 442 |
stSpawn: begin |
443 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
444 |
inc(step) |
|
445 |
end; |
|
446 |
stNTurn: begin |
|
447 |
if isInMultiShoot then isInMultiShoot:= false |
|
307 | 448 |
else begin |
351 | 449 |
ParseCommand('/nextturn', true); |
307 | 450 |
end; |
15 | 451 |
step:= Low(step) |
452 |
end; |
|
453 |
end; |
|
454 |
||
4 | 455 |
if TurnTimeLeft > 0 then |
870 | 456 |
if CurrentHedgehog^.Gear <> nil then |
457 |
if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) |
|
458 |
and not isInMultiShoot then |
|
459 |
begin |
|
460 |
if (TurnTimeLeft = 5000) |
|
461 |
and (CurrentHedgehog^.Gear <> nil) |
|
462 |
and ((CurrentHedgehog^.Gear^.State and gstAttacked) = 0) then PlaySound(sndHurry, false); |
|
463 |
dec(TurnTimeLeft) |
|
464 |
end; |
|
351 | 465 |
|
651 | 466 |
if (not CurrentTeam^.ExtDriven) and |
917 | 467 |
((GameTicks and $FFFF) = $FFFF) then |
468 |
begin |
|
469 |
SendIPCTimeInc; |
|
470 |
inc(hiTicks) // we do not recieve a message for this |
|
471 |
end; |
|
656
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset
|
472 |
|
515 | 473 |
inc(GameTicks) |
4 | 474 |
end; |
475 |
||
476 |
procedure SetAllToActive; |
|
477 |
var t: PGear; |
|
478 |
begin |
|
479 |
AllInactive:= false; |
|
480 |
t:= GearsList; |
|
351 | 481 |
while t <> nil do |
4 | 482 |
begin |
351 | 483 |
t^.Active:= true; |
484 |
t:= t^.NextGear |
|
4 | 485 |
end |
486 |
end; |
|
487 |
||
488 |
procedure SetAllHHToActive; |
|
489 |
var t: PGear; |
|
490 |
begin |
|
491 |
AllInactive:= false; |
|
492 |
t:= GearsList; |
|
351 | 493 |
while t <> nil do |
4 | 494 |
begin |
351 | 495 |
if t^.Kind = gtHedgehog then t^.Active:= true; |
496 |
t:= t^.NextGear |
|
4 | 497 |
end |
498 |
end; |
|
499 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
500 |
procedure DrawHH(Gear: PGear); |
371 | 501 |
var t: LongInt; |
822 | 502 |
amt: TAmmoType; |
862 | 503 |
hx, hy, m: LongInt; |
504 |
aAngle, dAngle: real; |
|
824 | 505 |
defaultPos: boolean; |
292 | 506 |
begin |
868 | 507 |
if (Gear^.State and gstHHDeath) <> 0 then |
508 |
begin |
|
509 |
DrawSprite(sprHHDeath, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 26 + WorldDy, Gear^.Pos); |
|
510 |
exit |
|
511 |
end; |
|
824 | 512 |
defaultPos:= true; |
847 | 513 |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
815
diff
changeset
|
514 |
if (Gear^.State and gstHHDriven) <> 0 then |
966 | 515 |
begin |
516 |
hx:= hwRound(Gear^.X) + 1 + 8 * hwSign(Gear^.dX) + WorldDx; |
|
517 |
hy:= hwRound(Gear^.Y) - 2 + WorldDy; |
|
518 |
aangle:= Gear^.Angle * 180 / cMaxAngle - 90; |
|
874 | 519 |
|
966 | 520 |
if CurAmmoGear <> nil then |
521 |
begin |
|
522 |
case CurAmmoGear^.Kind of |
|
523 |
gtShotgunShot: if (CurAmmoGear^.State and gstAnimation <> 0) then |
|
524 |
DrawRotated(sprShotgun, hx, hy, hwSign(Gear^.dX), aangle) |
|
525 |
else |
|
526 |
DrawRotated(sprHandShotgun, hx, hy, hwSign(Gear^.dX), aangle); |
|
527 |
gtDEagleShot: DrawRotated(sprDEagle, hx, hy, hwSign(Gear^.dX), aangle); |
|
528 |
gtRope: begin |
|
529 |
if Gear^.X < CurAmmoGear^.X then |
|
530 |
begin |
|
531 |
dAngle:= 0; |
|
532 |
m:= 1 |
|
533 |
end else |
|
534 |
begin |
|
535 |
dAngle:= 180; |
|
536 |
m:= -1 |
|
537 |
end; |
|
538 |
DrawHedgehog(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
|
539 |
m, |
|
540 |
1, |
|
541 |
0, |
|
542 |
DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX) + dAngle); |
|
543 |
defaultPos:= false |
|
862 | 544 |
end; |
966 | 545 |
gtBlowTorch: begin |
546 |
DrawRotated(sprBlowTorch, hx, hy, hwSign(Gear^.dX), aangle); |
|
547 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
548 |
hwSign(Gear^.dX), |
|
549 |
1, |
|
550 |
3, |
|
551 |
0); |
|
552 |
defaultPos:= false |
|
553 |
end; |
|
554 |
gtShover: DrawRotated(sprHandBaseball, hx, hy, hwSign(Gear^.dX), aangle + 180); |
|
555 |
gtFirePunch: begin |
|
556 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
557 |
hwSign(Gear^.dX), |
|
558 |
1, |
|
559 |
4, |
|
560 |
0); |
|
561 |
defaultPos:= false |
|
562 |
end; |
|
563 |
gtPickHammer, |
|
564 |
gtTeleport: defaultPos:= false; |
|
565 |
end; |
|
876 | 566 |
|
966 | 567 |
case CurAmmoGear^.Kind of |
568 |
gtShotgunShot, |
|
569 |
gtDEagleShot, |
|
570 |
gtShover: begin |
|
571 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
572 |
hwSign(Gear^.dX), |
|
573 |
0, |
|
574 |
4, |
|
575 |
0); |
|
576 |
defaultPos:= false |
|
577 |
end |
|
876 | 578 |
end |
966 | 579 |
end else |
874 | 580 |
|
966 | 581 |
if ((Gear^.State and gstHHJumping) <> 0) then |
824 | 582 |
begin |
874 | 583 |
if ((Gear^.State and gstHHHJump) <> 0) then |
584 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
585 |
- hwSign(Gear^.dX), |
|
586 |
1, |
|
587 |
1, |
|
588 |
0) |
|
589 |
else |
|
590 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
591 |
hwSign(Gear^.dX), |
|
592 |
1, |
|
593 |
1, |
|
594 |
0); |
|
824 | 595 |
defaultPos:= false |
596 |
end else |
|
966 | 597 |
|
598 |
if (Gear^.Message and (gm_Left or gm_Right) <> 0) then |
|
599 |
begin |
|
822 | 600 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
601 |
hwSign(Gear^.dX), |
|
602 |
0, |
|
966 | 603 |
PHedgehog(Gear^.Hedgehog)^.visStepPos div 2, |
822 | 604 |
0); |
966 | 605 |
defaultPos:= false |
606 |
end |
|
607 |
else |
|
608 |
||
609 |
if ((Gear^.State and gstAttacked) = 0) then |
|
610 |
begin |
|
611 |
amt:= CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].AmmoType; |
|
612 |
case amt of |
|
613 |
amBazooka, |
|
614 |
amMortar: DrawRotated(sprHandBazooka, hx, hy, hwSign(Gear^.dX), aangle); |
|
615 |
amRope: DrawRotated(sprHandRope, hx, hy, hwSign(Gear^.dX), aangle); |
|
616 |
amShotgun: DrawRotated(sprHandShotgun, hx, hy, hwSign(Gear^.dX), aangle); |
|
617 |
amDEagle: DrawRotated(sprHandDEagle, hx, hy, hwSign(Gear^.dX), aangle); |
|
618 |
amBlowTorch: DrawRotated(sprHandBlowTorch, hx, hy, hwSign(Gear^.dX), aangle); |
|
619 |
end; |
|
620 |
||
621 |
case amt of |
|
622 |
amAirAttack, |
|
623 |
amMineStrike: DrawRotated(sprHandAirAttack, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) + WorldDy, hwSign(Gear^.dX), 0); |
|
624 |
amPickHammer: DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
625 |
hwSign(Gear^.dX), |
|
626 |
1, |
|
627 |
2, |
|
628 |
0); |
|
629 |
amBlowTorch: DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
630 |
hwSign(Gear^.dX), |
|
631 |
1, |
|
632 |
3, |
|
633 |
0); |
|
634 |
amTeleport: DrawRotatedF(sprTeleport, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, 0, hwSign(Gear^.dX), 0); |
|
635 |
else |
|
636 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
637 |
hwSign(Gear^.dX), |
|
638 |
0, |
|
639 |
4, |
|
640 |
0); |
|
641 |
end; |
|
642 |
||
643 |
case amt of |
|
644 |
amBaseballBat: DrawRotated(sprHandBaseball, |
|
645 |
hwRound(Gear^.X) + 1 - 4 * hwSign(Gear^.dX) + WorldDx, |
|
646 |
hwRound(Gear^.Y) + 6 + WorldDy, hwSign(Gear^.dX), aangle); |
|
647 |
end; |
|
648 |
||
649 |
defaultPos:= false |
|
650 |
end |
|
651 |
end else // not gstHHDriven |
|
652 |
if ((Gear^.State and gstHHJumping) <> 0) then |
|
653 |
begin |
|
654 |
if ((Gear^.State and gstHHHJump) <> 0) then |
|
655 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
656 |
- hwSign(Gear^.dX), |
|
657 |
1, |
|
658 |
1, |
|
659 |
0) |
|
660 |
else |
|
661 |
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, |
|
662 |
hwSign(Gear^.dX), |
|
663 |
1, |
|
664 |
1, |
|
665 |
0); |
|
666 |
defaultPos:= false |
|
834 | 667 |
end; |
668 |
||
824 | 669 |
|
845 | 670 |
if defaultPos then |
970 | 671 |
begin |
954 | 672 |
DrawRotatedF(sprHHIdle, |
673 |
hwRound(Gear^.X) + 1 + WorldDx, |
|
674 |
hwRound(Gear^.Y) - 3 + WorldDy, |
|
957 | 675 |
(RealTicks div 128 + Gear^.Pos) mod 19, |
822 | 676 |
hwSign(Gear^.dX), |
677 |
0); |
|
970 | 678 |
DrawRotatedF(sprHat, |
679 |
hwRound(Gear^.X) + 1 + WorldDx, |
|
680 |
hwRound(Gear^.Y) - 8 + WorldDy, |
|
681 |
(RealTicks div 128 + Gear^.Pos) mod 19, |
|
682 |
hwSign(Gear^.dX), |
|
683 |
0); |
|
684 |
end; |
|
292 | 685 |
|
351 | 686 |
with PHedgehog(Gear^.Hedgehog)^ do |
958 | 687 |
if (Gear^.State{ and not gstAnimation}) = 0 then |
688 |
begin |
|
976 | 689 |
t:= hwRound(Gear^.Y) - cHHRadius - 12 + WorldDy; |
958 | 690 |
if (cTagsMask and 1) <> 0 then |
691 |
begin |
|
692 |
dec(t, HealthTagTex^.h + 2); |
|
693 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, HealthTagTex) |
|
694 |
end; |
|
695 |
if (cTagsMask and 2) <> 0 then |
|
696 |
begin |
|
697 |
dec(t, NameTagTex^.h + 2); |
|
698 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, NameTagTex) |
|
699 |
end; |
|
700 |
if (cTagsMask and 4) <> 0 then |
|
701 |
begin |
|
702 |
dec(t, Team^.NameTagTex^.h + 2); |
|
703 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTagTex) |
|
704 |
end |
|
705 |
end else // Current hedgehog |
|
706 |
if (Gear^.State and gstHHDriven) <> 0 then |
|
707 |
begin |
|
708 |
if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then |
|
709 |
DrawSprite(sprFinger, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 64 + WorldDy, |
|
710 |
GameTicks div 32 mod 16); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
815
diff
changeset
|
711 |
|
958 | 712 |
if (Gear^.State and gstDrowning) = 0 then |
713 |
if (Gear^.State and gstHHThinking) <> 0 then |
|
714 |
DrawSprite(sprQuestion, hwRound(Gear^.X) - 10 + WorldDx, hwRound(Gear^.Y) - cHHRadius - 34 + WorldDy, 0) |
|
715 |
else |
|
716 |
if ShowCrosshair and ((Gear^.State and gstAttacked) = 0) then |
|
717 |
begin |
|
718 |
if ((Gear^.State and gstHHHJump) <> 0) then m:= -1 else m:= 1; |
|
719 |
DrawRotatedTex(Team^.CrosshairTex, |
|
720 |
12, 12, |
|
721 |
Round(hwRound(Gear^.X) + hwSign(Gear^.dX) * m * Sin(Gear^.Angle*pi/cMaxAngle) * 60) + WorldDx, |
|
722 |
Round(hwRound(Gear^.Y) - Cos(Gear^.Angle*pi/cMaxAngle) * 60) + WorldDy, 0, |
|
723 |
hwSign(Gear^.dX) * (Gear^.Angle * 180.0) / cMaxAngle) |
|
724 |
end |
|
725 |
end; |
|
292 | 726 |
end; |
727 |
||
956 | 728 |
procedure DrawGears; |
853 | 729 |
var Gear, HHGear: PGear; |
4 | 730 |
i: Longword; |
371 | 731 |
roplen: LongInt; |
4 | 732 |
|
371 | 733 |
procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt); |
734 |
var eX, eY, dX, dY: LongInt; |
|
735 |
i, sX, sY, x, y, d: LongInt; |
|
366 | 736 |
b: boolean; |
4 | 737 |
begin |
37 | 738 |
if (X1 = X2) and (Y1 = Y2) then |
739 |
begin |
|
351 | 740 |
OutError('WARNING: zero length rope line!', false); |
37 | 741 |
exit |
742 |
end; |
|
366 | 743 |
eX:= 0; |
744 |
eY:= 0; |
|
745 |
dX:= X2 - X1; |
|
746 |
dY:= Y2 - Y1; |
|
747 |
||
748 |
if (dX > 0) then sX:= 1 |
|
749 |
else |
|
750 |
if (dX < 0) then |
|
751 |
begin |
|
752 |
sX:= -1; |
|
753 |
dX:= -dX |
|
754 |
end else sX:= dX; |
|
755 |
||
756 |
if (dY > 0) then sY:= 1 |
|
757 |
else |
|
758 |
if (dY < 0) then |
|
4 | 759 |
begin |
366 | 760 |
sY:= -1; |
761 |
dY:= -dY |
|
762 |
end else sY:= dY; |
|
763 |
||
764 |
if (dX > dY) then d:= dX |
|
765 |
else d:= dY; |
|
766 |
||
767 |
x:= X1; |
|
768 |
y:= Y1; |
|
769 |
||
770 |
for i:= 0 to d do |
|
771 |
begin |
|
772 |
inc(eX, dX); |
|
773 |
inc(eY, dY); |
|
774 |
b:= false; |
|
775 |
if (eX > d) then |
|
35 | 776 |
begin |
366 | 777 |
dec(eX, d); |
778 |
inc(x, sX); |
|
779 |
b:= true |
|
35 | 780 |
end; |
366 | 781 |
if (eY > d) then |
35 | 782 |
begin |
366 | 783 |
dec(eY, d); |
784 |
inc(y, sY); |
|
785 |
b:= true |
|
35 | 786 |
end; |
366 | 787 |
if b then |
788 |
begin |
|
789 |
inc(roplen); |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
790 |
if (roplen mod 4) = 0 then DrawSprite(sprRopeNode, x - 2, y - 2, 0) |
366 | 791 |
end |
4 | 792 |
end |
366 | 793 |
end; |
4 | 794 |
|
795 |
begin |
|
796 |
Gear:= GearsList; |
|
797 |
while Gear<>nil do |
|
798 |
begin |
|
351 | 799 |
case Gear^.Kind of |
822 | 800 |
gtAmmo_Bomb: DrawRotated(sprBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
801 |
gtHedgehog: DrawHH(Gear); |
822 | 802 |
gtAmmo_Grenade: DrawRotated(sprGrenade, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); |
522 | 803 |
gtHealthTag, |
762 | 804 |
gtSmallDamage: if Gear^.Tex <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
805 |
gtGrave: DrawSurfSprite(hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, PHedgehog(Gear^.Hedgehog)^.Team^.GraveTex); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
806 |
gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4); |
848 | 807 |
gtPickHammer: DrawSprite(sprPHammer, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 50 + LongInt(((GameTicks shr 5) and 1) * 2) + WorldDy, 0); |
4 | 808 |
gtRope: begin |
35 | 809 |
roplen:= 0; |
4 | 810 |
if RopePoints.Count > 0 then |
811 |
begin |
|
812 |
i:= 0; |
|
813 |
while i < Pred(RopePoints.Count) do |
|
814 |
begin |
|
351 | 815 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
816 |
hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
4 | 817 |
inc(i) |
818 |
end; |
|
351 | 819 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
820 |
hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy); |
|
821 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
|
822 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
822 | 823 |
DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle) |
4 | 824 |
end else |
35 | 825 |
begin |
351 | 826 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
827 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
822 | 828 |
DrawRotated(sprRopeHook, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); |
35 | 829 |
end; |
4 | 830 |
end; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
831 |
gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
832 |
gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State); |
351 | 833 |
gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420) |
822 | 834 |
then DrawRotated(sprMineOff, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle) |
835 |
else DrawRotated(sprMineOn, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle); |
|
351 | 836 |
gtCase: case Gear^.Pos of |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
837 |
posCaseAmmo : DrawSprite(sprCase, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
838 |
posCaseHealth: DrawSprite(sprFAid, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13); |
42 | 839 |
end; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
840 |
gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1); |
822 | 841 |
gtClusterBomb: DrawRotated(sprClusterBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
842 |
gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
843 |
gtFlame: DrawSprite(sprFlame, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy,(GameTicks div 128 + Gear^.Angle) mod 8); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
844 |
gtParachute: DrawSprite(sprParachute, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 48 + WorldDy, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
845 |
gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 0) |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
846 |
else DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 1); |
822 | 847 |
gtAirBomb: DrawRotated(sprAirBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); |
853 | 848 |
gtTeleport: begin |
849 |
HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear; |
|
850 |
DrawRotatedF(sprTeleport, hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y) - 3 + WorldDy, Gear^.Pos, hwSign(HHGear^.dX), 0); |
|
851 |
DrawRotatedF(sprTeleport, hwRound(HHGear^.X) + 1 + WorldDx, hwRound(HHGear^.Y) - 3 + WorldDy, 11 - Gear^.Pos, hwSign(HHGear^.dX), 0); |
|
852 |
end; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
853 |
gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, (GameTicks shr 6) mod 12); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
854 |
gtTarget: DrawSprite(sprTarget, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0); |
959 | 855 |
gtMortar: DrawRotated(sprMortar, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); |
4 | 856 |
end; |
351 | 857 |
Gear:= Gear^.NextGear |
4 | 858 |
end; |
859 |
end; |
|
860 |
||
861 |
procedure FreeGearsList; |
|
862 |
var t, tt: PGear; |
|
863 |
begin |
|
864 |
tt:= GearsList; |
|
865 |
GearsList:= nil; |
|
866 |
while tt<>nil do |
|
867 |
begin |
|
868 |
t:= tt; |
|
351 | 869 |
tt:= tt^.NextGear; |
4 | 870 |
Dispose(t) |
871 |
end; |
|
872 |
end; |
|
873 |
||
10 | 874 |
procedure AddMiscGears; |
371 | 875 |
var i: LongInt; |
4 | 876 |
begin |
498 | 877 |
AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000); |
22 | 878 |
if (GameFlags and gfForts) = 0 then |
622 | 879 |
for i:= 0 to Pred(cLandAdditions) do |
498 | 880 |
FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048); |
4 | 881 |
end; |
882 |
||
371 | 883 |
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); |
4 | 884 |
var Gear: PGear; |
506 | 885 |
dmg, dmgRadius: LongInt; |
4 | 886 |
begin |
887 |
TargetPoint.X:= NoPointX; |
|
888 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
498 | 889 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0, _0, _0, 0); |
355 | 890 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false); |
506 | 891 |
if (Mask and EXPLAllDamageInRadius)=0 then dmgRadius:= Radius shl 1 |
892 |
else dmgRadius:= Radius; |
|
4 | 893 |
Gear:= GearsList; |
894 |
while Gear <> nil do |
|
895 |
begin |
|
506 | 896 |
dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
538 | 897 |
if (dmg > 1) and |
522 | 898 |
((Gear^.State and gstNoDamage) = 0) then |
4 | 899 |
begin |
355 | 900 |
dmg:= dmg div 2; |
351 | 901 |
case Gear^.Kind of |
10 | 902 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
903 |
gtMine, |
79 | 904 |
gtCase, |
593 | 905 |
gtTarget, |
79 | 906 |
gtFlame: begin |
355 | 907 |
{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF} |
522 | 908 |
if (Mask and EXPLNoDamage) = 0 then |
909 |
begin |
|
910 |
inc(Gear^.Damage, dmg); |
|
911 |
if Gear^.Kind = gtHedgehog then |
|
912 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear) |
|
913 |
end; |
|
351 | 914 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then |
42 | 915 |
begin |
506 | 916 |
DeleteCI(Gear); |
498 | 917 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - int2hwFloat(X)); |
918 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - int2hwFloat(Y)); |
|
503 | 919 |
Gear^.State:= Gear^.State or gstMoving; |
351 | 920 |
Gear^.Active:= true; |
42 | 921 |
FollowGear:= Gear |
922 |
end; |
|
4 | 923 |
end; |
51 | 924 |
gtGrave: begin |
351 | 925 |
Gear^.dY:= - _0_004 * dmg; |
926 |
Gear^.Active:= true; |
|
51 | 927 |
end; |
4 | 928 |
end; |
929 |
end; |
|
351 | 930 |
Gear:= Gear^.NextGear |
80 | 931 |
end; |
621 | 932 |
if (Mask and EXPLDontDraw) = 0 then |
933 |
if (GameFlags and gfSolidLand) = 0 then DrawExplosion(X, Y, Radius); |
|
498 | 934 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
4 | 935 |
end; |
936 |
||
506 | 937 |
procedure ShotgunShot(Gear: PGear); |
938 |
var t: PGear; |
|
955 | 939 |
dmg: LongInt; |
506 | 940 |
begin |
509 | 941 |
Gear^.Radius:= cShotgunRadius; |
506 | 942 |
t:= GearsList; |
943 |
while t <> nil do |
|
944 |
begin |
|
945 |
dmg:= min(Gear^.Radius + t^.Radius - hwRound(Distance(Gear^.X - t^.X, Gear^.Y - t^.Y)), 25); |
|
538 | 946 |
if dmg > 0 then |
506 | 947 |
case t^.Kind of |
948 |
gtHedgehog, |
|
949 |
gtMine, |
|
593 | 950 |
gtCase, |
951 |
gtTarget: begin |
|
506 | 952 |
inc(t^.Damage, dmg); |
867 | 953 |
|
522 | 954 |
if t^.Kind = gtHedgehog then |
531 | 955 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, t); |
867 | 956 |
|
506 | 957 |
DeleteCI(t); |
856 | 958 |
t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX); |
506 | 959 |
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; |
960 |
t^.State:= t^.State or gstMoving; |
|
961 |
t^.Active:= true; |
|
962 |
FollowGear:= t |
|
963 |
end; |
|
964 |
gtGrave: begin |
|
965 |
t^.dY:= - _0_1; |
|
966 |
t^.Active:= true |
|
967 |
end; |
|
968 |
end; |
|
969 |
t:= t^.NextGear |
|
970 |
end; |
|
621 | 971 |
if (GameFlags and gfSolidLand) = 0 then DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) |
506 | 972 |
end; |
973 |
||
371 | 974 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
53 | 975 |
var t: PGearArray; |
371 | 976 |
i: LongInt; |
38 | 977 |
begin |
53 | 978 |
t:= CheckGearsCollision(Ammo); |
351 | 979 |
i:= t^.Count; |
53 | 980 |
while i > 0 do |
981 | 981 |
begin |
982 |
dec(i); |
|
983 |
if (t^.ar[i]^.State and gstNoDamage) = 0 then |
|
984 |
case t^.ar[i]^.Kind of |
|
985 |
gtHedgehog, |
|
986 |
gtMine, |
|
987 |
gtTarget, |
|
988 |
gtCase: begin |
|
989 |
inc(t^.ar[i]^.Damage, Damage); |
|
990 |
||
991 |
if t^.ar[i]^.Kind = gtHedgehog then |
|
992 |
AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]); |
|
867 | 993 |
|
981 | 994 |
DeleteCI(t^.ar[i]); |
995 |
t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01; |
|
996 |
t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01; |
|
997 |
t^.ar[i]^.Active:= true; |
|
998 |
t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving; |
|
867 | 999 |
|
982 | 1000 |
if TestCollisionXwithGear(t^.ar[i], hwSign(t^.ar[i]^.dX)) then |
981 | 1001 |
begin |
1002 |
if not (TestCollisionXwithXYShift(t^.ar[i], _0, -3, hwSign(t^.ar[i]^.dX)) |
|
1003 |
or TestCollisionYwithGear(t^.ar[i], -1)) then t^.ar[i]^.Y:= t^.ar[i]^.Y - _1; |
|
1004 |
if not (TestCollisionXwithXYShift(t^.ar[i], _0, -2, hwSign(t^.ar[i]^.dX)) |
|
1005 |
or TestCollisionYwithGear(t^.ar[i], -1)) then t^.ar[i]^.Y:= t^.ar[i]^.Y - _1; |
|
1006 |
if not (TestCollisionXwithXYShift(t^.ar[i], _0, -1, hwSign(t^.ar[i]^.dX)) |
|
1007 |
or TestCollisionYwithGear(t^.ar[i], -1)) then t^.ar[i]^.Y:= t^.ar[i]^.Y - _1; |
|
1008 |
end; |
|
982 | 1009 |
|
981 | 1010 |
FollowGear:= t^.ar[i] |
1011 |
end; |
|
1012 |
end |
|
1013 |
end; |
|
126 | 1014 |
SetAllToActive |
38 | 1015 |
end; |
1016 |
||
4 | 1017 |
procedure AssignHHCoords; |
955 | 1018 |
var i, t, p, j: LongInt; |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
1019 |
ar: array[0..Pred(cMaxHHs)] of PGear; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
1020 |
Count: Longword; |
4 | 1021 |
begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
1022 |
if (GameFlags and gfForts) <> 0 then |
955 | 1023 |
begin |
1024 |
t:= 0; |
|
1025 |
for p:= 0 to 1 do |
|
1026 |
begin |
|
1027 |
with ClansArray[p]^ do |
|
1028 |
for j:= 0 to Pred(TeamsNumber) do |
|
1029 |
with Teams[j]^ do |
|
1030 |
for i:= 0 to cMaxHHIndex do |
|
1031 |
with Hedgehogs[i] do |
|
958 | 1032 |
if (Gear <> nil) and (Gear^.X.QWordValue = 0) then |
1033 |
begin |
|
1034 |
FindPlace(Gear, false, t, t + 1024); |
|
959 | 1035 |
Gear^.Pos:= GetRandom(19) |
958 | 1036 |
end; |
955 | 1037 |
inc(t, 1024) |
1038 |
end |
|
1039 |
end else // mix hedgehogs |
|
1040 |
begin |
|
1041 |
Count:= 0; |
|
1042 |
for p:= 0 to Pred(TeamsCount) do |
|
1043 |
with TeamsArray[p]^ do |
|
1044 |
begin |
|
1045 |
for i:= 0 to cMaxHHIndex do |
|
1046 |
with Hedgehogs[i] do |
|
1047 |
if (Gear <> nil) and (Gear^.X.QWordValue = 0) then |
|
1048 |
begin |
|
1049 |
ar[Count]:= Gear; |
|
1050 |
inc(Count) |
|
1051 |
end; |
|
1052 |
end; |
|
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
1053 |
|
955 | 1054 |
while (Count > 0) do |
1055 |
begin |
|
1056 |
i:= GetRandom(Count); |
|
1057 |
FindPlace(ar[i], false, 0, 2048); |
|
959 | 1058 |
ar[i]^.Pos:= GetRandom(19); |
955 | 1059 |
ar[i]:= ar[Count - 1]; |
1060 |
dec(Count) |
|
1061 |
end |
|
1062 |
end |
|
4 | 1063 |
end; |
1064 |
||
371 | 1065 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
10 | 1066 |
var t: PGear; |
1067 |
begin |
|
1068 |
t:= GearsList; |
|
1069 |
rX:= sqr(rX); |
|
1070 |
rY:= sqr(rY); |
|
1071 |
while t <> nil do |
|
1072 |
begin |
|
351 | 1073 |
if (t <> Gear) and (t^.Kind = Kind) then |
498 | 1074 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
351 | 1075 |
exit(t); |
1076 |
t:= t^.NextGear |
|
10 | 1077 |
end; |
351 | 1078 |
CheckGearNear:= nil |
15 | 1079 |
end; |
1080 |
||
79 | 1081 |
procedure AmmoFlameWork(Ammo: PGear); |
1082 |
var t: PGear; |
|
1083 |
begin |
|
1084 |
t:= GearsList; |
|
1085 |
while t <> nil do |
|
1086 |
begin |
|
351 | 1087 |
if (t^.Kind = gtHedgehog) and (t^.Y < Ammo^.Y) then |
498 | 1088 |
if not (hwSqr(Ammo^.X - t^.X) + hwSqr(Ammo^.Y - t^.Y - int2hwFloat(cHHRadius)) * 2 > _2) then |
79 | 1089 |
begin |
351 | 1090 |
inc(t^.Damage, 5); |
1091 |
t^.dX:= t^.dX + (t^.X - Ammo^.X) * _0_02; |
|
1092 |
t^.dY:= - _0_25; |
|
1093 |
t^.Active:= true; |
|
79 | 1094 |
DeleteCI(t); |
1095 |
FollowGear:= t |
|
1096 |
end; |
|
351 | 1097 |
t:= t^.NextGear |
79 | 1098 |
end; |
1099 |
end; |
|
1100 |
||
371 | 1101 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
16 | 1102 |
var t: PGear; |
1103 |
begin |
|
1104 |
t:= GearsList; |
|
1105 |
rX:= sqr(rX); |
|
1106 |
rY:= sqr(rY); |
|
1107 |
while t <> nil do |
|
1108 |
begin |
|
351 | 1109 |
if t^.Kind in Kind then |
498 | 1110 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
351 | 1111 |
exit(t); |
1112 |
t:= t^.NextGear |
|
16 | 1113 |
end; |
351 | 1114 |
CheckGearsNear:= nil |
16 | 1115 |
end; |
1116 |
||
1117 |
function CountGears(Kind: TGearType): Longword; |
|
1118 |
var t: PGear; |
|
351 | 1119 |
Result: Longword; |
16 | 1120 |
begin |
1121 |
Result:= 0; |
|
1122 |
t:= GearsList; |
|
1123 |
while t <> nil do |
|
1124 |
begin |
|
351 | 1125 |
if t^.Kind = Kind then inc(Result); |
1126 |
t:= t^.NextGear |
|
16 | 1127 |
end; |
351 | 1128 |
CountGears:= Result |
16 | 1129 |
end; |
1130 |
||
15 | 1131 |
procedure SpawnBoxOfSmth; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1132 |
var t: LongInt; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1133 |
i: TAmmoType; |
15 | 1134 |
begin |
614 | 1135 |
if (cCaseFactor = 0) or |
1136 |
(CountGears(gtCase) >= 5) or |
|
1137 |
(getrandom(cCaseFactor) <> 0) then exit; |
|
498 | 1138 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
295 | 1139 |
case getrandom(2) of |
1140 |
0: begin |
|
351 | 1141 |
FollowGear^.Health:= 25; |
1142 |
FollowGear^.Pos:= posCaseHealth |
|
295 | 1143 |
end; |
1144 |
1: begin |
|
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1145 |
t:= 0; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1146 |
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
|
1147 |
inc(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1148 |
t:= GetRandom(t); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1149 |
i:= Low(TAmmoType); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1150 |
dec(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1151 |
while t >= 0 do |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1152 |
begin |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1153 |
inc(i); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1154 |
dec(t, Ammoz[i].Probability) |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1155 |
end; |
865 | 1156 |
PlaySound(sndReinforce, false); |
351 | 1157 |
FollowGear^.Pos:= posCaseAmmo; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
1158 |
FollowGear^.State:= Longword(i) |
295 | 1159 |
end; |
1160 |
end; |
|
70 | 1161 |
FindPlace(FollowGear, true, 0, 2048) |
1162 |
end; |
|
1163 |
||
371 | 1164 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); |
70 | 1165 |
|
371 | 1166 |
function CountNonZeroz(x, y, r: LongInt): LongInt; |
1167 |
var i: LongInt; |
|
1168 |
Result: LongInt; |
|
70 | 1169 |
begin |
1170 |
Result:= 0; |
|
701 | 1171 |
if (y and $FFFFFC00) = 0 then |
1172 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
351 | 1173 |
if Land[y, i] <> 0 then inc(Result); |
1174 |
CountNonZeroz:= Result |
|
70 | 1175 |
end; |
1176 |
||
495 | 1177 |
var x: LongInt; |
371 | 1178 |
y, sy: LongInt; |
386 | 1179 |
ar: array[0..511] of TPoint; |
1180 |
ar2: array[0..1023] of TPoint; |
|
392 | 1181 |
cnt, cnt2: Longword; |
1182 |
delta: LongInt; |
|
70 | 1183 |
begin |
386 | 1184 |
delta:= 250; |
1185 |
cnt2:= 0; |
|
16 | 1186 |
repeat |
392 | 1187 |
x:= Left + LongInt(GetRandom(Delta)); |
70 | 1188 |
repeat |
386 | 1189 |
inc(x, Delta); |
70 | 1190 |
cnt:= 0; |
351 | 1191 |
y:= -Gear^.Radius * 2; |
70 | 1192 |
while y < 1023 do |
16 | 1193 |
begin |
70 | 1194 |
repeat |
701 | 1195 |
inc(y, 2); |
351 | 1196 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0); |
70 | 1197 |
sy:= y; |
1198 |
repeat |
|
1199 |
inc(y); |
|
351 | 1200 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0); |
1201 |
if (y - sy > Gear^.Radius * 2) |
|
70 | 1202 |
and (y < 1023) |
351 | 1203 |
and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
70 | 1204 |
begin |
1205 |
ar[cnt].X:= x; |
|
351 | 1206 |
if withFall then ar[cnt].Y:= sy + Gear^.Radius |
1207 |
else ar[cnt].Y:= y - Gear^.Radius; |
|
70 | 1208 |
inc(cnt) |
1209 |
end; |
|
386 | 1210 |
inc(y, 45) |
16 | 1211 |
end; |
70 | 1212 |
if cnt > 0 then |
1213 |
with ar[GetRandom(cnt)] do |
|
1214 |
begin |
|
386 | 1215 |
ar2[cnt2].x:= x; |
1216 |
ar2[cnt2].y:= y; |
|
1217 |
inc(cnt2) |
|
70 | 1218 |
end |
386 | 1219 |
until (x + Delta > Right); |
1220 |
dec(Delta, 60) |
|
1221 |
until (cnt2 > 0) or (Delta < 70); |
|
1222 |
if cnt2 > 0 then |
|
1223 |
with ar2[GetRandom(cnt2)] do |
|
1224 |
begin |
|
498 | 1225 |
Gear^.X:= int2hwFloat(x); |
1226 |
Gear^.Y:= int2hwFloat(y); |
|
386 | 1227 |
{$IFDEF DEBUGFILE} |
1228 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
1229 |
{$ENDIF} |
|
1230 |
end |
|
1231 |
else |
|
1232 |
begin |
|
1233 |
OutError('Can''t find place for Gear', false); |
|
1234 |
DeleteGear(Gear) |
|
1235 |
end |
|
10 | 1236 |
end; |
1237 |
||
4 | 1238 |
initialization |
1239 |
||
1240 |
finalization |
|
95 | 1241 |
FreeGearsList; |
4 | 1242 |
|
1243 |
end. |