The Battle for Wesnoth  1.13.4+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 - 2016 by David White <[email protected]>
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 
15 #include "global.hpp"
16 #include "map_create.hpp"
17 
21 #include "log.hpp"
22 #include "scoped_resource.hpp"
24 
25 #include <cassert>
26 #include <sstream>
27 
28 static lg::log_domain log_config("config");
29 #define ERR_CF LOG_STREAM(err, log_config)
30 
32 {
33  if(name == "default" || name == "") {
34  return new default_map_generator(cfg);
35  } else if(name == "cave") {
36  return new cave_map_generator(cfg);
37  } else if(name == "lua") {
38  return new lua_map_generator(cfg);
39  } else {
40  return nullptr;
41  }
42 }
43 
44 //function to generate a random map, from a string which describes
45 //the generator to use and its arguments
47 {
48  //the first token is the name of the generator, tokens after
49  //that are arguments to the generator
50  std::vector<std::string> parameters = utils::split(parms, ' ');
51  assert(!parameters.empty()); //we use parameters.front() in the next line.
53  if(generator == nullptr) {
54  std::stringstream ss;
55  ss << "could not find map generator '" << parameters.front() << "'";
56  throw mapgen_exception(ss.str());
57  }
58 
59  parameters.erase(parameters.begin());
60  return generator.get()->create_map();
61 }
62 
64 {
65  //the first token is the name of the generator, tokens after
66  //that are arguments to the generator
67  std::vector<std::string> parameters = utils::split(parms, ' ');
68  assert(!parameters.empty()); //we use parameters.front() in the next line.
70  if(generator == nullptr) {
71  std::stringstream ss;
72  ss << "could not find map generator '" << parameters.front() << "'";
73  throw mapgen_exception(ss.str());
74  }
75 
76  parameters.erase(parameters.begin());
77  return generator->create_scenario();
78 }
std::string random_generate_map(const std::string &parms, const config &cfg)
Definition: map_create.cpp:46
static lg::log_domain log_config("config")
rng * generator
This generator is automatically synced during synced context.
Definition: random_new.cpp:52
scoped_resource: class template, functions, helper policies etc. for resource management.
config random_generate_scenario(const std::string &parms, const config &cfg)
Definition: map_create.cpp:63
map_generator * create_map_generator(const std::string &name, const config &cfg)
Definition: map_create.cpp:31
A class which implements an approximation of template typedef scoped_resource scoped_ptr;.
const std::string & parameters
Definition: filter.cpp:155
GLuint const GLchar * name
Definition: glew.h:1782
Standard logging facilities (interface).
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503