31 #define LOG_NG LOG_STREAM(info, log_engine)
39 cfg_(cfg ? cfg :
config()),
43 flipx_chance_(cfg_[
"flipx_chance"]),
44 flipy_chance_(cfg_[
"flipy_chance"])
69 y =
params.height_ - y - 1;
78 return res[
"map_data"];
93 , starting_positions_()
102 std::cerr <<
"creating random cave with seed:" << seed;
106 LOG_NG <<
"creating scenario....\n";
109 LOG_NG <<
"placing chambers...\n";
114 LOG_NG <<
"placing passages...\n";
119 LOG_NG <<
"outputting map....\n";
126 if(size == 0 || locs.count(loc) != 0 || !
params.on_board(loc))
133 for(
size_t n = 0;
n != 6; ++
n) {
134 if(
int(rng_() % 100) < (100
l - static_cast<long>(jagged))) {
135 build_chamber(adj[
n],locs,size-1,jagged);
145 if (ch.has_attribute(
"chance") &&
int(rng_() % 100) < ch[
"chance"].to_int()) {
152 size_t min_xpos = 0, min_ypos = 0, max_xpos =
params.width_, max_ypos =
params.height_;
156 if(items.empty() ==
false) {
157 min_xpos = std::stoi(items.front()) - 1;
158 max_xpos = std::stoi(items.back());
164 if(items.empty() ==
false) {
165 min_ypos = std::stoi(items.front()) - 1;
166 max_ypos = std::stoi(items.back());
169 const size_t x = translate_x(min_xpos + (rng_()%(max_xpos-min_xpos)));
170 const size_t y = translate_y(min_ypos + (rng_()%(max_ypos-min_ypos)));
172 int chamber_size = ch[
"size"].to_int(3);
173 int jagged_edges = ch[
"jagged"];
177 build_chamber(new_chamber.
center,new_chamber.
locs,chamber_size,jagged_edges);
180 new_chamber.
items = items ? &items :
nullptr;
184 chamber_ids_[
id] = chambers_.size();
187 chambers_.push_back(new_chamber);
194 const std::map<std::string,size_t>::const_iterator
itor = chamber_ids_.find(dst);
195 if(itor == chamber_ids_.end())
198 assert(itor->second < chambers_.size());
200 passages_.push_back(
passage(new_chamber.
center, chambers_[itor->second].center,
p));
207 for(std::set<map_location>::const_iterator
i = c.
locs.begin();
i != c.
locs.end(); ++
i) {
211 if (c.
items ==
nullptr || c.
locs.empty())
return;
218 config* object_filter =
nullptr;
220 if (
config &of =
object.child(
"filter"))
224 if (!it.cfg[
"same_location_as_previous"].to_bool()) {
225 index = rng_()%c.
locs.size();
229 std::set<map_location>::const_iterator loc = c.
locs.begin();
230 std::advance(loc,index);
232 cfg[
"x"] = loc->x + 1;
233 cfg[
"y"] = loc->y + 1;
236 filter[
"x"] = loc->x + 1;
237 filter[
"y"] = loc->y + 1;
241 (*object_filter)[
"x"] = loc->x + 1;
242 (*object_filter)[
"y"] = loc->y + 1;
246 if (it.key ==
"side" && !it.cfg[
"no_castle"].to_bool()) {
247 place_castle(it.cfg[
"side"].to_int(-1), *loc);
250 res_.add_child(it.key, cfg);
252 if(!loc_var.empty()) {
254 temp[
"name"] =
"prestart";
256 xcfg[
"name"] = loc_var +
"_x";
257 xcfg[
"value"] = loc->x + 1;
259 ycfg[
"name"] = loc_var +
"_y";
260 ycfg[
"value"] = loc->y + 1;
269 double laziness,
size_t windiness,
270 boost::random::mt19937& rng) :
271 map_(mapdata),
wall_(wall), laziness_(laziness), windiness_(windiness), rng_(rng)
274 virtual double cost(
const map_location& loc,
const double so_far)
const;
291 res *= double(rng_()%windiness_);
300 if(chance !=
"" &&
int(rng_()%100) < std::stoi(chance)) {
305 int windiness = p.
cfg[
"windiness"];
306 double laziness = std::max<double>(1.0, p.
cfg[
"laziness"].to_double());
312 int width = std::max<int>(1, p.
cfg[
"width"].to_int());
313 int jagged = p.
cfg[
"jagged"];
315 for(std::vector<map_location>::const_iterator
i = rt.
steps.begin();
i != rt.
steps.end(); ++
i) {
316 std::set<map_location> locs;
317 build_chamber(*
i,locs,width,jagged);
318 for(std::set<map_location>::const_iterator j = locs.begin(); j != locs.end(); ++j) {
319 set_terrain(*j,
params.clear_);
326 if (
params.on_board(loc)) {
331 if ( t ==
params.clear_ &&
int(rng_() % 1000) <
params.village_density_ )
342 if (starting_position != -1) {
343 set_terrain(loc,
params.keep_);
348 starting_positions_.insert(t_translation::tstarting_positions::value_type(std::to_string(starting_position), coord));
353 for(
size_t n = 0;
n != 6; ++
n) {
354 set_terrain(adj[
n],
params.castle_);
child_itors child_range(const std::string &key)
Contains an x and y coordinate used for starting positions in maps.
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator *calc, const size_t width, const size_t height, const teleport_map *teleports, bool border)
std::string create_map(boost::optional< boost::uint32_t > randomseed=boost::none)
Creates a new map and returns it.
t_translation::tstarting_positions starting_positions_
const t_terrain UNDERGROUND_VILLAGE
config create_scenario(boost::optional< boost::uint32_t > randomseed=boost::none)
std::string write_game_map(const t_map &map, const tstarting_positions &starting_positions, coordinate border_offset)
Write a gamemap in to a vector string.
std::vector< passage > passages_
std::string config_name() const
Return a friendly name for the generator used to differentiate between different configs of the same ...
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
static const int default_border
The default border style for a map.
GLint GLint GLint GLint GLint GLint y
const std::vector< std::string > items
t_translation::t_map map_
cave_map_generator_job(const cave_map_generator ¶ms, boost::optional< boost::uint32_t > randomseed=boost::none)
boost::random::mt19937 & rng_
t_translation::t_terrain wall_
std::vector< std::vector< t_terrain > > t_map
std::vector< map_location > steps
Structure which holds a single route between one location and another.
all_children_itors all_children_range() const
In-order iteration over all children.
Encapsulates the map of the game.
const t_terrain DWARVEN_CASTLE
config & add_child(const std::string &key)
virtual double cost(const map_location &loc, const double so_far) const
void place_chamber(const chamber &c)
void place_passage(const passage &p)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Templates and utility-routines for strings and numbers.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
void place_castle(int starting_position, const map_location &loc)
Encapsulates the map of the game.
std::set< map_location > locs
void build_chamber(map_location loc, std::set< map_location > &locs, size_t size, size_t jagged)
std::map< std::string, tfilter >::iterator itor
size_t translate_x(size_t x) const
size_t translate_y(size_t y) const
static lg::log_domain log_engine("engine")
const t_terrain CAVE_WALL
GLint GLint GLint GLint GLint x
const t_terrain DWARVEN_KEEP
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
passage_path_calculator(const t_translation::t_map &mapdata, const t_translation::t_terrain &wall, double laziness, size_t windiness, boost::random::mt19937 &rng)
t_translation::t_terrain wall_
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void set_terrain(map_location loc, const t_translation::t_terrain &t)
Standard logging facilities (interface).
GLint GLint GLint GLint GLint GLint GLsizei width
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
std::vector< chamber > chambers_
A config object defines a single node in a WML file, with access to child nodes.
cave_map_generator(const config &game_config)
This module contains various pathfinding functions and utilities.
GLsizei const GLcharARB ** string
const t_translation::t_map & map_
std::vector< t_terrain > t_list
boost::random::mt19937 rng_