From 65f6fd37e46e23f18213be05747f770d919749d2 Mon Sep 17 00:00:00 2001 From: cazfi Date: Wed, 10 May 2017 15:39:01 +0000 Subject: [PATCH] Avoid double map_move_cost_unit() See hrm Feature #658612 git-svn-id: svn://svn.gna.org/svn/freeciv/branches/S2_6@35494 a0f10bec-cc02-0410-94fc-a9cfff90b4cd --- ai/default/aitools.c | 6 ++++-- server/advisors/advgoto.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ai/default/aitools.c b/ai/default/aitools.c index d6ea8950a9..502ae23410 100644 --- a/ai/default/aitools.c +++ b/ai/default/aitools.c @@ -880,6 +880,7 @@ bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile) int sanity = punit->id; struct player *pplayer = unit_owner(punit); const bool is_ai = pplayer->ai_controlled; + int mcost; CHECK_UNIT(punit); fc_assert_ret_val_msg(is_tiles_adjacent(unit_tile(punit), ptile), FALSE, @@ -912,8 +913,9 @@ bool dai_unit_move(struct ai_type *ait, struct unit *punit, struct tile *ptile) } /* Try not to end move next to an enemy if we can avoid it by waiting */ - if (punit->moves_left <= map_move_cost_unit(punit, ptile) - && unit_move_rate(punit) > map_move_cost_unit(punit, ptile) + mcost = map_move_cost_unit(punit, ptile); + if (punit->moves_left <= mcost + && unit_move_rate(punit) > mcost && adv_danger_at(punit, ptile) && !adv_danger_at(punit, unit_tile(punit))) { UNIT_LOG(LOG_DEBUG, punit, "ending move early to stay out of trouble"); diff --git a/server/advisors/advgoto.c b/server/advisors/advgoto.c index dbe9e1beaa..3f20141af8 100644 --- a/server/advisors/advgoto.c +++ b/server/advisors/advgoto.c @@ -129,6 +129,7 @@ bool adv_unit_execute_path(struct unit *punit, struct pf_path *path) static bool adv_unit_move(struct unit *punit, struct tile *ptile) { struct player *pplayer = unit_owner(punit); + int mcost; /* if enemy, stop and give a chance for the human player to handle this case */ @@ -139,8 +140,9 @@ static bool adv_unit_move(struct unit *punit, struct tile *ptile) } /* Try not to end move next to an enemy if we can avoid it by waiting */ - if (punit->moves_left <= map_move_cost_unit(punit, ptile) - && unit_move_rate(punit) > map_move_cost_unit(punit, ptile) + mcost = map_move_cost_unit(punit, ptile); + if (punit->moves_left <= mcost + && unit_move_rate(punit) > mcost && adv_danger_at(punit, ptile) && !adv_danger_at(punit, unit_tile(punit))) { UNIT_LOG(LOG_DEBUG, punit, "ending move early to stay out of trouble"); -- 2.11.4.GIT