add external api: dig_now_tile(out, pos)

develop
myk002 2021-06-27 18:00:26 -07:00
parent 1a19c3a944
commit fc19fb6785
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 40 additions and 14 deletions

@ -2,6 +2,8 @@
* Simulates completion of dig designations. * Simulates completion of dig designations.
*/ */
#include "dig-now.h"
#include "DataFuncs.h" #include "DataFuncs.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "TileTypes.h" #include "TileTypes.h"
@ -790,25 +792,16 @@ static void print_help(color_ostream &out) {
} }
} }
command_result dig_now(color_ostream &out, std::vector<std::string> &params) { bool dig_now_impl(color_ostream &out, const dig_now_options &options) {
CoreSuspender suspend;
dig_now_options options;
if (!get_options(out, options, params) || options.help)
{
print_help(out);
return options.help ? CR_OK : CR_FAILURE;
}
if (!Maps::IsValid()) { if (!Maps::IsValid()) {
out.printerr("Map is not available!\n"); out.printerr("Map is not available!\n");
return CR_FAILURE; return false;
} }
// required for boulder generation // required for boulder generation
if (world->units.active.size() == 0) { if (world->units.active.size() == 0) {
out.printerr("At least one unit must be alive!\n"); out.printerr("At least one unit must be alive!\n");
return CR_FAILURE; return false;
} }
// track which positions were modified and where to produce items // track which positions were modified and where to produce items
@ -817,12 +810,25 @@ command_result dig_now(color_ostream &out, std::vector<std::string> &params) {
do_dig(out, dug_coords, item_coords, options); do_dig(out, dug_coords, item_coords, options);
create_boulders(out, item_coords, options); create_boulders(out, item_coords, options);
post_process_dug_tiles (out, dug_coords); post_process_dug_tiles(out, dug_coords);
// force the game to recompute its walkability cache // force the game to recompute its walkability cache
world->reindex_pathfinding = true; world->reindex_pathfinding = true;
return CR_OK; return true;
}
command_result dig_now(color_ostream &out, std::vector<std::string> &params) {
CoreSuspender suspend;
dig_now_options options;
if (!get_options(out, options, params) || options.help)
{
print_help(out);
return options.help ? CR_OK : CR_FAILURE;
}
return dig_now_impl(out, options) ? CR_OK : CR_FAILURE;
} }
DFhackCExport command_result plugin_init(color_ostream &, DFhackCExport command_result plugin_init(color_ostream &,
@ -835,3 +841,14 @@ DFhackCExport command_result plugin_init(color_ostream &,
DFhackCExport command_result plugin_shutdown(color_ostream &) { DFhackCExport command_result plugin_shutdown(color_ostream &) {
return CR_OK; return CR_OK;
} }
// External API
// runs dig-now for the specified tile. default options apply.
bool dig_now_tile (color_ostream& out, const DFCoord& pos)
{
dig_now_options options;
options.start = pos;
options.end = pos;
return dig_now_impl(out, options);
}

@ -0,0 +1,9 @@
#pragma once
#include "ColorText.h"
#include "modules/Maps.h"
/**
* Runs dig-now for the specified tile. Default options apply.
*/
bool dig_now_tile(DFHack::color_ostream &out, const DFHack::DFCoord &pos);