diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 928b3874e..0f949a397 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -1276,9 +1276,10 @@ Units module * ``dfhack.units.setLaborValidity(unit_labor, isValid)`` - Sets the given labor to the given (boolean) validity for all playable units in - the game (that is, for all civilizations whose members can be residents of - your fort). + Sets the given labor to the given (boolean) validity for all units that are + part of your fortress civilization. Valid labors are allowed to be toggled + in the in-game labor management screens (including DFHack's labor manipulator + screen). * ``dfhack.units.getNominalSkill(unit, skill[, use_rust])`` diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 6ca2e852a..7edf90817 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -899,19 +899,10 @@ bool Units::setLaborValidity(df::unit_labor labor, bool isValid) return false; if (labor == df::unit_labor::NONE) return false; - for (size_t i = 0; i < world->raws.entities.size(); ++i) - { - if (!world->raws.entities[i] || - world->raws.entities[i]->flags.is_set(df::entity_raw_flags::LAYER_LINKED) || // Animal people - world->raws.entities[i]->flags.is_set(df::entity_raw_flags::GENERATED) || // Vault guardians - !world->raws.entities[i]->flags.is_set(df::entity_raw_flags::CIV_CONTROLLABLE) || // non-controllable civs - world->raws.entities[i]->translation == "") // Kobolds - { - continue; - } - - world->raws.entities[i]->jobs.permitted_labor[labor] = isValid; - } + df::historical_entity *entity = df::historical_entity::find(ui->civ_id); + if (!entity || !entity->entity_raw) + return false; + entity->entity_raw->jobs.permitted_labor[labor] = isValid; return true; }