Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/traderoutes.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
traderoutes.c
Go to the documentation of this file.
1/****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "log.h"
20#include "rand.h"
21
22/* common */
23#include "city.h"
24#include "effects.h"
25#include "game.h"
26#include "map.h"
27#include "tile.h"
28#include "unittype.h"
29
30#include "traderoutes.h"
31
32 const char *trade_route_type_names[] = {
33 "National", "NationalIC", "IN", "INIC", "Ally", "AllyIC",
34 "Enemy", "EnemyIC", "Team", "TeamIC"
35};
36
37 const char *trade_route_cancelling_type_names[] = {
38 "Active", "Inactive", "Cancel"
39};
40
41 struct trade_route_settings trtss[TRT_LAST];
42
43 static struct goods_type goods[MAX_GOODS_TYPES];
44
45/*********************************************************************/
48 unsigned max_trade_routes(const struct city *pcity)
49{
50 int eft = get_city_bonus(pcity, EFT_MAX_TRADE_ROUTES);
51
52 return CLIP(0, eft, MAX_TRADE_ROUTES);
53}
54
55/*********************************************************************/
58 enum trade_route_type cities_trade_route_type(const struct city *pcity1,
59 const struct city *pcity2)
60{
61 struct player *plr1 = city_owner(pcity1);
62 struct player *plr2 = city_owner(pcity2);
63
64 if (plr1 != plr2) {
65 struct player_diplstate *ds = player_diplstate_get(plr1, plr2);
66
67 if (city_tile(pcity1)->continent != city_tile(pcity2)->continent) {
68 switch (ds->type) {
69 case DS_ALLIANCE:
70 return TRT_ALLY_IC;
71 case DS_WAR:
72 return TRT_ENEMY_IC;
73 case DS_TEAM:
74 return TRT_TEAM_IC;
75 case DS_ARMISTICE:
76 case DS_CEASEFIRE:
77 case DS_PEACE:
78 case DS_NO_CONTACT:
79 return TRT_IN_IC;
80 case DS_LAST:
81 fc_assert(ds->type != DS_LAST);
82 return TRT_IN_IC;
83 }
84 fc_assert(FALSE);
85
86 return TRT_IN_IC;
87 } else {
88 switch (ds->type) {
89 case DS_ALLIANCE:
90 return TRT_ALLY;
91 case DS_WAR:
92 return TRT_ENEMY;
93 case DS_TEAM:
94 return TRT_TEAM;
95 case DS_ARMISTICE:
96 case DS_CEASEFIRE:
97 case DS_PEACE:
98 case DS_NO_CONTACT:
99 return TRT_IN;
100 case DS_LAST:
101 fc_assert(ds->type != DS_LAST);
102 return TRT_IN;
103 }
104 fc_assert(FALSE);
105
106 return TRT_IN;
107 }
108 } else {
109 if (city_tile(pcity1)->continent != city_tile(pcity2)->continent) {
110 return TRT_NATIONAL_IC;
111 } else {
112 return TRT_NATIONAL;
113 }
114 }
115
116 return TRT_LAST;
117}
118
119/*********************************************************************/
122 int trade_route_type_trade_pct(enum trade_route_type type)
123{
124 if (type >= TRT_LAST) {
125 return 0;
126 }
127
128 return trtss[type].trade_pct;
129}
130
131/*********************************************************************/
134 void trade_route_types_init(void)
135{
136 enum trade_route_type type;
137
138 for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
139 struct trade_route_settings *set = trade_route_settings_by_type(type);
140
141 set->trade_pct = 100;
142 }
143}
144
145/*********************************************************************/
148 const char *trade_route_type_name(enum trade_route_type type)
149{
150 fc_assert_ret_val(type >= TRT_NATIONAL && type < TRT_LAST, NULL);
151
152 return trade_route_type_names[type];
153}
154
155/*********************************************************************/
158 enum trade_route_type trade_route_type_by_name(const char *name)
159{
160 enum trade_route_type type;
161
162 for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
163 if (!fc_strcasecmp(trade_route_type_names[type], name)) {
164 return type;
165 }
166 }
167
168 return TRT_LAST;
169}
170
171/*********************************************************************/
174 const char *trade_route_cancelling_type_name(enum trade_route_illegal_cancelling type)
175{
176 fc_assert_ret_val(type >= TRI_ACTIVE && type < TRI_LAST, NULL);
177
178 return trade_route_cancelling_type_names[type];
179}
180
181/*********************************************************************/
184 enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name(const char *name)
185{
186 enum trade_route_illegal_cancelling type;
187
188 for (type = TRI_ACTIVE; type < TRI_LAST; type++) {
189 if (!fc_strcasecmp(trade_route_cancelling_type_names[type], name)) {
190 return type;
191 }
192 }
193
194 return TRI_LAST;
195}
196
197/*********************************************************************/
200struct trade_route_settings *
201trade_route_settings_by_type(enum trade_route_type type)
202{
203 fc_assert_ret_val(type >= TRT_NATIONAL && type < TRT_LAST, NULL);
204
205 return &trtss[type];
206}
207
208/*********************************************************************/
214 bool can_cities_trade(const struct city *pc1, const struct city *pc2)
215{
216 /* If you change the logic here, make sure to update the help in
217 * helptext_unit(). */
218 return (pc1 && pc2 && pc1 != pc2
219 && (city_owner(pc1) != city_owner(pc2)
220 || map_distance(pc1->tile, pc2->tile)
221 >= game.info.trademindist)
222 && (trade_route_type_trade_pct(cities_trade_route_type(pc1, pc2))
223 > 0));
224}
225
226/*********************************************************************/
231 int city_trade_removable(const struct city *pcity,
232 struct trade_route_list *would_remove)
233{
234 struct trade_route *sorted[MAX_TRADE_ROUTES];
235 int num, i, j;
236
237 /* Sort trade route values. */
238 num = 0;
239 trade_routes_iterate(pcity, proute) {
240 for (j = num; j > 0 && (proute->value < sorted[j - 1]->value) ; j--) {
241 sorted[j] = sorted[j - 1];
242 }
243 sorted[j] = proute;
244 num++;
245 } trade_routes_iterate_end;
246
247 /* No trade routes at all. */
248 if (0 == num) {
249 return 0;
250 }
251
252 /* Adjust number of concerned trade routes. */
253 num += 1 - max_trade_routes(pcity);
254 if (0 >= num) {
255 num = 1;
256 }
257
258 /* Return values. */
259 for (i = j = 0; i < num; i++) {
260 j += sorted[i]->value;
261 if (NULL != would_remove) {
262 trade_route_list_append(would_remove, sorted[i]);
263 }
264 }
265
266 return j;
267}
268
269/*********************************************************************/
275 bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
276{
277 int trade = -1;
278 int maxpc1;
279 int maxpc2;
280
281 if (!pc1 || !pc2 || pc1 == pc2
282 || !can_cities_trade(pc1, pc2)
283 || have_cities_trade_route(pc1, pc2)) {
284 return FALSE;
285 }
286
287 /* First check if cities can have trade routes at all. */
288 maxpc1 = max_trade_routes(pc1);
289 if (maxpc1 <= 0) {
290 return FALSE;
291 }
292 maxpc2 = max_trade_routes(pc2);
293 if (maxpc2 <= 0) {
294 return FALSE;
295 }
296
297 if (city_num_trade_routes(pc1) >= maxpc1) {
298 trade = trade_base_between_cities(pc1, pc2);
299 /* can we replace trade route? */
300 if (city_trade_removable(pc1, NULL) >= trade) {
301 return FALSE;
302 }
303 }
304
305 if (city_num_trade_routes(pc2) >= maxpc2) {
306 if (trade == -1) {
307 trade = trade_base_between_cities(pc1, pc2);
308 }
309 /* can we replace trade route? */
310 if (city_trade_removable(pc2, NULL) >= trade) {
311 return FALSE;
312 }
313 }
314
315 return TRUE;
316}
317
318/*********************************************************************/
322 int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
323{
324 int bonus = 0;
325
326 if (NULL == pc1 || NULL == pc1->tile || NULL == pc2 || NULL == pc2->tile) {
327 return 0;
328 }
329
330 if (game.info.trade_revenue_style == TRS_CLASSIC) {
331 /* Classic Freeciv */
332 int real_dist = real_map_distance(pc1->tile, pc2->tile);
333 int weighted_distance
334 = ((100 - game.info.trade_world_rel_pct) * real_dist
335 + game.info.trade_world_rel_pct
336 * (real_dist * 40 / MAX(wld.map.xsize, wld.map.ysize))) / 100;
337
338 bonus = weighted_distance
339 + city_size_get(pc1) + city_size_get(pc2);
340 } else if (game.info.trade_revenue_style == TRS_SIMPLE) {
341 /* Simple revenue style */
342 bonus = (pc1->citizen_base[O_TRADE] + pc2->citizen_base[O_TRADE] + 4)
343 * 3;
344 }
345
346 bonus = bonus
347 * trade_route_type_trade_pct(cities_trade_route_type(pc1, pc2))
348 / 100;
349
350 bonus /= 12;
351
352 return bonus;
353}
354
355/*********************************************************************/
358 int trade_from_route(const struct city *pc1, const struct trade_route *route,
359 int base)
360{
361 int val;
362
363 if (route->dir == RDIR_TO) {
364 val = base * route->goods->to_pct / 100;
365
366 if (route->goods->to_pct > 0) {
367 val = MAX(val, game.info.min_trade_route_val);
368 }
369 } else {
370 val = base * route->goods->from_pct / 100;
371
372 if (route->goods->from_pct > 0) {
373 val = MAX(val, game.info.min_trade_route_val);
374 }
375 }
376
377 return val;
378}
379
380/*********************************************************************/
383 int city_num_trade_routes(const struct city *pcity)
384{
385 return trade_route_list_size(pcity->routes);
386}
387
388/*********************************************************************/
391 static int best_value(const void *a, const void *b)
392{
393 return *(int *)a < *(int *)b;
394}
395
396/*********************************************************************/
399 static int max_tile_trade(const struct city *pcity)
400{
401 int i, total = 0;
402 int radius_sq = city_map_radius_sq_get(pcity);
403 int tile_trade[city_map_tiles(radius_sq)];
404 size_t size = 0;
405 bool is_celebrating = base_city_celebrating(pcity);
406 const struct civ_map *nmap = &(wld.map);
407
408 if (pcity->tile == NULL) {
409 return 0;
410 }
411
412 city_map_iterate(radius_sq, cindex, cx, cy) {
413 struct tile *ptile = city_map_to_tile(nmap, pcity->tile, radius_sq, cx, cy);
414
415 if (ptile == NULL) {
416 continue;
417 }
418
419 if (is_free_worked_index(cindex)) {
420 total += city_tile_output(pcity, ptile, is_celebrating, O_TRADE);
421 continue;
422 }
423
424 if (!city_can_work_tile(pcity, ptile)) {
425 continue;
426 }
427
428 tile_trade[size++] = city_tile_output(pcity, ptile, is_celebrating,
429 O_TRADE);
430 } city_map_iterate_end;
431
432 qsort(tile_trade, size, sizeof(*tile_trade), best_value);
433
434 for (i = 0; i < pcity->size && i < size; i++) {
435 total += tile_trade[i];
436 }
437
438 return total;
439}
440
441/*********************************************************************/
444 int max_trade_prod(const struct city *pcity)
445{
446 /* Trade tile base */
447 int trade_prod = max_tile_trade(pcity);
448
449 /* Add trade routes values */
450 trade_partners_iterate(pcity, partner) {
451 trade_prod += trade_base_between_cities(pcity, partner);
452 } trade_partners_iterate_end;
453
454 return trade_prod;
455}
456
457/*********************************************************************/
467 int get_caravan_enter_city_trade_bonus(const struct city *pc1,
468 const struct city *pc2,
469 struct goods_type *pgood,
470 const bool establish_trade)
471{
472 int tb = 0, bonus = 0;
473 enum trade_route_type trtype = cities_trade_route_type(pc1, pc2);
474
475 if (trtss[trtype].bonus_type == TBONUS_NONE) {
476 return 0;
477 }
478
479 if (game.info.caravan_bonus_style == CBS_CLASSIC) {
480 /* Should this be real_map_distance? */
481 int distance = map_distance(pc1->tile, pc2->tile);
482 int weighted_distance = ((100 - game.info.trade_world_rel_pct) * distance
483 + game.info.trade_world_rel_pct
484 * (distance * 40 / MAX(wld.map.xsize, wld.map.ysize))) / 100;
485
486 tb = weighted_distance + 10;
487 tb = (tb * (pc1->surplus[O_TRADE] + pc2->surplus[O_TRADE])) / 24;
488 } else if (game.info.caravan_bonus_style == CBS_LOGARITHMIC) {
489 /* Logarithmic bonus */
490 int distance = real_map_distance(pc1->tile, pc2->tile);
491 int weighted_distance = ((100 - game.info.trade_world_rel_pct) * distance
492 + game.info.trade_world_rel_pct
493 * (distance * 40 / MAX(wld.map.xsize, wld.map.ysize))) / 100;
494
495 tb = pow(log(weighted_distance + 20
496 + max_trade_prod(pc1) + max_trade_prod(pc2)) * 2, 2);
497 }
498
499 if (pgood != NULL) {
500 tb = tb * pgood->onetime_pct / 100;
501 }
502
503 /* Trade_revenue_bonus increases revenue by power of 2 in milimes */
504 bonus = get_target_bonus_effects(NULL,
505 /* TODO: Should unit requirements be
506 * allowed so stuff like moves left and
507 * unit type can modify the bonus? */
508 &(const struct req_context) {
509 .player = city_owner(pc1),
510 .city = pc1,
511 .tile = city_tile(pc1),
512 /* Could be used to reduce the one time
513 * bonus if no trade route is
514 * established. */
515 .action = action_by_number(
516 establish_trade
517 ? ACTION_TRADE_ROUTE
518 : ACTION_MARKETPLACE
519 ),
520 }, city_owner(pc2),
521 EFT_TRADE_REVENUE_BONUS);
522
523 /* Be mercy full to players with small amounts. Round up. */
524 tb = ceil((float)tb * pow(2.0, (double)bonus / 1000.0));
525
526 return tb;
527}
528
529/*********************************************************************/
532 bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
533{
534 trade_partners_iterate(pc1, route_to) {
535 if (route_to->id == pc2->id) {
536 return TRUE;
537 }
538 } trade_partners_iterate_end;
539
540 return FALSE;
541}
542
543/*********************************************************************/
546 void goods_init(void)
547{
548 int i;
549
550 for (i = 0; i < MAX_GOODS_TYPES; i++) {
551 goods[i].id = i;
552
553 requirement_vector_init(&(goods[i].reqs));
554 goods[i].ruledit_disabled = FALSE;
555 goods[i].helptext = NULL;
556 }
557}
558
559/*********************************************************************/
562 void goods_free(void)
563{
564 int i;
565
566 for (i = 0; i < MAX_GOODS_TYPES; i++) {
567 requirement_vector_free(&(goods[i].reqs));
568
569 if (NULL != goods[i].helptext) {
570 strvec_destroy(goods[i].helptext);
571 goods[i].helptext = NULL;
572 }
573 }
574}
575
576/*********************************************************************/
579 Goods_type_id goods_number(const struct goods_type *pgood)
580{
581 fc_assert_ret_val(NULL != pgood, -1);
582
583 return pgood->id;
584}
585
586/*********************************************************************/
592 Goods_type_id goods_index(const struct goods_type *pgood)
593{
594 fc_assert_ret_val(NULL != pgood, -1);
595
596 return pgood - goods;
597}
598
599/*********************************************************************/
602 struct goods_type *goods_by_number(Goods_type_id id)
603{
604 fc_assert_ret_val(id >= 0 && id < game.control.num_goods_types, NULL);
605
606 return &goods[id];
607}
608
609/*********************************************************************/
612 const char *goods_name_translation(struct goods_type *pgood)
613{
614 return name_translation_get(&pgood->name);
615}
616
617/*********************************************************************/
620 const char *goods_rule_name(struct goods_type *pgood)
621{
622 return rule_name_get(&pgood->name);
623}
624
625/*********************************************************************/
629 struct goods_type *goods_by_rule_name(const char *name)
630{
631 const char *qs;
632
633 if (name == NULL) {
634 return NULL;
635 }
636
637 qs = Qn_(name);
638
639 goods_type_iterate(pgood) {
640 if (!fc_strcasecmp(goods_rule_name(pgood), qs)) {
641 return pgood;
642 }
643 } goods_type_iterate_end;
644
645 return NULL;
646}
647
648/*********************************************************************/
652 struct goods_type *goods_by_translated_name(const char *name)
653{
654 goods_type_iterate(pgood) {
655 if (0 == strcmp(goods_name_translation(pgood), name)) {
656 return pgood;
657 }
658 } goods_type_iterate_end;
659
660 return NULL;
661}
662
663/*********************************************************************/
666 bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
667{
668 return BV_ISSET(pgood->flags, flag);
669}
670
671/*********************************************************************/
674 bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
675 struct unit *punit)
676{
677 return are_reqs_active(&(const struct req_context) {
678 .player = city_owner(pcity),
679 .city = pcity,
680 .tile = city_tile(pcity),
681 .unit = punit,
682 .unittype = punit ? unit_type_get(punit) : NULL,
683 },
684 NULL,
685 &pgood->reqs, RPT_CERTAIN);
686}
687
688/*********************************************************************/
691 bool city_receives_goods(const struct city *pcity,
692 const struct goods_type *pgood)
693{
694 trade_routes_iterate(pcity, proute) {
695 if (proute->goods == pgood
696 && (proute->dir == RDIR_TO || proute->dir == RDIR_BIDIRECTIONAL)) {
697 struct city *tcity = game_city_by_number(proute->partner);
698 enum trade_route_type type;
699 struct trade_route_settings *settings;
700
701 if (can_cities_trade(pcity, tcity)) {
702 return TRUE;
703 }
704
705 type = cities_trade_route_type(pcity, tcity);
706 settings = trade_route_settings_by_type(type);
707
708 if (settings->cancelling == TRI_ACTIVE) {
709 return TRUE;
710 }
711 }
712 } trade_routes_iterate_end;
713
714 return FALSE;
715}
716
717/*********************************************************************/
720 struct goods_type *goods_from_city_to_unit(struct city *src, struct unit *punit)
721{
722 int i = 0;
723 struct goods_type *potential[MAX_GOODS_TYPES];
724
725 goods_type_iterate(pgood) {
726 if (goods_can_be_provided(src, pgood, punit)) {
727 potential[i++] = pgood;
728 }
729 } goods_type_iterate_end;
730
731 if (i == 0) {
732 return NULL;
733 }
734
735 return potential[fc_rand(i)];
736}
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
base_city_celebrating
bool base_city_celebrating(const struct city *pcity)
Definition city.c:1606
city_map_to_tile
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:300
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
city_tile_output
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1255
city_map_tiles
int city_map_tiles(int city_radius_sq)
Definition city.c:166
city_can_work_tile
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1425
city.h
city_tile
#define city_tile(_pcity_)
Definition city.h:544
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_map_iterate_end
#define city_map_iterate_end
Definition city.h:169
city_map_iterate
#define city_map_iterate(_radius_sq, _index, _x, _y)
Definition city.h:165
is_free_worked_index
#define is_free_worked_index(city_tile_index)
Definition city.h:847
base
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2839
punit
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
id
int int id
Definition editgui_g.h:28
reqs
struct @21::@22 reqs
get_target_bonus_effects
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:691
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
effects.h
MAX_TRADE_ROUTES
#define MAX_TRADE_ROUTES
Definition fc_types.h:1111
Goods_type_id
int Goods_type_id
Definition fc_types.h:357
MAX_GOODS_TYPES
#define MAX_GOODS_TYPES
Definition fc_types.h:51
RPT_CERTAIN
@ RPT_CERTAIN
Definition fc_types.h:586
O_TRADE
@ O_TRADE
Definition fc_types.h:91
Qn_
#define Qn_(String)
Definition fcintl.h:89
game
struct civ_game game
Definition game.c:57
wld
struct world wld
Definition game.c:58
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
game.h
type
GType type
Definition repodlgs.c:1312
name
const char * name
Definition inputfile.c:127
log.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
real_map_distance
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:628
map_distance
int map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:652
map.h
rule_name_get
static const char * rule_name_get(const struct name_translation *ptrans)
Definition name_translation.h:112
name_translation_get
static const char * name_translation_get(const struct name_translation *ptrans)
Definition name_translation.h:121
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:34
are_reqs_active
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
Definition requirements.c:4361
settings
static struct setting settings[]
Definition settings.c:1378
CLIP
#define CLIP(lower, current, upper)
Definition shared.h:57
MAX
#define MAX(x, y)
Definition shared.h:54
size
size_t size
Definition specvec.h:72
strvec_destroy
void strvec_destroy(struct strvec *psv)
Definition string_vector.c:71
city
Definition city.h:309
city::surplus
int surplus[O_LAST]
Definition city.h:343
city::id
int id
Definition city.h:315
city::citizen_base
int citizen_base[O_LAST]
Definition city.h:347
city::routes
struct trade_route_list * routes
Definition city.h:332
city::size
citizens size
Definition city.h:320
city::tile
struct tile * tile
Definition city.h:311
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_map
Definition map_types.h:71
civ_map::xsize
int xsize
Definition map_types.h:77
civ_map::ysize
int ysize
Definition map_types.h:77
goods_type
Definition traderoutes.h:180
goods_type::to_pct
int to_pct
Definition traderoutes.h:188
goods_type::from_pct
int from_pct
Definition traderoutes.h:187
goods_type::id
int id
Definition traderoutes.h:181
goods_type::reqs
struct requirement_vector reqs
Definition traderoutes.h:185
goods_type::onetime_pct
int onetime_pct
Definition traderoutes.h:189
goods_type::ruledit_disabled
bool ruledit_disabled
Definition traderoutes.h:183
goods_type::flags
bv_goods_flags flags
Definition traderoutes.h:191
goods_type::helptext
struct strvec * helptext
Definition traderoutes.h:193
goods_type::name
struct name_translation name
Definition traderoutes.h:182
packet_game_info::min_trade_route_val
int min_trade_route_val
Definition packets_gen.h:160
packet_game_info::trade_world_rel_pct
int trade_world_rel_pct
Definition packets_gen.h:159
packet_game_info::trade_revenue_style
enum trade_revenue_style trade_revenue_style
Definition packets_gen.h:237
packet_game_info::caravan_bonus_style
enum caravan_bonus_style caravan_bonus_style
Definition packets_gen.h:135
packet_game_info::trademindist
int trademindist
Definition packets_gen.h:236
packet_ruleset_control::num_goods_types
int num_goods_types
Definition packets_gen.h:1464
player_diplstate
Definition player.h:200
player_diplstate::type
enum diplstate_type type
Definition player.h:201
player
Definition player.h:249
req_context
Definition requirements.h:99
tile
Definition tile.h:49
trade_route_settings
Definition traderoutes.h:75
trade_route_settings::trade_pct
int trade_pct
Definition traderoutes.h:76
trade_route
Definition traderoutes.h:83
trade_route::dir
enum route_direction dir
Definition traderoutes.h:86
trade_route::goods
struct goods_type * goods
Definition traderoutes.h:87
trade_route::value
int value
Definition traderoutes.h:85
unit
Definition unit.h:138
world::map
struct civ_map map
Definition world_object.h:38
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
tile.h
max_trade_prod
int max_trade_prod(const struct city *pcity)
Definition traderoutes.c:444
goods_from_city_to_unit
struct goods_type * goods_from_city_to_unit(struct city *src, struct unit *punit)
Definition traderoutes.c:720
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
cities_trade_route_type
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
trade_route_cancelling_type_names
const char * trade_route_cancelling_type_names[]
Definition traderoutes.c:37
trade_route_type_trade_pct
int trade_route_type_trade_pct(enum trade_route_type type)
Definition traderoutes.c:122
trade_base_between_cities
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:322
city_num_trade_routes
int city_num_trade_routes(const struct city *pcity)
Definition traderoutes.c:383
goods_number
Goods_type_id goods_number(const struct goods_type *pgood)
Definition traderoutes.c:579
goods
static struct goods_type goods[MAX_GOODS_TYPES]
Definition traderoutes.c:43
goods_has_flag
bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
Definition traderoutes.c:666
trade_route_cancelling_type_by_name
enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name(const char *name)
Definition traderoutes.c:184
trade_route_type_name
const char * trade_route_type_name(enum trade_route_type type)
Definition traderoutes.c:148
max_tile_trade
static int max_tile_trade(const struct city *pcity)
Definition traderoutes.c:399
trade_route_settings_by_type
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
Definition traderoutes.c:201
trtss
struct trade_route_settings trtss[TRT_LAST]
Definition traderoutes.c:41
goods_by_rule_name
struct goods_type * goods_by_rule_name(const char *name)
Definition traderoutes.c:629
trade_from_route
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
Definition traderoutes.c:358
goods_rule_name
const char * goods_rule_name(struct goods_type *pgood)
Definition traderoutes.c:620
max_trade_routes
unsigned max_trade_routes(const struct city *pcity)
Definition traderoutes.c:48
goods_name_translation
const char * goods_name_translation(struct goods_type *pgood)
Definition traderoutes.c:612
trade_route_types_init
void trade_route_types_init(void)
Definition traderoutes.c:134
goods_index
Goods_type_id goods_index(const struct goods_type *pgood)
Definition traderoutes.c:592
best_value
static int best_value(const void *a, const void *b)
Definition traderoutes.c:391
goods_by_translated_name
struct goods_type * goods_by_translated_name(const char *name)
Definition traderoutes.c:652
get_caravan_enter_city_trade_bonus
int get_caravan_enter_city_trade_bonus(const struct city *pc1, const struct city *pc2, struct goods_type *pgood, const bool establish_trade)
Definition traderoutes.c:467
city_trade_removable
int city_trade_removable(const struct city *pcity, struct trade_route_list *would_remove)
Definition traderoutes.c:231
can_establish_trade_route
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:275
goods_by_number
struct goods_type * goods_by_number(Goods_type_id id)
Definition traderoutes.c:602
trade_route_cancelling_type_name
const char * trade_route_cancelling_type_name(enum trade_route_illegal_cancelling type)
Definition traderoutes.c:174
goods_init
void goods_init(void)
Definition traderoutes.c:546
city_receives_goods
bool city_receives_goods(const struct city *pcity, const struct goods_type *pgood)
Definition traderoutes.c:691
goods_free
void goods_free(void)
Definition traderoutes.c:562
goods_can_be_provided
bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood, struct unit *punit)
Definition traderoutes.c:674
trade_route_type_names
const char * trade_route_type_names[]
Definition traderoutes.c:32
trade_route_type_by_name
enum trade_route_type trade_route_type_by_name(const char *name)
Definition traderoutes.c:158
have_cities_trade_route
bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:532
traderoutes.h
goods_type_iterate_end
#define goods_type_iterate_end
Definition traderoutes.h:223
trade_route_illegal_cancelling
trade_route_illegal_cancelling
Definition traderoutes.h:29
TRI_LAST
@ TRI_LAST
Definition traderoutes.h:33
TRI_ACTIVE
@ TRI_ACTIVE
Definition traderoutes.h:30
goods_type_iterate
#define goods_type_iterate(_p)
Definition traderoutes.h:217
trade_routes_iterate_end
#define trade_routes_iterate_end
Definition traderoutes.h:133
trade_partners_iterate_end
#define trade_partners_iterate_end
Definition traderoutes.h:165
trade_routes_iterate
#define trade_routes_iterate(c, proute)
Definition traderoutes.h:129
trade_partners_iterate
#define trade_partners_iterate(c, p)
Definition traderoutes.h:160
trade_route_type
trade_route_type
Definition traderoutes.h:37
TRT_NATIONAL_IC
@ TRT_NATIONAL_IC
Definition traderoutes.h:39
TRT_TEAM_IC
@ TRT_TEAM_IC
Definition traderoutes.h:47
TRT_ALLY_IC
@ TRT_ALLY_IC
Definition traderoutes.h:43
TRT_IN_IC
@ TRT_IN_IC
Definition traderoutes.h:41
TRT_NATIONAL
@ TRT_NATIONAL
Definition traderoutes.h:38
TRT_LAST
@ TRT_LAST
Definition traderoutes.h:48
TRT_IN
@ TRT_IN
Definition traderoutes.h:40
TRT_TEAM
@ TRT_TEAM
Definition traderoutes.h:46
TRT_ALLY
@ TRT_ALLY
Definition traderoutes.h:42
TRT_ENEMY_IC
@ TRT_ENEMY_IC
Definition traderoutes.h:45
TRT_ENEMY
@ TRT_ENEMY
Definition traderoutes.h:44
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unittype.h