Freeciv-3.2
Loading...
Searching...
No Matches
movement.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__MOVEMENT_H
14#define FC__MOVEMENT_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* common */
21#include "fc_types.h"
22#include "map.h"
23
24struct tile;
25
26#define SINGLE_MOVE (terrain_control.move_fragments)
27#define MOVE_COST_IGTER (terrain_control.igter_cost)
28/* packets.def MOVEFRAGS */
29#define MAX_MOVE_FRAGS 65535
30
31struct unit_type;
32struct terrain;
33
55
56int utype_move_rate(const struct unit_type *utype, const struct tile *ptile,
57 const struct player *pplayer, int veteran_level,
58 int hitpoints);
59int unit_move_rate(const struct unit *punit);
60int utype_unknown_move_cost(const struct unit_type *utype);
61
62bool unit_can_defend_here(const struct civ_map *nmap, const struct unit *punit);
63bool can_attack_non_native_hard_reqs(const struct unit_type *utype);
64bool can_attack_non_native(const struct unit_type *utype);
65bool can_attack_from_non_native(const struct unit_type *utype);
66
67bool is_city_channel_tile(const struct civ_map *nmap,
68 const struct unit_class *punitclass,
69 const struct tile *ptile,
70 const struct tile *pexclude);
71bool may_be_city_channel_tile(const struct civ_map *nmap,
72 const struct unit_class *punitclass,
73 const struct tile *ptile,
74 const struct player *pov_player);
75
76bool is_native_tile(const struct unit_type *punittype,
77 const struct tile *ptile);
78
80 const struct terrain *pterrain,
81 const bv_extras *extras);
82
83/****************************************************************************
84 Check if this tile is native to given unit class.
85
86 See is_native_to_class()
87****************************************************************************/
88static inline bool is_native_tile_to_class(const struct unit_class *punitclass,
89 const struct tile *ptile)
90{
92 tile_extras(ptile));
93}
94
95bool is_native_move(const struct civ_map *nmap,
96 const struct unit_class *punitclass,
97 const struct tile *src_tile,
98 const struct tile *dst_tile);
99bool is_native_near_tile(const struct civ_map *nmap,
100 const struct unit_class *uclass,
101 const struct tile *ptile);
102bool can_exist_at_tile(const struct civ_map *nmap,
103 const struct unit_type *utype,
104 const struct tile *ptile);
105bool could_exist_in_city(const struct civ_map *nmap,
106 const struct player *pov_player,
107 const struct unit_type *utype,
108 const struct city *pcity);
109bool can_unit_exist_at_tile(const struct civ_map *nmap,
110 const struct unit *punit, const struct tile *ptile);
111bool can_unit_survive_at_tile(const struct civ_map *nmap,
112 const struct unit *punit,
113 const struct tile *ptile);
115 const struct player *unit_owner,
116 const struct tile *src_tile,
117 const struct tile *dst_tile,
118 const struct civ_map *zmap);
119bool unit_can_move_to_tile(const struct civ_map *nmap,
120 const struct unit *punit,
121 const struct tile *ptile,
122 bool igzoc,
123 bool enter_transport,
124 bool enter_enemy_city);
125bool unit_can_teleport_to_tile(const struct civ_map *nmap,
126 const struct unit *punit,
127 const struct tile *ptile,
128 bool enter_transport,
129 bool enter_enemy_city);
132 const struct unit *punit,
133 enum unit_activity activity,
134 const struct tile *src_tile,
135 const struct tile *dst_tile,
136 bool igzoc,
137 bool enter_transport, struct unit *embark_to,
138 bool enter_enemy_city);
141 const struct unit *punit,
142 enum unit_activity activity,
143 const struct tile *src_tile,
144 const struct tile *dst_tile,
145 bool enter_transport, struct unit *embark_to,
146 bool enter_enemy_city);
147bool can_unit_transport(const struct unit *transporter, const struct unit *transported);
148bool can_unit_type_transport(const struct unit_type *transporter,
149 const struct unit_class *transported);
150bool unit_can_load(const struct unit *punit);
151bool unit_could_load_at(const struct unit *punit, const struct tile *ptile);
152
153void init_move_fragments(void);
154const char *move_points_text_full(int mp, bool reduce, const char *prefix,
155 const char *none, bool align);
156const char *move_points_text(int mp, bool reduce);
157
158/* Simple algorithm that checks connectivity of _tile_ on _map_
159 * to a tile where _found_ is true via adjacency of tiles where _conn_.
160 * _found_ and _conn_ must be boolean expressions checking tile _piter_.
161 * _conn_ is not checked at starting and finishing _tile_.
162 * Assigns the found tile to _tile_, or NULL if not found */
163#define MAP_TILE_CONN_TO_BY(_map_, _tile_, _piter_, _found_, _conn_) {\
164 struct dbv tile_processed; \
165 struct tile_list *process_queue = tile_list_new(); \
166 bool found = FALSE; \
167 \
168 dbv_init(&tile_processed, map_num_tiles()); \
169 for (;;) { \
170 dbv_set(&tile_processed, tile_index(_tile_)); \
171 adjc_iterate(_map_, _tile_, _piter_) { \
172 if (dbv_isset(&tile_processed, tile_index(_piter_))) { \
173 continue; \
174 } else if (_found_) { \
175 _tile_ = _piter_; \
176 found = TRUE; \
177 break; \
178 } else if (_conn_) { \
179 tile_list_append(process_queue, _piter_); \
180 } else { \
181 dbv_set(&tile_processed, tile_index(_piter_)); \
182 } \
183 } adjc_iterate_end; \
184 \
185 if (found) { \
186 /* got it*/ \
187 break; \
188 } \
189 if (0 == tile_list_size(process_queue)) { \
190 /* No more tile to process. */ \
191 _tile_ = NULL; \
192 break; \
193 } else { \
194 _tile_ = tile_list_front(process_queue); \
195 tile_list_pop_front(process_queue); \
196 } \
197 } \
198 \
199 dbv_free(&tile_processed); \
200 tile_list_destroy(process_queue); \
201}
202
203#ifdef __cplusplus
204}
205#endif /* __cplusplus */
206
207#endif /* FC__MOVEMENT_H */
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1047
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)
Definition movement.c:604
const char * move_points_text_full(int mp, bool reduce, const char *prefix, const char *none, bool align)
Definition movement.c:980
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:279
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)
Definition movement.c:662
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:351
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:363
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)
Definition movement.c:574
bool could_exist_in_city(const struct civ_map *nmap, const struct player *pov_player, const struct unit_type *utype, const struct city *pcity)
Definition movement.c:310
int utype_unknown_move_cost(const struct unit_type *utype)
Definition movement.c:105
bool unit_can_load(const struct unit *punit)
Definition movement.c:915
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Definition movement.c:887
int unit_move_rate(const struct unit *punit)
Definition movement.c:90
bool unit_could_load_at(const struct unit *punit, const struct tile *ptile)
Definition movement.c:943
bool can_attack_non_native_hard_reqs(const struct unit_type *utype)
Definition movement.c:204
static bool is_native_tile_to_class(const struct unit_class *punitclass, const struct tile *ptile)
Definition movement.h:88
bool can_attack_from_non_native(const struct unit_type *utype)
Definition movement.c:227
unit_move_result
Definition movement.h:34
@ MR_CANNOT_DISEMBARK
Definition movement.h:48
@ MR_OK
Definition movement.h:35
@ MR_RANDOM_ONLY
Definition movement.h:52
@ MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT
Definition movement.h:45
@ MR_TRIREME
Definition movement.h:47
@ MR_NON_NATIVE_MOVE
Definition movement.h:49
@ MR_BAD_MAP_POSITION
Definition movement.h:43
@ MR_BAD_ACTIVITY
Definition movement.h:41
@ MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_CITY
Definition movement.h:44
@ MR_ANIMAL_DISALLOWED
Definition movement.h:50
@ MR_PEACE
Definition movement.h:39
@ MR_ZOC
Definition movement.h:40
@ MR_NOT_ALLOWED
Definition movement.h:53
@ MR_DEATH
Definition movement.h:36
@ MR_NO_WAR
Definition movement.h:38
@ MR_BAD_DESTINATION
Definition movement.h:42
@ MR_NO_TRANSPORTER_CAPACITY
Definition movement.h:46
@ MR_UNIT_STAY
Definition movement.h:51
@ MR_PAUSE
Definition movement.h:37
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)
Definition movement.c:624
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)
Definition movement.c:806
bool unit_can_defend_here(const struct civ_map *nmap, const struct unit *punit)
Definition movement.c:174
bool is_native_move(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *src_tile, const struct tile *dst_tile)
Definition movement.c:405
bool may_be_city_channel_tile(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct player *pov_player)
Definition movement.c:260
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
Definition movement.c:374
int utype_move_rate(const struct unit_type *utype, const struct tile *ptile, const struct player *pplayer, int veteran_level, int hitpoints)
Definition movement.c:47
bool is_city_channel_tile(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
Definition movement.c:243
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:523
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:497
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:900
void init_move_fragments(void)
Definition movement.c:959
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:214
Definition city.h:320
Definition tile.h:50
Definition unit.h:138
#define tile_terrain(_tile)
Definition tile.h:114
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:124
#define unit_owner(_pu)
Definition unit.h:396