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