move alchemist-enabling logic to autohauler

develop
myk002 2021-02-06 14:14:08 -08:00
parent 6819ee9928
commit 09d91dcae1
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
3 changed files with 21 additions and 34 deletions

@ -1274,10 +1274,11 @@ Units module
Returns whether the indicated labor is settable for the given unit.
* ``dfhack.units.setLaborValidity(unit_labor)``
* ``dfhack.units.setLaborValidity(unit_labor, isValid)``
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).
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).
* ``dfhack.units.getNominalSkill(unit, skill[, use_rust])``

@ -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 <Plug
));
// Initialize plugin labor lists
init_state();
init_state(out);
return CR_OK;
}
@ -763,7 +776,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
switch (event) {
case SC_MAP_LOADED:
cleanup_state();
init_state();
init_state(out);
break;
case SC_MAP_UNLOADED:
cleanup_state();

@ -2279,16 +2279,6 @@ 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)
@ -2301,9 +2291,6 @@ 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;
@ -2319,20 +2306,6 @@ 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();