Validate action target kind
osdn refuses to upload the patch. It says "The specified file was not found." Inline:
From 8263d5ea2032ae54749bdbe439bc3c5709a83449 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net> Date: Sat, 6 Feb 2021 19:27:27 +0100 Subject: PATCH Validate action target kind.
Allowing the ruleset to change action target kind requires that Freeciv validates that the specified target kind will work with the action's result.
See osdn #41498 ---
diff --git a/common/actions.c b/common/actions.c index a060a30233..3406574b5d 100644 --- a/common/actions.c +++ b/common/actions.c @@ -7596,6 +7596,103 @@ const char *action_target_kind_ruleset_var_name(int act)
+/**********************************************************************//** + Returns TRUE iff the specified action result works with the specified + action target kind. +**************************************************************************/ +bool action_result_legal_target_kind(enum action_result result, + enum action_target_kind tgt_kind) +{ + fc_assert_ret_val(action_result_is_valid(result) || result == ACTRES_NONE, + FALSE); + fc_assert_ret_val(action_target_kind_is_valid(tgt_kind), + FALSE); + + 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_JOIN_CITY: + case ACTRES_STEAL_MAPS: + case ACTRES_SPY_NUKE: + case ACTRES_NUKE_CITY: + case ACTRES_DESTROY_CITY: + case ACTRES_RECYCLE_UNIT: + case ACTRES_HOME_CITY: + case ACTRES_UPGRADE_UNIT: + case ACTRES_AIRLIFT: + case ACTRES_STRIKE_BUILDING: + case ACTRES_STRIKE_PRODUCTION: + case ACTRES_CONQUER_CITY: + case ACTRES_SPY_SPREAD_PLAGUE: + return tgt_kind == ATK_CITY; + case ACTRES_SPY_BRIBE_UNIT: + case ACTRES_SPY_SABOTAGE_UNIT: + case ACTRES_EXPEL_UNIT: + case ACTRES_HEAL_UNIT: + case ACTRES_TRANSPORT_ALIGHT: + case ACTRES_TRANSPORT_UNLOAD: + case ACTRES_TRANSPORT_BOARD: + case ACTRES_TRANSPORT_EMBARK: + return tgt_kind == ATK_UNIT; + case ACTRES_CAPTURE_UNITS: + case ACTRES_BOMBARD: + case ACTRES_NUKE_UNITS: + case ACTRES_ATTACK: + case ACTRES_SPY_ATTACK: + return tgt_kind == ATK_UNITS; + case ACTRES_FOUND_CITY: + case ACTRES_NUKE: + case ACTRES_PARADROP: + case ACTRES_TRANSFORM_TERRAIN: + case ACTRES_CULTIVATE: + case ACTRES_PLANT: + case ACTRES_PILLAGE: + case ACTRES_CLEAN_POLLUTION: + case ACTRES_CLEAN_FALLOUT: + case ACTRES_ROAD: + case ACTRES_BASE: + case ACTRES_MINE: + case ACTRES_IRRIGATE: + case ACTRES_TRANSPORT_DISEMBARK: + return tgt_kind == ATK_TILE; + case ACTRES_CONQUER_EXTRAS: + return tgt_kind == ATK_EXTRAS; + case ACTRES_DISBAND_UNIT: + case ACTRES_CONVERT: + case ACTRES_FORTIFY: + return tgt_kind == ATK_SELF; + case ACTRES_NONE: + switch (tgt_kind) { + case ATK_CITY: + case ATK_UNIT: + case ATK_UNITS: + case ATK_TILE: + case ATK_EXTRAS: + case ATK_SELF: + /* Works with all existing target kinds. */ + return TRUE; + case ATK_COUNT: + fc_assert_ret_val(tgt_kind != ATK_COUNT, FALSE); + break; + } + break; + } + + /* Should never be reached. */ + return FALSE; +} +
diff --git a/common/actions.h b/common/actions.h index 12eb785bd7..76c2f89178 100644 --- a/common/actions.h +++ b/common/actions.h @@ -622,6 +622,9 @@ const char *action_max_range_ruleset_var_name(int act);
+bool action_result_legal_target_kind(enum action_result result, + enum action_target_kind tgt_kind); +
diff --git a/server/rssanity.c b/server/rssanity.c index ae469c9287..7c2035d66e 100644 --- a/server/rssanity.c +++ b/server/rssanity.c @@ -1047,6 +1047,14 @@ bool sanity_check_ruleset_data(bool ignore_retired)
+ if (!action_result_legal_target_kind(paction->result, + paction->target_kind)) { + ruleset_error(LOG_ERROR, "Action \"%s\": unsupported target kind %s.", + action_id_rule_name(act), + action_target_kind_name(paction->target_kind)); + ok = FALSE; + } +
-- 2.20.1
Patch can be seen at: https://github.com/kvilhaugsvik/freeciv/commit/a26806b8462537cac6840099dec6ee40100a729a
Validate action target kind.
Allowing the ruleset to change action target kind requires that Freeciv validates that the specified target kind will work with the action's result.