The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
map_generator.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 
15 /**
16  * @file
17  * Map-generator, with standalone testprogram.
18  */
19 
21 
22 #include "config.hpp"
23 #include "gettext.hpp"
24 #include "log.hpp"
25 
26 static lg::log_domain log_mapgen("mapgen");
27 #define ERR_NG LOG_STREAM(err, log_mapgen)
28 #define LOG_NG LOG_STREAM(info, log_mapgen)
29 
30 config map_generator::create_scenario(boost::optional<uint32_t> randomseed)
31 {
32  config res;
33  res["map_data"] = create_map(randomseed);
34  return res;
35 }
36 std::string map_generator::create_map(boost::optional<uint32_t> randomseed)
37 {
38  return create_scenario(randomseed)["map_data"];
39 }
40 /**
41  by default we don't allow user configs.
42 */
44 {
45  return false;
46 }
47 
49 {
50 }
51 
52 #ifdef TEST_MAPGEN
53 
54 /** Standalone testprogram for the mapgenerator. */
55 int main(int argc, char** argv)
56 {
57  int x = 50, y = 50, iterations = 50,
58  hill_size = 50, lakes=3,
59  nvillages = 25, nplayers = 2;
60  if(argc >= 2) {
61  x = std::stoi(argv[1]);
62  }
63 
64  if(argc >= 3) {
65  y = std::stoi(argv[2]);
66  }
67 
68  if(argc >= 4) {
69  iterations = std::stoi(argv[3]);
70  }
71 
72  if(argc >= 5) {
73  hill_size = std::stoi(argv[4]);
74  }
75 
76  if(argc >= 6) {
77  lakes = std::stoi(argv[5]);
78  }
79 
80  if(argc >= 7) {
81  nvillages = std::stoi(argv[6]);
82  }
83 
84  if(argc >= 8) {
85  nplayers = std::stoi(argv[7]);
86  }
87 
88  srand(time(nullptr));
89  std::cout << generate_map(x,y,iterations,hill_size,lakes,nvillages,nplayers) << "\n";
90 }
91 
92 #endif
virtual bool allow_user_config() const
Returns true if the map generator has an interactive screen, which allows the user to modify how the ...
std::vector< char_t > string
virtual config create_scenario(boost::optional< uint32_t > randomseed=boost::none)
Definitions for the interface to Wesnoth Markup Language (WML).
virtual void user_config()
Display the interactive screen, which allows the user to modify how the generator behaves...
virtual std::string create_map(boost::optional< uint32_t > randomseed=boost::none)=0
Creates a new map and returns it.
int main()
static lg::log_domain log_mapgen("mapgen")
Standard logging facilities (interface).
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93