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