55 #define pmap(_tile) (placed_map[tile_index(_tile)])
104 bool (*filter)(
const struct tile *ptile,
107 int minval = 0, maxval = 0, total = 0;
130 int const size = 1 + maxval - minval;
131 int i, count = 0, frequencies[
size];
146 for (i = 0; i <
size; i++) {
147 count += frequencies[i];
148 frequencies[i] = (count * int_map_max) / total;
170 static const float weight_standard[5] = {0.13, 0.19, 0.37, 0.19, 0.13};
171 static const float weight_isometric[5] = {0.15, 0.21, 0.29, 0.21, 0.15};
174 int *target_map, *source_map;
177 weight = weight_standard;
178 target_map = alt_int_map;
179 source_map = int_map;
189 N += weight[i + 2] * source_map[
tile_index(pnear)];
192 if (zeroes_at_edges) {
200 weight = weight_isometric;
205 source_map = alt_int_map;
206 target_map = int_map;
209 delete[] alt_int_map;
210 alt_int_map =
nullptr;
272 struct tile_list *tlist =
nullptr;
273 const struct terrain *pterrain =
nullptr;
284 tlist = tile_list_new();
285 tile_list_append(tlist, ptile);
287 while (tile_list_size(tlist) > 0) {
304 if (!tile_list_search(tlist, ptile3)) {
305 tile_list_append(tlist, ptile3);
312 tile_list_remove(tlist, ptile2);
323 tile_list_destroy(tlist);
338 int num_laketypes[2] = {0, 0};
347 if (num_laketypes[frozen] <
ARRAY_SIZE(lakes[frozen])) {
348 lakes[frozen][num_laketypes[frozen]++] = pterr;
350 qDebug(
"Ruleset has more than %d %s lake types, ignoring %s",
363 if (num_laketypes[0] == 0) {
365 }
else if (num_laketypes[1] == 0) {
367 lake_for_ocean[0][i] = lake_for_ocean[1][i] =
368 lakes[0][
fc_rand(num_laketypes[0])];
373 for (frozen = 0; frozen < 2; frozen++) {
374 lake_for_ocean[frozen][i] =
375 lakes[frozen][
fc_rand(num_laketypes[frozen])];
486 bool oceans =
false, frozenmatch =
false;
487 struct terrain *shallow =
nullptr;
495 if (!oceans && nonfresh) {
499 frozenmatch = frozen_ok;
501 }
else if (oceans && !nonfresh) {
505 if (!frozenmatch && frozen_ok) {
511 }
else if (frozenmatch && !frozen_ok) {
517 < shallow->
property[MG_OCEAN_DEPTH]) {
534 struct terrain *best_terrain =
nullptr;
540 && TERRAIN_OCEAN_DEPTH_MINIMUM <= pterrain->
property[MG_OCEAN_DEPTH]
543 int match = abs(depth - pterrain->property[MG_OCEAN_DEPTH]);
545 if (best_match > match) {
547 best_terrain = pterrain;
590 if (pterrain ==
tile_terrain(atile) && need <= ++count) {
608 const int OCEAN_DEPTH_STEP = 25;
609 const int OCEAN_DEPTH_RAND = 15;
622 if (dist <= OCEAN_DIST_MAX) {
627 log_debug(
"Replacing %s by %s at (%d, %d) "
628 "to have shallow ocean on coast.",
646 log_debug(
"Replacing %s by %s at (%d, %d) "
647 "to smooth the ocean types.",
717 enum mapgen_terrain_property prefer,
718 enum mapgen_terrain_property avoid)
726 if (avoid !=
MG_UNUSED && pterrain->property[avoid] > 0) {
729 if (prefer !=
MG_UNUSED && pterrain->property[prefer] == 0) {
734 sum += pterrain->property[target];
751 if (avoid !=
MG_UNUSED && pterrain->property[avoid] > 0) {
754 if (prefer !=
MG_UNUSED && pterrain->property[prefer] == 0) {
759 property = pterrain->property[target];
774 log_debug(
"pick_terrain(target: %s, [dropping prefer: %s], avoid: %s)",
775 mapgen_terrain_property_name(target),
776 mapgen_terrain_property_name(prefer),
777 mapgen_terrain_property_name(avoid));
781 "pick_terrain(target: %s, prefer: MG_UNUSED, [dropping avoid: %s])",
782 mapgen_terrain_property_name(target),
783 mapgen_terrain_property_name(avoid));
786 log_debug(
"pick_terrain([dropping target: %s], prefer: MG_UNUSED, "
788 mapgen_terrain_property_name(target));
signed short Continent_id
#define fc_assert_ret(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
struct terrain_misc terrain_control
int map_vector_to_real_distance(int dx, int dy)
Return the "real" distance for a given vector.
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define adjc_iterate(nmap, center_tile, itr_tile)
#define square_iterate_end
#define whole_map_iterate(_map, _tile)
#define square_dxy_iterate(nmap, center_tile, radius, tile_itr, dx_itr, dy_itr)
#define whole_map_iterate_end
#define square_dxy_iterate_end
int get_continent_size(Continent_id id)
Return size in tiles of the given continent (not ocean)
std::vector< Continent_id > lake_surrounders
void smooth_int_map(int *int_map, bool zeroes_at_edges)
Apply a Gaussian diffusion filter on the map.
static int real_distance_to_land(const struct tile *ptile, int max)
Determines the minimal distance to the land.
std::vector< int > continent_sizes
static bool * placed_map
Map that contains, according to circumstances, information on whether we have already placed terrain ...
static struct terrain * most_adjacent_ocean_type(const struct tile *ptile)
Determines what is the most popular ocean type arround (need 2/3 of the adjcacent tiles).
void map_set_placed(struct tile *ptile)
Mark tile terrain as placed.
bool not_placed(const struct tile *ptile)
Checks if land has not yet been placed on pmap at (x, y)
struct terrain * pick_ocean(int depth, bool frozen)
Picks an ocean terrain to match the given depth.
void create_placed_map()
Create a clean pmap.
std::vector< int > ocean_sizes
void adjust_int_map_filtered(int *int_map, int int_map_max, void *data, bool(*filter)(const struct tile *ptile, const void *data))
Change the values of the integer map, so that they contain ranking of each tile scaled to [0 .
void destroy_placed_map()
Free the pmap.
void set_all_ocean_tiles_placed()
Set all oceanics tiles in placed_map.
void set_placed_near_pos(struct tile *ptile, int dist)
Set all nearby tiles as placed on pmap.
bool placed_map_is_initialized()
Return TRUE if initialized.
struct terrain * most_shallow_ocean(bool frozen)
Return most shallow ocean terrain type.
int get_ocean_size(Continent_id id)
Return size in tiles of the given ocean.
void regenerate_lakes()
Regenerate all oceanic tiles for small water bodies as lakes.
static void recalculate_lake_surrounders()
Calculate lake_surrounders[] array.
void generator_free()
Free resources allocated by the generator.
struct terrain * pick_terrain_by_flag(enum terrain_flag_id flag)
Return a random terrain that has the specified flag.
void smooth_water_depth()
Makes a simple depth map for all ocean tiles based on their proximity to any land tiles and reassigne...
struct terrain * pick_terrain(enum mapgen_terrain_property target, enum mapgen_terrain_property prefer, enum mapgen_terrain_property avoid)
Pick a terrain based on the target property and a property to avoid.
static void assign_continent_flood(struct tile *ptile, bool is_land, int nr)
Number this tile and nearby tiles with the specified continent number 'nr'.
void assign_continent_numbers()
Assigns continent and ocean numbers to all tiles, and set map.num_continents and map....
void map_unset_placed(struct tile *ptile)
Mark tile terrain as not placed.
int get_lake_surrounders(Continent_id cont)
Get continent surrounding lake, or -1 if there is multiple continents.
#define whole_map_iterate_filtered(_tile, pdata, pfilter)
#define axis_iterate(nmap, center_tile, _tile, _index, dist, is_X_axis)
#define whole_map_iterate_filtered_end
#define INITIALIZE_ARRAY(array, size, value)
Terrain_type_id terrain_count()
Return the number of terrains.
const char * terrain_rule_name(const struct terrain *pterrain)
Return the (untranslated) rule name of the terrain.
Terrain_type_id terrain_index(const struct terrain *pterrain)
Return the terrain index.
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
What terrain class terrain type belongs to.
#define terrain_type_iterate(_p)
#define is_ocean(pterrain)
#define is_ocean_tile(ptile)
#define terrain_type_iterate_end
#define TERRAIN_OCEAN_DEPTH_MAXIMUM
#define terrain_has_flag(terr, flag)
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Set the given terrain at the specified tile.
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Change the terrain to the given type.
void tile_set_continent(struct tile *ptile, Continent_id val)
Set the continent ID of the tile.
#define tile_list_iterate(tile_list, ptile)
#define tile_terrain(_tile)
#define tile_list_iterate_end
#define tile_continent(_tile)