author | unc0rr |
Sat, 04 Jan 2014 23:30:52 +0400 | |
changeset 9948 | 91a43c79cd4b |
parent 9814 | c740c865294d |
child 9950 | 2759212a27de |
child 9998 | 736015b847e3 |
permissions | -rw-r--r-- |
6581 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9080 | 3 |
* Copyright (c) 2004-2013 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 |
|
9285 | 23 |
uses uTypes, uFloat; |
6581 | 24 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
25 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword); inline; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
26 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
27 |
|
6581 | 28 |
function ModifyDamage(dmg: Longword; Gear: PGear): Longword; |
29 |
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); |
|
30 |
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword); |
|
31 |
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource); |
|
32 |
procedure CheckHHDamage(Gear: PGear); |
|
33 |
procedure CalcRotationDirAngle(Gear: PGear); |
|
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
34 |
procedure ResurrectHedgehog(var gear: PGear); |
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
35 |
|
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
36 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt); inline; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
37 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
38 |
|
6581 | 39 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
40 |
function CheckGearDrowning(var Gear: PGear): boolean; |
7592 | 41 |
procedure CheckCollision(Gear: PGear); inline; |
42 |
procedure CheckCollisionWithLand(Gear: PGear); inline; |
|
6581 | 43 |
|
9285 | 44 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
45 |
function GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): PGearArrayS; |
|
46 |
procedure SpawnBoxOfSmth; |
|
47 |
procedure ShotgunShot(Gear: PGear); |
|
48 |
||
49 |
procedure SetAllToActive; |
|
50 |
procedure SetAllHHToActive; inline; |
|
51 |
procedure SetAllHHToActive(Ice: boolean); |
|
52 |
||
53 |
function GetAmmo(Hedgehog: PHedgehog): TAmmoType; |
|
54 |
function GetUtility(Hedgehog: PHedgehog): TAmmoType; |
|
55 |
||
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
56 |
function WorldWrap(var Gear: PGear): boolean; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
57 |
|
9285 | 58 |
|
59 |
||
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
60 |
function MakeHedgehogsStep(Gear: PGear) : boolean; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
61 |
|
6581 | 62 |
var doStepHandlers: array[TGearType] of TGearStepProcedure; |
63 |
||
64 |
implementation |
|
9285 | 65 |
uses uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc, |
6581 | 66 |
uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore, |
9285 | 67 |
uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, |
68 |
uGearsList, Math, uVisualGearsList, uGearsHandlersMess, |
|
69 |
uGearsHedgehog; |
|
6581 | 70 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
71 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword); inline; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
72 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
73 |
doMakeExplosion(X, Y, Radius, AttackingHog, Mask, $FFFFFFFF); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
74 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
75 |
|
6581 | 76 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); |
77 |
var Gear: PGear; |
|
6769
44ad49a3a126
Add drowning to grenade too, try some little optimisations
nemo
parents:
6765
diff
changeset
|
78 |
dmg, dmgBase: LongInt; |
6765 | 79 |
fX, fY, tdX, tdY: hwFloat; |
6581 | 80 |
vg: PVisualGear; |
81 |
i, cnt: LongInt; |
|
82 |
begin |
|
83 |
if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
84 |
if Radius > 25 then KickFlakes(Radius, X, Y); |
|
85 |
||
86 |
if ((Mask and EXPLNoGfx) = 0) then |
|
87 |
begin |
|
88 |
vg:= nil; |
|
89 |
if Radius > 50 then vg:= AddVisualGear(X, Y, vgtBigExplosion) |
|
90 |
else if Radius > 10 then vg:= AddVisualGear(X, Y, vgtExplosion); |
|
91 |
if vg <> nil then |
|
92 |
vg^.Tint:= Tint; |
|
93 |
end; |
|
94 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion); |
|
95 |
||
6765 | 96 |
(*if (Mask and EXPLAllDamageInRadius) = 0 then |
6581 | 97 |
dmgRadius:= Radius shl 1 |
98 |
else |
|
99 |
dmgRadius:= Radius; |
|
6765 | 100 |
dmgBase:= dmgRadius + cHHRadius div 2;*) |
101 |
dmgBase:= Radius shl 1 + cHHRadius div 2; |
|
6581 | 102 |
fX:= int2hwFloat(X); |
103 |
fY:= int2hwFloat(Y); |
|
104 |
Gear:= GearsList; |
|
105 |
while Gear <> nil do |
|
106 |
begin |
|
107 |
dmg:= 0; |
|
108 |
//dmg:= dmgRadius + cHHRadius div 2 - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
|
109 |
//if (dmg > 1) and |
|
110 |
if (Gear^.State and gstNoDamage) = 0 then |
|
111 |
begin |
|
112 |
case Gear^.Kind of |
|
113 |
gtHedgehog, |
|
114 |
gtMine, |
|
115 |
gtBall, |
|
116 |
gtMelonPiece, |
|
117 |
gtGrenade, |
|
118 |
gtClusterBomb, |
|
119 |
// gtCluster, too game breaking I think |
|
120 |
gtSMine, |
|
121 |
gtCase, |
|
122 |
gtTarget, |
|
123 |
gtFlame, |
|
7754 | 124 |
gtKnife, |
8161 | 125 |
gtExplosives: begin //, |
126 |
//gtStructure: begin |
|
6581 | 127 |
// Run the calcs only once we know we have a type that will need damage |
6765 | 128 |
tdX:= Gear^.X-fX; |
129 |
tdY:= Gear^.Y-fY; |
|
7721 | 130 |
if LongInt(tdX.Round + tdY.Round + 2) < dmgBase then |
7272
71df899c4163
Second part of the change. Make collision check use the new mask bit.
nemo
parents:
7190
diff
changeset
|
131 |
dmg:= dmgBase - hwRound(Distance(tdX, tdY)); |
6581 | 132 |
if dmg > 1 then |
133 |
begin |
|
134 |
dmg:= ModifyDamage(min(dmg div 2, Radius), Gear); |
|
135 |
//AddFileLog('Damage: ' + inttostr(dmg)); |
|
136 |
if (Mask and EXPLNoDamage) = 0 then |
|
137 |
begin |
|
9685
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
138 |
if Gear^.Hedgehog^.Effects[heInvulnerable] = 0 then |
6581 | 139 |
ApplyDamage(Gear, AttackingHog, dmg, dsExplosion) |
140 |
else |
|
141 |
Gear^.State:= Gear^.State or gstWinner; |
|
142 |
end; |
|
143 |
if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then |
|
144 |
begin |
|
145 |
DeleteCI(Gear); |
|
6765 | 146 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, tdX)/(Gear^.Density/_3); |
147 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, tdY)/(Gear^.Density/_3); |
|
6581 | 148 |
|
149 |
Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser); |
|
7767 | 150 |
if Gear^.Kind = gtKnife then Gear^.State:= Gear^.State and (not gstCollision); |
9685
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
151 |
if Gear^.Hedgehog^.Effects[heInvulnerable] = 0 then |
6581 | 152 |
Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner); |
153 |
Gear^.Active:= true; |
|
154 |
if Gear^.Kind <> gtFlame then FollowGear:= Gear |
|
155 |
end; |
|
9685
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
156 |
if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heInvulnerable] = 0) and (Gear^.State and gstHHDeath = 0) then |
7010
10a0a31804f3
Switch effects to longint for convenience of tracking ice states. I could add a new Hedgehog value, but since we have this effects list being all useless as booleans anyway...
nemo
parents:
6990
diff
changeset
|
157 |
Gear^.Hedgehog^.Effects[hePoisoned] := 1; |
6581 | 158 |
end; |
159 |
||
160 |
end; |
|
9814 | 161 |
gtGrave: if Mask and EXPLDoNotTouchAny = 0 then |
6581 | 162 |
// Run the calcs only once we know we have a type that will need damage |
163 |
begin |
|
9814 | 164 |
tdX:= Gear^.X-fX; |
165 |
tdY:= Gear^.Y-fY; |
|
166 |
if LongInt(tdX.Round + tdY.Round + 2) < dmgBase then |
|
167 |
dmg:= dmgBase - hwRound(Distance(tdX, tdY)); |
|
168 |
if dmg > 1 then |
|
169 |
begin |
|
170 |
dmg:= ModifyDamage(min(dmg div 2, Radius), Gear); |
|
171 |
Gear^.dY:= - _0_004 * dmg; |
|
172 |
Gear^.Active:= true |
|
173 |
end |
|
174 |
end; |
|
6581 | 175 |
end; |
176 |
end; |
|
177 |
Gear:= Gear^.NextGear |
|
178 |
end; |
|
179 |
||
180 |
if (Mask and EXPLDontDraw) = 0 then |
|
181 |
if (GameFlags and gfSolidLand) = 0 then |
|
182 |
begin |
|
183 |
cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk |
|
184 |
if (cnt > 0) and (SpritesData[sprChunk].Texture <> nil) then |
|
185 |
for i:= 0 to cnt do |
|
186 |
AddVisualGear(X, Y, vgtChunk) |
|
187 |
end; |
|
188 |
||
189 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
|
190 |
end; |
|
191 |
||
192 |
function ModifyDamage(dmg: Longword; Gear: PGear): Longword; |
|
193 |
var i: hwFloat; |
|
194 |
begin |
|
195 |
(* Invulnerability cannot be placed in here due to still needing kicks |
|
196 |
Not without a new damage machine. |
|
197 |
King check should be in here instead of ApplyDamage since Tiy wants them kicked less |
|
198 |
*) |
|
199 |
i:= _1; |
|
200 |
if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then |
|
201 |
i:= _1_5; |
|
8632
b5ed76d2a1f9
Make hogs thaw only on enemy turns, make timebox counter decrement only on your turn, adjust knock for frozen hogs, increase damage on frozen hogs, make freezer fuel only reduce when not adjusting angle.
nemo
parents:
8560
diff
changeset
|
202 |
if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.King or (Gear^.Hedgehog^.Effects[heFrozen] > 0)) then |
9148
78c699d8fdfd
move 0.01 to the end to avoid increase damage fail on small values like fire. thanks to hedgewars wiki for noting this for fire damage.
nemo
parents:
9080
diff
changeset
|
203 |
ModifyDamage:= hwRound(cDamageModifier * dmg * i * cDamagePercent * _0_5 * _0_01) |
9149 | 204 |
else |
9148
78c699d8fdfd
move 0.01 to the end to avoid increase damage fail on small values like fire. thanks to hedgewars wiki for noting this for fire damage.
nemo
parents:
9080
diff
changeset
|
205 |
ModifyDamage:= hwRound(cDamageModifier * dmg * i * cDamagePercent * _0_01) |
6581 | 206 |
end; |
207 |
||
208 |
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); |
|
209 |
var s: shortstring; |
|
210 |
vampDmg, tmpDmg, i: Longword; |
|
211 |
vg: PVisualGear; |
|
212 |
begin |
|
213 |
if Damage = 0 then |
|
214 |
exit; // nothing to apply |
|
215 |
||
216 |
if (Gear^.Kind = gtHedgehog) then |
|
217 |
begin |
|
218 |
Gear^.LastDamage := AttackerHog; |
|
219 |
||
220 |
Gear^.Hedgehog^.Team^.Clan^.Flawless:= false; |
|
221 |
HHHurt(Gear^.Hedgehog, Source); |
|
222 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color); |
|
223 |
tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage)); |
|
224 |
if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then |
|
225 |
begin |
|
226 |
if cVampiric then |
|
227 |
begin |
|
228 |
vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8); |
|
229 |
if vampDmg >= 1 then |
|
230 |
begin |
|
231 |
// was considering pulsing on attack, Tiy thinks it should be permanent while in play |
|
232 |
//CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric; |
|
233 |
inc(CurrentHedgehog^.Gear^.Health,vampDmg); |
|
234 |
str(vampDmg, s); |
|
235 |
s:= '+' + s; |
|
236 |
AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); |
|
237 |
RenderHealth(CurrentHedgehog^); |
|
238 |
RecountTeamHealth(CurrentHedgehog^.Team); |
|
239 |
i:= 0; |
|
240 |
while i < vampDmg do |
|
241 |
begin |
|
242 |
vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot); |
|
243 |
if vg <> nil then |
|
244 |
with vg^ do |
|
245 |
begin |
|
246 |
Tint:= $FF0000FF; |
|
247 |
State:= ord(sprHealth) |
|
248 |
end; |
|
249 |
inc(i, 5); |
|
250 |
end; |
|
251 |
end |
|
252 |
end; |
|
9685
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
253 |
if (GameFlags and gfKarma <> 0) and (GameFlags and gfInvulnerable = 0) and |
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
254 |
(CurrentHedgehog^.Effects[heInvulnerable] = 0) then |
6581 | 255 |
begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid |
256 |
inc(CurrentHedgehog^.Gear^.Karma, tmpDmg); |
|
257 |
CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog; |
|
258 |
spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg); |
|
259 |
end; |
|
260 |
uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false); |
|
261 |
end; |
|
8199
886ed135665b
Fix crashes and wtf behaviour introduced in r0b8beacff8a5
unc0rr
parents:
8161
diff
changeset
|
262 |
end else |
8161 | 263 |
//else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure |
6581 | 264 |
Gear^.Hedgehog:= AttackerHog; |
265 |
inc(Gear^.Damage, Damage); |
|
266 |
||
267 |
ScriptCall('onGearDamage', Gear^.UID, Damage); |
|
268 |
end; |
|
269 |
||
270 |
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword); |
|
271 |
var tag: PVisualGear; |
|
272 |
begin |
|
273 |
tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg); |
|
274 |
if (tag <> nil) then |
|
275 |
tag^.Hedgehog:= HHGear^.Hedgehog; // the tag needs the tag to determine the text color |
|
276 |
AllInactive:= false; |
|
277 |
HHGear^.Active:= true; |
|
278 |
end; |
|
279 |
||
280 |
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource); |
|
281 |
begin |
|
9071 | 282 |
if Hedgehog^.Effects[heFrozen] <> 0 then exit; |
6581 | 283 |
if (Source = dsFall) or (Source = dsExplosion) then |
284 |
case random(3) of |
|
7053 | 285 |
0: PlaySoundV(sndOoff1, Hedgehog^.Team^.voicepack); |
286 |
1: PlaySoundV(sndOoff2, Hedgehog^.Team^.voicepack); |
|
287 |
2: PlaySoundV(sndOoff3, Hedgehog^.Team^.voicepack); |
|
6581 | 288 |
end |
289 |
else if (Source = dsPoison) then |
|
290 |
case random(2) of |
|
7053 | 291 |
0: PlaySoundV(sndPoisonCough, Hedgehog^.Team^.voicepack); |
292 |
1: PlaySoundV(sndPoisonMoan, Hedgehog^.Team^.voicepack); |
|
6581 | 293 |
end |
294 |
else |
|
295 |
case random(4) of |
|
7053 | 296 |
0: PlaySoundV(sndOw1, Hedgehog^.Team^.voicepack); |
297 |
1: PlaySoundV(sndOw2, Hedgehog^.Team^.voicepack); |
|
298 |
2: PlaySoundV(sndOw3, Hedgehog^.Team^.voicepack); |
|
299 |
3: PlaySoundV(sndOw4, Hedgehog^.Team^.voicepack); |
|
6581 | 300 |
end |
301 |
end; |
|
302 |
||
303 |
procedure CheckHHDamage(Gear: PGear); |
|
304 |
var |
|
9809 | 305 |
dmg: LongInt; |
8003 | 306 |
i: LongWord; |
6581 | 307 |
particle: PVisualGear; |
308 |
begin |
|
9071 | 309 |
if _0_4 < Gear^.dY then |
310 |
begin |
|
311 |
dmg := ModifyDamage(1 + hwRound((Gear^.dY - _0_4) * 70), Gear); |
|
312 |
if Gear^.Hedgehog^.Effects[heFrozen] = 0 then |
|
313 |
PlaySound(sndBump) |
|
314 |
else PlaySound(sndFrozenHogImpact); |
|
315 |
if dmg < 1 then |
|
316 |
exit; |
|
6581 | 317 |
|
9809 | 318 |
for i:= min(12, 3 + dmg div 10) downto 0 do |
9071 | 319 |
begin |
320 |
particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust); |
|
321 |
if particle <> nil then |
|
322 |
particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480); |
|
323 |
end; |
|
6581 | 324 |
|
9685
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
325 |
if ((Gear^.Hedgehog^.Effects[heInvulnerable] <> 0)) then |
9071 | 326 |
exit; |
6581 | 327 |
|
9071 | 328 |
//if _0_6 < Gear^.dY then |
329 |
// PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack) |
|
330 |
//else |
|
331 |
// PlaySound(sndOw1, Gear^.Hedgehog^.Team^.voicepack); |
|
6581 | 332 |
|
9071 | 333 |
if Gear^.LastDamage <> nil then |
334 |
ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall) |
|
335 |
else |
|
336 |
ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall); |
|
6581 | 337 |
end |
338 |
end; |
|
339 |
||
340 |
||
341 |
procedure CalcRotationDirAngle(Gear: PGear); |
|
342 |
var |
|
343 |
dAngle: real; |
|
344 |
begin |
|
7825 | 345 |
// Frac/Round to be kind to JS as of 2012-08-27 where there is yet no int64/uint64 |
346 |
//dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000; |
|
347 |
dAngle := (Gear^.dX.Round + Gear^.dY.Round) / 2 + (Gear^.dX.Frac/$100000000+Gear^.dY.Frac/$100000000); |
|
6581 | 348 |
if not Gear^.dX.isNegative then |
349 |
Gear^.DirAngle := Gear^.DirAngle + dAngle |
|
350 |
else |
|
351 |
Gear^.DirAngle := Gear^.DirAngle - dAngle; |
|
352 |
||
353 |
if Gear^.DirAngle < 0 then |
|
354 |
Gear^.DirAngle := Gear^.DirAngle + 360 |
|
355 |
else if 360 < Gear^.DirAngle then |
|
356 |
Gear^.DirAngle := Gear^.DirAngle - 360 |
|
357 |
end; |
|
358 |
||
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
359 |
function CheckGearDrowning(var Gear: PGear): boolean; |
6581 | 360 |
var |
361 |
skipSpeed, skipAngle, skipDecay: hwFloat; |
|
362 |
i, maxDrops, X, Y: LongInt; |
|
363 |
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
|
364 |
particle, splash: PVisualGear; |
6581 | 365 |
isSubmersible: boolean; |
366 |
begin |
|
367 |
// probably needs tweaking. might need to be in a case statement based upon gear type |
|
368 |
Y:= hwRound(Gear^.Y); |
|
369 |
if cWaterLine < Y + Gear^.Radius then |
|
370 |
begin |
|
7389
15c3fb4882df
Sorry about the slight delay in pickup. You can blame a few lame cheaters. This is to make their cheating a bit harder.
nemo
parents:
7372
diff
changeset
|
371 |
if Gear^.State and gstInvisible <> 0 then |
15c3fb4882df
Sorry about the slight delay in pickup. You can blame a few lame cheaters. This is to make their cheating a bit harder.
nemo
parents:
7372
diff
changeset
|
372 |
begin |
7406
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
373 |
if Gear^.Kind = gtGenericFaller then |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
374 |
begin |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
375 |
Gear^.X:= int2hwFloat(GetRandom(rightX-leftX)+leftX); |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
376 |
Gear^.Y:= int2hwFloat(GetRandom(LAND_HEIGHT-topY)+topY); |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
377 |
Gear^.dX:= _90-(GetRandomf*_360); |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
378 |
Gear^.dY:= _90-(GetRandomf*_360) |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
379 |
end |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
380 |
else DeleteGear(Gear); |
7389
15c3fb4882df
Sorry about the slight delay in pickup. You can blame a few lame cheaters. This is to make their cheating a bit harder.
nemo
parents:
7372
diff
changeset
|
381 |
exit |
15c3fb4882df
Sorry about the slight delay in pickup. You can blame a few lame cheaters. This is to make their cheating a bit harder.
nemo
parents:
7372
diff
changeset
|
382 |
end; |
8992
5b0be812dcdb
Rename submersible state, increase getaway time for attack underwater, slow down gear dx/dy underwater to simulate water resistance
nemo
parents:
8991
diff
changeset
|
383 |
isSubmersible:= ((Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.State and gstSubmersible <> 0)) or (Gear^.State and gstSubmersible <> 0); |
6581 | 384 |
skipSpeed := _0_25; |
385 |
skipAngle := _1_9; |
|
386 |
skipDecay := _0_87; |
|
387 |
X:= hwRound(Gear^.X); |
|
388 |
vdX:= hwFloat2Float(Gear^.dX); |
|
389 |
vdY:= hwFloat2Float(Gear^.dY); |
|
390 |
// this could perhaps be a tiny bit higher. |
|
8990 | 391 |
if (cWaterLine + 64 + Gear^.Radius > Y) and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) |
6581 | 392 |
and (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then |
393 |
begin |
|
394 |
Gear^.dY.isNegative := true; |
|
395 |
Gear^.dY := Gear^.dY * skipDecay; |
|
396 |
Gear^.dX := Gear^.dX * skipDecay; |
|
397 |
CheckGearDrowning := false; |
|
398 |
PlaySound(sndSkip) |
|
399 |
end |
|
400 |
else |
|
401 |
begin |
|
402 |
if not isSubmersible then |
|
403 |
begin |
|
404 |
CheckGearDrowning := true; |
|
405 |
Gear^.State := gstDrowning; |
|
406 |
Gear^.RenderTimer := false; |
|
407 |
if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot) |
|
408 |
and (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then |
|
409 |
if Gear^.Kind = gtHedgehog then |
|
410 |
begin |
|
7010
10a0a31804f3
Switch effects to longint for convenience of tracking ice states. I could add a new Hedgehog value, but since we have this effects list being all useless as booleans anyway...
nemo
parents:
6990
diff
changeset
|
411 |
if Gear^.Hedgehog^.Effects[heResurrectable] <> 0 then |
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
412 |
begin |
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
413 |
// Gear could become nil after this, just exit to skip splashes |
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
414 |
ResurrectHedgehog(Gear); |
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
415 |
exit |
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
416 |
end |
6581 | 417 |
else |
418 |
begin |
|
419 |
Gear^.doStep := @doStepDrowningGear; |
|
420 |
Gear^.State := Gear^.State and (not gstHHDriven); |
|
421 |
AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); |
|
422 |
end |
|
423 |
end |
|
424 |
else |
|
425 |
Gear^.doStep := @doStepDrowningGear; |
|
426 |
if Gear^.Kind = gtFlake then |
|
427 |
exit // skip splashes |
|
8990 | 428 |
end |
8991
82e3a6e5d51b
Actually, let's use *4 since could be fired from lower down
nemo
parents:
8990
diff
changeset
|
429 |
else if (Y > cWaterLine + cVisibleWater*4) and |
8992
5b0be812dcdb
Rename submersible state, increase getaway time for attack underwater, slow down gear dx/dy underwater to simulate water resistance
nemo
parents:
8991
diff
changeset
|
430 |
((Gear <> CurrentHedgehog^.Gear) or (CurAmmoGear = nil) or (CurAmmoGear^.State and gstSubmersible = 0)) then |
8990 | 431 |
Gear^.doStep:= @doStepDrowningGear; |
6581 | 432 |
if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) |
8989 | 433 |
or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and (Gear = CurAmmoGear) and ((CurAmmoGear^.Pos = 0) |
6581 | 434 |
and (CurAmmoGear^.dY < _0_01))) then |
6804 | 435 |
if Gear^.Density * Gear^.dY > _1 then |
436 |
PlaySound(sndSplash) |
|
437 |
else if Gear^.Density * Gear^.dY > _0_5 then |
|
438 |
PlaySound(sndSkip) |
|
439 |
else |
|
440 |
PlaySound(sndDroplet2); |
|
6581 | 441 |
end; |
442 |
||
443 |
if ((cReducedQuality and rqPlainSplash) = 0) |
|
444 |
and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) |
|
8989 | 445 |
or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and (Gear = CurAmmoGear) and ((CurAmmoGear^.Pos = 0) |
6581 | 446 |
and (CurAmmoGear^.dY < _0_01)))) then |
447 |
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
|
448 |
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
|
449 |
if splash <> nil then |
7372
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
450 |
with splash^ do |
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
|
451 |
begin |
7372
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
452 |
Scale:= hwFloat2Float(Gear^.Density / _3 * Gear^.dY); |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
453 |
if Scale > 1 then Scale:= power(Scale,0.3333) |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
454 |
else Scale:= Scale + ((1-Scale) / 2); |
7420 | 455 |
if Scale > 1 then Timer:= round(min(Scale*0.0005/cGravityf,4)) |
7372
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
456 |
else Timer:= 1; |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
457 |
// Low Gravity |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
458 |
FrameTicks:= FrameTicks*Timer; |
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
|
459 |
end; |
6581 | 460 |
|
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
|
461 |
maxDrops := (hwRound(Gear^.Density) * 3) div 2 + round(vdX * hwRound(Gear^.Density) * 6) + round(vdY * hwRound(Gear^.Density) * 6); |
6581 | 462 |
for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do |
463 |
begin |
|
7372
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
464 |
particle := AddVisualGear(X - 3 + Random(7), cWaterLine, vgtDroplet); |
6581 | 465 |
if particle <> nil then |
7372
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
466 |
with particle^ do |
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
|
467 |
begin |
7372
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
468 |
dX := dX - vdX / 10; |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
469 |
dY := dY - vdY / 5; |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
470 |
if splash <> nil then |
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
|
471 |
begin |
7372
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
472 |
if splash^.Scale > 1 then |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
473 |
begin |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
474 |
dX:= dX * power(splash^.Scale,0.3333); // tone down the droplet height further |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
475 |
dY:= dY * power(splash^.Scale, 0.3333) |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
476 |
end |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
477 |
else |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
478 |
begin |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
479 |
dX:= dX * splash^.Scale; |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
480 |
dY:= dY * splash^.Scale |
fcc002658832
Spread the droplets around more so it looks less square (looked especially bad with piano). Slow down large splashes a bit for dramatic purposes, also taking low-g into account. Small splashes you can't really tell anyway.
nemo
parents:
7357
diff
changeset
|
481 |
end |
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
|
482 |
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
|
483 |
end |
6581 | 484 |
end |
485 |
end; |
|
8989 | 486 |
if isSubmersible and (Gear = CurAmmoGear) and (CurAmmoGear^.Pos = 0) then |
6581 | 487 |
CurAmmoGear^.Pos := 1000 |
488 |
end |
|
489 |
else |
|
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
490 |
begin |
9479
167dea42d7d7
move border back a bit from left/right bounds, bee tweak
nemo
parents:
9477
diff
changeset
|
491 |
if not (Gear^.Kind in [gtJetpack, gtBee]) then Gear^.State:= Gear^.State and not gstSubmersible; // making it temporary for most gears is more attractive I think |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
492 |
CheckGearDrowning := false |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
493 |
end |
6581 | 494 |
end; |
495 |
||
496 |
||
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
497 |
procedure ResurrectHedgehog(var gear: PGear); |
6581 | 498 |
var tempTeam : PTeam; |
7092
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
499 |
sparkles: PVisualGear; |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
500 |
gX, gY: LongInt; |
6581 | 501 |
begin |
7357
06454899d0d2
Score AI resurrection as a kill. These values will not be the same as the in-game scoring, since in-game scoring doesn't count friendlies.
nemo
parents:
7272
diff
changeset
|
502 |
if (Gear^.LastDamage <> nil) then |
06454899d0d2
Score AI resurrection as a kill. These values will not be the same as the in-game scoring, since in-game scoring doesn't count friendlies.
nemo
parents:
7272
diff
changeset
|
503 |
uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true) |
06454899d0d2
Score AI resurrection as a kill. These values will not be the same as the in-game scoring, since in-game scoring doesn't count friendlies.
nemo
parents:
7272
diff
changeset
|
504 |
else |
06454899d0d2
Score AI resurrection as a kill. These values will not be the same as the in-game scoring, since in-game scoring doesn't count friendlies.
nemo
parents:
7272
diff
changeset
|
505 |
uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true); |
6581 | 506 |
AttackBar:= 0; |
507 |
gear^.dX := _0; |
|
508 |
gear^.dY := _0; |
|
509 |
gear^.Damage := 0; |
|
510 |
gear^.Health := gear^.Hedgehog^.InitialHealth; |
|
7010
10a0a31804f3
Switch effects to longint for convenience of tracking ice states. I could add a new Hedgehog value, but since we have this effects list being all useless as booleans anyway...
nemo
parents:
6990
diff
changeset
|
511 |
gear^.Hedgehog^.Effects[hePoisoned] := 0; |
7176
fb4b0c6dfdbd
Make watching AI v AI on ai survival a bit more entertaining
nemo
parents:
7168
diff
changeset
|
512 |
if (CurrentHedgehog^.Effects[heResurrectable] = 0) or ((CurrentHedgehog^.Effects[heResurrectable] <> 0) |
fb4b0c6dfdbd
Make watching AI v AI on ai survival a bit more entertaining
nemo
parents:
7168
diff
changeset
|
513 |
and (Gear^.Hedgehog^.Team^.Clan <> CurrentHedgehog^.Team^.Clan)) then |
6581 | 514 |
with CurrentHedgehog^ do |
515 |
begin |
|
516 |
inc(Team^.stats.AIKills); |
|
517 |
FreeTexture(Team^.AIKillsTex); |
|
518 |
Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16); |
|
519 |
end; |
|
520 |
tempTeam := gear^.Hedgehog^.Team; |
|
521 |
DeleteCI(gear); |
|
7092
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
522 |
gX := hwRound(gear^.X); |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
523 |
gY := hwRound(gear^.Y); |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
524 |
// might need more sparkles for a column |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
525 |
sparkles:= AddVisualGear(gX, gY, vgtDust, 1); |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
526 |
if sparkles <> nil then |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
527 |
begin |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
528 |
sparkles^.Tint:= tempTeam^.Clan^.Color shl 8 or $FF; |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
529 |
//sparkles^.Angle:= random(360); |
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
530 |
end; |
6581 | 531 |
FindPlace(gear, false, 0, LAND_WIDTH, true); |
532 |
if gear <> nil then |
|
533 |
begin |
|
7092
c9ca770fd7fc
Add an emergency return to the timebox in the case of death of rest of team. Also add a small visual effect to AI survival
nemo
parents:
7066
diff
changeset
|
534 |
AddVisualGear(hwRound(gear^.X), hwRound(gear^.Y), vgtExplosion); |
7168
8defaabce92e
warp sound when AI survival hog respawns. attempt at a bit of a crate spawn animation (moar sparkles and a quick fadein)
nemo
parents:
7092
diff
changeset
|
535 |
PlaySound(sndWarp); |
6581 | 536 |
RenderHealth(gear^.Hedgehog^); |
537 |
ScriptCall('onGearResurrect', gear^.uid); |
|
538 |
gear^.State := gstWait; |
|
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
539 |
end; |
6581 | 540 |
RecountTeamHealth(tempTeam); |
541 |
end; |
|
542 |
||
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
543 |
function CountNonZeroz(x, y, r, c: LongInt; mask: LongWord): LongInt; |
6581 | 544 |
var i: LongInt; |
545 |
count: LongInt = 0; |
|
546 |
begin |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
547 |
if (y and LAND_HEIGHT_MASK) = 0 then |
7509 | 548 |
for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do |
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
549 |
if Land[y, i] and mask <> 0 then |
6581 | 550 |
begin |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
551 |
inc(count); |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
552 |
if count = c then |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
553 |
begin |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
554 |
CountNonZeroz:= count; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
555 |
exit |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
556 |
end; |
6581 | 557 |
end; |
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
558 |
CountNonZeroz:= count; |
6581 | 559 |
end; |
560 |
||
6888 | 561 |
|
562 |
function NoGearsToAvoid(mX, mY: LongInt; rX, rY: LongInt): boolean; |
|
563 |
var t: PGear; |
|
564 |
begin |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
565 |
NoGearsToAvoid:= false; |
6888 | 566 |
t:= GearsList; |
567 |
rX:= sqr(rX); |
|
568 |
rY:= sqr(rY); |
|
569 |
while t <> nil do |
|
570 |
begin |
|
571 |
if t^.Kind <= gtExplosives then |
|
572 |
if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
573 |
exit; |
6888 | 574 |
t:= t^.NextGear |
575 |
end; |
|
576 |
NoGearsToAvoid:= true |
|
577 |
end; |
|
578 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
579 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt); inline; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
580 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
581 |
FindPlace(Gear, withFall, Left, Right, false); |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
582 |
end; |
6888 | 583 |
|
6581 | 584 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean); |
585 |
var x: LongInt; |
|
586 |
y, sy: LongInt; |
|
8007 | 587 |
ar: array[0..1023] of TPoint; |
588 |
ar2: array[0..2047] of TPoint; |
|
6581 | 589 |
cnt, cnt2: Longword; |
590 |
delta: LongInt; |
|
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
591 |
ignoreNearObjects, ignoreOverlap, tryAgain: boolean; |
6581 | 592 |
begin |
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
593 |
ignoreNearObjects:= false; // try not skipping proximity at first |
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
594 |
ignoreOverlap:= false; // this not only skips proximity, but allows overlapping objects (barrels, mines, hogs, crates). Saving it for a 3rd pass. With this active, winning AI Survival goes back to virtual impossibility |
6581 | 595 |
tryAgain:= true; |
9477 | 596 |
if WorldEdge <> weNone then |
597 |
begin |
|
9809 | 598 |
Left:= max(Left, LongInt(leftX) + Gear^.Radius); |
9477 | 599 |
Right:= min(Right,rightX-Gear^.Radius) |
600 |
end; |
|
6581 | 601 |
while tryAgain do |
602 |
begin |
|
8007 | 603 |
delta:= LAND_WIDTH div 16; |
6581 | 604 |
cnt2:= 0; |
605 |
repeat |
|
8007 | 606 |
x:= Left + max(LAND_WIDTH div 2048, LongInt(GetRandom(Delta))); |
6581 | 607 |
repeat |
608 |
inc(x, Delta); |
|
609 |
cnt:= 0; |
|
9809 | 610 |
y:= min(1024, topY) - Gear^.Radius shl 1; |
6581 | 611 |
while y < cWaterLine do |
612 |
begin |
|
613 |
repeat |
|
614 |
inc(y, 2); |
|
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
615 |
until (y >= cWaterLine) or |
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
616 |
(not ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) = 0)) or |
8751
4609823efc94
More flagging of Land values. Also use less than for tests of non-terrain, instead of "and $FF00 = 0". Saves a couple of ops, which actually matters a small amount in a few places.
nemo
parents:
8632
diff
changeset
|
617 |
(ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask) = 0)); |
6581 | 618 |
|
619 |
sy:= y; |
|
620 |
||
621 |
repeat |
|
622 |
inc(y); |
|
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
623 |
until (y >= cWaterLine) or |
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
624 |
(not ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) <> 0)) or |
8751
4609823efc94
More flagging of Land values. Also use less than for tests of non-terrain, instead of "and $FF00 = 0". Saves a couple of ops, which actually matters a small amount in a few places.
nemo
parents:
8632
diff
changeset
|
625 |
(ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask) <> 0)); |
6581 | 626 |
|
627 |
if (y - sy > Gear^.Radius * 2) |
|
628 |
and (((Gear^.Kind = gtExplosives) |
|
629 |
and (y < cWaterLine) |
|
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
630 |
and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 60, 60)) |
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
631 |
and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1, $FFFF) > Gear^.Radius)) |
6581 | 632 |
or |
633 |
((Gear^.Kind <> gtExplosives) |
|
634 |
and (y < cWaterLine) |
|
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
635 |
and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 110, 110)) |
6888 | 636 |
)) then |
637 |
begin |
|
6581 | 638 |
ar[cnt].X:= x; |
639 |
if withFall then |
|
640 |
ar[cnt].Y:= sy + Gear^.Radius |
|
641 |
else |
|
642 |
ar[cnt].Y:= y - Gear^.Radius; |
|
643 |
inc(cnt) |
|
644 |
end; |
|
645 |
||
7603
e9c3c67b5dfd
reducing this value is sufficient to ensure crates drop just below top border or a girder
nemo
parents:
7599
diff
changeset
|
646 |
inc(y, 10) |
6581 | 647 |
end; |
648 |
||
649 |
if cnt > 0 then |
|
650 |
with ar[GetRandom(cnt)] do |
|
651 |
begin |
|
652 |
ar2[cnt2].x:= x; |
|
653 |
ar2[cnt2].y:= y; |
|
654 |
inc(cnt2) |
|
655 |
end |
|
656 |
until (x + Delta > Right); |
|
657 |
||
658 |
dec(Delta, 60) |
|
659 |
until (cnt2 > 0) or (Delta < 70); |
|
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
660 |
// if either of these has not been tried, do another pass |
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
661 |
if (cnt2 = 0) and skipProximity and (not ignoreOverlap) then |
6581 | 662 |
tryAgain:= true |
663 |
else tryAgain:= false; |
|
7190
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
664 |
if ignoreNearObjects then ignoreOverlap:= true; |
aa8d68817c32
Make it AI survival almost definitely impossible by adding a 3rd pass to FindGear. 1st pass normal, 2nd pass allow close to objects, 3rd pass, allow overlapping objects.
nemo
parents:
7176
diff
changeset
|
665 |
ignoreNearObjects:= true; |
6581 | 666 |
end; |
667 |
||
668 |
if cnt2 > 0 then |
|
669 |
with ar2[GetRandom(cnt2)] do |
|
670 |
begin |
|
671 |
Gear^.X:= int2hwFloat(x); |
|
672 |
Gear^.Y:= int2hwFloat(y); |
|
673 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
674 |
end |
|
675 |
else |
|
676 |
begin |
|
677 |
OutError('Can''t find place for Gear', false); |
|
678 |
if Gear^.Kind = gtHedgehog then |
|
7010
10a0a31804f3
Switch effects to longint for convenience of tracking ice states. I could add a new Hedgehog value, but since we have this effects list being all useless as booleans anyway...
nemo
parents:
6990
diff
changeset
|
679 |
Gear^.Hedgehog^.Effects[heResurrectable] := 0; |
6581 | 680 |
DeleteGear(Gear); |
681 |
Gear:= nil |
|
682 |
end |
|
683 |
end; |
|
684 |
||
685 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
|
686 |
var t: PGear; |
|
687 |
begin |
|
688 |
t:= GearsList; |
|
689 |
rX:= sqr(rX); |
|
690 |
rY:= sqr(rY); |
|
691 |
||
692 |
while t <> nil do |
|
693 |
begin |
|
694 |
if (t <> Gear) and (t^.Kind = Kind) then |
|
695 |
if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then |
|
6990
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
696 |
begin |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
697 |
CheckGearNear:= t; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
698 |
exit; |
40e5af28d026
change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents:
6986
diff
changeset
|
699 |
end; |
6581 | 700 |
t:= t^.NextGear |
701 |
end; |
|
702 |
||
703 |
CheckGearNear:= nil |
|
704 |
end; |
|
705 |
||
7592 | 706 |
procedure CheckCollision(Gear: PGear); inline; |
707 |
begin |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
708 |
if (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0) |
7592 | 709 |
or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then |
710 |
Gear^.State := Gear^.State or gstCollision |
|
711 |
else |
|
712 |
Gear^.State := Gear^.State and (not gstCollision) |
|
713 |
end; |
|
714 |
||
715 |
procedure CheckCollisionWithLand(Gear: PGear); inline; |
|
716 |
begin |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
717 |
if (TestCollisionX(Gear, hwSign(Gear^.dX)) <> 0) |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
718 |
or (TestCollisionY(Gear, hwSign(Gear^.dY)) <> 0) then |
7592 | 719 |
Gear^.State := Gear^.State or gstCollision |
720 |
else |
|
721 |
Gear^.State := Gear^.State and (not gstCollision) |
|
722 |
end; |
|
723 |
||
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
724 |
function MakeHedgehogsStep(Gear: PGear) : boolean; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
725 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
726 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then if (TestCollisionYwithGear(Gear, -1) = 0) then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
727 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
728 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
729 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then if (TestCollisionYwithGear(Gear, -1) = 0) then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
730 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
731 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
732 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then if (TestCollisionYwithGear(Gear, -1) = 0) then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
733 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
734 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
735 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then if (TestCollisionYwithGear(Gear, -1) = 0) then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
736 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
737 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
738 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then if (TestCollisionYwithGear(Gear, -1) = 0) then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
739 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
740 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
741 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then if (TestCollisionYwithGear(Gear, -1) = 0) then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
742 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
743 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
744 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
745 |
Gear^.Y:= Gear^.Y + _6 |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
746 |
end else Gear^.Y:= Gear^.Y + _5 else |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
747 |
end else Gear^.Y:= Gear^.Y + _4 else |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
748 |
end else Gear^.Y:= Gear^.Y + _3 else |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
749 |
end else Gear^.Y:= Gear^.Y + _2 else |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
750 |
end else Gear^.Y:= Gear^.Y + _1 |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
751 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
752 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
753 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) = 0 then |
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
754 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
755 |
Gear^.X:= Gear^.X + SignAs(_1, Gear^.dX); |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
756 |
MakeHedgehogsStep:= true |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
757 |
end else |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
758 |
MakeHedgehogsStep:= false; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
759 |
|
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
760 |
if TestCollisionYwithGear(Gear, 1) = 0 then |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
761 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
762 |
Gear^.Y:= Gear^.Y + _1; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
763 |
if TestCollisionYwithGear(Gear, 1) = 0 then |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
764 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
765 |
Gear^.Y:= Gear^.Y + _1; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
766 |
if TestCollisionYwithGear(Gear, 1) = 0 then |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
767 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
768 |
Gear^.Y:= Gear^.Y + _1; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
769 |
if TestCollisionYwithGear(Gear, 1) = 0 then |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
770 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
771 |
Gear^.Y:= Gear^.Y + _1; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
772 |
if TestCollisionYwithGear(Gear, 1) = 0 then |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
773 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
774 |
Gear^.Y:= Gear^.Y + _1; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
775 |
if TestCollisionYwithGear(Gear, 1) = 0 then |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
776 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
777 |
Gear^.Y:= Gear^.Y + _1; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
778 |
if TestCollisionYwithGear(Gear, 1) = 0 then |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
779 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
780 |
Gear^.Y:= Gear^.Y - _6; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
781 |
Gear^.dY:= _0; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
782 |
Gear^.State:= Gear^.State or gstMoving; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
783 |
exit |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
784 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
785 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
786 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
787 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
788 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
789 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
790 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
791 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
792 |
|
9285 | 793 |
|
794 |
procedure ShotgunShot(Gear: PGear); |
|
795 |
var t: PGear; |
|
796 |
dmg, r, dist: LongInt; |
|
797 |
dx, dy: hwFloat; |
|
798 |
begin |
|
799 |
Gear^.Radius:= cShotgunRadius; |
|
800 |
t:= GearsList; |
|
801 |
while t <> nil do |
|
802 |
begin |
|
803 |
case t^.Kind of |
|
804 |
gtHedgehog, |
|
805 |
gtMine, |
|
806 |
gtSMine, |
|
807 |
gtKnife, |
|
808 |
gtCase, |
|
809 |
gtTarget, |
|
810 |
gtExplosives: begin//, |
|
811 |
// gtStructure: begin |
|
812 |
//addFileLog('ShotgunShot radius: ' + inttostr(Gear^.Radius) + ', t^.Radius = ' + inttostr(t^.Radius) + ', distance = ' + inttostr(dist) + ', dmg = ' + inttostr(dmg)); |
|
813 |
dmg:= 0; |
|
814 |
r:= Gear^.Radius + t^.Radius; |
|
815 |
dx:= Gear^.X-t^.X; |
|
816 |
dx.isNegative:= false; |
|
817 |
dy:= Gear^.Y-t^.Y; |
|
818 |
dy.isNegative:= false; |
|
819 |
if r-hwRound(dx+dy) > 0 then |
|
820 |
begin |
|
821 |
dist:= hwRound(Distance(dx, dy)); |
|
822 |
dmg:= ModifyDamage(min(r - dist, 25), t); |
|
823 |
end; |
|
824 |
if dmg > 0 then |
|
825 |
begin |
|
9685
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
826 |
if t^.Hedgehog^.Effects[heInvulnerable] = 0 then |
9285 | 827 |
ApplyDamage(t, Gear^.Hedgehog, dmg, dsBullet) |
828 |
else |
|
829 |
Gear^.State:= Gear^.State or gstWinner; |
|
830 |
||
831 |
DeleteCI(t); |
|
832 |
t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX); |
|
833 |
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; |
|
834 |
t^.State:= t^.State or gstMoving; |
|
835 |
if t^.Kind = gtKnife then t^.State:= t^.State and (not gstCollision); |
|
836 |
t^.Active:= true; |
|
837 |
FollowGear:= t |
|
838 |
end |
|
839 |
end; |
|
840 |
gtGrave: begin |
|
841 |
dmg:= 0; |
|
842 |
r:= Gear^.Radius + t^.Radius; |
|
843 |
dx:= Gear^.X-t^.X; |
|
844 |
dx.isNegative:= false; |
|
845 |
dy:= Gear^.Y-t^.Y; |
|
846 |
dy.isNegative:= false; |
|
847 |
if r-hwRound(dx+dy) > 0 then |
|
848 |
begin |
|
849 |
dist:= hwRound(Distance(dx, dy)); |
|
850 |
dmg:= ModifyDamage(min(r - dist, 25), t); |
|
851 |
end; |
|
852 |
if dmg > 0 then |
|
853 |
begin |
|
854 |
t^.dY:= - _0_1; |
|
855 |
t^.Active:= true |
|
856 |
end |
|
857 |
end; |
|
858 |
end; |
|
859 |
t:= t^.NextGear |
|
860 |
end; |
|
861 |
if (GameFlags and gfSolidLand) = 0 then |
|
862 |
DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) |
|
863 |
end; |
|
864 |
||
865 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
|
866 |
var t: PGearArray; |
|
867 |
Gear: PGear; |
|
868 |
i, j, tmpDmg: LongInt; |
|
869 |
VGear: PVisualGear; |
|
870 |
begin |
|
871 |
t:= CheckGearsCollision(Ammo); |
|
872 |
// Just to avoid hogs on rope dodging fire. |
|
873 |
if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy)) |
|
874 |
and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.CollisionIndex = -1) |
|
875 |
and (sqr(hwRound(Ammo^.X) - hwRound(CurrentHedgehog^.Gear^.X)) + sqr(hwRound(Ammo^.Y) - hwRound(CurrentHedgehog^.Gear^.Y)) <= sqr(cHHRadius + Ammo^.Radius)) then |
|
876 |
begin |
|
877 |
t^.ar[t^.Count]:= CurrentHedgehog^.Gear; |
|
878 |
inc(t^.Count) |
|
879 |
end; |
|
880 |
||
881 |
i:= t^.Count; |
|
882 |
||
883 |
if (Ammo^.Kind = gtFlame) and (i > 0) then |
|
884 |
Ammo^.Health:= 0; |
|
885 |
while i > 0 do |
|
886 |
begin |
|
887 |
dec(i); |
|
888 |
Gear:= t^.ar[i]; |
|
889 |
if ((Ammo^.Kind = gtFlame) or (Ammo^.Kind = gtBlowTorch)) and |
|
890 |
(Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heFrozen] > 255) then |
|
891 |
Gear^.Hedgehog^.Effects[heFrozen]:= max(255,Gear^.Hedgehog^.Effects[heFrozen]-10000); |
|
892 |
tmpDmg:= ModifyDamage(Damage, Gear); |
|
893 |
if (Gear^.State and gstNoDamage) = 0 then |
|
894 |
begin |
|
895 |
||
896 |
if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then |
|
897 |
begin |
|
898 |
VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit); |
|
899 |
if VGear <> nil then |
|
900 |
VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY); |
|
901 |
end; |
|
902 |
||
903 |
if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then |
|
904 |
Gear^.FlightTime:= 1; |
|
905 |
||
906 |
||
907 |
case Gear^.Kind of |
|
908 |
gtHedgehog, |
|
909 |
gtMine, |
|
910 |
gtSMine, |
|
911 |
gtKnife, |
|
912 |
gtTarget, |
|
913 |
gtCase, |
|
914 |
gtExplosives: //, |
|
915 |
//gtStructure: |
|
916 |
begin |
|
917 |
if (Ammo^.Kind = gtDrill) then |
|
918 |
begin |
|
919 |
Ammo^.Timer:= 0; |
|
920 |
exit; |
|
921 |
end; |
|
9685
7d925e82e572
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
nemo
parents:
9561
diff
changeset
|
922 |
if Gear^.Hedgehog^.Effects[heInvulnerable] = 0 then |
9285 | 923 |
begin |
924 |
if (Ammo^.Kind = gtKnife) and (tmpDmg > 0) then |
|
925 |
for j:= 1 to max(1,min(3,tmpDmg div 5)) do |
|
926 |
begin |
|
927 |
VGear:= AddVisualGear(hwRound(Ammo^.X-((Ammo^.X-Gear^.X)/_2)), hwRound(Ammo^.Y-((Ammo^.Y-Gear^.Y)/_2)), vgtStraightShot); |
|
928 |
if VGear <> nil then |
|
929 |
with VGear^ do |
|
930 |
begin |
|
931 |
Tint:= $FFCC00FF; |
|
932 |
Angle:= random(360); |
|
933 |
dx:= 0.0005 * (random(100)); |
|
934 |
dy:= 0.0005 * (random(100)); |
|
935 |
if random(2) = 0 then |
|
936 |
dx := -dx; |
|
937 |
if random(2) = 0 then |
|
938 |
dy := -dy; |
|
939 |
FrameTicks:= 600+random(200); |
|
940 |
State:= ord(sprStar) |
|
941 |
end |
|
942 |
end; |
|
943 |
ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove) |
|
944 |
end |
|
945 |
else |
|
946 |
Gear^.State:= Gear^.State or gstWinner; |
|
947 |
if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then |
|
948 |
begin |
|
949 |
if (Ammo^.Hedgehog^.Gear <> nil) then |
|
950 |
Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable); |
|
951 |
ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch |
|
952 |
end; |
|
953 |
||
954 |
if (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.King or (Gear^.Hedgehog^.Effects[heFrozen] > 0)) then |
|
955 |
begin |
|
956 |
Gear^.dX:= Ammo^.dX * Power * _0_005; |
|
957 |
Gear^.dY:= Ammo^.dY * Power * _0_005 |
|
958 |
end |
|
959 |
else if ((Ammo^.Kind <> gtFlame) or (Gear^.Kind = gtHedgehog)) and (Power <> 0) then |
|
960 |
begin |
|
961 |
Gear^.dX:= Ammo^.dX * Power * _0_01; |
|
962 |
Gear^.dY:= Ammo^.dY * Power * _0_01 |
|
963 |
end; |
|
964 |
||
965 |
if (not isZero(Gear^.dX)) or (not isZero(Gear^.dY)) then |
|
966 |
begin |
|
967 |
Gear^.Active:= true; |
|
968 |
DeleteCI(Gear); |
|
969 |
Gear^.State:= Gear^.State or gstMoving; |
|
970 |
if Gear^.Kind = gtKnife then Gear^.State:= Gear^.State and (not gstCollision); |
|
971 |
// move the gear upwards a bit to throw it over tiny obstacles at start |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
972 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then |
9285 | 973 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
974 |
if (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) = 0) and |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
975 |
(TestCollisionYwithGear(Gear, -1) = 0) then |
9285 | 976 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
977 |
if (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) = 0) and |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
978 |
(TestCollisionYwithGear(Gear, -1) = 0) then |
9285 | 979 |
Gear^.Y:= Gear^.Y - _1; |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
980 |
if (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) = 0) and |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
981 |
(TestCollisionYwithGear(Gear, -1) = 0) then |
9285 | 982 |
Gear^.Y:= Gear^.Y - _1; |
983 |
end |
|
984 |
end; |
|
985 |
||
986 |
||
987 |
if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then |
|
988 |
FollowGear:= Gear |
|
989 |
end; |
|
990 |
end |
|
991 |
end; |
|
992 |
end; |
|
993 |
if i <> 0 then |
|
994 |
SetAllToActive |
|
995 |
end; |
|
996 |
||
997 |
||
998 |
function CountGears(Kind: TGearType): Longword; |
|
999 |
var t: PGear; |
|
1000 |
count: Longword = 0; |
|
1001 |
begin |
|
1002 |
||
1003 |
t:= GearsList; |
|
1004 |
while t <> nil do |
|
1005 |
begin |
|
1006 |
if t^.Kind = Kind then |
|
1007 |
inc(count); |
|
1008 |
t:= t^.NextGear |
|
1009 |
end; |
|
1010 |
CountGears:= count; |
|
1011 |
end; |
|
1012 |
||
1013 |
procedure SetAllToActive; |
|
1014 |
var t: PGear; |
|
1015 |
begin |
|
1016 |
AllInactive:= false; |
|
1017 |
t:= GearsList; |
|
1018 |
while t <> nil do |
|
1019 |
begin |
|
1020 |
t^.Active:= true; |
|
1021 |
t:= t^.NextGear |
|
1022 |
end |
|
1023 |
end; |
|
1024 |
||
1025 |
procedure SetAllHHToActive; inline; |
|
1026 |
begin |
|
1027 |
SetAllHHToActive(true) |
|
1028 |
end; |
|
1029 |
||
1030 |
||
1031 |
procedure SetAllHHToActive(Ice: boolean); |
|
1032 |
var t: PGear; |
|
1033 |
begin |
|
1034 |
AllInactive:= false; |
|
1035 |
t:= GearsList; |
|
1036 |
while t <> nil do |
|
1037 |
begin |
|
1038 |
if (t^.Kind = gtHedgehog) or (t^.Kind = gtExplosives) then |
|
1039 |
begin |
|
1040 |
if (t^.Kind = gtHedgehog) and Ice then CheckIce(t); |
|
1041 |
t^.Active:= true |
|
1042 |
end; |
|
1043 |
t:= t^.NextGear |
|
1044 |
end |
|
1045 |
end; |
|
1046 |
||
1047 |
||
1048 |
var GearsNearArray : TPGearArray; |
|
1049 |
function GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): PGearArrayS; |
|
1050 |
var |
|
1051 |
t: PGear; |
|
1052 |
s: Longword; |
|
1053 |
begin |
|
1054 |
r:= r*r; |
|
1055 |
s:= 0; |
|
1056 |
SetLength(GearsNearArray, s); |
|
1057 |
t := GearsList; |
|
1058 |
while t <> nil do |
|
1059 |
begin |
|
1060 |
if (t^.Kind = Kind) |
|
1061 |
and ((X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) < int2hwFloat(r)) then |
|
1062 |
begin |
|
1063 |
inc(s); |
|
1064 |
SetLength(GearsNearArray, s); |
|
1065 |
GearsNearArray[s - 1] := t; |
|
1066 |
end; |
|
1067 |
t := t^.NextGear; |
|
1068 |
end; |
|
1069 |
||
1070 |
GearsNear.size:= s; |
|
1071 |
GearsNear.ar:= @GearsNearArray |
|
1072 |
end; |
|
1073 |
||
1074 |
||
1075 |
procedure SpawnBoxOfSmth; |
|
1076 |
var t, aTot, uTot, a, h: LongInt; |
|
1077 |
i: TAmmoType; |
|
1078 |
begin |
|
1079 |
if (PlacingHogs) or |
|
1080 |
(cCaseFactor = 0) |
|
1081 |
or (CountGears(gtCase) >= 5) |
|
1082 |
or (GetRandom(cCaseFactor) <> 0) then |
|
1083 |
exit; |
|
1084 |
||
1085 |
FollowGear:= nil; |
|
1086 |
aTot:= 0; |
|
1087 |
uTot:= 0; |
|
1088 |
for i:= Low(TAmmoType) to High(TAmmoType) do |
|
1089 |
if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then |
|
1090 |
inc(aTot, Ammoz[i].Probability) |
|
1091 |
else |
|
1092 |
inc(uTot, Ammoz[i].Probability); |
|
1093 |
||
1094 |
t:=0; |
|
1095 |
a:=aTot; |
|
1096 |
h:= 1; |
|
1097 |
||
1098 |
if (aTot+uTot) <> 0 then |
|
1099 |
if ((GameFlags and gfInvulnerable) = 0) then |
|
1100 |
begin |
|
1101 |
h:= cHealthCaseProb * 100; |
|
1102 |
t:= GetRandom(10000); |
|
1103 |
a:= (10000-h)*aTot div (aTot+uTot) |
|
1104 |
end |
|
1105 |
else |
|
1106 |
begin |
|
1107 |
t:= GetRandom(aTot+uTot); |
|
1108 |
h:= 0 |
|
1109 |
end; |
|
1110 |
||
1111 |
||
1112 |
if t<h then |
|
1113 |
begin |
|
1114 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
|
1115 |
FollowGear^.Health:= cHealthCaseAmount; |
|
1116 |
FollowGear^.Pos:= posCaseHealth; |
|
1117 |
AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo); |
|
1118 |
end |
|
1119 |
else if (t<a+h) then |
|
1120 |
begin |
|
1121 |
t:= aTot; |
|
1122 |
if (t > 0) then |
|
1123 |
begin |
|
1124 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
|
1125 |
t:= GetRandom(t); |
|
1126 |
i:= Low(TAmmoType); |
|
1127 |
FollowGear^.Pos:= posCaseAmmo; |
|
1128 |
FollowGear^.AmmoType:= i; |
|
1129 |
AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo); |
|
1130 |
end |
|
1131 |
end |
|
1132 |
else |
|
1133 |
begin |
|
1134 |
t:= uTot; |
|
1135 |
if (t > 0) then |
|
1136 |
begin |
|
1137 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
|
1138 |
t:= GetRandom(t); |
|
1139 |
i:= Low(TAmmoType); |
|
1140 |
FollowGear^.Pos:= posCaseUtility; |
|
1141 |
FollowGear^.AmmoType:= i; |
|
1142 |
AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo); |
|
1143 |
end |
|
1144 |
end; |
|
1145 |
||
1146 |
// handles case of no ammo or utility crates - considered also placing booleans in uAmmos and altering probabilities |
|
1147 |
if (FollowGear <> nil) then |
|
1148 |
begin |
|
1149 |
FindPlace(FollowGear, true, 0, LAND_WIDTH); |
|
1150 |
||
1151 |
if (FollowGear <> nil) then |
|
1152 |
AddVoice(sndReinforce, CurrentTeam^.voicepack) |
|
1153 |
end |
|
1154 |
end; |
|
1155 |
||
1156 |
||
1157 |
function GetAmmo(Hedgehog: PHedgehog): TAmmoType; |
|
1158 |
var t, aTot: LongInt; |
|
1159 |
i: TAmmoType; |
|
1160 |
begin |
|
1161 |
Hedgehog:= Hedgehog; // avoid hint |
|
1162 |
||
1163 |
aTot:= 0; |
|
1164 |
for i:= Low(TAmmoType) to High(TAmmoType) do |
|
1165 |
if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then |
|
1166 |
inc(aTot, Ammoz[i].Probability); |
|
1167 |
||
1168 |
t:= aTot; |
|
1169 |
i:= Low(TAmmoType); |
|
1170 |
if (t > 0) then |
|
1171 |
begin |
|
1172 |
t:= GetRandom(t); |
|
1173 |
while t >= 0 do |
|
1174 |
begin |
|
1175 |
inc(i); |
|
1176 |
if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then |
|
1177 |
dec(t, Ammoz[i].Probability) |
|
1178 |
end |
|
1179 |
end; |
|
1180 |
GetAmmo:= i |
|
1181 |
end; |
|
1182 |
||
1183 |
function GetUtility(Hedgehog: PHedgehog): TAmmoType; |
|
1184 |
var t, uTot: LongInt; |
|
1185 |
i: TAmmoType; |
|
1186 |
begin |
|
1187 |
||
1188 |
uTot:= 0; |
|
1189 |
for i:= Low(TAmmoType) to High(TAmmoType) do |
|
1190 |
if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) |
|
1191 |
and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then |
|
1192 |
inc(uTot, Ammoz[i].Probability); |
|
1193 |
||
1194 |
t:= uTot; |
|
1195 |
i:= Low(TAmmoType); |
|
1196 |
if (t > 0) then |
|
1197 |
begin |
|
1198 |
t:= GetRandom(t); |
|
1199 |
while t >= 0 do |
|
1200 |
begin |
|
1201 |
inc(i); |
|
1202 |
if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1) |
|
1203 |
or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then |
|
1204 |
dec(t, Ammoz[i].Probability) |
|
1205 |
end |
|
1206 |
end; |
|
1207 |
GetUtility:= i |
|
1208 |
end; |
|
1209 |
||
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1210 |
(* |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1211 |
Intended to check Gear X/Y against the map left/right edges and apply one of the world modes |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1212 |
* Normal - infinite world, do nothing |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1213 |
* Wrap (entering left edge exits at same height on right edge) |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1214 |
* Bounce (striking edge is treated as a 100% elasticity bounce) |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1215 |
* From the depths (same as from sky, but from sea, with submersible flag set) |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1216 |
|
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1217 |
Trying to make the checks a little broader than on first pass to catch things that don't move normally. |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1218 |
*) |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1219 |
function WorldWrap(var Gear: PGear): boolean; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1220 |
var tdx: hwFloat; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1221 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1222 |
WorldWrap:= false; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1223 |
if WorldEdge = weNone then exit(false); |
9809 | 1224 |
if (hwRound(Gear^.X) - Gear^.Radius < LongInt(leftX)) or |
1225 |
(hwRound(Gear^.X) + LongInt(Gear^.Radius) > LongInt(rightX)) then |
|
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1226 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1227 |
if WorldEdge = weWrap then |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1228 |
begin |
9809 | 1229 |
if (hwRound(Gear^.X) - Gear^.Radius < LongInt(leftX)) then |
1230 |
Gear^.X:= int2hwfloat(rightX - Gear^.Radius) |
|
1231 |
else Gear^.X:= int2hwfloat(LongInt(leftX) + Gear^.Radius); |
|
9557 | 1232 |
LeftImpactTimer:= 150; |
1233 |
RightImpactTimer:= 150 |
|
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1234 |
end |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1235 |
else if WorldEdge = weBounce then |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1236 |
begin |
9809 | 1237 |
if (hwRound(Gear^.X) - Gear^.Radius < LongInt(leftX)) then |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1238 |
begin |
9557 | 1239 |
LeftImpactTimer:= 333; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1240 |
Gear^.dX.isNegative:= false; |
9809 | 1241 |
Gear^.X:= int2hwfloat(LongInt(leftX) + Gear^.Radius) |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1242 |
end |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1243 |
else |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1244 |
begin |
9557 | 1245 |
RightImpactTimer:= 333; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1246 |
Gear^.dX.isNegative:= true; |
9485
3dee8a3b0406
add shotgun wrap, revert 100px offset. Problematic w/ things that rely on Land.
nemo
parents:
9479
diff
changeset
|
1247 |
Gear^.X:= int2hwfloat(rightX-Gear^.Radius) |
9557 | 1248 |
end; |
9561 | 1249 |
if (Gear^.Radius > 2) and (Gear^.dX.QWordValue > _0_001.QWordValue) then |
1250 |
PlaySound(sndMelonImpact) |
|
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1251 |
end |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1252 |
else if WorldEdge = weSea then |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1253 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1254 |
if (hwRound(Gear^.Y) > cWaterLine) and (Gear^.State and gstSubmersible <> 0) then |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1255 |
Gear^.State:= Gear^.State and not gstSubmersible |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1256 |
else |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1257 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1258 |
Gear^.State:= Gear^.State or gstSubmersible; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1259 |
Gear^.X:= int2hwFloat(PlayWidth)*int2hwFloat(min(max(0,hwRound(Gear^.Y)),PlayHeight))/PlayHeight; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1260 |
Gear^.Y:= int2hwFloat(cWaterLine+cVisibleWater+Gear^.Radius*2); |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1261 |
tdx:= Gear^.dX; |
9522 | 1262 |
Gear^.dX:= -Gear^.dY; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1263 |
Gear^.dY:= tdx; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1264 |
Gear^.dY.isNegative:= true |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1265 |
end |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1266 |
end; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1267 |
(* |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1268 |
* Window in the sky (Gear moved high into the sky, Y is used to determine X) [unfortunately, not a safe thing to do. shame, I thought aerial bombardment would be kinda neat |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1269 |
This one would be really easy to freeze game unless it was flagged unfortunately. |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1270 |
|
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1271 |
else |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1272 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1273 |
Gear^.X:= int2hwFloat(PlayWidth)*int2hwFloat(min(max(0,hwRound(Gear^.Y)),PlayHeight))/PlayHeight; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1274 |
Gear^.Y:= -_2048-_256-_256; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1275 |
tdx:= Gear^.dX; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1276 |
Gear^.dX:= Gear^.dY; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1277 |
Gear^.dY:= tdx; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1278 |
Gear^.dY.isNegative:= false |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1279 |
end |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1280 |
*) |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1281 |
WorldWrap:= true |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1282 |
end; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1283 |
end; |
9285 | 1284 |
|
6581 | 1285 |
end. |