pascal Code:
program FindBuildingsTest;
{-------------------------------------------------------------------------------
FindBuildingsTest v2 -- "proof of concept" example to locate Feasting Hall,
Rally Spot, and Barracks buildings using Dynamic Deformable Template Models (or
DDTM's)
Instructions:
1. Drag the target icon from the button bar above onto the flash player client
in your browser.
2. Select 'Town' in Evony.
3. Make sure the building levels are showing and no windows are open.
What is it doing? Searches within a box for a DTM, which is a point described by
a color a certain distance from another point also described by a color. DTMs
can have as many points as necessary. Each point was given a tolerance of 2 for
both size and color, giving a bit of flexability to the model.
Tested on Google Chrome browser with a client size of 1215 x 709 px.
Next step is to modify DDTM routines to use percentages. (All three were created
using DDTM_editor and left as-is, which comes with the SRL resource library
download and is also available seperately.)
Changes:
v2
+ Added a loop to look for Feasting Hall/Inn, Rally Spot, and Barracks in all
cities instead of just the one on the screen. Selects each city starting at the
top, and stops when encounters a blank tile.
! Moved point conversion and DTM functions to seperate files as includes to make
the main block easier to read.
+ Added a compiler instruction to make turning on/off debugging simple.
+ Added additional comments throughout for readability.
+ Added a section for constants to allow tweaking when necessary.
-------------------------------------------------------------------------------}
//Compiler instructions
//{$define debug} //Uncomment for add'l debugging info to be added to output
//Global constants
const
LOAD_WAIT = 2000; //Pause in mS for city to switch and image to reload.
//City Test
CT_COLOR = 10209771;
CT_TOLERANCE = 2;
CT_THRESHOLD = 1;
//Global types
type
TDTMPointDef = TSDTMPointDef;
TDTMPointDefArray = TSDTMPointDefArray;
TDTM = TSDTM;
//Global variables
var
cw, ch : integer; //Client width and height
TownBox : TBox; //Town search bounds
CitiesBox : TBox; //Cities selector area
BlueDDTM, RedDDTM, GreenDDTM : integer; //Template to search for
fx, fy : integer; //Results
i, xs, ys, xe, ye : integer;
{$I Point Conversions.simba}
{$I Building DDTMs.simba}
procedure Init;
begin
GetClientDimensions(cw, ch);
with TownBox do
begin
X1 := PercentToScreenX(5.26748971193416);
Y1 := PercentToScreenY(17.636684303351);
X2 := PercentToScreenX(65.3497942386831);
Y2 := PercentToScreenY(70.8289241622575);
end;
with CitiesBox do
begin
X1 := PercentToScreenX(73.1687242798353);
Y1 := PercentToScreenY(36.8253968253968);
X2 := PercentToScreenX(79.2592592592592);
Y2 := PercentToScreenY(98.342151675485);
end;
BlueDDTM := SetBlueDDTM;
RedDDTM := SetRedDDTM;
GreenDDTM := SetGreenDDTM;
i := 0;
end;
begin
Init; //Run initialization procedure above
ClearDebug; //Clear old from debug window below
ActivateClient; //Make client window active window
with CitiesBox do
begin
xs := X1 + 10;
xe := X2 - 10;
ys := Y1 + ((Y2 - Y1) / 10 * i) + 10;
ye := ys + ((Y2 - Y1) / 10) - 10;
while CountColorTolerance(CT_COLOR, xs, ys, xe, ye, CT_TOLERANCE) < CT_THRESHOLD do
begin
{$ifdef debug}
writeln(format('Search box = (%d, %d, %d, %d), Result = %d',
[xs, ys, xe, ye,
CountColorTolerance(CT_COLOR, xs, ys, xe, ye, CT_TOLERANCE)]));
{$endif}
MoveMouse(xs, ys);
ClickMouse(xs, ys, Mouse_Left);
Sleep(LOAD_WAIT);
//Write # of city, starting at the top.
writeln(format('-+ City #%2d', [i + 1]));
//Search the town for Feasting Hall, Rally Spot, and Barracks
// if successful, return the screen coordinates
// otherwise so something else
with TownBox do
begin
//Line below is how it would look without 'with TownBox' statement
//if FindDTM(BlueDDTM, fx, fy, TownBox.X1, TownBox.Y1, TownBox.X2, TownBox.Y2) then
if FindDTM(BlueDDTM, fx, fy, X1, Y1, X2, Y2) then
writeln(format(' +- Feasting Hall (or perhaps Inn) found at (%d, %d)', [fx, fy]))
else
writeln(' +- No result for Feasting Hall(or Inn).');
if FindDTM(RedDDTM, fx, fy, X1, Y1, X2, Y2) then
writeln(format(' +- Rally Spot found at (%d, %d)', [fx, fy]))
else
writeln(' +- No result for Rally Spot.');
if FindDTM(GreenDDTM, fx, fy, X1, Y1, X2, Y2) then
writeln(format(' +- Barracks found at (%d, %d)', [fx, fy]))
else
writeln(' +- No result for Barracks.');
end; //with TownBox block
//Increment the counter and set box to next city to test
Inc(i);
xs := X1 + 10;
xe := X2 - 10;
ys := Y1 + ((Y2 - Y1) / 10 * i) + 10;
ye := ys + ((Y2 - Y1) / 10) - 10;
end; //while..do loop block
end; //with CitiesBox block
//Free everything
FreeDTM(BlueDDTM);
FreeDTM(RedDDTM);
FreeDTM(GreenDDTM);
end.