@ -1213,7 +1213,7 @@ static void run_dfhack_init(color_ostream &out, Core *core)
out . printerr ( " Key globals are missing, skipping loading dfhack.init. \n " ) ;
out . printerr ( " Key globals are missing, skipping loading dfhack.init. \n " ) ;
return ;
return ;
}
}
std : : vector < std : : string > prefixes ( 1 , " dfhack " ) ;
std : : vector < std : : string > prefixes ( 1 , " dfhack " ) ;
size_t count = loadScriptFiles ( core , out , prefixes , " . " ) ;
size_t count = loadScriptFiles ( core , out , prefixes , " . " ) ;
if ( ! count )
if ( ! count )
@ -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,22 +1880,22 @@ 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 ) ) ;
}
}
va_end ( list ) ;
va_end ( list ) ;
return result ;
return result ;
}
}
InitVariationTable getTable ( const EntryVector & vec ) {
InitVariationTable getTable ( const EntryVector & vec ) {
return InitVariationTable ( vec . begin ( ) , vec . end ( ) ) ;
return InitVariationTable ( vec . begin ( ) , vec . end ( ) ) ;
}
}
@ -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 )