summaryrefslogtreecommitdiff
path: root/plugins/skeleton
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-01-28 16:03:56 +0400
committerAlexander Gavrilov2012-01-28 16:03:56 +0400
commitfa4fb4b407b701d707ac3e3a4a0e6804cca2c526 (patch)
treeda7e5bf1119f33f7678e0a55adacd307788bb65a /plugins/skeleton
parentc59f5c16421f62f88697624457b4b390306ca5a5 (diff)
downloaddfhack-fa4fb4b407b701d707ac3e3a4a0e6804cca2c526.tar.gz
dfhack-fa4fb4b407b701d707ac3e3a4a0e6804cca2c526.tar.bz2
dfhack-fa4fb4b407b701d707ac3e3a4a0e6804cca2c526.tar.xz
Modify a number of commands to use CR_WRONG_USAGE for displaying help.
Diffstat (limited to 'plugins/skeleton')
-rw-r--r--plugins/skeleton/skeleton.cpp70
1 files changed, 49 insertions, 21 deletions
diff --git a/plugins/skeleton/skeleton.cpp b/plugins/skeleton/skeleton.cpp
index 1b3ad398..a5a66f35 100644
--- a/plugins/skeleton/skeleton.cpp
+++ b/plugins/skeleton/skeleton.cpp
@@ -5,7 +5,13 @@
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
+
+// DF data structure definition headers
+#include "DataDefs.h"
+//#include "df/world.h"
+
using namespace DFHack;
+using namespace df::enums;
// our own, empty header.
#include "skeleton.h"
@@ -13,7 +19,7 @@ using namespace DFHack;
// Here go all the command declarations...
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom
-DFhackCExport command_result skeleton (Core * c, std::vector <std::string> & parameters);
+command_result skeleton (Core * c, std::vector <std::string> & parameters);
// A plugins must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll
DFhackCExport const char * plugin_name ( void )
@@ -26,10 +32,15 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
{
// Fill the command list with your commands.
commands.clear();
- commands.push_back(PluginCommand("skeleton",
- "Do nothing, look pretty.",
- skeleton /*,
- true or false - true means that the command can't be used from non-interactive user interface'*/));
+ commands.push_back(PluginCommand(
+ "skeleton", "Do nothing, look pretty.",
+ skeleton, false, /* true means that the command can't be used from non-interactive user interface */
+ // Extended help string. Used by CR_WRONG_USAGE and the help command:
+ " This command does nothing at all.\n"
+ "Example:\n"
+ " skeleton\n"
+ " Does nothing.\n"
+ ));
return CR_OK;
}
@@ -42,6 +53,26 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
return CR_OK;
}
+// 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.
+/*
+DFhackCExport command_result plugin_onstatechange(Core* c, state_change_event event)
+{
+ switch (event) {
+ case SC_GAME_LOADED:
+ // initialize from the world just loaded
+ break;
+ case SC_GAME_UNLOADED:
+ // cleanup
+ break;
+ default:
+ break;
+ }
+ return CR_OK;
+}
+*/
+
// Whatever you put here will be done in each game step. Don't abuse it.
// It's optional, so you can just comment it out like this if you don't need it.
/*
@@ -53,26 +84,23 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
*/
// A command! It sits around and looks pretty. And it's nice and friendly.
-DFhackCExport command_result skeleton (Core * c, std::vector <std::string> & parameters)
+command_result skeleton (Core * c, std::vector <std::string> & parameters)
{
- // It's nice to provide a 'help' option for your command.
- // It's also nice to print the same help if you get invalid options from the user instead of just acting strange
- for(int i = 0; i < parameters.size();i++)
- {
- if(parameters[i] == "help" || parameters[i] == "?")
- {
- // Core has a handle to the console. The console is thread-safe.
- // Only one thing can read from it at a time though...
- c->con.print("This command does nothing!\n");
- return CR_OK;
- }
- }
+ // 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'.
+ if (!parameters.empty())
+ return CR_WRONG_USAGE;
// Commands are called from threads other than the DF one.
- // Suspend this thread until DF has time for us.
- c->Suspend();
+ // Suspend this thread until DF has time for us. If you
+ // use CoreSuspender, it'll automatically resume DF when
+ // execution leaves the current scope.
+ CoreSuspender suspend(c);
// Actually do something here. Yay.
c->con.print("Hello! I do nothing, remember?\n");
// Give control back to DF.
- c->Resume();
return CR_OK;
}