Author: sveinung
Date: Mon Oct 31 10:31:49 2016
New Revision: 34298

URL: http://svn.gna.org/viewcvs/freeciv?rev=34298&view=rev
Log:
Action auto performer action iterator macro.

See patch #7892

Modified:
    trunk/common/actions.h
    trunk/server/actiontools.c

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=34298&r1=34297&r2=34298&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Mon Oct 31 10:31:49 2016
@@ -294,6 +294,22 @@
 #define action_auto_perf_by_cause_iterate_end                             \
 } action_auto_perf_iterate_end
 
+#define action_auto_perf_actions_iterate(_autoperf_, _act_id_)            \
+{                                                                         \
+  int _perf_pos_;                                                         \
+                                                                          \
+  for (_perf_pos_ = 0; _perf_pos_ < ACTION_COUNT; _perf_pos_++) {         \
+    const int _act_id_ = _autoperf_->alternatives[_perf_pos_];            \
+                                                                          \
+    if (_act_id_ == ACTION_COUNT) {                                       \
+      /* No more alternative actions. */                                  \
+      break;                                                              \
+    }
+
+#define action_auto_perf_actions_iterate_end                              \
+  }                                                                       \
+}
+
 /* Hard coded location of action auto performers. Used for conversion while
  * action auto performers aren't directly exposed to the ruleset. */
 #define ACTION_AUTO_UPKEEP_FOOD   0

Modified: trunk/server/actiontools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/actiontools.c?rev=34298&r1=34297&r2=34298&view=diff
==============================================================================
--- trunk/server/actiontools.c  (original)
+++ trunk/server/actiontools.c  Mon Oct 31 10:31:49 2016
@@ -796,8 +796,6 @@
                          const struct city *target_city,
                          const struct unit *target_unit)
 {
-  int i;
-
   int actor_id;
 
   const struct city *tgt_city;
@@ -826,13 +824,8 @@
                ? target_tile
                : action_tgt_tile_units(actor, unit_tile(actor), TRUE));
 
-  for (i = 0; i < ACTION_COUNT; i++) {
-    const enum gen_action act = autoperf->alternatives[i];
-
-    if (act == ACTION_COUNT) {
-      /* No more alternative actions. */
-      break;
-    } else if (action_id_get_actor_kind(act) == AAK_UNIT) {
+  action_auto_perf_actions_iterate(autoperf, act) {
+    if (action_id_get_actor_kind(act) == AAK_UNIT) {
       /* This action can be done by units. */
 
 #define perform_action_to(act, actor, tgtid)                              \
@@ -882,7 +875,7 @@
         return NULL;
       }
     }
-  }
+  } action_auto_perf_actions_iterate_end;
 
   return NULL;
 }


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

Reply via email to