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 features
Fixes
steam-engine: fixed a crash on arena load
Misc Improvements
Removed

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