Freeciv21
Develop your civilization from humble roots to a global empire
traderoutes.cpp
Go to the documentation of this file.
1 /*
2 _ ._ Copyright (c) 1996-2021 Freeciv21 and Freeciv contributors.
3  \ | This file is part of Freeciv21. Freeciv21 is free software: you
4  \_| can redistribute it and/or modify it under the terms of the
5  .' '. GNU General Public License as published by the Free
6  :O O: Software Foundation, either version 3 of the License,
7  '/ \' or (at your option) any later version. You should have
8  :X: received a copy of the GNU General Public License along with
9  :X: Freeciv21. If not, see https://www.gnu.org/licenses/.
10  */
11 
12 // utility
13 #include "fcintl.h"
14 #include "log.h"
15 #include "rand.h"
16 
17 // common
18 #include "city.h"
19 #include "effects.h"
20 #include "game.h"
21 #include "map.h"
22 #include "tile.h"
23 #include "unittype.h"
24 
25 #include "traderoutes.h"
26 
27 const char *trade_route_type_names[] = {
28  "National", "NationalIC", "IN", "INIC", "Ally",
29  "AllyIC", "Enemy", "EnemyIC", "Team", "TeamIC"};
30 
31 const char *traderoute_cancelling_type_names[] = {"Active", "Inactive",
32  "Cancel"};
33 
35 
36 static struct goods_type goods[MAX_GOODS_TYPES];
37 
41 int max_trade_routes(const struct city *pcity)
42 {
43  int eft = get_city_bonus(pcity, EFT_MAX_TRADE_ROUTES);
44 
45  return CLIP(0, eft, MAX_TRADE_ROUTES);
46 }
47 
51 enum trade_route_type cities_trade_route_type(const struct city *pcity1,
52  const struct city *pcity2)
53 {
54  struct player *plr1 = city_owner(pcity1);
55  struct player *plr2 = city_owner(pcity2);
56 
57  if (plr1 != plr2) {
58  struct player_diplstate *ds = player_diplstate_get(plr1, plr2);
59 
60  if (city_tile(pcity1)->continent != city_tile(pcity2)->continent) {
61  switch (ds->type) {
62  case DS_ALLIANCE:
63  return TRT_ALLY_IC;
64  case DS_WAR:
65  return TRT_ENEMY_IC;
66  case DS_TEAM:
67  return TRT_TEAM_IC;
68  case DS_ARMISTICE:
69  case DS_CEASEFIRE:
70  case DS_PEACE:
71  case DS_NO_CONTACT:
72  return TRT_IN_IC;
73  case DS_LAST:
74  fc_assert(ds->type != DS_LAST);
75  return TRT_IN_IC;
76  }
77  fc_assert(false);
78 
79  return TRT_IN_IC;
80  } else {
81  switch (ds->type) {
82  case DS_ALLIANCE:
83  return TRT_ALLY;
84  case DS_WAR:
85  return TRT_ENEMY;
86  case DS_TEAM:
87  return TRT_TEAM;
88  case DS_ARMISTICE:
89  case DS_CEASEFIRE:
90  case DS_PEACE:
91  case DS_NO_CONTACT:
92  return TRT_IN;
93  case DS_LAST:
94  fc_assert(ds->type != DS_LAST);
95  return TRT_IN;
96  }
97  fc_assert(false);
98 
99  return TRT_IN;
100  }
101  } else {
102  if (city_tile(pcity1)->continent != city_tile(pcity2)->continent) {
103  return TRT_NATIONAL_IC;
104  } else {
105  return TRT_NATIONAL;
106  }
107  }
108 
109  return TRT_LAST;
110 }
111 
116 {
117  if (type >= TRT_LAST) {
118  return 0;
119  }
120 
121  return trtss[type].trade_pct;
122 }
123 
128 {
129  for (int type = TRT_NATIONAL; type < TRT_LAST; type++) {
130  struct trade_route_settings *set =
132 
133  set->trade_pct = 100;
134  }
135 }
136 
141 {
142  fc_assert_ret_val(type >= TRT_NATIONAL && type < TRT_LAST, nullptr);
143 
144  return trade_route_type_names[type];
145 }
146 
151 {
152  for (int type = TRT_NATIONAL; type < TRT_LAST; type++) {
154  return trade_route_type(type);
155  }
156  }
157 
158  return TRT_LAST;
159 }
160 
164 const char *
166 {
167  fc_assert_ret_val(type >= TRI_ACTIVE && type < TRI_LAST, nullptr);
168 
170 }
171 
177 {
178  for (int type = TRI_ACTIVE; type < TRI_LAST; type++) {
180  return traderoute_illegal_cancelling(type);
181  }
182  }
183 
184  return TRI_LAST;
185 }
186 
190 struct trade_route_settings *
192 {
193  fc_assert_ret_val(type >= TRT_NATIONAL && type < TRT_LAST, nullptr);
194 
195  return &trtss[type];
196 }
197 
204 bool can_cities_trade(const struct city *pc1, const struct city *pc2)
205 {
206  /* If you change the logic here, make sure to update the help in
207  * helptext_unit(). */
208  return (pc1 && pc2 && pc1 != pc2
209  && (city_owner(pc1) != city_owner(pc2)
210  || real_map_distance(pc1->tile, pc2->tile)
211  >= game.info.trademindist)
213  > 0));
214 }
215 
221 int city_trade_removable(const struct city *pcity,
222  struct trade_route_list *would_remove)
223 {
225  int num, i, j;
226 
227  // Sort trade route values.
228  num = 0;
229  trade_routes_iterate(pcity, proute)
230  {
231  for (j = num; j > 0 && (proute->value < sorted[j - 1]->value); j--) {
232  sorted[j] = sorted[j - 1];
233  }
234  sorted[j] = proute;
235  num++;
236  }
238 
239  // No trade routes at all.
240  if (0 == num) {
241  return 0;
242  }
243 
244  // Adjust number of concerned trade routes.
245  num += 1 - max_trade_routes(pcity);
246  if (0 >= num) {
247  num = 1;
248  }
249 
250  // Return values.
251  for (i = j = 0; i < num; i++) {
252  j += sorted[i]->value;
253  if (nullptr != would_remove) {
254  trade_route_list_append(would_remove, sorted[i]);
255  }
256  }
257 
258  return j;
259 }
260 
267 bool can_establish_trade_route(const struct city *pc1,
268  const struct city *pc2)
269 {
270  int trade = -1;
271  int maxpc1;
272  int maxpc2;
273 
274  if (!pc1 || !pc2 || pc1 == pc2 || !can_cities_trade(pc1, pc2)
275  || have_cities_trade_route(pc1, pc2)) {
276  return false;
277  }
278 
279  // First check if cities can have trade routes at all.
280  maxpc1 = max_trade_routes(pc1);
281  if (maxpc1 <= 0) {
282  return false;
283  }
284  maxpc2 = max_trade_routes(pc2);
285  if (maxpc2 <= 0) {
286  return false;
287  }
288 
289  if (city_num_trade_routes(pc1) >= maxpc1) {
290  trade = trade_base_between_cities(pc1, pc2);
291  // can we replace trade route?
292  if (city_trade_removable(pc1, nullptr) >= trade) {
293  return false;
294  }
295  }
296 
297  if (city_num_trade_routes(pc2) >= maxpc2) {
298  if (trade == -1) {
299  trade = trade_base_between_cities(pc1, pc2);
300  }
301  // can we replace trade route?
302  if (city_trade_removable(pc2, nullptr) >= trade) {
303  return false;
304  }
305  }
306 
307  return true;
308 }
309 
314 int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
315 {
316  int bonus = 0;
317 
318  if (nullptr == pc1 || nullptr == pc1->tile || nullptr == pc2
319  || nullptr == pc2->tile) {
320  return 0;
321  }
322 
323  if (game.info.trade_revenue_style == TRS_CLASSIC) {
324  // Classic Freeciv
325  int real_dist = real_map_distance(pc1->tile, pc2->tile);
326  int weighted_distance =
327  ((100 - game.info.trade_world_rel_pct) * real_dist
328  + game.info.trade_world_rel_pct
329  * (real_dist * 40 / MAX(wld.map.xsize, wld.map.ysize)))
330  / 100;
331 
332  bonus = weighted_distance + city_size_get(pc1) + city_size_get(pc2);
333  } else if (game.info.trade_revenue_style == TRS_SIMPLE) {
334  // Simple revenue style
335  bonus =
336  (pc1->citizen_base[O_TRADE] + pc2->citizen_base[O_TRADE] + 4) * 3;
337  }
338 
339  bonus = bonus
341  / 100;
342 
343  bonus /= 12;
344 
345  return bonus;
346 }
347 
351 int trade_from_route(const struct city *pc1, const struct trade_route *route,
352  int base)
353 {
354  Q_UNUSED(pc1)
355  if (route->dir == RDIR_TO) {
356  return base * route->goods->to_pct / 100;
357  }
358 
359  return base * route->goods->from_pct / 100;
360 }
361 
365 int city_num_trade_routes(const struct city *pcity)
366 {
367  return trade_route_list_size(pcity->routes);
368 }
369 
373 static int max_tile_trade(const struct city *pcity, const player *seen_as)
374 {
375  int i, total = 0;
376  int radius_sq = city_map_radius_sq_get(pcity);
377  std::vector<int> tile_trade;
378  tile_trade.resize(city_map_tiles(radius_sq));
379  size_t size = 0;
380  bool is_celebrating = base_city_celebrating(pcity);
381 
382  if (pcity->tile == nullptr) {
383  return 0;
384  }
385 
386  city_map_iterate(radius_sq, cindex, cx, cy)
387  {
388  struct tile *ptile = city_map_to_tile(pcity->tile, radius_sq, cx, cy);
389 
390  if (ptile == nullptr) {
391  continue;
392  }
393 
394  if (is_city_center_index(cindex)) {
395  total += city_tile_output(pcity, ptile, is_celebrating, O_TRADE);
396  continue;
397  }
398 
399  if (!base_city_can_work_tile(seen_as ? seen_as : city_owner(pcity),
400  pcity, ptile)) {
401  continue;
402  }
403 
404  tile_trade[size++] =
405  city_tile_output(pcity, ptile, is_celebrating, O_TRADE);
406  }
408 
409  std::sort(tile_trade.begin(), tile_trade.end());
410 
411  for (i = 0; i < pcity->size && i < size; i++) {
412  total += tile_trade[i];
413  }
414 
415  return total;
416 }
417 
421 static int max_trade_prod(const struct city *pcity, const player *seen_as)
422 {
423  // Trade tile base
424  int trade_prod = max_tile_trade(pcity, seen_as);
425 
426  // Add trade routes values
427  trade_partners_iterate(pcity, partner)
428  {
429  trade_prod += trade_base_between_cities(pcity, partner);
430  }
432 
433  return trade_prod;
434 }
435 
447  const struct city *pc2,
448  const player *seen_as,
449  struct goods_type *pgood,
450  const bool establish_trade)
451 {
452  int rmd, trade2, max_trade_2;
453  int tb = 0, bonus = 0;
454 
455  if (pc2) {
456  rmd = real_map_distance(pc1->tile, pc2->tile);
457  trade2 = pc2->surplus[O_TRADE];
458  max_trade_2 = max_trade_prod(pc2, seen_as);
459  } else {
460  rmd = 10;
461  trade2 = pc1->surplus[O_TRADE] * 0.75;
462  max_trade_2 = max_trade_prod(pc1, seen_as) * 0.75;
463  }
464 
465  if (game.info.caravan_bonus_style == CBS_CLASSIC) {
466  tb = rmd + 10;
467  tb = (tb * (pc1->surplus[O_TRADE] + trade2)) / 24;
468  } else if (game.info.caravan_bonus_style == CBS_LOGARITHMIC) {
469  // Logarithmic bonus
470  tb = pow(log(rmd + 20 + max_trade_prod(pc1, seen_as) + max_trade_2) * 2,
471  2);
472  } else if (game.info.caravan_bonus_style == CBS_LINEAR) {
473  // Linear bonus (like CLASSIC) but using max_trade_prod
474  tb = rmd + 10;
475  tb = (tb * (max_trade_prod(pc1, seen_as) + max_trade_2)) / 24;
476  } else if (game.info.caravan_bonus_style == CBS_DISTANCE) {
477  // Purely dependent on distance, ignore city trade
478  tb = rmd + 10;
479  }
480 
481  if (pgood != nullptr) {
482  tb = tb * pgood->onetime_pct / 100;
483  }
484 
485  // Trade_revenue_exponent (in milimes) bends the shape of the curve
486  bonus = get_target_bonus_effects(
487  nullptr, city_owner(pc1), pc2 ? city_owner(pc2) : nullptr, pc1,
488  nullptr, city_tile(pc1), nullptr, nullptr, nullptr, nullptr,
489  action_by_number(establish_trade ? ACTION_TRADE_ROUTE
490  : ACTION_MARKETPLACE),
491  EFT_TRADE_REVENUE_EXPONENT);
492  tb = ceil(pow(static_cast<float>(tb),
493  1.0f + static_cast<float>(bonus) / 1000.0));
494 
495  // Trade_revenue_bonus increases revenue by power of 2 in milimes
496  bonus = get_target_bonus_effects(
497  nullptr, city_owner(pc1), pc2 ? city_owner(pc2) : nullptr, pc1,
498  nullptr, city_tile(pc1),
499  /* TODO: Should unit requirements be
500  * allowed so stuff like moves left and
501  * unit type can modify the bonus? */
502  nullptr, nullptr, nullptr, nullptr,
503  /* Could be used to reduce the one time
504  * bonus if no trade route is
505  * established. */
506  action_by_number(establish_trade ? ACTION_TRADE_ROUTE
507  : ACTION_MARKETPLACE),
508  EFT_TRADE_REVENUE_BONUS);
509 
510  // Be mercy full to players with small amounts. Round up.
511  tb = ceil(static_cast<float>(tb)
512  * pow(2.0, static_cast<double>(bonus) / 1000.0));
513 
514  return tb;
515 }
516 
520 bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
521 {
522  trade_partners_iterate(pc1, route_to)
523  {
524  if (route_to->id == pc2->id) {
525  return true;
526  }
527  }
529 
530  return false;
531 }
532 
537 {
538  int i;
539 
540  for (i = 0; i < MAX_GOODS_TYPES; i++) {
541  goods[i].id = i;
542 
543  requirement_vector_init(&(goods[i].reqs));
544  goods[i].ruledit_disabled = false;
545  goods[i].helptext = nullptr;
546  }
547 }
548 
553 {
554  int i;
555 
556  for (i = 0; i < MAX_GOODS_TYPES; i++) {
557  requirement_vector_free(&(goods[i].reqs));
558  delete[] goods[i].helptext;
559  goods[i].helptext = nullptr;
560  }
561 }
562 
567 {
568  fc_assert_ret_val(nullptr != pgood, 0);
569 
570  return pgood->id;
571 }
572 
580 {
581  fc_assert_ret_val(nullptr != pgood, 0);
582 
583  return pgood - goods;
584 }
585 
590 {
591  fc_assert_ret_val(id >= 0 && id < game.control.num_goods_types, nullptr);
592 
593  return &goods[id];
594 }
595 
599 const char *goods_name_translation(struct goods_type *pgood)
600 {
601  return name_translation_get(&pgood->name);
602 }
603 
607 const char *goods_rule_name(struct goods_type *pgood)
608 {
609  return rule_name_get(&pgood->name);
610 }
611 
616 struct goods_type *goods_by_rule_name(const char *name)
617 {
618  const char *qs;
619 
620  if (name == nullptr) {
621  return nullptr;
622  }
623 
624  qs = Qn_(name);
625 
626  goods_type_iterate(pgood)
627  {
628  if (!fc_strcasecmp(goods_rule_name(pgood), qs)) {
629  return pgood;
630  }
631  }
633 
634  return nullptr;
635 }
636 
637 /*
638  Returns goods type matching the translated name, or nullptr if there is no
639  goods type with that name.
640  */
642 {
643  goods_type_iterate(pgood)
644  {
645  if (0 == strcmp(goods_name_translation(pgood), name)) {
646  return pgood;
647  }
648  }
650 
651  return nullptr;
652 }
653 
657 bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
658 {
659  return BV_ISSET(pgood->flags, flag);
660 }
661 
665 bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
666  struct unit *punit)
667 {
668  const struct unit_type *ptype;
669 
670  if (punit != nullptr) {
671  ptype = unit_type_get(punit);
672  } else {
673  ptype = nullptr;
674  }
675 
676  return are_reqs_active(city_owner(pcity), nullptr, pcity, nullptr,
677  city_tile(pcity), punit, ptype, nullptr, nullptr,
678  nullptr, &pgood->reqs, RPT_CERTAIN);
679 }
680 
684 bool city_receives_goods(const struct city *pcity,
685  const struct goods_type *pgood)
686 {
687  trade_routes_iterate(pcity, proute)
688  {
689  if (proute->goods == pgood
690  && (proute->dir == RDIR_TO || proute->dir == RDIR_BIDIRECTIONAL)) {
691  return true;
692  }
693  }
695 
696  return false;
697 }
698 
703  struct unit *punit)
704 {
705  int i = 0;
706  struct goods_type *potential[MAX_GOODS_TYPES];
707 
708  goods_type_iterate(pgood)
709  {
710  if (goods_can_be_provided(src, pgood, punit)) {
711  potential[i++] = pgood;
712  }
713  }
715 
716  if (i == 0) {
717  return nullptr;
718  }
719 
720  return potential[fc_rand(i)];
721 }
struct action * action_by_number(action_id act_id)
Return the action with the given id.
Definition: actions.cpp:1149
bool BV_ISSET(const BV &bv, int bit)
Definition: bitvector.h:37
bool base_city_celebrating(const struct city *pcity)
Return TRUE if the city was celebrating at the start of the turn, and it still has sufficient size to...
Definition: city.cpp:1555
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
Definition: city.cpp:1083
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Returns TRUE when a tile is available to be worked, or the city itself is currently working the tile ...
Definition: city.cpp:1339
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
Definition: city.cpp:1095
struct tile * city_map_to_tile(const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Finds the map position for a given city map coordinate of a certain city.
Definition: city.cpp:298
int city_map_radius_sq_get(const struct city *pcity)
Returns the current squared radius of the city.
Definition: city.cpp:130
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Calculate the output for the tile.
Definition: city.cpp:1230
int city_map_tiles(int city_radius_sq)
Return the number of tiles for the given city radius.
Definition: city.cpp:164
citizens city_size_get(const struct city *pcity)
Get the city size.
Definition: city.cpp:1101
#define city_map_iterate_end
Definition: city.h:148
#define is_city_center_index(city_tile_index)
Definition: city.h:778
#define city_map_iterate(_radius_sq, _index, _x, _y)
Definition: city.h:144
std::vector< unit * > sorted(const unit_list *units)
Returns a version of units sorted in the way the user would like to see them.
Definition: unit_utils.cpp:87
static void base(QVariant data1, QVariant data2)
Action "Build Base" for choice dialog.
Definition: dialogs.cpp:2393
int get_target_bonus_effects(struct effect_list *plist, const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, enum effect_type effect_type, enum vision_layer vision_layer, enum national_intelligence nintel)
Returns the effect bonus of a given type for any target.
Definition: effects.cpp:611
struct @19::@20 reqs
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
Definition: effects.cpp:688
#define MAX_TRADE_ROUTES
Definition: fc_types.h:1073
int Goods_type_id
Definition: fc_types.h:304
#define MAX_GOODS_TYPES
Definition: fc_types.h:45
@ RPT_CERTAIN
Definition: fc_types.h:568
@ O_TRADE
Definition: fc_types.h:87
#define Qn_(String)
Definition: fcintl.h:66
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
const char * name
Definition: inputfile.cpp:118
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
Definition: map.cpp:599
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
Definition: player.cpp:288
#define fc_rand(_size)
Definition: rand.h:16
bool are_reqs_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement_vector *reqs, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement(s) to see if they are active on the given target.
#define CLIP(lower, current, upper)
Definition: shared.h:51
#define MAX(x, y)
Definition: shared.h:48
size_t size
Definition: specvec.h:64
Definition: city.h:291
int surplus[O_LAST]
Definition: city.h:324
int id
Definition: city.h:296
int citizen_base[O_LAST]
Definition: city.h:328
struct trade_route_list * routes
Definition: city.h:313
citizens size
Definition: city.h:301
struct tile * tile
Definition: city.h:293
struct packet_ruleset_control control
Definition: game.h:74
struct packet_game_info info
Definition: game.h:80
int xsize
Definition: map_types.h:73
int ysize
Definition: map_types.h:73
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
enum diplstate_type type
Definition: player.h:193
Definition: player.h:231
Definition: tile.h:42
enum route_direction dir
Definition: traderoutes.h:75
struct goods_type * goods
Definition: traderoutes.h:76
Definition: unit.h:134
struct civ_map map
Definition: world_object.h:21
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
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.
static struct goods_type goods[MAX_GOODS_TYPES]
Definition: traderoutes.cpp:36
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 trade_route_settings trtss[TRT_LAST]
Definition: traderoutes.cpp:34
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.
static int max_trade_prod(const struct city *pcity, const player *seen_as)
Returns the maximum trade production of a city.
const char * traderoute_cancelling_type_names[]
Definition: traderoutes.cpp:31
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.
static int max_tile_trade(const struct city *pcity, const player *seen_as)
Returns the maximum trade production of the tiles of the city.
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.
const char * trade_route_type_names[]
Definition: traderoutes.cpp:27
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.
traderoute_illegal_cancelling
Definition: traderoutes.h:23
@ TRI_LAST
Definition: traderoutes.h:27
@ TRI_ACTIVE
Definition: traderoutes.h:24
#define goods_type_iterate_end
Definition: traderoutes.h:224
#define goods_type_iterate(_p)
Definition: traderoutes.h:218
#define trade_routes_iterate_end
Definition: traderoutes.h:127
#define trade_partners_iterate_end
Definition: traderoutes.h:163
#define trade_routes_iterate(c, proute)
Definition: traderoutes.h:122
#define trade_partners_iterate(c, p)
Definition: traderoutes.h:153
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
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
Definition: unittype.cpp:114