Author: sveinung
Date: Fri Aug 12 20:38:55 2016
New Revision: 33584

URL: http://svn.gna.org/viewcvs/freeciv?rev=33584&view=rev
Log:
Deduplicate action_mp_full_makes_legal().

Replace two functions that checks if a currently illegal action would be
legal if the actor unit had all its movement points with a common function
in actions.c.

See patch #7586

Modified:
    branches/S2_6/common/actions.c
    branches/S2_6/common/actions.h
    branches/S2_6/server/unithand.c
    branches/S2_6/server/unittools.c

Modified: branches/S2_6/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/actions.c?rev=33584&r1=33583&r2=33584&view=diff
==============================================================================
--- branches/S2_6/common/actions.c      (original)
+++ branches/S2_6/common/actions.c      Fri Aug 12 20:38:55 2016
@@ -23,6 +23,7 @@
 #include "city.h"
 #include "game.h"
 #include "map.h"
+#include "movement.h"
 #include "unit.h"
 #include "research.h"
 #include "tile.h"
@@ -1515,3 +1516,21 @@
                             city_tile(target_city), NULL, NULL,
                             NULL, NULL);
 }
+
+/**************************************************************************
+  Returns TRUE if the specified action can't be done now but would have
+  been legal if the unit had full movement.
+**************************************************************************/
+bool action_mp_full_makes_legal(const struct unit *actor,
+                                const int action_id)
+{
+  fc_assert(action_id_is_valid(action_id) || action_id == ACTION_ANY);
+
+  /* Check if full movement points may enable the specified action. */
+  return !utype_may_act_move_frags(unit_type_get(actor),
+                                   action_id,
+                                   actor->moves_left)
+      && utype_may_act_move_frags(unit_type_get(actor),
+                                  action_id,
+                                  unit_move_rate(actor));
+}

Modified: branches/S2_6/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/actions.h?rev=33584&r1=33583&r2=33584&view=diff
==============================================================================
--- branches/S2_6/common/actions.h      (original)
+++ branches/S2_6/common/actions.h      Fri Aug 12 20:38:55 2016
@@ -214,6 +214,9 @@
                                 const struct player *actor_player,
                                 const struct city* target_city);
 
+bool action_mp_full_makes_legal(const struct unit *actor,
+                                const int action_id);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=33584&r1=33583&r2=33584&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Fri Aug 12 20:38:55 2016
@@ -579,23 +579,6 @@
                                target_tile, target_city,
                                target_unit);
   }
-}
-
-/**************************************************************************
-  Returns TRUE if the specified action can't be done now but would have
-  been legal if the unit had full movement.
-**************************************************************************/
-static bool need_full_mp(const struct unit *actor, const int action_id)
-{
-  fc_assert(action_id_is_valid(action_id) || action_id == ACTION_ANY);
-
-  /* Check if full movement points may enable the specified action. */
-  return !utype_may_act_move_frags(unit_type_get(actor),
-                                   action_id,
-                                   actor->moves_left)
-      && utype_may_act_move_frags(unit_type_get(actor),
-                                  action_id,
-                                  unit_move_rate(actor));
 }
 
 /**************************************************************************
@@ -689,7 +672,7 @@
                                                 target_unit))) {
     explnat->kind = ANEK_NO_WAR;
     explnat->no_war_with = must_war_player;
-  } else if (need_full_mp(punit, action_id)) {
+  } else if (action_mp_full_makes_legal(punit, action_id)) {
     explnat->kind = ANEK_LOW_MP;
   } else {
     explnat->kind = ANEK_UNKNOWN;

Modified: branches/S2_6/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=33584&r1=33583&r2=33584&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c    (original)
+++ branches/S2_6/server/unittools.c    Fri Aug 12 20:38:55 2016
@@ -3859,20 +3859,6 @@
 }
 
 /**************************************************************************
-  Returns TRUE iff punit currently don't have enough move fragments to
-  perform the specified action but will have it next turn.
-**************************************************************************/
-static bool should_wait_for_mp(struct unit *punit, int action_id)
-{
-  return !utype_may_act_move_frags(unit_type_get(punit),
-                                   action_id,
-                                   punit->moves_left)
-      && utype_may_act_move_frags(unit_type_get(punit),
-                                  action_id,
-                                  unit_move_rate(punit));
-}
-
-/**************************************************************************
   Returns the action id corresponding to the specified order id.
 **************************************************************************/
 static int order_to_action(struct unit *punit, enum unit_orders order)
@@ -3994,7 +3980,7 @@
       break;
     case ORDER_BUILD_WONDER:
     case ORDER_TRADE_ROUTE:
-      if (should_wait_for_mp(punit, order_to_action(punit, order.order))) {
+      if (action_mp_full_makes_legal(punit, order_to_action(punit, 
order.order))) {
         log_debug("  stopping. Not enough move points this turn");
         return TRUE;
       }


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

Reply via email to