Author: sveinung Date: Sun Sep 14 13:13:01 2014 New Revision: 26409 URL: http://svn.gna.org/viewcvs/freeciv?rev=26409&view=rev Log: Centralize checking that an action probability represents a possible value.
Introduce the new function action_prob_possible() in the actions module to do the check. See patch #5225 Modified: trunk/ai/default/aidiplomat.c trunk/client/gui-gtk-2.0/action_dialog.c trunk/client/gui-gtk-3.0/action_dialog.c trunk/client/gui-qt/dialogs.cpp trunk/client/gui-sdl/action_dialog.c trunk/client/gui-sdl2/action_dialog.c trunk/client/gui-xaw/action_dialog.c trunk/common/actions.c trunk/common/actions.h trunk/server/unithand.c Modified: trunk/ai/default/aidiplomat.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aidiplomat.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/ai/default/aidiplomat.c (original) +++ trunk/ai/default/aidiplomat.c Sun Sep 14 13:13:01 2014 @@ -337,7 +337,7 @@ unit_activity_handling(punit, ACTIVITY_IDLE); #define T(my_act, my_val) \ - if (ACTPROB_IMPOSSIBLE != action_prob_vs_city(punit, my_act, ctarget)) {\ + if (action_prob_possible(action_prob_vs_city(punit, my_act, ctarget))) {\ log_base(LOG_DIPLOMAT, "%s %s[%d] does " #my_act " at %s", \ nation_rule_name(nation_of_unit(punit)), \ unit_rule_name(punit), punit->id, city_name(ctarget)); \ @@ -642,9 +642,9 @@ pf_path_destroy(path); } - if (ACTPROB_IMPOSSIBLE != action_prob_vs_unit(punit, - ACTION_SPY_BRIBE_UNIT, - pvictim)) { + if (action_prob_possible(action_prob_vs_unit(punit, + ACTION_SPY_BRIBE_UNIT, + pvictim))) { handle_unit_do_action(pplayer, punit->id, pvictim->id, -1, ACTION_SPY_BRIBE_UNIT); @@ -654,9 +654,9 @@ } else { return FALSE; } - } else if (ACTPROB_IMPOSSIBLE != action_prob_vs_unit(punit, - ACTION_SPY_SABOTAGE_UNIT, - pvictim) + } else if (action_prob_possible(action_prob_vs_unit(punit, + ACTION_SPY_SABOTAGE_UNIT, + pvictim)) && threat) { /* don't stand around waiting for the final blow */ handle_unit_do_action(pplayer, punit->id, Modified: trunk/client/gui-gtk-2.0/action_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/action_dialog.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/client/gui-gtk-2.0/action_dialog.c (original) +++ trunk/client/gui-gtk-2.0/action_dialog.c Sun Sep 14 13:13:01 2014 @@ -951,7 +951,7 @@ const gchar *tooltip; /* Don't show disabled actions. */ - if (action_probabilities[action_id] == ACTPROB_IMPOSSIBLE) { + if (!action_prob_possible(action_probabilities[action_id])) { return; } Modified: trunk/client/gui-gtk-3.0/action_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/action_dialog.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/action_dialog.c (original) +++ trunk/client/gui-gtk-3.0/action_dialog.c Sun Sep 14 13:13:01 2014 @@ -961,7 +961,7 @@ const gchar *tooltip; /* Don't show disabled actions. */ - if (action_probabilities[action_id] == ACTPROB_IMPOSSIBLE) { + if (!action_prob_possible(action_probabilities[action_id])) { return; } Modified: trunk/client/gui-qt/dialogs.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.cpp?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/client/gui-qt/dialogs.cpp (original) +++ trunk/client/gui-qt/dialogs.cpp Sun Sep 14 13:13:01 2014 @@ -1214,7 +1214,7 @@ QString tool_tip; /* Don't show disabled actions. */ - if (action_probabilities[act] == ACTPROB_IMPOSSIBLE) { + if (!action_prob_possible(action_probabilities[act])) { return; } Modified: trunk/client/gui-sdl/action_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/action_dialog.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/client/gui-sdl/action_dialog.c (original) +++ trunk/client/gui-sdl/action_dialog.c Sun Sep 14 13:13:01 2014 @@ -849,7 +849,7 @@ const char *ui_name; /* Don't show disabled actions */ - if (action_probabilities[act] == ACTPROB_IMPOSSIBLE) { + if (!action_prob_possible(action_probabilities[act])) { return; } Modified: trunk/client/gui-sdl2/action_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/action_dialog.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/client/gui-sdl2/action_dialog.c (original) +++ trunk/client/gui-sdl2/action_dialog.c Sun Sep 14 13:13:01 2014 @@ -849,7 +849,7 @@ const char *ui_name; /* Don't show disabled actions */ - if (action_probabilities[act] == ACTPROB_IMPOSSIBLE) { + if (!action_prob_possible(action_probabilities[act])) { return; } Modified: trunk/client/gui-xaw/action_dialog.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-xaw/action_dialog.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/client/gui-xaw/action_dialog.c (original) +++ trunk/client/gui-xaw/action_dialog.c Sun Sep 14 13:13:01 2014 @@ -835,7 +835,7 @@ { Arg arglist[1]; - if (!action_probabilities[action_id]) { + if (!action_prob_possible(action_probabilities[action_id])) { XtSetSensitive(w, FALSE); } Modified: trunk/common/actions.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/common/actions.c (original) +++ trunk/common/actions.c Sun Sep 14 13:13:01 2014 @@ -892,6 +892,15 @@ } /************************************************************************** + Returns TRUE iff the given action probability belongs to an action that + may be possible. +**************************************************************************/ +bool action_prob_possible(action_probability probability) +{ + return ACTPROB_IMPOSSIBLE != probability; +} + +/************************************************************************** Will a player with the government gov be immune to the action act? **************************************************************************/ bool action_immune_government(struct government *gov, int act) Modified: trunk/common/actions.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/common/actions.h (original) +++ trunk/common/actions.h Sun Sep 14 13:13:01 2014 @@ -186,6 +186,8 @@ action_probability action_prob_vs_unit(struct unit* actor, int action_id, struct unit* victim); +bool action_prob_possible(action_probability probability); + /* Reasoning about actions */ bool action_immune_government(struct government *gov, int act); Modified: trunk/server/unithand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=26409&r1=26408&r2=26409&view=diff ============================================================================== --- trunk/server/unithand.c (original) +++ trunk/server/unithand.c Sun Sep 14 13:13:01 2014 @@ -215,7 +215,7 @@ continue; } - if (ACTPROB_IMPOSSIBLE != action_prob_vs_city(actor, act, target)) { + if (action_prob_possible(action_prob_vs_city(actor, act, target))) { /* The actor unit may be able to do this action to the target * city. */ return TRUE; @@ -247,7 +247,7 @@ continue; } - if (ACTPROB_IMPOSSIBLE != action_prob_vs_unit(actor, act, target)) { + if (action_prob_possible(action_prob_vs_unit(actor, act, target))) { /* The actor unit may be able to do this action to the target * unit. */ return TRUE; @@ -363,7 +363,7 @@ /* Analyze the probabilities. Decide what targets to send and if an * explanation is needed. */ action_iterate(act) { - if (probabilities[act] != ACTPROB_IMPOSSIBLE) { + if (action_prob_possible(probabilities[act])) { /* An action can be done. No need to explain why no action can be * done. */ at_least_one_action = TRUE; _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits