From 79e0a33a855cd4ac9f02a4dc8dbad3f613e6c6ae Mon Sep 17 00:00:00 2001 From: Torwent Date: Fri, 19 Jan 2024 12:58:00 +0100 Subject: [PATCH] fix: read notes - better login on the last commit - Cuboids not on the mainscreen are filtered based on their center now instead of them being fully visible on the mainscreen. This fixes issues with large objects like wintertodt gate --- osr/interfaces/mainscreen.simba | 2 +- osr/mm2ms.simba | 16 +- osr/walker/objects/rsobjects.simba | 1 + osr/walker/objects/walkerobjects.simba | 286 ++++++++----------------- 4 files changed, 97 insertions(+), 208 deletions(-) diff --git a/osr/interfaces/mainscreen.simba b/osr/interfaces/mainscreen.simba index 06c83084..ed74bbdf 100644 --- a/osr/interfaces/mainscreen.simba +++ b/osr/interfaces/mainscreen.simba @@ -176,7 +176,7 @@ end; function TRSMainScreen.IsVisible(cuboid: TCuboidEx): Boolean; overload; begin - Result := Self.IsVisible(cuboid.ConvexHull(), False); + Result := Self.IsVisible(cuboid.Center()); end; diff --git a/osr/mm2ms.simba b/osr/mm2ms.simba index 36c265cb..97d6ed5d 100644 --- a/osr/mm2ms.simba +++ b/osr/mm2ms.simba @@ -112,20 +112,20 @@ Example *) procedure TMM2MS.SetupZoom(); begin - if (Self.ZoomLevel = -1) then - begin - Self.DebugLn('Unknown zoom level, reading from options...'); - Self.ZoomLevel := Options.GetZoomLevel; - Self.DebugLn('Current zoom level: ' + ToString(Self.ZoomLevel)); - end; + if Self.ZoomLevel > -1 then + Exit; + + Self.DebugLn('Unknown zoom level, reading from options...'); + Self.ZoomLevel := Options.GetZoomLevel(); + Self.DebugLn('Current zoom level: ' + ToString(Self.ZoomLevel)); end; -function TRSMinimap.ArrToMs(atpa: T2DPointArray; roll:Single=$FFFF): T2DPointArray; overload; +function TRSMinimap.ArrToMs(atpa: T2DPointArray; roll: Single = $FFFF): T2DPointArray; overload; var tpa: TPointArray; begin - if (roll = $FFFF) then + if roll = $FFFF then roll := Self.GetCompassAngle(False); for tpa in atpa do diff --git a/osr/walker/objects/rsobjects.simba b/osr/walker/objects/rsobjects.simba index d43b9024..b050c842 100644 --- a/osr/walker/objects/rsobjects.simba +++ b/osr/walker/objects/rsobjects.simba @@ -542,6 +542,7 @@ begin begin SetupEx([10, 4, 30], [[1912, 596]]); SetupUpText(['Doors', 'Dinh']); + Filter.Finder := False; end; with Self.WintertodtRootNW do diff --git a/osr/walker/objects/walkerobjects.simba b/osr/walker/objects/walkerobjects.simba index 017c9278..abd8fbfe 100644 --- a/osr/walker/objects/walkerobjects.simba +++ b/osr/walker/objects/walkerobjects.simba @@ -342,10 +342,10 @@ function TRSWalkerObject.FindOnMainScreen(cuboidArray: TCuboidExArray): T2DPoint var i: Int32; tpa: TPointArray; - tempFinder: TRSObjectFinder; + tmpFinder: TRSObjectFinder; begin if Self.Filter.Finder then - tempFinder := Self.Finder.Unlimited(); + tmpFinder := Self.Finder.Unlimited(); cuboidArray := MainScreen.Filter(cuboidArray); @@ -357,7 +357,7 @@ begin begin RSClient.DrawCuboid(cuboidArray[i], $FFFFFF, 1); - tpa := MainScreen.FindObject(tempFinder, cuboidArray[i].Bounds()).Merge(); + tpa := MainScreen.FindObject(tmpFinder, cuboidArray[i].Bounds()).Merge(); if tpa = [] then Continue; @@ -583,23 +583,17 @@ end; function PWalkerObjectArray.GetClosestEx(value: TPoint): PRSWalkerObject; var - i, hi: Int32; - closest, current: Double; + i: Int32; tmp: PRSWalkerObject; + closest: Double = $FFFFFF; + current: Double; begin - if Self = [] then - Exit; - - closest := $FFFFFF; - for i := 0 to hi := High(Self) do + for i := High(Self) downto 0 do begin tmp := PRSWalkerObject(Self[i]); - if tmp^.Coordinates = [] then begin Delete(Self, i, 1); - hi -= 1; - i -= 1; Continue; end; @@ -634,154 +628,6 @@ This are meant to be TRSWalkerObjects that do not have a minimap dot so TRSObjec PRSObject = ^TRSObject; PRSObjectArray = array of PRSObject; -procedure PRSObjectArray.Del(const index: Int32; const count: Int32 = 1); -begin - Delete(Self, index, count); -end; - -function PRSObjectArray.IndexOf(value: TPoint): Int32; overload; -var - i: Int32; -begin - for i := 0 to High(Self) do - if Self[i]^.Coordinates.Contains(value) then - Exit(i); - - Result := -1; -end; - -function PRSObjectArray.GetClosestEx(value: TPoint): TRSObject; -var - i, hi: Int32; - closest, current: Double; -begin - if Self = [] then - Exit; - - closest := High(Int32); - hi := High(Self); - for i := 0 to hi do - begin - if Self[i]^.Coordinates = [] then - begin - Self.Del(i); - hi -= 1; - i -= 1; - Continue; - end; - - current := Self[i]^.Coordinates.NearestPoint(value).DistanceTo(value); - if current < closest then - begin - closest := current; - Result := Self[i]^; - end; - end; -end; - -function PRSObjectArray.GetClosest(): TRSObject; -begin - if (Self = []) or (ScriptWalker = nil) then - Exit; - - Result := Self.GetClosestEx(ScriptWalker^.GetMyPos()); -end; - - -{$IFDEF SIMBA1400} -procedure TRSObjectArray.Del(const index: Int32; const count: Int32 = 1); -begin - Delete(Self, index, count); -end; - -function TRSObjectArray.IndexOf(value: TRSObject): Int32; -begin - Result := System.IndexOf(value, Self); //Simba doesn't show this but it exists and it's very fast -end; - -function TRSObjectArray.IndexOf(value: TPoint): Int32; overload; -var - i: Int32; -begin - for i := 0 to High(Self) do - if Self[i].Coordinates.Contains(value) then - Exit(i); - - Result := -1; -end; - -function TRSObjectArray.IndicesOf(value: TRSObject): TIntegerArray; -begin - Result := System.IndicesOf(value, Self); //Simba doesn't show this but it exists and it's very fast -end; - -function TRSObjectArray.IndicesOf(value: TPoint): TIntegerArray; overload; -var - i: Int32; -begin - for i := 0 to High(Self) do - if Self[i].Coordinates.Contains(value) then - Result += i; -end; - -procedure TRSObjectArray.Remove(const value: TRSObject; const all: Boolean = False); -var - i: Int32; - lst: TIntegerArray; -begin - if (not all) then - begin - i := Self.IndexOf(value); - if i >= 0 then - Self.Del(i); - Exit; - end; - - lst := Self.IndicesOf(value); - for i := High(lst) downto 0 do - Self.Del(lst[i]); -end; -{$ENDIF} - - -function TRSObjectArray.GetClosestEx(value: TPoint): TRSObject; -var - i, hi: Int32; - closest, current: Double; -begin - if Self = [] then - Exit; - - closest := High(Int32); - hi := High(Self); - for i := 0 to hi do - begin - if Self[i].Coordinates = [] then - begin - Self.Del(i); - hi -= 1; - i -= 1; - Continue; - end; - - current := Self[i].Coordinates.NearestPoint(value).DistanceTo(value); - if current < closest then - begin - closest := current; - Result := Self[i]; - end; - end; -end; - -function TRSObjectArray.GetClosest(): TRSObject; -begin - if (Self = []) or (ScriptWalker = nil) then - Exit; - - Result := Self.GetClosestEx(ScriptWalker^.GetMyPos()); -end; - - (* TRSObject.Setup ~~~~~~~~~~~~~~~ @@ -881,13 +727,11 @@ begin if Self.Filter.Walker then begin cuboidArray := Self.GetCuboidArray(); - if cuboidArray = [] then Exit; atpa := Self.FindOnMainScreen(cuboidArray); end - else if Self.Filter.Finder then atpa := MainScreen.FindObject(Self.Finder).SortFrom(MainScreen.GetPlayerBox().Center()); @@ -1354,6 +1198,38 @@ begin Self.CurrentActionUpText := []; end; +function PRSObjectArray.GetClosestEx(value: TPoint): PRSObject; +var + i: Int32; + closest: Double = $FFFFFF; + current: Double; +begin + for i := High(Self) downto 0 do + begin + if Self[i]^.Coordinates = [] then + begin + Delete(Self, i, 1); + Continue; + end; + + current := Self[i]^.Coordinates.NearestPoint(value).DistanceTo(value); + if current < closest then + begin + closest := current; + Result := Self[i]; + end; + end; +end; + +function PRSObjectArray.GetClosest(): PRSObject; +begin + if (Self = []) or (ScriptWalker = nil) then + Exit; + + Result := Self.GetClosestEx(ScriptWalker^.GetMyPos()); +end; + + type (* type TRSMMDot @@ -1402,7 +1278,6 @@ The other methods all call this first one with certain default values: - If size is omited, shape.X and shape.Y are set to 1. *) - procedure TRSMMDot.SetupCoordinates(radii: TIntegerArray; coordinates: TPointArray); overload; var i, j, hi: Int32; @@ -1605,7 +1480,6 @@ begin end; end; - (* TRSMMDot.FindEx ~~~~~~~~~~~~~~~ @@ -2135,7 +2009,6 @@ begin Self.CurrentActionUpText := []; end; - type (* type TRSNPC @@ -2171,17 +2044,6 @@ This are meant to be TRSMMDot that have a white minimap dot so TRSPlayer.Filter. TRSPlayer = type TRSMMDot; TRSPlayerArray = array of TRSPlayer; -procedure PRSNPCArray.Del(const Index: Integer; const Count: Integer = 1); -begin - Delete(Self, Index, Count); -end; - -procedure PRSGroundItemArray.Del(const Index: Integer; const Count: Integer = 1); -begin - Delete(Self, Index, Count); -end; - - (* TRSNPC.Setup ~~~~~~~~~~~~ @@ -2258,52 +2120,78 @@ begin end; -function PRSNPCArray.IndexOf(value: TPoint): Int32; overload; +function PRSNPCArray.GetClosestEx(value: TPoint): PRSNPC; var i: Int32; + closest, current: Double; begin - for i := 0 to High(Self) do - if Self[i]^.Coordinates.Contains(value) then - Exit(i); + if Self = [] then + Exit; + + closest := $FFFFFF; + + for i := High(Self) downto 0 do + begin + if Self[i]^.Coordinates = [] then + begin + Delete(Self, i, 1); + Continue; + end; - Result := -1; + current := Self[i]^.Coordinates.NearestPoint(value).DistanceTo(value); + if current < closest then + begin + closest := current; + Result := Self[i]; + end; + end; end; -function PRSNPCArray.GetClosest(): TRSNPC; -var - me: TPoint; - i, hi: Int32; - tpa, tmp: TPointArray; +function PRSNPCArray.GetClosest(): PRSNPC; begin - if Self = [] then + if (Self = []) or (ScriptWalker = nil) then Exit; - if ScriptWalker = nil then + Result := Self.GetClosestEx(ScriptWalker^.GetMyPos()); +end; + + +function PRSGroundItemArray.GetClosestEx(value: TPoint): PRSGroundItem; +var + i: Int32; + closest, current: Double; +begin + if Self = [] then Exit; - me := ScriptWalker^.GetMyPos(); + closest := $FFFFFF; - hi := High(Self); - for i := 0 to hi do + for i := High(Self) downto 0 do begin if Self[i]^.Coordinates = [] then begin - Self.Del(i); //remove the empty ones so next times are faster since we don't have to check them. - hi -= 1; + Delete(Self, i, 1); Continue; end; - tmp := Self[i]^.Coordinates.SortFrom(me); - tpa += tmp.First(); + current := Self[i]^.Coordinates.NearestPoint(value).DistanceTo(value); + if current < closest then + begin + closest := current; + Result := Self[i]; + end; end; +end; - if tpa = [] then +function PRSGroundItemArray.GetClosest(): PRSGroundItem; +begin + if (Self = []) or (ScriptWalker = nil) then Exit; - tpa := tpa.SortFrom(me); - Result := Self[Self.IndexOf(tpa.First())]^; + Result := Self.GetClosestEx(ScriptWalker^.GetMyPos()); end; + (* Debug ~~~~~