Fix a few issues with init file variations

* GCC does not allow std::string instances or enums without a base
  type to be passed as varargs
* Fixed path concatenation issue causing dfhack.init to not be loaded
develop
lethosor 2015-09-21 18:57:58 -04:00
parent 0a4f55b7dd
commit 91a1836439
1 changed files with 18 additions and 24 deletions

@ -1862,7 +1862,7 @@ size_t loadScriptFiles(Core* core, color_ostream& out, const vector<std::string>
size_t result = 0; size_t result = 0;
for ( size_t a = 0; a < scriptFiles.size(); a++ ) { for ( size_t a = 0; a < scriptFiles.size(); a++ ) {
result++; result++;
core->loadScriptFile(out, folder + scriptFiles[a], true); core->loadScriptFile(out, folder + "/" + scriptFiles[a], true);
} }
return result; return result;
} }
@ -1880,15 +1880,15 @@ namespace DFHack {
va_start(list,none); va_start(list,none);
EntryVector result; EntryVector result;
while(true) { while(true) {
Key key = va_arg(list,Key); Key key = (Key)va_arg(list,int);
if ( key < 0 ) if ( key == SC_UNKNOWN )
break; break;
Val val; Val val;
while(true) { while (true) {
string v = va_arg(list,string); const char *v = va_arg(list, const char *);
if ( v.empty() ) if (!v || !v[0])
break; break;
val.push_back(v); val.push_back(string(v));
} }
result.push_back(Entry(key,val)); result.push_back(Entry(key,val));
} }
@ -1904,29 +1904,23 @@ namespace DFHack {
void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event event) { void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event event) {
static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(0, static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(0,
SC_WORLD_LOADED, (string)"onLoad", (string)"onLoadWorld", (string)"onWorldLoaded", (string)"", (int)SC_WORLD_LOADED, "onLoad", "onLoadWorld", "onWorldLoaded", "",
SC_WORLD_UNLOADED, (string)"onUnload", (string)"onUnloadWorld", (string)"onWorldUnloaded", (string)"", (int)SC_WORLD_UNLOADED, "onUnload", "onUnloadWorld", "onWorldUnloaded", "",
SC_MAP_LOADED, (string)"onMapLoad", (string)"onLoadMap", (string)"", (int)SC_MAP_LOADED, "onMapLoad", "onLoadMap", "",
SC_MAP_UNLOADED, (string)"onMapUnload", (string)"onUnloadMap", (string)"", (int)SC_MAP_UNLOADED, "onMapUnload", "onUnloadMap", "",
(X::Key)(-1) (int)SC_UNKNOWN
)); ));
if (!df::global::world) if (!df::global::world)
return; return;
//TODO: use different separators for windows std::string rawFolder = "data/save/" + (df::global::world->cur_savegame.save_dir) + "/raw/";
#ifdef _WIN32
static const std::string separator = "\\";
#else
static const std::string separator = "/";
#endif
std::string rawFolder = "data" + separator + "save" + separator + (df::global::world->cur_savegame.save_dir) + separator + "raw" + separator;
auto i = table.find(event); auto i = table.find(event);
if ( i != table.end() ) { if ( i != table.end() ) {
const std::vector<std::string>& set = i->second; const std::vector<std::string>& set = i->second;
loadScriptFiles(this, out, set, "." ); loadScriptFiles(this, out, set, "." );
loadScriptFiles(this, out, set, rawFolder); loadScriptFiles(this, out, set, rawFolder);
loadScriptFiles(this, out, set, rawFolder + "objects" + separator); loadScriptFiles(this, out, set, rawFolder + "objects/");
} }
for (auto it = state_change_scripts.begin(); it != state_change_scripts.end(); ++it) for (auto it = state_change_scripts.begin(); it != state_change_scripts.end(); ++it)