From 2ba9ef04e30f42f966aba243c97dfa1135021930 Mon Sep 17 00:00:00 2001 From: PeridexisErrant Date: Tue, 17 Nov 2015 13:55:43 +0930 Subject: [PATCH] Replace drybuckets plugin with a script Also closes #248, by checking job and building flags. --- NEWS.rst | 4 +++ docs/Plugins.rst | 4 --- plugins/CMakeLists.txt | 1 - plugins/drybuckets.cpp | 52 ------------------------------------- scripts/fix/dry-buckets.lua | 22 ++++++++++++++++ 5 files changed, 26 insertions(+), 57 deletions(-) delete mode 100644 plugins/drybuckets.cpp create mode 100644 scripts/fix/dry-buckets.lua diff --git a/NEWS.rst b/NEWS.rst index 8bec5b809..d3f60beb8 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -36,6 +36,10 @@ Fixes ----- - confirm haul-delete: Fixed issue preventing deletion of stop conditions or using "x" in route names +New Scripts +----------- +- `fix/dry-buckets`: replaces the ``drybuckets`` plugin + DFHack 0.40.24-r4 ================= diff --git a/docs/Plugins.rst b/docs/Plugins.rst index 0cd16a075..c0c049708 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -182,10 +182,6 @@ Shows all items needed for the currently active strange mood. Bugfixes ======== -drybuckets -========== -Removes water from all buckets in your fortress, allowing them to be used for making lye. - fixdiplomats ============ Adds a Diplomat position to all Elven civilizations, allowing them to negotiate diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 115f6196e..aca7d0996 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -115,7 +115,6 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(dig dig.cpp) DFHACK_PLUGIN(digFlood digFlood.cpp) add_subdirectory(diggingInvaders) - DFHACK_PLUGIN(drybuckets drybuckets.cpp) DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(embark-tools embark-tools.cpp) DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua) diff --git a/plugins/drybuckets.cpp b/plugins/drybuckets.cpp deleted file mode 100644 index 711a05928..000000000 --- a/plugins/drybuckets.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Dry Buckets : Remove all "water" objects from buckets scattered around the fortress - -#include "Core.h" -#include "Console.h" -#include "Export.h" -#include "PluginManager.h" - -#include "DataDefs.h" -#include "df/world.h" -#include "df/item.h" -#include "df/builtin_mats.h" - -using std::string; -using std::vector; -using namespace DFHack; -using namespace df::enums; - -DFHACK_PLUGIN("drybuckets"); -REQUIRE_GLOBAL(world); - -command_result df_drybuckets (color_ostream &out, vector & parameters) -{ - if (!parameters.empty()) - return CR_WRONG_USAGE; - - CoreSuspender suspend; - - int dried_total = 0; - for (size_t i = 0; i < world->items.all.size(); i++) - { - df::item *item = world->items.all[i]; - if ((item->getType() == item_type::LIQUID_MISC) && (item->getMaterial() == builtin_mats::WATER)) - { - item->flags.bits.garbage_collect = 1; - dried_total++; - } - } - if (dried_total) - out.print("Done. %d buckets of water marked for emptying.\n", dried_total); - return CR_OK; -} - -DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) -{ - commands.push_back(PluginCommand("drybuckets", "Removes water from buckets.", df_drybuckets)); - return CR_OK; -} - -DFhackCExport command_result plugin_shutdown ( color_ostream &out ) -{ - return CR_OK; -} diff --git a/scripts/fix/dry-buckets.lua b/scripts/fix/dry-buckets.lua new file mode 100644 index 000000000..ddf5302b7 --- /dev/null +++ b/scripts/fix/dry-buckets.lua @@ -0,0 +1,22 @@ +-- Removes water from buckets (for lye-making). +--[[=begin + +fix/dry-buckets +=============== +Removes water from all buckets in your fortress, allowing them +to be used for making lye. Skips buckets in buildings (eg a well), +being carried, or currently used by a job. + +=end]] + +local emptied = 0 +local water_type = dfhack.matinfo.find('WATER').type + +for _,item in ipairs(df.global.world.items.all) do + if item:getMaterial() == water_type and not (item.flags.in_job or item.flags.in_building) then + dfhack.items.remove(item) + emptied = emptied + 1 + end +end + +print('Emptied '..emptied..' buckets.')