14 #include <fc_config.h>
50 #define RIVERS_MAXTRIES 32767
104 #define ini_hmap_low_level() \
107 (4 * swamp_pct * (hmap_max_level - hmap_shore_level)) / 100 \
108 + hmap_shore_level; \
111 #define map_pos_is_low(ptile) ((hmap((ptile)) < hmap_low_level))
132 qCritical(
"Invalid wetness_c %d", c);
149 qCritical(
"Invalid miscellaneous_c %d", c);
324 struct terrain *pterrain,
int *to_be_placed,
328 if (*to_be_placed <= 0) {
345 place_terrain(tile1, diff - 1 - Delta, pterrain, to_be_placed, wc, tc,
394 #define PLACE_ONE_TYPE(count, alternate, ter, wc, tc, mc, weight) \
396 struct tile *ptile; \
398 if ((ptile = rand_map_pos_characteristic((wc), (tc), (mc)))) { \
399 place_terrain(ptile, (weight), (ter), &(count), (wc), (tc), (mc)); \
403 (alternate) += (count); \
418 int forests_count = 0;
419 int jungles_count = 0;
420 int deserts_count = 0;
421 int alt_deserts_count = 0;
422 int plains_count = 0;
423 int swamps_count = 0;
441 total - forests_count - deserts_count - swamps_count - jungles_count;
462 if (plains_count > 0) {
474 }
while (forests_count > 0 || jungles_count > 0 || deserts_count > 0
475 || alt_deserts_count > 0 || plains_count > 0 || swamps_count > 0);
617 #define NUM_TEST_FUNCTIONS 9
726 int rd_comparison_val[8];
728 bool rd_direction_is_valid[8];
729 int num_valid_directions, func_num, direction;
734 log_debug(
"The tile at (%d, %d) has been marked as river in river_map.",
748 log_debug(
"The river did not end at (%d, %d). Evaluating directions...",
752 memset(rd_direction_is_valid, 0,
sizeof(rd_direction_is_valid));
755 rd_direction_is_valid[dir] =
true;
766 if (rd_direction_is_valid[dir]) {
767 rd_comparison_val[dir] =
770 if (best_val == -1) {
771 best_val = rd_comparison_val[dir];
773 best_val =
MIN(rd_comparison_val[dir], best_val);
788 if (rd_direction_is_valid[dir]) {
789 if (rd_comparison_val[dir] != best_val) {
790 rd_direction_is_valid[dir] =
false;
799 num_valid_directions = 0;
802 if (rd_direction_is_valid[dir]) {
803 num_valid_directions++;
808 if (num_valid_directions == 0) {
813 log_debug(
"mapgen.c: Had to let the random number"
814 " generator select a direction for a river.");
815 direction =
fc_rand(num_valid_directions);
816 log_debug(
"mapgen.c: direction: %d", direction);
821 if (rd_direction_is_valid[dir]) {
850 int desirable_riverlength =
862 int current_riverlength = 0;
867 int iteration_counter = 0;
881 while (current_riverlength < desirable_riverlength
914 && (pterrain->
property[MG_MOUNTAINOUS] == 0
919 && (pterrain->
property[MG_FROZEN] == 0
928 rivermap.
ok.fill(
false);
934 if (oriver != road_river) {
946 log_debug(
"Found a suitable starting tile for a river at (%d, %d)."
947 " Starting to make it.",
951 if (
make_river(&rivermap, ptile, road_river)) {
960 if (river_terrain !=
nullptr) {
966 current_riverlength++;
973 log_debug(
"mapgen.c: A river failed. It might have gotten stuck "
978 log_debug(
"current_riverlength: %d; desirable_riverlength: %d; "
979 "iteration_counter: %d",
980 current_riverlength, desirable_riverlength, iteration_counter);
993 struct terrain *land_fill =
nullptr;
1006 land_fill = pterrain;
1013 "No land terrain type could be found for the purpose "
1014 "of temporarily filling in land tiles during map "
1015 "generation. This could be an error in Freeciv21, or a "
1016 "mistake in the terrain.ruleset file. Please make sure "
1017 "there is at least one land terrain type in the "
1018 "ruleset, or use a different map generator. If this "
1019 "error persists, please report it at: %s",
1045 depth += 30 * (ocean - land) /
MAX(1, (ocean + land));
1061 if (frozen && !pterrain) {
1163 int total = 0, ocean = 0;
1183 qDebug(
"map settings:");
1184 qDebug(
" %-20s : %5d%%",
"mountain_pct",
mountain_pct);
1185 qDebug(
" %-20s : %5d%%",
"desert_pct",
desert_pct);
1186 qDebug(
" %-20s : %5d%%",
"forest_pct",
forest_pct);
1187 qDebug(
" %-20s : %5d%%",
"jungle_pct",
jungle_pct);
1188 qDebug(
" %-20s : %5d%%",
"swamp_pct",
swamp_pct);
1190 qDebug(
"map statistics:");
1193 total = qMax(1, total);
1194 ocean = qMax(1, ocean);
1198 qDebug(
" %-20s : %6d %5.1f%% (ocean: %5.1f%%)",
1207 qDebug(
" %-20s : %6d %5.1f%% (land: %5.1f%%)",
1213 * 100 / (total - ocean));
1333 fc_assert_msg(
false,
"Fair island generator failed to allocated "
1334 "start positions!");
1343 qDebug(
"Map generator chose startpos=ALL");
1353 qDebug(
"Map generator chose startpos=SINGLE");
1359 qDebug(
"Map generator chose startpos=2or3");
1379 qDebug(
"Falling back to startpos=2or3");
1383 qDebug(
"Falling back to startpos=ALL");
1387 qDebug(
"Falling back to startpos=VARIABLE");
1391 qCritical(
_(
"The server couldn't allocate starting positions."));
1414 float mount_factor = (100.0 - polar - 30 * 0.8) / 10000;
1415 float factor = (100.0 - polar -
wld.
map.
server.steepness * 0.8) / 10000;
1471 if (phut !=
nullptr) {
1514 for (r = pterrain->
resources; *r; r++) {
1519 if ((*r)->generated) {
1544 && priver->generated) {
bool map_generate_fair_islands()
Build a map using generator 'FAIR'.
void make_fracture_hmap()
Fracture map generator.
void make_fracture_relief()
make_fracture_relief() Goes through a couple of iterations.
void make_random_hmap()
Create uncorrelated rand map and do some call to smoth to correlate it a little and create randoms sh...
void renormalize_hmap_poles()
Invert (most of) the effects of normalize_hmap_poles so that we have accurate heights for texturing t...
void normalize_hmap_poles()
Lower the land near the map edges and (optionally) the polar region to avoid too much land there.
bool area_is_too_flat(struct tile *ptile, int thill, int my_height)
We don't want huge areas of grass/plains, so we put in a hill here and there, where it gets too 'clea...
void make_pseudofractal_hmap()
Generator 5 makes earthlike worlds with one or more large continents and a scattering of smaller isla...
bool map_generate_island()
Generate a map with the ISLAND family of generators.
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert_exit_msg(condition, message,...)
#define fc_assert(condition)
#define fc_assert_ret_msg(condition, message,...)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
int map_startpos_count()
Is there start positions set for map.
void main_map_allocate()
Allocate main map and related global structures.
struct tile * rand_map_pos_filtered(const struct civ_map *nmap, void *data, bool(*filter)(const struct tile *ptile, const void *data))
Give a random tile anywhere on the map for which the 'filter' function returns TRUE.
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define cardinal_adjc_iterate_end
#define adjc_iterate(nmap, center_tile, itr_tile)
#define cardinal_adjc_dir_iterate_end
#define square_iterate_end
#define cardinal_adjc_iterate(nmap, center_tile, itr_tile)
#define whole_map_iterate(_map, _tile)
#define cardinal_adjc_dir_base_iterate_end
#define cardinal_adjc_dir_base_iterate(nmap, center_tile, dir_itr)
#define cardinal_adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr)
#define whole_map_iterate_end
static int hmap_low_level
#define NUM_TEST_FUNCTIONS
static void river_types_init()
Initialize river types array.
static int river_test_adjacent_swamp(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static int river_test_height_map(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static struct tile * rand_map_pos_characteristic(wetness_c wc, temperature_type tc, miscellaneous_c mc)
Return random map coordinates which have some conditions and which are not yet placed on pmap.
void make_polar()
Add frozen tiles in the arctic zone.
static void make_rivers()
Calls make_river until there are enough river tiles on the map.
static void adjust_terrain_param()
Convert parameters from the server into terrains percents parameters for the generators.
static void make_relief()
make_relief() will convert all squares that are higher than thill to mountains and hills.
static void print_mapgen_map()
Debugging function to print information about the map that's been generated.
static void remove_tiny_islands()
Removes all 1x1 islands (sets them to ocean).
struct extra_type * river_types[MAX_ROAD_TYPES]
#define map_pos_is_low(ptile)
#define ini_hmap_low_level()
static bool test_miscellaneous(const struct tile *ptile, miscellaneous_c c)
Checks if the given location satisfy some miscellaneous condition.
static int river_test_adjacent_ocean(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static void river_blockmark(struct river_map *privermap, struct tile *ptile)
Called from make_river.
static void make_huts(int number)
This function spreads out huts on the map, a position can be used for a hut if there isn't another hu...
static bool is_tiny_island(struct tile *ptile)
Returns if this is a 1x1 island.
#define PLACE_ONE_TYPE(count, alternate, ter, wc, tc, mc, weight)
This place randomly a cluster of terrains with some characteristics.
static int river_test_adjacent_highlands(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static bool near_safe_tiles(struct tile *ptile)
Return TRUE if a safe tile is in a radius of 1.
static bool ok_for_separate_poles(struct tile *ptile)
If separatepoles is set, return false if this tile has to keep ocean.
static bool condition_filter(const struct tile *ptile, const void *data)
A filter function to be passed to rand_map_pos_filtered().
bool test_wetness(const struct tile *ptile, wetness_c c)
These functions test for conditions used in rand_map_pos_characteristic.
static bool is_resource_close(const struct tile *ptile)
Return TRUE iff there's a resource within one tile of the given map position.
static void add_resources(int prob)
Add specials to the map with given probability (out of 1000).
static int river_test_highlands(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static bool make_river(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Makes a river starting at (x, y).
bool map_generate(bool autosize, struct unit_type *initial_unit)
See stdinhand.c for information on map generation methods.
static int river_test_rivergrid(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static void make_land()
make land simply does it all based on a generated heightmap 1) with map.server.landpercent it generat...
static void make_plain(struct tile *ptile, int *to_be_placed)
A simple function that adds plains grassland or tundra to the current location.
static struct test_func test_funcs[NUM_TEST_FUNCTIONS]
void make_plains()
Make_plains converts all not yet placed terrains to plains (tundra, grass) used by generators 2-4.
static int river_test_adjacent_river(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static void make_polar_land()
Place untextured land at the poles on any tile that is not already covered with TER_FROZEN terrain.
static int river_test_swamp(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
static void place_terrain(struct tile *ptile, int diff, struct terrain *pterrain, int *to_be_placed, wetness_c wc, temperature_type tc, miscellaneous_c mc)
Recursively generate terrains.
static bool terrain_is_too_high(struct tile *ptile, int thill, int my_height)
We don't want huge areas of hill/mountains, so we put in a plains here and there, where it gets too '...
static void make_terrains()
Make_terrains calls make_forest, make_dessert,etc with random free locations until there has been mad...
static int river_test_blocked(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
Help function used in make_river().
#define map_pos_is_dry(ptile)
Conditions used mainly in rand_map_pos_characteristic()
void generator_init_topology(bool autosize)
This function sets sizes in a topology-specific way then calls map_init_topology().
int map_colatitude(const struct tile *ptile)
Returns the colatitude of this map position.
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.
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.
struct terrain * most_shallow_ocean(bool frozen)
Return most shallow ocean terrain type.
void regenerate_lakes()
Regenerate all oceanic tiles for small water bodies as lakes.
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.
void assign_continent_numbers()
Assigns continent and ocean numbers to all tiles, and set map.num_continents and map....
std::mt19937 & fc_rand_state()
Returns a reference to the current random generator state; eg for save/restore.
void fc_rand_set_state(const std::mt19937 &state)
Replace current rand_state with user-supplied; eg for save/restore.
void fc_srand(std::uint_fast32_t seed)
Initialize the generator; see comment at top of file.
void fc_rand_seed(std::mt19937 &gen)
Seeds the given generator with a random value.
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Check if road provides effect.
int count_river_near_tile(const struct tile *ptile, const struct extra_type *priver)
Count tiles with any river near the tile.
int count_river_type_tile_card(const struct tile *ptile, const struct extra_type *priver, bool percentage)
Count tiles with river of specific type cardinally adjacent to the tile.
bool create_start_positions(enum map_startpos mode, struct unit_type *initial_unit)
where do the different nations start on the map? well this function tries to spread them out on the d...
Passed as data to rand_map_pos_filtered() by rand_map_pos_characteristic()
struct civ_map::@39::@41 server
struct extra_type ** resources
int(* func)(struct river_map *privermap, struct tile *ptile, struct extra_type *priver)
bool temperature_is_initialized()
Returns one line (given by the y coordinate) of the temperature map.
bool tmap_is(const struct tile *ptile, temperature_type tt)
Return true if the tile has tt temperature type.
void destroy_tmap()
Free the tmap.
bool is_temperature_type_near(const struct tile *ptile, temperature_type tt)
Return true if at least one tile has tt temperature type.
void create_tmap(bool real)
Initialize the temperature_map if arg is FALSE, create a dummy tmap == map_colatitude to be used if h...
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.
int count_terrain_property_near_tile(const struct tile *ptile, bool cardinal_only, bool percentage, enum mapgen_terrain_property prop)
Return the number of adjacent tiles that have the given terrain property.
Terrain_type_id terrain_index(const struct terrain *pterrain)
Return the terrain index.
int count_terrain_class_near_tile(const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_class tclass)
Return the number of adjacent tiles that have given terrain class (not including ptile itself).
#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_add_extra(struct tile *ptile, const struct extra_type *pextra)
Adds extra to tile.
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Set the given terrain at the specified tile.
bool tile_has_river(const struct tile *ptile)
Tile has any river type.
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Remove extra and adjust other extras accordingly.
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Set the given resource at the specified tile.
void tile_set_continent(struct tile *ptile, Continent_id val)
Set the continent ID of the tile.
#define tile_resource(_tile)
#define tile_terrain(_tile)
#define tile_continent(_tile)
#define tile_has_extra(ptile, pextra)