Feature #641 ยป 0001-Move-continent-ocean-sizes-and-lake-surrounders-to-c.patch
ai/default/aiparatrooper.c | ||
---|---|---|
/* common */
|
||
#include "city.h"
|
||
#include "game.h"
|
||
#include "map.h"
|
||
#include "player.h"
|
||
#include "research.h"
|
||
#include "unit.h"
|
||
... | ... | |
/* server/advisors */
|
||
#include "advdata.h"
|
||
/* server/generator */
|
||
#include "mapgen_utils.h"
|
||
/* ai */
|
||
#include "handicaps.h"
|
||
common/map.c | ||
---|---|---|
imap->north_latitude = MAP_DEFAULT_NORTH_LATITUDE;
|
||
imap->south_latitude = MAP_DEFAULT_SOUTH_LATITUDE;
|
||
imap->continent_sizes = nullptr;
|
||
imap->ocean_sizes = nullptr;
|
||
imap->lake_surrounders = nullptr;
|
||
if (server_side) {
|
||
imap->server.mapsize = MAP_DEFAULT_MAPSIZE;
|
||
imap->server.size = MAP_DEFAULT_SIZE;
|
||
... | ... | |
FC_FREE(fmap->iterate_outwards_indices);
|
||
}
|
||
if (fmap->continent_sizes) {
|
||
FC_FREE(fmap->continent_sizes);
|
||
fmap->num_continents = 0;
|
||
}
|
||
if (fmap->ocean_sizes) {
|
||
FC_FREE(fmap->ocean_sizes);
|
||
fmap->num_oceans = 0;
|
||
}
|
||
if (fmap->lake_surrounders) {
|
||
FC_FREE(fmap->lake_surrounders);
|
||
fmap->num_oceans = 0;
|
||
}
|
||
}
|
||
/*******************************************************************//**
|
||
... | ... | |
return ret;
|
||
}
|
||
/**********************************************************************//**
|
||
Return size in tiles of the given continent (not ocean)
|
||
**************************************************************************/
|
||
int get_continent_size(Continent_id id)
|
||
{
|
||
fc_assert_ret_val(id > 0, -1);
|
||
fc_assert_ret_val(id <= wld.map.num_continents, -1);
|
||
/* Client updates num_continents, but not continent_sizes */
|
||
fc_assert_ret_val(is_server(), -1);
|
||
return wld.map.continent_sizes[id];
|
||
}
|
||
/**********************************************************************//**
|
||
Return size in tiles of the given ocean. You should use positive ocean
|
||
number.
|
||
**************************************************************************/
|
||
int get_ocean_size(Continent_id id)
|
||
{
|
||
fc_assert_ret_val(id > 0, -1);
|
||
fc_assert_ret_val(id <= wld.map.num_oceans, -1);
|
||
return wld.map.ocean_sizes[id];
|
||
}
|
||
/**********************************************************************//**
|
||
Get continent surrounding lake, or -1 if there is multiple continents.
|
||
**************************************************************************/
|
||
int get_lake_surrounders(Continent_id id)
|
||
{
|
||
fc_assert_ret_val(id < 0, -1);
|
||
fc_assert_ret_val(id >= -wld.map.num_oceans, -1);
|
||
return wld.map.lake_surrounders[-id];
|
||
}
|
||
/*******************************************************************//**
|
||
The basic cost to move punit from tile t1 to tile t2.
|
||
That is, tile_move_cost(), with pre-calculated tile pointers;
|
common/map.h | ||
---|---|---|
const struct tile *src_tile,
|
||
const struct tile *dst_tile);
|
||
int get_continent_size(Continent_id id);
|
||
int get_ocean_size(Continent_id id);
|
||
int get_lake_surrounders(Continent_id id);
|
||
/* Specific functions for start positions. */
|
||
struct startpos *map_startpos_by_number(int id);
|
common/map_types.h | ||
---|---|---|
int xsize, ysize; /* Native dimensions */
|
||
int north_latitude;
|
||
int south_latitude;
|
||
int num_continents;
|
||
int num_oceans; /* Not updated at the client */
|
||
/* These arrays are indexed by continent number (or negative of the
|
||
* ocean number) so the 0th element is unused and the array is 1 element
|
||
* larger than you'd expect.
|
||
*
|
||
* The _sizes arrays give the sizes (in tiles) of each continent and
|
||
* ocean.
|
||
*
|
||
* The lake_surrounders array tells which single continent surrounds each
|
||
* ocean; or -1 if there's more than one adjacent continent.
|
||
*/
|
||
int *continent_sizes; /* Not updated at the client */
|
||
int *ocean_sizes; /* Not updated at the client */
|
||
Continent_id *lake_surrounders; /* Not updated at the client */
|
||
struct tile *tiles;
|
||
struct startpos_hash *startpos_table;
|
||
server/generator/mapgen_utils.c | ||
---|---|---|
FC_FREE(alt_int_map);
|
||
}
|
||
/* These arrays are indexed by continent number (or negative of the
|
||
* ocean number) so the 0th element is unused and the array is 1 element
|
||
* larger than you'd expect.
|
||
*
|
||
* The lake surrounders array tells how many land continents surround each
|
||
* ocean (or -1 if the ocean touches more than one continent).
|
||
*
|
||
* The _sizes arrays give the sizes (in tiles) of each continent and
|
||
* ocean.
|
||
*/
|
||
static Continent_id *lake_surrounders = NULL;
|
||
static int *continent_sizes = NULL;
|
||
static int *ocean_sizes = NULL;
|
||
/**********************************************************************//**
|
||
Calculate lake_surrounders[] array
|
||
Calculate wld.map.lake_surrounders[] array
|
||
**************************************************************************/
|
||
static void recalculate_lake_surrounders(void)
|
||
{
|
||
const size_t size = (wld.map.num_oceans + 1) * sizeof(*lake_surrounders);
|
||
size_t size;
|
||
lake_surrounders = fc_realloc(lake_surrounders, size);
|
||
memset(lake_surrounders, 0, size);
|
||
size = (wld.map.num_oceans + 1) * sizeof(*wld.map.lake_surrounders);
|
||
wld.map.lake_surrounders = fc_realloc(wld.map.lake_surrounders, size);
|
||
memset(wld.map.lake_surrounders, 0, size);
|
||
whole_map_iterate(&(wld.map), ptile) {
|
||
const struct terrain *pterrain = tile_terrain(ptile);
|
||
... | ... | |
continue;
|
||
}
|
||
if (terrain_type_terrain_class(pterrain) != TC_OCEAN) {
|
||
adjc_iterate(&(wld.map), ptile, tile2) {
|
||
Continent_id cont2 = tile_continent(tile2);
|
||
if (is_ocean_tile(tile2)) {
|
||
if (lake_surrounders[-cont2] == 0) {
|
||
lake_surrounders[-cont2] = cont;
|
||
} else if (lake_surrounders[-cont2] != cont) {
|
||
lake_surrounders[-cont2] = -1;
|
||
}
|
||
}
|
||
if (!is_ocean(pterrain)) {
|
||
fc_assert_action(cont > 0, continue);
|
||
adjc_iterate(&(wld.map), ptile, adj_tile) {
|
||
Continent_id adj_cont = tile_continent(adj_tile);
|
||
if (is_ocean_tile(adj_tile)) {
|
||
fc_assert_action(adj_cont < 0, continue);
|
||
if (wld.map.lake_surrounders[-adj_cont] == 0) {
|
||
wld.map.lake_surrounders[-adj_cont] = cont;
|
||
} else if (wld.map.lake_surrounders[-adj_cont] != cont) {
|
||
wld.map.lake_surrounders[-adj_cont] = -1;
|
||
}
|
||
}
|
||
} adjc_iterate_end;
|
||
}
|
||
} whole_map_iterate_end;
|
||
... | ... | |
/* Count the tile */
|
||
if (nr < 0) {
|
||
ocean_sizes[-nr]++;
|
||
wld.map.ocean_sizes[-nr]++;
|
||
} else {
|
||
continent_sizes[nr]++;
|
||
wld.map.continent_sizes[nr]++;
|
||
}
|
||
}
|
||
... | ... | |
if (terrain_type_terrain_class(pterrain) != TC_OCEAN) {
|
||
continue;
|
||
}
|
||
if (0 < lake_surrounders[-here]) {
|
||
if (terrain_control.lake_max_size >= ocean_sizes[-here]) {
|
||
if (0 < wld.map.lake_surrounders[-here]) {
|
||
if (terrain_control.lake_max_size >= wld.map.ocean_sizes[-here]) {
|
||
int frozen = terrain_has_flag(pterrain, TER_FROZEN);
|
||
tile_change_terrain(ptile, lake_for_ocean[frozen][-here-1]);
|
||
}
|
||
... | ... | |
} whole_map_iterate_end;
|
||
}
|
||
/**********************************************************************//**
|
||
Get continent surrounding lake, or -1 if there is multiple continents.
|
||
**************************************************************************/
|
||
int get_lake_surrounders(Continent_id cont)
|
||
{
|
||
return lake_surrounders[-cont];
|
||
}
|
||
/**********************************************************************//**
|
||
Return size in tiles of the given continent (not ocean)
|
||
**************************************************************************/
|
||
int get_continent_size(Continent_id id)
|
||
{
|
||
fc_assert_ret_val(id > 0, -1);
|
||
return continent_sizes[id];
|
||
}
|
||
/**********************************************************************//**
|
||
Return size in tiles of the given ocean. You should use positive ocean
|
||
number.
|
||
**************************************************************************/
|
||
int get_ocean_size(Continent_id id)
|
||
{
|
||
fc_assert_ret_val(id > 0, -1);
|
||
return ocean_sizes[id];
|
||
}
|
||
/**********************************************************************//**
|
||
Assigns continent and ocean numbers to all tiles, and set
|
||
map.num_continents and map.num_oceans. Recalculates continent and
|
||
... | ... | |
if (terrain_type_terrain_class(pterrain) != TC_OCEAN) {
|
||
wld.map.num_continents++;
|
||
continent_sizes = fc_realloc(continent_sizes,
|
||
(wld.map.num_continents + 1) * sizeof(*continent_sizes));
|
||
continent_sizes[wld.map.num_continents] = 0;
|
||
wld.map.continent_sizes = fc_realloc(wld.map.continent_sizes,
|
||
(wld.map.num_continents + 1) * sizeof(*wld.map.continent_sizes));
|
||
wld.map.continent_sizes[wld.map.num_continents] = 0;
|
||
assign_continent_flood(ptile, TRUE, wld.map.num_continents);
|
||
} else {
|
||
wld.map.num_oceans++;
|
||
ocean_sizes = fc_realloc(ocean_sizes,
|
||
(wld.map.num_oceans + 1) * sizeof(*ocean_sizes));
|
||
ocean_sizes[wld.map.num_oceans] = 0;
|
||
wld.map.ocean_sizes = fc_realloc(wld.map.ocean_sizes,
|
||
(wld.map.num_oceans + 1) * sizeof(*wld.map.ocean_sizes));
|
||
wld.map.ocean_sizes[wld.map.num_oceans] = 0;
|
||
assign_continent_flood(ptile, FALSE, -wld.map.num_oceans);
|
||
}
|
||
} whole_map_iterate_end;
|
||
... | ... | |
**************************************************************************/
|
||
void generator_free(void)
|
||
{
|
||
if (lake_surrounders != NULL) {
|
||
free(lake_surrounders);
|
||
lake_surrounders = NULL;
|
||
}
|
||
if (continent_sizes != NULL) {
|
||
free(continent_sizes);
|
||
continent_sizes = NULL;
|
||
}
|
||
if (ocean_sizes != NULL) {
|
||
free(ocean_sizes);
|
||
ocean_sizes = NULL;
|
||
}
|
||
}
|
||
/**********************************************************************//**
|
server/generator/mapgen_utils.h | ||
---|---|---|
void regenerate_lakes(void);
|
||
void smooth_water_depth(void);
|
||
void assign_continent_numbers(void);
|
||
int get_lake_surrounders(Continent_id cont);
|
||
int get_continent_size(Continent_id id);
|
||
int get_ocean_size(Continent_id id);
|
||
struct terrain *most_shallow_ocean(bool frozen);
|
||
struct terrain *pick_ocean(int depth, bool frozen);
|