diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index f0b35ea9ef..1e27144f0b 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -97,7 +97,7 @@ if(BUILD_SUPPORTED) dfhack_plugin(changeitem changeitem.cpp) dfhack_plugin(changelayer changelayer.cpp) dfhack_plugin(changevein changevein.cpp) - #add_subdirectory(channel-safely) + add_subdirectory(channel-safely) dfhack_plugin(cleanconst cleanconst.cpp) dfhack_plugin(cleaners cleaners.cpp) dfhack_plugin(cleanowned cleanowned.cpp) diff --git a/plugins/channel-safely/CMakeLists.txt b/plugins/channel-safely/CMakeLists.txt index 36c7307e45..3debd754cf 100644 --- a/plugins/channel-safely/CMakeLists.txt +++ b/plugins/channel-safely/CMakeLists.txt @@ -2,6 +2,7 @@ project(channel-safely) include_directories(include) SET(SOURCES + dwarves-onbreak.cpp channel-groups.cpp channel-manager.cpp channel-safely-plugin.cpp) diff --git a/plugins/channel-safely/channel-groups.cpp b/plugins/channel-safely/channel-groups.cpp index c1a5b5953f..9480366def 100644 --- a/plugins/channel-safely/channel-groups.cpp +++ b/plugins/channel-safely/channel-groups.cpp @@ -1,11 +1,9 @@ #include -#include #include -#include +#include +#include #include -#include - // iterates the DF job list and adds channel jobs to the `jobs` container void ChannelJobs::load_channel_jobs() { locations.clear(); diff --git a/plugins/channel-safely/channel-manager.cpp b/plugins/channel-safely/channel-manager.cpp index 67f8742b38..80e41c271b 100644 --- a/plugins/channel-safely/channel-manager.cpp +++ b/plugins/channel-safely/channel-manager.cpp @@ -1,9 +1,8 @@ -#include -#include #include - -#include //hash function for df::coord +#include +#include #include +#include #define NUMARGS(...) std::tuple_size::value #define d_assert(condition, ...) \ @@ -182,7 +181,7 @@ bool ChannelManager::manage_one(const df::coord &map_pos, bool set_marker_mode, } if (marker_mode) { if (jobs.count(map_pos)) { - cancel_job(map_pos); + cancel_job(jobs.find_job(map_pos)); } } else if (!block->flags.bits.designated) { block->flags.bits.designated = true; diff --git a/plugins/channel-safely/channel-safely-plugin.cpp b/plugins/channel-safely/channel-safely-plugin.cpp index 679fab24d4..4558723fb3 100644 --- a/plugins/channel-safely/channel-safely-plugin.cpp +++ b/plugins/channel-safely/channel-safely-plugin.cpp @@ -53,25 +53,19 @@ This skeletal logic has not been kept up-to-date since ~v0.5 -> NoDesignation: manage tile below */ -#include "plugin.h" -#include "inlines.h" -#include "channel-manager.h" -#include "tile-cache.h" -#include -#include - -#include -#include +#include +#include +#include +#include +#include #include #include -#include -#include +#include +#include +#include -#include -#include -#include // Debugging namespace DFHack { @@ -90,6 +84,8 @@ namespace EM = EventManager; using namespace DFHack; using namespace EM::EventType; +std::unique_ptr HandleEnablingMining; + int32_t mapx, mapy, mapz; Configuration config; PersistentDataItem psetting; @@ -314,7 +310,7 @@ namespace CSP { return; } switch (report->type) { - case announcement_type::CANCEL_JOB: + case announcement_type::announcement_type::CANCEL_JOB: if (config.insta_dig) { if (report->text.find("cancels Dig") != std::string::npos || report->text.find("path") != std::string::npos) { @@ -444,8 +440,8 @@ namespace CSP { // prevent algorithm from re-enabling designation for (auto &be: Maps::getBlock(job->pos)->block_events) { - if (auto bsedp = virtual_cast( - be)) { + if (auto bsedp = + virtual_cast(be)) { df::coord local(job->pos); local.x = local.x % 16; local.y = local.y % 16; @@ -498,7 +494,12 @@ namespace CSP { command_result channel_safely(color_ostream &out, std::vector ¶meters); +void reset_mining_labor(color_ostream&, void*) { + +} + DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { + HandleEnablingMining = std::make_unique(plugin_self, reset_mining_labor, 2); commands.push_back(PluginCommand("channel-safely", "Automatically manage channel designations.", channel_safely, diff --git a/plugins/channel-safely/include/inlines.h b/plugins/channel-safely/include/inlines.h index 362fd927a3..7ccc8724f4 100644 --- a/plugins/channel-safely/include/inlines.h +++ b/plugins/channel-safely/include/inlines.h @@ -1,16 +1,15 @@ #pragma once -#include "plugin.h" -#include "channel-manager.h" +#include +#include +#include +#include +#include #include -#include -#include -#include +#include #include - -#include -#include -#include +#include +#include #define Coord(id) (id).x][(id).y #define COORD "%" PRIi16 ",%" PRIi16 ",%" PRIi16 @@ -195,9 +194,9 @@ inline void cancel_job(df::job* job) { df::tile_designation &designation = job_block->designation[x][y]; auto type = job->job_type; ChannelManager::Get().jobs.erase(pos); - Job::removeWorker(job); - Job::removePostings(job, true); - Job::removeJob(job); + auto unit = Job::getWorker(job); + unit->status.labors[0] = false; + DwarvesOnBreak::register_dwarf(unit); job_block->flags.bits.designated = true; job_block->occupancy[x][y].bits.dig_marked = true; switch (type) { @@ -226,11 +225,6 @@ inline void cancel_job(df::job* job) { } } -inline void cancel_job(const df::coord &map_pos) { - cancel_job(ChannelManager::Get().jobs.find_job(map_pos)); - ChannelManager::Get().jobs.erase(map_pos); -} - // executes dig designations for the specified tile coordinates inline bool dig_now(color_ostream &out, const df::coord &map_pos) { static std::default_random_engine rng;