Merge pull request #104 from matthew-cline/TOPIC-die

Linux only plugin: use "die" command to kill game
develop
Petr Mrázek 2011-07-15 22:54:40 -07:00
commit 83b190b5d8
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(vdig vdig.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;
}