Freeciv-3.2
Loading...
Searching...
No Matches
Macros | Enumerations | Functions
movement.h File Reference
#include "fc_types.h"
#include "map.h"

Go to the source code of this file.

Macros

#define SINGLE_MOVE   (terrain_control.move_fragments)
 
#define MOVE_COST_IGTER   (terrain_control.igter_cost)
 
#define MAX_MOVE_FRAGS   65535
 

Enumerations

enum  unit_move_result {
  MR_OK , MR_DEATH , MR_PAUSE , MR_NO_WAR ,
  MR_PEACE , MR_ZOC , MR_BAD_ACTIVITY , MR_BAD_DESTINATION ,
  MR_BAD_MAP_POSITION , MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_CITY , MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT , MR_NO_TRANSPORTER_CAPACITY ,
  MR_TRIREME , MR_CANNOT_DISEMBARK , MR_NON_NATIVE_MOVE , MR_ANIMAL_DISALLOWED ,
  MR_UNIT_STAY , MR_RANDOM_ONLY , MR_NOT_ALLOWED
}
 

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 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)
 
static bool is_native_tile_to_class (const struct unit_class *punitclass, const struct tile *ptile)
 
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_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 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 *ptile, 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 *ptile, 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 charmove_points_text_full (int mp, bool reduce, const char *prefix, const char *none, bool align)
 
const charmove_points_text (int mp, bool reduce)
 

Macro Definition Documentation

◆ MAX_MOVE_FRAGS

#define MAX_MOVE_FRAGS   65535

Definition at line 29 of file movement.h.

◆ MOVE_COST_IGTER

#define MOVE_COST_IGTER   (terrain_control.igter_cost)

Definition at line 27 of file movement.h.

◆ SINGLE_MOVE

#define SINGLE_MOVE   (terrain_control.move_fragments)

Definition at line 26 of file movement.h.

Enumeration Type Documentation

◆ unit_move_result

Enumerator
MR_OK 
MR_DEATH 
MR_PAUSE 
MR_NO_WAR 
MR_PEACE 
MR_ZOC 
MR_BAD_ACTIVITY 
MR_BAD_DESTINATION 
MR_BAD_MAP_POSITION 
MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_CITY 
MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT 
MR_NO_TRANSPORTER_CAPACITY 
MR_TRIREME 
MR_CANNOT_DISEMBARK 
MR_NON_NATIVE_MOVE 
MR_ANIMAL_DISALLOWED 
MR_UNIT_STAY 
MR_RANDOM_ONLY 
MR_NOT_ALLOWED 

Definition at line 34 of file movement.h.

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(), remove_city(), 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 
)

◆ 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 
)

◆ 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_native_tile()

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

◆ is_native_tile_to_class()

static bool is_native_tile_to_class ( const struct unit_class punitclass,
const struct tile ptile 
)
inlinestatic

◆ 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 
)

◆ 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)

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