Only initialize steam-engine when a fortress mode map is loaded

world->raws.buildings.workshops is not always cleared on world load
(notably in the arena), so it can contain invalid pointers from
previous games.

Fixes #444
develop
lethosor 2015-04-02 17:17:29 -04:00
parent 7758311f88
commit 6187ac3054
2 changed files with 5 additions and 3 deletions

@ -8,6 +8,7 @@ DFHack Future
New tweaks New tweaks
New features New features
Fixes Fixes
steam-engine: fixed a crash on arena load
Misc Improvements Misc Improvements
Removed Removed

@ -5,6 +5,7 @@
#include <modules/Gui.h> #include <modules/Gui.h>
#include <modules/Screen.h> #include <modules/Screen.h>
#include <modules/Maps.h> #include <modules/Maps.h>
#include <modules/World.h>
#include <TileTypes.h> #include <TileTypes.h>
#include <vector> #include <vector>
#include <cstdio> #include <cstdio>
@ -978,8 +979,8 @@ 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_WORLD_LOADED: case SC_MAP_LOADED:
if (find_engines(out)) if (World::isFortressMode() && find_engines(out))
{ {
out.print("Detected steam engine workshops - enabling plugin.\n"); out.print("Detected steam engine workshops - enabling plugin.\n");
enable_hooks(true); enable_hooks(true);
@ -987,7 +988,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
else else
enable_hooks(false); enable_hooks(false);
break; break;
case SC_WORLD_UNLOADED: case SC_MAP_UNLOADED:
enable_hooks(false); enable_hooks(false);
engines.clear(); engines.clear();
break; break;