Freeciv-3.1
Loading...
Searching...
No Matches
Functions | Variables
traderoutes.c File Reference
#include "log.h"
#include "rand.h"
#include "city.h"
#include "effects.h"
#include "game.h"
#include "map.h"
#include "tile.h"
#include "unittype.h"
#include "traderoutes.h"

Go to the source code of this file.

Functions

unsigned max_trade_routes (const struct city *pcity)
 
enum trade_route_type cities_trade_route_type (const struct city *pcity1, const struct city *pcity2)
 
int trade_route_type_trade_pct (enum trade_route_type type)
 
void trade_route_types_init (void)
 
const char * trade_route_type_name (enum trade_route_type type)
 
enum trade_route_type trade_route_type_by_name (const char *name)
 
const char * trade_route_cancelling_type_name (enum trade_route_illegal_cancelling type)
 
enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name (const char *name)
 
struct trade_route_settingstrade_route_settings_by_type (enum trade_route_type type)
 
bool can_cities_trade (const struct city *pc1, const struct city *pc2)
 
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)
 
int trade_base_between_cities (const struct city *pc1, const struct city *pc2)
 
int trade_from_route (const struct city *pc1, const struct trade_route *route, int base)
 
int city_num_trade_routes (const struct city *pcity)
 
static int best_value (const void *a, const void *b)
 
static int max_tile_trade (const struct city *pcity)
 
int max_trade_prod (const struct city *pcity)
 
int get_caravan_enter_city_trade_bonus (const struct city *pc1, const struct city *pc2, struct goods_type *pgood, const bool establish_trade)
 
bool have_cities_trade_route (const struct city *pc1, const struct city *pc2)
 
void goods_init (void)
 
void goods_free (void)
 
Goods_type_id goods_number (const struct goods_type *pgood)
 
Goods_type_id goods_index (const struct goods_type *pgood)
 
struct goods_typegoods_by_number (Goods_type_id id)
 
const char * goods_name_translation (struct goods_type *pgood)
 
const char * goods_rule_name (struct goods_type *pgood)
 
struct goods_typegoods_by_rule_name (const char *name)
 
struct goods_typegoods_by_translated_name (const char *name)
 
bool goods_has_flag (const struct goods_type *pgood, enum goods_flag_id flag)
 
bool goods_can_be_provided (struct city *pcity, struct goods_type *pgood, struct unit *punit)
 
bool city_receives_goods (const struct city *pcity, const struct goods_type *pgood)
 
struct goods_typegoods_from_city_to_unit (struct city *src, struct unit *punit)
 

Variables

const char * trade_route_type_names []
 
const char * trade_route_cancelling_type_names []
 
struct trade_route_settings trtss [TRT_LAST]
 
static struct goods_type goods [MAX_GOODS_TYPES]
 

Function Documentation

◆ best_value()

static int best_value ( const void *  a,
const void *  b 
)
static

Comparator used in max_tile_trade.

Definition at line 391 of file traderoutes.c.

Referenced by check_for_game_over(), consider_settler_action(), dem_line_item(), max_tile_trade(), and settler_evaluate_city_requests().

◆ can_cities_trade()

bool can_cities_trade ( const struct city pc1,
const struct city pc2 
)

◆ can_establish_trade_route()

bool can_establish_trade_route ( const struct city pc1,
const struct city pc2 
)

Returns TRUE iff the two cities can establish a trade route. We look at the distance and ownership of the cities as well as their existing trade routes. Should only be called if you already know that can_cities_trade().

Definition at line 275 of file traderoutes.c.

Referenced by trade_generator::calculate_inner(), dai_manage_caravan(), is_action_possible(), popup_info_text(), real_menus_update(), reestablish_city_trade_routes(), trade_benefit(), and windfall_benefit().

◆ cities_trade_route_type()

enum trade_route_type cities_trade_route_type ( const struct city pcity1,
const struct city pcity2 
)

◆ city_num_trade_routes()

int city_num_trade_routes ( const struct city pcity)

◆ city_receives_goods()

bool city_receives_goods ( const struct city pcity,
const struct goods_type pgood 
)

Does city receive goods

Definition at line 691 of file traderoutes.c.

Referenced by is_good_req_active().

◆ city_trade_removable()

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. The target routes to be removed will be put into 'would_remove', if set.

Definition at line 231 of file traderoutes.c.

Referenced by can_establish_trade_route(), do_unit_establish_trade(), and one_city_trade_benefit().

◆ 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 
)

Returns the revenue trade bonus - you get this when establishing a trade route and also when you simply sell your trade goods at the new city.

If you change this calculation remember to also update its duplication in dai_choose_trade_route()

pgood can be NULL for ignoring good's onetime_pct.

Definition at line 467 of file traderoutes.c.

Referenced by do_unit_establish_trade(), get_act_sel_action_custom_text(), real_menus_update(), and windfall_benefit().

◆ goods_by_number()

struct goods_type * goods_by_number ( Goods_type_id  id)

◆ goods_by_rule_name()

struct goods_type * goods_by_rule_name ( const char *  name)

Returns goods type matching rule name or NULL if there is no goods type with such name.

Definition at line 629 of file traderoutes.c.

Referenced by tab_good::initialize_new_good(), tab_good::select_good(), sg_load_player_city(), sg_load_player_unit(), and universal_value_from_str().

◆ goods_by_translated_name()

struct goods_type * goods_by_translated_name ( const char *  name)

Returns goods type matching the translated name, or NULL if there is no goods type with that name.

Definition at line 652 of file traderoutes.c.

Referenced by help_update_goods(), and help_widget::set_topic_goods().

◆ goods_can_be_provided()

bool goods_can_be_provided ( struct city pcity,
struct goods_type pgood,
struct unit punit 
)

Can the city provide goods.

Definition at line 674 of file traderoutes.c.

Referenced by goods_from_city_to_unit(), and update_city_activities().

◆ goods_free()

void goods_free ( void  )

Free the memory associated with goods

Definition at line 562 of file traderoutes.c.

Referenced by game_ruleset_free().

◆ goods_from_city_to_unit()

struct goods_type * goods_from_city_to_unit ( struct city src,
struct unit punit 
)

Return goods type for the new trade route between given cities.

Definition at line 720 of file traderoutes.c.

Referenced by do_unit_establish_trade(), and unit_get_goods().

◆ goods_has_flag()

bool goods_has_flag ( const struct goods_type pgood,
enum goods_flag_id  flag 
)

Check if goods has given flag

Definition at line 666 of file traderoutes.c.

Referenced by do_unit_establish_trade(), save_game_ruleset(), and update_city_activities().

◆ goods_index()

Goods_type_id goods_index ( const struct goods_type pgood)

Return the goods index.

Currently same as goods_number(), paired with goods_count() indicates use as an array index.

Definition at line 592 of file traderoutes.c.

Referenced by load_game_names(), load_ruleset_game(), package_unit(), and tab_good::refresh().

◆ goods_init()

void goods_init ( void  )

Initialize goods structures.

Definition at line 546 of file traderoutes.c.

Referenced by game_ruleset_init().

◆ goods_name_translation()

const char * goods_name_translation ( struct goods_type pgood)

◆ goods_number()

Goods_type_id goods_number ( const struct goods_type pgood)

Return the goods id.

Definition at line 579 of file traderoutes.c.

Referenced by package_city(), send_ruleset_goods(), and universal_number().

◆ goods_rule_name()

const char * goods_rule_name ( struct goods_type pgood)

◆ have_cities_trade_route()

bool have_cities_trade_route ( const struct city pc1,
const struct city pc2 
)

Check if cities have an established trade route.

Definition at line 532 of file traderoutes.c.

Referenced by trade_generator::calculate_inner(), can_establish_trade_route(), do_unit_establish_trade(), and draw_calculated_trade_routes().

◆ max_tile_trade()

static int max_tile_trade ( const struct city pcity)
static

Returns the maximum trade production of the tiles of the city.

Definition at line 399 of file traderoutes.c.

Referenced by max_trade_prod().

◆ max_trade_prod()

int max_trade_prod ( const struct city pcity)

Returns the maximum trade production of a city.

Definition at line 444 of file traderoutes.c.

Referenced by dai_choose_trade_route(), and get_caravan_enter_city_trade_bonus().

◆ max_trade_routes()

unsigned max_trade_routes ( const struct city pcity)

◆ trade_base_between_cities()

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.

Definition at line 322 of file traderoutes.c.

Referenced by can_establish_trade_route(), dai_effect_value(), do_unit_establish_trade(), get_act_sel_action_custom_text(), max_trade_prod(), popup_info_text(), real_menus_update(), set_city_production(), and trade_benefit().

◆ trade_from_route()

int trade_from_route ( const struct city pc1,
const struct trade_route route,
int  base 
)

Get trade income specific to route's good.

Definition at line 358 of file traderoutes.c.

Referenced by set_city_production().

◆ trade_route_cancelling_type_by_name()

enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name ( const char *  name)

Get trade route cancelling type by name.

Definition at line 184 of file traderoutes.c.

Referenced by load_ruleset_game().

◆ trade_route_cancelling_type_name()

const char * trade_route_cancelling_type_name ( enum trade_route_illegal_cancelling  type)

Return human readable name of trade route cancelling type

Definition at line 174 of file traderoutes.c.

Referenced by save_game_ruleset().

◆ trade_route_settings_by_type()

struct trade_route_settings * trade_route_settings_by_type ( enum trade_route_type  type)

◆ trade_route_type_by_name()

enum trade_route_type trade_route_type_by_name ( const char *  name)

Get trade route type by name.

Definition at line 158 of file traderoutes.c.

Referenced by load_ruleset_game().

◆ trade_route_type_name()

const char * trade_route_type_name ( enum trade_route_type  type)

Return human readable name of trade route type

Definition at line 148 of file traderoutes.c.

Referenced by save_game_ruleset().

◆ trade_route_type_trade_pct()

int trade_route_type_trade_pct ( enum trade_route_type  type)

Return percentage bonus for trade route type.

Definition at line 122 of file traderoutes.c.

Referenced by can_cities_trade(), dai_choose_trade_route(), and trade_base_between_cities().

◆ trade_route_types_init()

void trade_route_types_init ( void  )

Initialize trade route types.

Definition at line 134 of file traderoutes.c.

Referenced by game_ruleset_init().

Variable Documentation

◆ goods

struct goods_type goods[MAX_GOODS_TYPES]
static

◆ trade_route_cancelling_type_names

const char* trade_route_cancelling_type_names[]
Initial value:
= {
"Active", "Inactive", "Cancel"
}

Definition at line 37 of file traderoutes.c.

Referenced by trade_route_cancelling_type_by_name(), and trade_route_cancelling_type_name().

◆ trade_route_type_names

const char* trade_route_type_names[]
Initial value:
= {
"National", "NationalIC", "IN", "INIC", "Ally", "AllyIC",
"Enemy", "EnemyIC", "Team", "TeamIC"
}

Definition at line 32 of file traderoutes.c.

Referenced by trade_route_type_by_name(), and trade_route_type_name().

◆ trtss