Author: cazfi
Date: Thu Jan 14 05:29:03 2016
New Revision: 31463

URL: http://svn.gna.org/viewcvs/freeciv?rev=31463&view=rev
Log:
Moved ASSERT_CHOICE() to advchoice.[ch] and renamed it as ADV_CHOICE_ASSERT()

See patch #6815

Modified:
    trunk/ai/default/aicity.c
    trunk/ai/default/aitools.c
    trunk/ai/default/aitools.h
    trunk/server/advisors/advchoice.c
    trunk/server/advisors/advchoice.h

Modified: trunk/ai/default/aicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aicity.c?rev=31463&r1=31462&r2=31463&view=diff
==============================================================================
--- trunk/ai/default/aicity.c   (original)
+++ trunk/ai/default/aicity.c   Thu Jan 14 05:29:03 2016
@@ -109,24 +109,6 @@
  (pcity->surplus[O_SHIELD] < 0 || city_unhappy(pcity)                  \
   || pcity->food_stock + pcity->surplus[O_FOOD] < 0)
 
-#ifdef FREECIV_NDEBUG
-#define ASSERT_CHOICE(c) /* Do nothing. */
-#else  /* FREECIV_NDEBUG */
-#define ASSERT_CHOICE(c)                                                 \
-  do {                                                                   \
-    if ((c).want > 0) {                                                  \
-      fc_assert((c).type > CT_NONE && (c).type < CT_LAST);               \
-      if ((c).type == CT_BUILDING) {                                     \
-        int _iindex = improvement_index((c).value.building);             \
-        fc_assert(_iindex >= 0 && _iindex < improvement_count());        \
-      } else {                                                           \
-        int _uindex = utype_index((c).value.utype);                      \
-        fc_assert(_uindex >= 0 && _uindex < utype_count());              \
-      }                                                                  \
-    }                                                                    \
-  } while(FALSE);
-#endif /* FREECIV_NDEBUG */
-
 static void dai_sell_obsolete_buildings(struct city *pcity);
 static void resolve_city_emergency(struct ai_type *ait, struct player *pplayer,
                                    struct city *pcity);
@@ -325,7 +307,7 @@
   }
 
   if (city_data->choice.want != 0) {
-    ASSERT_CHOICE(city_data->choice);
+    ADV_CHOICE_ASSERT(city_data->choice);
 
     CITY_LOG(LOG_DEBUG, pcity, "wants %s with desire " ADV_WANT_PRINTF ".",
             dai_choice_rule_name(&city_data->choice),
@@ -584,7 +566,7 @@
     /* Not dealing with this city a second time */
     city_data->choice.want = 0;
 
-    ASSERT_CHOICE(bestchoice);
+    ADV_CHOICE_ASSERT(bestchoice);
 
     /* Try upgrade units at danger location (high want is usually danger) */
     if (city_data->urgency > 1) {
@@ -891,7 +873,7 @@
       contemplate_new_city(ait, pcity);
     }
     TIMING_LOG(AIT_CITY_SETTLERS, TIMER_STOP);
-    ASSERT_CHOICE(city_data->choice);
+    ADV_CHOICE_ASSERT(city_data->choice);
   } city_list_iterate_end;
   /* Reset auto settler state for the next run. */
   dai_auto_settler_reset(ait, pplayer);

Modified: trunk/ai/default/aitools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aitools.c?rev=31463&r1=31462&r2=31463&view=diff
==============================================================================
--- trunk/ai/default/aitools.c  (original)
+++ trunk/ai/default/aitools.c  Thu Jan 14 05:29:03 2016
@@ -1017,14 +1017,6 @@
 }
 
 /**************************************************************************
-  Does choice type refer to unit
-**************************************************************************/
-bool is_unit_choice_type(enum choice_type type)
-{
-   return type == CT_CIVILIAN || type == CT_ATTACKER || type == CT_DEFENDER;
-}
-
-/**************************************************************************
   Calls dai_wants_role_unit to choose the best unit with the given role and 
   set tech wants.  Sets choice->value.utype when we can build something.
 **************************************************************************/

Modified: trunk/ai/default/aitools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aitools.h?rev=31463&r1=31462&r2=31463&view=diff
==============================================================================
--- trunk/ai/default/aitools.h  (original)
+++ trunk/ai/default/aitools.h  Thu Jan 14 05:29:03 2016
@@ -71,8 +71,6 @@
 
 void adjust_choice(int value, struct adv_choice *choice);
 
-bool is_unit_choice_type(enum choice_type type);
-
 bool dai_choose_role_unit(struct ai_type *ait, struct player *pplayer,
                           struct city *pcity, struct adv_choice *choice,
                           enum choice_type type, int role, int want,

Modified: trunk/server/advisors/advchoice.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/advchoice.c?rev=31463&r1=31462&r2=31463&view=diff
==============================================================================
--- trunk/server/advisors/advchoice.c   (original)
+++ trunk/server/advisors/advchoice.c   Thu Jan 14 05:29:03 2016
@@ -108,9 +108,15 @@
   }
 }
 
+/**************************************************************************
+  Does choice type refer to unit
+**************************************************************************/
+bool is_unit_choice_type(enum choice_type type)
+{
+   return type == CT_CIVILIAN || type == CT_ATTACKER || type == CT_DEFENDER;
+}
 
 #ifdef ADV_CHOICE_TRACK
-
 /**************************************************************************
   Copy contents of one choice structure to the other
 **************************************************************************/

Modified: trunk/server/advisors/advchoice.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/advchoice.h?rev=31463&r1=31462&r2=31463&view=diff
==============================================================================
--- trunk/server/advisors/advchoice.h   (original)
+++ trunk/server/advisors/advchoice.h   Thu Jan 14 05:29:03 2016
@@ -50,6 +50,8 @@
 struct adv_choice *adv_better_choice_free(struct adv_choice *first,
                                           struct adv_choice *second);
 
+bool is_unit_choice_type(enum choice_type type);
+
 #ifdef ADV_CHOICE_TRACK
 void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src);
 void adv_choice_set_use(struct adv_choice *choice, const char *use);
@@ -65,4 +67,22 @@
 #define adv_choice_log_info(_choice, _loc1, _loc2)
 #endif /* ADV_CHOICE_TRACK */
 
-#endif   /* FC__ADVCHOICE_H */
+#ifdef FREECIV_NDEBUG
+#define ADV_CHOICE_ASSERT(c) /* Do nothing. */
+#else  /* FREECIV_NDEBUG */
+#define ADV_CHOICE_ASSERT(c)                                             \
+  do {                                                                   \
+    if ((c).want > 0) {                                                  \
+      fc_assert((c).type > CT_NONE && (c).type < CT_LAST);               \
+      if (!is_unit_choice_type((c).type)) {                              \
+        int _iindex = improvement_index((c).value.building);             \
+        fc_assert(_iindex >= 0 && _iindex < improvement_count());        \
+      } else {                                                           \
+        int _uindex = utype_index((c).value.utype);                      \
+        fc_assert(_uindex >= 0 && _uindex < utype_count());              \
+      }                                                                  \
+    }                                                                    \
+  } while(FALSE);
+#endif /* FREECIV_NDEBUG */
+
+#endif /* FC__ADVCHOICE_H */


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

Reply via email to