Author: cazfi
Date: Wed May 10 17:38:55 2017
New Revision: 35493

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

See hrm Feature #658612

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

Modified: branches/S3_0/ai/default/aitools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/ai/default/aitools.c?rev=35493&r1=35492&r2=35493&view=diff
==============================================================================
--- branches/S3_0/ai/default/aitools.c  (original)
+++ branches/S3_0/ai/default/aitools.c  Wed May 10 17:38:55 2017
@@ -916,6 +916,7 @@
   int sanity = punit->id;
   struct player *pplayer = unit_owner(punit);
   const bool is_plr_ai = is_ai(pplayer);
+  int mcost;
 
   CHECK_UNIT(punit);
   fc_assert_ret_val_msg(is_tiles_adjacent(unit_tile(punit), ptile), FALSE,
@@ -948,8 +949,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/S3_0/server/advisors/advgoto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/advisors/advgoto.c?rev=35493&r1=35492&r2=35493&view=diff
==============================================================================
--- branches/S3_0/server/advisors/advgoto.c     (original)
+++ branches/S3_0/server/advisors/advgoto.c     Wed May 10 17:38:55 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