Freeciv21
Develop your civilization from humble roots to a global empire
caravan.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
20 };
21 
37  const struct city *src;
38  const struct city *dest;
40 
41  double value;
43 };
44 
46  /*
47  * How many turns to consider when optimizing.
48  */
49  int horizon;
50 
51  /*
52  * Discount factor (that is, 1 / interest rate).
53  * The worth of a trade route is equivalent to:
54  * sum_{i=0}^{horizon} value in i turns * discount^i
55  * The discount should be in (0..1].
56  * A discount of 1 means future earnings are worth the same as immediate
57  * earnings. A discount of .95 means a dollar next turn is worth only 95
58  * cents today; or, in other words, 95 cents in the bank today would yield
59  * a dollar next turn.
60  */
61  double discount;
62 
63  /*
64  * What to consider:
65  * - the immediate windfall when the caravan reaches destination
66  * - the trade
67  * - the reduction in cost of helping build a wonder
68  */
72 
73  /*
74  * A new trade route may break old routes.
75  * Account for the loss of old routes.
76  */
78 
79  /*
80  * Allow trading with allies and peaceful neighbours.
81  * BUG: currently we only consider allies.
82  */
84 
85  /*
86  * Normally, we'd want to compute the time it takes to establish the
87  * trade route.
88  * There are two reasons to ignore the transit time:
89  * (1) it may be infinite (i.e. requires crossing an ocean)
90  * (2) it's slow to compute it.
91  */
93 
94  /*
95  * The 'effect of trade' can be computed exactly by an expensive
96  * calculation which will take into account buildings, national budget,
97  * etc; or by a cheap calculation that just says that each trade is worth
98  * one science or gold.
99  */
101 
102  /*
103  * This callback, if non-null, is called whenever a trade route
104  * is evaluated. One intended usage is for collecting all the
105  * trade routes into a sorted list.
106  * Note that the result must be copied to be stored.
107  */
108  void (*callback)(const struct caravan_result *result, void *data);
110 };
111 
112 void caravan_parameter_init_default(struct caravan_parameter *parameter);
114  const struct unit *caravan);
115 
116 void caravan_result_init_zero(struct caravan_result *result);
117 int caravan_result_compare(const struct caravan_result *a,
118  const struct caravan_result *b);
119 
120 void caravan_find_best_destination(const struct unit *caravan,
121  const struct caravan_parameter *parameter,
122  struct caravan_result *result,
123  bool omniscient);
void caravan_find_best_destination(const struct unit *caravan, const struct caravan_parameter *parameter, struct caravan_result *result, bool omniscient)
Find the best destination city for the caravan.
Definition: caravan.cpp:568
void caravan_result_init_zero(struct caravan_result *result)
Initialize the result to be worth zero and go from nowhere to nowhere.
Definition: caravan.cpp:65
int caravan_result_compare(const struct caravan_result *a, const struct caravan_result *b)
Compare the two results for sorting.
Definition: caravan.cpp:92
foreign_trade_limit
Definition: caravan.h:15
@ FTL_ALLIED
Definition: caravan.h:17
@ FTL_NATIONAL_ONLY
Definition: caravan.h:16
@ FTL_NONWAR
Definition: caravan.h:19
@ FTL_PEACEFUL
Definition: caravan.h:18
void caravan_parameter_init_default(struct caravan_parameter *parameter)
Create a valid parameter with default values.
Definition: caravan.cpp:29
void caravan_parameter_init_from_unit(struct caravan_parameter *parameter, const struct unit *caravan)
Create a valid parameter with default values based on the caravan.
Definition: caravan.cpp:46
bool consider_trade
Definition: caravan.h:70
bool convert_trade
Definition: caravan.h:100
bool consider_windfall
Definition: caravan.h:69
void(* callback)(const struct caravan_result *result, void *data)
Definition: caravan.h:108
enum foreign_trade_limit allow_foreign_trade
Definition: caravan.h:83
bool consider_wonders
Definition: caravan.h:71
bool ignore_transit_time
Definition: caravan.h:92
double discount
Definition: caravan.h:61
bool account_for_broken_routes
Definition: caravan.h:77
void * callback_data
Definition: caravan.h:109
An advisor for using caravans optimally.
Definition: caravan.h:36
const struct city * src
Definition: caravan.h:37
const struct city * dest
Definition: caravan.h:38
int arrival_time
Definition: caravan.h:39
bool help_wonder
Definition: caravan.h:42
double value
Definition: caravan.h:41
Definition: city.h:291
Definition: unit.h:134