Freeciv-3.3: /fast/freeciv/nightly/main/common/aicore/caravan.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
caravan.h
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#ifndef FC__CARAVAN_H
14#define FC__CARAVAN_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20
21/* utility */
22#include "log.h" /* enum log_level */
23#include "shared.h"
24
25/* common */
26#include "fc_types.h"
27
28 enum foreign_trade_limit
29{
30 FTL_NATIONAL_ONLY,
31 FTL_ALLIED,
32 FTL_PEACEFUL,
33 FTL_NONWAR
34};
35
36
51 struct caravan_result {
52 const struct city *src;
53 const struct city *dest;
54 int arrival_time;
55
56 double value;
57 bool help_wonder;
58 bool required_boat;
59};
60
61 struct caravan_parameter {
62 /*
63 * How many turns to consider when optimizing.
64 */
65 int horizon;
66
67 /*
68 * Discount factor (that is, 1 / interest rate).
69 * The worth of a trade route is equivalent to:
70 * sum_{i=0}^{horizon} value in i turns * discount^i
71 * The discount should be in (0..1].
72 * A discount of 1 means future earnings are worth the same as immediate
73 * earnings. A discount of .95 means a dollar next turn is worth only 95
74 * cents today; or, in other words, 95 cents in the bank today would yield
75 * a dollar next turn.
76 */
77 double discount;
78
79 /*
80 * What to consider:
81 * - the immediate windfall when the caravan reaches destination
82 * - the trade
83 * - the reduction in cost of helping build a wonder
84 */
85 bool consider_windfall;
86 bool consider_trade;
87 bool consider_wonders;
88
89 /*
90 * A new trade route may break old routes.
91 * Account for the loss of old routes.
92 */
93 bool account_for_broken_routes;
94
95 /*
96 * Allow trading with allies and peaceful neighbors.
97 * BUG: currently we only consider allies.
98 */
99 enum foreign_trade_limit allow_foreign_trade;
100
101 /*
102 * Normally, we'd want to compute the time it takes to establish the
103 * trade route.
104 * There are two reasons to ignore the transit time:
105 * (1) it may be infinite (i.e. requires crossing an ocean)
106 * (2) it's slow to compute it.
107 */
108 bool ignore_transit_time;
109
110 /*
111 * The 'effect of trade' can be computed exactly by an expensive
112 * calculation which will take into account buildings, tax rates, etc; or
113 * by a cheap calculation that just says that each trade is worth one
114 * science or gold.
115 */
116 bool convert_trade;
117
118 /*
119 * This callback, if non-null, is called whenever a trade route
120 * is evaluated. One intended usage is for collecting all the
121 * trade routes into a sorted list.
122 * Note that the result must be copied to be stored.
123 */
124 void (*callback)(const struct caravan_result *result, void *data);
125 void *callback_data;
126};
127
128
129void caravan_parameter_init_default(struct caravan_parameter *parameter);
130void caravan_parameter_init_from_unit(struct caravan_parameter *parameter,
131 const struct unit *caravan);
132bool caravan_parameter_is_legal(const struct caravan_parameter *parameter);
133void caravan_parameter_log_real(const struct caravan_parameter *parameter,
134 enum log_level level, const char *file,
135 const char *function, int line);
136#define caravan_parameter_log(parameter, loglevel) \
137 if (log_do_output_for_level(loglevel)) { \
138 caravan_parameter_log_real(parameter, loglevel, __FILE__, \
139 __FUNCTION__, __FC_LINE__); \
140 }
141
142void caravan_result_init_zero(struct caravan_result *result);
143int caravan_result_compare(const struct caravan_result *a,
144 const struct caravan_result *b);
145
146void caravan_find_best_destination(const struct civ_map *nmap,
147 const struct unit *caravan,
148 const struct caravan_parameter *parameter,
149 struct caravan_result *result, bool omniscient);
150
151void caravan_optimize_allpairs(const struct unit *caravan,
152 const struct caravan_parameter *parameter,
153 struct caravan_result *result, bool omniscient);
154
155#ifdef __cplusplus
156}
157#endif /* __cplusplus */
158
159#endif /* FC__CARAVAN_H */
caravan_find_best_destination
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:679
caravan_parameter_is_legal
bool caravan_parameter_is_legal(const struct caravan_parameter *parameter)
Definition caravan.c:72
caravan_result_init_zero
void caravan_result_init_zero(struct caravan_result *result)
Definition caravan.c:144
caravan_result_compare
int caravan_result_compare(const struct caravan_result *a, const struct caravan_result *b)
Definition caravan.c:183
foreign_trade_limit
foreign_trade_limit
Definition caravan.h:29
FTL_ALLIED
@ FTL_ALLIED
Definition caravan.h:31
FTL_NATIONAL_ONLY
@ FTL_NATIONAL_ONLY
Definition caravan.h:30
FTL_NONWAR
@ FTL_NONWAR
Definition caravan.h:33
FTL_PEACEFUL
@ FTL_PEACEFUL
Definition caravan.h:32
caravan_parameter_log_real
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
caravan_parameter_init_default
void caravan_parameter_init_default(struct caravan_parameter *parameter)
Definition caravan.c:36
caravan_parameter_init_from_unit
void caravan_parameter_init_from_unit(struct caravan_parameter *parameter, const struct unit *caravan)
Definition caravan.c:53
caravan_optimize_allpairs
void caravan_optimize_allpairs(const struct unit *caravan, const struct caravan_parameter *parameter, struct caravan_result *result, bool omniscient)
Definition caravan.c:799
incite_cost
char * incite_cost
Definition comments.c:74
fc_types.h
log.h
log_level
log_level
Definition log.h:28
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
shared.h
callback
Definition gui_main.c:2404
caravan_parameter
Definition caravan.h:61
caravan_parameter::horizon
int horizon
Definition caravan.h:65
caravan_parameter::consider_trade
bool consider_trade
Definition caravan.h:86
caravan_parameter::convert_trade
bool convert_trade
Definition caravan.h:116
caravan_parameter::consider_windfall
bool consider_windfall
Definition caravan.h:85
caravan_parameter::allow_foreign_trade
enum foreign_trade_limit allow_foreign_trade
Definition caravan.h:99
caravan_parameter::consider_wonders
bool consider_wonders
Definition caravan.h:87
caravan_parameter::ignore_transit_time
bool ignore_transit_time
Definition caravan.h:108
caravan_parameter::discount
double discount
Definition caravan.h:77
caravan_parameter::account_for_broken_routes
bool account_for_broken_routes
Definition caravan.h:93
caravan_parameter::callback_data
void * callback_data
Definition caravan.h:125
caravan_result
Definition caravan.h:51
caravan_result::src
const struct city * src
Definition caravan.h:52
caravan_result::dest
const struct city * dest
Definition caravan.h:53
caravan_result::arrival_time
int arrival_time
Definition caravan.h:54
caravan_result::help_wonder
bool help_wonder
Definition caravan.h:57
caravan_result::required_boat
bool required_boat
Definition caravan.h:58
caravan_result::value
double value
Definition caravan.h:56
city
Definition city.h:320
civ_map
Definition map_types.h:71
unit
Definition unit.h:140