Author: sveinung Date: Wed Jul 20 15:39:50 2016 New Revision: 33281 URL: http://svn.gna.org/viewcvs/freeciv?rev=33281&view=rev Log: Remove magic value use inside action probs.
See patch #7477 Modified: trunk/common/actions.c Modified: trunk/common/actions.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=33281&r1=33280&r2=33281&view=diff ============================================================================== --- trunk/common/actions.c (original) +++ trunk/common/actions.c Wed Jul 20 15:39:50 2016 @@ -30,6 +30,24 @@ #include "unit.h" #include "research.h" #include "tile.h" + +/* Values used to interpret action probabilities. + * + * Action probabilities are sent over the network. A change in a value here + * will therefore change the network protocol. + * + * A change in a value here should also update the action probability + * format documentation in fc_types.h */ +/* The lowest possible probability value (0%) */ +#define ACTPROB_VAL_MIN 0 +/* The highest possible probability value (100%) */ +#define ACTPROB_VAL_MAX 200 +/* A probability increase of 1% corresponds to this increase. */ +#define ACTPROB_VAL_1_PCT (ACTPROB_VAL_MAX / 100) +/* Action probability doesn't apply when min is this. */ +#define ACTPROB_VAL_NA 253 +/* Action probability unsupported when min is this. */ +#define ACTPROB_VAL_NOT_IMPL 254 static struct action *actions[ACTION_COUNT]; struct action_auto_perf auto_perfs[MAX_NUM_ACTION_AUTO_PERFORMERS]; @@ -577,12 +595,13 @@ /* TRANS: the probability that an action will succeed. Given in * percentage. Resolution is 0.5%. */ - astr_set(&chance, _("%.1f%%"), (double)prob.max / 2); + astr_set(&chance, _("%.1f%%"), (double)prob.max / ACTPROB_VAL_1_PCT); } else { /* TRANS: the interval (end points included) where the probability of * the action's success is. Given in percentage. Resolution is 0.5%. */ astr_set(&chance, _("[%.1f%%, %.1f%%]"), - (double)prob.min / 2, (double)prob.max / 2); + (double)prob.min / ACTPROB_VAL_1_PCT, + (double)prob.max / ACTPROB_VAL_1_PCT); } probtxt = astr_str(&chance); } @@ -628,14 +647,15 @@ /* TRANS: action probability of success. Given in percentage. * Resolution is 0.5%. */ astr_set(&tool_tip, _("The probability of success is %.1f%%."), - (double)prob.max / 2.0); + (double)prob.max / ACTPROB_VAL_1_PCT); } else { astr_set(&tool_tip, /* TRANS: action probability range (min to max). Given in * percentage. Resolution is 0.5%. */ _("The probability of success is %.1f%%, %.1f%% or somewhere" " in between."), - (double)prob.min / 2.0, (double)prob.max / 2.0); + (double)prob.min / ACTPROB_VAL_1_PCT, + (double)prob.max / ACTPROB_VAL_1_PCT); } return astr_str(&tool_tip); @@ -2179,8 +2199,8 @@ } /* Convert to action probability */ - out.min = chance * 2; - out.max = chance * 2; + out.min = chance * ACTPROB_VAL_1_PCT; + out.max = chance * ACTPROB_VAL_1_PCT; return out; } @@ -2417,8 +2437,8 @@ if (can_player_see_unit(actor_player, defender_unit)) { double unconverted = unit_win_chance(actor_unit, defender_unit); - chance.min = floor((double)200 * unconverted); - chance.max = ceil((double)200 * unconverted); + chance.min = floor((double)ACTPROB_VAL_MAX * unconverted); + chance.max = ceil((double)ACTPROB_VAL_MAX * unconverted); } else if (known == TRI_YES) { known = TRI_MAYBE; } @@ -2612,8 +2632,8 @@ /* Probability against all target units considered until this moment * and the probability against this target unit. */ - prob_all.min = (prob_all.min * prob_unit.min) / 200; - prob_all.max = (prob_all.max * prob_unit.max) / 200; + prob_all.min = (prob_all.min * prob_unit.min) / ACTPROB_VAL_MAX; + prob_all.max = (prob_all.max * prob_unit.max) / ACTPROB_VAL_MAX; break; } } unit_list_iterate_end; @@ -2713,7 +2733,7 @@ **************************************************************************/ struct act_prob action_prob_new_impossible(void) { - struct act_prob out = { 0, 0 }; + struct act_prob out = { ACTPROB_VAL_MIN, ACTPROB_VAL_MIN }; return out; } @@ -2723,7 +2743,7 @@ **************************************************************************/ struct act_prob action_prob_new_certain(void) { - struct act_prob out = { 200, 200 }; + struct act_prob out = { ACTPROB_VAL_MAX, ACTPROB_VAL_MAX }; return out; } @@ -2733,7 +2753,7 @@ **************************************************************************/ struct act_prob action_prob_new_not_relevant(void) { - struct act_prob out = { 253, 0}; + struct act_prob out = { ACTPROB_VAL_NA, ACTPROB_VAL_MIN}; return out; } @@ -2743,7 +2763,7 @@ **************************************************************************/ struct act_prob action_prob_new_not_impl(void) { - struct act_prob out = { 254, 0 }; + struct act_prob out = { ACTPROB_VAL_NOT_IMPL, ACTPROB_VAL_MIN }; return out; } @@ -2753,7 +2773,7 @@ **************************************************************************/ struct act_prob action_prob_new_unknown(void) { - struct act_prob out = { 0, 200 }; + struct act_prob out = { ACTPROB_VAL_MIN, ACTPROB_VAL_MAX }; return out; } @@ -2764,7 +2784,7 @@ **************************************************************************/ bool action_prob_possible(const struct act_prob probability) { - return (0 < probability.max + return (ACTPROB_VAL_MIN < probability.max || action_prob_not_impl(probability)); } @@ -2775,7 +2795,8 @@ static inline bool action_prob_not_relevant(const struct act_prob probability) { - return probability.min == 253 && probability.max == 0; + return probability.min == ACTPROB_VAL_NA + && probability.max == ACTPROB_VAL_MIN; } /************************************************************************** @@ -2785,7 +2806,8 @@ static inline bool action_prob_not_impl(const struct act_prob probability) { - return probability.min == 254 && probability.max == 0; + return probability.min == ACTPROB_VAL_NOT_IMPL + && probability.max == ACTPROB_VAL_MIN; } /************************************************************************** _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits