Update some plugins to use REQUIRE_GLOBAL

develop
lethosor 2014-12-02 21:44:20 -05:00
parent e206c242c6
commit cac2245438
31 changed files with 85 additions and 100 deletions

@ -27,6 +27,7 @@ distribution.
#include "Export.h" #include "Export.h"
#include "Hooks.h" #include "Hooks.h"
#include "ColorText.h" #include "ColorText.h"
#include "MiscUtils.h"
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>

@ -41,14 +41,13 @@ using std::stack;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; 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("add-spatter");
DFHACK_PLUGIN_IS_ENABLED(is_enabled); 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 { struct ReagentSource {
int idx; int idx;

@ -37,14 +37,15 @@
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
using df::global::ui_advmode;
using df::nemesis_record; using df::nemesis_record;
using df::historical_figure; using df::historical_figure;
using namespace DFHack::Translation; using namespace DFHack::Translation;
DFHACK_PLUGIN("advtools");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(ui_advmode);
/********************* /*********************
* PLUGIN INTERFACE * * PLUGIN INTERFACE *
*********************/ *********************/
@ -54,8 +55,6 @@ static bool bodyswap_hotkey(df::viewscreen *top);
command_result adv_bodyswap (color_ostream &out, std::vector <std::string> & parameters); command_result adv_bodyswap (color_ostream &out, std::vector <std::string> & parameters);
command_result adv_tools (color_ostream &out, std::vector <std::string> & parameters); command_result adv_tools (color_ostream &out, std::vector <std::string> & parameters);
DFHACK_PLUGIN("advtools");
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 (!ui_advmode) if (!ui_advmode)

@ -36,12 +36,10 @@ using std::set;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
using df::global::ui;
#define PLUGIN_VERSION 0.3 #define PLUGIN_VERSION 0.3
DFHACK_PLUGIN("autochop"); DFHACK_PLUGIN("autochop");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(ui);
static bool autochop_enabled = false; static bool autochop_enabled = false;
static int min_logs, max_logs; static int min_logs, max_logs;

@ -34,10 +34,10 @@ using namespace df::enums;
using MapExtras::Block; using MapExtras::Block;
using MapExtras::MapCache; using MapExtras::MapCache;
using df::global::world;
using df::building_stockpilest; using df::building_stockpilest;
DFHACK_PLUGIN("autodump"); DFHACK_PLUGIN("autodump");
REQUIRE_GLOBAL(world);
// Stockpile interface START // Stockpile interface START
static const string PERSISTENCE_KEY = "autodump/stockpiles"; static const string PERSISTENCE_KEY = "autodump/stockpiles";

@ -44,8 +44,10 @@ using std::endl;
using std::vector; using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; 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])) #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 // 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 <std::string> & parameters); command_result autolabor (color_ostream &out, std::vector <std::string> & 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(); static void generate_labor_to_skill_map();
enum labor_mode { enum labor_mode {

@ -43,11 +43,11 @@ using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::gps;
using df::global::ui;
using df::global::ui_build_selector;
DFHACK_PLUGIN("automaterial"); DFHACK_PLUGIN("automaterial");
REQUIRE_GLOBAL(gps);
REQUIRE_GLOBAL(ui);
REQUIRE_GLOBAL(ui_build_selector);
struct MaterialDescriptor struct MaterialDescriptor
{ {

@ -14,13 +14,13 @@
#include "modules/World.h" #include "modules/World.h"
#include "df/item_quality.h" #include "df/item_quality.h"
using df::global::world;
using df::global::cursor;
using df::global::ui;
using df::building_stockpilest; using df::building_stockpilest;
DFHACK_PLUGIN("automelt"); DFHACK_PLUGIN("automelt");
#define PLUGIN_VERSION 0.3 #define PLUGIN_VERSION 0.3
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(cursor);
REQUIRE_GLOBAL(ui);
static const string PERSISTENCE_KEY = "automelt/stockpiles"; static const string PERSISTENCE_KEY = "automelt/stockpiles";

@ -19,12 +19,12 @@
#include "df/mandate.h" #include "df/mandate.h"
#include "modules/Maps.h" #include "modules/Maps.h"
using df::global::world;
using df::global::cursor;
using df::global::ui;
using df::building_stockpilest; using df::building_stockpilest;
DFHACK_PLUGIN("autotrade"); DFHACK_PLUGIN("autotrade");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(cursor);
REQUIRE_GLOBAL(ui);
static const string PERSISTENCE_KEY = "autotrade/stockpiles"; static const string PERSISTENCE_KEY = "autotrade/stockpiles";

@ -24,9 +24,10 @@
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
DFHACK_PLUGIN("building-hacks"); 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. 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 int16_t tile; //originally uint8_t but we need to indicate non-animated tiles

@ -35,12 +35,11 @@
#include "df/building.h" #include "df/building.h"
#include "df/building_doorst.h" #include "df/building_doorst.h"
using df::global::ui;
using df::global::ui_build_selector;
using df::global::world;
DFHACK_PLUGIN("buildingplan"); DFHACK_PLUGIN("buildingplan");
#define PLUGIN_VERSION 0.14 #define PLUGIN_VERSION 0.14
REQUIRE_GLOBAL(ui);
REQUIRE_GLOBAL(ui_build_selector);
REQUIRE_GLOBAL(world);
struct MaterialDescriptor struct MaterialDescriptor
{ {

@ -37,9 +37,10 @@ using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using namespace dfproto; using namespace dfproto;
using df::global::ui; DFHACK_PLUGIN("burrows");
using df::global::world; REQUIRE_GLOBAL(ui);
using df::global::gamemode; REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(gamemode);
/* /*
* Initialization. * Initialization.
@ -47,8 +48,6 @@ using df::global::gamemode;
static command_result burrow(color_ostream &out, vector <string> & parameters); static command_result burrow(color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("burrows");
static void init_map(color_ostream &out); static void init_map(color_ostream &out);
static void deinit_map(color_ostream &out); static void deinit_map(color_ostream &out);

@ -25,11 +25,11 @@ using namespace std;
#include <df/unit_genes.h> #include <df/unit_genes.h>
using namespace DFHack; using namespace DFHack;
using df::global::world;
command_result catsplosion (color_ostream &out, std::vector <std::string> & parameters);
DFHACK_PLUGIN("catsplosion"); DFHACK_PLUGIN("catsplosion");
REQUIRE_GLOBAL(world);
command_result catsplosion (color_ostream &out, std::vector <std::string> & parameters);
// Mandatory init function. If you have some global state, create it here. // Mandatory init function. If you have some global state, create it here.
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)

@ -31,9 +31,9 @@ using namespace df::enums;
using MapExtras::Block; using MapExtras::Block;
using MapExtras::MapCache; using MapExtras::MapCache;
using df::global::world;
DFHACK_PLUGIN("changeitem"); DFHACK_PLUGIN("changeitem");
REQUIRE_GLOBAL(world);
command_result df_changeitem(color_ostream &out, vector <string> & parameters); command_result df_changeitem(color_ostream &out, vector <string> & parameters);

@ -28,8 +28,9 @@ using namespace std;
using std::vector; using std::vector;
using std::string; using std::string;
using df::global::world; DFHACK_PLUGIN("changelayer");
using df::global::cursor; REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(cursor);
const string changelayer_help = const string changelayer_help =
" Allows to change the material of whole geology layers.\n" " 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 <std::string> & parameters); command_result changelayer (color_ostream &out, std::vector <std::string> & parameters);
DFHACK_PLUGIN("changelayer");
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand( commands.push_back(PluginCommand(

@ -15,8 +15,9 @@ using std::string;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world; DFHACK_PLUGIN("changevein");
using df::global::cursor; REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(cursor);
command_result df_changevein (color_ostream &out, vector <string> & parameters) command_result df_changevein (color_ostream &out, vector <string> & parameters)
{ {
@ -77,8 +78,6 @@ command_result df_changevein (color_ostream &out, vector <string> & parameters)
return CR_OK; return CR_OK;
} }
DFHACK_PLUGIN("changevein");
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("changevein", commands.push_back(PluginCommand("changevein",

@ -16,9 +16,8 @@
using namespace std; using namespace std;
using namespace DFHack; using namespace DFHack;
using df::global::world;
DFHACK_PLUGIN("cleanconst"); DFHACK_PLUGIN("cleanconst");
REQUIRE_GLOBAL(world);
command_result df_cleanconst(color_ostream &out, vector <string> & parameters) command_result df_cleanconst(color_ostream &out, vector <string> & parameters)
{ {

@ -18,10 +18,9 @@ using std::string;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
using df::global::cursor;
DFHACK_PLUGIN("cleaners"); DFHACK_PLUGIN("cleaners");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(cursor);
command_result cleanmap (color_ostream &out, bool snow, bool mud, bool item_spatter) command_result cleanmap (color_ostream &out, bool snow, bool mud, bool item_spatter)
{ {

@ -23,12 +23,11 @@ using namespace std;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world; DFHACK_PLUGIN("cleanowned");
REQUIRE_GLOBAL(world);
command_result df_cleanowned (color_ostream &out, vector <string> & parameters); command_result df_cleanowned (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("cleanowned");
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand( commands.push_back(PluginCommand(

@ -14,6 +14,7 @@ using namespace DFHack;
command_result colonies (color_ostream &out, vector <string> & parameters); command_result colonies (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("colonies"); DFHACK_PLUGIN("colonies");
REQUIRE_GLOBAL(world); // used by Materials
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {

@ -22,9 +22,10 @@
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::ui; DFHACK_PLUGIN("command-prompt");
using df::global::gps; REQUIRE_GLOBAL(ui);
using df::global::enabler; REQUIRE_GLOBAL(gps);
REQUIRE_GLOBAL(enabler);
std::vector<std::string> command_history; std::vector<std::string> command_history;
@ -303,7 +304,7 @@ void viewscreen_commandpromptst::feed(std::set<df::interface_key> *events)
frame = 0; frame = 0;
} }
DFHACK_PLUGIN("command-prompt");
command_result show_prompt(color_ostream &out, std::vector <std::string> & parameters) command_result show_prompt(color_ostream &out, std::vector <std::string> & parameters)
{ {
if (Gui::getCurFocus() == "dfhack/commandprompt") if (Gui::getCurFocus() == "dfhack/commandprompt")

@ -31,11 +31,10 @@ using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
using df::global::ui;
using df::global::gametype;
DFHACK_PLUGIN("createitem"); DFHACK_PLUGIN("createitem");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(ui);
REQUIRE_GLOBAL(gametype);
int dest_container = -1, dest_building = -1; int dest_container = -1, dest_building = -1;

@ -48,12 +48,12 @@ using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
using df::global::cursor;
command_result cursecheck (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("cursecheck"); DFHACK_PLUGIN("cursecheck");
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(cursor);
command_result cursecheck (color_ostream &out, vector <string> & parameters);
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {

@ -14,9 +14,8 @@ using std::string;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
DFHACK_PLUGIN("deramp"); DFHACK_PLUGIN("deramp");
REQUIRE_GLOBAL(world);
command_result df_deramp (color_ostream &out, vector <string> & parameters) command_result df_deramp (color_ostream &out, vector <string> & parameters)
{ {

@ -18,8 +18,10 @@ using namespace df::enums;
using std::string; using std::string;
using std::vector; 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 // The error messages are taken from the clsocket source code
const char * translate_socket_error(CSimpleSocket::CSocketError err) { const char * translate_socket_error(CSimpleSocket::CSocketError err) {
@ -283,8 +285,6 @@ public:
} }
}; };
DFHACK_PLUGIN("dfstream");
inline df::renderer *& active_renderer() { inline df::renderer *& active_renderer() {
return enabler->renderer; return enabler->renderer;
} }

@ -27,6 +27,7 @@ command_result digcircle (color_ostream &out, vector <string> & parameters);
command_result digtype (color_ostream &out, vector <string> & parameters); command_result digtype (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("dig"); DFHACK_PLUGIN("dig");
REQUIRE_GLOBAL(world);
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {

@ -21,14 +21,11 @@
using namespace DFHack; using namespace DFHack;
using namespace std; using namespace std;
using df::global::world; DFHACK_PLUGIN("digFlood");
// using df::global::process_jobs; REQUIRE_GLOBAL(world);
// using df::global::process_dig;
command_result digFlood (color_ostream &out, std::vector <std::string> & parameters); command_result digFlood (color_ostream &out, std::vector <std::string> & parameters);
DFHACK_PLUGIN("digFlood");
void onDig(color_ostream& out, void* ptr); void onDig(color_ostream& out, void* ptr);
void maybeExplore(color_ostream& out, MapExtras::MapCache& cache, df::coord pt, set<df::coord>& jobLocations); void maybeExplore(color_ostream& out, MapExtras::MapCache& cache, df::coord pt, set<df::coord>& jobLocations);
EventManager::EventHandler digHandler(onDig, 0); EventManager::EventHandler digHandler(onDig, 0);

@ -77,6 +77,7 @@ void findAndAssignInvasionJob(color_ostream& out, void*);
DFHACK_PLUGIN_IS_ENABLED(enabled); DFHACK_PLUGIN_IS_ENABLED(enabled);
DFHACK_PLUGIN("diggingInvaders"); DFHACK_PLUGIN("diggingInvaders");
REQUIRE_GLOBAL(world);
//TODO: when world unloads //TODO: when world unloads
static int32_t lastInvasionJob=-1; static int32_t lastInvasionJob=-1;
@ -386,8 +387,8 @@ void findAndAssignInvasionJob(color_ostream& out, void* tickTime) {
unordered_set<uint16_t> localConnectivity; unordered_set<uint16_t> localConnectivity;
//find all locals and invaders //find all locals and invaders
for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) { for ( size_t a = 0; a < world->units.all.size(); a++ ) {
df::unit* unit = df::global::world->units.all[a]; df::unit* unit = world->units.all[a];
if ( unit->flags1.bits.dead ) if ( unit->flags1.bits.dead )
continue; continue;
if ( Units::isCitizen(unit) ) { if ( Units::isCitizen(unit) ) {
@ -597,7 +598,7 @@ void findAndAssignInvasionJob(color_ostream& out, void* tickTime) {
lastInvasionDigger = firstInvader->id; lastInvasionDigger = firstInvader->id;
lastInvasionJob = firstInvader->job.current_job ? firstInvader->job.current_job->id : -1; lastInvasionJob = firstInvader->job.current_job ? firstInvader->job.current_job->id : -1;
invaderJobs.erase(lastInvasionJob); 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 ) if ( link->item == NULL )
continue; continue;
df::job* job = link->item; df::job* job = link->item;

@ -15,9 +15,8 @@ using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::world;
DFHACK_PLUGIN("drybuckets"); DFHACK_PLUGIN("drybuckets");
REQUIRE_GLOBAL(world);
command_result df_drybuckets (color_ostream &out, vector <string> & parameters) command_result df_drybuckets (color_ostream &out, vector <string> & parameters)
{ {

@ -43,9 +43,11 @@
using std::deque; using std::deque;
using df::global::current_weather; DFHACK_PLUGIN("dwarfmonitor");
using df::global::world; DFHACK_PLUGIN_IS_ENABLED(is_enabled);
using df::global::ui; REQUIRE_GLOBAL(current_weather);
REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(ui);
typedef int16_t activity_type; 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, feed);
IMPLEMENT_VMETHOD_INTERPOSE(dwarf_monitor_hook, render); 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) static bool set_monitoring_mode(const string &mode, const bool &state)
{ {
bool mode_recognized = false; bool mode_recognized = false;

@ -34,14 +34,13 @@ using std::stack;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using df::global::gps; DFHACK_PLUGIN("eventful");
using df::global::world; REQUIRE_GLOBAL(gps);
using df::global::ui; REQUIRE_GLOBAL(world);
REQUIRE_GLOBAL(ui);
typedef df::reaction_product_itemst item_product; typedef df::reaction_product_itemst item_product;
DFHACK_PLUGIN("eventful");
struct ReagentSource { struct ReagentSource {
int idx; int idx;
df::reaction_reagent *reagent; df::reaction_reagent *reagent;