From a2faec9f33920bdd099fef78992dfe9bed6dc7cc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 29 Dec 2022 03:31:10 +0200 Subject: [PATCH 17/17] Make is_..._city_tile() to return bool That's what their name suggest, and what most of the callers expect. Returning a point to those callers was causing an error when compiler is following c2x standard. Added tile_..._city() family of members that those former is_..._city_tile() callers that actually expect a pointer call instead. See osdn #46306 Signed-off-by: Marko Lindqvist --- client/goto.c | 6 ++-- common/aicore/pf_tools.c | 3 +- common/city.c | 44 ++++++++++++++++-------------- common/city.h | 59 +++++++++++++++++++++++++++++++++------- common/unit.c | 2 +- server/unithand.c | 2 +- server/unittools.c | 2 +- 7 files changed, 80 insertions(+), 38 deletions(-) diff --git a/client/goto.c b/client/goto.c index f48dffa8d9..4753e3cc0b 100644 --- a/client/goto.c +++ b/client/goto.c @@ -571,7 +571,7 @@ static enum tile_behavior get_TB_aggr(const struct tile *ptile, return TB_IGNORE; } } else if (is_non_allied_unit_tile(ptile, param->owner) - || is_non_allied_city_tile(ptile, param->owner)) { + || is_non_allied_city_tile(ptile, param->owner)) { /* Can attack but can't count on going through */ return TB_DONT_LEAVE; } @@ -1434,7 +1434,7 @@ static void send_path_orders(struct unit *punit, struct pf_path *path, if (i > 0 && p.orders[i - 1] == ORDER_MOVE - && (is_non_allied_city_tile(old_tile, client_player()) != NULL + && (is_non_allied_city_tile(old_tile, client_player()) || is_non_allied_unit_tile(old_tile, client_player()) != NULL)) { /* Won't be able to perform a regular move to the target tile... */ if (!final_order) { @@ -1699,7 +1699,7 @@ static bool order_wants_direction(enum unit_orders order, action_id act_id, return FALSE; } - if (is_non_allied_city_tile(tgt_tile, client_player()) != NULL + if (is_non_allied_city_tile(tgt_tile, client_player()) || is_non_allied_unit_tile(tgt_tile, client_player()) != NULL) { /* Won't be able to move to the target tile to perform the action on * top of it. */ diff --git a/common/aicore/pf_tools.c b/common/aicore/pf_tools.c index 5cdeebf3b3..406dc223ef 100644 --- a/common/aicore/pf_tools.c +++ b/common/aicore/pf_tools.c @@ -87,8 +87,7 @@ static enum pf_action pf_get_action(const struct tile *ptile, enum known_type known, const struct pf_parameter *param) { - bool non_allied_city = (NULL != is_non_allied_city_tile(ptile, - param->owner)); + bool non_allied_city = is_non_allied_city_tile(ptile, param->owner); if (non_allied_city) { if (PF_AA_TRADE_ROUTE & param->actions) { diff --git a/common/city.c b/common/city.c index 0a0474da91..5c01368b5c 100644 --- a/common/city.c +++ b/common/city.c @@ -1940,59 +1940,63 @@ bool city_can_grow_to(const struct city *pcity, int pop_size) } /************************************************************************** - is there an enemy city on this tile? + Return enemy city on the tile, if one exist **************************************************************************/ -struct city *is_enemy_city_tile(const struct tile *ptile, - const struct player *pplayer) +struct city *tile_enemy_city(const struct tile *ptile, + const struct player *pplayer) { struct city *pcity = tile_city(ptile); - if (pcity && pplayers_at_war(pplayer, city_owner(pcity))) + if (pcity != NULL && pplayers_at_war(pplayer, city_owner(pcity))) { return pcity; - else + } else { return NULL; + } } /************************************************************************** - is there an friendly city on this tile? + Return friendly city on the tile, if one exist **************************************************************************/ -struct city *is_allied_city_tile(const struct tile *ptile, - const struct player *pplayer) +struct city *tile_allied_city(const struct tile *ptile, + const struct player *pplayer) { struct city *pcity = tile_city(ptile); - if (pcity && pplayers_allied(pplayer, city_owner(pcity))) + if (pcity != NULL && pplayers_allied(pplayer, city_owner(pcity))) { return pcity; - else + } else { return NULL; + } } /************************************************************************** - is there an enemy city on this tile? + Return non-attack city on the tile, if one exist **************************************************************************/ -struct city *is_non_attack_city_tile(const struct tile *ptile, - const struct player *pplayer) +struct city *tile_non_attack_city(const struct tile *ptile, + const struct player *pplayer) { struct city *pcity = tile_city(ptile); - if (pcity && pplayers_non_attack(pplayer, city_owner(pcity))) + if (pcity != NULL && pplayers_non_attack(pplayer, city_owner(pcity))) { return pcity; - else + } else{ return NULL; + } } /************************************************************************** - is there an non_allied city on this tile? + Return non-allied city on the tile, if one exist **************************************************************************/ -struct city *is_non_allied_city_tile(const struct tile *ptile, - const struct player *pplayer) +struct city *tile_non_allied_city(const struct tile *ptile, + const struct player *pplayer) { struct city *pcity = tile_city(ptile); - if (pcity && !pplayers_allied(pplayer, city_owner(pcity))) + if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) { return pcity; - else + } else { return NULL; + } } /************************************************************************** diff --git a/common/city.h b/common/city.h index 91ce4efe90..99d31b8885 100644 --- a/common/city.h +++ b/common/city.h @@ -672,21 +672,60 @@ struct city *city_list_find_name(struct city_list *This, const char *name); int city_name_compare(const void *p1, const void *p2); -/* city style functions */ +/* City style functions */ const char *city_style_rule_name(const int style); const char *city_style_name_translation(const int style); int city_style_by_rule_name(const char *s); int city_style_by_translated_name(const char *s); -struct city *is_enemy_city_tile(const struct tile *ptile, - const struct player *pplayer); -struct city *is_allied_city_tile(const struct tile *ptile, - const struct player *pplayer); -struct city *is_non_attack_city_tile(const struct tile *ptile, - const struct player *pplayer); -struct city *is_non_allied_city_tile(const struct tile *ptile, - const struct player *pplayer); +struct city *tile_enemy_city(const struct tile *ptile, + const struct player *pplayer); + +/**********************************************************************//** + Is there an enemy city on the tile? +**************************************************************************/ +static inline bool is_enemy_city_tile(const struct tile *ptile, + const struct player *pplayer) +{ + return NULL != tile_enemy_city(ptile, pplayer); +} + +struct city *tile_allied_city(const struct tile *ptile, + const struct player *pplayer); + +/**********************************************************************//** + Is there an allied city on the tile? +**************************************************************************/ +static inline bool is_allied_city_tile(const struct tile *ptile, + const struct player *pplayer) +{ + return NULL != tile_allied_city(ptile, pplayer); +} + +struct city *tile_non_attack_city(const struct tile *ptile, + const struct player *pplayer); + +/**********************************************************************//** + Is there a non-attack city on the tile? +**************************************************************************/ +static inline bool is_non_attack_city_tile(const struct tile *ptile, + const struct player *pplayer) +{ + return NULL != tile_non_attack_city(ptile, pplayer); +} + +struct city *tile_non_allied_city(const struct tile *ptile, + const struct player *pplayer); + +/**********************************************************************//** + Is there a non-allied city on the tile? +**************************************************************************/ +static inline bool is_non_allied_city_tile(const struct tile *ptile, + const struct player *pplayer) +{ + 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, @@ -694,7 +733,7 @@ bool is_friendly_city_near(const struct player *owner, bool city_exists_within_max_city_map(const struct tile *ptile, bool may_be_on_center); -/* granary size as a function of city size */ +/* Granary size as a function of city size */ int city_granary_size(int city_size); void city_add_improvement(struct city *pcity, diff --git a/common/unit.c b/common/unit.c index a299eec71c..f7ce4f8add 100644 --- a/common/unit.c +++ b/common/unit.c @@ -1449,7 +1449,7 @@ bool is_my_zoc(const struct player *pplayer, const struct tile *ptile0) continue; } - pcity = is_non_allied_city_tile(ptile, pplayer); + pcity = tile_non_allied_city(ptile, pplayer); if (pcity != NULL) { if ((srv && unit_list_size(ptile->units) > 0) || (!srv && (pcity->client.occupied diff --git a/server/unithand.c b/server/unithand.c index 03a4da3aed..a4edccaec9 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -801,7 +801,7 @@ static struct player *need_war_player_hlp(const struct unit *actor, struct city *tcity; - if ((tcity = is_non_attack_city_tile(target_tile, actor_player))) { + if ((tcity = tile_non_attack_city(target_tile, actor_player))) { return city_owner(tcity); } } diff --git a/server/unittools.c b/server/unittools.c index 6ba96ef7fc..2a65095cb1 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1459,7 +1459,7 @@ static bool is_refuel_tile(const struct tile *ptile, { const struct unit_class *pclass; - if (NULL != is_allied_city_tile(ptile, pplayer)) { + if (is_allied_city_tile(ptile, pplayer)) { return TRUE; } -- 2.39.0