Freeciv-3.2
Loading...
Searching...
No Matches
caravan.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <math.h>
19
20/* utility */
21#include "log.h"
22
23/* common */
24#include "game.h"
25#include "traderoutes.h"
26
27/* aicore */
28#include "path_finding.h"
29#include "pf_tools.h"
30
31#include "caravan.h"
32
33/************************************************************************/
37{
38 parameter->horizon = FC_INFINITY;
39 parameter->discount = 0.95;
40 parameter->consider_windfall = TRUE;
41 parameter->consider_trade = TRUE;
42 parameter->consider_wonders = TRUE; /* see also init_from_unit */
45 parameter->ignore_transit_time = FALSE;
46 parameter->convert_trade = FALSE;
47 parameter->callback = NULL;
48}
49
50/************************************************************************/
54 const struct unit *caravan)
55{
58 parameter->consider_trade = FALSE;
59 }
62 parameter->consider_windfall = FALSE;
63 }
65 parameter->consider_wonders = FALSE;
66 }
67}
68
69/************************************************************************/
72bool caravan_parameter_is_legal(const struct caravan_parameter *parameter)
73{
74 /* a discount > 1.0 means money later is worth more than money now,
75 which is ridiculous. */
76 if (parameter->discount > 1.0) {
77 return FALSE;
78 }
79
80 /* a negative discount doesn't converge */
81 if (parameter->discount < 0.0) {
82 return FALSE;
83 }
84
85 /* infinite horizon with no discount gives infinite reward. */
86 if (parameter->horizon == FC_INFINITY && parameter->discount == 1.0) {
87 return FALSE;
88 }
89
90 return TRUE;
91}
92
93/************************************************************************/
96static const char *ftl_name(enum foreign_trade_limit ftl)
97{
98 switch (ftl) {
100 return "no";
101 case FTL_ALLIED:
102 return "allied";
103 case FTL_PEACEFUL:
104 return "peaceful";
105 case FTL_NONWAR:
106 return "anything but enemies";
107 }
108
109 return "<illegal>";
110}
111
112/************************************************************************/
116 enum log_level level, const char *file,
117 const char *function, int line)
118{
119 do_log(file, function, line, FALSE, level,
120 "parameter {\n"
121 " horizon = %d\n"
122 " discount = %g\n"
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"
128 "}\n",
129 parameter->horizon,
130 parameter->discount,
131 parameter->consider_windfall ? "windfall" : "-",
132 parameter->consider_trade ? "trade" : "-",
133 parameter->consider_wonders ? "wonders" : "-",
134 parameter->account_for_broken_routes ? "yes" : "no",
135 ftl_name(parameter->allow_foreign_trade),
136 parameter->ignore_transit_time ? "yes" : "no",
137 parameter->convert_trade ? "yes" : "no");
138}
139
140
141/************************************************************************/
145{
146 result->src = result->dest = NULL;
147 result->arrival_time = 0;
148 result->value = 0;
149 result->help_wonder = FALSE;
150 result->required_boat = FALSE;
151}
152
153/************************************************************************/
157static void caravan_result_init(struct caravan_result *result,
158 const struct city *src,
159 const struct city *dest,
160 int arrival_time)
161{
162 result->src = src;
163 result->dest = dest;
164 result->arrival_time = arrival_time;
165
166 result->value = 0;
167 result->help_wonder = FALSE;
168 /* FIXME: required_boat field is never used. */
169 if ((src != NULL) && (dest != NULL)) {
170 if (tile_continent(src->tile) != tile_continent(dest->tile)) {
171 result->required_boat = TRUE;
172 } else {
173 result->required_boat = FALSE;
174 }
175 } else {
176 result->required_boat = FALSE;
177 }
178}
179
180/************************************************************************/
184 const struct caravan_result *b)
185{
186 if (a->value > b->value) {
187 return 1;
188 } else if (a->value < b->value) {
189 return -1;
190 } else {
191 /* Faster time is better, so reverse-sort on time. */
192 return b->arrival_time - a->arrival_time ;
193 }
194}
195
196/************************************************************************/
204typedef bool (*search_callback) (const struct civ_map *nmap,
205 void *data, const struct city *pcity,
207
208static void caravan_search_from(const struct civ_map *nmap,
209 const struct unit *caravan,
210 const struct caravan_parameter *param,
211 struct tile *start_tile,
213 bool omniscient,
215 void *callback_data)
216{
217 struct pf_map *pfm;
218 struct pf_parameter pfparam;
219 int end_time;
220
221 end_time = param->horizon - turns_before;
222
223 /* Initialize the pf run. */
224 pft_fill_unit_parameter(&pfparam, nmap, (struct unit *) caravan);
225 pfparam.start_tile = start_tile;
226 pfparam.moves_left_initially = moves_left_before;
227 pfparam.omniscience = omniscient;
229
230 /* For every tile in distance order:
231 quit if we've exceeded the maximum number of turns
232 otherwise, run the callback if we're on a city.
233 Do-while loop rather than while loop to make sure to process the
234 start tile.
235 */
237 struct city *pcity;
238
239 if (pos.turn > end_time) {
240 break;
241 }
242
243 pcity = tile_city(pos.tile);
244 if (pcity != NULL
245 && callback(nmap, callback_data, pcity, turns_before + pos.turn,
246 pos.moves_left)) {
247 break;
248 }
250
252}
253
254/************************************************************************/
258static double windfall_benefit(const struct unit *caravan,
259 const struct city *src,
260 const struct city *dest,
261 const struct caravan_parameter *param)
262{
263 if (!param->consider_windfall || !can_cities_trade(src, dest)) {
264 return 0;
265 } else {
267 && can_establish_trade_route(src, dest));
269 unit_type_get(caravan),
271
272 /* when bonus goes to both sci and gold, double it */
274 (cities_trade_route_type(src, dest))->bonus_type) {
275 bonus *= 2;
276 }
277
278 return bonus;
279 }
280}
281
282/****************************************************************************
283 Compute the change in the per-turn trade.
284****************************************************************************/
285
286/************************************************************************/
290static int one_city_trade_benefit(const struct city *pcity,
291 const struct player *pplayer,
292 bool countloser, int newtrade)
293{
294 int losttrade = 0;
295
296 /* if the city is owned by someone else, we don't benefit from the
297 new trade (but we might still lose from a broken trade route) */
298 if (city_owner(pcity) != pplayer) {
299 newtrade = 0;
300 }
301
302 if (city_num_trade_routes(pcity) < max_trade_routes(pcity)) {
303 /* if the city can handle this route, we don't break any old routes */
304 losttrade = 0;
305 } else {
308
309 /* if we own the city, the trade benefit is only by how much
310 better we are than the old trade route */
311 if (city_owner(pcity) == pplayer) {
313 }
314
315 /* if the cities that lost a trade route is one of ours, and if we
316 care about accounting for the lost trade, count it. */
317 if (countloser) {
319 struct city *losercity = game_city_by_number(plost->partner);
320
321 if (city_owner(losercity) == pplayer) {
323 if (pback->partner == pcity->id) {
324 losttrade += pback->value;
325 }
327 }
330 }
331 }
332
333 /* find the increase or decrease in trade we benefit from */
334 return newtrade - losttrade;
335}
336
337/************************************************************************/
342static double trade_benefit(const struct player *caravan_owner,
343 const struct city *src,
344 const struct city *dest,
345 const struct caravan_parameter *param)
346{
347 /* do we care about trade at all? */
348 if (!param->consider_trade) {
349 return 0;
350 }
351
352 /* first, see if a new route is made. */
353 if (!can_cities_trade(src, dest) || !can_establish_trade_route(src, dest)) {
354 return 0;
355 }
356 if (max_trade_routes(src) <= 0 || max_trade_routes(dest) <= 0) {
357 /* Can't create new trade routes even by replacing old ones if
358 * there's no slots at all. */
359 return 0;
360 }
361
362 if (!param->convert_trade) {
364 int newtrade = trade_base_between_cities(src, dest);
365
368 } else {
369 /* Always fails. */
371 "Unimplemented functionality: "
372 "using CM to calculate trade.");
373 return 0;
374 }
375}
376
377/************************************************************************/
384static double wonder_benefit(const struct unit *caravan, int arrival_time,
385 const struct city *dest,
386 const struct caravan_parameter *param)
387{
390
391 if (!param->consider_wonders
392 /* TODO: Should helping an ally to build be considered when legal? */
393 || unit_owner(caravan) != city_owner(dest)
395 /* TODO: Should helping to build a unit be considered when legal? */
396 || VUT_UTYPE == dest->production.kind
397 /* TODO: Should helping to build an improvement be considered when
398 * legal? */
399 || !is_wonder(dest->production.value.building)) {
400 return 0;
401 }
402
404 + arrival_time * dest->surplus[O_SHIELD];
405
410
412 return costwithout - costwith;
413}
414
415/************************************************************************/
419static double presentvalue(double payment, int term, double rate)
420{
421 return payment * pow(rate, term);
422}
423
424/************************************************************************/
428static double perpetuity(double payment, double rate)
429{
430 return payment / (1.0 - rate);
431}
432
433/************************************************************************/
437static double annuity(double payment, int term, double rate)
438{
439 return perpetuity(payment, rate) * (1.0 - 1.0 / pow(rate, term));
440}
441
442/************************************************************************/
445static bool does_foreign_trade_param_allow(const struct caravan_parameter *param,
446 struct player *src, struct player *dest)
447{
448 switch (param->allow_foreign_trade) {
450 return (src == dest);
451 break;
452 case FTL_ALLIED:
453 return pplayers_allied(src, dest);
454 break;
455 case FTL_PEACEFUL:
456 return pplayers_in_peace(src, dest);
457 break;
458 case FTL_NONWAR:
459 return !pplayers_at_war(src, dest);
460 }
461
463 return FALSE;
464}
465
466/************************************************************************/
472static bool get_discounted_reward(const struct unit *caravan,
473 const struct caravan_parameter *parameter,
474 struct caravan_result *result)
475{
476 double trade;
477 double windfall;
478 double wonder;
479 const struct city *src = result->src;
480 const struct city *dest = result->dest;
481 int arrival_time = result->arrival_time;
482 double discount = parameter->discount;
483 struct player *pplayer_src = city_owner(src);
484 struct player *pplayer_dest = city_owner(dest);
485 int cost = unit_build_shield_cost(src, caravan);
486 bool consider_wonder;
487 bool consider_trade;
488 bool consider_windfall;
489 const struct civ_map *nmap = &(wld.map);
490
491 /* If no foreign trade is allowed, just quit. */
494 return FALSE;
495 }
496
500 caravan, src, city_tile(dest),
501 TRUE, dest));
502 consider_trade = parameter->consider_trade
505 caravan, src, city_tile(dest),
506 TRUE, dest));
507 consider_windfall = parameter->consider_windfall
510 caravan, src, city_tile(dest),
511 TRUE, dest));
512
513 if (!consider_wonder && !consider_trade && !consider_windfall) {
514 /* No caravan action is possible against this target. */
516
517 return FALSE;
518 }
519
520 if (consider_wonder) {
521 wonder = wonder_benefit(caravan, arrival_time, dest, parameter);
522 /* we want to aid for wonder building */
523 wonder *= 2;
524
525 wonder = presentvalue(wonder, arrival_time, discount);
526 } else {
527 wonder = -1.0;
528 }
529
530 if (consider_trade) {
531 trade = trade_benefit(pplayer_src, src, dest, parameter);
532 if (parameter->horizon == FC_INFINITY) {
533 trade = perpetuity(trade, discount);
534 } else {
535 trade = annuity(trade, parameter->horizon - arrival_time, discount);
536 }
537 trade = presentvalue(trade, arrival_time, discount);
538 } else {
539 trade = 0.0;
540 }
541
542 if (consider_windfall) {
543 windfall = windfall_benefit(caravan, src, dest, parameter);
544 windfall = presentvalue(windfall, arrival_time, discount);
545 } else {
546 windfall = 0.0;
547 }
548
549 if ((consider_trade
550 || (consider_windfall
551 && (!parameter->consider_trade /* Can only enter marketplaces */
552 /* (FIXME: test any extra restrictions for trade routes) */
553 /* or the result is so big that we are still in plus */
554 /* (consider having produced IF_GOLD instead) */
555 || windfall
557 / MAX(src->surplus[O_SHIELD], 2), discount)))
558 ) && trade + windfall >= wonder) {
559 result->value = trade + windfall;
560 result->help_wonder = FALSE;
561 } else if (consider_wonder) {
562 result->value = wonder;
563 result->help_wonder = TRUE;
564 } else {
566 return FALSE;
567 }
568
569 if (parameter->callback) {
570 parameter->callback(result, parameter->callback_data);
571 }
572
573 return TRUE;
574}
575
576/****************************************************************************
577 Functions to compute the benefit of moving the caravan to dest.
578****************************************************************************/
579
580/************************************************************************/
584static void caravan_evaluate_notransit(const struct unit *caravan,
585 const struct city *dest,
586 const struct caravan_parameter *param,
587 struct caravan_result *result)
588{
589 const struct city *src = game_city_by_number(caravan->homecity);
590
591 caravan_result_init(result, src, dest, 0);
592 get_discounted_reward(caravan, param, result);
593}
594
595/************************************************************************/
599struct cewt_data {
600 const struct unit *caravan;
603};
604
605static bool cewt_callback(const struct civ_map *nmap,
606 void *vdata, const struct city *dest,
607 int arrival_time, int moves_left)
608{
609 struct cewt_data *data = vdata;
610
612
613 if (dest == data->result->dest) {
614 data->result->arrival_time = arrival_time;
615 get_discounted_reward(data->caravan, data->param, data->result);
616 return TRUE;
617 } else {
618 return FALSE;
619 }
620}
621
622/************************************************************************/
626static void caravan_evaluate_withtransit(const struct civ_map *nmap,
627 const struct unit *caravan,
628 const struct city *dest,
629 const struct caravan_parameter *param,
630 struct caravan_result *result,
631 bool omniscient)
632{
633 struct cewt_data data;
634
635 data.caravan = caravan;
636 data.param = param;
638 dest, 0);
639 data.result = result;
641 caravan->moves_left, omniscient, cewt_callback, &data);
642}
643
644/************************************************************************/
647void caravan_evaluate(const struct unit *caravan,
648 const struct city *dest,
649 const struct caravan_parameter *param,
650 struct caravan_result *result, bool omniscient)
651{
652 const struct civ_map *nmap = &(wld.map);
653
654 if (param->ignore_transit_time) {
655 caravan_evaluate_notransit(caravan, dest, param, result);
656 } else {
657 caravan_evaluate_withtransit(nmap, caravan, dest, param, result, omniscient);
658 }
659}
660
661
662/************************************************************************/
665static void caravan_find_best_destination_notransit(const struct unit *caravan,
666 const struct caravan_parameter *param,
667 struct caravan_result *best)
668{
669 struct caravan_result current;
670 struct city *pcity = game_city_by_number(caravan->homecity);
671 struct player *src_owner = city_owner(pcity);
672
673 caravan_result_init(best, pcity, NULL, 0);
674 current = *best;
675
678 city_list_iterate(dest_owner->cities, dest) {
679 caravan_result_init(&current, pcity, dest, 0);
680 if (get_discounted_reward(caravan, param, &current)
681 && caravan_result_compare(&current, best) > 0) {
682 *best = current;
683 }
685 }
687}
688
689/************************************************************************/
695 const struct unit *caravan;
697};
698
699static bool cfbdw_callback(const struct civ_map *nmap,
700 void *vdata, const struct city *dest,
701 int arrival_time, int moves_left)
702{
703 struct cfbdw_data *data = vdata;
704 struct caravan_result current;
705
706 caravan_result_init(&current, data->best->src, dest, arrival_time);
707
708 if (get_discounted_reward(data->caravan, data->param, &current)
709 && caravan_result_compare(&current, data->best) > 0) {
710 *data->best = current;
711 }
712
713 return FALSE; /* Don't stop. */
714}
715
716/************************************************************************/
720 const struct civ_map *nmap,
721 const struct unit *caravan,
722 const struct caravan_parameter *param,
723 const struct city *src,
724 int turns_before,
725 int moves_left,
726 bool omniscient,
727 struct caravan_result *result)
728{
729 struct tile *start_tile;
730 struct cfbdw_data data;
731
732 data.param = param;
733 data.caravan = caravan;
734 data.best = result;
735 caravan_result_init(data.best, src, NULL, 0);
736
737 if (src->id != caravan->homecity) {
738 start_tile = src->tile;
739 } else {
740 start_tile = unit_tile(caravan);
741 }
742
744 caravan->moves_left, omniscient, cfbdw_callback, &data);
745}
746
747/************************************************************************/
753 const struct unit *caravan,
754 const struct caravan_parameter *parameter,
755 struct caravan_result *result, bool omniscient)
756{
757 if (parameter->ignore_transit_time) {
759 } else {
760 const struct city *src = game_city_by_number(caravan->homecity);
761
762 fc_assert(src != NULL);
763
764 caravan_find_best_destination_withtransit(nmap, caravan, parameter, src, 0,
765 caravan->moves_left, omniscient, result);
766 }
767}
768
769/************************************************************************/
772static void caravan_optimize_notransit(const struct unit *caravan,
773 const struct caravan_parameter *param,
774 struct caravan_result *best)
775{
776 struct player *pplayer = unit_owner(caravan);
777
778 /* Iterate over all cities we own (since the caravan could change its
779 * home city); iterate over all cities we know about (places the caravan
780 * can go to); pick out the best trade route. */
781 city_list_iterate(pplayer->cities, src) {
783 if (does_foreign_trade_param_allow(param, pplayer, dest_owner)) {
784 city_list_iterate(dest_owner->cities, dest) {
785 struct caravan_result current;
786
787 caravan_result_init(&current, src, dest, 0);
788 get_discounted_reward(caravan, param, &current);
789 if (caravan_result_compare(&current, best) > 0) {
790 *best = current;
791 }
793 }
796}
797
798/****************************************************************************
799 Struct for the caravan_search invocation in
800 caravan_optimize_withtransit.
801****************************************************************************/
802struct cowt_data {
804 const struct unit *caravan;
807};
808
809/************************************************************************/
816static bool cowt_callback(const struct civ_map *nmap, void *vdata,
817 const struct city *pcity,
818 int arrival_time, int moves_left)
819{
820 struct cowt_data *data = vdata;
821 const struct unit *caravan = data->caravan;
822 struct caravan_result current;
823
825 pcity, arrival_time);
826
827 /* first, see what benefit we'd get from not changing home city */
828 get_discounted_reward(caravan, data->param, &current);
829 if (caravan_result_compare(&current, data->best) > 0) {
830 *data->best = current;
831 }
832
833 /* next, try changing home city (if we're allowed to) */
834 if (city_owner(pcity) == unit_owner(caravan)) {
836 nmap, caravan, data->param, pcity, arrival_time, moves_left, data->omniscient,
837 &current);
838 if (caravan_result_compare(&current, data->best) > 0) {
839 *data->best = current;
840 }
841 }
842
843 return FALSE; /* don't stop searching */
844}
845
846/************************************************************************/
850static void caravan_optimize_withtransit(const struct civ_map *nmap,
851 const struct unit *caravan,
852 const struct caravan_parameter *param,
853 struct caravan_result *result,
854 bool omniscient)
855{
856 struct cowt_data data;
857
858 data.param = param;
859 data.caravan = caravan;
860 data.best = result;
861 data.omniscient = omniscient;
865}
866
867/************************************************************************/
873 const struct caravan_parameter *param,
874 struct caravan_result *result, bool omniscient)
875{
876 const struct civ_map *nmap = &(wld.map);
877
878 if (param->ignore_transit_time) {
879 caravan_optimize_notransit(caravan, param, result);
880 } else {
881 caravan_optimize_withtransit(nmap, caravan, param, result, omniscient);
882 }
883}
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5821
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)
Definition actions.c:5574
static double wonder_benefit(const struct unit *caravan, int arrival_time, const struct city *dest, const struct caravan_parameter *param)
Definition caravan.c:384
static double perpetuity(double payment, double rate)
Definition caravan.c:428
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)
Definition caravan.c:752
static bool does_foreign_trade_param_allow(const struct caravan_parameter *param, struct player *src, struct player *dest)
Definition caravan.c:445
static bool cowt_callback(const struct civ_map *nmap, void *vdata, const struct city *pcity, int arrival_time, int moves_left)
Definition caravan.c:816
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)
Definition caravan.c:208
bool caravan_parameter_is_legal(const struct caravan_parameter *parameter)
Definition caravan.c:72
static void caravan_find_best_destination_notransit(const struct unit *caravan, const struct caravan_parameter *param, struct caravan_result *best)
Definition caravan.c:665
static void caravan_evaluate_notransit(const struct unit *caravan, const struct city *dest, const struct caravan_parameter *param, struct caravan_result *result)
Definition caravan.c:584
static int one_city_trade_benefit(const struct city *pcity, const struct player *pplayer, bool countloser, int newtrade)
Definition caravan.c:290
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)
Definition caravan.c:850
void caravan_result_init_zero(struct caravan_result *result)
Definition caravan.c:144
static bool cewt_callback(const struct civ_map *nmap, void *vdata, const struct city *dest, int arrival_time, int moves_left)
Definition caravan.c:605
static void caravan_optimize_notransit(const struct unit *caravan, const struct caravan_parameter *param, struct caravan_result *best)
Definition caravan.c:772
static double annuity(double payment, int term, double rate)
Definition caravan.c:437
static bool cfbdw_callback(const struct civ_map *nmap, void *vdata, const struct city *dest, int arrival_time, int moves_left)
Definition caravan.c:699
static const char * ftl_name(enum foreign_trade_limit ftl)
Definition caravan.c:96
bool(* search_callback)(const struct civ_map *nmap, void *data, const struct city *pcity, int arrival_turn, int arrival_moves_left)
Definition caravan.c:204
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)
Definition caravan.c:626
int caravan_result_compare(const struct caravan_result *a, const struct caravan_result *b)
Definition caravan.c:183
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)
Definition caravan.c:719
void caravan_parameter_log_real(const struct caravan_parameter *parameter, enum log_level level, const char *file, const char *function, int line)
Definition caravan.c:115
void caravan_evaluate(const struct unit *caravan, const struct city *dest, const struct caravan_parameter *param, struct caravan_result *result, bool omniscient)
Definition caravan.c:647
static bool get_discounted_reward(const struct unit *caravan, const struct caravan_parameter *parameter, struct caravan_result *result)
Definition caravan.c:472
static double trade_benefit(const struct player *caravan_owner, const struct city *src, const struct city *dest, const struct caravan_parameter *param)
Definition caravan.c:342
void caravan_parameter_init_default(struct caravan_parameter *parameter)
Definition caravan.c:36
static double windfall_benefit(const struct unit *caravan, const struct city *src, const struct city *dest, const struct caravan_parameter *param)
Definition caravan.c:258
static double presentvalue(double payment, int term, double rate)
Definition caravan.c:419
void caravan_parameter_init_from_unit(struct caravan_parameter *parameter, const struct unit *caravan)
Definition caravan.c:53
static void caravan_result_init(struct caravan_result *result, const struct city *src, const struct city *dest, int arrival_time)
Definition caravan.c:157
void caravan_optimize_allpairs(const struct unit *caravan, const struct caravan_parameter *param, struct caravan_result *result, bool omniscient)
Definition caravan.c:872
foreign_trade_limit
Definition caravan.h:29
@ FTL_ALLIED
Definition caravan.h:31
@ FTL_NATIONAL_ONLY
Definition caravan.h:30
@ FTL_NONWAR
Definition caravan.h:33
@ FTL_PEACEFUL
Definition caravan.h:32
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1860
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
char * incite_cost
Definition comments.c:75
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
Definition dialogs_g.h:74
@ O_SHIELD
Definition fc_types.h:101
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:107
static struct tile * pos
Definition finddlg.c:53
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,...)
Definition log.c:514
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_level
Definition log.h:28
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)
void pft_fill_unit_parameter(struct pf_parameter *parameter, const struct civ_map *nmap, const struct unit *punit)
Definition pf_tools.c:840
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
bool pplayers_in_peace(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1426
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
bool consider_trade
Definition caravan.h:86
bool consider_windfall
Definition caravan.h:85
void(* callback)(const struct caravan_result *result, void *data)
Definition caravan.h:124
enum foreign_trade_limit allow_foreign_trade
Definition caravan.h:99
bool consider_wonders
Definition caravan.h:87
bool ignore_transit_time
Definition caravan.h:108
double discount
Definition caravan.h:77
bool account_for_broken_routes
Definition caravan.h:93
void * callback_data
Definition caravan.h:125
const struct city * src
Definition caravan.h:52
const struct city * dest
Definition caravan.h:53
int arrival_time
Definition caravan.h:54
bool help_wonder
Definition caravan.h:57
bool required_boat
Definition caravan.h:58
double value
Definition caravan.h:56
const struct unit * caravan
Definition caravan.c:600
const struct caravan_parameter * param
Definition caravan.c:602
struct caravan_result * result
Definition caravan.c:601
struct caravan_result * best
Definition caravan.c:696
const struct unit * caravan
Definition caravan.c:695
const struct caravan_parameter * param
Definition caravan.c:694
Definition city.h:320
int surplus[O_LAST]
Definition city.h:355
int id
Definition city.h:326
struct universal production
Definition city.h:396
int bonus[O_LAST]
Definition city.h:363
struct tile * tile
Definition city.h:322
int shield_stock
Definition city.h:368
const struct caravan_parameter * param
Definition caravan.c:803
struct caravan_result * best
Definition caravan.c:805
const struct unit * caravan
Definition caravan.c:804
bool omniscient
Definition caravan.c:806
struct tile * start_tile
struct city_list * cities
Definition player.h:279
Definition tile.h:50
Definition unit.h:138
int moves_left
Definition unit.h:150
int homecity
Definition unit.h:146
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
struct civ_map map
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define bool
Definition support.h:71
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_continent(_tile)
Definition tile.h:92
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)
Definition traderoutes.c:58
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)
Definition traderoutes.c:48
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)
int get_caravan_enter_city_trade_bonus(const struct city *pc1, const struct city *pc2, const struct unit_type *ut, struct goods_type *pgood, const bool establish_trade)
#define trade_route_list_iterate(trade_route_list, proute)
Definition traderoutes.h:95
#define trade_routes_iterate_end
#define trade_route_list_iterate_end
Definition traderoutes.h:97
#define trade_routes_iterate(c, proute)
const struct impr_type * building
Definition fc_types.h:714
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:359
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int unit_build_shield_cost(const struct city *pcity, const struct unit *punit)
Definition unittype.c:1476
int unit_build_shield_cost_base(const struct unit *punit)
Definition unittype.c:1484