The Battle for Wesnoth  1.19.5+dev
cave_map_generator.hpp
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 #pragma once
17 
18 #include "config.hpp"
20 #include "terrain/translation.hpp"
21 #include "utils/optional_fwd.hpp"
22 
23 #include <set>
24 #include <random>
25 
27 {
28 public:
30 
31  std::string name() const { return "cave"; }
32 
33  std::string config_name() const;
34 
35  std::string create_map(utils::optional<uint32_t> randomseed = {});
36  config create_scenario(utils::optional<uint32_t> randomseed = {});
37 
38 private:
40  {
41  cave_map_generator_job(const cave_map_generator& params, utils::optional<uint32_t> randomseed = {});
42 
43  struct chamber {
45  : center()
46  , locs()
47  , items(nullptr)
48  {
49  }
50 
52  std::set<map_location> locs;
53  const config *items;
54  };
55 
56  struct passage {
58  : src(s), dst(d), cfg(c)
59  {}
62  };
63 
64  void generate_chambers();
65  void build_chamber(map_location loc, std::set<map_location>& locs, std::size_t size, std::size_t jagged);
66 
67  void place_chamber(const chamber& c);
68 
69  void place_passage(const passage& p);
70 
72  void place_castle(int starting_position, const map_location &loc);
73 
74  std::size_t translate_x(std::size_t x) const;
75  std::size_t translate_y(std::size_t y) const;
76 
77 
79  bool flipx_, flipy_;
80 
83  std::map<std::string,std::size_t> chamber_ids_;
84  std::vector<chamber> chambers_;
85  std::vector<passage> passages_;
87  std::mt19937 rng_;
88  };
89 
90  bool on_board(const map_location& loc) const
91  {
92  return loc.x >= 0 && loc.y >= 0 && loc.x < width_ && loc.y < height_;
93  }
94 
96 
99 
100  // The scenario may have a chance to flip all x values or y values
101  // to make the scenario appear all random. This is kept track of here.
103 };
double t
Definition: astarsearch.cpp:63
cave_map_generator(const config &game_config)
t_translation::terrain_code keep_
t_translation::terrain_code village_
std::string create_map(utils::optional< uint32_t > randomseed={})
Creates a new map and returns it.
config create_scenario(utils::optional< uint32_t > randomseed={})
t_translation::terrain_code clear_
t_translation::terrain_code castle_
std::string name() const
Returns a string identifying the generator by name.
bool on_board(const map_location &loc) const
std::string config_name() const
Return a friendly name for the generator used to differentiate between different configs of the same ...
t_translation::terrain_code wall_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Definitions for the interface to Wesnoth Markup Language (WML).
Game configuration data as global variables.
Definition: build_info.cpp:61
boost::bimaps::bimap< boost::bimaps::set_of< std::string >, boost::bimaps::multiset_of< coordinate > > starting_positions
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
passage(map_location s, map_location d, const config &c)
void set_terrain(map_location loc, const t_translation::terrain_code &t)
cave_map_generator_job(const cave_map_generator &params, utils::optional< uint32_t > randomseed={})
void build_chamber(map_location loc, std::set< map_location > &locs, std::size_t size, std::size_t jagged)
std::size_t translate_x(std::size_t x) const
t_translation::starting_positions starting_positions_
std::size_t translate_y(std::size_t y) const
void place_castle(int starting_position, const map_location &loc)
std::map< std::string, std::size_t > chamber_ids_
Encapsulates the map of the game.
Definition: location.hpp:45
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:49
mock_char c
mock_party p
static map_location::direction s
#define d