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-04-07 09:08:30 -06:00
|
|
|
#include "modules/Translation.h"
|
|
|
|
#include "modules/Units.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"
|
2012-02-22 06:44:36 -07:00
|
|
|
#include "df/historical_entity.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "df/historical_figure.h"
|
2012-02-20 07:04:58 -07:00
|
|
|
#include "df/historical_figure_info.h"
|
|
|
|
#include "df/assumed_identity.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "df/language_name.h"
|
2011-12-29 06:37:07 -07:00
|
|
|
|
2012-03-15 03:01:23 -06:00
|
|
|
#include "RemoteServer.h"
|
|
|
|
#include "rename.pb.h"
|
|
|
|
|
2012-04-05 08:10:16 -06:00
|
|
|
#include "MiscUtils.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;
|
2012-03-15 03:01:23 -06:00
|
|
|
using namespace dfproto;
|
2011-12-29 06:37:07 -07:00
|
|
|
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::world;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result rename(color_ostream &out, vector <string> & parameters);
|
2011-12-29 06:37:07 -07:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("rename");
|
2011-12-29 06:37:07 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-12-29 06:37:07 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-12-29 06:37:07 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-22 06:44:36 -07:00
|
|
|
static df::squad *getSquadByIndex(unsigned idx)
|
|
|
|
{
|
|
|
|
auto entity = df::historical_entity::find(ui->group_id);
|
|
|
|
if (!entity)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (idx >= entity->squads.size())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return df::squad::find(entity->squads[idx]);
|
|
|
|
}
|
|
|
|
|
2012-03-17 10:04:15 -06:00
|
|
|
static command_result RenameSquad(color_ostream &stream, const RenameSquadIn *in)
|
2012-03-15 03:01:23 -06:00
|
|
|
{
|
|
|
|
df::squad *squad = df::squad::find(in->squad_id());
|
|
|
|
if (!squad)
|
|
|
|
return CR_NOT_FOUND;
|
|
|
|
|
|
|
|
if (in->has_nickname())
|
2012-04-07 09:08:30 -06:00
|
|
|
Translation::setNickname(&squad->name, UTF2DF(in->nickname()));
|
2012-03-15 03:01:23 -06:00
|
|
|
if (in->has_alias())
|
2012-04-05 08:10:16 -06:00
|
|
|
squad->alias = UTF2DF(in->alias());
|
2012-03-15 03:01:23 -06:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-17 10:04:15 -06:00
|
|
|
static command_result RenameUnit(color_ostream &stream, const RenameUnitIn *in)
|
2012-03-15 03:01:23 -06:00
|
|
|
{
|
|
|
|
df::unit *unit = df::unit::find(in->unit_id());
|
|
|
|
if (!unit)
|
|
|
|
return CR_NOT_FOUND;
|
|
|
|
|
|
|
|
if (in->has_nickname())
|
2012-04-07 09:08:30 -06:00
|
|
|
Units::setNickname(unit, UTF2DF(in->nickname()));
|
2012-03-15 03:01:23 -06:00
|
|
|
if (in->has_profession())
|
2012-04-05 08:10:16 -06:00
|
|
|
unit->custom_profession = UTF2DF(in->profession());
|
2012-03-15 03:01:23 -06:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport RPCService *plugin_rpcconnect(color_ostream &)
|
|
|
|
{
|
|
|
|
RPCService *svc = new RPCService();
|
|
|
|
svc->addFunction("RenameSquad", RenameSquad);
|
|
|
|
svc->addFunction("RenameUnit", RenameUnit);
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result rename(color_ostream &out, vector <string> ¶meters)
|
2011-12-29 06:37:07 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2011-12-29 06:37:07 -07:00
|
|
|
|
|
|
|
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
|
|
|
int id = atoi(parameters[1].c_str());
|
2012-02-22 06:44:36 -07:00
|
|
|
df::squad *squad = getSquadByIndex(id-1);
|
|
|
|
|
|
|
|
if (!squad) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Couldn't find squad with index %d.\n", id);
|
2012-01-14 08:31:43 -07:00
|
|
|
return CR_WRONG_USAGE;
|
2011-12-29 06:37:07 -07:00
|
|
|
}
|
|
|
|
|
2012-02-22 06:44:36 -07:00
|
|
|
squad->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) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.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;
|
|
|
|
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = Gui::getSelectedUnit(out, true);
|
2012-01-14 08:31:43 -07:00
|
|
|
if (!unit)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-04-07 09:08:30 -06:00
|
|
|
Units::setNickname(unit, parameters[1]);
|
2012-01-14 08:31:43 -07:00
|
|
|
}
|
2012-01-15 04:57:33 -07:00
|
|
|
else if (cmd == "unit-profession")
|
|
|
|
{
|
|
|
|
if (parameters.size() != 2)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-04-17 08:57:41 -06:00
|
|
|
df::unit *unit = Gui::getSelectedUnit(out, true);
|
2012-01-15 04:57:33 -07:00
|
|
|
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 != "?")
|
2012-03-10 04:55:42 -07:00
|
|
|
out.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;
|
|
|
|
}
|