Freeciv-3.2
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
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);
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);
123 const struct city *pc2,
124 const struct unit_type *ut,
125 struct goods_type *pgood,
126 const bool establish_trade);
127int city_trade_removable(const struct city *pcity,
129
130#define trade_routes_iterate(c, proute) \
131do { \
132 trade_route_list_iterate(c->routes, proute) {
133
134#define trade_routes_iterate_end \
135 } trade_route_list_iterate_end; \
136} while (FALSE)
137
138#define trade_routes_iterate_safe(c, proute) \
139{ \
140 struct city *c##_proute = c; \
141 int _routes##_size = trade_route_list_size(c##_proute->routes); \
142 \
143 if (_routes##_size > 0) { \
144 struct trade_route *_routes##_saved[_routes##_size]; \
145 int _routes##_index; \
146 \
147 _routes##_size = 0; \
148 trade_routes_iterate(c##_proute, _proute) { \
149 _routes##_saved[_routes##_size++] = _proute; \
150 } trade_routes_iterate_end; \
151 for (_routes##_index = 0; \
152 _routes##_index < _routes##_size; \
153 _routes##_index++) { \
154 struct trade_route *proute = _routes##_saved[_routes##_index];
155
156#define trade_routes_iterate_safe_end \
157 } \
158 } \
159}
160
161#define trade_partners_iterate(c, p) \
162do { \
163 trade_routes_iterate(c, _proute_) { \
164 struct city *p = game_city_by_number(_proute_->partner);
165
166#define trade_partners_iterate_end \
167 } trade_routes_iterate_end; \
168} while (FALSE);
169
170/* Used in the network protocol. */
171#define SPECENUM_NAME goods_flag_id
172#define SPECENUM_VALUE0 GF_BIDIRECTIONAL
173#define SPECENUM_VALUE0NAME "Bidirectional"
174#define SPECENUM_VALUE1 GF_DEPLETES
175#define SPECENUM_VALUE1NAME "Depletes"
176#define SPECENUM_VALUE2 GF_SELF_PROVIDED
177#define SPECENUM_VALUE2NAME "Self-Provided"
178#define SPECENUM_COUNT GF_COUNT
179#define SPECENUM_BITVECTOR bv_goods_flags
180#include "specenum_gen.h"
181
183{
184 int id;
186 bool ruledit_disabled; /* Does not really exist - hole in goods array */
187
189
193
195
197};
198
199void goods_init(void);
200void goods_free(void);
201
204
206
207const char *goods_name_translation(struct goods_type *pgood);
208const char *goods_rule_name(struct goods_type *pgood);
209struct goods_type *goods_by_rule_name(const char *name);
210struct goods_type *goods_by_translated_name(const char *name);
211
212bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag);
213
214bool goods_can_be_provided(const struct city *pcity,
215 const struct goods_type *pgood,
216 struct unit *punit);
217struct goods_type *goods_from_city_to_unit(struct city *src, struct unit *punit);
218bool city_receives_goods(const struct city *pcity,
219 const struct goods_type *pgood);
220
221#define goods_type_iterate(_p) \
222{ \
223 int _i_; \
224 for (_i_ = 0; _i_ < game.control.num_goods_types ; _i_++) { \
225 struct goods_type *_p = goods_by_number(_i_);
226
227#define goods_type_iterate_end \
228 } \
229}
230
231#define goods_type_re_active_iterate(_p) \
232 goods_type_iterate(_p) { \
233 if (!_p->ruledit_disabled) {
234
235#define goods_type_re_active_iterate_end \
236 } \
237 } goods_type_iterate_end;
238
239#ifdef __cplusplus
240}
241#endif /* __cplusplus */
242
243#endif /* FC__TRADEROUTES_H */
char * incite_cost
Definition comments.c:75
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2931
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
int Goods_type_id
Definition fc_types.h:387
GType type
Definition repodlgs.c:1313
const char * name
Definition inputfile.c:127
Definition city.h:320
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 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 goods_can_be_provided(const struct city *pcity, const struct goods_type *pgood, struct unit *punit)
bool city_receives_goods(const struct city *pcity, const struct goods_type *pgood)
void goods_free(void)
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)
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)