bool loadGameConfAndInitWorld(const std::string &path, const SubgameSpec &gamespec) { // Override defaults with those provided by the game. // We clear and reload the defaults because the defaults // might have been overridden by other subgame config // files that were loaded before. g_settings->clearDefaults(); set_default_settings(g_settings); Settings game_defaults; getGameMinetestConfig(gamespec.path, game_defaults); override_default_settings(g_settings, &game_defaults); infostream << "Initializing world at " << path << std::endl; fs::CreateAllDirs(path); // Create world.mt if does not already exist std::string worldmt_path = path + DIR_DELIM "world.mt"; if (!fs::PathExists(worldmt_path)) { Settings conf; conf.set("gameid", gamespec.id); conf.set("backend", "sqlite3"); conf.set("player_backend", "sqlite3"); conf.setBool("creative_mode", g_settings->getBool("creative_mode")); conf.setBool("enable_damage", g_settings->getBool("enable_damage")); if (!conf.updateConfigFile(worldmt_path.c_str())) return false; } // Create map_meta.txt if does not already exist std::string map_meta_path = path + DIR_DELIM + "map_meta.txt"; if (!fs::PathExists(map_meta_path)) { verbosestream << "Creating map_meta.txt (" << map_meta_path << ")" << std::endl; fs::CreateAllDirs(path); std::ostringstream oss(std::ios_base::binary); Settings conf; MapgenParams params; params.readParams(g_settings); params.writeParams(&conf); conf.writeLines(oss); oss << "[end_of_params]\n"; fs::safeWriteToFile(map_meta_path, oss.str()); } return true; }
MapgenParams *EmergeManager::getParamsFromSettings(Settings *settings) { std::string mg_name = settings->get("mg_name"); MapgenParams *mgparams = createMapgenParams(mg_name); mgparams->mg_name = mg_name; mgparams->seed = settings->getU64(settings == g_settings ? "fixed_map_seed" : "seed"); mgparams->water_level = settings->getS16("water_level"); mgparams->chunksize = settings->getS16("chunksize"); mgparams->flags = settings->getFlagStr("mg_flags", flagdesc_mapgen); if (!mgparams->readParams(settings)) { delete mgparams; return NULL; } return mgparams; }
MapgenParams *MapSettingsManager::makeMapgenParams() { if (mapgen_params) return mapgen_params; assert(m_user_settings != NULL); assert(m_map_settings != NULL); // At this point, we have (in order of precedence): // 1). m_mapgen_settings->m_settings containing map_meta.txt settings or // explicit overrides from scripts // 2). m_mapgen_settings->m_defaults containing script-set mgparams without // overrides // 3). g_settings->m_settings containing all user-specified config file // settings // 4). g_settings->m_defaults containing any low-priority settings from // scripts, e.g. mods using Lua as an enhanced config file) // Now, get the mapgen type so we can create the appropriate MapgenParams std::string mg_name; MapgenType mgtype = getMapSetting("mg_name", &mg_name) ? Mapgen::getMapgenType(mg_name) : MAPGEN_DEFAULT; if (mgtype == MAPGEN_INVALID) { errorstream << "EmergeManager: mapgen '" << mg_name << "' not valid; falling back to " << Mapgen::getMapgenName(MAPGEN_DEFAULT) << std::endl; mgtype = MAPGEN_DEFAULT; } // Create our MapgenParams MapgenParams *params = Mapgen::createMapgenParams(mgtype); if (params == NULL) return NULL; params->mgtype = mgtype; // Load the rest of the mapgen params from our active settings params->MapgenParams::readParams(m_user_settings); params->MapgenParams::readParams(m_map_settings); params->readParams(m_user_settings); params->readParams(m_map_settings); // Hold onto our params mapgen_params = params; return params; }
MapgenParams *EmergeManager::setMapgenType(MapgenParams *mgparams, std::string newname) { MapgenParams *newparams = createMapgenParams(newname); if (!newparams) { errorstream << "EmergeManager: Mapgen override failed" << std::endl; return NULL; } newparams->mg_name = newname; newparams->seed = mgparams->seed; newparams->water_level = mgparams->water_level; newparams->chunksize = mgparams->chunksize; newparams->flags = mgparams->flags; if (!newparams->readParams(g_settings)) { errorstream << "EmergeManager: Mapgen override failed" << std::endl; delete newparams; return NULL; } delete mgparams; return newparams; }