Author: sveinung
Date: Tue Mar  3 13:06:38 2015
New Revision: 28379

URL: http://svn.gna.org/viewcvs/freeciv?rev=28379&view=rev
Log:
Have the orders system support server side target extra finding for pillage.

Pillage support was added to the orders system in patch #5861. When set to
FALSE the ruleset option pillage_select forbids the player to select what
target extra to pillage. Supporting pillage in the orders system without
server side target selection is therefore useless for clients that are
trying to support all rulesets.

See bug #23339

Modified:
    branches/S2_6/server/unithand.c
    branches/S2_6/server/unittools.c
    branches/S2_6/server/unittools.h

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=28379&r1=28378&r2=28379&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Tue Mar  3 13:06:38 2015
@@ -2927,9 +2927,10 @@
         return;
       }
 
-      if (activity_requires_target(packet->activity[i])
-          && packet->target[i] == EXTRA_NONE) {
-        /* The orders system can't do server side target assignment. */
+      if (packet->target[i] == EXTRA_NONE
+          && unit_activity_needs_target_from_client(packet->activity[i])) {
+        /* The orders system can't do server side target assignment for
+         * this activity. */
         return;
       }
 

Modified: branches/S2_6/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=28379&r1=28378&r2=28379&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c    (original)
+++ branches/S2_6/server/unittools.c    Tue Mar  3 13:06:38 2015
@@ -978,10 +978,28 @@
 }
 
 /**************************************************************************
+  Return TRUE iff activity requires some sort of target to be specified by
+  the client.
+**************************************************************************/
+bool unit_activity_needs_target_from_client(enum unit_activity activity)
+{
+  switch (activity) {
+  case ACTIVITY_PILLAGE:
+    /* Can be set server side. */
+    return FALSE;
+  default:
+    return activity_requires_target(activity);
+  }
+}
+
+/**************************************************************************
   For some activities (currently only pillaging), the precise target can
   be assigned by the server rather than explicitly requested by the client.
   This function assigns a specific activity+target if the current
   settings are open-ended (otherwise leaves them unchanged).
+
+  Please update unit_activity_needs_target_from_client() if you add server
+  side unit activity target setting to more activities.
 **************************************************************************/
 void unit_assign_specific_activity_target(struct unit *punit,
                                           enum unit_activity *activity,
@@ -3819,6 +3837,45 @@
                                        NULL :
                                        extra_by_number(order.target));
 
+        if (pextra == NULL && activity_requires_target(order.activity)) {
+          /* Try to find a target extra before giving up this order or, if
+           * serious enough, all orders. */
+
+          enum unit_activity new_activity = order.activity;
+
+          unit_assign_specific_activity_target(punit,
+                                               &new_activity, &pextra);
+
+          if (new_activity != order.activity) {
+            /* At the time this code was written the only possible activity
+             * change from unit_assign_specific_activity_target() was from
+             * ACTIVITY_PILLAGE to ACTIVITY_IDLE. That would only happen
+             * when a target extra couldn't be found. -- Sveinung */
+            fc_assert_msg((order.activity == ACTIVITY_PILLAGE
+                           && new_activity == ACTIVITY_IDLE),
+                          "Skipping an order when canceling all orders may"
+                          " have been the correct thing to do.");
+
+            /* Already removed, let's continue. */
+            break;
+          }
+
+          /* Should have given up or, if supported, changed the order's
+           * activity to the activity suggested by
+           * unit_activity_handling_targeted() before this line was
+           * reached.
+           * Remember that unit_activity_handling_targeted() has the power
+           * to change the order's target extra directly. */
+          fc_assert_msg(new_activity == order.activity,
+                        "Activity not updated. Target may have changed.");
+
+          /* Should have found a target or given up before reaching this
+           * line. */
+          fc_assert_msg((pextra != NULL
+                         || !activity_requires_target(order.activity)),
+                        "Activity requires a target. No target found.");
+        }
+
         if (can_unit_do_activity_targeted(punit, activity, pextra)) {
           punit->done_moving = TRUE;
           set_unit_activity_targeted(punit, activity, pextra);

Modified: branches/S2_6/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.h?rev=28379&r1=28378&r2=28379&view=diff
==============================================================================
--- branches/S2_6/server/unittools.h    (original)
+++ branches/S2_6/server/unittools.h    Tue Mar  3 13:06:38 2015
@@ -109,6 +109,7 @@
 void unit_refresh_vision(struct unit *punit);
 void unit_list_refresh_vision(struct unit_list *punitlist);
 void bounce_unit(struct unit *punit, bool verbose);
+bool unit_activity_needs_target_from_client(enum unit_activity activity);
 void unit_assign_specific_activity_target(struct unit *punit,
                                           enum unit_activity *activity,
                                           struct extra_type **target);


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

Reply via email to