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