From 24e87ec0d4762b6aac5d85a5635124c3e3865eb4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 9 Sep 2021 17:25:05 +0300 Subject: [PATCH 27/27] get_potential_improvement_bonus(): Consider multipliers See osdn #42836 Signed-off-by: Marko Lindqvist --- common/effects.c | 28 ++++++++++++++++++++++------ common/effects.h | 3 ++- common/improvement.c | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/common/effects.c b/common/effects.c index c66ab6716f..043ae69cbe 100644 --- a/common/effects.c +++ b/common/effects.c @@ -1035,8 +1035,9 @@ int get_current_construction_bonus(const struct city *pcity, if (VUT_IMPROVEMENT == pcity->production.kind) { return get_potential_improvement_bonus(pcity->production.value.building, - pcity, effect_type, prob_type); + pcity, effect_type, prob_type, TRUE); } + return 0; } @@ -1049,11 +1050,17 @@ int get_current_construction_bonus(const struct city *pcity, int get_potential_improvement_bonus(const struct impr_type *pimprove, const struct city *pcity, enum effect_type effect_type, - const enum req_problem_type prob_type) + const enum req_problem_type prob_type, + bool consider_multipliers) { struct universal source = { .kind = VUT_IMPROVEMENT, .value = {.building = pimprove}}; struct effect_list *plist = get_req_source_effects(&source); + struct player *owner = NULL; + + if (pcity != NULL) { + owner = city_owner(pcity); + } if (plist) { int power = 0; @@ -1073,25 +1080,34 @@ int get_potential_improvement_bonus(const struct impr_type *pimprove, continue; } - if (!is_req_active(city_owner(pcity), NULL, pcity, pimprove, + if (!is_req_active(owner, NULL, pcity, pimprove, NULL, NULL, NULL, NULL, NULL, NULL, preq, prob_type)) { useful = FALSE; break; - } + } } requirement_vector_iterate_end; if (useful) { + int val; + if (present) { - power += peffect->value; + val = peffect->value; } else { - power -= peffect->value; + val = -peffect->value; } + + if (consider_multipliers && peffect->multiplier) { + val = val * player_multiplier_effect_value(owner, peffect->multiplier) / 100; + } + + power += val; } } effect_list_iterate_end; return power; } + return 0; } diff --git a/common/effects.h b/common/effects.h index 4cb5d84317..f547d26661 100644 --- a/common/effects.h +++ b/common/effects.h @@ -467,7 +467,8 @@ int get_current_construction_bonus(const struct city *pcity, int get_potential_improvement_bonus(const struct impr_type *pimprove, const struct city *pcity, enum effect_type effect_type, - const enum req_problem_type prob_type); + const enum req_problem_type prob_type, + bool consider_multipliers); struct effect_list *get_effects(enum effect_type effect_type); diff --git a/common/improvement.c b/common/improvement.c index 3b04de355f..a7cd835ca8 100644 --- a/common/improvement.c +++ b/common/improvement.c @@ -593,7 +593,7 @@ static bool improvement_has_effects(const struct city *pcity, effect_list_iterate(plist, peffect) { if (0 != get_potential_improvement_bonus(pimprove, pcity, - peffect->type, RPT_CERTAIN)) { + peffect->type, RPT_CERTAIN, TRUE)) { return TRUE; } } effect_list_iterate_end; -- 2.33.0