From 0d9fc123b34f209ae5d7c703275ec3a2f7324d9d Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 11 May 2021 10:58:17 +0200 Subject: [PATCH 2/9] get_unittype_bonus(): take action parameter. Allow get_unittype_bonus() using effects to take action requirements. See osdn #42222 --- ai/default/aitech.c | 2 +- ai/default/aiunit.c | 5 +++-- ai/default/daimilitary.c | 8 +++++--- common/aicore/path_finding.c | 2 +- common/aicore/pf_tools.c | 2 +- common/city.c | 4 ++-- common/combat.c | 8 +++++--- common/effects.c | 3 ++- common/effects.h | 1 + common/movement.c | 3 ++- common/unit.c | 3 ++- common/unittype.c | 8 +++++--- server/unittools.c | 2 +- 13 files changed, 31 insertions(+), 20 deletions(-) diff --git a/ai/default/aitech.c b/ai/default/aitech.c index e3faa7e7e1..5f7a864713 100644 --- a/ai/default/aitech.c +++ b/ai/default/aitech.c @@ -382,7 +382,7 @@ struct unit_type *dai_wants_defender_against(struct ai_type *ait, int def_values[U_LAST]; int att_idx = utype_index(att); int defbonus = 100 - + get_unittype_bonus(pplayer, ptile, att, EFT_DEFEND_BONUS); + + get_unittype_bonus(pplayer, ptile, att, NULL, EFT_DEFEND_BONUS); unit_type_iterate(deftype) { int mp_pct = deftype->cache.defense_mp_bonuses_pct[att_idx] + 100; diff --git a/ai/default/aiunit.c b/ai/default/aiunit.c index 2b7bb082b3..95f8d3039d 100644 --- a/ai/default/aiunit.c +++ b/ai/default/aiunit.c @@ -1642,8 +1642,9 @@ struct city *find_nearest_safe_city(struct unit *punit) cur = move_cost; /* Note the unit owner may be different from the city owner. */ - if (0 == get_unittype_bonus(unit_owner(punit), ptile, unit_type_get(punit), - EFT_HP_REGEN)) { + if (0 == get_unittype_bonus(unit_owner(punit), ptile, + unit_type_get(punit), NULL, + EFT_HP_REGEN)) { /* If we cannot regen fast our hit points here, let's make some * penalty. */ cur *= 3; diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index a6dc1c0e88..6843d90ed9 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -90,7 +90,8 @@ struct unit_type *dai_choose_defender_versus(struct city *pcity, int fpatt, fpdef, defense, attack; double want, loss, cost = utype_build_shield_cost(pcity, NULL, punittype); struct unit *defender; - int veteran = get_unittype_bonus(city_owner(pcity), pcity->tile, punittype, + int veteran = get_unittype_bonus(city_owner(pcity), pcity->tile, + punittype, NULL, EFT_VETERAN_BUILD); defender = unit_virtual_create(pplayer, pcity, punittype, veteran); @@ -404,7 +405,7 @@ static unsigned int assess_danger_unit(const struct city *pcity, danger = adv_unit_att_rating(punit); mod = 100 + get_unittype_bonus(city_owner(pcity), ptile, - punittype, EFT_DEFEND_BONUS); + punittype, NULL, EFT_DEFEND_BONUS); return danger * 100 / MAX(mod, 1); } @@ -520,7 +521,8 @@ static unsigned int assess_danger(struct ai_type *ait, struct city *pcity, best_non_scramble[idx] = -1; /* FIXME: cache it somewhere? */ city_def_against[idx] - = 100 + get_unittype_bonus(pplayer, ptile, utype, EFT_DEFEND_BONUS); + = 100 + get_unittype_bonus(pplayer, ptile, utype, NULL, + EFT_DEFEND_BONUS); city_def_against[idx] = MAX(city_def_against[idx], 1); } unit_type_iterate_end; diff --git a/common/aicore/path_finding.c b/common/aicore/path_finding.c index 0e225fd6c3..202c61dd6c 100644 --- a/common/aicore/path_finding.c +++ b/common/aicore/path_finding.c @@ -3812,7 +3812,7 @@ pf_reverse_map_utype_pos(struct pf_reverse_map *pfrm, struct pf_parameter *param = &pfrm->template; const struct player *pplayer = param->owner; int veteran_level = get_unittype_bonus(pplayer, ptile, punittype, - EFT_VETERAN_BUILD); + NULL, EFT_VETERAN_BUILD); if (veteran_level >= utype_veteran_levels(punittype)) { veteran_level = utype_veteran_levels(punittype) - 1; diff --git a/common/aicore/pf_tools.c b/common/aicore/pf_tools.c index 2c8d55ba1b..1b719f2b8d 100644 --- a/common/aicore/pf_tools.c +++ b/common/aicore/pf_tools.c @@ -719,7 +719,7 @@ pft_fill_utype_default_parameter(struct pf_parameter *parameter, struct player *powner) { int veteran_level = get_unittype_bonus(powner, pstart_tile, punittype, - EFT_VETERAN_BUILD); + NULL, EFT_VETERAN_BUILD); if (veteran_level >= utype_veteran_levels(punittype)) { veteran_level = utype_veteran_levels(punittype) - 1; diff --git a/common/city.c b/common/city.c index c0d7ab334e..9f787d079f 100644 --- a/common/city.c +++ b/common/city.c @@ -796,7 +796,7 @@ int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype) { int levels = get_unittype_bonus(city_owner(pcity), pcity->tile, punittype, - EFT_VETERAN_BUILD); + NULL, EFT_VETERAN_BUILD); int max_levels = utype_veteran_levels(punittype) - 1; levels = CLIP(0, levels, max_levels); @@ -1520,7 +1520,7 @@ bool city_got_defense_effect(const struct city *pcity, } return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker, - EFT_DEFEND_BONUS) > 0; + NULL, EFT_DEFEND_BONUS) > 0; } /**********************************************************************//** diff --git a/common/combat.c b/common/combat.c index c9e342f572..dc97e650b6 100644 --- a/common/combat.c +++ b/common/combat.c @@ -427,7 +427,8 @@ void get_modified_firepower(const struct unit *attacker, */ if (unit_has_type_flag(attacker, UTYF_BADWALLATTACKER) && get_unittype_bonus(unit_owner(defender), unit_tile(defender), - unit_type_get(attacker), EFT_DEFEND_BONUS) > 0) { + unit_type_get(attacker), NULL, + EFT_DEFEND_BONUS) > 0) { *att_fp = 1; } @@ -595,7 +596,8 @@ int get_total_attack_power(const struct unit *attacker, int attackpower = get_attack_power(attacker); mod = 100 + get_unittype_bonus(unit_owner(attacker), unit_tile(defender), - unit_type_get(attacker), EFT_ATTACK_BONUS); + unit_type_get(attacker), NULL, + EFT_ATTACK_BONUS); return attackpower * mod / 100; } @@ -639,7 +641,7 @@ static int defense_multiplication(const struct unit_type *att_type, int defense_multiplier_pct = 100 + def_type->cache.defense_mp_bonuses_pct[utype_index(att_type)]; int mod = 100 + get_unittype_bonus(def_player, ptile, - att_type, EFT_DEFEND_BONUS); + att_type, NULL, EFT_DEFEND_BONUS); /* This applies even if pcity is NULL. */ defensepower = defensepower * defense_multiplier_pct / 100; diff --git a/common/effects.c b/common/effects.c index 62bd903dcb..7800f18c89 100644 --- a/common/effects.c +++ b/common/effects.c @@ -878,6 +878,7 @@ int get_building_bonus(const struct city *pcity, int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, + const struct action *paction, enum effect_type effect_type) { struct city *pcity; @@ -897,7 +898,7 @@ int get_unittype_bonus(const struct player *pplayer, return get_target_bonus_effects(NULL, pplayer, NULL, pcity, NULL, ptile, NULL, punittype, NULL, - NULL, NULL, effect_type); + NULL, paction, effect_type); } /**********************************************************************//** diff --git a/common/effects.h b/common/effects.h index af37b00306..a40ae5498b 100644 --- a/common/effects.h +++ b/common/effects.h @@ -425,6 +425,7 @@ int get_building_bonus(const struct city *pcity, int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, /* pcity is implied */ const struct unit_type *punittype, + const struct action *paction, enum effect_type effect_type); int get_unit_bonus(const struct unit *punit, enum effect_type effect_type); int get_unit_vs_tile_bonus(const struct tile *ptile, diff --git a/common/movement.c b/common/movement.c index e20a3bf2c9..276efa8886 100644 --- a/common/movement.c +++ b/common/movement.c @@ -68,7 +68,8 @@ int utype_move_rate(const struct unit_type *utype, const struct tile *ptile, /* Add on effects bonus (Magellan's Expedition, Lighthouse, * Nuclear Power). */ - move_rate += (get_unittype_bonus(pplayer, ptile, utype, EFT_MOVE_BONUS) + move_rate += (get_unittype_bonus(pplayer, ptile, utype, NULL, + EFT_MOVE_BONUS) * SINGLE_MOVE); /* Don't let the move_rate be less than min_speed unless the base_move_rate is diff --git a/common/unit.c b/common/unit.c index 74e65d3429..2d01f5f2e7 100644 --- a/common/unit.c +++ b/common/unit.c @@ -2064,7 +2064,8 @@ bool is_losing_hp(const struct unit *punit) bool unit_type_is_losing_hp(const struct player *pplayer, const struct unit_type *punittype) { - return get_unittype_bonus(pplayer, NULL, punittype, EFT_UNIT_RECOVER) + return get_unittype_bonus(pplayer, NULL, punittype, NULL, + EFT_UNIT_RECOVER) < (punittype->hp * utype_class(punittype)->hp_loss_pct / 100); } diff --git a/common/unittype.c b/common/unittype.c index bdae7374ba..dddd896805 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -1409,7 +1409,8 @@ int utype_build_shield_cost(const struct city *pcity, } base = punittype->build_cost - * (100 + get_unittype_bonus(owner, ptile, punittype, EFT_UNIT_BUILD_COST_PCT)) / 100; + * (100 + get_unittype_bonus(owner, ptile, punittype, NULL, + EFT_UNIT_BUILD_COST_PCT)) / 100; return MAX(base * game.info.shieldbox / 100, 1); } @@ -1467,7 +1468,8 @@ int utype_buy_gold_cost(const struct city *pcity, } cost = cost - * (100 + get_unittype_bonus(owner, ptile, punittype, EFT_UNIT_BUY_COST_PCT)) + * (100 + get_unittype_bonus(owner, ptile, punittype, NULL, + EFT_UNIT_BUY_COST_PCT)) / 100; return cost; @@ -1481,7 +1483,7 @@ int utype_pop_value(const struct unit_type *punittype, const struct city *pcity) int pop_cost = punittype->pop_cost; pop_cost -= get_unittype_bonus(city_owner(pcity), city_tile(pcity), - punittype, EFT_POPCOST_FREE); + punittype, NULL, EFT_POPCOST_FREE); return MAX(0, pop_cost); } diff --git a/server/unittools.c b/server/unittools.c index ada9e1299c..0c1fccc456 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -4572,7 +4572,7 @@ int get_unit_vision_at(struct unit *punit, const struct tile *ptile, { const int base = (unit_type_get(punit)->vision_radius_sq + get_unittype_bonus(unit_owner(punit), ptile, - unit_type_get(punit), + unit_type_get(punit), NULL, EFT_UNIT_VISION_RADIUS_SQ)); switch (vlayer) { case V_MAIN: -- 2.30.2