//-------------------------------------------------------------------------------------------- bool_t setup_write() { /// @details BB@> save the current setup file bool_t success = bfalse; if ( INVALID_CSTR( _config_filename ) ) return bfalse; success = ConfigFile_succeed == SaveConfigFileAs( lConfigSetup, _config_filename ); if ( !success ) log_warning( "Failed to save setup.txt!\n" ); return success; }
//-------------------------------------------------------------------------------------------- bool setup_init_module_vfs_paths(const char *mod_path) { const char * path_seperator_1, * path_seperator_2; const char * mod_dir_ptr; STRING mod_dir_string; STRING tmpDir; if ( INVALID_CSTR( mod_path ) ) return false; // revert to the program's basic mount points setup_clear_module_vfs_paths(); path_seperator_1 = strrchr( mod_path, SLASH_CHR ); path_seperator_2 = strrchr( mod_path, NET_SLASH_CHR ); path_seperator_1 = std::max( path_seperator_1, path_seperator_2 ); if ( NULL == path_seperator_1 ) { mod_dir_ptr = mod_path; } else { mod_dir_ptr = path_seperator_1 + 1; } strncpy( mod_dir_string, mod_dir_ptr, SDL_arraysize( mod_dir_string ) ); //==== set the module-dependent mount points //---- add the "/modules/*.mod/objects" directories to mp_objects snprintf( tmpDir, SDL_arraysize( tmpDir ), "modules" SLASH_STR "%s" SLASH_STR "objects", mod_dir_string ); // mount the user's module objects directory at the beginning of the mount point list vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath(tmpDir), Ego::VfsPath("mp_objects"), 1 ); // mount the global module objects directory next in the mount point list vfs_add_mount_point( fs_getUserDirectory(), Ego::FsPath(tmpDir), Ego::VfsPath("mp_objects"), 1 ); //---- add the "/basicdat/globalobjects/*" directories to mp_objects //ZF> TODO: Maybe we should dynamically search for all folders in this directory and add them as valid mount points? vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "items"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "magic"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "magic_item"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "misc"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "monsters"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "players"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "potions"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "unique"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "weapons"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "work_in_progress"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "traps"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "pets"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "scrolls"), Ego::VfsPath("mp_objects"), 1 ); vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalobjects" SLASH_STR "armor"), Ego::VfsPath("mp_objects"), 1 ); //---- add the "/modules/*.mod/gamedat" directory to mp_data snprintf( tmpDir, SDL_arraysize( tmpDir ), "modules" SLASH_STR "%s" SLASH_STR "gamedat", mod_dir_string ); // mount the user's module gamedat directory at the beginning of the mount point list vfs_add_mount_point( fs_getUserDirectory(), Ego::FsPath(tmpDir), Ego::VfsPath("mp_data"), 1 ); // append the global module gamedat directory vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath(tmpDir), Ego::VfsPath("mp_data"), 1 ); // put the global globalparticles data after the module gamedat data vfs_add_mount_point( fs_getDataDirectory(), Ego::FsPath("basicdat" SLASH_STR "globalparticles"), Ego::VfsPath("mp_data"), 1 ); return true; }
//-------------------------------------------------------------------------------------------- egoboo_rv get_random_treasure( char * buffer, size_t buffer_length ) { //ZF> Gets the name for a treasure randomly selected from the specified treasure table // This function effectively "converts" a table name into a random element from that table IPair loc_rand; size_t i; int treasure_index; bool_t found = bfalse; STRING tmp_buffer; // Trap invalid strings if ( 0 == buffer_length || INVALID_CSTR( buffer ) ) return rv_error; // make a local copy of the string strncpy( tmp_buffer, buffer, SDL_arraysize( tmp_buffer ) ); // Iterate through every treasure table until we find the one we want found = bfalse; for ( i = 0; i < MAX_TABLES; i++ ) { //Continue looking until we find the correct table if ( 0 != strcmp( treasureTableList[i].table_name, tmp_buffer ) ) continue; //Pick a random number between 0 and the length of the table to get a random element out of the array loc_rand.base = 0; loc_rand.rand = treasureTableList[i].size; treasure_index = generate_irand_pair( loc_rand ); strncpy( tmp_buffer, treasureTableList[i].object_list[treasure_index], buffer_length ); //See if it is an actual random object or a reference to a different random table if ( '%' != tmp_buffer[0] ) { found = btrue; } else { if ( rv_success == get_random_treasure( tmp_buffer, buffer_length ) ) { found = btrue; } } } //Could not find anything if ( found ) { // copy the local string to the output strncpy( buffer, tmp_buffer, buffer_length ); printf( "Random treasure: %s\n", buffer ); } else { // give a warning tmp_buffer[0] = CSTR_END; log_warning( "Could not find treasure table: %s!\n", buffer ); } return found ? rv_success : rv_fail; }