Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / terrain.h
blobd1e50a441053bf0f50ed666485cac2c3df133c63
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.
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__TERRAIN_H
14 #define FC__TERRAIN_H
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /* utility */
21 #include "bitvector.h"
22 #include "shared.h"
24 /* common */
25 #include "fc_types.h"
26 #include "name_translation.h"
27 #include "unittype.h"
29 struct base_type;
30 struct strvec; /* Actually defined in "utility/string_vector.h". */
31 struct rgbcolor;
33 /* Used in the network protocol. */
34 enum special_river_move {
35 RMV_NORMAL = 0,
36 RMV_FAST_STRICT = 1,
37 RMV_FAST_RELAXED = 2,
38 RMV_FAST_ALWAYS = 3,
41 /* === */
43 struct resource_type {
45 char id_old_save; /* Single-character identifier used in old savegames. */
46 #define RESOURCE_NULL_IDENTIFIER '\0'
47 #define RESOURCE_NONE_IDENTIFIER ' '
49 int output[O_LAST]; /* Amount added by this resource. */
51 struct extra_type *self;
54 /* === */
56 #define T_NONE (NULL) /* A special flag meaning no terrain type. */
57 #define T_UNKNOWN (NULL) /* An unknown terrain. */
59 /* The first terrain value. */
60 #define T_FIRST 0
62 /* A hard limit on the number of terrains; useful for static arrays.
63 * Used in the network protocol. */
64 #define MAX_NUM_TERRAINS (96)
65 /* Reflect reality; but theoretically could be larger than terrains!
66 * Used in the network protocol. */
67 #define MAX_RESOURCE_TYPES (MAX_NUM_TERRAINS / 2)
69 /* Used in the network protocol. */
70 #define SPECENUM_NAME terrain_class
71 #define SPECENUM_VALUE0 TC_LAND
72 /* TRANS: terrain class: used adjectivally */
73 #define SPECENUM_VALUE0NAME N_("Land")
74 #define SPECENUM_VALUE1 TC_OCEAN
75 /* TRANS: terrain class: used adjectivally */
76 #define SPECENUM_VALUE1NAME N_("Oceanic")
77 #define SPECENUM_COUNT TC_COUNT
78 #include "specenum_gen.h"
80 /* Types of alterations available to terrain.
81 * This enum is only used in the effects system; the relevant information
82 * is encoded in other members of the terrain structure.
84 * Used in the network protocol. */
85 #define SPECENUM_NAME terrain_alteration
86 /* Can build irrigation without changing terrain */
87 #define SPECENUM_VALUE0 TA_CAN_IRRIGATE
88 /* TRANS: this and following strings may rarely be presented to the player
89 * in ruleset help text, to denote the set of terrains which can be altered
90 * in a particular way */
91 #define SPECENUM_VALUE0NAME N_("CanIrrigate")
92 /* Can build mine without changing terrain */
93 #define SPECENUM_VALUE1 TA_CAN_MINE
94 #define SPECENUM_VALUE1NAME N_("CanMine")
95 /* Can build roads and/or railroads */
96 #define SPECENUM_VALUE2 TA_CAN_ROAD
97 #define SPECENUM_VALUE2NAME N_("CanRoad")
98 #define SPECENUM_COUNT TA_COUNT
99 #include "specenum_gen.h"
101 /* Used in the network protocol. */
102 #define SPECENUM_NAME terrain_flag_id
103 /* No barbarians summoned on this terrain. */
104 #define SPECENUM_VALUE0 TER_NO_BARBS
105 /* TRANS: this and following strings are 'terrain flags', which may rarely
106 * be presented to the player in ruleset help text */
107 #define SPECENUM_VALUE0NAME N_("NoBarbs")
108 /* No cities on this terrain. */
109 #define SPECENUM_VALUE1 TER_NO_CITIES
110 #define SPECENUM_VALUE1NAME N_("NoCities")
111 /* Players will start on this terrain type. */
112 #define SPECENUM_VALUE2 TER_STARTER
113 #define SPECENUM_VALUE2NAME N_("Starter")
114 /* Terrains with this type can have road with "River" flag on them. */
115 #define SPECENUM_VALUE3 TER_CAN_HAVE_RIVER
116 #define SPECENUM_VALUE3NAME N_("CanHaveRiver")
117 /*this tile is not safe as coast, (all ocean / ice) */
118 #define SPECENUM_VALUE4 TER_UNSAFE_COAST
119 #define SPECENUM_VALUE4NAME N_("UnsafeCoast")
120 /* Fresh water terrain */
121 #define SPECENUM_VALUE5 TER_FRESHWATER
122 #define SPECENUM_VALUE5NAME N_("FreshWater")
123 /* Map generator does not place this terrain */
124 #define SPECENUM_VALUE6 TER_NOT_GENERATED
125 #define SPECENUM_VALUE6NAME N_("NotGenerated")
126 /* Units on this terrain are not generating or subject to zoc */
127 #define SPECENUM_VALUE7 TER_NO_ZOC
128 #define SPECENUM_VALUE7NAME N_("NoZoc")
129 /* No unit can fortify on this terrain */
130 #define SPECENUM_VALUE8 TER_NO_FORTIFY
131 #define SPECENUM_VALUE8NAME N_("NoFortify")
132 /* Ice-covered terrain (affects minimap) */
133 #define SPECENUM_VALUE9 TER_FROZEN
134 #define SPECENUM_VALUE9NAME N_("Frozen")
135 #define SPECENUM_VALUE10 TER_USER_1
136 #define SPECENUM_VALUE11 TER_USER_2
137 #define SPECENUM_VALUE12 TER_USER_3
138 #define SPECENUM_VALUE13 TER_USER_4
139 #define SPECENUM_VALUE14 TER_USER_5
140 #define SPECENUM_VALUE15 TER_USER_6
141 #define SPECENUM_VALUE16 TER_USER_7
142 #define SPECENUM_VALUE17 TER_USER_LAST
143 #define SPECENUM_NAMEOVERRIDE
144 #define SPECENUM_BITVECTOR bv_terrain_flags
145 #include "specenum_gen.h"
147 #define MAX_NUM_USER_TER_FLAGS (TER_USER_LAST - TER_USER_1 + 1)
149 #define SPECENUM_NAME mapgen_terrain_property
150 #define SPECENUM_VALUE0 MG_MOUNTAINOUS
151 #define SPECENUM_VALUE0NAME "mountainous"
152 #define SPECENUM_VALUE1 MG_GREEN
153 #define SPECENUM_VALUE1NAME "green"
154 #define SPECENUM_VALUE2 MG_FOLIAGE
155 #define SPECENUM_VALUE2NAME "foliage"
156 #define SPECENUM_VALUE3 MG_TROPICAL
157 #define SPECENUM_VALUE3NAME "tropical"
158 #define SPECENUM_VALUE4 MG_TEMPERATE
159 #define SPECENUM_VALUE4NAME "temperate"
160 #define SPECENUM_VALUE5 MG_COLD
161 #define SPECENUM_VALUE5NAME "cold"
162 #define SPECENUM_VALUE6 MG_FROZEN
163 #define SPECENUM_VALUE6NAME "frozen"
164 #define SPECENUM_VALUE7 MG_WET
165 #define SPECENUM_VALUE7NAME "wet"
166 #define SPECENUM_VALUE8 MG_DRY
167 #define SPECENUM_VALUE8NAME "dry"
168 #define SPECENUM_VALUE9 MG_OCEAN_DEPTH
169 #define SPECENUM_VALUE9NAME "ocean_depth"
170 #define SPECENUM_COUNT MG_COUNT
171 #include "specenum_gen.h"
174 * This struct gives data about each terrain type. There are many ways
175 * it could be extended.
177 struct terrain {
178 int item_number;
179 struct name_translation name;
180 bool disabled; /* Does not really exist - hole in terrain array */
181 char graphic_str[MAX_LEN_NAME]; /* add tile_ prefix */
182 char graphic_alt[MAX_LEN_NAME];
184 char identifier; /* Single-character identifier used in games saved. */
185 char identifier_load; /* Single-character identifier that was used in the savegame
186 * loaded. */
188 #define TERRAIN_UNKNOWN_IDENTIFIER 'u'
190 enum terrain_class tclass;
192 int movement_cost; /* whole MP, not scaled by SINGLE_MOVE */
193 int defense_bonus; /* % defense bonus - defaults to zero */
195 int output[O_LAST];
197 struct extra_type **resources; /* NULL-terminated */
199 int road_output_incr_pct[O_LAST];
200 int base_time;
201 int road_time;
203 struct terrain *irrigation_result;
204 int irrigation_food_incr;
205 int irrigation_time;
207 struct terrain *mining_result;
208 int mining_shield_incr;
209 int mining_time;
211 struct terrain *transform_result;
212 int transform_time;
213 int clean_pollution_time;
214 int clean_fallout_time;
215 int pillage_time;
217 struct unit_type *animal;
219 /* May be NULL if the transformation is impossible. */
220 struct terrain *warmer_wetter_result, *warmer_drier_result;
221 struct terrain *cooler_wetter_result, *cooler_drier_result;
223 /* These are special properties of the terrain used by mapgen. If a tile
224 * has a property, then the value gives the weighted amount of tiles that
225 * will be assigned this terrain.
227 * For instance if mountains have 70 and hills have 30 of MG_MOUNTAINOUS
228 * then 70% of 'mountainous' tiles will be given mountains.
230 * Ocean_depth is different. Instead of a percentage, the depth of the
231 * tile in the range 0 (never chosen) to 100 (deepest) is used.
233 int property[MG_COUNT];
234 #define TERRAIN_OCEAN_DEPTH_MINIMUM (1)
235 #define TERRAIN_OCEAN_DEPTH_MAXIMUM (100)
237 bv_unit_classes native_to;
239 bv_terrain_flags flags;
241 struct rgbcolor *rgb;
243 struct strvec *helptext;
246 /* General terrain accessor functions. */
247 Terrain_type_id terrain_count(void);
248 Terrain_type_id terrain_index(const struct terrain *pterrain);
249 Terrain_type_id terrain_number(const struct terrain *pterrain);
251 struct terrain *terrain_by_number(const Terrain_type_id type);
253 struct terrain *terrain_by_identifier(const char identifier);
254 struct terrain *terrain_by_rule_name(const char *name);
255 struct terrain *terrain_by_translated_name(const char *name);
256 struct terrain *rand_terrain_by_flag(enum terrain_flag_id flag);
258 char terrain_identifier(const struct terrain *pterrain);
259 const char *terrain_rule_name(const struct terrain *pterrain);
260 const char *terrain_name_translation(const struct terrain *pterrain);
262 /* Functions to operate on a terrain flag. */
263 #define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
265 bool is_terrain_flag_card_near(const struct tile *ptile,
266 enum terrain_flag_id flag);
267 bool is_terrain_flag_near_tile(const struct tile *ptile,
268 enum terrain_flag_id flag);
269 int count_terrain_flag_near_tile(const struct tile *ptile,
270 bool cardinal_only, bool percentage,
271 enum terrain_flag_id flag);
272 void user_terrain_flags_init(void);
273 void user_terrain_flags_free(void);
274 void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt);
275 const char *terrain_flag_helptxt(enum terrain_flag_id id);
277 /* Terrain-specific functions. */
278 #define is_ocean(pterrain) ((pterrain) != T_UNKNOWN \
279 && terrain_type_terrain_class(pterrain) == TC_OCEAN)
280 #define is_ocean_tile(ptile) \
281 is_ocean(tile_terrain(ptile))
283 bool terrain_has_resource(const struct terrain *pterrain,
284 const struct extra_type *presource);
286 /* Functions to operate on a general terrain type. */
287 bool is_terrain_card_near(const struct tile *ptile,
288 const struct terrain *pterrain,
289 bool check_self);
290 bool is_terrain_near_tile(const struct tile *ptile,
291 const struct terrain *pterrain,
292 bool check_self);
293 int count_terrain_near_tile(const struct tile *ptile,
294 bool cardinal_only, bool percentage,
295 const struct terrain *pterrain);
296 int count_terrain_property_near_tile(const struct tile *ptile,
297 bool cardinal_only, bool percentage,
298 enum mapgen_terrain_property prop);
300 bool is_resource_card_near(const struct tile *ptile,
301 const struct extra_type *pres,
302 bool check_self);
303 bool is_resource_near_tile(const struct tile *ptile,
304 const struct extra_type *pres,
305 bool check_self);
307 struct resource_type *resource_type_init(struct extra_type *pextra);
308 void resource_types_free(void);
310 struct extra_type *resource_extra_get(const struct resource_type *presource);
312 /* Special helper functions */
313 const char *get_infrastructure_text(bv_extras extras);
314 struct extra_type *get_preferred_pillage(bv_extras extras);
316 int terrain_extra_build_time(const struct terrain *pterrain,
317 enum unit_activity activity,
318 const struct extra_type *tgt);
319 int terrain_extra_removal_time(const struct terrain *pterrain,
320 enum unit_activity activity,
321 const struct extra_type *tgt);
323 /* Functions to operate on a terrain class. */
324 const char *terrain_class_name_translation(enum terrain_class tclass);
326 enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain);
327 bool is_terrain_class_card_near(const struct tile *ptile, enum terrain_class tclass);
328 bool is_terrain_class_near_tile(const struct tile *ptile, enum terrain_class tclass);
329 int count_terrain_class_near_tile(const struct tile *ptile,
330 bool cardinal_only, bool percentage,
331 enum terrain_class tclass);
333 /* Functions to deal with possible terrain alterations. */
334 bool terrain_can_support_alteration(const struct terrain *pterrain,
335 enum terrain_alteration talter);
337 /* Initialization and iteration */
338 void terrains_init(void);
339 void terrains_free(void);
341 struct terrain *terrain_array_first(void);
342 const struct terrain *terrain_array_last(void);
344 #define terrain_type_iterate(_p) \
346 struct terrain *_p = terrain_array_first(); \
347 if (NULL != _p) { \
348 for (; _p <= terrain_array_last(); _p++) {
350 #define terrain_type_iterate_end \
355 #define terrain_active_iterate(_p) \
356 terrain_type_iterate(_p) { \
357 if (!_p->disabled) {
359 #define terrain_active_iterate_end \
361 } terrain_type_iterate_end;
363 #ifdef __cplusplus
365 #endif /* __cplusplus */
367 #endif /* FC__TERRAIN_H */