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