author  unc0rr 
Tue, 25 Mar 2008 21:50:36 +0000  
changeset 824  e632cc7caf3a 
parent 823  90d651e75547 
child 825  4b32f282f9d7 
permissions  rwrr 
4  1 
(* 
2 
* Hedgewars, a wormslike game 

393  3 
* Copyright (c) 20042007 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 021111307, 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; 
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset

40 
DirAngle: real; 
4  41 
Timer : LongWord; 
351  42 
Elasticity: hwFloat; 
43 
Friction : hwFloat; 

783  44 
Message, MsgParam : Longword; 
4  45 
Hedgehog: pointer; 
371  46 
Health, Damage: LongInt; 
511  47 
CollisionIndex: LongInt; 
371  48 
Tag: LongInt; 
762  49 
Tex: PTexture; 
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; 
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
593
diff
changeset

52 
TriggerId: Longword; 
4  53 
end; 
54 

371  55 
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; 
4  56 
procedure ProcessGears; 
57 
procedure SetAllToActive; 

58 
procedure SetAllHHToActive; 

59 
procedure DrawGears(Surface: PSDL_Surface); 

60 
procedure FreeGearsList; 

10  61 
procedure AddMiscGears; 
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, 
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

72 
uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers, GL, 
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

73 
uStats; 
789  74 

75 
const MAXROPEPOINTS = 300; 

68  76 
var RopePoints: record 
4  77 
Count: Longword; 
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset

78 
HookAngle: GLfloat; 
789  79 
ar: array[0..MAXROPEPOINTS] of record 
351  80 
X, Y: hwFloat; 
81 
dLen: hwFloat; 

4  82 
b: boolean; 
83 
end; 

84 
end; 

85 

86 
procedure DeleteGear(Gear: PGear); forward; 

371  87 
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward; 
88 
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward; 

79  89 
procedure AmmoFlameWork(Ammo: PGear); forward; 
371  90 
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; forward; 
15  91 
procedure SpawnBoxOfSmth; forward; 
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset

92 
procedure AfterAttack; forward; 
371  93 
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); forward; 
302  94 
procedure HedgehogStep(Gear: PGear); forward; 
303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset

95 
procedure HedgehogChAngle(Gear: PGear); forward; 
506  96 
procedure ShotgunShot(Gear: PGear); forward; 
522  97 
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); forward; 
4  98 

99 
{$INCLUDE GSHandlers.inc} 

100 
{$INCLUDE HHHandlers.inc} 

101 

102 
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( 

351  103 
@doStepBomb, 
104 
@doStepHedgehog, 

105 
@doStepGrenade, 

106 
@doStepHealthTag, 

107 
@doStepGrave, 

108 
@doStepUFO, 

109 
@doStepShotgunShot, 

110 
@doStepPickHammer, 

111 
@doStepRope, 

112 
@doStepSmokeTrace, 

113 
@doStepExplosion, 

114 
@doStepMine, 

115 
@doStepCase, 

116 
@doStepDEagleShot, 

117 
@doStepDynamite, 

118 
@doStepTeamHealthSorter, 

119 
@doStepBomb, 

120 
@doStepCluster, 

121 
@doStepShover, 

122 
@doStepFlame, 

123 
@doStepFirePunch, 

124 
@doStepActionTimer, 

125 
@doStepActionTimer, 

126 
@doStepActionTimer, 

127 
@doStepParachute, 

128 
@doStepAirAttack, 

129 
@doStepAirBomb, 

409  130 
@doStepBlowTorch, 
520  131 
@doStepGirder, 
522  132 
@doStepTeleport, 
534  133 
@doStepHealthTag, 
590  134 
@doStepSwitcher, 
135 
@doStepCase 

4  136 
); 
137 

294  138 
procedure InsertGearToList(Gear: PGear); 
803  139 
var tmp, ptmp: PGear; 
294  140 
begin 
141 
if GearsList = nil then 

142 
GearsList:= Gear 

143 
else begin 

144 
tmp:= GearsList; 

803  145 
ptmp:= GearsList; 
146 
while (tmp <> nil) and (tmp^.Z <= Gear^.Z) do 

147 
begin 

148 
ptmp:= tmp; 

149 
tmp:= tmp^.NextGear 

150 
end; 

294  151 

803  152 
if ptmp <> nil then 
153 
begin 

154 
Gear^.NextGear:= ptmp^.NextGear; 

155 
Gear^.PrevGear:= ptmp; 

156 
if ptmp^.NextGear <> nil then ptmp^.NextGear^.PrevGear:= Gear; 

157 
ptmp^.NextGear:= Gear 

158 
end 

159 
else GearsList:= Gear 

294  160 
end 
161 
end; 

162 

163 
procedure RemoveGearFromList(Gear: PGear); 

164 
begin 

351  165 
if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear; 
166 
if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear 

809  167 
else GearsList:= Gear^.NextGear 
294  168 
end; 
169 

371  170 
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; 
79  171 
const Counter: Longword = 0; 
351  172 
var Result: PGear; 
4  173 
begin 
79  174 
inc(Counter); 
108  175 
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF} 
4  176 
New(Result); 
357  177 
{$IFDEF DEBUGFILE}AddFileLog('AddGear: type = ' + inttostr(ord(Kind)));{$ENDIF} 
4  178 
FillChar(Result^, sizeof(TGear), 0); 
498  179 
Result^.X:= int2hwFloat(X); 
180 
Result^.Y:= int2hwFloat(Y); 

351  181 
Result^.Kind := Kind; 
182 
Result^.State:= State; 

183 
Result^.Active:= true; 

184 
Result^.dX:= dX; 

185 
Result^.dY:= dY; 

186 
Result^.doStep:= doStepHandlers[Kind]; 

511  187 
Result^.CollisionIndex:= 1; 
351  188 
Result^.Timer:= Timer; 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset

189 

4  190 
if CurrentTeam <> nil then 
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset

191 
begin 
602  192 
Result^.Hedgehog:= CurrentHedgehog; 
193 
Result^.IntersectGear:= CurrentHedgehog^.Gear 

505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset

194 
end; 
802
ed5450a89b96
Start implementing 'visual gears'  gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
789
diff
changeset

195 

4  196 
case Kind of 
197 
gtAmmo_Bomb: begin 

351  198 
Result^.Radius:= 4; 
199 
Result^.Elasticity:= _0_6; 

200 
Result^.Friction:= _0_995; 

4  201 
end; 
202 
gtHedgehog: begin 

351  203 
Result^.Radius:= cHHRadius; 
204 
Result^.Elasticity:= _0_35; 

205 
Result^.Friction:= _0_999; 

206 
Result^.Angle:= cMaxAngle div 2; 

207 
Result^.Z:= cHHZ; 

4  208 
end; 
209 
gtAmmo_Grenade: begin 

351  210 
Result^.Radius:= 4; 
4  211 
end; 
212 
gtHealthTag: begin 

351  213 
Result^.Timer:= 1500; 
522  214 
Result^.Z:= 2001; 
4  215 
end; 
216 
gtGrave: begin 

351  217 
Result^.Radius:= 10; 
218 
Result^.Elasticity:= _0_6; 

4  219 
end; 
220 
gtUFO: begin 

351  221 
Result^.Radius:= 5; 
222 
Result^.Timer:= 500; 

223 
Result^.Elasticity:= _0_9 

4  224 
end; 
225 
gtShotgunShot: begin 

351  226 
Result^.Timer:= 900; 
227 
Result^.Radius:= 2 

4  228 
end; 
229 
gtPickHammer: begin 

351  230 
Result^.Radius:= 10; 
231 
Result^.Timer:= 4000 

4  232 
end; 
233 
gtSmokeTrace: begin 

498  234 
Result^.X:= Result^.X  _16; 
235 
Result^.Y:= Result^.Y  _16; 

351  236 
Result^.State:= 8 
4  237 
end; 
238 
gtRope: begin 

351  239 
Result^.Radius:= 3; 
498  240 
Result^.Friction:= _450; 
4  241 
RopePoints.Count:= 0; 
242 
end; 

9  243 
gtExplosion: begin 
498  244 
Result^.X:= Result^.X  _25; 
245 
Result^.Y:= Result^.Y  _25; 

9  246 
end; 
10  247 
gtMine: begin 
503  248 
Result^.State:= Result^.State or gstMoving; 
351  249 
Result^.Radius:= 3; 
250 
Result^.Elasticity:= _0_55; 

251 
Result^.Friction:= _0_995; 

252 
Result^.Timer:= 3000; 

10  253 
end; 
14
81f125629b25
 Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset

254 
gtCase: begin 
351  255 
Result^.Radius:= 16; 
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
595
diff
changeset

256 
Result^.Elasticity:= _0_3 
14
81f125629b25
 Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset

257 
end; 
37  258 
gtDEagleShot: begin 
351  259 
Result^.Radius:= 1; 
260 
Result^.Health:= 50 

37  261 
end; 
39  262 
gtDynamite: begin 
351  263 
Result^.Radius:= 3; 
264 
Result^.Elasticity:= _0_55; 

265 
Result^.Friction:= _0_03; 

266 
Result^.Timer:= 5000; 

39  267 
end; 
78  268 
gtClusterBomb: begin 
351  269 
Result^.Radius:= 4; 
270 
Result^.Elasticity:= _0_6; 

271 
Result^.Friction:= _0_995; 

78  272 
end; 
79  273 
gtFlame: begin 
351  274 
Result^.Angle:= Counter mod 64; 
275 
Result^.Radius:= 1; 

276 
Result^.Health:= 2; 

277 
Result^.dY:= (getrandom  _0_8) * _0_03; 

278 
Result^.dX:= (getrandom  _0_5) * _0_4 

79  279 
end; 
82  280 
gtFirePunch: begin 
351  281 
Result^.Radius:= 15; 
282 
Result^.Tag:= Y 

82  283 
end; 
302  284 
gtAirBomb: begin 
543
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

285 
Result^.Radius:= 5; 
302  286 
end; 
287 
gtBlowTorch: begin 

511  288 
Result^.Radius:= cHHRadius + cBlowTorchC; 
351  289 
Result^.Timer:= 7500; 
302  290 
end; 
522  291 
gtSmallDamage: begin 
292 
Result^.Timer:= 1100; 

293 
Result^.Z:= 2000; 

294 
end; 

540  295 
gtSwitcher: begin 
296 
Result^.Z:= cCurrHHZ 

297 
end; 

593  298 
gtTarget: begin 
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
595
diff
changeset

299 
Result^.Radius:= 16; 
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
595
diff
changeset

300 
Result^.Elasticity:= _0_3 
593  301 
end; 
4  302 
end; 
351  303 
InsertGearToList(Result); 
304 
AddGear:= Result 

4  305 
end; 
306 

307 
procedure DeleteGear(Gear: PGear); 

48  308 
var team: PTeam; 
307  309 
t: Longword; 
4  310 
begin 
503  311 
DeleteCI(Gear); 
762  312 

313 
if Gear^.Tex <> nil then 

522  314 
begin 
762  315 
FreeTexture(Gear^.Tex); 
316 
Gear^.Tex:= nil 

522  317 
end; 
762  318 

351  319 
if Gear^.Kind = gtHedgehog then 
4  320 
if CurAmmoGear <> nil then 
321 
begin 

351  322 
Gear^.Message:= gm_Destroy; 
323 
CurAmmoGear^.Message:= gm_Destroy; 

4  324 
exit 
47  325 
end else 
326 
begin 

498  327 
if not (hwRound(Gear^.Y) < cWaterLine) then 
307  328 
begin 
351  329 
t:= max(Gear^.Damage, Gear^.Health); 
498  330 
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtHealthTag, t, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; 
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

331 
uStats.HedgehogDamaged(Gear, t) 
307  332 
end; 
351  333 
team:= PHedgehog(Gear^.Hedgehog)^.Team; 
602  334 
if CurrentHedgehog^.Gear = Gear then 
145  335 
FreeActionsList; // to avoid ThinkThread on drawned gear 
351  336 
PHedgehog(Gear^.Hedgehog)^.Gear:= nil; 
307  337 
inc(KilledHHs); 
48  338 
RecountTeamHealth(team); 
47  339 
end; 
357  340 
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear');{$ENDIF} 
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
593
diff
changeset

341 
if Gear^.TriggerId <> 0 then TickTrigger(Gear^.TriggerId); 
82  342 
if CurAmmoGear = Gear then CurAmmoGear:= nil; 
4  343 
if FollowGear = Gear then FollowGear:= nil; 
294  344 
RemoveGearFromList(Gear); 
4  345 
Dispose(Gear) 
346 
end; 

347 

348 
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs 

349 
var Gear: PGear; 

350 
begin 

351  351 
CheckNoDamage:= true; 
4  352 
Gear:= GearsList; 
353 
while Gear <> nil do 

354 
begin 

351  355 
if Gear^.Kind = gtHedgehog then 
356 
if Gear^.Damage <> 0 then 

4  357 
begin 
351  358 
CheckNoDamage:= false; 
359 
if Gear^.Health < Gear^.Damage then Gear^.Health:= 0 

522  360 
else dec(Gear^.Health, Gear^.Damage); 
361 
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y)  cHHRadius  12, 

498  362 
gtHealthTag, Gear^.Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; 
351  363 
RenderHealth(PHedgehog(Gear^.Hedgehog)^); 
364 
RecountTeamHealth(PHedgehog(Gear^.Hedgehog)^.Team); 

365 

366 
Gear^.Damage:= 0 

4  367 
end; 
351  368 
Gear:= Gear^.NextGear 
83  369 
end; 
4  370 
end; 
371 

522  372 
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); 
373 
begin 

529  374 
if cAltDamage then 
375 
AddGear(X, Y, gtSmallDamage, Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; 

522  376 
end; 
377 

4  378 
procedure ProcessGears; 
614  379 
const delay: LongWord = 0; 
815  380 
step: (stDelay, stChDmg, stChWin, stTurnReact, 
381 
stAfterDelay, stSpawn, stNTurn) = stDelay; 

4  382 
var Gear, t: PGear; 
383 
begin 

384 
AllInactive:= true; 

385 
t:= GearsList; 

386 
while t<>nil do 

387 
begin 

388 
Gear:= t; 

351  389 
t:= Gear^.NextGear; 
390 
if Gear^.Active then Gear^.doStep(Gear); 

4  391 
end; 
89  392 

4  393 
if AllInactive then 
15  394 
case step of 
395 
stDelay: begin 

396 
if delay = 0 then 

397 
delay:= cInactDelay 

614  398 
else 
399 
dec(delay); 

400 

401 
if delay = 0 then 

402 
inc(step) 

15  403 
end; 
404 
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; 

351  405 
stChWin: if not CheckForWin then inc(step) else step:= stDelay; 
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

406 
stTurnReact: begin 
815  407 
if not isInMultiShoot then uStats.TurnReaction; 
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

408 
inc(step) 
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

409 
end; 
815  410 
stAfterDelay: begin 
411 
if delay = 0 then 

412 
delay:= cInactDelay 

413 
else 

414 
dec(delay); 

415 

416 
if delay = 0 then 

417 
inc(step) 

418 
end; 

15  419 
stSpawn: begin 
420 
if not isInMultiShoot then SpawnBoxOfSmth; 

421 
inc(step) 

422 
end; 

423 
stNTurn: begin 

351  424 
//AwareOfExplosion(0, 0, 0); 
15  425 
if isInMultiShoot then isInMultiShoot:= false 
307  426 
else begin 
351  427 
ParseCommand('/nextturn', true); 
307  428 
end; 
15  429 
step:= Low(step) 
430 
end; 

431 
end; 

432 

4  433 
if TurnTimeLeft > 0 then 
602  434 
if CurrentHedgehog^.Gear <> nil then 
435 
if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) 

4  436 
and not isInMultiShoot then dec(TurnTimeLeft); 
351  437 

651  438 
if (not CurrentTeam^.ExtDriven) and 
656
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset

439 
((GameTicks and $FFFF) = $FFFF) then 
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset

440 
begin 
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset

441 
SendIPCTimeInc; 
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset

442 
inc(hiTicks) // we do not recieve a message for it 
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset

443 
end; 
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset

444 

515  445 
inc(GameTicks) 
4  446 
end; 
447 

448 
procedure SetAllToActive; 

449 
var t: PGear; 

450 
begin 

451 
AllInactive:= false; 

452 
t:= GearsList; 

351  453 
while t <> nil do 
4  454 
begin 
351  455 
t^.Active:= true; 
456 
t:= t^.NextGear 

4  457 
end 
458 
end; 

459 

460 
procedure SetAllHHToActive; 

461 
var t: PGear; 

462 
begin 

463 
AllInactive:= false; 

464 
t:= GearsList; 

351  465 
while t <> nil do 
4  466 
begin 
351  467 
if t^.Kind = gtHedgehog then t^.Active:= true; 
468 
t:= t^.NextGear 

4  469 
end 
470 
end; 

471 

292  472 
procedure DrawHH(Gear: PGear; Surface: PSDL_Surface); 
371  473 
var t: LongInt; 
822  474 
amt: TAmmoType; 
475 
hx, hy: LongInt; 

476 
aangle: real; 

824  477 
defaultPos: boolean; 
292  478 
begin 
824  479 
defaultPos:= true; 
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
815
diff
changeset

480 
if (Gear^.State and gstHHDriven) <> 0 then 
822  481 
begin 
482 
if CurAmmoGear <> nil then 

483 
begin 

484 
if (CurAmmoGear^.Kind = gtRope) then 

824  485 
begin 
486 
DrawHedgehog(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 

487 
1, 

488 
1, 

489 
0, 

490 
DxDy2Angle(CurAmmoGear^.dY, CurAmmoGear^.dX)  110); 

491 
defaultPos:= false 

492 
end 

822  493 
end else 
824  494 
if ((Gear^.State and gstHHJumping) <> 0) then 
495 
begin 

496 
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y)  3 + WorldDy, 

497 
hwSign(Gear^.dX), 

498 
1, 

499 
1, 

500 
0); 

501 
defaultPos:= false 

502 
end else 

503 
if (Gear^.Message and (gm_Left or gm_Right) <> 0) 

504 
or ((Gear^.State and gstAttacked) <> 0) then 

505 
begin 

822  506 
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y)  3 + WorldDy, 
507 
hwSign(Gear^.dX), 

508 
0, 

509 
PHedgehog(Gear^.Hedgehog)^.visStepPos div 2, 

824  510 
0); 
511 
defaultPos:= false 

512 
end 

822  513 
else 
514 
begin 

515 
amt:= CurrentHedgehog^.Ammo^[CurrentHedgehog^.CurSlot, CurrentHedgehog^.CurAmmo].AmmoType; 

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; 

519 
case amt of 

823
90d651e75547
Use ammoinhand sprites for desert eagle, shotgun and bazooka
unc0rr
parents:
822
diff
changeset

520 
amBazooka: DrawRotated(sprHandBazooka, hx, hy, hwSign(Gear^.dX), aangle); 
822  521 
amRope: DrawRotated(sprHandRope, hx, hy, hwSign(Gear^.dX), aangle); 
823
90d651e75547
Use ammoinhand sprites for desert eagle, shotgun and bazooka
unc0rr
parents:
822
diff
changeset

522 
amShotgun: DrawRotated(sprHandShotgun, hx, hy, hwSign(Gear^.dX), aangle); 
90d651e75547
Use ammoinhand sprites for desert eagle, shotgun and bazooka
unc0rr
parents:
822
diff
changeset

523 
amDEagle: DrawRotated(sprHandDEagle, hx, hy, hwSign(Gear^.dX), aangle); 
822  524 
else 
525 
end; 

526 
case amt of 

823
90d651e75547
Use ammoinhand sprites for desert eagle, shotgun and bazooka
unc0rr
parents:
822
diff
changeset

527 
amBazooka, 
90d651e75547
Use ammoinhand sprites for desert eagle, shotgun and bazooka
unc0rr
parents:
822
diff
changeset

528 
amRope, 
90d651e75547
Use ammoinhand sprites for desert eagle, shotgun and bazooka
unc0rr
parents:
822
diff
changeset

529 
amShotgun, 
824  530 
amDEagle: begin 
531 
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y)  3 + WorldDy, 

532 
hwSign(Gear^.dX), 

533 
0, 

534 
4, 

535 
0); 

536 
defaultPos:= false 

537 
end 

822  538 
else 
539 
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y)  3 + WorldDy, 

540 
hwSign(Gear^.dX), 

541 
0, 

542 
3, 

543 
0); 

824  544 
defaultPos:= false 
822  545 
end 
546 
end 

824  547 
end; 
548 

549 
if defaultPos then 

822  550 
DrawHedgehog(hwRound(Gear^.X) + 1 + WorldDx, hwRound(Gear^.Y)  3 + WorldDy, 
551 
hwSign(Gear^.dX), 

552 
0, 

553 
3, 

554 
0); 

292  555 

351  556 
with PHedgehog(Gear^.Hedgehog)^ do 
538  557 
if (Gear^.State{ and not gstAnimation}) = 0 then 
292  558 
begin 
351  559 
t:= hwRound(Gear^.Y)  cHHRadius  10 + WorldDy; 
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

560 
if (cTagsMask and 1) <> 0 then 
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

561 
begin 
762  562 
dec(t, HealthTagTex^.h + 2); 
563 
DrawCentered(hwRound(Gear^.X) + WorldDx, t, HealthTagTex) 

539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

564 
end; 
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

565 
if (cTagsMask and 2) <> 0 then 
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

566 
begin 
762  567 
dec(t, NameTagTex^.h + 2); 
568 
DrawCentered(hwRound(Gear^.X) + WorldDx, t, NameTagTex) 

539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

569 
end; 
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

570 
if (cTagsMask and 4) <> 0 then 
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

571 
begin 
762  572 
dec(t, Team^.NameTagTex^.h + 2); 
573 
DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTagTex) 

539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset

574 
end 
292  575 
end else // Current hedgehog 
538  576 
if (Gear^.State and gstHHDriven) <> 0 then 
292  577 
begin 
351  578 
if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then 
579 
DrawSprite(sprFinger, hwRound(Gear^.X)  16 + WorldDx, hwRound(Gear^.Y)  64 + WorldDy, 

292  580 
GameTicks div 32 mod 16, Surface); 
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
815
diff
changeset

581 

542  582 
if (Gear^.State and (gstMoving or gstDrowning)) = 0 then 
351  583 
if (Gear^.State and gstHHThinking) <> 0 then 
688  584 
DrawSprite(sprQuestion, hwRound(Gear^.X)  10 + WorldDx, hwRound(Gear^.Y)  cHHRadius  34 + WorldDy, 0, Surface) 
292  585 
else 
351  586 
if ShowCrosshair and ((Gear^.State and gstAttacked) = 0) then 
777  587 
DrawRotatedTex(Team^.CrosshairTex, 
588 
12, 12, 

589 
Round(hwRound(Gear^.X) + 

590 
hwSign(Gear^.dX) * Sin(Gear^.Angle*pi/cMaxAngle)*60) + WorldDx, 

591 
Round(hwRound(Gear^.Y)  

822  592 
Cos(Gear^.Angle*pi/cMaxAngle)*60) + WorldDy, 0, 
777  593 
hwSign(Gear^.dX) * Gear^.Angle * 180 / cMaxAngle) 
292  594 
end; 
595 
end; 

596 

4  597 
procedure DrawGears(Surface: PSDL_Surface); 
598 
var Gear: PGear; 

599 
i: Longword; 

371  600 
roplen: LongInt; 
4  601 

371  602 
procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt); 
603 
var eX, eY, dX, dY: LongInt; 

604 
i, sX, sY, x, y, d: LongInt; 

366  605 
b: boolean; 
4  606 
begin 
37  607 
if (X1 = X2) and (Y1 = Y2) then 
608 
begin 

351  609 
OutError('WARNING: zero length rope line!', false); 
37  610 
exit 
611 
end; 

366  612 
eX:= 0; 
613 
eY:= 0; 

614 
dX:= X2  X1; 

615 
dY:= Y2  Y1; 

616 

617 
if (dX > 0) then sX:= 1 

618 
else 

619 
if (dX < 0) then 

620 
begin 

621 
sX:= 1; 

622 
dX:= dX 

623 
end else sX:= dX; 

624 

625 
if (dY > 0) then sY:= 1 

626 
else 

627 
if (dY < 0) then 

4  628 
begin 
366  629 
sY:= 1; 
630 
dY:= dY 

631 
end else sY:= dY; 

632 

633 
if (dX > dY) then d:= dX 

634 
else d:= dY; 

635 

636 
x:= X1; 

637 
y:= Y1; 

638 

639 
for i:= 0 to d do 

640 
begin 

641 
inc(eX, dX); 

642 
inc(eY, dY); 

643 
b:= false; 

644 
if (eX > d) then 

35  645 
begin 
366  646 
dec(eX, d); 
647 
inc(x, sX); 

648 
b:= true 

35  649 
end; 
366  650 
if (eY > d) then 
35  651 
begin 
366  652 
dec(eY, d); 
653 
inc(y, sY); 

654 
b:= true 

35  655 
end; 
366  656 
if b then 
657 
begin 

658 
inc(roplen); 

688  659 
if (roplen mod 4) = 0 then DrawSprite(sprRopeNode, x  2, y  2, 0, Surface) 
366  660 
end 
4  661 
end 
366  662 
end; 
4  663 

664 
begin 

665 
Gear:= GearsList; 

666 
while Gear<>nil do 

667 
begin 

351  668 
case Gear^.Kind of 
822  669 
gtAmmo_Bomb: DrawRotated(sprBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle); 
292  670 
gtHedgehog: DrawHH(Gear, Surface); 
822  671 
gtAmmo_Grenade: DrawRotated(sprGrenade, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); 
522  672 
gtHealthTag, 
762  673 
gtSmallDamage: if Gear^.Tex <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex); 
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset

674 
gtGrave: DrawSurfSprite(hwRound(Gear^.X) + WorldDx  16, hwRound(Gear^.Y) + WorldDy  16, 32, (GameTicks shr 7) and 7, PHedgehog(Gear^.Hedgehog)^.Team^.GraveTex, Surface); 
351  675 
gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X)  16 + WorldDx, hwRound(Gear^.Y)  16 + WorldDy, (GameTicks shr 7) mod 4, Surface); 
4  676 
gtRope: begin 
35  677 
roplen:= 0; 
4  678 
if RopePoints.Count > 0 then 
679 
begin 

680 
i:= 0; 

681 
while i < Pred(RopePoints.Count) do 

682 
begin 

351  683 
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, 
684 
hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy); 

4  685 
inc(i) 
686 
end; 

351  687 
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, 
688 
hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy); 

689 
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 

690 
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); 

822  691 
DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle) 
4  692 
end else 
35  693 
begin 
351  694 
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 
695 
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); 

822  696 
DrawRotated(sprRopeHook, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); 
35  697 
end; 
4  698 
end; 
568  699 
gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); 
351  700 
gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); 
701 
gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420) 

822  702 
then DrawRotated(sprMineOff, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle) 
703 
else DrawRotated(sprMineOn, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle); 

351  704 
gtCase: case Gear^.Pos of 
705 
posCaseAmmo : DrawSprite(sprCase, hwRound(Gear^.X)  16 + WorldDx, hwRound(Gear^.Y)  16 + WorldDy, 0, Surface); 

706 
posCaseHealth: DrawSprite(sprFAid, hwRound(Gear^.X)  24 + WorldDx, hwRound(Gear^.Y)  24 + WorldDy, (GameTicks shr 6) mod 13, Surface); 

42  707 
end; 
568  708 
gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X)  16 + WorldDx, hwRound(Gear^.Y)  25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1, Surface); 
822  709 
gtClusterBomb: DrawRotated(sprClusterBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, Gear^.DirAngle); 
351  710 
gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X)  8 + WorldDx, hwRound(Gear^.Y)  8 + WorldDy, 0, Surface); 
711 
gtFlame: DrawSprite(sprFlame, hwRound(Gear^.X)  8 + WorldDx, hwRound(Gear^.Y)  8 + WorldDy,(GameTicks div 128 + Gear^.Angle) mod 8, Surface); 

568  712 
gtParachute: DrawSprite(sprParachute, hwRound(Gear^.X)  24 + WorldDx, hwRound(Gear^.Y)  48 + WorldDy, 0, Surface); 
408  713 
gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X)  60 + WorldDx, hwRound(Gear^.Y)  25 + WorldDy, 0, Surface) 
534  714 
else DrawSprite(sprAirplane, hwRound(Gear^.X)  60 + WorldDx, hwRound(Gear^.Y)  25 + WorldDy, 1, Surface); 
822  715 
gtAirBomb: DrawRotated(sprAirBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); 
708  716 
gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X)  16 + WorldDx, hwRound(Gear^.Y)  56 + WorldDy, (GameTicks shr 6) mod 12, Surface); 
593  717 
gtTarget: DrawSprite(sprTarget, hwRound(Gear^.X)  16 + WorldDx, hwRound(Gear^.Y)  16 + WorldDy, 0, Surface); 
4  718 
end; 
351  719 
Gear:= Gear^.NextGear 
4  720 
end; 
721 
end; 

722 

723 
procedure FreeGearsList; 

724 
var t, tt: PGear; 

725 
begin 

726 
tt:= GearsList; 

727 
GearsList:= nil; 

728 
while tt<>nil do 

729 
begin 

730 
t:= tt; 

351  731 
tt:= tt^.NextGear; 
4  732 
Dispose(t) 
733 
end; 

734 
end; 

735 

10  736 
procedure AddMiscGears; 
371  737 
var i: LongInt; 
4  738 
begin 
498  739 
AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000); 
22  740 
if (GameFlags and gfForts) = 0 then 
622  741 
for i:= 0 to Pred(cLandAdditions) do 
498  742 
FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048); 
4  743 
end; 
744 

371  745 
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); 
4  746 
var Gear: PGear; 
506  747 
dmg, dmgRadius: LongInt; 
4  748 
begin 
749 
TargetPoint.X:= NoPointX; 

750 
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} 

498  751 
if Radius = 50 then AddGear(X, Y, gtExplosion, 0, _0, _0, 0); 
355  752 
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false); 
506  753 
if (Mask and EXPLAllDamageInRadius)=0 then dmgRadius:= Radius shl 1 
754 
else dmgRadius:= Radius; 

4  755 
Gear:= GearsList; 
756 
while Gear <> nil do 

757 
begin 

506  758 
dmg:= dmgRadius  hwRound(Distance(Gear^.X  int2hwFloat(X), Gear^.Y  int2hwFloat(Y))); 
538  759 
if (dmg > 1) and 
522  760 
((Gear^.State and gstNoDamage) = 0) then 
4  761 
begin 
355  762 
dmg:= dmg div 2; 
351  763 
case Gear^.Kind of 
10  764 
gtHedgehog, 
14
81f125629b25
 Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset

765 
gtMine, 
79  766 
gtCase, 
593  767 
gtTarget, 
79  768 
gtFlame: begin 
355  769 
{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF} 
522  770 
if (Mask and EXPLNoDamage) = 0 then 
771 
begin 

772 
inc(Gear^.Damage, dmg); 

814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

773 
uStats.HedgehogDamaged(Gear, dmg); 
522  774 
if Gear^.Kind = gtHedgehog then 
775 
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear) 

776 
end; 

351  777 
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then 
42  778 
begin 
506  779 
DeleteCI(Gear); 
498  780 
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X  int2hwFloat(X)); 
781 
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y  int2hwFloat(Y)); 

503  782 
Gear^.State:= Gear^.State or gstMoving; 
351  783 
Gear^.Active:= true; 
42  784 
FollowGear:= Gear 
785 
end; 

4  786 
end; 
51  787 
gtGrave: begin 
351  788 
Gear^.dY:=  _0_004 * dmg; 
789 
Gear^.Active:= true; 

51  790 
end; 
4  791 
end; 
792 
end; 

351  793 
Gear:= Gear^.NextGear 
80  794 
end; 
621  795 
if (Mask and EXPLDontDraw) = 0 then 
796 
if (GameFlags and gfSolidLand) = 0 then DrawExplosion(X, Y, Radius); 

498  797 
uAIMisc.AwareOfExplosion(0, 0, 0) 
4  798 
end; 
799 

506  800 
procedure ShotgunShot(Gear: PGear); 
801 
var t: PGear; 

802 
dmg: integer; 

803 
begin 

509  804 
Gear^.Radius:= cShotgunRadius; 
506  805 
t:= GearsList; 
806 
while t <> nil do 

807 
begin 

808 
dmg:= min(Gear^.Radius + t^.Radius  hwRound(Distance(Gear^.X  t^.X, Gear^.Y  t^.Y)), 25); 

538  809 
if dmg > 0 then 
506  810 
case t^.Kind of 
811 
gtHedgehog, 

812 
gtMine, 

593  813 
gtCase, 
814 
gtTarget: begin 

506  815 
inc(t^.Damage, dmg); 
522  816 
if t^.Kind = gtHedgehog then 
817 
begin 

531  818 
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, t); 
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

819 
uStats.HedgehogDamaged(Gear, dmg) 
522  820 
end; 
506  821 
DeleteCI(t); 
822 
t^.dX:= t^.dX + SignAs(Gear^.dX * dmg * _0_01 + cHHKick, t^.X  Gear^.X); 

823 
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; 

824 
t^.State:= t^.State or gstMoving; 

825 
t^.Active:= true; 

826 
FollowGear:= t 

827 
end; 

828 
gtGrave: begin 

829 
t^.dY:=  _0_1; 

830 
t^.Active:= true 

831 
end; 

832 
end; 

833 
t:= t^.NextGear 

834 
end; 

621  835 
if (GameFlags and gfSolidLand) = 0 then DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) 
506  836 
end; 
837 

371  838 
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); 
53  839 
var t: PGearArray; 
371  840 
i: LongInt; 
307  841 
hh: PHedgehog; 
38  842 
begin 
53  843 
t:= CheckGearsCollision(Ammo); 
351  844 
i:= t^.Count; 
845 
hh:= Ammo^.Hedgehog; 

53  846 
while i > 0 do 
847 
begin 

848 
dec(i); 

351  849 
if (t^.ar[i]^.State and gstNoDamage) = 0 then 
850 
case t^.ar[i]^.Kind of 

53  851 
gtHedgehog, 
852 
gtMine, 

593  853 
gtTarget, 
53  854 
gtCase: begin 
351  855 
inc(t^.ar[i]^.Damage, Damage); 
522  856 
if t^.ar[i]^.Kind = gtHedgehog then 
857 
begin 

858 
AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]); 

814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
809
diff
changeset

859 
uStats.HedgehogDamaged(t^.ar[i], Damage) 
522  860 
end; 
538  861 
DeleteCI(t^.ar[i]); 
351  862 
t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01; 
863 
t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01; 

864 
t^.ar[i]^.Active:= true; 

503  865 
t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving; 
351  866 
FollowGear:= t^.ar[i] 
53  867 
end; 
868 
end 

126  869 
end; 
870 
SetAllToActive 

38  871 
end; 
872 

4  873 
procedure AssignHHCoords; 
547  874 
var i, t, p: LongInt; 
543
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

875 
ar: array[0..Pred(cMaxHHs)] of PGear; 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

876 
Count: Longword; 
4  877 
begin 
543
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

878 
if (GameFlags and gfForts) <> 0 then 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

879 
begin 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

880 
t:= 0; 
547  881 
for p:= 0 to Pred(TeamsCount) do 
882 
with TeamsArray[p]^ do 

543
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

883 
begin 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

884 
for i:= 0 to cMaxHHIndex do 
547  885 
with Hedgehogs[i] do 
604
2f1165467a66
Let hedgehog position be taken from config, still more work is needed
unc0rr
parents:
602
diff
changeset

886 
if (Gear <> nil) and (Gear^.X.QWordValue = 0) then FindPlace(Gear, false, t, t + 1024); 
543
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

887 
inc(t, 1024); 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

888 
end 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

889 
end else // mix hedgehogs 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

890 
begin 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

891 
Count:= 0; 
547  892 
for p:= 0 to Pred(TeamsCount) do 
893 
with TeamsArray[p]^ do 

4  894 
begin 
82  895 
for i:= 0 to cMaxHHIndex do 
547  896 
with Hedgehogs[i] do 
604
2f1165467a66
Let hedgehog position be taken from config, still more work is needed
unc0rr
parents:
602
diff
changeset

897 
if (Gear <> nil) and (Gear^.X.QWordValue = 0) then 
543
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

898 
begin 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

899 
ar[Count]:= Gear; 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

900 
inc(Count) 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

901 
end; 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

902 
end; 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

903 

465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

904 
while (Count > 0) do 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

905 
begin 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

906 
i:= GetRandom(Count); 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

907 
FindPlace(ar[i], false, 0, 2048); 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

908 
ar[i]:= ar[Count  1]; 
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

909 
dec(Count) 
4  910 
end 
543
465e2ec8f05f
 Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset

911 
end 
4  912 
end; 
913 

371  914 
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; 
10  915 
var t: PGear; 
916 
begin 

917 
t:= GearsList; 

918 
rX:= sqr(rX); 

919 
rY:= sqr(rY); 

920 
while t <> nil do 

921 
begin 

351  922 
if (t <> Gear) and (t^.Kind = Kind) then 
498  923 
if not((hwSqr(Gear^.X  t^.X) / rX + hwSqr(Gear^.Y  t^.Y) / rY) > _1) then 
351  924 
exit(t); 
925 
t:= t^.NextGear 

10  926 
end; 
351  927 
CheckGearNear:= nil 
15  928 
end; 
929 

79  930 
procedure AmmoFlameWork(Ammo: PGear); 
931 
var t: PGear; 

932 
begin 

933 
t:= GearsList; 

934 
while t <> nil do 

935 
begin 

351  936 
if (t^.Kind = gtHedgehog) and (t^.Y < Ammo^.Y) then 
498  937 
if not (hwSqr(Ammo^.X  t^.X) + hwSqr(Ammo^.Y  t^.Y  int2hwFloat(cHHRadius)) * 2 > _2) then 
79  938 
begin 
351  939 
inc(t^.Damage, 5); 
940 
t^.dX:= t^.dX + (t^.X  Ammo^.X) * _0_02; 

941 
t^.dY:=  _0_25; 

942 
t^.Active:= true; 

79  943 
DeleteCI(t); 
944 
FollowGear:= t 

945 
end; 

351  946 
t:= t^.NextGear 
79  947 
end; 
948 
end; 

949 

371  950 
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; 
16  951 
var t: PGear; 
952 
begin 

953 
t:= GearsList; 

954 
rX:= sqr(rX); 

955 
rY:= sqr(rY); 

956 
while t <> nil do 

957 
begin 

351  958 
if t^.Kind in Kind then 
498  959 
if not (hwSqr(int2hwFloat(mX)  t^.X) / rX + hwSqr(int2hwFloat(mY)  t^.Y) / rY > _1) then 
351  960 
exit(t); 
961 
t:= t^.NextGear 

16  962 
end; 
351  963 
CheckGearsNear:= nil 
16  964 
end; 
965 

966 
function CountGears(Kind: TGearType): Longword; 

967 
var t: PGear; 

351  968 
Result: Longword; 
16  969 
begin 
970 
Result:= 0; 

971 
t:= GearsList; 

972 
while t <> nil do 

973 
begin 

351  974 
if t^.Kind = Kind then inc(Result); 
975 
t:= t^.NextGear 

16  976 
end; 
351  977 
CountGears:= Result 
16  978 
end; 
979 

15  980 
procedure SpawnBoxOfSmth; 
394
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

981 
var t: LongInt; 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

982 
i: TAmmoType; 
15  983 
begin 
614  984 
if (cCaseFactor = 0) or 
985 
(CountGears(gtCase) >= 5) or 

986 
(getrandom(cCaseFactor) <> 0) then exit; 

498  987 
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); 
295  988 
case getrandom(2) of 
989 
0: begin 

351  990 
FollowGear^.Health:= 25; 
991 
FollowGear^.Pos:= posCaseHealth 

295  992 
end; 
993 
1: begin 

394
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

994 
t:= 0; 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

995 
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

996 
inc(t, Ammoz[i].Probability); 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

997 
t:= GetRandom(t); 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

998 
i:= Low(TAmmoType); 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

999 
dec(t, Ammoz[i].Probability); 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

1000 
while t >= 0 do 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

1001 
begin 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

1002 
inc(i); 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

1003 
dec(t, Ammoz[i].Probability) 
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

1004 
end; 
351  1005 
FollowGear^.Pos:= posCaseAmmo; 
394
4c017ae1226a
 Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset

1006 
FollowGear^.State:= Longword(i) 
295  1007 
end; 
1008 
end; 

70  1009 
FindPlace(FollowGear, true, 0, 2048) 
1010 
end; 

1011 

371  1012 
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); 
70  1013 

371  1014 
function CountNonZeroz(x, y, r: LongInt): LongInt; 
1015 
var i: LongInt; 

1016 
Result: LongInt; 

70  1017 
begin 
1018 
Result:= 0; 

701  1019 
if (y and $FFFFFC00) = 0 then 
1020 
for i:= max(x  r, 0) to min(x + r, 2043) do 

351  1021 
if Land[y, i] <> 0 then inc(Result); 
1022 
CountNonZeroz:= Result 

70  1023 
end; 
1024 

495  1025 
var x: LongInt; 
371  1026 
y, sy: LongInt; 
386  1027 
ar: array[0..511] of TPoint; 
1028 
ar2: array[0..1023] of TPoint; 

392  1029 
cnt, cnt2: Longword; 
1030 
delta: LongInt; 

70  1031 
begin 
386  1032 
delta:= 250; 
1033 
cnt2:= 0; 

16  1034 
repeat 
392  1035 
x:= Left + LongInt(GetRandom(Delta)); 
70  1036 
repeat 
386  1037 
inc(x, Delta); 
70  1038 
cnt:= 0; 
351  1039 
y:= Gear^.Radius * 2; 
70  1040 
while y < 1023 do 
16  1041 
begin 
70  1042 
repeat 
701  1043 
inc(y, 2); 
351  1044 
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius  1) = 0); 
70  1045 
sy:= y; 
1046 
repeat 

1047 
inc(y); 

351  1048 
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius  1) <> 0); 
1049 
if (y  sy > Gear^.Radius * 2) 

70  1050 
and (y < 1023) 
351  1051 
and (CheckGearsNear(x, y  Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then 
70  1052 
begin 
1053 
ar[cnt].X:= x; 

351  1054 
if withFall then ar[cnt].Y:= sy + Gear^.Radius 
1055 
else ar[cnt].Y:= y  Gear^.Radius; 

70  1056 
inc(cnt) 
1057 
end; 

386  1058 
inc(y, 45) 
16  1059 
end; 
70  1060 
if cnt > 0 then 
1061 
with ar[GetRandom(cnt)] do 

1062 
begin 

386  1063 
ar2[cnt2].x:= x; 
1064 
ar2[cnt2].y:= y; 

1065 
inc(cnt2) 

70  1066 
end 
386  1067 
until (x + Delta > Right); 
1068 
dec(Delta, 60) 

1069 
until (cnt2 > 0) or (Delta < 70); 

1070 
if cnt2 > 0 then 

1071 
with ar2[GetRandom(cnt2)] do 

1072 
begin 

498  1073 
Gear^.X:= int2hwFloat(x); 
1074 
Gear^.Y:= int2hwFloat(y); 

386  1075 
{$IFDEF DEBUGFILE} 
1076 
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); 

1077 
{$ENDIF} 

1078 
end 

1079 
else 

1080 
begin 

1081 
OutError('Can''t find place for Gear', false); 

1082 
DeleteGear(Gear) 

1083 
end 

10  1084 
end; 
1085 

4  1086 
initialization 
1087 

1088 
finalization 

95  1089 
FreeGearsList; 
4  1090 

1091 
end. 