Project

General

Profile

Feature #227 » 0013-Unhardcode-wld.map-from-terrain_surroundings_allow_c.patch

S3_1 - Marko Lindqvist, 02/04/2024 06:00 PM

View differences:

common/actions.c
pterrain = tile_terrain(target->tile);
if (pterrain->transform_result == T_NONE
|| pterrain == pterrain->transform_result
|| !terrain_surroundings_allow_change(target->tile,
|| !terrain_surroundings_allow_change(nmap, target->tile,
pterrain->transform_result)
|| (terrain_has_flag(pterrain->transform_result, TER_NO_CITIES)
&& (tile_city(target->tile)))) {
......
if (pterrain->cultivate_result == NULL) {
return TRI_NO;
}
if (!terrain_surroundings_allow_change(target->tile,
if (!terrain_surroundings_allow_change(nmap, target->tile,
pterrain->cultivate_result)
|| (terrain_has_flag(pterrain->cultivate_result, TER_NO_CITIES)
&& tile_city(target->tile))) {
......
if (pterrain->plant_result == NULL) {
return TRI_NO;
}
if (!terrain_surroundings_allow_change(target->tile,
if (!terrain_surroundings_allow_change(nmap, target->tile,
pterrain->plant_result)
|| (terrain_has_flag(pterrain->plant_result, TER_NO_CITIES)
&& tile_city(target->tile))) {
common/map.c
"reclaimed" from ocean into land. This is the case only when there are
a sufficient number of adjacent tiles that are not ocean.
***********************************************************************/
bool can_reclaim_ocean(const struct tile *ptile)
bool can_reclaim_ocean(const struct civ_map *nmap,
const struct tile *ptile)
{
int land_tiles = 100 - count_terrain_class_near_tile(&(wld.map), ptile,
int land_tiles = 100 - count_terrain_class_near_tile(nmap, ptile,
FALSE, TRUE,
TC_OCEAN);
......
"channeled" from land into ocean. This is the case only when there are
a sufficient number of adjacent tiles that are ocean.
***********************************************************************/
bool can_channel_land(const struct tile *ptile)
bool can_channel_land(const struct civ_map *nmap,
const struct tile *ptile)
{
int ocean_tiles = count_terrain_class_near_tile(&(wld.map), ptile,
int ocean_tiles = count_terrain_class_near_tile(nmap, ptile,
FALSE, TRUE, TC_OCEAN);
return ocean_tiles >= terrain_control.land_channel_requirement_pct;
......
terrain with a 'Frozen' flag to terrain without. This requires
a sufficient number of adjacent unfrozen tiles.
***********************************************************************/
bool can_thaw_terrain(const struct tile *ptile)
bool can_thaw_terrain(const struct civ_map *nmap,
const struct tile *ptile)
{
int unfrozen_tiles = 100 - count_terrain_flag_near_tile(&(wld.map), ptile,
int unfrozen_tiles = 100 - count_terrain_flag_near_tile(nmap, ptile,
FALSE, TRUE,
TER_FROZEN);
......
terrain without a 'Frozen' flag to terrain with. This requires
a sufficient number of adjacent frozen tiles.
***********************************************************************/
bool can_freeze_terrain(const struct tile *ptile)
bool can_freeze_terrain(const struct civ_map *nmap,
const struct tile *ptile)
{
int frozen_tiles = count_terrain_flag_near_tile(&(wld.map), ptile,
int frozen_tiles = count_terrain_flag_near_tile(nmap, ptile,
FALSE, TRUE,
TER_FROZEN);
......
Returns FALSE if a terrain change to 'pterrain' would be prevented by not
having enough similar terrain surrounding ptile.
***********************************************************************/
bool terrain_surroundings_allow_change(const struct tile *ptile,
bool terrain_surroundings_allow_change(const struct civ_map *nmap,
const struct tile *ptile,
const struct terrain *pterrain)
{
bool ret = TRUE;
if (is_ocean(tile_terrain(ptile))
&& !is_ocean(pterrain) && !can_reclaim_ocean(ptile)) {
&& !is_ocean(pterrain) && !can_reclaim_ocean(nmap, ptile)) {
ret = FALSE;
} else if (!is_ocean(tile_terrain(ptile))
&& is_ocean(pterrain) && !can_channel_land(ptile)) {
&& is_ocean(pterrain) && !can_channel_land(nmap, ptile)) {
ret = FALSE;
}
if (ret) {
if (terrain_has_flag(tile_terrain(ptile), TER_FROZEN)
&& !terrain_has_flag(pterrain, TER_FROZEN)
&& !can_thaw_terrain(ptile)) {
&& !can_thaw_terrain(nmap, ptile)) {
ret = FALSE;
} else if (!terrain_has_flag(tile_terrain(ptile), TER_FROZEN)
&& terrain_has_flag(pterrain, TER_FROZEN)
&& !can_freeze_terrain(ptile)) {
&& !can_freeze_terrain(nmap, ptile)) {
ret = FALSE;
}
}
common/map.h
bv_extras get_tile_infrastructure_set(const struct tile *ptile,
int *count);
bool can_channel_land(const struct tile *ptile);
bool can_reclaim_ocean(const struct tile *ptile);
bool can_thaw_terrain(const struct tile *ptile);
bool can_freeze_terrain(const struct tile *ptile);
bool terrain_surroundings_allow_change(const struct tile *ptile,
bool can_channel_land(const struct civ_map *nmap,
const struct tile *ptile);
bool can_reclaim_ocean(const struct civ_map *nmap,
const struct tile *ptile);
bool can_thaw_terrain(const struct civ_map *nmap,
const struct tile *ptile);
bool can_freeze_terrain(const struct civ_map *nmap,
const struct tile *ptile);
bool terrain_surroundings_allow_change(const struct civ_map *nmap,
const struct tile *ptile,
const struct terrain *pterrain);
extern struct terrain_misc terrain_control;
server/advisors/infracache.c
adv_want goodness;
struct tile *vtile;
struct terrain *old_terrain, *new_terrain;
const struct civ_map *nmap = &(wld.map);
fc_assert_ret_val(ptile != NULL, -1);
......
return -1;
}
if (!terrain_surroundings_allow_change(ptile, new_terrain)) {
if (!terrain_surroundings_allow_change(nmap, ptile, new_terrain)) {
/* Can't do this terrain conversion here. */
return -1;
}
server/maphand.c
{
int k = map_num_tiles();
bool used[k];
const struct civ_map *nmap = &(wld.map);
memset(used, 0, sizeof(used));
log_verbose("Climate change: %s (%d)",
......
/* Only change between water and land at coastlines, and between
* frozen and unfrozen at ice margin */
if (!terrain_surroundings_allow_change(ptile, new)) {
if (!terrain_surroundings_allow_change(nmap, ptile, new)) {
continue;
}
(2-2/2)