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