diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 81c662728..0f949a397 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -1270,6 +1270,17 @@ Units module Returns the age of the unit in years as a floating-point value. If ``true_age`` is true, ignores false identities. +* ``dfhack.units.isValidLabor(unit, unit_labor)`` + + Returns whether the indicated labor is settable for the given unit. + +* ``dfhack.units.setLaborValidity(unit_labor, isValid)`` + + 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])`` Retrieves the nominal skill level for the given unit. If ``use_rust`` diff --git a/docs/changelog.txt b/docs/changelog.txt index f7a9b28a1..8dafc52c2 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -34,6 +34,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future ## Misc Improvements +- `autohauler`: allow the ``Alchemist`` labor to be enabled in `manipulator` and other labor screens so it can be used for its intended purpose of flagging that no hauling labors should be assigned to a dwarf. Before, the only way to set the flag was to use an external program like Dwarf Therapist. - `embark-assistant`: slightly improved performance of surveying - `quickfort`: Dreamfort blueprint set improvements: `significant `_ refinements across the entire blueprint set. Dreamfort is now much faster, much more efficient, and much easier to use. The `checklist `__ now includes a mini-walkthrough for quick reference. The spreadsheet now also includes `embark profile suggestions `__ - `quickfort`: added aliases for configuring masterwork and artifact core quality for all stockpile categories that have them; made it possible to take from multiple stockpiles in the ``quantumstop`` alias diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index d7f3b269f..1c115471a 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1600,6 +1600,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = { WRAPM(Units, getEffectiveSkill), WRAPM(Units, getExperience), WRAPM(Units, isValidLabor), + WRAPM(Units, setLaborValidity), WRAPM(Units, computeMovementSpeed), WRAPM(Units, computeSlowdownFactor), WRAPM(Units, getProfessionName), diff --git a/library/include/modules/Units.h b/library/include/modules/Units.h index e2d34254d..4a8452203 100644 --- a/library/include/modules/Units.h +++ b/library/include/modules/Units.h @@ -163,6 +163,7 @@ DFHACK_EXPORT int getEffectiveSkill(df::unit *unit, df::job_skill skill_id); DFHACK_EXPORT int getExperience(df::unit *unit, df::job_skill skill_id, bool total = false); DFHACK_EXPORT bool isValidLabor(df::unit *unit, df::unit_labor labor); +DFHACK_EXPORT bool setLaborValidity(df::unit_labor labor, bool isValid); DFHACK_EXPORT int computeMovementSpeed(df::unit *unit); DFHACK_EXPORT float computeSlowdownFactor(df::unit *unit); diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index a8f96b29f..7edf90817 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -893,6 +893,19 @@ bool Units::isValidLabor(df::unit *unit, df::unit_labor labor) return true; } +bool Units::setLaborValidity(df::unit_labor labor, bool isValid) +{ + if (!is_valid_enum_item(labor)) + return false; + if (labor == df::unit_labor::NONE) + return false; + 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; +} + inline void adjust_speed_rating(int &rating, bool is_adventure, int value, int dwarf100, int dwarf200, int adv50, int adv75, int adv100, int adv200) { if (is_adventure) diff --git a/plugins/autohauler.cpp b/plugins/autohauler.cpp index 40d7452c7..7dd574f5f 100644 --- a/plugins/autohauler.cpp +++ b/plugins/autohauler.cpp @@ -565,10 +565,20 @@ static void cleanup_state() labor_infos.clear(); } +static void enable_alchemist(color_ostream &out) +{ + if (!Units::setLaborValidity(unit_labor::ALCHEMIST, true)) + { + // informational only; this is a non-fatal error + out.printerr("manipulator: Could not flag Alchemist as a valid skill; Alchemist will not" + " be settable from DF or DFHack labor management screens.\n"); + } +} + /** * Initialize the plugin labor lists */ -static void init_state() +static void init_state(color_ostream &out) { // This obtains the persistent data from the world save file config = World::GetPersistentData("autohauler/config"); @@ -656,6 +666,9 @@ static void init_state() reset_labor((df::unit_labor) i); } + // Allow Alchemist to be set in the labor-related UI screens so the player + // can actually use it as a flag without having to run Dwarf Therapist + enable_alchemist(out); } /** @@ -681,7 +694,7 @@ static void enable_plugin(color_ostream &out) cleanup_state(); // Initialize the plugin - init_state(); + init_state(out); } /** @@ -740,7 +753,7 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector