Project

General

Profile

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

main, S3_2 - 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
**************************************************************************/
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,
int distance)
{
return is_friendly_city_near(unit_owner(punit), unit_tile(punit),
return is_friendly_city_near(nmap, unit_owner(punit), unit_tile(punit),
distance);
}
/**********************************************************************//**
Return TRUE if there is a friendly city near to this tile.
**************************************************************************/
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,
int distance)
{
square_iterate(&(wld.map), ptile, distance, ptile1) {
square_iterate(nmap, ptile, distance, 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_unit_near_a_friendly_city(const struct civ_map *nmap,
const struct unit *punit,
int distance);
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,
int distance);
bool city_exists_within_max_city_map(const struct tile *ptile,
common/unit.c
{
const struct tile *ptile = unit_tile(punit);
int max_friendliness_range;
const struct civ_map *nmap = &(wld.map);
if (!is_attack_unit(punit)) {
return FALSE;
......
max_friendliness_range = tile_has_not_aggressive_extra_for_unit(ptile,
unit_type_get(punit));
if (max_friendliness_range >= 0) {
return !is_unit_near_a_friendly_city(punit, max_friendliness_range);
return !is_unit_near_a_friendly_city(nmap, punit, max_friendliness_range);
}
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) {
......
type_end_pos);
if (max_friendliness_range >= 0
&& is_friendly_city_near(pplayer_end_pos, dst_tile, max_friendliness_range)) {
&& is_friendly_city_near(nmap, pplayer_end_pos, dst_tile, max_friendliness_range)) {
friendly_end = TRUE;
} else {
max_friendliness_range = tile_has_not_aggressive_extra_for_unit(src_tile,
type_start_pos);
if (max_friendliness_range >= 0
&& is_friendly_city_near(pplayer_start_pos, src_tile, max_friendliness_range)) {
&& is_friendly_city_near(nmap, pplayer_start_pos, src_tile, max_friendliness_range)) {
friendly_end = TRUE;
}
}
(1-1/2)