Author: sveinung
Date: Fri May 22 12:40:48 2015
New Revision: 29120

URL: http://svn.gna.org/viewcvs/freeciv?rev=29120&view=rev
Log:
Explain when too few MPs left

Identify situations were an action can't be done because the action unit
don't have enough movement points left in the code that tries to explain why
an action can't be done.

Thanks to Jordi Negrevernis i Font <jorneg> for spotting a typo.

See patch #6096

Modified:
    trunk/server/unithand.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29120&r1=29119&r2=29120&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Fri May 22 12:40:48 2015
@@ -82,6 +82,8 @@
   ANEK_IS_NOT_TRANSPORTED,
   /* Explanation: must declare war first. */
   ANEK_NO_WAR,
+  /* Explanation: not enough MP left. */
+  ANEK_LOW_MP,
   /* Explanation not detected. */
   ANEK_UNKNOWN,
 };
@@ -616,6 +618,34 @@
     return need_war_player_hlp(actor, action_id,
                                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)
+{
+  if (action_id == ACTION_ANY) {
+    /* Any action at all will do. */
+    action_iterate(act) {
+      if (need_full_mp(actor, action_id)) {
+        /* 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));
   }
 }
 
@@ -656,6 +686,8 @@
                                                 target_unit))) {
     expl->kind = ANEK_NO_WAR;
     expl->no_war_with = must_war_player;
+  } else if (need_full_mp(punit, action_id)) {
+    expl->kind = ANEK_LOW_MP;
   } else {
     expl->kind = ANEK_UNKNOWN;
   }
@@ -698,6 +730,10 @@
                   _("You must declare war on %s first.  Try using "
                     "the Nations report (F3)."),
                   player_name(expl->no_war_with));
+    break;
+  case ANEK_LOW_MP:
+    notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
+                  _("This unit has too few moves left to act."));
     break;
   case ANEK_UNKNOWN:
     notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
@@ -907,6 +943,13 @@
                   unit_name_translation(actor),
                   gen_action_translated_name(stopped_action),
                   player_name(expl->no_war_with));
+    break;
+  case ANEK_LOW_MP:
+    notify_player(pplayer, unit_tile(actor),
+                  event, ftc_server,
+                  _("Your %s has too few moves left to %s."),
+                  unit_name_translation(actor),
+                  gen_action_translated_name(stopped_action));
     break;
   case ANEK_UNKNOWN:
     notify_player(pplayer, unit_tile(actor),


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

Reply via email to