SRL Archive - SRL Member Goodies

MayaMiner [Unfinished]


Daniel

2012-04-22 05:37:18

Well,

Due to Kyle Undefined's constant harassment for me to release this since I wasn't getting any work done on it, nor have in the past two weeks, here it is. It is my unfinished power miner (which could easily be expanded to support walking to and from various locations by several means). It was originally split up into multiple files, which you can probably see. The goal of this script was to be so easily maintainable, in that if something went wrong, all you would have to do is change just one line (the settings, up top), which could be something a complete novice could even do.

Anyways, enough chit chat, and here it is. Finish it, salvage it, it's up to you :)


program New;
{$include SRL/SRL.simba}


const
Yes = True; // Alternative to True. Easier for some people to understand/input. :-)
No = False; // Alternative to False. Easier for some people to understand/input. :-)

COLOUR_BESTCOLOUR_INDEX = 0;
COLOURS_MAX_INDEX = COLOUR_BESTCOLOUR_INDEX + 254;

COLOUR_BEST_ORE_CLAY = 16777215; // The ACA best colour of the ore, Clay.
COLOUR_BEST_ORE_COPPER = 16777215; // The ACA best colour of the ore, Copper.
COLOUR_BEST_ORE_TIN = 16777215; // The ACA best colour of the ore, Tin.
COLOUR_BEST_ORE_BLURITE = 16777215; // The ACA best colour of the ore, Blurite.
COLOUR_BEST_ORE_IRON = 16777215; // The ACA best colour of the ore, Iron.
COLOUR_BEST_ORE_SILVER = 16777215; // The ACA best colour of the ore, Silver.
COLOUR_BEST_ORE_COAL = 16777215; // The ACA best colour of the ore, Coal.
COLOUR_BEST_ORE_GOLD = 16777215; // The ACA best colour of the ore, Gold.
COLOUR_BEST_ORE_MITHRIL = 16777215; // The ACA best colour of the ore, Mithril.
COLOUR_BEST_ORE_ADAMANTITE = 16777215; // The ACA best colour of the ore, Adamantite.
COLOUR_BEST_ORE_RUNITE = 16777215; // The ACA best colour of the ore, Runite.

TOL_BEST_ORE_CLAY = 255; // The ACA best tolerance of the ore, Clay.
TOL_BEST_ORE_COPPER = 255; // The ACA best tolerance of the ore, Copper.
TOL_BEST_ORE_TIN = 255; // The ACA best tolerance of the ore, Tin.
TOL_BEST_ORE_BLURITE = 255; // The ACA best tolerance of the ore, Blurite.
TOL_BEST_ORE_IRON = 255; // The ACA best tolerance of the ore, Iron.
TOL_BEST_ORE_SILVER = 255; // The ACA best tolerance of the ore, Silver.
TOL_BEST_ORE_COAL = 255; // The ACA best tolerance of the ore, Coal.
TOL_BEST_ORE_GOLD = 255; // The ACA best tolerance of the ore, Gold.
TOL_BEST_ORE_MITHRIL = 255; // The ACA best tolerance of the ore, Mithril.
TOL_BEST_ORE_ADAMANTITE = 255; // The ACA best tolerance of the ore, Adamantite.
TOL_BEST_ORE_RUNITE = 255; // The ACA best tolerance of the ore, Runite.

DTM_SYMBOL_MINE = ''; // The DTM of the minimap symbol for a digsite.
DTM_SYMBOL_ORE = ''; // The DTM of the minimap icon for an ore deposit.
DTM_OBJECT_PICKAXE_BRONZE = ''; // The DTM of the inventory/equip icon for a Bronze pickaxe.
DTM_OBJECT_PICKAXE_IRON = ''; // The DTM of the inventory/equip icon for an Iron pickaxe.
DTM_OBJECT_PICKAXE_STEEL = ''; // The DTM of the inventory/equip icon for a Steel pickaxe.
DTM_OBJECT_PICKAXE_MITRHIL = ''; // The DTM of the inventory/equip icon for a Mithril pickaxe.
DTM_OBJECT_PICKAXE_ADAMANT = ''; // The DTM of the inventory/equip icon for an Adamant pickaxe.
DTM_OBJECT_PICKAXE_RUNE = ''; // The DTM of the inventory/equip icon for a Runite pickaxe.
DTM_OBJECT_PICKAXE_DRAGON = ''; // The DTM of the inventory/equip icon for a Dragon pickaxe.
DTM_OBJECT_PICKAXE_INFERNO = ''; // The DTM of the inventory/equip icon for an Inferno pickaxe.

ANTIBAN = Yes; // Enable anti-ban in the script?
ANTIBAN_ACTIONCHANCE = 50; // The chance of doing an anti-ban action after either mining or dropping (0 - Never do antiban during/after dropping, 50 - Equal chance, 100 - Never do antiban during/after mining).
ANTIBAN_CHANCE = 100; // If the above is set to Yes, the chance (%) of doing an anti-ban action after mining?

ANTIBAN_ACCIDENTALTYPE = Yes; // Anti-ban: Accidentally press a key, but delete it afterwards?
ANTIBAN_WILDMOUSE = Yes; // Anti-ban: Move the mouse all over the screen?
ANTIBAN_ROTATECOMPASS = Yes; // Anti-ban: Rotate the compass to a random angle?
ANTIBAN_CHANGEANGLE = Yes; // Anti-ban: Change the position of the RuneScape viewing angle (up arrow and down arrow)?
ANTIBAN_PICKUPMOUSE = Yes; // Anti-ban: Simulate a human picking up their mouse?
ANTIBAN_RANDOMTAB = Yes; // Anti-ban: Change to a random tab?
ANTIBAN_CHECKMININGLEVEL = Yes; // Anti-ban: Check the mining level of your character?
ANTIBAN_CHECKRANDOMLEVEL = Yes; // Anti-ban: Check any other random level of your character?
ANTIBAN_HOVERINV = Yes; // Anti-ban: Hover over a random item in your inventory?
ANTIBAN_EXAMINEINV = Yes; // Anti-ban: Examine a random item in your inventory?
ANTIBAN_RANDOMRIGHTCLICKMS = Yes; // Anti-ban: Do a random right click anywhere on the main screen?
ANTIBAN_RANDOMRIGHTCLICKINV = Yes; // Anti-ban: Do a random right click anywhere in the inventory?

ANTIBAN_MOUSESPEED = 17; // Your desired mouse speed for the script to use?
ANTIBAN_MOUSESPEEDVARIATION = 3; // Your maximum variation desired for the mouse speed above (-X, X).
ANTIBAN_MOUSERADIIPRECISION = 5; // Increase for much more precision when clicking on/moving over a target. Too high will cause the script to click exactly on the target pixel (similar effect to: MMouse(x, y, 0, 0); ).

ANTIRANDOMS_COMPLETE = Yes; // Solve anti-randoms? If otherwise, upon random detection, it will log out.

DEBUG_LEVEL_ERROR = 0; // Debug Level: Output critical errors only.
DEBUG_LEVEL_WARNING = 1; // Debug Level: Output warnings and the aforementioned.
DEBUG_LEVEL_INFO = 2; // Debug Level: Output information and the aforementioned.
DEBUG_LEVEL_ALL = 3; // Debug Level: Output all.

SCRIPT_NAME = 'MayaMiner'; // The name of the script.
SCRIPT_VERSION = 0.01; // The current version of the script.
SCRIPT_STATS_ID = 999; // The scripts SRL Stats identification number.

SCRIPT_UPDATE = Yes; // Check for updates for this script?
SCRIPT_UPDATE_FORCE = Yes; // Do not ask for user permission to update?

SCRIPT_DEBUG = Yes; // Output debug information?
SCRIPT_DEBUG_LEVEL = DEBUG_LEVEL_ALL;// Your desired debug level (see debug levels above).
SCRIPT_DEBUG_LOG = Yes; // Log the debug text to a file?
SCRIPT_DEBUG_LEVELCHAR = '.'; // Just for aesthetics.
SCRIPT_DEBUG_INDENTCNT = 2; // Just for aesthetics of the debug output. Increase for greater indentation.

SCRIPT_SEARCH_OWNCOLOUR = Yes; // Do a no-tolerance search on proven ore colours to identify an ore (otherwise best colour searching will be used)?
SCRIPT_SEARCH_MM = Yes; // Search via the minimap symbols of the ore deposit?
SCRIPT_SEARCH_UPTEXT = Yes; // Confirm that a rock exists in a particular location by checking for the prescence of an UpText value?
SCRIPT_SEARCH_UPTEXT_STR = 'Mine|ine'; // The UpText string to find as confirmation of an ore (separate with |, in order).

SCRIPT_DIRECTORY_DEBUG = 'logs'; // Debug directory to output log file (relative to script path).
SCRIPT_DIRECTORY_COLOURS = 'colours'; // Directory which holds single colour values for ores (relative to script path).

SITE = 'http://mayazcherquoi.co.cc/srl/scripts/mayaminer/'; // Website path to check for updates.
SITE_VERSION_CHECK = 'ver.ss'; // The file (relative to the website path) to retrieve the latest version information.
SITE_SCRIPT_UPDATE = 'script.ss'; // The file (relative to the website path) to retrieve the script for download.
SITE_CHANGELOG = 'changelog.ss'; // The file (relative to the website path) to retrieve the latest changes.

ROCK_INDEX_HUE = 0; // The array index for Hue in TRock.StandardHS.
ROCK_INDEX_SATURATION = 1; // The array index for Saturation in TRock.StandardHS.

DTM_INDEX_FROM = 0; // Starting index of the DTMs array.
DTM_INDEX_TO = 9; // Last index of the DTMs array.

DTM_INDEX_SYMBOL_MINE = 0; // The index for the DTM array which contains the DTM for the digsite symbol.
DTM_INDEX_SYMBOL_ORE = 1; // The index for the DTM array which contains the DTM for the ore symbol.
DTM_INDEX_OBJECT_PICKAXE_BRONZE = 2; // The index for the DTM array which contains the DTM for the Bronze pickaxe.
DTM_INDEX_OBJECT_PICKAXE_IRON = 3; // The index for the DTM array which contains the DTM for the Iron pickaxe.
DTM_INDEX_OBJECT_PICKAXE_STEEL = 4; // The index for the DTM array which contains the DTM for the Steel pickaxe.
DTM_INDEX_OBJECT_PICKAXE_MITHRIL = 5; // The index for the DTM array which contains the DTM for the Mithril pickaxe.
DTM_INDEX_OBJECT_PICKAXE_ADAMANT = 6; // The index for the DTM array which contains the DTM for the Adamant pickaxe.
DTM_INDEX_OBJECT_PICKAXE_RUNE = 7; // The index for the DTM array which contains the DTM for the Rune pickaxe.
DTM_INDEX_OBJECT_PICKAXE_DRAGON = 8; // The index for the DTM array which contains the DTM for the Dragon pickaxe.
DTM_INDEX_OBJECT_PICKAXE_INFERNO = 9; // The index for the DTM array which contains the DTM for the Inferno pickaxe.

MINE_CLAY = $1; // ID: Ore, Clay.
MINE_COPPER = $2; // ID: Ore, Copper.
MINE_TIN = $4; // ID: Ore, Tin.
MINE_BLURITE = $8; // ID: Ore, Blurite.
MINE_IRON = $10; // ID: Ore, Iron.
MINE_SILVER = $20; // ID: Ore, Silver.
MINE_COAL = $40; // ID: Ore, Coal.
MINE_GOLD = $80; // ID: Ore, Gold.
MINE_MITHRIL = $100; // ID: Ore, Mithril.
MINE_ADAMANTITE = $200; // ID: Ore, Adamantite.
MINE_RUNITE = $400; // ID: Ore, Runite.

PICK_BRONZE = 0; // ID: Pickaxe, Bronze.
PICK_IRON = 1; // ID: Pickaxe, Iron.
PICK_STEEL = 2; // ID: Pickaxe, Steel.
PICK_MITHRIL = 3; // ID: Pickaxe, Mithril.
PICK_ADAMANT = 4; // ID: Pickaxe, Adamant.
PICK_RUNE = 5; // ID: Pickaxe, Rune.
PICK_DRAGON = 6; // ID: Pickaxe, Dragon.
PICK_INFERNO = 7; // ID: Pickaxe, Inferno.

RUNESCAPE_TILE_WIDTH = 38; // Approximate width of a RuneScape mainscreen tile. (deprecated)
RUNESCAPE_TILE_HEIGHT = 38; // Approximate height of a RuneScape mainscreen tile. (deprecated)

(* Standard error codes *)
RETURN_NOERROR = $0; // No error.
RETURN_EXCEPTION = $1; // Critical error. Can not continue with method.
RETURN_TERMINATE = $2; // Critical error. Can not continue with script.
RETURN_NODIGSITE = $4; // The digsite minimap symbol can not be found.
RETURN_NOMINIMAPROCKS = $8; // There are no rocks visible on the minimap.
RETURN_NOMAINSCRROCKS = $10; // No rocks can be found on the main screen.
RETURN_NOUPTEXT = $20; // No UpText can be found to verify the rocks.
RETURN_NOPICK = $40; // No pickaxe can be found (equipped or non-equipped).
RETURN_DROPERROR = $80; // Error while dropping.
RETURN_NOTLOGGEDIN = $100; // The player is not logged in.
RETURN_PLAYERERROR = $200; // There was an error with the player.
RETURN_NOMOREPLAYERS = $400; // There are no more active players to cycle through.
RETURN_NOOWNCOLOUR = $800; // None of the single colour's can be found.
RETURN_NOBESTCOLOUR = $1000; // The best colour for the ore can not be found.
RETURN_NOCOLOURS = $2000; // No colours exist in the array.
RETURN_SUCCESS = $8000; // The method had executed successfully.

////////////////////////////////////////////////////////////////////////////////

type
Float = Extended;
Real = Extended;
UInt32 = Cardinal;
DWord = Cardinal;

TFloatArray = array of Float;
TRealArray = array of Real;

TPolyBox = record
P1, P2, P3, P4: TPoint;
end;

TPolyBoxArray = array of TPolyBox;

TOre = record
Name: AnsiString;
Identification: Byte;
MinimumRequiredLevel: Byte;

Colours: array[COLOUR_BESTCOLOUR_INDEX..COLOURS_MAX_INDEX] of Cardinal;
BestColourTol: Byte;
StandardHS: array[0..1] of Float;
end;

TOres = array of TOre;

TPickaxe = record
PickaxeType: Byte;

Wielded: Boolean;
end;

TMayaPlayer = record
Name, Pass: AnsiString;
Active: Boolean;

Pickaxe: TPickaxe;
Ores: array of Integer;
Priority: array of Integer;
end;

TMayaPlayers = array of TMayaPlayer;

var
arrDTMs: array of array of Integer;

function CheckBitwise(const Output: Cardinal; const Bit: Cardinal): Boolean;
begin
Result := (Output and Bit) > 0;
end;

function GetBitPos(const Value: Cardinal): Byte;
begin
Result := 0;
if(Value < 1) then
Exit;

for Result := 0 to 255 do
if((1 shl Result) = Value) then
Break;

Result := Result + 1;
end;

function rs_OnMainScreenPoint(const P: TPoint): Boolean;
begin
Result := InRange(P.X, MSX1, MSX2) and InRange(P.Y, MSY1, MSY2);
end;

function rs_OnMainScreen(const x, y: Integer): Boolean;
begin
Result := rs_OnMainScreenPoint(Point(x, y));
end;

////////////////////////////////////////////////////////////////////////////////

var
FILE_DEBUG_HANDLE: Integer;

function DateTimeToUNIX(Time: TDateTime): Cardinal;
begin
Result := Round((Time - 25569) * 86400);
end;

function UNIXNow: Cardinal;
begin
Result := DateTimeToUNIX(Now);
end;

function CreateUniqueDebugFileEx(const Path: AnsiString): THandle;
var
I: Byte;
UNIX_Timestamp: Cardinal;
FileName, FileExt: AnsiString;
begin
Result := -1;
UNIX_Timestamp := UNIXNow;
FileName := Path + IntToStr(UNIX_Timestamp);
FileExt := '.log';

if(FileExists(FileName + FileExt)) then
begin
I := 1;

repeat
if(not(FileExists(FileName + '_' + IntToStr(I) + FileExt))) then
begin
FileName := FileName + '_' + IntToStr(I);
Break;
end;
Until(I > 254);

if(I > 254) then
Exit;
end;

Result := CreateFile(FileName + FileExt);
end;

function CreateUniqueDebugFile: THandle;
begin
Result := CreateUniqueDebugFileEx(ScriptPath + SCRIPT_DIRECTORY_DEBUG);
end;

procedure Debug(const Str: String; const Debug_Level, Places: Byte);
var
H, M, S, MS: Word;
IsPM: Boolean;
AMPM, OutStr: AnsiString;
I, bI: Byte;
begin
if(not(Debug_Level <= SCRIPT_DEBUG_LEVEL)) then
Exit;

DecodeTime(Now, H, M, S, MS);

if(H > 12) then
begin
H := H - 12;
AMPM := ' PM';
end else
AMPM := ' AM';

if(H = 0) then
H := 12;

OutStr := IntToStr(H) + ':' + IntToStr(M) + ':' + IntToStr(S) + AMPM + ' - ';

bI := Max(Places, 1) * SCRIPT_DEBUG_INDENTCNT;
for I := 1 to bI do
OutStr := OutStr + SCRIPT_DEBUG_LEVELCHAR;

OutStr := OutStr + Str;

Writeln(OutStr);
if((FILE_DEBUG_HANDLE > 0) and (SCRIPT_DEBUG_LOG)) then
WriteFileString(FILE_DEBUG_HANDLE, OutStr);
end;

procedure PrintReturnCodes(const Input: Cardinal; const Places: Byte);
var
I, bI: Integer;
MSB: Byte;
curCode: Word;
begin
curCode := 1 shl ((SizeOf(curCode) shl 3) - 1);
while (curCode > 0) do
begin
curCode := curCode shr 1;

case (curCode and Input) of
RETURN_NOCOLOURS : Debug('WARNING [E' + IntToStr(RETURN_NOCOLOURS) + ']: No colours could be found at all.', DEBUG_LEVEL_WARNING);
RETURN_NOBESTCOLOUR : Debug('WARNING [E' + IntToStr(RETURN_NOBESTCOLOUR) + ']: The best colour for the specified ore could not be found.', DEBUG_LEVEL_WARNING);
RETURN_NOOWNCOLOUR : Debug('WARNING [E' + IntToStr(RETURN_NOOWNCOLOUR) + ']: The individual colours for the specified ore could not be found.', DEBUG_LEVEL_WARNING);
RETURN_NOMOREPLAYERS : Debug('INFO [E' + IntToStr(RETURN_NOMOREPLAYERS) + ']: There are no more active players in the player list to cycle through.', DEBUG_LEVEL_INFO);
RETURN_PLAYERERROR : Debug('ERROR [E' + IntToStr(RETURN_PLAYERERROR) + ']: There was an error with the current active player.', DEBUG_LEVEL_ERROR);
RETURN_NOTLOGGEDIN : Debug('ALL [E' + IntToStr(RETURN_NOTLOGGEDIN) + ']: The currently active player is not logged in.', DEBUG_LEVEL_ALL);
RETURN_DROPERROR : Debug('INFO [E' + IntToStr(RETURN_DROPERROR) + ']: An error has occurred while dropping the ores from your inventory.', DEBUG_LEVEL_INFO);
RETURN_NOPICK : Debug('WARNING [E' + IntToStr(RETURN_NOPICK) + ']: No pickaxe has been found (equipped or non-equipped).', DEBUG_LEVEL_WARNING);
RETURN_NOUPTEXT : Debug('WARNING [E' + IntToStr(RETURN_NOUPTEXT) + ']: No UpText can be found to verify the location of the rocks.', DEBUG_LEVEL_WARNING);
RETURN_NOMAINSCRROCKS : Debug('WARNING [E' + IntToStr(RETURN_NOMAINSCRROCKS) + ']: No mineable rocks have been found on the RuneScape main screen.', DEBUG_LEVEL_WARNING);
RETURN_NOMINIMAPROCKS : Debug('WARNING [E' + IntToStr(RETURN_NOMINIMAPROCKS) + ']: There are no visible minimap icons for rocks. Player is possibly AWOL.', DEBUG_LEVEL_WARNING);
RETURN_NODIGSITE : Debug('ERROR [E' + IntToStr(RETURN_NODIGSITE) + ']: The digsite minimap symbol can not be found. Player is possibly AWOL.', DEBUG_LEVEL_ERROR);

RETURN_TERMINATE : Debug('CRITICAL ERROR [E' + IntToStr(RETURN_TERMINATE) + ']: The script can not continue. Immediate termination imminent. WARNING, WARNING!', DEBUG_LEVEL_ERROR);
RETURN_EXCEPTION : Debug('CRITICAL ERROR [E' + IntToStr(RETURN_EXCEPTION) + ']: The current method can not continue. Exiting and/or retrying.', DEBUG_LEVEL_ERROR);
end;
end;
end;

function GetCursorPos: TPoint;
var
cx, cy: Integer;
begin
GetMousePos(cx, cy);
Result := Point(cx, cy);
end;

procedure GetCursorPosWrap(var Pos: TPoint);
begin
Pos := GetCursorPos;
end;

procedure SafeClick(Left: Boolean);
var
cPos: TPoint;
RRange, ReleaseTime: Integer;
begin
GetCursorPosWrap(cPos);
RRange := RandomRange(72, 102);
if(InRange(RRange, 92, 95)) then
RRange := RRange + RandomRange(-7, 7);
ReleaseTime := GetTickCount + RRange;

HoldMouse(cPos.X, cPos.Y, Integer(Left));
while GetTickCount < ReleaseTime do
Sleep(1);
ReleaseMouse(cPos.X, cPos.Y, Integer(Left));
end;

function PointsInAbstract(const TPA: TPointArray; const AbstractBox: TPointArray; const MinCount: Word): Boolean;
var
I, tpaHi, J: Word;
begin
Result := False;

if(Length(AbstractBox) <> 4) then
Exit;

Result := True;
J := 0;
tpaHi := High(TPA);

for I := Low(TPA) to tpaHi do
if(InAbstractBox(AbstractBox[0].X, AbstractBox[0].Y, AbstractBox[1].X, AbstractBox[1].Y, AbstractBox[2].X, AbstractBox[2].Y, AbstractBox[3].X, AbstractBox[3].Y, TPA[I].x, TPA[I].y)) then
begin
Inc(J);

if(J >= MinCount) then
Exit;
end;

Result := False;
end;

function MassMMPointsToMS(const Arr: TPointArray): T2DPointArray;
var
I, arrLength: Integer;
tempPoints: TPointArray;
begin
arrLength := High(Arr);
SetArrayLength(tempPoints, arrLength + 1);
SetArrayLength(Result, arrLength + 1);

for I := 0 to arrLength do
tempPoints[I] := MMToMSEx(0, 0, Arr[I]);

SortCircleWise(tempPoints, MSCX, MSCY, Random(360), True, Boolean(Random(2)));

for I := 0 to arrLength do
Result[I] := GetGridAbstractBox(tempPoints[I]);
end;

function GetMinimapRocks(out Points: TPointArray): Boolean;
begin
Result := FindDTMs(DTM_SYMBOL_ORE, Points, MMX1, MMY1, MMX2, MMY2);
end;

function FindRocksFromMM(out oreBounds: T2DPointArray; const MMFoundPoints: T2DPointArray; var Rock: TOre): Word;
var
tempCTS: Byte;
I, J: Cardinal;

coloursLo, coloursHi, coloursLen, oreBoundsHi: Word;

counterCount: Word;
validAreas: array of Integer;

tempPoints: TPointArray;
tempBox: TBox;
begin
Result := RETURN_NOERROR or RETURN_CALLED;
tempCTS := GetToleranceSpeed;

oreBoundsHi := High(MMFoundPoints);

if(SCRIPT_SEARCH_OWNCOLOUR) then
begin
coloursLen := Length(Rock.Colours);
coloursLo := Low(Rock.Colours);
coloursHi := High(Rock.Colours);

SetColorToleranceSpeed(0);

SetLength(validAreas, 0);

counterCount := 0;

for I := 0 to oreBoundsHi do
begin
tempBox := GetTPABounds(MMFoundPoints[I]);

for J := coloursLo to coloursHi do
begin
if(J = COLOUR_BESTCOLOUR_INDEX) then
Continue;

if(FindColors(tempPoints, Rock.Colours[J], tempBox.x1, tempBox.y1, tempBox.x2, tempBox.y2)) then
if(PointsInAbstract(tempPoints, MMFoundPoints[I])) then
begin
Inc(counterCount);
SetLength(validAreas, counterCount + 1);
validAreas[counterCount] := I;
end;
end;
end;

if(counterCount > 0) then
begin
SetLength(oreBounds, counterCount + 1);
for I := 0 to counterCount do
oreBounds[I] := MMFoundPoints[validAreas[I]];

SetColorToleranceSpeed(tempCTS);

Exit;
end;
end;

Result := Result or RETURN_NOOWNCOLOUR;
counterCount := 0;

SetLength(validAreas, 0);

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(Rock.StandardHS[ROCK_INDEX_HUE], Rock.StandardHS[ROCK_INDEX_SATURATION]);

for I := 0 to oreBoundsHi do
begin
tempBox := GetTPABounds(MMFoundPoints[I]);

if(FindColorTolerance(tempPoints, Rock.Colours[COLOUR_BESTCOLOUR_INDEX], tempBox.x1, tempBox.y1, tempBox.x2, tempBox.y2, Rock.BestColourTol)) then
if(PoinstInAbstract(tempPoints, MMFoundPoints[I])) then
begin
Inc(counterCount);
SetLength(validAreas, counterCount + 1);
validAreas[counterCount] := I;
end;
end;

if(counterCount > 0) then
begin
SetLength(oreBounds, counterCount + 1);
for I := 0 to counterCount do
oreBounds[I] := MMFoundPoints[validAreas[I]];

SetColorToleranceSpeed(tempCTS);

Exit;
end;

Result := Result or RETURN_NOBESTCOLOUR or RETURN_NOCOLOURS;
end;

function FindRockSimple(out oreBounds: T2DPointArray; var Rock: TOre): Word;
var
I, arrHi: Cardinal;

coloursLo, coloursHi, coloursLen: Word;

tempPoints: TPointArray;
tempMultiPoints: T2DPointArray;
begin
Result := RETURN_NOERROR or RETURN_CALLED;
tempCTS := GetToleranceSpeed;

if(SCRIPT_SEARCH_OWNCOLOUR) then
begin
coloursLen := Length(Rock.Colours);
coloursLo := Low(Rock.Colours);
coloursHi := High(Rock.Colours);

SetColorToleranceSpeed(0);

SetLength(tempMultiPoints, coloursLen);

for I := coloursLo to coloursHi do
begin
if(I = COLOUR_BESTCOLOUR_INDEX) then
Continue;

FindColors(tempMultiPoints[I - coloursLo], Rock.Colours[I], MSX1, MSY1, MSX2, MSY2);
end;

MergeATPAWrap(tempMultiPoints, tempPoints);

if(Length(tempMultiPoints) > 0) then
begin
arrHi := High(tempPoints);
for I := 0 to arrHi do
tempPoints[I] := GetGridPos(tempPoints[I]);

ClearDoubleTPA(tempPoints);
SortCircleWise(tempPoints, MMCX, MMCY, Random(360), True, Boolean(Random(2)));

arrHi := High(tempPoints);
SetLength(oreBounds, arrHi + 1);
for I := 0 to arrHi do
oreBounds[I] := GetGridAbstractBox(tempPoints[I]);

SetColorToleranceSpeed(tempCTS);

Exit;
end;
end;

Result := Result or RETURN_NOOWNCOLOUR;

SetColorToleranceSpeed(2);
SetColorspeed2Modifiers(Rock.StandardHS[ROCK_INDEX_HUE], Rock.StandardHS[ROCK_INDEX_SATURATION]);

if(FindColorsTolerance(tempPoints, Rock.Colours[COLOUR_BESTCOLOUR_INDEX], MSX1, MSY1, MSX2, MSY2, Rock.BestColourTol)) then
begin
arrHi := High(tempPoints);
for I := 0 to arrHi do
tempPoints[I] := GetGridPos(tempPoints[I]);

ClearDoubleTPA(tempPoints);
SortCircleWise(tempPoints, MMCX, MMCY, Random(360), True, Boolean(Random(2)));

arrHi := High(tempPoints);
SetLength(oreBounds, arrHi + 1);
for I := 0 to arrHi do
oreBounds[I] := GetGridAbstractBox(tempPoints[I]);

SetColorToleranceSpeed(tempCTS);

Exit;
end;

Result := Result or RETURN_NOBESTCOLOUR or RETURN_NOCOLOURS;

SetColorToleranceSpeed(tempCTS);
end;

function FindRock(out x, y: Integer; var Rock: TOre): Word;
var
pointsMMFound: TPointArray;
pointsMMToGrid, oresFound: T2DPointArray;
tempPoint: TPoint;
tempPointArrBox: TBox;

tempRes: Word;
I, bI, J, Hi, Lo: Word;

tempUpText: AnsiString;
UpTextSearchArr: array of String;
UpTextFoundArr: array of Boolean;
begin
Result := RETURN_NOERROR;
tempRes := RETURN_NOERROR;

if(SCRIPT_SEARCH_MM) then
begin
if(GetMinimapRocks(pointsMMFound)) then
begin
pointsMMToGrid := MassMMPointsToMS(pointsMMFound);

tempRes := FindRocksFromMM(oresFound, pointsMMToGrid, Rock);

Debug('METHOD : FindRocksFromMM', DEBUG_LEVEL_ERROR, 3);
PrintReturnCodes(tempRes, 4);
Result := Result or (RETURN_NOCOLOURS and tempRes);
end else
Result := Result or RETURN_NOMINIMAPROCKS or RETURN_NOCOLOURS;
end else
Result := Result or RETURN_NOCOLOURS;

if((CheckBitwise(Result, RETURN_NOCOLOURS)) or (CheckBitwise(tempRes, RETURN_NOCOLOURS))) then
begin
tempRes := FindRockSimple(oresFound, Rock);

Debug('METHOD : FindRockSimple', DEBUG_LEVEL_ERROR, 3);
PrintReturnCodes(tempRes, 4);
if(CheckBitwise(tempRes, RETURN_NOCOLOURS)) then
begin
Result := Result or RETURN_NOMAINSCRROCKS;
Exit;
end;
end;

Lo := Low(oresFound);

if(SCRIPT_SEARCH_UPTEXT) then
begin
Result := Result or RETURN_NOUPTEXT;

ExplodeWrap('|', SCRIPT_SEARCH_UPTEXT_STR, UpTextSearchArr);

bI := High(UpTextSearchArr);

Hi := High(oresFound);

for J := Lo to Hi do
begin

if(MiddleTPAEx(oresFound[J], tempPoint.X, tempPoint.Y)) then
begin
tempPointArrBox := GetTPABounds(oresFound[J]);
MouseOval(tempPoint.X, tempPoint.Y, Max(tempPointArrBox.X2 - tempPoint.X - ANTIBAN_MOUSERADIIPRECISION, 0), Max(tempPointArrBox.Y2 - tempPoint.Y - ANTIBAN_MOUSERADIIPRECISION, 0), mouse_move);

tempUpText := rs_GetUpText;

for I := 0 to bI do
begin
if(Pos(UpTextSearchArr[I], tempUpText) > 0) then
begin
X := tempPoint.X;
Y := tempPoint.Y;

Result := Result - RETURN_NOUPTEXT;

Exit;
end;
end;
end;

end;
end;

if(not(MiddleTPAEx(oresFound[Lo], X, Y))) then
Result := Result or RETURN_EXCEPTION;
end;

procedure MineBestRock;
begin

end;

begin
end.

BobboHobbo

2012-04-22 09:03:15

Looks neat !