Freeciv-3.3: /fast/freeciv/nightly/main/common/terrain.h Source File

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. */
39 enum special_river_move {
40 RMV_NORMAL = 0,
41 RMV_FAST_STRICT = 1,
42 RMV_FAST_RELAXED = 2,
43 RMV_FAST_ALWAYS = 3,
44};
45
46/* === */
47
48 struct resource_type {
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
56 struct extra_type *self;
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 */
75 struct terrain {
76 int item_number;
77 struct name_translation name;
78 bool ruledit_disabled; /* Does not really exist - hole in terrain array */
79 void *ruledit_dlg;
80 char graphic_str[MAX_LEN_NAME];
81 char graphic_alt[MAX_LEN_NAME];
82 char graphic_alt2[MAX_LEN_NAME];
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
90 enum terrain_class tclass;
91
92 int movement_cost; /* whole MP, not scaled by SINGLE_MOVE */
93 int defense_bonus; /* % defense bonus - defaults to zero */
94
95 int output[O_LAST];
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
104 int road_output_incr_pct[O_LAST];
105 int base_time;
106 int road_time;
107
108 struct terrain *cultivate_result;
109 int cultivate_time;
110
111 struct terrain *plant_result;
112 int plant_time;
113
114 int irrigation_food_incr;
115 int irrigation_time;
116
117 int mining_shield_incr;
118 int mining_time;
119
120 int placing_time;
121
122 struct terrain *transform_result;
123
124 int transform_time;
125 int pillage_time;
126
127 /* Currently only clean times, but named for future */
128 int extra_removal_times[MAX_EXTRA_TYPES];
129
130 const struct unit_type *animal;
131
132 /* May be NULL if the transformation is impossible. */
133 struct terrain *warmer_wetter_result, *warmer_drier_result;
134 struct terrain *cooler_wetter_result, *cooler_drier_result;
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
150 bv_unit_classes native_to;
151
152 bv_terrain_flags flags;
153
154 struct rgbcolor *rgb;
155
156 struct strvec *helptext;
157};
158
159/* General terrain accessor functions. */
160 Terrain_type_id terrain_count(void);
161 Terrain_type_id terrain_index(const struct terrain *pterrain);
162 Terrain_type_id terrain_number(const struct terrain *pterrain);
163
164struct terrain *terrain_by_number(const Terrain_type_id type);
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);
169struct terrain *rand_terrain_by_flag(enum terrain_flag_id flag);
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);
184int count_terrain_flag_near_tile(const struct civ_map *nmap,
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);
211int count_terrain_property_near_tile(const struct civ_map *nmap,
212 const struct tile *ptile,
213 bool cardinal_only, bool percentage,
214 enum mapgen_terrain_property prop);
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 */
231const char *get_infrastructure_text(bv_extras extras);
232struct extra_type *get_preferred_pillage(bv_extras extras);
233
234int terrain_extra_build_time(const struct terrain *pterrain,
235 enum unit_activity activity,
236 const struct extra_type *tgt);
237 int 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);
250int count_terrain_class_near_tile(const struct civ_map *nmap,
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,
257 enum terrain_alteration talter);
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 */
bitvector.h
incite_cost
char * incite_cost
Definition comments.c:74
extras
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
fc_types.h
Terrain_type_id
int Terrain_type_id
Definition fc_types.h:377
MAX_EXTRA_TYPES
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
O_LAST
@ O_LAST
Definition fc_types.h:101
type
GType type
Definition repodlgs.c:1313
name
const char * name
Definition inputfile.c:127
name_translation.h
shared.h
base_type
Definition base.h:41
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:88
name_translation
Definition name_translation.h:35
resource_type
Definition terrain.h:48
resource_type::self
struct extra_type * self
Definition terrain.h:56
resource_type::id_old_save
char id_old_save
Definition terrain.h:50
resource_type::output
int output[O_LAST]
Definition terrain.h:54
rgbcolor
Definition rgbcolor.h:33
strvec
Definition string_vector.c:29
terrain
Definition terrain.h:75
terrain::cultivate_result
struct terrain * cultivate_result
Definition terrain.h:108
terrain::placing_time
int placing_time
Definition terrain.h:120
terrain::cooler_wetter_result
struct terrain * cooler_wetter_result
Definition terrain.h:134
terrain::resources
struct extra_type ** resources
Definition terrain.h:97
terrain::cooler_drier_result
struct terrain * cooler_drier_result
Definition terrain.h:134
terrain::item_number
int item_number
Definition terrain.h:76
terrain::helptext
struct strvec * helptext
Definition terrain.h:156
terrain::warmer_wetter_result
struct terrain * warmer_wetter_result
Definition terrain.h:133
terrain::graphic_alt2
char graphic_alt2[MAX_LEN_NAME]
Definition terrain.h:82
terrain::flags
bv_terrain_flags flags
Definition terrain.h:152
terrain::resource_freq
int * resource_freq
Definition terrain.h:98
terrain::native_to
bv_unit_classes native_to
Definition terrain.h:150
terrain::road_time
int road_time
Definition terrain.h:106
terrain::name
struct name_translation name
Definition terrain.h:77
terrain::plant_time
int plant_time
Definition terrain.h:112
terrain::plant_result
struct terrain * plant_result
Definition terrain.h:111
terrain::irrigation_food_incr
int irrigation_food_incr
Definition terrain.h:114
terrain::warmer_drier_result
struct terrain * warmer_drier_result
Definition terrain.h:133
terrain::defense_bonus
int defense_bonus
Definition terrain.h:93
terrain::cultivate_time
int cultivate_time
Definition terrain.h:109
terrain::movement_cost
int movement_cost
Definition terrain.h:92
terrain::animal
const struct unit_type * animal
Definition terrain.h:130
terrain::pillage_time
int pillage_time
Definition terrain.h:125
terrain::output
int output[O_LAST]
Definition terrain.h:95
terrain::transform_time
int transform_time
Definition terrain.h:124
terrain::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:81
terrain::mining_time
int mining_time
Definition terrain.h:118
terrain::identifier_load
char identifier_load
Definition terrain.h:85
terrain::rgb
struct rgbcolor * rgb
Definition terrain.h:154
terrain::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:80
terrain::tclass
enum terrain_class tclass
Definition terrain.h:90
terrain::road_output_incr_pct
int road_output_incr_pct[O_LAST]
Definition terrain.h:104
terrain::extra_removal_times
int extra_removal_times[MAX_EXTRA_TYPES]
Definition terrain.h:128
terrain::transform_result
struct terrain * transform_result
Definition terrain.h:122
terrain::irrigation_time
int irrigation_time
Definition terrain.h:115
terrain::base_time
int base_time
Definition terrain.h:105
terrain::mining_shield_incr
int mining_shield_incr
Definition terrain.h:117
terrain::ruledit_dlg
void * ruledit_dlg
Definition terrain.h:79
terrain::identifier
char identifier
Definition terrain.h:84
terrain::ruledit_disabled
bool ruledit_disabled
Definition terrain.h:78
tile
Definition tile.h:50
unit_type
Definition unittype.h:507
fc__attribute
#define fc__attribute(x)
Definition support.h:99
user_terrain_flags_init
void user_terrain_flags_init(void)
Definition terrain.c:764
terrains_free
void terrains_free(void)
Definition terrain.c:65
terrain_by_rule_name
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:186
is_terrain_class_near_tile
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:612
terrain_identifier
char terrain_identifier(const struct terrain *pterrain)
Definition terrain.c:126
terrain_count
Terrain_type_id terrain_count(void)
Definition terrain.c:118
terrains_init
void terrains_init(void)
Definition terrain.c:42
resource_extra_get
struct extra_type * resource_extra_get(const struct resource_type *presource)
Definition terrain.c:296
terrain_can_support_alteration
bool terrain_can_support_alteration(const struct terrain *pterrain, enum terrain_alteration talter)
Definition terrain.c:673
count_terrain_class_near_tile
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
is_terrain_class_card_near
bool is_terrain_class_card_near(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:591
terrain_by_translated_name
struct terrain * terrain_by_translated_name(const char *name)
Definition terrain.c:202
count_terrain_flag_near_tile
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
terrain_class_name_translation
int const char * terrain_class_name_translation(enum terrain_class tclass)
Definition terrain.c:661
get_infrastructure_text
const char * get_infrastructure_text(bv_extras extras)
Definition terrain.c:508
terrain_index
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:138
is_resource_card_near
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
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
terrain_array_first
struct terrain * terrain_array_first(void)
Definition terrain.c:96
rand_terrain_by_flag
struct terrain * rand_terrain_by_flag(enum terrain_flag_id flag)
Definition terrain.c:217
terrain_by_number
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:156
is_terrain_card_near
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
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
is_resource_near_tile
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
resource_types_free
void resource_types_free(void)
Definition terrain.c:288
user_terrain_flags_free
void user_terrain_flags_free(void)
Definition terrain.c:776
terrain_type_terrain_class
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:582
terrain_flag_helptxt
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Definition terrain.c:829
terrain_has_resource
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:255
resource_type_init
struct resource_type * resource_type_init(struct extra_type *pextra)
Definition terrain.c:272
is_terrain_flag_near_tile
bool is_terrain_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_flag_id flag)
Definition terrain.c:458
get_preferred_pillage
struct extra_type * get_preferred_pillage(bv_extras extras)
Definition terrain.c:550
set_user_terrain_flag_name
void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt)
Definition terrain.c:788
terrain_array_last
const struct terrain * terrain_array_last(void)
Definition terrain.c:107
terrain_extra_build_time
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:699
terrain_number
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
terrain_by_identifier
struct terrain * terrain_by_identifier(const char identifier)
Definition terrain.c:169
is_terrain_flag_card_near
bool is_terrain_flag_card_near(const struct civ_map *nmap, const struct tile *ptile, enum terrain_flag_id flag)
Definition terrain.c:438
terrain_extra_removal_time
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
special_river_move
Definition terrain.h:39
RMV_NORMAL
@ RMV_NORMAL
Definition terrain.h:40
RMV_FAST_RELAXED
@ RMV_FAST_RELAXED
Definition terrain.h:42
RMV_FAST_STRICT
@ RMV_FAST_STRICT
Definition terrain.h:41
RMV_FAST_ALWAYS
@ RMV_FAST_ALWAYS
Definition terrain.h:43
count_terrain_property_near_tile
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
is_terrain_near_tile
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
unittype.h