From fc19fb678501a4a568f9d429a93e4c8e8252b64e Mon Sep 17 00:00:00 2001 From: myk002 Date: Sun, 27 Jun 2021 18:00:26 -0700 Subject: [PATCH] add external api: dig_now_tile(out, pos) --- plugins/dig-now.cpp | 45 +++++++++++++++++++++++++++++++-------------- plugins/dig-now.h | 9 +++++++++ 2 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 plugins/dig-now.h diff --git a/plugins/dig-now.cpp b/plugins/dig-now.cpp index e583168fc..968f35815 100644 --- a/plugins/dig-now.cpp +++ b/plugins/dig-now.cpp @@ -2,6 +2,8 @@ * Simulates completion of dig designations. */ +#include "dig-now.h" + #include "DataFuncs.h" #include "PluginManager.h" #include "TileTypes.h" @@ -790,25 +792,16 @@ static void print_help(color_ostream &out) { } } -command_result dig_now(color_ostream &out, std::vector ¶ms) { - CoreSuspender suspend; - - dig_now_options options; - if (!get_options(out, options, params) || options.help) - { - print_help(out); - return options.help ? CR_OK : CR_FAILURE; - } - +bool dig_now_impl(color_ostream &out, const dig_now_options &options) { if (!Maps::IsValid()) { out.printerr("Map is not available!\n"); - return CR_FAILURE; + return false; } // required for boulder generation if (world->units.active.size() == 0) { 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 @@ -817,12 +810,25 @@ command_result dig_now(color_ostream &out, std::vector ¶ms) { do_dig(out, dug_coords, 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 world->reindex_pathfinding = true; - return CR_OK; + return true; +} + +command_result dig_now(color_ostream &out, std::vector ¶ms) { + 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 &, @@ -835,3 +841,14 @@ DFhackCExport command_result plugin_init(color_ostream &, DFhackCExport command_result plugin_shutdown(color_ostream &) { 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); +} diff --git a/plugins/dig-now.h b/plugins/dig-now.h new file mode 100644 index 000000000..1ed9c84e4 --- /dev/null +++ b/plugins/dig-now.h @@ -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);