Minimap to Mainscreen

The core for our minimap to mainscreen projection. Supports rotation, and zoom, and resizable client.

MM2MS extends the Minimap interface as well as the mainscreen interface with functionality to convert coordinates to & from the minimap to the mainscreen.


type TMM2MS

TMM2MS = record(TSRLBaseRecord)
  ZoomLevel: Int32;
  ZoomRectangles: array [0..100] of TRectangle;
  PlayerBoxes: array [0..100] of TBox;
end;

The comments explains it. This is the datastructure MM2MS uses.


var MM2MS

var MM2MS: TMM2MS;

The global variable which you would refer to.


Minimap Extensions

Extend the minimap-functionality with MM2MS functions


Minimap.ToMS

function TRSMinimap.VectorsToMS(vectors: Vector3Array; roll: Single = $FFFF): TPointArray;
function TRSMinimap.PointsToMS(points: TPointArray; roll: Single = $FFFF): TPointArray;
function TRSMinimap.VectorToMS(vec: Vector3; roll: Single = $FFFF): TPoint;
function TRSMinimap.PointToMS(pt: TPoint; roll: Single = $FFFF): TPoint;
function TRSMinimap.StaticToMS(StaticMMPoint: TPoint; Height:Int32=0): TPoint;

Convert minimap coordinates to mainscreen ones. Methods that use Vector3 are used internally, you probably don’t need to use them.

The static method assumes the coordinate is from the compass angle set to 0. And will be rotated to the current compass angle.


Minimap.ToMSRect

function TRSMinimap.VectorToMSRect(vector: Vector3; weSize, nsSize: Double = 1; roll: Single = $FFFF): TRectangle;
function TRSMinimap.PointToMSRect(pt: TPoint; weSize, nsSize: Double = 1; roll: Single = $FFFF): TRectangle;
function TRSMinimap.StaticToMsRect(staticMMPoint: TPoint; weSize, nsSize: Double = 1; Height: Double = 0): TRectangle;

Converts minimap coordinates to mainscreen rectangles.

The static method assumes a coordinate with compass angle set to 0. So the coordinate will be rotated to whatever the current angle is.

The rectangle can be expanded with weSize and nsSize and it’s unit is measured in game tiles.


Minimap.GetTile

function TRSMinimap.GetTileMS(loc: TPoint; tile: Vector3 = [1, 1, 0]; offset: Vector2 = [0, 0]; angle: Single = $FFFF): TRectangle;
function TRSMinimap.GetTileMS(loc: TPoint; shape: TRSMainScreenShape; offset: TPoint = [0, 0]; angle: Single = $FFFF): TRectangle; overload;
function TRSMinimap.GetTileArrayMS(locArray: TPointArray; tile: Vector3 = [1, 1, 0]; offset: TPoint = [0, 0]; angle: Single = $FFFF): TRectArray;
function TRSMinimap.GetTileArrayMS(locArray: TPointArray; shapeArray: TRSMainScreenShapeArray; offset: TPoint = [0, 0]; angle: Single = $FFFF): TRectArray; overload;

Converts minimap coordinates to mainscreen tile at a specific height. There’s no accurate way of measuring height so this value has to be eyeballed. As a guide, a bank chest is around 4 height, a player is around 6 and a oak tree 12/14.

Methods with TRSMainScreenShape parameters allow you do have “tilted” rectangles.


Minimap.GetCuboidMS

function TRSMinimap.GetCuboidMSEx(loc: TPoint; shape: vector3; rotation: Single = 0; offset: Vector3 = [0, 0, 0]; angle: Single = $FFFF): TCuboidEx;
function TRSMinimap.GetCuboidMS(loc: TPoint; tile: Vector3 = [1, 1, 4]; offset: Vector3 = [0, 0, 0]; angle: Single = $FFFF): TCuboidEx;
function TRSMinimap.GetCuboidArrayMSEx(locArray: TPointArray; shape: Vector3; rotations: TSingleArray; startHeights: TDoubleArray; offset: Vector2 = [0, 0]; angle: Single = $FFFF): TCuboidExArray;
function TRSMinimap.GetCuboidArrayMS(locArray: TPointArray; tile: Vector3; offset: Vector2 = [0, 0]; angle: Single = $FFFF): TCuboidExArray; overload;

Converts minimap coordinates to mainscreen cuboid(s) at a specific height. To understand what this better, you should read about Minimap.GetTileMS and TPointArray.ConvexHull and understand what they do.

To put it simply, this will will first calculate a floor rectangle with tile.Z, or height if you prefer of 0 and then calculate the top rectangle of the tile.Z you specified.

After this 2 rectangles are calculated, a cuboid is then made out of the two, resulting in a ConvexHull which is returned.

This is perfect to to get an accurate bounding cuboid of objects and NPCs which you can use to accurately color search after.

The example below will show you how it could be used to retrieve an accurate player bounding cuboid.

Example:

P := Minimap.GetDots(ERSMinimapDot.PLAYER)[0];         //find a player dot and returns it's coodinates.
offset := [2 , 2];                                     //Minimap dots are actually returned with a slight offset of -2, -2 when converting them to the mainscreen.
Debug(Minimap.GetCuboidMS(P, [1, 1, 7], offset));     //This will draw a polygon around the nearest player.

Minimap.GetZoomRectangle

function TRSMinimap.GetZoomRectangle(): TRectangle;

This function returns an accurate rectangle of what’s visible on the MainScreen on the Minimap. This can be used to know if it’s possible to make something visible by adjusting the zoom level or rotating the camera.

Example:

Debug(Minimap.GetZoomRectangle());

Minimap.PointInZoomRectangle()

function Minimap.PointInZoomRectangle(p: TPoint): Boolean;

Check if a given point is within our zoom rectangle, in other words, in visible in the Mainscreen.

Example::

p := Minimap.GetDots(ERSMinimapDot.ITEM)[0]; //find an item dot and returns it's coodinates.
WriteLn Minimap.PointInZoomRadius(p);

Minimap.RandomPointInZoomRectangle()

function TRSMinimap.RandomPointInZoomRectangle(p: TPoint; randomness: Int32): TPoint;

Creates a random point that based on randomness and p that is within the zoom rectangle. Returns [0, 0] if the point couldn’t be generated, e.g. it’s too far away from the zoom rectangle.


Minimap.PointWithinZoom

function TRSMinimap.InZoomRangeEx(p: TPoint; out corner: TPoint): Boolean;
function TRSMinimap.InZoomRange(p: TPoint): Boolean;
function TRSMinimap.AnyInZoomRange(tpa: TPointArray): Boolean; overload;

Method used to know if a point is within reach of the Zoom rectangle without adjusting the zoom level. Check TRSMinimap.GetZoomRectangle for information on the Zoom rectangle.

Example:

WriteLn Minimap.PointWithinZoom([620, 100]);

Minimap.GetZoomToPoint

function TRSMinimap.GetZoomToPoint(p: TPoint; randomness: Int32 = 0): Int32;

This function gives us a zoom level where P would be visible in the MainScreen.

Example:

p := Minimap.GetDots(ERSMinimapDot.ITEM)[0]; //find an item dot and returns it's coodinates.
Options.SetZoomLevel(Minimap.ZoomToVisiblePoint(p));

Minimap.SetZoomToPoint

function TRSMinimap.SetZoomToPoint(p: TPoint; randomness: Int32 = 0): Boolean;

This function adjusts the zoom level so P TRSMinimap.PointWithinZoom() is true.


Minimap.MakePointVisible

function TRSMinimap.MakePointVisible(p: TPoint): Boolean;
function TRSMinimap.MakePointVisible(tpa: TPointArray): Boolean; overload;

Uses both Minimap.ZoomToPoint() and Minimap.FacePoint() to make a point visible on the Mainscreen.


Mainscreen Extensions

Extend the mainscreen-functionality with MS2MM function


MainScreen.PointToMM() override

function TRSMainScreen.PointToMM(MS: TPoint; Height: Int32=0; Accuracy:Double=0.2): Vector3; override;

Takes a mainscreen point and converts it to a point on the minimap.

Returns a Vector3 which includes input height. Conversion to a TPoint if that’s what you need is simply done by calling .ToPoint on the result.

Example:

WriteLn Mainscreen.PointToMM(Point(250,140), 2);           // as a vector (more accurate)
WriteLn Mainscreen.PointToMM(Point(250,140), 2).ToPoint(); // as a TPoint (lost accuracy)

MainScreen.NormalizeDistance() override

function TRSMainScreen.NormalizeDistance(Dist: Int32; Accuracy: Single = 1.05): Int32; override;

Converts a distance acquired from the *fixed client and default zoom to the current mainscreen.

Example:

// 20 pixels on the fixed client and default zoom(50) is currently x pixels at the current zoom & client size.
WriteLn(MainScreen.TranslateDistance(20));

MainScreen.GetPlayerBox() override

function TRSMainScreen.GetPlayerBox: TBox;

Returns a box surrounding our player. Works at any zoom level.


Minimap.FacePoint

function TRSMinimap.FacePoint(p: TPoint; randomness: Int32 = 0): Boolean;

This method will rotate the camera so that P is within the zoom rectangle without adjusting the zoom level.

Example:

WriteLn Minimap.FacePoint([620, 100]); //keep in mind this example uses a static point, you will probably never do this.

MainScreen.FacePoint

function TRSMainScreen.FacePoint(p: TPoint; randomness: Int32 = 0): Boolean; override;

Rotates the camera to face point p.


Options.SetZoomLevel() override

function TRSOptions.SetZoomLevel(Level: Int32): Boolean; override;

Override to automatically update MM2MS.ZoomLevel.