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.