Author: sveinung
Date: Fri May 22 12:40:28 2015
New Revision: 29119

URL: http://svn.gna.org/viewcvs/freeciv?rev=29119&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:
    branches/S2_6/server/unithand.c

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=29119&r1=29118&r2=29119&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Fri May 22 12:40:28 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,
 };
@@ -527,6 +529,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));
   }
 }
 
@@ -567,6 +597,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;
   }
@@ -609,6 +641,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,
@@ -822,6 +858,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),
+                  E_UNIT_ILLEGAL_ACTION, 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