Skip to content

Commit c670ab3

Browse files
committed
fix: more work on door handling
1 parent e41d2eb commit c670ab3

File tree

3 files changed

+77
-23
lines changed

3 files changed

+77
-23
lines changed

osrs/interfaces/minimap.simba

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,58 @@ begin
290290
if asDegrees then Result := RadToDeg(Result);
291291
end;
292292

293+
property TRSMinimap.CompassRadians: Single;
294+
var
295+
center: TPoint;
296+
bounds: TBox;
297+
north,south,west,east: TPoint;
298+
Nclr, dials, southArr, westArr, eastArr: TPointArray;
299+
n,w,e,s,x,y: Single;
300+
begin
301+
center := Self.Compass.Circle.Center;
302+
bounds := Self.Compass.Circle.Bounds;
303+
304+
dials := Target.FindColor($26259C, 12, bounds);
305+
Nclr := Target.FindColor($1D2931, 0.6, bounds);
306+
307+
dials := dials.ExtractDist(center, 10, 20);
308+
north := Nclr.ExtractDist(center, 0,20).Mean();
309+
310+
southArr := dials.ExtractDist(north, 21, 50);
311+
south := southArr.FurthestPoint(center);
312+
313+
dials := dials.Difference(southArr);
314+
315+
for dials in dials.Cluster(3) do
316+
begin
317+
if CrossProduct(dials.Mean(), north, south) > 0 then
318+
westArr := dials
319+
else
320+
eastArr := dials;
321+
end;
322+
323+
west := westArr.FurthestPoint(eastArr.Mean()); //late edit: Should not this be middle, not eastarr.mean
324+
east := eastArr.FurthestPoint(westArr.Mean()); //late edit: Should not this be middle, not westarr.mean
325+
326+
n := ArcTan2(north.y-center.y, north.x-center.x) + HALF_PI;
327+
s := ArcTan2(south.y-center.y, south.x-center.x) - HALF_PI;
328+
w := ArcTan2(west.y-center.y, west.x-center.x)+PI;
329+
e := ArcTan2(east.y-center.y, east.x-center.x);
330+
331+
x := Cos(s) + Cos(e) + Cos(w) + Cos(n);
332+
y := Sin(s) + Sin(e) + Sin(w) + Sin(n);
333+
334+
Result := ArcTan2(y/4, x/4);
335+
if Result < 0 then
336+
Result := Result + TAU;
337+
end;
338+
339+
property TRSMinimap.CompassDegrees: Single;
340+
begin
341+
Result := RadToDeg(Self.CompassRadians);
342+
end;
343+
344+
293345

294346
(*
295347
## Minimap.SetCompassAngle

osrs/position/map/mapdebugger.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ var
9898
begin
9999
pt := TPoint.Create(x,y);
100100
g := Self.GetGlobal(pt);
101-
Self.Coordinate.Caption := Format('[%d, %d]', [pt.X, pt.Y]);
101+
Self.Coordinate.Caption := Format('[%d, %d]', [g.X, g.Y]);
102102

103103
Self.Path := [];
104104
if (shift = [ELazShiftStates.Shift]) and (Self.Selected > -1) then

osrs/walker.simba

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ var
232232
arr: TPointArray;
233233
begin
234234
if not me.InRange(mapPoint, MM2MS.MAX_RENDER_DISTANCE) then Exit;
235-
if radians = $FFFF then radians := Minimap.GetCompassAngle(False);
235+
if radians = $FFFF then radians := Minimap.CompassRadians;
236236
vector := Self.Point2MMVec(me, mapPoint, radians);
237237
pt := vector.ToPoint();
238238

239-
vector := Minimap.NormalizeEx(vector, radians);
239+
vector := vector.Rotate(-radians, Minimap.Center.ToVec2());
240240
me := Self.GetLocal(me);
241241

242242
h := Self.Height(me - [1,3], False) + Self.Height(me + [3,-3], False) +
@@ -265,11 +265,11 @@ var
265265
arr: TPointArray;
266266
begin
267267
if not me.InRange(mapPoint, MM2MS.MAX_RENDER_DISTANCE) then Exit;
268-
if radians = $FFFF then radians := Minimap.GetCompassAngle(False);
268+
if radians = $FFFF then radians := Minimap.CompassRadians;
269269
vector := Self.Point2MMVec(me, mapPoint, radians);
270270
pt := vector.ToPoint();
271271

272-
vector := Minimap.NormalizeEx(vector, radians);
272+
vector := vector.Rotate(-radians, Minimap.Center.ToVec2());
273273
me := Self.GetLocal(me);
274274

275275
h := Self.Height(me - [1,3], False) + Self.Height(me + [3,-3], False) +
@@ -299,7 +299,7 @@ function TRSWalker.MM2Map(me, minimapPoint: TPoint; radians: Single = $FFFF): TP
299299
begin
300300
Result := me + minimapPoint - Minimap.Center;
301301
if (radians = $FFFF) then
302-
radians := Minimap.GetCompassAngle(False);
302+
radians := Minimap.CompassRadians;
303303
Result := Result.Rotate(-radians, me);
304304
end;
305305

@@ -433,7 +433,7 @@ var
433433
speed: Double;
434434
angle, h, diff: Single;
435435
begin
436-
angle := Minimap.GetCompassAngle(False);
436+
angle := Minimap.CompassRadians;
437437
idx := Self._Index;
438438

439439
while (idx < High(Self._Path)) and Self.IsWalkable(Self._Path[idx+1].Node, myPos, tmp, angle) do
@@ -511,7 +511,7 @@ begin
511511
if position.Current <> position.Previous then
512512
countdown.Restart();
513513

514-
//if (Self._Node <> EGraphNode.NORMAL) and Self.FlagMoved(position.Current, Minimap.GetCompassAngle(False)) then
514+
//if (Self._Node <> EGraphNode.NORMAL) and Self.FlagMoved(position.Current, Minimap.CompassRadians) then
515515
begin
516516
Self.Walking := False;
517517
Break;
@@ -584,7 +584,11 @@ begin
584584

585585
if Self.ScreenWalk then
586586
begin
587-
pt := mapPoint.Random(-8, 8);
587+
if randomness = 0 then
588+
pt := mapPoint
589+
else
590+
pt := mapPoint.Random(-randomness, randomness);
591+
588592
if not me.InRange(pt, MM2MS.MAX_RENDER_DISTANCE) then Exit;
589593

590594
quad := Self.GetQuadMS(me, pt);
@@ -666,7 +670,7 @@ begin
666670
if @Self.OnWalkEvent <> nil then Self.OnWalkEvent(@Self, me, mapPoint);
667671
if Time() - t > 100 then me := Self.Position(); //Check if event took too long and update position.
668672

669-
if not Self.Walking or not Self.IsWalkable(mapPoint, me, minimapPoint, Minimap.GetCompassAngle(False)) then
673+
if not Self.Walking or not Self.IsWalkable(mapPoint, me, minimapPoint, Minimap.CompassRadians) then
670674
Exit(not Self.Walking);
671675

672676
if Minimap.Center.InRange(minimapPoint, 4) then
@@ -720,28 +724,26 @@ end;
720724
function TRSWalker.CrossDoor(me: TPoint; index: Integer; attempts: Integer = 3): Boolean;
721725
var
722726
tmp: TPoint;
723-
door, furthest: Integer;
727+
furthest: Integer;
724728
radians: Double;
725729
mapPt, minimapPt, flag: TPoint;
726730
shouldExit, handleDoor: Boolean;
727731
cuboid: TCuboid;
728732
begin
729-
WriteLn GetDebugLn(Self.Name, 'Attempting to cross door');
730733
if attempts = 0 then Exit;
731-
732734
if index = High(Self._Path) then
733735
raise GetDebugLn(Self.Name, 'Paths should not end at a door node.');
736+
WriteLn GetDebugLn(Self.Name, 'Attempting to cross door');
734737

735-
door := Self._Path.IndexOf(Self._Path[index].Node);
736-
furthest := door;
738+
furthest := index;
737739

738-
radians := Minimap.GetCompassAngle(False);
740+
radians := Minimap.CompassRadians;
739741
while (furthest < High(Self._Path)) and Self.IsWalkable(Self._Path[furthest+1].Node, me, tmp, radians) do
740742
if Self._Path[furthest+1].Typ = EGraphNode.NORMAL then
741743
Inc(furthest);
742744

743745
if Biometrics.RandomBoolean(0.002) then
744-
furthest := Random(door, furthest);
746+
furthest := Random(index, furthest);
745747

746748
mapPt := Self._Path[furthest].Node;
747749
if not Self._WalkStepHelper(me, mapPt, 0, minimapPt, shouldExit) then
@@ -750,7 +752,7 @@ begin
750752
if shouldExit then Exit;
751753

752754
if Self.WaitFlag(flag) then
753-
handleDoor := Self.FlagMoved(flag, radians)
755+
handleDoor := not me.InRange(flag, 12) and Self.FlagMoved(flag, radians)
754756
else
755757
handleDoor := True;
756758

@@ -766,7 +768,7 @@ begin
766768
if handleDoor then
767769
begin
768770
WriteLn GetDebugLn(Self.Name, 'Attempting to open door');
769-
cuboid := Self.GetCuboidMS(me, Self._Path[door].Node, [0.6,0.6,4], radians);
771+
cuboid := Self.GetCuboidMS(me, Self._Path[index].Node, [0.6,0.6,4], radians);
770772
ShowOnTarget(cuboid);
771773
Mouse.Move(cuboid.ShapeFill().RandomMean());
772774
if MainScreen.IsUpText('Open') then
@@ -821,7 +823,7 @@ var
821823
path: TPointArray;
822824
compass: Single;
823825
begin
824-
compass := Minimap.GetCompassAngle(False);
826+
compass := Minimap.CompassRadians;
825827
for i := 0 to High(Self._Path) do
826828
if me.InRange(Self._Path[i].Node, 90) then
827829
path += Self.Point2MM(me, Self._Path[i].Node, compass);
@@ -971,7 +973,7 @@ begin
971973
if (Result = 5) then
972974
begin
973975
Minimap.SetCompassAngle(RadToDeg(angle) + RandomLeft(30, 360) * Random(-1,1));
974-
angle := Minimap.GetCompassAngle(False);
976+
angle := Minimap.CompassRadians;
975977
end;
976978

977979
if Result mod 2 = 0 then
@@ -1007,7 +1009,7 @@ var
10071009
begin
10081010
Self._WalkPathSetup(path);
10091011

1010-
angle := Minimap.GetCompassAngle(False);
1012+
angle := Minimap.CompassRadians;
10111013
while Self.Walking and (fails < 10) do
10121014
begin
10131015
me := Self.Position();
@@ -1165,7 +1167,7 @@ Wrapper function used to attempt to make a Point visible on the MainScreen.
11651167
*)
11661168
function TRSWalker.MakePointVisible(me: TPoint; pt: TPoint): Boolean;
11671169
begin
1168-
Result := Minimap.MakePointVisible(Self.Point2MM(me, pt, Minimap.GetCompassAngle(False)));
1170+
Result := Minimap.MakePointVisible(Self.Point2MM(me, pt, Minimap.CompassRadians));
11691171
end;
11701172

11711173
function TRSWalker.MakePointVisible(pt: TPoint): Boolean; overload;

0 commit comments

Comments
 (0)