From ac3ba737ffcca67fdea777546ee2a0a5062c2a4c Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Fri, 5 Mar 2021 10:00:53 +0100 Subject: [PATCH 1/3] Get default action distance range by result. Change action_min_range_default() and action_max_range_default() to specify the default action action distance range by action result. This changes the default max range of "Nuke City" to 0 since it shares its action result with "Explode Nuclear". See osdn #41700 --- common/actions.c | 334 ++++++++++++++------------------------ common/actions.h | 4 +- server/rscompat.c | 1 + server/ruleset.c | 10 +- tools/ruleutil/rulesave.c | 16 +- 5 files changed, 146 insertions(+), 219 deletions(-) diff --git a/common/actions.c b/common/actions.c index 828e62a02f..d5ca27aceb 100644 --- a/common/actions.c +++ b/common/actions.c @@ -7511,117 +7511,76 @@ const char *action_min_range_ruleset_var_name(int act) /**********************************************************************//** Return default min range for the action if it is ruleset settable. **************************************************************************/ -int action_min_range_default(int act) +int action_min_range_default(enum action_result result) { - switch ((enum gen_action)act) { - case ACTION_SPY_POISON: - case ACTION_SPY_POISON_ESC: - case ACTION_SPY_SABOTAGE_UNIT: - case ACTION_SPY_SABOTAGE_UNIT_ESC: - case ACTION_SPY_BRIBE_UNIT: - case ACTION_SPY_SABOTAGE_CITY: - case ACTION_SPY_SABOTAGE_CITY_ESC: - case ACTION_SPY_TARGETED_SABOTAGE_CITY: - case ACTION_SPY_SABOTAGE_CITY_PRODUCTION: - case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC: - case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC: - case ACTION_SPY_INCITE_CITY: - case ACTION_SPY_INCITE_CITY_ESC: - case ACTION_ESTABLISH_EMBASSY: - case ACTION_ESTABLISH_EMBASSY_STAY: - case ACTION_SPY_STEAL_TECH: - case ACTION_SPY_STEAL_TECH_ESC: - case ACTION_SPY_TARGETED_STEAL_TECH: - case ACTION_SPY_TARGETED_STEAL_TECH_ESC: - case ACTION_SPY_INVESTIGATE_CITY: - case ACTION_INV_CITY_SPEND: - case ACTION_SPY_STEAL_GOLD: - case ACTION_SPY_STEAL_GOLD_ESC: - case ACTION_SPY_SPREAD_PLAGUE: - case ACTION_STEAL_MAPS: - case ACTION_STEAL_MAPS_ESC: - case ACTION_TRADE_ROUTE: - case ACTION_MARKETPLACE: - case ACTION_HELP_WONDER: - case ACTION_CAPTURE_UNITS: - case ACTION_EXPEL_UNIT: - case ACTION_FOUND_CITY: - case ACTION_JOIN_CITY: - case ACTION_SPY_NUKE: - case ACTION_SPY_NUKE_ESC: - case ACTION_NUKE_CITY: - case ACTION_NUKE_UNITS: - case ACTION_DESTROY_CITY: - case ACTION_RECYCLE_UNIT: - case ACTION_DISBAND_UNIT: - case ACTION_HOME_CITY: - case ACTION_UPGRADE_UNIT: - case ACTION_PARADROP: - case ACTION_AIRLIFT: - case ACTION_ATTACK: - case ACTION_SUICIDE_ATTACK: - case ACTION_STRIKE_BUILDING: - case ACTION_STRIKE_PRODUCTION: - case ACTION_CONQUER_CITY: - case ACTION_CONQUER_CITY2: - case ACTION_CONQUER_CITY3: - case ACTION_CONQUER_CITY4: - case ACTION_HEAL_UNIT: - case ACTION_HEAL_UNIT2: - case ACTION_TRANSFORM_TERRAIN: - case ACTION_CULTIVATE: - case ACTION_PLANT: - case ACTION_PILLAGE: - case ACTION_CLEAN_POLLUTION: - case ACTION_CLEAN_FALLOUT: - case ACTION_FORTIFY: - case ACTION_ROAD: - case ACTION_CONVERT: - case ACTION_BASE: - case ACTION_MINE: - case ACTION_IRRIGATE: - case ACTION_TRANSPORT_ALIGHT: - case ACTION_TRANSPORT_BOARD: - case ACTION_TRANSPORT_EMBARK: - case ACTION_TRANSPORT_EMBARK2: - case ACTION_TRANSPORT_EMBARK3: - case ACTION_TRANSPORT_UNLOAD: - case ACTION_TRANSPORT_DISEMBARK1: - case ACTION_TRANSPORT_DISEMBARK2: - case ACTION_TRANSPORT_DISEMBARK3: - case ACTION_TRANSPORT_DISEMBARK4: - case ACTION_BOMBARD: - case ACTION_BOMBARD2: - case ACTION_BOMBARD3: - case ACTION_NUKE: - case ACTION_SPY_ATTACK: - case ACTION_CONQUER_EXTRAS: - case ACTION_CONQUER_EXTRAS2: - case ACTION_CONQUER_EXTRAS3: - case ACTION_CONQUER_EXTRAS4: - case ACTION_HUT_ENTER: - case ACTION_HUT_ENTER2: - case ACTION_HUT_ENTER3: - case ACTION_HUT_ENTER4: - case ACTION_HUT_FRIGHTEN: - case ACTION_HUT_FRIGHTEN2: - case ACTION_HUT_FRIGHTEN3: - case ACTION_HUT_FRIGHTEN4: - case ACTION_UNIT_MOVE: - case ACTION_UNIT_MOVE2: - case ACTION_UNIT_MOVE3: + switch (result) { + case ACTRES_ESTABLISH_EMBASSY: + case ACTRES_SPY_INVESTIGATE_CITY: + case ACTRES_SPY_POISON: + case ACTRES_SPY_STEAL_GOLD: + case ACTRES_SPY_SABOTAGE_CITY: + case ACTRES_SPY_TARGETED_SABOTAGE_CITY: + case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION: + case ACTRES_SPY_STEAL_TECH: + case ACTRES_SPY_TARGETED_STEAL_TECH: + case ACTRES_SPY_INCITE_CITY: + case ACTRES_TRADE_ROUTE: + case ACTRES_MARKETPLACE: + case ACTRES_HELP_WONDER: + case ACTRES_SPY_BRIBE_UNIT: + case ACTRES_SPY_SABOTAGE_UNIT: + case ACTRES_CAPTURE_UNITS: + case ACTRES_FOUND_CITY: + case ACTRES_JOIN_CITY: + case ACTRES_STEAL_MAPS: + case ACTRES_BOMBARD: + case ACTRES_SPY_NUKE: + case ACTRES_NUKE: + case ACTRES_NUKE_UNITS: + case ACTRES_DESTROY_CITY: + case ACTRES_EXPEL_UNIT: + case ACTRES_RECYCLE_UNIT: + case ACTRES_DISBAND_UNIT: + case ACTRES_HOME_CITY: + case ACTRES_UPGRADE_UNIT: + case ACTRES_PARADROP: + case ACTRES_AIRLIFT: + case ACTRES_STRIKE_BUILDING: + case ACTRES_STRIKE_PRODUCTION: + case ACTRES_ATTACK: + case ACTRES_CONQUER_CITY: + case ACTRES_HEAL_UNIT: + case ACTRES_TRANSFORM_TERRAIN: + case ACTRES_CULTIVATE: + case ACTRES_PLANT: + case ACTRES_PILLAGE: + case ACTRES_CLEAN_POLLUTION: + case ACTRES_CLEAN_FALLOUT: + case ACTRES_FORTIFY: + case ACTRES_ROAD: + case ACTRES_CONVERT: + case ACTRES_BASE: + case ACTRES_MINE: + case ACTRES_IRRIGATE: + case ACTRES_TRANSPORT_ALIGHT: + case ACTRES_TRANSPORT_UNLOAD: + case ACTRES_TRANSPORT_DISEMBARK: + case ACTRES_TRANSPORT_BOARD: + case ACTRES_TRANSPORT_EMBARK: + case ACTRES_SPY_ATTACK: + case ACTRES_SPY_SPREAD_PLAGUE: + case ACTRES_CONQUER_EXTRAS: + case ACTRES_HUT_ENTER: + case ACTRES_HUT_FRIGHTEN: + case ACTRES_UNIT_MOVE: /* Non ruleset defined action min range not supported here */ fc_assert_msg(FALSE, "Probably wrong value."); return RS_DEFAULT_ACTION_MIN_RANGE; - case ACTION_USER_ACTION1: - case ACTION_USER_ACTION2: - case ACTION_USER_ACTION3: + case ACTRES_NONE: return RS_DEFAULT_ACTION_MIN_RANGE; - case ACTION_COUNT: - break; } - fc_assert(act >= 0 && act < ACTION_COUNT); + fc_assert(action_result_is_valid(result) || result == ACTRES_NONE); return 0; } @@ -7758,122 +7717,81 @@ const char *action_max_range_ruleset_var_name(int act) /**********************************************************************//** Return default max range for the action if it is ruleset settable. **************************************************************************/ -int action_max_range_default(int act) +int action_max_range_default(enum action_result result) { - switch ((enum gen_action)act) { - case ACTION_SPY_POISON: - case ACTION_SPY_POISON_ESC: - case ACTION_SPY_SABOTAGE_UNIT: - case ACTION_SPY_SABOTAGE_UNIT_ESC: - case ACTION_SPY_BRIBE_UNIT: - case ACTION_SPY_SABOTAGE_CITY: - case ACTION_SPY_SABOTAGE_CITY_ESC: - case ACTION_SPY_TARGETED_SABOTAGE_CITY: - case ACTION_SPY_SABOTAGE_CITY_PRODUCTION: - case ACTION_SPY_TARGETED_SABOTAGE_CITY_ESC: - case ACTION_SPY_SABOTAGE_CITY_PRODUCTION_ESC: - case ACTION_SPY_INCITE_CITY: - case ACTION_SPY_INCITE_CITY_ESC: - case ACTION_ESTABLISH_EMBASSY: - case ACTION_ESTABLISH_EMBASSY_STAY: - case ACTION_SPY_STEAL_TECH: - case ACTION_SPY_STEAL_TECH_ESC: - case ACTION_SPY_TARGETED_STEAL_TECH: - case ACTION_SPY_TARGETED_STEAL_TECH_ESC: - case ACTION_SPY_INVESTIGATE_CITY: - case ACTION_INV_CITY_SPEND: - case ACTION_SPY_STEAL_GOLD: - case ACTION_SPY_STEAL_GOLD_ESC: - case ACTION_STEAL_MAPS: - case ACTION_STEAL_MAPS_ESC: - case ACTION_SPY_SPREAD_PLAGUE: - case ACTION_TRADE_ROUTE: - case ACTION_MARKETPLACE: - case ACTION_CAPTURE_UNITS: - case ACTION_EXPEL_UNIT: - case ACTION_FOUND_CITY: - case ACTION_JOIN_CITY: - case ACTION_SPY_NUKE: - case ACTION_SPY_NUKE_ESC: - case ACTION_DESTROY_CITY: - case ACTION_DISBAND_UNIT: - case ACTION_HOME_CITY: - case ACTION_UPGRADE_UNIT: - case ACTION_PARADROP: - case ACTION_ATTACK: - case ACTION_SUICIDE_ATTACK: - case ACTION_STRIKE_BUILDING: - case ACTION_STRIKE_PRODUCTION: - case ACTION_CONQUER_CITY: - case ACTION_CONQUER_CITY2: - case ACTION_CONQUER_CITY3: - case ACTION_CONQUER_CITY4: - case ACTION_HEAL_UNIT: - case ACTION_HEAL_UNIT2: - case ACTION_TRANSFORM_TERRAIN: - case ACTION_CULTIVATE: - case ACTION_PLANT: - case ACTION_PILLAGE: - case ACTION_CLEAN_POLLUTION: - case ACTION_CLEAN_FALLOUT: - case ACTION_FORTIFY: - case ACTION_ROAD: - case ACTION_CONVERT: - case ACTION_BASE: - case ACTION_MINE: - case ACTION_IRRIGATE: - case ACTION_TRANSPORT_ALIGHT: - case ACTION_TRANSPORT_BOARD: - case ACTION_TRANSPORT_EMBARK: - case ACTION_TRANSPORT_EMBARK2: - case ACTION_TRANSPORT_EMBARK3: - case ACTION_TRANSPORT_UNLOAD: - case ACTION_TRANSPORT_DISEMBARK1: - case ACTION_TRANSPORT_DISEMBARK2: - case ACTION_TRANSPORT_DISEMBARK3: - case ACTION_TRANSPORT_DISEMBARK4: - case ACTION_SPY_ATTACK: - case ACTION_CONQUER_EXTRAS: - case ACTION_CONQUER_EXTRAS2: - case ACTION_CONQUER_EXTRAS3: - case ACTION_CONQUER_EXTRAS4: - case ACTION_HUT_ENTER: - case ACTION_HUT_ENTER2: - case ACTION_HUT_ENTER3: - case ACTION_HUT_ENTER4: - case ACTION_HUT_FRIGHTEN: - case ACTION_HUT_FRIGHTEN2: - case ACTION_HUT_FRIGHTEN3: - case ACTION_HUT_FRIGHTEN4: - case ACTION_UNIT_MOVE: - case ACTION_UNIT_MOVE2: - case ACTION_UNIT_MOVE3: + switch (result) { + case ACTRES_ESTABLISH_EMBASSY: + case ACTRES_SPY_INVESTIGATE_CITY: + case ACTRES_SPY_POISON: + case ACTRES_SPY_STEAL_GOLD: + case ACTRES_SPY_SABOTAGE_CITY: + case ACTRES_SPY_TARGETED_SABOTAGE_CITY: + case ACTRES_SPY_SABOTAGE_CITY_PRODUCTION: + case ACTRES_SPY_STEAL_TECH: + case ACTRES_SPY_TARGETED_STEAL_TECH: + case ACTRES_SPY_INCITE_CITY: + case ACTRES_TRADE_ROUTE: + case ACTRES_MARKETPLACE: + case ACTRES_SPY_BRIBE_UNIT: + case ACTRES_SPY_SABOTAGE_UNIT: + case ACTRES_CAPTURE_UNITS: + case ACTRES_FOUND_CITY: + case ACTRES_JOIN_CITY: + case ACTRES_STEAL_MAPS: + case ACTRES_SPY_NUKE: + case ACTRES_DESTROY_CITY: + case ACTRES_EXPEL_UNIT: + case ACTRES_DISBAND_UNIT: + case ACTRES_HOME_CITY: + case ACTRES_UPGRADE_UNIT: + case ACTRES_PARADROP: + case ACTRES_STRIKE_BUILDING: + case ACTRES_STRIKE_PRODUCTION: + case ACTRES_ATTACK: + case ACTRES_CONQUER_CITY: + case ACTRES_HEAL_UNIT: + case ACTRES_TRANSFORM_TERRAIN: + case ACTRES_CULTIVATE: + case ACTRES_PLANT: + case ACTRES_PILLAGE: + case ACTRES_CLEAN_POLLUTION: + case ACTRES_CLEAN_FALLOUT: + case ACTRES_FORTIFY: + case ACTRES_ROAD: + case ACTRES_CONVERT: + case ACTRES_BASE: + case ACTRES_MINE: + case ACTRES_IRRIGATE: + case ACTRES_TRANSPORT_ALIGHT: + case ACTRES_TRANSPORT_UNLOAD: + case ACTRES_TRANSPORT_DISEMBARK: + case ACTRES_TRANSPORT_BOARD: + case ACTRES_TRANSPORT_EMBARK: + case ACTRES_SPY_ATTACK: + case ACTRES_SPY_SPREAD_PLAGUE: + case ACTRES_CONQUER_EXTRAS: + case ACTRES_HUT_ENTER: + case ACTRES_HUT_FRIGHTEN: + case ACTRES_UNIT_MOVE: /* Non ruleset defined action max range not supported here */ fc_assert_msg(FALSE, "Probably wrong value."); return RS_DEFAULT_ACTION_MAX_RANGE; - case ACTION_HELP_WONDER: - case ACTION_RECYCLE_UNIT: + case ACTRES_HELP_WONDER: + case ACTRES_RECYCLE_UNIT: return RS_DEFAULT_ACTION_MAX_RANGE; - case ACTION_BOMBARD: - case ACTION_BOMBARD2: - case ACTION_BOMBARD3: + case ACTRES_BOMBARD: return RS_DEFAULT_ACTION_MAX_RANGE; - case ACTION_NUKE: + case ACTRES_NUKE: return RS_DEFAULT_EXPLODE_NUCLEAR_MAX_RANGE; - case ACTION_NUKE_CITY: - case ACTION_NUKE_UNITS: + case ACTRES_NUKE_UNITS: return RS_DEFAULT_ACTION_MAX_RANGE; - case ACTION_AIRLIFT: + case ACTRES_AIRLIFT: return ACTION_DISTANCE_UNLIMITED; - case ACTION_USER_ACTION1: - case ACTION_USER_ACTION2: - case ACTION_USER_ACTION3: + case ACTRES_NONE: return RS_DEFAULT_ACTION_MAX_RANGE; - case ACTION_COUNT: - break; } - fc_assert(act >= 0 && act < ACTION_COUNT); + fc_assert(action_result_is_valid(result) || result == ACTRES_NONE); return 0; } diff --git a/common/actions.h b/common/actions.h index 09d0a1dd97..48f436f1c1 100644 --- a/common/actions.h +++ b/common/actions.h @@ -689,9 +689,9 @@ const char *action_ui_name_ruleset_var_name(int act); const char *action_ui_name_default(int act); const char *action_min_range_ruleset_var_name(int act); -int action_min_range_default(int act); +int action_min_range_default(enum action_result result); const char *action_max_range_ruleset_var_name(int act); -int action_max_range_default(int act); +int action_max_range_default(enum action_result result); const char *action_target_kind_ruleset_var_name(int act); enum action_target_kind diff --git a/server/rscompat.c b/server/rscompat.c index 18c3d93e32..e43afd019a 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -838,6 +838,7 @@ void rscompat_postprocess(struct rscompat_info *info) paction = action_by_number(ACTION_NUKE_CITY); paction->target_kind = ATK_CITY; paction->actor_consuming_always = TRUE; + paction->max_distance = RS_DEFAULT_ACTION_MAX_RANGE; paction = action_by_number(ACTION_NUKE); paction->actor_consuming_always = TRUE; diff --git a/server/ruleset.c b/server/ruleset.c index 4df011d102..98b767afec 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -6138,12 +6138,13 @@ static bool load_action_range_max(struct section_file *file, action_id act) { struct entry *pentry; int max_range; + struct action *paction = action_by_number(act); pentry = secfile_entry_lookup(file, "actions.%s", action_max_range_ruleset_var_name(act)); if (!pentry) { - max_range = action_max_range_default(act); + max_range = action_max_range_default(paction->result); } else { const char *custom; @@ -6157,7 +6158,7 @@ static bool load_action_range_max(struct section_file *file, action_id act) } else { ruleset_error(LOG_ERROR, "Bad actions.%s", action_max_range_ruleset_var_name(act)); - action_by_number(act)->max_distance = action_max_range_default(act); + action_by_number(act)->max_distance = action_max_range_default(paction->result); return FALSE; } } @@ -6171,6 +6172,8 @@ static bool load_action_range_max(struct section_file *file, action_id act) **************************************************************************/ static bool load_action_range(struct section_file *file, action_id act) { + struct action *paction = action_by_number(act); + if (action_max_range_ruleset_var_name(act) != NULL) { /* Max range can be loaded from the ruleset. */ if (!load_action_range_max(file, act)) { @@ -6181,7 +6184,8 @@ static bool load_action_range(struct section_file *file, action_id act) if (action_min_range_ruleset_var_name(act) != NULL) { /* Min range can be loaded from the ruleset. */ action_by_number(act)->min_distance - = secfile_lookup_int_default(file, action_min_range_default(act), + = secfile_lookup_int_default(file, + action_min_range_default(paction->result), "actions.%s", action_min_range_ruleset_var_name(act)); } diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 6885b19284..994b335696 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -825,14 +825,15 @@ static bool save_action_ui_name(struct section_file *sfile, static bool save_action_max_range(struct section_file *sfile, action_id act) { - if (action_by_number(act)->max_distance - == ACTION_DISTANCE_UNLIMITED) { + struct action *paction = action_by_number(act); + + if (paction->max_distance == ACTION_DISTANCE_UNLIMITED) { return secfile_insert_str(sfile, RS_ACTION_NO_MAX_DISTANCE, "actions.%s", action_max_range_ruleset_var_name(act)) != NULL; } else { return save_default_int(sfile, action_by_number(act)->max_distance, - action_max_range_default(act), + action_max_range_default(paction->result), "actions", action_max_range_ruleset_var_name(act)); } @@ -843,12 +844,15 @@ static bool save_action_max_range(struct section_file *sfile, **************************************************************************/ static bool save_action_range(struct section_file *sfile, action_id act) { + struct action *paction = action_by_number(act); + if (action_min_range_ruleset_var_name(act) != NULL) { /* Min range can be loaded from the ruleset. */ save_default_int(sfile, - action_by_number(act)->min_distance, - action_min_range_default(act), - "actions", action_min_range_ruleset_var_name(act)); + paction->min_distance, + action_min_range_default(paction->result), + "actions", + action_min_range_ruleset_var_name(act)); } if (action_max_range_ruleset_var_name(act) != NULL) { -- 2.20.1