Added exporatory mining patterns tool.

develop
Petr Mrázek 2011-08-17 13:26:03 +02:00
parent 03e3e9002b
commit 09cb6a6828
3 changed files with 367 additions and 3 deletions

@ -25,7 +25,7 @@ set(DF_VERSION_MINOR "31")
set(DF_VERSION_PATCH "25") set(DF_VERSION_PATCH "25")
set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}") set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}")
set(DFHACK_RELEASE "3") set(DFHACK_RELEASE "4")
## where to install things (after the build is done, classic 'make install' or package structure) ## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here: # the dfhack libraries will be installed here:

@ -397,6 +397,8 @@ bool Core::Init()
{ {
if(started) if(started)
return true; return true;
if(errorstate)
return false;
// find out what we are... // find out what we are...
#ifdef LINUX_BUILD #ifdef LINUX_BUILD

@ -16,17 +16,21 @@ using std::stack;
using namespace DFHack; using namespace DFHack;
DFhackCExport command_result vdig (Core * c, vector <string> & parameters); DFhackCExport command_result vdig (Core * c, vector <string> & parameters);
DFhackCExport command_result vdigx (Core * c, vector <string> & parameters);
DFhackCExport command_result autodig (Core * c, vector <string> & parameters); DFhackCExport command_result autodig (Core * c, vector <string> & parameters);
DFhackCExport command_result expdig (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void ) DFhackCExport const char * plugin_name ( void )
{ {
return "vein digger"; return "vdig";
} }
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{ {
commands.clear(); commands.clear();
commands.push_back(PluginCommand("vdig","Dig a whole vein. With 'x' option, dig stairs between z-levels.",vdig)); commands.push_back(PluginCommand("vdig","Dig a whole vein.",vdig));
commands.push_back(PluginCommand("vdigx","Dig a whole vein, follow vein through z-levels with stairs.",vdigx));
commands.push_back(PluginCommand("expdig","Select or designate an exploratory pattern. Use 'expdig ?' for help.",expdig));
//commands.push_back(PluginCommand("autodig","Mark a tile for continuous digging.",autodig)); //commands.push_back(PluginCommand("autodig","Mark a tile for continuous digging.",autodig));
return CR_OK; return CR_OK;
} }
@ -35,6 +39,364 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
{ {
return CR_OK; return CR_OK;
} }
typedef char digmask[16][16];
static digmask diag5[5] =
{
{
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0},
{0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0},
{0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0},
{0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0},
{0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0},
{0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0},
{0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
},
{
{0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0},
{0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0},
{0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0},
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1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
enum explo_how
{
EXPLO_NOTHING,
EXPLO_DIAG5,
EXPLO_LADDER,
EXPLO_CLEAR,
};
enum explo_what
{
EXPLO_ALL,
EXPLO_HIDDEN,
EXPLO_DESIGNATED,
};
DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
{
bool force_help = false;
static explo_how how = EXPLO_NOTHING;
static explo_what what = EXPLO_HIDDEN;
for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "help" || parameters[i] == "?")
{
force_help = true;
}
else if(parameters[i] == "all")
{
what = EXPLO_ALL;
}
else if(parameters[i] == "hidden")
{
what = EXPLO_HIDDEN;
}
else if(parameters[i] == "designated")
{
what = EXPLO_DESIGNATED;
}
else if(parameters[i] == "diag5")
{
how = EXPLO_DIAG5;
}
else if(parameters[i] == "clear")
{
how = EXPLO_CLEAR;
}
else if(parameters[i] == "ladder")
{
how = EXPLO_LADDER;
}
}
if(force_help || how == EXPLO_NOTHING)
{
c->con.print("This command can be used for exploratory mining.\n"
"http://df.magmawiki.com/index.php/DF2010:Exploratory_mining\n"
"\n"
"There are two variables that can be set: pattern and filter.\n"
"Patterns:\n"
" diag5 = diagonals separated by 5 tiles\n"
" ladder = A 'ladder' pattern\n"
" clear = Just remove all dig designations\n"
"Filters:\n"
" all = designate whole z-level\n"
" hidden = designate only hidden tiles of z-level (default)\n"
" designated = Take current designation and apply pattern to it.\n"
"\n"
"After you have a pattern set, you can use 'expdig' to apply it:\n"
"'expdig diag5 hidden' = set filter to hidden, pattern to diag5.\n"
"'expdig' = apply the pattern with filter.\n"
);
return CR_OK;
}
c->Suspend();
Gui * gui = c->getGui();
Maps * maps = c->getMaps();
uint32_t x_max, y_max, z_max;
if(!maps->Start())
{
c->Resume();
c->con.printerr("Can't init the map...\n");
return CR_FAILURE;
}
maps->getSize(x_max,y_max,z_max);
int32_t xzzz,yzzz,z_level;
if(!gui->getViewCoords(xzzz,yzzz,z_level))
{
c->Resume();
c->con.printerr("Can't get view coords...\n");
return CR_FAILURE;
}
auto apply = [&](uint32_t bx, uint32_t by, digmask & dm) -> bool
{
df_block * bl = maps->getBlock(bx,by,z_level);
if(!bl)
return false;
int x = 0,mx = 16;
if(bx == 0)
x = 1;
if(bx == x_max - 1)
mx = 15;
for(; x < mx; x++)
{
int y = 0,my = 16;
if(by == 0)
y = 1;
if(by == y_max - 1)
my = 15;
for(; y < my; y++)
{
naked_designation & des = bl->designation[x][y].bits;
short unsigned int tt = bl->tiletype[x][y];
// could be potentially used to locate hidden constructions?
if(tileMaterial(tt) == CONSTRUCTED && !des.hidden)
continue;
if(!isWallTerrain(tt) && !des.hidden)
continue;
if(how == EXPLO_CLEAR)
{
des.dig = designation_no;
continue;
}
if(dm[y][x])
{
if(what == EXPLO_ALL
|| des.dig == designation_default && what == EXPLO_DESIGNATED
|| des.hidden && what == EXPLO_HIDDEN)
{
des.dig = designation_default;
}
}
else if(what == EXPLO_DESIGNATED)
{
des.dig = designation_no;
}
}
}
bl->flags.set(BLOCK_DESIGNATED);
return true;
};
if(how == EXPLO_DIAG5)
{
int which;
for(uint32_t x = 0; x < x_max; x++)
{
for(int32_t y = 0 ; y < y_max; y++)
{
which = (4*x + y) % 5;
apply(x,y_max - 1 - y,diag5[which]);
}
}
}
else if(how == EXPLO_LADDER)
{
int which;
for(uint32_t x = 0; x < x_max; x++)
{
which = x % 3;
for(int32_t y = 0 ; y < y_max; y++)
{
apply(x,y,ladder[which]);
}
}
}
else for(uint32_t x = 0; x < x_max; x++)
for(int32_t y = 0 ; y < y_max; y++)
apply(x,y,all_tiles);
c->Resume();
return CR_OK;
}
DFhackCExport command_result vdigx (Core * c, vector <string> & parameters)
{
for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "help" || parameters[i] == "?")
{
c->con.print("Designates a whole vein under the cursor for digging.\n"
"Also follows the vein between z-levels with stairs, like 'vdig x' would.\n"
);
return CR_OK;
}
}
vector <string> lol;
lol.push_back("x");
return vdig(c,lol);
}
DFhackCExport command_result vdig (Core * c, vector <string> & parameters) DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
{ {