SRL Archive - SRL Archives

TPA Library


Sir R. M8gic1an

2008-12-08 11:13:14

hey guys, this is an idea i had like 6 months ago, and actually started using.

just like we have (had?) a bitmap library i thought of making a TPA library. they're more accurate than DTMs, they're faster (a few ms do count!) and they're easier to make.

here's how i did it:

program New;
{.include srl/srl.scar}
procedure WriteTPALn(slot:integer);
var
TPA:TPointArray;
TB: Tbox;
i:integer;
begin
TB := InvBox(slot);
FindColorsTolerance(TPA, 65536, TB.x1, TB.y1, TB.x2, TB.y2, 0);

for i:=0 to High(TPA) do
writeln('TPA['+IntToStr(i)+'].X := '+IntToStr(TPA[i].x)+'; TPA['+IntToStr(i)+'].Y := '+IntToStr(TPA[i].y)+';');

end;


begin
writeTPAln(2);
end.

in the end they might look a bit messy, but i'm sure we can overcome that.

this is how one of mine ended up looking:

//declaring a TPA, using it instead of bmp/dtm, faster.
TPA_Item[0].X := 625; TPA_Item[0].Y := 217;TPA_Item[1].X := 626; TPA_Item[1].Y := 217;TPA_Item[2].X := 627; TPA_Item[2].Y := 217;TPA_Item[3].X := 628; TPA_Item[3].Y := 217;TPA_Item[4].X := 629; TPA_Item[4].Y := 217;TPA_Item[5].X := 623; TPA_Item[5].Y := 218;TPA_Item[6].X := 624; TPA_Item[6].Y := 218;TPA_Item[7].X := 630; TPA_Item[7].Y := 218;TPA_Item[8].X := 622; TPA_Item[8].Y := 219;TPA_Item[9].X := 630; TPA_Item[9].Y := 219;
TPA_Item[10].X := 611; TPA_Item[10].Y := 220;TPA_Item[11].X := 612; TPA_Item[11].Y := 220;TPA_Item[12].X := 613; TPA_Item[12].Y := 220;TPA_Item[13].X := 614; TPA_Item[13].Y := 220;TPA_Item[14].X := 615; TPA_Item[14].Y := 220;TPA_Item[15].X := 616; TPA_Item[15].Y := 220;TPA_Item[16].X := 617; TPA_Item[16].Y := 220;TPA_Item[17].X := 618; TPA_Item[17].Y := 220;TPA_Item[18].X := 619; TPA_Item[18].Y := 220;TPA_Item[19].X := 620; TPA_Item[19].Y := 220;
TPA_Item[20].X := 621; TPA_Item[20].Y := 220;TPA_Item[21].X := 630; TPA_Item[21].Y := 220;TPA_Item[22].X := 610; TPA_Item[22].Y := 221;TPA_Item[23].X := 630; TPA_Item[23].Y := 221;TPA_Item[24].X := 609; TPA_Item[24].Y := 222;TPA_Item[25].X := 631; TPA_Item[25].Y := 222;TPA_Item[26].X := 609; TPA_Item[26].Y := 223;TPA_Item[27].X := 631; TPA_Item[27].Y := 223;TPA_Item[28].X := 609; TPA_Item[28].Y := 224;TPA_Item[29].X := 630; TPA_Item[29].Y := 224;
TPA_Item[30].X := 609; TPA_Item[30].Y := 225;TPA_Item[31].X := 630; TPA_Item[31].Y := 225;TPA_Item[32].X := 609; TPA_Item[32].Y := 226;TPA_Item[33].X := 630; TPA_Item[33].Y := 226;TPA_Item[34].X := 631; TPA_Item[34].Y := 226;TPA_Item[35].X := 607; TPA_Item[35].Y := 227;TPA_Item[36].X := 608; TPA_Item[36].Y := 227;TPA_Item[37].X := 609; TPA_Item[37].Y := 227;TPA_Item[38].X := 632; TPA_Item[38].Y := 227;TPA_Item[39].X := 606; TPA_Item[39].Y := 228;
TPA_Item[40].X := 633; TPA_Item[40].Y := 228;TPA_Item[41].X := 634; TPA_Item[41].Y := 228;TPA_Item[42].X := 605; TPA_Item[42].Y := 229;TPA_Item[43].X := 635; TPA_Item[43].Y := 229;TPA_Item[44].X := 605; TPA_Item[44].Y := 230;TPA_Item[45].X := 635; TPA_Item[45].Y := 230;TPA_Item[46].X := 605; TPA_Item[46].Y := 231;TPA_Item[47].X := 635; TPA_Item[47].Y := 231;TPA_Item[48].X := 605; TPA_Item[48].Y := 232;TPA_Item[49].X := 635; TPA_Item[49].Y := 232;
TPA_Item[50].X := 605; TPA_Item[50].Y := 233;TPA_Item[51].X := 635; TPA_Item[51].Y := 233;TPA_Item[52].X := 605; TPA_Item[52].Y := 234;TPA_Item[53].X := 634; TPA_Item[53].Y := 234;TPA_Item[54].X := 605; TPA_Item[54].Y := 235;TPA_Item[55].X := 634; TPA_Item[55].Y := 235;TPA_Item[56].X := 606; TPA_Item[56].Y := 236;TPA_Item[57].X := 629; TPA_Item[57].Y := 236;TPA_Item[58].X := 630; TPA_Item[58].Y := 236;TPA_Item[59].X := 631; TPA_Item[59].Y := 236;
TPA_Item[60].X := 632; TPA_Item[60].Y := 236;TPA_Item[61].X := 633; TPA_Item[61].Y := 236;TPA_Item[62].X := 607; TPA_Item[62].Y := 237;TPA_Item[63].X := 608; TPA_Item[63].Y := 237;TPA_Item[64].X := 609; TPA_Item[64].Y := 237;TPA_Item[65].X := 610; TPA_Item[65].Y := 237;TPA_Item[66].X := 611; TPA_Item[66].Y := 237;TPA_Item[67].X := 625; TPA_Item[67].Y := 237;TPA_Item[68].X := 626; TPA_Item[68].Y := 237;TPA_Item[69].X := 627; TPA_Item[69].Y := 237;
TPA_Item[70].X := 628; TPA_Item[70].Y := 237;TPA_Item[71].X := 611; TPA_Item[71].Y := 238; TPA_Item[72].X := 622; TPA_Item[72].Y := 238; TPA_Item[73].X := 623; TPA_Item[73].Y := 238; TPA_Item[74].X := 624; TPA_Item[74].Y := 238; TPA_Item[75].X := 612; TPA_Item[75].Y := 239; TPA_Item[76].X := 619; TPA_Item[76].Y := 239; TPA_Item[77].X := 620; TPA_Item[77].Y := 239; TPA_Item[78].X := 621; TPA_Item[78].Y := 239; TPA_Item[79].X := 613; TPA_Item[79].Y := 240;
TPA_Item[80].X := 617; TPA_Item[80].Y := 240; TPA_Item[81].X := 618; TPA_Item[81].Y := 240; TPA_Item[82].X := 614; TPA_Item[82].Y := 241; TPA_Item[83].X := 615; TPA_Item[83].Y := 241; TPA_Item[84].X := 616; TPA_Item[84].Y := 241;

do notice it uses 84 points, when a dtm would use about 5, and it still finds it faster :p

~Rasta

Freddy1990

2008-12-08 13:56:07

From: Rasta Magician
a few ms do count!


Been trying to bring across that point for ages, but no one usually believes it :p
Good idea though

Dan Cardin

2008-12-08 14:12:39

the only problem is that (as far as i know) none of the previous library attempts have actually continued to be updated and used. Its just easier to make them yourself, than constantly update a library

Sir R. M8gic1an

2008-12-08 14:44:59

i used that bitmap library often and saw quite a few updates!
and a TPA library won't change as often as the BMP, as a color change won't actually affect us. Plus, updating this one is very fast and everyone is qualified enough to do it ;)

~Rasta

Magiic

2008-12-08 15:37:37

yeah tbh it wouldn't be much of a bother, it'd just take a while getting the points in the first place.
edit:i mean it'd take a while depending on how many items we did

Boreas

2008-12-09 23:50:54

I've been debating about this for about 2 years. Now, with the GE and bank tabs, it appears that the best solution is a database that can build itself. With an INI, it can be updated by functions such as MouseItem, WithdrawItem etc during runtime. The black outline needs only a one time update, but the color data will get more accurate over time (still working on that part).

program New;
{.include Srl\SRL.scar}
var
UIDB_Net: TPointArray;

procedure UIDB_LoadNet;
var tmpcount,hx,hy:integer;
begin
SetArrayLength(UIDB_Net,506);
repeat
hy:=9;
hx:=hx+1;
repeat
hy:=hy+1;
if (((hx mod 2)=0) or ((hy mod 2)=0)) then
begin
UIDB_Net[tmpcount]:=Point(hx,hy);
Inc(tmpcount);
end;
until hy=31;
until hx=31;
end;



Function InvBox2(i :Integer): TBox;
begin
if (i < 1) or (i > 28) then
begin
srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
exit;
end;
{1 x1 563 y1 213 x2 594 y2 244}
{5 x1 605 y1 249}
Result.x1 :=563+((((i+3)mod 4))*(605-563));
Result.y1 :=213+((((i-1)/4))*(249-213));
Result.x2 := Result.x1+31;
Result.y2 := Result.y1+31;
end;

{*******************************************************************************
function strToIntArrayEx(intArray, Separater : String) : Array of Integer;
By: moparisthebest and modified by Ron
Description: Loads a String into an array of integer. (Example String: '567 389 3234 98342 7998767')
*******************************************************************************}

function strToIntArrayEx(intArray, Separater : String) : Array of Integer;
var
i, spacePos: Integer;
begin
repeat
SetArrayLength(Result, i + 1);
spacePos := Pos(Separater, intArray);
if (not (spacePos = 0)) then
Result[i] := StrToInt(Copy(intArray, 1, spacePos - 1))
else
begin
Result[i] := StrToInt(Copy(intArray, 1, Length(intArray)));
break;
end;
Delete(intArray, 1, spacePos);
i := i + 1;
until (False)
end;

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

function strToIntArray(intArray : String) : Array of Integer;
begin
Result := strToIntArrayEx(intArray, ' ');
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;







function CreateBL(Area:string; Slot:integer): TIntegerArray;
var SlotBox:TBox;
i,tmpAL:integer;
begin
case lowercase(Area) of
'inv': SlotBox:= InvBox2(Slot);
'bank': SlotBox:= BankIndexToMSBox(Slot);
end;
tmpAL:=1;
SetArrayLength(result,tmpAL+1);
for i:=0 to 505 do
begin
if getcolor(UIDB_Net[i].x+SlotBox.x1,UIDB_Net[i].y+SlotBox.y1)=65536 then
begin
result[tmpAL]:=i;
Inc(tmpAL);
SetArrayLength(result,tmpAL+1);
end;
end;
SetArrayLength(result,tmpAL);
result[0]:=tmpAL-1;
end;

function CompareBL(First,Second:TIntegerArray):boolean;
var i:integer;
begin
if First[0]<> Second[0] then exit;
for i:=1 to First[0] do
begin
if First[i] <> Second[i] then exit;
end;
result:=true;
end;


var c,t,MyBMP:integer;
MyBL:TIntegerArray;
begin
UIDB_LoadNet;

MyBmp:= LoadBitmap(AppPath+'\UIDB\BmpTest2.bmp');
SetTargetBitmap(MyBmp);
for c:=1 to 26 do
begin
MyBL:=CreateBL('inv',c);
WriteINI('Item'+inttostr(c),'Black', intArrayToStr(MyBL),AppPath+'\UIDB\UIDB.ini');
end;
FreeBitmap(mybmp);

t:=getsystemtime;
if CompareBL( strToIntArray(ReadIni('Item3','Black',AppPath+'\UIDB\UIDB.ini')),
CreateBL('inv',8)) then
writeln('yes');
writeln(inttostr(getsystemtime-t));
end.

Wizzup?

2008-12-10 06:08:48

I've never seen the use of those big TPA Databases.
However, I'm still in for making them, just cause they are databases. ;)
I think it would be nice to convert them to string first though, and use zlib to compress them. (Just like SCAR's DTM's.)

Depending on how exactly you want to use the Database. (Do you want to identify certain TPA's or want to grab a TPA from the Database and count it's occurrence) there are different ways to store / load them.

n3ss3s

2008-12-10 09:46:45

Don't make a library containing stuff like FindTPA, because that's the same as a FindDTM… Just wanted to remind you because it's easy to forget…

Sir R. M8gic1an

2008-12-10 11:21:25

From: n3ss3s
Don't make a library containing stuff like FindTPA, because that's the same as a FindDTM… Just wanted to remind you because it's easy to forget…


if the TPA is faster i don't see why not?

-RM