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