2011-10-06 19:53:58 -06:00
|
|
|
// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D
|
|
|
|
|
|
|
|
// some headers required for a plugin. Nothing special, just the basics.
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
2021-07-03 20:32:02 -06:00
|
|
|
#include <modules/EventManager.h>
|
2018-08-26 17:26:09 -06:00
|
|
|
// If you need to save data per-world:
|
|
|
|
//#include "modules/Persistence.h"
|
|
|
|
|
2012-01-28 05:03:56 -07:00
|
|
|
// DF data structure definition headers
|
|
|
|
#include "DataDefs.h"
|
|
|
|
//#include "df/world.h"
|
|
|
|
|
2014-12-06 18:55:57 -07:00
|
|
|
// our own, empty header.
|
|
|
|
#include "skeleton.h"
|
|
|
|
|
2011-10-06 19:53:58 -06:00
|
|
|
using namespace DFHack;
|
2012-01-28 05:03:56 -07:00
|
|
|
using namespace df::enums;
|
2011-10-06 19:53:58 -06:00
|
|
|
|
2021-07-24 21:48:30 -06:00
|
|
|
// Expose the plugin name to the DFHack core, as well as metadata like the DFHack version.
|
2014-12-06 18:55:57 -07:00
|
|
|
// The name string provided must correspond to the filename -
|
|
|
|
// skeleton.plug.so, skeleton.plug.dylib, or skeleton.plug.dll in this case
|
|
|
|
DFHACK_PLUGIN("skeleton");
|
2011-10-06 19:53:58 -06:00
|
|
|
|
2021-07-24 21:48:30 -06:00
|
|
|
// The identifier declared with this macro (ie. enabled) can be specified by the user
|
|
|
|
// and subsequently used to manage the plugin's operations.
|
|
|
|
// This will also be tracked by `plug`; when true the plugin will be shown as enabled.
|
2021-07-03 20:32:02 -06:00
|
|
|
DFHACK_PLUGIN_IS_ENABLED(enabled);
|
|
|
|
|
2014-12-06 18:55:57 -07:00
|
|
|
// Any globals a plugin requires (e.g. world) should be listed here.
|
|
|
|
// For example, this line expands to "using df::global::world" and prevents the
|
|
|
|
// plugin from being loaded if df::global::world is null (i.e. missing from symbols.xml):
|
|
|
|
//
|
2021-07-03 20:32:02 -06:00
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
|
|
|
|
// You may want some compile time debugging options
|
|
|
|
// one easy system just requires you to cache the color_ostream &out into a global debug variable
|
|
|
|
//#define P_DEBUG 1
|
|
|
|
//uint16_t maxTickFreq = 1200; //maybe you want to use some events
|
|
|
|
|
|
|
|
command_result command_callback1(color_ostream &out, std::vector<std::string> ¶meters);
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
|
|
|
|
commands.push_back(PluginCommand("skeleton",
|
|
|
|
"~54 character description of plugin", //to use one line in the ``[DFHack]# ls`` output
|
|
|
|
command_callback1,
|
|
|
|
false,
|
2021-08-05 10:38:28 -06:00
|
|
|
"example usage"
|
2021-07-03 20:32:02 -06:00
|
|
|
" skeleton <option> <args>\n"
|
|
|
|
" explanation of plugin/command\n"
|
|
|
|
"\n"
|
|
|
|
" skeleton\n"
|
|
|
|
" what happens when using the command\n"
|
|
|
|
"\n"
|
|
|
|
" skeleton option1\n"
|
|
|
|
" what happens when using the command with option1\n"
|
|
|
|
"\n"));
|
2011-10-06 19:53:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-03 20:32:02 -06:00
|
|
|
DFhackCExport command_result plugin_shutdown(color_ostream &out) {
|
2011-10-06 19:53:58 -06:00
|
|
|
// You *MUST* kill all threads you created before this returns.
|
2012-02-21 10:19:17 -07:00
|
|
|
// If everything fails, just return CR_FAILURE. Your plugin will be
|
2011-10-06 19:53:58 -06:00
|
|
|
// in a zombie state, but things won't crash.
|
|
|
|
return CR_OK;
|
2021-07-03 20:32:02 -06:00
|
|
|
|
2011-10-06 19:53:58 -06:00
|
|
|
}
|
|
|
|
|
2021-06-17 23:58:03 -06:00
|
|
|
DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) {
|
2021-07-03 20:32:02 -06:00
|
|
|
namespace EM = EventManager;
|
|
|
|
if (enable && !enabled) {
|
|
|
|
//using namespace EM::EventType;
|
|
|
|
//EM::EventHandler eventHandler(onNewEvent, maxTickFreq);
|
|
|
|
//EM::registerListener(EventType::JOB_COMPLETED, eventHandler, plugin_self);
|
|
|
|
//out.print("plugin enabled!\n");
|
|
|
|
} else if (!enable && enabled) {
|
|
|
|
EM::unregisterAll(plugin_self);
|
|
|
|
//out.print("plugin disabled!\n");
|
|
|
|
}
|
2021-06-17 23:58:03 -06:00
|
|
|
enabled = enable;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-03 20:32:02 -06:00
|
|
|
|
|
|
|
/* OPTIONAL *
|
2012-01-28 05:03:56 -07:00
|
|
|
// Called to notify the plugin about important state changes.
|
|
|
|
// Invoked with DF suspended, and always before the matching plugin_onupdate.
|
|
|
|
// More event codes may be added in the future.
|
2021-07-03 20:32:02 -06:00
|
|
|
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) {
|
|
|
|
if (enabled) {
|
|
|
|
switch (event) {
|
|
|
|
case SC_UNKNOWN:
|
|
|
|
break;
|
|
|
|
case SC_WORLD_LOADED:
|
|
|
|
break;
|
|
|
|
case SC_WORLD_UNLOADED:
|
|
|
|
break;
|
|
|
|
case SC_MAP_LOADED:
|
|
|
|
break;
|
|
|
|
case SC_MAP_UNLOADED:
|
|
|
|
break;
|
|
|
|
case SC_VIEWSCREEN_CHANGED:
|
|
|
|
break;
|
|
|
|
case SC_CORE_INITIALIZED:
|
|
|
|
break;
|
|
|
|
case SC_BEGIN_UNLOAD:
|
|
|
|
break;
|
|
|
|
case SC_PAUSED:
|
|
|
|
break;
|
|
|
|
case SC_UNPAUSED:
|
|
|
|
break;
|
|
|
|
}
|
2012-01-28 05:03:56 -07:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-06 19:53:58 -06:00
|
|
|
// Whatever you put here will be done in each game step. Don't abuse it.
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
2011-10-06 19:53:58 -06:00
|
|
|
{
|
|
|
|
// whetever. You don't need to suspend DF execution here.
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2018-08-26 17:26:09 -06:00
|
|
|
// If you need to save or load world-specific data, define these functions.
|
2019-05-29 17:52:03 -06:00
|
|
|
// plugin_save_data is called when the game might be about to save the world,
|
|
|
|
// and plugin_load_data is called whenever a new world is loaded. If the plugin
|
|
|
|
// is loaded or unloaded while a world is active, plugin_save_data or
|
|
|
|
// plugin_load_data will be called immediately.
|
|
|
|
DFhackCExport command_result plugin_save_data (color_ostream &out)
|
2018-08-26 17:26:09 -06:00
|
|
|
{
|
|
|
|
// Call functions in the Persistence module here.
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-29 17:52:03 -06:00
|
|
|
DFhackCExport command_result plugin_load_data (color_ostream &out)
|
2018-08-26 17:26:09 -06:00
|
|
|
{
|
|
|
|
// Call functions in the Persistence module here.
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2021-07-03 20:32:02 -06:00
|
|
|
* OPTIONAL */
|
|
|
|
|
2018-08-26 17:26:09 -06:00
|
|
|
|
2011-10-06 19:53:58 -06:00
|
|
|
// A command! It sits around and looks pretty. And it's nice and friendly.
|
2021-07-03 20:32:02 -06:00
|
|
|
command_result command_callback1(color_ostream &out, std::vector<std::string> ¶meters) {
|
2012-01-28 05:03:56 -07:00
|
|
|
// It's nice to print a help message you get invalid options
|
|
|
|
// from the user instead of just acting strange.
|
|
|
|
// This can be achieved by adding the extended help string to the
|
|
|
|
// PluginCommand registration as show above, and then returning
|
|
|
|
// CR_WRONG_USAGE from the function. The same string will also
|
|
|
|
// be used by 'help your-command'.
|
2021-07-03 20:32:02 -06:00
|
|
|
if (!parameters.empty()) {
|
|
|
|
return CR_WRONG_USAGE; //or maybe you want it to do something else
|
|
|
|
}
|
2011-10-06 19:53:58 -06:00
|
|
|
// Commands are called from threads other than the DF one.
|
2021-07-03 20:32:02 -06:00
|
|
|
// Suspend this thread until DF has time for us.
|
|
|
|
// **If you use CoreSuspender** it'll automatically resume DF when
|
2012-01-28 05:03:56 -07:00
|
|
|
// execution leaves the current scope.
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2011-10-06 19:53:58 -06:00
|
|
|
// Actually do something here. Yay.
|
2021-07-03 20:32:02 -06:00
|
|
|
|
|
|
|
// process parameters
|
|
|
|
if (parameters.size() == 1 && parameters[0] == "option1") {
|
|
|
|
// stuff
|
|
|
|
} else {
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-10-06 19:53:58 -06:00
|
|
|
// Give control back to DF.
|
|
|
|
return CR_OK;
|
2022-04-12 12:48:19 -06:00
|
|
|
}
|