Linux only plugin: use "die" command to kill game

Since you can't do "Ctrl-Z kill -9 %1" from the console, instead just
give the "die" command to terminate the game without saving.  Linux
only, since _exit() probably doesn't work on Windows.

Need to set cmake option BUILD_KILL_GAME to ON to compile this plugin.
develop
Matthew Cline 2011-07-13 23:52:06 -07:00
parent f2b46274ec
commit 8ad6a56704
2 changed files with 54 additions and 0 deletions

@ -34,3 +34,10 @@ DFHACK_PLUGIN(cleanmap cleanmap.cpp)
DFHACK_PLUGIN(weather weather.cpp) DFHACK_PLUGIN(weather weather.cpp)
DFHACK_PLUGIN(vdig vdig.cpp) DFHACK_PLUGIN(vdig vdig.cpp)
DFHACK_PLUGIN(colonies colonies.cpp) DFHACK_PLUGIN(colonies colonies.cpp)
IF(UNIX)
OPTION(BUILD_KILL_GAME "Build the kill gmae plugin." OFF)
if(BUILD_KILL_GAME)
DFHACK_PLUGIN(die die.cpp)
endif()
endif()

@ -0,0 +1,47 @@
// Since you can't do "Ctrl-Z kill -9 %1" from the console, instead just
// give the "die" command to terminate the game without saving.
// Linux only, since _exit() probably doesn't work on Windows.
//
// Need to set cmake option BUILD_KILL_GAME to ON to compile this
// plugin.
#ifndef LINUX_BUILD
#error "This plugin only compiles on Linux"
#endif
#include <dfhack/Core.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <vector>
#include <string>
using std::vector;
using std::string;
using namespace DFHack;
DFhackCExport command_result df_die (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "die";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("die",
"Kill game without saving", df_die));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
DFhackCExport command_result df_die (Core * c, vector <string> & parameters)
{
_exit(0);
return CR_OK;
}