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; }