The Battle for Wesnoth  1.17.0-dev
map_generator.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Map-generator, with standalone testprogram.
19  */
20 
22 
23 #include "config.hpp"
24 #include "gettext.hpp"
25 #include "log.hpp"
26 
27 static lg::log_domain log_mapgen("mapgen");
28 #define ERR_NG LOG_STREAM(err, log_mapgen)
29 #define LOG_NG LOG_STREAM(info, log_mapgen)
30 
31 config map_generator::create_scenario(std::optional<uint32_t> randomseed)
32 {
33  config res;
34  res["map_data"] = create_map(randomseed);
35  return res;
36 }
37 std::string map_generator::create_map(std::optional<uint32_t> randomseed)
38 {
39  return create_scenario(randomseed)["map_data"];
40 }
41 /**
42  by default we don't allow user configs.
43 */
45 {
46  return false;
47 }
48 
50 {
51 }
52 
53 #ifdef TEST_MAPGEN
54 
55 /** Standalone testprogram for the mapgenerator. */
56 int main(int argc, char** argv)
57 {
58  int x = 50, y = 50, iterations = 50,
59  hill_size = 50, lakes=3,
60  nvillages = 25, nplayers = 2;
61  if(argc >= 2) {
62  x = std::stoi(argv[1]);
63  }
64 
65  if(argc >= 3) {
66  y = std::stoi(argv[2]);
67  }
68 
69  if(argc >= 4) {
70  iterations = std::stoi(argv[3]);
71  }
72 
73  if(argc >= 5) {
74  hill_size = std::stoi(argv[4]);
75  }
76 
77  if(argc >= 6) {
78  lakes = std::stoi(argv[5]);
79  }
80 
81  if(argc >= 7) {
82  nvillages = std::stoi(argv[6]);
83  }
84 
85  if(argc >= 8) {
86  nplayers = std::stoi(argv[7]);
87  }
88 
89  srand(std::time(nullptr));
90  std::cout << generate_map(x,y,iterations,hill_size,lakes,nvillages,nplayers) << "\n";
91 }
92 
93 #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 ...
Definitions for the interface to Wesnoth Markup Language (WML).
int main(int argc, char **argv)
Definition: SDLMain.mm:115
virtual void user_config()
Display the interactive screen, which allows the user to modify how the generator behaves...
virtual config create_scenario(std::optional< uint32_t > randomseed={})
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:61
virtual std::string create_map(std::optional< uint32_t > randomseed={})=0
Creates a new map and returns it.