author | Wuzzy <Wuzzy2@mail.ru> |
Wed, 14 Feb 2018 22:27:18 +0100 | |
changeset 12998 | 22e032ab1cb7 |
parent 12821 | f3e07e53460d |
child 13069 | ba7ac61c7668 |
permissions | -rw-r--r-- |
7660 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
7660 | 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:
10017
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
7660 | 17 |
*) |
18 |
||
19 |
{$INCLUDE "options.inc"} |
|
20 |
unit uGearsHandlersRope; |
|
21 |
interface |
|
22 |
||
23 |
uses uTypes; |
|
24 |
||
25 |
procedure doStepRope(Gear: PGear); |
|
26 |
||
27 |
implementation |
|
28 |
uses uConsts, uFloat, uCollisions, uVariables, uGearsList, uSound, uGearsUtils, |
|
29 |
uAmmos, uDebug, uUtils, uGearsHedgehog, uGearsRender; |
|
30 |
||
10684 | 31 |
const |
10722 | 32 |
IsNilHHFatal = false; |
10684 | 33 |
|
7660 | 34 |
procedure doStepRopeAfterAttack(Gear: PGear); |
10017 | 35 |
var |
7660 | 36 |
HHGear: PGear; |
9526 | 37 |
tX: hwFloat; |
7660 | 38 |
begin |
39 |
HHGear := Gear^.Hedgehog^.Gear; |
|
10681 | 40 |
if HHGear = nil then |
41 |
begin |
|
10684 | 42 |
OutError('ERROR: doStepRopeAfterAttack called while HHGear = nil', IsNilHHFatal); |
10681 | 43 |
DeleteGear(Gear); |
44 |
exit() |
|
11258 | 45 |
end |
11266
31e0e38e703c
Make camera refocus less aggressive. Only if there's a camera target already.
nemo
parents:
11258
diff
changeset
|
46 |
else if not CurrentTeam^.ExtDriven and (FollowGear <> nil) then FollowGear := HHGear; |
10681 | 47 |
|
9526 | 48 |
tX:= HHGear^.X; |
10017 | 49 |
if WorldWrap(HHGear) and (WorldEdge = weWrap) and |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
50 |
((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0)) then |
9526 | 51 |
begin |
52 |
HHGear^.X:= tX; |
|
9809 | 53 |
HHGear^.dX.isNegative:= hwRound(tX) > LongInt(leftX) + HHGear^.Radius * 2 |
9526 | 54 |
end; |
55 |
||
8680 | 56 |
if (HHGear^.Hedgehog^.CurAmmoType = amParachute) and (HHGear^.dY > _0_39) then |
57 |
begin |
|
58 |
DeleteGear(Gear); |
|
59 |
ApplyAmmoChanges(HHGear^.Hedgehog^); |
|
60 |
HHGear^.Message:= HHGear^.Message or gmLJump; |
|
61 |
exit |
|
62 |
end; |
|
63 |
||
7660 | 64 |
if ((HHGear^.State and gstHHDriven) = 0) |
65 |
or (CheckGearDrowning(HHGear)) |
|
66 |
or (TestCollisionYwithGear(HHGear, 1) <> 0) then |
|
67 |
begin |
|
68 |
DeleteGear(Gear); |
|
12821
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
69 |
if (TestCollisionYwithGear(HHGear, 1) <> 0) and (GetAmmoEntry(HHGear^.Hedgehog^, amRope)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then |
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
70 |
HHGear^.Hedgehog^.CurAmmoType:= amRope; |
7660 | 71 |
isCursorVisible := false; |
72 |
ApplyAmmoChanges(HHGear^.Hedgehog^); |
|
73 |
exit |
|
74 |
end; |
|
75 |
||
76 |
HedgehogChAngle(HHGear); |
|
77 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
78 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0 then |
7660 | 79 |
SetLittle(HHGear^.dX); |
80 |
||
81 |
if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then |
|
82 |
HHGear^.dY := _0; |
|
83 |
HHGear^.X := HHGear^.X + HHGear^.dX; |
|
84 |
HHGear^.Y := HHGear^.Y + HHGear^.dY; |
|
85 |
HHGear^.dY := HHGear^.dY + cGravity; |
|
10017 | 86 |
|
7660 | 87 |
if (GameFlags and gfMoreWind) <> 0 then |
88 |
HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; |
|
89 |
||
90 |
if (Gear^.Message and gmAttack) <> 0 then |
|
91 |
begin |
|
92 |
Gear^.X := HHGear^.X; |
|
93 |
Gear^.Y := HHGear^.Y; |
|
94 |
||
95 |
ApplyAngleBounds(Gear^.Hedgehog^, amRope); |
|
96 |
||
97 |
Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX); |
|
98 |
Gear^.dY := -AngleCos(HHGear^.Angle); |
|
99 |
Gear^.Friction := _4_5 * cRopePercent; |
|
100 |
Gear^.Elasticity := _0; |
|
101 |
Gear^.State := Gear^.State and (not gsttmpflag); |
|
102 |
Gear^.doStep := @doStepRope; |
|
103 |
end |
|
104 |
end; |
|
105 |
||
106 |
procedure RopeDeleteMe(Gear, HHGear: PGear); |
|
107 |
begin |
|
108 |
with HHGear^ do |
|
109 |
begin |
|
110 |
Message := Message and (not gmAttack); |
|
111 |
State := (State or gstMoving) and (not gstWinner); |
|
112 |
end; |
|
113 |
DeleteGear(Gear) |
|
114 |
end; |
|
115 |
||
116 |
procedure RopeWaitCollision(Gear, HHGear: PGear); |
|
117 |
begin |
|
118 |
with HHGear^ do |
|
119 |
begin |
|
120 |
Message := Message and (not gmAttack); |
|
121 |
State := State or gstMoving; |
|
122 |
end; |
|
123 |
RopePoints.Count := 0; |
|
124 |
Gear^.Elasticity := _0; |
|
125 |
Gear^.doStep := @doStepRopeAfterAttack |
|
126 |
end; |
|
127 |
||
128 |
procedure doStepRopeWork(Gear: PGear); |
|
10017 | 129 |
var |
7660 | 130 |
HHGear: PGear; |
131 |
len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat; |
|
132 |
lx, ly, cd: LongInt; |
|
133 |
haveCollision, |
|
134 |
haveDivided: boolean; |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
135 |
wrongSide: boolean; |
7660 | 136 |
begin |
10680
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
137 |
HHGear := Gear^.Hedgehog^.Gear; |
10681 | 138 |
if HHGear = nil then |
139 |
begin |
|
10684 | 140 |
OutError('ERROR: doStepRopeWork called while HHGear = nil', IsNilHHFatal); |
10681 | 141 |
DeleteGear(Gear); |
142 |
exit() |
|
11258 | 143 |
end |
11266
31e0e38e703c
Make camera refocus less aggressive. Only if there's a camera target already.
nemo
parents:
11258
diff
changeset
|
144 |
else if not CurrentTeam^.ExtDriven and (FollowGear <> nil) then FollowGear := HHGear; |
7660 | 145 |
|
10680
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
146 |
if ((HHGear^.State and gstHHDriven) = 0) or |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
147 |
(CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
148 |
begin |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
149 |
PlaySound(sndRopeRelease); |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
150 |
RopeDeleteMe(Gear, HHGear); |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
151 |
exit |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
152 |
end; |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
153 |
|
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
154 |
if GameTicks mod 4 <> 0 then exit; |
7660 | 155 |
|
9526 | 156 |
tX:= HHGear^.X; |
10017 | 157 |
if WorldWrap(HHGear) and (WorldEdge = weWrap) and |
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
158 |
((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0)) then |
9526 | 159 |
begin |
160 |
PlaySound(sndRopeRelease); |
|
161 |
RopeDeleteMe(Gear, HHGear); |
|
162 |
HHGear^.X:= tX; |
|
9809 | 163 |
HHGear^.dX.isNegative:= hwRound(tX) > LongInt(leftX) + HHGear^.Radius * 2; |
9526 | 164 |
exit |
165 |
end; |
|
166 |
||
167 |
tX:= HHGear^.X; |
|
7660 | 168 |
HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue shl 2; |
169 |
HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue shl 2; |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
170 |
if (Gear^.Message and gmLeft <> 0) and (TestCollisionXwithGear(HHGear, -1) = 0) then |
7660 | 171 |
HHGear^.dX := HHGear^.dX - _0_0032; |
172 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
173 |
if (Gear^.Message and gmRight <> 0) and (TestCollisionXwithGear(HHGear, 1) = 0) then |
7660 | 174 |
HHGear^.dX := HHGear^.dX + _0_0032; |
175 |
||
176 |
// vector between hedgehog and rope attaching point |
|
177 |
ropeDx := HHGear^.X - Gear^.X; |
|
178 |
ropeDy := HHGear^.Y - Gear^.Y; |
|
179 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
180 |
if TestCollisionYwithXYShift(HHGear, 0, 1, 1) = 0 then |
7660 | 181 |
begin |
182 |
||
183 |
// depending on the rope vector we know which X-side to check for collision |
|
184 |
// in order to find out if the hog can still be moved by gravity |
|
185 |
if ropeDx.isNegative = RopeDy.IsNegative then |
|
186 |
cd:= -1 |
|
187 |
else |
|
188 |
cd:= 1; |
|
189 |
||
190 |
// apply gravity if there is no obstacle |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
191 |
if TestCollisionXwithXYShift(HHGear, _2*cd, 0, cd, true) = 0 then |
7660 | 192 |
HHGear^.dY := HHGear^.dY + cGravity * 16; |
193 |
||
194 |
if (GameFlags and gfMoreWind) <> 0 then |
|
195 |
// apply wind if there's no obstacle |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
196 |
if TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) = 0 then |
7660 | 197 |
HHGear^.dX := HHGear^.dX + cWindSpeed * 16 / HHGear^.Density; |
198 |
end; |
|
199 |
||
200 |
mdX := ropeDx + HHGear^.dX; |
|
201 |
mdY := ropeDy + HHGear^.dY; |
|
202 |
len := _1 / Distance(mdX, mdY); |
|
203 |
// rope vector plus hedgehog direction vector normalized |
|
204 |
mdX := mdX * len; |
|
205 |
mdY := mdY * len; |
|
206 |
||
207 |
// for visual purposes only |
|
208 |
Gear^.dX := mdX; |
|
209 |
Gear^.dY := mdY; |
|
210 |
||
211 |
///// |
|
212 |
tx := HHGear^.X; |
|
213 |
ty := HHGear^.Y; |
|
214 |
||
215 |
if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
216 |
if not ((TestCollisionXwithXYShift(HHGear, _2*hwSign(ropeDx), 0, hwSign(ropeDx), true) <> 0) |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
217 |
or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*hwSign(ropeDy), hwSign(ropeDy)) <> 0))) then |
7660 | 218 |
Gear^.Elasticity := Gear^.Elasticity + _1_2; |
219 |
||
220 |
if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
221 |
if not ((TestCollisionXwithXYShift(HHGear, -_2*hwSign(ropeDx), 0, -hwSign(ropeDx), true) <> 0) |
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
222 |
or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*-hwSign(ropeDy), -hwSign(ropeDy)) <> 0))) then |
7660 | 223 |
Gear^.Elasticity := Gear^.Elasticity - _1_2; |
224 |
||
225 |
HHGear^.X := Gear^.X + mdX * Gear^.Elasticity; |
|
226 |
HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity; |
|
227 |
||
228 |
HHGear^.dX := HHGear^.X - tx; |
|
229 |
HHGear^.dY := HHGear^.Y - ty; |
|
230 |
//// |
|
231 |
||
232 |
||
233 |
haveDivided := false; |
|
234 |
// check whether rope needs dividing |
|
235 |
||
236 |
len := Gear^.Elasticity - _5; |
|
237 |
nx := Gear^.X + mdX * len; |
|
238 |
ny := Gear^.Y + mdY * len; |
|
239 |
tx := mdX * _1_2; // should be the same as increase step |
|
240 |
ty := mdY * _1_2; |
|
241 |
||
242 |
while len > _3 do |
|
243 |
begin |
|
244 |
lx := hwRound(nx); |
|
245 |
ly := hwRound(ny); |
|
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:
8744
diff
changeset
|
246 |
if ((ly and LAND_HEIGHT_MASK) = 0) and ((lx and LAND_WIDTH_MASK) = 0) and (Land[ly, lx] > lfAllObjMask) then |
7660 | 247 |
begin |
8397
5b273af3ac95
Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents:
7674
diff
changeset
|
248 |
tx := _1 / Distance(ropeDx, ropeDy); |
7660 | 249 |
// old rope pos |
8397
5b273af3ac95
Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents:
7674
diff
changeset
|
250 |
nx := ropeDx * tx; |
5b273af3ac95
Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents:
7674
diff
changeset
|
251 |
ny := ropeDy * tx; |
7660 | 252 |
|
253 |
with RopePoints.ar[RopePoints.Count] do |
|
254 |
begin |
|
255 |
X := Gear^.X; |
|
256 |
Y := Gear^.Y; |
|
257 |
if RopePoints.Count = 0 then |
|
258 |
RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX); |
|
259 |
b := (nx * HHGear^.dY) > (ny * HHGear^.dX); |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
260 |
sx:= Gear^.dX.isNegative; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
261 |
sy:= Gear^.dY.isNegative; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
262 |
sb:= Gear^.dX.QWordValue < Gear^.dY.QWordValue; |
7660 | 263 |
dLen := len |
264 |
end; |
|
8397
5b273af3ac95
Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents:
7674
diff
changeset
|
265 |
|
7660 | 266 |
with RopePoints.rounded[RopePoints.Count] do |
267 |
begin |
|
268 |
X := hwRound(Gear^.X); |
|
269 |
Y := hwRound(Gear^.Y); |
|
270 |
end; |
|
271 |
||
272 |
Gear^.X := Gear^.X + nx * len; |
|
273 |
Gear^.Y := Gear^.Y + ny * len; |
|
274 |
inc(RopePoints.Count); |
|
11532 | 275 |
if checkFails(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true) then exit; |
7660 | 276 |
Gear^.Elasticity := Gear^.Elasticity - len; |
277 |
Gear^.Friction := Gear^.Friction - len; |
|
278 |
haveDivided := true; |
|
279 |
break |
|
280 |
end; |
|
281 |
nx := nx - tx; |
|
282 |
ny := ny - ty; |
|
283 |
||
284 |
// len := len - _1_2 // should be the same as increase step |
|
285 |
len.QWordValue := len.QWordValue - _1_2.QWordValue; |
|
286 |
end; |
|
287 |
||
288 |
if not haveDivided then |
|
289 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
290 |
begin |
|
291 |
tx := RopePoints.ar[Pred(RopePoints.Count)].X; |
|
292 |
ty := RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
293 |
mdX := tx - Gear^.X; |
|
294 |
mdY := ty - Gear^.Y; |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
295 |
ropeDx:= tx - HHGear^.X; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
296 |
ropeDy:= ty - HHGear^.Y; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
297 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor (mdX * ropeDy > ropeDx * mdY) then |
7660 | 298 |
begin |
299 |
dec(RopePoints.Count); |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
300 |
Gear^.X := tx; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
301 |
Gear^.Y := ty; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
302 |
|
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
303 |
// oops, opposite quadrant, don't restore hog position in such case, just remove the point |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
304 |
wrongSide:= (ropeDx.isNegative = RopePoints.ar[RopePoints.Count].sx) |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
305 |
and (ropeDy.isNegative = RopePoints.ar[RopePoints.Count].sy); |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
306 |
|
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
307 |
// previous check could be inaccurate in vertical/horizontal rope positions, |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
308 |
// so perform this check also, even though odds are 1 to 415927 to hit this |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
309 |
if (not wrongSide) |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
310 |
and ((ropeDx.isNegative = RopePoints.ar[RopePoints.Count].sx) |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
311 |
<> (ropeDy.isNegative = RopePoints.ar[RopePoints.Count].sy)) then |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
312 |
if RopePoints.ar[RopePoints.Count].sb then |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
313 |
wrongSide:= ropeDy.isNegative = RopePoints.ar[RopePoints.Count].sy |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
314 |
else |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
315 |
wrongSide:= ropeDx.isNegative = RopePoints.ar[RopePoints.Count].sx; |
7660 | 316 |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
317 |
if wrongSide then |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
318 |
begin |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
319 |
Gear^.Elasticity := Gear^.Elasticity - RopePoints.ar[RopePoints.Count].dLen; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
320 |
Gear^.Friction := Gear^.Friction - RopePoints.ar[RopePoints.Count].dLen; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
321 |
end else |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
322 |
begin |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
323 |
Gear^.Elasticity := Gear^.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
324 |
Gear^.Friction := Gear^.Friction + RopePoints.ar[RopePoints.Count].dLen; |
7660 | 325 |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
326 |
// restore hog position |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
327 |
len := _1 / Distance(mdX, mdY); |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
328 |
mdX := mdX * len; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
329 |
mdY := mdY * len; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
330 |
|
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
331 |
HHGear^.X := Gear^.X - mdX * Gear^.Elasticity; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
332 |
HHGear^.Y := Gear^.Y - mdY * Gear^.Elasticity; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
333 |
end; |
7660 | 334 |
end |
335 |
end; |
|
336 |
||
337 |
haveCollision := false; |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
338 |
if TestCollisionXwithXYShift(HHGear, _2*hwSign(HHGear^.dX), 0, hwSign(HHGear^.dX), true) <> 0 then |
7660 | 339 |
begin |
340 |
HHGear^.dX := -_0_6 * HHGear^.dX; |
|
341 |
haveCollision := true |
|
342 |
end; |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
343 |
if TestCollisionYwithXYShift(HHGear, 0, 1*hwSign(HHGear^.dY), hwSign(HHGear^.dY)) <> 0 then |
7660 | 344 |
begin |
345 |
HHGear^.dY := -_0_6 * HHGear^.dY; |
|
346 |
haveCollision := true |
|
347 |
end; |
|
348 |
||
349 |
if haveCollision and (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.Message and (gmUp or gmDown) <> 0) then |
|
350 |
begin |
|
351 |
HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _0_8, HHGear^.dX); |
|
352 |
HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _0_8, HHGear^.dY) |
|
353 |
end; |
|
354 |
||
355 |
len := hwSqr(HHGear^.dX) + hwSqr(HHGear^.dY); |
|
356 |
if len > _10 then |
|
357 |
begin |
|
358 |
len := _3_2 / hwSqrt(len); |
|
359 |
HHGear^.dX := HHGear^.dX * len; |
|
360 |
HHGear^.dY := HHGear^.dY * len; |
|
361 |
end; |
|
362 |
||
363 |
haveCollision:= ((hwRound(Gear^.Y) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X) and LAND_WIDTH_MASK) = 0) and ((Land[hwRound(Gear^.Y), hwRound(Gear^.X)]) <> 0); |
|
364 |
||
365 |
if not haveCollision then |
|
366 |
begin |
|
367 |
// backup gear location |
|
368 |
tx:= Gear^.X; |
|
369 |
ty:= Gear^.Y; |
|
370 |
||
371 |
if RopePoints.Count > 0 then |
|
372 |
begin |
|
373 |
// set gear location to the remote end of the rope, the attachment point |
|
374 |
Gear^.X:= RopePoints.ar[0].X; |
|
375 |
Gear^.Y:= RopePoints.ar[0].Y; |
|
376 |
end; |
|
377 |
||
378 |
CheckCollision(Gear); |
|
379 |
// if we haven't found any collision yet then check the other side too |
|
380 |
if (Gear^.State and gstCollision) = 0 then |
|
381 |
begin |
|
382 |
Gear^.dX.isNegative:= not Gear^.dX.isNegative; |
|
383 |
Gear^.dY.isNegative:= not Gear^.dY.isNegative; |
|
384 |
CheckCollision(Gear); |
|
385 |
Gear^.dX.isNegative:= not Gear^.dX.isNegative; |
|
386 |
Gear^.dY.isNegative:= not Gear^.dY.isNegative; |
|
387 |
end; |
|
388 |
||
389 |
haveCollision:= (Gear^.State and gstCollision) <> 0; |
|
390 |
||
391 |
// restore gear location |
|
392 |
Gear^.X:= tx; |
|
393 |
Gear^.Y:= ty; |
|
394 |
end; |
|
395 |
||
396 |
// if the attack key is pressed, lose rope contact as well |
|
397 |
if (Gear^.Message and gmAttack) <> 0 then |
|
398 |
haveCollision:= false; |
|
399 |
||
400 |
HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue shr 2; |
|
401 |
HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue shr 2; |
|
7674
aead327f1e1a
fix for issue 293 : "rope stuck after picking crate"
sheepluva
parents:
7662
diff
changeset
|
402 |
if (not haveCollision) and ((Gear^.State and gsttmpFlag) <> 0) then |
7660 | 403 |
begin |
404 |
begin |
|
405 |
PlaySound(sndRopeRelease); |
|
406 |
if Gear^.Hedgehog^.CurAmmoType <> amParachute then |
|
407 |
RopeWaitCollision(Gear, HHGear) |
|
408 |
else |
|
409 |
RopeDeleteMe(Gear, HHGear) |
|
410 |
end |
|
411 |
end |
|
412 |
else |
|
413 |
if (Gear^.State and gsttmpFlag) = 0 then |
|
414 |
Gear^.State := Gear^.State or gsttmpFlag; |
|
415 |
end; |
|
416 |
||
417 |
procedure RopeRemoveFromAmmo(Gear, HHGear: PGear); |
|
418 |
begin |
|
419 |
if (Gear^.State and gstAttacked) = 0 then |
|
420 |
begin |
|
421 |
OnUsedAmmo(HHGear^.Hedgehog^); |
|
422 |
Gear^.State := Gear^.State or gstAttacked |
|
423 |
end; |
|
424 |
ApplyAmmoChanges(HHGear^.Hedgehog^) |
|
425 |
end; |
|
426 |
||
427 |
procedure doStepRopeAttach(Gear: PGear); |
|
10017 | 428 |
var |
7660 | 429 |
HHGear: PGear; |
430 |
tx, ty, tt: hwFloat; |
|
431 |
begin |
|
11258 | 432 |
|
7660 | 433 |
Gear^.X := Gear^.X - Gear^.dX; |
434 |
Gear^.Y := Gear^.Y - Gear^.dY; |
|
435 |
Gear^.Elasticity := Gear^.Elasticity + _1; |
|
436 |
||
437 |
HHGear := Gear^.Hedgehog^.Gear; |
|
10681 | 438 |
if HHGear = nil then |
439 |
begin |
|
10684 | 440 |
OutError('ERROR: doStepRopeAttach called while HHGear = nil', IsNilHHFatal); |
10681 | 441 |
DeleteGear(Gear); |
442 |
exit() |
|
11258 | 443 |
end |
11266
31e0e38e703c
Make camera refocus less aggressive. Only if there's a camera target already.
nemo
parents:
11258
diff
changeset
|
444 |
else if not CurrentTeam^.ExtDriven and (FollowGear <> nil) then FollowGear := HHGear; |
10681 | 445 |
|
12651
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
446 |
// Destroy rope if it touched bouncy or world wrap world edge. |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
447 |
// TODO: Allow to shoot rope through the world wrap edge and rope normally. |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
448 |
if (WorldWrap(Gear) and (WorldEdge = weWrap)) or |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
449 |
((WorldEdge = weBounce) and ((hwRound(Gear^.X) <= LeftX) or (hwRound(Gear^.X) >= RightX))) then |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
450 |
begin |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
451 |
HHGear^.State := HHGear^.State and (not (gstAttacking or gstHHJumping or gstHHHJump)); |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
452 |
HHGear^.Message := HHGear^.Message and (not gmAttack); |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
453 |
DeleteGear(Gear); |
12700
16fcd59295e3
Don't switch back to rope/chute/jetpack if selected ammo is not ammoprop_AltUse
Wuzzy <almikes@aol.com>
parents:
12695
diff
changeset
|
454 |
if (GetAmmoEntry(HHGear^.Hedgehog^, amRope)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then |
12821
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
455 |
HHGear^.Hedgehog^.CurAmmoType:= amRope; |
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
456 |
isCursorVisible := false; |
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
457 |
ApplyAmmoChanges(HHGear^.Hedgehog^); |
12651
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
458 |
exit() |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
459 |
end; |
5e115ed19e27
Destroy rope when attempting to shoot it through wrap / bouncy world edge
Wuzzy <almikes@aol.com>
parents:
11831
diff
changeset
|
460 |
|
7660 | 461 |
DeleteCI(HHGear); |
462 |
||
463 |
if (HHGear^.State and gstMoving) <> 0 then |
|
464 |
begin |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
465 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0 then |
7660 | 466 |
SetLittle(HHGear^.dX); |
467 |
if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then |
|
468 |
HHGear^.dY := _0; |
|
469 |
||
470 |
HHGear^.X := HHGear^.X + HHGear^.dX; |
|
471 |
Gear^.X := Gear^.X + HHGear^.dX; |
|
472 |
||
473 |
if TestCollisionYwithGear(HHGear, 1) <> 0 then |
|
474 |
begin |
|
475 |
CheckHHDamage(HHGear); |
|
476 |
HHGear^.dY := _0 |
|
477 |
//HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump)); |
|
478 |
end |
|
479 |
else |
|
480 |
begin |
|
481 |
HHGear^.Y := HHGear^.Y + HHGear^.dY; |
|
482 |
Gear^.Y := Gear^.Y + HHGear^.dY; |
|
483 |
HHGear^.dY := HHGear^.dY + cGravity; |
|
484 |
if (GameFlags and gfMoreWind) <> 0 then |
|
485 |
HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density |
|
486 |
end; |
|
487 |
||
488 |
tt := Gear^.Elasticity; |
|
489 |
tx := _0; |
|
490 |
ty := _0; |
|
491 |
while tt > _20 do |
|
492 |
begin |
|
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:
8744
diff
changeset
|
493 |
if ((hwRound(Gear^.Y+ty) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X+tx) and LAND_WIDTH_MASK) = 0) and (Land[hwRound(Gear^.Y+ty), hwRound(Gear^.X+tx)] > lfAllObjMask) then |
7660 | 494 |
begin |
495 |
Gear^.X := Gear^.X + tx; |
|
496 |
Gear^.Y := Gear^.Y + ty; |
|
497 |
Gear^.Elasticity := tt; |
|
498 |
Gear^.doStep := @doStepRopeWork; |
|
499 |
PlaySound(sndRopeAttach); |
|
500 |
with HHGear^ do |
|
501 |
begin |
|
502 |
State := State and (not (gstAttacking or gstHHJumping or gstHHHJump)); |
|
503 |
Message := Message and (not gmAttack) |
|
504 |
end; |
|
505 |
||
506 |
RopeRemoveFromAmmo(Gear, HHGear); |
|
507 |
||
508 |
tt := _0; |
|
509 |
exit |
|
510 |
end; |
|
511 |
tx := tx + Gear^.dX + Gear^.dX; |
|
512 |
ty := ty + Gear^.dY + Gear^.dY; |
|
513 |
tt := tt - _2; |
|
514 |
end; |
|
515 |
end; |
|
516 |
||
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:
8744
diff
changeset
|
517 |
if Gear^.Elasticity < _20 then Gear^.CollisionMask:= lfLandMask |
11831
dd18d8100afd
Change this back to allowing hooking rope to hogs again, 'cause, well, rage...
nemo
parents:
11589
diff
changeset
|
518 |
else Gear^.CollisionMask:= lfNotCurrentMask; //lfNotObjMask or lfNotHHObjMask; |
7660 | 519 |
CheckCollision(Gear); |
520 |
||
521 |
if (Gear^.State and gstCollision) <> 0 then |
|
522 |
if Gear^.Elasticity < _10 then |
|
523 |
Gear^.Elasticity := _10000 |
|
524 |
else |
|
525 |
begin |
|
526 |
Gear^.doStep := @doStepRopeWork; |
|
527 |
PlaySound(sndRopeAttach); |
|
528 |
with HHGear^ do |
|
529 |
begin |
|
530 |
State := State and (not (gstAttacking or gstHHJumping or gstHHHJump)); |
|
531 |
Message := Message and (not gmAttack) |
|
532 |
end; |
|
533 |
||
534 |
RopeRemoveFromAmmo(Gear, HHGear); |
|
535 |
||
536 |
exit |
|
537 |
end; |
|
538 |
||
539 |
if (Gear^.Elasticity > Gear^.Friction) |
|
540 |
or ((Gear^.Message and gmAttack) = 0) |
|
541 |
or ((HHGear^.State and gstHHDriven) = 0) |
|
542 |
or (HHGear^.Damage > 0) then |
|
543 |
begin |
|
544 |
with Gear^.Hedgehog^.Gear^ do |
|
545 |
begin |
|
546 |
State := State and (not gstAttacking); |
|
547 |
Message := Message and (not gmAttack) |
|
548 |
end; |
|
549 |
DeleteGear(Gear); |
|
12700
16fcd59295e3
Don't switch back to rope/chute/jetpack if selected ammo is not ammoprop_AltUse
Wuzzy <almikes@aol.com>
parents:
12695
diff
changeset
|
550 |
if (GetAmmoEntry(HHGear^.Hedgehog^, amRope)^.Count >= 1) and ((Ammoz[HHGear^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then |
12821
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
551 |
HHGear^.Hedgehog^.CurAmmoType:= amRope; |
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
552 |
isCursorVisible := false; |
f3e07e53460d
Fix desyncs when forcing rope re-selection after missing a shot or hitting bounce world edge
Wuzzy <Wuzzy2@mail.ru>
parents:
12819
diff
changeset
|
553 |
ApplyAmmoChanges(HHGear^.Hedgehog^); |
7660 | 554 |
exit; |
555 |
end; |
|
556 |
if CheckGearDrowning(HHGear) then DeleteGear(Gear) |
|
557 |
end; |
|
558 |
||
559 |
procedure doStepRope(Gear: PGear); |
|
560 |
begin |
|
561 |
Gear^.dX := - Gear^.dX; |
|
562 |
Gear^.dY := - Gear^.dY; |
|
563 |
Gear^.doStep := @doStepRopeAttach; |
|
564 |
PlaySound(sndRopeShot) |
|
565 |
end; |
|
566 |
||
567 |
end. |