author | nemo |
Wed, 14 Mar 2012 21:12:04 -0400 | |
changeset 6785 | a8aa5984185f |
parent 6769 | 44ad49a3a126 |
child 6803 | 0e70f3ea3bf8 |
permissions | -rw-r--r-- |
6581 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
6581 | 4 |
* |
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 |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
*) |
|
18 |
||
19 |
{$INCLUDE "options.inc"} |
|
20 |
||
21 |
unit uGearsUtils; |
|
22 |
interface |
|
23 |
uses uTypes; |
|
24 |
||
25 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); |
|
26 |
function ModifyDamage(dmg: Longword; Gear: PGear): Longword; |
|
27 |
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); |
|
28 |
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword); |
|
29 |
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource); |
|
30 |
procedure CheckHHDamage(Gear: PGear); |
|
31 |
procedure CalcRotationDirAngle(Gear: PGear); |
|
32 |
procedure ResurrectHedgehog(gear: PGear); |
|
33 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean = false); |
|
34 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
|
35 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
|
36 |
function CheckGearDrowning(Gear: PGear): boolean; |
|
37 |
||
38 |
var doStepHandlers: array[TGearType] of TGearStepProcedure; |
|
39 |
||
40 |
||
41 |
implementation |
|
42 |
uses uFloat, uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc, |
|
43 |
uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore, |
|
44 |
uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, uGears, |
|
45 |
uGearsList; |
|
46 |
||
47 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); |
|
48 |
var Gear: PGear; |
|
6769
44ad49a3a126
Add drowning to grenade too, try some little optimisations
nemo
parents:
6765
diff
changeset
|
49 |
dmg, dmgBase: LongInt; |
6765 | 50 |
fX, fY, tdX, tdY: hwFloat; |
6581 | 51 |
vg: PVisualGear; |
52 |
i, cnt: LongInt; |
|
53 |
begin |
|
54 |
if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
55 |
if Radius > 25 then KickFlakes(Radius, X, Y); |
|
56 |
||
57 |
if ((Mask and EXPLNoGfx) = 0) then |
|
58 |
begin |
|
59 |
vg:= nil; |
|
60 |
if Radius > 50 then vg:= AddVisualGear(X, Y, vgtBigExplosion) |
|
61 |
else if Radius > 10 then vg:= AddVisualGear(X, Y, vgtExplosion); |
|
62 |
if vg <> nil then |
|
63 |
vg^.Tint:= Tint; |
|
64 |
end; |
|
65 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion); |
|
66 |
||
6765 | 67 |
(*if (Mask and EXPLAllDamageInRadius) = 0 then |
6581 | 68 |
dmgRadius:= Radius shl 1 |
69 |
else |
|
70 |
dmgRadius:= Radius; |
|
6765 | 71 |
dmgBase:= dmgRadius + cHHRadius div 2;*) |
72 |
dmgBase:= Radius shl 1 + cHHRadius div 2; |
|
6581 | 73 |
fX:= int2hwFloat(X); |
74 |
fY:= int2hwFloat(Y); |
|
75 |
Gear:= GearsList; |
|
76 |
while Gear <> nil do |
|
77 |
begin |
|
78 |
dmg:= 0; |
|
79 |
//dmg:= dmgRadius + cHHRadius div 2 - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
|
80 |
//if (dmg > 1) and |
|
81 |
if (Gear^.State and gstNoDamage) = 0 then |
|
82 |
begin |
|
83 |
case Gear^.Kind of |
|
84 |
gtHedgehog, |
|
85 |
gtMine, |
|
86 |
gtBall, |
|
87 |
gtMelonPiece, |
|
88 |
gtGrenade, |
|
89 |
gtClusterBomb, |
|
90 |
// gtCluster, too game breaking I think |
|
91 |
gtSMine, |
|
92 |
gtCase, |
|
93 |
gtTarget, |
|
94 |
gtFlame, |
|
95 |
gtExplosives, |
|
96 |
gtStructure: begin |
|
97 |
// Run the calcs only once we know we have a type that will need damage |
|
6765 | 98 |
tdX:= Gear^.X-fX; |
99 |
tdY:= Gear^.Y-fY; |
|
100 |
if hwRound(hwAbs(tdX)+hwAbs(tdY)) < dmgBase then |
|
101 |
dmg:= dmgBase - max(hwRound(Distance(tdX, tdY)),Gear^.Radius); |
|
6581 | 102 |
if dmg > 1 then |
103 |
begin |
|
104 |
dmg:= ModifyDamage(min(dmg div 2, Radius), Gear); |
|
105 |
//AddFileLog('Damage: ' + inttostr(dmg)); |
|
106 |
if (Mask and EXPLNoDamage) = 0 then |
|
107 |
begin |
|
108 |
if not Gear^.Invulnerable then |
|
109 |
ApplyDamage(Gear, AttackingHog, dmg, dsExplosion) |
|
110 |
else |
|
111 |
Gear^.State:= Gear^.State or gstWinner; |
|
112 |
end; |
|
113 |
if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then |
|
114 |
begin |
|
115 |
DeleteCI(Gear); |
|
6765 | 116 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, tdX)/(Gear^.Density/_3); |
117 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, tdY)/(Gear^.Density/_3); |
|
6581 | 118 |
|
119 |
Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser); |
|
120 |
if not Gear^.Invulnerable then |
|
121 |
Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner); |
|
122 |
Gear^.Active:= true; |
|
123 |
if Gear^.Kind <> gtFlame then FollowGear:= Gear |
|
124 |
end; |
|
125 |
if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (not Gear^.Invulnerable) then |
|
126 |
Gear^.Hedgehog^.Effects[hePoisoned] := true; |
|
127 |
end; |
|
128 |
||
129 |
end; |
|
130 |
gtGrave: begin |
|
131 |
// Run the calcs only once we know we have a type that will need damage |
|
6765 | 132 |
tdX:= Gear^.X-fX; |
133 |
tdY:= Gear^.Y-fY; |
|
134 |
if hwRound(hwAbs(tdX)+hwAbs(tdY)) < dmgBase then |
|
135 |
dmg:= dmgBase - hwRound(Distance(tdX, tdY)); |
|
6581 | 136 |
if dmg > 1 then |
137 |
begin |
|
138 |
dmg:= ModifyDamage(min(dmg div 2, Radius), Gear); |
|
139 |
Gear^.dY:= - _0_004 * dmg; |
|
140 |
Gear^.Active:= true |
|
141 |
end |
|
142 |
end; |
|
143 |
end; |
|
144 |
end; |
|
145 |
Gear:= Gear^.NextGear |
|
146 |
end; |
|
147 |
||
148 |
if (Mask and EXPLDontDraw) = 0 then |
|
149 |
if (GameFlags and gfSolidLand) = 0 then |
|
150 |
begin |
|
151 |
cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk |
|
152 |
if (cnt > 0) and (SpritesData[sprChunk].Texture <> nil) then |
|
153 |
for i:= 0 to cnt do |
|
154 |
AddVisualGear(X, Y, vgtChunk) |
|
155 |
end; |
|
156 |
||
157 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
158 |
end; |
|
159 |
||
160 |
function ModifyDamage(dmg: Longword; Gear: PGear): Longword; |
|
161 |
var i: hwFloat; |
|
162 |
begin |
|
163 |
(* Invulnerability cannot be placed in here due to still needing kicks |
|
164 |
Not without a new damage machine. |
|
165 |
King check should be in here instead of ApplyDamage since Tiy wants them kicked less |
|
166 |
*) |
|
167 |
i:= _1; |
|
168 |
if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then |
|
169 |
i:= _1_5; |
|
170 |
if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.King) then |
|
171 |
ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent * _0_5) |
|
172 |
else |
|
173 |
ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent) |
|
174 |
end; |
|
175 |
||
176 |
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); |
|
177 |
var s: shortstring; |
|
178 |
vampDmg, tmpDmg, i: Longword; |
|
179 |
vg: PVisualGear; |
|
180 |
begin |
|
181 |
if Damage = 0 then |
|
182 |
exit; // nothing to apply |
|
183 |
||
184 |
if (Gear^.Kind = gtHedgehog) then |
|
185 |
begin |
|
186 |
Gear^.LastDamage := AttackerHog; |
|
187 |
||
188 |
Gear^.Hedgehog^.Team^.Clan^.Flawless:= false; |
|
189 |
HHHurt(Gear^.Hedgehog, Source); |
|
190 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color); |
|
191 |
tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage)); |
|
192 |
if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then |
|
193 |
begin |
|
194 |
if cVampiric then |
|
195 |
begin |
|
196 |
vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8); |
|
197 |
if vampDmg >= 1 then |
|
198 |
begin |
|
199 |
// was considering pulsing on attack, Tiy thinks it should be permanent while in play |
|
200 |
//CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric; |
|
201 |
inc(CurrentHedgehog^.Gear^.Health,vampDmg); |
|
202 |
str(vampDmg, s); |
|
203 |
s:= '+' + s; |
|
204 |
AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); |
|
205 |
RenderHealth(CurrentHedgehog^); |
|
206 |
RecountTeamHealth(CurrentHedgehog^.Team); |
|
207 |
i:= 0; |
|
208 |
while i < vampDmg do |
|
209 |
begin |
|
210 |
vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot); |
|
211 |
if vg <> nil then |
|
212 |
with vg^ do |
|
213 |
begin |
|
214 |
Tint:= $FF0000FF; |
|
215 |
State:= ord(sprHealth) |
|
216 |
end; |
|
217 |
inc(i, 5); |
|
218 |
end; |
|
219 |
end |
|
220 |
end; |
|
221 |
if ((GameFlags and gfKarma) <> 0) and |
|
222 |
((GameFlags and gfInvulnerable) = 0) |
|
223 |
and (not CurrentHedgehog^.Gear^.Invulnerable) then |
|
224 |
begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid |
|
225 |
inc(CurrentHedgehog^.Gear^.Karma, tmpDmg); |
|
226 |
CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog; |
|
227 |
spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg); |
|
228 |
end; |
|
229 |
uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false); |
|
230 |
end; |
|
231 |
end |
|
232 |
else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure |
|
233 |
begin |
|
234 |
Gear^.Hedgehog:= AttackerHog; |
|
235 |
end; |
|
236 |
inc(Gear^.Damage, Damage); |
|
237 |
||
238 |
ScriptCall('onGearDamage', Gear^.UID, Damage); |
|
239 |
end; |
|
240 |
||
241 |
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword); |
|
242 |
var tag: PVisualGear; |
|
243 |
begin |
|
244 |
tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg); |
|
245 |
if (tag <> nil) then |
|
246 |
tag^.Hedgehog:= HHGear^.Hedgehog; // the tag needs the tag to determine the text color |
|
247 |
AllInactive:= false; |
|
248 |
HHGear^.Active:= true; |
|
249 |
end; |
|
250 |
||
251 |
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource); |
|
252 |
begin |
|
253 |
if (Source = dsFall) or (Source = dsExplosion) then |
|
254 |
case random(3) of |
|
255 |
0: PlaySound(sndOoff1, Hedgehog^.Team^.voicepack); |
|
256 |
1: PlaySound(sndOoff2, Hedgehog^.Team^.voicepack); |
|
257 |
2: PlaySound(sndOoff3, Hedgehog^.Team^.voicepack); |
|
258 |
end |
|
259 |
else if (Source = dsPoison) then |
|
260 |
case random(2) of |
|
261 |
0: PlaySound(sndPoisonCough, Hedgehog^.Team^.voicepack); |
|
262 |
1: PlaySound(sndPoisonMoan, Hedgehog^.Team^.voicepack); |
|
263 |
end |
|
264 |
else |
|
265 |
case random(4) of |
|
266 |
0: PlaySound(sndOw1, Hedgehog^.Team^.voicepack); |
|
267 |
1: PlaySound(sndOw2, Hedgehog^.Team^.voicepack); |
|
268 |
2: PlaySound(sndOw3, Hedgehog^.Team^.voicepack); |
|
269 |
3: PlaySound(sndOw4, Hedgehog^.Team^.voicepack); |
|
270 |
end |
|
271 |
end; |
|
272 |
||
273 |
procedure CheckHHDamage(Gear: PGear); |
|
274 |
var |
|
275 |
dmg: Longword; |
|
276 |
i: LongInt; |
|
277 |
particle: PVisualGear; |
|
278 |
begin |
|
279 |
if _0_4 < Gear^.dY then |
|
280 |
begin |
|
281 |
dmg := ModifyDamage(1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70), Gear); |
|
282 |
PlaySound(sndBump); |
|
283 |
if dmg < 1 then |
|
284 |
exit; |
|
285 |
||
286 |
for i:= min(12, (3 + dmg div 10)) downto 0 do |
|
287 |
begin |
|
288 |
particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust); |
|
289 |
if particle <> nil then |
|
290 |
particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480); |
|
291 |
end; |
|
292 |
||
293 |
if (Gear^.Invulnerable) then |
|
294 |
exit; |
|
295 |
||
296 |
//if _0_6 < Gear^.dY then |
|
297 |
// PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack) |
|
298 |
//else |
|
299 |
// PlaySound(sndOw1, Gear^.Hedgehog^.Team^.voicepack); |
|
300 |
||
301 |
if Gear^.LastDamage <> nil then |
|
302 |
ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall) |
|
303 |
else |
|
304 |
ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall); |
|
305 |
end |
|
306 |
end; |
|
307 |
||
308 |
||
309 |
procedure CalcRotationDirAngle(Gear: PGear); |
|
310 |
var |
|
311 |
dAngle: real; |
|
312 |
begin |
|
313 |
dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000; |
|
314 |
if not Gear^.dX.isNegative then |
|
315 |
Gear^.DirAngle := Gear^.DirAngle + dAngle |
|
316 |
else |
|
317 |
Gear^.DirAngle := Gear^.DirAngle - dAngle; |
|
318 |
||
319 |
if Gear^.DirAngle < 0 then |
|
320 |
Gear^.DirAngle := Gear^.DirAngle + 360 |
|
321 |
else if 360 < Gear^.DirAngle then |
|
322 |
Gear^.DirAngle := Gear^.DirAngle - 360 |
|
323 |
end; |
|
324 |
||
325 |
function CheckGearDrowning(Gear: PGear): boolean; |
|
326 |
var |
|
327 |
skipSpeed, skipAngle, skipDecay: hwFloat; |
|
328 |
i, maxDrops, X, Y: LongInt; |
|
329 |
vdX, vdY: real; |
|
330 |
particle: PVisualGear; |
|
331 |
isSubmersible: boolean; |
|
332 |
begin |
|
333 |
// probably needs tweaking. might need to be in a case statement based upon gear type |
|
334 |
Y:= hwRound(Gear^.Y); |
|
335 |
if cWaterLine < Y + Gear^.Radius then |
|
336 |
begin |
|
337 |
isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack); |
|
338 |
skipSpeed := _0_25; |
|
339 |
skipAngle := _1_9; |
|
340 |
skipDecay := _0_87; |
|
341 |
X:= hwRound(Gear^.X); |
|
342 |
vdX:= hwFloat2Float(Gear^.dX); |
|
343 |
vdY:= hwFloat2Float(Gear^.dY); |
|
344 |
// this could perhaps be a tiny bit higher. |
|
345 |
if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) |
|
346 |
and (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then |
|
347 |
begin |
|
348 |
Gear^.dY.isNegative := true; |
|
349 |
Gear^.dY := Gear^.dY * skipDecay; |
|
350 |
Gear^.dX := Gear^.dX * skipDecay; |
|
351 |
CheckGearDrowning := false; |
|
352 |
PlaySound(sndSkip) |
|
353 |
end |
|
354 |
else |
|
355 |
begin |
|
356 |
if not isSubmersible then |
|
357 |
begin |
|
358 |
CheckGearDrowning := true; |
|
359 |
Gear^.State := gstDrowning; |
|
360 |
Gear^.RenderTimer := false; |
|
361 |
if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot) |
|
362 |
and (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then |
|
363 |
if Gear^.Kind = gtHedgehog then |
|
364 |
begin |
|
365 |
if Gear^.Hedgehog^.Effects[heResurrectable] then |
|
366 |
ResurrectHedgehog(Gear) |
|
367 |
else |
|
368 |
begin |
|
369 |
Gear^.doStep := @doStepDrowningGear; |
|
370 |
Gear^.State := Gear^.State and (not gstHHDriven); |
|
371 |
AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); |
|
372 |
end |
|
373 |
end |
|
374 |
else |
|
375 |
Gear^.doStep := @doStepDrowningGear; |
|
376 |
if Gear^.Kind = gtFlake then |
|
377 |
exit // skip splashes |
|
378 |
end; |
|
379 |
if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) |
|
380 |
or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) |
|
381 |
and (CurAmmoGear^.dY < _0_01))) then |
|
382 |
// don't play splash if they are already way past the surface |
|
383 |
PlaySound(sndSplash) |
|
384 |
end; |
|
385 |
||
386 |
if ((cReducedQuality and rqPlainSplash) = 0) |
|
387 |
and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) |
|
388 |
or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) |
|
389 |
and (CurAmmoGear^.dY < _0_01)))) then |
|
390 |
begin |
|
391 |
AddVisualGear(X, cWaterLine, vgtSplash); |
|
392 |
||
393 |
maxDrops := (Gear^.Radius div 2) + round(vdX * Gear^.Radius * 2) + round(vdY * Gear^.Radius * 2); |
|
394 |
for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do |
|
395 |
begin |
|
396 |
particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet); |
|
397 |
if particle <> nil then |
|
398 |
begin |
|
399 |
particle^.dX := particle^.dX - vdX / 10; |
|
400 |
particle^.dY := particle^.dY - vdY / 5; |
|
401 |
end |
|
402 |
end |
|
403 |
end; |
|
404 |
if isSubmersible and (CurAmmoGear^.Pos = 0) then |
|
405 |
CurAmmoGear^.Pos := 1000 |
|
406 |
end |
|
407 |
else |
|
408 |
CheckGearDrowning := false; |
|
409 |
end; |
|
410 |
||
411 |
||
412 |
procedure ResurrectHedgehog(gear: PGear); |
|
413 |
var tempTeam : PTeam; |
|
414 |
begin |
|
415 |
AttackBar:= 0; |
|
416 |
gear^.dX := _0; |
|
417 |
gear^.dY := _0; |
|
418 |
gear^.Damage := 0; |
|
419 |
gear^.Health := gear^.Hedgehog^.InitialHealth; |
|
420 |
gear^.Hedgehog^.Effects[hePoisoned] := false; |
|
421 |
if not CurrentHedgehog^.Effects[heResurrectable] then |
|
422 |
with CurrentHedgehog^ do |
|
423 |
begin |
|
424 |
inc(Team^.stats.AIKills); |
|
425 |
FreeTexture(Team^.AIKillsTex); |
|
426 |
Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16); |
|
427 |
end; |
|
428 |
tempTeam := gear^.Hedgehog^.Team; |
|
429 |
DeleteCI(gear); |
|
430 |
FindPlace(gear, false, 0, LAND_WIDTH, true); |
|
431 |
if gear <> nil then |
|
432 |
begin |
|
433 |
RenderHealth(gear^.Hedgehog^); |
|
434 |
ScriptCall('onGearResurrect', gear^.uid); |
|
435 |
gear^.State := gstWait; |
|
436 |
end; |
|
437 |
RecountTeamHealth(tempTeam); |
|
438 |
end; |
|
439 |
||
440 |
function CountNonZeroz(x, y, r, c: LongInt): LongInt; |
|
441 |
var i: LongInt; |
|
442 |
count: LongInt = 0; |
|
443 |
begin |
|
444 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
445 |
for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do |
|
446 |
if Land[y, i] <> 0 then |
|
447 |
begin |
|
448 |
inc(count); |
|
449 |
if count = c then |
|
450 |
exit(count) |
|
451 |
end; |
|
452 |
CountNonZeroz:= count; |
|
453 |
end; |
|
454 |
||
455 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean); |
|
456 |
var x: LongInt; |
|
457 |
y, sy: LongInt; |
|
458 |
ar: array[0..511] of TPoint; |
|
459 |
ar2: array[0..1023] of TPoint; |
|
460 |
cnt, cnt2: Longword; |
|
461 |
delta: LongInt; |
|
462 |
reallySkip, tryAgain: boolean; |
|
463 |
begin |
|
464 |
reallySkip:= false; // try not skipping proximity at first |
|
465 |
tryAgain:= true; |
|
466 |
while tryAgain do |
|
467 |
begin |
|
468 |
delta:= 250; |
|
469 |
cnt2:= 0; |
|
470 |
repeat |
|
471 |
x:= Left + LongInt(GetRandom(Delta)); |
|
472 |
repeat |
|
473 |
inc(x, Delta); |
|
474 |
cnt:= 0; |
|
475 |
y:= min(1024, topY) - 2 * Gear^.Radius; |
|
476 |
while y < cWaterLine do |
|
477 |
begin |
|
478 |
repeat |
|
479 |
inc(y, 2); |
|
480 |
until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0); |
|
481 |
||
482 |
sy:= y; |
|
483 |
||
484 |
repeat |
|
485 |
inc(y); |
|
486 |
until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0); |
|
487 |
||
488 |
if (y - sy > Gear^.Radius * 2) |
|
489 |
and (((Gear^.Kind = gtExplosives) |
|
490 |
and (y < cWaterLine) |
|
491 |
and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil)) |
|
492 |
and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius)) |
|
493 |
or |
|
494 |
((Gear^.Kind <> gtExplosives) |
|
495 |
and (y < cWaterLine) |
|
496 |
and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then |
|
497 |
||
498 |
begin |
|
499 |
ar[cnt].X:= x; |
|
500 |
if withFall then |
|
501 |
ar[cnt].Y:= sy + Gear^.Radius |
|
502 |
else |
|
503 |
ar[cnt].Y:= y - Gear^.Radius; |
|
504 |
inc(cnt) |
|
505 |
end; |
|
506 |
||
507 |
inc(y, 45) |
|
508 |
end; |
|
509 |
||
510 |
if cnt > 0 then |
|
511 |
with ar[GetRandom(cnt)] do |
|
512 |
begin |
|
513 |
ar2[cnt2].x:= x; |
|
514 |
ar2[cnt2].y:= y; |
|
515 |
inc(cnt2) |
|
516 |
end |
|
517 |
until (x + Delta > Right); |
|
518 |
||
519 |
dec(Delta, 60) |
|
520 |
until (cnt2 > 0) or (Delta < 70); |
|
521 |
if (cnt2 = 0) and skipProximity and (not reallySkip) then |
|
522 |
tryAgain:= true |
|
523 |
else tryAgain:= false; |
|
524 |
reallySkip:= true; |
|
525 |
end; |
|
526 |
||
527 |
if cnt2 > 0 then |
|
528 |
with ar2[GetRandom(cnt2)] do |
|
529 |
begin |
|
530 |
Gear^.X:= int2hwFloat(x); |
|
531 |
Gear^.Y:= int2hwFloat(y); |
|
532 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
533 |
end |
|
534 |
else |
|
535 |
begin |
|
536 |
OutError('Can''t find place for Gear', false); |
|
537 |
if Gear^.Kind = gtHedgehog then |
|
538 |
Gear^.Hedgehog^.Effects[heResurrectable] := false; |
|
539 |
DeleteGear(Gear); |
|
540 |
Gear:= nil |
|
541 |
end |
|
542 |
end; |
|
543 |
||
544 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
|
545 |
var t: PGear; |
|
546 |
begin |
|
547 |
t:= GearsList; |
|
548 |
rX:= sqr(rX); |
|
549 |
rY:= sqr(rY); |
|
550 |
||
551 |
while t <> nil do |
|
552 |
begin |
|
553 |
if (t <> Gear) and (t^.Kind = Kind) then |
|
554 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
|
555 |
exit(t); |
|
556 |
t:= t^.NextGear |
|
557 |
end; |
|
558 |
||
559 |
CheckGearNear:= nil |
|
560 |
end; |
|
561 |
||
562 |
||
563 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
|
564 |
var t: PGear; |
|
565 |
begin |
|
566 |
t:= GearsList; |
|
567 |
rX:= sqr(rX); |
|
568 |
rY:= sqr(rY); |
|
569 |
while t <> nil do |
|
570 |
begin |
|
571 |
if t^.Kind in Kind then |
|
572 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
|
573 |
exit(t); |
|
574 |
t:= t^.NextGear |
|
575 |
end; |
|
576 |
CheckGearsNear:= nil |
|
577 |
end; |
|
578 |
end. |