54 const struct unit *caravan)
106 return "anything but enemies";
117 const char *function,
int line)
123 " objective = <%s,%s,%s>\n"
124 " account-broken = %s\n"
125 " allow-foreign = %s\n"
126 " ignore-transit = %s\n"
127 " convert-trade = %s\n"
146 result->
src = result->
dest = NULL;
158 const struct city *src,
159 const struct city *dest,
169 if ((src != NULL) && (dest != NULL)) {
205 void *data,
const struct city *pcity,
206 int arrival_turn,
int arrival_moves_left);
209 const struct unit *caravan,
211 struct tile *start_tile,
212 int turns_before,
int moves_left_before,
221 end_time = param->
horizon - turns_before;
239 if (
pos.turn > end_time) {
245 &&
callback(nmap, callback_data, pcity, turns_before +
pos.turn,
259 const struct city *src,
260 const struct city *dest,
290 const struct player *pplayer,
291 bool countloser,
int newtrade)
305 struct trade_route_list *would_remove = (countloser ? trade_route_list_new() : NULL);
311 newtrade -= oldtrade;
322 if (pback->partner == pcity->
id) {
323 losttrade += pback->value;
328 trade_route_list_destroy(would_remove);
333 return newtrade - losttrade;
342 const struct city *src,
343 const struct city *dest,
370 "Unimplemented functionality: "
371 "using CM to calculate trade.");
384 const struct city *dest,
387 int costwithout, costwith;
388 int shields_at_arrival;
411 return costwithout - costwith;
420 return payment * pow(rate, term);
429 return payment / (1.0 - rate);
436static double annuity(
double payment,
int term,
double rate)
438 return perpetuity(payment, rate) * (1.0 - 1.0 / pow(rate, term));
449 return (src == dest);
478 const struct city *src = result->
src;
479 const struct city *dest = result->
dest;
481 double discount = parameter->
discount;
485 bool consider_wonder;
487 bool consider_windfall;
512 if (!consider_wonder && !consider_trade && !consider_windfall) {
519 if (consider_wonder) {
529 if (consider_trade) {
534 trade =
annuity(trade, parameter->
horizon - arrival_time, discount);
541 if (consider_windfall) {
543 windfall =
presentvalue(windfall, arrival_time, discount);
549 || (consider_windfall
557 ) && trade + windfall >= wonder) {
558 result->
value = trade + windfall;
560 }
else if (consider_wonder) {
561 result->
value = wonder;
584 const struct city *dest,
605 void *vdata,
const struct city *dest,
606 int arrival_time,
int moves_left)
627 const struct city *dest,
647 const struct city *dest,
699 void *vdata,
const struct city *
dest,
709 *data->
best = current;
720 const struct unit *caravan,
728 struct tile *start_tile;
737 start_tile = src->
tile;
816 const struct city *pcity,
829 *data->
best = current;
838 *data->
best = current;
850 const struct unit *caravan,
bool action_prob_possible(const struct act_prob probability)
struct act_prob action_speculate_unit_on_city(const struct civ_map *nmap, const action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, const bool omniscient_cheat, const struct city *target)
static double wonder_benefit(const struct unit *caravan, int arrival_time, const struct city *dest, const struct caravan_parameter *param)
static double perpetuity(double payment, double rate)
void caravan_find_best_destination(const struct civ_map *nmap, const struct unit *caravan, const struct caravan_parameter *parameter, struct caravan_result *result, bool omniscient)
static bool does_foreign_trade_param_allow(const struct caravan_parameter *param, struct player *src, struct player *dest)
static bool cowt_callback(const struct civ_map *nmap, void *vdata, const struct city *pcity, int arrival_time, int moves_left)
static void caravan_search_from(const struct civ_map *nmap, const struct unit *caravan, const struct caravan_parameter *param, struct tile *start_tile, int turns_before, int moves_left_before, bool omniscient, search_callback callback, void *callback_data)
bool caravan_parameter_is_legal(const struct caravan_parameter *parameter)
static void caravan_find_best_destination_notransit(const struct unit *caravan, const struct caravan_parameter *param, struct caravan_result *best)
static void caravan_evaluate_notransit(const struct unit *caravan, const struct city *dest, const struct caravan_parameter *param, struct caravan_result *result)
static int one_city_trade_benefit(const struct city *pcity, const struct player *pplayer, bool countloser, int newtrade)
static void caravan_optimize_withtransit(const struct civ_map *nmap, const struct unit *caravan, const struct caravan_parameter *param, struct caravan_result *result, bool omniscient)
void caravan_result_init_zero(struct caravan_result *result)
static bool cewt_callback(const struct civ_map *nmap, void *vdata, const struct city *dest, int arrival_time, int moves_left)
static void caravan_optimize_notransit(const struct unit *caravan, const struct caravan_parameter *param, struct caravan_result *best)
static double annuity(double payment, int term, double rate)
static bool cfbdw_callback(const struct civ_map *nmap, void *vdata, const struct city *dest, int arrival_time, int moves_left)
static const char * ftl_name(enum foreign_trade_limit ftl)
bool(* search_callback)(const struct civ_map *nmap, void *data, const struct city *pcity, int arrival_turn, int arrival_moves_left)
static void caravan_evaluate_withtransit(const struct civ_map *nmap, const struct unit *caravan, const struct city *dest, const struct caravan_parameter *param, struct caravan_result *result, bool omniscient)
int caravan_result_compare(const struct caravan_result *a, const struct caravan_result *b)
static void caravan_find_best_destination_withtransit(const struct civ_map *nmap, const struct unit *caravan, const struct caravan_parameter *param, const struct city *src, int turns_before, int moves_left, bool omniscient, struct caravan_result *result)
void caravan_parameter_log_real(const struct caravan_parameter *parameter, enum log_level level, const char *file, const char *function, int line)
void caravan_evaluate(const struct unit *caravan, const struct city *dest, const struct caravan_parameter *param, struct caravan_result *result, bool omniscient)
static bool get_discounted_reward(const struct unit *caravan, const struct caravan_parameter *parameter, struct caravan_result *result)
static double trade_benefit(const struct player *caravan_owner, const struct city *src, const struct city *dest, const struct caravan_parameter *param)
void caravan_parameter_init_default(struct caravan_parameter *parameter)
static double windfall_benefit(const struct unit *caravan, const struct city *src, const struct city *dest, const struct caravan_parameter *param)
static double presentvalue(double payment, int term, double rate)
void caravan_parameter_init_from_unit(struct caravan_parameter *parameter, const struct unit *caravan)
static void caravan_result_init(struct caravan_result *result, const struct city *src, const struct city *dest, int arrival_time)
void caravan_optimize_allpairs(const struct unit *caravan, const struct caravan_parameter *param, struct caravan_result *result, bool omniscient)
bool city_production_gets_caravan_shields(const struct universal *tgt)
#define city_list_iterate(citylist, pcity)
#define city_tile(_pcity_)
#define city_owner(_pcity_)
#define city_list_iterate_end
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
struct city * game_city_by_number(int id)
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
bool is_wonder(const struct impr_type *pimprove)
void do_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, const char *message,...)
#define fc_assert_msg(condition, message,...)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
void pf_map_destroy(struct pf_map *pfm)
#define pf_map_positions_iterate_end
#define pf_map_positions_iterate(ARG_pfm, NAME_pos, COND_from_start)
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
#define players_iterate_end
#define players_iterate(_pplayer)
struct setting_list * level[OLEVELS_NUM]
void(* callback)(const struct caravan_result *result, void *data)
enum foreign_trade_limit allow_foreign_trade
bool account_for_broken_routes
const struct unit * caravan
const struct caravan_parameter * param
struct caravan_result * result
struct caravan_result * best
const struct unit * caravan
const struct caravan_parameter * param
struct universal production
const struct caravan_parameter * param
struct caravan_result * best
const struct unit * caravan
struct city_list * cities
struct city * tile_city(const struct tile *ptile)
#define tile_continent(_tile)
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
int city_num_trade_routes(const struct city *pcity)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
unsigned max_trade_routes(const struct city *pcity)
int get_caravan_enter_city_trade_bonus(const struct city *pc1, const struct city *pc2, struct goods_type *pgood, const bool establish_trade)
int city_trade_removable(const struct city *pcity, struct trade_route_list *would_remove)
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
#define trade_route_list_iterate(trade_route_list, proute)
#define trade_routes_iterate_end
#define trade_route_list_iterate_end
#define trade_routes_iterate(c, proute)
const struct impr_type * building
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
int unit_build_shield_cost(const struct city *pcity, const struct unit *punit)
int unit_build_shield_cost_base(const struct unit *punit)