Freeciv-3.1
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. */
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. */
39 TRT_NATIONAL_IC = 1, /* Intercontinental */
40 TRT_IN = 2,
41 TRT_IN_IC = 3, /* International intercontinental */
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
80
81struct goods_type;
82
85 int value;
86 enum route_direction dir;
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);
103
104void trade_route_types_init(void);
107
110
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);
116bool have_cities_trade_route(const struct city *pc1, const struct city *pc2);
117int trade_base_between_cities(const struct city *pc1, const struct city *pc2);
118int trade_from_route(const struct city *pc1, const struct trade_route *route,
119 int base);
120int city_num_trade_routes(const struct city *pcity);
121int max_trade_prod(const struct city *pcity);
122int get_caravan_enter_city_trade_bonus(const struct city *pc1,
123 const struct city *pc2,
124 struct goods_type *pgood,
125 const bool establish_trade);
126int city_trade_removable(const struct city *pcity,
127 struct trade_route_list *would_remove);
128
129#define trade_routes_iterate(c, proute) \
130do { \
131 trade_route_list_iterate(c->routes, proute) {
132
133#define trade_routes_iterate_end \
134 } trade_route_list_iterate_end; \
135} while (FALSE)
136
137#define trade_routes_iterate_safe(c, proute) \
138{ \
139 struct city *c##_proute = c; \
140 int _routes##_size = trade_route_list_size(c##_proute->routes); \
141 \
142 if (_routes##_size > 0) { \
143 struct trade_route *_routes##_saved[_routes##_size]; \
144 int _routes##_index; \
145 \
146 _routes##_size = 0; \
147 trade_routes_iterate(c##_proute, _proute) { \
148 _routes##_saved[_routes##_size++] = _proute; \
149 } trade_routes_iterate_end; \
150 for (_routes##_index = 0; \
151 _routes##_index < _routes##_size; \
152 _routes##_index++) { \
153 struct trade_route *proute = _routes##_saved[_routes##_index];
154
155#define trade_routes_iterate_safe_end \
156 } \
157 } \
158}
159
160#define trade_partners_iterate(c, p) \
161do { \
162 trade_routes_iterate(c, _proute_) { \
163 struct city *p = game_city_by_number(_proute_->partner);
164
165#define trade_partners_iterate_end \
166 } trade_routes_iterate_end; \
167} while (FALSE);
168
169/* Used in the network protocol. */
170#define SPECENUM_NAME goods_flag_id
171#define SPECENUM_VALUE0 GF_BIDIRECTIONAL
172#define SPECENUM_VALUE0NAME "Bidirectional"
173#define SPECENUM_VALUE1 GF_DEPLETES
174#define SPECENUM_VALUE1NAME "Depletes"
175#define SPECENUM_COUNT GF_COUNT
176#define SPECENUM_BITVECTOR bv_goods_flags
177#include "specenum_gen.h"
178
180{
181 int id;
183 bool ruledit_disabled; /* Does not really exist - hole in goods array */
184
185 struct requirement_vector reqs;
186
190
191 bv_goods_flags flags;
192
194};
195
196void goods_init(void);
197void goods_free(void);
198
199Goods_type_id goods_index(const struct goods_type *pgood);
200Goods_type_id goods_number(const struct goods_type *pgood);
201
203
204const char *goods_name_translation(struct goods_type *pgood);
205const char *goods_rule_name(struct goods_type *pgood);
206struct goods_type *goods_by_rule_name(const char *name);
207struct goods_type *goods_by_translated_name(const char *name);
208
209bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag);
210
211bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
212 struct unit *punit);
213struct goods_type *goods_from_city_to_unit(struct city *src, struct unit *punit);
214bool city_receives_goods(const struct city *pcity,
215 const struct goods_type *pgood);
216
217#define goods_type_iterate(_p) \
218{ \
219 int _i_; \
220 for (_i_ = 0; _i_ < game.control.num_goods_types ; _i_++) { \
221 struct goods_type *_p = goods_by_number(_i_);
222
223#define goods_type_iterate_end \
224 } \
225}
226
227#define goods_type_re_active_iterate(_p) \
228 goods_type_iterate(_p) { \
229 if (!_p->ruledit_disabled) {
230
231#define goods_type_re_active_iterate_end \
232 } \
233 } goods_type_iterate_end;
234
235#ifdef __cplusplus
236}
237#endif /* __cplusplus */
238
239#endif /* FC__TRADEROUTES_H */
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2840
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:73
int Goods_type_id
Definition fc_types.h:357
GType type
Definition repodlgs.c:1312
const char * name
Definition inputfile.c:127
Definition city.h:309
struct requirement_vector reqs
bool ruledit_disabled
bv_goods_flags flags
struct strvec * helptext
struct name_translation name
enum trade_route_bonus_type bonus_type
Definition traderoutes.h:78
enum trade_route_illegal_cancelling cancelling
Definition traderoutes.h:77
enum route_direction dir
Definition traderoutes.h:86
struct goods_type * goods
Definition traderoutes.h:87
Definition unit.h:138
int max_trade_prod(const struct city *pcity)
struct goods_type * goods_from_city_to_unit(struct city *src, struct unit *punit)
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_route_type_trade_pct(enum trade_route_type type)
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
int city_num_trade_routes(const struct city *pcity)
Goods_type_id goods_number(const struct goods_type *pgood)
bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name(const char *name)
const char * trade_route_type_name(enum trade_route_type type)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
trade_route_illegal_cancelling
Definition traderoutes.h:29
@ TRI_LAST
Definition traderoutes.h:33
@ TRI_ACTIVE
Definition traderoutes.h:30
@ TRI_INACTIVE
Definition traderoutes.h:31
@ TRI_CANCEL
Definition traderoutes.h:32
struct goods_type * goods_by_rule_name(const char *name)
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
const char * goods_rule_name(struct goods_type *pgood)
unsigned max_trade_routes(const struct city *pcity)
Definition traderoutes.c:48
const char * goods_name_translation(struct goods_type *pgood)
void trade_route_types_init(void)
Goods_type_id goods_index(const struct goods_type *pgood)
struct goods_type * goods_by_translated_name(const char *name)
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)
struct goods_type * goods_by_number(Goods_type_id id)
const char * trade_route_cancelling_type_name(enum trade_route_illegal_cancelling type)
void goods_init(void)
bool city_receives_goods(const struct city *pcity, const struct goods_type *pgood)
void goods_free(void)
bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood, struct unit *punit)
trade_route_type
Definition traderoutes.h:37
@ TRT_NATIONAL_IC
Definition traderoutes.h:39
@ TRT_TEAM_IC
Definition traderoutes.h:47
@ TRT_ALLY_IC
Definition traderoutes.h:43
@ TRT_IN_IC
Definition traderoutes.h:41
@ TRT_NATIONAL
Definition traderoutes.h:38
@ TRT_LAST
Definition traderoutes.h:48
@ TRT_IN
Definition traderoutes.h:40
@ TRT_TEAM
Definition traderoutes.h:46
@ TRT_ALLY
Definition traderoutes.h:42
@ TRT_ENEMY_IC
Definition traderoutes.h:45
@ TRT_ENEMY
Definition traderoutes.h:44
enum trade_route_type trade_route_type_by_name(const char *name)
bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)