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