Freeciv-3.3
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
29/* gen_headers/enums */
30#include "terrain_enums_gen.h"
31
32#define MAX_NUM_USER_TER_FLAGS (TER_USER_LAST - TER_USER_1 + 1)
33
34struct base_type;
35struct strvec; /* Actually defined in "utility/string_vector.h". */
36struct rgbcolor;
37
38/* Used in the network protocol. */
45
46/* === */
47
49
50 char id_old_save; /* Single-character identifier used in old savegames. */
51#define RESOURCE_NULL_IDENTIFIER '\0'
52#define RESOURCE_NONE_IDENTIFIER ' '
53
54 int output[O_LAST]; /* Amount added by this resource. */
55
57};
58
59/* === */
60
61#define T_NONE (NULL) /* A special flag meaning no terrain type. */
62#define T_UNKNOWN (NULL) /* An unknown terrain. */
63
64/* The first terrain value. */
65#define T_FIRST 0
66
67/* A hard limit on the number of terrains; useful for static arrays.
68 * Used in the network protocol. */
69#define MAX_NUM_TERRAINS (96)
70
71/*
72 * This struct gives data about each terrain type. There are many ways
73 * it could be extended.
74 */
75struct terrain {
78 bool ruledit_disabled; /* Does not really exist - hole in terrain array */
83
84 char identifier; /* Single-character identifier used in games saved. */
85 char identifier_load; /* Single-character identifier that was used in the savegame
86 * loaded. */
87
88#define TERRAIN_UNKNOWN_IDENTIFIER 'u'
89
91
92 int movement_cost; /* whole MP, not scaled by SINGLE_MOVE */
93 int defense_bonus; /* % defense bonus - defaults to zero */
94
96
97 struct extra_type **resources; /* NULL-terminated */
98 int *resource_freq; /* same length as resources */
99
100#define RESOURCE_FREQUENCY_MINIMUM (0)
101#define RESOURCE_FREQUENCY_DEFAULT (1)
102#define RESOURCE_FREQUENCY_MAXIMUM (255)
103
107
110
113
116
119
121
123
126
127 /* Currently only clean times, but named for future */
129
130 const struct unit_type *animal;
131
132 /* May be NULL if the transformation is impossible. */
135
136 /* These are special properties of the terrain used by mapgen. If a tile
137 * has a property, then the value gives the weighted amount of tiles that
138 * will be assigned this terrain.
139 *
140 * For instance if mountains have 70 and hills have 30 of MG_MOUNTAINOUS
141 * then 70% of 'mountainous' tiles will be given mountains.
142 *
143 * Ocean_depth is different. Instead of a percentage, the depth of the
144 * tile in the range 0 (never chosen) to 100 (deepest) is used.
145 */
146 int property[MG_COUNT];
147#define TERRAIN_OCEAN_DEPTH_MINIMUM (1)
148#define TERRAIN_OCEAN_DEPTH_MAXIMUM (100)
149
151
153
154 struct rgbcolor *rgb;
155
157};
158
159/* General terrain accessor functions. */
161Terrain_type_id terrain_index(const struct terrain *pterrain);
162Terrain_type_id terrain_number(const struct terrain *pterrain);
163
165
166struct terrain *terrain_by_identifier(const char identifier);
167struct terrain *terrain_by_rule_name(const char *name);
168struct terrain *terrain_by_translated_name(const char *name);
170
171char terrain_identifier(const struct terrain *pterrain);
172const char *terrain_rule_name(const struct terrain *pterrain);
173const char *terrain_name_translation(const struct terrain *pterrain);
174
175/* Functions to operate on a terrain flag. */
176#define terrain_has_flag(terr, flag) BV_ISSET((terr)->flags, flag)
177
178bool is_terrain_flag_card_near(const struct civ_map *nmap,
179 const struct tile *ptile,
180 enum terrain_flag_id flag);
181bool is_terrain_flag_near_tile(const struct civ_map *nmap,
182 const struct tile *ptile,
183 enum terrain_flag_id flag);
185 const struct tile *ptile,
186 bool cardinal_only, bool percentage,
187 enum terrain_flag_id flag);
188void user_terrain_flags_init(void);
189void user_terrain_flags_free(void);
190void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt);
191const char *terrain_flag_helptxt(enum terrain_flag_id id);
192
193/* Terrain-specific functions. */
194#define is_ocean(pterrain) ((pterrain) != T_UNKNOWN \
195 && terrain_type_terrain_class(pterrain) == TC_OCEAN)
196#define is_ocean_tile(ptile) \
197 is_ocean(tile_terrain(ptile))
198
199bool terrain_has_resource(const struct terrain *pterrain,
200 const struct extra_type *presource);
201
202/* Functions to operate on a general terrain type. */
203bool is_terrain_card_near(const struct civ_map *nmap,
204 const struct tile *ptile,
205 const struct terrain *pterrain,
206 bool check_self);
207bool is_terrain_near_tile(const struct civ_map *nmap,
208 const struct tile *ptile,
209 const struct terrain *pterrain,
210 bool check_self);
212 const struct tile *ptile,
213 bool cardinal_only, bool percentage,
215
216bool is_resource_card_near(const struct civ_map *nmap,
217 const struct tile *ptile,
218 const struct extra_type *pres,
219 bool check_self);
220bool is_resource_near_tile(const struct civ_map *nmap,
221 const struct tile *ptile,
222 const struct extra_type *pres,
223 bool check_self);
224
225struct resource_type *resource_type_init(struct extra_type *pextra);
226void resource_types_free(void);
227
228struct extra_type *resource_extra_get(const struct resource_type *presource);
229
230/* Special helper functions */
233
234int terrain_extra_build_time(const struct terrain *pterrain,
235 enum unit_activity activity,
236 const struct extra_type *tgt);
237int terrain_extra_removal_time(const struct terrain *pterrain,
238 enum unit_activity activity,
239 const struct extra_type *tgt)
240 fc__attribute((nonnull (1, 3)));
241
242/* Functions to operate on a terrain class. */
243const char *terrain_class_name_translation(enum terrain_class tclass);
244
245enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain);
246bool is_terrain_class_card_near(const struct civ_map *nmap,
247 const struct tile *ptile, enum terrain_class tclass);
248bool is_terrain_class_near_tile(const struct civ_map *nmap,
249 const struct tile *ptile, enum terrain_class tclass);
251 const struct tile *ptile,
252 bool cardinal_only, bool percentage,
253 enum terrain_class tclass);
254
255/* Functions to deal with possible terrain alterations. */
256bool terrain_can_support_alteration(const struct terrain *pterrain,
258
259/* Initialization and iteration */
260void terrains_init(void);
261void terrains_free(void);
262
263struct terrain *terrain_array_first(void);
264const struct terrain *terrain_array_last(void);
265
266#define terrain_type_iterate(_p) \
267{ \
268 struct terrain *_p = terrain_array_first(); \
269 if (NULL != _p) { \
270 for (; _p <= terrain_array_last(); _p++) {
271
272#define terrain_type_iterate_end \
273 } \
274 } \
275}
276
277#define terrain_re_active_iterate(_p) \
278 terrain_type_iterate(_p) { \
279 if (!_p->ruledit_disabled) {
280
281#define terrain_re_active_iterate_end \
282 } \
283 } terrain_type_iterate_end;
284
285#define terrain_resources_iterate(pterrain, _res, _freq) \
286 if (NULL != pterrain && NULL != pterrain->resources) { \
287 int _res##_index; \
288 for (_res##_index = 0; \
289 pterrain->resources[_res##_index] != NULL; \
290 _res##_index++) { \
291 struct extra_type *_res = pterrain->resources[_res##_index]; \
292 int _freq = pterrain->resource_freq[_res##_index];
293
294#define terrain_resources_iterate_end \
295 } \
296 }
297
298#ifdef __cplusplus
299}
300#endif /* __cplusplus */
301
302#endif /* FC__TERRAIN_H */
char * incite_cost
Definition comments.c:76
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
int Terrain_type_id
Definition fc_types.h:232
#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:56
char id_old_save
Definition terrain.h:50
int output[O_LAST]
Definition terrain.h:54
struct terrain * cultivate_result
Definition terrain.h:108
int placing_time
Definition terrain.h:120
struct terrain * cooler_wetter_result
Definition terrain.h:134
struct extra_type ** resources
Definition terrain.h:97
struct terrain * cooler_drier_result
Definition terrain.h:134
int item_number
Definition terrain.h:76
struct strvec * helptext
Definition terrain.h:156
struct terrain * warmer_wetter_result
Definition terrain.h:133
char graphic_alt2[MAX_LEN_NAME]
Definition terrain.h:82
bv_terrain_flags flags
Definition terrain.h:152
int * resource_freq
Definition terrain.h:98
bv_unit_classes native_to
Definition terrain.h:150
int road_time
Definition terrain.h:106
struct name_translation name
Definition terrain.h:77
int plant_time
Definition terrain.h:112
struct terrain * plant_result
Definition terrain.h:111
int irrigation_food_incr
Definition terrain.h:114
struct terrain * warmer_drier_result
Definition terrain.h:133
int defense_bonus
Definition terrain.h:93
int cultivate_time
Definition terrain.h:109
int movement_cost
Definition terrain.h:92
const struct unit_type * animal
Definition terrain.h:130
int pillage_time
Definition terrain.h:125
int output[O_LAST]
Definition terrain.h:95
int transform_time
Definition terrain.h:124
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:81
int mining_time
Definition terrain.h:118
char identifier_load
Definition terrain.h:85
struct rgbcolor * rgb
Definition terrain.h:154
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:80
enum terrain_class tclass
Definition terrain.h:90
int road_output_incr_pct[O_LAST]
Definition terrain.h:104
int extra_removal_times[MAX_EXTRA_TYPES]
Definition terrain.h:128
struct terrain * transform_result
Definition terrain.h:122
int irrigation_time
Definition terrain.h:115
int base_time
Definition terrain.h:105
int mining_shield_incr
Definition terrain.h:117
void * ruledit_dlg
Definition terrain.h:79
char identifier
Definition terrain.h:84
bool ruledit_disabled
Definition terrain.h:78
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:39
@ RMV_NORMAL
Definition terrain.h:40
@ RMV_FAST_RELAXED
Definition terrain.h:42
@ RMV_FAST_STRICT
Definition terrain.h:41
@ RMV_FAST_ALWAYS
Definition terrain.h:43
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