Author: sveinung
Date: Wed Aug 19 16:55:29 2015
New Revision: 29588

URL: http://svn.gna.org/viewcvs/freeciv?rev=29588&view=rev
Log:
Handle ACTION_ANY in move frags may act code

Handle the special value ACTION_ANY, meaning any action, in
utype_may_act_move_frags(). This is the code responsible for figuring out if
a unit will be able to perform an action if it has a certain amount of move
fragments left. Stop handling it in its users.

See patch #6253

Modified:
    branches/S2_6/common/unittype.c
    branches/S2_6/server/unithand.c

Modified: branches/S2_6/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unittype.c?rev=29588&r1=29587&r2=29588&view=diff
==============================================================================
--- branches/S2_6/common/unittype.c     (original)
+++ branches/S2_6/common/unittype.c     Wed Aug 19 16:55:29 2015
@@ -611,6 +611,27 @@
                               const int move_fragments)
 {
   struct range *ml_range;
+
+  fc_assert(action_id_is_valid(action_id) || action_id == ACTION_ANY);
+
+  if (!is_actor_unit_type(punit_type)) {
+    /* Not an actor unit. */
+    return FALSE;
+  }
+
+  if (action_id == ACTION_ANY) {
+    /* Any action is OK. */
+    action_iterate(alt_act) {
+      if (utype_may_act_move_frags(punit_type, alt_act,
+                                   move_fragments)) {
+        /* It only has to be true for one action. */
+        return TRUE;
+      }
+    } action_iterate_end;
+
+    /* No action enabled. */
+    return FALSE;
+  }
 
   if (action_get_actor_kind(action_id) != AAK_UNIT) {
     /* This action isn't performed by any unit at all so this unit type

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=29588&r1=29587&r2=29588&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Wed Aug 19 16:55:29 2015
@@ -579,26 +579,15 @@
 **************************************************************************/
 static bool need_full_mp(const struct unit *actor, const int action_id)
 {
-  if (action_id == ACTION_ANY) {
-    /* Any action at all will do. */
-    action_iterate(act) {
-      if (need_full_mp(actor, act)) {
-        /* Full movement points may enable this action. */
-        return TRUE;
-      }
-    } action_iterate_end;
-
-    /* No action at all may be enabled by full MP. */
-    return FALSE;
-  } else {
-    /* Check if full movement points may enable the specified action. */
-    return !utype_may_act_move_frags(unit_type(actor),
-                                     action_id,
-                                     actor->moves_left)
-        && utype_may_act_move_frags(unit_type(actor),
-                                    action_id,
-                                    unit_move_rate(actor));
-  }
+  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(actor),
+                                   action_id,
+                                   actor->moves_left)
+      && utype_may_act_move_frags(unit_type(actor),
+                                  action_id,
+                                  unit_move_rate(actor));
 }
 
 /**************************************************************************


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

Reply via email to