00001 /* $Id: map_create.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2003 - 2012 by David White <dave@whitevine.net> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #include "global.hpp" 00017 #include "map_create.hpp" 00018 00019 #include "cavegen.hpp" 00020 #include "log.hpp" 00021 #include "mapgen_dialog.hpp" 00022 #include "scoped_resource.hpp" 00023 #include "serialization/string_utils.hpp" 00024 00025 00026 static lg::log_domain log_config("config"); 00027 #define ERR_CF LOG_STREAM(err, log_config) 00028 00029 map_generator* create_map_generator(const std::string& name, const config &cfg) 00030 { 00031 if(name == "default" || name == "") { 00032 return new default_map_generator(cfg); 00033 } else if(name == "cave") { 00034 return new cave_map_generator(cfg); 00035 } else { 00036 return NULL; 00037 } 00038 } 00039 00040 //function to generate a random map, from a string which describes 00041 //the generator to use and its arguments 00042 std::string random_generate_map(const std::string& parms, const config &cfg) 00043 { 00044 //the first token is the name of the generator, tokens after 00045 //that are arguments to the generator 00046 std::vector<std::string> parameters = utils::split(parms, ' '); 00047 util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg)); 00048 if(generator == NULL) { 00049 ERR_CF << "could not find map generator '" << parameters.front() << "'\n"; 00050 return std::string(); 00051 } 00052 00053 parameters.erase(parameters.begin()); 00054 return generator.get()->create_map(parameters); 00055 } 00056 00057 config random_generate_scenario(const std::string& parms, const config &cfg) 00058 { 00059 //the first token is the name of the generator, tokens after 00060 //that are arguments to the generator 00061 std::vector<std::string> parameters = utils::split(parms, ' '); 00062 util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg)); 00063 if(generator == NULL) { 00064 ERR_CF << "could not find map generator '" << parameters.front() << "'\n"; 00065 return config(); 00066 } 00067 00068 parameters.erase(parameters.begin()); 00069 return generator->create_scenario(parameters); 00070 }
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:05 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |