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