map_create.cpp

Go to the documentation of this file.
00001 /* $Id: map_create.cpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 #include "global.hpp"
00016 
00017 #include "cavegen.hpp"
00018 #include "log.hpp"
00019 #include "map_create.hpp"
00020 #include "mapgen_dialog.hpp"
00021 #include "scoped_resource.hpp"
00022 #include "serialization/string_utils.hpp"
00023 
00024 #include <ostream>
00025 #include <string>
00026 #include <vector>
00027 
00028 #define ERR_CF LOG_STREAM(err, config)
00029 
00030 map_generator* create_map_generator(const std::string& name, const config* cfg)
00031 {
00032     if(name == "default" || name == "") {
00033         return new default_map_generator(cfg);
00034     } else if(name == "cave") {
00035         return new cave_map_generator(cfg);
00036     } else {
00037         return NULL;
00038     }
00039 }
00040 
00041 //function to generate a random map, from a string which describes
00042 //the generator to use and its arguments
00043 std::string random_generate_map(const std::string& parms, const config* cfg)
00044 {
00045     //the first token is the name of the generator, tokens after
00046     //that are arguments to the generator
00047     std::vector<std::string> parameters = utils::split(parms, ' ');
00048     util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg));
00049     if(generator == NULL) {
00050         ERR_CF << "could not find map generator '" << parameters.front() << "'\n";
00051         return std::string();
00052     }
00053 
00054     parameters.erase(parameters.begin());
00055     return generator.get()->create_map(parameters);
00056 }
00057 
00058 config random_generate_scenario(const std::string& parms, const config* cfg)
00059 {
00060     //the first token is the name of the generator, tokens after
00061     //that are arguments to the generator
00062     std::vector<std::string> parameters = utils::split(parms, ' ');
00063     util::scoped_ptr<map_generator> generator(create_map_generator(parameters.front(),cfg));
00064     if(generator == NULL) {
00065         ERR_CF << "could not find map generator '" << parameters.front() << "'\n";
00066         return config();
00067     }
00068 
00069     parameters.erase(parameters.begin());
00070     return generator->create_scenario(parameters);
00071 }

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs