SRL Archive - News and General

Find banksymbol in crowded bank


Boreas

2007-04-20 17:20:13

Ok I fixed it :p

This uses Divi with SRL that comes with Divi.
It lags a bit because its holding a huge bitmap in memory, version for SRL 3.7+ does not.

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

function InIntArray(TheInt:integer;TheArray:array of integer):boolean;
var i:integer;
begin
repeat
if TheArray[i]=TheInt then
result:=true;
i:=i+1;
until ((i=getarraylength(TheArray)) or (result));
end;
procedure RemoveFromTPA(Index:integer; var TPA:array of tpoint);
var swapTP:tpoint;
AL:integer;
begin
AL:=getarraylength(TPA);
swapTP:=TPA[AL-1];
TPA[AL-1]:=TPA[Index];
TPA[Index]:=swapTP;
setarraylength(TPA,AL-1);
end;




type ColorTPA = record
color:integer;
tpa: array of tpoint;
end;
var
PlayerDotCTPA:array of ColorTPA;
client,parray,parray2,tx,ty,tmpcolor,mmbmp,dropdot,AL,PointsLeft:integer;
ColorArray: array of integer;
tmpbool:boolean;

procedure updatebitmap(sx,sy,color:integer);
begin
FastSetPixel(mmbmp,sx,sy,color);
CopyCanvas(getbitmapcanvas(mmbmp),getdebugcanvas,mmx1,mmy1,mmx2,mmy2,0,0,mmx2-mmx1,mmy2-mmy1);
DisplayDebugImgWindow(mmx2-mmx1,mmy2-mmy1)

activateclient;

end;
begin
setupsrl;
if FindSymbol(tx,ty,'bank') then
begin
writeln('found bank without help');
writeln('please try again');

terminatescript;
end;
DisplayDebugImgWindow(mmx2-mmx1,mmy2-mmy1)//displays debug image
MMbmp:=BitmapFromString(766,504,'');
CopyClientToBitmap(MMbmp,0,0,766,504);
CopyCanvas(getbitmapcanvas(mmbmp),getdebugcanvas,mmx1,mmy1,mmx2,mmy2,0,0,mmx2-mmx1,mmy2-mmy1);
DisplayDebugImgWindow(mmx2-mmx1,mmy2-mmy1)

dropdot:= DTMFromString('78DA6354666060606340012FA134238C56021' +
'2ECA86A3EA2AB5104121CA86A6EA2AB51C634E71C921A66200600' +
'386A0432');
setarraylength(colorarray,6);
ColorArray[0]:=16711422;
ColorArray[1]:=15527148;
ColorArray[2]:=13816530;
ColorArray[3]:=14869218;
ColorArray[4]:=12961221;
ColorArray[5]:=65536;
if FindDTM(dropdot,tx,ty,mmx1,mmy1,mmx2,mmy2)then
begin
setarraylength(colorarray,18);
ColorArray[6]:=getcolor(tx,ty);
ColorArray[7]:=getcolor(tx,ty+1);
ColorArray[8]:=getcolor(tx-1,ty-1);
ColorArray[9]:=getcolor(tx-1,ty);
ColorArray[10]:=getcolor(tx-1,ty+1);
ColorArray[11]:=getcolor(tx-1,ty+2);
ColorArray[12]:=getcolor(tx-2,ty-1);
ColorArray[13]:=getcolor(tx-2,ty);
ColorArray[14]:=getcolor(tx-2,ty+1);
ColorArray[15]:=getcolor(tx-2,ty+2);
ColorArray[16]:=getcolor(tx-3,ty);
ColorArray[17]:=getcolor(tx-3,ty+1);
end;
freedtm(dropdot);
AL:=getarraylength(colorarray);
setarraylength(PlayerDotCTPA,AL);
for parray:=0 to AL-1 do
begin
PlayerDotCTPA[parray].color:=colorarray[parray];
// writeln(inttostr(PlayerDotCTPA[parray].color));
end;
AL:=getarraylength(colorarray);
for parray:=0 to AL-1 do
begin
FindColorsSpiralTolerance(tx,ty,PlayerDotCTPA[parray].tpa,
PlayerDotCTPA[parray].color,mmx1,mmy1,mmx2,mmy2,0);
end;
repeat
for parray:=0 to AL-1 do
begin
for parray2:=0 to getarraylength(PlayerDotCTPA[parray].tpa)-1 do
begin
tmpcolor:=getcolor(PlayerDotCTPA[parray].tpa[parray2].x,PlayerDotCTPA[parray].tpa[parray2].y);
if not(InIntArray(tmpcolor,ColorArray)) then
// if not(tmpcolor=PlayerDotCTPA[parray].color) then
begin
UpdateBitmap(PlayerDotCTPA[parray].tpa[parray2].x,PlayerDotCTPA[parray].tpa[parray2].y,tmpcolor);
RemoveFromTPA(parray2,PlayerDotCTPA[parray].tpa);
end;
end;
end;

PointsLeft:=0;
for parray:=0 to AL-1 do
begin
PointsLeft:=PointsLeft+getarraylength(PlayerDotCTPA[parray].tpa);
end;
cleardebug;
writeln(inttostr(PointsLeft));


wait(500);
// CopyCanvas(getbitmapcanvas(mmbmp),getdebugcanvas,0,05,mmx2-mmx1,mmy2-mmy1,0,0,748-541,175);
//DisplayDebugImgWindow(748-541,175)
//writeln('new bmp');
//repeat
// wait(30);
//until isfkeydown(12);
//if random(10)=1 then
begin
client:= GetClientWindowHandle;
SetTargetBitmap(mmbmp);
//tmpbool:=FindSymbolIn(tx,ty,'bank',0,0,mmx2-mmx1,mmy2-mmy1);
tmpbool:=FindSymbol(tx,ty,'bank');

SetClientWindowHandle(client);
end;
//repeat
// wait(30);
until (isfkeydown(11)) or (tmpbool);
// until PointsLeft<50;
client:= GetClientWindowHandle;
SetTargetBitmap(mmbmp);
//if FindSymbolIn(tx,ty,'bank',0,0,mmx2-mmx1,mmy2-mmy1)then
if FindSymbol(tx,ty,'bank')then
begin
writeln('banksymbol loc on debug image '+inttostr(tx-mmx1)+','+inttostr(ty-mmy1));
writeln('banksymbol loc on rs applet '+inttostr(tx)+','+inttostr(ty));

end;
SetClientWindowHandle(client);
FreeBitmap(mmbmp);
activateclient;
//gametab(1);


end.



Run that in a bank in a fairly crowded world, where the bank symbol is covered up too much for normal finding to work. If it isn't covered up enough for normal finding to work, it will tell you to try again.

Watch the player dots disappear on the debug image, it's kinda spooky.

Smartzkid

2007-04-20 17:22:55

Awesome

*whips open rs*

EDIT
Line 135: [Error] (17470:10): Unknown identifier 'FindSymbolIn' in script

Ehh?

Boreas

2007-04-20 17:39:55

Oops sorry. Hold on.

Starblaster100

2007-04-20 17:52:48

tut Tut Boreas, using the Dev version of SRL and releasing to those less fortunate? :P

Ejjman

2007-04-20 17:54:35

Will test once you fix ;)

Boreas

2007-04-20 19:04:09

I forgot lol. I also forgot to say it needs Divi. Thread closed until SRL 3.7 is released.


EDIT: Duh, I got another way. I'll change it to use a full size bitmap, so that regular findsymbol will work in mmx1,mmy1,mmx2,mmy2, and I'll make it only display part of the bitmap. Thread will be reopened soon lol.


EDIT2/Bump for reopening.

Fixed it to work for everyone :p see first post. It uses a big bitmap to use the regular findsymbol. It lags a bit but it works :D

Cheesehunk

2007-04-20 20:00:00

Nice job. :) It is a bit laggy with the current Divi version, but it worked well.

Ejjman

2007-04-20 20:03:01

It is really cool to watch everything dissapear! lol good job

Boreas

2007-04-20 20:54:48

Eij: Thanks :)

Chuck/other devs: If you want the non lagging version just pm/msn :D

Ruroken

2007-04-21 10:58:28

From: Starblaster100
tut Tut Boreas, using the Dev version of SRL and releasing to those less fortunate? :P


Oohhhh!!

Boreas is in trouble!! :p

Infantry001

2007-04-21 23:21:02

wow that's really cool, Boreas! Great job!

da_professa

2007-04-26 05:16:59

Ohh sounds soo cool, I'll give it a try when I get time.

nielsie95

2007-04-28 15:14:40

Wow.. This is very nice :)
Nice to see the dots dissapear :p

Mjordan

2007-04-29 09:15:30

Is this going to be put into SRL? Because I think it should.

Bobarkinator

2007-04-29 14:45:59

I think there is a better way to do it in SRL 7 if I'm not mistaken.

Boreas

2007-04-30 09:17:41

FindSymbolIn is now public so I can go back to the original, faster way. I'm gonna turn it into a function, and decide whether it's worth removing yellow dots. Hopefully the new version will be done in time for SRL 4.0.

nielsie95

2007-04-30 09:39:07

Will SRL 4.0 come quick after this version then? :D

Smartzkid

2007-04-30 17:46:28

From: Boreas
FindSymbolIn is now public so I can go back to the original, faster way. I'm gonna turn it into a function, and decide whether it's worth removing yellow dots. Hopefully the new version will be done in time for SRL 4.0.


Maybe just add a boolean parameter to the function?

FindCrowdedSymbol(x, y: integer; symbol: string, UnCoverEverything: boolean);

Boreas

2007-04-30 22:16:20

If it makes a significant difference in speed, yea I'll do that.

@nielsie No clue. One of 3.7's purposes is to buy us time to work on 4.0.