SRL Archive - SRL Archives

Doorprofile and findsymbols extra's


nielsie95

2007-05-01 05:02:12

Hey,

With SRL 3.7 there came DoorProfiles and a new function called FindSymbols.
Both return TPA's. I made some functions to make things easier :).


ReArrangeTPADistEx –> Arranges your TPA by distance from cx and cy. Usefull for arranging symbols to return the closest point. - Based on Boreas' RearrangeTPA

{*******************************************************************************
function ReArrangeTPADistEx(TheArray: TPointArray; cx, cy: integer Close: Boolean): TPointArray;
By: Nielsie95
Description: Arranges your TPointArray by distance from cx and cy. Set close true
to return the most close first. False for the most far first.
*******************************************************************************}
function ReArrangeTPADistEx(TheArray: TPointArray; cx, cy: integer; Close: Boolean): TPointArray;
var Done: Boolean; ttp: Tpoint; tmpTPA: TpointArray; c: integer;
begin
SetArrayLength(tmpTPA, GetArrayLength(TheArray));
tmpTPA:= TheArray;
if Close then
begin
repeat
done := true;
for c := 0 to (GetArrayLength(TheArray) - 2) do
if Distance(cx, cy, tmpTPA[c].x, tmpTPA[c].y) > Distance(cx, cy, tmpTPA[c + 1].x, tmpTPA[c + 1].y) then
begin
ttp := tmpTPA[c];
tmpTPA[c] := tmpTPA[c + 1];
tmpTPA[c + 1] := ttp;
done := false;
end;
until(done);
SetArrayLength(Result, GetArrayLength(tmpTPA));
Result := tmpTPA;
Exit;
end else
begin
repeat
done := true;
for c := 0 to (getarraylength(thearray) - 2) do
if Distance(cx, cy, tmpTPA[c].x, tmpTPA[c].y) < Distance(cx, cy, tmpTPA[c + 1].x, tmpTPA[c + 1].y) then
begin
ttp := tmpTPA[c];
tmpTPA[c] := tmpTPA[c + 1];
tmpTPA[c + 1] := ttp;
done := false;
end;
until(done);
SetArrayLength(Result, GetArrayLength(tmpTPA));
Result := tmpTPA;
Exit;
end
end;


ReArrangeDoorDistEx –> Arranges Array of DoorProfiles by distance from cx and cy. Usefull for doorfinding. - Based on Boreas' RearrangeTPA

{*******************************************************************************
function ReArrangeDoorDistEx(Doors: Array of DoorProfile; cx, cy: integer; Close: Boolean): Array of DoorProfile;
By: Nielsie95
Description: Arranges your DoorProfiles by distance from cx and cy. Set close
true to return the most close door first. False for the most far first.
*******************************************************************************}
function ReArrangeDoorDistEx(Doors: Array of DoorProfile; cx, cy: integer; Close: Boolean): Array of DoorProfile;
var Done: Boolean; ttp: DoorProfile; tmp: Array of DoorProfile; c: integer;
begin
SetArrayLength(tmp, GetArrayLength(Doors));
tmp := Doors;
if Close then
begin
repeat
done := true;
for c := 0 to (GetArrayLength(Doors) - 2) do
if Distance(cx, cy, tmp[c].MidPoint.x, tmp[c].MidPoint.y) > Distance(cx, cy, tmp[c + 1].MidPoint.x, tmp[c + 1].MidPoint.y) then
begin
ttp := tmp[c];
tmp[c] := tmp[c + 1];
tmp[c + 1] := ttp;
done := false;
end;
until(done);
SetArrayLength(Result, GetArrayLength(tmp));
Result := tmp;
Exit;
end else
begin
repeat
done := true;
for c := 0 to (GetArrayLength(Doors) - 2) do
if Distance(cx, cy, tmp[c].MidPoint.x, tmp[c].MidPoint.y) < Distance(cx, cy, tmp[c + 1].MidPoint.x, tmp[c + 1].MidPoint.y) then
begin
ttp := tmp[c];
tmp[c] := tmp[c + 1];
tmp[c + 1] := ttp;
done := false;
end;
until(done);
SetArrayLength(Result, GetArrayLength(tmp));
Result := tmp;
Exit;
end
end;


ReArrangeDoorDist –> Arranges your array of DoorProfile by distance from the MM-Center.
ReArrangeTPADist –> Arranges your TPA by distance from MM-Center.
ClosestDoor –> Returns the closest door (Needs ReArrangeDoorDist)
ClosestTPA –> Returns the closest TPA (Needs ReArrangeTPA) Usefull for closest symbol finding.

{*******************************************************************************
function ReArrangeDoorDist(Doors: Array of DoorProfile; cx, cy: integer; Close: Boolean): Array of DoorProfile;
By: Nielsie95
Description: Arranges doors by distance from MM-Center
*******************************************************************************}
function ReArrangeDoorDist(Doors: Array of DoorProfile; cx, cy: integer; Close: Boolean): Array of DoorProfile;
begin
Result := ReArrangeDoorDistEx(Doors, MMCX, MMCY, Close);
end;

{*******************************************************************************
function ReArrangeTPADist(TheArray: TPointArray; Close: Boolean): TPointArray;
By: Nielsie95
Description: Arranges TPA by distance from MM-Center
*******************************************************************************}
function ReArrangeTPADist(TheArray: TPointArray; Close: Boolean): TPointArray;
begin
Result := ReArrangeTPADistEx(TheArray, MMCX, MMCY, Close);
end;

{*******************************************************************************
function ClosestDoor(Doors: Array of DoorProfile): DoorProfile;
By: Nielsie95
Description: Returns the closest door in the Array (on MM)
*******************************************************************************}
function ClosestDoor(Doors: Array of DoorProfile): DoorProfile;
var tmp: Array of DoorProfile;
begin
tmp := ReArrangeDoorDistEx(Doors, True);
Result := tmp[0];
end;

{*******************************************************************************
function ClosestTPA(TPoints: TpointArray): TPoint;
By: Nielsie95
Description: Returns the closest TPA in Array (on MM)
*******************************************************************************}
function ClosestTPA(TPoints: TpointArray): TPoint;
var tmp: TPointArray;
begin
tmp := ReArrangeTPADist(TPoints, True);
Result := tmp[0];
end;


LargeDoors –> Returns all small or large doors from the array. Usefull for finding gates or small doors.

{*******************************************************************************
function LargeDoors(Doors: Array of DoorProfile; Large: Boolean): Array of DoorProfile;
By: Nielsie95
Description: Returns the small or large doors in the Array
*******************************************************************************}
function LargeDoors(Doors: Array of DoorProfile; Large: Boolean): Array of DoorProfile;
var c: integer;
begin
for c := 0 to GetArrayLength(Doors) -1 do
begin
if Large then
begin
if Doors[c].PixelCount > 5 then
begin
SetArrayLength(Result, GetArrayLength(Result) +1);
Result[GetArrayLength(Result) -1]:= Doors[c];
end;
end else
begin
if Doors[c].PixelCount < 6 then
begin
SetArrayLength(Result, GetArrayLength(Result) +1);
Result[GetArrayLength(Result) -1]:= Doors[c];
end;
end;
end
end;


DoorDirection –> Returns all vertical or horizontal doors from the array. Usefull for finding specific doors (Check function beneath).

{*******************************************************************************
function DoorDirection(Doors: Array of DoorProfile; Vertical: Boolean): Array of DoorProfile;
By: Nielsie95
Description: Returns all horizontal or vertical doors from the array
*******************************************************************************}
function DoorDirection(Doors: Array of DoorProfile; Vertical: Boolean): Array of DoorProfile;
var c: integer;
begin
if Vertical then
for c := 0 to GetArrayLength(Doors) -1 do
begin
if Doors[c].Slope >= 1 then
begin
SetArrayLength(Result, GetArrayLength(Result) +1);
Result[GetArrayLength(Result) -1]:= Doors[c];
end
end
else
for c := 0 to GetArrayLength(Doors) -1 do
begin
if (Doors[c].Slope < 1) then
begin
SetArrayLength(Result, GetArrayLength(Result) +1);
Result[GetArrayLength(Result) -1]:= Doors[c];
end
end
end;


GetTheseDoors –> Returns Doors which match the needs. Usefull for finding specific doors. (Needs DoorDirection + LargeDoors + ReArrangeDoorDist)

{*******************************************************************************
function GetTheseDoors(SmallDoors, Vertical, Close: Boolean): Array of DoorProfile;
By: Nielsie95
Description: Returns all doors that match the needs (Small or big and Horizontal / Vertical)
and arranges the array by distance from MM-Center.
*******************************************************************************}
function GetTheseDoors(SmallDoors, Vertical, Close: Boolean): Array of DoorProfile;
var Doors, TempDoors: array of DoorProfile;
begin
TempDoors := DoorDirection(GetDoors, Vertical);
Doors := LargeDoors(TempDoors, (not (SmallDoors)));
Result := ReArrangeDoorDist(Doors, Close);
end;

DoorsToTPA –> Converts your array of Doorprofile to a TpointArray. (Request of Boreas)
{*******************************************************************************
function DoorsToTPA(Doors: Array of Doorprofile): TPointArray;
By: Nielsie95
Description: Converts your arrray of DoorProfile to a TPointArray;
*******************************************************************************}
function DoorsToTPA(Doors: Array of Doorprofile): TPointArray;
var i: integer;
begin
SetArrayLength(Result, GetArrayLength(Doors));
for i := 0 to GetArrayLength(Doors) -1 do Result[i]:= Doors[i].MidPoint;
end;


FindHowManyDoors –> Finds the amount of doors you need. Usefull for crowded spots.
{*******************************************************************************
function FindHowManyDoors(var Doors: Array of DoorProfile; HowMany: integer): Boolean;
By: Nielsie95
Description: Repeats untill it finds the number of doors given.
*******************************************************************************}
function FindHowManyDoors(var Doors: Array of DoorProfile; HowMany: integer): Boolean;
var i: integer;
begin
repeat
Doors := GetDoors;
Wait(500);
i := i + 1;
until (GetArrayLength(Doors) = HowMany) or (i > 20);
Result := i <= 20;
end;

FindMinimalDoors –> Finds a minimal amount of doors you need. Usefull for crowded spots.
{*******************************************************************************
function FindMinimalDoors(var Doors: Array of DoorProfile; HowManyMinimal: integer): Boolean;
By: Nielsie95
Description: Repeats untill it finds the minimal number of symbols given.
*******************************************************************************}
function FindMinimalDoors(var Doors: Array of DoorProfile; HowManyMinimal: integer): Boolean;
var i: integer;
begin
repeat
Doors := GetDoors;
Wait(500);
i := i + 1;
until (GetArrayLength(Doors) >= HowManyMinimal) or (i > 20);
Result := i <= 20;
end;

FindHowManySymbols –> Finds the amount of symbols you need. Usefull for crowded spots.
{*******************************************************************************
function FindHowManySymbols(var Tpoints: TPointArray; Name: String; HowMany: integer): Boolean;
By: Nielsie95
Description: Repeats untill it finds the number of symbols given.
*******************************************************************************}
function FindHowManySymbols(var Tpoints: TPointArray; Name: String; HowMany: integer): Boolean;
var i: integer;
begin
repeat
FindSymbols(TPoints, Name);
Wait(50);
i := i + 1;
until (GetArrayLength(TPoints) = HowMany) or (i > 20);
Result := i <= 20;
end;

FindMinimalSymbols –> Finds a minimal amount of symbols you need. Usefull for crowded spots.
{*******************************************************************************
function FindMinimalSymbols(var Tpoints: TPointArray; Name: String; HowManyMinimal: integer): Boolean;
By: Nielsie95
Description: Repeats untill it finds the minimal number of symbols given.
*******************************************************************************}
function FindMinimalSymbols(var Tpoints: TPointArray; Name: String; HowManyMinimal: integer): Boolean;
var i: integer;
begin
repeat
FindSymbols(TPoints, Name);
Wait(50);
i := i + 1;
until (GetArrayLength(TPoints) >= HowManyMinimal) or (i > 20);
Result := i <= 20;
end;


Some examples:


// It will find all TreeSymbols and click on the one that's the most far away.
// Something like this can be used at (Barbarian) fishingspots, (Edge) yews, etc.
var TPoints, TmpTPA: TPointArray; Point: TPoint;
begin
FindHowManySymbols(TPoints, 'special trees', 2);
tmpTPA := ReArrangeTPADist(Tpoints, False);
Mouse(tmpTPA[0].x, tmpTPA[0].y, 4, 4, True);
Flag;
end;


// Stand outside the Lumb Castle and this will click on the first large door (entrance)
var DoorArray: Array of DoorProfiles;
begin
DoorArray := GetTheseDoors(False, True, True);
//This will find all Large, Vertical doors and arranges the array (closest first).
//There are only 2 large, vertical gates, but the closest is first,
// so that has to be the right door =]
Mouse(DoorArray[0].MidPoint.x, DoorArray[0].MidPoint.y, 0, 0);
Flag;
end;


// This will click on the upper watersymbol at Lumbridge castle. It uses the Tutor symbol to define which watersymbol is needed.
var tx, ty: integer; tmpTPoints, TPoints: TpointArray;
begin
if FindSymbol(tx, ty, 'Tutor') then //Finds the TutorSymbol
begin
FindHowManySymbols(tmpTPoints, 'Water', 2); //Finds both watersymbols
TPoints := ReArrangeTPADistEx(tmpTPoints, tx, ty, True); //Arranges the watersymbols by distance from the Tutor.
Mouse(Tpoints[0].x, TPoits[0].y, 3, 3, True); //Clicks on the closest symbol to the tutor.
Flag;
end
end;

I hope these functions will help you to find the doors/symbols you need :).
Tell me what you think of them and how I can improve them. I attached a script so you can test GetTheseDoors :).

Thank you,
Nielsie95

shaunthasheep

2007-05-01 10:10:06

I like the door functions, should come useful to me.. and soon many other ppl.

Boreas

2007-05-02 14:10:21

Good job, I will add to next version.

Also a function that turns an array of doors into an array of tpoints would be nice too.
  MyDoors:=GetDoors;
setarraylength(mytpa,getarraylength(mydoors));
for f:= 0 to getarraylength(MyDoors)-1 do
begin
MyTPA[f]:=MyDoors[f].MidPoint;
end;

If you don't get around to it I'll will :)

nielsie95

2007-05-02 15:10:03

Great :). And do you mean something like this?


function DoorsToTPA(Doors: Array of Doorprofile): TPointArray;
var i: integer;
begin
SetArrayLength(Result, GetArrayLength(Doors));
for i := 0 to GetArrayLength(Doors) -1 do Result[i]:= Doors[i].MidPoint
end;

Can you also tell me if I used Slope right in DoorDirection? :)

Boreas

2007-05-02 15:33:44

Yes.

Almost. 1 is diagonal, 0 is horizontal, and infinity (the highest it can go is 150, so no divide by 0 errors :)) is vertical. Change .5 to 1, and change > to >=, because it is very possible to get a 1.

program New;
{.include SRL/SRL.scar}
var mydoors: array of DoorProfile;
i:integer;
begin
SetupSRL;
mydoors:=getdoors;
for i:=0 to getarraylength(mydoors)-1 do
writeln( floattostr(mydoors[i].slope));
end.


SRL Compiled in 235msec.
1
0
150
0
0
150
Successfully executed

That was from draynor

I had considered building that into GetDoors, with vert/horz string instead of the extended. But I didn't know whether to include diagonal as a category, and if so, where to draw the line.

nielsie95

2007-05-02 15:59:55

Ok, thank you. Added DoorsToTPA and fixed DoorDirection. To get diagonal you can use the colors (I think). Diagonal doors are (always) an other color then the rest (the one at the wheatfield is always 238..)?

XcanadamanX

2007-05-02 20:59:25

very nice! these will come in useful.

Boreas

2007-05-02 22:14:56

From: nielsie95
Ok, thank you. Added DoorsToTPA and fixed DoorDirection. To get diagonal you can use the colors (I think). Diagonal doors are (always) an other color then the rest (the one at the wheatfield is always 238..)?



Diagonal can be the same as the rest. And they won't always have a slope of 1. The diagonal door west of the wheatfield is always 238 AFAIK, but the others can also be 238.