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)
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 ***********************************************************************/
18 #endif /* __cplusplus */
21 #include "bitvector.h"
26 #include "name_translation.h"
30 struct strvec
; /* Actually defined in "utility/string_vector.h". */
33 /* Used in the network protocol. */
34 enum special_river_move
{
41 /* S_LAST-terminated */
42 extern enum tile_special_type infrastructure_specials
[];
44 BV_DEFINE(bv_special
, S_LAST
); /* Used in the network protocol. */
46 /* NB: This does not include S_FORTRESS and S_AIRBASE.
47 * You must use base_type_iterate and related accessors
48 * in base.h for those. */
49 #define tile_special_type_iterate(special) \
51 enum tile_special_type special = 0; \
52 for (; special < S_LAST; special++) { \
54 #define tile_special_type_iterate_end \
62 struct name_translation name
;
63 char graphic_str
[MAX_LEN_NAME
];
64 char graphic_alt
[MAX_LEN_NAME
];
66 char identifier
; /* Single-character identifier used in savegames. */
67 #define RESOURCE_NULL_IDENTIFIER '\0'
68 #define RESOURCE_NONE_IDENTIFIER ' '
70 int output
[O_LAST
]; /* Amount added by this resource. */
75 #define T_NONE (NULL) /* A special flag meaning no terrain type. */
76 #define T_UNKNOWN (NULL) /* An unknown terrain. */
78 /* The first terrain value. */
81 /* A hard limit on the number of terrains; useful for static arrays.
82 * Used in the network protocol. */
83 #define MAX_NUM_TERRAINS (96)
84 /* Reflect reality; but theoretically could be larger than terrains!
85 * Used in the network protocol. */
86 #define MAX_NUM_RESOURCES (MAX_NUM_TERRAINS/2)
88 #define SPECENUM_NAME terrain_class
89 #define SPECENUM_VALUE0 TC_LAND
90 /* TRANS: terrain class: used adjectivally */
91 #define SPECENUM_VALUE0NAME N_("Land")
92 #define SPECENUM_VALUE1 TC_OCEAN
93 /* TRANS: terrain class: used adjectivally */
94 #define SPECENUM_VALUE1NAME N_("Oceanic")
95 #include "specenum_gen.h"
97 /* Types of alterations available to terrain.
98 * This enum is only used in the effects system; the relevant information
99 * is encoded in other members of the terrain structure. */
100 #define SPECENUM_NAME terrain_alteration
101 /* Can build irrigation without changing terrain */
102 #define SPECENUM_VALUE0 TA_CAN_IRRIGATE
103 #define SPECENUM_VALUE0NAME "CanIrrigate"
104 /* Can build mine without changing terrain */
105 #define SPECENUM_VALUE1 TA_CAN_MINE
106 #define SPECENUM_VALUE1NAME "CanMine"
107 /* Can build roads and/or railroads */
108 #define SPECENUM_VALUE2 TA_CAN_ROAD
109 #define SPECENUM_VALUE2NAME "CanRoad"
110 #include "specenum_gen.h"
112 #define SPECENUM_NAME terrain_flag_id
113 /* No barbarians summoned on this terrain. */
114 #define SPECENUM_VALUE0 TER_NO_BARBS
115 /* TRANS: this and following strings are 'terrain flags', which may rarely
116 * be presented to the player in ruleset help text */
117 #define SPECENUM_VALUE0NAME N_("NoBarbs")
118 /* This terrain cannot be polluted. */
119 #define SPECENUM_VALUE1 TER_NO_POLLUTION
120 #define SPECENUM_VALUE1NAME N_("NoPollution")
121 /* No cities on this terrain. */
122 #define SPECENUM_VALUE2 TER_NO_CITIES
123 #define SPECENUM_VALUE2NAME N_("NoCities")
124 /* Players will start on this terrain type. */
125 #define SPECENUM_VALUE3 TER_STARTER
126 #define SPECENUM_VALUE3NAME N_("Starter")
127 /* Terrains with this type can have road with "River" flag on them. */
128 #define SPECENUM_VALUE4 TER_CAN_HAVE_RIVER
129 #define SPECENUM_VALUE4NAME N_("CanHaveRiver")
130 /*this tile is not safe as coast, (all ocean / ice) */
131 #define SPECENUM_VALUE5 TER_UNSAFE_COAST
132 #define SPECENUM_VALUE5NAME N_("UnsafeCoast")
133 /* Fresh water terrain */
134 #define SPECENUM_VALUE6 TER_FRESHWATER
135 #define SPECENUM_VALUE6NAME N_("FreshWater")
136 /* Map generator does not place this terrain */
137 #define SPECENUM_VALUE7 TER_NOT_GENERATED
138 #define SPECENUM_VALUE7NAME N_("NotGenerated")
139 #define SPECENUM_VALUE8 TER_USER_1
140 #define SPECENUM_VALUE9 TER_USER_2
141 #define SPECENUM_VALUE10 TER_USER_3
142 #define SPECENUM_VALUE11 TER_USER_4
143 #define SPECENUM_VALUE12 TER_USER_5
144 #define SPECENUM_VALUE13 TER_USER_6
145 #define SPECENUM_VALUE14 TER_USER_7
146 #define SPECENUM_VALUE15 TER_USER_LAST
147 #define SPECENUM_NAMEOVERRIDE
148 #include "specenum_gen.h"
150 #define TER_MAX 64 /* Changing this breaks network compatability. */
152 #define MAX_NUM_USER_TER_FLAGS (TER_USER_LAST - TER_USER_1 + 1)
154 BV_DEFINE(bv_terrain_flags
, TER_MAX
); /* Used in the network protocol. */
156 #define SPECENUM_NAME mapgen_terrain_property
157 #define SPECENUM_VALUE0 MG_MOUNTAINOUS
158 #define SPECENUM_VALUE0NAME "mountainous"
159 #define SPECENUM_VALUE1 MG_GREEN
160 #define SPECENUM_VALUE1NAME "green"
161 #define SPECENUM_VALUE2 MG_FOLIAGE
162 #define SPECENUM_VALUE2NAME "foliage"
163 #define SPECENUM_VALUE3 MG_TROPICAL
164 #define SPECENUM_VALUE3NAME "tropical"
165 #define SPECENUM_VALUE4 MG_TEMPERATE
166 #define SPECENUM_VALUE4NAME "temperate"
167 #define SPECENUM_VALUE5 MG_COLD
168 #define SPECENUM_VALUE5NAME "cold"
169 #define SPECENUM_VALUE6 MG_FROZEN
170 #define SPECENUM_VALUE6NAME "frozen"
171 #define SPECENUM_VALUE7 MG_WET
172 #define SPECENUM_VALUE7NAME "wet"
173 #define SPECENUM_VALUE8 MG_DRY
174 #define SPECENUM_VALUE8NAME "dry"
175 #define SPECENUM_VALUE9 MG_OCEAN_DEPTH
176 #define SPECENUM_VALUE9NAME "ocean_depth"
177 #define SPECENUM_COUNT MG_COUNT
178 #include "specenum_gen.h"
181 * This struct gives data about each terrain type. There are many ways
182 * it could be extended.
186 struct name_translation name
;
187 char graphic_str
[MAX_LEN_NAME
]; /* add tile_ prefix */
188 char graphic_alt
[MAX_LEN_NAME
];
190 char identifier
; /* Single-character identifier used in savegames. */
192 #define TERRAIN_UNKNOWN_IDENTIFIER 'u'
194 enum terrain_class tclass
;
196 int movement_cost
; /* whole MP, not scaled by SINGLE_MOVE */
197 int defense_bonus
; /* % defense bonus - defaults to zero */
201 struct resource
**resources
; /* NULL-terminated */
203 int road_output_incr_pct
[O_LAST
];
207 struct terrain
*irrigation_result
;
208 int irrigation_food_incr
;
211 struct terrain
*mining_result
;
212 int mining_shield_incr
;
215 struct terrain
*transform_result
;
217 int clean_pollution_time
;
218 int clean_fallout_time
;
220 /* May be NULL if the transformation is impossible. */
221 struct terrain
*warmer_wetter_result
, *warmer_drier_result
;
222 struct terrain
*cooler_wetter_result
, *cooler_drier_result
;
224 /* These are special properties of the terrain used by mapgen. If a tile
225 * has a property, then the value gives the weighted amount of tiles that
226 * will be assigned this terrain.
228 * For instance if mountains have 70 and hills have 30 of MG_MOUNTAINOUS
229 * then 70% of 'mountainous' tiles will be given mountains.
231 * Ocean_depth is different. Instead of a percentage, the depth of the
232 * tile in the range 0 (never chosen) to 100 (deepest) is used.
234 int property
[MG_COUNT
];
235 #define TERRAIN_OCEAN_DEPTH_MINIMUM (1)
236 #define TERRAIN_OCEAN_DEPTH_MAXIMUM (100)
238 bv_unit_classes native_to
;
240 bv_terrain_flags flags
;
242 struct rgbcolor
*rgb
;
244 struct strvec
*helptext
;
247 /* General terrain accessor functions. */
248 Terrain_type_id
terrain_count(void);
249 Terrain_type_id
terrain_index(const struct terrain
*pterrain
);
250 Terrain_type_id
terrain_number(const struct terrain
*pterrain
);
252 struct terrain
*terrain_by_number(const Terrain_type_id type
);
254 struct terrain
*terrain_by_identifier(const char identifier
);
255 struct terrain
*terrain_by_rule_name(const char *name
);
256 struct terrain
*terrain_by_translated_name(const char *name
);
257 struct terrain
*rand_terrain_by_flag(enum terrain_flag_id flag
);
259 char terrain_identifier(const struct terrain
*pterrain
);
260 const char *terrain_rule_name(const struct terrain
*pterrain
);
261 const char *terrain_name_translation(const struct terrain
*pterrain
);
263 /* Functions to operate on a terrain flag. */
264 #define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
266 int terrains_by_flag(enum terrain_flag_id flag
, struct terrain
**buffer
, int bufsize
);
268 bool is_terrain_flag_card_near(const struct tile
*ptile
,
269 enum terrain_flag_id flag
);
270 bool is_terrain_flag_near_tile(const struct tile
*ptile
,
271 enum terrain_flag_id flag
);
272 int count_terrain_flag_near_tile(const struct tile
*ptile
,
273 bool cardinal_only
, bool percentage
,
274 enum terrain_flag_id flag
);
275 void user_terrain_flags_init(void);
276 void user_terrain_flags_free(void);
277 void set_user_terrain_flag_name(enum terrain_flag_id id
, const char *name
, const char *helptxt
);
278 const char *terrain_flag_helptxt(enum terrain_flag_id id
);
280 /* Terrain-specific functions. */
281 #define is_ocean(pterrain) ((pterrain) != T_UNKNOWN \
282 && terrain_type_terrain_class(pterrain) == TC_OCEAN)
283 #define is_ocean_tile(ptile) \
284 is_ocean(tile_terrain(ptile))
286 bool terrain_has_resource(const struct terrain
*pterrain
,
287 const struct resource
*presource
);
289 /* Functions to operate on a general terrain type. */
290 bool is_terrain_card_near(const struct tile
*ptile
,
291 const struct terrain
*pterrain
,
293 bool is_terrain_near_tile(const struct tile
*ptile
,
294 const struct terrain
*pterrain
,
296 int count_terrain_near_tile(const struct tile
*ptile
,
297 bool cardinal_only
, bool percentage
,
298 const struct terrain
*pterrain
);
299 int count_terrain_property_near_tile(const struct tile
*ptile
,
300 bool cardinal_only
, bool percentage
,
301 enum mapgen_terrain_property prop
);
303 bool is_resource_card_near(const struct tile
*ptile
,
304 const struct resource
*pres
,
306 bool is_resource_near_tile(const struct tile
*ptile
,
307 const struct resource
*pres
,
310 /* General resource accessor functions. */
311 Resource_type_id
resource_count(void);
312 Resource_type_id
resource_index(const struct resource
*presource
);
313 Resource_type_id
resource_number(const struct resource
*presource
);
315 struct resource
*resource_by_number(const Resource_type_id id
);
316 struct resource
*resource_by_identifier(const char identifier
);
317 struct resource
*resource_by_rule_name(const char *name
);
319 const char *resource_rule_name(const struct resource
*presource
);
320 const char *resource_name_translation(const struct resource
*presource
);
322 /* General special accessor functions. */
323 enum tile_special_type
special_by_rule_name(const char *name
);
324 const char *special_rule_name(enum tile_special_type type
);
325 const char *special_name_translation(enum tile_special_type type
);
327 void set_special(bv_special
*set
, enum tile_special_type to_set
);
328 void clear_special(bv_special
*set
, enum tile_special_type to_clear
);
329 void clear_all_specials(bv_special
*set
);
330 bool contains_special(bv_special all
,
331 enum tile_special_type to_test_for
);
332 bool contains_any_specials(bv_special all
);
334 bool is_native_terrain_to_special(enum tile_special_type special
,
335 const struct terrain
*pterrain
);
336 bool is_native_tile_to_special(enum tile_special_type special
,
337 const struct tile
*ptile
);
339 /* Special helper functions */
340 const char *get_infrastructure_text(bv_special pset
, bv_bases bases
, bv_roads roads
);
341 enum tile_special_type
get_infrastructure_prereq(enum tile_special_type spe
);
342 bool get_preferred_pillage(struct act_tgt
*tgt
,
347 int terrain_base_time(const struct terrain
*pterrain
,
350 int terrain_road_time(const struct terrain
*pterrain
,
353 /* Functions to operate on a terrain special. */
354 bool is_special_card_near(const struct tile
*ptile
,
355 enum tile_special_type spe
,
357 bool is_special_near_tile(const struct tile
*ptile
,
358 enum tile_special_type spe
,
360 int count_special_near_tile(const struct tile
*ptile
,
361 bool cardinal_only
, bool percentage
,
362 enum tile_special_type spe
);
364 /* Functions to operate on a terrain class. */
365 const char *terrain_class_name_translation(enum terrain_class tclass
);
367 enum terrain_class
terrain_type_terrain_class(const struct terrain
*pterrain
);
368 bool is_terrain_class_card_near(const struct tile
*ptile
, enum terrain_class tclass
);
369 bool is_terrain_class_near_tile(const struct tile
*ptile
, enum terrain_class tclass
);
370 int count_terrain_class_near_tile(const struct tile
*ptile
,
371 bool cardinal_only
, bool percentage
,
372 enum terrain_class tclass
);
374 /* Functions to deal with possible terrain alterations. */
375 const char *terrain_alteration_name_translation(enum terrain_alteration talter
);
376 bool terrain_can_support_alteration(const struct terrain
*pterrain
,
377 enum terrain_alteration talter
);
379 /* Initialization and iteration */
380 struct resource
*resource_array_first(void);
381 const struct resource
*resource_array_last(void);
383 #define resource_type_iterate(_p) \
385 struct resource *_p = resource_array_first(); \
387 for (; _p <= resource_array_last(); _p++) {
389 #define resource_type_iterate_end \
394 /* Initialization and iteration */
395 void terrains_init(void);
396 void terrains_free(void);
398 struct terrain
*terrain_array_first(void);
399 const struct terrain
*terrain_array_last(void);
401 #define terrain_type_iterate(_p) \
403 struct terrain *_p = terrain_array_first(); \
405 for (; _p <= terrain_array_last(); _p++) {
407 #define terrain_type_iterate_end \
414 #endif /* __cplusplus */
416 #endif /* FC__TERRAIN_H */