Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/movement.c File Reference

Freeciv-3.2

Loading...
Searching...
No Matches
Functions | Variables
movement.c File Reference
`#include "bitvector.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "astring.h"`
`#include "base.h"`
`#include "effects.h"`
`#include "fc_types.h"`
`#include "game.h"`
`#include "map.h"`
`#include "road.h"`
`#include "unit.h"`
`#include "unitlist.h"`
`#include "unittype.h"`
`#include "terrain.h"`
`#include "movement.h"`

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)
int | unit_move_rate (const struct unit *punit)
int | utype_unknown_move_cost (const struct unit_type *utype)
bool | unit_can_defend_here (const struct civ_map *nmap, const struct unit *punit)
bool | can_attack_non_native_hard_reqs (const struct unit_type *utype)
bool | can_attack_non_native (const struct unit_type *utype)
bool | can_attack_from_non_native (const struct unit_type *utype)
bool | is_city_channel_tile (const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
bool | can_exist_at_tile (const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
bool | can_unit_exist_at_tile (const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
bool | is_native_tile (const struct unit_type *punittype, const struct tile *ptile)
bool | is_native_to_class (const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
bool | is_native_move (const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *src_tile, const struct tile *dst_tile)
bool | is_native_near_tile (const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
bool | can_unit_survive_at_tile (const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
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)
bool | unit_can_move_to_tile (const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool igzoc, bool enter_transport, bool enter_enemy_city)
bool | unit_can_teleport_to_tile (const struct civ_map *nmap, const struct unit *punit, const struct tile *dst_tile, bool enter_transport, bool enter_enemy_city)
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, bool enter_transport, struct unit *embark_to, bool enter_enemy_city)
enum unit_move_result | unit_teleport_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 enter_transport, struct unit *embark_to, bool enter_enemy_city)
bool | can_unit_transport (const struct unit *transporter, const struct unit *transported)
bool | can_unit_type_transport (const struct unit_type *transporter, const struct unit_class *transported)
bool | unit_can_load (const struct unit *punit)
bool | unit_could_load_at (const struct unit *punit, const struct tile *ptile)
void | init_move_fragments (void)
const char * | move_points_text_full (int mp, bool reduce, const char *prefix, const char *none, bool align)
const char * | move_points_text (int mp, bool reduce)

## Variables

static int | move_points_denomlen = 0

## 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 harbor cities)

Definition at line 227 of file movement.c.

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 214 of file movement.c.

Referenced by action_prob_vs_stack_full(), 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_attack_non_native_hard_reqs()

bool can_attack_non_native_hard_reqs | ( | const struct unit_type * | utype | ) |

Returns TRUE iff a unit of this type can attack non-native tiles (eg. Ships ability to shore bombardment) given that it can perform an attack action.

Definition at line 204 of file movement.c.

Referenced by can_attack_non_native(), unit_attack_unit_at_tile_result(), and unit_wipe_units_at_tile_result().

## ◆ 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 290 of file movement.c.

Referenced by api_edit_create_unit_full(), api_methods_unit_type_can_exist_at_tile(), can_unit_exist_at_tile(), fill_parameter_part(), get_modified_firepower(), get_virtual_defense_power(), handle_edit_unit_create(), kill_unit(), place_animal(), unit_move_to_tile_test(), unit_teleport_to_tile_test(), and unit_transform_result().

## ◆ 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 542 of file movement.c.

Referenced by unit_move_to_tile_test().

## ◆ can_unit_exist_at_tile()

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 319 of file movement.c.

Referenced by actres_possible(), api_edit_unit_teleport(), can_create_unit_at_tile(), can_unit_survive_at_tile(), check_units_single_tile(), city_can_be_built_here(), create_unit_menu(), dai_military_attack_barbarian(), do_paradrop(), expl_act_not_enabl(), explain_why_no_action_enabled(), illegal_action_msg(), is_action_possible(), is_unitstate_req_active(), place_unit(), present_unit_callback(), request_move_unit_direction(), sg_load_sanitycheck(), sg_load_sanitycheck(), terrain_change_bounce_single_unit(), test_unit_can_airlift_to(), throw_units_from_illegal_cities(), transfer_unit(), unit_can_defend_here(), unit_move(), units_can_unload(), unit_actions::update_actions(), wakeup_neighbor_sentries(), and wipe_unit_full().

## ◆ 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 491 of file movement.c.

Referenced by adv_unit_move(), bounce_unit(), can_unit_do_activity_targeted_at(), dai_manage_barbarian_leader(), dai_unit_attack(), dai_unit_move(), remove_city(), request_unit_unload(), resolve_stack_conflicts(), unit_move(), and unit_move_handling().

## ◆ 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 855 of file movement.c.

Referenced by could_unit_be_in_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
| ) |  |

Return TRUE iff transporter type has ability to transport transported class.

Definition at line 868 of file movement.c.

Referenced by action_actor_utype_hard_reqs_ok_full(), adv_data_phase_init(), can_type_transport_units_cargo(), can_unit_transport(), dai_hunter_missile_want(), dai_units_ruleset_init(), helptext_unit(), pf_transport_check(), rs_barbarian_units(), try_summon_barbarians(), unit_transform_result(), and unit_transport_check_one().

## ◆ init_move_fragments()

void init_move_fragments | ( | void |  | ) |

Call whenever terrain_control.move_fragments / SINGLE_MOVE changes.

Definition at line 927 of file movement.c.

Referenced by handle_ruleset_terrain_control(), and load_ruleset_terrain().

## ◆ is_city_channel_tile()

bool is_city_channel_tile | ( | const struct civ_map * | nmap,
|  | const struct unit_class * | punitclass,
|  | const struct tile * | ptile,
|  | const struct tile * | pexclude
| ) |  |

Check for a city channel.

Definition at line 243 of file movement.c.

Referenced by can_exist_at_tile(), pf_get_move_scope(), and remove_city().

## ◆ is_native_move()

bool is_native_move | ( | const struct civ_map * | nmap,
|  | 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 373 of file movement.c.

Referenced by pf_move_possible(), and unit_move_to_tile_test().

## ◆ is_native_near_tile()

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 465 of file movement.c.

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(), pf_get_move_scope(), and process_attacker_want().

## ◆ is_native_tile()

bool is_native_tile | ( | const struct unit_type * | punittype,
|  | const struct tile * | ptile
| ) |  |

This tile is native to unit.

See is_native_to_class()

Definition at line 331 of file movement.c.

Referenced by action_prob_vs_stack_full(), amphibious_behaviour(), amphibious_extra_cost(), amphibious_is_pos_dangerous(), assess_danger_unit(), can_exist_at_tile(), check_native_area(), dai_rampage_want(), expl_act_not_enabl(), fill_grid_sprite_array(), find_a_good_partisan_spot(), find_beachhead(), find_something_to_kill(), get_modified_firepower(), is_square_threatened(), is_unitstate_req_active(), is_valid_start_pos(), pf_attack_possible(), place_starting_unit(), remove_city(), try_summon_barbarians(), unit_attack_unit_at_tile_result(), unit_wipe_units_at_tile_result(), and unleash_barbarians().

## ◆ 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 342 of file movement.c.

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().

## ◆ move_points_text()

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 1015 of file movement.c.

Referenced by units_select::create_pixmap(), create_present_supported_units_widget_list(), get_tooltip_unit(), help_update_unit_type(), helptext_extra(), helptext_unit(), illegal_action_pay_price(), manual_units(), popup_advanced_terrain_dialog(), popup_terrain_info(), popup_unit_info(), popup_worklist_editor(), redraw_unit_info_label(), req_text_insert(), help_widget::set_topic_unit(), hud_unit_loader::show_me(), unit_activity_astr(), unit_select_dialog_popup(), universal_name_translation(), hud_units::update_actions(), and utype_values_string().

## ◆ 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 NULL 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 948 of file movement.c.

Referenced by insert_veteran_help(), and move_points_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 174 of file movement.c.

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 883 of file movement.c.

Referenced by create_unit_menu(), present_unit_callback(), 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_transport,
|  | bool | enter_enemy_city
| ) |  |

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

See unit_move_to_tile_test().

Definition at line 572 of file movement.c.

Referenced by actres_possible(), unit_move_handling(), and unleash_barbarians().

## ◆ unit_can_teleport_to_tile()

bool unit_can_teleport_to_tile | ( | const struct civ_map * | nmap,
|  | const struct unit * | punit,
|  | const struct tile * | dst_tile,
|  | bool | enter_transport,
|  | bool | enter_enemy_city
| ) |  |

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

See unit_teleport_to_tile_test().

Definition at line 592 of file movement.c.

Referenced by actres_possible().

## ◆ 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 911 of file movement.c.

Referenced by do_paradrop(), expl_act_not_enabl(), is_action_possible(), is_refuel_point(), unit_move_to_tile_test(), and unit_teleport_to_tile_test().

## ◆ unit_move_rate()

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 90 of file movement.c.

Referenced by action_mp_full_makes_legal(), adv_unit_execute_path(), adv_unit_move(), base_transporter_for_unit(), calculate_city_clusters(), 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(), occupy_move(), pf_reverse_map_unit_pos(), pft_fill_unit_default_parameter(), transform_unit(), unit_restore_movepoints(), unit_virtual_create(), and unit_virtual_prepare().

## ◆ 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,
|  | bool | enter_transport,
|  | 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) Unit is not a "random movement only" one, or this is random movement 4) The target location is next to the unit. 5) There are no non-allied units on the target tile. 6) Animals cannot move out from home terrains 7) Unit can move to a tile where it can't survive on its own if there is free transport capacity. 8) There are no peaceful but non-allied units on the target tile. 9) 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. 10) There is no non-allied unit blocking (zoc) [or igzoc is true]. 11) Triremes cannot move out of sight from land. 12) It is not the territory of a player we are at peace with, or it's terrain where borders don't count 13) The unit is unable to disembark from current transporter. 14) The unit is making a non-native move (e.g. lack of road)

Definition at line 630 of file movement.c.

Referenced by adv_could_unit_move_to_tile(), api_edit_unit_move(), can_unit_move_to_tile_with_notify(), expl_act_not_enabl(), and unit_can_move_to_tile().

## ◆ unit_teleport_to_tile_test()

enum unit_move_result unit_teleport_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 | enter_transport,
|  | struct unit * | embark_to,
|  | bool | enter_enemy_city
| ) |  |

Returns whether the unit can teleport from its current tile to the destination tile. An enumerated value is returned indication the error or success status.

The unit can teleport if: 1) There are no non-allied units on the target tile. 2) Animals cannot move out from home terrains 3) Unit can move to a tile where it can't survive on its own if there is free transport capacity. 4) There are no peaceful but non-allied units on the target tile. 5) 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. 6) Triremes cannot move out of sight from land. 7) It is not the territory of a player we are at peace with, or it's terrain where borders don't count

Definition at line 774 of file movement.c.

Referenced by api_edit_unit_teleport(), expl_act_not_enabl(), and unit_can_teleport_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 NULL.

Definition at line 47 of file movement.c.

Referenced by pf_reverse_map_utype_pos(), 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 105 of file movement.c.

Referenced by handle_rulesets_ready(), and load_rulesetdir().

## Variable Documentation

## ◆ move_points_denomlen

int move_points_denomlen = 0

static

Definition at line 922 of file movement.c.

Referenced by init_move_fragments(), and move_points_text_full().