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