Do not return NULL as boolean from wonder_is_lost() nor wonder_is_built()
[freeciv.git] / common / terrain.h
blob76b194a5d4261d8eea37b8d94232ab3e5b94a120
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 {
44 int item_number;
45 struct name_translation name;
46 char graphic_str[MAX_LEN_NAME];
47 char graphic_alt[MAX_LEN_NAME];
49 char identifier; /* Single-character identifier used in savegames. */
50 #define RESOURCE_NULL_IDENTIFIER '\0'
51 #define RESOURCE_NONE_IDENTIFIER ' '
53 int output[O_LAST]; /* Amount added by this resource. */
56 /* === */
58 #define T_NONE (NULL) /* A special flag meaning no terrain type. */
59 #define T_UNKNOWN (NULL) /* An unknown terrain. */
61 /* The first terrain value. */
62 #define T_FIRST 0
64 /* A hard limit on the number of terrains; useful for static arrays.
65 * Used in the network protocol. */
66 #define MAX_NUM_TERRAINS (96)
67 /* Reflect reality; but theoretically could be larger than terrains!
68 * Used in the network protocol. */
69 #define MAX_NUM_RESOURCES (MAX_NUM_TERRAINS/2)
71 /* Used in the network protocol. */
72 #define SPECENUM_NAME terrain_class
73 #define SPECENUM_VALUE0 TC_LAND
74 /* TRANS: terrain class: used adjectivally */
75 #define SPECENUM_VALUE0NAME N_("Land")
76 #define SPECENUM_VALUE1 TC_OCEAN
77 /* TRANS: terrain class: used adjectivally */
78 #define SPECENUM_VALUE1NAME N_("Oceanic")
79 #include "specenum_gen.h"
81 /* Types of alterations available to terrain.
82 * This enum is only used in the effects system; the relevant information
83 * is encoded in other members of the terrain structure.
85 * Used in the network protocol. */
86 #define SPECENUM_NAME terrain_alteration
87 /* Can build irrigation without changing terrain */
88 #define SPECENUM_VALUE0 TA_CAN_IRRIGATE
89 /* TRANS: this and following strings may rarely be presented to the player
90 * in ruleset help text, to denote the set of terrains which can be altered
91 * in a particular way */
92 #define SPECENUM_VALUE0NAME N_("CanIrrigate")
93 /* Can build mine without changing terrain */
94 #define SPECENUM_VALUE1 TA_CAN_MINE
95 #define SPECENUM_VALUE1NAME N_("CanMine")
96 /* Can build roads and/or railroads */
97 #define SPECENUM_VALUE2 TA_CAN_ROAD
98 #define SPECENUM_VALUE2NAME N_("CanRoad")
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 char graphic_str[MAX_LEN_NAME]; /* add tile_ prefix */
181 char graphic_alt[MAX_LEN_NAME];
183 char identifier; /* Single-character identifier used in games saved. */
184 char identifier_load; /* Single-character identifier that was used in the savegame
185 * loaded. */
187 #define TERRAIN_UNKNOWN_IDENTIFIER 'u'
189 enum terrain_class tclass;
191 int movement_cost; /* whole MP, not scaled by SINGLE_MOVE */
192 int defense_bonus; /* % defense bonus - defaults to zero */
194 int output[O_LAST];
196 struct resource **resources; /* NULL-terminated */
198 int road_output_incr_pct[O_LAST];
199 int base_time;
200 int road_time;
202 struct terrain *irrigation_result;
203 int irrigation_food_incr;
204 int irrigation_time;
206 struct terrain *mining_result;
207 int mining_shield_incr;
208 int mining_time;
210 struct terrain *transform_result;
211 int transform_time;
212 int clean_pollution_time;
213 int clean_fallout_time;
214 int pillage_time;
216 struct unit_type *animal;
218 /* May be NULL if the transformation is impossible. */
219 struct terrain *warmer_wetter_result, *warmer_drier_result;
220 struct terrain *cooler_wetter_result, *cooler_drier_result;
222 /* These are special properties of the terrain used by mapgen. If a tile
223 * has a property, then the value gives the weighted amount of tiles that
224 * will be assigned this terrain.
226 * For instance if mountains have 70 and hills have 30 of MG_MOUNTAINOUS
227 * then 70% of 'mountainous' tiles will be given mountains.
229 * Ocean_depth is different. Instead of a percentage, the depth of the
230 * tile in the range 0 (never chosen) to 100 (deepest) is used.
232 int property[MG_COUNT];
233 #define TERRAIN_OCEAN_DEPTH_MINIMUM (1)
234 #define TERRAIN_OCEAN_DEPTH_MAXIMUM (100)
236 bv_unit_classes native_to;
238 bv_terrain_flags flags;
240 struct rgbcolor *rgb;
242 struct strvec *helptext;
245 /* General terrain accessor functions. */
246 Terrain_type_id terrain_count(void);
247 Terrain_type_id terrain_index(const struct terrain *pterrain);
248 Terrain_type_id terrain_number(const struct terrain *pterrain);
250 struct terrain *terrain_by_number(const Terrain_type_id type);
252 struct terrain *terrain_by_identifier(const char identifier);
253 struct terrain *terrain_by_rule_name(const char *name);
254 struct terrain *terrain_by_translated_name(const char *name);
255 struct terrain *rand_terrain_by_flag(enum terrain_flag_id flag);
257 char terrain_identifier(const struct terrain *pterrain);
258 const char *terrain_rule_name(const struct terrain *pterrain);
259 const char *terrain_name_translation(const struct terrain *pterrain);
261 /* Functions to operate on a terrain flag. */
262 #define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
264 bool is_terrain_flag_card_near(const struct tile *ptile,
265 enum terrain_flag_id flag);
266 bool is_terrain_flag_near_tile(const struct tile *ptile,
267 enum terrain_flag_id flag);
268 int count_terrain_flag_near_tile(const struct tile *ptile,
269 bool cardinal_only, bool percentage,
270 enum terrain_flag_id flag);
271 void user_terrain_flags_init(void);
272 void user_terrain_flags_free(void);
273 void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt);
274 const char *terrain_flag_helptxt(enum terrain_flag_id id);
276 /* Terrain-specific functions. */
277 #define is_ocean(pterrain) ((pterrain) != T_UNKNOWN \
278 && terrain_type_terrain_class(pterrain) == TC_OCEAN)
279 #define is_ocean_tile(ptile) \
280 is_ocean(tile_terrain(ptile))
282 bool terrain_has_resource(const struct terrain *pterrain,
283 const struct resource *presource);
285 /* Functions to operate on a general terrain type. */
286 bool is_terrain_card_near(const struct tile *ptile,
287 const struct terrain *pterrain,
288 bool check_self);
289 bool is_terrain_near_tile(const struct tile *ptile,
290 const struct terrain *pterrain,
291 bool check_self);
292 int count_terrain_near_tile(const struct tile *ptile,
293 bool cardinal_only, bool percentage,
294 const struct terrain *pterrain);
295 int count_terrain_property_near_tile(const struct tile *ptile,
296 bool cardinal_only, bool percentage,
297 enum mapgen_terrain_property prop);
299 bool is_resource_card_near(const struct tile *ptile,
300 const struct resource *pres,
301 bool check_self);
302 bool is_resource_near_tile(const struct tile *ptile,
303 const struct resource *pres,
304 bool check_self);
306 /* General resource accessor functions. */
307 Resource_type_id resource_count(void);
308 Resource_type_id resource_index(const struct resource *presource);
309 Resource_type_id resource_number(const struct resource *presource);
311 struct resource *resource_by_number(const Resource_type_id id);
312 struct resource *resource_by_identifier(const char identifier);
313 struct resource *resource_by_rule_name(const char *name);
315 const char *resource_rule_name(const struct resource *presource);
316 const char *resource_name_translation(const struct resource *presource);
318 /* Special helper functions */
319 const char *get_infrastructure_text(bv_extras extras);
320 struct extra_type *get_preferred_pillage(bv_extras extras);
322 int terrain_extra_build_time(const struct terrain *pterrain,
323 enum unit_activity activity,
324 const struct extra_type *tgt);
325 int terrain_extra_removal_time(const struct terrain *pterrain,
326 enum unit_activity activity,
327 const struct extra_type *tgt);
329 /* Functions to operate on a terrain class. */
330 const char *terrain_class_name_translation(enum terrain_class tclass);
332 enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain);
333 bool is_terrain_class_card_near(const struct tile *ptile, enum terrain_class tclass);
334 bool is_terrain_class_near_tile(const struct tile *ptile, enum terrain_class tclass);
335 int count_terrain_class_near_tile(const struct tile *ptile,
336 bool cardinal_only, bool percentage,
337 enum terrain_class tclass);
339 /* Functions to deal with possible terrain alterations. */
340 bool terrain_can_support_alteration(const struct terrain *pterrain,
341 enum terrain_alteration talter);
343 /* Initialization and iteration */
344 struct resource *resource_array_first(void);
345 const struct resource *resource_array_last(void);
347 #define resource_type_iterate(_p) \
349 struct resource *_p = resource_array_first(); \
350 if (NULL != _p) { \
351 for (; _p <= resource_array_last(); _p++) {
353 #define resource_type_iterate_end \
358 /* Initialization and iteration */
359 void terrains_init(void);
360 void terrains_free(void);
362 struct terrain *terrain_array_first(void);
363 const struct terrain *terrain_array_last(void);
365 #define terrain_type_iterate(_p) \
367 struct terrain *_p = terrain_array_first(); \
368 if (NULL != _p) { \
369 for (; _p <= terrain_array_last(); _p++) {
371 #define terrain_type_iterate_end \
376 #ifdef __cplusplus
378 #endif /* __cplusplus */
380 #endif /* FC__TERRAIN_H */