Author: sveinung
Date: Thu Aug  6 19:36:36 2015
New Revision: 29362

URL: http://svn.gna.org/viewcvs/freeciv?rev=29362&view=rev
Log:
orders system: stop assuming that perform action is the last order

See patch #6178

Modified:
    trunk/server/unittools.c

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=29362&r1=29361&r2=29362&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Thu Aug  6 19:36:36 2015
@@ -3791,6 +3791,7 @@
 {
   struct tile *dst_tile;
   action_probability prob;
+  bool performed;
   bool res, last_order;
   int unitid = punit->id;
   struct player *pplayer = unit_owner(punit);
@@ -4151,10 +4152,18 @@
       case ATK_CITY:
       case ATK_UNIT:
         log_error("Unsupported action target kind");
-        return TRUE;
+
+        /* Makes the check below abort and cancel the orders */
+        prob = 0;
+
+        break;
       case ATK_COUNT:
         log_error("Invalid action target kind");
-        return TRUE;
+
+        /* Makes the check below abort and cancel the orders */
+        prob = 0;
+
+        break;
       }
 
       if (!action_prob_possible(prob)) {
@@ -4172,12 +4181,31 @@
         return TRUE;
       }
 
-      handle_unit_do_action(pplayer,
-                            unitid,
-                            dst_tile->index,
-                            0, "", order.action);
-
-      return player_unit_by_number(pplayer, unitid);
+      performed = unit_perform_action(pplayer,
+                                      unitid,
+                                      dst_tile->index,
+                                      0, "", order.action);
+
+      if (!player_unit_by_number(pplayer, unitid)) {
+        /* The unit "died" while performing the action. */
+        return FALSE;
+      }
+
+      if (!performed) {
+        /* The action wasn't performed as ordered. */
+
+        cancel_orders(punit, "  failed action");
+        notify_player(pplayer, unit_tile(punit), E_UNIT_ORDERS, ftc_server,
+                      _("Orders for %s aborted because "
+                        "doing %s to %s failed."),
+                      unit_link(punit),
+                      action_get_ui_name(order.action),
+                      tile_link(dst_tile));
+
+        return TRUE;
+      }
+
+      break;
     case ORDER_LAST:
       cancel_orders(punit, "  client sent invalid order!");
       notify_player(pplayer, unit_tile(punit), E_UNIT_ORDERS, ftc_server,


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

Reply via email to