Freeciv21
Develop your civilization from humble roots to a global empire
traderoutes.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include "support.h" // bool
16 
17 struct city;
18 struct city_list;
19 struct player;
20 
21 /* What to do with previously established traderoutes that are now illegal.
22  * Used in the network protocol. */
24  TRI_ACTIVE = 0, // Keep them active
25  TRI_INACTIVE = 1, // They are inactive
26  TRI_CANCEL = 2, // Completely cancel them
27  TRI_LAST = 3
28 };
29 
32  TRT_NATIONAL_IC = 1, // Intercontinental
33  TRT_IN = 2,
34  TRT_IN_IC = 3, // International intercontinental
35  TRT_ALLY = 4,
37  TRT_ENEMY = 6,
39  TRT_TEAM = 8,
41  TRT_LAST = 10
42 };
43 
44 #define SPECENUM_NAME traderoute_bonus_type
45 #define SPECENUM_VALUE0 TBONUS_NONE
46 #define SPECENUM_VALUE0NAME "None"
47 #define SPECENUM_VALUE1 TBONUS_GOLD
48 #define SPECENUM_VALUE1NAME "Gold"
49 #define SPECENUM_VALUE2 TBONUS_SCIENCE
50 #define SPECENUM_VALUE2NAME "Science"
51 #define SPECENUM_VALUE3 TBONUS_BOTH
52 #define SPECENUM_VALUE3NAME "Both"
53 #include "specenum_gen.h"
54 
55 #define SPECENUM_NAME route_direction
56 #define SPECENUM_VALUE0 RDIR_FROM
57 #define SPECENUM_VALUE0NAME N_("?routedir:From")
58 #define SPECENUM_VALUE1 RDIR_TO
59 #define SPECENUM_VALUE1NAME N_("?routedir:To")
60 #define SPECENUM_VALUE2 RDIR_BIDIRECTIONAL
61 #define SPECENUM_VALUE2NAME N_("?routedir:Bidirectional")
62 #include "specenum_gen.h"
63 
65  int trade_pct;
67  enum traderoute_bonus_type bonus_type;
68 };
69 
70 struct goods_type;
71 
72 struct trade_route {
73  int partner;
74  int value;
75  enum route_direction dir;
76  struct goods_type *goods;
77 };
78 
79 // get 'struct trade_route_list' and related functions:
80 #define SPECLIST_TAG trade_route
81 #define SPECLIST_TYPE struct trade_route
82 #include "speclist.h"
83 
84 #define trade_route_list_iterate(trade_route_list, proute) \
85  TYPED_LIST_ITERATE(struct trade_route, trade_route_list, proute)
86 #define trade_route_list_iterate_end LIST_ITERATE_END
87 
88 int max_trade_routes(const struct city *pcity);
89 enum trade_route_type cities_trade_route_type(const struct city *pcity1,
90  const struct city *pcity2);
92 
94 const char *trade_route_type_name(enum trade_route_type type);
96 
97 const char *
101 
102 struct trade_route_settings *
104 
105 bool can_cities_trade(const struct city *pc1, const struct city *pc2);
106 bool can_establish_trade_route(const struct city *pc1,
107  const struct city *pc2);
108 bool have_cities_trade_route(const struct city *pc1, const struct city *pc2);
109 int trade_base_between_cities(const struct city *pc1,
110  const struct city *pc2);
111 int trade_from_route(const struct city *pc1, const struct trade_route *route,
112  int base);
113 int city_num_trade_routes(const struct city *pcity);
114 int get_caravan_enter_city_trade_bonus(const struct city *pc1,
115  const struct city *pc2,
116  const player *seen_as,
117  struct goods_type *pgood,
118  const bool establish_trade);
119 int city_trade_removable(const struct city *pcity,
120  struct trade_route_list *would_remove);
121 
122 #define trade_routes_iterate(c, proute) \
123  do { \
124  trade_route_list_iterate(c->routes, proute) \
125  {
126 
127 #define trade_routes_iterate_end \
128  } \
129  trade_route_list_iterate_end; \
130  } \
131  while (false)
132 
133 #define trade_routes_iterate_safe(c, proute) \
134  { \
135  int _routes##_size = trade_route_list_size(c->routes); \
136  if (_routes##_size > 0) { \
137  struct trade_route *_routes##_saved[_routes##_size]; \
138  int _routes##_index = 0; \
139  trade_routes_iterate(c, _proute) \
140  { \
141  _routes##_saved[_routes##_index++] = _proute; \
142  } \
143  trade_routes_iterate_end; \
144  for (_routes##_index = 0; _routes##_index < _routes##_size; \
145  _routes##_index++) { \
146  struct trade_route *proute = _routes##_saved[_routes##_index];
147 
148 #define trade_routes_iterate_safe_end \
149  } \
150  } \
151  }
152 
153 #define trade_partners_iterate(c, p) \
154  do { \
155  trade_routes_iterate(c, _proute_) \
156  { \
157  struct city *p = game_city_by_number(_proute_->partner); \
158  /* Maybe we haven't yet recieved info about this city */ \
159  if (!p) { \
160  continue; \
161  }
162 
163 #define trade_partners_iterate_end \
164  } \
165  trade_routes_iterate_end; \
166  } \
167  while (false) \
168  ;
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_COUNT GF_COUNT
177 #define SPECENUM_BITVECTOR bv_goods_flags
178 #include "specenum_gen.h"
179 
180 struct goods_type {
181  int id;
182  struct name_translation name;
183  bool ruledit_disabled; // Does not really exist - hole in goods array
184 
185  struct requirement_vector reqs;
186 
187  int from_pct;
188  int to_pct;
190 
191  bv_goods_flags flags;
192 
194 };
195 
196 void goods_init();
197 void goods_free();
198 
199 Goods_type_id goods_index(const struct goods_type *pgood);
200 Goods_type_id goods_number(const struct goods_type *pgood);
201 
203 
204 const char *goods_name_translation(struct goods_type *pgood);
205 const char *goods_rule_name(struct goods_type *pgood);
206 struct goods_type *goods_by_rule_name(const char *name);
207 struct goods_type *goods_by_translated_name(const char *name);
208 
209 bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag);
210 
211 bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
212  struct unit *punit);
213 struct goods_type *goods_from_city_to_unit(struct city *src,
214  struct unit *punit);
215 bool city_receives_goods(const struct city *pcity,
216  const struct goods_type *pgood);
217 
218 #define goods_type_iterate(_p) \
219  { \
220  int _i_; \
221  for (_i_ = 0; _i_ < game.control.num_goods_types; _i_++) { \
222  struct goods_type *_p = goods_by_number(_i_);
223 
224 #define goods_type_iterate_end \
225  } \
226  }
227 
228 #define goods_type_re_active_iterate(_p) \
229  goods_type_iterate(_p) \
230  { \
231  if (!_p->ruledit_disabled) {
232 
233 #define goods_type_re_active_iterate_end \
234  } \
235  } \
236  goods_type_iterate_end;
static void base(QVariant data1, QVariant data2)
Action "Build Base" for choice dialog.
Definition: dialogs.cpp:2393
int Goods_type_id
Definition: fc_types.h:304
const char * name
Definition: inputfile.cpp:118
Definition: city.h:291
struct requirement_vector reqs
Definition: traderoutes.h:185
int onetime_pct
Definition: traderoutes.h:189
bool ruledit_disabled
Definition: traderoutes.h:183
bv_goods_flags flags
Definition: traderoutes.h:191
QVector< QString > * helptext
Definition: traderoutes.h:193
struct name_translation name
Definition: traderoutes.h:182
Definition: player.h:231
enum traderoute_bonus_type bonus_type
Definition: traderoutes.h:67
enum traderoute_illegal_cancelling cancelling
Definition: traderoutes.h:66
enum route_direction dir
Definition: traderoutes.h:75
struct goods_type * goods
Definition: traderoutes.h:76
Definition: unit.h:134
traderoute_illegal_cancelling
Definition: traderoutes.h:23
@ TRI_LAST
Definition: traderoutes.h:27
@ TRI_ACTIVE
Definition: traderoutes.h:24
@ TRI_INACTIVE
Definition: traderoutes.h:25
@ TRI_CANCEL
Definition: traderoutes.h:26
struct goods_type * goods_by_number(Goods_type_id id)
Return goods type of given id.
const char * goods_rule_name(struct goods_type *pgood)
Return untranslated name of this goods type.
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Return TRUE iff the two cities are capable of trade; i.e., if a caravan from one city can enter the o...
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
What is type of the traderoute between two cities.
Definition: traderoutes.cpp:51
int trade_route_type_trade_pct(enum trade_route_type type)
Return percentage bonus for trade route type.
int max_trade_routes(const struct city *pcity)
Return current maximum number of trade routes city can have.
Definition: traderoutes.cpp:41
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
Return the trade that exists between these cities, assuming they have a trade route.
enum traderoute_illegal_cancelling traderoute_cancelling_type_by_name(const char *name)
Get traderoute cancelling type by name.
struct goods_type * goods_by_rule_name(const char *name)
Returns goods type matching rule name or nullptr if there is no goods type with such name.
int city_num_trade_routes(const struct city *pcity)
Return number of trade route city has.
Goods_type_id goods_number(const struct goods_type *pgood)
Return the goods id.
const char * goods_name_translation(struct goods_type *pgood)
Return translated name of this goods type.
bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
Check if goods has given flag.
void trade_route_types_init()
Initialize trade route types.
struct goods_type * goods_from_city_to_unit(struct city *src, struct unit *punit)
Return goods type for the new traderoute between given cities.
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
Get trade income specific to route's good.
struct goods_type * goods_by_translated_name(const char *name)
const char * trade_route_type_name(enum trade_route_type type)
Return human readable name of trade route type.
void goods_init()
Initialize goods structures.
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
Get trade route settings related to type.
Goods_type_id goods_index(const struct goods_type *pgood)
Return the goods index.
void goods_free()
Free the memory associated with goods.
int city_trade_removable(const struct city *pcity, struct trade_route_list *would_remove)
Return the minimum value of the sum of trade routes which could be replaced by a new one.
int get_caravan_enter_city_trade_bonus(const struct city *pc1, const struct city *pc2, const player *seen_as, struct goods_type *pgood, const bool establish_trade)
Returns the revenue trade bonus - you get this when establishing a trade route and also when you simp...
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
Returns TRUE iff the two cities can establish a trade route.
bool city_receives_goods(const struct city *pcity, const struct goods_type *pgood)
Does city receive goods.
const char * traderoute_cancelling_type_name(enum traderoute_illegal_cancelling type)
Return human readable name of traderoute cancelling type.
bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood, struct unit *punit)
Can the city provide goods.
trade_route_type
Definition: traderoutes.h:30
@ TRT_NATIONAL_IC
Definition: traderoutes.h:32
@ TRT_TEAM_IC
Definition: traderoutes.h:40
@ TRT_ALLY_IC
Definition: traderoutes.h:36
@ TRT_IN_IC
Definition: traderoutes.h:34
@ TRT_NATIONAL
Definition: traderoutes.h:31
@ TRT_LAST
Definition: traderoutes.h:41
@ TRT_IN
Definition: traderoutes.h:33
@ TRT_TEAM
Definition: traderoutes.h:39
@ TRT_ALLY
Definition: traderoutes.h:35
@ TRT_ENEMY_IC
Definition: traderoutes.h:38
@ TRT_ENEMY
Definition: traderoutes.h:37
enum trade_route_type trade_route_type_by_name(const char *name)
Get trade route type by name.
bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
Check if cities have an established trade route.