From 9c447e8d45479c14d5a29113446c85360db70709 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 26 Apr 2023 14:39:13 -0700 Subject: [PATCH] re-add add-spatter plugin (minimal changes) --- docs/changelog.txt | 1 + docs/plugins/add-spatter.rst | 2 +- plugins/CMakeLists.txt | 2 +- plugins/add-spatter.cpp | 62 +++++++++++------------------------- 4 files changed, 21 insertions(+), 46 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 91f25a323..25391f081 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -34,6 +34,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future ## New Plugins +- `add-spatter`: allow mods to add poisons and magical effects to weapons ## Fixes - `autoclothing`: eliminate game lag when there are many inventory items in the fort diff --git a/docs/plugins/add-spatter.rst b/docs/plugins/add-spatter.rst index 6914690ea..2c43a88ef 100644 --- a/docs/plugins/add-spatter.rst +++ b/docs/plugins/add-spatter.rst @@ -2,7 +2,7 @@ add-spatter =========== .. dfhack-tool:: - :summary: Make tagged reactions produce contaminants. + :summary: Add poisons and magical effects to weapons. :tags: unavailable adventure fort gameplay items :no-command: diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 97216ad50..8aadd46f2 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -74,7 +74,7 @@ set_source_files_properties( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE ) # see instructions for adding "external" plugins at the end of this file. #dfhack_plugin(3dveins 3dveins.cpp) -#dfhack_plugin(add-spatter add-spatter.cpp) +dfhack_plugin(add-spatter add-spatter.cpp) dfhack_plugin(autobutcher autobutcher.cpp LINK_LIBRARIES lua) dfhack_plugin(autochop autochop.cpp LINK_LIBRARIES lua) dfhack_plugin(autoclothing autoclothing.cpp LINK_LIBRARIES lua) diff --git a/plugins/add-spatter.cpp b/plugins/add-spatter.cpp index 451fffabf..3cfefce39 100644 --- a/plugins/add-spatter.cpp +++ b/plugins/add-spatter.cpp @@ -1,51 +1,26 @@ -#include "Core.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "df/item_liquid_miscst.h" +#include "PluginManager.h" +#include "VTableInterpose.h" + +#include "modules/Items.h" +#include "modules/Units.h" + #include "df/item_constructed.h" -#include "df/builtin_mats.h" -#include "df/world.h" #include "df/job.h" #include "df/job_item.h" #include "df/job_item_ref.h" -#include "df/plotinfost.h" -#include "df/report.h" #include "df/reaction.h" #include "df/reaction_reagent_itemst.h" #include "df/reaction_product_item_improvementst.h" -#include "df/reaction_product_improvement_flags.h" -#include "df/matter_state.h" #include "df/spatter.h" -#include "MiscUtils.h" - using std::vector; using std::string; -using std::stack; + using namespace DFHack; using namespace df::enums; DFHACK_PLUGIN("add-spatter"); DFHACK_PLUGIN_IS_ENABLED(is_enabled); -REQUIRE_GLOBAL(gps); -REQUIRE_GLOBAL(world); -REQUIRE_GLOBAL(plotinfo); typedef df::reaction_product_item_improvementst improvement_product; @@ -397,18 +372,20 @@ static void enable_hooks(bool enable) INTERPOSE_HOOK(product_hook, produce).apply(enable); } +DFhackCExport command_result plugin_load_data (color_ostream &out) { + if (find_reactions(out)) { + out.print("Detected spatter add reactions - enabling plugin.\n"); + enable_hooks(true); + } + else + enable_hooks(false); + + return CR_OK; +} + DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) { switch (event) { - case SC_WORLD_LOADED: - if (find_reactions(out)) - { - out.print("Detected spatter add reactions - enabling plugin.\n"); - enable_hooks(true); - } - else - enable_hooks(false); - break; case SC_WORLD_UNLOADED: enable_hooks(false); reactions.clear(); @@ -423,9 +400,6 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - if (Core::getInstance().isWorldLoaded()) - plugin_onstatechange(out, SC_WORLD_LOADED); - return CR_OK; }