From 8217633d2506c2ac664ae6a1d7d51ffdb2b812ad Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 25 Sep 2023 22:09:21 +0300 Subject: [PATCH 38/38] Replace action_removes_extra() with actres_removes_extra() Uses indexed table lookup instead of a switch See osdn #48728 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/menu.c | 2 +- client/gui-gtk-4.0/menu.c | 2 +- client/gui-qt/menu.cpp | 2 +- client/helpdata.c | 4 +- common/actions.c | 89 ---------------------- common/actions.h | 3 - common/actres.c | 151 +++++++++++++++++++++---------------- common/actres.h | 3 + common/unit.c | 4 +- common/unittype.c | 2 +- server/unittools.c | 2 +- 11 files changed, 96 insertions(+), 168 deletions(-) diff --git a/client/gui-gtk-3.22/menu.c b/client/gui-gtk-3.22/menu.c index 5f7e0bd1ae..b490bd235d 100644 --- a/client/gui-gtk-3.22/menu.c +++ b/client/gui-gtk-3.22/menu.c @@ -3082,7 +3082,7 @@ void real_menus_init(void) case ASTK_EXTRA_NOT_THERE: extra_type_iterate(pextra) { if (!actres_creates_extra(paction->result, pextra) - && !action_removes_extra(paction, pextra)) { + && !actres_removes_extra(paction->result, pextra)) { /* Not relevant */ continue; } diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index ce5fadae50..325fd769e4 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -3507,7 +3507,7 @@ void real_menus_update(void) case ASTK_EXTRA_NOT_THERE: extra_type_iterate(pextra) { if (!actres_creates_extra(paction->result, pextra) - && !action_removes_extra(paction, pextra)) { + && !actres_removes_extra(paction->result, pextra)) { /* Not relevant */ continue; } diff --git a/client/gui-qt/menu.cpp b/client/gui-qt/menu.cpp index 09decd53dd..0ba8dee2c6 100644 --- a/client/gui-qt/menu.cpp +++ b/client/gui-qt/menu.cpp @@ -779,7 +779,7 @@ void go_act_menu::create() case ASTK_EXTRA_NOT_THERE: extra_type_iterate(pextra) { if (!actres_creates_extra(paction->result, pextra) - && !action_removes_extra(paction, pextra)) { + && !actres_removes_extra(paction->result, pextra)) { // Not relevant continue; } diff --git a/client/helpdata.c b/client/helpdata.c index 16aa891735..2078bca62f 100644 --- a/client/helpdata.c +++ b/client/helpdata.c @@ -2912,7 +2912,7 @@ char *helptext_unit(char *buf, size_t bufsz, struct player *pplayer, struct strvec *extras_vec = strvec_new(); extra_type_iterate(pextra) { - if (action_removes_extra(paction, pextra)) { + if (actres_removes_extra(paction->result, pextra)) { strvec_append(extras_vec, extra_name_translation(pextra)); } } extra_type_iterate_end; @@ -2934,7 +2934,7 @@ char *helptext_unit(char *buf, size_t bufsz, struct player *pplayer, struct strvec *extras_vec = strvec_new(); extra_type_iterate(pextra) { - if (action_removes_extra(paction, pextra)) { + if (actres_removes_extra(paction->result, pextra)) { strvec_append(extras_vec, extra_name_translation(pextra)); } } extra_type_iterate_end; diff --git a/common/actions.c b/common/actions.c index 5188f15256..5a818ce7bd 100644 --- a/common/actions.c +++ b/common/actions.c @@ -1393,95 +1393,6 @@ int action_get_act_time(const struct action *paction, return ACT_TIME_INSTANTANEOUS; } -/**********************************************************************//** - Returns TRUE iff the specified action can remove the specified extra. -**************************************************************************/ -bool action_removes_extra(const struct action *paction, - const struct extra_type *pextra) -{ - fc_assert(paction != NULL); - if (pextra == NULL) { - return FALSE; - } - - switch (paction->result) { - case ACTRES_PILLAGE: - return is_extra_removed_by(pextra, ERM_PILLAGE); - case ACTRES_CLEAN: - return is_extra_removed_by(pextra, ERM_CLEAN); - case ACTRES_HUT_ENTER: - case ACTRES_HUT_FRIGHTEN: - return is_extra_removed_by(pextra, ERM_ENTER); - 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_SPY_ESCAPE: - 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_DISBAND_UNIT_RECOVER: - case ACTRES_DISBAND_UNIT: - case ACTRES_HOME_CITY: - case ACTRES_HOMELESS: - case ACTRES_UPGRADE_UNIT: - case ACTRES_PARADROP: - case ACTRES_PARADROP_CONQUER: - case ACTRES_AIRLIFT: - case ACTRES_STRIKE_BUILDING: - case ACTRES_STRIKE_PRODUCTION: - case ACTRES_ATTACK: - case ACTRES_WIPE_UNITS: - case ACTRES_CONQUER_CITY: - case ACTRES_CONQUER_EXTRAS: - case ACTRES_HEAL_UNIT: - case ACTRES_TRANSFORM_TERRAIN: - case ACTRES_CULTIVATE: - case ACTRES_PLANT: - case ACTRES_FORTIFY: - case ACTRES_ROAD: - case ACTRES_CONVERT: - case ACTRES_BASE: - case ACTRES_MINE: - case ACTRES_IRRIGATE: - case ACTRES_TRANSPORT_DEBOARD: - case ACTRES_TRANSPORT_UNLOAD: - case ACTRES_TRANSPORT_LOAD: - case ACTRES_TRANSPORT_DISEMBARK: - case ACTRES_TRANSPORT_BOARD: - case ACTRES_TRANSPORT_EMBARK: - case ACTRES_SPY_ATTACK: - case ACTRES_SPY_SPREAD_PLAGUE: - case ACTRES_UNIT_MOVE: - case ACTRES_TELEPORT: - case ACTRES_ENABLER_CHECK: - case ACTRES_NONE: - break; - - ASSERT_UNUSED_ACTRES_CASES; - } - - return FALSE; -} - /**********************************************************************//** Create a new action enabler. **************************************************************************/ diff --git a/common/actions.h b/common/actions.h index bedccb75e9..4d04ffd1e6 100644 --- a/common/actions.h +++ b/common/actions.h @@ -685,9 +685,6 @@ int action_get_act_time(const struct action *paction, action_get_act_time(action_by_number(act_id), \ actor_unit, tgt_tile, tgt_extra) -bool action_removes_extra(const struct action *paction, - const struct extra_type *pextra); - bool action_id_is_rare_pop_up(action_id act_id); bool action_distance_accepted(const struct action *action, diff --git a/common/actres.c b/common/actres.c index 0da0c6a934..b24ac76958 100644 --- a/common/actres.c +++ b/common/actres.c @@ -33,205 +33,205 @@ static struct actres act_results[ACTRES_LAST] = { { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_ESTABLISH_EMBASSY */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_SPY_INVESTIGATE_CITY */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_POISON */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_STEAL_GOLD */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_CITY */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC, /* ACTRES_SPY_TARGETED_SABOTAGE_CITY */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_CITY_PRODUCTION */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_STEAL_TECH */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC, /* ACTRES_SPY_TARGETED_STEAL_TECH */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_INCITE_CITY */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRADE_ROUTE */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_MARKETPLACE */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HELP_WONDER */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_BRIBE_UNIT */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_UNIT */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CAPTURE_UNITS */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_FOUND_CITY */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_JOIN_CITY */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_STEAL_MAPS */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_BOMBARD */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_NUKE */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_NUKE */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_NUKE_UNITS */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DESTROY_CITY */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_EXPEL_UNIT */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DISBAND_UNIT_RECOVER */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE , ERM_NONE}, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DISBAND_UNIT */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HOME_CITY */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_UPGRADE_UNIT */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PARADROP */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_AIRLIFT */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD, /* ACTRES_ATTACK */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_STRIKE_BUILDING */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_STRIKE_PRODUCTION */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONQUER_CITY */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HEAL_UNIT */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSFORM_TERRAIN */ FALSE, ACTIVITY_TRANSFORM, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CULTIVATE */ FALSE, ACTIVITY_CULTIVATE, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PLANT */ FALSE, ACTIVITY_PLANT, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_PILLAGE */ TRUE, ACTIVITY_PILLAGE, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_PILLAGE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_FORTIFY */ FALSE, ACTIVITY_FORTIFYING, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_ROAD */ FALSE, ACTIVITY_GEN_ROAD, DRT_NONE, - EC_ROAD }, + EC_ROAD, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONVERT */ FALSE, ACTIVITY_CONVERT, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_BASE */ FALSE, ACTIVITY_BASE, DRT_NONE, - EC_BASE }, + EC_BASE, ERM_NONE }, { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_MINE */ FALSE, ACTIVITY_MINE, DRT_NONE, - EC_MINE }, + EC_MINE, ERM_NONE }, { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_IRRIGATE */ FALSE, ACTIVITY_IRRIGATE, DRT_NONE, - EC_IRRIGATION }, + EC_IRRIGATION, ERM_NONE }, { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_UNUSED_1 */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_UNUSED_2 */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_DEBOARD */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_UNLOAD */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_DISEMBARK */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_BOARD */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_EMBARK */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SPREAD_PLAGUE */ TRUE, ACTIVITY_LAST, DRT_DIPLCHANCE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_ATTACK */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONQUER_EXTRAS */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HUT_ENTER */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_ENTER }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HUT_FRIGHTEN */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_ENTER }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_UNIT_MOVE */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PARADROP_CONQUER */ FALSE, ACTIVITY_LAST, DRT_NONE, /* TODO: Should this be hostile? */ - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HOMELESS */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD, /* ACTRES_WIPE_UNITS */ TRUE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_SPY_ESCAPE */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_LOAD */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_CLEAN */ FALSE, ACTIVITY_CLEAN, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_CLEAN }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TELEPORT */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE }, + EC_NONE, ERM_NONE }, { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_ENABLER_CHECK */ FALSE, ACTIVITY_LAST, DRT_NONE, - EC_NONE } + EC_NONE, ERM_NONE } }; /*********************************************************************//** @@ -340,6 +340,23 @@ bool actres_creates_extra(enum action_result result, return is_extra_caused_by(pextra, act_results[result].ecause); } +/**********************************************************************//** + Does action with the result remove the extra + + @param result Action result to check + @param pextra Extra to check + @return Whether action removes the extra +**************************************************************************/ +bool actres_removes_extra(enum action_result result, + const struct extra_type *pextra) +{ + if (act_results[result].ermcause == ERM_NONE) { + return FALSE; + } + + return is_extra_removed_by(pextra, act_results[result].ermcause); +} + /**********************************************************************//** Returns TRUE iff the specified player knows (has seen) the specified tile. diff --git a/common/actres.h b/common/actres.h index 3e3bc16248..353299ed52 100644 --- a/common/actres.h +++ b/common/actres.h @@ -119,6 +119,7 @@ struct actres { enum dice_roll_type dice; enum extra_cause ecause; /* Could deduct this from 'activity', but we should merge * activities completely with actions in the future */ + enum extra_rmcause ermcause; }; void actres_init(void); @@ -131,6 +132,8 @@ enum unit_activity actres_activity_result(enum action_result result); enum dice_roll_type actres_dice_type(enum action_result result); bool actres_creates_extra(enum action_result result, const struct extra_type *pextra); +bool actres_removes_extra(enum action_result result, + const struct extra_type *pextra); enum fc_tristate actres_possible(enum action_result result, const struct req_context *actor, diff --git a/common/unit.c b/common/unit.c index f3b12c83cf..4a22daba14 100644 --- a/common/unit.c +++ b/common/unit.c @@ -2739,8 +2739,8 @@ bool unit_order_list_is_sane(int length, const struct unit_order *orders) return FALSE; } } else { - if (!(action_removes_extra(paction, pextra) - || actres_creates_extra(paction->result, pextra))) { + if (!actres_removes_extra(paction->result, pextra) + && !actres_creates_extra(paction->result, pextra)) { /* Target extra is irrelevant for the action. */ log_error("at index %d, cannot do %s to %s.", i, action_id_rule_name(orders[i].action), diff --git a/common/unittype.c b/common/unittype.c index 0b9fb25621..1b8bad21f9 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -249,7 +249,7 @@ bool utype_can_remove_extra(const struct unit_type *putype, continue; } - if (action_removes_extra(paction, pextra)) { + if (actres_removes_extra(paction->result, pextra)) { /* Can remove */ return TRUE; } diff --git a/server/unittools.c b/server/unittools.c index 8722362836..2391fa6b70 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -4583,7 +4583,7 @@ bool execute_orders(struct unit *punit, const bool fresh) if (action_get_sub_target_kind(oaction) == ASTK_EXTRA && pextra != NULL - && action_removes_extra(oaction, pextra) + && actres_removes_extra(oaction->result, pextra) && !tile_has_extra(dst_tile, pextra)) { /* Already not there. Move on to the next order. */ break; -- 2.40.1