Feature #69 ยป 0023-Maintain-altitude-map.patch
| common/map.c | ||
|---|---|---|
|
ptile->placing = nullptr;
|
||
|
ptile->claimer = nullptr;
|
||
|
ptile->worked = nullptr; /* No city working here. */
|
||
|
ptile->altitude = 0;
|
||
|
ptile->spec_sprite = nullptr;
|
||
|
}
|
||
| common/tile.c | ||
|---|---|---|
|
/************************************************************************//**
|
||
|
Returns a virtual tile. If ptile is given, the properties of this tile are
|
||
|
copied, else it is completely blank (except for the unit list
|
||
|
vtile->units, which is created for you). Be sure to call tile_virtual_free
|
||
|
vtile->units, which is created for you). Be sure to call tile_virtual_free()
|
||
|
on it when it is no longer needed.
|
||
|
****************************************************************************/
|
||
|
struct tile *tile_virtual_new(const struct tile *ptile)
|
||
| ... | ... | |
|
vtile = fc_calloc(1, sizeof(*vtile));
|
||
|
/* initialise some values */
|
||
|
/* Initialise some values */
|
||
|
vtile->index = TILE_INDEX_NONE;
|
||
|
vtile->continent = -1;
|
||
|
BV_CLR_ALL(vtile->extras);
|
||
|
vtile->resource = NULL;
|
||
|
vtile->terrain = NULL;
|
||
|
vtile->resource = nullptr;
|
||
|
vtile->terrain = nullptr;
|
||
|
vtile->units = unit_list_new();
|
||
|
vtile->worked = NULL;
|
||
|
vtile->owner = NULL;
|
||
|
vtile->placing = NULL;
|
||
|
vtile->extras_owner = NULL;
|
||
|
vtile->claimer = NULL;
|
||
|
vtile->spec_sprite = NULL;
|
||
|
if (ptile) {
|
||
|
/* Used by is_city_center to give virtual tiles the output bonuses
|
||
|
vtile->worked = nullptr;
|
||
|
vtile->owner = nullptr;
|
||
|
vtile->placing = nullptr;
|
||
|
vtile->extras_owner = nullptr;
|
||
|
vtile->claimer = nullptr;
|
||
|
vtile->altitude = 0;
|
||
|
vtile->spec_sprite = nullptr;
|
||
|
if (ptile != nullptr) {
|
||
|
/* Used by is_city_center() to give virtual tiles the output bonuses
|
||
|
* they deserve. */
|
||
|
vtile->index = tile_index(ptile);
|
||
| ... | ... | |
|
vtile->owner = ptile->owner;
|
||
|
vtile->extras_owner = ptile->extras_owner;
|
||
|
vtile->claimer = ptile->claimer;
|
||
|
vtile->spec_sprite = NULL;
|
||
|
vtile->altitude = ptile->altitude;
|
||
|
vtile->spec_sprite = nullptr;
|
||
|
}
|
||
|
return vtile;
|
||
| ... | ... | |
|
}
|
||
|
} unit_list_iterate_end;
|
||
|
unit_list_destroy(vtile->units);
|
||
|
vtile->units = NULL;
|
||
|
vtile->units = nullptr;
|
||
|
}
|
||
|
vcity = tile_city(vtile);
|
||
| ... | ... | |
|
if (city_is_virtual(vcity)) {
|
||
|
destroy_city_virtual(vcity);
|
||
|
}
|
||
|
tile_set_worked(vtile, NULL);
|
||
|
tile_set_worked(vtile, nullptr);
|
||
|
}
|
||
|
free(vtile);
|
||
| common/tile.h | ||
|---|---|---|
|
int infra_turns;
|
||
|
struct player *extras_owner;
|
||
|
struct tile *claimer;
|
||
|
int altitude;
|
||
|
char *label; /* NULL for no label */
|
||
|
char *spec_sprite;
|
||
|
};
|
||
| server/generator/height_map.c | ||
|---|---|---|
|
return TRUE;
|
||
|
}
|
||
|
/**********************************************************************//**
|
||
|
Copy height map to actual map tiles.
|
||
|
**************************************************************************/
|
||
|
void height_map_to_map(void)
|
||
|
{
|
||
|
whole_map_iterate(&(wld.map), ptile) {
|
||
|
ptile->altitude = hmap(ptile);
|
||
|
} whole_map_iterate_end;
|
||
|
wld.map.altitude_info = TRUE;
|
||
|
}
|
||
| server/generator/height_map.h | ||
|---|---|---|
|
bool area_is_too_flat(struct tile *ptile, int thill, int my_height);
|
||
|
void height_map_to_map(void);
|
||
|
#endif /* FC__HEIGHT__MAP_H */
|
||
| server/generator/mapgen.c | ||
|---|---|---|
|
static bool map_generate_fair_islands(void);
|
||
|
static void adjust_terrain_param(void);
|
||
|
/* common variables for generator 2, 3 and 4 */
|
||
|
/* Common variables for generator 2, 3 and 4 */
|
||
|
struct gen234_state {
|
||
|
int isleindex, n, e, s, w;
|
||
|
long int totalmass;
|
||
|
};
|
||
|
/* define one terrain selection */
|
||
|
/* Define one terrain selection */
|
||
|
struct terrain_select {
|
||
|
int weight;
|
||
|
enum mapgen_terrain_property target;
|
||
| ... | ... | |
|
int wet_condition);
|
||
|
static void tersel_free(struct terrain_select *ptersel);
|
||
|
/* terrain selection lists for make_island() */
|
||
|
/* Terrain selection lists for make_island() */
|
||
|
static struct {
|
||
|
bool init;
|
||
|
struct terrain_select_list *forest;
|
||
| ... | ... | |
|
**************************************************************************/
|
||
|
/* WETNESS */
|
||
|
/* necessary condition of deserts placement */
|
||
|
/* Necessary condition of deserts placement */
|
||
|
#define map_pos_is_dry(ptile) \
|
||
|
(map_colatitude((ptile)) <= DRY_MAX_LEVEL \
|
||
|
&& map_colatitude((ptile)) > DRY_MIN_LEVEL \
|
||
| ... | ... | |
|
/* MISCELANEOUS (OTHER CONDITIONS) */
|
||
|
/* necessary condition of swamp placement */
|
||
|
/* Necessary condition of swamp placement */
|
||
|
static int hmap_low_level = 0;
|
||
|
#define ini_hmap_low_level() \
|
||
|
{ \
|
||
|
hmap_low_level = (4 * swamp_pct * \
|
||
|
(hmap_max_level - hmap_shore_level)) / 100 + hmap_shore_level; \
|
||
|
}
|
||
|
/* should be used after having hmap_low_level initialized */
|
||
|
/* Should be used after having hmap_low_level initialized */
|
||
|
#define map_pos_is_low(ptile) ((hmap((ptile)) < hmap_low_level))
|
||
|
typedef enum { MC_NONE, MC_LOW, MC_NLOW } miscellaneous_c;
|
||
| ... | ... | |
|
make_fracture_map();
|
||
|
}
|
||
|
/* if hmap only generator make anything else */
|
||
|
/* If hmap only generator make anything else */
|
||
|
if (MAPGEN_RANDOM == wld.map.server.generator
|
||
|
|| MAPGEN_FRACTAL == wld.map.server.generator
|
||
|
|| MAPGEN_FRACTURE == wld.map.server.generator) {
|
||
|
height_map_to_map();
|
||
|
make_land();
|
||
|
free(height_map);
|
||
|
height_map = NULL;
|
||
|
height_map = nullptr;
|
||
|
}
|
||
|
if (!wld.map.server.tinyisles) {
|
||
|
remove_tiny_islands();
|
||
| ... | ... | |
|
static bool create_island(int islemass, struct gen234_state *pstate)
|
||
|
{
|
||
|
int i, nat_x, nat_y;
|
||
|
long int tries = islemass*(2+islemass/20)+99;
|
||
|
long int tries = islemass * (2 + islemass / 20) + 99;
|
||
|
bool j;
|
||
|
struct tile *ptile = native_pos_to_tile(&(wld.map),
|
||
|
wld.map.xsize / 2, wld.map.ysize / 2);
|
||
| ... | ... | |
|
}
|
||
|
/**********************************************************************//**
|
||
|
fill ocean and make polar
|
||
|
Fill ocean and make polar
|
||
|
A temperature map is created in map_fractal_generate().
|
||
|
**************************************************************************/
|
||
|
static void initworld(struct gen234_state *pstate)
|
||
| ... | ... | |
|
struct terrain *deepest_ocean = pick_ocean(TERRAIN_OCEAN_DEPTH_MAXIMUM,
|
||
|
FALSE);
|
||
|
fc_assert(NULL != deepest_ocean);
|
||
|
fc_assert(deepest_ocean != nullptr);
|
||
|
height_map = fc_malloc(MAP_INDEX_SIZE * sizeof(*height_map));
|
||
|
create_placed_map(); /* land tiles which aren't placed yet */
|
||
|
create_placed_map(); /* Land tiles which aren't placed yet */
|
||
|
whole_map_iterate(&(wld.map), ptile) {
|
||
|
tile_set_terrain(ptile, deepest_ocean);
|
||
|
tile_set_continent(ptile, 0);
|
||
|
map_set_placed(ptile); /* not a land tile */
|
||
|
map_set_placed(ptile); /* Not a land tile */
|
||
|
BV_CLR_ALL(ptile->extras);
|
||
|
tile_set_owner(ptile, NULL, NULL);
|
||
|
ptile->extras_owner = NULL;
|
||
| ... | ... | |
|
log_verbose("ISLAND generator: falling back to RANDOM generator");
|
||
|
wld.map.server.generator = MAPGEN_RANDOM;
|
||
|
/* init world created this map, destroy it before abort */
|
||
|
/* Init world created this map, destroy it before abort */
|
||
|
destroy_placed_map();
|
||
|
free(height_map);
|
||
|
height_map = NULL;
|
||
|
height_map = nullptr;
|
||
|
return;
|
||
|
}
|
||
| ... | ... | |
|
make_island(smallfrac * pstate->totalmass / totalweight, 0, pstate, DMSIS);
|
||
|
}
|
||
|
make_plains();
|
||
|
height_map_to_map();
|
||
|
make_plains();
|
||
|
destroy_placed_map();
|
||
|
free(height_map);
|
||
|
height_map = NULL;
|
||
|
height_map = nullptr;
|
||
|
if (checkmass > wld.map.xsize + wld.map.ysize + totalweight) {
|
||
|
log_verbose("%ld mass left unplaced", checkmass);
|
||
| ... | ... | |
|
pstate, DMSIS);
|
||
|
}
|
||
|
make_plains();
|
||
|
height_map_to_map();
|
||
|
make_plains();
|
||
|
destroy_placed_map();
|
||
|
free(height_map);
|
||
|
height_map = NULL;
|
||
|
|
||
|
height_map = nullptr;
|
||
|
if (j == 1500) {
|
||
|
log_normal(_("Generator 3 left %li landmass unplaced."), checkmass);
|
||
|
} else if (checkmass > wld.map.xsize + wld.map.ysize) {
|
||
| ... | ... | |
|
for (i = player_count(); i > 0; i--) {
|
||
|
make_island(10 * pstate->totalmass / totalweight, 0, pstate, DMSIS);
|
||
|
}
|
||
|
make_plains();
|
||
|
height_map_to_map();
|
||
|
make_plains();
|
||
|
destroy_placed_map();
|
||
|
free(height_map);
|
||
|
height_map = NULL;
|
||
|
height_map = nullptr;
|
||
|
if (checkmass > wld.map.xsize + wld.map.ysize + totalweight) {
|
||
|
log_verbose("%ld mass left unplaced", checkmass);
|
||
| server/savegame/savegame3.c | ||
|---|---|---|
|
static void sg_load_map(struct loaddata *loading);
|
||
|
static void sg_save_map(struct savedata *saving);
|
||
|
static void sg_load_map_tiles(struct loaddata *loading);
|
||
|
static void sg_load_map_altitude(struct loaddata *loading);
|
||
|
static void sg_save_map_tiles(struct savedata *saving);
|
||
|
static void sg_save_map_altitude(struct savedata *saving);
|
||
|
static void sg_load_map_tiles_extras(struct loaddata *loading);
|
||
|
static void sg_save_map_tiles_extras(struct savedata *saving);
|
||
| ... | ... | |
|
}
|
||
|
sg_load_map_tiles(loading);
|
||
|
if (wld.map.altitude_info) {
|
||
|
sg_load_map_altitude(loading);
|
||
|
}
|
||
|
sg_load_map_startpos(loading);
|
||
|
sg_load_map_tiles_extras(loading);
|
||
|
sg_load_map_known(loading);
|
||
| ... | ... | |
|
}
|
||
|
sg_save_map_tiles(saving);
|
||
|
if (wld.map.altitude_info) {
|
||
|
sg_save_map_altitude(saving);
|
||
|
}
|
||
|
sg_save_map_startpos(saving);
|
||
|
sg_save_map_tiles_extras(saving);
|
||
|
sg_save_map_owner(saving);
|
||
| ... | ... | |
|
} whole_map_iterate_end;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
|
Load map tiles altitude
|
||
|
****************************************************************************/
|
||
|
static void sg_load_map_altitude(struct loaddata *loading)
|
||
|
{
|
||
|
int y;
|
||
|
/* Check status and return if not OK (sg_success FALSE). */
|
||
|
sg_check_ret();
|
||
|
for (y = 0; y < wld.map.ysize; y++) {
|
||
|
const char *buffer = secfile_lookup_str(loading->file,
|
||
|
"map.alt%04d", y);
|
||
|
const char *ptr = buffer;
|
||
|
int x;
|
||
|
sg_failure_ret(buffer != nullptr, "%s", secfile_error());
|
||
|
for (x = 0; x < wld.map.xsize; x++) {
|
||
|
char token[TOKEN_SIZE];
|
||
|
struct tile *ptile = native_pos_to_tile(&(wld.map), x, y);
|
||
|
int number;
|
||
|
scanin(&ptr, ",", token, sizeof(token));
|
||
|
sg_failure_ret(token[0] != '\0',
|
||
|
"Map size not correct (map.alt%d).", y);
|
||
|
sg_failure_ret(str_to_int(token, &number),
|
||
|
"Got map alt %s in (%d, %d).", token, x, y);
|
||
|
ptile->altitude = number;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
/************************************************************************//**
|
||
|
Save map tiles altitude
|
||
|
****************************************************************************/
|
||
|
static void sg_save_map_altitude(struct savedata *saving)
|
||
|
{
|
||
|
int y;
|
||
|
/* Check status and return if not OK (sg_success FALSE). */
|
||
|
sg_check_ret();
|
||
|
for (y = 0; y < wld.map.ysize; y++) {
|
||
|
char line[wld.map.xsize * TOKEN_SIZE];
|
||
|
int x;
|
||
|
line[0] = '\0';
|
||
|
for (x = 0; x < wld.map.xsize; x++) {
|
||
|
char token[TOKEN_SIZE];
|
||
|
struct tile *ptile = native_pos_to_tile(&(wld.map), x, y);
|
||
|
fc_snprintf(token, sizeof(token), "%d", ptile->altitude);
|
||
|
strcat(line, token);
|
||
|
if (x + 1 < wld.map.xsize) {
|
||
|
strcat(line, ",");
|
||
|
}
|
||
|
}
|
||
|
secfile_insert_str(saving->file, line, "map.alt%04d", y);
|
||
|
}
|
||
|
}
|
||
|
/************************************************************************//**
|
||
|
Load extras to map
|
||
|
****************************************************************************/
|
||
| ... | ... | |
|
****************************************************************************/
|
||
|
static void sg_load_map_owner(struct loaddata *loading)
|
||
|
{
|
||
|
int x, y;
|
||
|
int y;
|
||
|
struct tile *claimer = NULL;
|
||
|
struct extra_type *placing = NULL;
|
||
| ... | ... | |
|
const char *ptr3 = buffer3;
|
||
|
const char *ptr_placing = buffer_placing;
|
||
|
const char *ptr_turns = buffer_turns;
|
||
|
int x;
|
||
|
sg_failure_ret(buffer1 != NULL, "%s", secfile_error());
|
||
|
sg_failure_ret(buffer2 != NULL, "%s", secfile_error());
|
||
| ... | ... | |
|
****************************************************************************/
|
||
|
static void sg_save_map_owner(struct savedata *saving)
|
||
|
{
|
||
|
int x, y;
|
||
|
int y;
|
||
|
/* Check status and return if not OK (sg_success FALSE). */
|
||
|
sg_check_ret();
|
||
| ... | ... | |
|
/* Store owner and ownership source as plain numbers. */
|
||
|
for (y = 0; y < wld.map.ysize; y++) {
|
||
|
char line[wld.map.xsize * TOKEN_SIZE];
|
||
|
int x;
|
||
|
line[0] = '\0';
|
||
|
for (x = 0; x < wld.map.xsize; x++) {
|
||
| ... | ... | |
|
strcat(line, ",");
|
||
|
}
|
||
|
}
|
||
|
secfile_insert_str(saving->file, line, "map.owner%04d", y);
|
||
|
}
|
||
|
for (y = 0; y < wld.map.ysize; y++) {
|
||
|
char line[wld.map.xsize * TOKEN_SIZE];
|
||
|
int x;
|
||
|
line[0] = '\0';
|
||
|
for (x = 0; x < wld.map.xsize; x++) {
|
||
| ... | ... | |
|
strcat(line, ",");
|
||
|
}
|
||
|
}
|
||
|
secfile_insert_str(saving->file, line, "map.source%04d", y);
|
||
|
}
|
||
|
for (y = 0; y < wld.map.ysize; y++) {
|
||
|
char line[wld.map.xsize * TOKEN_SIZE];
|
||
|
int x;
|
||
|
line[0] = '\0';
|
||
|
for (x = 0; x < wld.map.xsize; x++) {
|
||
| ... | ... | |
|
strcat(line, ",");
|
||
|
}
|
||
|
}
|
||
|
secfile_insert_str(saving->file, line, "map.eowner%04d", y);
|
||
|
}
|
||
|
for (y = 0; y < wld.map.ysize; y++) {
|
||
|
char line[wld.map.xsize * TOKEN_SIZE];
|
||
|
int x;
|
||
|
line[0] = '\0';
|
||
|
for (x = 0; x < wld.map.xsize; x++) {
|
||
| ... | ... | |
|
strcat(line, ",");
|
||
|
}
|
||
|
}
|
||
|
secfile_insert_str(saving->file, line, "map.placing%04d", y);
|
||
|
}
|
||
|
for (y = 0; y < wld.map.ysize; y++) {
|
||
|
char line[wld.map.xsize * TOKEN_SIZE];
|
||
|
int x;
|
||
|
line[0] = '\0';
|
||
|
for (x = 0; x < wld.map.xsize; x++) {
|
||
| ... | ... | |
|
strcat(line, ",");
|
||
|
}
|
||
|
}
|
||
|
secfile_insert_str(saving->file, line, "map.infra_turns%04d", y);
|
||
|
}
|
||
|
}
|
||