Freeciv21
Develop your civilization from humble roots to a global empire
mapgen_utils.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can
4  ^oo^ redistribute it and/or modify it under the terms of the GNU
5  (..) General Public License as published by the Free Software
6  () () Foundation, either version 3 of the License, or (at your
7  ()__() option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 #define MG_UNUSED mapgen_terrain_property_invalid()
14 
15 void generator_free();
16 
17 void regenerate_lakes();
18 void smooth_water_depth();
23 
24 struct terrain *most_shallow_ocean(bool frozen);
25 struct terrain *pick_ocean(int depth, bool frozen);
26 
27 struct terrain *pick_terrain_by_flag(enum terrain_flag_id flag);
28 struct terrain *pick_terrain(enum mapgen_terrain_property target,
29  enum mapgen_terrain_property prefer,
30  enum mapgen_terrain_property avoid);
31 
32 /* Provide a block to convert from native to map coordinates. For instance
33  * do_in_map_pos(mx, my, xn, yn) {
34  * tile_set_terrain(mx, my, T_OCEAN);
35  * } do_in_map_pos_end;
36  * Note: that the map position is declared as const and can't be changed
37  * inside the block.
38  */
39 #define do_in_map_pos(nmap, ptile, nat_x, nat_y) \
40  { \
41  struct tile *ptile = native_pos_to_tile(nmap, (nat_x), (nat_y)); \
42  {
43 
44 #define do_in_map_pos_end \
45  } \
46  }
47 
48 /***************************************************************************
49  iterate on selected axe (x if is_X_axis is TRUE) over a interval of -dist
50  to dist around the center_tile
51  _index : the position in the interval of iteration (from -dist to dist)
52  _tile : the tile pointer
53  */
54 #define axis_iterate(nmap, center_tile, _tile, _index, dist, is_X_axis) \
55  { \
56  int _tile##_x, _tile##_y; \
57  struct tile *_tile; \
58  const struct tile *_tile##_center = (center_tile); \
59  const bool _index##_axis = (is_X_axis); \
60  const int _index##_d = (dist); \
61  int _index = -(_index##_d); \
62  \
63  for (; _index <= _index##_d; _index++) { \
64  int _nat##_x, _nat##_y; \
65  index_to_native_pos(&_nat##_x, &_nat##_y, \
66  tile_index(_tile##_center)); \
67  _tile##_x = _nat##_x + (_index##_axis ? _index : 0); \
68  _tile##_y = _nat##_y + (_index##_axis ? 0 : _index); \
69  _tile = native_pos_to_tile(nmap, _tile##_x, _tile##_y); \
70  if (nullptr != _tile) {
71 
72 #define axis_iterate_end \
73  } \
74  } \
75  }
76 
77 /***************************************************************************
78  pdata or pfilter can be nullptr!
79 ***************************************************************************/
80 #define whole_map_iterate_filtered(_tile, pdata, pfilter) \
81  { \
82  bool (*_tile##_filter)(const struct tile *vtile, const void *vdata) = \
83  (pfilter); \
84  const void *_tile##_data = (pdata); \
85  \
86  whole_map_iterate(&(wld.map), _tile) \
87  { \
88  if (nullptr == _tile##_filter \
89  || (_tile##_filter)(_tile, _tile##_data)) {
90 
91 #define whole_map_iterate_filtered_end \
92  } \
93  } \
94  whole_map_iterate_end; \
95  }
96 
97 // int maps tools
98 void adjust_int_map_filtered(int *int_map, int int_map_max, void *data,
99  bool (*filter)(const struct tile *ptile,
100  const void *data));
101 #define adjust_int_map(int_map, int_map_max) \
102  adjust_int_map_filtered( \
103  int_map, int_map_max, (void *) nullptr, \
104  (bool (*)(const struct tile *ptile, const void *data)) nullptr)
105 void smooth_int_map(int *int_map, bool zeroes_at_edges);
106 
107 // placed_map tool
108 void create_placed_map();
109 void destroy_placed_map();
110 void map_set_placed(struct tile *ptile);
111 void map_unset_placed(struct tile *ptile);
112 bool not_placed(const struct tile *ptile);
115 void set_placed_near_pos(struct tile *ptile, int dist);
signed short Continent_id
Definition: fc_types.h:289
int get_continent_size(Continent_id id)
Return size in tiles of the given continent (not ocean)
void smooth_int_map(int *int_map, bool zeroes_at_edges)
Apply a Gaussian diffusion filter on the map.
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 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.
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.
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.
Definition: tile.h:42