Project

General

Profile

Feature #620 ยป 0005-Pass-briber-unit-to-Unit_Bribe_Cost_Pct-effects-as-o.patch

main - Alina Lenk, 05/15/2024 07:45 PM

View differences:

ai/default/aidiplomat.c
}
/* Should we make the expense? */
cost = unit_bribe_cost(pvictim, pplayer);
cost = unit_bribe_cost(pvictim, pplayer, punit);
if (!threat) {
/* Don't empty our treasure without good reason! */
gold_avail = pplayer->economic.gold - dai_gold_reserve(pplayer);
client/text.c
if (owner == plr || client_is_global_observer()) {
/* Show bribe cost for own units. */
astr_add_line(&str, _("Probable bribe cost: %d"),
unit_bribe_cost(punit, nullptr));
unit_bribe_cost(punit, nullptr, nullptr));
} else {
/* We can only give an (lower) boundary for units of other players. */
astr_add_line(&str, _("Estimated bribe cost: > %d"),
unit_bribe_cost(punit, plr));
unit_bribe_cost(punit, plr, nullptr));
}
if ((plr == nullptr || owner == plr)
common/unit.c
unit. For a damaged unit the price is reduced. For a veteran unit, it is
increased.
@param punit Unit to bribe
@param briber Player that wants to bribe
@return Bribe cost
@param punit Unit to bribe
@param briber Player that wants to bribe
@param briber_unit Unit that does the bribing
@return Bribe cost
**************************************************************************/
int unit_bribe_cost(struct unit *punit, struct player *briber)
int unit_bribe_cost(const struct unit *punit, const struct player *briber,
const struct unit *briber_unit)
{
int cost, default_hp;
struct tile *ptile = unit_tile(punit);
......
cost *= unit_build_shield_cost_base(punit) / 10.0;
/* Rule set specific cost modification */
cost += (cost
* get_target_bonus_effects(NULL,
&(const struct req_context) {
.player = owner,
.city = game_city_by_number(
punit->homecity
),
.tile = ptile,
.unit = punit,
.unittype = ptype,
},
&(const struct req_context) {
.player = briber,
},
EFT_UNIT_BRIBE_COST_PCT))
cost += (cost * get_target_bonus_effects(NULL,
&(const struct req_context) {
.player = owner,
.city = game_city_by_number(punit->homecity),
.tile = ptile,
.unit = punit,
.unittype = ptype,
},
&(const struct req_context) {
.player = briber,
.unit = briber_unit,
.unittype = briber_unit ? unit_type_get(briber_unit)
: nullptr,
.tile = briber_unit ? unit_tile(briber_unit)
: nullptr,
.city = briber_unit
? game_city_by_number(briber_unit->homecity)
: nullptr,
},
EFT_UNIT_BRIBE_COST_PCT))
/ 100;
/* Veterans are not cheap. */
common/unit.h
void unit_set_ai_data(struct unit *punit, const struct ai_type *ai,
void *data);
int unit_bribe_cost(struct unit *punit, struct player *briber);
int unit_bribe_cost(const struct unit *punit, const struct player *briber,
const struct unit *briber_unit);
bool unit_transport_load(struct unit *pcargo, struct unit *ptrans,
bool force);
server/diplomats.c
log_debug("bribe-unit: unit: %d", pdiplomat->id);
/* Get bribe cost, ignoring any previously saved value. */
bribe_cost = unit_bribe_cost(pvictim, pplayer);
bribe_cost = unit_bribe_cost(pvictim, pplayer, pdiplomat);
/* If player doesn't have enough gold, can't bribe. */
if (pplayer->economic.gold < bribe_cost) {
server/unithand.c
pactor, punit)) {
dsend_packet_unit_action_answer(pc,
actor_id, target_id,
unit_bribe_cost(punit, pplayer),
unit_bribe_cost(punit, pplayer,
pactor),
action_type, request_kind);
} else {
illegal_action(pplayer, pactor, action_type,
    (1-1/1)