make alchemist flag valid for controllable civs

develop
myk002 2021-02-05 16:45:39 -08:00
parent 4d57d27d4d
commit 6819ee9928
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
6 changed files with 63 additions and 0 deletions

@ -1270,6 +1270,15 @@ 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)``
Sets the given labor as valid for all playable units in the game (that is, for
all civilizations whose members can be residents of your fort).
* ``dfhack.units.getNominalSkill(unit, skill[, use_rust])``
Retrieves the nominal skill level for the given unit. If ``use_rust``

@ -33,6 +33,9 @@ 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.
# 0.47.04-r5
## Fixes

@ -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),

@ -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);

@ -893,6 +893,28 @@ 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;
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;
}
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)

@ -2279,6 +2279,16 @@ struct unitlist_hook : df::viewscreen_unitlistst
IMPLEMENT_VMETHOD_INTERPOSE(unitlist_hook, feed);
IMPLEMENT_VMETHOD_INTERPOSE(unitlist_hook, render);
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");
}
}
DFhackCExport command_result plugin_enable(color_ostream &out, bool enable)
{
if (!gps)
@ -2291,6 +2301,9 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable)
return CR_FAILURE;
is_enabled = enable;
if (is_enabled)
enable_alchemist(out);
}
return CR_OK;
@ -2306,6 +2319,20 @@ DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCom
return CR_OK;
}
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{
switch (event) {
case SC_MAP_LOADED:
if (is_enabled)
enable_alchemist(out);
break;
default:
break;
}
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
INTERPOSE_HOOK(unitlist_hook, feed).remove();