Map

This file is responsible for the TRSMap positioning system. It was made from scratch by Torwent but heavily inspired in the original TRSWalker by Slacky and it’s future iterations made by Olly. Without them, this wouldn’t be possible.


type TRSPosition

TRSPosition = record(TPoint)
  Z: Int32;
  Plane: Int32;
end;

Record holding a player’s full position:

  • X, Y coordinate

  • Z which is the player height on the current heightmap

  • Plane which is the player’s current plane if several planes are being used.


type TRSMap

TRSMap = record
  Walker: TRSWalkerV2;
  Objects: TRSMapObjects;

  RegionIndex: Int32;
  Region: TRSMapRegion;
  Similarity: Double;
  Cache: TMatchTemplateRGBCache;
  Loader: TRSMapLoader;

  IsSetup: Boolean;
end;

Record responsible for positioning.


Map.InternalSetup

procedure TRSMap.InternalSetup();

Internal TRSMap setup method. This is caleld automatically for you and you shouldn’t need to call it.


Map.Setup

procedure TRSMap.Setup(filename: String; downscale: Int32 = 8);
procedure TRSMap.SetupRegions(filename: String; regions: TBoxArray; downscale: Int32 = 8);
procedure TRSMap.SetupRegion(filename: String; region: TBox; downscale: Int32 = 8);
procedure TRSMap.SetupFromURL(url: String; filename: String = ''; downscale: Int32 = 8; force: Boolean = False);
procedure TRSMap.SetupChunksEx(chunks: TBoxArray; levels: TIntegerArray = [0]; downscale: UInt32 = 8);
procedure TRSMap.SetupChunkEx(chunk: TBox; levels: TIntegerArray = [0]; downscale: UInt32 = 8);
procedure TRSMap.SetupChunks(chunks: array of TRSMapChunk; downscale: UInt32 = 8);
procedure TRSMap.SetupChunk(chunk: TRSMapChunk; downscale: UInt32 = 8);
procedure TRSMap.SetupChunks(chunks: array of ERSChunk; downscale: UInt32 = 8); overload;
procedure TRSMap.SetupChunk(chunk: ERSChunk; downscale: UInt32 = 8); overload;

Setup a TRSMap. If for some reason you can’t setup all your maps at once, you can later use the Add methods. This however is not recommended if you can avoid it, read more about it there.

Methods with the “Chunk” keyword are the recommended ones to use. If for some reason you need a custom map, use any of the other methods.

With the “Chunk” methods you are able to setup multiple levels from 0 to 3.


Map.Add

procedure TRSMap.Add(filename: String; downscale: Int32 = 8);
procedure TRSMap.AddRegions(filename: String; regions: TBoxArray; downscale: Int32 = 8);
procedure TRSMap.AddRegion(filename: String; region: TBox; downscale: Int32 = 8);
procedure TRSMap.AddFromURL(url: String; filename: String = ''; downscale: Int32 = 8; force: Boolean = False);
procedure TRSMap.AddChunksEx(chunks: TBoxArray; levels: TIntegerArray = [0]; downscale: UInt32 = 8);
procedure TRSMap.AddChunkEx(chunk: TBox; levels: TIntegerArray = [0]; downscale: UInt32 = 8);
procedure TRSMap.AddChunks(chunks: array of TRSMapChunk; downscale: UInt32 = 8);
procedure TRSMap.AddChunk(chunk: TRSMapChunk; downscale: UInt32 = 8);
procedure TRSMap.AddChunks(chunks: array of ERSChunk; downscale: UInt32 = 8); overload;
procedure TRSMap.AddChunk(chunk: ERSChunk; downscale: UInt32 = 8); overload;

TRSMap to add maps to an already setup TRSMap. If it’s possible to add all your maps during setup, avoid using this, because this has to repeat several slow step the setup methods already take.

Methods with the “Chunk” keyword are the recommended ones to use. If for some reason you need a custom map, use any of the other methods.

With the “Chunk” methods you are able to setup multiple levels from 0 to 3.


Map.ScaledSearch

function TRSMap.ScaledSearch(bitmap: TMufasaBitmap; samples: Int32): TPointArray;

Internal TRSMap method used to get an initial TPointArray of possible positions. This is performed in a downscaled map with a downscaled minimap. This is very innacurate by itself but by ruling down most of the map in a downscaled search before doing a full sized search speed has a dramatic boost. You probably won’t ever need to call this directly.


Map.FullSearch

function TRSMap.FullSearch(template, world: TMufasaBitmap; position: TPoint; out match: Single): TPoint;

Internal TRSMap method used to get the player position. This is used by TRSMap.Position() to determine how likely is the Position passed in, our actual position. This likelyhood is returned with Match which ranges from 0 to 1. You probably won’t ever need to call this directly.


Map.Position

function TRSMap.Position(): TPoint;
function TRSMap.FullPosition(): TRSPosition;

Returns the players current position on the loaded map. TRSMap.FullPosition() also returns the current Z level.

Example:

WriteLn(Map.Position());
WriteLn(Map.Similarity); // Check to see the match percentage if needed

Map.Height

function TRSMap.Height(p: TPoint = [-1,-1]; global: Boolean): Single;
function TRSMap.Height(p: TPoint = [-1,-1]): Single; overload;

Returns the height of the player at the specified coordinate if there’s a heightmap loaded. If p is [-1,-1], which is the default then we will use our current position. global decides wether the coordinate is converted to global coordinates or internal walker coordinates (read about walker regions for more info).

Example:

WriteLn rsw.GetHeight();

TRSMap.InRange

function TRSMap.InRange(p: TPoint; distance: Int32 = 4): Boolean;
function TRSMap.InRange(tpa: TPointArray; distance: Int32 = 4): Boolean; overload;

Method used to quickly check if we are within distance of a certain point or points. This distance is measure in pixels and in a radial way.


Map.Map2MM

function TRSMap.Map2MM(playerPoint, mapPoint: TPoint; radians: Double): TPoint;
function TRSMap.Map2MM(mapPoint: TPoint): TPoint; overload;

Converts a map coordinate to a point on the minimap.

Example:

var
  p: TPoint;
  bitmap: TMufasaBitmap;
begin
  Map.SetupChunk([49,54,49,54], [0, 1]); //Make sure you are in GE for this example.
  p := Map.Map2MM([4620, 2100]);         //This is just a random point in the ge with SRL map.

  bitmap.FromClient();
  bitmap.DrawCross(p, 4, $FFFFFF);
  bitmap.Free();
end;

TRSMap.MM2Map

function TRSMap.MM2Map(playerPoint, minimapPoint: TPoint; radians: Single = $FFFF): TPoint;
function TRSMap.MM2Map(minimapPoint: TPoint; radians: Single = $FFFF): TPoint;

Converts a point on the minimap to a map coordinate.


TRSMap.MS2Map

function TRSMap.MS2Map(playerPoint, minimapPoint: TPoint; height: Int32 = 0; accuracy: Double = 0.2): TPoint;
function TRSMap.MS2Map(minimapPoint: TPoint; height: Int32=0; accuracy:Double=0.2): TPoint; overload;

Converts a point on the mainscreen to a map coordinate.


TRSMap.GetTileMS

function TRSMap.GetTileMS(playerPoint, mapPoint: TPoint; height: Double = 0; offset: Vector2 = [0,0]): TRectangle;
function TRSMap.GetTileMS(mapPoint: TPoint; height,  offset: Vector2 = [0,0]): TRectangle; overload;

Returns a tile on the mainscreen with the help of TRSMap and MM2MS.

Example:

Debug(Map.GetTileMS(Map.Position() + [10, 10]));

Map.DebugPosition

function TRSMap.DebugPosition(): TPoint;

Debugs the player position in the currently loaded map.

Example:

Map.Setup();
while True do
  Map.DebugPosition();

TRSMap.Debug

procedure TRSMap.Debug(map: ERSMapType = ERSMapType.NORMAL; graph: Boolean = False);

Displays one of the maps loaded. You can optionally overlay the webgraph on top of you map.

Example:

Map.SetupChunks([[18,56,22,60], [42,50, 46, 45]], [0, 1]);
Map.Debug(ERSMapType.HEIGHT);

var Map

Global TRSMap variable