author | nemo |
Mon, 26 Mar 2012 20:29:37 -0400 | |
changeset 6828 | 6a5d33bff0b0 |
parent 6804 | 06bedc419d04 |
child 6888 | 32a54322d262 |
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 |
|
6803
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
23 |
uses uTypes, math; |
6581 | 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; |
|
6803
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
330 |
particle, splash: PVisualGear; |
6581 | 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 |
|
6804 | 382 |
if Gear^.Density * Gear^.dY > _1 then |
383 |
PlaySound(sndSplash) |
|
384 |
else if Gear^.Density * Gear^.dY > _0_5 then |
|
385 |
PlaySound(sndSkip) |
|
386 |
else |
|
387 |
PlaySound(sndDroplet2); |
|
6581 | 388 |
end; |
389 |
||
390 |
if ((cReducedQuality and rqPlainSplash) = 0) |
|
391 |
and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) |
|
392 |
or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) |
|
393 |
and (CurAmmoGear^.dY < _0_01)))) then |
|
394 |
begin |
|
6803
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
395 |
splash:= AddVisualGear(X, cWaterLine, vgtSplash); |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
396 |
if splash <> nil then |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
397 |
begin |
6804 | 398 |
splash^.Scale:= hwFloat2Float(Gear^.Density / _3 * Gear^.dY); |
6803
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
399 |
if splash^.Scale > 1 then splash^.Scale:= power(splash^.Scale,0.3333) |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
400 |
else splash^.Scale:= splash^.Scale + ((1-splash^.Scale) / 2); |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
401 |
end; |
6581 | 402 |
|
6803
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
403 |
maxDrops := (hwRound(Gear^.Density) * 3) div 2 + round(vdX * hwRound(Gear^.Density) * 6) + round(vdY * hwRound(Gear^.Density) * 6); |
6581 | 404 |
for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do |
405 |
begin |
|
406 |
particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet); |
|
407 |
if particle <> nil then |
|
408 |
begin |
|
409 |
particle^.dX := particle^.dX - vdX / 10; |
|
410 |
particle^.dY := particle^.dY - vdY / 5; |
|
6803
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
411 |
if splash <> nil then |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
412 |
begin |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
413 |
if splash^.Scale > 1 then |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
414 |
begin |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
415 |
particle^.dX:= particle^.dX * power(splash^.Scale,0.3333); // tone down the droplet height further |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
416 |
particle^.dY:= particle^.dY * power(splash^.Scale, 0.3333) |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
417 |
end |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
418 |
else |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
419 |
begin |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
420 |
particle^.dX:= particle^.dX * splash^.Scale; |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
421 |
particle^.dY:= particle^.dY * splash^.Scale |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
422 |
end |
0e70f3ea3bf8
bit of an experiment in variable splash sizes based on object/speed. not sure if it looks good yet. need to drown more stuff.
nemo
parents:
6769
diff
changeset
|
423 |
end |
6581 | 424 |
end |
425 |
end |
|
426 |
end; |
|
427 |
if isSubmersible and (CurAmmoGear^.Pos = 0) then |
|
428 |
CurAmmoGear^.Pos := 1000 |
|
429 |
end |
|
430 |
else |
|
431 |
CheckGearDrowning := false; |
|
432 |
end; |
|
433 |
||
434 |
||
435 |
procedure ResurrectHedgehog(gear: PGear); |
|
436 |
var tempTeam : PTeam; |
|
437 |
begin |
|
438 |
AttackBar:= 0; |
|
439 |
gear^.dX := _0; |
|
440 |
gear^.dY := _0; |
|
441 |
gear^.Damage := 0; |
|
442 |
gear^.Health := gear^.Hedgehog^.InitialHealth; |
|
443 |
gear^.Hedgehog^.Effects[hePoisoned] := false; |
|
444 |
if not CurrentHedgehog^.Effects[heResurrectable] then |
|
445 |
with CurrentHedgehog^ do |
|
446 |
begin |
|
447 |
inc(Team^.stats.AIKills); |
|
448 |
FreeTexture(Team^.AIKillsTex); |
|
449 |
Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16); |
|
450 |
end; |
|
451 |
tempTeam := gear^.Hedgehog^.Team; |
|
452 |
DeleteCI(gear); |
|
453 |
FindPlace(gear, false, 0, LAND_WIDTH, true); |
|
454 |
if gear <> nil then |
|
455 |
begin |
|
456 |
RenderHealth(gear^.Hedgehog^); |
|
457 |
ScriptCall('onGearResurrect', gear^.uid); |
|
458 |
gear^.State := gstWait; |
|
459 |
end; |
|
460 |
RecountTeamHealth(tempTeam); |
|
461 |
end; |
|
462 |
||
463 |
function CountNonZeroz(x, y, r, c: LongInt): LongInt; |
|
464 |
var i: LongInt; |
|
465 |
count: LongInt = 0; |
|
466 |
begin |
|
467 |
if (y and LAND_HEIGHT_MASK) = 0 then |
|
468 |
for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do |
|
469 |
if Land[y, i] <> 0 then |
|
470 |
begin |
|
471 |
inc(count); |
|
472 |
if count = c then |
|
473 |
exit(count) |
|
474 |
end; |
|
475 |
CountNonZeroz:= count; |
|
476 |
end; |
|
477 |
||
478 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean); |
|
479 |
var x: LongInt; |
|
480 |
y, sy: LongInt; |
|
481 |
ar: array[0..511] of TPoint; |
|
482 |
ar2: array[0..1023] of TPoint; |
|
483 |
cnt, cnt2: Longword; |
|
484 |
delta: LongInt; |
|
485 |
reallySkip, tryAgain: boolean; |
|
486 |
begin |
|
487 |
reallySkip:= false; // try not skipping proximity at first |
|
488 |
tryAgain:= true; |
|
489 |
while tryAgain do |
|
490 |
begin |
|
491 |
delta:= 250; |
|
492 |
cnt2:= 0; |
|
493 |
repeat |
|
494 |
x:= Left + LongInt(GetRandom(Delta)); |
|
495 |
repeat |
|
496 |
inc(x, Delta); |
|
497 |
cnt:= 0; |
|
498 |
y:= min(1024, topY) - 2 * Gear^.Radius; |
|
499 |
while y < cWaterLine do |
|
500 |
begin |
|
501 |
repeat |
|
502 |
inc(y, 2); |
|
503 |
until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0); |
|
504 |
||
505 |
sy:= y; |
|
506 |
||
507 |
repeat |
|
508 |
inc(y); |
|
509 |
until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0); |
|
510 |
||
511 |
if (y - sy > Gear^.Radius * 2) |
|
512 |
and (((Gear^.Kind = gtExplosives) |
|
513 |
and (y < cWaterLine) |
|
514 |
and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil)) |
|
515 |
and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius)) |
|
516 |
or |
|
517 |
((Gear^.Kind <> gtExplosives) |
|
518 |
and (y < cWaterLine) |
|
519 |
and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then |
|
520 |
||
521 |
begin |
|
522 |
ar[cnt].X:= x; |
|
523 |
if withFall then |
|
524 |
ar[cnt].Y:= sy + Gear^.Radius |
|
525 |
else |
|
526 |
ar[cnt].Y:= y - Gear^.Radius; |
|
527 |
inc(cnt) |
|
528 |
end; |
|
529 |
||
530 |
inc(y, 45) |
|
531 |
end; |
|
532 |
||
533 |
if cnt > 0 then |
|
534 |
with ar[GetRandom(cnt)] do |
|
535 |
begin |
|
536 |
ar2[cnt2].x:= x; |
|
537 |
ar2[cnt2].y:= y; |
|
538 |
inc(cnt2) |
|
539 |
end |
|
540 |
until (x + Delta > Right); |
|
541 |
||
542 |
dec(Delta, 60) |
|
543 |
until (cnt2 > 0) or (Delta < 70); |
|
544 |
if (cnt2 = 0) and skipProximity and (not reallySkip) then |
|
545 |
tryAgain:= true |
|
546 |
else tryAgain:= false; |
|
547 |
reallySkip:= true; |
|
548 |
end; |
|
549 |
||
550 |
if cnt2 > 0 then |
|
551 |
with ar2[GetRandom(cnt2)] do |
|
552 |
begin |
|
553 |
Gear^.X:= int2hwFloat(x); |
|
554 |
Gear^.Y:= int2hwFloat(y); |
|
555 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
556 |
end |
|
557 |
else |
|
558 |
begin |
|
559 |
OutError('Can''t find place for Gear', false); |
|
560 |
if Gear^.Kind = gtHedgehog then |
|
561 |
Gear^.Hedgehog^.Effects[heResurrectable] := false; |
|
562 |
DeleteGear(Gear); |
|
563 |
Gear:= nil |
|
564 |
end |
|
565 |
end; |
|
566 |
||
567 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
|
568 |
var t: PGear; |
|
569 |
begin |
|
570 |
t:= GearsList; |
|
571 |
rX:= sqr(rX); |
|
572 |
rY:= sqr(rY); |
|
573 |
||
574 |
while t <> nil do |
|
575 |
begin |
|
576 |
if (t <> Gear) and (t^.Kind = Kind) then |
|
577 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
|
578 |
exit(t); |
|
579 |
t:= t^.NextGear |
|
580 |
end; |
|
581 |
||
582 |
CheckGearNear:= nil |
|
583 |
end; |
|
584 |
||
585 |
||
586 |
function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear; |
|
587 |
var t: PGear; |
|
588 |
begin |
|
589 |
t:= GearsList; |
|
590 |
rX:= sqr(rX); |
|
591 |
rY:= sqr(rY); |
|
592 |
while t <> nil do |
|
593 |
begin |
|
594 |
if t^.Kind in Kind then |
|
595 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
|
596 |
exit(t); |
|
597 |
t:= t^.NextGear |
|
598 |
end; |
|
599 |
CheckGearsNear:= nil |
|
600 |
end; |
|
601 |
end. |