Freeciv21
Develop your civilization from humble roots to a global empire
unit.cpp File Reference
#include "bitvector.h"
#include "fcintl.h"
#include "shared.h"
#include "support.h"
#include "actions.h"
#include "ai.h"
#include "city.h"
#include "game.h"
#include "log.h"
#include "map.h"
#include "movement.h"
#include "packets.h"
#include "player.h"
#include "unitlist.h"
#include "unit.h"
+ Include dependency graph for unit.cpp:

Go to the source code of this file.

Classes

struct  cargo_iter
 

Macros

#define CARGO_ITER(iter)   ((struct cargo_iter *) (iter))
 

Functions

static bool is_real_activity (enum unit_activity activity)
 Return if given activity really is in game. More...
 
bool are_unit_orders_equal (const struct unit_order *order1, const struct unit_order *order2)
 Checks unit orders for equality. More...
 
enum unit_airlift_result test_unit_can_airlift_to (const struct player *restriction, const struct unit *punit, const struct city *pdest_city)
 Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now. More...
 
bool unit_can_airlift_to (const struct unit *punit, const struct city *pdest_city)
 Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now. More...
 
bool unit_has_orders (const struct unit *punit)
 Return TRUE iff the unit is following client-side orders. More...
 
int unit_shield_value (const struct unit *punit, const struct unit_type *punittype, const struct action *paction)
 Returns how many shields the unit (type) is worth. More...
 
bool unit_can_help_build_wonder_here (const struct unit *punit)
 Return TRUE unless it is known to be imposible to disband this unit at its current position to get full shields for building a wonder. More...
 
bool unit_can_est_trade_route_here (const struct unit *punit)
 Return TRUE iff this unit can be disbanded at its current location to provide a trade route from the homecity to the target city. More...
 
int get_transporter_capacity (const struct unit *punit)
 Return the number of units the transporter can hold (or 0). More...
 
bool is_attack_unit (const struct unit *punit)
 Is the unit capable of attacking? More...
 
bool is_military_unit (const struct unit *punit)
 Military units are capable of enforcing martial law. More...
 
bool unit_can_do_action (const struct unit *punit, const action_id act_id)
 Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlled action. More...
 
bool unit_can_do_action_result (const struct unit *punit, enum action_result result)
 Return TRUE iff this unit can do any enabler controlled action with the specified action result. More...
 
bool is_square_threatened (const struct player *pplayer, const struct tile *ptile, bool omniscient)
 Return TRUE iff this tile is threatened from any unit within 2 tiles. More...
 
bool is_field_unit (const struct unit *punit)
 This checks the "field unit" flag on the unit. More...
 
bool is_hiding_unit (const struct unit *punit)
 Is the unit one that is invisible on the map. More...
 
bool kills_citizen_after_attack (const struct unit *punit)
 Return TRUE iff an attack from this unit would kill a citizen in a city (city walls protect against this). More...
 
bool unit_can_add_or_build_city (const struct unit *punit)
 Return TRUE iff this unit can add to a current city or build a new city at its current location. More...
 
bool can_unit_change_homecity_to (const struct unit *punit, const struct city *pcity)
 Return TRUE iff the unit can change homecity to the given city. More...
 
bool can_unit_change_homecity (const struct unit *punit)
 Return TRUE iff the unit can change homecity at its current location. More...
 
int get_activity_rate (const struct unit *punit)
 Returns the speed of a unit doing an activity. More...
 
int get_activity_rate_this_turn (const struct unit *punit)
 Returns the amount of work a unit does (will do) on an activity this turn. More...
 
int get_turns_for_activity_at (const struct unit *punit, enum unit_activity activity, const struct tile *ptile, struct extra_type *tgt)
 Return the estimated number of turns for the worker unit to start and complete the activity at the given location. More...
 
bool activity_requires_target (enum unit_activity activity)
 Return TRUE if activity requires some sort of target to be specified. More...
 
bool can_unit_do_autosettlers (const struct unit *punit)
 Return whether the unit can be put in auto-settler mode. More...
 
void setup_real_activities_array ()
 Setup array of real activities. More...
 
const char * get_activity_text (enum unit_activity activity)
 Return the name of the activity in a static buffer. More...
 
bool could_unit_load (const struct unit *pcargo, const struct unit *ptrans)
 Return TRUE iff the given unit could be loaded into the transporter if we moved there. More...
 
bool can_unit_load (const struct unit *pcargo, const struct unit *ptrans)
 Return TRUE iff the given unit can be loaded into the transporter. More...
 
bool can_unit_unload (const struct unit *pcargo, const struct unit *ptrans)
 Return TRUE iff the given unit can be unloaded from its current transporter. More...
 
bool can_unit_alight_or_be_unloaded (const struct unit *pcargo, const struct unit *ptrans)
 Return TRUE iff the given unit can leave its current transporter without doing any other action or move. More...
 
bool can_unit_paradrop (const struct unit *punit)
 Return whether the unit can be paradropped - that is, if the unit is in a friendly city or on an airbase special, has enough movepoints left, and has not paradropped yet this turn. More...
 
bool can_unit_continue_current_activity (struct unit *punit)
 Check if the unit's current activity is actually legal. More...
 
bool can_unit_do_activity (const struct unit *punit, enum unit_activity activity)
 Return TRUE iff the unit can do the given untargeted activity at its current location. More...
 
bool can_unit_do_activity_targeted (const struct unit *punit, enum unit_activity activity, struct extra_type *target)
 Return whether the unit can do the targeted activity at its current location. More...
 
bool can_unit_do_activity_targeted_at (const struct unit *punit, enum unit_activity activity, struct extra_type *target, const struct tile *ptile)
 Return TRUE if the unit can do the targeted activity at the given location. More...
 
static void set_unit_activity_internal (struct unit *punit, enum unit_activity new_activity)
 Assign a new task to a unit. More...
 
void set_unit_activity (struct unit *punit, enum unit_activity new_activity)
 Assign a new untargeted task to a unit. More...
 
void set_unit_activity_targeted (struct unit *punit, enum unit_activity new_activity, struct extra_type *new_target)
 assign a new targeted task to a unit. More...
 
bool is_unit_activity_on_tile (enum unit_activity activity, const struct tile *ptile)
 Return whether any units on the tile are doing this activity. More...
 
bv_extras get_unit_tile_pillage_set (const struct tile *ptile)
 Return a mask of the extras which are actively (currently) being pillaged on the given tile. More...
 
const QString unit_activity_text (const struct unit *punit)
 Return text describing the unit's current activity as a static string. More...
 
void unit_activity_astr (const struct unit *punit, QString &s)
 Append text describing the unit's current activity to the given astring. More...
 
void unit_upkeep_astr (const struct unit *punit, QString &s)
 Append a line of text describing the unit's upkeep to the astring. More...
 
struct playerunit_nationality (const struct unit *punit)
 Return the nationality of the unit. More...
 
void unit_tile_set (struct unit *punit, struct tile *ptile)
 Set the tile location of the unit. More...
 
struct unitis_allied_unit_tile (const struct tile *ptile, const struct player *pplayer)
 Returns true if the tile contains an allied unit and only allied units. More...
 
struct unitis_enemy_unit_tile (const struct tile *ptile, const struct player *pplayer)
 Is there an enemy unit on this tile? Returns the unit or nullptr if none. More...
 
struct unitis_non_allied_unit_tile (const struct tile *ptile, const struct player *pplayer)
 Is there an non-allied unit on this tile? More...
 
struct unitis_other_players_unit_tile (const struct tile *ptile, const struct player *pplayer)
 Is there an unit belonging to another player on this tile? More...
 
struct unitis_non_attack_unit_tile (const struct tile *ptile, const struct player *pplayer)
 Is there an unit we have peace or ceasefire with on this tile? More...
 
struct unitunit_occupies_tile (const struct tile *ptile, const struct player *pplayer)
 Is there an occupying unit on this tile? More...
 
bool is_my_zoc (const struct player *pplayer, const struct tile *ptile0, const struct civ_map *zmap)
 Is this square controlled by the pplayer? More...
 
bool unit_type_really_ignores_zoc (const struct unit_type *punittype)
 Takes into account unit class flag UCF_ZOC as well as IGZOC. More...
 
bool unit_being_aggressive (const struct unit *punit)
 An "aggressive" unit is a unit which may cause unhappiness under a Republic or Democracy. More...
 
bool is_build_activity (enum unit_activity activity, const struct tile *ptile)
 Returns true if given activity is some kind of building. More...
 
bool is_clean_activity (enum unit_activity activity)
 Returns true if given activity is some kind of cleaning. More...
 
bool is_terrain_change_activity (enum unit_activity activity)
 Returns true if given activity changes terrain. More...
 
bool is_tile_activity (enum unit_activity activity)
 Returns true if given activity affects tile. More...
 
struct unitunit_virtual_create (struct player *pplayer, struct city *pcity, const struct unit_type *punittype, int veteran_level)
 Create a virtual unit skeleton. More...
 
void unit_virtual_destroy (struct unit *punit)
 Free the memory used by virtual unit. More...
 
void free_unit_orders (struct unit *punit)
 Free and reset the unit's goto route (punit->pgr). More...
 
int get_transporter_occupancy (const struct unit *ptrans)
 Return how many units are in the transport. More...
 
static struct unitbase_transporter_for_unit (const struct unit *pcargo, const struct tile *ptile, bool(*unit_load_test)(const struct unit *pc, const struct unit *pt))
 Helper for transporter_for_unit() and transporter_for_unit_at() More...
 
struct unittransporter_for_unit (const struct unit *pcargo)
 Find the best transporter at the given location for the unit. More...
 
struct unittransporter_for_unit_at (const struct unit *pcargo, const struct tile *ptile)
 Find the best transporter at the given location for the unit. More...
 
static bool can_type_transport_units_cargo (const struct unit_type *utype, const struct unit *punit)
 Check if unit of given type would be able to transport all of transport's cargo. More...
 
enum unit_upgrade_result unit_upgrade_test (const struct unit *punit, bool is_free)
 Tests if the unit could be updated. More...
 
bool unit_can_convert (const struct unit *punit)
 Tests if unit can be converted to another type. More...
 
enum unit_upgrade_result unit_upgrade_info (const struct unit *punit, char *buf, size_t bufsz)
 Find the result of trying to upgrade the unit, and a message that most callers can use directly. More...
 
int unit_pays_mp_for_action (const struct action *paction, const struct unit *punit)
 Returns the amount of movement points successfully performing the specified action will consume in the actor unit. More...
 
bool is_losing_hp (const struct unit *punit)
 Does unit lose hitpoints each turn? More...
 
bool unit_type_is_losing_hp (const struct player *pplayer, const struct unit_type *punittype)
 Does unit lose hitpoints each turn? More...
 
bool unit_is_alive (int id)
 Check if unit with given id is still alive. More...
 
bool unit_is_virtual (const struct unit *punit)
 Return TRUE if this is a valid unit pointer but does not correspond to any unit that exists in the game. More...
 
void * unit_ai_data (const struct unit *punit, const struct ai_type *ai)
 Return pointer to ai data of given unit and ai type. More...
 
void unit_set_ai_data (struct unit *punit, const struct ai_type *ai, void *data)
 Attach ai data to unit. More...
 
int unit_bribe_cost (struct unit *punit, struct player *briber)
 Calculate how expensive it is to bribe the unit. More...
 
bool unit_transport_load (struct unit *pcargo, struct unit *ptrans, bool force)
 Load pcargo onto ptrans. More...
 
bool unit_transport_unload (struct unit *pcargo)
 Unload pcargo from ptrans. More...
 
bool unit_transported (const struct unit *pcargo)
 Returns TRUE iff the unit is transported. More...
 
struct unitunit_transport_get (const struct unit *pcargo)
 Returns the transporter of the unit or nullptr if it is not transported. More...
 
struct unit_list * unit_transport_cargo (const struct unit *ptrans)
 Returns the list of cargo units. More...
 
static bool unit_transport_check_one (const struct unit_type *cargo_utype, const struct unit_type *trans_utype)
 Helper for unit_transport_check(). More...
 
bool unit_transport_check (const struct unit *pcargo, const struct unit *ptrans)
 Returns whether 'pcargo' in 'ptrans' is a valid transport. More...
 
bool unit_contained_in (const struct unit *pcargo, const struct unit *ptrans)
 Returns whether 'pcargo' is transported by 'ptrans', either directly or indirectly. More...
 
int unit_cargo_depth (const struct unit *ptrans)
 Returns the number of unit cargo layers within transport 'ptrans'. More...
 
int unit_transport_depth (const struct unit *pcargo)
 Returns the number of unit transport layers which carry unit 'pcargo'. More...
 
size_t cargo_iter_sizeof ()
 Returns the size of the unit cargo iterator. More...
 
static void * cargo_iter_get (const struct iterator *it)
 Get the unit of the cargo iterator. More...
 
static void cargo_iter_next (struct iterator *it)
 Try to find next unit for the cargo iterator. More...
 
static bool cargo_iter_valid (const struct iterator *it)
 Return whether the iterator is still valid. More...
 
struct iteratorcargo_iter_init (struct cargo_iter *iter, const struct unit *ptrans)
 Initialize the cargo iterator. More...
 
bool unit_is_cityfounder (const struct unit *punit)
 Is a cityfounder unit? More...
 

Variables

Activity_type_id real_activities [ACTIVITY_LAST]
 
const Activity_type_id tile_changing_activities []
 

Macro Definition Documentation

◆ CARGO_ITER

#define CARGO_ITER (   iter)    ((struct cargo_iter *) (iter))

Definition at line 49 of file unit.cpp.

Function Documentation

◆ activity_requires_target()

bool activity_requires_target ( enum unit_activity  activity)

◆ are_unit_orders_equal()

bool are_unit_orders_equal ( const struct unit_order order1,
const struct unit_order order2 
)

Checks unit orders for equality.

Definition at line 54 of file unit.cpp.

◆ base_transporter_for_unit()

static struct unit* base_transporter_for_unit ( const struct unit pcargo,
const struct tile ptile,
bool(*)(const struct unit *pc, const struct unit *pt)  unit_load_test 
)
static

◆ can_type_transport_units_cargo()

static bool can_type_transport_units_cargo ( const struct unit_type utype,
const struct unit punit 
)
static

Check if unit of given type would be able to transport all of transport's cargo.

Definition at line 1799 of file unit.cpp.

Referenced by unit_can_convert().

◆ can_unit_alight_or_be_unloaded()

bool can_unit_alight_or_be_unloaded ( const struct unit pcargo,
const struct unit ptrans 
)

Return TRUE iff the given unit can leave its current transporter without doing any other action or move.

Definition at line 745 of file unit.cpp.

Referenced by unit_can_defend_here().

◆ can_unit_change_homecity()

bool can_unit_change_homecity ( const struct unit punit)

Return TRUE iff the unit can change homecity at its current location.

Definition at line 430 of file unit.cpp.

Referenced by mr_menu::menus_sensitive().

◆ can_unit_change_homecity_to()

bool can_unit_change_homecity_to ( const struct unit punit,
const struct city pcity 
)

Return TRUE iff the unit can change homecity to the given city.

Definition at line 415 of file unit.cpp.

Referenced by can_unit_change_homecity(), and unit_actions::update_actions().

◆ can_unit_continue_current_activity()

bool can_unit_continue_current_activity ( struct unit punit)

Check if the unit's current activity is actually legal.

Definition at line 780 of file unit.cpp.

Referenced by create_city(), research_tech_lost(), sg_load_players(), unit_activities_cancel_all_illegal(), unit_activity_complete(), and unit_change_homecity_handling().

◆ can_unit_do_activity()

bool can_unit_do_activity ( const struct unit punit,
enum unit_activity  activity 
)

◆ can_unit_do_activity_targeted()

bool can_unit_do_activity_targeted ( const struct unit punit,
enum unit_activity  activity,
struct extra_type target 
)

◆ can_unit_do_activity_targeted_at()

bool can_unit_do_activity_targeted_at ( const struct unit punit,
enum unit_activity  activity,
struct extra_type target,
const struct tile ptile 
)

Return TRUE if the unit can do the targeted activity at the given location.

Definition at line 854 of file unit.cpp.

Referenced by can_unit_do_activity_targeted().

◆ can_unit_do_autosettlers()

bool can_unit_do_autosettlers ( const struct unit punit)

Return whether the unit can be put in auto-settler mode.

NOTE: we used to have "auto" mode including autosettlers and auto-attack. This was bad because the two were indestinguishable even though they are very different. Now auto-attack is done differently so we just have auto-settlers. If any new auto modes are introduced they should be handled separately.

Definition at line 548 of file unit.cpp.

Referenced by key_unit_auto_settle(), mr_menu::menus_sensitive(), request_unit_autosettlers(), unit_server_side_agent_set(), and unit_actions::update_actions().

◆ can_unit_load()

bool can_unit_load ( const struct unit pcargo,
const struct unit ptrans 
)

Return TRUE iff the given unit can be loaded into the transporter.

Definition at line 693 of file unit.cpp.

Referenced by api_edit_create_unit_full(), dai_unit_new_task(), transporter_for_unit(), and unit_transport_load().

◆ can_unit_paradrop()

bool can_unit_paradrop ( const struct unit punit)

Return whether the unit can be paradropped - that is, if the unit is in a friendly city or on an airbase special, has enough movepoints left, and has not paradropped yet this turn.

Definition at line 772 of file unit.cpp.

Referenced by dai_manage_paratrooper(), mr_menu::menus_sensitive(), request_unit_paradrop(), mr_menu::slot_clean_pollution(), and unit_actions::update_actions().

◆ can_unit_unload()

bool can_unit_unload ( const struct unit pcargo,
const struct unit ptrans 
)

Return TRUE iff the given unit can be unloaded from its current transporter.

This function checks everything except the legality of the position after the unloading. The caller may also want to call can_unit_exist_at_tile() to check this, unless the unit is unloading and moving at the same time.

Definition at line 720 of file unit.cpp.

Referenced by request_unit_unload(), unit_can_load(), units_can_unload(), unit_actions::update_actions(), and wipe_unit_full().

◆ cargo_iter_get()

static void* cargo_iter_get ( const struct iterator it)
static

Get the unit of the cargo iterator.

Definition at line 2324 of file unit.cpp.

Referenced by cargo_iter_init().

◆ cargo_iter_init()

struct iterator* cargo_iter_init ( struct cargo_iter iter,
const struct unit ptrans 
)

Initialize the cargo iterator.

Definition at line 2372 of file unit.cpp.

Referenced by unit_cargo_depth().

◆ cargo_iter_next()

static void cargo_iter_next ( struct iterator it)
static

Try to find next unit for the cargo iterator.

Definition at line 2334 of file unit.cpp.

Referenced by cargo_iter_init().

◆ cargo_iter_sizeof()

size_t cargo_iter_sizeof ( )

Returns the size of the unit cargo iterator.

Definition at line 2319 of file unit.cpp.

◆ cargo_iter_valid()

static bool cargo_iter_valid ( const struct iterator it)
static

Return whether the iterator is still valid.

Definition at line 2364 of file unit.cpp.

Referenced by cargo_iter_init().

◆ could_unit_load()

bool could_unit_load ( const struct unit pcargo,
const struct unit ptrans 
)

Return TRUE iff the given unit could be loaded into the transporter if we moved there.

Definition at line 646 of file unit.cpp.

Referenced by can_unit_load(), request_unit_load(), transporter_for_unit_at(), unit_can_load(), and unit_could_load_at().

◆ free_unit_orders()

◆ get_activity_rate()

int get_activity_rate ( const struct unit punit)

Returns the speed of a unit doing an activity.

This depends on the veteran level and the base move_rate of the unit (regardless of HP or effects). Usually this is just used for settlers but the value is also used for military units doing fortify/pillage activities.

The speed is multiplied by ACTIVITY_FACTOR.

Definition at line 443 of file unit.cpp.

Referenced by calc_activity(), get_activity_rate_this_turn(), and get_turns_for_activity_at().

◆ get_activity_rate_this_turn()

int get_activity_rate_this_turn ( const struct unit punit)

Returns the amount of work a unit does (will do) on an activity this turn.

Units that have no MP do no work.

The speed is multiplied by ACTIVITY_FACTOR.

Definition at line 470 of file unit.cpp.

Referenced by calc_activity(), converting_fuel_rescue(), and update_unit_activity().

◆ get_activity_text()

const char* get_activity_text ( enum unit_activity  activity)

Return the name of the activity in a static buffer.

Definition at line 586 of file unit.cpp.

Referenced by concat_tile_activity_text(), contemplate_terrain_improvements(), settler_evaluate_improvements(), unit_activity_astr(), and unit_log_prefix().

◆ get_transporter_capacity()

int get_transporter_capacity ( const struct unit punit)

◆ get_transporter_occupancy()

◆ get_turns_for_activity_at()

int get_turns_for_activity_at ( const struct unit punit,
enum unit_activity  activity,
const struct tile ptile,
struct extra_type tgt 
)

Return the estimated number of turns for the worker unit to start and complete the activity at the given location.

This assumes no other worker units are helping out, and doesn't take account of any work already done by this unit.

Definition at line 486 of file unit.cpp.

Referenced by settler_evaluate_improvements().

◆ get_unit_tile_pillage_set()

bv_extras get_unit_tile_pillage_set ( const struct tile ptile)

Return a mask of the extras which are actively (currently) being pillaged on the given tile.

Definition at line 1063 of file unit.cpp.

◆ is_allied_unit_tile()

struct unit* is_allied_unit_tile ( const struct tile ptile,
const struct player pplayer 
)

Returns true if the tile contains an allied unit and only allied units.

(ie, if your nation A is allied with B, and B is allied with C, a tile containing units from B and C will return false)

Definition at line 1211 of file unit.cpp.

Referenced by can_step_taken_wrt_to_zoc(), kill_unit(), and freeciv::refuel_destination::reached().

◆ is_attack_unit()

bool is_attack_unit ( const struct unit punit)

Is the unit capable of attacking?

Definition at line 288 of file unit.cpp.

Referenced by unit_being_aggressive().

◆ is_build_activity()

bool is_build_activity ( enum unit_activity  activity,
const struct tile ptile 
)

Returns true if given activity is some kind of building.

Definition at line 1434 of file unit.cpp.

Referenced by calc_activity(), can_unit_do_activity_targeted_at(), concat_tile_activity_text(), and is_tile_activity().

◆ is_clean_activity()

bool is_clean_activity ( enum unit_activity  activity)

Returns true if given activity is some kind of cleaning.

Definition at line 1450 of file unit.cpp.

Referenced by calc_activity(), concat_tile_activity_text(), and is_tile_activity().

◆ is_enemy_unit_tile()

struct unit* is_enemy_unit_tile ( const struct tile ptile,
const struct player pplayer 
)

Is there an enemy unit on this tile? Returns the unit or nullptr if none.

This function is likely to fail if used at the client because the client doesn't see all units. (Maybe it should be moved into the server code.)

Definition at line 1235 of file unit.cpp.

Referenced by adv_unit_move(), dai_unit_move(), find_something_to_bomb(), handle_edit_city_create(), and unit_can_be_retired().

◆ is_field_unit()

bool is_field_unit ( const struct unit punit)

This checks the "field unit" flag on the unit.

Field units cause unhappiness (under certain governments) even when they aren't abroad.

Definition at line 355 of file unit.cpp.

Referenced by city_unit_unhappiness(), and resolve_city_emergency().

◆ is_hiding_unit()

bool is_hiding_unit ( const struct unit punit)

Is the unit one that is invisible on the map.

A unit is invisible if it has the UTYF_PARTIAL_INVIS flag or if it transported by a unit with this flag.

FIXME: Should the transports recurse all the way?

Definition at line 367 of file unit.cpp.

Referenced by can_player_see_unit_at().

◆ is_losing_hp()

bool is_losing_hp ( const struct unit punit)

Does unit lose hitpoints each turn?

Definition at line 1992 of file unit.cpp.

Referenced by can_unit_do_activity_targeted_at(), can_unit_survive_at_tile(), dai_fill_unit_param(), and dai_manage_unit().

◆ is_military_unit()

bool is_military_unit ( const struct unit punit)

Military units are capable of enforcing martial law.

Military ground and heli units can occupy empty cities – see unit_can_take_over(punit). Some military units, like the Galleon, have no attack strength.

Definition at line 300 of file unit.cpp.

Referenced by adv_settler_safe_tile(), base_assess_defense_unit(), calc_civ_score(), city_support(), dai_manage_unit(), get_munits(), has_defense(), kill_something_with(), notify_illegal_armistice_units(), quickselect(), remove_illegal_armistice_units(), text_happiness_units(), and unit_occupies_tile().

◆ is_my_zoc()

bool is_my_zoc ( const struct player pplayer,
const struct tile ptile0,
const struct civ_map zmap 
)

Is this square controlled by the pplayer?

Here "is_my_zoc" means essentially a square which is not adjacent to an enemy unit (that has a ZOC) on a terrain that has zoc rules.

Since this function is also used in the client, it has to deal with some client-specific features, like FoW and the fact that the client cannot see units inside enemy cities.

Definition at line 1341 of file unit.cpp.

Referenced by can_step_taken_wrt_to_zoc(), pft_fill_attack_param(), pft_fill_overlap_param(), pft_fill_parameter(), and stack_risk().

◆ is_non_allied_unit_tile()

◆ is_non_attack_unit_tile()

struct unit* is_non_attack_unit_tile ( const struct tile ptile,
const struct player pplayer 
)

Is there an unit we have peace or ceasefire with on this tile?

Definition at line 1286 of file unit.cpp.

◆ is_other_players_unit_tile()

struct unit* is_other_players_unit_tile ( const struct tile ptile,
const struct player pplayer 
)

Is there an unit belonging to another player on this tile?

Definition at line 1269 of file unit.cpp.

Referenced by dai_diplomat_bribe_nearby().

◆ is_real_activity()

static bool is_real_activity ( enum unit_activity  activity)
static

Return if given activity really is in game.

For savegame compatibility activity enum cannot be reordered and there is holes in it.

Definition at line 573 of file unit.cpp.

Referenced by setup_real_activities_array().

◆ is_square_threatened()

bool is_square_threatened ( const struct player pplayer,
const struct tile ptile,
bool  omniscient 
)

Return TRUE iff this tile is threatened from any unit within 2 tiles.

Definition at line 327 of file unit.cpp.

Referenced by adv_settler_safe_tile().

◆ is_terrain_change_activity()

bool is_terrain_change_activity ( enum unit_activity  activity)

Returns true if given activity changes terrain.

Definition at line 1465 of file unit.cpp.

Referenced by is_tile_activity().

◆ is_tile_activity()

bool is_tile_activity ( enum unit_activity  activity)

Returns true if given activity affects tile.

Definition at line 1480 of file unit.cpp.

Referenced by concat_tile_activity_text().

◆ is_unit_activity_on_tile()

bool is_unit_activity_on_tile ( enum unit_activity  activity,
const struct tile ptile 
)

Return whether any units on the tile are doing this activity.

Definition at line 1046 of file unit.cpp.

Referenced by units_have_activity_on_tile().

◆ kills_citizen_after_attack()

bool kills_citizen_after_attack ( const struct unit punit)

Return TRUE iff an attack from this unit would kill a citizen in a city (city walls protect against this).

Definition at line 389 of file unit.cpp.

Referenced by unit_attack_civilian_casualties().

◆ set_unit_activity()

◆ set_unit_activity_internal()

static void set_unit_activity_internal ( struct unit punit,
enum unit_activity  new_activity 
)
static

Assign a new task to a unit.

Doesn't account for changed_from.

Definition at line 993 of file unit.cpp.

Referenced by set_unit_activity(), and set_unit_activity_targeted().

◆ set_unit_activity_targeted()

void set_unit_activity_targeted ( struct unit punit,
enum unit_activity  new_activity,
struct extra_type new_target 
)

assign a new targeted task to a unit.

Definition at line 1028 of file unit.cpp.

Referenced by set_unit_activity_base(), set_unit_activity_road(), sg_load_player_unit(), and unit_activity_targeted_internal().

◆ setup_real_activities_array()

void setup_real_activities_array ( )

Setup array of real activities.

Definition at line 556 of file unit.cpp.

Referenced by fc_interface_init().

◆ test_unit_can_airlift_to()

enum unit_airlift_result test_unit_can_airlift_to ( const struct player restriction,
const struct unit punit,
const struct city pdest_city 
)

Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now.

If pdest_city is nullptr, just indicate whether it's possible for the unit to be airlifted at all from its current position. The 'restriction' parameter specifies which player's knowledge this is based on – one player can't see whether another's cities are currently able to airlift. (Clients other than global observers should only call this with a non-nullptr 'restriction'.)

Definition at line 54 of file unit.cpp.

Referenced by action_not_enabled_reason(), and get_airlift_text().

◆ transporter_for_unit()

struct unit* transporter_for_unit ( const struct unit pcargo)

Find the best transporter at the given location for the unit.

See also unit_can_load() to test if there will be transport might be suitable for 'pcargo'.

Definition at line 1779 of file unit.cpp.

Referenced by api_find_transport_unit(), freeciv::path_finder::path_finder_private::attempt_load(), player_restore_units(), request_unit_load(), try_to_save_unit(), and unit_move().

◆ transporter_for_unit_at()

struct unit* transporter_for_unit_at ( const struct unit pcargo,
const struct tile ptile 
)

Find the best transporter at the given location for the unit.

See also unit_could_load_at() to test if there will be transport might be suitable for 'pcargo'.

Definition at line 1789 of file unit.cpp.

Referenced by adv_unit_move(), freeciv::path_finder::path_finder_private::attempt_unload(), dai_unit_attack(), dai_unit_move(), remove_city(), and request_transport().

◆ unit_activity_astr()

void unit_activity_astr ( const struct unit punit,
QString &  s 
)

Append text describing the unit's current activity to the given astring.

Definition at line 1096 of file unit.cpp.

Referenced by unit_activity_text(), and unit_description().

◆ unit_activity_text()

const QString unit_activity_text ( const struct unit punit)

Return text describing the unit's current activity as a static string.

FIXME: Convert all callers of this function to unit_activity_astr() because this function is not re-entrant.

Definition at line 1085 of file unit.cpp.

Referenced by units_select::paint().

◆ unit_ai_data()

void* unit_ai_data ( const struct unit punit,
const struct ai_type ai 
)

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

Definition at line 2039 of file unit.cpp.

Referenced by def_ai_unit_data().

◆ unit_being_aggressive()

bool unit_being_aggressive ( const struct unit punit)

An "aggressive" unit is a unit which may cause unhappiness under a Republic or Democracy.

A unit is not aggressive if one or more of following is true:

  • zero attack strength
  • inside a city
  • ground unit inside a fortress within 3 squares of a friendly city

Definition at line 1399 of file unit.cpp.

Referenced by city_unit_unhappiness(), and resolve_city_emergency().

◆ unit_bribe_cost()

int unit_bribe_cost ( struct unit punit,
struct player briber 
)

Calculate how expensive it is to bribe the unit.

The cost depends on the distance to the capital, the owner's treasury, and the build cost of the unit. For a damaged unit the price is reduced. For a veteran unit, it is increased.

The bribe cost for settlers are halved.

Definition at line 2061 of file unit.cpp.

Referenced by dai_diplomat_bribe_nearby(), diplomat_bribe(), handle_unit_action_query(), and popup_info_text().

◆ unit_can_add_or_build_city()

bool unit_can_add_or_build_city ( const struct unit punit)

Return TRUE iff this unit can add to a current city or build a new city at its current location.

Definition at line 399 of file unit.cpp.

Referenced by mr_menu::menus_sensitive(), mr_menu::slot_build_city(), and unit_actions::update_actions().

◆ unit_can_airlift_to()

bool unit_can_airlift_to ( const struct unit punit,
const struct city pdest_city 
)

Determines if punit can be airlifted to dest_city now! So punit needs to be in a city now.

On the server this gives correct information; on the client it errs on the side of saying airlifting is possible even if it's not certain given player knowledge.

Definition at line 179 of file unit.cpp.

Referenced by goto_dialog::airlift_to(), dai_airlift(), and goto_dialog::item_selected().

◆ unit_can_convert()

bool unit_can_convert ( const struct unit punit)

Tests if unit can be converted to another type.

Definition at line 1877 of file unit.cpp.

Referenced by converting_fuel_rescue(), unit_convert(), and units_can_convert().

◆ unit_can_do_action()

◆ unit_can_do_action_result()

bool unit_can_do_action_result ( const struct unit punit,
enum action_result  result 
)

Return TRUE iff this unit can do any enabler controlled action with the specified action result.

Definition at line 318 of file unit.cpp.

Referenced by dai_diplomat_bribe_nearby(), and is_attack_unit().

◆ unit_can_est_trade_route_here()

bool unit_can_est_trade_route_here ( const struct unit punit)

Return TRUE iff this unit can be disbanded at its current location to provide a trade route from the homecity to the target city.

Definition at line 267 of file unit.cpp.

Referenced by mr_menu::menus_sensitive(), and mr_menu::slot_build_road().

◆ unit_can_help_build_wonder_here()

bool unit_can_help_build_wonder_here ( const struct unit punit)

Return TRUE unless it is known to be imposible to disband this unit at its current position to get full shields for building a wonder.

Definition at line 243 of file unit.cpp.

Referenced by mr_menu::menus_sensitive().

◆ unit_cargo_depth()

int unit_cargo_depth ( const struct unit ptrans)

Returns the number of unit cargo layers within transport 'ptrans'.

Definition at line 2289 of file unit.cpp.

Referenced by could_unit_load(), and pft_fill_unit_default_parameter().

◆ unit_contained_in()

bool unit_contained_in ( const struct unit pcargo,
const struct unit ptrans 
)

Returns whether 'pcargo' is transported by 'ptrans', either directly or indirectly.

Definition at line 2274 of file unit.cpp.

Referenced by mr_menu::find_last_unit_pos(), and unit_move_handling().

◆ unit_has_orders()

◆ unit_is_alive()

bool unit_is_alive ( int  id)

Check if unit with given id is still alive.

Use this before using old unit pointers when unit might have died.

Definition at line 2014 of file unit.cpp.

Referenced by action_auto_perf_unit_do(), action_success_actor_consume(), action_success_pay_mp(), action_success_target_pay_mp(), city_create_unit(), diplomat_bribe(), spy_attack(), unit_do_disband_trad(), unit_enter_hut(), unit_move(), unit_move_consequences(), and upkeep_kill_unit().

◆ unit_is_cityfounder()

bool unit_is_cityfounder ( const struct unit punit)

◆ unit_is_virtual()

bool unit_is_virtual ( const struct unit punit)

Return TRUE if this is a valid unit pointer but does not correspond to any unit that exists in the game.

NB: A return value of FALSE implies that either the pointer is nullptr or that the unit exists in the game.

Definition at line 2027 of file unit.cpp.

Referenced by tile_virtual_destroy().

◆ unit_nationality()

struct player* unit_nationality ( const struct unit punit)

Return the nationality of the unit.

Definition at line 1190 of file unit.cpp.

Referenced by city_add_unit(), city_build(), do_heal_unit(), package_unit(), popup_info_text(), sg_save_player_units(), and unit_description().

◆ unit_occupies_tile()

struct unit* unit_occupies_tile ( const struct tile ptile,
const struct player pplayer 
)

Is there an occupying unit on this tile?

Intended for both client and server; assumes that hiding units are not sent to client. First check tile for known and seen.

called by city_can_work_tile().

Definition at line 1308 of file unit.cpp.

Referenced by base_city_can_work_tile().

◆ unit_pays_mp_for_action()

int unit_pays_mp_for_action ( const struct action paction,
const struct unit punit 
)

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

Definition at line 1973 of file unit.cpp.

Referenced by action_success_pay_mp(), adv_unit_move(), freeciv::detail::vertex::child_for_action(), dai_action_value_unit_vs_city(), and dai_unit_move().

◆ unit_set_ai_data()

void unit_set_ai_data ( struct unit punit,
const struct ai_type ai,
void *  data 
)

Attach ai data to unit.

Definition at line 2047 of file unit.cpp.

Referenced by dai_unit_close(), and dai_unit_init().

◆ unit_shield_value()

int unit_shield_value ( const struct unit punit,
const struct unit_type punittype,
const struct action paction 
)

Returns how many shields the unit (type) is worth.

Parameters
punitthe unit. Can be nullptr if punittype is set.
punittypethe unit's type. Can be nullptr iff punit is set.
pactionthe action the unit does when valued.
Returns
the unit's value in shields.

Definition at line 204 of file unit.cpp.

Referenced by city_gold_worth(), unit_do_help_build(), and unit_upgrade_price().

◆ unit_tile_set()

◆ unit_transport_cargo()

struct unit_list* unit_transport_cargo ( const struct unit ptrans)

◆ unit_transport_check()

bool unit_transport_check ( const struct unit pcargo,
const struct unit ptrans 
)

Returns whether 'pcargo' in 'ptrans' is a valid transport.

Note that 'pcargo' can already be (but doesn't need) loaded into 'ptrans'.

It may fail if one of the cargo unit has the same type of one of the transporter unit or if one of the cargo unit can transport one of the transporters.

Definition at line 2227 of file unit.cpp.

Referenced by could_unit_load().

◆ unit_transport_check_one()

static bool unit_transport_check_one ( const struct unit_type cargo_utype,
const struct unit_type trans_utype 
)
inlinestatic

Helper for unit_transport_check().

Definition at line 2211 of file unit.cpp.

Referenced by unit_transport_check().

◆ unit_transport_depth()

int unit_transport_depth ( const struct unit pcargo)

Returns the number of unit transport layers which carry unit 'pcargo'.

Definition at line 2307 of file unit.cpp.

Referenced by amphibious_move_scope(), base_transporter_for_unit(), and could_unit_load().

◆ unit_transport_get()

◆ unit_transport_load()

bool unit_transport_load ( struct unit pcargo,
struct unit ptrans,
bool  force 
)

Load pcargo onto ptrans.

Returns TRUE on success.

Definition at line 2123 of file unit.cpp.

Referenced by dai_military_attack_barbarian(), handle_unit_packet_common(), sg_load_player_units_transport(), unit_transport_load_send(), and unit_transport_load_tp_status().

◆ unit_transport_unload()

bool unit_transport_unload ( struct unit pcargo)

◆ unit_transported()

◆ unit_type_is_losing_hp()

bool unit_type_is_losing_hp ( const struct player pplayer,
const struct unit_type punittype 
)

Does unit lose hitpoints each turn?

Definition at line 2003 of file unit.cpp.

Referenced by dai_choose_attacker_air().

◆ unit_type_really_ignores_zoc()

bool unit_type_really_ignores_zoc ( const struct unit_type punittype)

Takes into account unit class flag UCF_ZOC as well as IGZOC.

Definition at line 1385 of file unit.cpp.

Referenced by can_step_taken_wrt_to_zoc(), pft_fill_attack_param(), pft_fill_overlap_param(), and pft_fill_parameter().

◆ unit_upgrade_info()

enum unit_upgrade_result unit_upgrade_info ( const struct unit punit,
char *  buf,
size_t  bufsz 
)

Find the result of trying to upgrade the unit, and a message that most callers can use directly.

Definition at line 1877 of file unit.cpp.

Referenced by get_units_upgrade_info().

◆ unit_upgrade_test()

enum unit_upgrade_result unit_upgrade_test ( const struct unit punit,
bool  is_free 
)

Tests if the unit could be updated.

Returns UU_OK if is this is possible.

is_free should be set if the unit upgrade is "free" (e.g., Leonardo's). Otherwise money is needed and the unit must be in an owned city.

Note that this function is strongly tied to unittools.c:upgrade_unit().

Definition at line 1799 of file unit.cpp.

Referenced by action_not_enabled_reason(), do_upgrade_effects(), get_units_upgrade_info(), handle_unit_type_upgrade(), units_can_upgrade(), and unit_actions::update_actions().

◆ unit_upkeep_astr()

void unit_upkeep_astr ( const struct unit punit,
QString &  s 
)

Append a line of text describing the unit's upkeep to the astring.

NB: In the client it is assumed that this information is only available for units owned by the client's player; the caller must check this.

Definition at line 1174 of file unit.cpp.

Referenced by unit_description().

◆ unit_virtual_create()

◆ unit_virtual_destroy()

Variable Documentation

◆ real_activities

Activity_type_id real_activities[ACTIVITY_LAST]

Definition at line 36 of file unit.cpp.

Referenced by setup_real_activities_array().

◆ tile_changing_activities

const Activity_type_id tile_changing_activities[]
Initial value:
= {
ACTIVITY_PILLAGE, ACTIVITY_GEN_ROAD, ACTIVITY_IRRIGATE,
ACTIVITY_MINE, ACTIVITY_BASE, ACTIVITY_CULTIVATE,
ACTIVITY_PLANT, ACTIVITY_TRANSFORM, ACTIVITY_POLLUTION,
ACTIVITY_FALLOUT, ACTIVITY_LAST}

Definition at line 38 of file unit.cpp.