![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
#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... | |
| 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().
| 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().
| 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().
| 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:
Definition at line 499 of file movement.cpp.
| 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.
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 267 of file movement.cpp.
Referenced by action_not_enabled_reason(), api_edit_unit_teleport(), freeciv::path_finder::path_finder_private::attempt_paradrop(), can_unit_survive_at_tile(), check_units_single_tile(), city_can_be_built_here(), create_unit_full(), dai_military_attack_barbarian(), diplomat_bribe(), do_paradrop(), explain_why_no_action_enabled(), illegal_action_msg(), request_move_unit_direction(), sg_load_sanitycheck(), throw_units_from_illegal_cities(), transfer_unit(), unit_can_defend_here(), unit_move(), unit_move_handling(), units_can_unload(), unit_actions::update_actions(), wakeup_neighbor_sentries(), and wipe_unit_full().
| 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().
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().
| 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.
Definition at line 698 of file movement.cpp.
Referenced by action_actor_utype_hard_reqs_ok_full(), adv_data_phase_init(), amphibious_move_scope(), can_type_transport_units_cargo(), can_unit_transport(), dai_hunter_missile_want(), dai_units_ruleset_init(), helptext_unit(), rs_barbarian_units(), try_summon_barbarians(), and unit_transport_check_one().
| 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().
| 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().
| 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().
| 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.
Definition at line 424 of file movement.cpp.
Referenced by assess_danger_unit(), can_city_build_unit_direct(), can_city_build_unit_later(), can_exist_at_tile(), find_closest_city(), is_square_threatened(), and process_attacker_want().
This tile is native to unit.
Definition at line 279 of file movement.cpp.
Referenced by action_not_enabled_reason(), amphibious_behaviour(), amphibious_is_pos_dangerous(), assess_danger_unit(), freeciv::path_finder::path_finder_private::attempt_paradrop(), can_exist_at_tile(), check_native_area(), dai_rampage_want(), freeciv::layer_grid::fill_sprite_array(), find_a_good_partisan_spot(), find_beachhead(), find_something_to_kill(), get_modified_firepower(), is_square_threatened(), is_valid_start_pos(), pf_attack_possible(), place_starting_unit(), remove_city(), try_summon_barbarians(), and unleash_barbarians().
| 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().
| 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().
| 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.
Definition at line 856 of file movement.cpp.
Referenced by units_select::create_pixmap(), get_tooltip_unit(), helptext_extra(), helptext_unit(), illegal_action_pay_price(), manual_command(), popup_terrain_info(), req_text_insert(), help_widget::set_topic_unit(), hud_unit_loader::show_me(), unit_activity_astr(), universal_name_translation(), hud_units::update_actions(), and utype_values_string().
| 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().
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().
| 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().
| 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.
Definition at line 531 of file movement.cpp.
Referenced by freeciv::path_finder::path_finder_private::attempt_action_move(), freeciv::path_finder::path_finder_private::attempt_move(), popup_action_selection(), unit_move_handling(), and unleash_barbarians().
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().
| int unit_move_rate | ( | const struct unit * | punit | ) |
This function calculates the move rate of the unit.
See utype_move_rate() for further details.
Definition at line 78 of file movement.cpp.
Referenced by action_mp_full_makes_legal(), adv_unit_move(), base_transporter_for_unit(), calculate_city_clusters(), create_unit_full(), dai_diplomat_bribe_nearby(), dai_hunter_manage(), dai_military_bodyguard(), dai_unit_move(), dai_wonder_city_distance(), do_attack(), execute_orders(), find_something_to_kill(), look_for_charge(), freeciv::path_finder::path_finder_private::maybe_insert_vertex(), occupy_move(), pf_reverse_map_unit_pos(), pft_fill_unit_default_parameter(), popup_info_text(), transform_unit(), unit_restore_movepoints(), and unit_virtual_create().
| 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().
| 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().
| 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().