Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / tile.h
blob9f758e1bd936fa2a8f029bcc88b3077ee987117f
1 /***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
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.
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 ***********************************************************************/
14 #ifndef FC__TILE_H
15 #define FC__TILE_H
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
21 /* utility */
22 #include "bitvector.h"
24 /* common */
25 #include "base.h"
26 #include "extras.h"
27 #include "fc_types.h"
28 #include "player.h"
29 #include "road.h"
30 #include "terrain.h"
31 #include "unitlist.h"
33 /* network, order dependent */
34 enum known_type {
35 TILE_UNKNOWN = 0,
36 TILE_KNOWN_UNSEEN = 1,
37 TILE_KNOWN_SEEN = 2,
40 /* Convenience macro for accessing tile coordinates. This should only be
41 * used for debugging. */
42 #define TILE_XY(ptile) ((ptile) ? index_to_map_pos_x(tile_index(ptile)) \
43 : -1), \
44 ((ptile) ? index_to_map_pos_y(tile_index(ptile)) \
45 : -1)
47 struct tile {
48 int index; /* Index coordinate of the tile. Used to calculate (x, y) pairs
49 * (index_to_map_pos()) and (nat_x, nat_y) pairs
50 * (index_to_native_pos()). */
51 Continent_id continent;
52 bv_extras extras;
53 struct extra_type *resource; /* NULL for no resource */
54 struct terrain *terrain; /* NULL for unknown tiles */
55 struct unit_list *units;
56 struct city *worked; /* NULL for not worked */
57 struct player *owner; /* NULL for not owned */
58 struct player *extras_owner;
59 struct tile *claimer;
60 char *label; /* NULL for no label */
61 char *spec_sprite;
64 /* 'struct tile_list' and related functions. */
65 #define SPECLIST_TAG tile
66 #define SPECLIST_TYPE struct tile
67 #include "speclist.h"
68 #define tile_list_iterate(tile_list, ptile) \
69 TYPED_LIST_ITERATE(struct tile, tile_list, ptile)
70 #define tile_list_iterate_end LIST_ITERATE_END
72 /* 'struct tile_hash' and related functions. */
73 #define SPECHASH_TAG tile
74 #define SPECHASH_IKEY_TYPE struct tile *
75 #define SPECHASH_IDATA_TYPE void *
76 #include "spechash.h"
77 #define tile_hash_iterate(hash, ptile) \
78 TYPED_HASH_KEYS_ITERATE(struct tile *, hash, ptile)
79 #define tile_hash_iterate_end HASH_KEYS_ITERATE_END
82 /* Tile accessor functions. */
83 #define tile_index(_pt_) (_pt_)->index
85 struct city *tile_city(const struct tile *ptile);
87 #define tile_continent(_tile) ((_tile)->continent)
88 /*Continent_id tile_continent(const struct tile *ptile);*/
89 void tile_set_continent(struct tile *ptile, Continent_id val);
91 #define tile_owner(_tile) ((_tile)->owner)
92 /*struct player *tile_owner(const struct tile *ptile);*/
93 void tile_set_owner(struct tile *ptile, struct player *pplayer,
94 struct tile *claimer);
95 #define tile_claimer(_tile) ((_tile)->claimer)
97 #define tile_resource(_tile) ((_tile)->resource)
98 static inline bool tile_resource_is_valid(const struct tile *ptile)
99 { return ptile->resource != NULL
100 && BV_ISSET(ptile->extras, ptile->resource->id);
102 /*const struct resource *tile_resource(const struct tile *ptile);*/
103 void tile_set_resource(struct tile *ptile, struct extra_type *presource);
105 #define tile_terrain(_tile) ((_tile)->terrain)
106 /*struct terrain *tile_terrain(const struct tile *ptile);*/
107 void tile_set_terrain(struct tile *ptile, struct terrain *pterrain);
109 #define tile_worked(_tile) ((_tile)->worked)
110 /* struct city *tile_worked(const struct tile *ptile); */
111 void tile_set_worked(struct tile *ptile, struct city *pcity);
113 const bv_extras *tile_extras_safe(const struct tile *ptile);
114 const bv_extras *tile_extras_null(void);
115 static inline const bv_extras *tile_extras(const struct tile *ptile)
117 return &(ptile->extras);
120 void tile_set_bases(struct tile *ptile, bv_bases bases);
121 bool tile_has_base(const struct tile *ptile, const struct base_type *pbase);
122 void tile_add_base(struct tile *ptile, const struct base_type *pbase);
123 void tile_remove_base(struct tile *ptile, const struct base_type *pbase);
124 bool tile_has_base_flag(const struct tile *ptile, enum base_flag_id flag);
125 bool tile_has_base_flag_for_unit(const struct tile *ptile,
126 const struct unit_type *punittype,
127 enum base_flag_id flag);
128 bool tile_has_refuel_extra(const struct tile *ptile,
129 const struct unit_type *punittype);
130 bool tile_has_native_base(const struct tile *ptile,
131 const struct unit_type *punittype);
132 bool tile_has_claimable_base(const struct tile *ptile,
133 const struct unit_type *punittype);
134 int tile_extras_defense_bonus(const struct tile *ptile,
135 const struct unit_type *punittype);
136 int tile_extras_class_defense_bonus(const struct tile *ptile,
137 const struct unit_class *pclass);
139 bool tile_has_road(const struct tile *ptile, const struct road_type *proad);
140 void tile_add_road(struct tile *ptile, const struct road_type *proad);
141 void tile_remove_road(struct tile *ptile, const struct road_type *proad);
142 bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag);
143 int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o);
144 int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o);
145 bool tile_has_river(const struct tile *tile);
147 bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt);
148 bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt);
149 #define tile_has_extra(ptile, pextra) BV_ISSET(ptile->extras, extra_index(pextra))
150 bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra);
151 bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra);
152 bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause);
153 void tile_add_extra(struct tile *ptile, const struct extra_type *pextra);
154 void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra);
155 bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag);;
157 /* Vision related */
158 enum known_type tile_get_known(const struct tile *ptile,
159 const struct player *pplayer);
161 bool tile_is_seen(const struct tile *target_tile,
162 const struct player *pow_player);
164 /* A somewhat arbitrary integer value. Activity times are multiplied by
165 * this amount, and divided by them later before being used. This may
166 * help to avoid rounding errors; however it should probably be removed. */
167 #define ACTIVITY_FACTOR 10
168 int tile_activity_time(enum unit_activity activity,
169 const struct tile *ptile,
170 struct extra_type *tgt);
172 /* These are higher-level functions that handle side effects on the tile. */
173 void tile_change_terrain(struct tile *ptile, struct terrain *pterrain);
174 bool tile_apply_activity(struct tile *ptile, Activity_type_id act,
175 struct extra_type *tgt);
177 #define TILE_LB_TERRAIN_RIVER (1 << 0)
178 #define TILE_LB_RIVER_RESOURCE (1 << 1)
179 #define TILE_LB_RESOURCE_POLL (1 << 2)
180 const char *tile_get_info_text(const struct tile *ptile,
181 bool include_nuisances, int linebreaks);
183 /* Virtual tiles are tiles that do not exist on the game map. */
184 struct tile *tile_virtual_new(const struct tile *ptile);
185 void tile_virtual_destroy(struct tile *vtile);
186 bool tile_virtual_check(struct tile *vtile);
188 void *tile_hash_key(const struct tile *ptile);
190 bool tile_set_label(struct tile *ptile, const char *label);
192 #ifdef __cplusplus
194 #endif /* __cplusplus */
196 #endif /* FC__TILE_H */