Freeciv21
Develop your civilization from humble roots to a global empire
movement.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include "map.h"
16 
17 #define SINGLE_MOVE (terrain_control.move_fragments)
18 #define MOVE_COST_IGTER (terrain_control.igter_cost)
19 // packets.def MOVEFRAGS
20 #define MAX_MOVE_FRAGS 65535
21 
22 struct unit_type;
23 struct terrain;
24 
29  MR_NO_WAR, // Can't move here without declaring war.
30  MR_PEACE, // Can't move here because of a peace treaty.
39  MR_NON_NATIVE_MOVE, // Usually RMM_RELAXED road diagonally without link
43 };
44 
45 int utype_move_rate(const struct unit_type *utype, const struct tile *ptile,
46  const struct player *pplayer, int veteran_level,
47  int hitpoints);
48 int unit_move_rate(const struct unit *punit);
49 int utype_unknown_move_cost(const struct unit_type *utype);
50 
51 bool unit_can_defend_here(const struct civ_map *nmap,
52  const struct unit *punit);
53 bool can_attack_non_native(const struct unit_type *utype);
54 bool can_attack_from_non_native(const struct unit_type *utype);
55 
56 bool is_city_channel_tile(const struct unit_class *punitclass,
57  const struct tile *ptile,
58  const struct tile *pexclude);
59 
60 bool is_native_tile(const struct unit_type *punittype,
61  const struct tile *ptile);
62 
63 bool is_native_to_class(const struct unit_class *punitclass,
64  const struct terrain *pterrain,
65  const bv_extras *extras);
66 
67 /****************************************************************************
68  Check if this tile is native to given unit class.
69 
70  See is_native_to_class()
71 ****************************************************************************/
72 static inline bool
73 is_native_tile_to_class(const struct unit_class *punitclass,
74  const struct tile *ptile)
75 {
76  return is_native_to_class(punitclass, tile_terrain(ptile),
77  tile_extras(ptile));
78 }
79 
80 bool is_native_move(const struct unit_class *punitclass,
81  const struct tile *src_tile,
82  const struct tile *dst_tile);
83 bool is_native_near_tile(const struct civ_map *nmap,
84  const struct unit_class *uclass,
85  const struct tile *ptile);
86 bool can_exist_at_tile(const struct civ_map *nmap,
87  const struct unit_type *utype,
88  const struct tile *ptile);
89 bool can_unit_exist_at_tile(const struct civ_map *nmap,
90  const struct unit *punit,
91  const struct tile *ptile);
92 bool can_unit_survive_at_tile(const struct civ_map *nmap,
93  const struct unit *punit,
94  const struct tile *ptile);
95 bool can_step_taken_wrt_to_zoc(const struct unit_type *punittype,
96  const struct player *unit_owner,
97  const struct tile *src_tile,
98  const struct tile *dst_tile,
99  const struct civ_map *zmap);
100 bool unit_can_move_to_tile(const struct civ_map *nmap,
101  const struct unit *punit,
102  const struct tile *ptile, bool igzoc,
103  bool enter_enemy_city);
104 enum unit_move_result
105 unit_move_to_tile_test(const struct civ_map *nmap, const struct unit *punit,
106  enum unit_activity activity,
107  const struct tile *src_tile,
108  const struct tile *dst_tile, bool igzoc,
109  struct unit *embark_to, bool enter_enemy_city);
110 bool can_unit_transport(const struct unit *transporter,
111  const struct unit *transported);
112 bool can_unit_type_transport(const struct unit_type *transporter,
113  const struct unit_class *transported);
114 bool unit_can_load(const struct unit *punit);
115 bool unit_could_load_at(const struct unit *punit, const struct tile *ptile);
116 
117 bool is_unit_being_refueled(const struct unit *punit);
118 bool is_airunit_refuel_point(const struct tile *ptile,
119  const struct player *pplayer,
120  const struct unit *punit);
121 
122 void init_move_fragments();
123 const char *move_points_text_full(int mp, bool reduce, const char *prefix,
124  const char *none, bool align);
125 const char *move_points_text(int mp, bool reduce);
char * extras
Definition: comments.cpp:34
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.
Definition: movement.cpp:797
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.
Definition: movement.cpp:236
bool unit_can_move_to_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile, bool igzoc, bool enter_enemy_city)
Returns whether the unit can move from its current tile to the destination tile.
Definition: movement.cpp:531
bool is_city_channel_tile(const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
Check for a city channel.
Definition: movement.cpp:192
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.
Definition: movement.cpp:267
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
This tile is native to unit.
Definition: movement.cpp:279
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).
Definition: movement.cpp:499
int utype_unknown_move_cost(const struct unit_type *utype)
This function calculates the movement cost to unknown tiles.
Definition: movement.cpp:93
bool unit_can_load(const struct unit *punit)
Return whether we can find a suitable transporter for given unit at current location.
Definition: movement.cpp:713
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Return true iff transporter has ability to transport transported.
Definition: movement.cpp:684
int unit_move_rate(const struct unit *punit)
This function calculates the move rate of the unit.
Definition: movement.cpp:78
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'.
Definition: movement.cpp:743
static bool is_native_tile_to_class(const struct unit_class *punitclass, const struct tile *ptile)
Definition: movement.h:73
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 cit...
Definition: movement.cpp:177
unit_move_result
Definition: movement.h:25
@ MR_CANNOT_DISEMBARK
Definition: movement.h:38
@ MR_OK
Definition: movement.h:26
@ MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT
Definition: movement.h:35
@ MR_TRIREME
Definition: movement.h:37
@ MR_NON_NATIVE_MOVE
Definition: movement.h:39
@ MR_BAD_MAP_POSITION
Definition: movement.h:34
@ MR_BAD_ACTIVITY
Definition: movement.h:32
@ MR_ANIMAL_DISALLOWED
Definition: movement.h:40
@ MR_PEACE
Definition: movement.h:30
@ MR_ZOC
Definition: movement.h:31
@ MR_NOT_ALLOWED
Definition: movement.h:42
@ MR_DEATH
Definition: movement.h:27
@ MR_NO_WAR
Definition: movement.h:29
@ MR_BAD_DESTINATION
Definition: movement.h:33
@ MR_NO_TRANSPORTER_CAPACITY
Definition: movement.h:36
@ MR_UNIT_STAY
Definition: movement.h:41
@ MR_PAUSE
Definition: movement.h:28
bool is_airunit_refuel_point(const struct tile *ptile, const struct player *pplayer, const struct unit *punit)
Can unit refuel on tile.
Definition: unittools.cpp:1635
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.
Definition: movement.cpp:142
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.
Definition: movement.cpp:290
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 hitpo...
Definition: movement.cpp:38
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.
Definition: movement.cpp:452
bool is_unit_being_refueled(const struct unit *punit)
Is unit being refueled in its current position.
Definition: movement.cpp:759
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: movement.cpp:424
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: movement.cpp:698
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 mo...
Definition: movement.cpp:322
void init_move_fragments()
Call whenever terrain_control.move_fragments / SINGLE_MOVE changes.
Definition: movement.cpp:777
bool can_attack_non_native(const struct unit_type *utype)
This unit can attack non-native tiles (eg.
Definition: movement.cpp:164
const char * move_points_text(int mp, bool reduce)
Simple version of move_points_text_full() – render positive movement points as text without any prefi...
Definition: movement.cpp:856
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.
Definition: movement.cpp:566
Definition: player.h:231
Definition: tile.h:42
Definition: unit.h:134
#define tile_terrain(_tile)
Definition: tile.h:93
static const bv_extras * tile_extras(const struct tile *ptile)
Definition: tile.h:102
#define unit_owner(_pu)
Definition: unit.h:370