When a save is loaded/unloaded, the script at raw/onLoad.init or raw/onUnload.init is run. They use the same format as dfhack.init.

develop
expwnent 2013-06-10 00:45:46 -04:00
parent 5c827beae0
commit 9f6638432f
2 changed files with 18 additions and 0 deletions

@ -32,6 +32,7 @@ DFHack future
- autotrade: Automatically send items in marked stockpiles to trade depot, when trading is possible.
- stocks: An improved stocks display screen.
Internals:
- Core: there is now a per-save dfhack.init file for when the save is loaded, and another for when it is unloaded
- EventManager: fixed job completion detection
- Once: easy way to make sure something happens once per run of DF, such as an error message

@ -1298,6 +1298,21 @@ void Core::onUpdate(color_ostream &out)
Lua::Core::onUpdate(out);
}
static void handleLoadAndUnloadScripts(Core* core, color_ostream& out, state_change_event event) {
//TODO: use different separators for windows
std::string rawFolder = "data/save/" + (df::global::world->cur_savegame.save_dir) + "/raw/";
switch(event) {
case SC_WORLD_LOADED:
core->loadScriptFile(out, rawFolder + "onLoad.init", true);
break;
case SC_WORLD_UNLOADED:
core->loadScriptFile(out, rawFolder + "onUnload.init", true);
break;
default:
break;
}
}
void Core::onStateChange(color_ostream &out, state_change_event event)
{
EventManager::onStateChange(out, event);
@ -1307,6 +1322,8 @@ void Core::onStateChange(color_ostream &out, state_change_event event)
plug_mgr->OnStateChange(out, event);
Lua::Core::onStateChange(out, event);
handleLoadAndUnloadScripts(this, out, event);
}
// FIXME: needs to terminate the IO threads and properly dismantle all the machinery involved.