author | unc0rr |
Fri, 07 Mar 2008 18:10:03 +0000 | |
changeset 803 | 3f73901a350a |
parent 802 | ed5450a89b96 |
child 809 | b33c2def1576 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2004-2007 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uGears; |
|
20 |
interface |
|
351 | 21 |
uses SDLh, uConsts, uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
23 |
const AllInactive: boolean = false; |
|
24 |
||
25 |
type PGear = ^TGear; |
|
26 |
TGearStepProcedure = procedure (Gear: PGear); |
|
27 |
TGear = record |
|
28 |
NextGear, PrevGear: PGear; |
|
29 |
Active: Boolean; |
|
188 | 30 |
State : Longword; |
351 | 31 |
X : hwFloat; |
32 |
Y : hwFloat; |
|
33 |
dX: hwFloat; |
|
34 |
dY: hwFloat; |
|
42 | 35 |
Kind: TGearType; |
36 |
Pos: Longword; |
|
4 | 37 |
doStep: TGearStepProcedure; |
371 | 38 |
Radius: LongInt; |
188 | 39 |
Angle, Power : Longword; |
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, |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
72 |
uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers, GL; |
789 | 73 |
|
74 |
const MAXROPEPOINTS = 300; |
|
68 | 75 |
var RopePoints: record |
4 | 76 |
Count: Longword; |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
77 |
HookAngle: GLfloat; |
789 | 78 |
ar: array[0..MAXROPEPOINTS] of record |
351 | 79 |
X, Y: hwFloat; |
80 |
dLen: hwFloat; |
|
4 | 81 |
b: boolean; |
82 |
end; |
|
83 |
end; |
|
307 | 84 |
StepDamage: Longword = 0; |
4 | 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 |
|
294 | 167 |
else begin |
351 | 168 |
GearsList:= Gear^.NextGear; |
169 |
if GearsList <> nil then GearsList^.PrevGear:= nil |
|
294 | 170 |
end; |
171 |
end; |
|
172 |
||
371 | 173 |
function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; |
79 | 174 |
const Counter: Longword = 0; |
351 | 175 |
var Result: PGear; |
4 | 176 |
begin |
79 | 177 |
inc(Counter); |
108 | 178 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF} |
4 | 179 |
New(Result); |
357 | 180 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: type = ' + inttostr(ord(Kind)));{$ENDIF} |
4 | 181 |
FillChar(Result^, sizeof(TGear), 0); |
498 | 182 |
Result^.X:= int2hwFloat(X); |
183 |
Result^.Y:= int2hwFloat(Y); |
|
351 | 184 |
Result^.Kind := Kind; |
185 |
Result^.State:= State; |
|
186 |
Result^.Active:= true; |
|
187 |
Result^.dX:= dX; |
|
188 |
Result^.dY:= dY; |
|
189 |
Result^.doStep:= doStepHandlers[Kind]; |
|
511 | 190 |
Result^.CollisionIndex:= -1; |
351 | 191 |
Result^.Timer:= Timer; |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
192 |
|
4 | 193 |
if CurrentTeam <> nil then |
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
194 |
begin |
602 | 195 |
Result^.Hedgehog:= CurrentHedgehog; |
196 |
Result^.IntersectGear:= CurrentHedgehog^.Gear |
|
505
fcba7d7aea0d
Fix old bug with grenade(bomd, etc..) not colliding with attacking hedgehog
unc0rr
parents:
503
diff
changeset
|
197 |
end; |
802
ed5450a89b96
Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
789
diff
changeset
|
198 |
|
4 | 199 |
case Kind of |
200 |
gtAmmo_Bomb: begin |
|
351 | 201 |
Result^.Radius:= 4; |
202 |
Result^.Elasticity:= _0_6; |
|
203 |
Result^.Friction:= _0_995; |
|
4 | 204 |
end; |
205 |
gtHedgehog: begin |
|
351 | 206 |
Result^.Radius:= cHHRadius; |
207 |
Result^.Elasticity:= _0_35; |
|
208 |
Result^.Friction:= _0_999; |
|
209 |
Result^.Angle:= cMaxAngle div 2; |
|
210 |
Result^.Z:= cHHZ; |
|
4 | 211 |
end; |
212 |
gtAmmo_Grenade: begin |
|
351 | 213 |
Result^.Radius:= 4; |
4 | 214 |
end; |
215 |
gtHealthTag: begin |
|
351 | 216 |
Result^.Timer:= 1500; |
522 | 217 |
Result^.Z:= 2001; |
4 | 218 |
end; |
219 |
gtGrave: begin |
|
351 | 220 |
Result^.Radius:= 10; |
221 |
Result^.Elasticity:= _0_6; |
|
4 | 222 |
end; |
223 |
gtUFO: begin |
|
351 | 224 |
Result^.Radius:= 5; |
225 |
Result^.Timer:= 500; |
|
226 |
Result^.Elasticity:= _0_9 |
|
4 | 227 |
end; |
228 |
gtShotgunShot: begin |
|
351 | 229 |
Result^.Timer:= 900; |
230 |
Result^.Radius:= 2 |
|
4 | 231 |
end; |
232 |
gtPickHammer: begin |
|
351 | 233 |
Result^.Radius:= 10; |
234 |
Result^.Timer:= 4000 |
|
4 | 235 |
end; |
236 |
gtSmokeTrace: begin |
|
498 | 237 |
Result^.X:= Result^.X - _16; |
238 |
Result^.Y:= Result^.Y - _16; |
|
351 | 239 |
Result^.State:= 8 |
4 | 240 |
end; |
241 |
gtRope: begin |
|
351 | 242 |
Result^.Radius:= 3; |
498 | 243 |
Result^.Friction:= _450; |
4 | 244 |
RopePoints.Count:= 0; |
245 |
end; |
|
9 | 246 |
gtExplosion: begin |
498 | 247 |
Result^.X:= Result^.X - _25; |
248 |
Result^.Y:= Result^.Y - _25; |
|
9 | 249 |
end; |
10 | 250 |
gtMine: begin |
503 | 251 |
Result^.State:= Result^.State or gstMoving; |
351 | 252 |
Result^.Radius:= 3; |
253 |
Result^.Elasticity:= _0_55; |
|
254 |
Result^.Friction:= _0_995; |
|
255 |
Result^.Timer:= 3000; |
|
10 | 256 |
end; |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
257 |
gtCase: begin |
351 | 258 |
Result^.Radius:= 16; |
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
595
diff
changeset
|
259 |
Result^.Elasticity:= _0_3 |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
260 |
end; |
37 | 261 |
gtDEagleShot: begin |
351 | 262 |
Result^.Radius:= 1; |
263 |
Result^.Health:= 50 |
|
37 | 264 |
end; |
39 | 265 |
gtDynamite: begin |
351 | 266 |
Result^.Radius:= 3; |
267 |
Result^.Elasticity:= _0_55; |
|
268 |
Result^.Friction:= _0_03; |
|
269 |
Result^.Timer:= 5000; |
|
39 | 270 |
end; |
78 | 271 |
gtClusterBomb: begin |
351 | 272 |
Result^.Radius:= 4; |
273 |
Result^.Elasticity:= _0_6; |
|
274 |
Result^.Friction:= _0_995; |
|
78 | 275 |
end; |
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; |
4 | 305 |
end; |
351 | 306 |
InsertGearToList(Result); |
307 |
AddGear:= Result |
|
4 | 308 |
end; |
309 |
||
310 |
procedure DeleteGear(Gear: PGear); |
|
48 | 311 |
var team: PTeam; |
307 | 312 |
t: Longword; |
4 | 313 |
begin |
503 | 314 |
DeleteCI(Gear); |
762 | 315 |
|
316 |
if Gear^.Tex <> nil then |
|
522 | 317 |
begin |
762 | 318 |
FreeTexture(Gear^.Tex); |
319 |
Gear^.Tex:= nil |
|
522 | 320 |
end; |
762 | 321 |
|
351 | 322 |
if Gear^.Kind = gtHedgehog then |
4 | 323 |
if CurAmmoGear <> nil then |
324 |
begin |
|
351 | 325 |
Gear^.Message:= gm_Destroy; |
326 |
CurAmmoGear^.Message:= gm_Destroy; |
|
4 | 327 |
exit |
47 | 328 |
end else |
329 |
begin |
|
498 | 330 |
if not (hwRound(Gear^.Y) < cWaterLine) then |
307 | 331 |
begin |
351 | 332 |
t:= max(Gear^.Damage, Gear^.Health); |
498 | 333 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtHealthTag, t, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
307 | 334 |
inc(StepDamage, t) |
335 |
end; |
|
351 | 336 |
team:= PHedgehog(Gear^.Hedgehog)^.Team; |
602 | 337 |
if CurrentHedgehog^.Gear = Gear then |
145 | 338 |
FreeActionsList; // to avoid ThinkThread on drawned gear |
351 | 339 |
PHedgehog(Gear^.Hedgehog)^.Gear:= nil; |
307 | 340 |
inc(KilledHHs); |
48 | 341 |
RecountTeamHealth(team); |
47 | 342 |
end; |
357 | 343 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear');{$ENDIF} |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
593
diff
changeset
|
344 |
if Gear^.TriggerId <> 0 then TickTrigger(Gear^.TriggerId); |
82 | 345 |
if CurAmmoGear = Gear then CurAmmoGear:= nil; |
4 | 346 |
if FollowGear = Gear then FollowGear:= nil; |
294 | 347 |
RemoveGearFromList(Gear); |
4 | 348 |
Dispose(Gear) |
349 |
end; |
|
350 |
||
351 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
352 |
var Gear: PGear; |
|
353 |
begin |
|
351 | 354 |
CheckNoDamage:= true; |
4 | 355 |
Gear:= GearsList; |
356 |
while Gear <> nil do |
|
357 |
begin |
|
351 | 358 |
if Gear^.Kind = gtHedgehog then |
359 |
if Gear^.Damage <> 0 then |
|
4 | 360 |
begin |
351 | 361 |
CheckNoDamage:= false; |
362 |
inc(StepDamage, Gear^.Damage); |
|
363 |
if Gear^.Health < Gear^.Damage then Gear^.Health:= 0 |
|
522 | 364 |
else dec(Gear^.Health, Gear^.Damage); |
365 |
AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12, |
|
498 | 366 |
gtHealthTag, Gear^.Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
351 | 367 |
RenderHealth(PHedgehog(Gear^.Hedgehog)^); |
368 |
RecountTeamHealth(PHedgehog(Gear^.Hedgehog)^.Team); |
|
369 |
||
370 |
Gear^.Damage:= 0 |
|
4 | 371 |
end; |
351 | 372 |
Gear:= Gear^.NextGear |
83 | 373 |
end; |
4 | 374 |
end; |
375 |
||
522 | 376 |
procedure AddDamageTag(X, Y, Damage: LongWord; Gear: PGear); |
377 |
begin |
|
529 | 378 |
if cAltDamage then |
379 |
AddGear(X, Y, gtSmallDamage, Damage, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; |
|
522 | 380 |
end; |
381 |
||
4 | 382 |
procedure ProcessGears; |
614 | 383 |
const delay: LongWord = 0; |
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
384 |
step: (stDelay, stChDmg, stChWin, stSpawn, stNTurn) = stDelay; |
4 | 385 |
var Gear, t: PGear; |
386 |
begin |
|
387 |
AllInactive:= true; |
|
388 |
t:= GearsList; |
|
389 |
while t<>nil do |
|
390 |
begin |
|
391 |
Gear:= t; |
|
351 | 392 |
t:= Gear^.NextGear; |
393 |
if Gear^.Active then Gear^.doStep(Gear); |
|
4 | 394 |
end; |
89 | 395 |
|
4 | 396 |
if AllInactive then |
15 | 397 |
case step of |
398 |
stDelay: begin |
|
399 |
if delay = 0 then |
|
400 |
delay:= cInactDelay |
|
614 | 401 |
else |
402 |
dec(delay); |
|
403 |
||
404 |
if delay = 0 then |
|
405 |
inc(step) |
|
15 | 406 |
end; |
407 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
351 | 408 |
stChWin: if not CheckForWin then inc(step) else step:= stDelay; |
15 | 409 |
stSpawn: begin |
410 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
411 |
inc(step) |
|
412 |
end; |
|
413 |
stNTurn: begin |
|
351 | 414 |
//AwareOfExplosion(0, 0, 0); |
15 | 415 |
if isInMultiShoot then isInMultiShoot:= false |
307 | 416 |
else begin |
602 | 417 |
with CurrentHedgehog^ do |
307 | 418 |
if MaxStepDamage < StepDamage then MaxStepDamage:= StepDamage; |
419 |
StepDamage:= 0; |
|
351 | 420 |
ParseCommand('/nextturn', true); |
307 | 421 |
end; |
15 | 422 |
step:= Low(step) |
423 |
end; |
|
424 |
end; |
|
425 |
||
4 | 426 |
if TurnTimeLeft > 0 then |
602 | 427 |
if CurrentHedgehog^.Gear <> nil then |
428 |
if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) |
|
4 | 429 |
and not isInMultiShoot then dec(TurnTimeLeft); |
351 | 430 |
|
651 | 431 |
if (not CurrentTeam^.ExtDriven) and |
656
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset
|
432 |
((GameTicks and $FFFF) = $FFFF) then |
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset
|
433 |
begin |
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset
|
434 |
SendIPCTimeInc; |
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset
|
435 |
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
|
436 |
end; |
6d6d9d7b1054
Fix network game bug caused by recent protocol changes
unc0rr
parents:
651
diff
changeset
|
437 |
|
515 | 438 |
inc(GameTicks) |
4 | 439 |
end; |
440 |
||
441 |
procedure SetAllToActive; |
|
442 |
var t: PGear; |
|
443 |
begin |
|
444 |
AllInactive:= false; |
|
445 |
t:= GearsList; |
|
351 | 446 |
while t <> nil do |
4 | 447 |
begin |
351 | 448 |
t^.Active:= true; |
449 |
t:= t^.NextGear |
|
4 | 450 |
end |
451 |
end; |
|
452 |
||
453 |
procedure SetAllHHToActive; |
|
454 |
var t: PGear; |
|
455 |
begin |
|
456 |
AllInactive:= false; |
|
457 |
t:= GearsList; |
|
351 | 458 |
while t <> nil do |
4 | 459 |
begin |
351 | 460 |
if t^.Kind = gtHedgehog then t^.Active:= true; |
461 |
t:= t^.NextGear |
|
4 | 462 |
end |
463 |
end; |
|
464 |
||
292 | 465 |
procedure DrawHH(Gear: PGear; Surface: PSDL_Surface); |
371 | 466 |
var t: LongInt; |
292 | 467 |
begin |
503 | 468 |
DrawHedgehog(hwRound(Gear^.X) - 15 + WorldDx, hwRound(Gear^.Y) - 18 + WorldDy, |
351 | 469 |
hwSign(Gear^.dX), 0, |
470 |
PHedgehog(Gear^.Hedgehog)^.visStepPos div 2, |
|
292 | 471 |
Surface); |
472 |
||
351 | 473 |
with PHedgehog(Gear^.Hedgehog)^ do |
538 | 474 |
if (Gear^.State{ and not gstAnimation}) = 0 then |
292 | 475 |
begin |
351 | 476 |
t:= hwRound(Gear^.Y) - cHHRadius - 10 + WorldDy; |
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
477 |
if (cTagsMask and 1) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
478 |
begin |
762 | 479 |
dec(t, HealthTagTex^.h + 2); |
480 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, HealthTagTex) |
|
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
481 |
end; |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
482 |
if (cTagsMask and 2) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
483 |
begin |
762 | 484 |
dec(t, NameTagTex^.h + 2); |
485 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, NameTagTex) |
|
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
486 |
end; |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
487 |
if (cTagsMask and 4) <> 0 then |
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
488 |
begin |
762 | 489 |
dec(t, Team^.NameTagTex^.h + 2); |
490 |
DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTagTex) |
|
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
538
diff
changeset
|
491 |
end |
292 | 492 |
end else // Current hedgehog |
538 | 493 |
if (Gear^.State and gstHHDriven) <> 0 then |
292 | 494 |
begin |
351 | 495 |
if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then |
496 |
DrawSprite(sprFinger, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 64 + WorldDy, |
|
292 | 497 |
GameTicks div 32 mod 16, Surface); |
542 | 498 |
if (Gear^.State and (gstMoving or gstDrowning)) = 0 then |
351 | 499 |
if (Gear^.State and gstHHThinking) <> 0 then |
688 | 500 |
DrawSprite(sprQuestion, hwRound(Gear^.X) - 10 + WorldDx, hwRound(Gear^.Y) - cHHRadius - 34 + WorldDy, 0, Surface) |
292 | 501 |
else |
351 | 502 |
if ShowCrosshair and ((Gear^.State and gstAttacked) = 0) then |
777 | 503 |
DrawRotatedTex(Team^.CrosshairTex, |
504 |
12, 12, |
|
505 |
Round(hwRound(Gear^.X) + |
|
506 |
hwSign(Gear^.dX) * Sin(Gear^.Angle*pi/cMaxAngle)*60) + WorldDx, |
|
507 |
Round(hwRound(Gear^.Y) - |
|
508 |
Cos(Gear^.Angle*pi/cMaxAngle)*60) + WorldDy, |
|
509 |
hwSign(Gear^.dX) * Gear^.Angle * 180 / cMaxAngle) |
|
292 | 510 |
end; |
511 |
end; |
|
512 |
||
4 | 513 |
procedure DrawGears(Surface: PSDL_Surface); |
514 |
var Gear: PGear; |
|
515 |
i: Longword; |
|
371 | 516 |
roplen: LongInt; |
4 | 517 |
|
371 | 518 |
procedure DrawRopeLine(X1, Y1, X2, Y2: LongInt); |
519 |
var eX, eY, dX, dY: LongInt; |
|
520 |
i, sX, sY, x, y, d: LongInt; |
|
366 | 521 |
b: boolean; |
4 | 522 |
begin |
37 | 523 |
if (X1 = X2) and (Y1 = Y2) then |
524 |
begin |
|
351 | 525 |
OutError('WARNING: zero length rope line!', false); |
37 | 526 |
exit |
527 |
end; |
|
366 | 528 |
eX:= 0; |
529 |
eY:= 0; |
|
530 |
dX:= X2 - X1; |
|
531 |
dY:= Y2 - Y1; |
|
532 |
||
533 |
if (dX > 0) then sX:= 1 |
|
534 |
else |
|
535 |
if (dX < 0) then |
|
536 |
begin |
|
537 |
sX:= -1; |
|
538 |
dX:= -dX |
|
539 |
end else sX:= dX; |
|
540 |
||
541 |
if (dY > 0) then sY:= 1 |
|
542 |
else |
|
543 |
if (dY < 0) then |
|
4 | 544 |
begin |
366 | 545 |
sY:= -1; |
546 |
dY:= -dY |
|
547 |
end else sY:= dY; |
|
548 |
||
549 |
if (dX > dY) then d:= dX |
|
550 |
else d:= dY; |
|
551 |
||
552 |
x:= X1; |
|
553 |
y:= Y1; |
|
554 |
||
555 |
for i:= 0 to d do |
|
556 |
begin |
|
557 |
inc(eX, dX); |
|
558 |
inc(eY, dY); |
|
559 |
b:= false; |
|
560 |
if (eX > d) then |
|
35 | 561 |
begin |
366 | 562 |
dec(eX, d); |
563 |
inc(x, sX); |
|
564 |
b:= true |
|
35 | 565 |
end; |
366 | 566 |
if (eY > d) then |
35 | 567 |
begin |
366 | 568 |
dec(eY, d); |
569 |
inc(y, sY); |
|
570 |
b:= true |
|
35 | 571 |
end; |
366 | 572 |
if b then |
573 |
begin |
|
574 |
inc(roplen); |
|
688 | 575 |
if (roplen mod 4) = 0 then DrawSprite(sprRopeNode, x - 2, y - 2, 0, Surface) |
366 | 576 |
end |
4 | 577 |
end |
366 | 578 |
end; |
4 | 579 |
|
580 |
begin |
|
581 |
Gear:= GearsList; |
|
582 |
while Gear<>nil do |
|
583 |
begin |
|
351 | 584 |
case Gear^.Kind of |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
585 |
gtAmmo_Bomb: DrawRotated(sprBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.DirAngle); |
292 | 586 |
gtHedgehog: DrawHH(Gear, Surface); |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
587 |
gtAmmo_Grenade: DrawRotated(sprGrenade, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, DxDy2Angle(Gear^.dY, Gear^.dX)); |
522 | 588 |
gtHealthTag, |
762 | 589 |
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
|
590 |
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 | 591 |
gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
4 | 592 |
gtRope: begin |
35 | 593 |
roplen:= 0; |
4 | 594 |
if RopePoints.Count > 0 then |
595 |
begin |
|
596 |
i:= 0; |
|
597 |
while i < Pred(RopePoints.Count) do |
|
598 |
begin |
|
351 | 599 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
600 |
hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
4 | 601 |
inc(i) |
602 |
end; |
|
351 | 603 |
DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, |
604 |
hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy); |
|
605 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
|
606 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
607 |
DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, RopePoints.HookAngle) |
4 | 608 |
end else |
35 | 609 |
begin |
351 | 610 |
DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, |
611 |
hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx, hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy); |
|
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
612 |
DrawRotated(sprRopeHook, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, DxDy2Angle(Gear^.dY, Gear^.dX)); |
35 | 613 |
end; |
4 | 614 |
end; |
568 | 615 |
gtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
351 | 616 |
gtExplosion: DrawSprite(sprExplosion50, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface); |
617 |
gtMine: if ((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420) |
|
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
618 |
then DrawRotated(sprMineOff, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.DirAngle) |
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
619 |
else DrawRotated(sprMineOn, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.DirAngle); |
351 | 620 |
gtCase: case Gear^.Pos of |
621 |
posCaseAmmo : DrawSprite(sprCase, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0, Surface); |
|
622 |
posCaseHealth: DrawSprite(sprFAid, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
|
42 | 623 |
end; |
568 | 624 |
gtDynamite: DrawSprite2(sprDynamite, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, Gear^.Tag and 1, Gear^.Tag shr 1, Surface); |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
625 |
gtClusterBomb: DrawRotated(sprClusterBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.DirAngle); |
351 | 626 |
gtCluster: DrawSprite(sprClusterParticle, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, 0, Surface); |
627 |
gtFlame: DrawSprite(sprFlame, hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy,(GameTicks div 128 + Gear^.Angle) mod 8, Surface); |
|
568 | 628 |
gtParachute: DrawSprite(sprParachute, hwRound(Gear^.X) - 24 + WorldDx, hwRound(Gear^.Y) - 48 + WorldDy, 0, Surface); |
408 | 629 |
gtAirAttack: if Gear^.Tag > 0 then DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 0, Surface) |
534 | 630 |
else DrawSprite(sprAirplane, hwRound(Gear^.X) - 60 + WorldDx, hwRound(Gear^.Y) - 25 + WorldDy, 1, Surface); |
776
8fc7e59d9cb4
Convert the rest of rotated sprites to be rotated by OpenGL
unc0rr
parents:
775
diff
changeset
|
631 |
gtAirBomb: DrawRotated(sprAirBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, DxDy2Angle(Gear^.dY, Gear^.dX)); |
708 | 632 |
gtSwitcher: DrawSprite(sprSwitch, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 56 + WorldDy, (GameTicks shr 6) mod 12, Surface); |
593 | 633 |
gtTarget: DrawSprite(sprTarget, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, 0, Surface); |
4 | 634 |
end; |
351 | 635 |
Gear:= Gear^.NextGear |
4 | 636 |
end; |
637 |
end; |
|
638 |
||
639 |
procedure FreeGearsList; |
|
640 |
var t, tt: PGear; |
|
641 |
begin |
|
642 |
tt:= GearsList; |
|
643 |
GearsList:= nil; |
|
644 |
while tt<>nil do |
|
645 |
begin |
|
646 |
t:= tt; |
|
351 | 647 |
tt:= tt^.NextGear; |
4 | 648 |
Dispose(t) |
649 |
end; |
|
650 |
end; |
|
651 |
||
10 | 652 |
procedure AddMiscGears; |
371 | 653 |
var i: LongInt; |
4 | 654 |
begin |
498 | 655 |
AddGear(0, 0, gtATStartGame, 0, _0, _0, 2000); |
22 | 656 |
if (GameFlags and gfForts) = 0 then |
622 | 657 |
for i:= 0 to Pred(cLandAdditions) do |
498 | 658 |
FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048); |
4 | 659 |
end; |
660 |
||
371 | 661 |
procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); |
4 | 662 |
var Gear: PGear; |
506 | 663 |
dmg, dmgRadius: LongInt; |
4 | 664 |
begin |
665 |
TargetPoint.X:= NoPointX; |
|
666 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
498 | 667 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0, _0, _0, 0); |
355 | 668 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion, false); |
506 | 669 |
if (Mask and EXPLAllDamageInRadius)=0 then dmgRadius:= Radius shl 1 |
670 |
else dmgRadius:= Radius; |
|
4 | 671 |
Gear:= GearsList; |
672 |
while Gear <> nil do |
|
673 |
begin |
|
506 | 674 |
dmg:= dmgRadius - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
538 | 675 |
if (dmg > 1) and |
522 | 676 |
((Gear^.State and gstNoDamage) = 0) then |
4 | 677 |
begin |
355 | 678 |
dmg:= dmg div 2; |
351 | 679 |
case Gear^.Kind of |
10 | 680 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
681 |
gtMine, |
79 | 682 |
gtCase, |
593 | 683 |
gtTarget, |
79 | 684 |
gtFlame: begin |
355 | 685 |
{$IFDEF DEBUGFILE}AddFileLog('Damage: ' + inttostr(dmg));{$ENDIF} |
522 | 686 |
if (Mask and EXPLNoDamage) = 0 then |
687 |
begin |
|
688 |
inc(Gear^.Damage, dmg); |
|
689 |
if Gear^.Kind = gtHedgehog then |
|
690 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear) |
|
691 |
end; |
|
351 | 692 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog) then |
42 | 693 |
begin |
506 | 694 |
DeleteCI(Gear); |
498 | 695 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - int2hwFloat(X)); |
696 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - int2hwFloat(Y)); |
|
503 | 697 |
Gear^.State:= Gear^.State or gstMoving; |
351 | 698 |
Gear^.Active:= true; |
42 | 699 |
FollowGear:= Gear |
700 |
end; |
|
4 | 701 |
end; |
51 | 702 |
gtGrave: begin |
351 | 703 |
Gear^.dY:= - _0_004 * dmg; |
704 |
Gear^.Active:= true; |
|
51 | 705 |
end; |
4 | 706 |
end; |
707 |
end; |
|
351 | 708 |
Gear:= Gear^.NextGear |
80 | 709 |
end; |
621 | 710 |
if (Mask and EXPLDontDraw) = 0 then |
711 |
if (GameFlags and gfSolidLand) = 0 then DrawExplosion(X, Y, Radius); |
|
498 | 712 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
4 | 713 |
end; |
714 |
||
506 | 715 |
procedure ShotgunShot(Gear: PGear); |
716 |
var t: PGear; |
|
717 |
dmg: integer; |
|
522 | 718 |
hh: PHedgehog; |
506 | 719 |
begin |
509 | 720 |
Gear^.Radius:= cShotgunRadius; |
522 | 721 |
hh:= Gear^.Hedgehog; |
506 | 722 |
t:= GearsList; |
723 |
while t <> nil do |
|
724 |
begin |
|
725 |
dmg:= min(Gear^.Radius + t^.Radius - hwRound(Distance(Gear^.X - t^.X, Gear^.Y - t^.Y)), 25); |
|
538 | 726 |
if dmg > 0 then |
506 | 727 |
case t^.Kind of |
728 |
gtHedgehog, |
|
729 |
gtMine, |
|
593 | 730 |
gtCase, |
731 |
gtTarget: begin |
|
506 | 732 |
inc(t^.Damage, dmg); |
522 | 733 |
if t^.Kind = gtHedgehog then |
734 |
begin |
|
531 | 735 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, t); |
522 | 736 |
inc(hh^.DamageGiven, dmg) |
737 |
end; |
|
506 | 738 |
DeleteCI(t); |
739 |
t^.dX:= t^.dX + SignAs(Gear^.dX * dmg * _0_01 + cHHKick, t^.X - Gear^.X); |
|
740 |
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; |
|
741 |
t^.State:= t^.State or gstMoving; |
|
742 |
t^.Active:= true; |
|
743 |
FollowGear:= t |
|
744 |
end; |
|
745 |
gtGrave: begin |
|
746 |
t^.dY:= - _0_1; |
|
747 |
t^.Active:= true |
|
748 |
end; |
|
749 |
end; |
|
750 |
t:= t^.NextGear |
|
751 |
end; |
|
621 | 752 |
if (GameFlags and gfSolidLand) = 0 then DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) |
506 | 753 |
end; |
754 |
||
371 | 755 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
53 | 756 |
var t: PGearArray; |
371 | 757 |
i: LongInt; |
307 | 758 |
hh: PHedgehog; |
38 | 759 |
begin |
53 | 760 |
t:= CheckGearsCollision(Ammo); |
351 | 761 |
i:= t^.Count; |
762 |
hh:= Ammo^.Hedgehog; |
|
53 | 763 |
while i > 0 do |
764 |
begin |
|
765 |
dec(i); |
|
351 | 766 |
if (t^.ar[i]^.State and gstNoDamage) = 0 then |
767 |
case t^.ar[i]^.Kind of |
|
53 | 768 |
gtHedgehog, |
769 |
gtMine, |
|
593 | 770 |
gtTarget, |
53 | 771 |
gtCase: begin |
351 | 772 |
inc(t^.ar[i]^.Damage, Damage); |
522 | 773 |
if t^.ar[i]^.Kind = gtHedgehog then |
774 |
begin |
|
775 |
AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]); |
|
776 |
inc(hh^.DamageGiven, Damage) |
|
777 |
end; |
|
538 | 778 |
DeleteCI(t^.ar[i]); |
351 | 779 |
t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01; |
780 |
t^.ar[i]^.dY:= Ammo^.dY * Power * _0_01; |
|
781 |
t^.ar[i]^.Active:= true; |
|
503 | 782 |
t^.ar[i]^.State:= t^.ar[i]^.State or gstMoving; |
351 | 783 |
FollowGear:= t^.ar[i] |
53 | 784 |
end; |
785 |
end |
|
126 | 786 |
end; |
787 |
SetAllToActive |
|
38 | 788 |
end; |
789 |
||
4 | 790 |
procedure AssignHHCoords; |
547 | 791 |
var i, t, p: LongInt; |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
792 |
ar: array[0..Pred(cMaxHHs)] of PGear; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
793 |
Count: Longword; |
4 | 794 |
begin |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
795 |
if (GameFlags and gfForts) <> 0 then |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
796 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
797 |
t:= 0; |
547 | 798 |
for p:= 0 to Pred(TeamsCount) do |
799 |
with TeamsArray[p]^ do |
|
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
800 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
801 |
for i:= 0 to cMaxHHIndex do |
547 | 802 |
with Hedgehogs[i] do |
604
2f1165467a66
Let hedgehog position be taken from config, still more work is needed
unc0rr
parents:
602
diff
changeset
|
803 |
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
|
804 |
inc(t, 1024); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
805 |
end |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
806 |
end else // mix hedgehogs |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
807 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
808 |
Count:= 0; |
547 | 809 |
for p:= 0 to Pred(TeamsCount) do |
810 |
with TeamsArray[p]^ do |
|
4 | 811 |
begin |
82 | 812 |
for i:= 0 to cMaxHHIndex do |
547 | 813 |
with Hedgehogs[i] do |
604
2f1165467a66
Let hedgehog position be taken from config, still more work is needed
unc0rr
parents:
602
diff
changeset
|
814 |
if (Gear <> nil) and (Gear^.X.QWordValue = 0) then |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
815 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
816 |
ar[Count]:= Gear; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
817 |
inc(Count) |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
818 |
end; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
819 |
end; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
820 |
|
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
821 |
while (Count > 0) do |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
822 |
begin |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
823 |
i:= GetRandom(Count); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
824 |
FindPlace(ar[i], false, 0, 2048); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
825 |
ar[i]:= ar[Count - 1]; |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
826 |
dec(Count) |
4 | 827 |
end |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
542
diff
changeset
|
828 |
end |
4 | 829 |
end; |
830 |
||
371 | 831 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
10 | 832 |
var t: PGear; |
833 |
begin |
|
834 |
t:= GearsList; |
|
835 |
rX:= sqr(rX); |
|
836 |
rY:= sqr(rY); |
|
837 |
while t <> nil do |
|
838 |
begin |
|
351 | 839 |
if (t <> Gear) and (t^.Kind = Kind) then |
498 | 840 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
351 | 841 |
exit(t); |
842 |
t:= t^.NextGear |
|
10 | 843 |
end; |
351 | 844 |
CheckGearNear:= nil |
15 | 845 |
end; |
846 |
||
79 | 847 |
procedure AmmoFlameWork(Ammo: PGear); |
848 |
var t: PGear; |
|
849 |
begin |
|
850 |
t:= GearsList; |
|
851 |
while t <> nil do |
|
852 |
begin |
|
351 | 853 |
if (t^.Kind = gtHedgehog) and (t^.Y < Ammo^.Y) then |
498 | 854 |
if not (hwSqr(Ammo^.X - t^.X) + hwSqr(Ammo^.Y - t^.Y - int2hwFloat(cHHRadius)) * 2 > _2) then |
79 | 855 |
begin |
351 | 856 |
inc(t^.Damage, 5); |
857 |
t^.dX:= t^.dX + (t^.X - Ammo^.X) * _0_02; |
|
858 |
t^.dY:= - _0_25; |
|
859 |
t^.Active:= true; |
|
79 | 860 |
DeleteCI(t); |
861 |
FollowGear:= t |
|
862 |
end; |
|
351 | 863 |
t:= t^.NextGear |
79 | 864 |
end; |
865 |
end; |
|
866 |
||
371 | 867 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
16 | 868 |
var t: PGear; |
869 |
begin |
|
870 |
t:= GearsList; |
|
871 |
rX:= sqr(rX); |
|
872 |
rY:= sqr(rY); |
|
873 |
while t <> nil do |
|
874 |
begin |
|
351 | 875 |
if t^.Kind in Kind then |
498 | 876 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
351 | 877 |
exit(t); |
878 |
t:= t^.NextGear |
|
16 | 879 |
end; |
351 | 880 |
CheckGearsNear:= nil |
16 | 881 |
end; |
882 |
||
883 |
function CountGears(Kind: TGearType): Longword; |
|
884 |
var t: PGear; |
|
351 | 885 |
Result: Longword; |
16 | 886 |
begin |
887 |
Result:= 0; |
|
888 |
t:= GearsList; |
|
889 |
while t <> nil do |
|
890 |
begin |
|
351 | 891 |
if t^.Kind = Kind then inc(Result); |
892 |
t:= t^.NextGear |
|
16 | 893 |
end; |
351 | 894 |
CountGears:= Result |
16 | 895 |
end; |
896 |
||
15 | 897 |
procedure SpawnBoxOfSmth; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
898 |
var t: LongInt; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
899 |
i: TAmmoType; |
15 | 900 |
begin |
614 | 901 |
if (cCaseFactor = 0) or |
902 |
(CountGears(gtCase) >= 5) or |
|
903 |
(getrandom(cCaseFactor) <> 0) then exit; |
|
498 | 904 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
295 | 905 |
case getrandom(2) of |
906 |
0: begin |
|
351 | 907 |
FollowGear^.Health:= 25; |
908 |
FollowGear^.Pos:= posCaseHealth |
|
295 | 909 |
end; |
910 |
1: begin |
|
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
911 |
t:= 0; |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
912 |
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
|
913 |
inc(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
914 |
t:= GetRandom(t); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
915 |
i:= Low(TAmmoType); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
916 |
dec(t, Ammoz[i].Probability); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
917 |
while t >= 0 do |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
918 |
begin |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
919 |
inc(i); |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
920 |
dec(t, Ammoz[i].Probability) |
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
921 |
end; |
351 | 922 |
FollowGear^.Pos:= posCaseAmmo; |
394
4c017ae1226a
- Implement hack to let ammo stores work without needed assistance of frontend
unc0rr
parents:
393
diff
changeset
|
923 |
FollowGear^.State:= Longword(i) |
295 | 924 |
end; |
925 |
end; |
|
70 | 926 |
FindPlace(FollowGear, true, 0, 2048) |
927 |
end; |
|
928 |
||
371 | 929 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: LongInt); |
70 | 930 |
|
371 | 931 |
function CountNonZeroz(x, y, r: LongInt): LongInt; |
932 |
var i: LongInt; |
|
933 |
Result: LongInt; |
|
70 | 934 |
begin |
935 |
Result:= 0; |
|
701 | 936 |
if (y and $FFFFFC00) = 0 then |
937 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
351 | 938 |
if Land[y, i] <> 0 then inc(Result); |
939 |
CountNonZeroz:= Result |
|
70 | 940 |
end; |
941 |
||
495 | 942 |
var x: LongInt; |
371 | 943 |
y, sy: LongInt; |
386 | 944 |
ar: array[0..511] of TPoint; |
945 |
ar2: array[0..1023] of TPoint; |
|
392 | 946 |
cnt, cnt2: Longword; |
947 |
delta: LongInt; |
|
70 | 948 |
begin |
386 | 949 |
delta:= 250; |
950 |
cnt2:= 0; |
|
16 | 951 |
repeat |
392 | 952 |
x:= Left + LongInt(GetRandom(Delta)); |
70 | 953 |
repeat |
386 | 954 |
inc(x, Delta); |
70 | 955 |
cnt:= 0; |
351 | 956 |
y:= -Gear^.Radius * 2; |
70 | 957 |
while y < 1023 do |
16 | 958 |
begin |
70 | 959 |
repeat |
701 | 960 |
inc(y, 2); |
351 | 961 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0); |
70 | 962 |
sy:= y; |
963 |
repeat |
|
964 |
inc(y); |
|
351 | 965 |
until (y > 1023) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0); |
966 |
if (y - sy > Gear^.Radius * 2) |
|
70 | 967 |
and (y < 1023) |
351 | 968 |
and (CheckGearsNear(x, y - Gear^.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
70 | 969 |
begin |
970 |
ar[cnt].X:= x; |
|
351 | 971 |
if withFall then ar[cnt].Y:= sy + Gear^.Radius |
972 |
else ar[cnt].Y:= y - Gear^.Radius; |
|
70 | 973 |
inc(cnt) |
974 |
end; |
|
386 | 975 |
inc(y, 45) |
16 | 976 |
end; |
70 | 977 |
if cnt > 0 then |
978 |
with ar[GetRandom(cnt)] do |
|
979 |
begin |
|
386 | 980 |
ar2[cnt2].x:= x; |
981 |
ar2[cnt2].y:= y; |
|
982 |
inc(cnt2) |
|
70 | 983 |
end |
386 | 984 |
until (x + Delta > Right); |
985 |
dec(Delta, 60) |
|
986 |
until (cnt2 > 0) or (Delta < 70); |
|
987 |
if cnt2 > 0 then |
|
988 |
with ar2[GetRandom(cnt2)] do |
|
989 |
begin |
|
498 | 990 |
Gear^.X:= int2hwFloat(x); |
991 |
Gear^.Y:= int2hwFloat(y); |
|
386 | 992 |
{$IFDEF DEBUGFILE} |
993 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
994 |
{$ENDIF} |
|
995 |
end |
|
996 |
else |
|
997 |
begin |
|
998 |
OutError('Can''t find place for Gear', false); |
|
999 |
DeleteGear(Gear) |
|
1000 |
end |
|
10 | 1001 |
end; |
1002 |
||
4 | 1003 |
initialization |
1004 |
||
1005 |
finalization |
|
95 | 1006 |
FreeGearsList; |
4 | 1007 |
|
1008 |
end. |