The Battle for Wesnoth  1.17.0-dev
cave_map_generator.hpp
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 #pragma once
17 
18 #include "config.hpp"
20 #include "terrain/translation.hpp"
21 #include <optional>
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(std::optional<uint32_t> randomseed = {});
36  config create_scenario(std::optional<uint32_t> randomseed = {});
37 
38 private:
40  {
41  cave_map_generator_job(const cave_map_generator& params, std::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 };
boost::bimaps::bimap< boost::bimaps::set_of< std::string >, boost::bimaps::multiset_of< coordinate > > starting_positions
t_translation::terrain_code village_
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
cave_map_generator_job(const cave_map_generator &params, std::optional< uint32_t > randomseed={})
t_translation::terrain_code clear_
#define d
Definitions for the interface to Wesnoth Markup Language (WML).
t_translation::terrain_code wall_
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
t_translation::terrain_code keep_
std::string create_map(std::optional< uint32_t > randomseed={})
Creates a new map and returns it.
std::size_t translate_y(std::size_t y) const
passage(map_location s, map_location d, const config &c)
std::string name() const
Returns a string identifying the generator by name.
void place_castle(int starting_position, const map_location &loc)
Encapsulates the map of the game.
Definition: location.hpp:38
mock_party p
Game configuration data as global variables.
Definition: build_info.cpp:59
static map_location::DIRECTION s
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 ...
std::map< std::string, std::size_t > chamber_ids_
config create_scenario(std::optional< uint32_t > randomseed={})
double t
Definition: astarsearch.cpp:65
t_translation::terrain_code castle_
void set_terrain(map_location loc, const t_translation::terrain_code &t)
void build_chamber(map_location loc, std::set< map_location > &locs, std::size_t size, std::size_t jagged)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
mock_char c
cave_map_generator(const config &game_config)
t_translation::starting_positions starting_positions_
std::size_t translate_x(std::size_t x) const