Freeciv21
Develop your civilization from humble roots to a global empire
movement.cpp File Reference
#include <QBitArray>
#include "bitvector.h"
#include "log.h"
#include "shared.h"
#include "support.h"
#include "fc_types.h"
#include "game.h"
#include "map.h"
#include "road.h"
#include "terrain.h"
#include "unit.h"
#include "unitlist.h"
#include "unittype.h"
#include "movement.h"
+ Include dependency graph for movement.cpp:

Go to the source code of this file.

Functions

int utype_move_rate (const struct unit_type *utype, const struct tile *ptile, const struct player *pplayer, int veteran_level, int hitpoints)
 This function calculates the move rate of the unit, taking into account the penalty for reduced hitpoints, the active effects, and any veteran bonuses. More...
 
int unit_move_rate (const struct unit *punit)
 This function calculates the move rate of the unit. More...
 
int utype_unknown_move_cost (const struct unit_type *utype)
 This function calculates the movement cost to unknown tiles. More...
 
bool unit_can_defend_here (const struct civ_map *nmap, const struct unit *punit)
 Return TRUE iff the unit can be a defender at its current location. More...
 
bool can_attack_non_native (const struct unit_type *utype)
 This unit can attack non-native tiles (eg. More...
 
bool can_attack_from_non_native (const struct unit_type *utype)
 This unit can attack from non-native tiles (Marines can attack from transport, ships from harbour cities) More...
 
bool is_city_channel_tile (const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
 Check for a city channel. More...
 
bool can_exist_at_tile (const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
 Return TRUE iff a unit of the given unit type can "exist" at this location. More...
 
bool can_unit_exist_at_tile (const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
 Return TRUE iff the unit can "exist" at this location. More...
 
bool is_native_tile (const struct unit_type *punittype, const struct tile *ptile)
 This tile is native to unit. More...
 
bool is_native_to_class (const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
 This terrain is native to unit class. More...
 
bool is_native_move (const struct unit_class *punitclass, const struct tile *src_tile, const struct tile *dst_tile)
 Is the move under consideration a native move? Note that this function does not check for possible moves, only native moves, so that callers are responsible for checking for other sources of legal moves (e.g. More...
 
bool is_native_near_tile (const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
 Is there native tile adjacent to given tile. More...
 
bool can_unit_survive_at_tile (const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
 Return TRUE iff the unit can "survive" at this location. More...
 
bool can_step_taken_wrt_to_zoc (const struct unit_type *punittype, const struct player *unit_owner, const struct tile *src_tile, const struct tile *dst_tile, const struct civ_map *zmap)
 Returns whether the unit is allowed (by ZOC) to move from src_tile to dest_tile (assumed adjacent). More...
 
bool unit_can_move_to_tile (const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool igzoc, bool enter_enemy_city)
 Returns whether the unit can move from its current tile to the destination tile. More...
 
enum unit_move_result unit_move_to_tile_test (const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity, const struct tile *src_tile, const struct tile *dst_tile, bool igzoc, struct unit *embark_to, bool enter_enemy_city)
 Returns whether the unit can move from its current tile to the destination tile. More...
 
bool can_unit_transport (const struct unit *transporter, const struct unit *transported)
 Return true iff transporter has ability to transport transported. More...
 
bool can_unit_type_transport (const struct unit_type *transporter, const struct unit_class *transported)
 Return TRUE iff transporter type has ability to transport transported class. More...
 
bool unit_can_load (const struct unit *punit)
 Return whether we can find a suitable transporter for given unit at current location. More...
 
bool unit_could_load_at (const struct unit *punit, const struct tile *ptile)
 Return whether we could find a suitable transporter for given unit at 'ptile'. More...
 
bool is_unit_being_refueled (const struct unit *punit)
 Is unit being refueled in its current position. More...
 
void init_move_fragments ()
 Call whenever terrain_control.move_fragments / SINGLE_MOVE changes. More...
 
const char * move_points_text_full (int mp, bool reduce, const char *prefix, const char *none, bool align)
 Render positive movement points as text, including fractional movement points, scaled by SINGLE_MOVE. More...
 
const char * move_points_text (int mp, bool reduce)
 Simple version of move_points_text_full() – render positive movement points as text without any prefix or alignment. More...
 

Function Documentation

◆ can_attack_from_non_native()

bool can_attack_from_non_native ( const struct unit_type utype)

This unit can attack from non-native tiles (Marines can attack from transport, ships from harbour cities)

Definition at line 177 of file movement.cpp.

Referenced by assess_danger_unit(), dai_unit_attack_desirability(), find_beachhead(), and pf_action_possible().

◆ can_attack_non_native()

bool can_attack_non_native ( const struct unit_type utype)

This unit can attack non-native tiles (eg.

Ships ability to shore bombardment)

Definition at line 164 of file movement.cpp.

Referenced by assess_danger_unit(), dai_hunter_guess_best(), find_something_to_kill(), helptext_unit(), is_square_threatened(), pf_attack_possible(), and update_simple_ai_types().

◆ can_exist_at_tile()

bool can_exist_at_tile ( const struct civ_map nmap,
const struct unit_type utype,
const struct tile ptile 
)

Return TRUE iff a unit of the given unit type can "exist" at this location.

This means it can physically be present on the tile (without the use of a transporter). See also can_unit_survive_at_tile().

Definition at line 236 of file movement.cpp.

Referenced by api_edit_create_unit_full(), api_methods_unit_type_can_exist_at_tile(), can_unit_exist_at_tile(), get_modified_firepower(), get_virtual_defense_power(), handle_edit_unit_create(), kill_unit(), place_animal(), and unit_can_convert().

◆ can_step_taken_wrt_to_zoc()

bool can_step_taken_wrt_to_zoc ( const struct unit_type punittype,
const struct player unit_owner,
const struct tile src_tile,
const struct tile dst_tile,
const struct civ_map zmap 
)

Returns whether the unit is allowed (by ZOC) to move from src_tile to dest_tile (assumed adjacent).

You CAN move if:

  1. You have units there already
  2. Your unit isn't a ground unit
  3. Your unit ignores ZOC (diplomat, freight, etc.)
  4. You're moving from or to a city
  5. You're moving from an ocean square (from a boat)
  6. The spot you're moving from or to is in your ZOC

Definition at line 499 of file movement.cpp.

◆ can_unit_exist_at_tile()

◆ can_unit_survive_at_tile()

bool can_unit_survive_at_tile ( const struct civ_map nmap,
const struct unit punit,
const struct tile ptile 
)

Return TRUE iff the unit can "survive" at this location.

This means it can not only be physically present at the tile but will be able to survive indefinitely on its own (without a transporter). Units that require fuel or have a danger of drowning are examples of non-survivable units. See also can_unit_exist_at_tile().

(This function could be renamed as unit_wants_transporter().)

Definition at line 452 of file movement.cpp.

Referenced by adv_unit_move(), freeciv::path_finder::path_finder_private::attempt_unload(), can_unit_do_activity_targeted_at(), dai_manage_barbarian_leader(), dai_unit_attack(), dai_unit_move(), freeciv::refuel_destination::reached(), remove_city(), request_unit_unload(), resolve_stack_conflicts(), and unit_move().

◆ can_unit_transport()

bool can_unit_transport ( const struct unit transporter,
const struct unit transported 
)

Return true iff transporter has ability to transport transported.

Definition at line 684 of file movement.cpp.

Referenced by could_unit_load(), request_transport(), and hud_unit_loader::show_me().

◆ can_unit_type_transport()

bool can_unit_type_transport ( const struct unit_type transporter,
const struct unit_class transported 
)

◆ init_move_fragments()

void init_move_fragments ( )

Call whenever terrain_control.move_fragments / SINGLE_MOVE changes.

Definition at line 777 of file movement.cpp.

Referenced by handle_ruleset_terrain_control(), and load_ruleset_terrain().

◆ is_city_channel_tile()

bool is_city_channel_tile ( const struct unit_class punitclass,
const struct tile ptile,
const struct tile pexclude 
)

Check for a city channel.

Definition at line 192 of file movement.cpp.

Referenced by can_exist_at_tile(), and remove_city().

◆ is_native_move()

bool is_native_move ( const struct unit_class punitclass,
const struct tile src_tile,
const struct tile dst_tile 
)

Is the move under consideration a native move? Note that this function does not check for possible moves, only native moves, so that callers are responsible for checking for other sources of legal moves (e.g.

cities, transports, etc.).

Definition at line 322 of file movement.cpp.

Referenced by pf_move_possible().

◆ is_native_near_tile()

bool is_native_near_tile ( const struct civ_map nmap,
const struct unit_class uclass,
const struct tile ptile 
)

◆ is_native_tile()

◆ is_native_to_class()

bool is_native_to_class ( const struct unit_class punitclass,
const struct terrain pterrain,
const bv_extras *  extras 
)

This terrain is native to unit class.

Units that require fuel dont survive even on native terrain.

Definition at line 290 of file movement.cpp.

Referenced by adv_units_ruleset_init(), do_paradrop(), helptext_terrain(), is_city_channel_tile(), is_native_move(), is_native_tile(), is_native_tile_to_class(), sanity_check_ruleset_data(), set_unit_move_type(), and utype_unknown_move_cost().

◆ is_unit_being_refueled()

bool is_unit_being_refueled ( const struct unit punit)

Is unit being refueled in its current position.

Definition at line 759 of file movement.cpp.

Referenced by dai_manage_airunit(), freeciv::path_finder::path_finder_private::maybe_insert_vertex(), and player_restore_units().

◆ move_points_text()

const char* move_points_text ( int  mp,
bool  reduce 
)

◆ move_points_text_full()

const char* move_points_text_full ( int  mp,
bool  reduce,
const char *  prefix,
const char *  none,
bool  align 
)

Render positive movement points as text, including fractional movement points, scaled by SINGLE_MOVE.

Returns a pointer to a static buffer. 'reduce' is whether fractional movement points should be reduced to lowest terms (this might be confusing in some cases). 'prefix' is a string put in front of all numeric output. 'none' is the string to display in place of the integer part if no movement points (or nullptr to just say 0). 'align' controls whether this is for a fixed-width table, in which case padding spaces will be included to make all such strings line up when right-aligned.

Definition at line 797 of file movement.cpp.

Referenced by insert_veteran_help(), move_points_text(), and popup_info_text().

◆ unit_can_defend_here()

bool unit_can_defend_here ( const struct civ_map nmap,
const struct unit punit 
)

Return TRUE iff the unit can be a defender at its current location.

This should be checked when looking for a defender - not all units on the tile are valid defenders.

Definition at line 142 of file movement.cpp.

Referenced by get_defender().

◆ unit_can_load()

bool unit_can_load ( const struct unit punit)

Return whether we can find a suitable transporter for given unit at current location.

It needs to have free space. To find the best transporter, see transporter_for_unit().

Definition at line 713 of file movement.cpp.

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

◆ unit_can_move_to_tile()

bool unit_can_move_to_tile ( const struct civ_map nmap,
const struct unit punit,
const struct tile dst_tile,
bool  igzoc,
bool  enter_enemy_city 
)

◆ unit_could_load_at()

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

Return whether we could find a suitable transporter for given unit at 'ptile'.

It needs to have free space. To find the best transporter, see transporter_for_unit_at().

Definition at line 743 of file movement.cpp.

Referenced by action_not_enabled_reason(), freeciv::path_finder::path_finder_private::attempt_paradrop(), do_paradrop(), and is_airunit_refuel_point().

◆ unit_move_rate()

◆ unit_move_to_tile_test()

enum unit_move_result unit_move_to_tile_test ( const struct civ_map nmap,
const struct unit punit,
enum unit_activity  activity,
const struct tile src_tile,
const struct tile dst_tile,
bool  igzoc,
struct unit embark_to,
bool  enter_enemy_city 
)

Returns whether the unit can move from its current tile to the destination tile.

An enumerated value is returned indication the error or success status.

The unit can move if: 1) The unit is idle or on server goto. 2) Unit is not prohibited from moving by scenario 3) The target location is next to the unit. 4) There are no non-allied units on the target tile. 5) Animals cannot move out from home terrains 6) Unit can move to a tile where it can't survive on its own if there is free transport capacity. 7) There are no peaceful but non allied units on the target tile. 8) There is not a non allied city on the target tile when enter_enemy_city is false. When enter_enemy_city is true a non peaceful city is also accepted. 9) There is no non-allied unit blocking (zoc) [or igzoc is true]. 10) Triremes cannot move out of sight from land. 11) It is not the territory of a player we are at peace with. 12) The unit is unable to disembark from current transporter. 13) The unit is making a non-native move (e.g. lack of road)

Definition at line 531 of file movement.cpp.

Referenced by action_not_enabled_reason(), adv_could_unit_move_to_tile(), can_unit_move_to_tile_with_notify(), and unit_can_move_to_tile().

◆ utype_move_rate()

int utype_move_rate ( const struct unit_type utype,
const struct tile ptile,
const struct player pplayer,
int  veteran_level,
int  hitpoints 
)

This function calculates the move rate of the unit, taking into account the penalty for reduced hitpoints, the active effects, and any veteran bonuses.

'utype' and 'pplayer' must be set. 'ptile' can be nullptr.

Definition at line 38 of file movement.cpp.

Referenced by pft_fill_utype_default_parameter(), and unit_move_rate().

◆ utype_unknown_move_cost()

int utype_unknown_move_cost ( const struct unit_type utype)

This function calculates the movement cost to unknown tiles.

The base value is equal to the highest movement cost the unit can encounter. If the unit cannot enter all terrains, a malus is applied. The returned value is usually cached into utype->unknown_move_cost and used in the path-finding module.

Definition at line 93 of file movement.cpp.

Referenced by handle_rulesets_ready(), and load_rulesetdir().