SRL Archive - MSI Bugs

Walking


Blumblebee

2010-05-08 17:33:02

Well This has sat dormant for a while and I figured I'd get things going. I can't commit to the SVN at the moment I think I might need to be readded or something I dunno :s

anyways, I did some work towards this. It's not great and is fairly primitive, but it is a start.

here's code (added all the MSI functions I use so you don't have to manually add this to your MSI folder):

program new;
{$i SRL/SRL.scar}

{******************************************************************************}
{ procedure MSI_SortColors(var Colors: tIntegerArray; col: Integer); }
{ By: Blumblebee }
{ Description: Sorts an array of colors }
{******************************************************************************}
procedure MSI_SortColors(var Colors: tIntegerArray; col: Integer);
var
tempB: tIntegerArray;
Tol: ShortInt;
I: Integer;
timer, L: LongInt;
begin
timer := getsystemtime;
tempB := Colors;
SetArrayLength(Colors, 0);
Tol := 0;
while Length(Colors) < (Length(tempB)/2 or 5) do
begin
if Getsystemtime-timer > 100 then Break;
for i := 0 to High(tempB) do
begin
if SimilarColors(tempB[i], col, Tol) then
begin
L := GetArrayLength(Colors);
SetArrayLength(Colors, L+1);
Colors[L] := tempB[i];
end;
if Tol > 10 then Break;
Inc(Tol);
end;
end;
end;

{******************************************************************************}
{ function MSI_AutoColorMM(const color: Integer): Integer; }
{ By: Blumblebee }
{ Description: Autocolors the color 'color' on the minimap }
{******************************************************************************}
function MSI_AutoColorMM(const color: Integer): Integer;
var
TPA: tPointArray;
List: tIntegerArray;
I: Integer;
begin
for i := 0 to 20 do
begin
FindColorsTolerance(TPA, color, MMx1, MMy1, MMx2, MMy2, 5+i);
if Length(TPA) > 0 then Break;
end;
if Length(TPA) <= 0 then Exit;
List := getColors(TPA);
MSI_SortColors(List, color);
if Length(List) <= 0 then Exit;
result := List[0];
end;

{******************************************************************************}
{ function MSI_CreateWalkTPA( ... ): TPointArray; }
{ By: Blumblebee }
{ Description: Creats a TPA of which can be walked to }
{******************************************************************************}
function MSI_CreateWalkTPA(x, y, color, width, height, tolerance: Integer): TpointArray;
var
TPA: tPointArray;
aTPA: t2DPointArray;
i: Integer;
L, P: Integer;
begin
FindColorsSpiralTolerance(x, y, TPA, color, MMx1, MMy1, MMx2, MMy2, tolerance);
aTPA := TPAtoATPAEx(TPA, width, height);
for i := 0 to High(aTPA) do
begin
if Length(aTPA) > 5 then
begin
l := getarraylength(Result);
SetArrayLength(Result, l+1);
Result[l] := MiddleTpa(aTPA[i]);
end;
end;
if Length(result) = 0 then Exit;
for i := 0 to High(Result) do
if rs_OnMiniMap(result[i].x, result[i].y) then Inc(p);
if p = 0 then SetArrayLength(Result, 0);
end;

{******************************************************************************}
{ function MSI_WalkTPAPoint( ... ): Boolean; }
{ By: Blumblebee }
{ Description: Walks to a point on the minimap }
{******************************************************************************}
function MSI_WalkTPAPoint(TPA: tPointArray; sortP: tPoint; flagDist: shortInt): Boolean;
var
i: Integer;
t: LongInt;
begin
t := getSystemTime;
if Length(TPA) <= 0 then Exit;
SortTPAFrom(TPA, sortP);
for i := 0 to High(TPA) do
begin
if rs_OnMiniMap(TPA[i].x, TPA[i].y) then
begin
Mouse(TPA[i].x, TPA[i].y, random(8), random(8), true);
wait(randomRange(1000, 2000));
while not FlagPresent do
begin
wait(250+randomRange(150, 350));
if getSystemTime-t > randomRange(2500, 3750) then
continue;
end;
FFlag(flagDist);
Result := True;
Exit;
end;
end;
end;

{******************************************************************************}
{ function MSI_CreateColorBox(Color: Integer): TBox; }
{ By: Blumblebee }
{ Description: Returns a box around the colors found }
{******************************************************************************}
function MSI_CreateColorBox(Color: Integer): TBox;
var
TPA: tPointArray;
begin
FindColors(TPA, Color, MMx1, MMy1, MMx2, MMy2);
if Length(TPA) <= 0 then Exit;
Result := GetTPABounds(TPA);
end;

{******************************************************************************}
{ function MSI_FindColorInBox(Color: Integer; Box: TBox): Boolean; }
{ By: Blumblebee }
{ Description: Returns true if the color is found in a box }
{******************************************************************************}
function MSI_FindColorInBox(Color: Integer; Box: TBox): Boolean;
var
TPA: tPointArray;
i: Integer;
begin
FindColorsTolerance(TPA, Color, Box.x1-5, Box.y1-5, Box.x2+5, Box.y2+5, 15);
if Length(TPA) <= 0 then Exit;
SortTPAFrom(TPA, Point(687, 50));
for i := 0 to High(TPA) do
begin
if not rs_OnMiniMap(TPA[i].x, TPA[i].y) then continue;
Mouse(TPA[i].x, TPA[i].y, 5, 5, True);
Wait(750+random(450));
if FlagPresent then
begin
FFlag(10);
Result := True;
Exit;
end;
end;
end;

const
COLOR_MM_ROCK = 5922133;
COLOR_MM_ROAD = 8554627;
COLOR_MM_BUSH = 731446;
COLOR_MM_NPC = 195836;
COLOR_MM_MINE = 3233669;


function CreateWalkIndex(Index: Byte): tPoint;
var
TPA, nTPA: tPointArray;
aTPA: t2DPointArray;
I, AC: Integer;
DTM, x, y: Integer;
begin
case Index of
0:
begin
AC := MSI_AutoColorMM(COLOR_MM_ROAD);
if AC = 0 then
Exit;
TPA := MSI_CreateWalkTPA(MMx2, MMcy, AC, 5, 5, 3);
FindColorsTolerance(nTPA, COLOR_MM_ROCK, MMx1, MMy1, MMx2, MMy2, 12);
if Length(nTPA) or Length(TPA) <= 0 then
Exit;
writeLn('Length TPA = '+inttostr(length(tpa)));
writeLn('Length nTPA = '+inttostr(length(ntpa)));
SortTPAFrom(nTPA, point(MMx2, MMcy));
SortTPAFrom(TPA, nTPA[0]);
for I := 0 to high(TPA) do
begin
if rs_OnMiniMap(TPA[i].x, TPA[i].y) then
begin
result := TPA[i];
Exit;
end;
end;
end;

1:
begin
AC := MSI_AutoColorMM(COLOR_MM_ROAD);
if AC = 0 then
Exit;
TPA := MSI_CreateWalkTPA(MMx2, MMcy, AC, 5, 5, 3);
if Length(nTPA) or Length(TPA) <= 0 then
Exit;
SortTPAFrom(TPA, point(MMx2, MMcy));
for I := 0 to high(TPA) do
begin
if rs_OnMiniMap(TPA[i].x, TPA[i].y) then
begin
result := TPA[i];
Exit;
end;
end;
end;

2:
begin
AC := MSI_AutoColorMM(COLOR_MM_ROAD);
if AC = 0 then
Exit;
TPA := MSI_CreateWalkTPA(MMcx, MMy2, AC, 5, 5, 3);
if Length(nTPA) or Length(TPA) <= 0 then
Exit;
SortTPAFrom(TPA, point(MMcx, MMy2));
for I := 0 to high(TPA) do
begin
if rs_OnMiniMap(TPA[i].x, TPA[i].y) then
begin
result := TPA[i];
Exit;
end;
end;
end;

3:
begin
AC := MSI_AutoColorMM(COLOR_MM_ROAD);
FindColorsTolerance(TPA, COLOR_MM_NPC, MMcx, MMcy, MMx2, MMy2, 15);
nTPA := MSI_CreateWalkTPA(MMcx, MMcy, AC, 5, 5, 3);
if Length(TPA) or Length(nTPA) <= 0 then
Exit;
SortTPAFrom(nTPA, TPA[0]);
result := point(nTPA[0].x-20, nTPA[0].y);
end;

4:
begin
AC := MSI_AutoColorMM(COLOR_MM_MINE);
if AC = 0 then
Exit;
FindColorsTolerance(TPA, AC, MMx1, MMy1, MMx2, MMy2, 10);
if Length(TPA) <= 0 then
Exit;
aTPA := SplitTPAEx(TPA, 20, 20);
sortATPAFrom(aTPA, Point(MMcx, MMcy));
result := MiddleTPA(aTPA[0]);
end;
end;
end;

var TP: tPoint;
begin
SetUpSRL();
TP := CreateWalkIndex(0);
Mouse(TP.x, TP.y, 5, 5, true);
Flag;
TP := CreateWalkIndex(1);
Mouse(TP.x, TP.y, 5, 5, true);
Flag;
TP := CreateWalkIndex(2);
Mouse(TP.x, TP.y, 5, 5, true);
Flag;
TP := CreateWalkIndex(2);
Mouse(TP.x, TP.y, 5, 5, true);
Flag;
TP := CreateWalkIndex(2);
Mouse(TP.x, TP.y, 5, 5, true);
Flag;
TP := CreateWalkIndex(3);
Mouse(TP.x, TP.y, 5, 5, true);
Flag;
TP := CreateWalkIndex(4);
Mouse(TP.x, TP.y, 5, 5, true);
Flag;
end.

this is only from bank -> mine but I found it worked fairly well.

the code pretty much works like this.

0: Finds Color of Rocks, Finds a Road TPA, sorts the road TPA from where the Rocks are located.

1: Walks directly East.

2: Walks downward using a simple Road TPA

3: Finds the NPC dot (This needs to be waaaaay better) of the Rat, walks in a near proximity of it

edit:

how does this look for index 3?
  COLOR_MM_TREE = 1662790; 

3:
begin
AC := MSI_AutoColorMM(COLOR_MM_ROAD);
FindColorsTolerance(TPA, COLOR_MM_TREE, MMcx, MMcy, MMx2, MMy2, 15);
nTPA := MSI_CreateWalkTPA(MMcx, MMcy, AC, 5, 5, 3);
if Length(TPA) or Length(nTPA) <= 0 then
Exit;
SortTPAFrom(TPA, point(MMcx, MMy1));
SortTPAFrom(nTPA, TPA[0]);
result := point(nTPA[0].x-20, nTPA[0].y+10);
end;

4: Enters the Mine

Index 3 needs some serious work but I was just being lazy and inventive haha. I think that there is a tree or something by the rat NPC that would prove valuable.

Anyways, lets get this rolling people, edit, adjust, and replace away.

NCDS

2010-05-08 19:58:46

Be online tomorrow afternoon and when I get home we can work on this a bit and most likely get the walking done as I still have my old VEM walking that might help as well.

Are we going to try and re-use some of the walking from the wcer? or just have the mining use all separate walking?

Blumblebee

2010-05-08 20:03:37

I'd prefer to just have all new although we could hypothetically reuse the first step out of the bank and the last (two?) steps to the Bank.

NCDS

2010-05-08 20:06:00

From: Blumblebee
I'd prefer to just have all new although we could hypothetically reuse the first step out of the bank and the last (two?) steps to the Bank.


Yeah that's what I was thinking. We can discuss further tomorrow via MSN though :)

Blumblebee

2010-05-08 20:07:28

ok. I will be gone between 4-10pm (mountain time -7) due to training. Other than that I'm good. If you can't catch me then just do some work/edit stuff/write your own and we'll mix and match later in the week.

Coh3n

2010-05-10 00:14:23


begin
Result := Point(-1, -1);
case index of
WALK_WC_VE_TREE_1, WALK_MINE_VE_MINE_1:
We need to be as efficient as possible. There's no point in having two separate indexes that walk to the same point. And, yes, we should be able to reuse the first two points.

E: We should probably think of a better shortform for Mining, rather than "MINE" as it could get confusing. Just saying.

NCDS

2010-05-10 18:56:57

From: Coh3n

E: We should probably think of a better shortform for Mining, rather than "MINE" as it could get confusing. Just saying.

WALK_ROCKS_VE_MINE_1:

and

WALK_BANK_VE_MINE_1:

That's really the only other way to name them that I can think of.

Coh3n

2010-05-10 19:16:39

From: NCDS
WALK_ROCKS_VE_MINE_1:

and

WALK_BANK_VE_MINE_1:

That's really the only other way to name them that I can think of.

We should keep all the constants the same. Like:

WALK_SKILL_LOCATION_WHERETO_INDEX:

We could just make abbreviations to each still and add them to the location ones in globals.scar. I'd rather just keep things consistent.

Maybe:

WC - Woodcutting
MI - Mining
FI - Fishing
etc.
Just another idea.

marpis

2010-05-11 03:12:49

From: Coh3n
We should keep all the constants the same. Like:

WALK_SKILL_LOCATION_WHERETO_INDEX:

We could just make abbreviations to each still and add them to the location ones in globals.scar. I'd rather just keep things consistent.

Maybe:

WC - Woodcutting
MI - Mining
FI - Fishing
etc.
Just another idea.


Abbreviations is a great idea!
WALK_WOODCUTTING_FALADOR_RIMMINGTON_1 <- this is awful
WALK_WC_FALLY_RIMM_1 <- not very beautiful either but better

Gu3st...

2010-05-24 09:49:45

From: marpis
Abbreviations is a great idea!
WALK_WOODCUTTING_FALADOR_RIMMINGTON_1 <- this is awful
WALK_WC_FALLY_RIMM_1 <- not very beautiful either but better
Imo only do abbreviations on skills. Looks ugly on places :s

3Garrett3

2010-05-24 10:00:49

Is the walking mostly done, or does it still need work? I should have a bit of free time in the upcoming days, and I prefer doing walking.

Blumblebee

2010-05-24 12:34:54

walking is far from complete. Have at it if you would like to put some time into it :)

marpis

2010-05-24 14:19:36

From: Zyt3x
Imo only do abbreviations on skills. Looks ugly on places :s


But it will be impossible to handle all the locations with numbers… There will be dosens of them.

Sir R. M8gic1an

2010-05-25 07:45:29

FALLY_RIMM_ is just fine… we don't want to have to write an essay for the sake of extra readability, when everyone understands the abbreviations…

~RM

Gu3st...

2010-05-25 08:08:57

From: Rasta Magician
FALLY_RIMM_ is just fine… we don't want to have to write an essay for the sake of extra readability, when everyone understands the abbreviations…

~RM
Ugh, if that's what everybody wants then I guess I'll have to get used to it >_<


I tested the script in the first post, and it messed up on the first and 2nd last walk almost every time I tested it :/

Blumblebee

2010-05-25 11:33:48

From: Zyt3x
Ugh, if that's what everybody wants then I guess I'll have to get used to it >_<


I tested the script in the first post, and it messed up on the first and 2nd last walk almost every time I tested it :/


I wrote it in <10 minutes without testing really. It was a start to push people to improve it (which never ended up happening..) I am really tight for time as of recently, but I will fix it up/rewrite the walking when I can (hopefully in the next couple of days)

Coh3n

2010-05-25 17:57:35

From: Blumblebee
I wrote it in <10 minutes without testing really. It was a start to push people to improve it (which never ended up happening..) I am really tight for time as of recently, but I will fix it up/rewrite the walking when I can (hopefully in the next couple of days)

You should be able to reuse the first two points from the woodcutter…

Blumblebee

2010-05-25 18:13:55

From: Coh3n
You should be able to reuse the first two points from the woodcutter…


I don't mind using the first point, the second one doesn't really walk all the way to the end of the road does it?

Coh3n

2010-05-25 18:15:16

From: Blumblebee
I don't mind using the first point, the second one doesn't really walk all the way to the end of the road does it?

From what I've tested, it does ~70% of the time. Every other time it's pretty close.

3Garrett3

2010-05-25 20:36:28

Either way, the tpa walking is still pretty inconsistent for walking to the trees. I've been trying to figure out the problem, but whenever I debug it, for some reason it works, and then it doesn't work when I don't debug it.

Coh3n

2010-05-25 20:41:51

From: 3Garrett3
Either way, the tpa walking is still pretty inconsistent for walking to the trees. I've been trying to figure out the problem, but whenever I debug it, for some reason it works, and then it doesn't work when I don't debug it.

What do you mean by 'debug' it? Like test the points individually? Or just have more writelns?

3Garrett3

2010-05-25 20:51:15

From: Coh3n
What do you mean by 'debug' it? Like test the points individually? Or just have more writelns?


Like have MSI_Debug tell me the length of the array, the colour that it finds, the point that it wants to click. The data is always right, and it clicks the right points for the 15 tries I do with the debug. Then when I remove those debugs because the function apparently works, it will fail and revert to the radialwalk fail safe for the next 25 times.

So apparently to fix up the walking, we need to place many multiple random writelns, and it will be beyond perfect.

E: And yes, I mean like test each step separately. Test the first step 15 times, test the first + second step 15 times, etc.

Sir R. M8gic1an

2010-05-26 05:13:51

From: 3Garrett3
Like have MSI_Debug tell me the length of the array, the colour that it finds, the point that it wants to click. The data is always right, and it clicks the right points for the 15 tries I do with the debug. Then when I remove those debugs because the function apparently works, it will fail and revert to the radialwalk fail safe for the next 25 times.

So apparently to fix up the walking, we need to place many multiple random writelns, and it will be beyond perfect.

E: And yes, I mean like test each step separately. Test the first step 15 times, test the first + second step 15 times, etc.


Just leave the debugs in there.

~RM

Coh3n

2010-05-26 06:10:56

From: 3Garrett3
Like have MSI_Debug tell me the length of the array, the colour that it finds, the point that it wants to click. The data is always right, and it clicks the right points for the 15 tries I do with the debug. Then when I remove those debugs because the function apparently works, it will fail and revert to the radialwalk fail safe for the next 25 times.

So apparently to fix up the walking, we need to place many multiple random writelns, and it will be beyond perfect.

E: And yes, I mean like test each step separately. Test the first step 15 times, test the first + second step 15 times, etc.

It may also depend on where the previous point takes you when you're testing as a whole. But that is weird..

3Garrett3

2010-05-26 06:37:41

From: Rasta Magician
Just leave the debugs in there.

~RM


I'm thinking I might try a bit more when I'm less frustrated with it, to try and see if anything else will help it, rather than random debugs.

From: Coh3n
It may also depend on where the previous point takes you when you're testing as a whole. But that is weird..


Yes. I don't know if the tpa walking works for everyone else? Maybe it's just me. My autoing career hasn't been taking off very well since I came back. Many, many things fail for me when they don't fail for anyone else.

Coh3n

2010-05-26 17:16:14

From: 3Garrett3
Yes. I don't know if the tpa walking works for everyone else? Maybe it's just me. My autoing career hasn't been taking off very well since I came back. Many, many things fail for me when they don't fail for anyone else.

Well when I tested, I'd say it works 50% of the time. I would say it could be the autocoloring, but it works in the radial walking so I don't think that's it. I wish I had more time right now to help out. It's just a busy couple months for me. Lol