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