Make 'die' plugin a builtin, made the console interaction less confusing.

develop
Petr Mrázek 2011-07-20 20:58:19 +02:00
parent 0defcc9889
commit 873cbd8388
5 changed files with 51 additions and 93 deletions

@ -130,7 +130,8 @@ int fIOthread(void * iodata)
con.printerr("Something horrible happened in Core's constructor...\n"); con.printerr("Something horrible happened in Core's constructor...\n");
return 0; return 0;
} }
con.print("DFHack is ready. Have a nice day! Type in '?' or 'help' for help.\n"); con.print("DFHack is ready. Have a nice day!\n"
"Type in '?' or 'help' for general help, 'ls' to see all commands.\n");
int clueless_counter = 0; int clueless_counter = 0;
while (true) while (true)
{ {
@ -171,17 +172,18 @@ int fIOthread(void * iodata)
"The console also has a command history - you can navigate it with Up and Down keys.\n" "The console also has a command history - you can navigate it with Up and Down keys.\n"
"On Windows, you may have to resize your console window. The appropriate menu is accessible\n" "On Windows, you may have to resize your console window. The appropriate menu is accessible\n"
"by clicking on the program icon in the top bar of the window.\n\n" "by clicking on the program icon in the top bar of the window.\n\n"
"Available basic commands:\n" "Basic commands:\n"
" help|? [plugin] - This text or help specific to a plugin.\n" " help|? - This text.\n"
" load plugin|all - Load a plugin by name or load all possible plugins.\n" " ls|dir [PLUGIN] - List available commands. Optionally for single plugin.\n"
" unload plugin|all - Unload a plugin or all loaded plugins.\n" " cls - Clear the console.\n"
" reload plugin|all - Reload a plugin or all loaded plugins.\n" " fpause - Force DF to pause.\n"
" listp - List plugins with their status.\n"
" listc [plugin] - List commands. Optionally of a single plugin.\n"
" lista - List all commands, sorted by plugin (verbose).\n"
" fpause - Force DF to pause without syncing.\n"
" die - Force DF to close immediately\n" " die - Force DF to close immediately\n"
" cls - Clear the console scrollback.\n" "Plugin management (useful for developers):\n"
//" belongs COMMAND - Tell which plugin a command belongs to.\n"
" plug [PLUGIN|v] - List plugin state and description.\n"
" load PLUGIN|all - Load a plugin by name or load all possible plugins.\n"
" unload PLUGIN|all - Unload a plugin or all loaded plugins.\n"
" reload PLUGIN|all - Reload a plugin or all loaded plugins.\n"
); );
} }
else else
@ -252,15 +254,7 @@ int fIOthread(void * iodata)
} }
} }
} }
else if(first == "listp") else if(first == "ls" || first == "dir")
{
for(int i = 0; i < plug_mgr->size();i++)
{
const Plugin * plug = (plug_mgr->operator[](i));
con.print("%s\n", plug->getName().c_str());
}
}
else if(first == "listc")
{ {
if(parts.size()) if(parts.size())
{ {
@ -273,10 +267,27 @@ int fIOthread(void * iodata)
else for (int j = 0; j < plug->size();j++) else for (int j = 0; j < plug->size();j++)
{ {
const PluginCommand & pcmd = (plug->operator[](j)); const PluginCommand & pcmd = (plug->operator[](j));
con.print("%12s| %s\n",pcmd.name.c_str(), pcmd.description.c_str()); con.print(" %-22s - %s\n",pcmd.name.c_str(), pcmd.description.c_str());
} }
} }
else for(int i = 0; i < plug_mgr->size();i++) else
{
con.print(
"builtin:\n"
" help|? - This text or help specific to a plugin.\n"
" ls [PLUGIN] - List available commands. Optionally for single plugin.\n"
" cls - Clear the console.\n"
" fpause - Force DF to pause.\n"
" die - Force DF to close immediately\n"
" belongs COMMAND - Tell which plugin a command belongs to.\n"
" plug [PLUGIN|v] - List plugin state and detailed description.\n"
" load PLUGIN|all - Load a plugin by name or load all possible plugins.\n"
" unload PLUGIN|all - Unload a plugin or all loaded plugins.\n"
" reload PLUGIN|all - Reload a plugin or all loaded plugins.\n"
"\n"
"plugins:\n"
);
for(int i = 0; i < plug_mgr->size();i++)
{ {
const Plugin * plug = (plug_mgr->operator[](i)); const Plugin * plug = (plug_mgr->operator[](i));
if(!plug->size()) if(!plug->size())
@ -284,25 +295,19 @@ int fIOthread(void * iodata)
for (int j = 0; j < plug->size();j++) for (int j = 0; j < plug->size();j++)
{ {
const PluginCommand & pcmd = (plug->operator[](j)); const PluginCommand & pcmd = (plug->operator[](j));
con.print("%12s| %s\n",pcmd.name.c_str(), pcmd.description.c_str()); con.print(" %-22s- %s\n",pcmd.name.c_str(), pcmd.description.c_str());
}
} }
} }
} }
else if(first == "lista") else if(first == "plug")
{ {
for(int i = 0; i < plug_mgr->size();i++) for(int i = 0; i < plug_mgr->size();i++)
{ {
const Plugin * plug = (plug_mgr->operator[](i)); const Plugin * plug = (plug_mgr->operator[](i));
if(!plug->size()) if(!plug->size())
continue; continue;
con.print("%s :\n", plug->getName().c_str()); con.print("%s\n", plug->getName().c_str());
for (int j = 0; j < plug->size();j++)
{
const PluginCommand & pcmd = (plug->operator[](j));
con.print("%12s| %s\n",pcmd.name.c_str(), pcmd.description.c_str());
//con << setw(12) << pcmd.name << "| " << pcmd.description << endl;
}
//con.print("\n");
} }
} }
else if(first == "fpause") else if(first == "fpause")
@ -315,6 +320,10 @@ int fIOthread(void * iodata)
{ {
con.clear(); con.clear();
} }
else if(first == "die")
{
_exit(666);
}
else else
{ {
vector <string> parts; vector <string> parts;

@ -196,7 +196,7 @@ bool Plugin::load()
plugin_status = (command_result (*)(Core *, std::string &)) LookupPlugin(plug, "plugin_status"); plugin_status = (command_result (*)(Core *, std::string &)) LookupPlugin(plug, "plugin_status");
plugin_onupdate = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_onupdate"); plugin_onupdate = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_onupdate");
plugin_shutdown = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_shutdown"); plugin_shutdown = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_shutdown");
name = _PlugName(); //name = _PlugName();
plugin_lib = plug; plugin_lib = plug;
if(plugin_init(&c,commands) == CR_OK) if(plugin_init(&c,commands) == CR_OK)
{ {
@ -322,6 +322,8 @@ PluginManager::PluginManager(Core * core)
{ {
Plugin * p = new Plugin(core, path + filez[i], filez[i], this); Plugin * p = new Plugin(core, path + filez[i], filez[i], this);
all_plugins.push_back(p); all_plugins.push_back(p);
// make all plugins load by default (until a proper design emerges).
p->load();
} }
} }
} }

@ -234,9 +234,8 @@ bool Maps::Start()
if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0) if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0)
{ {
cerr << hex << &mx << " " << &my << " " << &mz << endl; cerr << hex << &mx << " " << &my << " " << &mz << endl;
cout << dec << mx << " "<< my << " "<< mz << endl; cerr << dec << mx << " "<< my << " "<< mz << endl;
// FIXME: this should be avoided! return false;
throw Error::BadMapDimensions(mx, my);
} }
d->Started = true; d->Started = true;

@ -108,11 +108,6 @@ if(BUILD_KITTENS)
endif() endif()
IF(UNIX) IF(UNIX)
OPTION(BUILD_KILL_GAME "Build the kill game plugin." OFF)
if(BUILD_KILL_GAME)
DFHACK_PLUGIN(die die.cpp)
endif()
OPTION(BUILD_VECTORS "Build the vectors search plugin." OFF) OPTION(BUILD_VECTORS "Build the vectors search plugin." OFF)
if(BUILD_VECTORS) if(BUILD_VECTORS)
DFHACK_PLUGIN(vectors vectors.cpp) DFHACK_PLUGIN(vectors vectors.cpp)

@ -1,47 +0,0 @@
// 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;
}