Freeciv21
Develop your civilization from humble roots to a global empire
unittype.cpp File Reference
#include <cmath>
#include <cstring>
#include "astring.h"
#include "fcintl.h"
#include "log.h"
#include "shared.h"
#include "support.h"
#include "ai.h"
#include "combat.h"
#include "game.h"
#include "government.h"
#include "movement.h"
#include "player.h"
#include "research.h"
#include "unitlist.h"
#include "unittype.h"
+ Include dependency graph for unittype.cpp:

Go to the source code of this file.

Classes

struct  range
 

Macros

#define MAX_UNIT_ROLES   L_LAST + ACTION_COUNT
 
#define ACTION_HOSTILE   ACTION_COUNT + 1
 
#define ACTION_AND_FAKES   ACTION_HOSTILE + 1
 
#define requirement_unit_state_ereq(_id_, _present_)    requirement_kind_ereq(_id_, REQ_RANGE_LOCAL, _present_, USP_COUNT)
 
#define requirement_citytile_ereq(_id_, _present_)    requirement_kind_ereq(_id_, REQ_RANGE_LOCAL, _present_, CITYT_LAST)
 
#define MOVES_LEFT_INFINITY   -1
 

Functions

struct unit_typeunit_type_array_first ()
 Return the first item of unit_types. More...
 
const struct unit_typeunit_type_array_last ()
 Return the last item of unit_types. More...
 
Unit_type_id utype_count ()
 Return the number of unit types. More...
 
Unit_type_id utype_index (const struct unit_type *punittype)
 Return the unit type index. More...
 
Unit_type_id utype_number (const struct unit_type *punittype)
 Return the unit type index. More...
 
struct unit_typeutype_by_number (const Unit_type_id id)
 Return a pointer for the unit type struct for the given unit type id. More...
 
const struct unit_typeunit_type_get (const struct unit *punit)
 Return the unit type for this unit. More...
 
int utype_upkeep_cost (const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
 Returns the upkeep of a unit of this type under the given government. More...
 
int utype_happy_cost (const struct unit_type *ut, const struct player *pplayer)
 Return the "happy cost" (the number of citizens who are discontented) for this unit. More...
 
bool unit_has_type_flag (const struct unit *punit, enum unit_type_flag_id flag)
 Return whether the unit has the given flag. More...
 
bool utype_has_role (const struct unit_type *punittype, int role)
 Return whether the given unit type has the role. More...
 
bool unit_has_type_role (const struct unit *punit, enum unit_role_id role)
 Return whether the unit has the given role. More...
 
bool unit_can_take_over (const struct unit *punit)
 Return whether the unit can take over enemy cities. More...
 
bool utype_can_take_over (const struct unit_type *punittype)
 Return whether the unit type can take over enemy cities. More...
 
bool utype_can_freely_load (const struct unit_type *pcargotype, const struct unit_type *ptranstype)
 Return TRUE iff the given cargo type has no restrictions on when it can load onto the given transporter. More...
 
bool utype_can_freely_unload (const struct unit_type *pcargotype, const struct unit_type *ptranstype)
 Return TRUE iff the given cargo type has no restrictions on when it can unload from the given transporter. More...
 
static bool action_is_hostile (action_id act_id)
 Returns TRUE iff the specified action is hostile. More...
 
static void unit_can_act_cache_set (struct unit_type *putype)
 Cache what generalized (ruleset defined) action enabler controlled actions a unit of the given type can perform. More...
 
bool utype_may_act_at_all (const struct unit_type *putype)
 Return TRUE iff units of this type can do actions controlled by generalized (ruleset defined) action enablers. More...
 
bool utype_can_do_action (const struct unit_type *putype, const action_id act_id)
 Return TRUE iff units of the given type can do the specified generalized (ruleset defined) action enabler controlled action. More...
 
bool utype_can_do_action_result (const struct unit_type *putype, enum action_result result)
 Return TRUE iff units of the given type can do any enabler controlled action with the specified action result. More...
 
static bool utype_can_do_action_role (const struct unit_type *putype, const int role)
 Return TRUE iff the unit type can perform the action corresponding to the unit type role. More...
 
bool utype_acts_hostile (const struct unit_type *putype)
 Return TRUE iff units of this type can do hostile actions controlled by generalized (ruleset defined) action enablers. More...
 
 BV_DEFINE (bv_ustate_act_cache, USP_COUNT *2)
 
 BV_DEFINE (bv_citytile_cache, CITYT_LAST *2)
 
static void unit_state_action_cache_set (struct unit_type *putype)
 Cache if any action may be possible for a unit of the type putype for each unit state property. More...
 
static void local_dipl_rel_action_cache_set (struct unit_type *putype)
 Cache what actions may be possible for a unit of the type putype for each local DiplRel variation. More...
 
static void tgt_citytile_act_cache_set (struct unit_type *putype)
 Cache if any action may be possible for a unit of the type putype for each target local city tile property. More...
 
static struct rangemoves_left_range (struct requirement_vector *reqs)
 Get the legal range of move fragments left of the specified requirement vector. More...
 
void unit_type_action_cache_set (struct unit_type *ptype)
 Cache if any action may be possible for a unit of the type putype given the property tested for. More...
 
void unit_type_action_cache_init ()
 Cache what unit types may be allowed do what actions, both at all and when certain properties are true. More...
 
bool can_unit_act_when_ustate_is (const struct unit_type *punit_type, const enum ustate_prop prop, const bool is_there)
 Return TRUE iff there exists an (action enabler controlled) action that a unit of the type punit_type can perform while its unit state property prop has the value is_there. More...
 
bool utype_can_do_act_when_ustate (const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
 Return TRUE iff the unit type can do the specified (action enabler controlled) action while its unit state property prop has the value is_there. More...
 
bool utype_can_do_act_if_tgt_citytile (const struct unit_type *punit_type, const action_id act_id, const enum citytile_type prop, const bool is_there)
 Returns TRUE iff the unit type can do the specified (action enabler controlled) action while its target's CityTile property state has the value is_there. More...
 
bool can_utype_do_act_if_tgt_diplrel (const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
 Return TRUE iff the given (action enabler controlled) action can be performed by a unit of the given type while the given property of its owner's diplomatic relationship to the target's owner has the given value. More...
 
bool utype_may_act_move_frags (const struct unit_type *punit_type, const action_id act_id, const int move_fragments)
 Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given type that has the given number of move fragments left. More...
 
bool utype_may_act_tgt_city_tile (const struct unit_type *punit_type, const action_id act_id, const enum citytile_type prop, const bool is_there)
 Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given type if the target tile has the given property. More...
 
bool utype_is_consumed_by_action (const struct action *paction, const struct unit_type *utype)
 Returns TRUE iff performing the specified action will consume an actor unit of the specified type. More...
 
bool utype_is_consumed_by_action_result (enum action_result result, const struct unit_type *utype)
 Returns TRUE iff performing an action with the specified action result will consume an actor unit of the specified type. More...
 
bool utype_is_moved_to_tgt_by_action (const struct action *paction, const struct unit_type *utype)
 Returns TRUE iff successfully performing the specified action always will move the actor unit of the specified type to the target's tile. More...
 
bool utype_is_unmoved_by_action (const struct action *paction, const struct unit_type *utype)
 Returns TRUE iff successfully performing the specified action never will move the actor unit from its current tile. More...
 
bool utype_pays_for_regular_move_to_tgt (const struct action *paction, const struct unit_type *utype)
 Returns TRUE iff successfully performing the specified action always will cost the actor unit of the specified type the move fragments it would take to perform a regular move to the target's tile. More...
 
int utype_pays_mp_for_action_base (const struct action *paction, const struct unit_type *putype)
 Returns the amount of movement points successfully performing the specified action will consume in the actor unit type without taking effects or regular moves into account. More...
 
int utype_pays_mp_for_action_estimate (const struct action *paction, const struct unit_type *putype, const struct player *act_player, const struct tile *act_tile, const struct tile *tgt_tile)
 Returns an estimate of the amount of movement points successfully performing the specified action will consume in the actor unit type. More...
 
int utype_build_shield_cost (const struct city *pcity, const struct unit_type *punittype)
 Returns the number of shields it takes to build this unit type. More...
 
int utype_build_shield_cost_base (const struct unit_type *punittype)
 Returns the number of shields this unit type represents. More...
 
int unit_build_shield_cost (const struct city *pcity, const struct unit *punit)
 Returns the number of shields it takes to build this unit. More...
 
int unit_build_shield_cost_base (const struct unit *punit)
 Returns the number of shields this unit represents. More...
 
int utype_buy_gold_cost (const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
 Returns the amount of gold it takes to rush this unit. More...
 
int utype_pop_value (const struct unit_type *punittype)
 How much city shrinks when it builds unit of this type. More...
 
int unit_pop_value (const struct unit *punit)
 How much population is put to building this unit. More...
 
enum unit_move_type utype_move_type (const struct unit_type *punittype)
 Return move type of the unit type. More...
 
const char * utype_name_translation (const struct unit_type *punittype)
 Return the (translated) name of the unit type. More...
 
const char * unit_name_translation (const struct unit *punit)
 Return the (translated) name of the unit. More...
 
const char * utype_rule_name (const struct unit_type *punittype)
 Return the (untranslated) rule name of the unit type. More...
 
const char * unit_rule_name (const struct unit *punit)
 Return the (untranslated) rule name of the unit. More...
 
const char * utype_values_string (const struct unit_type *punittype)
 Return string describing unit type values. More...
 
const char * utype_values_translation (const struct unit_type *punittype)
 Return string with translated unit name and list of its values. More...
 
const char * uclass_name_translation (const struct unit_class *pclass)
 Return the (translated) name of the unit class. More...
 
const char * uclass_rule_name (const struct unit_class *pclass)
 Return the (untranslated) rule name of the unit class. More...
 
bool role_units_translations (QString &astr, int flag, bool alts)
 Return a string with all the names of units with this flag. More...
 
const struct unit_typecan_upgrade_unittype (const struct player *pplayer, const struct unit_type *punittype)
 Return whether this player can upgrade this unit type (to any other unit type). More...
 
int unit_upgrade_price (const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
 Return the cost (gold) of upgrading a single unit of the specified type to the new type. More...
 
struct unit_typeunit_type_by_translated_name (const char *name)
 Returns the unit type that has the given (translated) name. More...
 
struct unit_typeunit_type_by_rule_name (const char *name)
 Returns the unit type that has the given (untranslated) rule name. More...
 
struct unit_classunit_class_by_rule_name (const char *s)
 Returns the unit class that has the given (untranslated) rule name. More...
 
void user_unit_class_flags_init ()
 Initialize user unit class flags. More...
 
void set_user_unit_class_flag_name (enum unit_class_flag_id id, const char *name, const char *helptxt)
 Sets user defined name for unit class flag. More...
 
const char * unit_class_flag_id_name_cb (enum unit_class_flag_id flag)
 Unit class flag name callback, called from specenum code. More...
 
const char * unit_class_flag_helptxt (enum unit_class_flag_id id)
 Return the (untranslated) help text of the user unit class flag. More...
 
void user_unit_type_flags_init ()
 Initialize user unit type flags. More...
 
void set_user_unit_type_flag_name (enum unit_type_flag_id id, const char *name, const char *helptxt)
 Sets user defined name for unit flag. More...
 
const char * unit_type_flag_id_name_cb (enum unit_type_flag_id flag)
 Unit type flag name callback, called from specenum code. More...
 
const char * unit_type_flag_helptxt (enum unit_type_flag_id id)
 Return the (untranslated) helptxt of the user unit flag. More...
 
bool utype_player_already_has_this_unique (const struct player *pplayer, const struct unit_type *putype)
 Returns TRUE iff the unit type is unique and the player already has one. More...
 
bool can_player_build_unit_direct (const struct player *p, const struct unit_type *punittype)
 Whether player can build given unit somewhere, ignoring whether unit is obsolete and assuming the player has a coastal city. More...
 
bool can_player_build_unit_now (const struct player *p, const struct unit_type *punittype)
 Whether player can build given unit somewhere; returns FALSE if unit is obsolete. More...
 
bool can_player_build_unit_later (const struct player *p, const struct unit_type *punittype)
 Whether player can eventually build given unit somewhere – ie, returns TRUE if unit is available with current tech OR will be available with future tech. More...
 
static void precalc_one (int i, bool(*func_has)(const struct unit_type *, int))
 Do the real work for role_unit_precalcs, for one role (or flag), given by i. More...
 
void role_unit_precalcs_free ()
 Free memory allocated by role_unit_precalcs(). More...
 
void role_unit_precalcs ()
 Initialize; it is safe to call this multiple times (e.g., if units have changed due to rulesets in client). More...
 
int num_role_units (int role)
 How many unit types have specified role/flag. More...
 
struct unit_typerole_units_iterate_backwards (int role, role_unit_callback cb, void *data)
 Iterate over all the role units and feed them to callback, starting from the last one. More...
 
struct unit_typeget_role_unit (int role, int role_index)
 Return index-th unit with specified role/flag. More...
 
struct unit_typebest_role_unit (const struct city *pcity, int role)
 Return "best" unit this city can build, with given role/flag. More...
 
struct unit_typebest_role_unit_for_player (const struct player *pplayer, int role)
 Return "best" unit the player can build, with given role/flag. More...
 
struct unit_typefirst_role_unit_for_player (const struct player *pplayer, int role)
 Return first unit the player can build, with given role/flag. More...
 
void unit_types_init ()
 Inialize unit-type structures. More...
 
static void unit_type_free (struct unit_type *punittype)
 Frees the memory associated with this unit type. More...
 
void unit_types_free ()
 Frees the memory associated with all unit types. More...
 
void unit_type_flags_free ()
 Frees the memory associated with all unit type flags. More...
 
void unit_class_flags_free ()
 Frees the memory associated with all unit class flags. More...
 
struct unit_classunit_class_array_first ()
 Return the first item of unit_classes. More...
 
const struct unit_classunit_class_array_last ()
 Return the last item of unit_classes. More...
 
Unit_Class_id uclass_count ()
 Return the unit_class count. More...
 
Unit_Class_id uclass_number (const struct unit_class *pclass)
 Return the unit_class index. More...
 
struct unit_classuclass_by_number (const Unit_Class_id id)
 Returns unit class pointer for an ID value. More...
 
struct unit_classunit_class_get (const struct unit *punit)
 Returns unit class pointer for a unit. More...
 
void unit_classes_init ()
 Initialize unit_class structures. More...
 
void unit_classes_free ()
 Free resources allocated for unit classes. More...
 
const struct veteran_systemutype_veteran_system (const struct unit_type *punittype)
 Return veteran system used for this unit type. More...
 
const struct veteran_levelutype_veteran_level (const struct unit_type *punittype, int level)
 Return veteran level properties of given unit in given veterancy level. More...
 
const char * utype_veteran_name_translation (const struct unit_type *punittype, int level)
 Return translated name of the given veteran level. More...
 
int utype_veteran_levels (const struct unit_type *punittype)
 Return veteran levels of the given unit type. More...
 
bool utype_veteran_has_power_bonus (const struct unit_type *punittype)
 Return whether this unit type's veteran system, if any, confers a power factor bonus at any level (it could just add extra moves). More...
 
struct veteran_systemveteran_system_new (int count)
 Allocate new veteran system structure with given veteran level count. More...
 
void veteran_system_destroy (struct veteran_system *vsystem)
 Free veteran system. More...
 
void veteran_system_definition (struct veteran_system *vsystem, int level, const char *vlist_name, int vlist_power, int vlist_move, int vlist_raise, int vlist_wraise)
 Fill veteran level in given veteran system with given information. More...
 
void * utype_ai_data (const struct unit_type *ptype, const struct ai_type *ai)
 Return pointer to ai data of given unit type and ai type. More...
 
void utype_set_ai_data (struct unit_type *ptype, const struct ai_type *ai, void *data)
 Attach ai data to unit type. More...
 
void set_unit_class_caches (struct unit_class *pclass)
 Set caches for unit class. More...
 
void set_unit_type_caches (struct unit_type *ptype)
 Set caches for unit types. More...
 
static enum unit_move_type move_type_from_extra (struct extra_type *pextra, struct unit_class *puc)
 What move types nativity of this extra will give? More...
 
void set_unit_move_type (struct unit_class *puclass)
 Set move_type for unit class. More...
 
bool utype_is_cityfounder (const struct unit_type *utype)
 Is cityfounder type. More...
 

Variables

static struct unit_type unit_types [U_LAST]
 
static struct unit_class unit_classes [UCL_LAST]
 
static struct user_flag user_type_flags [MAX_NUM_USER_UNIT_FLAGS]
 
static struct user_flag user_class_flags [MAX_NUM_USER_UCLASS_FLAGS]
 
static bv_unit_types unit_can_act_cache [ACTION_AND_FAKES]
 
static bv_ustate_act_cache ustate_act_cache [U_LAST][ACTION_AND_FAKES]
 
static bv_diplrel_all_reqs dipl_rel_action_cache [U_LAST][ACTION_AND_FAKES]
 
static bv_citytile_cache ctile_tgt_act_cache [U_LAST][ACTION_AND_FAKES]
 
static bool first_init = true
 The following functions use static variables so we can quickly look up which unit types have given flag or role. More...
 
static int n_with_role [MAX_UNIT_ROLES]
 
static struct unit_type ** with_role [MAX_UNIT_ROLES]
 

Macro Definition Documentation

◆ ACTION_AND_FAKES

#define ACTION_AND_FAKES   ACTION_HOSTILE + 1

Definition at line 326 of file unittype.cpp.

◆ ACTION_HOSTILE

#define ACTION_HOSTILE   ACTION_COUNT + 1

Definition at line 323 of file unittype.cpp.

◆ MAX_UNIT_ROLES

#define MAX_UNIT_ROLES   L_LAST + ACTION_COUNT

Definition at line 36 of file unittype.cpp.

◆ MOVES_LEFT_INFINITY

#define MOVES_LEFT_INFINITY   -1

Definition at line 677 of file unittype.cpp.

◆ requirement_citytile_ereq

#define requirement_citytile_ereq (   _id_,
  _present_ 
)     requirement_kind_ereq(_id_, REQ_RANGE_LOCAL, _present_, CITYT_LAST)

Definition at line 456 of file unittype.cpp.

◆ requirement_unit_state_ereq

#define requirement_unit_state_ereq (   _id_,
  _present_ 
)     requirement_kind_ereq(_id_, REQ_RANGE_LOCAL, _present_, USP_COUNT)

Definition at line 454 of file unittype.cpp.

Function Documentation

◆ action_is_hostile()

static bool action_is_hostile ( action_id  act_id)
static

Returns TRUE iff the specified action is hostile.

Definition at line 249 of file unittype.cpp.

Referenced by local_dipl_rel_action_cache_set(), tgt_citytile_act_cache_set(), unit_can_act_cache_set(), and unit_state_action_cache_set().

◆ best_role_unit()

struct unit_type* best_role_unit ( const struct city pcity,
int  role 
)

Return "best" unit this city can build, with given role/flag.

Returns nullptr if none match. "Best" means highest unit type id.

Definition at line 1920 of file unittype.cpp.

Referenced by city_choose_build_default(), contemplate_new_city(), dai_choose_diplomat_defensive(), dai_choose_diplomat_offensive(), dai_choose_help_wonder(), dai_choose_trade_route(), dai_city_choose_build(), and domestic_advisor_choose_build().

◆ best_role_unit_for_player()

struct unit_type* best_role_unit_for_player ( const struct player pplayer,
int  role 
)

Return "best" unit the player can build, with given role/flag.

Returns nullptr if none match. "Best" means highest unit type id.

TODO: Cache the result per player?

Definition at line 1950 of file unittype.cpp.

Referenced by api_find_role_unit_type(), calculate_city_clusters(), city_gold_worth(), dai_wonder_city_distance(), find_best_city_placement(), find_something_to_kill(), and place_partisans().

◆ BV_DEFINE() [1/2]

BV_DEFINE ( bv_citytile_cache  ,
CITYT_LAST *  2 
)

◆ BV_DEFINE() [2/2]

BV_DEFINE ( bv_ustate_act_cache  ,
USP_COUNT *  2 
)

◆ can_player_build_unit_direct()

bool can_player_build_unit_direct ( const struct player p,
const struct unit_type punittype 
)

Whether player can build given unit somewhere, ignoring whether unit is obsolete and assuming the player has a coastal city.

Definition at line 1628 of file unittype.cpp.

Referenced by adv_data_phase_init(), can_city_build_unit_direct(), can_city_build_unit_now(), can_player_build_unit_later(), can_player_build_unit_now(), can_upgrade_unittype(), clipboard_copy_production(), and find_a_unit_type().

◆ can_player_build_unit_later()

bool can_player_build_unit_later ( const struct player p,
const struct unit_type punittype 
)

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

Returns FALSE if unit is obsolete.

Definition at line 1761 of file unittype.cpp.

Referenced by can_city_build_unit_later(), and collect_eventually_buildable_targets().

◆ can_player_build_unit_now()

bool can_player_build_unit_now ( const struct player p,
const struct unit_type punittype 
)

Whether player can build given unit somewhere; returns FALSE if unit is obsolete.

Definition at line 1742 of file unittype.cpp.

Referenced by best_role_unit_for_player(), collect_eventually_buildable_targets(), first_role_unit_for_player(), and mr_menu::update_airlift_menu().

◆ can_unit_act_when_ustate_is()

bool can_unit_act_when_ustate_is ( const struct unit_type punit_type,
const enum ustate_prop  prop,
const bool  is_there 
)

Return TRUE iff there exists an (action enabler controlled) action that a unit of the type punit_type can perform while its unit state property prop has the value is_there.

Definition at line 733 of file unittype.cpp.

Referenced by pf_action_possible().

◆ can_upgrade_unittype()

const struct unit_type* can_upgrade_unittype ( const struct player pplayer,
const struct unit_type punittype 
)

Return whether this player can upgrade this unit type (to any other unit type).

Returns nullptr if no upgrade is possible.

Definition at line 1379 of file unittype.cpp.

Referenced by action_not_enabled_reason(), count_my_units(), dai_upgrade_units(), do_unit_upgrade(), do_upgrade_effects(), get_units_upgrade_info(), get_units_view_data(), handle_unit_action_query(), handle_unit_type_upgrade(), upgrade_canvas_clipboard(), and units_view::upgrade_units().

◆ can_utype_do_act_if_tgt_diplrel()

bool can_utype_do_act_if_tgt_diplrel ( const struct unit_type punit_type,
const action_id  act_id,
const int  prop,
const bool  is_there 
)

Return TRUE iff the given (action enabler controlled) action can be performed by a unit of the given type while the given property of its owner's diplomatic relationship to the target's owner has the given value.

Note: since this only supports the local range no information for other ranges are stored in dipl_rel_action_cache.

Definition at line 784 of file unittype.cpp.

Referenced by action_not_enabled_reason(), city_can_be_built_here(), helptext_unit(), and need_war_player_hlp().

◆ first_role_unit_for_player()

struct unit_type* first_role_unit_for_player ( const struct player pplayer,
int  role 
)

Return first unit the player can build, with given role/flag.

Returns nullptr if none match. Used eg when placing starting units.

Definition at line 1976 of file unittype.cpp.

Referenced by building_advisor(), and crole_to_unit_type().

◆ get_role_unit()

◆ local_dipl_rel_action_cache_set()

static void local_dipl_rel_action_cache_set ( struct unit_type putype)
static

Cache what actions may be possible for a unit of the type putype for each local DiplRel variation.

Since a diplomatic relationship could be ignored both present and !present must be checked.

Note: since can_unit_act_when_local_diplrel_is() only supports querying the local range no values for the other ranges are set.

Definition at line 536 of file unittype.cpp.

Referenced by unit_type_action_cache_set().

◆ move_type_from_extra()

static enum unit_move_type move_type_from_extra ( struct extra_type pextra,
struct unit_class puc 
)
static

What move types nativity of this extra will give?

Definition at line 2408 of file unittype.cpp.

Referenced by set_unit_move_type().

◆ moves_left_range()

static struct range* moves_left_range ( struct requirement_vector *  reqs)
static

Get the legal range of move fragments left of the specified requirement vector.

Definition at line 683 of file unittype.cpp.

Referenced by utype_may_act_move_frags().

◆ num_role_units()

◆ precalc_one()

static void precalc_one ( int  i,
bool(*)(const struct unit_type *, int)  func_has 
)
static

Do the real work for role_unit_precalcs, for one role (or flag), given by i.

Definition at line 1791 of file unittype.cpp.

Referenced by role_unit_precalcs().

◆ role_unit_precalcs()

void role_unit_precalcs ( )

Initialize; it is safe to call this multiple times (e.g., if units have changed due to rulesets in client).

Definition at line 1838 of file unittype.cpp.

Referenced by client_state(), and load_rulesetdir().

◆ role_unit_precalcs_free()

void role_unit_precalcs_free ( )

Free memory allocated by role_unit_precalcs().

Definition at line 1823 of file unittype.cpp.

Referenced by game_ruleset_free(), and role_unit_precalcs().

◆ role_units_iterate_backwards()

struct unit_type* role_units_iterate_backwards ( int  role,
role_unit_callback  cb,
void *  data 
)

Iterate over all the role units and feed them to callback, starting from the last one.

Once callback returns TRUE, no further units are feeded to it and we return the unit that caused callback to return TRUE

Definition at line 1883 of file unittype.cpp.

Referenced by dai_role_utype_for_terrain_class().

◆ role_units_translations()

bool role_units_translations ( QString &  astr,
int  flag,
bool  alts 
)

Return a string with all the names of units with this flag.

If "alts" is set, separate with "or", otherwise "and". Return FALSE if no unit with this flag exists.

Definition at line 1343 of file unittype.cpp.

Referenced by illegal_action_msg(), req_text_insert(), and request_unit_goto().

◆ set_unit_class_caches()

void set_unit_class_caches ( struct unit_class pclass)

Set caches for unit class.

Definition at line 2349 of file unittype.cpp.

Referenced by handle_rulesets_ready(), and load_rulesetdir().

◆ set_unit_move_type()

void set_unit_move_type ( struct unit_class puclass)

Set move_type for unit class.

Definition at line 2504 of file unittype.cpp.

Referenced by handle_rulesets_ready().

◆ set_unit_type_caches()

void set_unit_type_caches ( struct unit_type ptype)

Set caches for unit types.

Definition at line 2408 of file unittype.cpp.

Referenced by handle_rulesets_ready(), and load_rulesetdir().

◆ set_user_unit_class_flag_name()

void set_user_unit_class_flag_name ( enum unit_class_flag_id  id,
const char *  name,
const char *  helptxt 
)

Sets user defined name for unit class flag.

Definition at line 1493 of file unittype.cpp.

Referenced by handle_ruleset_unit_class_flag(), load_unit_names(), and rscompat_names().

◆ set_user_unit_type_flag_name()

void set_user_unit_type_flag_name ( enum unit_type_flag_id  id,
const char *  name,
const char *  helptxt 
)

Sets user defined name for unit flag.

Definition at line 1556 of file unittype.cpp.

Referenced by handle_ruleset_unit_flag(), load_unit_names(), and rscompat_names().

◆ tgt_citytile_act_cache_set()

static void tgt_citytile_act_cache_set ( struct unit_type putype)
static

Cache if any action may be possible for a unit of the type putype for each target local city tile property.

Both present and !present must be checked since a city tile property could be ignored.

Definition at line 611 of file unittype.cpp.

Referenced by unit_type_action_cache_set().

◆ uclass_by_number()

struct unit_class* uclass_by_number ( const Unit_Class_id  id)

Returns unit class pointer for an ID value.

Definition at line 2129 of file unittype.cpp.

Referenced by handle_ruleset_unit(), handle_ruleset_unit_class(), and universal_value_initial().

◆ uclass_count()

Unit_Class_id uclass_count ( )

Return the unit_class count.

Definition at line 2101 of file unittype.cpp.

Referenced by helptext_extra(), helptext_terrain(), helptext_unit(), and req_text_insert().

◆ uclass_name_translation()

const char* uclass_name_translation ( const struct unit_class pclass)

Return the (translated) name of the unit class.

You don't have to free the return pointer.

Definition at line 1324 of file unittype.cpp.

Referenced by can_unit_move_to_tile_with_notify(), helptext_extra(), helptext_government(), helptext_terrain(), helptext_unit(), req_text_insert(), and universal_name_translation().

◆ uclass_number()

Unit_Class_id uclass_number ( const struct unit_class pclass)

Return the unit_class index.

Definition at line 2120 of file unittype.cpp.

Referenced by send_ruleset_unit_classes(), send_ruleset_units(), and universal_number().

◆ uclass_rule_name()

const char* uclass_rule_name ( const struct unit_class pclass)

Return the (untranslated) rule name of the unit class.

You don't have to free the return pointer.

Definition at line 1333 of file unittype.cpp.

Referenced by load_ruleset_units(), rscompat_optional_capabilities(), sanity_check_ruleset_data(), save_terrain_ruleset(), save_uclass_vec(), save_units_ruleset(), unit_class_by_rule_name(), universal_kind_values(), and universal_rule_name().

◆ unit_build_shield_cost()

int unit_build_shield_cost ( const struct city pcity,
const struct unit punit 
)

Returns the number of shields it takes to build this unit.

Definition at line 1176 of file unittype.cpp.

Referenced by city_gold_worth(), and city_incite_cost().

◆ unit_build_shield_cost_base()

◆ unit_can_act_cache_set()

static void unit_can_act_cache_set ( struct unit_type putype)
static

Cache what generalized (ruleset defined) action enabler controlled actions a unit of the given type can perform.

Definition at line 338 of file unittype.cpp.

Referenced by unit_type_action_cache_set().

◆ unit_can_take_over()

bool unit_can_take_over ( const struct unit punit)

Return whether the unit can take over enemy cities.

Definition at line 203 of file unittype.cpp.

Referenced by assess_danger(), dai_rampage_want(), dai_should_we_air_attack_tile(), find_something_to_kill(), kill_something_with(), and unit_conquer_city().

◆ unit_class_array_first()

struct unit_class* unit_class_array_first ( )

Return the first item of unit_classes.

Definition at line 2079 of file unittype.cpp.

◆ unit_class_array_last()

const struct unit_class* unit_class_array_last ( )

Return the last item of unit_classes.

Definition at line 2090 of file unittype.cpp.

◆ unit_class_by_rule_name()

struct unit_class* unit_class_by_rule_name ( const char *  s)

Returns the unit class that has the given (untranslated) rule name.

Returns nullptr if none match.

Definition at line 1463 of file unittype.cpp.

Referenced by load_ruleset_terrain(), load_ruleset_units(), and universal_by_number().

◆ unit_class_flag_helptxt()

const char* unit_class_flag_helptxt ( enum unit_class_flag_id  id)

Return the (untranslated) help text of the user unit class flag.

Definition at line 1534 of file unittype.cpp.

Referenced by helptext_unit(), save_units_ruleset(), and send_ruleset_unit_classes().

◆ unit_class_flag_id_name_cb()

const char* unit_class_flag_id_name_cb ( enum unit_class_flag_id  flag)

Unit class flag name callback, called from specenum code.

Definition at line 1522 of file unittype.cpp.

Referenced by first_free_unit_class_user_flag(), and save_units_ruleset().

◆ unit_class_flags_free()

void unit_class_flags_free ( )

Frees the memory associated with all unit class flags.

Definition at line 2067 of file unittype.cpp.

Referenced by game_ruleset_free().

◆ unit_class_get()

◆ unit_classes_free()

void unit_classes_free ( )

Free resources allocated for unit classes.

Definition at line 2179 of file unittype.cpp.

Referenced by game_ruleset_free().

◆ unit_classes_init()

void unit_classes_init ( )

Initialize unit_class structures.

Definition at line 2159 of file unittype.cpp.

Referenced by game_ruleset_init().

◆ unit_has_type_flag()

◆ unit_has_type_role()

bool unit_has_type_role ( const struct unit punit,
enum unit_role_id  role 
)

Return whether the unit has the given role.

Definition at line 195 of file unittype.cpp.

Referenced by dai_fill_unit_param(), dai_hunter_qualify(), dai_manage_barbarian_leader(), dai_manage_unit(), dai_spend_gold(), dai_unit_make_homecity(), and kill_unit().

◆ unit_name_translation()

◆ unit_pop_value()

int unit_pop_value ( const struct unit punit)

How much population is put to building this unit.

Definition at line 1239 of file unittype.cpp.

Referenced by action_not_enabled_reason(), city_add_unit(), and city_desirability().

◆ unit_rule_name()

◆ unit_state_action_cache_set()

static void unit_state_action_cache_set ( struct unit_type putype)
static

Cache if any action may be possible for a unit of the type putype for each unit state property.

Since a unit state property could be ignored both present and !present must be checked.

Definition at line 469 of file unittype.cpp.

Referenced by unit_type_action_cache_set().

◆ unit_type_action_cache_init()

void unit_type_action_cache_init ( )

Cache what unit types may be allowed do what actions, both at all and when certain properties are true.

Definition at line 722 of file unittype.cpp.

Referenced by load_rulesetdir().

◆ unit_type_action_cache_set()

void unit_type_action_cache_set ( struct unit_type ptype)

Cache if any action may be possible for a unit of the type putype given the property tested for.

Since a it could be ignored both present and !present must be checked.

Definition at line 710 of file unittype.cpp.

Referenced by handle_rulesets_ready(), and unit_type_action_cache_init().

◆ unit_type_array_first()

struct unit_type* unit_type_array_first ( )

Return the first item of unit_types.

Definition at line 52 of file unittype.cpp.

Referenced by api_edit_create_unit_full().

◆ unit_type_array_last()

const struct unit_type* unit_type_array_last ( )

Return the last item of unit_types.

Definition at line 63 of file unittype.cpp.

Referenced by api_edit_create_unit_full().

◆ unit_type_by_rule_name()

struct unit_type* unit_type_by_rule_name ( const char *  name)

Returns the unit type that has the given (untranslated) rule name.

Returns nullptr if none match.

Definition at line 1444 of file unittype.cpp.

Referenced by api_find_unit_type_by_name(), tab_unit::initialize_new_utype(), lookup_unit_list(), lookup_unit_type(), tab_unit::select_unit(), sg_load_player_units(), and universal_by_number().

◆ unit_type_by_translated_name()

struct unit_type* unit_type_by_translated_name ( const char *  name)

Returns the unit type that has the given (translated) name.

Returns nullptr if none match.

Definition at line 1427 of file unittype.cpp.

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

◆ unit_type_flag_helptxt()

const char* unit_type_flag_helptxt ( enum unit_type_flag_id  id)

Return the (untranslated) helptxt of the user unit flag.

Definition at line 1589 of file unittype.cpp.

Referenced by helptext_unit(), save_units_ruleset(), and send_ruleset_units().

◆ unit_type_flag_id_name_cb()

const char* unit_type_flag_id_name_cb ( enum unit_type_flag_id  flag)

Unit type flag name callback, called from specenum code.

Definition at line 1577 of file unittype.cpp.

Referenced by first_free_unit_type_user_flag(), and save_units_ruleset().

◆ unit_type_flags_free()

void unit_type_flags_free ( )

Frees the memory associated with all unit type flags.

Definition at line 2055 of file unittype.cpp.

Referenced by game_ruleset_free().

◆ unit_type_free()

static void unit_type_free ( struct unit_type punittype)
static

Frees the memory associated with this unit type.

Definition at line 2020 of file unittype.cpp.

Referenced by unit_types_free().

◆ unit_type_get()

const struct unit_type* unit_type_get ( const struct unit punit)

Return the unit type for this unit.

Definition at line 114 of file unittype.cpp.

Referenced by action_auto_perf_unit_sel(), action_dice_roll_odds(), action_get_act_time(), action_maybe_possible_actor_unit(), action_mp_full_makes_legal(), action_not_enabled_reason(), action_success_actor_consume(), action_success_target_pay_mp(), adv_danger_at(), adv_data_phase_init(), adv_unit_att_rating(), adv_unit_def_rating_basic(), adv_unit_move(), amphibious_move_scope(), api_edit_create_unit_full(), are_road_reqs_fulfilled(), assess_danger(), assess_danger_unit(), auto_settlers_player(), base_assess_defense_unit(), base_get_defense_power(), base_transporter_for_unit(), calculate_want_for_paratrooper(), can_be_irrigated(), can_build_base(), can_build_extra(), can_player_see_hypotetic_units_at(), can_player_see_unit_at(), can_remove_extra(), can_unit_do_activity_targeted_at(), can_unit_do_autosettlers(), can_unit_do_connect(), can_unit_exist_at_tile(), can_unit_move_to_tile_with_notify(), can_unit_survive_at_tile(), can_unit_transport(), can_unit_unload(), city_build(), city_can_be_built_here(), city_distribute_surplus_shields(), city_gold_worth(), city_unit_present(), city_unit_slots_available(), city_unit_supported(), city_unit_unhappiness(), city_units_upkeep(), clipboard_copy_production(), contemplate_terrain_improvements(), converting_fuel_rescue(), could_unit_load(), count_my_units(), cr_entry_attack(), cr_entry_defense(), create_extra(), units_select::create_pixmap(), dai_action_value_unit_vs_city(), dai_airlift(), dai_consider_tile_dangerous(), dai_data_phase_begin(), dai_diplomat_bribe_nearby(), dai_evaluate_tile_for_air_attack(), dai_fill_unit_param(), dai_find_strategic_airbase(), dai_gothere_bodyguard(), dai_hunter_juiciness(), dai_hunter_manage(), dai_hunter_missile_want(), dai_hunter_try_launch(), dai_manage_airunit(), dai_manage_diplomat(), dai_manage_hitpoint_recovery(), dai_manage_military(), dai_manage_paratrooper(), dai_manage_unit(), dai_military_attack(), dai_military_findjob(), dai_rampage_want(), dai_set_defenders(), dai_unit_make_homecity(), dai_unit_move(), dai_unit_new_task(), dai_upgrade_units(), dai_war_desire(), defense_multiplication(), destroy_extra(), diplomat_bribe(), diplomat_embassy(), diplomat_escape_full(), diplomat_get_tech(), diplomat_investigate(), diplomat_success_vs_defender(), disband_all_units(), do_capture_units(), do_heal_unit(), do_move_unit(), do_paradrop(), do_unit_act_sel_vs(), do_unit_upgrade(), do_upgrade_effects(), does_nation_block_action(), does_terrain_block_action(), edit_buffer_copy(), editor_grab_tool(), explain_why_no_action_enabled(), explorer_desirable(), freeciv::layer_grid::fill_sprite_array(), freeciv::layer_units::fill_sprite_array(), find_best_focus_candidate(), find_best_tile_to_paradrop_to(), find_nearest_safe_city(), find_nearest_unit(), find_something_to_kill(), get_activity_rate(), get_attack_power(), get_economy_report_units_data(), get_fortified_defense_power(), get_modified_firepower(), get_total_attack_power(), get_total_defense_power(), get_transporter_capacity(), get_unit_bonus(), get_unit_vision_at(), get_units_upgrade_info(), get_units_view_data(), goods_can_be_provided(), goto_fill_parameter_base(), handle_edit_unit(), handle_edit_unit_remove(), handle_unit_action_query(), handle_unit_bombard_info(), handle_unit_combat_info(), handle_unit_packet_common(), handle_unit_type_upgrade(), hp_gain_coord(), illegal_action_msg(), illegal_action_pay_price(), immediate_destination(), invasion_funct(), is_action_enabled_unit_on_city_full(), is_action_enabled_unit_on_self_full(), is_action_enabled_unit_on_tile_full(), is_action_enabled_unit_on_unit_full(), is_action_enabled_unit_on_units_full(), is_action_possible_on_unit(), is_attack_unit(), is_city_surrounded_by_our_spies(), is_hiding_unit(), is_losing_hp(), is_my_turn(), is_possible_base_fuel(), is_req_active(), is_square_threatened(), is_unit_being_refueled(), is_unit_reachable_at(), is_unit_reachable_by_unit(), key_unit_action_select(), kill_something_with(), look_for_charge(), map_change_seen(), map_hide_tile(), map_move_cost_unit(), map_show_tile(), maybe_become_veteran_real(), maybe_claim_base(), need_war_player_hlp(), notify_unit_experience(), package_short_unit(), package_unit(), units_select::paint(), paste_tile(), pf_attack_possible(), pf_reverse_map_unit_pos(), pft_fill_unit_attack_param(), pft_fill_unit_default_parameter(), pft_fill_unit_overlap_param(), pft_fill_unit_parameter(), player_restore_units(), popup_info_text(), quickselect(), remove_city(), request_unit_select(), request_units_return(), resolve_city_emergency(), sg_load_player_unit(), sg_load_player_units(), sg_load_sanitycheck(), mr_menu::slot_build_city(), spy_nuke_city(), spy_steal_some_maps(), tai_tile_worker_task_select(), texai_tile_worker_task_select(), texai_unit_update(), transfer_unit(), transform_unit(), unit_activity_astr(), unit_att_rating_now(), unit_being_aggressive(), unit_bombs_unit(), unit_bribe_cost(), unit_build_shield_cost(), unit_build_shield_cost_base(), unit_can_convert(), unit_can_do_action(), unit_can_do_action_result(), unit_can_est_trade_route_here(), unit_can_help_build_wonder_here(), unit_can_take_over(), unit_change_homecity_handling(), unit_change_owner(), unit_class_get(), unit_conquer_city(), unit_convert(), unit_def_rating(), unit_description(), unit_do_help_build(), unit_food_upkeep(), unit_foodbox_cost(), unit_has_type_flag(), unit_has_type_role(), unit_move(), unit_move_consequences(), unit_move_rate(), unit_name_translation(), unit_occupies_tile(), unit_pays_mp_for_action(), unit_pop_value(), unit_restore_hitpoints(), unit_rule_name(), unit_shield_value(), unit_transport_check(), unit_veteran_level_and_bonus(), unit_veteran_level_string(), unit_virtual_create(), units_can_convert(), hud_units::update_actions(), upgrade_unit_order_targets(), utype_player_already_has_this_unique(), and wipe_unit_full().

◆ unit_types_free()

void unit_types_free ( )

Frees the memory associated with all unit types.

Definition at line 2041 of file unittype.cpp.

Referenced by game_ruleset_free().

◆ unit_types_init()

void unit_types_init ( )

Inialize unit-type structures.

Definition at line 2001 of file unittype.cpp.

Referenced by game_ruleset_init().

◆ unit_upgrade_price()

int unit_upgrade_price ( const struct player pplayer,
const struct unit_type from,
const struct unit_type to 
)

Return the cost (gold) of upgrading a single unit of the specified type to the new type.

This price could (but currently does not) depend on other attributes (like nation or government type) of the player the unit belongs to.

Definition at line 1407 of file unittype.cpp.

Referenced by action_not_enabled_reason(), dai_upgrade_units(), do_unit_upgrade(), get_units_upgrade_info(), handle_unit_action_query(), handle_unit_type_upgrade(), transform_unit(), and units_view::upgrade_units().

◆ user_unit_class_flags_init()

void user_unit_class_flags_init ( )

Initialize user unit class flags.

Definition at line 1481 of file unittype.cpp.

Referenced by game_ruleset_init().

◆ user_unit_type_flags_init()

void user_unit_type_flags_init ( )

Initialize user unit type flags.

Definition at line 1544 of file unittype.cpp.

Referenced by game_ruleset_init().

◆ utype_acts_hostile()

bool utype_acts_hostile ( const struct unit_type putype)

Return TRUE iff units of this type can do hostile actions controlled by generalized (ruleset defined) action enablers.

Definition at line 432 of file unittype.cpp.

Referenced by assess_danger(), dai_hunter_juiciness(), dai_hunter_manage(), find_something_to_kill(), goto_fill_parameter_base(), and is_square_threatened().

◆ utype_ai_data()

void* utype_ai_data ( const struct unit_type ptype,
const struct ai_type ai 
)

Return pointer to ai data of given unit type and ai type.

Definition at line 2332 of file unittype.cpp.

Referenced by assess_danger(), dai_can_unit_type_follow_unit_type(), dai_hunter_guess_best(), dai_unit_defence_desirability(), dai_units_ruleset_close(), and dai_units_ruleset_init().

◆ utype_build_shield_cost()

◆ utype_build_shield_cost_base()

int utype_build_shield_cost_base ( const struct unit_type punittype)

◆ utype_buy_gold_cost()

int utype_buy_gold_cost ( const struct city pcity,
const struct unit_type punittype,
int  shields_in_stock 
)

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

Definition at line 1193 of file unittype.cpp.

Referenced by city_gold_worth(), and city_production_buy_gold_cost().

◆ utype_by_number()

◆ utype_can_do_act_if_tgt_citytile()

bool utype_can_do_act_if_tgt_citytile ( const struct unit_type punit_type,
const action_id  act_id,
const enum citytile_type  prop,
const bool  is_there 
)

Returns TRUE iff the unit type can do the specified (action enabler controlled) action while its target's CityTile property state has the value is_there.

Definition at line 763 of file unittype.cpp.

◆ utype_can_do_act_when_ustate()

bool utype_can_do_act_when_ustate ( const struct unit_type punit_type,
const action_id  act_id,
const enum ustate_prop  prop,
const bool  is_there 
)

Return TRUE iff the unit type can do the specified (action enabler controlled) action while its unit state property prop has the value is_there.

Definition at line 746 of file unittype.cpp.

Referenced by action_not_enabled_reason(), can_attack_from_non_native(), can_unit_act_when_ustate_is(), city_can_be_built_here(), explain_why_no_action_enabled(), and illegal_action_msg().

◆ utype_can_do_action()

bool utype_can_do_action ( const struct unit_type putype,
const action_id  act_id 
)

◆ utype_can_do_action_result()

bool utype_can_do_action_result ( const struct unit_type putype,
enum action_result  result 
)

Return TRUE iff units of the given type can do any enabler controlled action with the specified action result.

Note that a specific unit in a specific situation still may be unable to perform the specified action.

Definition at line 402 of file unittype.cpp.

Referenced by aia_utype_is_considered_caravan_trade(), aia_utype_is_considered_spy(), aia_utype_is_considered_spy_vs_city(), aia_utype_is_considered_worker(), can_attack_non_native(), can_player_build_unit_direct(), dai_fill_unit_param(), get_fortified_defense_power(), helptext_unit(), look_for_charge(), city_production_delegate::paint(), unit_can_do_action_result(), utype_can_take_over(), and utype_is_cityfounder().

◆ utype_can_do_action_role()

static bool utype_can_do_action_role ( const struct unit_type putype,
const int  role 
)
static

Return TRUE iff the unit type can perform the action corresponding to the unit type role.

Definition at line 422 of file unittype.cpp.

Referenced by role_unit_precalcs().

◆ utype_can_freely_load()

bool utype_can_freely_load ( const struct unit_type pcargotype,
const struct unit_type ptranstype 
)

Return TRUE iff the given cargo type has no restrictions on when it can load onto the given transporter.

(Does not check that cargo is valid for transport!)

Definition at line 227 of file unittype.cpp.

Referenced by could_unit_load(), helptext_unit(), and is_possible_base_fuel().

◆ utype_can_freely_unload()

bool utype_can_freely_unload ( const struct unit_type pcargotype,
const struct unit_type ptranstype 
)

Return TRUE iff the given cargo type has no restrictions on when it can unload from the given transporter.

(Does not check that cargo is valid for transport!)

Definition at line 239 of file unittype.cpp.

Referenced by base_transporter_for_unit(), can_unit_unload(), helptext_unit(), pf_danger_map_iterate(), pf_fuel_map_iterate(), and pf_normal_map_new().

◆ utype_can_take_over()

bool utype_can_take_over ( const struct unit_type punittype)

Return whether the unit type can take over enemy cities.

Definition at line 215 of file unittype.cpp.

Referenced by process_attacker_want(), and unit_can_take_over().

◆ utype_count()

Unit_type_id utype_count ( )

◆ utype_happy_cost()

int utype_happy_cost ( const struct unit_type ut,
const struct player pplayer 
)

Return the "happy cost" (the number of citizens who are discontented) for this unit.

Definition at line 167 of file unittype.cpp.

Referenced by city_unit_unhappiness(), and resolve_city_emergency().

◆ utype_has_role()

bool utype_has_role ( const struct unit_type punittype,
int  role 
)

Return whether the given unit type has the role.

Roles are like flags but have no meaning except to the AI.

Definition at line 186 of file unittype.cpp.

Referenced by api_methods_unit_type_has_role(), can_player_build_unit_direct(), dai_choose_bodyguard(), dai_process_defender_want(), load_ruleset_units(), role_unit_precalcs(), rs_barbarian_units(), save_units_ruleset(), unit_has_type_role(), and unit_role_defender().

◆ utype_index()

◆ utype_is_cityfounder()

bool utype_is_cityfounder ( const struct unit_type utype)

Is cityfounder type.

Definition at line 2549 of file unittype.cpp.

Referenced by dai_spend_gold(), and dai_war_desire().

◆ utype_is_consumed_by_action()

bool utype_is_consumed_by_action ( const struct action paction,
const struct unit_type utype 
)

◆ utype_is_consumed_by_action_result()

bool utype_is_consumed_by_action_result ( enum action_result  result,
const struct unit_type utype 
)

Returns TRUE iff performing an action with the specified action result will consume an actor unit of the specified type.

Definition at line 947 of file unittype.cpp.

Referenced by best_role_unit(), dai_choose_attacker_air(), dai_choose_paratrooper(), dai_hunter_guess_best(), and city_production_delegate::paint().

◆ utype_is_moved_to_tgt_by_action()

bool utype_is_moved_to_tgt_by_action ( const struct action paction,
const struct unit_type utype 
)

Returns TRUE iff successfully performing the specified action always will move the actor unit of the specified type to the target's tile.

Definition at line 969 of file unittype.cpp.

Referenced by adv_unit_move(), freeciv::detail::vertex::child_for_action(), dai_action_value_unit_vs_city(), dai_unit_move(), illegal_action_pay_price(), unit_order_list_is_sane(), upgrade_unit_order_targets(), utype_pays_for_regular_move_to_tgt(), and utype_pays_mp_for_action_estimate().

◆ utype_is_unmoved_by_action()

bool utype_is_unmoved_by_action ( const struct action paction,
const struct unit_type utype 
)

Returns TRUE iff successfully performing the specified action never will move the actor unit from its current tile.

Definition at line 1009 of file unittype.cpp.

Referenced by dai_action_value_unit_vs_city(), unit_order_list_is_sane(), and upgrade_unit_order_targets().

◆ utype_may_act_at_all()

bool utype_may_act_at_all ( const struct unit_type putype)

◆ utype_may_act_move_frags()

bool utype_may_act_move_frags ( const struct unit_type punit_type,
const action_id  act_id,
const int  move_fragments 
)

Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given type that has the given number of move fragments left.

Note: Values aren't cached. If a performance critical user appears it would be a good idea to cache the (merged) ranges of move fragments where a unit of the given type can perform the specified action.

Definition at line 804 of file unittype.cpp.

Referenced by action_mp_full_makes_legal().

◆ utype_may_act_tgt_city_tile()

bool utype_may_act_tgt_city_tile ( const struct unit_type punit_type,
const action_id  act_id,
const enum citytile_type  prop,
const bool  is_there 
)

Return TRUE iff the given (action enabler controlled) action may be performed by a unit of the given type if the target tile has the given property.

Note: Values aren't cached. If a performance critical user appears it would be a good idea to cache the result.

Definition at line 870 of file unittype.cpp.

Referenced by action_not_enabled_reason().

◆ utype_move_type()

enum unit_move_type utype_move_type ( const struct unit_type punittype)

Return move type of the unit type.

Definition at line 1239 of file unittype.cpp.

Referenced by editor_grab_tool(), and quickselect().

◆ utype_name_translation()

const char* utype_name_translation ( const struct unit_type punittype)

Return the (translated) name of the unit type.

You don't have to free the return pointer.

Definition at line 1256 of file unittype.cpp.

Referenced by api_methods_unit_type_name_translation(), boot_help_texts(), can_unit_move_to_tile_with_notify(), city_build_unit(), disband_all_units(), disband_city(), eco_report::disband_units(), units_view::disband_units(), do_unit_upgrade(), do_upgrade_effects(), editor_tool_get_value_name(), explain_why_no_action_enabled(), get_tooltip_unit(), handle_edit_unit_create(), handle_edit_unit_remove(), handle_unit_type_upgrade(), helptext_building(), helptext_government(), helptext_nation(), helptext_unit(), illegal_action_msg(), insert_allows(), manual_command(), research_diagram::mousePressEvent(), city_production_delegate::paint(), city_production_model::populate(), popup_info_text(), really_handle_city_buy(), req_text_insert(), research_tech_lost(), role_units_translations(), rscompat_optional_capabilities(), help_widget::set_topic_tech(), help_widget::set_topic_unit(), sg_load_sanitycheck(), try_to_save_unit(), unit_convert(), unit_description(), unit_hud_selector::unit_hud_selector(), unit_lost_with_transport(), unit_name_translation(), unit_type_by_translated_name(), universal_name_translation(), mr_menu::update_airlift_menu(), eco_report::update_report(), units_view::update_units(), units_view::update_waiting(), upgrade_unit_prod(), units_view::upgrade_units(), utype_values_translation(), worklist_change_build_target(), and worklist_item_postpone_req_vec().

◆ utype_number()

◆ utype_pays_for_regular_move_to_tgt()

bool utype_pays_for_regular_move_to_tgt ( const struct action paction,
const struct unit_type utype 
)

Returns TRUE iff successfully performing the specified action always will cost the actor unit of the specified type the move fragments it would take to perform a regular move to the target's tile.

This cost is added to the cost of successfully performing the action.

Definition at line 1052 of file unittype.cpp.

Referenced by dai_action_value_unit_vs_city(), and utype_pays_mp_for_action_estimate().

◆ utype_pays_mp_for_action_base()

int utype_pays_mp_for_action_base ( const struct action paction,
const struct unit_type putype 
)

Returns the amount of movement points successfully performing the specified action will consume in the actor unit type without taking effects or regular moves into account.

Definition at line 1083 of file unittype.cpp.

Referenced by helptext_unit(), unit_pays_mp_for_action(), and utype_pays_mp_for_action_estimate().

◆ utype_pays_mp_for_action_estimate()

int utype_pays_mp_for_action_estimate ( const struct action paction,
const struct unit_type putype,
const struct player act_player,
const struct tile act_tile,
const struct tile tgt_tile 
)

Returns an estimate of the amount of movement points successfully performing the specified action will consume in the actor unit type.

Definition at line 1104 of file unittype.cpp.

Referenced by dai_evaluate_tile_for_air_attack().

◆ utype_player_already_has_this_unique()

bool utype_player_already_has_this_unique ( const struct player pplayer,
const struct unit_type putype 
)

Returns TRUE iff the unit type is unique and the player already has one.

Definition at line 1599 of file unittype.cpp.

Referenced by action_not_enabled_reason(), can_player_build_unit_direct(), diplomat_bribe(), do_capture_units(), transfer_unit(), unit_change_homecity_handling(), and unit_change_owner().

◆ utype_pop_value()

int utype_pop_value ( const struct unit_type punittype)

How much city shrinks when it builds unit of this type.

Definition at line 1231 of file unittype.cpp.

Referenced by action_actor_utype_hard_reqs_ok_full(), city_build_unit(), city_production_build_units(), helptext_unit(), and unit_pop_value().

◆ utype_rule_name()

◆ utype_set_ai_data()

void utype_set_ai_data ( struct unit_type ptype,
const struct ai_type ai,
void *  data 
)

Attach ai data to unit type.

Definition at line 2340 of file unittype.cpp.

Referenced by dai_units_ruleset_close(), and dai_units_ruleset_init().

◆ utype_upkeep_cost()

int utype_upkeep_cost ( const struct unit_type ut,
struct player pplayer,
Output_type_id  otype 
)

◆ utype_values_string()

const char* utype_values_string ( const struct unit_type punittype)

Return string describing unit type values.

String is static buffer that gets reused when function is called again.

Definition at line 1292 of file unittype.cpp.

Referenced by utype_values_translation().

◆ utype_values_translation()

const char* utype_values_translation ( const struct unit_type punittype)

Return string with translated unit name and list of its values.

String is static buffer that gets reused when function is called again.

Definition at line 1310 of file unittype.cpp.

Referenced by name_and_sort_items(), and city_dialog::update_improvements().

◆ utype_veteran_has_power_bonus()

bool utype_veteran_has_power_bonus ( const struct unit_type punittype)

Return whether this unit type's veteran system, if any, confers a power factor bonus at any level (it could just add extra moves).

Definition at line 2267 of file unittype.cpp.

Referenced by helptext_unit().

◆ utype_veteran_level()

◆ utype_veteran_levels()

int utype_veteran_levels ( const struct unit_type punittype)

◆ utype_veteran_name_translation()

const char* utype_veteran_name_translation ( const struct unit_type punittype,
int  level 
)

Return translated name of the given veteran level.

nullptr if this unit type doesn't have different veteran levels.

Definition at line 2239 of file unittype.cpp.

Referenced by popup_info_text(), and unit_description().

◆ utype_veteran_system()

const struct veteran_system* utype_veteran_system ( const struct unit_type punittype)

Return veteran system used for this unit type.

Definition at line 2208 of file unittype.cpp.

Referenced by helptext_government(), maybe_become_veteran_real(), notify_unit_experience(), transform_unit(), utype_veteran_level(), and utype_veteran_levels().

◆ veteran_system_definition()

void veteran_system_definition ( struct veteran_system vsystem,
int  level,
const char *  vlist_name,
int  vlist_power,
int  vlist_move,
int  vlist_raise,
int  vlist_wraise 
)

Fill veteran level in given veteran system with given information.

Definition at line 2310 of file unittype.cpp.

Referenced by handle_ruleset_game(), handle_ruleset_unit(), and load_ruleset_veteran().

◆ veteran_system_destroy()

void veteran_system_destroy ( struct veteran_system vsystem)

Free veteran system.

Definition at line 2298 of file unittype.cpp.

Referenced by game_ruleset_free(), and unit_type_free().

◆ veteran_system_new()

struct veteran_system* veteran_system_new ( int  count)

Allocate new veteran system structure with given veteran level count.

Definition at line 2281 of file unittype.cpp.

Referenced by handle_ruleset_game(), handle_ruleset_unit(), and load_ruleset_veteran().

Variable Documentation

◆ ctile_tgt_act_cache

bv_citytile_cache ctile_tgt_act_cache[U_LAST][ACTION_AND_FAKES]
static

Definition at line 462 of file unittype.cpp.

Referenced by tgt_citytile_act_cache_set(), and utype_can_do_act_if_tgt_citytile().

◆ dipl_rel_action_cache

bv_diplrel_all_reqs dipl_rel_action_cache[U_LAST][ACTION_AND_FAKES]
static

◆ first_init

bool first_init = true
static

The following functions use static variables so we can quickly look up which unit types have given flag or role.

For these functions flags and roles are considered to be in the same "space", and any "role" argument can also be a "flag". Unit order is in terms of the order in the units ruleset.

Definition at line 1783 of file unittype.cpp.

Referenced by best_role_unit(), best_role_unit_for_player(), first_role_unit_for_player(), get_role_unit(), num_role_units(), and role_unit_precalcs().

◆ n_with_role

◆ unit_can_act_cache

bv_unit_types unit_can_act_cache[ACTION_AND_FAKES]
static

Definition at line 332 of file unittype.cpp.

Referenced by unit_can_act_cache_set(), and utype_can_do_action().

◆ unit_classes

◆ unit_types

◆ user_class_flags

◆ user_type_flags

◆ ustate_act_cache

bv_ustate_act_cache ustate_act_cache[U_LAST][ACTION_AND_FAKES]
static

Definition at line 460 of file unittype.cpp.

Referenced by unit_state_action_cache_set(), and utype_can_do_act_when_ustate().

◆ with_role