The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
map_create.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
20 #include "log.hpp"
22 
23 #include <cassert>
24 #include <sstream>
25 
26 static lg::log_domain log_config("config");
27 #define ERR_CF LOG_STREAM(err, log_config)
28 
30 {
31  if(name == "default" || name.empty()) {
32  return new default_map_generator(cfg);
33  } else if(name == "cave") {
34  ERR_CF << "map/scenario_generation=cave is deprecatd and will be removed soon, use map/scenario_generation=lua with lua/cave_map_generator.lua instead.\n";
35  return new cave_map_generator(cfg);
36  } else if(name == "lua") {
37  return new lua_map_generator(cfg);
38  } else {
39  return nullptr;
40  }
41 }
42 
43 //function to generate a random map, from a string which describes
44 //the generator to use
46 {
47  std::unique_ptr<map_generator> generator(create_map_generator(name,cfg));
48  if(generator == nullptr) {
49  std::stringstream ss;
50  ss << "could not find map generator '" << name << "'";
51  throw mapgen_exception(ss.str());
52  }
53 
54  return generator->create_map();
55 }
56 
58 {
59  std::unique_ptr<map_generator> generator(create_map_generator(name,cfg));
60  if(generator == nullptr) {
61  std::stringstream ss;
62  ss << "could not find map generator '" << name << "'";
63  throw mapgen_exception(ss.str());
64  }
65 
66  return generator->create_scenario();
67 }
std::vector< char_t > string
static lg::log_domain log_config("config")
virtual config create_scenario(boost::optional< uint32_t > randomseed=boost::none)
config random_generate_scenario(const std::string &name, const config &cfg)
Definition: map_create.cpp:57
#define ERR_CF
Definition: map_create.cpp:27
virtual std::string create_map(boost::optional< uint32_t > randomseed=boost::none)=0
Creates a new map and returns it.
map_generator * create_map_generator(const std::string &name, const config &cfg)
Definition: map_create.cpp:29
rng * generator
This generator is automatically synced during synced context.
Definition: random.cpp:57
std::string random_generate_map(const std::string &name, const config &cfg)
Definition: map_create.cpp:45
Standard logging facilities (interface).
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93