Author: cazfi
Date: Wed May 10 17:39:07 2017
New Revision: 35495

URL: http://svn.gna.org/viewcvs/freeciv?rev=35495&view=rev
Log:
Avoid double map_move_cost_unit()

See hrm Feature #658612

Modified:
    branches/S2_5/ai/default/aitools.c
    branches/S2_5/server/advisors/advgoto.c

Modified: branches/S2_5/ai/default/aitools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/ai/default/aitools.c?rev=35495&r1=35494&r2=35495&view=diff
==============================================================================
--- branches/S2_5/ai/default/aitools.c  (original)
+++ branches/S2_5/ai/default/aitools.c  Wed May 10 17:39:07 2017
@@ -951,6 +951,7 @@
   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,
@@ -983,8 +984,9 @@
   }
 
   /* 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");

Modified: branches/S2_5/server/advisors/advgoto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/advisors/advgoto.c?rev=35495&r1=35494&r2=35495&view=diff
==============================================================================
--- branches/S2_5/server/advisors/advgoto.c     (original)
+++ branches/S2_5/server/advisors/advgoto.c     Wed May 10 17:39:07 2017
@@ -129,6 +129,7 @@
 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 @@
   }
 
   /* 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");


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to