Project

General

Profile

Feature #480 » 0017-Unhardcode-wld.map-from-is_friendly_city_near.patch

S3_1 - Marko Lindqvist, 04/19/2024 09:33 PM

View differences:

common/city.c
Return TRUE if there is a friendly city near to this unit (within 3
steps).
**************************************************************************/
bool is_unit_near_a_friendly_city(const struct unit *punit)
bool is_unit_near_a_friendly_city(const struct civ_map *nmap,
const struct unit *punit)
{
return is_friendly_city_near(unit_owner(punit), unit_tile(punit));
return is_friendly_city_near(nmap, unit_owner(punit), unit_tile(punit));
}
/**********************************************************************//**
Return TRUE if there is a friendly city near to this tile (within 3
steps).
**************************************************************************/
bool is_friendly_city_near(const struct player *owner,
bool is_friendly_city_near(const struct civ_map *nmap,
const struct player *owner,
const struct tile *ptile)
{
square_iterate(&(wld.map), ptile, 3, ptile1) {
square_iterate(nmap, ptile, 3, ptile1) {
struct city *pcity = tile_city(ptile1);
if (pcity && pplayers_allied(owner, city_owner(pcity))) {
common/city.h
return NULL != tile_non_allied_city(ptile, pplayer);
}
bool is_unit_near_a_friendly_city(const struct unit *punit);
bool is_friendly_city_near(const struct player *owner,
bool is_unit_near_a_friendly_city(const struct civ_map *nmap,
const struct unit *punit);
bool is_friendly_city_near(const struct civ_map *nmap,
const struct player *owner,
const struct tile *ptile);
bool city_exists_within_max_city_map(const struct tile *ptile,
bool may_be_on_center);
common/unit.c
**************************************************************************/
bool unit_being_aggressive(const struct unit *punit)
{
const struct civ_map *nmap = &(wld.map);
if (!is_attack_unit(punit)) {
return FALSE;
}
......
}
if (tile_has_not_aggressive_extra_for_unit(unit_tile(punit),
unit_type_get(punit))) {
return !is_unit_near_a_friendly_city(punit);
return !is_unit_near_a_friendly_city(nmap, punit);
}
return TRUE;
server/unittools.c
bool refresh_homecity_end_pos = FALSE;
int saved_id = punit->id;
bool alive = TRUE;
const struct civ_map *nmap = &(wld.map);
if (tocity && conquer_city_allowed) {
if (!passenger) {
......
}
}
/* entering/leaving a fortress or friendly territory */
/* Entering/leaving a fortress or friendly territory */
if (homecity_start_pos || homecity_end_pos) {
if ((game.info.happyborders != HB_DISABLED && tile_owner(src_tile) != tile_owner(dst_tile))
|| (tile_has_not_aggressive_extra_for_unit(dst_tile,
type_end_pos)
&& is_friendly_city_near(pplayer_end_pos, dst_tile))
&& is_friendly_city_near(nmap, pplayer_end_pos, dst_tile))
|| (tile_has_not_aggressive_extra_for_unit(src_tile,
type_start_pos)
&& is_friendly_city_near(pplayer_start_pos, src_tile))) {
&& is_friendly_city_near(nmap, pplayer_start_pos, src_tile))) {
refresh_homecity_start_pos = TRUE;
refresh_homecity_end_pos = TRUE;
}
(2-2/2)