Project

General

Profile

Bug #2179 » 2179_Main.patch

Dean Brown, 10/19/2026 02:41 AM

View differences:

ai/default/daiunit.c
/* We are moving to our destination */
/* We check to see if our current goal is feasible */
struct city *city_dest = tile_city(punit->goto_tile);
struct goods_type *pgood = unit_current_goods(punit, homecity);
int priority = unit_current_good_replace_priority(punit, homecity);
if ((city_dest == nullptr)
|| !pplayers_allied(unit_owner(punit), city_dest->owner)
|| (unit_data->task == AIUNIT_TRADE
&& !(can_cities_trade(homecity, city_dest)
&& can_establish_trade_route(homecity, city_dest,
pgood->replace_priority)))
priority)))
|| (unit_data->task == AIUNIT_WONDER
/* Helping the (new) production is illegal. */
&& !city_production_gets_caravan_shields(&city_dest->production))
client/gui-sdl2/menu.c
unit_type_get(punit),
punit->carrying,
TRUE);
struct goods_type *pgood = unit_current_goods(punit, homecity);
int priority = unit_current_good_replace_priority(punit, homecity);
if (can_establish_trade_route(homecity, pcity, pgood->replace_priority)) {
if (can_establish_trade_route(homecity, pcity, priority)) {
fc_snprintf(cbuf, sizeof(cbuf),
_("%s With %s ( %d one time bonus + %d trade ) (R)"),
action_id_name_translation(ACTION_TRADE_ROUTE),
client/gui-sdl3/menu.c
unit_type_get(punit),
punit->carrying,
TRUE);
struct goods_type *pgood = unit_current_goods(punit, homecity);
int priority = unit_current_good_replace_priority(punit, homecity);
if (can_establish_trade_route(homecity, pcity, pgood->replace_priority)) {
if (can_establish_trade_route(homecity, pcity, priority)) {
fc_snprintf(cbuf, sizeof(cbuf),
_("%s With %s ( %d one time bonus + %d trade ) (R)"),
action_id_name_translation(ACTION_TRADE_ROUTE),
client/text.c
struct city *hcity = game_city_by_number(pfocus_unit->homecity);
if (utype_can_do_action(unit_type_get(pfocus_unit), ACTION_TRADE_ROUTE)
&& can_cities_trade(hcity, pcity)
&& can_establish_trade_route(hcity, pcity,
unit_current_goods(pfocus_unit,
hcity)->replace_priority)) {
/* TRANS: "Trade from Warsaw: 5" */
astr_add_line(&str, _("Trade from %s: %d"),
city_name_get(hcity),
trade_base_between_cities(hcity, pcity));
&& can_cities_trade(hcity, pcity)) {
int priority = unit_current_good_replace_priority(pfocus_unit, hcity);
if (can_establish_trade_route(hcity, pcity, priority)) {
/* TRANS: "Trade from Warsaw: 5" */
astr_add_line(&str, _("Trade from %s: %d"),
city_name_get(hcity),
trade_base_between_cities(hcity, pcity));
}
}
} unit_list_iterate_end;
}
common/actres.c
/* There are more restrictions on establishing a trade route than on
* entering the market place. */
if (result == ACTRES_TRADE_ROUTE) {
struct goods_type *pgood = unit_current_goods(actor->unit, homecity);
int priority =
unit_current_good_replace_priority(actor->unit, homecity);
if (!can_establish_trade_route(homecity, target->city,
pgood->replace_priority)) {
if (!can_establish_trade_route(homecity, target->city, priority)) {
return TRI_NO;
}
}
common/aicore/caravan.c
pf_map_destroy(pfm);
}
/**********************************************************************//**
Return the replace_priority of the goods a city would provide.
May return -1 if city can't provide any goods.
@param src City to start traderoute from
@return the goods's replace_priority, maybe -1
**************************************************************************/
static int city_current_good_replace_priority(const struct city *pcity)
{
struct goods_type *pgoods = goods_from_city_to_unit(pcity, nullptr);
return pgoods != nullptr ? pgoods->replace_priority : -1;
}
/************************************************************************//**
When the caravan arrives, compute the benefit from the immediate windfall,
taking into account the parameter's objective.
......
static double windfall_benefit(const struct unit *caravan,
const struct city *src,
const struct city *dest,
const struct goods_type *pgood,
const struct caravan_parameter *param)
{
if (!param->consider_windfall || !can_cities_trade(src, dest)) {
return 0;
} else {
bool can_establish = (unit_can_do_action(caravan, ACTION_TRADE_ROUTE)
&& can_establish_trade_route(src, dest,
pgood->replace_priority));
int priority =
city_current_good_replace_priority(src);
bool can_establish = unit_can_do_action(caravan, ACTION_TRADE_ROUTE)
&& can_establish_trade_route(src, dest, priority);
int bonus = get_caravan_enter_city_trade_bonus(src, dest,
unit_type_get(caravan),
nullptr, can_establish);
......
****************************************************************************/
static int one_city_trade_benefit(const struct city *pcity,
const struct player *pplayer,
const struct goods_type *pgood,
bool countloser, int newtrade)
{
int losttrade = 0;
......
/* If the city can handle this route, we don't break any old routes */
losttrade = 0;
} else {
int priority = city_current_good_replace_priority(pcity);
struct trade_route_list *would_remove
= (countloser ? trade_route_list_new() : nullptr);
int oldtrade = city_trade_removable(pcity, pgood->replace_priority,
would_remove);
int oldtrade = city_trade_removable(pcity, priority, would_remove);
/* If we own the city, the trade benefit is only by how much
better we are than the old trade route */
......
static double trade_benefit(const struct player *caravan_owner,
const struct city *src,
const struct city *dest,
const struct goods_type *pgood,
const struct caravan_parameter *param)
{
/* Do we care about trade at all? */
......
/* First, see if a new route is made. */
if (!can_cities_trade(src, dest)
|| !can_establish_trade_route(src, dest, pgood->replace_priority)) {
|| !can_establish_trade_route(src, dest,
city_current_good_replace_priority(src))) {
return 0;
}
if (max_trade_routes(src) <= 0 || max_trade_routes(dest) <= 0) {
......
bool countloser = param->account_for_broken_routes;
int newtrade = trade_base_between_cities(src, dest);
return one_city_trade_benefit(src, caravan_owner, pgood,
countloser, newtrade)
+ one_city_trade_benefit(dest, caravan_owner, pgood,
countloser, newtrade);
return one_city_trade_benefit(src, caravan_owner, countloser, newtrade)
+ one_city_trade_benefit(dest, caravan_owner, countloser, newtrade);
} else {
/* Always fails. */
fc_assert_msg(!param->convert_trade,
......
bool consider_wonder;
bool consider_trade;
bool consider_windfall;
struct goods_type *pgood;
const struct civ_map *nmap = &(wld.map);
/* If no foreign trade is allowed, just quit. */
......
wonder = -1.0;
}
pgood = goods_from_city_to_unit(src, nullptr);
if (consider_trade) {
trade = trade_benefit(pplayer_src, src, dest, pgood, parameter);
trade = trade_benefit(pplayer_src, src, dest, parameter);
if (parameter->horizon == FC_INFINITY) {
trade = perpetuity(trade, discount);
} else {
......
}
if (consider_windfall) {
windfall = windfall_benefit(caravan, src, dest, pgood, parameter);
windfall = windfall_benefit(caravan, src, dest, parameter);
windfall = presentvalue(windfall, arrival_time, discount);
} else {
windfall = 0.0;
common/traderoutes.c
}
/*********************************************************************//**
Fond out goods type for the new trade route
Return goods type for the new trade route.
May return nullptr if city can't provide any goods.
@param src City to start traderoute from
@param punit Unit to carry the goods
@return Goods to carry
@return Goods to carry, may be nullptr
*************************************************************************/
struct goods_type *goods_from_city_to_unit(const struct city *src,
const struct unit *punit)
......
/*********************************************************************//**
What goods unit would provide if it established trade route now?
May return nullptr if city can't provide any goods.
@param punit Unit to establish the trade route
@param homecity Homecity of the unit. Can be used speculatively.
@return What good unit would provide
@return What good unit would provide, may be nullptr
*************************************************************************/
struct goods_type *unit_current_goods(const struct unit *punit,
const struct city *homecity)
common/unit.c
return utype_upkeep_cost(unit_type_get(punit), punit, unit_owner(punit),
otype);
}
/**********************************************************************//**
Returns the unit's *pgood's replace_priority, or -1 if pgood is nullptr
**************************************************************************/
int unit_current_good_replace_priority(const struct unit *punit,
const struct city *homecity)
{
struct goods_type *pgoods = unit_current_goods(punit, homecity);
return pgoods != nullptr ? pgoods->replace_priority : -1;
}
common/unit.h
enum gen_action activity_default_action(enum unit_activity act);
int unit_current_good_replace_priority(const struct unit *punit,
const struct city *homecity);
#ifdef __cplusplus
}
#endif /* __cplusplus */
(2-2/2)