29 #define LOG_NG LOG_STREAM(info, log_engine) 32 #define ERR_WML LOG_STREAM(err, log_wml) 40 cfg_(cfg ? cfg :
config()),
44 flipx_chance_(cfg_[
"flipx_chance"]),
45 flipy_chance_(cfg_[
"flipy_chance"])
61 x = params.width_ - x - 1;
70 y = params.height_ - y - 1;
79 return res[
"map_data"];
93 , starting_positions_()
97 , res_(params.
cfg_.child_or_empty(
"settings"))
102 "deprecated_message",
config {
103 "what",
"scenario_generation=cave",
105 "message",
"Use the Lua cave generator instead, with scenario_generation=lua and create_scenario= (see wiki for details).",
110 LOG_NG <<
"creating random cave with seed: " << seed;
114 LOG_NG <<
"creating scenario....";
117 LOG_NG <<
"placing chambers...";
122 LOG_NG <<
"placing passages...";
127 LOG_NG <<
"outputting map....";
140 if(static_cast<int>(
rng_() % 100) < (100l - static_cast<long>(jagged))) {
151 if (ch.has_attribute(
"chance") &&
static_cast<int>(
rng_() % 100) < ch[
"chance"].to_int()) {
155 const std::string &xpos = ch[
"x"];
156 const std::string &ypos = ch[
"y"];
162 if(items.empty() ==
false) {
164 min_xpos = std::stoi(items.front()) - 1;
165 max_xpos = std::stoi(items.back());
166 }
catch(
const std::invalid_argument&) {
167 lg::log_to_chat() <<
"Invalid min/max coordinates in cave_map_generator: " << items.front() <<
", " << items.back() <<
"\n";
168 ERR_WML <<
"Invalid min/max coordinates in cave_map_generator: " << items.front() <<
", " << items.back();
176 if(items.empty() ==
false) {
178 min_ypos = std::stoi(items.front()) - 1;
179 max_ypos = std::stoi(items.back());
180 }
catch(
const std::invalid_argument&) {
181 lg::log_to_chat() <<
"Invalid min/max coordinates in cave_map_generator: " << items.front() <<
", " << items.back() <<
"\n";
182 ERR_WML <<
"Invalid min/max coordinates in cave_map_generator: " << items.front() <<
", " << items.back();
186 const std::size_t x =
translate_x(min_xpos + (
rng_()%(max_xpos-min_xpos)));
187 const std::size_t y =
translate_y(min_ypos + (
rng_()%(max_ypos-min_ypos)));
189 int chamber_size = ch[
"size"].to_int(3);
190 int jagged_edges = ch[
"jagged"];
199 const std::string &
id = ch[
"id"];
206 for(
const config &
p : ch.child_range(
"passage"))
208 const std::string &dst =
p[
"destination"];
211 const std::map<std::string,std::size_t>::const_iterator itor =
chamber_ids_.find(dst);
224 for(std::set<map_location>::const_iterator
i = c.
locs.begin();
i != c.
locs.end(); ++
i) {
228 if (c.
items ==
nullptr || c.
locs.empty())
return;
230 std::size_t
index = 0;
235 config* object_filter =
nullptr;
237 if (
config &of =
object.child(
"filter"))
241 if (!it.cfg[
"same_location_as_previous"].to_bool()) {
244 std::string loc_var = it.cfg[
"store_location_as"];
246 std::set<map_location>::const_iterator loc = c.
locs.begin();
247 std::advance(loc,index);
249 cfg[
"x"] = loc->x + 1;
250 cfg[
"y"] = loc->y + 1;
253 filter[
"x"] = loc->x + 1;
254 filter[
"y"] = loc->y + 1;
258 (*object_filter)[
"x"] = loc->x + 1;
259 (*object_filter)[
"y"] = loc->y + 1;
263 if (it.key ==
"side" && !it.cfg[
"no_castle"].to_bool()) {
269 if(!loc_var.empty()) {
271 temp[
"name"] =
"prestart";
273 xcfg[
"name"] = loc_var +
"_x";
274 xcfg[
"value"] = loc->x + 1;
276 ycfg[
"name"] = loc_var +
"_y";
277 ycfg[
"value"] = loc->y + 1;
286 double laziness, std::size_t windiness,
288 map_(mapdata),
wall_(wall), laziness_(laziness), windiness_(windiness),
rng_(rng)
291 virtual double cost(
const map_location& loc,
const double so_far)
const;
308 res *=
static_cast<double>(
rng_()%windiness_);
316 const std::string& chance = p.
cfg[
"chance"];
317 if(!chance.empty() &&
static_cast<int>(
rng_()%100) < std::stoi(chance)) {
322 int windiness = p.
cfg[
"windiness"];
323 double laziness = std::max<double>(1.0, p.
cfg[
"laziness"].to_double());
329 int width = std::max<int>(1, p.
cfg[
"width"].to_int());
330 int jagged = p.
cfg[
"jagged"];
332 for(std::vector<map_location>::const_iterator
i = rt.
steps.begin();
i != rt.
steps.end(); ++
i) {
333 std::set<map_location> locs;
335 for(std::set<map_location>::const_iterator j = locs.begin(); j != locs.end(); ++j) {
359 if (starting_position != -1) {
365 starting_positions_.insert(t_translation::starting_positions::value_type(std::to_string(starting_position), coord));
const t_translation::ter_map & map_
static const int default_border
The default border style for a map.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
const_all_children_itors all_children_range() const
In-order iteration over all children.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
const terrain_code DWARVEN_KEEP
std::vector< passage > passages_
child_itors child_range(config_key_type key)
t_translation::terrain_code village_
virtual double cost(const map_location &loc, const double so_far) const
const std::vector< std::string > items
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
cave_map_generator_job(const cave_map_generator ¶ms, std::optional< uint32_t > randomseed={})
t_translation::terrain_code wall_
t_translation::terrain_code clear_
t_translation::terrain_code wall_
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
std::vector< map_location > steps
Structure which holds a single route between one location and another.
t_translation::terrain_code keep_
const terrain_code DWARVEN_CASTLE
Encapsulates the map of the game.
std::string create_map(std::optional< uint32_t > randomseed={})
Creates a new map and returns it.
static lg::log_domain log_wml("wml")
const cave_map_generator & params
std::size_t translate_y(std::size_t y) const
void place_chamber(const chamber &c)
void place_passage(const passage &p)
void place_castle(int starting_position, const map_location &loc)
Encapsulates the map of the game.
std::set< map_location > locs
std::string id
Text to match against addon_info.tags()
static lg::log_domain log_engine("engine")
t_translation::ter_map map_
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::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
const terrain_code CAVE_WALL
terrain_code & get(int x, int y)
config & add_child(config_key_type key)
std::string write_game_map(const ter_map &map, const starting_positions &starting_positions, coordinate border_offset)
Write a gamemap in to a vector string.
std::map< std::string, std::size_t > chamber_ids_
config create_scenario(std::optional< uint32_t > randomseed={})
std::vector< std::string > split(const config_attribute_value &val)
const terrain_code UNDERGROUND_VILLAGE
t_translation::terrain_code castle_
Standard logging facilities (interface).
passage_path_calculator(const t_translation::ter_map &mapdata, const t_translation::terrain_code &wall, double laziness, std::size_t windiness, std::mt19937 &rng)
void set_terrain(map_location loc, const t_translation::terrain_code &t)
std::vector< chamber > chambers_
void build_chamber(map_location loc, std::set< map_location > &locs, std::size_t size, std::size_t jagged)
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator &calc, const std::size_t width, const std::size_t height, const teleport_map *teleports, bool border)
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.
t_translation::starting_positions starting_positions_
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
std::size_t translate_x(std::size_t x) const