2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/Gui.h"
|
2012-01-14 08:31:43 -07:00
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/squad.h"
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit_soul.h"
|
|
|
|
#include "df/historical_figure.h"
|
|
|
|
#include "df/language_name.h"
|
2011-12-29 06:37:07 -07:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::world;
|
|
|
|
|
|
|
|
static command_result rename(Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "rename";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init (Core *c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
if (world && ui) {
|
2012-01-14 08:31:43 -07:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"rename", "Rename various things.", rename, false,
|
|
|
|
" rename squad <index> \"name\"\n"
|
|
|
|
" rename hotkey <index> \"name\"\n"
|
2012-01-15 04:57:33 -07:00
|
|
|
" (identified by ordinal index)\n"
|
2012-01-14 08:31:43 -07:00
|
|
|
" rename unit \"nickname\"\n"
|
2012-01-15 04:57:33 -07:00
|
|
|
" rename unit-profession \"custom profession\"\n"
|
2012-01-14 08:31:43 -07:00
|
|
|
" (a unit must be highlighted in the ui)\n"
|
|
|
|
));
|
2011-12-29 06:37:07 -07:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-14 08:31:43 -07:00
|
|
|
static void set_nickname(df::language_name *name, std::string nick)
|
2011-12-29 06:37:07 -07:00
|
|
|
{
|
2012-01-14 08:31:43 -07:00
|
|
|
if (!name->has_name)
|
|
|
|
{
|
|
|
|
*name = df::language_name();
|
|
|
|
|
|
|
|
name->language = 0;
|
|
|
|
name->has_name = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
name->nickname = nick;
|
2011-12-29 06:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static command_result rename(Core * c, vector <string> ¶meters)
|
|
|
|
{
|
|
|
|
CoreSuspender suspend(c);
|
|
|
|
|
|
|
|
string cmd;
|
|
|
|
if (!parameters.empty())
|
|
|
|
cmd = parameters[0];
|
|
|
|
|
2012-01-14 08:31:43 -07:00
|
|
|
if (cmd == "squad")
|
|
|
|
{
|
2011-12-29 06:37:07 -07:00
|
|
|
if (parameters.size() != 3)
|
2012-01-14 08:31:43 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2011-12-29 06:37:07 -07:00
|
|
|
std::vector<df::squad*> &squads = world->squads.all;
|
|
|
|
|
|
|
|
int id = atoi(parameters[1].c_str());
|
|
|
|
if (id < 1 || id > squads.size()) {
|
|
|
|
c->con.printerr("Invalid squad index\n");
|
2012-01-14 08:31:43 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-12-29 06:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
squads[id-1]->alias = parameters[2];
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
else if (cmd == "hotkey")
|
|
|
|
{
|
2011-12-29 06:37:07 -07:00
|
|
|
if (parameters.size() != 3)
|
2012-01-14 08:31:43 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-12-29 06:37:07 -07:00
|
|
|
|
|
|
|
int id = atoi(parameters[1].c_str());
|
|
|
|
if (id < 1 || id > 16) {
|
|
|
|
c->con.printerr("Invalid hotkey index\n");
|
2012-01-14 08:31:43 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-12-29 06:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->main.hotkeys[id-1].name = parameters[2];
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
|
|
|
else if (cmd == "unit")
|
|
|
|
{
|
|
|
|
if (parameters.size() != 2)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
df::unit *unit = getSelectedUnit(c);
|
|
|
|
if (!unit)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
// There are 3 copies of the name, and the one
|
|
|
|
// in the unit is not the authoritative one.
|
|
|
|
// This is the reason why military units often
|
|
|
|
// lose nicknames set from Dwarf Therapist.
|
|
|
|
set_nickname(&unit->name, parameters[1]);
|
|
|
|
|
|
|
|
if (unit->status.current_soul)
|
|
|
|
set_nickname(&unit->status.current_soul->name, parameters[1]);
|
|
|
|
|
|
|
|
df::historical_figure *figure = df::historical_figure::find(unit->hist_figure_id);
|
|
|
|
if (figure)
|
|
|
|
set_nickname(&figure->name, parameters[1]);
|
|
|
|
}
|
2012-01-15 04:57:33 -07:00
|
|
|
else if (cmd == "unit-profession")
|
|
|
|
{
|
|
|
|
if (parameters.size() != 2)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
df::unit *unit = getSelectedUnit(c);
|
|
|
|
if (!unit)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
unit->custom_profession = parameters[1];
|
|
|
|
}
|
2012-01-14 08:31:43 -07:00
|
|
|
else
|
|
|
|
{
|
2011-12-29 06:37:07 -07:00
|
|
|
if (!parameters.empty() && cmd != "?")
|
|
|
|
c->con.printerr("Invalid command: %s\n", cmd.c_str());
|
2012-01-14 08:31:43 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-12-29 06:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|