Freeciv21
Develop your civilization from humble roots to a global empire
terrain.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10  */
11 
12 // utility
13 #include "fcintl.h"
14 #include "log.h" // fc_assert
15 #include "rand.h"
16 #include "shared.h"
17 #include "support.h"
18 
19 // common
20 #include "extras.h"
21 #include "game.h"
22 #include "map.h"
23 #include "rgbcolor.h"
24 #include "road.h"
25 
26 #include "terrain.h"
27 
30 
35 {
36  int i;
37 
38  for (i = 0; i < ARRAY_SIZE(civ_terrains); i++) {
39  // Can't use terrain_by_number here because it does a bounds check.
41  civ_terrains[i].ruledit_disabled = false;
42  civ_terrains[i].rgb = nullptr;
43  civ_terrains[i].animal = nullptr;
44  }
45 }
46 
51 {
52  terrain_type_iterate(pterrain)
53  {
54  delete pterrain->helptext;
55  pterrain->helptext = nullptr;
56  delete[] pterrain->resources;
57  pterrain->resources = nullptr;
58  if (pterrain->rgb != nullptr) {
59  /* Server allocates this on ruleset loading, client when
60  * ruleset packet is received. */
61  rgbcolor_destroy(pterrain->rgb);
62  pterrain->rgb = nullptr;
63  }
64  }
66 }
67 
72 {
73  if (game.control.terrain_count > 0) {
74  return civ_terrains;
75  }
76  return nullptr;
77 }
78 
82 const struct terrain *terrain_array_last()
83 {
84  if (game.control.terrain_count > 0) {
85  return &civ_terrains[game.control.terrain_count - 1];
86  }
87  return nullptr;
88 }
89 
93 Terrain_type_id terrain_count() { return game.control.terrain_count; }
94 
98 char terrain_identifier(const struct terrain *pterrain)
99 {
100  fc_assert_ret_val(pterrain, '\0');
101  return pterrain->identifier;
102 }
103 
110 Terrain_type_id terrain_index(const struct terrain *pterrain)
111 {
112  fc_assert_ret_val(pterrain, 0);
113  return pterrain - civ_terrains;
114 }
115 
119 Terrain_type_id terrain_number(const struct terrain *pterrain)
120 {
121  fc_assert_ret_val(pterrain, 0);
122  return pterrain->item_number;
123 }
124 
129 {
130  if (type < 0 || type >= game.control.terrain_count) {
131  // This isn't an error; some T_UNKNOWN callers depend on it.
132  return nullptr;
133  }
134  return &civ_terrains[type];
135 }
136 
140 struct terrain *terrain_by_rule_name(const char *name)
141 {
142  const char *qname = Qn_(name);
143 
144  terrain_type_iterate(pterrain)
145  {
146  if (0 == fc_strcasecmp(terrain_rule_name(pterrain), qname)) {
147  return pterrain;
148  }
149  }
151 
152  return T_UNKNOWN;
153 }
154 
159 {
160  terrain_type_iterate(pterrain)
161  {
162  if (0 == strcmp(terrain_name_translation(pterrain), name)) {
163  return pterrain;
164  }
165  }
167 
168  return T_UNKNOWN;
169 }
170 
175 const char *terrain_name_translation(const struct terrain *pterrain)
176 {
177  return name_translation_get(&pterrain->name);
178 }
179 
184 const char *terrain_rule_name(const struct terrain *pterrain)
185 {
186  return rule_name_get(&pterrain->name);
187 }
188 
192 bool terrain_has_resource(const struct terrain *pterrain,
193  const struct extra_type *presource)
194 {
195  struct extra_type **r = pterrain->resources;
196 
197  while (nullptr != *r) {
198  if (*r == presource) {
199  return true;
200  }
201  r++;
202  }
203  return false;
204 }
205 
210 {
211  auto *presource = new resource_type;
212 
213  pextra->data.resource = presource;
214 
215  presource->self = pextra;
216 
217  return presource;
218 }
219 
224 {
225  // Resource structure itself is freed as part of extras destruction.
226 }
227 
232 #define variable_adjc_iterate(nmap, center_tile, _tile, card_only) \
233  { \
234  enum direction8 *_tile##_list; \
235  int _tile##_count; \
236  \
237  if (card_only) { \
238  _tile##_list = wld.map.cardinal_dirs; \
239  _tile##_count = wld.map.num_cardinal_dirs; \
240  } else { \
241  _tile##_list = wld.map.valid_dirs; \
242  _tile##_count = wld.map.num_valid_dirs; \
243  } \
244  adjc_dirlist_iterate(nmap, center_tile, _tile, _tile##_dir, \
245  _tile##_list, _tile##_count) \
246  {
247 
248 #define variable_adjc_iterate_end \
249  } \
250  adjc_dirlist_iterate_end; \
251  }
252 
256 bool is_terrain_card_near(const struct tile *ptile,
257  const struct terrain *pterrain, bool check_self)
258 {
259  if (!pterrain) {
260  return false;
261  }
262 
263  cardinal_adjc_iterate(&(wld.map), ptile, adjc_tile)
264  {
265  if (tile_terrain(adjc_tile) == pterrain) {
266  return true;
267  }
268  }
270 
271  return check_self && ptile->terrain == pterrain;
272 }
273 
277 bool is_terrain_near_tile(const struct tile *ptile,
278  const struct terrain *pterrain, bool check_self)
279 {
280  if (!pterrain) {
281  return false;
282  }
283 
284  adjc_iterate(&(wld.map), ptile, adjc_tile)
285  {
286  if (tile_terrain(adjc_tile) == pterrain) {
287  return true;
288  }
289  }
291 
292  return check_self && ptile->terrain == pterrain;
293 }
294 
298 int count_terrain_property_near_tile(const struct tile *ptile,
299  bool cardinal_only, bool percentage,
300  enum mapgen_terrain_property prop)
301 {
302  int count = 0, total = 0;
303 
304  variable_adjc_iterate(&(wld.map), ptile, adjc_tile, cardinal_only)
305  {
306  struct terrain *pterrain = tile_terrain(adjc_tile);
307 
308  if (pterrain->property[prop] > 0) {
309  count++;
310  }
311  total++;
312  }
314 
315  if (percentage) {
316  count = count * 100 / std::max(1, total);
317  }
318  return count;
319 }
320 
325 bool is_terrain_flag_card_near(const struct tile *ptile,
326  enum terrain_flag_id flag)
327 {
328  cardinal_adjc_iterate(&(wld.map), ptile, adjc_tile)
329  {
330  struct terrain *pterrain = tile_terrain(adjc_tile);
331 
332  if (T_UNKNOWN != pterrain && terrain_has_flag(pterrain, flag)) {
333  return true;
334  }
335  }
337 
338  return false;
339 }
340 
345 bool is_terrain_flag_near_tile(const struct tile *ptile,
346  enum terrain_flag_id flag)
347 {
348  adjc_iterate(&(wld.map), ptile, adjc_tile)
349  {
350  struct terrain *pterrain = tile_terrain(adjc_tile);
351 
352  if (T_UNKNOWN != pterrain && terrain_has_flag(pterrain, flag)) {
353  return true;
354  }
355  }
357 
358  return false;
359 }
360 
365 int count_terrain_flag_near_tile(const struct tile *ptile,
366  bool cardinal_only, bool percentage,
367  enum terrain_flag_id flag)
368 {
369  int count = 0, total = 0;
370 
371  variable_adjc_iterate(&(wld.map), ptile, adjc_tile, cardinal_only)
372  {
373  struct terrain *pterrain = tile_terrain(adjc_tile);
374 
375  if (T_UNKNOWN != pterrain && terrain_has_flag(pterrain, flag)) {
376  count++;
377  }
378  total++;
379  }
381 
382  if (percentage) {
383  count = count * 100 / std::max(1, total);
384  }
385  return count;
386 }
387 
394 const char *get_infrastructure_text(bv_extras extras)
395 {
396  static char s[256];
397  char *p;
398  int len;
399 
400  s[0] = '\0';
401 
402  extra_type_iterate(pextra)
403  {
404  if (pextra->category == ECAT_INFRA
405  && BV_ISSET(extras, extra_index(pextra))) {
406  bool hidden = false;
407 
408  extra_type_iterate(top)
409  {
410  int topi = extra_index(top);
411 
412  if (BV_ISSET(pextra->hidden_by, topi) && BV_ISSET(extras, topi)) {
413  hidden = true;
414  break;
415  }
416  }
418 
419  if (!hidden) {
420  cat_snprintf(s, sizeof(s), "%s/", extra_name_translation(pextra));
421  }
422  }
423  }
425 
426  len = qstrlen(s);
427  p = s + len - 1;
428  if (len > 0 && *p == '/') {
429  *p = '\0';
430  }
431 
432  return s;
433 }
434 
440 {
441  // Semi-arbitrary preference order reflecting previous behavior
442  static const enum extra_cause prefs[] = {
443  EC_IRRIGATION, EC_MINE, EC_BASE, EC_ROAD, EC_HUT,
444  EC_APPEARANCE, EC_POLLUTION, EC_FALLOUT, EC_RESOURCE, EC_NONE};
445  int i;
446 
447  for (i = 0; i < ARRAY_SIZE(prefs); i++) {
448  extra_type_by_cause_iterate_rev(prefs[i], pextra)
449  {
450  if (is_extra_removed_by(pextra, ERM_PILLAGE)
451  && BV_ISSET(extras, extra_index(pextra))) {
452  return pextra;
453  }
454  }
456  }
457 
458  return nullptr;
459 }
460 
464 enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
465 {
466  return pterrain->tclass;
467 }
468 
473 bool is_terrain_class_card_near(const struct tile *ptile,
474  enum terrain_class tclass)
475 {
476  cardinal_adjc_iterate(&(wld.map), ptile, adjc_tile)
477  {
478  struct terrain *pterrain = tile_terrain(adjc_tile);
479 
480  if (pterrain != T_UNKNOWN) {
481  if (terrain_type_terrain_class(pterrain) == tclass) {
482  return true;
483  }
484  }
485  }
487 
488  return false;
489 }
490 
495 bool is_terrain_class_near_tile(const struct tile *ptile,
496  enum terrain_class tclass)
497 {
498  adjc_iterate(&(wld.map), ptile, adjc_tile)
499  {
500  struct terrain *pterrain = tile_terrain(adjc_tile);
501 
502  if (pterrain != T_UNKNOWN) {
503  if (terrain_type_terrain_class(pterrain) == tclass) {
504  return true;
505  }
506  }
507  }
509 
510  return false;
511 }
512 
517 int count_terrain_class_near_tile(const struct tile *ptile,
518  bool cardinal_only, bool percentage,
519  enum terrain_class tclass)
520 {
521  int count = 0, total = 0;
522 
523  variable_adjc_iterate(&(wld.map), ptile, adjc_tile, cardinal_only)
524  {
525  struct terrain *pterrain = tile_terrain(adjc_tile);
526 
527  if (T_UNKNOWN != pterrain
528  && terrain_type_terrain_class(pterrain) == tclass) {
529  count++;
530  }
531  total++;
532  }
534 
535  if (percentage) {
536  count = count * 100 / std::max(1, total);
537  }
538 
539  return count;
540 }
541 
546 const char *terrain_class_name_translation(enum terrain_class tclass)
547 {
548  if (!terrain_class_is_valid(tclass)) {
549  return nullptr;
550  }
551 
552  return _(terrain_class_name(tclass));
553 }
554 
558 bool terrain_can_support_alteration(const struct terrain *pterrain,
559  enum terrain_alteration alter)
560 {
561  switch (alter) {
562  case TA_CAN_IRRIGATE:
563  return (pterrain == pterrain->irrigation_result);
564  case TA_CAN_MINE:
565  return (pterrain == pterrain->mining_result);
566  case TA_CAN_ROAD:
567  return (pterrain->road_time > 0);
568  default:
569  break;
570  }
571 
572  fc_assert(false);
573  return false;
574 }
575 
579 int terrain_extra_build_time(const struct terrain *pterrain,
580  enum unit_activity activity,
581  const struct extra_type *tgt)
582 {
583  int factor;
584 
585  if (tgt != nullptr && tgt->build_time != 0) {
586  // Extra specific build time
587  return tgt->build_time;
588  }
589 
590  if (tgt == nullptr) {
591  factor = 1;
592  } else {
593  factor = tgt->build_time_factor;
594  }
595 
596  // Terrain and activity specific build time
597  switch (activity) {
598  case ACTIVITY_BASE:
599  return pterrain->base_time * factor;
600  case ACTIVITY_GEN_ROAD:
601  return pterrain->road_time * factor;
602  case ACTIVITY_IRRIGATE:
603  return pterrain->irrigation_time * factor;
604  case ACTIVITY_MINE:
605  return pterrain->mining_time * factor;
606  default:
607  fc_assert(false);
608  return 0;
609  }
610 }
611 
615 int terrain_extra_removal_time(const struct terrain *pterrain,
616  enum unit_activity activity,
617  const struct extra_type *tgt)
618 {
619  int factor;
620 
621  if (tgt != nullptr && tgt->removal_time != 0) {
622  // Extra specific removal time
623  return tgt->removal_time;
624  }
625 
626  if (tgt == nullptr) {
627  factor = 1;
628  } else {
629  factor = tgt->removal_time_factor;
630  }
631 
632  // Terrain and activity specific removal time
633  switch (activity) {
634  case ACTIVITY_POLLUTION:
635  return pterrain->clean_pollution_time * factor;
636  case ACTIVITY_FALLOUT:
637  return pterrain->clean_fallout_time * factor;
638  case ACTIVITY_PILLAGE:
639  return pterrain->pillage_time * factor;
640  default:
641  fc_assert(false);
642  return 0;
643  }
644 }
645 
650 {
651  int i;
652 
653  for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
655  }
656 }
657 
662 {
663  int i;
664 
665  for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
667  }
668 }
669 
673 void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name,
674  const char *helptxt)
675 {
676  int tfid = id - TER_USER_1;
677 
678  fc_assert_ret(id >= TER_USER_1 && id <= TER_USER_LAST);
679 
680  delete[] user_terrain_flags[tfid].name;
681  user_terrain_flags[tfid].name = nullptr;
682  if (name && name[0] != '\0') {
684  }
685 
686  delete[] user_terrain_flags[tfid].helptxt;
687  user_terrain_flags[tfid].helptxt = nullptr;
688  if (helptxt && helptxt[0] != '\0') {
689  user_terrain_flags[tfid].helptxt = fc_strdup(helptxt);
690  }
691 }
692 
696 const char *terrain_flag_id_name_cb(enum terrain_flag_id flag)
697 {
698  if (flag < TER_USER_1 || flag > TER_USER_LAST) {
699  return nullptr;
700  }
701 
702  return user_terrain_flags[flag - TER_USER_1].name;
703 }
704 
708 const char *terrain_flag_helptxt(enum terrain_flag_id id)
709 {
710  fc_assert(id >= TER_USER_1 && id <= TER_USER_LAST);
711 
712  return user_terrain_flags[id - TER_USER_1].helptxt;
713 }
bool BV_ISSET(const BV &bv, int bit)
Definition: bitvector.h:37
char * extras
Definition: comments.cpp:34
const char * extra_name_translation(const struct extra_type *pextra)
Return the (translated) name of the extra type.
Definition: extras.cpp:165
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Is given cause one of the removal causes for the given extra?
Definition: extras.cpp:307
#define extra_type_by_cause_iterate_rev(_cause, _extra)
Definition: extras.h:313
#define extra_type_by_cause_iterate_rev_end
Definition: extras.h:319
#define extra_type_iterate(_p)
Definition: extras.h:279
#define extra_type_iterate_end
Definition: extras.h:285
#define extra_index(_e_)
Definition: extras.h:163
int Terrain_type_id
Definition: fc_types.h:290
#define EC_NONE
Definition: fc_types.h:934
#define _(String)
Definition: fcintl.h:50
#define Qn_(String)
Definition: fcintl.h:66
void user_flag_init(struct user_flag *flag)
Initialize user flag.
Definition: game.cpp:788
void user_flag_free(struct user_flag *flag)
Free user flag.
Definition: game.cpp:797
struct civ_game game
Definition: game.cpp:47
struct world wld
Definition: game.cpp:48
const char * name
Definition: inputfile.cpp:118
#define fc_assert_ret(condition)
Definition: log.h:112
#define fc_assert(condition)
Definition: log.h:89
#define fc_assert_ret_val(condition, val)
Definition: log.h:114
#define adjc_iterate_end
Definition: map.h:358
#define cardinal_adjc_iterate_end
Definition: map.h:384
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition: map.h:351
#define cardinal_adjc_iterate(nmap, center_tile, itr_tile)
Definition: map.h:380
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
int len
Definition: packhand.cpp:127
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Free rgbcolor structure.
Definition: rgbcolor.cpp:65
#define ARRAY_SIZE(x)
Definition: shared.h:79
struct packet_ruleset_control control
Definition: game.h:74
struct resource_type * resource
Definition: extras.h:136
int removal_time
Definition: extras.h:104
int build_time_factor
Definition: extras.h:103
struct extra_type::@22 data
int removal_time_factor
Definition: extras.h:105
int build_time
Definition: extras.h:102
struct extra_type * self
Definition: terrain.h:45
int property[MG_COUNT]
Definition: terrain.h:232
struct extra_type ** resources
Definition: terrain.h:190
int item_number
Definition: terrain.h:171
int road_time
Definition: terrain.h:194
struct name_translation name
Definition: terrain.h:172
int clean_fallout_time
Definition: terrain.h:213
struct terrain * irrigation_result
Definition: terrain.h:200
const struct unit_type * animal
Definition: terrain.h:216
int pillage_time
Definition: terrain.h:214
struct terrain * mining_result
Definition: terrain.h:204
int mining_time
Definition: terrain.h:206
struct rgbcolor * rgb
Definition: terrain.h:240
int clean_pollution_time
Definition: terrain.h:212
enum terrain_class tclass
Definition: terrain.h:183
int irrigation_time
Definition: terrain.h:202
int base_time
Definition: terrain.h:193
char identifier
Definition: terrain.h:177
bool ruledit_disabled
Definition: terrain.h:173
Definition: tile.h:42
struct terrain * terrain
Definition: tile.h:49
Definition: game.h:64
char * name
Definition: game.h:65
char * helptxt
Definition: game.h:66
struct civ_map map
Definition: world_object.h:21
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
Definition: support.cpp:89
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
Definition: support.cpp:564
#define fc_strdup(str)
Definition: support.h:111
int terrain_extra_removal_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Time to complete the extra removal activity on the given terrain.
Definition: terrain.cpp:615
Terrain_type_id terrain_count()
Return the number of terrains.
Definition: terrain.cpp:93
char terrain_identifier(const struct terrain *pterrain)
Return the terrain identifier.
Definition: terrain.cpp:98
struct extra_type * get_preferred_pillage(bv_extras extras)
Returns the highest-priority (best) extra to be pillaged from the terrain set.
Definition: terrain.cpp:439
void user_terrain_flags_init()
Initialize user terrain type flags.
Definition: terrain.cpp:649
int count_terrain_flag_near_tile(const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_flag_id flag)
Return the number of adjacent tiles that have terrain with the given flag (not including ptile itself...
Definition: terrain.cpp:365
bool is_terrain_class_card_near(const struct tile *ptile, enum terrain_class tclass)
Is there terrain of the given class cardinally near tile? (Does not check ptile itself....
Definition: terrain.cpp:473
bool is_terrain_flag_near_tile(const struct tile *ptile, enum terrain_flag_id flag)
Returns TRUE iff any adjacent tile contains terrain with the given flag (does not check ptile itself)...
Definition: terrain.cpp:345
bool is_terrain_flag_card_near(const struct tile *ptile, enum terrain_flag_id flag)
Returns TRUE iff any cardinally adjacent tile contains terrain with the given flag (does not check pt...
Definition: terrain.cpp:325
struct terrain * terrain_by_translated_name(const char *name)
Return the terrain type matching the name, or T_UNKNOWN if none matches.
Definition: terrain.cpp:158
struct terrain * terrain_by_number(const Terrain_type_id type)
Return the terrain for the given terrain index.
Definition: terrain.cpp:128
const char * terrain_rule_name(const struct terrain *pterrain)
Return the (untranslated) rule name of the terrain.
Definition: terrain.cpp:184
int count_terrain_property_near_tile(const struct tile *ptile, bool cardinal_only, bool percentage, enum mapgen_terrain_property prop)
Return the number of adjacent tiles that have the given terrain property.
Definition: terrain.cpp:298
const char * terrain_flag_id_name_cb(enum terrain_flag_id flag)
Terrain flag name callback, called from specenum code.
Definition: terrain.cpp:696
struct resource_type * resource_type_init(struct extra_type *pextra)
Initialize resource_type structure.
Definition: terrain.cpp:209
void terrains_free()
Free memory which is associated with terrain types.
Definition: terrain.cpp:50
struct terrain * terrain_by_rule_name(const char *name)
Return the terrain type matching the name, or T_UNKNOWN if none matches.
Definition: terrain.cpp:140
const char * terrain_class_name_translation(enum terrain_class tclass)
Return the (translated) name of the given terrain class.
Definition: terrain.cpp:546
Terrain_type_id terrain_index(const struct terrain *pterrain)
Return the terrain index.
Definition: terrain.cpp:110
#define variable_adjc_iterate(nmap, center_tile, _tile, card_only)
This iterator behaves like adjc_iterate or cardinal_adjc_iterate depending on the value of card_only.
Definition: terrain.cpp:232
bool is_terrain_near_tile(const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Returns TRUE iff any adjacent tile contains the given terrain.
Definition: terrain.cpp:277
const char * get_infrastructure_text(bv_extras extras)
Return a (static) string with extra(s) name(s): eg: "Mine" eg: "Road/Farmland" This only includes "in...
Definition: terrain.cpp:394
const struct terrain * terrain_array_last()
Return the last item of terrains.
Definition: terrain.cpp:82
bool terrain_can_support_alteration(const struct terrain *pterrain, enum terrain_alteration alter)
Can terrain support given infrastructure?
Definition: terrain.cpp:558
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Return the (untranslated) helptxt of the user terrain flag.
Definition: terrain.cpp:708
bool is_terrain_card_near(const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Returns TRUE iff any cardinally adjacent tile contains the given terrain.
Definition: terrain.cpp:256
void user_terrain_flags_free()
Frees the memory associated with all user terrain flags.
Definition: terrain.cpp:661
bool is_terrain_class_near_tile(const struct tile *ptile, enum terrain_class tclass)
Is there terrain of the given class near tile? (Does not check ptile itself.)
Definition: terrain.cpp:495
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
What terrain class terrain type belongs to.
Definition: terrain.cpp:464
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Check for resource in terrain resources list.
Definition: terrain.cpp:192
void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt)
Sets user defined name for terrain flag.
Definition: terrain.cpp:673
static struct terrain civ_terrains[MAX_NUM_TERRAINS]
Definition: terrain.cpp:28
const char * terrain_name_translation(const struct terrain *pterrain)
Return the (translated) name of the terrain.
Definition: terrain.cpp:175
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Time to complete the extra building activity on the given terrain.
Definition: terrain.cpp:579
static struct user_flag user_terrain_flags[MAX_NUM_USER_TER_FLAGS]
Definition: terrain.cpp:29
Terrain_type_id terrain_number(const struct terrain *pterrain)
Return the terrain index.
Definition: terrain.cpp:119
int count_terrain_class_near_tile(const struct tile *ptile, bool cardinal_only, bool percentage, enum terrain_class tclass)
Return the number of adjacent tiles that have given terrain class (not including ptile itself).
Definition: terrain.cpp:517
struct terrain * terrain_array_first()
Return the first item of terrains.
Definition: terrain.cpp:71
#define variable_adjc_iterate_end
Definition: terrain.cpp:248
void resource_types_free()
Free the memory associated with resource types.
Definition: terrain.cpp:223
void terrains_init()
Initialize terrain and resource structures.
Definition: terrain.cpp:34
#define terrain_type_iterate(_p)
Definition: terrain.h:331
#define T_UNKNOWN
Definition: terrain.h:51
#define terrain_type_iterate_end
Definition: terrain.h:337
#define MAX_NUM_TERRAINS
Definition: terrain.h:58
#define terrain_has_flag(terr, flag)
Definition: terrain.h:260
#define MAX_NUM_USER_TER_FLAGS
Definition: terrain.h:140
#define tile_terrain(_tile)
Definition: tile.h:93