Freeciv-3.1
Loading...
Searching...
No Matches
terrain.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__TERRAIN_H
14#define FC__TERRAIN_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "bitvector.h"
22#include "shared.h"
23
24/* common */
25#include "fc_types.h"
26#include "name_translation.h"
27#include "unittype.h"
28
29struct base_type;
30struct strvec; /* Actually defined in "utility/string_vector.h". */
31struct rgbcolor;
32
33/* Used in the network protocol. */
40
41/* === */
42
44
45 char id_old_save; /* Single-character identifier used in old savegames. */
46#define RESOURCE_NULL_IDENTIFIER '\0'
47#define RESOURCE_NONE_IDENTIFIER ' '
48
49 int output[O_LAST]; /* Amount added by this resource. */
50
52};
53
54/* === */
55
56#define T_NONE (NULL) /* A special flag meaning no terrain type. */
57#define T_UNKNOWN (NULL) /* An unknown terrain. */
58
59/* The first terrain value. */
60#define T_FIRST 0
61
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)
68
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"
79
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.
83 *
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"
100
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/* Ice-covered terrain (affects minimap) */
130#define SPECENUM_VALUE8 TER_FROZEN
131#define SPECENUM_VALUE8NAME N_("Frozen")
132#define SPECENUM_VALUE9 TER_USER_1
133#define SPECENUM_VALUE10 TER_USER_2
134#define SPECENUM_VALUE11 TER_USER_3
135#define SPECENUM_VALUE12 TER_USER_4
136#define SPECENUM_VALUE13 TER_USER_5
137#define SPECENUM_VALUE14 TER_USER_6
138#define SPECENUM_VALUE15 TER_USER_7
139#define SPECENUM_VALUE16 TER_USER_8
140#define SPECENUM_VALUE17 TER_USER_9
141#define SPECENUM_VALUE18 TER_USER_LAST
142#define SPECENUM_NAMEOVERRIDE
143#define SPECENUM_BITVECTOR bv_terrain_flags
144#include "specenum_gen.h"
145
146#define MAX_NUM_USER_TER_FLAGS (TER_USER_LAST - TER_USER_1 + 1)
147
148#define SPECENUM_NAME mapgen_terrain_property
149#define SPECENUM_VALUE0 MG_MOUNTAINOUS
150#define SPECENUM_VALUE0NAME "mountainous"
151#define SPECENUM_VALUE1 MG_GREEN
152#define SPECENUM_VALUE1NAME "green"
153#define SPECENUM_VALUE2 MG_FOLIAGE
154#define SPECENUM_VALUE2NAME "foliage"
155#define SPECENUM_VALUE3 MG_TROPICAL
156#define SPECENUM_VALUE3NAME "tropical"
157#define SPECENUM_VALUE4 MG_TEMPERATE
158#define SPECENUM_VALUE4NAME "temperate"
159#define SPECENUM_VALUE5 MG_COLD
160#define SPECENUM_VALUE5NAME "cold"
161#define SPECENUM_VALUE6 MG_FROZEN
162#define SPECENUM_VALUE6NAME "frozen"
163#define SPECENUM_VALUE7 MG_WET
164#define SPECENUM_VALUE7NAME "wet"
165#define SPECENUM_VALUE8 MG_DRY
166#define SPECENUM_VALUE8NAME "dry"
167#define SPECENUM_VALUE9 MG_OCEAN_DEPTH
168#define SPECENUM_VALUE9NAME "ocean_depth"
169#define SPECENUM_COUNT MG_COUNT
170#include "specenum_gen.h"
171
172/*
173 * This struct gives data about each terrain type. There are many ways
174 * it could be extended.
175 */
176struct terrain {
179 bool ruledit_disabled; /* Does not really exist - hole in terrain array */
181 char graphic_str[MAX_LEN_NAME]; /* add tile_ prefix */
183
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. */
187
188#define TERRAIN_UNKNOWN_IDENTIFIER 'u'
189
190 enum terrain_class tclass;
191
192 int movement_cost; /* whole MP, not scaled by SINGLE_MOVE */
193 int defense_bonus; /* % defense bonus - defaults to zero */
194
196
197 struct extra_type **resources; /* NULL-terminated */
198
202
205
208
211
214
216
222
223 const struct unit_type *animal;
224
225 /* May be NULL if the transformation is impossible. */
228
229 /* These are special properties of the terrain used by mapgen. If a tile
230 * has a property, then the value gives the weighted amount of tiles that
231 * will be assigned this terrain.
232 *
233 * For instance if mountains have 70 and hills have 30 of MG_MOUNTAINOUS
234 * then 70% of 'mountainous' tiles will be given mountains.
235 *
236 * Ocean_depth is different. Instead of a percentage, the depth of the
237 * tile in the range 0 (never chosen) to 100 (deepest) is used.
238 */
239 int property[MG_COUNT];
240#define TERRAIN_OCEAN_DEPTH_MINIMUM (1)
241#define TERRAIN_OCEAN_DEPTH_MAXIMUM (100)
242
243 bv_unit_classes native_to;
244
245 bv_terrain_flags flags;
246
247 struct rgbcolor *rgb;
248
250};
251
252/* General terrain accessor functions. */
254Terrain_type_id terrain_index(const struct terrain *pterrain);
255Terrain_type_id terrain_number(const struct terrain *pterrain);
256
258
259struct terrain *terrain_by_identifier(const char identifier);
260struct terrain *terrain_by_rule_name(const char *name);
261struct terrain *terrain_by_translated_name(const char *name);
262struct terrain *rand_terrain_by_flag(enum terrain_flag_id flag);
263
264char terrain_identifier(const struct terrain *pterrain);
265const char *terrain_rule_name(const struct terrain *pterrain);
266const char *terrain_name_translation(const struct terrain *pterrain);
267
268/* Functions to operate on a terrain flag. */
269#define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
270
271bool is_terrain_flag_card_near(const struct civ_map *nmap,
272 const struct tile *ptile,
273 enum terrain_flag_id flag);
274bool is_terrain_flag_near_tile(const struct civ_map *nmap,
275 const struct tile *ptile,
276 enum terrain_flag_id flag);
277int count_terrain_flag_near_tile(const struct civ_map *nmap,
278 const struct tile *ptile,
279 bool cardinal_only, bool percentage,
280 enum terrain_flag_id flag);
281void user_terrain_flags_init(void);
282void user_terrain_flags_free(void);
283void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt);
284const char *terrain_flag_helptxt(enum terrain_flag_id id);
285
286/* Terrain-specific functions. */
287#define is_ocean(pterrain) ((pterrain) != T_UNKNOWN \
288 && terrain_type_terrain_class(pterrain) == TC_OCEAN)
289#define is_ocean_tile(ptile) \
290 is_ocean(tile_terrain(ptile))
291
292bool terrain_has_resource(const struct terrain *pterrain,
293 const struct extra_type *presource);
294
295/* Functions to operate on a general terrain type. */
296bool is_terrain_card_near(const struct civ_map *nmap,
297 const struct tile *ptile,
298 const struct terrain *pterrain,
299 bool check_self);
300bool is_terrain_near_tile(const struct civ_map *nmap,
301 const struct tile *ptile,
302 const struct terrain *pterrain,
303 bool check_self);
304int count_terrain_property_near_tile(const struct civ_map *nmap,
305 const struct tile *ptile,
306 bool cardinal_only, bool percentage,
307 enum mapgen_terrain_property prop);
308
309bool is_resource_card_near(const struct civ_map *nmap,
310 const struct tile *ptile,
311 const struct extra_type *pres,
312 bool check_self);
313bool is_resource_near_tile(const struct civ_map *nmap,
314 const struct tile *ptile,
315 const struct extra_type *pres,
316 bool check_self);
317
318struct resource_type *resource_type_init(struct extra_type *pextra);
319void resource_types_free(void);
320
321struct extra_type *resource_extra_get(const struct resource_type *presource);
322
323/* Special helper functions */
324const char *get_infrastructure_text(bv_extras extras);
325struct extra_type *get_preferred_pillage(bv_extras extras);
326
327int terrain_extra_build_time(const struct terrain *pterrain,
328 enum unit_activity activity,
329 const struct extra_type *tgt);
330int terrain_extra_removal_time(const struct terrain *pterrain,
331 enum unit_activity activity,
332 const struct extra_type *tgt);
333
334/* Functions to operate on a terrain class. */
335const char *terrain_class_name_translation(enum terrain_class tclass);
336
337enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain);
338bool is_terrain_class_card_near(const struct civ_map *nmap,
339 const struct tile *ptile, enum terrain_class tclass);
340bool is_terrain_class_near_tile(const struct civ_map *nmap,
341 const struct tile *ptile, enum terrain_class tclass);
342int count_terrain_class_near_tile(const struct civ_map *nmap,
343 const struct tile *ptile,
344 bool cardinal_only, bool percentage,
345 enum terrain_class tclass);
346
347/* Functions to deal with possible terrain alterations. */
348bool terrain_can_support_alteration(const struct terrain *pterrain,
349 enum terrain_alteration talter);
350
351/* Initialization and iteration */
352void terrains_init(void);
353void terrains_free(void);
354
355struct terrain *terrain_array_first(void);
356const struct terrain *terrain_array_last(void);
357
358#define terrain_type_iterate(_p) \
359{ \
360 struct terrain *_p = terrain_array_first(); \
361 if (NULL != _p) { \
362 for (; _p <= terrain_array_last(); _p++) {
363
364#define terrain_type_iterate_end \
365 } \
366 } \
367}
368
369#define terrain_re_active_iterate(_p) \
370 terrain_type_iterate(_p) { \
371 if (!_p->ruledit_disabled) {
372
373#define terrain_re_active_iterate_end \
374 } \
375 } terrain_type_iterate_end;
376
377#ifdef __cplusplus
378}
379#endif /* __cplusplus */
380
381#endif /* FC__TERRAIN_H */
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
int Terrain_type_id
Definition fc_types.h:343
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_LAST
Definition fc_types.h:91
GType type
Definition repodlgs.c:1312
const char * name
Definition inputfile.c:127
struct extra_type * self
Definition terrain.h:51
char id_old_save
Definition terrain.h:45
int output[O_LAST]
Definition terrain.h:49
struct terrain * cultivate_result
Definition terrain.h:203
int placing_time
Definition terrain.h:215
struct terrain * cooler_wetter_result
Definition terrain.h:227
struct extra_type ** resources
Definition terrain.h:197
struct terrain * cooler_drier_result
Definition terrain.h:227
int item_number
Definition terrain.h:177
struct strvec * helptext
Definition terrain.h:249
struct terrain * warmer_wetter_result
Definition terrain.h:226
bv_terrain_flags flags
Definition terrain.h:245
bv_unit_classes native_to
Definition terrain.h:243
int road_time
Definition terrain.h:201
struct name_translation name
Definition terrain.h:178
int plant_time
Definition terrain.h:207
struct terrain * plant_result
Definition terrain.h:206
int irrigation_food_incr
Definition terrain.h:209
int clean_fallout_time
Definition terrain.h:220
struct terrain * warmer_drier_result
Definition terrain.h:226
int defense_bonus
Definition terrain.h:193
int cultivate_time
Definition terrain.h:204
int movement_cost
Definition terrain.h:192
const struct unit_type * animal
Definition terrain.h:223
int pillage_time
Definition terrain.h:221
int output[O_LAST]
Definition terrain.h:195
int transform_time
Definition terrain.h:218
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:182
int mining_time
Definition terrain.h:213
char identifier_load
Definition terrain.h:185
struct rgbcolor * rgb
Definition terrain.h:247
int clean_pollution_time
Definition terrain.h:219
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:181
enum terrain_class tclass
Definition terrain.h:190
int road_output_incr_pct[O_LAST]
Definition terrain.h:199
struct terrain * transform_result
Definition terrain.h:217
int irrigation_time
Definition terrain.h:210
int base_time
Definition terrain.h:200
int mining_shield_incr
Definition terrain.h:212
void * ruledit_dlg
Definition terrain.h:180
char identifier
Definition terrain.h:184
bool ruledit_disabled
Definition terrain.h:179
Definition tile.h:49
int terrain_extra_removal_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:718
void user_terrain_flags_init(void)
Definition terrain.c:752
void terrains_free(void)
Definition terrain.c:59
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:174
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:600
char terrain_identifier(const struct terrain *pterrain)
Definition terrain.c:114
Terrain_type_id terrain_count(void)
Definition terrain.c:106
void terrains_init(void)
Definition terrain.c:42
struct extra_type * resource_extra_get(const struct resource_type *presource)
Definition terrain.c:284
bool terrain_can_support_alteration(const struct terrain *pterrain, enum terrain_alteration talter)
Definition terrain.c:661
int count_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_class tclass)
Definition terrain.c:621
bool is_terrain_class_card_near(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:579
struct terrain * terrain_by_translated_name(const char *name)
Definition terrain.c:190
const char * terrain_class_name_translation(enum terrain_class tclass)
Definition terrain.c:649
int count_terrain_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_flag_id flag)
Definition terrain.c:466
const char * get_infrastructure_text(bv_extras extras)
Definition terrain.c:496
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:126
bool is_resource_card_near(const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pres, bool check_self)
Definition terrain.c:383
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
struct terrain * terrain_array_first(void)
Definition terrain.c:84
struct terrain * rand_terrain_by_flag(enum terrain_flag_id flag)
Definition terrain.c:205
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:144
bool is_terrain_card_near(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:315
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
bool is_resource_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct extra_type *pres, bool check_self)
Definition terrain.c:404
void resource_types_free(void)
Definition terrain.c:276
void user_terrain_flags_free(void)
Definition terrain.c:764
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:570
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Definition terrain.c:817
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:243
struct resource_type * resource_type_init(struct extra_type *pextra)
Definition terrain.c:260
bool is_terrain_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_flag_id flag)
Definition terrain.c:446
struct extra_type * get_preferred_pillage(bv_extras extras)
Definition terrain.c:538
void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt)
Definition terrain.c:776
const struct terrain * terrain_array_last(void)
Definition terrain.c:95
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:682
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:135
struct terrain * terrain_by_identifier(const char identifier)
Definition terrain.c:157
bool is_terrain_flag_card_near(const struct civ_map *nmap, const struct tile *ptile, enum terrain_flag_id flag)
Definition terrain.c:426
special_river_move
Definition terrain.h:34
@ RMV_NORMAL
Definition terrain.h:35
@ RMV_FAST_RELAXED
Definition terrain.h:37
@ RMV_FAST_STRICT
Definition terrain.h:36
@ RMV_FAST_ALWAYS
Definition terrain.h:38
int count_terrain_property_near_tile(const struct civ_map *nmap, const struct tile *ptile, bool cardinal_only, bool percentage, enum mapgen_terrain_property prop)
Definition terrain.c:357
bool is_terrain_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:336