forbid manipulator editing non-citizens

develop
sv-esk 2016-02-11 06:14:04 +02:00
parent ac070e49a4
commit 83c70ccb0f
4 changed files with 21 additions and 0 deletions

@ -1535,6 +1535,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, isHunter),
WRAPM(Units, isAvailableForAdoption),
WRAPM(Units, isOwnCiv),
WRAPM(Units, isOwnGroup),
WRAPM(Units, isOwnRace),
WRAPM(Units, getRaceName),
WRAPM(Units, getRaceNamePlural),

@ -240,6 +240,7 @@ DFHACK_EXPORT bool isWar(df::unit* unit);
DFHACK_EXPORT bool isHunter(df::unit* unit);
DFHACK_EXPORT bool isAvailableForAdoption(df::unit* unit);
DFHACK_EXPORT bool isOwnCiv(df::unit* unit);
DFHACK_EXPORT bool isOwnGroup(df::unit* unit);
DFHACK_EXPORT bool isOwnRace(df::unit* unit);
DFHACK_EXPORT std::string getRaceNameById(int32_t race_id);

@ -888,6 +888,22 @@ bool Units::isOwnCiv(df::unit* unit)
return unit->civ_id == ui->civ_id;
}
// check if creature belongs to the player's group
bool Units::isOwnGroup(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
auto histfig = df::historical_figure::find(unit->hist_figure_id);
if (!histfig)
return false;
for (size_t i = 0; i < histfig->entity_links.size(); i++)
{
auto link = histfig->entity_links[i];
if (link->entity_id == ui->group_id && (*link).getType() == df::histfig_entity_link_type::MEMBER)
return true;
}
return false;
}
// check if creature belongs to the player's race
// (in combination with check for civ helps to filter out own dwarves)
bool Units::isOwnRace(df::unit* unit)

@ -1146,6 +1146,9 @@ viewscreen_unitlaborsst::viewscreen_unitlaborsst(vector<df::unit*> &src, int cur
if (!Units::isOwnCiv(unit))
cur->allowEdit = false;
if (!Units::isOwnGroup(unit))
cur->allowEdit = false;
if (unit->flags1.bits.dead)
cur->allowEdit = false;