Freeciv-3.1
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#include "fc_types.h"
21#include "map.h"
22#include "tile.h"
23
24#define SINGLE_MOVE (terrain_control.move_fragments)
25#define MOVE_COST_IGTER (terrain_control.igter_cost)
26/* packets.def MOVEFRAGS */
27#define MAX_MOVE_FRAGS 65535
28
29struct unit_type;
30struct terrain;
31
52
53int utype_move_rate(const struct unit_type *utype, const struct tile *ptile,
54 const struct player *pplayer, int veteran_level,
55 int hitpoints);
56int unit_move_rate(const struct unit *punit);
57int utype_unknown_move_cost(const struct unit_type *utype);
58
59bool unit_can_defend_here(const struct civ_map *nmap, const struct unit *punit);
60bool can_attack_non_native(const struct unit_type *utype);
61bool can_attack_from_non_native(const struct unit_type *utype);
62
63bool is_city_channel_tile(const struct civ_map *nmap,
64 const struct unit_class *punitclass,
65 const struct tile *ptile,
66 const struct tile *pexclude);
67bool may_be_city_channel_tile(const struct civ_map *nmap,
68 const struct unit_class *punitclass,
69 const struct tile *ptile,
70 const struct player *pov_player);
71
72bool is_native_tile(const struct unit_type *punittype,
73 const struct tile *ptile);
74
75bool is_native_to_class(const struct unit_class *punitclass,
76 const struct terrain *pterrain,
77 const bv_extras *extras);
78
79/****************************************************************************
80 Check if this tile is native to given unit class.
81
82 See is_native_to_class()
83****************************************************************************/
84static inline bool is_native_tile_to_class(const struct unit_class *punitclass,
85 const struct tile *ptile)
86{
87 return is_native_to_class(punitclass, tile_terrain(ptile),
88 tile_extras(ptile));
89}
90
91bool is_native_move(const struct civ_map *nmap,
92 const struct unit_class *punitclass,
93 const struct tile *src_tile,
94 const struct tile *dst_tile);
95bool is_native_near_tile(const struct civ_map *nmap,
96 const struct unit_class *uclass,
97 const struct tile *ptile);
98bool can_exist_at_tile(const struct civ_map *nmap,
99 const struct unit_type *utype,
100 const struct tile *ptile);
101bool could_exist_in_city(const struct civ_map *nmap,
102 const struct player *pov_player,
103 const struct unit_type *utype,
104 const struct city *pcity);
105bool can_unit_exist_at_tile(const struct civ_map *nmap,
106 const struct unit *punit, const struct tile *ptile);
107bool can_unit_survive_at_tile(const struct civ_map *nmap,
108 const struct unit *punit,
109 const struct tile *ptile);
110bool can_step_taken_wrt_to_zoc(const struct unit_type *punittype,
111 const struct player *unit_owner,
112 const struct tile *src_tile,
113 const struct tile *dst_tile,
114 const struct civ_map *zmap);
115bool unit_can_move_to_tile(const struct civ_map *nmap,
116 const struct unit *punit,
117 const struct tile *ptile,
118 bool igzoc,
119 bool enter_transport,
120 bool enter_enemy_city);
122unit_move_to_tile_test(const struct civ_map *nmap,
123 const struct unit *punit,
124 enum unit_activity activity,
125 const struct tile *src_tile,
126 const struct tile *dst_tile,
127 bool igzoc,
128 bool enter_transport, struct unit *embark_to,
129 bool enter_enemy_city);
131unit_teleport_to_tile_test(const struct civ_map *nmap,
132 const struct unit *punit,
133 enum unit_activity activity,
134 const struct tile *src_tile,
135 const struct tile *dst_tile,
136 bool enter_transport, struct unit *embark_to,
137 bool enter_enemy_city);
138bool can_unit_transport(const struct unit *transporter, const struct unit *transported);
139bool can_unit_type_transport(const struct unit_type *transporter,
140 const struct unit_class *transported);
141bool unit_can_load(const struct unit *punit);
142bool unit_could_load_at(const struct unit *punit, const struct tile *ptile);
143
144void init_move_fragments(void);
145const char *move_points_text_full(int mp, bool reduce, const char *prefix,
146 const char *none, bool align);
147const char *move_points_text(int mp, bool reduce);
148
149/* Simple algorithm that checks connectivity of _tile_ on _map_
150 * to a tile where _found_ is true via adjacency of tiles where _conn_.
151 * _found_ and _conn_ must be boolean expressions checking tile _piter_.
152 * _conn_ is not checked at starting and finishing _tile_.
153 * Assigns the found tile to _tile_, or NULL if not found */
154#define MAP_TILE_CONN_TO_BY(_map_, _tile_, _piter_, _found_, _conn_) {\
155 struct dbv tile_processed; \
156 struct tile_list *process_queue = tile_list_new(); \
157 bool found = FALSE; \
158 \
159 dbv_init(&tile_processed, map_num_tiles()); \
160 for (;;) { \
161 dbv_set(&tile_processed, tile_index(_tile_)); \
162 adjc_iterate(_map_, _tile_, _piter_) { \
163 if (dbv_isset(&tile_processed, tile_index(_piter_))) { \
164 continue; \
165 } else if (_found_) { \
166 _tile_ = _piter_; \
167 found = TRUE; \
168 break; \
169 } else if (_conn_) { \
170 tile_list_append(process_queue, _piter_); \
171 } else { \
172 dbv_set(&tile_processed, tile_index(_piter_)); \
173 } \
174 } adjc_iterate_end; \
175 \
176 if (found) { \
177 /* got it*/ \
178 break; \
179 } \
180 if (0 == tile_list_size(process_queue)) { \
181 /* No more tile to process. */ \
182 _tile_ = NULL; \
183 break; \
184 } else { \
185 _tile_ = tile_list_front(process_queue); \
186 tile_list_pop_front(process_queue); \
187 } \
188 } \
189 \
190 dbv_free(&tile_processed); \
191 tile_list_destroy(process_queue); \
192}
193
194#ifdef __cplusplus
195}
196#endif /* __cplusplus */
197
198#endif /* FC__MOVEMENT_H */
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:73
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1005
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:589
const char * move_points_text_full(int mp, bool reduce, const char *prefix, const char *none, bool align)
Definition movement.c:938
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:264
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:627
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:336
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:348
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:559
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:295
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:873
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Definition movement.c:845
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:901
static bool is_native_tile_to_class(const struct unit_class *punitclass, const struct tile *ptile)
Definition movement.h:84
bool can_attack_from_non_native(const struct unit_type *utype)
Definition movement.c:215
unit_move_result
Definition movement.h:32
@ MR_CANNOT_DISEMBARK
Definition movement.h:46
@ MR_OK
Definition movement.h:33
@ MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT
Definition movement.h:43
@ MR_TRIREME
Definition movement.h:45
@ MR_NON_NATIVE_MOVE
Definition movement.h:47
@ MR_BAD_MAP_POSITION
Definition movement.h:41
@ MR_BAD_ACTIVITY
Definition movement.h:39
@ MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_CITY
Definition movement.h:42
@ MR_ANIMAL_DISALLOWED
Definition movement.h:48
@ MR_PEACE
Definition movement.h:37
@ MR_ZOC
Definition movement.h:38
@ MR_NOT_ALLOWED
Definition movement.h:50
@ MR_DEATH
Definition movement.h:34
@ MR_NO_WAR
Definition movement.h:36
@ MR_BAD_DESTINATION
Definition movement.h:40
@ MR_NO_TRANSPORTER_CAPACITY
Definition movement.h:44
@ MR_UNIT_STAY
Definition movement.h:49
@ MR_PAUSE
Definition movement.h:35
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:764
bool unit_can_defend_here(const struct civ_map *nmap, const struct unit *punit)
Definition movement.c:175
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:390
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:245
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
Definition movement.c:359
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:228
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:508
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:482
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:858
void init_move_fragments(void)
Definition movement.c:917
bool can_attack_non_native(const struct unit_type *utype)
Definition movement.c:202
Definition city.h:309
Definition tile.h:49
Definition unit.h:138
#define tile_terrain(_tile)
Definition tile.h:113
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:123
#define unit_owner(_pu)
Definition unit.h:394