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

Freeciv-3.3

Loading...
Searching...
No Matches
traderoutes.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__TRADEROUTES_H
14#define FC__TRADEROUTES_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "support.h" /* bool */
22
23struct city;
24struct city_list;
25
26/* What to do with previously established trade routes that are now illegal.
27 * Used in the network protocol. */
28 enum trade_route_illegal_cancelling
29 {
30 TRI_ACTIVE = 0, /* Keep them active */
31 TRI_INACTIVE = 1, /* They are inactive */
32 TRI_CANCEL = 2, /* Completely cancel them */
33 TRI_LAST = 3
34 };
35
36/* Values used in the network protocol. */
37 enum trade_route_type {
38 TRT_NATIONAL = 0,
39 TRT_NATIONAL_IC = 1, /* Intercontinental */
40 TRT_IN = 2,
41 TRT_IN_IC = 3, /* International intercontinental */
42 TRT_ALLY = 4,
43 TRT_ALLY_IC = 5,
44 TRT_ENEMY = 6,
45 TRT_ENEMY_IC = 7,
46 TRT_TEAM = 8,
47 TRT_TEAM_IC = 9,
48 TRT_LAST = 10
49};
50
51/* Values used in the network protocol. */
52#define SPECENUM_NAME trade_route_bonus_type
53#define SPECENUM_VALUE0 TBONUS_NONE
54#define SPECENUM_VALUE0NAME "None"
55#define SPECENUM_VALUE1 TBONUS_GOLD
56#define SPECENUM_VALUE1NAME "Gold"
57#define SPECENUM_VALUE2 TBONUS_SCIENCE
58#define SPECENUM_VALUE2NAME "Science"
59#define SPECENUM_VALUE3 TBONUS_BOTH
60#define SPECENUM_VALUE3NAME "Both"
61#include "specenum_gen.h"
62
63/* Values used in the network protocol. */
64#define SPECENUM_NAME route_direction
65#define SPECENUM_VALUE0 RDIR_NONE
66#define SPECENUM_VALUE0NAME N_("?routedir:None")
67#define SPECENUM_VALUE1 RDIR_FROM
68#define SPECENUM_VALUE1NAME N_("?routedir:From")
69#define SPECENUM_VALUE2 RDIR_TO
70#define SPECENUM_VALUE2NAME N_("?routedir:To")
71#define SPECENUM_VALUE3 RDIR_BIDIRECTIONAL
72#define SPECENUM_VALUE3NAME N_("?routedir:Bidirectional")
73#include "specenum_gen.h"
74
75 struct trade_route_settings {
76 int trade_pct;
77 enum trade_route_illegal_cancelling cancelling;
78 enum trade_route_bonus_type bonus_type;
79};
80
81struct goods_type;
82
83 struct trade_route {
84 int partner;
85 int value;
86 enum route_direction dir;
87 struct goods_type *goods;
88};
89
90/* get 'struct trade_route_list' and related functions: */
91#define SPECLIST_TAG trade_route
92#define SPECLIST_TYPE struct trade_route
93#include "speclist.h"
94
95#define trade_route_list_iterate(trade_route_list, proute) \
96 TYPED_LIST_ITERATE(struct trade_route, trade_route_list, proute)
97#define trade_route_list_iterate_end LIST_ITERATE_END
98
99unsigned max_trade_routes(const struct city *pcity);
100enum trade_route_type cities_trade_route_type(const struct city *pcity1,
101 const struct city *pcity2);
102int trade_route_type_trade_pct(enum trade_route_type type);
103
104void trade_route_types_init(void);
105const char *trade_route_type_name(enum trade_route_type type);
106enum trade_route_type trade_route_type_by_name(const char *name);
107
108const char *trade_route_cancelling_type_name(enum trade_route_illegal_cancelling type);
109enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name(const char *name);
110
111struct trade_route_settings *
112 trade_route_settings_by_type(enum trade_route_type type);
113
114bool can_cities_trade(const struct city *pc1, const struct city *pc2);
115bool can_establish_trade_route(const struct city *pc1, const struct city *pc2,
116 int priority);
117bool have_cities_trade_route(const struct city *pc1, const struct city *pc2);
118int trade_base_between_cities(const struct city *pc1, const struct city *pc2);
119int trade_from_route(const struct city *pc1, const struct trade_route *route,
120 int base);
121int city_num_trade_routes(const struct city *pcity);
122int max_trade_prod(const struct city *pcity);
123int get_caravan_enter_city_trade_bonus(const struct city *pc1,
124 const struct city *pc2,
125 const struct unit_type *ut,
126 struct goods_type *pgood,
127 const bool establish_trade);
128int city_trade_removable(const struct city *pcity, int priority,
129 struct trade_route_list *would_remove);
130
131#define trade_routes_iterate(c, proute) \
132do { \
133 trade_route_list_iterate(c->routes, proute) {
134
135#define trade_routes_iterate_end \
136 } trade_route_list_iterate_end; \
137} while (FALSE)
138
139#define trade_routes_iterate_safe(c, proute) \
140{ \
141 struct city *c##_proute = c; \
142 int _routes##_size = trade_route_list_size(c##_proute->routes); \
143 \
144 if (_routes##_size > 0) { \
145 struct trade_route *_routes##_saved[_routes##_size]; \
146 int _routes##_index; \
147 \
148 _routes##_size = 0; \
149 trade_routes_iterate(c##_proute, _proute) { \
150 _routes##_saved[_routes##_size++] = _proute; \
151 } trade_routes_iterate_end; \
152 for (_routes##_index = 0; \
153 _routes##_index < _routes##_size; \
154 _routes##_index++) { \
155 struct trade_route *proute = _routes##_saved[_routes##_index];
156
157#define trade_routes_iterate_safe_end \
158 } \
159 } \
160}
161
162#define trade_partners_iterate(c, p) \
163do { \
164 trade_routes_iterate(c, _proute_) { \
165 struct city *p = game_city_by_number(_proute_->partner);
166
167#define trade_partners_iterate_end \
168 } trade_routes_iterate_end; \
169} while (FALSE);
170
171/* Used in the network protocol. */
172#define SPECENUM_NAME goods_flag_id
173#define SPECENUM_VALUE0 GF_BIDIRECTIONAL
174#define SPECENUM_VALUE0NAME "Bidirectional"
175#define SPECENUM_VALUE1 GF_DEPLETES
176#define SPECENUM_VALUE1NAME "Depletes"
177#define SPECENUM_VALUE2 GF_SELF_PROVIDED
178#define SPECENUM_VALUE2NAME "Self-Provided"
179#define SPECENUM_COUNT GF_COUNT
180#define SPECENUM_BITVECTOR bv_goods_flags
181#include "specenum_gen.h"
182
183/* Some places assume this to be bigger than any actual goods priority */
184#define GOODS_HIGH_PRIORITY 100
185
186 struct goods_type
187{
188 int id;
189 struct name_translation name;
190 bool ruledit_disabled; /* Does not really exist - hole in goods array */
191
192 struct requirement_vector reqs;
193
194 int from_pct;
195 int to_pct;
196 int onetime_pct;
197
198 int select_priority;
199 int priority;
200
201 bv_goods_flags flags;
202
203 struct strvec *helptext;
204};
205
206void goods_init(void);
207void goods_free(void);
208
209 Goods_type_id goods_index(const struct goods_type *pgood);
210 Goods_type_id goods_number(const struct goods_type *pgood);
211
212struct goods_type *goods_by_number(Goods_type_id id);
213
214const char *goods_name_translation(struct goods_type *pgood);
215const char *goods_rule_name(struct goods_type *pgood);
216struct goods_type *goods_by_rule_name(const char *name);
217struct goods_type *goods_by_translated_name(const char *name);
218
219bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag);
220
221bool goods_can_be_provided(const struct city *pcity,
222 const struct goods_type *pgood,
223 const struct unit *punit);
224struct goods_type *goods_from_city_to_unit(const struct city *src,
225 const struct unit *punit);
226struct goods_type *unit_current_goods(const struct unit *punit,
227 const struct city *homecity);
228bool city_receives_goods(const struct city *pcity,
229 const struct goods_type *pgood);
230
231#define goods_type_iterate(_p) \
232{ \
233 int _i_; \
234 for (_i_ = 0; _i_ < game.control.num_goods_types ; _i_++) { \
235 struct goods_type *_p = goods_by_number(_i_);
236
237#define goods_type_iterate_end \
238 } \
239}
240
241#define goods_type_re_active_iterate(_p) \
242 goods_type_iterate(_p) { \
243 if (!_p->ruledit_disabled) {
244
245#define goods_type_re_active_iterate_end \
246 } \
247 } goods_type_iterate_end;
248
249#ifdef __cplusplus
250}
251#endif /* __cplusplus */
252
253#endif /* FC__TRADEROUTES_H */
incite_cost
char * incite_cost
Definition comments.c:74
base
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2938
punit
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 * punit
Definition dialogs_g.h:74
Goods_type_id
int Goods_type_id
Definition fc_types.h:391
type
GType type
Definition repodlgs.c:1313
name
const char * name
Definition inputfile.c:127
specenum_gen.h
speclist.h
priority
SPECPQ_PRIORITY_TYPE priority
Definition specpq.h:86
city
Definition city.h:320
goods_type
Definition traderoutes.h:187
goods_type::to_pct
int to_pct
Definition traderoutes.h:195
goods_type::from_pct
int from_pct
Definition traderoutes.h:194
goods_type::priority
int priority
Definition traderoutes.h:199
goods_type::id
int id
Definition traderoutes.h:188
goods_type::reqs
struct requirement_vector reqs
Definition traderoutes.h:192
goods_type::onetime_pct
int onetime_pct
Definition traderoutes.h:196
goods_type::ruledit_disabled
bool ruledit_disabled
Definition traderoutes.h:190
goods_type::select_priority
int select_priority
Definition traderoutes.h:198
goods_type::flags
bv_goods_flags flags
Definition traderoutes.h:201
goods_type::helptext
struct strvec * helptext
Definition traderoutes.h:203
goods_type::name
struct name_translation name
Definition traderoutes.h:189
name_translation
Definition name_translation.h:35
strvec
Definition string_vector.c:29
trade_route_settings
Definition traderoutes.h:75
trade_route_settings::bonus_type
enum trade_route_bonus_type bonus_type
Definition traderoutes.h:78
trade_route_settings::trade_pct
int trade_pct
Definition traderoutes.h:76
trade_route_settings::cancelling
enum trade_route_illegal_cancelling cancelling
Definition traderoutes.h:77
trade_route
Definition traderoutes.h:83
trade_route::dir
enum route_direction dir
Definition traderoutes.h:86
trade_route::goods
struct goods_type * goods
Definition traderoutes.h:87
trade_route::value
int value
Definition traderoutes.h:85
trade_route::partner
int partner
Definition traderoutes.h:84
unit_type
Definition unittype.h:507
unit
Definition unit.h:140
support.h
max_trade_prod
int max_trade_prod(const struct city *pcity)
Definition traderoutes.c:453
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
cities_trade_route_type
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
trade_route_type_trade_pct
int trade_route_type_trade_pct(enum trade_route_type type)
Definition traderoutes.c:122
trade_base_between_cities
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:331
goods_can_be_provided
bool goods_can_be_provided(const struct city *pcity, const struct goods_type *pgood, const struct unit *punit)
Definition traderoutes.c:692
city_num_trade_routes
int city_num_trade_routes(const struct city *pcity)
Definition traderoutes.c:392
goods_number
Goods_type_id goods_number(const struct goods_type *pgood)
Definition traderoutes.c:597
goods_has_flag
bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
Definition traderoutes.c:684
trade_route_cancelling_type_by_name
enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name(const char *name)
Definition traderoutes.c:184
trade_route_type_name
const char * trade_route_type_name(enum trade_route_type type)
Definition traderoutes.c:148
trade_route_settings_by_type
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
Definition traderoutes.c:201
trade_route_illegal_cancelling
trade_route_illegal_cancelling
Definition traderoutes.h:29
TRI_LAST
@ TRI_LAST
Definition traderoutes.h:33
TRI_ACTIVE
@ TRI_ACTIVE
Definition traderoutes.h:30
TRI_INACTIVE
@ TRI_INACTIVE
Definition traderoutes.h:31
TRI_CANCEL
@ TRI_CANCEL
Definition traderoutes.h:32
goods_by_rule_name
struct goods_type * goods_by_rule_name(const char *name)
Definition traderoutes.c:647
trade_from_route
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
Definition traderoutes.c:367
goods_rule_name
const char * goods_rule_name(struct goods_type *pgood)
Definition traderoutes.c:638
goods_from_city_to_unit
struct goods_type * goods_from_city_to_unit(const struct city *src, const struct unit *punit)
Definition traderoutes.c:743
unit_current_goods
struct goods_type * unit_current_goods(const struct unit *punit, const struct city *homecity)
Definition traderoutes.c:778
max_trade_routes
unsigned max_trade_routes(const struct city *pcity)
Definition traderoutes.c:48
goods_name_translation
const char * goods_name_translation(struct goods_type *pgood)
Definition traderoutes.c:630
trade_route_types_init
void trade_route_types_init(void)
Definition traderoutes.c:134
goods_index
Goods_type_id goods_index(const struct goods_type *pgood)
Definition traderoutes.c:610
goods_by_translated_name
struct goods_type * goods_by_translated_name(const char *name)
Definition traderoutes.c:670
city_trade_removable
int city_trade_removable(const struct city *pcity, int priority, struct trade_route_list *would_remove)
Definition traderoutes.c:231
can_establish_trade_route
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2, int priority)
Definition traderoutes.c:283
goods_by_number
struct goods_type * goods_by_number(Goods_type_id id)
Definition traderoutes.c:620
trade_route_cancelling_type_name
const char * trade_route_cancelling_type_name(enum trade_route_illegal_cancelling type)
Definition traderoutes.c:174
goods_init
void goods_init(void)
Definition traderoutes.c:564
city_receives_goods
bool city_receives_goods(const struct city *pcity, const struct goods_type *pgood)
Definition traderoutes.c:710
goods_free
void goods_free(void)
Definition traderoutes.c:580
trade_route_type
trade_route_type
Definition traderoutes.h:37
TRT_NATIONAL_IC
@ TRT_NATIONAL_IC
Definition traderoutes.h:39
TRT_TEAM_IC
@ TRT_TEAM_IC
Definition traderoutes.h:47
TRT_ALLY_IC
@ TRT_ALLY_IC
Definition traderoutes.h:43
TRT_IN_IC
@ TRT_IN_IC
Definition traderoutes.h:41
TRT_NATIONAL
@ TRT_NATIONAL
Definition traderoutes.h:38
TRT_LAST
@ TRT_LAST
Definition traderoutes.h:48
TRT_IN
@ TRT_IN
Definition traderoutes.h:40
TRT_TEAM
@ TRT_TEAM
Definition traderoutes.h:46
TRT_ALLY
@ TRT_ALLY
Definition traderoutes.h:42
TRT_ENEMY_IC
@ TRT_ENEMY_IC
Definition traderoutes.h:45
TRT_ENEMY
@ TRT_ENEMY
Definition traderoutes.h:44
trade_route_type_by_name
enum trade_route_type trade_route_type_by_name(const char *name)
Definition traderoutes.c:158
have_cities_trade_route
bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:550
get_caravan_enter_city_trade_bonus
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)
Definition traderoutes.c:476