author | unc0rr |
Tue, 19 Dec 2006 17:20:14 +0000 | |
changeset 305 | 1c1cd66ffcdc |
parent 303 | 1659c4aad5ab |
child 306 | 7b61834edcf6 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
47 | 3 |
* Copyright (c) 2004, 2005, 2006 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 |
|
21 |
uses SDLh, uConsts; |
|
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; |
108 | 31 |
X : Double; |
32 |
Y : Double; |
|
33 |
dX: Double; |
|
34 |
dY: Double; |
|
42 | 35 |
Kind: TGearType; |
36 |
Pos: Longword; |
|
4 | 37 |
doStep: TGearStepProcedure; |
53 | 38 |
Radius: integer; |
188 | 39 |
Angle, Power : Longword; |
107 | 40 |
DirAngle: Double; |
4 | 41 |
Timer : LongWord; |
108 | 42 |
Elasticity: Double; |
43 |
Friction : Double; |
|
4 | 44 |
Message : Longword; |
45 |
Hedgehog: pointer; |
|
38 | 46 |
Health, Damage: integer; |
4 | 47 |
CollIndex: Longword; |
6 | 48 |
Tag: integer; |
95 | 49 |
Surf: PSDL_Surface; |
293 | 50 |
Z: Longword; |
4 | 51 |
end; |
52 |
||
188 | 53 |
function AddGear(X, Y: integer; Kind: TGearType; State: Longword; const dX: Double=0.0; dY: Double=0.0; Timer: LongWord=0): PGear; |
4 | 54 |
procedure ProcessGears; |
55 |
procedure SetAllToActive; |
|
56 |
procedure SetAllHHToActive; |
|
57 |
procedure DrawGears(Surface: PSDL_Surface); |
|
58 |
procedure FreeGearsList; |
|
10 | 59 |
procedure AddMiscGears; |
293 | 60 |
procedure AddClouds; |
4 | 61 |
procedure AssignHHCoords; |
294 | 62 |
procedure InsertGearToList(Gear: PGear); |
63 |
procedure RemoveGearFromList(Gear: PGear); |
|
4 | 64 |
|
65 |
var CurAmmoGear: PGear = nil; |
|
68 | 66 |
GearsList: PGear = nil; |
70 | 67 |
|
4 | 68 |
implementation |
81 | 69 |
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, |
295 | 70 |
uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos; |
68 | 71 |
var RopePoints: record |
4 | 72 |
Count: Longword; |
73 |
HookAngle: integer; |
|
74 |
ar: array[0..300] of record |
|
107 | 75 |
X, Y: Double; |
76 |
dLen: Double; |
|
4 | 77 |
b: boolean; |
78 |
end; |
|
79 |
end; |
|
80 |
||
81 |
procedure DeleteGear(Gear: PGear); forward; |
|
82 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); forward; |
|
75 | 83 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); forward; |
79 | 84 |
procedure AmmoFlameWork(Ammo: PGear); forward; |
17 | 85 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; forward; |
15 | 86 |
procedure SpawnBoxOfSmth; forward; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
24
diff
changeset
|
87 |
procedure AfterAttack; forward; |
70 | 88 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); forward; |
302 | 89 |
procedure HedgehogStep(Gear: PGear); forward; |
303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset
|
90 |
procedure HedgehogChAngle(Gear: PGear); forward; |
4 | 91 |
|
92 |
{$INCLUDE GSHandlers.inc} |
|
93 |
{$INCLUDE HHHandlers.inc} |
|
94 |
||
95 |
const doStepHandlers: array[TGearType] of TGearStepProcedure = ( |
|
96 |
doStepCloud, |
|
97 |
doStepBomb, |
|
98 |
doStepHedgehog, |
|
99 |
doStepGrenade, |
|
100 |
doStepHealthTag, |
|
101 |
doStepGrave, |
|
102 |
doStepUFO, |
|
103 |
doStepShotgunShot, |
|
104 |
doStepPickHammer, |
|
105 |
doStepRope, |
|
9 | 106 |
doStepSmokeTrace, |
10 | 107 |
doStepExplosion, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
108 |
doStepMine, |
37 | 109 |
doStepCase, |
39 | 110 |
doStepDEagleShot, |
49 | 111 |
doStepDynamite, |
78 | 112 |
doStepTeamHealthSorter, |
113 |
doStepBomb, |
|
79 | 114 |
doStepCluster, |
115 |
doStepShover, |
|
82 | 116 |
doStepFlame, |
83 | 117 |
doStepFirePunch, |
118 |
doStepActionTimer, |
|
119 |
doStepActionTimer, |
|
211 | 120 |
doStepActionTimer, |
263 | 121 |
doStepParachute, |
122 |
doStepAirAttack, |
|
302 | 123 |
doStepAirBomb, |
124 |
doStepBlowTorch |
|
4 | 125 |
); |
126 |
||
294 | 127 |
procedure InsertGearToList(Gear: PGear); |
128 |
var tmp: PGear; |
|
129 |
begin |
|
130 |
if GearsList = nil then |
|
131 |
GearsList:= Gear |
|
132 |
else begin |
|
133 |
// WARNING: this code assumes that the first gears added to the list are clouds (have maximal Z) |
|
134 |
tmp:= GearsList; |
|
135 |
while (tmp <> nil) and (tmp.Z < Gear.Z) do |
|
136 |
tmp:= tmp.NextGear; |
|
137 |
||
138 |
if tmp.PrevGear <> nil then tmp.PrevGear.NextGear:= Gear; |
|
139 |
Gear.PrevGear:= tmp.PrevGear; |
|
140 |
tmp.PrevGear:= Gear; |
|
141 |
Gear.NextGear:= tmp; |
|
142 |
if GearsList = tmp then GearsList:= Gear |
|
143 |
end |
|
144 |
end; |
|
145 |
||
146 |
procedure RemoveGearFromList(Gear: PGear); |
|
147 |
begin |
|
148 |
if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; |
|
149 |
if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear |
|
150 |
else begin |
|
151 |
GearsList:= Gear.NextGear; |
|
152 |
if GearsList <> nil then GearsList.PrevGear:= nil |
|
153 |
end; |
|
154 |
end; |
|
155 |
||
188 | 156 |
function AddGear(X, Y: integer; Kind: TGearType; State: Longword; const dX: Double=0.0; dY: Double=0.0; Timer: LongWord=0): PGear; |
79 | 157 |
const Counter: Longword = 0; |
4 | 158 |
begin |
79 | 159 |
inc(Counter); |
108 | 160 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: ('+inttostr(x)+','+inttostr(y)+'), d('+floattostr(dX)+','+floattostr(dY)+')');{$ENDIF} |
4 | 161 |
New(Result); |
293 | 162 |
{$IFDEF DEBUGFILE}AddFileLog('AddGear: type = '+inttostr(ord(Kind))+'; handle = '+inttostr(integer(Result)));{$ENDIF} |
4 | 163 |
FillChar(Result^, sizeof(TGear), 0); |
164 |
Result.X:= X; |
|
165 |
Result.Y:= Y; |
|
166 |
Result.Kind := Kind; |
|
167 |
Result.State:= State; |
|
168 |
Result.Active:= true; |
|
169 |
Result.dX:= dX; |
|
170 |
Result.dY:= dY; |
|
171 |
Result.doStep:= doStepHandlers[Kind]; |
|
172 |
Result.CollIndex:= High(Longword); |
|
83 | 173 |
Result.Timer:= Timer; |
4 | 174 |
if CurrentTeam <> nil then |
175 |
Result.Hedgehog:= @CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]; |
|
176 |
case Kind of |
|
293 | 177 |
gtCloud: Result.Z:= High(Result.Z); |
4 | 178 |
gtAmmo_Bomb: begin |
53 | 179 |
Result.Radius:= 4; |
4 | 180 |
Result.Elasticity:= 0.6; |
181 |
Result.Friction:= 0.995; |
|
182 |
end; |
|
183 |
gtHedgehog: begin |
|
53 | 184 |
Result.Radius:= cHHRadius; |
149 | 185 |
Result.Elasticity:= 0.35; |
70 | 186 |
Result.Friction:= 0.999; |
64 | 187 |
Result.Angle:= cMaxAngle div 2; |
294 | 188 |
Result.Z:= cHHZ; |
4 | 189 |
end; |
190 |
gtAmmo_Grenade: begin |
|
53 | 191 |
Result.Radius:= 4; |
4 | 192 |
end; |
193 |
gtHealthTag: begin |
|
194 |
Result.Timer:= 1500; |
|
293 | 195 |
Result.Z:= 2000; |
4 | 196 |
end; |
197 |
gtGrave: begin |
|
53 | 198 |
Result.Radius:= 10; |
4 | 199 |
Result.Elasticity:= 0.6; |
200 |
end; |
|
201 |
gtUFO: begin |
|
53 | 202 |
Result.Radius:= 5; |
4 | 203 |
Result.Timer:= 500; |
204 |
Result.Elasticity:= 0.9 |
|
205 |
end; |
|
206 |
gtShotgunShot: begin |
|
207 |
Result.Timer:= 900; |
|
53 | 208 |
Result.Radius:= 2 |
4 | 209 |
end; |
210 |
gtPickHammer: begin |
|
53 | 211 |
Result.Radius:= 10; |
4 | 212 |
Result.Timer:= 4000 |
213 |
end; |
|
214 |
gtSmokeTrace: begin |
|
9 | 215 |
Result.X:= Result.X - 16; |
216 |
Result.Y:= Result.Y - 16; |
|
217 |
Result.State:= 8 |
|
4 | 218 |
end; |
219 |
gtRope: begin |
|
53 | 220 |
Result.Radius:= 3; |
4 | 221 |
Result.Friction:= 500; |
222 |
RopePoints.Count:= 0; |
|
223 |
end; |
|
9 | 224 |
gtExplosion: begin |
225 |
Result.X:= Result.X - 25; |
|
226 |
Result.Y:= Result.Y - 25; |
|
227 |
end; |
|
10 | 228 |
gtMine: begin |
53 | 229 |
Result.Radius:= 3; |
10 | 230 |
Result.Elasticity:= 0.55; |
231 |
Result.Friction:= 0.995; |
|
232 |
Result.Timer:= 3000; |
|
233 |
end; |
|
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
234 |
gtCase: begin |
75 | 235 |
Result.Radius:= 16; |
145 | 236 |
Result.Elasticity:= 0.4 |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
237 |
end; |
37 | 238 |
gtDEagleShot: begin |
53 | 239 |
Result.Radius:= 1; |
240 |
Result.Radius:= 1; |
|
38 | 241 |
Result.Health:= 50 |
37 | 242 |
end; |
39 | 243 |
gtDynamite: begin |
53 | 244 |
Result.Radius:= 3; |
56 | 245 |
Result.Elasticity:= 0.55; |
39 | 246 |
Result.Friction:= 0.03; |
247 |
Result.Timer:= 5000; |
|
248 |
end; |
|
78 | 249 |
gtClusterBomb: begin |
250 |
Result.Radius:= 4; |
|
251 |
Result.Elasticity:= 0.6; |
|
252 |
Result.Friction:= 0.995; |
|
253 |
end; |
|
79 | 254 |
gtFlame: begin |
255 |
Result.Angle:= Counter mod 64; |
|
256 |
Result.Radius:= 1; |
|
257 |
Result.Health:= 2; |
|
258 |
Result.dY:= (getrandom - 0.8) * 0.03; |
|
259 |
Result.dX:= (getrandom - 0.5) * 0.4 |
|
260 |
end; |
|
82 | 261 |
gtFirePunch: begin |
262 |
Result.Radius:= 15; |
|
263 |
Result.Tag:= Y |
|
264 |
end; |
|
302 | 265 |
gtAirBomb: begin |
266 |
Result.Radius:= 10; |
|
267 |
end; |
|
268 |
gtBlowTorch: begin |
|
305 | 269 |
Result.Radius:= cHHRadius + 6; |
303
1659c4aad5ab
Now blow torch angle can be changed during blowing :)
unc0rr
parents:
302
diff
changeset
|
270 |
Result.Timer:= 7500; |
302 | 271 |
end; |
4 | 272 |
end; |
294 | 273 |
InsertGearToList(Result) |
4 | 274 |
end; |
275 |
||
276 |
procedure DeleteGear(Gear: PGear); |
|
48 | 277 |
var team: PTeam; |
4 | 278 |
begin |
53 | 279 |
if Gear.CollIndex < High(Longword) then DeleteCI(Gear); |
95 | 280 |
if Gear.Surf <> nil then SDL_FreeSurface(Gear.Surf); |
4 | 281 |
if Gear.Kind = gtHedgehog then |
282 |
if CurAmmoGear <> nil then |
|
283 |
begin |
|
284 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: Sending gm_Destroy, hh handle = '+inttostr(integer(Gear)));{$ENDIF} |
|
285 |
Gear.Message:= gm_Destroy; |
|
286 |
CurAmmoGear.Message:= gm_Destroy; |
|
287 |
exit |
|
47 | 288 |
end else |
289 |
begin |
|
263 | 290 |
if Gear.Y >= cWaterLine then |
291 |
AddGear(Round(Gear.X), Round(Gear.Y), gtHealthTag, max(Gear.Damage, Gear.Health)).Hedgehog:= Gear.Hedgehog; |
|
48 | 292 |
team:= PHedgehog(Gear.Hedgehog).Team; |
145 | 293 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear = Gear then |
294 |
FreeActionsList; // to avoid ThinkThread on drawned gear |
|
263 | 295 |
PHedgehog(Gear.Hedgehog).Gear:= nil; |
48 | 296 |
RecountTeamHealth(team); |
47 | 297 |
end; |
95 | 298 |
{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} |
82 | 299 |
if CurAmmoGear = Gear then CurAmmoGear:= nil; |
4 | 300 |
if FollowGear = Gear then FollowGear:= nil; |
294 | 301 |
RemoveGearFromList(Gear); |
4 | 302 |
Dispose(Gear) |
303 |
end; |
|
304 |
||
305 |
function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs |
|
306 |
var Gear: PGear; |
|
307 |
begin |
|
308 |
Result:= true; |
|
309 |
Gear:= GearsList; |
|
310 |
while Gear <> nil do |
|
311 |
begin |
|
312 |
if Gear.Kind = gtHedgehog then |
|
313 |
if Gear.Damage <> 0 then |
|
314 |
begin |
|
315 |
Result:= false; |
|
316 |
if Gear.Health < Gear.Damage then Gear.Health:= 0 |
|
317 |
else dec(Gear.Health, Gear.Damage); |
|
293 | 318 |
AddGear(Round(Gear.X), round(Gear.Y) - cHHRadius - 12 - PHedgehog(Gear.Hedgehog)^.HealthTag.h, |
319 |
gtHealthTag, Gear.Damage).Hedgehog:= Gear.Hedgehog; |
|
4 | 320 |
RenderHealth(PHedgehog(Gear.Hedgehog)^); |
47 | 321 |
RecountTeamHealth(PHedgehog(Gear.Hedgehog)^.Team); |
4 | 322 |
|
323 |
Gear.Damage:= 0 |
|
324 |
end; |
|
325 |
Gear:= Gear.NextGear |
|
83 | 326 |
end; |
4 | 327 |
end; |
328 |
||
329 |
procedure ProcessGears; |
|
330 |
const delay: integer = cInactDelay; |
|
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
331 |
step: (stDelay, stChDmg, stChWin, stSpawn, stNTurn) = stDelay; |
4 | 332 |
var Gear, t: PGear; |
333 |
{$IFDEF COUNTTICKS} |
|
334 |
tickcntA, tickcntB: LongWord; |
|
335 |
const cntSecTicks: LongWord = 0; |
|
336 |
{$ENDIF} |
|
337 |
begin |
|
338 |
{$IFDEF COUNTTICKS} |
|
339 |
asm |
|
340 |
push eax |
|
341 |
push edx |
|
342 |
rdtsc |
|
343 |
mov tickcntA, eax |
|
344 |
mov tickcntB, edx |
|
345 |
pop edx |
|
346 |
pop eax |
|
347 |
end; |
|
348 |
{$ENDIF} |
|
349 |
AllInactive:= true; |
|
350 |
t:= GearsList; |
|
351 |
while t<>nil do |
|
352 |
begin |
|
353 |
Gear:= t; |
|
354 |
t:= Gear.NextGear; |
|
355 |
if Gear.Active then Gear.doStep(Gear); |
|
356 |
end; |
|
89 | 357 |
|
4 | 358 |
if AllInactive then |
15 | 359 |
case step of |
360 |
stDelay: begin |
|
361 |
dec(delay); |
|
362 |
if delay = 0 then |
|
363 |
begin |
|
364 |
inc(step); |
|
365 |
delay:= cInactDelay |
|
366 |
end |
|
367 |
end; |
|
368 |
stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; |
|
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
369 |
stChWin: if not CheckForWin then inc(step) else step:= stDelay; |
15 | 370 |
stSpawn: begin |
371 |
if not isInMultiShoot then SpawnBoxOfSmth; |
|
372 |
inc(step) |
|
373 |
end; |
|
374 |
stNTurn: begin |
|
74 | 375 |
AwareOfExplosion(0, 0, 0); |
15 | 376 |
if isInMultiShoot then isInMultiShoot:= false |
377 |
else ParseCommand('/nextturn'); |
|
378 |
step:= Low(step) |
|
379 |
end; |
|
380 |
end; |
|
381 |
||
4 | 382 |
if TurnTimeLeft > 0 then |
383 |
if CurrentTeam <> nil then |
|
384 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil then |
|
385 |
if ((CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.State and gstAttacking) = 0) |
|
386 |
and not isInMultiShoot then dec(TurnTimeLeft); |
|
74 | 387 |
|
4 | 388 |
inc(GameTicks); |
389 |
{$IFDEF COUNTTICKS} |
|
390 |
asm |
|
391 |
push eax |
|
392 |
push edx |
|
393 |
rdtsc |
|
394 |
sub eax, [tickcntA] |
|
395 |
sbb edx, [tickcntB] |
|
396 |
add [cntSecTicks], eax |
|
397 |
pop edx |
|
398 |
pop eax |
|
399 |
end; |
|
400 |
if (GameTicks and 1023) = 0 then |
|
401 |
begin |
|
402 |
cntTicks:= cntSecTicks shr 10; |
|
403 |
{$IFDEF DEBUGFILE} |
|
404 |
AddFileLog('<' + inttostr(cntTicks) + '>x1024 ticks'); |
|
405 |
{$ENDIF} |
|
406 |
cntSecTicks:= 0 |
|
407 |
end; |
|
408 |
{$ENDIF} |
|
409 |
end; |
|
410 |
||
411 |
procedure SetAllToActive; |
|
412 |
var t: PGear; |
|
413 |
begin |
|
414 |
AllInactive:= false; |
|
415 |
t:= GearsList; |
|
416 |
while t<>nil do |
|
417 |
begin |
|
418 |
t.Active:= true; |
|
419 |
t:= t.NextGear |
|
420 |
end |
|
421 |
end; |
|
422 |
||
423 |
procedure SetAllHHToActive; |
|
424 |
var t: PGear; |
|
425 |
begin |
|
426 |
AllInactive:= false; |
|
427 |
t:= GearsList; |
|
428 |
while t<>nil do |
|
429 |
begin |
|
430 |
if t.Kind = gtHedgehog then t.Active:= true; |
|
431 |
t:= t.NextGear |
|
432 |
end |
|
433 |
end; |
|
434 |
||
292 | 435 |
procedure DrawHH(Gear: PGear; Surface: PSDL_Surface); |
436 |
var t: integer; |
|
437 |
begin |
|
438 |
DrawHedgehog(Round(Gear.X) - 14 + WorldDx, Round(Gear.Y) - 18 + WorldDy, |
|
439 |
hwSign(Gear.dX), 0, |
|
440 |
PHedgehog(Gear.Hedgehog).visStepPos div 2, |
|
441 |
Surface); |
|
442 |
||
443 |
with PHedgehog(Gear.Hedgehog)^ do |
|
444 |
if Gear.State = 0 then |
|
445 |
begin |
|
446 |
t:= round(Gear.Y) - cHHRadius - 10 + WorldDy; |
|
447 |
dec(t, HealthTag.h + 2); |
|
448 |
DrawCentered(round(Gear.X) + WorldDx, t, HealthTag, Surface); |
|
449 |
dec(t, NameTag.h + 2); |
|
450 |
DrawCentered(round(Gear.X) + WorldDx, t, NameTag, Surface); |
|
451 |
dec(t, Team.NameTag.h + 2); |
|
452 |
DrawCentered(round(Gear.X) + WorldDx, t, Team.NameTag, Surface) |
|
453 |
end else // Current hedgehog |
|
454 |
begin |
|
455 |
if bShowFinger and ((Gear.State and gstHHDriven) <> 0) then |
|
456 |
DrawSprite(sprFinger, round(Gear.X) - 16 + WorldDx, round(Gear.Y) - 64 + WorldDy, |
|
457 |
GameTicks div 32 mod 16, Surface); |
|
458 |
if (Gear.State and (gstMoving or gstDrowning or gstFalling)) = 0 then |
|
459 |
if (Gear.State and gstHHThinking) <> 0 then |
|
460 |
DrawGear(sQuestion, Round(Gear.X) - 10 + WorldDx, Round(Gear.Y) - cHHRadius - 34 + WorldDy, Surface) |
|
461 |
else |
|
462 |
if ShowCrosshair and ((Gear.State and gstAttacked) = 0) then |
|
463 |
DrawSurfSprite(Round(Gear.X + hwSign(Gear.dX) * Sin(Gear.Angle*pi/cMaxAngle)*60) + WorldDx - 11, |
|
464 |
Round(Gear.Y - Cos(Gear.Angle*pi/cMaxAngle)*60) + WorldDy - 12, |
|
465 |
24, (18 + hwSign(Gear.dX) * integer(((Gear.Angle * 72 div cMaxAngle) + 1) div 2) mod 18) mod 18, |
|
466 |
Team.CrosshairSurf, Surface); |
|
467 |
end; |
|
468 |
end; |
|
469 |
||
4 | 470 |
procedure DrawGears(Surface: PSDL_Surface); |
471 |
var Gear: PGear; |
|
472 |
i: Longword; |
|
107 | 473 |
roplen: Double; |
4 | 474 |
|
475 |
procedure DrawRopeLine(X1, Y1, X2, Y2: integer); |
|
35 | 476 |
const nodlen = 5; |
477 |
var i, x, y: integer; |
|
107 | 478 |
t, k, ladd: Double; |
4 | 479 |
begin |
37 | 480 |
if (X1 = X2) and (Y1 = Y2) then |
481 |
begin |
|
83 | 482 |
OutError('WARNING: zero length rope line!'); |
37 | 483 |
exit |
484 |
end; |
|
4 | 485 |
if abs(X1 - X2) > abs(Y1 - Y2) then |
486 |
begin |
|
487 |
if X1 > X2 then |
|
488 |
begin |
|
489 |
i:= X1; |
|
490 |
X1:= X2; |
|
491 |
X2:= i; |
|
492 |
i:= Y1; |
|
493 |
Y1:= Y2; |
|
494 |
Y2:= i |
|
495 |
end; |
|
496 |
k:= (Y2 - Y1) / (X2 - X1); |
|
35 | 497 |
ladd:= sqrt(1 + sqr(k)); |
4 | 498 |
if X1 < 0 then |
499 |
begin |
|
500 |
t:= Y1 - 2 - k * X1; |
|
501 |
X1:= 0 |
|
502 |
end else t:= Y1 - 2; |
|
503 |
if X2 > cScreenWidth then X2:= cScreenWidth; |
|
35 | 504 |
for x:= X1 to X2 do |
505 |
begin |
|
506 |
roplen:= roplen + ladd; |
|
507 |
if roplen > nodlen then |
|
508 |
begin |
|
509 |
DrawGear(sRopeNode, x - 2, round(t) - 2, Surface); |
|
510 |
roplen:= roplen - nodlen; |
|
511 |
end; |
|
512 |
t:= t + k; |
|
513 |
end; |
|
4 | 514 |
end else |
515 |
begin |
|
516 |
if Y1 > Y2 then |
|
517 |
begin |
|
518 |
i:= X1; |
|
519 |
X1:= X2; |
|
520 |
X2:= i; |
|
521 |
i:= Y1; |
|
522 |
Y1:= Y2; |
|
523 |
Y2:= i |
|
524 |
end; |
|
525 |
k:= (X2 - X1) / (Y2 - Y1); |
|
35 | 526 |
ladd:= sqrt(1 + sqr(k)); |
4 | 527 |
if Y1 < 0 then |
528 |
begin |
|
529 |
t:= X1 - 2 - k * Y1; |
|
530 |
Y1:= 0 |
|
531 |
end else t:= X1 - 2; |
|
532 |
if Y2 > cScreenHeight then Y2:= cScreenHeight; |
|
35 | 533 |
for y:= Y1 to Y2 do |
534 |
begin |
|
535 |
roplen:= roplen + ladd; |
|
536 |
if roplen > nodlen then |
|
537 |
begin |
|
538 |
DrawGear(sRopeNode, round(t) - 2, y - 2, Surface); |
|
539 |
roplen:= roplen - nodlen; |
|
540 |
end; |
|
541 |
t:= t + k; |
|
542 |
end; |
|
4 | 543 |
end |
544 |
end; |
|
545 |
||
546 |
begin |
|
547 |
Gear:= GearsList; |
|
548 |
while Gear<>nil do |
|
549 |
begin |
|
550 |
case Gear.Kind of |
|
551 |
gtCloud: DrawSprite(sprCloud , Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
|
552 |
gtAmmo_Bomb: DrawSprite(sprBomb , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
292 | 553 |
gtHedgehog: DrawHH(Gear, Surface); |
4 | 554 |
gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
95 | 555 |
gtHealthTag: if Gear.Surf <> nil then DrawCentered(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.Surf, Surface); |
4 | 556 |
gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); |
557 |
gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); |
|
9 | 558 |
gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
4 | 559 |
gtRope: begin |
35 | 560 |
roplen:= 0; |
4 | 561 |
if RopePoints.Count > 0 then |
562 |
begin |
|
563 |
i:= 0; |
|
564 |
while i < Pred(RopePoints.Count) do |
|
565 |
begin |
|
566 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
567 |
Round(RopePoints.ar[Succ(i)].X) + WorldDx, Round(RopePoints.ar[Succ(i)].Y) + WorldDy); |
|
568 |
inc(i) |
|
569 |
end; |
|
570 |
DrawRopeLine(Round(RopePoints.ar[i].X) + WorldDx, Round(RopePoints.ar[i].Y) + WorldDy, |
|
571 |
Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy); |
|
35 | 572 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
573 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 574 |
DrawSprite(sprRopeHook, Round(RopePoints.ar[0].X) + WorldDx - 16, Round(RopePoints.ar[0].Y) + WorldDy - 16, RopePoints.HookAngle, Surface); |
575 |
end else |
|
35 | 576 |
begin |
577 |
DrawRopeLine(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, |
|
578 |
Round(PHedgehog(Gear.Hedgehog).Gear.X) + WorldDx, Round(PHedgehog(Gear.Hedgehog).Gear.Y) + WorldDy); |
|
4 | 579 |
DrawSprite(sprRopeHook, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
35 | 580 |
end; |
4 | 581 |
end; |
9 | 582 |
gtExplosion: DrawSprite(sprExplosion50, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); |
10 | 583 |
gtMine: if ((Gear.State and gstAttacking) = 0)or((Gear.Timer and $3FF) < 420) |
584 |
then DrawSprite(sprMineOff , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface) |
|
585 |
else DrawSprite(sprMineOn , Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
|
46 | 586 |
gtDynamite: DrawSprite2(sprDynamite, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 25 + WorldDy, Gear.Tag and 1, Gear.Tag shr 1, Surface); |
42 | 587 |
gtCase: case Gear.Pos of |
588 |
posCaseAmmo : DrawSprite(sprCase, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, 0, Surface); |
|
75 | 589 |
posCaseHealth: DrawSprite(sprFAid, Round(Gear.X) - 24 + WorldDx, Round(Gear.Y) - 24 + WorldDy, (GameTicks shr 6) mod 13, Surface); |
42 | 590 |
end; |
78 | 591 |
gtClusterBomb: DrawSprite(sprClusterBomb, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, trunc(Gear.DirAngle), Surface); |
592 |
gtCluster: DrawSprite(sprClusterParticle, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy, 0, Surface); |
|
79 | 593 |
gtFlame: DrawSprite(sprFlame, Round(Gear.X) - 8 + WorldDx, Round(Gear.Y) - 8 + WorldDy,(GameTicks div 128 + Gear.Angle) mod 8, Surface); |
263 | 594 |
gtAirBomb: DrawSprite(sprAirBomb , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); |
283 | 595 |
gtAirAttack: DrawSprite(sprAirplane, Round(Gear.X) - 60 + WorldDx, Round(Gear.Y) - 25 + WorldDy, 0, Surface); |
4 | 596 |
end; |
597 |
Gear:= Gear.NextGear |
|
598 |
end; |
|
599 |
end; |
|
600 |
||
601 |
procedure FreeGearsList; |
|
602 |
var t, tt: PGear; |
|
603 |
begin |
|
604 |
tt:= GearsList; |
|
605 |
GearsList:= nil; |
|
606 |
while tt<>nil do |
|
607 |
begin |
|
608 |
t:= tt; |
|
609 |
tt:= tt.NextGear; |
|
610 |
Dispose(t) |
|
611 |
end; |
|
612 |
end; |
|
613 |
||
10 | 614 |
procedure AddMiscGears; |
70 | 615 |
var i: integer; |
4 | 616 |
begin |
83 | 617 |
AddGear(0, 0, gtATStartGame, 0, 0, 0, 2000); |
22 | 618 |
if (GameFlags and gfForts) = 0 then |
619 |
for i:= 0 to 3 do |
|
70 | 620 |
FindPlace(AddGear(0, 0, gtMine, 0), false, 0, 2048); |
4 | 621 |
end; |
622 |
||
293 | 623 |
procedure AddClouds; |
624 |
var i: integer; |
|
625 |
begin |
|
626 |
for i:= 0 to cCloudsNumber do |
|
627 |
AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), |
|
628 |
(0.5-random)*0.1, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)) |
|
629 |
end; |
|
630 |
||
4 | 631 |
procedure doMakeExplosion(X, Y, Radius: integer; Mask: LongWord); |
632 |
var Gear: PGear; |
|
633 |
dmg: integer; |
|
634 |
begin |
|
635 |
TargetPoint.X:= NoPointX; |
|
636 |
{$IFDEF DEBUGFILE}if Radius > 3 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');{$ENDIF} |
|
305 | 637 |
if (Mask and EXPLDontDraw) = 0 then DrawExplosion(X, Y, Radius); |
9 | 638 |
if Radius = 50 then AddGear(X, Y, gtExplosion, 0); |
4 | 639 |
if (Mask and EXPLAutoSound)<>0 then PlaySound(sndExplosion); |
640 |
if (Mask and EXPLAllDamageInRadius)=0 then Radius:= Radius shl 1; |
|
641 |
Gear:= GearsList; |
|
642 |
while Gear <> nil do |
|
643 |
begin |
|
644 |
dmg:= Radius - Round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - Y))); |
|
645 |
if dmg > 0 then |
|
646 |
begin |
|
647 |
dmg:= dmg shr 1; |
|
648 |
case Gear.Kind of |
|
10 | 649 |
gtHedgehog, |
14
81f125629b25
- Mine checks whether a hedgehog is near less frequently
unc0rr
parents:
10
diff
changeset
|
650 |
gtMine, |
79 | 651 |
gtCase, |
652 |
gtFlame: begin |
|
39 | 653 |
if (Mask and EXPLNoDamage) = 0 then inc(Gear.Damage, dmg); |
42 | 654 |
if ((Mask and EXPLDoNotTouchHH) = 0) or (Gear.Kind <> gtHedgehog) then |
655 |
begin |
|
300 | 656 |
Gear.dX:= Gear.dX + (dmg / 200 + cHHKick)* hwSign(Gear.X - X); |
657 |
Gear.dY:= Gear.dY + (dmg / 200 + cHHKick)* hwSign(Gear.Y - Y); |
|
42 | 658 |
Gear.Active:= true; |
659 |
FollowGear:= Gear |
|
660 |
end; |
|
4 | 661 |
end; |
51 | 662 |
gtGrave: begin |
663 |
Gear.dY:= - dmg / 250; |
|
664 |
Gear.Active:= true; |
|
665 |
end; |
|
4 | 666 |
end; |
667 |
end; |
|
668 |
Gear:= Gear.NextGear |
|
80 | 669 |
end; |
670 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
4 | 671 |
end; |
672 |
||
75 | 673 |
procedure AmmoShove(Ammo: PGear; Damage, Power: integer); |
53 | 674 |
var t: PGearArray; |
675 |
i: integer; |
|
38 | 676 |
begin |
53 | 677 |
t:= CheckGearsCollision(Ammo); |
678 |
i:= t.Count; |
|
679 |
while i > 0 do |
|
680 |
begin |
|
681 |
dec(i); |
|
79 | 682 |
if (t.ar[i].State and gstNoDamage) = 0 then |
683 |
case t.ar[i].Kind of |
|
53 | 684 |
gtHedgehog, |
685 |
gtMine, |
|
686 |
gtCase: begin |
|
75 | 687 |
inc(t.ar[i].Damage, Damage); |
53 | 688 |
t.ar[i].dX:= Ammo.dX * Power * 0.01; |
689 |
t.ar[i].dY:= Ammo.dY * Power * 0.01; |
|
690 |
t.ar[i].Active:= true; |
|
691 |
DeleteCI(t.ar[i]); |
|
692 |
FollowGear:= t.ar[i] |
|
693 |
end; |
|
694 |
end |
|
126 | 695 |
end; |
696 |
SetAllToActive |
|
38 | 697 |
end; |
698 |
||
4 | 699 |
procedure AssignHHCoords; |
82 | 700 |
var Team: PTeam; |
701 |
i, t: integer; |
|
4 | 702 |
begin |
82 | 703 |
Team:= TeamsList; |
704 |
t:= 0; |
|
705 |
while Team <> nil do |
|
4 | 706 |
begin |
82 | 707 |
for i:= 0 to cMaxHHIndex do |
708 |
with Team.Hedgehogs[i] do |
|
709 |
if Gear <> nil then |
|
710 |
if (GameFlags and gfForts) = 0 then FindPlace(Gear, false, 0, 2048) |
|
711 |
else FindPlace(Gear, false, t, t + 1024); |
|
712 |
inc(t, 1024); |
|
713 |
Team:= Team.Next |
|
4 | 714 |
end |
715 |
end; |
|
716 |
||
15 | 717 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: integer): PGear; |
10 | 718 |
var t: PGear; |
719 |
begin |
|
720 |
t:= GearsList; |
|
721 |
rX:= sqr(rX); |
|
722 |
rY:= sqr(rY); |
|
723 |
while t <> nil do |
|
724 |
begin |
|
725 |
if (t <> Gear) and (t.Kind = Kind) then |
|
726 |
if sqr(Gear.X - t.X) / rX + sqr(Gear.Y - t.Y) / rY <= 1 then |
|
727 |
begin |
|
15 | 728 |
Result:= t; |
10 | 729 |
exit |
730 |
end; |
|
731 |
t:= t.NextGear |
|
732 |
end; |
|
15 | 733 |
Result:= nil |
734 |
end; |
|
735 |
||
79 | 736 |
procedure AmmoFlameWork(Ammo: PGear); |
737 |
var t: PGear; |
|
738 |
begin |
|
739 |
t:= GearsList; |
|
740 |
while t <> nil do |
|
741 |
begin |
|
742 |
if (t.Kind = gtHedgehog) and (t.Y < Ammo.Y) then |
|
743 |
if sqr(Ammo.X - t.X) + sqr(Ammo.Y - t.Y - cHHRadius) * 2 <= sqr(4) then |
|
744 |
begin |
|
745 |
inc(t.Damage, 5); |
|
746 |
t.dX:= t.dX + (t.X - Ammo.X) * 0.02; |
|
747 |
t.dY:= - 0.25; |
|
748 |
t.Active:= true; |
|
749 |
DeleteCI(t); |
|
750 |
FollowGear:= t |
|
751 |
end; |
|
752 |
t:= t.NextGear |
|
753 |
end; |
|
754 |
end; |
|
755 |
||
16 | 756 |
function CheckGearsNear(mX, mY: integer; Kind: TGearsType; rX, rY: integer): PGear; |
757 |
var t: PGear; |
|
758 |
begin |
|
759 |
t:= GearsList; |
|
760 |
rX:= sqr(rX); |
|
761 |
rY:= sqr(rY); |
|
762 |
while t <> nil do |
|
763 |
begin |
|
764 |
if t.Kind in Kind then |
|
765 |
if sqr(mX - t.X) / rX + sqr(mY - t.Y) / rY <= 1 then |
|
766 |
begin |
|
767 |
Result:= t; |
|
768 |
exit |
|
769 |
end; |
|
770 |
t:= t.NextGear |
|
771 |
end; |
|
772 |
Result:= nil |
|
773 |
end; |
|
774 |
||
775 |
function CountGears(Kind: TGearType): Longword; |
|
776 |
var t: PGear; |
|
777 |
begin |
|
778 |
Result:= 0; |
|
779 |
t:= GearsList; |
|
780 |
while t <> nil do |
|
781 |
begin |
|
782 |
if t.Kind = Kind then inc(Result); |
|
783 |
t:= t.NextGear |
|
784 |
end; |
|
785 |
end; |
|
786 |
||
15 | 787 |
procedure SpawnBoxOfSmth; |
788 |
begin |
|
295 | 789 |
if (CountGears(gtCase) >= 5) or (getrandom(cCaseFactor) <> 0) then exit; |
70 | 790 |
FollowGear:= AddGear(0, 0, gtCase, 0); |
295 | 791 |
case getrandom(2) of |
792 |
0: begin |
|
793 |
FollowGear.Health:= 25; |
|
794 |
FollowGear.Pos:= posCaseHealth |
|
795 |
end; |
|
796 |
1: begin |
|
797 |
FollowGear.Pos:= posCaseAmmo; |
|
798 |
FollowGear.State:= Longword(amMineStrike) |
|
799 |
end; |
|
800 |
end; |
|
70 | 801 |
FindPlace(FollowGear, true, 0, 2048) |
802 |
end; |
|
803 |
||
804 |
procedure FindPlace(Gear: PGear; withFall: boolean; Left, Right: integer); |
|
805 |
||
806 |
function CountNonZeroz(x, y, r: integer): integer; |
|
807 |
var i: integer; |
|
808 |
begin |
|
809 |
Result:= 0; |
|
810 |
if (y and $FFFFFC00) <> 0 then exit; |
|
811 |
for i:= max(x - r, 0) to min(x + r, 2043) do |
|
812 |
if Land[y, i] <> 0 then inc(Result) |
|
813 |
end; |
|
814 |
||
815 |
var fx, x: integer; |
|
816 |
y, sy: integer; |
|
817 |
ar: array[0..512] of TPoint; |
|
818 |
cnt, delta: Longword; |
|
819 |
begin |
|
820 |
fx:= Left + integer(GetRandom(Right - Left)); |
|
821 |
x:= fx; |
|
822 |
delta:= 130; |
|
16 | 823 |
repeat |
70 | 824 |
repeat |
825 |
inc(x, Gear.Radius); |
|
826 |
if x > Right then x:= Left + (x mod (Right - left)); |
|
827 |
cnt:= 0; |
|
828 |
y:= -Gear.Radius * 2; |
|
829 |
while y < 1023 do |
|
16 | 830 |
begin |
70 | 831 |
repeat |
832 |
inc(y, 2); |
|
833 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) = 0); |
|
834 |
sy:= y; |
|
835 |
repeat |
|
836 |
inc(y); |
|
837 |
until (y > 1023) or (CountNonZeroz(x, y, Gear.Radius - 1) <> 0); |
|
838 |
if (y - sy > Gear.Radius * 2) |
|
839 |
and (y < 1023) |
|
840 |
and (CheckGearsNear(x, y - Gear.Radius, [gtHedgehog, gtMine, gtCase], 110, 110) = nil) then |
|
841 |
begin |
|
842 |
ar[cnt].X:= x; |
|
843 |
if withFall then ar[cnt].Y:= sy + Gear.Radius |
|
844 |
else ar[cnt].Y:= y - Gear.Radius; |
|
845 |
inc(cnt) |
|
846 |
end; |
|
847 |
inc(y, 80) |
|
16 | 848 |
end; |
70 | 849 |
if cnt > 0 then |
850 |
with ar[GetRandom(cnt)] do |
|
851 |
begin |
|
852 |
Gear.X:= x; |
|
853 |
Gear.Y:= y; |
|
854 |
{$IFDEF DEBUGFILE} |
|
855 |
AddFileLog('Assigned Gear ' + inttostr(integer(Gear)) + |
|
856 |
' coordinates (' + inttostr(x) + |
|
857 |
',' + inttostr(y) + ')'); |
|
858 |
{$ENDIF} |
|
859 |
exit |
|
860 |
end |
|
861 |
until (x - Gear.Radius < fx) and (x + Gear.Radius > fx); |
|
862 |
dec(Delta, 20) |
|
863 |
until (Delta < 70); |
|
864 |
OutError('Couldn''t find place for Gear ' + inttostr(integer(Gear)), false); |
|
865 |
DeleteGear(Gear) |
|
10 | 866 |
end; |
867 |
||
4 | 868 |
initialization |
869 |
||
870 |
finalization |
|
95 | 871 |
FreeGearsList; |
4 | 872 |
|
873 |
end. |