Author: sveinung
Date: Tue Mar 14 10:40:05 2017
New Revision: 35111

URL: http://svn.gna.org/viewcvs/freeciv?rev=35111&view=rev
Log:
Prepare action counting for generic actions.

Make it possible to distinguish the number of actions in the current
ruleset from the maximum number of actions. This will be needed when actions
becomes generic.

Introduce the distinction in action auto performers. Introduce the
distinction in action_iterate. Other areas should be clarified in follow up
patches.

See hrm Feature #644446

Modified:
    branches/S3_0/common/actions.c
    branches/S3_0/common/actions.h
    branches/S3_0/common/networking/packets.def
    branches/S3_0/server/ruleset.c
    branches/S3_0/tools/ruleutil/rulesave.c

Modified: branches/S3_0/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/common/actions.c?rev=35111&r1=35110&r2=35111&view=diff
==============================================================================
--- branches/S3_0/common/actions.c      (original)
+++ branches/S3_0/common/actions.c      Tue Mar 14 10:40:05 2017
@@ -512,7 +512,7 @@
     /* The criteria to pick *this* auto performer for its cause. */
     requirement_vector_init(&auto_perfs[i].reqs);
 
-    for (j = 0; j < ACTION_COUNT; j++) {
+    for (j = 0; j < MAX_NUM_ACTIONS; j++) {
       /* Nothing here. Nothing after this point. */
       auto_perfs[i].alternatives[j] = ACTION_NONE;
     }

Modified: branches/S3_0/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/common/actions.h?rev=35111&r1=35110&r2=35111&view=diff
==============================================================================
--- branches/S3_0/common/actions.h      (original)
+++ branches/S3_0/common/actions.h      Tue Mar 14 10:40:05 2017
@@ -123,6 +123,10 @@
 /* Used to signal the absence of any actions. */
 #define ACTION_NONE ACTION_COUNT
 
+/* Used in the network protocol. */
+#define MAX_NUM_ACTIONS ACTION_COUNT
+#define NUM_ACTIONS MAX_NUM_ACTIONS
+
 /* Who ordered the action to be performed? */
 #define SPECENUM_NAME action_requester
 /* The player ordered it directly. */
@@ -212,10 +216,10 @@
   TYPED_LIST_ITERATE(struct action_enabler, action_enabler_list, aenabler)
 #define action_enabler_list_iterate_end LIST_ITERATE_END
 
-#define action_iterate(_act_)                          \
-{                                                      \
-  int _act_;                                           \
-  for (_act_ = 0; _act_ < ACTION_COUNT; _act_++) {
+#define action_iterate(_act_)                                             \
+{                                                                         \
+  int _act_;                                                              \
+  for (_act_ = 0; _act_ < NUM_ACTIONS; _act_++) {
 
 #define action_iterate_end                             \
   }                                                    \
@@ -266,7 +270,7 @@
 
   /* Auto perform the first legal action in this list.
    * The list is terminated by ACTION_NONE. */
-  enum gen_action alternatives[ACTION_COUNT];
+  enum gen_action alternatives[MAX_NUM_ACTIONS];
 };
 
 #define action_auto_perf_iterate(_act_perf_)                              \
@@ -298,7 +302,7 @@
 {                                                                         \
   int _perf_pos_;                                                         \
                                                                           \
-  for (_perf_pos_ = 0; _perf_pos_ < ACTION_COUNT; _perf_pos_++) {         \
+  for (_perf_pos_ = 0; _perf_pos_ < NUM_ACTIONS; _perf_pos_++) {          \
     const int _act_id_ = _autoperf_->alternatives[_perf_pos_];            \
                                                                           \
     if (_act_id_ == ACTION_NONE) {                                        \

Modified: branches/S3_0/common/networking/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/common/networking/packets.def?rev=35111&r1=35110&r2=35111&view=diff
==============================================================================
--- branches/S3_0/common/networking/packets.def (original)
+++ branches/S3_0/common/networking/packets.def Tue Mar 14 10:40:05 2017
@@ -1758,7 +1758,7 @@
   REQUIREMENT       reqs[MAX_NUM_REQS:reqs_count];
 
   UINT8             alternatives_count;
-  GEN_ACTION        alternatives[ACTION_COUNT:alternatives_count];
+  GEN_ACTION        alternatives[MAX_NUM_ACTIONS:alternatives_count];
 end
 
 PACKET_RULESET_MUSIC = 240; sc, lsend

Modified: branches/S3_0/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/ruleset.c?rev=35111&r1=35110&r2=35111&view=diff
==============================================================================
--- branches/S3_0/server/ruleset.c      (original)
+++ branches/S3_0/server/ruleset.c      Tue Mar 14 10:40:05 2017
@@ -7508,7 +7508,7 @@
 
     for (counter = 0;
          /* Can't list more actions than all actions. */
-         counter < ACTION_COUNT
+         counter < NUM_ACTIONS
          /* ACTION_NONE terminates the list. */
          && aperf->alternatives[counter] != ACTION_NONE;
          counter++) {

Modified: branches/S3_0/tools/ruleutil/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S3_0/tools/ruleutil/rulesave.c?rev=35111&r1=35110&r2=35111&view=diff
==============================================================================
--- branches/S3_0/tools/ruleutil/rulesave.c     (original)
+++ branches/S3_0/tools/ruleutil/rulesave.c     Tue Mar 14 10:40:05 2017
@@ -562,7 +562,7 @@
                                          const int aap,
                                          const char *actions_path)
 {
-  enum gen_action unit_acts[ACTION_COUNT];
+  enum gen_action unit_acts[MAX_NUM_ACTIONS];
   size_t i;
   size_t ret;
 
@@ -571,7 +571,7 @@
 
   i = 0;
   for (i = 0;
-       i < ACTION_COUNT && auto_perf->alternatives[i] != ACTION_NONE;
+       i < NUM_ACTIONS && auto_perf->alternatives[i] != ACTION_NONE;
        i++) {
     unit_acts[i] = auto_perf->alternatives[i];
   }


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

Reply via email to