Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / traderoutes.h
blob507d8117c86c922f3255d571d76202afba7480c8
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.
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
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 #include "support.h" /* bool */
22 struct city;
23 struct city_list;
25 /* What to do with previously established traderoutes that are now illegal.
26 * Used in the network protocol. */
27 enum traderoute_illegal_cancelling
29 TRI_ACTIVE = 0, /* Keep them active */
30 TRI_INACTIVE = 1, /* They are inactive */
31 TRI_CANCEL = 2, /* Completely cancel them */
32 TRI_LAST = 3
35 enum trade_route_type {
36 TRT_NATIONAL = 0,
37 TRT_NATIONAL_IC = 1, /* Intercontinental */
38 TRT_IN = 2,
39 TRT_IN_IC = 3, /* International intercontinental */
40 TRT_ALLY = 4,
41 TRT_ALLY_IC = 5,
42 TRT_ENEMY = 6,
43 TRT_ENEMY_IC = 7,
44 TRT_TEAM = 8,
45 TRT_TEAM_IC = 9,
46 TRT_LAST = 10
49 #define SPECENUM_NAME traderoute_bonus_type
50 #define SPECENUM_VALUE0 TBONUS_NONE
51 #define SPECENUM_VALUE0NAME "None"
52 #define SPECENUM_VALUE1 TBONUS_GOLD
53 #define SPECENUM_VALUE1NAME "Gold"
54 #define SPECENUM_VALUE2 TBONUS_SCIENCE
55 #define SPECENUM_VALUE2NAME "Science"
56 #define SPECENUM_VALUE3 TBONUS_BOTH
57 #define SPECENUM_VALUE3NAME "Both"
58 #include "specenum_gen.h"
60 #define SPECENUM_NAME route_direction
61 #define SPECENUM_VALUE0 RDIR_FROM
62 #define SPECENUM_VALUE0NAME N_("?routedir:From")
63 #define SPECENUM_VALUE1 RDIR_TO
64 #define SPECENUM_VALUE1NAME N_("?routedir:To")
65 #define SPECENUM_VALUE2 RDIR_BIDIRECTIONAL
66 #define SPECENUM_VALUE2NAME N_("?routedir:Bidirectional")
67 #include "specenum_gen.h"
69 struct trade_route_settings {
70 int trade_pct;
71 enum traderoute_illegal_cancelling cancelling;
72 enum traderoute_bonus_type bonus_type;
75 struct goods_type;
77 struct trade_route {
78 int partner;
79 int value;
80 enum route_direction dir;
81 struct goods_type *goods;
84 /* get 'struct trade_route_list' and related functions: */
85 #define SPECLIST_TAG trade_route
86 #define SPECLIST_TYPE struct trade_route
87 #include "speclist.h"
89 #define trade_route_list_iterate(trade_route_list, proute) \
90 TYPED_LIST_ITERATE(struct trade_route, trade_route_list, proute)
91 #define trade_route_list_iterate_end LIST_ITERATE_END
93 int max_trade_routes(const struct city *pcity);
94 enum trade_route_type cities_trade_route_type(const struct city *pcity1,
95 const struct city *pcity2);
96 int trade_route_type_trade_pct(enum trade_route_type type);
98 void trade_route_types_init(void);
99 const char *trade_route_type_name(enum trade_route_type type);
100 enum trade_route_type trade_route_type_by_name(const char *name);
102 const char *traderoute_cancelling_type_name(enum traderoute_illegal_cancelling type);
103 enum traderoute_illegal_cancelling traderoute_cancelling_type_by_name(const char *name);
105 struct trade_route_settings *
106 trade_route_settings_by_type(enum trade_route_type type);
108 bool can_cities_trade(const struct city *pc1, const struct city *pc2);
109 bool can_establish_trade_route(const struct city *pc1, const struct city *pc2);
110 bool have_cities_trade_route(const struct city *pc1, const struct city *pc2);
111 int trade_base_between_cities(const struct city *pc1, const struct city *pc2);
112 int trade_from_route(const struct city *pc1, const struct trade_route *route,
113 int base);
114 int city_num_trade_routes(const struct city *pcity);
115 int get_caravan_enter_city_trade_bonus(const struct city *pc1,
116 const struct city *pc2,
117 const bool establish_trade);
118 int city_trade_removable(const struct city *pcity,
119 struct trade_route_list *would_remove);
121 #define trade_routes_iterate(c, proute) \
122 do { \
123 trade_route_list_iterate(c->routes, proute) {
125 #define trade_routes_iterate_end \
126 } trade_route_list_iterate_end; \
127 } while (FALSE)
129 #define trade_routes_iterate_safe(c, proute) \
131 int _routes##_size = trade_route_list_size(c->routes); \
132 if (_routes##_size > 0) { \
133 struct trade_route *_routes##_saved[_routes##_size]; \
134 int _routes##_index = 0; \
135 trade_routes_iterate(c, _proute) { \
136 _routes##_saved[_routes##_index++] = _proute; \
137 } trade_routes_iterate_end; \
138 for (_routes##_index = 0; \
139 _routes##_index < _routes##_size; \
140 _routes##_index++) { \
141 struct trade_route *proute = _routes##_saved[_routes##_index];
143 #define trade_routes_iterate_safe_end \
148 #define trade_partners_iterate(c, p) \
149 do { \
150 trade_routes_iterate(c, _proute_) { \
151 struct city *p = game_city_by_number(_proute_->partner);
153 #define trade_partners_iterate_end \
154 } trade_routes_iterate_end; \
155 } while (FALSE);
157 /* Used in the network protocol. */
158 #define SPECENUM_NAME goods_flag_id
159 #define SPECENUM_VALUE0 GF_BIDIRECTIONAL
160 #define SPECENUM_VALUE0NAME "Bidirectional"
161 #define SPECENUM_VALUE1 GF_DEPLETES
162 #define SPECENUM_VALUE1NAME "Depletes"
163 #define SPECENUM_COUNT GF_COUNT
164 #define SPECENUM_BITVECTOR bv_goods_flags
165 #include "specenum_gen.h"
167 struct goods_type
169 int id;
170 struct name_translation name;
171 bool disabled; /* Does not really exist - hole in goods array */
173 struct requirement_vector reqs;
175 int from_pct;
176 int to_pct;
178 bv_goods_flags flags;
180 struct strvec *helptext;
183 void goods_init(void);
184 void goods_free(void);
186 Goods_type_id goods_index(const struct goods_type *pgood);
187 Goods_type_id goods_number(const struct goods_type *pgood);
189 struct goods_type *goods_by_number(Goods_type_id id);
191 const char *goods_name_translation(struct goods_type *pgood);
192 const char *goods_rule_name(struct goods_type *pgood);
193 struct goods_type *goods_by_rule_name(const char *name);
194 struct goods_type *goods_by_translated_name(const char *name);
196 bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag);
198 bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
199 struct unit *punit);
200 struct goods_type *goods_from_city_to_unit(struct city *src, struct unit *punit);
201 bool city_receives_goods(const struct city *pcity,
202 const struct goods_type *pgood);
204 #define goods_type_iterate(_p) \
206 int _i_; \
207 for (_i_ = 0; _i_ < game.control.num_goods_types ; _i_++) { \
208 struct goods_type *_p = goods_by_number(_i_);
210 #define goods_type_iterate_end \
214 #define goods_active_type_iterate(_p) \
215 goods_type_iterate(_p) { \
216 if (!_p->disabled) {
218 #define goods_active_type_iterate_end \
220 } goods_type_iterate_end;
222 #ifdef __cplusplus
224 #endif /* __cplusplus */
226 #endif /* FC__TRADEROUTES_H */