Author: sveinung
Date: Wed Jun 22 09:01:10 2016
New Revision: 32952

URL: http://svn.gna.org/viewcvs/freeciv?rev=32952&view=rev
Log:
Improve action probability assertion readability.

Replace checks for details of the current action probability format with
calls to functions with descriptive names.

See patch #7286

Modified:
    trunk/common/actions.c

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=32952&r1=32951&r2=32952&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Wed Jun 22 09:01:10 2016
@@ -59,6 +59,11 @@
                              const struct unit_type *target_unittype,
                              const struct output_type *target_output,
                              const struct specialist *target_specialist);
+
+#ifndef FREECIV_NDEBUG
+static inline bool action_prob_is_signal(action_probability probability);
+static inline bool action_prob_not_relevant(action_probability probability);
+#endif /* FREECIV_NDEBUG */
 
 /**************************************************************************
   Initialize the actions and the action enablers.
@@ -536,7 +541,7 @@
     /* Could be a client who haven't gotten the ruleset yet */
 
     /* so there shouldn't be any action probability to show */
-    fc_assert(prob == ACTPROB_NA);
+    fc_assert(action_prob_not_relevant(prob));
 
     /* but the action should be valid */
     fc_assert_ret_val_msg(action_id_is_valid(action_id),
@@ -579,7 +584,7 @@
     /* ACTPROB_IMPOSSIBLE is a 0% probability of success */
   default:
     /* Should be in the range 0 (0%) to 200 (100%) */
-    fc_assert_msg(prob < 201,
+    fc_assert_msg(!action_prob_is_signal(prob),
                   "Diplomat action probability out of range");
 
     /* TRANS: the probability that a diplomat action will succeed. */
@@ -2731,6 +2736,26 @@
   return ACTPROB_IMPOSSIBLE != probability && ACTPROB_NA != probability;
 }
 
+#ifndef FREECIV_NDEBUG
+/**************************************************************************
+  Returns TRUE iff the given action probability represents the lack of
+  an action probability.
+**************************************************************************/
+static inline bool action_prob_not_relevant(action_probability probability)
+{
+  return ACTPROB_NA == probability;
+}
+
+/**************************************************************************
+  Returns TRUE iff the given action probability represents a special
+  signal value rather than a regular action probability value.
+**************************************************************************/
+static inline bool action_prob_is_signal(action_probability probability)
+{
+  return probability < 0 && probability > 200;
+}
+#endif /* FREECIV_NDEBUG */
+
 /**************************************************************************
   Will a player with the government gov be immune to the action act?
 **************************************************************************/


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

Reply via email to