SRL Archive - Reflection Development

OutlineTile and Debug Painting Procedures


mc_teo

2010-06-29 19:06:14

I made this today. Theres a collection procedures for drawing on canvas for debugging purposes.

The main thing I wanted to show is the OutlineTile procedure. You give it a TTile and a TColor, and it will draw a line around that Tile. It would be nice in a mining script to show the next prospective rock.

So feedback/comments please


program ReflectionScript;
{$DEFINE SMART}
{$i srl\srl.scar}
{$i srl\srl\reflection\reflection.simba}

const
{---SMART Setup Constants---}
WORLD = 165;
MEMBERS = false;
SIGNED = true;
{---------------------------}

var
MyPos:TTile;
X, Y: integer;

{*******************************************************************************
procedure CleanTPA(var TPA:TPointArray);
By: mc_teo
Description: Tweaks TPA to remove any Out of Array Bounds errors.
*******************************************************************************}
procedure CleanTPA(var TPA:TPointArray);
var
Len: Integer;
I: Integer;
Bound: TPoint;
begin
Len := Length(TPA);
GetClientDimensions(Bound.X, Bound.Y);
for I := 0 to Len-1 do
begin
if ((TPA[I].X < 0) or (TPA[I].X > Bound.X)) then
TPA[I].X := 0;
if ((TPA[I].Y < 0) or (TPA[I].Y > Bound.Y)) then
TPA[I].Y := 0;
end;
end;

{*******************************************************************************
function DebugTPA(Points: TPointArray; Colour: TColor): Boolean;
By: Narcle (well i got this version from his thread anyways)
Description: Paints the Points on SMART's Debug Canvas (in Colour).
*******************************************************************************}
function DebugTPA(Points: TPointArray; Colour: TColor): Boolean;
var
Bmp: integer;
P: TPoint;
Canvas: TCanvas;
begin
GetClientDimensions(P.x, P.y);
Bmp := BitmapFromString(P.x, P.y,'');
CleanTPA(Points);
DrawTPABitmap(Bmp, Points, Colour);
Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;
DrawBitmap(Bmp, Canvas, 0, 0);
FreeBitmap(Bmp);
Result := True;
end;

{*******************************************************************************
procedure PointToPoint(var bmp: Integer; start, finish: TPoint; colour: TColor);
Bresenham's Line Algorithm (implemented in PS by mc_teo)
Description: Draws a line on given Bmp, from TPoint Start to TPoint Finish.
*******************************************************************************}
procedure PointToPoint(var bmp: Integer; start, finish: TPoint; colour: TColor);
var
steep: boolean;
deltax, deltay, error, ystep: integer;
begin
steep := (iAbs(finish.Y - start.Y) > iAbs(finish.X - start.X));
if steep then
begin
swap(start.X, start.Y);
swap(finish.X, finish.Y);
end;
if start.X > finish.X then
begin
swap(start.X, finish.X);
swap(start.Y, finish.Y);
end;
deltax := (finish.X - start.X);
deltay := iAbs(finish.Y - start.Y);
error := (deltax / 2);
y := start.Y
if (start.Y < finish.Y) then
ystep := 1
else
ystep := -1;
for x := start.X to finish.X do
begin
if steep then
FastSetPixel(bmp, y, x, colour)
else
FastSetPixel(bmp, x, y, colour);
error := error - deltay;
if error < 0 then
begin
y := y + ystep;
error := error + deltax;
end;
end;
end;

{*******************************************************************************
function DebugRectangle(x1, y1, x2, y2: TPoint; colour: TColor): Boolean;
By: caused (adapted for Simba and SMART by mc_teo)
Description: Draws a rectancle on SMART's Debug Canvas, in Colour.
*******************************************************************************}
function DebugRectangle(x1, y1, x2, y2: TPoint; Colour: TColor): Boolean;
var
Bmp: integer;
P: TPoint;
Canvas: TCanvas;
begin
GetClientDimensions(P.x, P.y);
Bmp := BitmapFromString(P.x, P.y,'');

PointToPoint(Bmp, x1, x2, Colour);
PointToPoint(Bmp, x1, y1, Colour);
PointToPoint(Bmp, x2, y2, Colour);
PointToPoint(Bmp, y1, y2, Colour);

Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;

DrawBitmap(Bmp, Canvas, 0, 0);
FreeBitmap(Bmp);
Result := True;
end;

{*******************************************************************************
procedure OutlineTile(T: TTile);
By: caused (adapted for Simba and SMART by mc_teo)
Description: Draws a rectancle on SMART's Debug Canvas, in Colour.
*******************************************************************************}
procedure OutlineTile(T: TTile; Colour: TColor);
var
x1, y1, x2, y2: TPoint;
begin
x1 := TileToMSEx(T, 0, 0, 0);
x2 := TileToMSEx(Tile(T.X+1, T.Y), 0, 0, 0);
y1 := TileToMSEx(Tile(T.X, T.Y+1), 0, 0, 0);
y2 := TileToMSEx(Tile(T.X+1, T.Y+1), 0, 0, 0);

DebugRectangle(x1, y1, x2, y2, Colour);
end;

begin
Smart_Members := MEMBERS;
Smart_Server := WORLD;
Smart_Signed := SIGNED;

SetupSRL;
SetupReflectionEx(true);

MyPos := GetMe().Tile;
OutlineTile(MyPos, clFuchsia);
end.

Feedback/Comments please

Sir R. M8gic1an

2010-06-29 19:54:53

I like!

~RM

lordsaturn

2010-06-29 23:35:50

How about

procedure OutlineTile(T: TTile; Colour: TColor);
var
x1, y1, x2, y2: TPoint;
begin
x1 := TileToMSEx(T, 0.0, 1.0, 0);
y1 := TileToMSEx(T, 1.0, 0.0, 0);
x2 := TileToMSEx(T, 1.0, 1.0, 0);
y2 := TileToMSEx(T, 0.0, 0.0, 0);
DebugRectangle(x1, x2, y2, y1, Colour);
end;

I tried your script and it works nicely. Pretty and well thought out code too. You should keep going and create the full runescape debugger! :)

DeSnob

2010-06-30 11:23:17

Very nice! You sure try one that outlines objects/npcs; that would be awesome! :)