re-add add-spatter plugin (minimal changes)

develop
Myk Taylor 2023-04-26 14:39:13 -07:00
parent ba06a8f2bb
commit 9c447e8d45
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
4 changed files with 21 additions and 46 deletions

@ -34,6 +34,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
# Future # Future
## New Plugins ## New Plugins
- `add-spatter`: allow mods to add poisons and magical effects to weapons
## Fixes ## Fixes
- `autoclothing`: eliminate game lag when there are many inventory items in the fort - `autoclothing`: eliminate game lag when there are many inventory items in the fort

@ -2,7 +2,7 @@ add-spatter
=========== ===========
.. dfhack-tool:: .. dfhack-tool::
:summary: Make tagged reactions produce contaminants. :summary: Add poisons and magical effects to weapons.
:tags: unavailable adventure fort gameplay items :tags: unavailable adventure fort gameplay items
:no-command: :no-command:

@ -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. # see instructions for adding "external" plugins at the end of this file.
#dfhack_plugin(3dveins 3dveins.cpp) #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(autobutcher autobutcher.cpp LINK_LIBRARIES lua)
dfhack_plugin(autochop autochop.cpp LINK_LIBRARIES lua) dfhack_plugin(autochop autochop.cpp LINK_LIBRARIES lua)
dfhack_plugin(autoclothing autoclothing.cpp LINK_LIBRARIES lua) dfhack_plugin(autoclothing autoclothing.cpp LINK_LIBRARIES lua)

@ -1,51 +1,26 @@
#include "Core.h" #include "PluginManager.h"
#include <Console.h> #include "VTableInterpose.h"
#include <Export.h>
#include <PluginManager.h> #include "modules/Items.h"
#include <modules/Gui.h> #include "modules/Units.h"
#include <modules/Screen.h>
#include <modules/Maps.h>
#include <modules/Job.h>
#include <modules/Items.h>
#include <modules/Units.h>
#include <TileTypes.h>
#include <vector>
#include <cstdio>
#include <stack>
#include <string>
#include <cmath>
#include <string.h>
#include <VTableInterpose.h>
#include "df/item_liquid_miscst.h"
#include "df/item_constructed.h" #include "df/item_constructed.h"
#include "df/builtin_mats.h"
#include "df/world.h"
#include "df/job.h" #include "df/job.h"
#include "df/job_item.h" #include "df/job_item.h"
#include "df/job_item_ref.h" #include "df/job_item_ref.h"
#include "df/plotinfost.h"
#include "df/report.h"
#include "df/reaction.h" #include "df/reaction.h"
#include "df/reaction_reagent_itemst.h" #include "df/reaction_reagent_itemst.h"
#include "df/reaction_product_item_improvementst.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 "df/spatter.h"
#include "MiscUtils.h"
using std::vector; using std::vector;
using std::string; using std::string;
using std::stack;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
DFHACK_PLUGIN("add-spatter"); DFHACK_PLUGIN("add-spatter");
DFHACK_PLUGIN_IS_ENABLED(is_enabled); DFHACK_PLUGIN_IS_ENABLED(is_enabled);
REQUIRE_GLOBAL(gps);
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(plotinfo);
typedef df::reaction_product_item_improvementst improvement_product; 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); INTERPOSE_HOOK(product_hook, produce).apply(enable);
} }
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) DFhackCExport command_result plugin_load_data (color_ostream &out) {
{ if (find_reactions(out)) {
switch (event) {
case SC_WORLD_LOADED:
if (find_reactions(out))
{
out.print("Detected spatter add reactions - enabling plugin.\n"); out.print("Detected spatter add reactions - enabling plugin.\n");
enable_hooks(true); enable_hooks(true);
} }
else else
enable_hooks(false); enable_hooks(false);
break;
return CR_OK;
}
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{
switch (event) {
case SC_WORLD_UNLOADED: case SC_WORLD_UNLOADED:
enable_hooks(false); enable_hooks(false);
reactions.clear(); 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 <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
if (Core::getInstance().isWorldLoaded())
plugin_onstatechange(out, SC_WORLD_LOADED);
return CR_OK; return CR_OK;
} }