The Battle for Wesnoth  1.15.12+dev
cave_map_generator.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
17 #include "config.hpp"
19 #include "terrain/translation.hpp"
20 #include <optional>
21 
22 #include <set>
23 #include <random>
24 
26 {
27 public:
29 
30  std::string name() const { return "cave"; }
31 
32  std::string config_name() const;
33 
34  std::string create_map(std::optional<uint32_t> randomseed = {});
35  config create_scenario(std::optional<uint32_t> randomseed = {});
36 
37 private:
39  {
40  cave_map_generator_job(const cave_map_generator& params, std::optional<uint32_t> randomseed = {});
41 
42  struct chamber {
44  : center()
45  , locs()
46  , items(nullptr)
47  {
48  }
49 
51  std::set<map_location> locs;
52  const config *items;
53  };
54 
55  struct passage {
57  : src(s), dst(d), cfg(c)
58  {}
61  };
62 
63  void generate_chambers();
64  void build_chamber(map_location loc, std::set<map_location>& locs, std::size_t size, std::size_t jagged);
65 
66  void place_chamber(const chamber& c);
67 
68  void place_passage(const passage& p);
69 
71  void place_castle(int starting_position, const map_location &loc);
72 
73  std::size_t translate_x(std::size_t x) const;
74  std::size_t translate_y(std::size_t y) const;
75 
76 
78  bool flipx_, flipy_;
79 
82  std::map<std::string,std::size_t> chamber_ids_;
83  std::vector<chamber> chambers_;
84  std::vector<passage> passages_;
86  std::mt19937 rng_;
87  };
88 
89  bool on_board(const map_location& loc) const
90  {
91  return loc.x >= 0 && loc.y >= 0 && loc.x < width_ && loc.y < height_;
92  }
93 
95 
98 
99  // The scenario may have a chance to flip all x values or y values
100  // to make the scenario appear all random. This is kept track of here.
102 };
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:49
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:86
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:37
mock_party p
Game configuration data as global variables.
Definition: build_info.cpp:58
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:64
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:59
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