From 4adf24e82a47547d597f34de5289798db09bf3de Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 21 Nov 2022 04:59:20 +0200 Subject: [PATCH 19/19] Make UTYF_COAST units to save themselves to coast Reported by Lexxie See osdn #45948 Signed-off-by: Marko Lindqvist --- ai/default/aiair.c | 8 +++---- server/unittools.c | 59 +++++++++++++++++++++++++--------------------- server/unittools.h | 14 +++++------ 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/ai/default/aiair.c b/ai/default/aiair.c index 8fdd0f046c..36c657ab3f 100644 --- a/ai/default/aiair.c +++ b/ai/default/aiair.c @@ -104,7 +104,7 @@ static struct tile *find_nearest_airbase(struct unit *punit, break; } - if (is_airunit_refuel_point(ptile, pplayer, punit)) { + if (is_refuel_point(ptile, pplayer, punit)) { if (lost_hp > 0) { int regt = regen_turns(punit, ptile, lost_hp); @@ -379,7 +379,7 @@ static struct tile *dai_find_strategic_airbase(struct ai_type *ait, break; /* Too far! */ } - if (!is_airunit_refuel_point(ptile, pplayer, punit)) { + if (!is_refuel_point(ptile, pplayer, punit)) { continue; /* Cannot refuel here. */ } @@ -496,7 +496,7 @@ void dai_manage_airunit(struct ai_type *ait, struct player *pplayer, /* We are on a GOTO. Check if it will get us anywhere */ && NULL != punit->goto_tile && !same_pos(unit_tile(punit), punit->goto_tile) - && is_airunit_refuel_point(punit->goto_tile, pplayer, punit)) { + && is_refuel_point(punit->goto_tile, pplayer, punit)) { pfm = pf_map_new(¶meter); path = pf_map_path(pfm, punit->goto_tile); if (path) { @@ -520,7 +520,7 @@ void dai_manage_airunit(struct ai_type *ait, struct player *pplayer, pf_path_destroy(path); } else { if (punit->fuel == 1) { - UNIT_LOG(LOG_DEBUG, punit, "Oops, fallin outta the sky"); + UNIT_LOG(LOG_DEBUG, punit, "Oops, fallin outta the sky"); } def_ai_unit_data(punit, ait)->done = TRUE; /* Won't help trying again */ return; diff --git a/server/unittools.c b/server/unittools.c index a670e65578..5ba25e2ca4 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -528,7 +528,7 @@ void player_restore_units(struct player *pplayer) break; } - if (is_airunit_refuel_point(ptile, pplayer, punit)) { + if (is_refuel_point(ptile, pplayer, punit)) { struct pf_path *path; int id = punit->id; @@ -1495,37 +1495,19 @@ void give_allied_visibility(struct player *pplayer, } /**********************************************************************//** - Is unit being refueled in its current position -**************************************************************************/ -bool is_unit_being_refueled(const struct unit *punit) -{ - if (unit_transported(punit) /* Carrier */ - || tile_city(unit_tile(punit)) /* City */ - || tile_has_refuel_extra(unit_tile(punit), - unit_type_get(punit))) { /* Airbase */ - return TRUE; - } - if (unit_has_type_flag(punit, UTYF_COAST)) { - return is_safe_ocean(&(wld.map), unit_tile(punit)); - } - - return FALSE; -} - -/**********************************************************************//** - Can unit refuel on tile. Considers also carrier capacity on tile. + Will unit refuel at this tile? Does not consider carriers. **************************************************************************/ -bool is_airunit_refuel_point(const struct tile *ptile, - const struct player *pplayer, - const struct unit *punit) +static bool is_refuel_tile(const struct tile *ptile, + const struct player *pplayer, + const struct unit *punit) { const struct unit_class *pclass; - if (NULL != is_non_allied_unit_tile(ptile, pplayer)) { - return FALSE; + if (NULL != is_allied_city_tile(ptile, pplayer)) { + return TRUE; } - if (NULL != is_allied_city_tile(ptile, pplayer)) { + if (unit_has_type_flag(punit, UTYF_COAST) && is_safe_ocean(&(wld.map), ptile)) { return TRUE; } @@ -1540,7 +1522,30 @@ bool is_airunit_refuel_point(const struct tile *ptile, } extra_type_list_iterate_end; } - return unit_could_load_at(punit, ptile); + return FALSE; +} + +/**********************************************************************//** + Is unit being refueled in its current position +**************************************************************************/ +bool is_unit_being_refueled(const struct unit *punit) +{ + return unit_transported(punit) /* Carrier */ + || is_refuel_tile(unit_tile(punit), unit_owner(punit), punit); +} + +/**********************************************************************//** + Can unit refuel on tile. Considers also carrier capacity on tile. +**************************************************************************/ +bool is_refuel_point(const struct tile *ptile, + const struct player *pplayer, + const struct unit *punit) +{ + if (NULL != is_non_allied_unit_tile(ptile, pplayer)) { + return FALSE; + } + + return is_refuel_tile(ptile, pplayer, punit) || unit_could_load_at(punit, ptile); } /**********************************************************************//** diff --git a/server/unittools.h b/server/unittools.h index 038f5f89da..47c59908d6 100644 --- a/server/unittools.h +++ b/server/unittools.h @@ -13,9 +13,9 @@ #ifndef FC__UNITTOOLS_H #define FC__UNITTOOLS_H +/* common */ #include "fc_types.h" - -#include "packets.h" /* enum unit_info_use */ +#include "packets.h" /* enum unit_info_use */ #include "unitlist.h" #define SPECENUM_NAME unit_loss_reason @@ -88,13 +88,13 @@ void unit_bombs_unit(struct unit *attacker, struct unit *defender, void combat_veterans(struct unit *attacker, struct unit *defender, bool powerless, int att_vet, int def_vet); -/* move check related */ +/* Move check related */ bool is_unit_being_refueled(const struct unit *punit); -bool is_airunit_refuel_point(const struct tile *ptile, - const struct player *pplayer, - const struct unit *punit); +bool is_refuel_point(const struct tile *ptile, + const struct player *pplayer, + const struct unit *punit); -/* turn update related */ +/* Turn update related */ void player_restore_units(struct player *pplayer); void update_unit_activities(struct player *pplayer); void random_movements(struct player *pplayer); -- 2.35.1