author | sheepluva |
Sat, 30 Apr 2016 00:13:11 +0200 | |
changeset 11785 | 2f8ffd1e1331 |
parent 11756 | 20e0a72e0e2c |
child 11827 | 4600dcb9db4f |
permissions | -rw-r--r-- |
6581 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10105
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6581 | 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; |
8330 | 26 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); |
10363 | 27 |
procedure AddSplashForGear(Gear: PGear; justSkipping: boolean); |
10508 | 28 |
procedure AddBounceEffectForGear(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
|
29 |
|
6581 | 30 |
function ModifyDamage(dmg: Longword; Gear: PGear): Longword; |
31 |
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); |
|
32 |
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword); |
|
33 |
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource); |
|
34 |
procedure CheckHHDamage(Gear: PGear); |
|
35 |
procedure CalcRotationDirAngle(Gear: PGear); |
|
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
36 |
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
|
37 |
|
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
|
6581 | 41 |
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
|
42 |
function CheckGearDrowning(var Gear: PGear): boolean; |
7592 | 43 |
procedure CheckCollision(Gear: PGear); inline; |
44 |
procedure CheckCollisionWithLand(Gear: PGear); inline; |
|
6581 | 45 |
|
9285 | 46 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
47 |
function GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): PGearArrayS; |
|
48 |
procedure SpawnBoxOfSmth; |
|
49 |
procedure ShotgunShot(Gear: PGear); |
|
50 |
||
51 |
procedure SetAllToActive; |
|
52 |
procedure SetAllHHToActive(Ice: boolean); |
|
9954 | 53 |
procedure SetAllHHToActive(); inline; |
9285 | 54 |
|
55 |
function GetAmmo(Hedgehog: PHedgehog): TAmmoType; |
|
56 |
function GetUtility(Hedgehog: PHedgehog): TAmmoType; |
|
57 |
||
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
58 |
function WorldWrap(var Gear: PGear): boolean; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
59 |
|
9285 | 60 |
|
61 |
||
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
62 |
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
|
63 |
|
6581 | 64 |
var doStepHandlers: array[TGearType] of TGearStepProcedure; |
65 |
||
66 |
implementation |
|
9285 | 67 |
uses uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc, |
6581 | 68 |
uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore, |
10015 | 69 |
uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, |
9285 | 70 |
uGearsList, Math, uVisualGearsList, uGearsHandlersMess, |
71 |
uGearsHedgehog; |
|
6581 | 72 |
|
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
73 |
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
|
74 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
75 |
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
|
76 |
end; |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
77 |
|
6581 | 78 |
procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); |
79 |
var Gear: PGear; |
|
6769
44ad49a3a126
Add drowning to grenade too, try some little optimisations
nemo
parents:
6765
diff
changeset
|
80 |
dmg, dmgBase: LongInt; |
6765 | 81 |
fX, fY, tdX, tdY: hwFloat; |
6581 | 82 |
vg: PVisualGear; |
83 |
i, cnt: LongInt; |
|
10653 | 84 |
wrap: boolean; |
10827 | 85 |
bubble: PVisualGear; |
6581 | 86 |
begin |
87 |
if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
88 |
if Radius > 25 then KickFlakes(Radius, X, Y); |
|
89 |
||
90 |
if ((Mask and EXPLNoGfx) = 0) then |
|
91 |
begin |
|
92 |
vg:= nil; |
|
10827 | 93 |
if CheckCoordInWater(X, Y - Radius) then |
94 |
begin |
|
95 |
cnt:= 2 * Radius; |
|
96 |
for i:= (Radius * Radius) div 4 downto 0 do |
|
97 |
begin |
|
98 |
bubble := AddVisualGear(X - Radius + random(cnt), Y - Radius + random(cnt), vgtBubble); |
|
99 |
if bubble <> nil then |
|
100 |
bubble^.dY:= 0.1 + random(20)/10; |
|
101 |
end |
|
102 |
end |
|
103 |
else if Radius > 50 then vg:= AddVisualGear(X, Y, vgtBigExplosion) |
|
6581 | 104 |
else if Radius > 10 then vg:= AddVisualGear(X, Y, vgtExplosion); |
105 |
if vg <> nil then |
|
106 |
vg^.Tint:= Tint; |
|
107 |
end; |
|
108 |
if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion); |
|
109 |
||
6765 | 110 |
(*if (Mask and EXPLAllDamageInRadius) = 0 then |
6581 | 111 |
dmgRadius:= Radius shl 1 |
112 |
else |
|
113 |
dmgRadius:= Radius; |
|
6765 | 114 |
dmgBase:= dmgRadius + cHHRadius div 2;*) |
115 |
dmgBase:= Radius shl 1 + cHHRadius div 2; |
|
10653 | 116 |
|
117 |
// we might have to run twice if weWrap is enabled |
|
118 |
wrap:= false; |
|
10659 | 119 |
repeat |
10653 | 120 |
|
10654 | 121 |
fX:= int2hwFloat(X); |
122 |
fY:= int2hwFloat(Y); |
|
123 |
Gear:= GearsList; |
|
124 |
||
6581 | 125 |
while Gear <> nil do |
126 |
begin |
|
127 |
dmg:= 0; |
|
128 |
//dmg:= dmgRadius + cHHRadius div 2 - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
|
129 |
//if (dmg > 1) and |
|
130 |
if (Gear^.State and gstNoDamage) = 0 then |
|
131 |
begin |
|
132 |
case Gear^.Kind of |
|
133 |
gtHedgehog, |
|
134 |
gtMine, |
|
135 |
gtBall, |
|
136 |
gtMelonPiece, |
|
137 |
gtGrenade, |
|
138 |
gtClusterBomb, |
|
139 |
// gtCluster, too game breaking I think |
|
140 |
gtSMine, |
|
10789
acbf69e2e5cf
experiment with air mines. thought they could make shoppa... interesting. ToDo: Allow mines to give up, tweak distances, real graphics, toggle for whether they can acquire a new target while they haven't given up.
nemo
parents:
10668
diff
changeset
|
141 |
gtAirMine, |
6581 | 142 |
gtCase, |
143 |
gtTarget, |
|
144 |
gtFlame, |
|
7754 | 145 |
gtKnife, |
8161 | 146 |
gtExplosives: begin //, |
147 |
//gtStructure: begin |
|
6581 | 148 |
// Run the calcs only once we know we have a type that will need damage |
6765 | 149 |
tdX:= Gear^.X-fX; |
150 |
tdY:= Gear^.Y-fY; |
|
7721 | 151 |
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
|
152 |
dmg:= dmgBase - hwRound(Distance(tdX, tdY)); |
6581 | 153 |
if dmg > 1 then |
154 |
begin |
|
155 |
dmg:= ModifyDamage(min(dmg div 2, Radius), Gear); |
|
156 |
//AddFileLog('Damage: ' + inttostr(dmg)); |
|
157 |
if (Mask and EXPLNoDamage) = 0 then |
|
158 |
begin |
|
10011
ead5e4b21671
Add check for gear kind of hedgehog on invulnerability effect. This probably fixes bug #766, is similar to change in previous r2a1483d91977 and was introduced by r7d925e82e572
nemo
parents:
10010
diff
changeset
|
159 |
if (Gear^.Kind <> gtHedgehog) or (Gear^.Hedgehog^.Effects[heInvulnerable] = 0) then |
6581 | 160 |
ApplyDamage(Gear, AttackingHog, dmg, dsExplosion) |
161 |
else |
|
162 |
Gear^.State:= Gear^.State or gstWinner; |
|
163 |
end; |
|
164 |
if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then |
|
165 |
begin |
|
166 |
DeleteCI(Gear); |
|
6765 | 167 |
Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, tdX)/(Gear^.Density/_3); |
168 |
Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, tdY)/(Gear^.Density/_3); |
|
6581 | 169 |
|
170 |
Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser); |
|
7767 | 171 |
if Gear^.Kind = gtKnife then Gear^.State:= Gear^.State and (not gstCollision); |
10011
ead5e4b21671
Add check for gear kind of hedgehog on invulnerability effect. This probably fixes bug #766, is similar to change in previous r2a1483d91977 and was introduced by r7d925e82e572
nemo
parents:
10010
diff
changeset
|
172 |
if (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heInvulnerable] = 0) then |
6581 | 173 |
Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner); |
174 |
Gear^.Active:= true; |
|
175 |
if Gear^.Kind <> gtFlame then FollowGear:= Gear |
|
176 |
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
|
177 |
if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heInvulnerable] = 0) and (Gear^.State and gstHHDeath = 0) then |
10012
82dd9f0c88f7
Make poison damage possibly variable (might as well since effects is a count). Scripts might find it handy.
nemo
parents:
10011
diff
changeset
|
178 |
Gear^.Hedgehog^.Effects[hePoisoned] := 5; |
6581 | 179 |
end; |
180 |
||
181 |
end; |
|
9814 | 182 |
gtGrave: if Mask and EXPLDoNotTouchAny = 0 then |
6581 | 183 |
// Run the calcs only once we know we have a type that will need damage |
184 |
begin |
|
9814 | 185 |
tdX:= Gear^.X-fX; |
186 |
tdY:= Gear^.Y-fY; |
|
187 |
if LongInt(tdX.Round + tdY.Round + 2) < dmgBase then |
|
188 |
dmg:= dmgBase - hwRound(Distance(tdX, tdY)); |
|
189 |
if dmg > 1 then |
|
190 |
begin |
|
191 |
dmg:= ModifyDamage(min(dmg div 2, Radius), Gear); |
|
192 |
Gear^.dY:= - _0_004 * dmg; |
|
193 |
Gear^.Active:= true |
|
194 |
end |
|
195 |
end; |
|
6581 | 196 |
end; |
197 |
end; |
|
198 |
Gear:= Gear^.NextGear |
|
199 |
end; |
|
200 |
||
201 |
if (Mask and EXPLDontDraw) = 0 then |
|
202 |
if (GameFlags and gfSolidLand) = 0 then |
|
203 |
begin |
|
204 |
cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk |
|
205 |
if (cnt > 0) and (SpritesData[sprChunk].Texture <> nil) then |
|
206 |
for i:= 0 to cnt do |
|
207 |
AddVisualGear(X, Y, vgtChunk) |
|
208 |
end; |
|
209 |
||
10653 | 210 |
if (WorldEdge = weWrap) then |
211 |
begin |
|
212 |
// already wrapped? let's not wrap again! |
|
213 |
if wrap then |
|
214 |
break; |
|
215 |
||
216 |
// Radius + 5 because that's the actual radius the explosion changes graphically |
|
217 |
if X + (Radius + 5) > LongInt(rightX) then |
|
218 |
begin |
|
219 |
dec(X, playWidth); |
|
220 |
wrap:= true; |
|
221 |
end |
|
222 |
else if X - (Radius + 5) < LongInt(leftX) then |
|
223 |
begin |
|
224 |
inc(X, playWidth); |
|
225 |
wrap:= true; |
|
226 |
end; |
|
227 |
end; |
|
228 |
||
229 |
until (not wrap); |
|
230 |
||
6581 | 231 |
uAIMisc.AwareOfExplosion(0, 0, 0) |
232 |
end; |
|
233 |
||
234 |
function ModifyDamage(dmg: Longword; Gear: PGear): Longword; |
|
235 |
var i: hwFloat; |
|
236 |
begin |
|
237 |
(* Invulnerability cannot be placed in here due to still needing kicks |
|
238 |
Not without a new damage machine. |
|
239 |
King check should be in here instead of ApplyDamage since Tiy wants them kicked less |
|
240 |
*) |
|
241 |
i:= _1; |
|
242 |
if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then |
|
243 |
i:= _1_5; |
|
10015 | 244 |
if (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog <> nil) and |
10010
2a1483d91977
well. let's fix this at least - only apply to gears that are actually hedgehogs, not just ones associated with a hedgehog (which can be pretty much any gear since damage tracking was added)
nemo
parents:
9998
diff
changeset
|
245 |
(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
|
246 |
ModifyDamage:= hwRound(cDamageModifier * dmg * i * cDamagePercent * _0_5 * _0_01) |
9149 | 247 |
else |
10526
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
248 |
ModifyDamage:= hwRound(cDamageModifier * dmg * i * cDamagePercent * _0_01); |
6581 | 249 |
end; |
250 |
||
251 |
procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); |
|
252 |
var s: shortstring; |
|
253 |
vampDmg, tmpDmg, i: Longword; |
|
254 |
vg: PVisualGear; |
|
255 |
begin |
|
256 |
if Damage = 0 then |
|
257 |
exit; // nothing to apply |
|
258 |
||
259 |
if (Gear^.Kind = gtHedgehog) then |
|
260 |
begin |
|
261 |
Gear^.LastDamage := AttackerHog; |
|
262 |
||
263 |
Gear^.Hedgehog^.Team^.Clan^.Flawless:= false; |
|
264 |
HHHurt(Gear^.Hedgehog, Source); |
|
265 |
AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color); |
|
266 |
tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage)); |
|
267 |
if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then |
|
268 |
begin |
|
269 |
if cVampiric then |
|
270 |
begin |
|
271 |
vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8); |
|
272 |
if vampDmg >= 1 then |
|
273 |
begin |
|
274 |
// was considering pulsing on attack, Tiy thinks it should be permanent while in play |
|
275 |
//CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric; |
|
276 |
inc(CurrentHedgehog^.Gear^.Health,vampDmg); |
|
277 |
str(vampDmg, s); |
|
278 |
s:= '+' + s; |
|
10124
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
10116
diff
changeset
|
279 |
AddCaption(ansistring(s), CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); |
6581 | 280 |
RenderHealth(CurrentHedgehog^); |
281 |
RecountTeamHealth(CurrentHedgehog^.Team); |
|
282 |
i:= 0; |
|
283 |
while i < vampDmg do |
|
284 |
begin |
|
285 |
vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot); |
|
286 |
if vg <> nil then |
|
287 |
with vg^ do |
|
288 |
begin |
|
289 |
Tint:= $FF0000FF; |
|
290 |
State:= ord(sprHealth) |
|
291 |
end; |
|
292 |
inc(i, 5); |
|
293 |
end; |
|
294 |
end |
|
295 |
end; |
|
10015 | 296 |
if (GameFlags and gfKarma <> 0) and (GameFlags and gfInvulnerable = 0) and |
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
|
297 |
(CurrentHedgehog^.Effects[heInvulnerable] = 0) then |
6581 | 298 |
begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid |
299 |
inc(CurrentHedgehog^.Gear^.Karma, tmpDmg); |
|
300 |
CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog; |
|
301 |
spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg); |
|
302 |
end; |
|
8330 | 303 |
uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false); |
6581 | 304 |
end; |
10526
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
305 |
|
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
306 |
if AprilOne and (Gear^.Hedgehog^.Hat = 'fr_tomato') and (Damage > 2) then |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
307 |
for i := 0 to random(min(Damage,20))+5 do |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
308 |
begin |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
309 |
vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot); |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
310 |
if vg <> nil then |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
311 |
with vg^ do |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
312 |
begin |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
313 |
dx:= 0.001 * (random(100)+10); |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
314 |
dy:= 0.001 * (random(100)+10); |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
315 |
tdy:= -cGravityf; |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
316 |
if random(2) = 0 then |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
317 |
dx := -dx; |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
318 |
//if random(2) = 0 then |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
319 |
// dy := -dy; |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
320 |
FrameTicks:= random(500) + 1000; |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
321 |
State:= ord(sprBubbles); |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
322 |
//Tint:= $bd2f03ff |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
323 |
Tint:= $ff0000ff |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
324 |
end |
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
325 |
end |
8199
886ed135665b
Fix crashes and wtf behaviour introduced in r0b8beacff8a5
unc0rr
parents:
8161
diff
changeset
|
326 |
end else |
8161 | 327 |
//else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure |
6581 | 328 |
Gear^.Hedgehog:= AttackerHog; |
329 |
inc(Gear^.Damage, Damage); |
|
8330 | 330 |
|
6581 | 331 |
ScriptCall('onGearDamage', Gear^.UID, Damage); |
332 |
end; |
|
333 |
||
334 |
procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword); |
|
335 |
var tag: PVisualGear; |
|
336 |
begin |
|
337 |
tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg); |
|
338 |
if (tag <> nil) then |
|
339 |
tag^.Hedgehog:= HHGear^.Hedgehog; // the tag needs the tag to determine the text color |
|
340 |
AllInactive:= false; |
|
341 |
HHGear^.Active:= true; |
|
342 |
end; |
|
8330 | 343 |
|
6581 | 344 |
procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource); |
345 |
begin |
|
9071 | 346 |
if Hedgehog^.Effects[heFrozen] <> 0 then exit; |
10526
b43d175d1577
Avoid promoting violence to hedgehogs. At least once a year.
nemo
parents:
10512
diff
changeset
|
347 |
|
6581 | 348 |
if (Source = dsFall) or (Source = dsExplosion) then |
349 |
case random(3) of |
|
7053 | 350 |
0: PlaySoundV(sndOoff1, Hedgehog^.Team^.voicepack); |
351 |
1: PlaySoundV(sndOoff2, Hedgehog^.Team^.voicepack); |
|
352 |
2: PlaySoundV(sndOoff3, Hedgehog^.Team^.voicepack); |
|
6581 | 353 |
end |
354 |
else if (Source = dsPoison) then |
|
355 |
case random(2) of |
|
7053 | 356 |
0: PlaySoundV(sndPoisonCough, Hedgehog^.Team^.voicepack); |
357 |
1: PlaySoundV(sndPoisonMoan, Hedgehog^.Team^.voicepack); |
|
6581 | 358 |
end |
359 |
else |
|
360 |
case random(4) of |
|
7053 | 361 |
0: PlaySoundV(sndOw1, Hedgehog^.Team^.voicepack); |
362 |
1: PlaySoundV(sndOw2, Hedgehog^.Team^.voicepack); |
|
363 |
2: PlaySoundV(sndOw3, Hedgehog^.Team^.voicepack); |
|
364 |
3: PlaySoundV(sndOw4, Hedgehog^.Team^.voicepack); |
|
6581 | 365 |
end |
366 |
end; |
|
367 |
||
368 |
procedure CheckHHDamage(Gear: PGear); |
|
10015 | 369 |
var |
9809 | 370 |
dmg: LongInt; |
8003 | 371 |
i: LongWord; |
6581 | 372 |
particle: PVisualGear; |
373 |
begin |
|
9071 | 374 |
if _0_4 < Gear^.dY then |
375 |
begin |
|
376 |
dmg := ModifyDamage(1 + hwRound((Gear^.dY - _0_4) * 70), Gear); |
|
377 |
if Gear^.Hedgehog^.Effects[heFrozen] = 0 then |
|
378 |
PlaySound(sndBump) |
|
379 |
else PlaySound(sndFrozenHogImpact); |
|
380 |
if dmg < 1 then |
|
381 |
exit; |
|
6581 | 382 |
|
9809 | 383 |
for i:= min(12, 3 + dmg div 10) downto 0 do |
9071 | 384 |
begin |
385 |
particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust); |
|
386 |
if particle <> nil then |
|
387 |
particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480); |
|
388 |
end; |
|
6581 | 389 |
|
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
|
390 |
if ((Gear^.Hedgehog^.Effects[heInvulnerable] <> 0)) then |
9071 | 391 |
exit; |
6581 | 392 |
|
9071 | 393 |
//if _0_6 < Gear^.dY then |
394 |
// PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack) |
|
395 |
//else |
|
396 |
// PlaySound(sndOw1, Gear^.Hedgehog^.Team^.voicepack); |
|
6581 | 397 |
|
9071 | 398 |
if Gear^.LastDamage <> nil then |
399 |
ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall) |
|
400 |
else |
|
401 |
ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall); |
|
6581 | 402 |
end |
403 |
end; |
|
404 |
||
405 |
||
406 |
procedure CalcRotationDirAngle(Gear: PGear); |
|
8330 | 407 |
var |
6581 | 408 |
dAngle: real; |
409 |
begin |
|
7825 | 410 |
// Frac/Round to be kind to JS as of 2012-08-27 where there is yet no int64/uint64 |
411 |
//dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000; |
|
412 |
dAngle := (Gear^.dX.Round + Gear^.dY.Round) / 2 + (Gear^.dX.Frac/$100000000+Gear^.dY.Frac/$100000000); |
|
6581 | 413 |
if not Gear^.dX.isNegative then |
414 |
Gear^.DirAngle := Gear^.DirAngle + dAngle |
|
415 |
else |
|
416 |
Gear^.DirAngle := Gear^.DirAngle - dAngle; |
|
417 |
||
418 |
if Gear^.DirAngle < 0 then |
|
419 |
Gear^.DirAngle := Gear^.DirAngle + 360 |
|
420 |
else if 360 < Gear^.DirAngle then |
|
421 |
Gear^.DirAngle := Gear^.DirAngle - 360 |
|
422 |
end; |
|
423 |
||
10363 | 424 |
procedure AddSplashForGear(Gear: PGear; justSkipping: boolean); |
425 |
var x, y, i, distL, distR, distB, minDist, maxDrops: LongInt; |
|
426 |
splash, particle: PVisualGear; |
|
427 |
speed, hwTmp: hwFloat; |
|
428 |
vi, vs, tmp: real; // impact speed and sideways speed |
|
429 |
isImpactH, isImpactRight: boolean; |
|
10419 | 430 |
const dist2surf = 4; |
10363 | 431 |
begin |
432 |
x:= hwRound(Gear^.X); |
|
433 |
y:= hwRound(Gear^.Y); |
|
434 |
||
10419 | 435 |
// find position for splash and impact speed |
10363 | 436 |
|
437 |
distB:= cWaterline - y; |
|
438 |
||
439 |
if WorldEdge <> weSea then |
|
440 |
minDist:= distB |
|
441 |
else |
|
442 |
begin |
|
443 |
distL:= x - leftX; |
|
444 |
distR:= rightX - x; |
|
445 |
minDist:= min(distB, min(distL, distR)); |
|
446 |
end; |
|
447 |
||
448 |
isImpactH:= (minDist <> distB); |
|
449 |
||
450 |
if not isImpactH then |
|
451 |
begin |
|
10417 | 452 |
y:= cWaterline - dist2surf; |
10363 | 453 |
speed:= hwAbs(Gear^.dY); |
454 |
end |
|
455 |
else |
|
456 |
begin |
|
457 |
isImpactRight := minDist = distR; |
|
458 |
if isImpactRight then |
|
10419 | 459 |
x:= rightX - dist2surf |
10363 | 460 |
else |
10419 | 461 |
x:= leftX + dist2surf; |
10363 | 462 |
speed:= hwAbs(Gear^.dX); |
463 |
end; |
|
464 |
||
465 |
// splash sound |
|
466 |
||
467 |
if justSkipping then |
|
468 |
PlaySound(sndSkip) |
|
469 |
else |
|
470 |
begin |
|
471 |
// adjust water impact sound based on gear speed and density |
|
472 |
hwTmp:= hwAbs(Gear^.Density * speed); |
|
473 |
||
474 |
if hwTmp > _1 then |
|
475 |
PlaySound(sndSplash) |
|
476 |
else if hwTmp > _0_5 then |
|
477 |
PlaySound(sndSkip) |
|
478 |
else |
|
479 |
PlaySound(sndDroplet2); |
|
480 |
end; |
|
481 |
||
10419 | 482 |
|
483 |
// splash visuals |
|
484 |
||
485 |
if ((cReducedQuality and rqPlainSplash) <> 0) then |
|
486 |
exit; |
|
487 |
||
488 |
splash:= AddVisualGear(x, y, vgtSplash); |
|
489 |
if splash = nil then |
|
490 |
exit; |
|
491 |
||
492 |
if not isImpactH then |
|
493 |
vs:= abs(hwFloat2Float(Gear^.dX)) |
|
494 |
else |
|
495 |
begin |
|
496 |
if isImpactRight then |
|
497 |
splash^.Angle:= -90 |
|
498 |
else |
|
499 |
splash^.Angle:= 90; |
|
500 |
vs:= abs(hwFloat2Float(Gear^.dY)); |
|
501 |
end; |
|
502 |
||
503 |
||
504 |
vi:= hwFloat2Float(speed); |
|
505 |
||
10363 | 506 |
with splash^ do |
507 |
begin |
|
508 |
Scale:= abs(hwFloat2Float(Gear^.Density / _3 * speed)); |
|
509 |
if Scale > 1 then Scale:= power(Scale,0.3333) |
|
510 |
else Scale:= Scale + ((1-Scale) / 2); |
|
511 |
if Scale > 1 then Timer:= round(min(Scale*0.0005/cGravityf,4)) |
|
512 |
else Timer:= 1; |
|
513 |
// Low Gravity |
|
514 |
FrameTicks:= FrameTicks*Timer; |
|
515 |
end; |
|
516 |
||
517 |
||
518 |
// eject water drops |
|
519 |
||
520 |
maxDrops := (hwRound(Gear^.Density) * 3) div 2 + round((vi + vs) * hwRound(Gear^.Density) * 6); |
|
521 |
for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do |
|
522 |
begin |
|
523 |
if isImpactH then |
|
524 |
particle := AddVisualGear(x, y - 3 + Random(7), vgtDroplet) |
|
525 |
else |
|
526 |
particle := AddVisualGear(x - 3 + Random(7), y, vgtDroplet); |
|
527 |
||
528 |
if particle <> nil then |
|
529 |
with particle^ do |
|
530 |
begin |
|
531 |
// dX and dY were initialized to have a random value on creation (see uVisualGearsList) |
|
532 |
if isImpactH then |
|
533 |
begin |
|
534 |
tmp:= dX; |
|
535 |
if isImpactRight then |
|
536 |
dX:= dY - vi / 5 |
|
537 |
else |
|
538 |
dX:= -dy + vi / 5; |
|
539 |
dY:= tmp * (1 + vs / 10); |
|
540 |
end |
|
541 |
else |
|
542 |
begin |
|
543 |
dX:= dX * (1 + vs / 10); |
|
544 |
dY:= dY - vi / 5; |
|
545 |
end; |
|
546 |
||
547 |
if splash <> nil then |
|
548 |
begin |
|
549 |
if splash^.Scale > 1 then |
|
550 |
begin |
|
551 |
dX:= dX * power(splash^.Scale, 0.3333); // tone down the droplet height further |
|
552 |
dY:= dY * power(splash^.Scale, 0.3333); |
|
553 |
end |
|
554 |
else |
|
555 |
begin |
|
556 |
dX:= dX * splash^.Scale; |
|
557 |
dY:= dY * splash^.Scale; |
|
558 |
end; |
|
559 |
end; |
|
560 |
end |
|
561 |
end; |
|
562 |
||
563 |
end; |
|
564 |
||
10354 | 565 |
procedure DrownGear(Gear: PGear); |
566 |
begin |
|
567 |
Gear^.doStep := @doStepDrowningGear; |
|
568 |
||
569 |
Gear^.Timer := 5000; // how long game should wait |
|
570 |
end; |
|
571 |
||
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
572 |
function CheckGearDrowning(var Gear: PGear): boolean; |
10015 | 573 |
var |
10363 | 574 |
skipSpeed, skipAngle, skipDecay: hwFloat; |
575 |
tmp, X, Y, dist2Water: LongInt; |
|
576 |
isSubmersible, isDirH, isImpact, isSkip: boolean; |
|
10124
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
10116
diff
changeset
|
577 |
s: ansistring; |
6581 | 578 |
begin |
579 |
// probably needs tweaking. might need to be in a case statement based upon gear type |
|
10354 | 580 |
X:= hwRound(Gear^.X); |
6581 | 581 |
Y:= hwRound(Gear^.Y); |
10354 | 582 |
|
583 |
dist2Water:= cWaterLine - (Y + Gear^.Radius); |
|
10363 | 584 |
isDirH:= false; |
10354 | 585 |
|
586 |
if WorldEdge = weSea then |
|
6581 | 587 |
begin |
10363 | 588 |
tmp:= dist2Water; |
10494 | 589 |
dist2Water:= min(dist2Water, min(X - Gear^.Radius - LongInt(leftX), LongInt(rightX) - (X + Gear^.Radius))); |
10363 | 590 |
// if water on sides is closer than on bottom -> horizontal direction |
591 |
isDirH:= tmp <> dist2Water; |
|
10354 | 592 |
end; |
593 |
||
10363 | 594 |
isImpact:= false; |
595 |
||
10354 | 596 |
if dist2Water < 0 then |
597 |
begin |
|
598 |
// invisible gears will just be deleted |
|
599 |
// unless they are generic fallers, then they will be "respawned" |
|
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
|
600 |
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
|
601 |
begin |
7406
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
602 |
if Gear^.Kind = gtGenericFaller then |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
603 |
begin |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
604 |
Gear^.X:= int2hwFloat(GetRandom(rightX-leftX)+leftX); |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
605 |
Gear^.Y:= int2hwFloat(GetRandom(LAND_HEIGHT-topY)+topY); |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
606 |
Gear^.dX:= _90-(GetRandomf*_360); |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
607 |
Gear^.dY:= _90-(GetRandomf*_360) |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
608 |
end |
1fe2c821f9bf
Try avoiding spamming the log by retaining the gears. untested.
nemo
parents:
7389
diff
changeset
|
609 |
else DeleteGear(Gear); |
10245 | 610 |
exit(true) |
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
|
611 |
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
|
612 |
isSubmersible:= ((Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.State and gstSubmersible <> 0)) or (Gear^.State and gstSubmersible <> 0); |
10363 | 613 |
|
6581 | 614 |
skipSpeed := _0_25; |
615 |
skipAngle := _1_9; |
|
616 |
skipDecay := _0_87; |
|
10363 | 617 |
|
10354 | 618 |
|
619 |
// skipping |
|
620 |
||
10512
25021aac078e
fix underwater-skipping bug and make air-strike missiles submersible when fired from within weSea
sheepluva
parents:
10508
diff
changeset
|
621 |
if (not isSubmersible) and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) |
10363 | 622 |
and ( ((not isDirH) and (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY))) |
623 |
or (isDirH and (hwAbs(Gear^.dY) > skipAngle * hwAbs(Gear^.dX))) ) then |
|
6581 | 624 |
begin |
10363 | 625 |
isSkip:= true; |
10354 | 626 |
// if skipping we move the gear out of water |
10363 | 627 |
if isDirH then |
10354 | 628 |
begin |
629 |
Gear^.dX.isNegative := (not Gear^.dX.isNegative); |
|
630 |
Gear^.X:= Gear^.X + Gear^.dX; |
|
631 |
end |
|
632 |
else |
|
633 |
begin |
|
634 |
Gear^.dY.isNegative := (not Gear^.dY.isNegative); |
|
635 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
|
636 |
end; |
|
6581 | 637 |
Gear^.dY := Gear^.dY * skipDecay; |
638 |
Gear^.dX := Gear^.dX * skipDecay; |
|
639 |
CheckGearDrowning := false; |
|
640 |
end |
|
10354 | 641 |
else // not skipping |
6581 | 642 |
begin |
10363 | 643 |
isImpact:= true; |
644 |
isSkip:= false; |
|
6581 | 645 |
if not isSubmersible then |
646 |
begin |
|
647 |
CheckGearDrowning := true; |
|
648 |
Gear^.State := gstDrowning; |
|
649 |
Gear^.RenderTimer := false; |
|
650 |
if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot) |
|
651 |
and (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then |
|
652 |
if Gear^.Kind = gtHedgehog then |
|
653 |
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
|
654 |
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
|
655 |
begin |
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
656 |
// 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
|
657 |
ResurrectHedgehog(Gear); |
10245 | 658 |
exit(true) |
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
659 |
end |
6581 | 660 |
else |
661 |
begin |
|
10354 | 662 |
DrownGear(Gear); |
6581 | 663 |
Gear^.State := Gear^.State and (not gstHHDriven); |
10124
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
10116
diff
changeset
|
664 |
s:= ansistring(Gear^.Hedgehog^.Name); |
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
10116
diff
changeset
|
665 |
AddCaption(FormatA(GetEventString(eidDrowned), s), cWhiteColor, capgrpMessage); |
6581 | 666 |
end |
667 |
end |
|
668 |
else |
|
10354 | 669 |
DrownGear(Gear); |
10419 | 670 |
if Gear^.Kind = gtFlake then |
10354 | 671 |
exit(true); // skip splashes |
8990 | 672 |
end |
10363 | 673 |
else // submersible |
674 |
begin |
|
675 |
// drown submersible grears if far below map |
|
676 |
if (Y > cWaterLine + cVisibleWater*4) then |
|
677 |
begin |
|
678 |
DrownGear(Gear); |
|
679 |
exit(true); // no splashes needed |
|
680 |
end; |
|
10354 | 681 |
|
10363 | 682 |
CheckGearDrowning := false; |
683 |
||
684 |
// check if surface was penetrated |
|
10354 | 685 |
|
10363 | 686 |
// no penetration if center's water distance not smaller than radius |
687 |
if abs(dist2Water + Gear^.Radius) >= Gear^.Radius then |
|
688 |
isImpact:= false |
|
6804 | 689 |
else |
10354 | 690 |
begin |
10363 | 691 |
// get distance to water of last tick |
692 |
if isDirH then |
|
693 |
begin |
|
694 |
tmp:= hwRound(Gear^.X - Gear^.dX); |
|
695 |
tmp:= abs(min(tmp - leftX, rightX - tmp)); |
|
696 |
end |
|
10354 | 697 |
else |
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
|
698 |
begin |
10363 | 699 |
tmp:= hwRound(Gear^.Y - Gear^.dY); |
700 |
tmp:= abs(cWaterLine - tmp); |
|
701 |
end; |
|
10354 | 702 |
|
10419 | 703 |
// there was an impact if distance was >= radius |
704 |
isImpact:= (tmp >= Gear^.Radius) |
|
10363 | 705 |
end; |
706 |
end; // end of submersible |
|
707 |
end; // end of not skipping |
|
708 |
||
709 |
// splash sound animation and droplets |
|
710 |
if isImpact or isSkip then |
|
711 |
addSplashForGear(Gear, isSkip); |
|
712 |
||
10668 | 713 |
if isSkip then |
714 |
ScriptCall('onGearWaterSkip', Gear^.uid); |
|
6581 | 715 |
end |
716 |
else |
|
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
717 |
CheckGearDrowning := false |
6581 | 718 |
end; |
719 |
||
720 |
||
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
721 |
procedure ResurrectHedgehog(var gear: PGear); |
6581 | 722 |
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
|
723 |
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
|
724 |
gX, gY: LongInt; |
6581 | 725 |
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
|
726 |
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
|
727 |
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
|
728 |
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
|
729 |
uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true); |
6581 | 730 |
AttackBar:= 0; |
731 |
gear^.dX := _0; |
|
732 |
gear^.dY := _0; |
|
733 |
gear^.Damage := 0; |
|
734 |
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
|
735 |
gear^.Hedgehog^.Effects[hePoisoned] := 0; |
7176
fb4b0c6dfdbd
Make watching AI v AI on ai survival a bit more entertaining
nemo
parents:
7168
diff
changeset
|
736 |
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
|
737 |
and (Gear^.Hedgehog^.Team^.Clan <> CurrentHedgehog^.Team^.Clan)) then |
8330 | 738 |
with CurrentHedgehog^ do |
6581 | 739 |
begin |
740 |
inc(Team^.stats.AIKills); |
|
10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10558
diff
changeset
|
741 |
FreeAndNilTexture(Team^.AIKillsTex); |
10124
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
10116
diff
changeset
|
742 |
Team^.AIKillsTex := RenderStringTex(ansistring(inttostr(Team^.stats.AIKills)), Team^.Clan^.Color, fnt16); |
6581 | 743 |
end; |
744 |
tempTeam := gear^.Hedgehog^.Team; |
|
745 |
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
|
746 |
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
|
747 |
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
|
748 |
// 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
|
749 |
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
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
//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
|
754 |
end; |
8330 | 755 |
FindPlace(gear, false, 0, LAND_WIDTH, true); |
6581 | 756 |
if gear <> nil then |
757 |
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
|
758 |
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
|
759 |
PlaySound(sndWarp); |
6581 | 760 |
RenderHealth(gear^.Hedgehog^); |
761 |
ScriptCall('onGearResurrect', gear^.uid); |
|
762 |
gear^.State := gstWait; |
|
8947
e906ebd59612
CheckGearDrowning could delete hedgehogs gear! (CheckGearDrowning -> ResurrectHedgehog -> FindPlace). Fixes bug 620.
unc0rr
parents:
8763
diff
changeset
|
763 |
end; |
6581 | 764 |
RecountTeamHealth(tempTeam); |
765 |
end; |
|
766 |
||
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
|
767 |
function CountNonZeroz(x, y, r, c: LongInt; mask: LongWord): LongInt; |
6581 | 768 |
var i: LongInt; |
769 |
count: LongInt = 0; |
|
770 |
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
|
771 |
if (y and LAND_HEIGHT_MASK) = 0 then |
10272
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
772 |
for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 1) 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
|
773 |
if Land[y, i] and mask <> 0 then |
6581 | 774 |
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
|
775 |
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
|
776 |
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
|
777 |
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
|
778 |
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
|
779 |
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
|
780 |
end; |
6581 | 781 |
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
|
782 |
CountNonZeroz:= count; |
6581 | 783 |
end; |
784 |
||
10272
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
785 |
function isSteadyPosition(x, y, r, c: LongInt; mask: Longword): boolean; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
786 |
var cnt, i: LongInt; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
787 |
begin |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
788 |
cnt:= 0; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
789 |
isSteadyPosition:= false; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
790 |
|
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
791 |
if ((y and LAND_HEIGHT_MASK) = 0) and (x - r >= 0) and (x + r < LAND_WIDTH) then |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
792 |
begin |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
793 |
for i:= r - c + 2 to r do |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
794 |
begin |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
795 |
if (Land[y, x - i] and mask <> 0) then inc(cnt); |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
796 |
if (Land[y, x + i] and mask <> 0) then inc(cnt); |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
797 |
|
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
798 |
if cnt >= c then |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
799 |
begin |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
800 |
isSteadyPosition:= true; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
801 |
exit |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
802 |
end; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
803 |
end; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
804 |
end; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
805 |
end; |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
806 |
|
6888 | 807 |
|
808 |
function NoGearsToAvoid(mX, mY: LongInt; rX, rY: LongInt): boolean; |
|
809 |
var t: PGear; |
|
810 |
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
|
811 |
NoGearsToAvoid:= false; |
6888 | 812 |
t:= GearsList; |
813 |
rX:= sqr(rX); |
|
814 |
rY:= sqr(rY); |
|
815 |
while t <> nil do |
|
816 |
begin |
|
817 |
if t^.Kind <= gtExplosives then |
|
818 |
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
|
819 |
exit; |
6888 | 820 |
t:= t^.NextGear |
821 |
end; |
|
822 |
NoGearsToAvoid:= true |
|
823 |
end; |
|
824 |
||
6986
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
825 |
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
|
826 |
begin |
409dd3851309
add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents:
6888
diff
changeset
|
827 |
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
|
828 |
end; |
6888 | 829 |
|
6581 | 830 |
procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean); |
831 |
var x: LongInt; |
|
11197
283b6e6cf7ea
Scan from right too. Not sure this is actually helpful, so committing separately.
nemo
parents:
11196
diff
changeset
|
832 |
y, sy, dir: LongInt; |
8007 | 833 |
ar: array[0..1023] of TPoint; |
834 |
ar2: array[0..2047] of TPoint; |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
8007
diff
changeset
|
835 |
temp: TPoint; |
6581 | 836 |
cnt, cnt2: Longword; |
837 |
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
|
838 |
ignoreNearObjects, ignoreOverlap, tryAgain: boolean; |
6581 | 839 |
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
|
840 |
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
|
841 |
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 | 842 |
tryAgain:= true; |
10015 | 843 |
if WorldEdge <> weNone then |
9477 | 844 |
begin |
9809 | 845 |
Left:= max(Left, LongInt(leftX) + Gear^.Radius); |
9477 | 846 |
Right:= min(Right,rightX-Gear^.Radius) |
847 |
end; |
|
6581 | 848 |
while tryAgain do |
849 |
begin |
|
8007 | 850 |
delta:= LAND_WIDTH div 16; |
6581 | 851 |
cnt2:= 0; |
852 |
repeat |
|
11197
283b6e6cf7ea
Scan from right too. Not sure this is actually helpful, so committing separately.
nemo
parents:
11196
diff
changeset
|
853 |
if GetRandom(2) = 0 then dir:= -1 else dir:= 1; |
283b6e6cf7ea
Scan from right too. Not sure this is actually helpful, so committing separately.
nemo
parents:
11196
diff
changeset
|
854 |
x:= max(LAND_WIDTH div 2048, LongInt(GetRandom(Delta))); |
283b6e6cf7ea
Scan from right too. Not sure this is actually helpful, so committing separately.
nemo
parents:
11196
diff
changeset
|
855 |
if dir = 1 then x:= Left + x else x:= Right - x; |
6581 | 856 |
repeat |
857 |
cnt:= 0; |
|
9809 | 858 |
y:= min(1024, topY) - Gear^.Radius shl 1; |
6581 | 859 |
while y < cWaterLine do |
860 |
begin |
|
861 |
repeat |
|
862 |
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
|
863 |
until (y >= cWaterLine) or |
10015 | 864 |
((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
|
865 |
(ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask) = 0)); |
6581 | 866 |
|
867 |
sy:= y; |
|
868 |
||
869 |
repeat |
|
870 |
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
|
871 |
until (y >= cWaterLine) or |
10015 | 872 |
((not ignoreOverlap) and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, $FFFF) <> 0)) or |
873 |
(ignoreOverlap and (CountNonZeroz(x, y, Gear^.Radius - 1, 1, lfLandMask) <> 0)); |
|
6581 | 874 |
|
10272
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
875 |
if (y - sy > Gear^.Radius * 2) and (y < cWaterLine) |
6581 | 876 |
and (((Gear^.Kind = gtExplosives) |
10272
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
877 |
and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 60, 60)) |
10274 | 878 |
and (isSteadyPosition(x, y+1, Gear^.Radius - 1, 3, $FFFF) |
879 |
or (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1, $FFFF) > Gear^.Radius) |
|
880 |
)) |
|
10272
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
881 |
or |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
882 |
((Gear^.Kind <> gtExplosives) |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
883 |
and (ignoreNearObjects or NoGearsToAvoid(x, y - Gear^.Radius, 110, 110)) |
31ee88c9b4d0
Allow barrels to spawn in U-shaped pits in stable position
unc0rr
parents:
10245
diff
changeset
|
884 |
)) then |
6888 | 885 |
begin |
6581 | 886 |
ar[cnt].X:= x; |
887 |
if withFall then |
|
888 |
ar[cnt].Y:= sy + Gear^.Radius |
|
889 |
else |
|
890 |
ar[cnt].Y:= y - Gear^.Radius; |
|
891 |
inc(cnt) |
|
892 |
end; |
|
893 |
||
7603
e9c3c67b5dfd
reducing this value is sufficient to ensure crates drop just below top border or a girder
nemo
parents:
7599
diff
changeset
|
894 |
inc(y, 10) |
6581 | 895 |
end; |
896 |
||
897 |
if cnt > 0 then |
|
10015 | 898 |
begin |
899 |
temp := ar[GetRandom(cnt)]; |
|
900 |
with temp do |
|
6581 | 901 |
begin |
902 |
ar2[cnt2].x:= x; |
|
903 |
ar2[cnt2].y:= y; |
|
904 |
inc(cnt2) |
|
11197
283b6e6cf7ea
Scan from right too. Not sure this is actually helpful, so committing separately.
nemo
parents:
11196
diff
changeset
|
905 |
end; |
11196
0f6916065849
This should probably fix feedback that hogs weren't spawning on left side of map.
nemo
parents:
11046
diff
changeset
|
906 |
end; |
11197
283b6e6cf7ea
Scan from right too. Not sure this is actually helpful, so committing separately.
nemo
parents:
11196
diff
changeset
|
907 |
inc(x, Delta*dir) |
283b6e6cf7ea
Scan from right too. Not sure this is actually helpful, so committing separately.
nemo
parents:
11196
diff
changeset
|
908 |
until ((dir = 1) and (x > Right)) or ((dir = -1) and (x < Left)); |
6581 | 909 |
|
910 |
dec(Delta, 60) |
|
911 |
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
|
912 |
// 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
|
913 |
if (cnt2 = 0) and skipProximity and (not ignoreOverlap) then |
6581 | 914 |
tryAgain:= true |
915 |
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
|
916 |
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
|
917 |
ignoreNearObjects:= true; |
6581 | 918 |
end; |
919 |
||
920 |
if cnt2 > 0 then |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
8007
diff
changeset
|
921 |
begin |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
8007
diff
changeset
|
922 |
temp := ar2[GetRandom(cnt2)]; |
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
8007
diff
changeset
|
923 |
with temp do |
6581 | 924 |
begin |
925 |
Gear^.X:= int2hwFloat(x); |
|
926 |
Gear^.Y:= int2hwFloat(y); |
|
927 |
AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')'); |
|
928 |
end |
|
8026
4a4f21070479
merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents:
8007
diff
changeset
|
929 |
end |
11482
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
930 |
else |
6581 | 931 |
begin |
932 |
OutError('Can''t find place for Gear', false); |
|
933 |
if Gear^.Kind = gtHedgehog then |
|
11482
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
934 |
begin |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
935 |
cnt:= 0; |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
936 |
if GameTicks = 0 then |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
937 |
begin |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
938 |
//AddFileLog('Trying to make a hole'); |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
939 |
while (cnt < 1000) do |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
940 |
begin |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
941 |
inc(cnt); |
11756
20e0a72e0e2c
make hog fallback (flower-in-hole) positioning respect limits (e.g. used by gfDivideTeams)
sheepluva
parents:
11556
diff
changeset
|
942 |
x:= left+GetRandom(right-left-2*cHHRadius)+cHHRadius; |
11484 | 943 |
y:= topY+GetRandom(LAND_HEIGHT-topY-64)+48; |
11483
8c95d5a4366c
Tweak the hole carving to become less agressive about spacing if random points keep failing.
nemo
parents:
11482
diff
changeset
|
944 |
if NoGearsToAvoid(x, y, 100 div max(1,cnt div 100), 100 div max(1,cnt div 100)) then |
11482
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
945 |
begin |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
946 |
Gear^.State:= Gear^.State or gsttmpFlag; |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
947 |
Gear^.X:= int2hwFloat(x); |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
948 |
Gear^.Y:= int2hwFloat(y); |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
949 |
AddFileLog('Picked a spot for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')'); |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
950 |
cnt:= 2000 |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
951 |
end |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
952 |
end; |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
953 |
end; |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
954 |
if cnt < 2000 then |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
955 |
begin |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
956 |
Gear^.Hedgehog^.Effects[heResurrectable] := 0; |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
957 |
DeleteGear(Gear); |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
958 |
Gear:= nil |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
959 |
end |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
960 |
end |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
961 |
else |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
962 |
begin |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
963 |
DeleteGear(Gear); |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
964 |
Gear:= nil |
e425a6eb9da3
Force locations for hogs if even TryHard fails on initial spawn.
nemo
parents:
11477
diff
changeset
|
965 |
end |
6581 | 966 |
end |
967 |
end; |
|
968 |
||
969 |
function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
|
970 |
var t: PGear; |
|
971 |
begin |
|
972 |
t:= GearsList; |
|
973 |
rX:= sqr(rX); |
|
974 |
rY:= sqr(rY); |
|
975 |
||
976 |
while t <> nil do |
|
977 |
begin |
|
978 |
if (t <> Gear) and (t^.Kind = Kind) then |
|
979 |
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
|
980 |
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
|
981 |
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
|
982 |
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
|
983 |
end; |
6581 | 984 |
t:= t^.NextGear |
985 |
end; |
|
986 |
||
987 |
CheckGearNear:= nil |
|
988 |
end; |
|
989 |
||
7592 | 990 |
procedure CheckCollision(Gear: PGear); inline; |
991 |
begin |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
992 |
if (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0) |
7592 | 993 |
or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then |
994 |
Gear^.State := Gear^.State or gstCollision |
|
995 |
else |
|
996 |
Gear^.State := Gear^.State and (not gstCollision) |
|
997 |
end; |
|
998 |
||
999 |
procedure CheckCollisionWithLand(Gear: PGear); inline; |
|
1000 |
begin |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
1001 |
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
|
1002 |
or (TestCollisionY(Gear, hwSign(Gear^.dY)) <> 0) then |
7592 | 1003 |
Gear^.State := Gear^.State or gstCollision |
8330 | 1004 |
else |
7592 | 1005 |
Gear^.State := Gear^.State and (not gstCollision) |
1006 |
end; |
|
1007 |
||
7719
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1008 |
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
|
1009 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
1010 |
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
|
1011 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1012 |
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
|
1013 |
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
|
1014 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1015 |
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
|
1016 |
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
|
1017 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1018 |
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
|
1019 |
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
|
1020 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1021 |
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
|
1022 |
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
|
1023 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1024 |
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
|
1025 |
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
|
1026 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1027 |
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
|
1028 |
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
|
1029 |
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
|
1030 |
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
|
1031 |
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
|
1032 |
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
|
1033 |
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
|
1034 |
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
|
1035 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1036 |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
1037 |
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
|
1038 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1039 |
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
|
1040 |
MakeHedgehogsStep:= true |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1041 |
end else |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1042 |
MakeHedgehogsStep:= false; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1043 |
|
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1044 |
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
|
1045 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1046 |
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
|
1047 |
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
|
1048 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1049 |
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
|
1050 |
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
|
1051 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1052 |
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
|
1053 |
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
|
1054 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1055 |
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
|
1056 |
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
|
1057 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1058 |
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
|
1059 |
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
|
1060 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1061 |
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
|
1062 |
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
|
1063 |
begin |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1064 |
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
|
1065 |
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
|
1066 |
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
|
1067 |
exit |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1068 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1069 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1070 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1071 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1072 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1073 |
end |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1074 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1075 |
end; |
eeae1cb6b6bf
Move hedgehog's step routine into separate function, use it in both hedgehog and ai code
unc0rr
parents:
7627
diff
changeset
|
1076 |
|
9285 | 1077 |
|
1078 |
procedure ShotgunShot(Gear: PGear); |
|
1079 |
var t: PGear; |
|
1080 |
dmg, r, dist: LongInt; |
|
1081 |
dx, dy: hwFloat; |
|
1082 |
begin |
|
1083 |
Gear^.Radius:= cShotgunRadius; |
|
1084 |
t:= GearsList; |
|
1085 |
while t <> nil do |
|
1086 |
begin |
|
1087 |
case t^.Kind of |
|
1088 |
gtHedgehog, |
|
1089 |
gtMine, |
|
1090 |
gtSMine, |
|
1091 |
gtKnife, |
|
1092 |
gtCase, |
|
1093 |
gtTarget, |
|
1094 |
gtExplosives: begin//, |
|
1095 |
// gtStructure: begin |
|
1096 |
//addFileLog('ShotgunShot radius: ' + inttostr(Gear^.Radius) + ', t^.Radius = ' + inttostr(t^.Radius) + ', distance = ' + inttostr(dist) + ', dmg = ' + inttostr(dmg)); |
|
1097 |
dmg:= 0; |
|
1098 |
r:= Gear^.Radius + t^.Radius; |
|
1099 |
dx:= Gear^.X-t^.X; |
|
1100 |
dx.isNegative:= false; |
|
1101 |
dy:= Gear^.Y-t^.Y; |
|
1102 |
dy.isNegative:= false; |
|
1103 |
if r-hwRound(dx+dy) > 0 then |
|
1104 |
begin |
|
1105 |
dist:= hwRound(Distance(dx, dy)); |
|
11477 | 1106 |
dmg:= ModifyDamage(min(r - dist, Gear^.Boom), t); |
9285 | 1107 |
end; |
1108 |
if dmg > 0 then |
|
1109 |
begin |
|
10558 | 1110 |
if (t^.Kind <> gtHedgehog) or (t^.Hedgehog^.Effects[heInvulnerable] = 0) then |
9285 | 1111 |
ApplyDamage(t, Gear^.Hedgehog, dmg, dsBullet) |
1112 |
else |
|
1113 |
Gear^.State:= Gear^.State or gstWinner; |
|
1114 |
||
1115 |
DeleteCI(t); |
|
1116 |
t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX); |
|
1117 |
t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; |
|
1118 |
t^.State:= t^.State or gstMoving; |
|
1119 |
if t^.Kind = gtKnife then t^.State:= t^.State and (not gstCollision); |
|
1120 |
t^.Active:= true; |
|
1121 |
FollowGear:= t |
|
1122 |
end |
|
1123 |
end; |
|
1124 |
gtGrave: begin |
|
1125 |
dmg:= 0; |
|
1126 |
r:= Gear^.Radius + t^.Radius; |
|
1127 |
dx:= Gear^.X-t^.X; |
|
1128 |
dx.isNegative:= false; |
|
1129 |
dy:= Gear^.Y-t^.Y; |
|
1130 |
dy.isNegative:= false; |
|
1131 |
if r-hwRound(dx+dy) > 0 then |
|
1132 |
begin |
|
1133 |
dist:= hwRound(Distance(dx, dy)); |
|
11477 | 1134 |
dmg:= ModifyDamage(min(r - dist, Gear^.Boom), t); |
9285 | 1135 |
end; |
1136 |
if dmg > 0 then |
|
1137 |
begin |
|
1138 |
t^.dY:= - _0_1; |
|
1139 |
t^.Active:= true |
|
1140 |
end |
|
1141 |
end; |
|
1142 |
end; |
|
1143 |
t:= t^.NextGear |
|
1144 |
end; |
|
1145 |
if (GameFlags and gfSolidLand) = 0 then |
|
1146 |
DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) |
|
1147 |
end; |
|
1148 |
||
1149 |
procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); |
|
1150 |
var t: PGearArray; |
|
1151 |
Gear: PGear; |
|
1152 |
i, j, tmpDmg: LongInt; |
|
1153 |
VGear: PVisualGear; |
|
1154 |
begin |
|
1155 |
t:= CheckGearsCollision(Ammo); |
|
1156 |
// Just to avoid hogs on rope dodging fire. |
|
1157 |
if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy)) |
|
1158 |
and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.CollisionIndex = -1) |
|
1159 |
and (sqr(hwRound(Ammo^.X) - hwRound(CurrentHedgehog^.Gear^.X)) + sqr(hwRound(Ammo^.Y) - hwRound(CurrentHedgehog^.Gear^.Y)) <= sqr(cHHRadius + Ammo^.Radius)) then |
|
1160 |
begin |
|
1161 |
t^.ar[t^.Count]:= CurrentHedgehog^.Gear; |
|
1162 |
inc(t^.Count) |
|
1163 |
end; |
|
1164 |
||
1165 |
i:= t^.Count; |
|
1166 |
||
1167 |
if (Ammo^.Kind = gtFlame) and (i > 0) then |
|
1168 |
Ammo^.Health:= 0; |
|
1169 |
while i > 0 do |
|
1170 |
begin |
|
1171 |
dec(i); |
|
1172 |
Gear:= t^.ar[i]; |
|
11556 | 1173 |
if (Ammo^.Data <> nil) and (Ammo^.Kind in [gtDEagleShot, gtSniperRifleShot]) and (PGear(Ammo^.Data) = Gear) then |
11555
881231c1ba46
disallow bullets to hit the hedgehog that fired them (unless bounced/wrapped/portal'd)
sheepluva
parents:
11484
diff
changeset
|
1174 |
continue; |
10015 | 1175 |
if ((Ammo^.Kind = gtFlame) or (Ammo^.Kind = gtBlowTorch)) and |
9285 | 1176 |
(Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heFrozen] > 255) then |
1177 |
Gear^.Hedgehog^.Effects[heFrozen]:= max(255,Gear^.Hedgehog^.Effects[heFrozen]-10000); |
|
1178 |
tmpDmg:= ModifyDamage(Damage, Gear); |
|
1179 |
if (Gear^.State and gstNoDamage) = 0 then |
|
1180 |
begin |
|
1181 |
||
10015 | 1182 |
if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then |
9285 | 1183 |
begin |
1184 |
VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit); |
|
1185 |
if VGear <> nil then |
|
1186 |
VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY); |
|
1187 |
end; |
|
1188 |
||
1189 |
if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then |
|
1190 |
Gear^.FlightTime:= 1; |
|
1191 |
||
1192 |
||
1193 |
case Gear^.Kind of |
|
1194 |
gtHedgehog, |
|
1195 |
gtMine, |
|
1196 |
gtSMine, |
|
1197 |
gtKnife, |
|
1198 |
gtTarget, |
|
1199 |
gtCase, |
|
1200 |
gtExplosives: //, |
|
1201 |
//gtStructure: |
|
1202 |
begin |
|
1203 |
if (Ammo^.Kind = gtDrill) then |
|
1204 |
begin |
|
1205 |
Ammo^.Timer:= 0; |
|
1206 |
exit; |
|
1207 |
end; |
|
10011
ead5e4b21671
Add check for gear kind of hedgehog on invulnerability effect. This probably fixes bug #766, is similar to change in previous r2a1483d91977 and was introduced by r7d925e82e572
nemo
parents:
10010
diff
changeset
|
1208 |
if (Gear^.Kind <> gtHedgehog) or (Gear^.Hedgehog^.Effects[heInvulnerable] = 0) then |
9285 | 1209 |
begin |
1210 |
if (Ammo^.Kind = gtKnife) and (tmpDmg > 0) then |
|
1211 |
for j:= 1 to max(1,min(3,tmpDmg div 5)) do |
|
1212 |
begin |
|
1213 |
VGear:= AddVisualGear(hwRound(Ammo^.X-((Ammo^.X-Gear^.X)/_2)), hwRound(Ammo^.Y-((Ammo^.Y-Gear^.Y)/_2)), vgtStraightShot); |
|
1214 |
if VGear <> nil then |
|
1215 |
with VGear^ do |
|
1216 |
begin |
|
1217 |
Tint:= $FFCC00FF; |
|
1218 |
Angle:= random(360); |
|
1219 |
dx:= 0.0005 * (random(100)); |
|
1220 |
dy:= 0.0005 * (random(100)); |
|
1221 |
if random(2) = 0 then |
|
1222 |
dx := -dx; |
|
1223 |
if random(2) = 0 then |
|
1224 |
dy := -dy; |
|
1225 |
FrameTicks:= 600+random(200); |
|
1226 |
State:= ord(sprStar) |
|
1227 |
end |
|
1228 |
end; |
|
1229 |
ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove) |
|
1230 |
end |
|
1231 |
else |
|
1232 |
Gear^.State:= Gear^.State or gstWinner; |
|
10015 | 1233 |
if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then |
9285 | 1234 |
begin |
1235 |
if (Ammo^.Hedgehog^.Gear <> nil) then |
|
1236 |
Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable); |
|
1237 |
ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch |
|
1238 |
end; |
|
1239 |
||
1240 |
if (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.King or (Gear^.Hedgehog^.Effects[heFrozen] > 0)) then |
|
1241 |
begin |
|
1242 |
Gear^.dX:= Ammo^.dX * Power * _0_005; |
|
1243 |
Gear^.dY:= Ammo^.dY * Power * _0_005 |
|
1244 |
end |
|
1245 |
else if ((Ammo^.Kind <> gtFlame) or (Gear^.Kind = gtHedgehog)) and (Power <> 0) then |
|
1246 |
begin |
|
1247 |
Gear^.dX:= Ammo^.dX * Power * _0_01; |
|
1248 |
Gear^.dY:= Ammo^.dY * Power * _0_01 |
|
1249 |
end; |
|
1250 |
||
1251 |
if (not isZero(Gear^.dX)) or (not isZero(Gear^.dY)) then |
|
1252 |
begin |
|
1253 |
Gear^.Active:= true; |
|
1254 |
DeleteCI(Gear); |
|
1255 |
Gear^.State:= Gear^.State or gstMoving; |
|
1256 |
if Gear^.Kind = gtKnife then Gear^.State:= Gear^.State and (not gstCollision); |
|
1257 |
// 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
|
1258 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then |
9285 | 1259 |
begin |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9685
diff
changeset
|
1260 |
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
|
1261 |
(TestCollisionYwithGear(Gear, -1) = 0) then |
9285 | 1262 |
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
|
1263 |
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
|
1264 |
(TestCollisionYwithGear(Gear, -1) = 0) then |
9285 | 1265 |
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
|
1266 |
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
|
1267 |
(TestCollisionYwithGear(Gear, -1) = 0) then |
9285 | 1268 |
Gear^.Y:= Gear^.Y - _1; |
1269 |
end |
|
1270 |
end; |
|
1271 |
||
1272 |
||
1273 |
if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then |
|
1274 |
FollowGear:= Gear |
|
1275 |
end; |
|
1276 |
end |
|
1277 |
end; |
|
1278 |
end; |
|
1279 |
if i <> 0 then |
|
1280 |
SetAllToActive |
|
1281 |
end; |
|
1282 |
||
1283 |
||
1284 |
function CountGears(Kind: TGearType): Longword; |
|
1285 |
var t: PGear; |
|
1286 |
count: Longword = 0; |
|
1287 |
begin |
|
1288 |
||
1289 |
t:= GearsList; |
|
1290 |
while t <> nil do |
|
1291 |
begin |
|
1292 |
if t^.Kind = Kind then |
|
1293 |
inc(count); |
|
1294 |
t:= t^.NextGear |
|
1295 |
end; |
|
1296 |
CountGears:= count; |
|
1297 |
end; |
|
1298 |
||
1299 |
procedure SetAllToActive; |
|
1300 |
var t: PGear; |
|
1301 |
begin |
|
1302 |
AllInactive:= false; |
|
1303 |
t:= GearsList; |
|
1304 |
while t <> nil do |
|
1305 |
begin |
|
1306 |
t^.Active:= true; |
|
1307 |
t:= t^.NextGear |
|
1308 |
end |
|
1309 |
end; |
|
1310 |
||
1311 |
procedure SetAllHHToActive; inline; |
|
1312 |
begin |
|
1313 |
SetAllHHToActive(true) |
|
1314 |
end; |
|
1315 |
||
1316 |
||
1317 |
procedure SetAllHHToActive(Ice: boolean); |
|
1318 |
var t: PGear; |
|
1319 |
begin |
|
1320 |
AllInactive:= false; |
|
1321 |
t:= GearsList; |
|
1322 |
while t <> nil do |
|
1323 |
begin |
|
1324 |
if (t^.Kind = gtHedgehog) or (t^.Kind = gtExplosives) then |
|
1325 |
begin |
|
1326 |
if (t^.Kind = gtHedgehog) and Ice then CheckIce(t); |
|
1327 |
t^.Active:= true |
|
1328 |
end; |
|
1329 |
t:= t^.NextGear |
|
1330 |
end |
|
1331 |
end; |
|
1332 |
||
1333 |
||
1334 |
var GearsNearArray : TPGearArray; |
|
1335 |
function GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): PGearArrayS; |
|
1336 |
var |
|
1337 |
t: PGear; |
|
1338 |
s: Longword; |
|
1339 |
begin |
|
1340 |
r:= r*r; |
|
1341 |
s:= 0; |
|
1342 |
SetLength(GearsNearArray, s); |
|
1343 |
t := GearsList; |
|
10015 | 1344 |
while t <> nil do |
9285 | 1345 |
begin |
10015 | 1346 |
if (t^.Kind = Kind) |
9285 | 1347 |
and ((X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) < int2hwFloat(r)) then |
1348 |
begin |
|
1349 |
inc(s); |
|
1350 |
SetLength(GearsNearArray, s); |
|
1351 |
GearsNearArray[s - 1] := t; |
|
1352 |
end; |
|
1353 |
t := t^.NextGear; |
|
1354 |
end; |
|
1355 |
||
1356 |
GearsNear.size:= s; |
|
1357 |
GearsNear.ar:= @GearsNearArray |
|
1358 |
end; |
|
1359 |
||
1360 |
||
1361 |
procedure SpawnBoxOfSmth; |
|
1362 |
var t, aTot, uTot, a, h: LongInt; |
|
1363 |
i: TAmmoType; |
|
1364 |
begin |
|
1365 |
if (PlacingHogs) or |
|
1366 |
(cCaseFactor = 0) |
|
1367 |
or (CountGears(gtCase) >= 5) |
|
1368 |
or (GetRandom(cCaseFactor) <> 0) then |
|
1369 |
exit; |
|
1370 |
||
1371 |
FollowGear:= nil; |
|
1372 |
aTot:= 0; |
|
1373 |
uTot:= 0; |
|
1374 |
for i:= Low(TAmmoType) to High(TAmmoType) do |
|
1375 |
if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then |
|
1376 |
inc(aTot, Ammoz[i].Probability) |
|
1377 |
else |
|
1378 |
inc(uTot, Ammoz[i].Probability); |
|
1379 |
||
1380 |
t:=0; |
|
1381 |
a:=aTot; |
|
1382 |
h:= 1; |
|
1383 |
||
1384 |
if (aTot+uTot) <> 0 then |
|
1385 |
if ((GameFlags and gfInvulnerable) = 0) then |
|
1386 |
begin |
|
1387 |
h:= cHealthCaseProb * 100; |
|
1388 |
t:= GetRandom(10000); |
|
1389 |
a:= (10000-h)*aTot div (aTot+uTot) |
|
1390 |
end |
|
1391 |
else |
|
1392 |
begin |
|
1393 |
t:= GetRandom(aTot+uTot); |
|
1394 |
h:= 0 |
|
1395 |
end; |
|
1396 |
||
1397 |
||
1398 |
if t<h then |
|
1399 |
begin |
|
1400 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
|
1401 |
FollowGear^.Health:= cHealthCaseAmount; |
|
1402 |
FollowGear^.Pos:= posCaseHealth; |
|
10506 | 1403 |
// health crate is smaller than the other crates |
1404 |
FollowGear^.Radius := cCaseHealthRadius; |
|
9285 | 1405 |
AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo); |
1406 |
end |
|
1407 |
else if (t<a+h) then |
|
1408 |
begin |
|
1409 |
t:= aTot; |
|
1410 |
if (t > 0) then |
|
1411 |
begin |
|
1412 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
|
1413 |
t:= GetRandom(t); |
|
1414 |
i:= Low(TAmmoType); |
|
1415 |
FollowGear^.Pos:= posCaseAmmo; |
|
1416 |
FollowGear^.AmmoType:= i; |
|
1417 |
AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo); |
|
1418 |
end |
|
1419 |
end |
|
1420 |
else |
|
1421 |
begin |
|
1422 |
t:= uTot; |
|
1423 |
if (t > 0) then |
|
1424 |
begin |
|
1425 |
FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); |
|
1426 |
t:= GetRandom(t); |
|
1427 |
i:= Low(TAmmoType); |
|
1428 |
FollowGear^.Pos:= posCaseUtility; |
|
1429 |
FollowGear^.AmmoType:= i; |
|
1430 |
AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo); |
|
1431 |
end |
|
1432 |
end; |
|
1433 |
||
1434 |
// handles case of no ammo or utility crates - considered also placing booleans in uAmmos and altering probabilities |
|
1435 |
if (FollowGear <> nil) then |
|
1436 |
begin |
|
1437 |
FindPlace(FollowGear, true, 0, LAND_WIDTH); |
|
1438 |
||
1439 |
if (FollowGear <> nil) then |
|
1440 |
AddVoice(sndReinforce, CurrentTeam^.voicepack) |
|
1441 |
end |
|
1442 |
end; |
|
1443 |
||
1444 |
||
1445 |
function GetAmmo(Hedgehog: PHedgehog): TAmmoType; |
|
1446 |
var t, aTot: LongInt; |
|
1447 |
i: TAmmoType; |
|
1448 |
begin |
|
1449 |
Hedgehog:= Hedgehog; // avoid hint |
|
1450 |
||
1451 |
aTot:= 0; |
|
1452 |
for i:= Low(TAmmoType) to High(TAmmoType) do |
|
1453 |
if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then |
|
1454 |
inc(aTot, Ammoz[i].Probability); |
|
1455 |
||
1456 |
t:= aTot; |
|
1457 |
i:= Low(TAmmoType); |
|
1458 |
if (t > 0) then |
|
1459 |
begin |
|
1460 |
t:= GetRandom(t); |
|
1461 |
while t >= 0 do |
|
1462 |
begin |
|
1463 |
inc(i); |
|
1464 |
if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then |
|
1465 |
dec(t, Ammoz[i].Probability) |
|
1466 |
end |
|
1467 |
end; |
|
1468 |
GetAmmo:= i |
|
1469 |
end; |
|
1470 |
||
1471 |
function GetUtility(Hedgehog: PHedgehog): TAmmoType; |
|
1472 |
var t, uTot: LongInt; |
|
1473 |
i: TAmmoType; |
|
1474 |
begin |
|
1475 |
||
1476 |
uTot:= 0; |
|
1477 |
for i:= Low(TAmmoType) to High(TAmmoType) do |
|
1478 |
if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) |
|
1479 |
and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then |
|
1480 |
inc(uTot, Ammoz[i].Probability); |
|
1481 |
||
1482 |
t:= uTot; |
|
1483 |
i:= Low(TAmmoType); |
|
1484 |
if (t > 0) then |
|
1485 |
begin |
|
1486 |
t:= GetRandom(t); |
|
1487 |
while t >= 0 do |
|
1488 |
begin |
|
1489 |
inc(i); |
|
1490 |
if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1) |
|
1491 |
or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then |
|
1492 |
dec(t, Ammoz[i].Probability) |
|
1493 |
end |
|
1494 |
end; |
|
1495 |
GetUtility:= i |
|
1496 |
end; |
|
1497 |
||
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1498 |
(* |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1499 |
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
|
1500 |
* Normal - infinite world, do nothing |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1501 |
* 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
|
1502 |
* 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
|
1503 |
* 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
|
1504 |
|
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1505 |
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
|
1506 |
*) |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1507 |
function WorldWrap(var Gear: PGear): boolean; |
10354 | 1508 |
//var tdx: hwFloat; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1509 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1510 |
WorldWrap:= false; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1511 |
if WorldEdge = weNone then exit(false); |
10160 | 1512 |
if (hwRound(Gear^.X) < LongInt(leftX)) or |
1513 |
(hwRound(Gear^.X) > LongInt(rightX)) then |
|
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1514 |
begin |
11555
881231c1ba46
disallow bullets to hit the hedgehog that fired them (unless bounced/wrapped/portal'd)
sheepluva
parents:
11484
diff
changeset
|
1515 |
// bullets can now hurt the hog that fired them |
11556 | 1516 |
if (WorldEdge <> weSea) and (Gear^.Kind in [gtDEagleShot, gtSniperRifleShot]) then |
11555
881231c1ba46
disallow bullets to hit the hedgehog that fired them (unless bounced/wrapped/portal'd)
sheepluva
parents:
11484
diff
changeset
|
1517 |
Gear^.Data:= nil; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1518 |
if WorldEdge = weWrap then |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1519 |
begin |
10160 | 1520 |
if (hwRound(Gear^.X) < LongInt(leftX)) then |
1521 |
Gear^.X:= Gear^.X + int2hwfloat(rightX - leftX) |
|
1522 |
else Gear^.X:= Gear^.X - int2hwfloat(rightX - leftX); |
|
9557 | 1523 |
LeftImpactTimer:= 150; |
1524 |
RightImpactTimer:= 150 |
|
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1525 |
end |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1526 |
else if WorldEdge = weBounce then |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1527 |
begin |
9809 | 1528 |
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
|
1529 |
begin |
9557 | 1530 |
LeftImpactTimer:= 333; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1531 |
Gear^.dX.isNegative:= false; |
9809 | 1532 |
Gear^.X:= int2hwfloat(LongInt(leftX) + Gear^.Radius) |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1533 |
end |
10015 | 1534 |
else |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1535 |
begin |
9557 | 1536 |
RightImpactTimer:= 333; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1537 |
Gear^.dX.isNegative:= true; |
9485
3dee8a3b0406
add shotgun wrap, revert 100px offset. Problematic w/ things that rely on Land.
nemo
parents:
9479
diff
changeset
|
1538 |
Gear^.X:= int2hwfloat(rightX-Gear^.Radius) |
9557 | 1539 |
end; |
9561 | 1540 |
if (Gear^.Radius > 2) and (Gear^.dX.QWordValue > _0_001.QWordValue) then |
10508 | 1541 |
AddBounceEffectForGear(Gear); |
10354 | 1542 |
end{ |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1543 |
else if WorldEdge = weSea then |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1544 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1545 |
if (hwRound(Gear^.Y) > cWaterLine) and (Gear^.State and gstSubmersible <> 0) then |
9521
8054d9d775fd
merge with latest defaul, fixing compiling with fpc, parsing and rendering with pas2c, some minor problems with compiling with clang
koda
diff
changeset
|
1546 |
Gear^.State:= Gear^.State and (not gstSubmersible) |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1547 |
else |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1548 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1549 |
Gear^.State:= Gear^.State or gstSubmersible; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1550 |
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
|
1551 |
Gear^.Y:= int2hwFloat(cWaterLine+cVisibleWater+Gear^.Radius*2); |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1552 |
tdx:= Gear^.dX; |
9522 | 1553 |
Gear^.dX:= -Gear^.dY; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1554 |
Gear^.dY:= tdx; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1555 |
Gear^.dY.isNegative:= true |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1556 |
end |
10354 | 1557 |
end}; |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1558 |
(* |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1559 |
* 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
|
1560 |
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
|
1561 |
|
10015 | 1562 |
else |
9473
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1563 |
begin |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1564 |
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
|
1565 |
Gear^.Y:= -_2048-_256-_256; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1566 |
tdx:= Gear^.dX; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1567 |
Gear^.dX:= Gear^.dY; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1568 |
Gear^.dY:= tdx; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1569 |
Gear^.dY.isNegative:= false |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1570 |
end |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1571 |
*) |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1572 |
WorldWrap:= true |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1573 |
end; |
a51a69094c24
partial implementation of non-infinite world (edge wrap/warp/bounce)
nemo
parents:
9285
diff
changeset
|
1574 |
end; |
9285 | 1575 |
|
10508 | 1576 |
procedure AddBounceEffectForGear(Gear: PGear); |
1577 |
var boing: PVisualGear; |
|
1578 |
begin |
|
1579 |
boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1); |
|
1580 |
if boing <> nil then |
|
1581 |
with boing^ do |
|
1582 |
begin |
|
1583 |
Angle:= random(360); |
|
1584 |
dx:= 0; |
|
1585 |
dy:= 0; |
|
1586 |
FrameTicks:= 200; |
|
1587 |
Scale:= hwFloat2Float(Gear^.Density * hwAbs(Gear^.dY) + hwAbs(Gear^.dX)) / 1.5; |
|
1588 |
State:= ord(sprBoing) |
|
1589 |
end; |
|
1590 |
PlaySound(sndMelonImpact, true) |
|
1591 |
end; |
|
1592 |
||
6581 | 1593 |
end. |