33 enum mapgen_terrain_property
target;
34 enum mapgen_terrain_property
prefer;
35 enum mapgen_terrain_property
avoid;
40 #define SPECLIST_TAG terrain_select
43 #define terrain_select_list_iterate(tersel_list, ptersel) \
44 TYPED_LIST_ITERATE(struct terrain_select, tersel_list, ptersel)
45 #define terrain_select_list_iterate_end LIST_ITERATE_END
48 enum mapgen_terrain_property
target,
49 enum mapgen_terrain_property
prefer,
50 enum mapgen_terrain_property
avoid,
61 struct terrain_select_list *
swamp;
64 static void fill_island(
int coast,
long int *bucket,
65 const struct terrain_select_list *tersel_list,
69 int min_specific_island_size);
158 int min_specific_island_size)
161 static long int tilefactor, balance, lastplaced;
162 static long int riverbuck, mountbuck, desertbuck, forestbuck, swampbuck;
180 qInfo(
_(
"High landmass - this may take a few seconds."));
184 i = (i <= 90) ? 100 : i * 11 / 10;
194 islemass = islemass - balance;
196 if (islemass > lastplaced + 1 + lastplaced / 50) {
198 islemass = lastplaced + 1 + lastplaced / 50;
221 if (i < islemass * min_specific_island_size / 100) {
228 if (i * 10 > islemass) {
229 balance = i - islemass;
234 qDebug(
"ini=%d, plc=%d, bal=%ld, tot=%ld", islemass, i, balance,
270 struct terrain *deepest_ocean =
285 ptile->extras_owner =
nullptr;
310 long int totalweight;
321 int bigfrac = 70, midfrac = 20, smallfrac = 10;
324 qDebug(
"ISLAND generator: falling back to the next generator");
336 while (!done && bigfrac > midfrac) {
357 qDebug(
"Island too small, trying again with all smaller "
359 midfrac += bigfrac * 0.01;
360 smallfrac += bigfrac * 0.04;
368 if (bigfrac <= midfrac) {
370 qDebug(
"ISLAND generator: falling back to the next generator");
395 qDebug(
"%ld mass left unplaced",
checkmass);
410 long int maxmassdiv6 = 20;
416 qDebug(
"ISLAND generator: falling back to the next generator due "
417 "to landpercent > 80.");
422 qDebug(
"ISLAND generator: falling back to the next generator due "
423 "to unsupported map size.");
442 islandmass = (
landmass) / (3 * bigislands);
443 if (islandmass < 4 * maxmassdiv6) {
444 islandmass = (
landmass) / (2 * bigislands);
447 islandmass = (
landmass) / (bigislands);
450 if (islandmass < 2) {
453 if (islandmass > maxmassdiv6 * 6) {
454 islandmass = maxmassdiv6 * 6;
465 qInfo(
_(
"Generator 3 didn't place all big islands."));
468 islandmass = (islandmass * 11) / 8;
470 if (islandmass < 2) {
474 while (
checkmass > islandmass && ++j < 1500) {
476 size =
fc_rand((islandmass + 1) / 2 + 1) + islandmass / 2;
494 qInfo(
_(
"Generator 3 left %li landmass unplaced."),
checkmass);
496 qDebug(
"%ld mass left unplaced",
checkmass);
510 long int totalweight;
517 qDebug(
"ISLAND generator: falling back to the next generator.");
564 qDebug(
"%ld mass left unplaced",
checkmass);
618 xrnd = pstate->
w +
fc_rand(pstate->
e - pstate->
w);
619 yrnd = pstate->
n +
fc_rand(pstate->
s - pstate->
n);
628 enum mapgen_terrain_property
target,
629 enum mapgen_terrain_property
prefer,
630 enum mapgen_terrain_property
avoid,
659 const struct terrain_select_list *tersel_list,
662 int i, k, capac, total_weight = 0;
663 int ntersel = terrain_select_list_size(tersel_list);
676 *bucket -= i * capac;
679 failsafe = i * (pstate->
s - pstate->
n) * (pstate->
e - pstate->
w);
681 failsafe = -failsafe;
686 total_weight += ptersel->weight;
690 if (total_weight <= 0) {
694 while (i > 0 && (failsafe--) > 0) {
702 terrain_select_list_get(tersel_list,
fc_rand(ntersel));
719 if ((i * 3 > k * 2 ||
fc_rand(100) < 50
726 log_debug(
"[fill_island] placed terrain '%s' at (%2d,%2d)",
742 int num_card_ocean, pct_adj_ocean, num_adj_river;
750 return (num_card_ocean == 1 && pct_adj_ocean <= 35 && num_adj_river == 0);
760 int pct_adj_ocean, num_card_ocean, pct_adj_river, num_card_river;
769 return (num_card_river == 1 && num_card_ocean == 0 && pct_adj_ocean < 20
770 && pct_adj_river < 35
773 && (pct_adj_river + pct_adj_ocean * 2) <
fc_rand(25) + 25);
782 long int failsafe, capac, i, k;
795 *bucket -= i * capac;
801 failsafe = i * (pstate->
s - pstate->
n) * (pstate->
e - pstate->
w) * 5;
803 failsafe = -failsafe;
806 while (i > 0 && failsafe-- > 0) {
823 && (
fc_rand(100) < coast || i == k))
861 for (ycur = pstate->
n, xcur = pstate->
w;
862 ycur < pstate->s && xcur < pstate->e; ycur++, xcur++) {
867 if (!tile0 || !tile1) {
875 for (ycur = pstate->
n; ycur < pstate->s; ycur++) {
876 for (xcur = pstate->
w; xcur < pstate->e; xcur++) {
881 if (!tile0 || !tile1) {
890 for (ycur = pstate->
n; ycur < pstate->s; ycur++) {
891 for (xcur = pstate->
w; xcur < pstate->e; xcur++) {
898 qCritical(
"mapgen.c: mass doesn't sum up.");
911 pstate->
s +=
nat_y - pstate->
n;
912 pstate->
e +=
nat_x - pstate->
w;
928 if (
hmap(tile1) != 0) {
943 long int tries = islemass * (2 + islemass / 20) + 99;
958 while (i > 0 && tries-- > 0) {
972 if (nat_y <= pstate->n && pstate->
n > 2) {
975 if (nat_x <= pstate->w && pstate->
w > 2) {
979 if (i < islemass / 10) {
982 for (ycur = pstate->
n; ycur < pstate->s; ycur++) {
983 for (xcur = pstate->
w; xcur < pstate->e; xcur++) {
985 if (
hmap(ptile) == 0 && i > 0
995 qCritical(
"create_island ended early with %d/%d.", islemass - i,
static map_landmass * landmass
#define terrain_select_list_iterate_end
bool map_generate_island()
Generate a map with the ISLAND family of generators.
static bool make_island(int islemass, int starters, struct gen234_state *pstate, int min_specific_island_size)
make an island, fill every tile type except plains note: you have to create big islands first.
static struct @92 island_terrain
struct terrain_select_list * mountain
static bool map_generate_island_2or3()
Generator for placing a couple of players to each island.
static void initworld(struct gen234_state *pstate)
fill ocean and make polar A temperature map is created in map_fractal_generate().
static void fill_island(int coast, long int *bucket, const struct terrain_select_list *tersel_list, const struct gen234_state *const pstate)
Fill an island with different types of terrains; rivers have extra code.
static struct terrain_select * tersel_new(int weight, enum mapgen_terrain_property target, enum mapgen_terrain_property prefer, enum mapgen_terrain_property avoid, int temp_condition, int wet_condition)
Allocate and initialize new terrain_select structure.
#define terrain_select_list_iterate(tersel_list, ptersel)
struct terrain_select_list * forest
static void island_terrain_init()
Initialize terrain selection lists for make_island().
static bool place_island(struct gen234_state *pstate)
Finds a place and drop the island created when called with islemass != 0.
static void island_terrain_free()
Free memory allocated for terrain selection lists.
struct terrain_select_list * swamp
static bool is_near_land(struct tile *ptile)
Return TRUE if the ocean position is near land.
static struct tile * get_random_map_position_from_state(const struct gen234_state *const pstate)
Returns a random position in the rectangle denoted by the given state.
static void fill_island_rivers(int coast, long int *bucket, const struct gen234_state *const pstate)
Fill an island with rivers.
static bool island_river_mouth_suitability(const struct tile *ptile, const struct extra_type *priver)
Returns TRUE if ptile is suitable for a river mouth.
static bool create_island(int islemass, struct gen234_state *pstate)
finds a place and drop the island created when called with islemass != 0
static bool island_river_suitability(const struct tile *ptile, const struct extra_type *priver)
Returns TRUE if there is a river in a cardinal direction near the tile and the tile is suitable for e...
static bool map_generate_island_single()
On popular demand, this tries to mimick the generator 3 as best as possible.
struct terrain_select_list * desert
static bool map_generate_island_variable()
island base map generators
static int count_card_adjc_elevated_tiles(struct tile *ptile)
Returns the number of cardinally adjacent tiles have a non-zero elevation.
static void tersel_free(struct terrain_select *ptersel)
Free resources allocated for terrain_select structure.
static long int checkmass
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
struct tile * rand_map_pos(const struct civ_map *nmap)
Random square anywhere on the map.
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
struct tile * native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
Return the tile for the given native position.
static const bool C_PERCENT
static const bool C_NUMBER
#define cardinal_adjc_iterate_end
#define adjc_iterate(nmap, center_tile, itr_tile)
static const bool C_ADJACENT
#define cardinal_adjc_iterate(nmap, center_tile, itr_tile)
#define whole_map_iterate(_map, _tile)
static const bool C_CARDINAL
#define index_to_native_pos(pnat_x, pnat_y, mindex)
#define whole_map_iterate_end
void make_polar()
Add frozen tiles in the arctic zone.
struct extra_type * river_types[MAX_ROAD_TYPES]
bool test_wetness(const struct tile *ptile, wetness_c c)
These functions test for conditions used in rand_map_pos_characteristic.
void make_plains()
Make_plains converts all not yet placed terrains to plains (tundra, grass) used by generators 2-4.
bool near_singularity(const struct tile *ptile)
Return TRUE if the map in a typical city radius is SINGULAR.
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.
bool placed_map_is_initialized()
Return TRUE if initialized.
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 map_unset_placed(struct tile *ptile)
Mark tile terrain as not placed.
int player_count()
Return the number of players.
int count_river_type_near_tile(const struct tile *ptile, const struct extra_type *priver, bool percentage)
Count tiles with river of specific type 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.
struct civ_map::@39::@41 server
enum mapgen_terrain_property avoid
enum mapgen_terrain_property target
enum mapgen_terrain_property prefer
bool tmap_is(const struct tile *ptile, temperature_type tt)
Return true if the tile has tt temperature type.
bool is_terrain_class_card_near(const struct tile *ptile, enum terrain_class tclass)
Is there terrain of the given class cardinally near tile? (Does not check ptile itself....
const char * terrain_rule_name(const struct terrain *pterrain)
Return the (untranslated) rule name of the terrain.
bool is_terrain_near_tile(const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Returns TRUE iff any adjacent tile contains the given terrain.
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 is_ocean(pterrain)
#define TERRAIN_OCEAN_DEPTH_MAXIMUM
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.
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Set the owner of a tile (may be nullptr).
void tile_set_continent(struct tile *ptile, Continent_id val)
Set the continent ID of the tile.
#define tile_terrain(_tile)
#define tile_continent(_tile)