Switch some plugins to using world load/unload instead of map.

Otherwise they apply and remove hooks every time fast travel is used.
develop
Alexander Gavrilov 2012-09-19 19:46:54 +04:00
parent 19e1711a2f
commit b5ede66224
3 changed files with 12 additions and 12 deletions

@ -397,7 +397,7 @@ static void enable_hooks(bool enable)
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{ {
switch (event) { switch (event) {
case SC_MAP_LOADED: case SC_WORLD_LOADED:
if (find_reactions(out)) if (find_reactions(out))
{ {
out.print("Detected spatter add reactions - enabling plugin.\n"); out.print("Detected spatter add reactions - enabling plugin.\n");
@ -406,7 +406,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
else else
enable_hooks(false); enable_hooks(false);
break; break;
case SC_MAP_UNLOADED: case SC_WORLD_UNLOADED:
enable_hooks(false); enable_hooks(false);
reactions.clear(); reactions.clear();
products.clear(); products.clear();
@ -420,8 +420,8 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
if (Core::getInstance().isMapLoaded()) if (Core::getInstance().isWorldLoaded())
plugin_onstatechange(out, SC_MAP_LOADED); plugin_onstatechange(out, SC_WORLD_LOADED);
return CR_OK; return CR_OK;
} }

@ -200,7 +200,7 @@ DFHACK_PLUGIN_LUA_FUNCTIONS {
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{ {
switch (event) { switch (event) {
case SC_MAP_LOADED: case SC_WORLD_LOADED:
{ {
auto pworld = Core::getInstance().getWorld(); auto pworld = Core::getInstance().getWorld();
bool enable = pworld->GetPersistentData("power-meter/enabled").isValid(); bool enable = pworld->GetPersistentData("power-meter/enabled").isValid();
@ -212,7 +212,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
} }
} }
break; break;
case SC_MAP_UNLOADED: case SC_WORLD_UNLOADED:
enable_hooks(false); enable_hooks(false);
break; break;
default: default:
@ -224,8 +224,8 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
if (Core::getInstance().isMapLoaded()) if (Core::getInstance().isWorldLoaded())
plugin_onstatechange(out, SC_MAP_LOADED); plugin_onstatechange(out, SC_WORLD_LOADED);
return CR_OK; return CR_OK;
} }

@ -972,7 +972,7 @@ static void enable_hooks(bool enable)
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{ {
switch (event) { switch (event) {
case SC_MAP_LOADED: case SC_WORLD_LOADED:
if (find_engines()) if (find_engines())
{ {
out.print("Detected steam engine workshops - enabling plugin.\n"); out.print("Detected steam engine workshops - enabling plugin.\n");
@ -981,7 +981,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
else else
enable_hooks(false); enable_hooks(false);
break; break;
case SC_MAP_UNLOADED: case SC_WORLD_UNLOADED:
enable_hooks(false); enable_hooks(false);
engines.clear(); engines.clear();
break; break;
@ -994,8 +994,8 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
if (Core::getInstance().isMapLoaded()) if (Core::getInstance().isWorldLoaded())
plugin_onstatechange(out, SC_MAP_LOADED); plugin_onstatechange(out, SC_WORLD_LOADED);
return CR_OK; return CR_OK;
} }