diff options
| author | Alexander Gavrilov | 2012-01-14 19:31:43 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-01-14 19:31:43 +0400 |
| commit | a31542862aa0a3f8a64db9dcf4d7351394c2dfe9 (patch) | |
| tree | 2bad38a5a63cedac89dba027036735c364295773 /plugins/rename.cpp | |
| parent | 53e9a1659be03338998d08d23c623c41655bbe18 (diff) | |
| download | dfhack-a31542862aa0a3f8a64db9dcf4d7351394c2dfe9.tar.gz dfhack-a31542862aa0a3f8a64db9dcf4d7351394c2dfe9.tar.bz2 dfhack-a31542862aa0a3f8a64db9dcf4d7351394c2dfe9.tar.xz | |
Add utility functions to retrieve the selected job/unit/item.
Units can be selected via 'u', 'j', 'v' and 'k'; full-screen
unit details view not supported.
Items can be selected via 't', 'k', 'v'->inventory.
Also, when viewing a container item full-screen, the selected
contained item or unit is returned; never the container itself.
The api is used in rename to allow setting nicknames for
arbitrary units, including animals and enemies.
Diffstat (limited to 'plugins/rename.cpp')
| -rw-r--r-- | plugins/rename.cpp | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/plugins/rename.cpp b/plugins/rename.cpp index 17841c5f..8ffc3af0 100644 --- a/plugins/rename.cpp +++ b/plugins/rename.cpp @@ -3,10 +3,16 @@ #include <Export.h> #include <PluginManager.h> +#include <modules/Gui.h> + #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> #include <stdlib.h> @@ -30,7 +36,13 @@ DFhackCExport command_result plugin_init (Core *c, std::vector <PluginCommand> & { commands.clear(); if (world && ui) { - commands.push_back(PluginCommand("rename", "Rename various things.", rename)); + commands.push_back(PluginCommand( + "rename", "Rename various things.", rename, false, + " rename squad <index> \"name\"\n" + " rename hotkey <index> \"name\"\n" + " rename unit \"nickname\"\n" + " (a unit must be highlighted in the ui)\n" + )); } return CR_OK; } @@ -40,12 +52,17 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) return CR_OK; } -static command_result usage(Core *c) +static void set_nickname(df::language_name *name, std::string nick) { - c->con << "Usage:" << endl - << " rename squad <index> \"name\"" << endl - << " rename hotkey <index> \"name\"" << endl; - return CR_OK; + if (!name->has_name) + { + *name = df::language_name(); + + name->language = 0; + name->has_name = true; + } + + name->nickname = nick; } static command_result rename(Core * c, vector <string> ¶meters) @@ -56,34 +73,61 @@ static command_result rename(Core * c, vector <string> ¶meters) if (!parameters.empty()) cmd = parameters[0]; - if (cmd == "squad") { + if (cmd == "squad") + { if (parameters.size() != 3) - return usage(c); - + return CR_WRONG_USAGE; + 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"); - return usage(c); + return CR_WRONG_USAGE; } squads[id-1]->alias = parameters[2]; - } else if (cmd == "hotkey") { + } + else if (cmd == "hotkey") + { if (parameters.size() != 3) - return usage(c); + return CR_WRONG_USAGE; int id = atoi(parameters[1].c_str()); if (id < 1 || id > 16) { c->con.printerr("Invalid hotkey index\n"); - return usage(c); + return CR_WRONG_USAGE; } ui->main.hotkeys[id-1].name = parameters[2]; - } else { + } + 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]); + } + else + { if (!parameters.empty() && cmd != "?") c->con.printerr("Invalid command: %s\n", cmd.c_str()); - return usage(c); + return CR_WRONG_USAGE; } return CR_OK; |
