Author: sveinung
Date: Tue Jan 19 13:23:29 2016
New Revision: 31488

URL: http://svn.gna.org/viewcvs/freeciv?rev=31488&view=rev
Log:
Remove non do action unit_do_action use.

Asking to be reminded to ask what actions the unit can do to a tile doesn't
change the game world. Stop sending it in the unit_do_action packet.

Asking about actions is done by the client. A unit's action decision state
therefore belongs to it even if it is stored at the server side too. The
same is true for a unit's battle group number. It is also handled client
side.

Client owned unit state is stored in the server so it can be sent to
reconnecting clients, stored in save games and, in cases like action
decision state, written to by the server.

Expand the unit_battlegroup packet to also cover action decision state. It
is therefore used to set more than one kind of unit server side client
owned state. Rename it to unit_sscs_set.

See patch #6819

Modified:
    trunk/client/control.c
    trunk/common/actions.h
    trunk/common/packets.def
    trunk/common/unit.h
    trunk/fc_version
    trunk/server/unithand.c

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=31488&r1=31487&r2=31488&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Tue Jan 19 13:23:29 2016
@@ -2953,8 +2953,8 @@
         && (ptile = unit_tile(punit))) {
       /* Have the server record that an action decision is wanted for this
        * unit. */
-      request_do_action(ACTION_COUNT, punit->id, tile_index(ptile),
-                        ACTSIG_QUEUE, "");
+      dsend_packet_unit_sscs_set(&client.conn, punit->id,
+                                 USSDT_QUEUE, tile_index(ptile));
     }
   } unit_list_iterate_end;
 }
@@ -3279,8 +3279,9 @@
       unit_list_iterate_safe(battlegroups[battlegroup], punit) {
        if (!unit_is_in_focus(punit)) {
          punit->battlegroup = BATTLEGROUP_NONE;
-         dsend_packet_unit_battlegroup(&client.conn,
-                                       punit->id, BATTLEGROUP_NONE);
+          dsend_packet_unit_sscs_set(&client.conn, punit->id,
+                                     USSDT_BATTLE_GROUP,
+                                     BATTLEGROUP_NONE);
          refresh_unit_mapcanvas(punit, unit_tile(punit), TRUE, FALSE);
          unit_list_remove(battlegroups[battlegroup], punit);
        }
@@ -3293,8 +3294,9 @@
          unit_list_remove(battlegroups[punit->battlegroup], punit);
        }
        punit->battlegroup = battlegroup;
-       dsend_packet_unit_battlegroup(&client.conn,
-                                     punit->id, battlegroup);
+        dsend_packet_unit_sscs_set(&client.conn, punit->id,
+                                   USSDT_BATTLE_GROUP,
+                                   battlegroup);
        unit_list_append(battlegroups[battlegroup], punit);
        refresh_unit_mapcanvas(punit, unit_tile(punit), TRUE, FALSE);
       }

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=31488&r1=31487&r2=31488&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Tue Jan 19 13:23:29 2016
@@ -106,13 +106,6 @@
 /* Used in searches to signal that any action at all is OK. */
 #define ACTION_ANY ACTION_COUNT
 
-/* Used in the network protocol */
-#define SPECENUM_NAME action_proto_signal
-/* The player wants to be reminded to ask what actions the unit can perform
- * to a certain target tile. */
-#define SPECENUM_VALUE0 ACTSIG_QUEUE
-#include "specenum_gen.h"
-
 /*
  * Action probability
  *

Modified: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=31488&r1=31487&r2=31488&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Tue Jan 19 13:23:29 2016
@@ -246,6 +246,7 @@
 type GEN_ACTION         = uint8(enum gen_action)
 type ACTION_AUTO_CAUSE  = uint8(enum action_auto_perf_cause)
 type ACTION_DECISION    = uint8(enum action_decision)
+type UNIT_DATA_TYPE     = uint8(enum unit_ss_data_type)
 type REVOLENTYPE        = uint8(enum revolen_type)
 type HAPPYBORDERSTYPE   = uint8(enum happyborders_type)
 type TECH_COST_STYLE    = uint8(enum tech_cost_style)
@@ -975,9 +976,10 @@
   BOOL make_winner_veteran;
 end
 
-PACKET_UNIT_BATTLEGROUP = 71; cs, dsend
+PACKET_UNIT_SSCS_SET = 71; cs, dsend
   UNIT unit_id;
-  SINT8 battlegroup;
+  UNIT_DATA_TYPE type;
+  SINT32 value;
 end
 
 # used for client orders: currently client-side goto and patrol

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=31488&r1=31487&r2=31488&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Tue Jan 19 13:23:29 2016
@@ -94,6 +94,16 @@
    * ORDER_PERFORM_ACTION. */
   enum direction8 dir;
 };
+
+/* Used in the network protocol */
+#define SPECENUM_NAME unit_ss_data_type
+/* The player wants to be reminded to ask what actions the unit can perform
+ * to a certain target tile. */
+#define SPECENUM_VALUE0 USSDT_QUEUE
+/* The player wants to record that the unit now belongs to the specified
+ * battle group. */
+#define SPECENUM_VALUE1 USSDT_BATTLE_GROUP
+#include "specenum_gen.h"
 
 struct unit;
 struct unit_list;

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=31488&r1=31487&r2=31488&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Tue Jan 19 13:23:29 2016
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jan.16"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jan.19"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=31488&r1=31487&r2=31488&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Tue Jan 19 13:23:29 2016
@@ -1433,11 +1433,7 @@
 /**************************************************************************
   Handle a request to do an action.
 
-  action_type can be a valid action or a ACTION_COUNT. ACTION_COUNT signals
-  that a special value used for in band signaling can be found in value.
-  The in band signaling values are:
-    ACTSIG_QUEUE - remind the player to ask what actions the unit can do
-                   to the target tile.
+  action_type must be a valid action.
 **************************************************************************/
 void handle_unit_do_action(struct player *pplayer,
                           const int actor_id,
@@ -1446,28 +1442,8 @@
                            const char *name,
                            const enum gen_action action_type)
 {
-  struct unit *actor_unit = player_unit_by_number(pplayer, actor_id);
-  struct tile *target_tile = index_to_tile(target_id);
-
-  switch (action_type) {
-  case ACTION_COUNT:
-    switch ((enum action_proto_signal)value) {
-    case ACTSIG_QUEUE:
-      actor_unit->action_decision_want = ACT_DEC_ACTIVE;
-      actor_unit->action_decision_tile = target_tile;
-
-      /* Let the client know that this unit needs the player to decide
-       * what to do. */
-      send_unit_info(player_reply_dest(pplayer), actor_unit);
-
-      break;
-    }
-    break;
-  default:
-    (void) unit_perform_action(pplayer, actor_id, target_id, value, name,
-                               action_type, ACT_REQ_PLAYER);
-    break;
-  }
+  (void) unit_perform_action(pplayer, actor_id, target_id, value, name,
+                             action_type, ACT_REQ_PLAYER);
 }
 
 /**************************************************************************
@@ -3612,23 +3588,56 @@
 }
 
 /**************************************************************************
-  Assign the unit to the battlegroup.
-
-  Battlegroups are handled entirely by the client, so all we have to
-  do here is save the battlegroup ID so that it'll be persistent.
-**************************************************************************/
-void handle_unit_battlegroup(struct player *pplayer,
-                            int unit_id, int battlegroup)
+  Change various unit server side client state.
+
+  The server keeps various unit state that is owned by the client. The only
+  consequence this state has for the game is how the client reacts to it.
+  The state may be server side because the server writes to it or simply to
+  have it end up in the save game.
+**************************************************************************/
+void handle_unit_sscs_set(struct player *pplayer,
+                          int unit_id,
+                          enum unit_ss_data_type type,
+                          int value)
 {
   struct unit *punit = player_unit_by_number(pplayer, unit_id);
 
   if (NULL == punit) {
     /* Probably died or bribed. */
-    log_verbose("handle_unit_battlegroup() invalid unit %d", unit_id);
+    log_verbose("handle_unit_sscs_set() invalid unit %d", unit_id);
     return;
   }
 
-  punit->battlegroup = CLIP(-1, battlegroup, MAX_NUM_BATTLEGROUPS);
+  switch (type) {
+  case USSDT_QUEUE:
+    /* Reminds the client to ask the server about what actions the unit can
+     * perform against the target tile. Action decision state can be set by
+     * the server it self too. */
+
+    if (index_to_tile(value) == NULL) {
+      /* Asked to be reminded to ask what actions the unit can do to a non
+       * existing target tile. */
+      log_verbose("unit_sscs_set() invalid target tile %d for unit %d",
+                  value, unit_id);
+      break;
+    }
+
+    punit->action_decision_want = ACT_DEC_ACTIVE;
+    punit->action_decision_tile = index_to_tile(value);
+
+    /* Let the client know that this unit needs the player to decide
+     * what to do. */
+    send_unit_info(player_reply_dest(pplayer), punit);
+
+    break;
+  case USSDT_BATTLE_GROUP:
+    /* Battlegroups are handled entirely by the client, so all we have to
+       do here is save the battlegroup ID so that it'll be persistent. */
+
+    punit->battlegroup = CLIP(-1, value, MAX_NUM_BATTLEGROUPS);
+
+    break;
+  }
 }
 
 /**************************************************************************


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

Reply via email to