SRL Archive - MSI Suggestions

Walking.simba : Increasing modularity


Sir R. M8gic1an

2010-05-27 08:04:32


{******************************************************************************}
{ function MSI_CreateWalkIndex(index: Integer): TPoint; }
{ By: Blumblebee, Coh3n and NCDS }
{ Description: Returns a point on the minimap depending on the specified }
{ location by 'index' }
{******************************************************************************}
function MSI_CreateWalkIndex(index: Integer): TPoint;
var
i, Tol: Integer;
aTPA: t2DPointArray;
TPA: tPointArray;
p: tPoint;
RockColor, TreeColor, BC: Integer;
t: LongInt;
begin
Result := Point(-1, -1);
case index of
WALK_WC_VE_TREE_1..WALK_WC_VE_BANK_4:
Result := Walk_WC_VE(index);
end;
end;

function Walk_WC_VE(index: integer): TPoint;
begin
case index of

//rock
WALK_WC_VE_TREE_1:
begin
if countColor(RoadColor, MMx1, MMy1, MMx2, MMy2) <= 5 then
RoadColor := MSI_AutoColorMM(COLOR_ROAD_VARROCK);
Tol := 2;
for i := 0 to 2 do
begin
FindColorsTolerance(TPA, RoadColor, MMCx, MMy1, MMx2, MMCy, Tol);
if Length(TPA) > 10 then
Break;
if i = 2 then
begin
MSI_Debug('WALK_WC_VE_TREE_1', 'Failed to locate road.', DEBUG_SMALL_DETAILS);
Exit;
end;
Tol := i * 2;
end;
SortTPAFrom(TPA, Point(MMCx, MMCy));
try
t := RandomRange(Length(TPA) - 10, Length(TPA) - 5);
except
t := Length(TPA) - 7;
end;
Result := Point(TPA[t].x, TPA[t].y);
end;


//road
WALK_WC_VE_TREE_2:
begin
Tol := 2;
for i := 0 to 2 do
begin
RoadColor := MSI_AutoColorMM(COLOR_ROAD_VARROCK);
FindColorsTolerance(TPA, RoadColor, MMCx + 40, MMCY - 40, MMx2, MMCy + 15, Tol);
if Length(TPA) > 10 then
Break;
if i = 2 then
begin
MSI_Debug('WALK_WC_VE_TREE_2', 'Failed to locate road.', DEBUG_SMALL_DETAILS);
Exit;
end;
Tol := i * 2;
end;
SortTPAFrom(TPA, Point(MMCx, MMCy));
i := (High(TPA) - RandomRange(1, 5));
Result := Point(TPA[i].x, TPA[i].y);
end;


//path
WALK_WC_VE_TREE_3:
begin
RockColor := MSI_AutoColorMM(COLOR_ROCK);
TPA := MSI_CreateWalkTPA(MMcx, MMy1, RockColor, 2, 2, 8);
if length(TPA) <= 0 then Exit;
for i := 0 to High(TPA) do
begin
if TPA[i].y > MMcy then continue;
Result := Point(TPA[i].x, TPA[i].y);
Exit;
end;
end;


//final
WALK_WC_VE_TREE_4:
begin
TreeColor := MSI_AutoColorMM(COLOR_TREE);
writeLn('Tree AutoColor = '+IntToStr(TreeColor));
FindColorsTolerance(TPA, TreeColor, MMx1, MMy1, MMx2, MMy2, 8);
if Length(TPA) <= 0 then Exit;
aTPA := SplitTPAEx(TPA, 10, 10);
if Length(aTPA) <= 0 then Exit;
SortATPASize(aTPA, true);
p := MiddleTPA(aTPA[0]);
if (p.x < MMcx+20) and (p.y < MMcy) then
Result := Point(p.x, p.y);
end;


//rock
WALK_WC_VE_BANK_1:
begin
RockColor := MSI_AutoColorMM(COLOR_ROCK);
TPA := MSI_CreateWalkTPA(MMcx, MMy2, RockColor, 2, 2, randomRange(5, 10));
if Length(TPA) <= 0 then Exit;
SortTPAFrom(TPA, point(700, 150));
for i := 0 to High(TPA) do
begin
if (TPA[i].y < MMcy-10) then continue;
Result := Point(TPA[i].x-5, TPA[i].y);
Exit;
end;
end;


//path
WALK_WC_VE_BANK_2:
begin
RoadColor := MSI_AutoColorMM(COLOR_ROAD_VARROCK);
FindColorsTolerance(TPA, RoadColor, MMx1, MMCy + 15, MMx2 - 20, MMy2, 4);
if Length(TPA) <= 0 then
Exit;
SortTPAFrom(TPA, Point(MMCx, MMCy));

for t := 0 to 4 do
begin
i := Length(TPA) - Random(2);
try
if rs_OnMiniMap(TPA[i].x, TPA[i].y) then
BC := 1;
except
Continue;
end;
if BC = 1 then
Break;
end;

if (t = 4) or (BC < 1) then
begin
MSI_Debug('CreatWalkIndex(WALK_WC_VE_BANK_2)', 'Failed to find road on minimap', DEBUG_FUNCTIONS);
Exit;
end;

Result := Point(TPA[i].x, TPA[i].y);
end;


//road
WALK_WC_VE_BANK_3:
begin
TPA := MSI_CreateWalkTPA(MMx1, MMcy, RoadColor, 3, 3, 8);
if Length(TPA) <= 0 then
Exit;
SortTPAFrom(TPA, point(MMx1-10, MMcy));
for i := 0 to High(TPA) do
begin
if not RS_onMinimap(TPA[i].x, TPA[i].y) then Continue;
Result := Point(TPA[i].x, TPA[i].y);
Exit;
end;
end;


//final
WALK_WC_VE_BANK_4:
begin
for i := 0 to 2 do
begin
BC := MSI_AutoColorMM(COLOR_BANKER);
FindColorsTolerance(TPA, BC, MMx1, MMCy, MMx2, MMy2, 5);
if Length(TPA) > 5 then
Break;
if i = 2 then
begin
MSI_Debug('MSI_CreateWalkTPA(WALK_BANK_Final);', 'Failed to find bankers on MiniMap.', DEBUG_FUNCTIONS);
Exit;
end;
end;

aTPA := TPAToATPAEx(TPA, 25, 5);
SortATPASize(aTPA, True);

i := Length(aTPA[0]);
t := RandomRange(0, i);
Result := Point(aTPA[0][t].x, aTPA[0][t].y - RandomRange(3, 7));
end;
end;
end;


Not a big change at all. Just makes it much more modular.

This way a person can develop an entire script and then just pluck it in with more ease. (Yes, I am currently looking at how to pluck in scripts :p)

Also, to re-use a walk index, just give its constant the same value.

eg
WALK_VE_TREE_1 = 0;
WALK_VE_MINE_1 = 0;

~RM

Coh3n

2010-05-29 08:07:20

From: Rasta Magician

Also, to re-use a walk index, just give its constant the same value.

eg
WALK_VE_TREE_1 = 0;
WALK_VE_MINE_1 = 0;

~RM

I thought that might get confusing. I was just going to do:

function CreateWalkIndex(which: integer);
begin
case which of
WALK_VE_TREES_1, WALK_VE_MINE_1:

I like how you separated the functions btw.

E: This and the other thread you put in SVN Commits, are you going to commit them? Or just wait for feedback?