SRL Archive - News and General

DTM library


mat_de_b

2007-09-24 14:46:26

Having read the page about SRL 4 and SVN i felt encouragged to make a DTM library hence the library :D spurred on by Pwnazor's code on making a dtm i will create something like this to automatically make DTMs of the items in your bank… this can then be added to a Database which can be updated via SVN?

Propsed Functions:
Automatically Finds + Names DTM (From Uptext)
Checks DTM Works
Saves DTM to a file if a file under that name doesnt exist

Would Need Help On:
It would be better however if there was a master file on the net that people uploaded thier thing to or like a folder etc… so there is a master copy however i am not entirely sure how to do this and would be looking for help.

itSchRis917

2007-09-24 19:01:27

ooo this sounds like a fun project. :) i might start on this. :)

mat_de_b

2007-09-25 11:59:40

Im already doing the dtm creator bit

itSchRis917

2007-09-25 16:16:30

Cool. i would love to share this project with you. Do you need any help?

pwnaz0r

2007-09-25 16:43:29

Hah my function :D. Anyways, glad to see its being put to use :D. You might want to team up with MSI on this b/c they are looking to make on of these (i think).

Hugolord

2007-09-25 16:45:37

From: pwnaz0r
Hah my function :D. Anyways, glad to see its being put to use :D. You might want to team up with MSI on this b/c they are looking to make on of these (i think).


sme ppl which i cant mention were doing this already ive seen their rough code its very tricky =/

Dan Cardin

2007-09-25 16:47:29

sounds like a good idea :) just the sending and recieving would be bad, cuz u might get more than 1 of each dtm

mat_de_b

2007-09-25 16:51:00

hence i said a check name :D the codes not too bad… ive written the DTM creater and its looking alright only struggling with odd looking items such as Pickaxes which cant be broken down into 4 corners but with a bit of effor that is easily sussed

Boreas

2007-09-25 17:28:02

By pwnaz0r, Sky Scripter, and me:

program New;
{.include srl/srl.scar}






type

BlackList = array of integer;

type
BlackListNet = array of Tpoint;

{*******************************************************************************
function CreateCustomNet(Num:integer):TPointArray;
By: Boreas
Note: Purely an internal function, used in setup.
Description: Returns a TPointArray containing the relative (to x1,y1 of a BSlot)
for a custom amount of points. Only needs to be done once, to create
the list of points to check for 65536. Only takes like 15ms, and I didn't
feel like typing them all out.
Num=1 will check every point
Num=2 will make a net with 1x1 holes
Num=4 will make a net with 3x3 holes
*******************************************************************************}
function CreateCustomNet(Num:integer):BlackListNet;
var Counter,hx,hy,tAL:integer;
var TPointsToCheck:array of TPoint;
begin
repeat
hy:=9;
hx:=hx+1;
repeat
hy:=hy+1;
if (((hx mod Num)=0) or ((hy mod Num)=0)) then
begin
tAL:=tAL+1;
setarraylength(TPointsToCheck,tAL);
TPointsToCheck[Counter].x:=hx;
TPointsToCheck[Counter].y:=hy;
Counter:=Counter+1;
end;
until hy=31;
until hx=31;
result:=TPointsToCheck;
end;

{*******************************************************************************
function CreateItemBlackList(WhichBankSlot:integer;WhichList:TPointArray):array of integer;
By: Boreas
Description: Looks at the points in the list for an item, and returns an array
contatining the indexes of the points that are black.
Usage: WhichBankSlot-just what it sounds like. WhichList-the TPointArray
containing positions relative to the x1,y1 of a bankslot which you want to check
*******************************************************************************}

function CreateItemBlackListBox(WhichBox:tbox;WhichList:TPointArray):array of integer;
var Counter,Counter2,Tmpx1,Tmpy1,ListLength:integer;
var TmpArray:array of integer;
begin
tmpx1:=whichbox.x1;
tmpy1:=whichbox.y1;


ListLength:=getarraylength(WhichList)-1;
setarraylength(tmparray,1);
for Counter:= 0 to ListLength do
begin

if GetColor(Tmpx1+WhichList[Counter].x,Tmpy1+WhichList[Counter].y)=65536 then
begin
TmpArray[Counter2]:=Counter;
Counter2:=Counter2+1;
setarraylength(TmpArray,Counter2+1);

end;
end;
setarraylength(TmpArray,Counter2-1);
result:=TmpArray;
end;





{*******************************************************************************
function CompareIntArrays(FirstIntArray,SecondIntArray:array of integer):boolean;
By: Boreas
Description: Returns true both arrays are the same
******************************************************************************}
function CompareIntArrays(FirstIntArray,SecondIntArray:array of integer):boolean;
var Counter:integer;
begin
if not(getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
result:=false;


if (getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
begin
result:=true;
repeat
if not(FirstIntArray[Counter]=SecondIntArray[Counter]) then
result:=false;
Counter:=Counter+1;
until ((Counter=getarraylength(FirstIntArray)) or (result=false));
end;
end;



type
TInvenItem = record
Width, Height : Integer; // the width and height of the item
Count : Integer; // the count of the item
ItemBox : TBox; // the exact box around the item
CenterItem : TPoint; // the center point inside the item
ExistsItem : Boolean; // to define the item Exists
end;


function GetInven(Box:tbox) : TInvenItem;
var
I, Cx, Cy: Integer;
P : TPointArray;
MinP, MaxP : TPoint;
begin
FindColorsTolerance(P, 65536, Box.x1+9, Box.y1+9, Box.x1 + 31, Box.y1 + 31, 0);
Result.Count := Length(P);
if (Result.Count = 0) then Exit;
Result.ExistsItem := True;
MinP := P[0];
MaxP := P[Result.Count-1];
Cx := P[0].x + P[Result.Count-1].x;
Cy := P[0].y + P[Result.Count-1].y;
for I := 1 to Result.Count - 2 do
begin
if (P[i].x < MinP.x) then MinP.x := P[i].x;
if (P[i].y < MinP.y) then MinP.y := P[i].y;
if (P[i].x > MaxP.x) then MaxP.x := P[i].x;
if (P[i].y > MaxP.y) then MaxP.y := P[i].y;
Cx := Cx + P[i].x;
Cy := Cy + P[i].y;
end;
Cx := Cx / Result.Count;
Cy := Cy / Result.Count;
Result.CenterItem := Point(Cx, Cy);
Result.Width := MaxP.x - MinP.x;
Result.Height := MaxP.y - MinP.y;
Result.ItemBox := PointToBox(MinP, MaxP);
end;

type
boolint = record
bool: boolean;
int: integer;
end;

function GetBarDistance: integer; // Will return -1 if false
var
dist: integer;
begin
if not GetColor(476, 74) = 2436403 then
begin
result:= -1;
exit;
end else
begin
for dist:= 1 to 175 do
begin
if GetColor(477, 74 + dist) = 5531254 then
begin
result:= dist;
exit;
end;
end;
end;
result:= -1;
end;

function CreateDifference: boolint; // return difference ratio
var
dis: integer;
begin
dis:= GetBarDistance;
result.int := Round((dis - 1) * 9.6);
result.bool := Result.int > 0;
end;

function HandleScreenShift(i: integer): integer;
var
tmpx,tmpy,t: integer;
begin
result:= i;
if getcolor(475,75) = 5531254 then
exit;
try
findcolor(tmpx, tmpy, 65535, 73, i-15, 443, i+15);
result:=tmpy;
except
FixBank;
wait(600);
try
findcolor(tmpx, tmpy, 65535, 73, i-15, 443, i+15);
result:=tmpy;
except
Writeln('Error');
exit;
end;
end;
end;

function BankBox(i :Integer): TBox;
var
row, col: Integer;
tmp: boolint;
begin
col := i mod 8; if col = 0 then col:= 8; // Columns are Vertical
row := i / 8; if i mod 8 <> 0 then Inc(row); // Rows are Horizontal
Result.x1 := 32 + (col * 47);
tmp:= CreateDifference;
if tmp.bool then
begin
Result.y1 := 24 + (row * 38) - tmp.int;
Result.y1 := HandleScreenShift(Result.y1);
end else Result.y1 := 24 + (row * 38);
Result.x2 := Result.x1 + 31;
Result.y2 := Result.y1 + 31;
end;

function BoxVisible(i: integer): Boolean;
var
TheBankBox: TBox;
begin
TheBankBox:= BankBox(i);
//Writeln(IntToStr(TheBankBox.y1));
if (TheBankBox.y1 >= 62) and (TheBankBox.y1 <= 254) then result:= True;
end;

function ResetForBox(i: integer): boolean;
var
BoxMark, bx, by: integer;
begin
FixBank;
If BoxVisible(i) then
begin
result:= true;
exit;
end;
HoldMouse(475 + random(6) - random(6), 281 + random(6) - random(6), true);
GetMousePos(bx, by);
MarkTime(BoxMark);
repeat
begin
Wait(1);
If TimeFromMark(BoxMark) >= 20000 then
begin
result:= false;
ReleaseMouse(bx, by, true);
exit;
end;
end;
until(BoxVisible(i));
ReleaseMouse(bx, by, true);
result:= true;
end;

function MakeBoxVisible(i: integer): boolean;
var
TheBankBox: TBox;
begin
if not BoxVisible(i) then
begin
// WriteLn('Bank box not visible');
ResetForBox(i);
end;
end;

function BoxVisibleFirstRow(i: integer): Boolean;
var
TheBankBox: TBox;
begin
TheBankBox:= BankBox(i);
//Writeln(IntToStr(TheBankBox.y1));
if (TheBankBox.y1 >= 62) and (TheBankBox.y1 <= 64) then result:= True;
end;

function ResetForBoxFirstRow(i: integer): boolean;
var
BoxMark, bx, by: integer;
begin
FixBank;
If BoxVisibleFirstRow(i) then
begin
result:= true;
exit;
end;
HoldMouse(475 + random(6) - random(6), 281 + random(6) - random(6), true);
GetMousePos(bx, by);
MarkTime(BoxMark);
repeat
begin
Wait(1);
If TimeFromMark(BoxMark) >= 20000 then
begin
result:= false;
ReleaseMouse(bx, by, true);
exit;
end;
end;
until(BoxVisibleFirstRow(i));
ReleaseMouse(bx, by, true);
result:= true;
end;

function MakeBoxVisibleFirstRow(i: integer): boolean;
var
TheBankBox: TBox;
begin
if not BoxVisibleFirstRow(i) then
begin
// WriteLn('Bank box not visible');
ResetForBoxFirstRow(i);
end;
end;




function MakeMiddlePoint(i: integer): TPoint;
var
TheBankBox: TBox;
begin
TheBankBox:= BankBox(i);
result.x:= ((TheBankBox.x2 - TheBankBox.x1) / 2) + TheBankBox.x1;
result.y:= ((TheBankBox.y2 - TheBankBox.y1) / 2) + TheBankBox.y1;
end;

procedure MMouseSlot(i: integer);
var
Mid: Tpoint;
TheBankBox: TBox;
begin
MakeBoxVisible(i);
TheBankBox:= BankBox(i);
MMouse(TheBankBox.x1 + 2 + random(27), TheBankBox.y1 + 2 + random(27), 0, 0);
end;

procedure MouseSlot(i: integer; left: boolean);
var
bx, by: integer;
begin
MMouseSlot(i);
GetMousePos(bx, by);
Mouse(bx, by, 0, 0, left);
end;

function ChooseOptionSlot(i: integer; s: string): boolean;
begin
MouseSlot(i, false);
wait(400);
result:= ChooseOption(s);
end;

function ItemExistsSlot(i: integer): boolean;
var
rx, ry: integer;
TheBankBox: TBox;
begin
MakeBoxVisible(i);
TheBankBox:= BankBox(i);
result:= FindColor(rx, ry, 65536, TheBankBox.x1, TheBankBox.y1, TheBankBox.x2, TheBankBox.y2);
end;
{*******************************************************************************
function intArrayToStrEx(intArray : Array of Integer; Separater : String) : String;
By: moparisthebest and modified by Ron
Description: Loads an array of integer into a String. (Example String: '567 389 3234 98342 7998767')
*******************************************************************************}

function intArrayToStrEx(intArray : Array of Integer; Separater : String) : String;
var
i, arrayLength: Integer;
begin
arrayLength := GetArrayLength(intArray);
repeat
Result := Result + IntToStr(intArray[i]);
if (not(i = (arrayLength - 1))) then
Result := Result + Separater;
i := i + 1;
until (i = arrayLength)
end;

{*******************************************************************************
function intArrayToStr(intArray : Array of Integer) : String;
By: moparisthebest and modified by Ron
Description: Refer to intArrayToStrEx.
*******************************************************************************}

function intArrayToStr(intArray : Array of Integer) : String;
begin
Result := intArrayToStrEx(intArray, ' ');
end;
type ItemCat=record
Itemtype:TinvenItem;
BL:blacklist;
Slots:array of integer;
end;

procedure AddToIntArray(var IntArr:array of integer; Num:integer);
var AL:integer;
begin
AL:=getarraylength(INtArr);
setarraylength(IntArr,AL+1);
IntArr[AL]:=Num;
end;

var Items:array of ItemCat;
//var Items: array of TInvenItem;
i,i2,i3,t:integer;
tmpitem: Tinvenitem;
mynet: BlackListNet;
tmpbl:blacklist;
begin
setupsrl;
setarraylength(Items,1);
Items[0].ItemType:= GetInven(BankBox(1));
AddToIntArray(Items[0].slots,1);
for i:=2 to 48 do
begin
tmpitem:= GetInven(BankBox(i));
i2:=0;
repeat
if (tmpitem.height=Items[i2].ItemType.height) and
(tmpitem.width=Items[i2].ItemType.width)and
(tmpitem.count=Items[i2].ItemType.count)
then
begin
AddToIntArray(Items[i2].slots,i);
break;
end;
i2:=i2+1;
until i2=getarraylength(Items);
if i2=getarraylength(Items) then
begin
setarraylength(Items,i2+1);
Items[i2].Itemtype:= tmpitem;
AddToIntArray(Items[i2].slots,i);
end;
end;


for i3:=0 to getarraylength(items)-1 do
writeln(intArrayToStr(Items[i3].slots));




mynet:=CreateCustomNet(2);

setarraylength(Items,1);
Items[0].BL:= CreateItemBlackListBox(BankBox(1),mynet);
AddToIntArray(Items[0].slots,1);
for i:=2 to 48 do
begin
tmpbl:= CreateItemBlackListBox(BankBox(i),mynet);
i2:=0;
repeat
if CompareIntArrays(tmpbl,Items[i2].bl)
then
begin
AddToIntArray(Items[i2].slots,i);
break;
end;
i2:=i2+1;
until i2=getarraylength(Items);
if i2=getarraylength(Items) then
begin
setarraylength(Items,i2+1);
Items[i2].BL:= tmpbl;
AddToIntArray(Items[i2].slots,i);
end;
end;



for i3:=0 to getarraylength(items)-1 do
writeln(intArrayToStr(Items[i3].slots));

{setarraylength(items,49);
for i:=1 to 48 do
begin
Items[i]:= GetInven(BankBox(i));
//writeln(inttostr(i)+': '+inttostr(items[i].width)+' '+inttostr(items[i].height)+' '+inttostr(items[i].count));
end;}
end.

mat_de_b

2007-09-25 17:33:09

Not entirely sure what the net bit is? But is that a function to determine bank slots? or to create ways of recognizing items?

On a Re-Read this does exactly what i was trying to do doesnt it?

R0b0t1

2007-09-25 21:27:20

Most people never really know what Boreas' code does. After all, he exists in neverland (or outside of time and space, but methinks thats BenLand).



I personally find my home between the nebular rifts :). (Or in any of the different places I appear… In you're computer FTW!)

Boreas

2007-09-25 22:14:40

The net controls how much detail is in the BlackList, because BlackLists only look at some of the black pixels in an item. Yes in there is a function to determine bankslots coords, and not just the first 48, all of them. Also in there is something in Inventory.scar SRL 4, TIvenItem, which is another way of looking at the black pixels in an item.

The output is a bunch of rows of numbers, with some rows having more than one. The numbers refer to bankslots, and if you look at a row with multiple numbers, and then look at the slots for those numbers, you will see they have the same black outline.

mat_de_b

2007-09-26 02:10:54

I got that, but this is a method for finding items just like mine is isnt it? you use the black list to find the item? and so is it worth me continuing?

Boreas

2007-09-26 11:08:09

This only finds the black outline. It doesn't distinguish a steel bar from a gold bar.

mat_de_b

2007-09-26 18:40:34

Edit: Rewrote the point finding part - It will pick the top,bottom,left and right point and then will choose a bunch of random points, this results in about 20 points being chosen, which ive been told is good, but im wondering if that is tooo many… here are some examples of the things it finds

Green Cross/Big Dot := shows the main point that will be reutrned as x and y
Green dots - Potential largest points (i.e furthest left)
Red Dots - Black colour found - nothing done
Yellow Dots - Black colour found and added as a rnadom point (there are more of these then shown becuase they get covered by green dots :'( )







As you can see it almost always gets the MP right in the center of the item and is even able to deal with odd shaped items such as Pickaxes

Boreas

2007-09-27 00:01:54

Here's the ultimate test:
Make one of a oak longbow (u) in the first slot, with an oak longbow (s) in the first bank slot, and try to find the unstrung