Author: sveinung Date: Tue Mar 14 10:39:47 2017 New Revision: 35110 URL: http://svn.gna.org/viewcvs/freeciv?rev=35110&view=rev Log: Prepare action ID validation for generic actions.
Rename the function action_id_is_valid() to action_id_exists(). Make it about the action with the given id, not about the action result. Use gen_action_is_valid() for action results. See hrm Feature #644444 Modified: branches/S3_0/ai/default/aicity.c branches/S3_0/client/control.c branches/S3_0/client/packhand.c branches/S3_0/common/actions.c branches/S3_0/common/actions.h branches/S3_0/common/unittype.c branches/S3_0/server/ruleset.c branches/S3_0/server/savegame3.c branches/S3_0/server/unithand.c Modified: branches/S3_0/ai/default/aicity.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/ai/default/aicity.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/ai/default/aicity.c (original) +++ branches/S3_0/ai/default/aicity.c Tue Mar 14 10:39:47 2017 @@ -1230,7 +1230,7 @@ "Action not aimed at cities"); } - fc_assert_msg(action_id_is_valid(action_id), + fc_assert_msg(action_id_exists(action_id), "Action %d don't exist.", action_id); /* Wrong action. Ignore it. */ Modified: branches/S3_0/client/control.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/client/control.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/client/control.c (original) +++ branches/S3_0/client/control.c Tue Mar 14 10:39:47 2017 @@ -1102,7 +1102,7 @@ if (last_order == ORDER_PERFORM_ACTION) { /* An action has been specified. */ - fc_assert_ret(action_id_is_valid(action_id)); + fc_assert_ret(action_id_exists(action_id)); /* The order system doesn't support actions that can be done to a * target that isn't at or next to the actor unit's tile. Modified: branches/S3_0/client/packhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/client/packhand.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/client/packhand.c (original) +++ branches/S3_0/client/packhand.c Tue Mar 14 10:39:47 2017 @@ -257,7 +257,7 @@ /* Just an assert. The client doesn't use the action data. */ fc_assert(punit->orders.list[i].order != ORDER_PERFORM_ACTION - || action_id_is_valid(punit->orders.list[i].action)); + || action_id_exists(punit->orders.list[i].action)); } } @@ -3966,9 +3966,7 @@ { struct action *act; - /* Action id is currently hard coded in the gen_action enum. It is - * therefore OK to use action_id_is_valid() */ - if (!action_id_is_valid(p->id)) { + if (!action_id_exists(p->id)) { /* Action id out of range */ log_error("handle_ruleset_action() the action id %d is out of range.", p->id); @@ -3998,7 +3996,7 @@ struct action_enabler *enabler; int i; - if (!action_id_is_valid(p->enabled_action)) { + if (!action_id_exists(p->enabled_action)) { /* Non existing action */ log_error("handle_ruleset_action_enabler() the action %d " "doesn't exist.", @@ -4413,7 +4411,7 @@ diplomat_id); if (ACTION_COUNT != action_type - && !action_id_is_valid(action_type)) { + && !action_id_exists(action_type)) { /* Non existing action */ log_error("handle_unit_action_answer() the action %d doesn't exist.", action_type); Modified: branches/S3_0/common/actions.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/common/actions.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/common/actions.c (original) +++ branches/S3_0/common/actions.c Tue Mar 14 10:39:47 2017 @@ -143,9 +143,9 @@ va_start(args, error_message); while (ACTION_NONE != (act = va_arg(args, enum gen_action))) { - /* The only expected invalid action id is ACTION_NONE and it should - * terminate the loop before this assertion. */ - fc_assert_ret_msg(action_id_is_valid(act), "Invalid action id %d", act); + /* Any invalid action result should terminate the loop before this + * assertion. */ + fc_assert_ret_msg(gen_action_is_valid(act), "Invalid action id %d", act); obligatory_req_vector_append(&obligatory_hard_reqs[act], oreq); } @@ -637,9 +637,10 @@ /************************************************************************** Returns TRUE iff the specified action ID refers to a valid action. **************************************************************************/ -bool action_id_is_valid(const int action_id) -{ - return gen_action_is_valid(action_id); +bool action_id_exists(const int action_id) +{ + /* Actions are still hard coded. */ + return gen_action_is_valid(action_id) && actions[action_id]; } /************************************************************************** @@ -649,7 +650,7 @@ **************************************************************************/ struct action *action_by_number(int action_id) { - if (!action_id_is_valid(action_id)) { + if (!action_id_exists(action_id)) { /* Nothing to return. */ log_verbose("Asked for non existing action numbered %d", action_id); @@ -672,7 +673,7 @@ /* Actions are still hard coded in the gen_action enum. */ int action_id = gen_action_by_name(name, fc_strcasecmp); - if (!action_id_is_valid(action_id)) { + if (!action_id_exists(action_id)) { /* Nothing to return. */ log_verbose("Asked for non existing action named %s", name); @@ -747,8 +748,7 @@ **************************************************************************/ bool action_id_is_rare_pop_up(int action_id) { - fc_assert_ret_val_msg((action_id_is_valid(action_id) - && actions[action_id]), + fc_assert_ret_val_msg((action_id_exists(action_id)), FALSE, "Action %d don't exist.", action_id); return actions[action_id]->rare_pop_up; @@ -868,7 +868,7 @@ fc_assert(action_prob_not_relevant(prob)); /* but the action should be valid */ - fc_assert_ret_val_msg(action_id_is_valid(action_id), + fc_assert_ret_val_msg(action_id_exists(action_id), "Invalid action", "Invalid action %d", action_id); @@ -1040,7 +1040,7 @@ /* Sanity check: a non existing action enabler can't be added. */ fc_assert_ret(enabler); /* Sanity check: a non existing action doesn't have enablers. */ - fc_assert_ret(action_id_is_valid(enabler->action)); + fc_assert_ret(action_id_exists(enabler->action)); action_enabler_list_append( action_enablers_for_action(enabler->action), @@ -1057,7 +1057,7 @@ /* Sanity check: a non existing action enabler can't be removed. */ fc_assert_ret_val(enabler, FALSE); /* Sanity check: a non existing action doesn't have enablers. */ - fc_assert_ret_val(action_id_is_valid(enabler->action), FALSE); + fc_assert_ret_val(action_id_exists(enabler->action), FALSE); return action_enabler_list_remove( action_enablers_for_action(enabler->action), @@ -1071,7 +1071,7 @@ action_enablers_for_action(enum gen_action action) { /* Sanity check: a non existing action doesn't have enablers. */ - fc_assert_ret_val(action_id_is_valid(action), NULL); + fc_assert_ret_val(action_id_exists(action), NULL); return action_enablers_by_action[action]; } @@ -1098,7 +1098,7 @@ /* Sanity check: a non existing action doesn't have any obligatory hard * requirements. */ - fc_assert_ret_val(action_id_is_valid(enabler->action), NULL); + fc_assert_ret_val(action_id_exists(enabler->action), NULL); obligatory_req_vector_iterate(&obligatory_hard_reqs[enabler->action], obreq) { @@ -1135,7 +1135,7 @@ /* Sanity check: a non existing action doesn't have any obligatory hard * requirements. */ - fc_assert_ret(action_id_is_valid(enabler->action)); + fc_assert_ret(action_id_exists(enabler->action)); obligatory_req_vector_iterate(&obligatory_hard_reqs[enabler->action], obreq) { @@ -2132,7 +2132,7 @@ /* No known hard coded requirements. */ break; case ACTION_COUNT: - fc_assert(action_id_is_valid(wanted_action)); + fc_assert(action_id_exists(wanted_action)); break; } @@ -3708,7 +3708,7 @@ bool action_mp_full_makes_legal(const struct unit *actor, const int action_id) { - fc_assert(action_id_is_valid(action_id) || action_id == ACTION_ANY); + fc_assert(action_id_exists(action_id) || action_id == ACTION_ANY); /* Check if full movement points may enable the specified action. */ return !utype_may_act_move_frags(unit_type_get(actor), Modified: branches/S3_0/common/actions.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/common/actions.h?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/common/actions.h (original) +++ branches/S3_0/common/actions.h Tue Mar 14 10:39:47 2017 @@ -324,7 +324,7 @@ bool actions_are_ready(void); -bool action_id_is_valid(const int action_id); +bool action_id_exists(const int action_id); struct action *action_by_number(int action_id); struct action *action_by_rule_name(const char *name); Modified: branches/S3_0/common/unittype.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/common/unittype.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/common/unittype.c (original) +++ branches/S3_0/common/unittype.c Tue Mar 14 10:39:47 2017 @@ -611,7 +611,7 @@ { struct range *ml_range; - fc_assert(action_id_is_valid(action_id) || action_id == ACTION_ANY); + fc_assert(action_id_exists(action_id) || action_id == ACTION_ANY); if (!utype_may_act_at_all(punit_type)) { /* Not an actor unit. */ Modified: branches/S3_0/server/ruleset.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/ruleset.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/server/ruleset.c (original) +++ branches/S3_0/server/ruleset.c Tue Mar 14 10:39:47 2017 @@ -6265,7 +6265,7 @@ } action = gen_action_by_name(action_text, fc_strcasecmp); - if (!action_id_is_valid(action)) { + if (!action_id_exists(action)) { ruleset_error(LOG_ERROR, "\"%s\" [%s] lists unknown action type \"%s\".", filename, sec_name, action_text); ok = FALSE; Modified: branches/S3_0/server/savegame3.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/savegame3.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/server/savegame3.c (original) +++ branches/S3_0/server/savegame3.c Tue Mar 14 10:39:47 2017 @@ -5451,7 +5451,7 @@ || (order->order == ORDER_ACTION_MOVE && !direction8_is_valid(order->dir)) || (order->order == ORDER_PERFORM_ACTION - && !action_id_is_valid(order->action)) + && !action_id_exists(order->action)) || (order->order == ORDER_ACTIVITY && order->activity == ACTIVITY_LAST)) { /* An invalid order. Just drop the orders for this unit. */ Modified: branches/S3_0/server/unithand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S3_0/server/unithand.c?rev=35110&r1=35109&r2=35110&view=diff ============================================================================== --- branches/S3_0/server/unithand.c (original) +++ branches/S3_0/server/unithand.c Tue Mar 14 10:39:47 2017 @@ -731,7 +731,7 @@ } /* ACTION_ANY is handled above. */ - fc_assert_ret_val(action_id_is_valid(action_id), FALSE); + fc_assert_ret_val(action_id_exists(action_id), FALSE); action_enabler_list_iterate(action_enablers_for_action(action_id), enabler) { @@ -773,7 +773,7 @@ } /* ACTION_ANY is handled above. */ - fc_assert_ret_val(action_id_is_valid(action_id), FALSE); + fc_assert_ret_val(action_id_exists(action_id), FALSE); action_enabler_list_iterate(action_enablers_for_action(action_id), enabler) { @@ -1046,7 +1046,7 @@ CITYT_CLAIMED, FALSE)) { explnat->kind = ANEK_TGT_IS_UNCLAIMED; - } else if (action_id_is_valid(action_id) && punit + } else if (action_id_exists(action_id) && punit && ((target_tile && !action_id_distance_inside_max(action_id, real_map_distance(unit_tile(punit), target_tile))) @@ -1065,7 +1065,7 @@ > unit_type_get(punit)->paratroopers_range) { explnat->kind = ANEK_DISTANCE_FAR; explnat->distance = unit_type_get(punit)->paratroopers_range; - } else if (action_id_is_valid(action_id) && punit + } else if (action_id_exists(action_id) && punit && ((target_tile && real_map_distance(unit_tile(punit), target_tile) < action_by_number(action_id)->min_distance) @@ -1155,7 +1155,7 @@ /* Please add a check for any new action forbidding scenario setting * above this comment. */ explnat->kind = ANEK_SCENARIO_DISABLED; - } else if (action_id_is_valid(action_id) + } else if (action_id_exists(action_id) && (blocker = action_is_blocked_by(action_id, punit, target_tile, target_city, target_unit))) { @@ -2040,7 +2040,7 @@ struct unit *punit = game_unit_by_number(target_id); struct city *pcity = game_city_by_number(target_id); - if (!action_id_is_valid(action_type)) { + if (!action_id_exists(action_type)) { /* Non existing action */ log_error("handle_unit_action_query() the action %d doesn't exist.", action_type); @@ -2156,7 +2156,7 @@ struct unit *punit = game_unit_by_number(target_id); struct city *pcity = game_city_by_number(target_id); - if (!action_id_is_valid(action_type)) { + if (!action_id_exists(action_type)) { /* Non existing action */ log_error("unit_perform_action() the action %d doesn't exist.", action_type); @@ -4539,7 +4539,7 @@ break; case ORDER_PERFORM_ACTION: - if (!action_id_is_valid(packet->action[i])) { + if (!action_id_exists(packet->action[i])) { /* Non existing action */ log_error("handle_unit_orders() the action %d doesn't exist. " "Sent in order number %d from %s to unit number %d.", _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits