Freeciv21
Develop your civilization from humble roots to a global empire
improvement.h File Reference
#include "bitvector.h"
#include "name_translation.h"
#include "requirements.h"
#include "specenum_gen.h"
+ Include dependency graph for improvement.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  impr_type
 

Macros

#define B_LAST   MAX_NUM_BUILDINGS
 
#define B_NEVER   (nullptr)
 
#define SPECENUM_NAME   impr_flag_id
 
#define SPECENUM_VALUE0   IF_VISIBLE_BY_OTHERS
 
#define SPECENUM_VALUE0NAME   "VisibleByOthers"
 
#define SPECENUM_VALUE1   IF_SAVE_SMALL_WONDER
 
#define SPECENUM_VALUE1NAME   "SaveSmallWonder"
 
#define SPECENUM_VALUE2   IF_GOLD
 
#define SPECENUM_VALUE2NAME   "Gold"
 
#define SPECENUM_VALUE3   IF_DISASTER_PROOF
 
#define SPECENUM_VALUE3NAME   "DisasterProof"
 
#define SPECENUM_COUNT   IF_COUNT
 
#define SPECENUM_BITVECTOR   bv_impr_flags
 
#define WONDER_DESTROYED
 
#define WONDER_NOT_OWNED
 
#define WONDER_OWNED(player_id)   ((player_id) < MAX_NUM_PLAYER_SLOTS)
 
#define WONDER_LOST   (-1)
 
#define WONDER_NOT_BUILT   0
 
#define WONDER_BUILT(city_id)   ((city_id) > 0)
 
#define improvement_iterate(_p)
 
#define improvement_iterate_end
 
#define improvement_re_active_iterate(_p)
 
#define improvement_re_active_iterate_end
 

Functions

 BV_DEFINE (bv_imprs, B_LAST)
 
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...
 
struct impr_typeimprovement_by_rule_name (const char *name)
 Does a linear search of improvement_types[].name.vernacular Returns nullptr when none match. 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...
 
const char * improvement_rule_name (const struct impr_type *pimprove)
 Return the (untranslated) rule name of the improvement. More...
 
const char * improvement_name_translation (const struct impr_type *pimprove)
 Return the (translated) name of the given improvement. 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...
 
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_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_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_improvement_visible (const struct impr_type *pimprove)
 Return TRUE if the improvement should be visible to others without spying. 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_wonder (const struct impr_type *pimprove)
 Returns whether improvement is some kind of 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...
 
bool can_improvement_go_obsolete (const struct impr_type *pimprove)
 Return TRUE if the improvement can ever go obsolete. 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...
 
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 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...
 
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_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 can_player_build_improvement_now (const struct player *p, struct impr_type *pimprove)
 Whether player can build given building somewhere immediately. More...
 
void improvements_init ()
 Initialize building structures. 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...
 

Macro Definition Documentation

◆ B_LAST

#define B_LAST   MAX_NUM_BUILDINGS

Definition at line 33 of file improvement.h.

◆ B_NEVER

#define B_NEVER   (nullptr)

Definition at line 35 of file improvement.h.

◆ improvement_iterate

#define improvement_iterate (   _p)
Value:
{ \
if (nullptr != _p) { \
for (; _p <= improvement_array_last(); _p++) {
struct impr_type * improvement_array_first()
Return the first item of improvements.
const struct impr_type * improvement_array_last()
Return the last item of improvements.

Definition at line 193 of file improvement.h.

◆ improvement_iterate_end

#define improvement_iterate_end
Value:
} \
} \
}

Definition at line 199 of file improvement.h.

◆ improvement_re_active_iterate

#define improvement_re_active_iterate (   _p)
Value:
{ \
if (!_p->ruledit_disabled) {
#define improvement_iterate(_p)
Definition: improvement.h:193

Definition at line 204 of file improvement.h.

◆ improvement_re_active_iterate_end

#define improvement_re_active_iterate_end
Value:
} \
} \
improvement_iterate_end;

Definition at line 209 of file improvement.h.

◆ SPECENUM_BITVECTOR

#define SPECENUM_BITVECTOR   bv_impr_flags

Definition at line 52 of file improvement.h.

◆ SPECENUM_COUNT

#define SPECENUM_COUNT   IF_COUNT

Definition at line 51 of file improvement.h.

◆ SPECENUM_NAME

#define SPECENUM_NAME   impr_flag_id

Definition at line 38 of file improvement.h.

◆ SPECENUM_VALUE0

#define SPECENUM_VALUE0   IF_VISIBLE_BY_OTHERS

Definition at line 40 of file improvement.h.

◆ SPECENUM_VALUE0NAME

#define SPECENUM_VALUE0NAME   "VisibleByOthers"

Definition at line 41 of file improvement.h.

◆ SPECENUM_VALUE1

#define SPECENUM_VALUE1   IF_SAVE_SMALL_WONDER

Definition at line 43 of file improvement.h.

◆ SPECENUM_VALUE1NAME

#define SPECENUM_VALUE1NAME   "SaveSmallWonder"

Definition at line 44 of file improvement.h.

◆ SPECENUM_VALUE2

#define SPECENUM_VALUE2   IF_GOLD

Definition at line 46 of file improvement.h.

◆ SPECENUM_VALUE2NAME

#define SPECENUM_VALUE2NAME   "Gold"

Definition at line 47 of file improvement.h.

◆ SPECENUM_VALUE3

#define SPECENUM_VALUE3   IF_DISASTER_PROOF

Definition at line 49 of file improvement.h.

◆ SPECENUM_VALUE3NAME

#define SPECENUM_VALUE3NAME   "DisasterProof"

Definition at line 50 of file improvement.h.

◆ WONDER_BUILT

#define WONDER_BUILT (   city_id)    ((city_id) > 0)

Definition at line 145 of file improvement.h.

◆ WONDER_DESTROYED

#define WONDER_DESTROYED
Value:
(MAX_NUM_PLAYER_SLOTS + 1) /* Used as player id. \
*/
#define MAX_NUM_PLAYER_SLOTS
Definition: fc_types.h:24

Definition at line 136 of file improvement.h.

◆ WONDER_LOST

#define WONDER_LOST   (-1)

Definition at line 143 of file improvement.h.

◆ WONDER_NOT_BUILT

#define WONDER_NOT_BUILT   0

Definition at line 144 of file improvement.h.

◆ WONDER_NOT_OWNED

#define WONDER_NOT_OWNED
Value:
(MAX_NUM_PLAYER_SLOTS + 2) /* Used as player id. \
*/

Definition at line 138 of file improvement.h.

◆ WONDER_OWNED

#define WONDER_OWNED (   player_id)    ((player_id) < MAX_NUM_PLAYER_SLOTS)

Definition at line 140 of file improvement.h.

Function Documentation

◆ BV_DEFINE()

BV_DEFINE ( bv_imprs  ,
B_LAST   
)

◆ 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_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_has_flag()

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