config random_generate_scenario(const std::string& parms, const config &cfg) { //the first token is the name of the generator, tokens after //that are arguments to the generator std::vector<std::string> parameters = utils::split(parms, ' '); util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg)); if(generator == NULL) { ERR_CF << "could not find map generator '" << parameters.front() << "'\n"; return config(); } parameters.erase(parameters.begin()); return generator->create_scenario(parameters); }
//function to generate a random map, from a string which describes //the generator to use and its arguments std::string random_generate_map(const std::string& parms, const config &cfg) { //the first token is the name of the generator, tokens after //that are arguments to the generator std::vector<std::string> parameters = utils::split(parms, ' '); assert(!parameters.empty()); //we use parameters.front() in the next line. util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg)); if(generator == NULL) { ERR_CF << "could not find map generator '" << parameters.front() << "'" << std::endl; return std::string(); } parameters.erase(parameters.begin()); return generator.get()->create_map(); }
void editor_controller::init_map_generators(const config& game_config) { foreach (const config &i, game_config.child_range("multiplayer")) { if (i["map_generation"] == "default") { const config &generator_cfg = i.child("generator"); if (!generator_cfg) { ERR_ED << "Scenario \"" << i["name"] << "\" with id " << i["id"] << " has map_generation=default but no [generator] tag"; } else { map_generator* m = create_map_generator("", generator_cfg); map_generators_.push_back(m); } } } }
config random_generate_scenario(const std::string& parms, const config &cfg) { //the first token is the name of the generator, tokens after //that are arguments to the generator std::vector<std::string> parameters = utils::split(parms, ' '); assert(!parameters.empty()); //we use parameters.front() in the next line. std::unique_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg)); if(generator == nullptr) { std::stringstream ss; ss << "could not find map generator '" << parameters.front() << "'"; throw mapgen_exception(ss.str()); } parameters.erase(parameters.begin()); return generator->create_scenario(); }