Author: sveinung
Date: Fri Aug 12 20:33:55 2016
New Revision: 33578

URL: http://svn.gna.org/viewcvs/freeciv?rev=33578&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:
    trunk/common/actions.c
    trunk/common/actions.h
    trunk/server/unithand.c
    trunk/server/unittools.c

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=33578&r1=33577&r2=33578&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Fri Aug 12 20:33:55 2016
@@ -3000,6 +3000,24 @@
 }
 
 /**************************************************************************
+  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));
+}
+
+/**************************************************************************
   Returns action auto performer rule slot number num so it can be filled.
 **************************************************************************/
 struct action_auto_perf *action_auto_perf_slot_number(const int num)

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=33578&r1=33577&r2=33578&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Fri Aug 12 20:33:55 2016
@@ -417,6 +417,9 @@
 bool action_maybe_possible_actor_unit(const int wanted_action,
                                       const struct unit* actor_unit);
 
+bool action_mp_full_makes_legal(const struct unit *actor,
+                                const int action_id);
+
 /* Action auto performers */
 const struct action_auto_perf *action_auto_perf_by_number(const int num);
 struct action_auto_perf *action_auto_perf_slot_number(const int num);

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=33578&r1=33577&r2=33578&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Fri Aug 12 20:33:55 2016
@@ -685,23 +685,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));
 }
 
 /**************************************************************************
@@ -906,7 +889,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 if (tgt_player
              && unit_owner(punit) != tgt_player

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=33578&r1=33577&r2=33578&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Fri Aug 12 20:33:55 2016
@@ -3900,20 +3900,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 TRUE iff it is reasonable to assume that the player is wathing
   the unit.
 
@@ -4013,7 +3999,7 @@
       }
       break;
     case ORDER_PERFORM_ACTION:
-      if (should_wait_for_mp(punit, order.action)) {
+      if (action_mp_full_makes_legal(punit, order.action)) {
         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