Freeciv-3.2
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
66/* Used in the network protocol. */
67#define SPECENUM_NAME terrain_class
68#define SPECENUM_VALUE0 TC_LAND
69/* TRANS: terrain class: used adjectivally */
70#define SPECENUM_VALUE0NAME N_("Land")
71#define SPECENUM_VALUE1 TC_OCEAN
72/* TRANS: terrain class: used adjectivally */
73#define SPECENUM_VALUE1NAME N_("Oceanic")
74#define SPECENUM_COUNT TC_COUNT
75#include "specenum_gen.h"
76
77/* Types of alterations available to terrain.
78 * This enum is only used in the effects system; the relevant information
79 * is encoded in other members of the terrain structure.
80 *
81 * Used in the network protocol. */
82#define SPECENUM_NAME terrain_alteration
83/* Can build irrigation without changing terrain */
84#define SPECENUM_VALUE0 TA_CAN_IRRIGATE
85/* TRANS: this and following strings may rarely be presented to the player
86 * in ruleset help text, to denote the set of terrains which can be altered
87 * in a particular way */
88#define SPECENUM_VALUE0NAME N_("CanIrrigate")
89/* Can build mine without changing terrain */
90#define SPECENUM_VALUE1 TA_CAN_MINE
91#define SPECENUM_VALUE1NAME N_("CanMine")
92/* Can build roads and/or railroads */
93#define SPECENUM_VALUE2 TA_CAN_ROAD
94#define SPECENUM_VALUE2NAME N_("CanRoad")
95/* Can build military base */
96#define SPECENUM_VALUE3 TA_CAN_BASE
97#define SPECENUM_VALUE3NAME N_("CanBase")
98/* Can place extras with infrapoints */
99#define SPECENUM_VALUE4 TA_CAN_PLACE
100#define SPECENUM_VALUE4NAME N_("CanPlace")
101#define SPECENUM_COUNT TA_COUNT
102#include "specenum_gen.h"
103
104/* Used in the network protocol. */
105#define SPECENUM_NAME terrain_flag_id
106/* No barbarians summoned on this terrain. */
107#define SPECENUM_VALUE0 TER_NO_BARBS
108/* TRANS: this and following strings are 'terrain flags', which may rarely
109 * be presented to the player in ruleset help text */
110#define SPECENUM_VALUE0NAME N_("NoBarbs")
111/* No cities on this terrain. */
112#define SPECENUM_VALUE1 TER_NO_CITIES
113#define SPECENUM_VALUE1NAME N_("NoCities")
114/* Players will start on this terrain type. */
115#define SPECENUM_VALUE2 TER_STARTER
116#define SPECENUM_VALUE2NAME N_("Starter")
117/* Terrains with this type can have road with "River" flag on them. */
118#define SPECENUM_VALUE3 TER_CAN_HAVE_RIVER
119#define SPECENUM_VALUE3NAME N_("CanHaveRiver")
120/*this tile is not safe as coast, (all ocean / ice) */
121#define SPECENUM_VALUE4 TER_UNSAFE_COAST
122#define SPECENUM_VALUE4NAME N_("UnsafeCoast")
123/* Fresh water terrain */
124#define SPECENUM_VALUE5 TER_FRESHWATER
125#define SPECENUM_VALUE5NAME N_("FreshWater")
126/* Map generator does not place this terrain */
127#define SPECENUM_VALUE6 TER_NOT_GENERATED
128#define SPECENUM_VALUE6NAME N_("NotGenerated")
129/* Units on this terrain are not generating or subject to zoc */
130#define SPECENUM_VALUE7 TER_NO_ZOC
131#define SPECENUM_VALUE7NAME N_("NoZoc")
132/* Borders on this terrain are not blocking unit movement */
133#define SPECENUM_VALUE8 TER_ENTER_BORDERS
134#define SPECENUM_VALUE8NAME N_("EnterBorders")
135/* Ice-covered terrain (affects minimap) */
136#define SPECENUM_VALUE9 TER_FROZEN
137#define SPECENUM_VALUE9NAME N_("Frozen")
138#define SPECENUM_VALUE10 TER_USER_1
139#define SPECENUM_VALUE11 TER_USER_2
140#define SPECENUM_VALUE12 TER_USER_3
141#define SPECENUM_VALUE13 TER_USER_4
142#define SPECENUM_VALUE14 TER_USER_5
143#define SPECENUM_VALUE15 TER_USER_6
144#define SPECENUM_VALUE16 TER_USER_7
145#define SPECENUM_VALUE17 TER_USER_8
146#define SPECENUM_VALUE18 TER_USER_9
147#define SPECENUM_VALUE19 TER_USER_LAST
148#define SPECENUM_NAMEOVERRIDE
149#define SPECENUM_BITVECTOR bv_terrain_flags
150#include "specenum_gen.h"
151
152#define MAX_NUM_USER_TER_FLAGS (TER_USER_LAST - TER_USER_1 + 1)
153
154#define SPECENUM_NAME mapgen_terrain_property
155#define SPECENUM_VALUE0 MG_MOUNTAINOUS
156#define SPECENUM_VALUE0NAME "mountainous"
157#define SPECENUM_VALUE1 MG_GREEN
158#define SPECENUM_VALUE1NAME "green"
159#define SPECENUM_VALUE2 MG_FOLIAGE
160#define SPECENUM_VALUE2NAME "foliage"
161#define SPECENUM_VALUE3 MG_TROPICAL
162#define SPECENUM_VALUE3NAME "tropical"
163#define SPECENUM_VALUE4 MG_TEMPERATE
164#define SPECENUM_VALUE4NAME "temperate"
165#define SPECENUM_VALUE5 MG_COLD
166#define SPECENUM_VALUE5NAME "cold"
167#define SPECENUM_VALUE6 MG_FROZEN
168#define SPECENUM_VALUE6NAME "frozen"
169#define SPECENUM_VALUE7 MG_WET
170#define SPECENUM_VALUE7NAME "wet"
171#define SPECENUM_VALUE8 MG_DRY
172#define SPECENUM_VALUE8NAME "dry"
173#define SPECENUM_VALUE9 MG_OCEAN_DEPTH
174#define SPECENUM_VALUE9NAME "ocean_depth"
175#define SPECENUM_COUNT MG_COUNT
176#include "specenum_gen.h"
177
178/*
179 * This struct gives data about each terrain type. There are many ways
180 * it could be extended.
181 */
182struct terrain {
185 bool ruledit_disabled; /* Does not really exist - hole in terrain array */
190
191 char identifier; /* Single-character identifier used in games saved. */
192 char identifier_load; /* Single-character identifier that was used in the savegame
193 * loaded. */
194
195#define TERRAIN_UNKNOWN_IDENTIFIER 'u'
196
198
199 int movement_cost; /* whole MP, not scaled by SINGLE_MOVE */
200 int defense_bonus; /* % defense bonus - defaults to zero */
201
203
204 struct extra_type **resources; /* NULL-terminated */
205 int *resource_freq; /* same length as resources */
206
207#define RESOURCE_FREQUENCY_MINIMUM (0)
208#define RESOURCE_FREQUENCY_DEFAULT (1)
209#define RESOURCE_FREQUENCY_MAXIMUM (255)
210
214
217
220
223
226
228
230
233
234 /* Currently only clean times, but named for future */
236
237 const struct unit_type *animal;
238
239 /* May be NULL if the transformation is impossible. */
242
243 /* These are special properties of the terrain used by mapgen. If a tile
244 * has a property, then the value gives the weighted amount of tiles that
245 * will be assigned this terrain.
246 *
247 * For instance if mountains have 70 and hills have 30 of MG_MOUNTAINOUS
248 * then 70% of 'mountainous' tiles will be given mountains.
249 *
250 * Ocean_depth is different. Instead of a percentage, the depth of the
251 * tile in the range 0 (never chosen) to 100 (deepest) is used.
252 */
253 int property[MG_COUNT];
254#define TERRAIN_OCEAN_DEPTH_MINIMUM (1)
255#define TERRAIN_OCEAN_DEPTH_MAXIMUM (100)
256
258
260
261 struct rgbcolor *rgb;
262
264};
265
266/* General terrain accessor functions. */
268Terrain_type_id terrain_index(const struct terrain *pterrain);
269Terrain_type_id terrain_number(const struct terrain *pterrain);
270
272
273struct terrain *terrain_by_identifier(const char identifier);
274struct terrain *terrain_by_rule_name(const char *name);
275struct terrain *terrain_by_translated_name(const char *name);
277
278char terrain_identifier(const struct terrain *pterrain);
279const char *terrain_rule_name(const struct terrain *pterrain);
280const char *terrain_name_translation(const struct terrain *pterrain);
281
282/* Functions to operate on a terrain flag. */
283#define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
284
285bool is_terrain_flag_card_near(const struct civ_map *nmap,
286 const struct tile *ptile,
287 enum terrain_flag_id flag);
288bool is_terrain_flag_near_tile(const struct civ_map *nmap,
289 const struct tile *ptile,
290 enum terrain_flag_id flag);
292 const struct tile *ptile,
293 bool cardinal_only, bool percentage,
294 enum terrain_flag_id flag);
295void user_terrain_flags_init(void);
296void user_terrain_flags_free(void);
297void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt);
298const char *terrain_flag_helptxt(enum terrain_flag_id id);
299
300/* Terrain-specific functions. */
301#define is_ocean(pterrain) ((pterrain) != T_UNKNOWN \
302 && terrain_type_terrain_class(pterrain) == TC_OCEAN)
303#define is_ocean_tile(ptile) \
304 is_ocean(tile_terrain(ptile))
305
306bool terrain_has_resource(const struct terrain *pterrain,
307 const struct extra_type *presource);
308
309/* Functions to operate on a general terrain type. */
310bool is_terrain_card_near(const struct civ_map *nmap,
311 const struct tile *ptile,
312 const struct terrain *pterrain,
313 bool check_self);
314bool is_terrain_near_tile(const struct civ_map *nmap,
315 const struct tile *ptile,
316 const struct terrain *pterrain,
317 bool check_self);
319 const struct tile *ptile,
320 bool cardinal_only, bool percentage,
322
323bool is_resource_card_near(const struct civ_map *nmap,
324 const struct tile *ptile,
325 const struct extra_type *pres,
326 bool check_self);
327bool is_resource_near_tile(const struct civ_map *nmap,
328 const struct tile *ptile,
329 const struct extra_type *pres,
330 bool check_self);
331
332struct resource_type *resource_type_init(struct extra_type *pextra);
333void resource_types_free(void);
334
335struct extra_type *resource_extra_get(const struct resource_type *presource);
336
337/* Special helper functions */
340
341int terrain_extra_build_time(const struct terrain *pterrain,
342 enum unit_activity activity,
343 const struct extra_type *tgt);
344int terrain_extra_removal_time(const struct terrain *pterrain,
345 enum unit_activity activity,
346 const struct extra_type *tgt)
347 fc__attribute((nonnull (1, 3)));
348
349/* Functions to operate on a terrain class. */
350const char *terrain_class_name_translation(enum terrain_class tclass);
351
352enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain);
353bool is_terrain_class_card_near(const struct civ_map *nmap,
354 const struct tile *ptile, enum terrain_class tclass);
355bool is_terrain_class_near_tile(const struct civ_map *nmap,
356 const struct tile *ptile, enum terrain_class tclass);
358 const struct tile *ptile,
359 bool cardinal_only, bool percentage,
360 enum terrain_class tclass);
361
362/* Functions to deal with possible terrain alterations. */
363bool terrain_can_support_alteration(const struct terrain *pterrain,
365
366/* Initialization and iteration */
367void terrains_init(void);
368void terrains_free(void);
369
370struct terrain *terrain_array_first(void);
371const struct terrain *terrain_array_last(void);
372
373#define terrain_type_iterate(_p) \
374{ \
375 struct terrain *_p = terrain_array_first(); \
376 if (NULL != _p) { \
377 for (; _p <= terrain_array_last(); _p++) {
378
379#define terrain_type_iterate_end \
380 } \
381 } \
382}
383
384#define terrain_re_active_iterate(_p) \
385 terrain_type_iterate(_p) { \
386 if (!_p->ruledit_disabled) {
387
388#define terrain_re_active_iterate_end \
389 } \
390 } terrain_type_iterate_end;
391
392#define terrain_resources_iterate(pterrain, _res, _freq) \
393 if (NULL != pterrain && NULL != pterrain->resources) { \
394 int _res##_index; \
395 for (_res##_index = 0; \
396 pterrain->resources[_res##_index] != NULL; \
397 _res##_index++) { \
398 struct extra_type *_res = pterrain->resources[_res##_index]; \
399 int _freq = pterrain->resource_freq[_res##_index];
400
401#define terrain_resources_iterate_end \
402 } \
403 }
404
405#ifdef __cplusplus
406}
407#endif /* __cplusplus */
408
409#endif /* FC__TERRAIN_H */
char * incite_cost
Definition comments.c:75
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
int Terrain_type_id
Definition fc_types.h:373
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_LAST
Definition fc_types.h:101
GType type
Definition repodlgs.c:1313
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:215
int placing_time
Definition terrain.h:227
struct terrain * cooler_wetter_result
Definition terrain.h:241
struct extra_type ** resources
Definition terrain.h:204
struct terrain * cooler_drier_result
Definition terrain.h:241
int item_number
Definition terrain.h:183
struct strvec * helptext
Definition terrain.h:263
struct terrain * warmer_wetter_result
Definition terrain.h:240
char graphic_alt2[MAX_LEN_NAME]
Definition terrain.h:189
bv_terrain_flags flags
Definition terrain.h:259
int * resource_freq
Definition terrain.h:205
bv_unit_classes native_to
Definition terrain.h:257
int road_time
Definition terrain.h:213
struct name_translation name
Definition terrain.h:184
int plant_time
Definition terrain.h:219
struct terrain * plant_result
Definition terrain.h:218
int irrigation_food_incr
Definition terrain.h:221
struct terrain * warmer_drier_result
Definition terrain.h:240
int defense_bonus
Definition terrain.h:200
int cultivate_time
Definition terrain.h:216
int movement_cost
Definition terrain.h:199
const struct unit_type * animal
Definition terrain.h:237
int pillage_time
Definition terrain.h:232
int output[O_LAST]
Definition terrain.h:202
int transform_time
Definition terrain.h:231
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:188
int mining_time
Definition terrain.h:225
char identifier_load
Definition terrain.h:192
struct rgbcolor * rgb
Definition terrain.h:261
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:187
enum terrain_class tclass
Definition terrain.h:197
int road_output_incr_pct[O_LAST]
Definition terrain.h:211
int extra_removal_times[MAX_EXTRA_TYPES]
Definition terrain.h:235
struct terrain * transform_result
Definition terrain.h:229
int irrigation_time
Definition terrain.h:222
int base_time
Definition terrain.h:212
int mining_shield_incr
Definition terrain.h:224
void * ruledit_dlg
Definition terrain.h:186
char identifier
Definition terrain.h:191
bool ruledit_disabled
Definition terrain.h:185
Definition tile.h:50
#define fc__attribute(x)
Definition support.h:99
void user_terrain_flags_init(void)
Definition terrain.c:764
void terrains_free(void)
Definition terrain.c:65
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:186
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:612
char terrain_identifier(const struct terrain *pterrain)
Definition terrain.c:126
Terrain_type_id terrain_count(void)
Definition terrain.c:118
void terrains_init(void)
Definition terrain.c:42
struct extra_type * resource_extra_get(const struct resource_type *presource)
Definition terrain.c:296
bool terrain_can_support_alteration(const struct terrain *pterrain, enum terrain_alteration talter)
Definition terrain.c:673
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:633
bool is_terrain_class_card_near(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:591
struct terrain * terrain_by_translated_name(const char *name)
Definition terrain.c:202
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:478
int const char * terrain_class_name_translation(enum terrain_class tclass)
Definition terrain.c:661
const char * get_infrastructure_text(bv_extras extras)
Definition terrain.c:508
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:138
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:395
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
struct terrain * terrain_array_first(void)
Definition terrain.c:96
struct terrain * rand_terrain_by_flag(enum terrain_flag_id flag)
Definition terrain.c:217
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:156
bool is_terrain_card_near(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:327
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
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:416
void resource_types_free(void)
Definition terrain.c:288
void user_terrain_flags_free(void)
Definition terrain.c:776
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:582
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Definition terrain.c:829
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:255
struct resource_type * resource_type_init(struct extra_type *pextra)
Definition terrain.c:272
bool is_terrain_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_flag_id flag)
Definition terrain.c:458
struct extra_type * get_preferred_pillage(bv_extras extras)
Definition terrain.c:550
void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt)
Definition terrain.c:788
const struct terrain * terrain_array_last(void)
Definition terrain.c:107
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:699
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
struct terrain * terrain_by_identifier(const char identifier)
Definition terrain.c:169
bool is_terrain_flag_card_near(const struct civ_map *nmap, const struct tile *ptile, enum terrain_flag_id flag)
Definition terrain.c:438
int terrain_extra_removal_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt) fc__attribute((nonnull(1
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:369
bool is_terrain_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:348