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