From 2caf3fb0643a30decd8d13c981e8c378ccfd1aa1 Mon Sep 17 00:00:00 2001 From: Robert Heinrich Date: Wed, 11 Apr 2012 22:29:56 +0200 Subject: [PATCH] tweak: removed stuff, added new command 'fixmigrants' which will deal with merchants (traders) and other types of bugged migrants. having more than one command for a bug which is basically the same makes no sense. --- plugins/tweak.cpp | 67 +++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index 3ac9b625b..5f65fe27d 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -53,14 +53,12 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector ¶meters) return CR_FAILURE; } } - else if (cmd == "clear-resident") + else if (cmd == "fixmigrant") { df::unit *unit = getSelectedUnit(out); - if (!unit) - return CR_FAILURE; - // must be own race and civ and a merchant - if ( unit->flags2.bits.resident - && unit->race == df::global::ui->race_id - && unit->civ_id == df::global::ui->civ_id) + if (!unit) { - // remove resident flag - unit->flags2.bits.resident = 0; - return fix_clothing_ownership(out, unit); + out << "No unit selected!" << endl; + return CR_FAILURE; } - else + + if(unit->race != df::global::ui->race_id) { - out.print("That's not a resident dwarf of your civilization!\n"); + out << "Selected unit does not belong to your race!" << endl; return CR_FAILURE; } - } - else if (cmd == "clear-merchant") - { - df::unit *unit = getSelectedUnit(out); - if (!unit) - return CR_FAILURE; - // must be own race and civ and a merchant - if ( unit->flags1.bits.merchant - && unit->race == df::global::ui->race_id - && unit->civ_id == df::global::ui->civ_id) - { - // remove merchant flag + if (unit->flags2.bits.resident) + unit->flags2.bits.resident = 0; + + if(unit->flags1.bits.merchant) unit->flags1.bits.merchant = 0; - return fix_clothing_ownership(out, unit); - } - else - { - out.print("That's not a dwarf merchant of your civilization!\n"); - return CR_FAILURE; - } + + // this one is a cheat, but bugged migrants usually have the same civ_id + // but if it happens that the player has 'foreign' units of the same race + // (dwarves not from moutainhome in vanilla df) on his map, just grab them + if(unit->civ_id != df::global::ui->civ_id) + unit->civ_id = df::global::ui->civ_id; + + return fix_clothing_ownership(out, unit); } - else return CR_WRONG_USAGE; + else + return CR_WRONG_USAGE; return CR_OK; }