Freeciv-3.1
Loading...
Searching...
No Matches
Functions | Variables
extras.c File Reference
#include "rand.h"
#include "string_vector.h"
#include "base.h"
#include "game.h"
#include "map.h"
#include "research.h"
#include "road.h"
#include "extras.h"

Go to the source code of this file.

Functions

void extras_init (void)
 
void extras_free (void)
 
int extra_count (void)
 
int extra_number (const struct extra_type *pextra)
 
struct extra_typeextra_by_number (int id)
 
const char * extra_name_translation (const struct extra_type *pextra)
 
const char * extra_rule_name (const struct extra_type *pextra)
 
struct extra_typeextra_type_by_rule_name (const char *name)
 
struct extra_typeextra_type_by_translated_name (const char *name)
 
struct extra_type_list * extra_type_list_by_cause (enum extra_cause cause)
 
struct extra_type_list * extra_type_list_of_unit_hiders (void)
 
struct extra_type_list * extra_type_list_of_terr_claimers (void)
 
struct extra_typerand_extra_for_tile (struct tile *ptile, enum extra_cause cause, bool generated)
 
void extra_to_caused_by_list (struct extra_type *pextra, enum extra_cause cause)
 
struct extra_type_list * extra_type_list_by_rmcause (enum extra_rmcause rmcause)
 
void extra_to_removed_by_list (struct extra_type *pextra, enum extra_rmcause rmcause)
 
bool is_extra_removed_by (const struct extra_type *pextra, enum extra_rmcause rmcause)
 
bool is_extra_card_near (const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pextra)
 
bool is_extra_near_tile (const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pextra)
 
bool extra_can_be_built (const struct extra_type *pextra, const struct tile *ptile)
 
bool can_build_extra_base (const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
 
bool player_can_build_extra (const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
 
bool player_can_place_extra (const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
 
bool can_build_extra (const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
 
static bool can_extra_be_removed (const struct extra_type *pextra, const struct tile *ptile)
 
bool player_can_remove_extra (const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
 
bool can_remove_extra (const struct extra_type *pextra, const struct unit *punit, const struct tile *ptile)
 
bool is_native_tile_to_extra (const struct extra_type *pextra, const struct tile *ptile)
 
bool extra_conflicting_on_tile (const struct extra_type *pextra, const struct tile *ptile)
 
bool hut_on_tile (const struct tile *ptile)
 
bool unit_can_enter_hut (const struct unit *punit, const struct tile *ptile)
 
bool unit_can_displace_hut (const struct unit *punit, const struct tile *ptile)
 
struct extra_typenext_extra_for_tile (const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
 
struct extra_typeprev_extra_in_tile (const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
 
bool is_native_extra_to_uclass (const struct extra_type *pextra, const struct unit_class *pclass)
 
bool is_native_extra_to_utype (const struct extra_type *pextra, const struct unit_type *punittype)
 
bool extra_has_flag (const struct extra_type *pextra, enum extra_flag_id flag)
 
bool is_extra_flag_card_near (const struct civ_map *nmap, const struct tile *ptile, enum extra_flag_id flag)
 
bool is_extra_flag_near_tile (const struct civ_map *nmap, const struct tile *ptile, enum extra_flag_id flag)
 
void user_extra_flags_init (void)
 
void extra_flags_free (void)
 
void set_user_extra_flag_name (enum extra_flag_id id, const char *name, const char *helptxt)
 
const char * extra_flag_id_name_cb (enum extra_flag_id flag)
 
const char * extra_flag_helptxt (enum extra_flag_id id)
 
bool extra_flag_is_in_use (enum extra_flag_id id)
 
bool can_extras_coexist (const struct extra_type *pextra1, const struct extra_type *pextra2)
 
bool extra_causes_env_upset (struct extra_type *pextra, enum environment_upset_type upset)
 
bool is_extra_caused_by_worker_action (const struct extra_type *pextra)
 
bool is_extra_removed_by_worker_action (const struct extra_type *pextra)
 
bool is_extra_caused_by_action (const struct extra_type *pextra, const struct action *paction)
 
bool is_extra_removed_by_action (const struct extra_type *pextra, const struct action *paction)
 
enum extra_cause activity_to_extra_cause (enum unit_activity act)
 
enum extra_rmcause activity_to_extra_rmcause (enum unit_activity act)
 
struct playerextra_owner (const struct tile *ptile)
 
bool can_extra_appear (const struct extra_type *pextra, const struct tile *ptile)
 
bool can_extra_disappear (const struct extra_type *pextra, const struct tile *ptile)
 
bool player_knows_extra_exist (const struct player *pplayer, const struct extra_type *pextra, const struct tile *ptile)
 

Variables

static struct extra_type extras [MAX_EXTRA_TYPES]
 
static struct user_flag user_extra_flags [MAX_NUM_USER_EXTRA_FLAGS]
 
static struct extra_type_list * caused_by [EC_LAST]
 
static struct extra_type_list * removed_by [ERM_COUNT]
 
static struct extra_type_list * unit_hidden
 
static struct extra_type_list * terr_claimer
 

Function Documentation

◆ activity_to_extra_cause()

enum extra_cause activity_to_extra_cause ( enum unit_activity  act)

◆ activity_to_extra_rmcause()

enum extra_rmcause activity_to_extra_rmcause ( enum unit_activity  act)

◆ can_build_extra()

bool can_build_extra ( const struct extra_type pextra,
const struct unit punit,
const struct tile ptile 
)

Tells if unit can build extra on tile.

Definition at line 507 of file extras.c.

Referenced by can_unit_do_connect(), is_action_possible(), and next_extra_for_tile().

◆ can_build_extra_base()

bool can_build_extra_base ( const struct extra_type pextra,
const struct player pplayer,
const struct tile ptile 
)

Tells if player can build extra to tile with suitable unit.

Definition at line 387 of file extras.c.

Referenced by can_build_base(), can_build_extra(), can_build_road(), player_can_build_base(), player_can_build_extra(), and player_can_build_road().

◆ can_extra_appear()

bool can_extra_appear ( const struct extra_type pextra,
const struct tile ptile 
)

Are all the requirements for extra to appear on tile fulfilled.

Definition at line 1076 of file extras.c.

Referenced by end_turn().

◆ can_extra_be_removed()

static bool can_extra_be_removed ( const struct extra_type pextra,
const struct tile ptile 
)
static

Is it possible at all to remove this extra now

Definition at line 531 of file extras.c.

Referenced by can_extra_disappear(), can_remove_extra(), and player_can_remove_extra().

◆ can_extra_disappear()

bool can_extra_disappear ( const struct extra_type pextra,
const struct tile ptile 
)

Are all the requirements for extra to disappear from tile fulfilled.

Definition at line 1090 of file extras.c.

Referenced by end_turn().

◆ can_extras_coexist()

bool can_extras_coexist ( const struct extra_type pextra1,
const struct extra_type pextra2 
)

◆ can_remove_extra()

bool can_remove_extra ( const struct extra_type pextra,
const struct unit punit,
const struct tile ptile 
)

Tells if unit can remove extra from tile. Does not examine action requirements if an action is required for it.

Definition at line 586 of file extras.c.

Referenced by is_action_possible(), and prev_extra_in_tile().

◆ extra_by_number()

struct extra_type * extra_by_number ( int  id)

◆ extra_can_be_built()

bool extra_can_be_built ( const struct extra_type pextra,
const struct tile ptile 
)

Tells if extra can build to tile if all other requirements are met.

Definition at line 368 of file extras.c.

Referenced by can_build_extra_base().

◆ extra_causes_env_upset()

bool extra_causes_env_upset ( struct extra_type pextra,
enum environment_upset_type  upset 
)

Does the extra count toward environment upset?

Definition at line 965 of file extras.c.

Referenced by update_environmental_upset().

◆ extra_conflicting_on_tile()

bool extra_conflicting_on_tile ( const struct extra_type pextra,
const struct tile ptile 
)

Returns TRUE iff an extra that conflicts with pextra exists at ptile.

Definition at line 655 of file extras.c.

Referenced by can_extra_appear().

◆ extra_count()

int extra_count ( void  )

Return the number of extra_types.

Definition at line 145 of file extras.c.

Referenced by fill_tile_edit_packet(), helptext_unit(), and tileset_setup_base().

◆ extra_flag_helptxt()

const char * extra_flag_helptxt ( enum extra_flag_id  id)

Return the (untranslated) help text of the user extra flag.

Definition at line 923 of file extras.c.

Referenced by helptext_extra(), save_terrain_ruleset(), and send_ruleset_extras().

◆ extra_flag_id_name_cb()

const char * extra_flag_id_name_cb ( enum extra_flag_id  flag)

Extra flag name callback, called from specenum code.

Definition at line 911 of file extras.c.

Referenced by save_terrain_ruleset().

◆ extra_flag_is_in_use()

bool extra_flag_is_in_use ( enum extra_flag_id  id)

Returns TRUE iff the specified extra type flag is in use by any extra type.

Parameters
idthe extra type flag to check if is in use.
Returns
TRUE if the extra type flag is used in the current ruleset.

Definition at line 936 of file extras.c.

Referenced by universal_never_there().

◆ extra_flags_free()

void extra_flags_free ( void  )

Frees the memory associated with all extra flags

Definition at line 870 of file extras.c.

Referenced by game_ruleset_free().

◆ extra_has_flag()

bool extra_has_flag ( const struct extra_type pextra,
enum extra_flag_id  flag 
)

◆ extra_name_translation()

const char * extra_name_translation ( const struct extra_type pextra)

◆ extra_number()

int extra_number ( const struct extra_type pextra)

◆ extra_owner()

struct player * extra_owner ( const struct tile ptile)

◆ extra_rule_name()

const char * extra_rule_name ( const struct extra_type pextra)

◆ extra_to_caused_by_list()

void extra_to_caused_by_list ( struct extra_type pextra,
enum extra_cause  cause 
)

Add extra type to list of extra caused by given cause.

Definition at line 296 of file extras.c.

Referenced by handle_ruleset_extra(), and load_ruleset_terrain().

◆ extra_to_removed_by_list()

void extra_to_removed_by_list ( struct extra_type pextra,
enum extra_rmcause  rmcause 
)

Add extra type to list of extra removed by given cause.

Definition at line 316 of file extras.c.

Referenced by handle_ruleset_extra(), load_ruleset_terrain(), and rscompat_extra_adjust_3_1().

◆ extra_type_by_rule_name()

struct extra_type * extra_type_by_rule_name ( const char *  name)

◆ extra_type_by_translated_name()

struct extra_type * extra_type_by_translated_name ( const char *  name)

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

Definition at line 227 of file extras.c.

Referenced by help_update_extra(), help_dialog::make_tree(), and help_widget::set_topic_extra().

◆ extra_type_list_by_cause()

struct extra_type_list * extra_type_list_by_cause ( enum extra_cause  cause)

◆ extra_type_list_by_rmcause()

struct extra_type_list * extra_type_list_by_rmcause ( enum extra_rmcause  rmcause)

Returns extra type for given rmcause.

Definition at line 306 of file extras.c.

◆ extra_type_list_of_terr_claimers()

struct extra_type_list * extra_type_list_of_terr_claimers ( void  )

◆ extra_type_list_of_unit_hiders()

struct extra_type_list * extra_type_list_of_unit_hiders ( void  )

Returns extra types that hide units.

Definition at line 251 of file extras.c.

Referenced by handle_ruleset_extra(), load_ruleset_terrain(), and player_can_trust_tile_has_no_units().

◆ extras_free()

void extras_free ( void  )

Free the memory associated with extras

Definition at line 80 of file extras.c.

Referenced by game_ruleset_free().

◆ extras_init()

void extras_init ( void  )

Initialize extras structures.

Definition at line 43 of file extras.c.

Referenced by game_ruleset_init().

◆ hut_on_tile()

bool hut_on_tile ( const struct tile ptile)

Returns TRUE iff an extra on the tile is a hut (removed by entering). The effect of entering is handled by unit_enter_hut() in unittools.c

Definition at line 672 of file extras.c.

Referenced by adv_data_phase_init(), dai_unit_move(), explorer_desirable(), and is_valid_start_pos().

◆ is_extra_card_near()

bool is_extra_card_near ( const struct civ_map nmap,
const struct tile ptile,
const struct extra_type pextra 
)

Is there extra of the given type cardinally near tile? (Does not check ptile itself.)

Definition at line 337 of file extras.c.

Referenced by is_extra_req_active().

◆ is_extra_caused_by_action()

bool is_extra_caused_by_action ( const struct extra_type pextra,
const struct action paction 
)

Is the extra caused by specific worker action?

Definition at line 1006 of file extras.c.

Referenced by settler_evaluate_improvements(), tai_tile_worker_task_select(), and texai_tile_worker_task_select().

◆ is_extra_caused_by_worker_action()

bool is_extra_caused_by_worker_action ( const struct extra_type pextra)

Is the extra caused by some kind of worker action?

Definition at line 981 of file extras.c.

Referenced by helptext_extra(), initialize_infrastructure_cache(), load_ruleset_terrain(), and save_terrain_ruleset().

◆ is_extra_flag_card_near()

bool is_extra_flag_card_near ( const struct civ_map nmap,
const struct tile ptile,
enum extra_flag_id  flag 
)

Returns TRUE iff any cardinally adjacent tile contains an extra with the given flag (does not check ptile itself).

Definition at line 819 of file extras.c.

Referenced by is_extraflag_req_active().

◆ is_extra_flag_near_tile()

bool is_extra_flag_near_tile ( const struct civ_map nmap,
const struct tile ptile,
enum extra_flag_id  flag 
)

Returns TRUE iff any adjacent tile contains an extra with the given flag (does not check ptile itself).

Definition at line 839 of file extras.c.

Referenced by is_extraflag_req_active().

◆ is_extra_near_tile()

bool is_extra_near_tile ( const struct civ_map nmap,
const struct tile ptile,
const struct extra_type pextra 
)

Is there extra of the given type near tile? (Does not check ptile itself.)

Definition at line 353 of file extras.c.

Referenced by is_extra_req_active().

◆ is_extra_removed_by()

bool is_extra_removed_by ( const struct extra_type pextra,
enum extra_rmcause  rmcause 
)

◆ is_extra_removed_by_action()

bool is_extra_removed_by_action ( const struct extra_type pextra,
const struct action paction 
)

Is the extra removed by specific worker action?

Definition at line 1017 of file extras.c.

Referenced by settler_evaluate_improvements(), tai_tile_worker_task_select(), and texai_tile_worker_task_select().

◆ is_extra_removed_by_worker_action()

bool is_extra_removed_by_worker_action ( const struct extra_type pextra)

Is the extra removed by some kind of worker action?

Definition at line 994 of file extras.c.

Referenced by initialize_infrastructure_cache().

◆ is_native_extra_to_uclass()

bool is_native_extra_to_uclass ( const struct extra_type pextra,
const struct unit_class pclass 
)

◆ is_native_extra_to_utype()

bool is_native_extra_to_utype ( const struct extra_type pextra,
const struct unit_type punittype 
)

Is extra native to unit type?

Definition at line 801 of file extras.c.

Referenced by create_extra(), destroy_extra(), and tile_has_not_aggressive_extra_for_unit().

◆ is_native_tile_to_extra()

bool is_native_tile_to_extra ( const struct extra_type pextra,
const struct tile ptile 
)

Is tile native to extra?

Definition at line 608 of file extras.c.

Referenced by add_recursive_extras(), can_extra_appear(), create_city(), rand_extra_for_tile(), remove_city(), and tile_change_terrain().

◆ next_extra_for_tile()

struct extra_type * next_extra_for_tile ( const struct tile ptile,
enum extra_cause  cause,
const struct player pplayer,
const struct unit punit 
)

◆ player_can_build_extra()

bool player_can_build_extra ( const struct extra_type pextra,
const struct player pplayer,
const struct tile ptile 
)

Tells if player can build extra to tile with suitable unit.

Definition at line 442 of file extras.c.

Referenced by adv_calc_extra(), can_extra_be_removed(), impr_provides_buildable_extras(), next_extra_for_tile(), player_can_place_extra(), and upgrade_city_extras().

◆ player_can_place_extra()

bool player_can_place_extra ( const struct extra_type pextra,
const struct player pplayer,
const struct tile ptile 
)

Tells if player can place extra on tile.

Definition at line 462 of file extras.c.

Referenced by handle_player_place_infra(), and infra_placement_set_tile().

◆ player_can_remove_extra()

bool player_can_remove_extra ( const struct extra_type pextra,
const struct player pplayer,
const struct tile ptile 
)

Tells if player can remove extra from tile with suitable unit.

Definition at line 564 of file extras.c.

Referenced by adv_calc_rmextra(), and prev_extra_in_tile().

◆ player_knows_extra_exist()

bool player_knows_extra_exist ( const struct player pplayer,
const struct extra_type pextra,
const struct tile ptile 
)

Extra is not hidden from the user.

Definition at line 1103 of file extras.c.

Referenced by send_tile_info(), and update_player_tile_knowledge().

◆ prev_extra_in_tile()

struct extra_type * prev_extra_in_tile ( const struct tile ptile,
enum extra_rmcause  rmcause,
const struct player pplayer,
const struct unit punit 
)

◆ rand_extra_for_tile()

struct extra_type * rand_extra_for_tile ( struct tile ptile,
enum extra_cause  cause,
bool  generated 
)

Return random extra type for given cause that is native to the tile.

Definition at line 267 of file extras.c.

Referenced by do_nuke_tile(), fair_map_make_huts(), make_huts(), and place_pollution().

◆ set_user_extra_flag_name()

void set_user_extra_flag_name ( enum extra_flag_id  id,
const char *  name,
const char *  helptxt 
)

Sets user defined name for extra flag.

Definition at line 882 of file extras.c.

Referenced by handle_ruleset_extra_flag(), and load_terrain_names().

◆ unit_can_displace_hut()

bool unit_can_displace_hut ( const struct unit punit,
const struct tile ptile 
)

Returns TRUE iff the unit can enter or frighten any hut on the tile. For the unit, tests only its class and its owner.

Definition at line 713 of file extras.c.

Referenced by is_action_possible().

◆ unit_can_enter_hut()

bool unit_can_enter_hut ( const struct unit punit,
const struct tile ptile 
)

Returns TRUE iff the unit can enter any hut on the tile. For the unit, tests only its class and its owner.

Definition at line 687 of file extras.c.

Referenced by dai_rampage_want(), and explorer_desirable().

◆ user_extra_flags_init()

void user_extra_flags_init ( void  )

Initialize user extra flags.

Definition at line 858 of file extras.c.

Referenced by game_ruleset_init().

Variable Documentation

◆ caused_by

struct extra_type_list* caused_by[EC_LAST]
static

◆ extras

struct extra_type extras[MAX_EXTRA_TYPES]
static

◆ removed_by

struct extra_type_list* removed_by[ERM_COUNT]
static

◆ terr_claimer

struct extra_type_list* terr_claimer
static

Definition at line 38 of file extras.c.

Referenced by extra_type_list_of_terr_claimers(), extras_free(), and extras_init().

◆ unit_hidden

struct extra_type_list* unit_hidden
static

Definition at line 37 of file extras.c.

Referenced by extra_type_list_of_unit_hiders(), extras_free(), and extras_init().

◆ user_extra_flags

struct user_flag user_extra_flags[MAX_NUM_USER_EXTRA_FLAGS]
static