From 2c949e3afc3ee8e74662e1dbfc6a95bab8103964 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 11 May 2021 13:07:53 +0200 Subject: [PATCH 7/7] get_diplomatic_defender(): take action parameter. Make get_diplomatic_defender() aware of what action is being performed. See osdn #42228 --- common/actions.c | 18 ++++++++++++------ common/combat.c | 3 ++- common/combat.h | 3 ++- server/diplomats.c | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/common/actions.c b/common/actions.c index cab339aa91..aff00e0161 100644 --- a/common/actions.c +++ b/common/actions.c @@ -5315,7 +5315,8 @@ static struct act_prob ap_dipl_battle_win(const struct unit *pattacker, **************************************************************************/ static struct act_prob ap_diplomat_battle(const struct unit *pattacker, const struct unit *pvictim, - const struct tile *tgt_tile) + const struct tile *tgt_tile, + const struct action *paction) { struct unit *pdefender; @@ -5327,7 +5328,8 @@ static struct act_prob ap_diplomat_battle(const struct unit *pattacker, return ACTPROB_NOT_KNOWN; } - pdefender = get_diplomatic_defender(pattacker, pvictim, tgt_tile); + pdefender = get_diplomatic_defender(pattacker, pvictim, tgt_tile, + paction); if (pdefender) { /* There will be a diplomatic battle in stead of an action. */ @@ -5407,7 +5409,8 @@ action_prob_battle_then_dice_roll(const struct player *act_player, /* No pre action battle. */ break; case ABK_DIPLOMATIC: - battle = ap_diplomat_battle(act_unit, tgt_unit, tgt_tile); + battle = ap_diplomat_battle(act_unit, tgt_unit, tgt_tile, + paction); break; case ABK_STANDARD: /* Not supported here yet. Implement when users appear. */ @@ -5527,15 +5530,18 @@ action_prob(const action_id wanted_action, break; case ACTRES_SPY_SABOTAGE_UNIT: /* All uncertainty comes from potential diplomatic battles. */ - chance = ap_diplomat_battle(actor_unit, target_unit, target_tile); + chance = ap_diplomat_battle(actor_unit, target_unit, target_tile, + paction); break; case ACTRES_SPY_BRIBE_UNIT: /* All uncertainty comes from potential diplomatic battles. */ - chance = ap_diplomat_battle(actor_unit, target_unit, target_tile); + chance = ap_diplomat_battle(actor_unit, target_unit, target_tile, + paction); break; case ACTRES_SPY_ATTACK: /* All uncertainty comes from potential diplomatic battles. */ - chance = ap_diplomat_battle(actor_unit, NULL, target_tile); + chance = ap_diplomat_battle(actor_unit, NULL, target_tile, + paction); break; case ACTRES_SPY_SABOTAGE_CITY: /* TODO */ diff --git a/common/combat.c b/common/combat.c index b3d4bd4dd2..9ebe2ba00d 100644 --- a/common/combat.c +++ b/common/combat.c @@ -897,7 +897,8 @@ struct unit *get_attacker(const struct unit *defender, **************************************************************************/ struct unit *get_diplomatic_defender(const struct unit *act_unit, const struct unit *pvictim, - const struct tile *tgt_tile) + const struct tile *tgt_tile, + const struct action *paction) { fc_assert_ret_val(act_unit, NULL); fc_assert_ret_val(tgt_tile, NULL); diff --git a/common/combat.h b/common/combat.h index abf3db3eb4..2c68b37424 100644 --- a/common/combat.h +++ b/common/combat.h @@ -94,7 +94,8 @@ struct unit *get_attacker(const struct unit *defender, struct unit *get_diplomatic_defender(const struct unit *act_unit, const struct unit *pvictim, - const struct tile *tgt_tile); + const struct tile *tgt_tile, + const struct action *paction); bool is_stack_vulnerable(const struct tile *ptile); diff --git a/server/diplomats.c b/server/diplomats.c index e7c1223ced..6d027739a1 100644 --- a/server/diplomats.c +++ b/server/diplomats.c @@ -1984,7 +1984,8 @@ static bool diplomat_infiltrate_tile(struct player *pplayer, sz_strlcpy(link_city, city_link(pcity)); } - if ((punit = get_diplomatic_defender(pdiplomat, pvictim, ptile))) { + if ((punit = get_diplomatic_defender(pdiplomat, pvictim, ptile, + paction))) { struct player *uplayer = unit_owner(punit); if (defender_owner != NULL) { -- 2.30.2