The Battle for Wesnoth  1.19.5+dev
map_generator.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 "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(utils::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(utils::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(std::time(nullptr));
89  std::cout << generate_map(x,y,iterations,hill_size,lakes,nvillages,nplayers) << "\n";
90 }
91 
92 #endif
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
virtual config create_scenario(utils::optional< uint32_t > randomseed={})
virtual std::string create_map(utils::optional< uint32_t > randomseed={})=0
Creates a new map and returns it.
virtual void user_config()
Display the interactive screen, which allows the user to modify how the generator behaves.
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).
Standard logging facilities (interface).
static lg::log_domain log_mapgen("mapgen")
int main(int, char **)
Definition: sdl2.cpp:25