author | nemo |
Wed, 24 Dec 2014 11:50:53 -0500 | |
changeset 10713 | ac12876c4f66 |
parent 10684 | d403fd2f9a6f |
child 10722 | 37264e44ec0f |
permissions | -rw-r--r-- |
7660 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9998 | 3 |
* Copyright (c) 2004-2014 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 |
32 |
IsNilHHFatal = true; |
|
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() |
|
45 |
end; |
|
46 |
||
9526 | 47 |
tX:= HHGear^.X; |
10017 | 48 |
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
|
49 |
((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0)) then |
9526 | 50 |
begin |
51 |
HHGear^.X:= tX; |
|
9809 | 52 |
HHGear^.dX.isNegative:= hwRound(tX) > LongInt(leftX) + HHGear^.Radius * 2 |
9526 | 53 |
end; |
54 |
||
8680 | 55 |
if (HHGear^.Hedgehog^.CurAmmoType = amParachute) and (HHGear^.dY > _0_39) then |
56 |
begin |
|
57 |
DeleteGear(Gear); |
|
58 |
ApplyAmmoChanges(HHGear^.Hedgehog^); |
|
59 |
HHGear^.Message:= HHGear^.Message or gmLJump; |
|
60 |
exit |
|
61 |
end; |
|
62 |
||
7660 | 63 |
if ((HHGear^.State and gstHHDriven) = 0) |
64 |
or (CheckGearDrowning(HHGear)) |
|
65 |
or (TestCollisionYwithGear(HHGear, 1) <> 0) then |
|
66 |
begin |
|
67 |
DeleteGear(Gear); |
|
68 |
isCursorVisible := false; |
|
69 |
ApplyAmmoChanges(HHGear^.Hedgehog^); |
|
70 |
exit |
|
71 |
end; |
|
72 |
||
73 |
HedgehogChAngle(HHGear); |
|
74 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
75 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0 then |
7660 | 76 |
SetLittle(HHGear^.dX); |
77 |
||
78 |
if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then |
|
79 |
HHGear^.dY := _0; |
|
80 |
HHGear^.X := HHGear^.X + HHGear^.dX; |
|
81 |
HHGear^.Y := HHGear^.Y + HHGear^.dY; |
|
82 |
HHGear^.dY := HHGear^.dY + cGravity; |
|
10017 | 83 |
|
7660 | 84 |
if (GameFlags and gfMoreWind) <> 0 then |
85 |
HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; |
|
86 |
||
87 |
if (Gear^.Message and gmAttack) <> 0 then |
|
88 |
begin |
|
89 |
Gear^.X := HHGear^.X; |
|
90 |
Gear^.Y := HHGear^.Y; |
|
91 |
||
92 |
ApplyAngleBounds(Gear^.Hedgehog^, amRope); |
|
93 |
||
94 |
Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX); |
|
95 |
Gear^.dY := -AngleCos(HHGear^.Angle); |
|
96 |
Gear^.Friction := _4_5 * cRopePercent; |
|
97 |
Gear^.Elasticity := _0; |
|
98 |
Gear^.State := Gear^.State and (not gsttmpflag); |
|
99 |
Gear^.doStep := @doStepRope; |
|
100 |
end |
|
101 |
end; |
|
102 |
||
103 |
procedure RopeDeleteMe(Gear, HHGear: PGear); |
|
104 |
begin |
|
105 |
with HHGear^ do |
|
106 |
begin |
|
107 |
Message := Message and (not gmAttack); |
|
108 |
State := (State or gstMoving) and (not gstWinner); |
|
109 |
end; |
|
110 |
DeleteGear(Gear) |
|
111 |
end; |
|
112 |
||
113 |
procedure RopeWaitCollision(Gear, HHGear: PGear); |
|
114 |
begin |
|
115 |
with HHGear^ do |
|
116 |
begin |
|
117 |
Message := Message and (not gmAttack); |
|
118 |
State := State or gstMoving; |
|
119 |
end; |
|
120 |
RopePoints.Count := 0; |
|
121 |
Gear^.Elasticity := _0; |
|
122 |
Gear^.doStep := @doStepRopeAfterAttack |
|
123 |
end; |
|
124 |
||
125 |
procedure doStepRopeWork(Gear: PGear); |
|
10017 | 126 |
var |
7660 | 127 |
HHGear: PGear; |
128 |
len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat; |
|
129 |
lx, ly, cd: LongInt; |
|
130 |
haveCollision, |
|
131 |
haveDivided: boolean; |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
132 |
wrongSide: boolean; |
7660 | 133 |
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
|
134 |
HHGear := Gear^.Hedgehog^.Gear; |
10681 | 135 |
if HHGear = nil then |
136 |
begin |
|
10684 | 137 |
OutError('ERROR: doStepRopeWork called while HHGear = nil', IsNilHHFatal); |
10681 | 138 |
DeleteGear(Gear); |
139 |
exit() |
|
140 |
end; |
|
7660 | 141 |
|
10680
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
142 |
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
|
143 |
(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
|
144 |
begin |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
exit |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
148 |
end; |
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
149 |
|
4a4a82686e91
Issue 871 in hedgewars: "Hedgehog dropping into water while still attached to a rope makes engine crash"
sheepluva
parents:
10108
diff
changeset
|
150 |
if GameTicks mod 4 <> 0 then exit; |
7660 | 151 |
|
9526 | 152 |
tX:= HHGear^.X; |
10017 | 153 |
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
|
154 |
((TestCollisionXwithGear(HHGear, 1) <> 0) or (TestCollisionXwithGear(HHGear, -1) <> 0)) then |
9526 | 155 |
begin |
156 |
PlaySound(sndRopeRelease); |
|
157 |
RopeDeleteMe(Gear, HHGear); |
|
158 |
HHGear^.X:= tX; |
|
9809 | 159 |
HHGear^.dX.isNegative:= hwRound(tX) > LongInt(leftX) + HHGear^.Radius * 2; |
9526 | 160 |
exit |
161 |
end; |
|
162 |
||
163 |
tX:= HHGear^.X; |
|
7660 | 164 |
HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue shl 2; |
165 |
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
|
166 |
if (Gear^.Message and gmLeft <> 0) and (TestCollisionXwithGear(HHGear, -1) = 0) then |
7660 | 167 |
HHGear^.dX := HHGear^.dX - _0_0032; |
168 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
169 |
if (Gear^.Message and gmRight <> 0) and (TestCollisionXwithGear(HHGear, 1) = 0) then |
7660 | 170 |
HHGear^.dX := HHGear^.dX + _0_0032; |
171 |
||
172 |
// vector between hedgehog and rope attaching point |
|
173 |
ropeDx := HHGear^.X - Gear^.X; |
|
174 |
ropeDy := HHGear^.Y - Gear^.Y; |
|
175 |
||
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
176 |
if TestCollisionYwithXYShift(HHGear, 0, 1, 1) = 0 then |
7660 | 177 |
begin |
178 |
||
179 |
// depending on the rope vector we know which X-side to check for collision |
|
180 |
// in order to find out if the hog can still be moved by gravity |
|
181 |
if ropeDx.isNegative = RopeDy.IsNegative then |
|
182 |
cd:= -1 |
|
183 |
else |
|
184 |
cd:= 1; |
|
185 |
||
186 |
// 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
|
187 |
if TestCollisionXwithXYShift(HHGear, _2*cd, 0, cd, true) = 0 then |
7660 | 188 |
HHGear^.dY := HHGear^.dY + cGravity * 16; |
189 |
||
190 |
if (GameFlags and gfMoreWind) <> 0 then |
|
191 |
// 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
|
192 |
if TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) = 0 then |
7660 | 193 |
HHGear^.dX := HHGear^.dX + cWindSpeed * 16 / HHGear^.Density; |
194 |
end; |
|
195 |
||
196 |
mdX := ropeDx + HHGear^.dX; |
|
197 |
mdY := ropeDy + HHGear^.dY; |
|
198 |
len := _1 / Distance(mdX, mdY); |
|
199 |
// rope vector plus hedgehog direction vector normalized |
|
200 |
mdX := mdX * len; |
|
201 |
mdY := mdY * len; |
|
202 |
||
203 |
// for visual purposes only |
|
204 |
Gear^.dX := mdX; |
|
205 |
Gear^.dY := mdY; |
|
206 |
||
207 |
///// |
|
208 |
tx := HHGear^.X; |
|
209 |
ty := HHGear^.Y; |
|
210 |
||
211 |
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
|
212 |
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
|
213 |
or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*hwSign(ropeDy), hwSign(ropeDy)) <> 0))) then |
7660 | 214 |
Gear^.Elasticity := Gear^.Elasticity + _1_2; |
215 |
||
216 |
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
|
217 |
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
|
218 |
or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*-hwSign(ropeDy), -hwSign(ropeDy)) <> 0))) then |
7660 | 219 |
Gear^.Elasticity := Gear^.Elasticity - _1_2; |
220 |
||
221 |
HHGear^.X := Gear^.X + mdX * Gear^.Elasticity; |
|
222 |
HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity; |
|
223 |
||
224 |
HHGear^.dX := HHGear^.X - tx; |
|
225 |
HHGear^.dY := HHGear^.Y - ty; |
|
226 |
//// |
|
227 |
||
228 |
||
229 |
haveDivided := false; |
|
230 |
// check whether rope needs dividing |
|
231 |
||
232 |
len := Gear^.Elasticity - _5; |
|
233 |
nx := Gear^.X + mdX * len; |
|
234 |
ny := Gear^.Y + mdY * len; |
|
235 |
tx := mdX * _1_2; // should be the same as increase step |
|
236 |
ty := mdY * _1_2; |
|
237 |
||
238 |
while len > _3 do |
|
239 |
begin |
|
240 |
lx := hwRound(nx); |
|
241 |
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
|
242 |
if ((ly and LAND_HEIGHT_MASK) = 0) and ((lx and LAND_WIDTH_MASK) = 0) and (Land[ly, lx] > lfAllObjMask) then |
7660 | 243 |
begin |
8397
5b273af3ac95
Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents:
7674
diff
changeset
|
244 |
tx := _1 / Distance(ropeDx, ropeDy); |
7660 | 245 |
// 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
|
246 |
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
|
247 |
ny := ropeDy * tx; |
7660 | 248 |
|
249 |
with RopePoints.ar[RopePoints.Count] do |
|
250 |
begin |
|
251 |
X := Gear^.X; |
|
252 |
Y := Gear^.Y; |
|
253 |
if RopePoints.Count = 0 then |
|
254 |
RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX); |
|
255 |
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
|
256 |
sx:= Gear^.dX.isNegative; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
257 |
sy:= Gear^.dY.isNegative; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
258 |
sb:= Gear^.dX.QWordValue < Gear^.dY.QWordValue; |
7660 | 259 |
dLen := len |
260 |
end; |
|
8397
5b273af3ac95
Don't use same hwFloat variable at both left and right sides of assignment (inlining bug?)
unc0rr
parents:
7674
diff
changeset
|
261 |
|
7660 | 262 |
with RopePoints.rounded[RopePoints.Count] do |
263 |
begin |
|
264 |
X := hwRound(Gear^.X); |
|
265 |
Y := hwRound(Gear^.Y); |
|
266 |
end; |
|
267 |
||
268 |
Gear^.X := Gear^.X + nx * len; |
|
269 |
Gear^.Y := Gear^.Y + ny * len; |
|
270 |
inc(RopePoints.Count); |
|
271 |
TryDo(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true); |
|
272 |
Gear^.Elasticity := Gear^.Elasticity - len; |
|
273 |
Gear^.Friction := Gear^.Friction - len; |
|
274 |
haveDivided := true; |
|
275 |
break |
|
276 |
end; |
|
277 |
nx := nx - tx; |
|
278 |
ny := ny - ty; |
|
279 |
||
280 |
// len := len - _1_2 // should be the same as increase step |
|
281 |
len.QWordValue := len.QWordValue - _1_2.QWordValue; |
|
282 |
end; |
|
283 |
||
284 |
if not haveDivided then |
|
285 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
286 |
begin |
|
287 |
tx := RopePoints.ar[Pred(RopePoints.Count)].X; |
|
288 |
ty := RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
289 |
mdX := tx - Gear^.X; |
|
290 |
mdY := ty - Gear^.Y; |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
291 |
ropeDx:= tx - HHGear^.X; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
292 |
ropeDy:= ty - HHGear^.Y; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
293 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor (mdX * ropeDy > ropeDx * mdY) then |
7660 | 294 |
begin |
295 |
dec(RopePoints.Count); |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
296 |
Gear^.X := tx; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
297 |
Gear^.Y := ty; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
298 |
|
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
299 |
// 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
|
300 |
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
|
301 |
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
|
302 |
|
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
303 |
// 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
|
304 |
// 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
|
305 |
if (not wrongSide) |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
306 |
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
|
307 |
<> (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
|
308 |
if RopePoints.ar[RopePoints.Count].sb then |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
309 |
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
|
310 |
else |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
311 |
wrongSide:= ropeDx.isNegative = RopePoints.ar[RopePoints.Count].sx; |
7660 | 312 |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
313 |
if wrongSide then |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
314 |
begin |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
end else |
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; |
7660 | 321 |
|
8733
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
322 |
// restore hog position |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
323 |
len := _1 / Distance(mdX, mdY); |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
324 |
mdX := mdX * len; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
325 |
mdY := mdY * len; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
326 |
|
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
327 |
HHGear^.X := Gear^.X - mdX * Gear^.Elasticity; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
328 |
HHGear^.Y := Gear^.Y - mdY * Gear^.Elasticity; |
b6002f1956d5
Hard math to fix issue 571. Well, not really hard math,
unc0rr
parents:
8680
diff
changeset
|
329 |
end; |
7660 | 330 |
end |
331 |
end; |
|
332 |
||
333 |
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
|
334 |
if TestCollisionXwithXYShift(HHGear, _2*hwSign(HHGear^.dX), 0, hwSign(HHGear^.dX), true) <> 0 then |
7660 | 335 |
begin |
336 |
HHGear^.dX := -_0_6 * HHGear^.dX; |
|
337 |
haveCollision := true |
|
338 |
end; |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
339 |
if TestCollisionYwithXYShift(HHGear, 0, 1*hwSign(HHGear^.dY), hwSign(HHGear^.dY)) <> 0 then |
7660 | 340 |
begin |
341 |
HHGear^.dY := -_0_6 * HHGear^.dY; |
|
342 |
haveCollision := true |
|
343 |
end; |
|
344 |
||
345 |
if haveCollision and (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.Message and (gmUp or gmDown) <> 0) then |
|
346 |
begin |
|
347 |
HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _0_8, HHGear^.dX); |
|
348 |
HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _0_8, HHGear^.dY) |
|
349 |
end; |
|
350 |
||
351 |
len := hwSqr(HHGear^.dX) + hwSqr(HHGear^.dY); |
|
352 |
if len > _10 then |
|
353 |
begin |
|
354 |
len := _3_2 / hwSqrt(len); |
|
355 |
HHGear^.dX := HHGear^.dX * len; |
|
356 |
HHGear^.dY := HHGear^.dY * len; |
|
357 |
end; |
|
358 |
||
359 |
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); |
|
360 |
||
361 |
if not haveCollision then |
|
362 |
begin |
|
363 |
// backup gear location |
|
364 |
tx:= Gear^.X; |
|
365 |
ty:= Gear^.Y; |
|
366 |
||
367 |
if RopePoints.Count > 0 then |
|
368 |
begin |
|
369 |
// set gear location to the remote end of the rope, the attachment point |
|
370 |
Gear^.X:= RopePoints.ar[0].X; |
|
371 |
Gear^.Y:= RopePoints.ar[0].Y; |
|
372 |
end; |
|
373 |
||
374 |
CheckCollision(Gear); |
|
375 |
// if we haven't found any collision yet then check the other side too |
|
376 |
if (Gear^.State and gstCollision) = 0 then |
|
377 |
begin |
|
378 |
Gear^.dX.isNegative:= not Gear^.dX.isNegative; |
|
379 |
Gear^.dY.isNegative:= not Gear^.dY.isNegative; |
|
380 |
CheckCollision(Gear); |
|
381 |
Gear^.dX.isNegative:= not Gear^.dX.isNegative; |
|
382 |
Gear^.dY.isNegative:= not Gear^.dY.isNegative; |
|
383 |
end; |
|
384 |
||
385 |
haveCollision:= (Gear^.State and gstCollision) <> 0; |
|
386 |
||
387 |
// restore gear location |
|
388 |
Gear^.X:= tx; |
|
389 |
Gear^.Y:= ty; |
|
390 |
end; |
|
391 |
||
392 |
// if the attack key is pressed, lose rope contact as well |
|
393 |
if (Gear^.Message and gmAttack) <> 0 then |
|
394 |
haveCollision:= false; |
|
395 |
||
396 |
HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue shr 2; |
|
397 |
HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue shr 2; |
|
7674
aead327f1e1a
fix for issue 293 : "rope stuck after picking crate"
sheepluva
parents:
7662
diff
changeset
|
398 |
if (not haveCollision) and ((Gear^.State and gsttmpFlag) <> 0) then |
7660 | 399 |
begin |
400 |
begin |
|
401 |
PlaySound(sndRopeRelease); |
|
402 |
if Gear^.Hedgehog^.CurAmmoType <> amParachute then |
|
403 |
RopeWaitCollision(Gear, HHGear) |
|
404 |
else |
|
405 |
RopeDeleteMe(Gear, HHGear) |
|
406 |
end |
|
407 |
end |
|
408 |
else |
|
409 |
if (Gear^.State and gsttmpFlag) = 0 then |
|
410 |
Gear^.State := Gear^.State or gsttmpFlag; |
|
411 |
end; |
|
412 |
||
413 |
procedure RopeRemoveFromAmmo(Gear, HHGear: PGear); |
|
414 |
begin |
|
415 |
if (Gear^.State and gstAttacked) = 0 then |
|
416 |
begin |
|
417 |
OnUsedAmmo(HHGear^.Hedgehog^); |
|
418 |
Gear^.State := Gear^.State or gstAttacked |
|
419 |
end; |
|
420 |
ApplyAmmoChanges(HHGear^.Hedgehog^) |
|
421 |
end; |
|
422 |
||
423 |
procedure doStepRopeAttach(Gear: PGear); |
|
10017 | 424 |
var |
7660 | 425 |
HHGear: PGear; |
426 |
tx, ty, tt: hwFloat; |
|
427 |
begin |
|
428 |
Gear^.X := Gear^.X - Gear^.dX; |
|
429 |
Gear^.Y := Gear^.Y - Gear^.dY; |
|
430 |
Gear^.Elasticity := Gear^.Elasticity + _1; |
|
431 |
||
432 |
HHGear := Gear^.Hedgehog^.Gear; |
|
10681 | 433 |
if HHGear = nil then |
434 |
begin |
|
10684 | 435 |
OutError('ERROR: doStepRopeAttach called while HHGear = nil', IsNilHHFatal); |
10681 | 436 |
DeleteGear(Gear); |
437 |
exit() |
|
438 |
end; |
|
439 |
||
7660 | 440 |
DeleteCI(HHGear); |
441 |
||
442 |
if (HHGear^.State and gstMoving) <> 0 then |
|
443 |
begin |
|
9706
5178d2263521
return land word from uCollisions to make decisions based on it. Should be handy for trampoline.
nemo
parents:
9683
diff
changeset
|
444 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) <> 0 then |
7660 | 445 |
SetLittle(HHGear^.dX); |
446 |
if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then |
|
447 |
HHGear^.dY := _0; |
|
448 |
||
449 |
HHGear^.X := HHGear^.X + HHGear^.dX; |
|
450 |
Gear^.X := Gear^.X + HHGear^.dX; |
|
451 |
||
452 |
if TestCollisionYwithGear(HHGear, 1) <> 0 then |
|
453 |
begin |
|
454 |
CheckHHDamage(HHGear); |
|
455 |
HHGear^.dY := _0 |
|
456 |
//HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump)); |
|
457 |
end |
|
458 |
else |
|
459 |
begin |
|
460 |
HHGear^.Y := HHGear^.Y + HHGear^.dY; |
|
461 |
Gear^.Y := Gear^.Y + HHGear^.dY; |
|
462 |
HHGear^.dY := HHGear^.dY + cGravity; |
|
463 |
if (GameFlags and gfMoreWind) <> 0 then |
|
464 |
HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density |
|
465 |
end; |
|
466 |
||
467 |
tt := Gear^.Elasticity; |
|
468 |
tx := _0; |
|
469 |
ty := _0; |
|
470 |
while tt > _20 do |
|
471 |
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
|
472 |
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 | 473 |
begin |
474 |
Gear^.X := Gear^.X + tx; |
|
475 |
Gear^.Y := Gear^.Y + ty; |
|
476 |
Gear^.Elasticity := tt; |
|
477 |
Gear^.doStep := @doStepRopeWork; |
|
478 |
PlaySound(sndRopeAttach); |
|
479 |
with HHGear^ do |
|
480 |
begin |
|
481 |
State := State and (not (gstAttacking or gstHHJumping or gstHHHJump)); |
|
482 |
Message := Message and (not gmAttack) |
|
483 |
end; |
|
484 |
||
485 |
RopeRemoveFromAmmo(Gear, HHGear); |
|
486 |
||
487 |
tt := _0; |
|
488 |
exit |
|
489 |
end; |
|
490 |
tx := tx + Gear^.dX + Gear^.dX; |
|
491 |
ty := ty + Gear^.dY + Gear^.dY; |
|
492 |
tt := tt - _2; |
|
493 |
end; |
|
494 |
end; |
|
495 |
||
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
|
496 |
if Gear^.Elasticity < _20 then Gear^.CollisionMask:= lfLandMask |
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
|
497 |
else Gear^.CollisionMask:= lfNotCurrentMask; |
7660 | 498 |
CheckCollision(Gear); |
499 |
||
500 |
if (Gear^.State and gstCollision) <> 0 then |
|
501 |
if Gear^.Elasticity < _10 then |
|
502 |
Gear^.Elasticity := _10000 |
|
503 |
else |
|
504 |
begin |
|
505 |
Gear^.doStep := @doStepRopeWork; |
|
506 |
PlaySound(sndRopeAttach); |
|
507 |
with HHGear^ do |
|
508 |
begin |
|
509 |
State := State and (not (gstAttacking or gstHHJumping or gstHHHJump)); |
|
510 |
Message := Message and (not gmAttack) |
|
511 |
end; |
|
512 |
||
513 |
RopeRemoveFromAmmo(Gear, HHGear); |
|
514 |
||
515 |
exit |
|
516 |
end; |
|
517 |
||
518 |
if (Gear^.Elasticity > Gear^.Friction) |
|
519 |
or ((Gear^.Message and gmAttack) = 0) |
|
520 |
or ((HHGear^.State and gstHHDriven) = 0) |
|
521 |
or (HHGear^.Damage > 0) then |
|
522 |
begin |
|
523 |
with Gear^.Hedgehog^.Gear^ do |
|
524 |
begin |
|
525 |
State := State and (not gstAttacking); |
|
526 |
Message := Message and (not gmAttack) |
|
527 |
end; |
|
528 |
DeleteGear(Gear); |
|
529 |
exit; |
|
530 |
end; |
|
531 |
if CheckGearDrowning(HHGear) then DeleteGear(Gear) |
|
532 |
end; |
|
533 |
||
534 |
procedure doStepRope(Gear: PGear); |
|
535 |
begin |
|
536 |
Gear^.dX := - Gear^.dX; |
|
537 |
Gear^.dY := - Gear^.dY; |
|
538 |
Gear^.doStep := @doStepRopeAttach; |
|
539 |
PlaySound(sndRopeShot) |
|
540 |
end; |
|
541 |
||
542 |
end. |