From 8bf19b5441b798aef505f5a68b4d944745e1a86e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 2 Mar 2023 13:24:55 +0200 Subject: [PATCH 28/28] Rename action_is_hostile() as actres_is_hostile() - Move it from unittype.c to actres.[ch] - Turn massive switch-case to an array lookup - Pass actres parameter instead of action one See osdn #47463 Signed-off-by: Marko Lindqvist --- common/actres.c | 207 +++++++++++++++++++++++++++++++--------------- common/actres.h | 2 + common/unittype.c | 108 ++++-------------------- 3 files changed, 159 insertions(+), 158 deletions(-) diff --git a/common/actres.c b/common/actres.c index 65fded929d..ef08327110 100644 --- a/common/actres.c +++ b/common/actres.c @@ -18,71 +18,136 @@ #include "actres.h" static struct actres act_results[ACTRES_LAST] = { - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_ESTABLISH_EMBASSY */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_SPY_INVESTIGATE_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_POISON */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_STEAL_GOLD */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_SABOTAGE_CITY */ - { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC }, /* ACTRES_SPY_TARGETED_SABOTAGE_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_SABOTAGE_CITY_PRODUCTION */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_STEAL_TECH */ - { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC }, /* ACTRES_SPY_TARGETED_STEAL_TECH */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_INCITE_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRADE_ROUTE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_MARKETPLACE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_HELP_WONDER */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_BRIBE_UNIT */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_SABOTAGE_UNIT */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_CAPTURE_UNITS */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_FOUND_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_JOIN_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_STEAL_MAPS */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_BOMBARD */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_NUKE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_NUKE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_NUKE_UNITS */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_DESTROY_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_EXPEL_UNIT */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_DISBAND_UNIT_RECOVER */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_DISBAND_UNIT */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_HOME_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_UPGRADE_UNIT */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_PARADROP */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_AIRLIFT */ - { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD }, /* ACTRES_ATTACK */ - { ACT_TGT_COMPL_MANDATORY, ABK_NONE }, /* ACTRES_STRIKE_BUILDING */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_STRIKE_PRODUCTION */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_CONQUER_CITY */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_HEAL_UNIT */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRANSFORM_TERRAIN */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_CULTIVATE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_PLANT */ - { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE }, /* ACTRES_PILLAGE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_FORTIFY */ - { ACT_TGT_COMPL_MANDATORY, ABK_NONE }, /* ACTRES_ROAD */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_CONVERT */ - { ACT_TGT_COMPL_MANDATORY, ABK_NONE }, /* ACTRES_BASE */ - { ACT_TGT_COMPL_MANDATORY, ABK_NONE }, /* ACTRES_MINE */ - { ACT_TGT_COMPL_MANDATORY, ABK_NONE }, /* ACTRES_IRRIGATE */ - { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE }, /* ACTRES_CLEAN_POLLUTION */ - { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE }, /* ACTRES_CLEAN_FALLOUT */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRANSPORT_DEBOARD */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRANSPORT_UNLOAD */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRANSPORT_DISEMBARK */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRANSPORT_BOARD */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRANSPORT_EMBARK */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_SPREAD_PLAGUE */ - { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC }, /* ACTRES_SPY_ATTACK */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_CONQUER_EXTRAS */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_HUT_ENTER */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_HUT_FRIGHTEN */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_UNIT_MOVE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_PARADROP_CONQUER */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_HOMELESS */ - { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD }, /* ACTRES_WIPE_UNITS */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_SPY_ESCAPE */ - { ACT_TGT_COMPL_SIMPLE, ABK_NONE }, /* ACTRES_TRANSPORT_LOAD */ - { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE } /* ACTRES_CLEAN */ + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_ESTABLISH_EMBASSY */ + FALSE}, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_SPY_INVESTIGATE_CITY */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_POISON */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_STEAL_GOLD */ + TRUE}, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_CITY */ + TRUE }, + { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC, /* ACTRES_SPY_TARGETED_SABOTAGE_CITY */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_CITY_PRODUCTION */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_STEAL_TECH */ + TRUE }, + { ACT_TGT_COMPL_MANDATORY, ABK_DIPLOMATIC, /* ACTRES_SPY_TARGETED_STEAL_TECH */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_INCITE_CITY */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRADE_ROUTE */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_MARKETPLACE */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HELP_WONDER */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_BRIBE_UNIT */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SABOTAGE_UNIT */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CAPTURE_UNITS */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_FOUND_CITY */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_JOIN_CITY */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_STEAL_MAPS */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_BOMBARD */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_NUKE */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_NUKE */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_NUKE_UNITS */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DESTROY_CITY */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_EXPEL_UNIT */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DISBAND_UNIT_RECOVER */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_DISBAND_UNIT */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HOME_CITY */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_UPGRADE_UNIT */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PARADROP */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_AIRLIFT */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD, /* ACTRES_ATTACK */ + TRUE }, + { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_STRIKE_BUILDING */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_STRIKE_PRODUCTION */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONQUER_CITY */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HEAL_UNIT */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSFORM_TERRAIN */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CULTIVATE */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PLANT */ + FALSE }, + { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_PILLAGE */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_FORTIFY */ + FALSE }, + { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_ROAD */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONVERT */ + FALSE }, + { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_BASE */ + FALSE }, + { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_MINE */ + FALSE }, + { ACT_TGT_COMPL_MANDATORY, ABK_NONE, /* ACTRES_IRRIGATE */ + FALSE }, + { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_CLEAN_POLLUTION */ + FALSE }, + { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_CLEAN_FALLOUT */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_DEBOARD */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_UNLOAD */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_DISEMBARK */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_BOARD */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_EMBARK */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_SPREAD_PLAGUE */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_DIPLOMATIC, /* ACTRES_SPY_ATTACK */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_CONQUER_EXTRAS */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HUT_ENTER */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HUT_FRIGHTEN */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_UNIT_MOVE */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_PARADROP_CONQUER */ + FALSE }, /* TODO: should this be hostile? */ + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_HOMELESS */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_STANDARD, /* ACTRES_WIPE_UNITS */ + TRUE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_SPY_ESCAPE */ + FALSE }, + { ACT_TGT_COMPL_SIMPLE, ABK_NONE, /* ACTRES_TRANSPORT_LOAD */ + FALSE }, + { ACT_TGT_COMPL_FLEXIBLE, ABK_NONE, /* ACTRES_CLEAN */ + FALSE } }; /*********************************************************************//** @@ -127,3 +192,15 @@ enum action_battle_kind actres_get_battle_kind(enum action_result result) return act_results[result].battle_kind; } + +/**********************************************************************//** + Returns TRUE iff the specified action result indicates hostile action. +**************************************************************************/ +bool actres_is_hostile(enum action_result result) +{ + if (result == ACTRES_NONE) { + return FALSE; + } + + return act_results[result].hostile; +} diff --git a/common/actres.h b/common/actres.h index 6c2c539be0..d63fa132de 100644 --- a/common/actres.h +++ b/common/actres.h @@ -93,6 +93,7 @@ extern "C" { struct actres { enum act_tgt_compl sub_tgt_compl; enum action_battle_kind battle_kind; + bool hostile; }; void actres_init(void); @@ -100,6 +101,7 @@ void actres_free(void); enum act_tgt_compl actres_target_compl_calc(enum action_result result); enum action_battle_kind actres_get_battle_kind(enum action_result result); +bool actres_is_hostile(enum action_result result); #ifdef __cplusplus } diff --git a/common/unittype.c b/common/unittype.c index e3a96320b0..474e7059a5 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -304,91 +304,6 @@ bool utype_can_freely_unload(const struct unit_type *pcargotype, uclass_index(utype_class(ptranstype))); } -/**********************************************************************//** - Returns TRUE iff the specified action is hostile. -**************************************************************************/ -static bool action_is_hostile(action_id act_id) -{ - struct action *paction = action_by_number(act_id); - - switch (paction->result) { - 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_BRIBE_UNIT: - case ACTRES_SPY_SABOTAGE_UNIT: - case ACTRES_CAPTURE_UNITS: - 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_STRIKE_BUILDING: - case ACTRES_STRIKE_PRODUCTION: - case ACTRES_ATTACK: - case ACTRES_WIPE_UNITS: - case ACTRES_CONQUER_CITY: - case ACTRES_PILLAGE: - case ACTRES_SPY_ATTACK: - case ACTRES_SPY_SPREAD_PLAGUE: - case ACTRES_CONQUER_EXTRAS: - return TRUE; - case ACTRES_ESTABLISH_EMBASSY: - case ACTRES_TRADE_ROUTE: - case ACTRES_MARKETPLACE: - case ACTRES_HELP_WONDER: - case ACTRES_FOUND_CITY: - case ACTRES_JOIN_CITY: - 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: /* TODO: should this be hostile? */ - case ACTRES_AIRLIFT: - case ACTRES_HEAL_UNIT: - case ACTRES_TRANSFORM_TERRAIN: - case ACTRES_CULTIVATE: - case ACTRES_PLANT: - case ACTRES_CLEAN: - 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_DEBOARD: - case ACTRES_TRANSPORT_UNLOAD: - case ACTRES_TRANSPORT_DISEMBARK: - case ACTRES_TRANSPORT_BOARD: - case ACTRES_TRANSPORT_LOAD: - case ACTRES_TRANSPORT_EMBARK: - case ACTRES_HUT_ENTER: - case ACTRES_HUT_FRIGHTEN: - case ACTRES_UNIT_MOVE: - case ACTRES_SPY_ESCAPE: - return FALSE; - case ACTRES_NONE: - /* Assume they are up to something. */ - return TRUE; - } - - /* Should not be reached. */ - fc_assert(FALSE); - return FALSE; -} - /* Fake action id representing any hostile action. */ #define ACTION_HOSTILE ACTION_COUNT + 1 @@ -429,7 +344,8 @@ static void unit_can_act_cache_set(struct unit_type *putype) action_rule_name(paction)); BV_SET(unit_can_act_cache[act_id], utype_index(putype)); BV_SET(unit_can_act_cache[ACTION_ANY], utype_index(putype)); - if (action_is_hostile(act_id)) { + + if (actres_is_hostile(paction->result)) { BV_SET(unit_can_act_cache[ACTION_HOSTILE], utype_index(putype)); } } @@ -690,9 +606,11 @@ static void unit_state_action_cache_set(struct unit_type *putype) * No unit state except present and !present of the same property * implies or conflicts with another so the tests can be simple. */ action_enablers_iterate(enabler) { + struct action *paction = enabler_get_action(enabler); + if (requirement_fulfilled_by_unit_type(putype, &(enabler->actor_reqs)) - && action_get_actor_kind(enabler_get_action(enabler)) == AAK_UNIT) { + && action_get_actor_kind(paction) == AAK_UNIT) { bool present = TRUE; do { @@ -704,7 +622,7 @@ static void unit_state_action_cache_set(struct unit_type *putype) BV_SET(ustate_act_cache[utype_index(putype)][act_id], requirement_unit_state_ereq(req.source.value.unit_state, !req.present)); - if (action_is_hostile(act_id)) { + if (actres_is_hostile(paction->result)) { BV_SET(ustate_act_cache[utype_index(putype)][ACTION_HOSTILE], requirement_unit_state_ereq(req.source.value.unit_state, !req.present)); @@ -790,7 +708,7 @@ static void local_dipl_rel_action_cache_set(struct unit_type *putype) BV_SET(dipl_rel_action_cache[uidx][act_id], requirement_diplrel_ereq(req.source.value.diplrel, REQ_RANGE_LOCAL, req.present)); - if (action_is_hostile(act_id)) { + if (actres_is_hostile(paction->result)) { BV_SET(dipl_rel_action_cache[uidx][ACTION_HOSTILE], requirement_diplrel_ereq(req.source.value.diplrel, REQ_RANGE_LOCAL, @@ -850,9 +768,11 @@ local_dipl_rel_tile_other_tgt_action_cache_set(struct unit_type *putype) * the cache when units can do an action given a certain diplomatic * relationship property value. */ action_enablers_iterate(enabler) { + struct action *paction = enabler_get_action(enabler); + if (requirement_fulfilled_by_unit_type(putype, &(enabler->actor_reqs)) - && action_get_actor_kind(enabler_get_action(enabler)) == AAK_UNIT + && action_get_actor_kind(paction) == AAK_UNIT /* No diplomatic relation to Nature */ && !does_req_contradicts_reqs(&tile_is_claimed, &enabler->target_reqs)) { @@ -866,7 +786,7 @@ local_dipl_rel_tile_other_tgt_action_cache_set(struct unit_type *putype) BV_SET(dipl_rel_tile_other_tgt_a_cache[uidx][act_id], requirement_diplrel_ereq(req.source.value.diplrel, REQ_RANGE_LOCAL, req.present)); - if (action_is_hostile(act_id)) { + if (actres_is_hostile(paction->result)) { BV_SET(dipl_rel_tile_other_tgt_a_cache[uidx][ACTION_HOSTILE], requirement_diplrel_ereq(req.source.value.diplrel, REQ_RANGE_LOCAL, @@ -922,9 +842,11 @@ static void tgt_citytile_act_cache_set(struct unit_type *putype) * property implies or conflicts with another so the tests can be * simple. */ action_enablers_iterate(enabler) { + struct action *paction = enabler_get_action(enabler); + if (requirement_fulfilled_by_unit_type(putype, &(enabler->target_reqs)) - && action_get_actor_kind(enabler_get_action(enabler)) == AAK_UNIT) { + && action_get_actor_kind(paction) == AAK_UNIT) { bool present = TRUE; do { @@ -937,7 +859,7 @@ static void tgt_citytile_act_cache_set(struct unit_type *putype) ctile_tgt_act_cache[utype_index(putype)][act_id], requirement_citytile_ereq(req.source.value.citytile, !req.present)); - if (action_is_hostile(act_id)) { + if (actres_is_hostile(paction->result)) { BV_SET( ctile_tgt_act_cache[utype_index(putype)][ACTION_HOSTILE], requirement_citytile_ereq(req.source.value.citytile, -- 2.39.2