Freeciv21
Develop your civilization from humble roots to a global empire
improvement.cpp File Reference
#include "fcintl.h"
#include "log.h"
#include "shared.h"
#include "support.h"
#include "game.h"
#include "victory.h"
#include "improvement.h"
+ Include dependency graph for improvement.cpp:

Go to the source code of this file.

Functions

void improvements_init ()
 Initialize building structures. More...
 
static void improvement_free (struct impr_type *p)
 Frees the memory associated with this improvement. More...
 
void improvements_free ()
 Frees the memory associated with all improvements. More...
 
void improvement_feature_cache_init ()
 Cache features of the improvement. More...
 
struct impr_typeimprovement_array_first ()
 Return the first item of improvements. More...
 
const struct impr_typeimprovement_array_last ()
 Return the last item of improvements. More...
 
Impr_type_id improvement_count ()
 Return the number of improvements. More...
 
Impr_type_id improvement_index (const struct impr_type *pimprove)
 Return the improvement index. More...
 
Impr_type_id improvement_number (const struct impr_type *pimprove)
 Return the improvement index. More...
 
struct impr_typeimprovement_by_number (const Impr_type_id id)
 Returns the improvement type for the given index/ID. More...
 
const struct impr_typevalid_improvement (const struct impr_type *pimprove)
 Returns pointer when the improvement_type "exists" in this game, returns nullptr otherwise. More...
 
const char * improvement_name_translation (const struct impr_type *pimprove)
 Return the (translated) name of the given improvement. More...
 
const char * improvement_rule_name (const struct impr_type *pimprove)
 Return the (untranslated) rule name of the improvement. More...
 
int impr_base_build_shield_cost (const struct impr_type *pimprove)
 Returns the base number of shields it takes to build this improvement. More...
 
int impr_estimate_build_shield_cost (const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
 Returns estimate of the number of shields it takes to build this improvement. More...
 
int impr_build_shield_cost (const struct city *pcity, const struct impr_type *pimprove)
 Returns the number of shields it takes to build this improvement. More...
 
int impr_buy_gold_cost (const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
 Returns the amount of gold it takes to rush this improvement. More...
 
int impr_sell_gold (const struct impr_type *pimprove)
 Returns the amount of gold received when this improvement is sold. More...
 
bool is_wonder (const struct impr_type *pimprove)
 Returns whether improvement is some kind of wonder. More...
 
struct impr_typeimprovement_by_translated_name (const char *name)
 Does a linear search of improvement_types[].name.translated Returns nullptr when none match. More...
 
struct impr_typeimprovement_by_rule_name (const char *name)
 Does a linear search of improvement_types[].name.vernacular Returns nullptr when none match. More...
 
bool improvement_has_flag (const struct impr_type *pimprove, enum impr_flag_id flag)
 Return TRUE if the impr has this flag otherwise FALSE. More...
 
bool is_improvement_visible (const struct impr_type *pimprove)
 Return TRUE if the improvement should be visible to others without spying. More...
 
bool can_improvement_go_obsolete (const struct impr_type *pimprove)
 Return TRUE if the improvement can ever go obsolete. More...
 
bool improvement_obsolete (const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
 Returns TRUE if the improvement or wonder is obsolete. More...
 
static bool impr_provides_buildable_units (const struct city *pcity, const struct impr_type *pimprove)
 Returns TRUE iff improvement provides units buildable in city. More...
 
static bool impr_provides_buildable_extras (const struct city *pcity, const struct impr_type *pimprove)
 Returns TRUE iff improvement provides extras buildable in city. More...
 
static bool impr_prevents_disaster (const struct city *pcity, const struct impr_type *pimprove)
 Returns TRUE iff improvement prevents a disaster in city. More...
 
static bool impr_protects_vs_actions (const struct city *pcity, const struct impr_type *pimprove)
 Returns TRUE iff improvement protects against an action on the city FIXME: This is prone to false positives: for example, if one requires a special tech or unit to perform an action, and no other player has or can gain that tech or unit, protection is still claimed. More...
 
static bool improvement_has_side_effects (const struct city *pcity, const struct impr_type *pimprove)
 Check if an improvement has side effects for a city. More...
 
static bool improvement_has_effects (const struct city *pcity, const struct impr_type *pimprove)
 Returns TRUE iff improvement provides some effect (good or bad). More...
 
bool is_improvement_productive (const struct city *pcity, const struct impr_type *pimprove)
 Returns TRUE if an improvement in a city is productive, in some way. More...
 
bool is_improvement_redundant (const struct city *pcity, const struct impr_type *pimprove)
 Returns TRUE if an improvement in a city is redundant, that is, the city wouldn't lose anything by losing the improvement, or gain anything by building it. More...
 
bool can_player_build_improvement_direct (const struct player *p, const struct impr_type *pimprove)
 Whether player can build given building somewhere, ignoring whether it is obsolete. More...
 
bool can_player_build_improvement_now (const struct player *p, struct impr_type *pimprove)
 Whether player can build given building somewhere immediately. More...
 
bool can_player_build_improvement_later (const struct player *p, const struct impr_type *pimprove)
 Whether player can eventually build given building somewhere – i.e., returns TRUE if building is available with current tech OR will be available with future tech. More...
 
bool is_great_wonder (const struct impr_type *pimprove)
 Is this building a great wonder? More...
 
bool is_small_wonder (const struct impr_type *pimprove)
 Is this building a small wonder? More...
 
bool is_improvement (const struct impr_type *pimprove)
 Is this building a regular improvement? More...
 
bool is_special_improvement (const struct impr_type *pimprove)
 Returns TRUE if this is a "special" improvement. More...
 
void wonder_built (const struct city *pcity, const struct impr_type *pimprove)
 Build a wonder in the city. More...
 
void wonder_destroyed (const struct city *pcity, const struct impr_type *pimprove)
 Remove a wonder from a city and destroy it if it's a great wonder. More...
 
bool wonder_is_lost (const struct player *pplayer, const struct impr_type *pimprove)
 Returns whether the player has lost this wonder after having owned it (small or great). More...
 
bool wonder_is_built (const struct player *pplayer, const struct impr_type *pimprove)
 Returns whether the player is currently in possession of this wonder (small or great) and it hasn't been just built this turn. More...
 
struct citycity_from_wonder (const struct player *pplayer, const struct impr_type *pimprove)
 Get the world city with this wonder (small or great). More...
 
bool great_wonder_is_built (const struct impr_type *pimprove)
 Returns whether this wonder is currently built. More...
 
bool great_wonder_is_destroyed (const struct impr_type *pimprove)
 Returns whether this wonder has been destroyed. More...
 
bool great_wonder_is_available (const struct impr_type *pimprove)
 Returns whether this wonder can be currently built. More...
 
struct citycity_from_great_wonder (const struct impr_type *pimprove)
 Get the world city with this great wonder. More...
 
struct playergreat_wonder_owner (const struct impr_type *pimprove)
 Get the player owning this small wonder. More...
 
struct citycity_from_small_wonder (const struct player *pplayer, const struct impr_type *pimprove)
 Get the player city with this small wonder. More...
 
bool can_sell_building (const struct impr_type *pimprove)
 Return TRUE iff the improvement can be sold. More...
 
bool can_city_sell_building (const struct city *pcity, const struct impr_type *pimprove)
 Return TRUE iff the city can sell the given improvement. More...
 
enum test_result test_player_sell_building_now (struct player *pplayer, const city *pcity, const struct impr_type *pimprove)
 Return TRUE iff the player can sell the given improvement from city. More...
 
const struct impr_typeimprovement_replacement (const struct impr_type *pimprove)
 Try to find a sensible replacement building, based on other buildings that may have caused this one to become obsolete. More...
 

Variables

static struct impr_type improvement_types [B_LAST]
 All the city improvements: Use improvement_by_number(id) to access the array. More...
 

Function Documentation

◆ can_city_sell_building()

bool can_city_sell_building ( const struct city pcity,
const struct impr_type pimprove 
)

◆ can_improvement_go_obsolete()

bool can_improvement_go_obsolete ( const struct impr_type pimprove)

Return TRUE if the improvement can ever go obsolete.

Can be used for buildings or wonders.

Definition at line 381 of file improvement.cpp.

Referenced by dai_can_requirement_be_met_in_city(), and req_text_insert().

◆ can_player_build_improvement_direct()

bool can_player_build_improvement_direct ( const struct player p,
const struct impr_type pimprove 
)

Whether player can build given building somewhere, ignoring whether it is obsolete.

Definition at line 614 of file improvement.cpp.

Referenced by can_city_build_improvement_direct(), can_player_build_improvement_now(), can_player_build_unit_direct(), dai_wants_defender_against(), and dai_wants_role_unit().

◆ can_player_build_improvement_later()

bool can_player_build_improvement_later ( const struct player p,
const struct impr_type pimprove 
)

Whether player can eventually build given building somewhere – i.e., returns TRUE if building is available with current tech OR will be available with future tech.

Returns FALSE if building is obsolete.

Definition at line 691 of file improvement.cpp.

Referenced by ba_human_wants(), can_city_build_improvement_later(), collect_eventually_buildable_targets(), and dai_build_adv_adjust().

◆ can_player_build_improvement_now()

bool can_player_build_improvement_now ( const struct player p,
struct impr_type pimprove 
)

Whether player can build given building somewhere immediately.

Returns FALSE if building is obsolete.

Definition at line 674 of file improvement.cpp.

Referenced by collect_eventually_buildable_targets().

◆ can_sell_building()

bool can_sell_building ( const struct impr_type pimprove)

Return TRUE iff the improvement can be sold.

Definition at line 989 of file improvement.cpp.

Referenced by eco_report::selection_changed().

◆ city_from_great_wonder()

struct city* city_from_great_wonder ( const struct impr_type pimprove)

Get the world city with this great wonder.

This doesn't always success on the client side.

Definition at line 926 of file improvement.cpp.

Referenced by calc_civ_score(), found_new_tech(), handle_edit_city(), and report_wonders_of_the_world().

◆ city_from_small_wonder()

struct city* city_from_small_wonder ( const struct player pplayer,
const struct impr_type pimprove 
)

Get the player city with this small wonder.

Definition at line 974 of file improvement.cpp.

Referenced by base_want(), build_free_small_wonders(), and handle_edit_city().

◆ city_from_wonder()

struct city* city_from_wonder ( const struct player pplayer,
const struct impr_type pimprove 
)

Get the world city with this wonder (small or great).

This doesn't always succeed on the client side, and even when it does, it may return an "invisible" city whose members are unexpectedly nullptr; take care.

Definition at line 845 of file improvement.cpp.

Referenced by city_from_great_wonder(), city_from_small_wonder(), and num_continent_buildings().

◆ great_wonder_is_available()

bool great_wonder_is_available ( const struct impr_type pimprove)

Returns whether this wonder can be currently built.

Definition at line 914 of file improvement.cpp.

Referenced by can_player_build_improvement_direct(), can_player_build_improvement_later(), city_improvement_name_translation(), and city_turns_to_build().

◆ great_wonder_is_built()

bool great_wonder_is_built ( const struct impr_type pimprove)

Returns whether this wonder is currently built.

Definition at line 888 of file improvement.cpp.

Referenced by can_player_build_unit_direct(), num_world_buildings(), and num_world_buildings_total().

◆ great_wonder_is_destroyed()

bool great_wonder_is_destroyed ( const struct impr_type pimprove)

Returns whether this wonder has been destroyed.

Definition at line 903 of file improvement.cpp.

Referenced by can_player_build_unit_direct(), city_improvement_name_translation(), num_world_buildings_total(), report_wonders_of_the_world(), and sg_save_players().

◆ great_wonder_owner()

struct player* great_wonder_owner ( const struct impr_type pimprove)

Get the player owning this small wonder.

This doesn't always success on the client side.

Definition at line 958 of file improvement.cpp.

Referenced by can_player_build_unit_direct().

◆ impr_base_build_shield_cost()

int impr_base_build_shield_cost ( const struct impr_type pimprove)

Returns the base number of shields it takes to build this improvement.

This one does not take city specific bonuses in to account.

Definition at line 233 of file improvement.cpp.

Referenced by help_widget::set_topic_building().

◆ impr_build_shield_cost()

int impr_build_shield_cost ( const struct city pcity,
const struct impr_type pimprove 
)

◆ impr_buy_gold_cost()

int impr_buy_gold_cost ( const struct city pcity,
const struct impr_type pimprove,
int  shields_in_stock 
)

Returns the amount of gold it takes to rush this improvement.

Definition at line 277 of file improvement.cpp.

Referenced by city_production_buy_gold_cost(), military_advisor_choose_build(), and wonder_benefit().

◆ impr_estimate_build_shield_cost()

int impr_estimate_build_shield_cost ( const struct player pplayer,
const struct tile ptile,
const struct impr_type pimprove 
)

Returns estimate of the number of shields it takes to build this improvement.

pplayer and ptile can be nullptr, but that might reduce quality of the estimate.

Definition at line 245 of file improvement.cpp.

Referenced by get_tooltip_improvement().

◆ impr_prevents_disaster()

static bool impr_prevents_disaster ( const struct city pcity,
const struct impr_type pimprove 
)
static

Returns TRUE iff improvement prevents a disaster in city.

Definition at line 467 of file improvement.cpp.

Referenced by improvement_has_side_effects().

◆ impr_protects_vs_actions()

static bool impr_protects_vs_actions ( const struct city pcity,
const struct impr_type pimprove 
)
static

Returns TRUE iff improvement protects against an action on the city FIXME: This is prone to false positives: for example, if one requires a special tech or unit to perform an action, and no other player has or can gain that tech or unit, protection is still claimed.

Definition at line 493 of file improvement.cpp.

Referenced by improvement_has_side_effects().

◆ impr_provides_buildable_extras()

static bool impr_provides_buildable_extras ( const struct city pcity,
const struct impr_type pimprove 
)
static

Returns TRUE iff improvement provides extras buildable in city.

Definition at line 438 of file improvement.cpp.

Referenced by improvement_has_side_effects().

◆ impr_provides_buildable_units()

static bool impr_provides_buildable_units ( const struct city pcity,
const struct impr_type pimprove 
)
static

Returns TRUE iff improvement provides units buildable in city.

Definition at line 415 of file improvement.cpp.

Referenced by improvement_has_side_effects().

◆ impr_sell_gold()

int impr_sell_gold ( const struct impr_type pimprove)

◆ improvement_array_first()

struct impr_type* improvement_array_first ( )

Return the first item of improvements.

Definition at line 128 of file improvement.cpp.

◆ improvement_array_last()

const struct impr_type* improvement_array_last ( )

Return the last item of improvements.

Definition at line 139 of file improvement.cpp.

◆ improvement_by_number()

◆ improvement_by_rule_name()

struct impr_type* improvement_by_rule_name ( const char *  name)

◆ improvement_by_translated_name()

struct impr_type* improvement_by_translated_name ( const char *  name)

Does a linear search of improvement_types[].name.translated Returns nullptr when none match.

Definition at line 326 of file improvement.cpp.

Referenced by help_dialog::make_tree(), and help_widget::set_topic_building().

◆ improvement_count()

◆ improvement_feature_cache_init()

void improvement_feature_cache_init ( )

Cache features of the improvement.

Definition at line 77 of file improvement.cpp.

Referenced by handle_rulesets_ready(), and load_rulesetdir().

◆ improvement_free()

static void improvement_free ( struct impr_type p)
static

Frees the memory associated with this improvement.

Definition at line 57 of file improvement.cpp.

Referenced by improvements_free().

◆ improvement_has_effects()

static bool improvement_has_effects ( const struct city pcity,
const struct impr_type pimprove 
)
static

Returns TRUE iff improvement provides some effect (good or bad).

Definition at line 539 of file improvement.cpp.

Referenced by is_improvement_productive().

◆ improvement_has_flag()

◆ improvement_has_side_effects()

static bool improvement_has_side_effects ( const struct city pcity,
const struct impr_type pimprove 
)
static

Check if an improvement has side effects for a city.

Side effects are any benefits that accrue that are not tracked by the effects system.

Note that this function will always return FALSE if the improvement does not currently provide a benefit to the city (for example, if the improvement has not yet been built, or another city benefits from the improvement in this city (i.e. Wonders)).

Definition at line 523 of file improvement.cpp.

Referenced by is_improvement_productive(), and is_improvement_redundant().

◆ improvement_index()

◆ improvement_name_translation()

◆ improvement_number()

◆ improvement_obsolete()

bool improvement_obsolete ( const struct player pplayer,
const struct impr_type pimprove,
const struct city pcity 
)

◆ improvement_replacement()

const struct impr_type* improvement_replacement ( const struct impr_type pimprove)

Try to find a sensible replacement building, based on other buildings that may have caused this one to become obsolete.

Definition at line 1034 of file improvement.cpp.

Referenced by building_upgrades_to().

◆ improvement_rule_name()

◆ improvements_free()

void improvements_free ( )

Frees the memory associated with all improvements.

Definition at line 68 of file improvement.cpp.

Referenced by game_ruleset_free().

◆ improvements_init()

void improvements_init ( )

Initialize building structures.

Definition at line 38 of file improvement.cpp.

Referenced by game_ruleset_init().

◆ is_great_wonder()

◆ is_improvement()

◆ is_improvement_productive()

bool is_improvement_productive ( const struct city pcity,
const struct impr_type pimprove 
)

Returns TRUE if an improvement in a city is productive, in some way.

Note that unproductive improvements may become productive later, if appropriate conditions are met (e.g. a special building that isn't producing units under the current government might under another).

Definition at line 570 of file improvement.cpp.

Referenced by ba_human_wants(), building_advisor(), and building_crucial().

◆ is_improvement_redundant()

bool is_improvement_redundant ( const struct city pcity,
const struct impr_type pimprove 
)

Returns TRUE if an improvement in a city is redundant, that is, the city wouldn't lose anything by losing the improvement, or gain anything by building it.

This means:

  • all of its effects (if any) are provided by other means, or it's obsolete (and thus assumed to have no effect); and
  • it's not enabling the city to build some kind of units; and
  • it's not Coinage (IF_GOLD). (Note that it's not impossible that this improvement could become useful if circumstances changed, say if a new government enabled the building of its special units.)

Definition at line 591 of file improvement.cpp.

Referenced by city_improvement_name_translation(), dai_city_sell_noncritical(), get_economy_report_data(), city_production_delegate::paint(), and sell_all_improvements().

◆ is_improvement_visible()

bool is_improvement_visible ( const struct impr_type pimprove)

Return TRUE if the improvement should be visible to others without spying.

Definition at line 371 of file improvement.cpp.

Referenced by handle_city_short_info(), is_req_knowable(), popup_info_text(), and update_dumb_city().

◆ is_small_wonder()

◆ is_special_improvement()

bool is_special_improvement ( const struct impr_type pimprove)

Returns TRUE if this is a "special" improvement.

For example, spaceship parts and coinage in the default ruleset are considered special.

Definition at line 751 of file improvement.cpp.

Referenced by handle_edit_city(), and city_production_model::populate().

◆ is_wonder()

◆ test_player_sell_building_now()

enum test_result test_player_sell_building_now ( struct player pplayer,
const city pcity,
const struct impr_type pimprove 
)

Return TRUE iff the player can sell the given improvement from city.

If pimprove is nullptr, returns iff city could sell some building type (this does not check if such building is in this city)

Definition at line 997 of file improvement.cpp.

Referenced by freeciv::improvement_seller::add_to_menu(), freeciv::improvement_seller::operator()(), and really_handle_city_sell().

◆ valid_improvement()

const struct impr_type* valid_improvement ( const struct impr_type pimprove)

Returns pointer when the improvement_type "exists" in this game, returns nullptr otherwise.

An improvement_type doesn't exist for any of:

  • the improvement_type has been flagged as removed by setting its tech_req to A_LAST; [was not in current 2007-07-27]
  • it is a space part, and the spacerace is not enabled.

Definition at line 194 of file improvement.cpp.

Referenced by advisor_choose_build(), boot_help_texts(), building_upgrades_to(), can_player_build_improvement_direct(), can_player_build_improvement_later(), can_sell_building(), and manual_command().

◆ wonder_built()

void wonder_built ( const struct city pcity,
const struct impr_type pimprove 
)

Build a wonder in the city.

Definition at line 759 of file improvement.cpp.

Referenced by city_add_improvement().

◆ wonder_destroyed()

void wonder_destroyed ( const struct city pcity,
const struct impr_type pimprove 
)

Remove a wonder from a city and destroy it if it's a great wonder.

To transfer a great wonder, use great_wonder_transfer.

Definition at line 784 of file improvement.cpp.

Referenced by city_remove_improvement().

◆ wonder_is_built()

bool wonder_is_built ( const struct player pplayer,
const struct impr_type pimprove 
)

Returns whether the player is currently in possession of this wonder (small or great) and it hasn't been just built this turn.

Definition at line 821 of file improvement.cpp.

Referenced by api_methods_player_has_wonder(), great_wonder_is_built(), num_player_buildings(), and player_has_ever_built().

◆ wonder_is_lost()

bool wonder_is_lost ( const struct player pplayer,
const struct impr_type pimprove 
)

Returns whether the player has lost this wonder after having owned it (small or great).

Definition at line 808 of file improvement.cpp.

Referenced by player_has_ever_built(), and sg_save_player_main().

Variable Documentation

◆ improvement_types

struct impr_type improvement_types[B_LAST]
static

All the city improvements: Use improvement_by_number(id) to access the array.

The improvement_types array is now setup in: server/ruleset.c (for the server) client/packhand.c (for the client)

Definition at line 1 of file improvement.cpp.

Referenced by improvement_array_first(), improvement_array_last(), improvement_by_number(), improvement_index(), and improvements_init().