marpis
2011-11-25 12:44:15
I am trying to set SPS area bitmaps as targets so I could use FindBitmap to them. I keep getting this error:
Here's my code:
EDIT: Also as you can see, I'm trying to set clRed transparent in InitObjects and then use the regular FindBitmap. Feel free to tell me if that doesn't work! :p I'm quite sure it doesn't work, but I'm bored and want to try.
Error: Exception: You passed wrong values to a finder function: xs > xe (0,-1). at line 43
and I thought I try to manually tell it the bitmap size by using FindBitmapIn(bmp, tmp, tmp, 0, 0, 499, 499); but then I get this:
Error: Exception: You passed a wrong xe to a finder function: 499. [B]The client has a width of 0[/B], thus the xe is out of bounds. at line 43
The bolded part is probably the key to the answer.Here's my code:
program SPS_object_recognizer;
{.include srl/srl.scar}
{.include sps/sps.simba}
const
ImgPath = AppPath + '/Includes/sps/img/static_objects/';
TotalObjects = 7;
// ObjectTolerance = 10;
var
MapObjects: Array [0..(TotalObjects - 1)] of integer;
AreaObjectInfo: Array [0..17] of Array [0..13] of TBooleanArray;
procedure InitObjects;
var
i: integer;
begin
MapObjects[0] := LoadBitmap(ImgPath + 'deadtree.bmp');
MapObjects[1] := LoadBitmap(ImgPath + 'palmtree.bmp');
MapObjects[2] := LoadBitmap(ImgPath + 'rock1.bmp');
MapObjects[3] := LoadBitmap(ImgPath + 'rock2.bmp');
MapObjects[4] := LoadBitmap(ImgPath + 'tree1.bmp');
MapObjects[5] := LoadBitmap(ImgPath + 'tree2.bmp');
MapObjects[6] := LoadBitmap(ImgPath + 'tree3.bmp');
for i := high(MapObjects) downto 0 do
SetTransparentColor(MapObjects[i], clRed);
end;
procedure GetObjectsInArea(areaX, areaY: integer);
var
TBA: TBooleanArray;
bmp, i, tmp: integer;
s: string;
begin
SetLength(TBA, TotalObjects);
s := ToStr(areaX)+'_'+ToStr(areaY);
bmp := LoadBitmap(AppPath + '/Includes/sps/sps/img/runescape_surface/' + s + '.png');
bmp := SetTargetBitmap(bmp);
for i := (TotalObjects - 1) downto 0 do
if FindBitmap(MapObjects[i], tmp, tmp) then
TBA[i] := True
else
TBA[i] := False;
FreeBitmap(bmp);
writeln('SPS_AreaObjectInfo['+ToStr(areax)+']['+ToStr(areay)+'] := '+ToStr(TBA)+';');
end;
procedure CreateAllAreaObjectInfo;
var
x, y: integer;
s: string;
begin
InitObjects;
for x := 0 to 17 do
for y := 0 to 13 do
begin
s := ToStr(x)+'_'+ToStr(y);
if not FileExists(AppPath + '/Includes/sps/img/runescape_surface/' + s +'.png') then
Continue;
GetObjectsInArea(x, y);
end;
end;
function GetAllAreasWithObjects(ObjectsToFind: TBooleanArray): TStringArray;
var
x, y, i, L: integer;
b: boolean;
s: string;
begin
SetLength(Result, 999);
for x := 0 to 17 do
for y := 0 to 13 do
begin
s := ToStr(x)+'_'+ToStr(y);
if not FileExists(AppPath + '/Includes/sps/img/runescape_surface/' + s +'.png') then
Continue;
Writeln('Scanning area: '+s);
b := true;
for i := (TotalObjects - 1) downto 0 do
if (ObjectsToFind[i] = True) and (AreaObjectInfo[x][y][i] = False) then
begin
b := false;
Break;
end;
if b then
begin
Result[L] := s;
Inc(L);
end;
end;
end;
begin
CreateAllAreaObjectInfo;
end.
EDIT: Also as you can see, I'm trying to set clRed transparent in InitObjects and then use the regular FindBitmap. Feel free to tell me if that doesn't work! :p I'm quite sure it doesn't work, but I'm bored and want to try.