From 26178f51ea92a5194452b73bec3b855d218c087d Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 11 May 2021 12:18:46 +0200 Subject: [PATCH 9/9] Support action specific Attack_Bonus effects. Make it possible to have an Attack_Bonus effect value based on what attack action is being used by having it accept Action requirements. See osdn #42230 --- ai/default/daimilitary.c | 2 +- common/combat.c | 7 ++++--- common/combat.h | 3 ++- doc/README.effects | 3 ++- server/unithand.c | 2 +- server/unittools.c | 4 ++-- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index 3029a10c94..ac301fb20f 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -96,7 +96,7 @@ struct unit_type *dai_choose_defender_versus(struct city *pcity, defender = unit_virtual_create(pplayer, pcity, punittype, veteran); defense = get_total_defense_power(attacker, defender); - attack = get_total_attack_power(attacker, defender); + attack = get_total_attack_power(attacker, defender, NULL); get_modified_firepower(attacker, defender, &fpatt, &fpdef); /* Greg's algorithm. loss is the average number of health lost by diff --git a/common/combat.c b/common/combat.c index dfbd330503..4f66d834fa 100644 --- a/common/combat.c +++ b/common/combat.c @@ -468,7 +468,7 @@ double unit_win_chance(const struct unit *attacker, const struct action *paction) { int def_power = get_total_defense_power(attacker, defender); - int att_power = get_total_attack_power(attacker, defender); + int att_power = get_total_attack_power(attacker, defender, paction); double chance; @@ -591,13 +591,14 @@ static int get_defense_power(const struct unit *punit) Return the modified attack power of a unit. ***********************************************************************/ int get_total_attack_power(const struct unit *attacker, - const struct unit *defender) + const struct unit *defender, + const struct action *paction) { int mod; int attackpower = get_attack_power(attacker); mod = 100 + get_unittype_bonus(unit_owner(attacker), unit_tile(defender), - unit_type_get(attacker), NULL, + unit_type_get(attacker), paction, EFT_ATTACK_BONUS); return attackpower * mod / 100; diff --git a/common/combat.h b/common/combat.h index 19030cda3e..483f582939 100644 --- a/common/combat.h +++ b/common/combat.h @@ -85,7 +85,8 @@ int get_virtual_defense_power(const struct unit_type *attacker, struct tile *ptile, bool fortified, int veteran); int get_total_attack_power(const struct unit *attacker, - const struct unit *defender); + const struct unit *defender, + const struct action *paction); struct unit *get_defender(const struct unit *attacker, const struct tile *ptile, diff --git a/doc/README.effects b/doc/README.effects index bc2a910839..8db5c5b5bd 100644 --- a/doc/README.effects +++ b/doc/README.effects @@ -456,7 +456,8 @@ Defend_Bonus Attack_Bonus Increases offensive bonuses of units. Unit requirements on this effect are - the attacking unit itself. + the attacking unit itself. Can be limited to only apply to some actions + via an Action requirement. Fortify_Defense_Bonus Percentage defense bonus multiplicative with Defend_Bonus, usually given diff --git a/server/unithand.c b/server/unithand.c index 21396221f9..d76b6c0cd8 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -4478,7 +4478,7 @@ static bool do_attack(struct unit *punit, struct tile *def_tile, att_hp_start = punit->hp; def_hp_start = pdefender->hp; def_power = get_total_defense_power(punit, pdefender); - att_power = get_total_attack_power(punit, pdefender); + att_power = get_total_attack_power(punit, pdefender, paction); get_modified_firepower(punit, pdefender, &att_fp, &def_fp); log_debug("Start attack: %s %s against %s %s.", diff --git a/server/unittools.c b/server/unittools.c index 3a3b5c17ff..a2cb9c8d2e 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -277,7 +277,7 @@ void unit_versus_unit(struct unit *attacker, struct unit *defender, int *att_hp, int *def_hp, const struct action *paction) { - int attackpower = get_total_attack_power(attacker, defender); + int attackpower = get_total_attack_power(attacker, defender, paction); int defensepower = get_total_defense_power(attacker, defender); int attack_firepower, defense_firepower; struct player *plr1 = unit_owner(attacker); @@ -333,7 +333,7 @@ void unit_bombs_unit(struct unit *attacker, struct unit *defender, int i; int rate = unit_type_get(attacker)->bombard_rate; - int attackpower = get_total_attack_power(attacker, defender); + int attackpower = get_total_attack_power(attacker, defender, paction); int defensepower = get_total_defense_power(attacker, defender); int attack_firepower, defense_firepower; struct player *plr1 = unit_owner(attacker); -- 2.30.2