diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index ba5b76b62..663dde90a 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -27,6 +27,7 @@ distribution. #include "Export.h" #include "Hooks.h" #include "ColorText.h" +#include "MiscUtils.h" #include #include #include diff --git a/plugins/add-spatter.cpp b/plugins/add-spatter.cpp index 52e95e88b..cb2858d06 100644 --- a/plugins/add-spatter.cpp +++ b/plugins/add-spatter.cpp @@ -41,14 +41,13 @@ using std::stack; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::world; -using df::global::ui; - -typedef df::reaction_product_item_improvementst improvement_product; - DFHACK_PLUGIN("add-spatter"); DFHACK_PLUGIN_IS_ENABLED(is_enabled); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); + +typedef df::reaction_product_item_improvementst improvement_product; struct ReagentSource { int idx; diff --git a/plugins/advtools.cpp b/plugins/advtools.cpp index ad50dbe5d..8f613d1cc 100644 --- a/plugins/advtools.cpp +++ b/plugins/advtools.cpp @@ -37,14 +37,15 @@ using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui_advmode; - using df::nemesis_record; using df::historical_figure; using namespace DFHack::Translation; +DFHACK_PLUGIN("advtools"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui_advmode); + /********************* * PLUGIN INTERFACE * *********************/ @@ -54,8 +55,6 @@ static bool bodyswap_hotkey(df::viewscreen *top); command_result adv_bodyswap (color_ostream &out, std::vector & parameters); command_result adv_tools (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("advtools"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { if (!ui_advmode) diff --git a/plugins/autochop.cpp b/plugins/autochop.cpp index 5dab8f69b..ee5f6c492 100644 --- a/plugins/autochop.cpp +++ b/plugins/autochop.cpp @@ -36,12 +36,10 @@ using std::set; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; - #define PLUGIN_VERSION 0.3 DFHACK_PLUGIN("autochop"); - +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); static bool autochop_enabled = false; static int min_logs, max_logs; diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index dcbc7c083..efb58a10c 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -34,10 +34,10 @@ using namespace df::enums; using MapExtras::Block; using MapExtras::MapCache; -using df::global::world; using df::building_stockpilest; DFHACK_PLUGIN("autodump"); +REQUIRE_GLOBAL(world); // Stockpile interface START static const string PERSISTENCE_KEY = "autodump/stockpiles"; diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index ad7992038..c1dfc5d2e 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -44,8 +44,10 @@ using std::endl; using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::ui; -using df::global::world; + +DFHACK_PLUGIN("autolabor"); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(world); #define ARRAY_COUNT(array) (sizeof(array)/sizeof((array)[0])) @@ -91,10 +93,6 @@ enum ConfigFlags { // mostly to allow having the mandatory stuff on top of the file and commands on the bottom command_result autolabor (color_ostream &out, std::vector & parameters); -// A plugin must be able to return its name and version. -// The name string provided must correspond to the filename - autolabor.plug.so or autolabor.plug.dll in this case -DFHACK_PLUGIN("autolabor"); - static void generate_labor_to_skill_map(); enum labor_mode { diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index b795622d9..b49b04ee8 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -43,11 +43,11 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::ui; -using df::global::ui_build_selector; DFHACK_PLUGIN("automaterial"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); struct MaterialDescriptor { diff --git a/plugins/automelt.cpp b/plugins/automelt.cpp index 042d8e082..ccbf3489c 100644 --- a/plugins/automelt.cpp +++ b/plugins/automelt.cpp @@ -14,13 +14,13 @@ #include "modules/World.h" #include "df/item_quality.h" -using df::global::world; -using df::global::cursor; -using df::global::ui; using df::building_stockpilest; DFHACK_PLUGIN("automelt"); #define PLUGIN_VERSION 0.3 +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); +REQUIRE_GLOBAL(ui); static const string PERSISTENCE_KEY = "automelt/stockpiles"; diff --git a/plugins/autotrade.cpp b/plugins/autotrade.cpp index e6156b0c3..e238cc514 100644 --- a/plugins/autotrade.cpp +++ b/plugins/autotrade.cpp @@ -19,12 +19,12 @@ #include "df/mandate.h" #include "modules/Maps.h" -using df::global::world; -using df::global::cursor; -using df::global::ui; using df::building_stockpilest; DFHACK_PLUGIN("autotrade"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); +REQUIRE_GLOBAL(ui); static const string PERSISTENCE_KEY = "autotrade/stockpiles"; diff --git a/plugins/building-hacks.cpp b/plugins/building-hacks.cpp index d56215fda..152e4568b 100644 --- a/plugins/building-hacks.cpp +++ b/plugins/building-hacks.cpp @@ -24,9 +24,10 @@ using namespace DFHack; using namespace df::enums; -using df::global::world; DFHACK_PLUGIN("building-hacks"); +REQUIRE_GLOBAL(world); + struct graphic_tile //could do just 31x31 and be done, but it's nicer to have flexible imho. { int16_t tile; //originally uint8_t but we need to indicate non-animated tiles diff --git a/plugins/buildingplan.cpp b/plugins/buildingplan.cpp index d916ba2e3..e9bb6eda4 100644 --- a/plugins/buildingplan.cpp +++ b/plugins/buildingplan.cpp @@ -35,12 +35,11 @@ #include "df/building.h" #include "df/building_doorst.h" -using df::global::ui; -using df::global::ui_build_selector; -using df::global::world; - DFHACK_PLUGIN("buildingplan"); #define PLUGIN_VERSION 0.14 +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); +REQUIRE_GLOBAL(world); struct MaterialDescriptor { diff --git a/plugins/burrows.cpp b/plugins/burrows.cpp index 214fb0582..87adbe734 100644 --- a/plugins/burrows.cpp +++ b/plugins/burrows.cpp @@ -37,9 +37,10 @@ using namespace DFHack; using namespace df::enums; using namespace dfproto; -using df::global::ui; -using df::global::world; -using df::global::gamemode; +DFHACK_PLUGIN("burrows"); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(gamemode); /* * Initialization. @@ -47,8 +48,6 @@ using df::global::gamemode; static command_result burrow(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("burrows"); - static void init_map(color_ostream &out); static void deinit_map(color_ostream &out); diff --git a/plugins/catsplosion.cpp b/plugins/catsplosion.cpp index 1c323de22..725aaf492 100644 --- a/plugins/catsplosion.cpp +++ b/plugins/catsplosion.cpp @@ -25,11 +25,11 @@ using namespace std; #include using namespace DFHack; -using df::global::world; - -command_result catsplosion (color_ostream &out, std::vector & parameters); DFHACK_PLUGIN("catsplosion"); +REQUIRE_GLOBAL(world); + +command_result catsplosion (color_ostream &out, std::vector & parameters); // Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) diff --git a/plugins/changeitem.cpp b/plugins/changeitem.cpp index 9c0a55ad9..b73f24097 100644 --- a/plugins/changeitem.cpp +++ b/plugins/changeitem.cpp @@ -31,9 +31,9 @@ using namespace df::enums; using MapExtras::Block; using MapExtras::MapCache; -using df::global::world; DFHACK_PLUGIN("changeitem"); +REQUIRE_GLOBAL(world); command_result df_changeitem(color_ostream &out, vector & parameters); diff --git a/plugins/changelayer.cpp b/plugins/changelayer.cpp index 3ab1899af..727fae56c 100644 --- a/plugins/changelayer.cpp +++ b/plugins/changelayer.cpp @@ -28,8 +28,9 @@ using namespace std; using std::vector; using std::string; -using df::global::world; -using df::global::cursor; +DFHACK_PLUGIN("changelayer"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); const string changelayer_help = " Allows to change the material of whole geology layers.\n" @@ -83,8 +84,6 @@ const string changelayer_trouble = command_result changelayer (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("changelayer"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/changevein.cpp b/plugins/changevein.cpp index 1d08cfeaf..9c17af292 100644 --- a/plugins/changevein.cpp +++ b/plugins/changevein.cpp @@ -15,8 +15,9 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; +DFHACK_PLUGIN("changevein"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); command_result df_changevein (color_ostream &out, vector & parameters) { @@ -77,8 +78,6 @@ command_result df_changevein (color_ostream &out, vector & parameters) return CR_OK; } -DFHACK_PLUGIN("changevein"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("changevein", diff --git a/plugins/cleanconst.cpp b/plugins/cleanconst.cpp index 3efdadecb..2d5bf77f6 100644 --- a/plugins/cleanconst.cpp +++ b/plugins/cleanconst.cpp @@ -16,9 +16,8 @@ using namespace std; using namespace DFHack; -using df::global::world; - DFHACK_PLUGIN("cleanconst"); +REQUIRE_GLOBAL(world); command_result df_cleanconst(color_ostream &out, vector & parameters) { diff --git a/plugins/cleaners.cpp b/plugins/cleaners.cpp index ab1ccda2b..953ff5305 100644 --- a/plugins/cleaners.cpp +++ b/plugins/cleaners.cpp @@ -18,10 +18,9 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; - DFHACK_PLUGIN("cleaners"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); command_result cleanmap (color_ostream &out, bool snow, bool mud, bool item_spatter) { diff --git a/plugins/cleanowned.cpp b/plugins/cleanowned.cpp index 28314d3f0..4dd3fd212 100644 --- a/plugins/cleanowned.cpp +++ b/plugins/cleanowned.cpp @@ -23,12 +23,11 @@ using namespace std; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("cleanowned"); +REQUIRE_GLOBAL(world); command_result df_cleanowned (color_ostream &out, vector & parameters); -DFHACK_PLUGIN("cleanowned"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/colonies.cpp b/plugins/colonies.cpp index 3ebfc324c..bea595bf9 100644 --- a/plugins/colonies.cpp +++ b/plugins/colonies.cpp @@ -14,6 +14,7 @@ using namespace DFHack; command_result colonies (color_ostream &out, vector & parameters); DFHACK_PLUGIN("colonies"); +REQUIRE_GLOBAL(world); // used by Materials DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp index cf1e78763..bc3b89610 100644 --- a/plugins/command-prompt.cpp +++ b/plugins/command-prompt.cpp @@ -22,9 +22,10 @@ using namespace DFHack; using namespace df::enums; -using df::global::ui; -using df::global::gps; -using df::global::enabler; +DFHACK_PLUGIN("command-prompt"); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(enabler); std::vector command_history; @@ -303,7 +304,7 @@ void viewscreen_commandpromptst::feed(std::set *events) frame = 0; } -DFHACK_PLUGIN("command-prompt"); + command_result show_prompt(color_ostream &out, std::vector & parameters) { if (Gui::getCurFocus() == "dfhack/commandprompt") diff --git a/plugins/createitem.cpp b/plugins/createitem.cpp index 89c2ade36..c4c0c6ebb 100644 --- a/plugins/createitem.cpp +++ b/plugins/createitem.cpp @@ -31,11 +31,10 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; -using df::global::gametype; - DFHACK_PLUGIN("createitem"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(gametype); int dest_container = -1, dest_building = -1; diff --git a/plugins/cursecheck.cpp b/plugins/cursecheck.cpp index f7c6d2fd9..dc7fd2f3c 100644 --- a/plugins/cursecheck.cpp +++ b/plugins/cursecheck.cpp @@ -48,12 +48,12 @@ using std::vector; using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; - -command_result cursecheck (color_ostream &out, vector & parameters); DFHACK_PLUGIN("cursecheck"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); + +command_result cursecheck (color_ostream &out, vector & parameters); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { diff --git a/plugins/deramp.cpp b/plugins/deramp.cpp index e5d0331d9..dc2651db7 100644 --- a/plugins/deramp.cpp +++ b/plugins/deramp.cpp @@ -14,9 +14,8 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; - DFHACK_PLUGIN("deramp"); +REQUIRE_GLOBAL(world); command_result df_deramp (color_ostream &out, vector & parameters) { diff --git a/plugins/dfstream.cpp b/plugins/dfstream.cpp index 19334abae..c8e99d678 100644 --- a/plugins/dfstream.cpp +++ b/plugins/dfstream.cpp @@ -18,8 +18,10 @@ using namespace df::enums; using std::string; using std::vector; -using df::global::gps; -using df::global::enabler; + +DFHACK_PLUGIN("dfstream"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(enabler); // The error messages are taken from the clsocket source code const char * translate_socket_error(CSimpleSocket::CSocketError err) { @@ -283,8 +285,6 @@ public: } }; -DFHACK_PLUGIN("dfstream"); - inline df::renderer *& active_renderer() { return enabler->renderer; } diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 082e6a04a..922a47477 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -27,6 +27,7 @@ command_result digcircle (color_ostream &out, vector & parameters); command_result digtype (color_ostream &out, vector & parameters); DFHACK_PLUGIN("dig"); +REQUIRE_GLOBAL(world); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { diff --git a/plugins/digFlood.cpp b/plugins/digFlood.cpp index 1646f4deb..170427bf6 100644 --- a/plugins/digFlood.cpp +++ b/plugins/digFlood.cpp @@ -21,14 +21,11 @@ using namespace DFHack; using namespace std; -using df::global::world; -// using df::global::process_jobs; -// using df::global::process_dig; +DFHACK_PLUGIN("digFlood"); +REQUIRE_GLOBAL(world); command_result digFlood (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("digFlood"); - void onDig(color_ostream& out, void* ptr); void maybeExplore(color_ostream& out, MapExtras::MapCache& cache, df::coord pt, set& jobLocations); EventManager::EventHandler digHandler(onDig, 0); diff --git a/plugins/diggingInvaders/diggingInvaders.cpp b/plugins/diggingInvaders/diggingInvaders.cpp index 48c34d5d4..cd171f527 100644 --- a/plugins/diggingInvaders/diggingInvaders.cpp +++ b/plugins/diggingInvaders/diggingInvaders.cpp @@ -77,6 +77,7 @@ void findAndAssignInvasionJob(color_ostream& out, void*); DFHACK_PLUGIN_IS_ENABLED(enabled); DFHACK_PLUGIN("diggingInvaders"); +REQUIRE_GLOBAL(world); //TODO: when world unloads static int32_t lastInvasionJob=-1; @@ -386,8 +387,8 @@ void findAndAssignInvasionJob(color_ostream& out, void* tickTime) { unordered_set localConnectivity; //find all locals and invaders - for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) { - df::unit* unit = df::global::world->units.all[a]; + for ( size_t a = 0; a < world->units.all.size(); a++ ) { + df::unit* unit = world->units.all[a]; if ( unit->flags1.bits.dead ) continue; if ( Units::isCitizen(unit) ) { @@ -597,7 +598,7 @@ void findAndAssignInvasionJob(color_ostream& out, void* tickTime) { lastInvasionDigger = firstInvader->id; lastInvasionJob = firstInvader->job.current_job ? firstInvader->job.current_job->id : -1; invaderJobs.erase(lastInvasionJob); - for ( df::job_list_link* link = &df::global::world->job_list; link != NULL; link = link->next ) { + for ( df::job_list_link* link = &world->job_list; link != NULL; link = link->next ) { if ( link->item == NULL ) continue; df::job* job = link->item; diff --git a/plugins/drybuckets.cpp b/plugins/drybuckets.cpp index e54d2b90c..711a05928 100644 --- a/plugins/drybuckets.cpp +++ b/plugins/drybuckets.cpp @@ -15,9 +15,8 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; - DFHACK_PLUGIN("drybuckets"); +REQUIRE_GLOBAL(world); command_result df_drybuckets (color_ostream &out, vector & parameters) { diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index cda764f54..8a90b3378 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -43,9 +43,11 @@ using std::deque; -using df::global::current_weather; -using df::global::world; -using df::global::ui; +DFHACK_PLUGIN("dwarfmonitor"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); +REQUIRE_GLOBAL(current_weather); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); typedef int16_t activity_type; @@ -1775,9 +1777,6 @@ struct dwarf_monitor_hook : public df::viewscreen_dwarfmodest IMPLEMENT_VMETHOD_INTERPOSE(dwarf_monitor_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(dwarf_monitor_hook, render); -DFHACK_PLUGIN("dwarfmonitor"); -DFHACK_PLUGIN_IS_ENABLED(is_enabled); - static bool set_monitoring_mode(const string &mode, const bool &state) { bool mode_recognized = false; diff --git a/plugins/eventful.cpp b/plugins/eventful.cpp index 6a264ab95..8cf1d7832 100644 --- a/plugins/eventful.cpp +++ b/plugins/eventful.cpp @@ -34,14 +34,13 @@ using std::stack; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::world; -using df::global::ui; +DFHACK_PLUGIN("eventful"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); typedef df::reaction_product_itemst item_product; -DFHACK_PLUGIN("eventful"); - struct ReagentSource { int idx; df::reaction_reagent *reagent;