Author: sveinung Date: Fri Jun 5 15:51:34 2015 New Revision: 29155 URL: http://svn.gna.org/viewcvs/freeciv?rev=29155&view=rev Log: AI: Warn if being a target of a new action isn't handled.
The AI uses the function action_target_neg_util() to consider how bad it is for one of its cities to be the victim of an action. It is easy to forget it when adding a new action that targets a city. Make the compiler warn if a new hard coded action is added without being listed in action_target_neg_util()'s switch statement. Being reminded to consider actions with a city target is worth having to list actions that don't target cities. See patch #6106 Modified: branches/S2_6/ai/default/aicity.c Modified: branches/S2_6/ai/default/aicity.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aicity.c?rev=29155&r1=29154&r2=29155&view=diff ============================================================================== --- branches/S2_6/ai/default/aicity.c (original) +++ branches/S2_6/ai/default/aicity.c Fri Jun 5 15:51:34 2015 @@ -1045,10 +1045,7 @@ static int action_target_neg_util(int action_id, const struct city *pcity) { - fc_assert_ret_val_msg(action_get_target_kind(action_id) == ATK_CITY, - 0, "Action not aimed at cities"); - - switch (action_id) { + switch ((enum gen_action)action_id) { case ACTION_SPY_INCITE_CITY: /* Copied from the evaluation of the No_Incite effect */ return MAX((game.server.diplchance * 2 @@ -1082,8 +1079,19 @@ case ACTION_HELP_WONDER: /* TODO: Individual and well balanced values */ return -1; - } - + + /* Shouldn't happen. */ + case ACTION_SPY_BRIBE_UNIT: + case ACTION_SPY_SABOTAGE_UNIT: + case ACTION_COUNT: + fc_assert_msg(action_get_target_kind(action_id) == ATK_CITY, + "Action not aimed at cities"); + } + + fc_assert_msg(gen_action_is_valid(action_id), + "Action %d don't exist.", action_id); + + /* Wrong action. Ignore it. */ return 0; } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits