Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/terrain.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
terrain.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2003 - The Freeciv Project
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "log.h" /* fc_assert */
21#include "mem.h" /* free */
22#include "rand.h"
23#include "shared.h"
24#include "string_vector.h"
25#include "support.h"
26
27/* common */
28#include "extras.h"
29#include "game.h"
30#include "map.h"
31#include "rgbcolor.h"
32#include "road.h"
33
34#include "terrain.h"
35
36 static struct terrain civ_terrains[MAX_NUM_TERRAINS];
37 static struct user_flag user_terrain_flags[MAX_NUM_USER_TER_FLAGS];
38
39/**********************************************************************/
42 void terrains_init(void)
43{
44 int i;
45
46 for (i = 0; i < ARRAY_SIZE(civ_terrains); i++) {
47 /* Can't use terrain_by_number here because it does a bounds check. */
48 civ_terrains[i].item_number = i;
49 civ_terrains[i].ruledit_disabled = FALSE;
50 civ_terrains[i].ruledit_dlg = NULL;
51 civ_terrains[i].rgb = NULL;
52 civ_terrains[i].animal = NULL;
53 }
54}
55
56/**********************************************************************/
59 void terrains_free(void)
60{
61 terrain_type_iterate(pterrain) {
62 if (NULL != pterrain->helptext) {
63 strvec_destroy(pterrain->helptext);
64 pterrain->helptext = NULL;
65 }
66 if (pterrain->resources != NULL) {
67 /* Server allocates this on ruleset loading, client when
68 * ruleset packet is received. */
69 free(pterrain->resources);
70 pterrain->resources = NULL;
71 }
72 if (pterrain->rgb != NULL) {
73 /* Server allocates this on ruleset loading, client when
74 * ruleset packet is received. */
75 rgbcolor_destroy(pterrain->rgb);
76 pterrain->rgb = NULL;
77 }
78 } terrain_type_iterate_end;
79}
80
81/**********************************************************************/
84 struct terrain *terrain_array_first(void)
85{
86 if (game.control.terrain_count > 0) {
87 return civ_terrains;
88 }
89 return NULL;
90}
91
92/**********************************************************************/
95 const struct terrain *terrain_array_last(void)
96{
97 if (game.control.terrain_count > 0) {
98 return &civ_terrains[game.control.terrain_count - 1];
99 }
100 return NULL;
101}
102
103/**********************************************************************/
106 Terrain_type_id terrain_count(void)
107{
108 return game.control.terrain_count;
109}
110
111/**********************************************************************/
114 char terrain_identifier(const struct terrain *pterrain)
115{
116 fc_assert_ret_val(pterrain, '\0');
117 return pterrain->identifier;
118}
119
120/**********************************************************************/
126 Terrain_type_id terrain_index(const struct terrain *pterrain)
127{
128 fc_assert_ret_val(pterrain, -1);
129 return pterrain - civ_terrains;
130}
131
132/**********************************************************************/
135 Terrain_type_id terrain_number(const struct terrain *pterrain)
136{
137 fc_assert_ret_val(pterrain, -1);
138 return pterrain->item_number;
139}
140
141/**********************************************************************/
144 struct terrain *terrain_by_number(const Terrain_type_id type)
145{
146 if (type < 0 || type >= game.control.terrain_count) {
147 /* This isn't an error; some T_UNKNOWN callers depend on it. */
148 return NULL;
149 }
150 return &civ_terrains[type];
151}
152
153/**********************************************************************/
157 struct terrain *terrain_by_identifier(const char identifier)
158{
159 if (TERRAIN_UNKNOWN_IDENTIFIER == identifier) {
160 return T_UNKNOWN;
161 }
162 terrain_type_iterate(pterrain) {
163 if (pterrain->identifier == identifier) {
164 return pterrain;
165 }
166 } terrain_type_iterate_end;
167
168 return T_UNKNOWN;
169}
170
171/**********************************************************************/
174 struct terrain *terrain_by_rule_name(const char *name)
175{
176 const char *qname = Qn_(name);
177
178 terrain_type_iterate(pterrain) {
179 if (0 == fc_strcasecmp(terrain_rule_name(pterrain), qname)) {
180 return pterrain;
181 }
182 } terrain_type_iterate_end;
183
184 return T_UNKNOWN;
185}
186
187/**********************************************************************/
190 struct terrain *terrain_by_translated_name(const char *name)
191{
192 terrain_type_iterate(pterrain) {
193 if (0 == strcmp(terrain_name_translation(pterrain), name)) {
194 return pterrain;
195 }
196 } terrain_type_iterate_end;
197
198 return T_UNKNOWN;
199}
200
201/**********************************************************************/
205 struct terrain *rand_terrain_by_flag(enum terrain_flag_id flag)
206{
207 int num = 0;
208 struct terrain *terr = NULL;
209
210 terrain_type_iterate(pterr) {
211 if (terrain_has_flag(pterr, flag)) {
212 num++;
213 if (fc_rand(num) == 1) {
214 terr = pterr;
215 }
216 }
217 } terrain_type_iterate_end;
218
219 return terr;
220}
221
222/**********************************************************************/
226 const char *terrain_name_translation(const struct terrain *pterrain)
227{
228 return name_translation_get(&pterrain->name);
229}
230
231/**********************************************************************/
235 const char *terrain_rule_name(const struct terrain *pterrain)
236{
237 return rule_name_get(&pterrain->name);
238}
239
240/**********************************************************************/
243 bool terrain_has_resource(const struct terrain *pterrain,
244 const struct extra_type *presource)
245{
246 struct extra_type **r = pterrain->resources;
247
248 while (NULL != *r) {
249 if (*r == presource) {
250 return TRUE;
251 }
252 r++;
253 }
254 return FALSE;
255}
256
257/**********************************************************************/
260 struct resource_type *resource_type_init(struct extra_type *pextra)
261{
262 struct resource_type *presource;
263
264 presource = fc_malloc(sizeof(*presource));
265
266 pextra->data.resource = presource;
267
268 presource->self = pextra;
269
270 return presource;
271}
272
273/**********************************************************************/
276 void resource_types_free(void)
277{
278 /* Resource structure itself is freed as part of extras destruction. */
279}
280
281/**********************************************************************/
284 struct extra_type *resource_extra_get(const struct resource_type *presource)
285{
286 return presource->self;
287}
288
289/**********************************************************************/
293#define variable_adjc_iterate(nmap, center_tile, _tile, card_only) \
294{ \
295 enum direction8 *_tile##_list; \
296 int _tile##_count; \
297 \
298 if (card_only) { \
299 _tile##_list = wld.map.cardinal_dirs; \
300 _tile##_count = wld.map.num_cardinal_dirs; \
301 } else { \
302 _tile##_list = wld.map.valid_dirs; \
303 _tile##_count = wld.map.num_valid_dirs; \
304 } \
305 adjc_dirlist_iterate(nmap, center_tile, _tile, _tile##_dir, \
306 _tile##_list, _tile##_count) {
307
308#define variable_adjc_iterate_end \
309 } adjc_dirlist_iterate_end; \
310}
311
312/**********************************************************************/
315 bool is_terrain_card_near(const struct civ_map *nmap,
316 const struct tile *ptile,
317 const struct terrain *pterrain,
318 bool check_self)
319{
320 if (pterrain == NULL) {
321 return FALSE;
322 }
323
324 cardinal_adjc_iterate(nmap, ptile, adjc_tile) {
325 if (tile_terrain(adjc_tile) == pterrain) {
326 return TRUE;
327 }
328 } cardinal_adjc_iterate_end;
329
330 return check_self && ptile->terrain == pterrain;
331}
332
333/**********************************************************************/
336 bool is_terrain_near_tile(const struct civ_map *nmap,
337 const struct tile *ptile,
338 const struct terrain *pterrain,
339 bool check_self)
340{
341 if (pterrain == NULL) {
342 return FALSE;
343 }
344
345 adjc_iterate(nmap, ptile, adjc_tile) {
346 if (tile_terrain(adjc_tile) == pterrain) {
347 return TRUE;
348 }
349 } adjc_iterate_end;
350
351 return check_self && ptile->terrain == pterrain;
352}
353
354/**********************************************************************/
357 int count_terrain_property_near_tile(const struct civ_map *nmap,
358 const struct tile *ptile,
359 bool cardinal_only, bool percentage,
360 enum mapgen_terrain_property prop)
361{
362 int count = 0, total = 0;
363
364 variable_adjc_iterate(nmap, ptile, adjc_tile, cardinal_only) {
365 struct terrain *pterrain = tile_terrain(adjc_tile);
366
367 if (pterrain->property[prop] > 0) {
368 count++;
369 }
370 total++;
371 } variable_adjc_iterate_end;
372
373 if (percentage && count > 0) { /* Latter condition avoids div by zero */
374 count = count * 100 / total;
375 }
376
377 return count;
378}
379
380/**********************************************************************/
383 bool is_resource_card_near(const struct civ_map *nmap,
384 const struct tile *ptile,
385 const struct extra_type *pres,
386 bool check_self)
387{
388 if (pres == NULL) {
389 return FALSE;
390 }
391
392 cardinal_adjc_iterate(nmap, ptile, adjc_tile) {
393 if (tile_resource(adjc_tile) == pres) {
394 return TRUE;
395 }
396 } cardinal_adjc_iterate_end;
397
398 return check_self && tile_resource(ptile) == pres;
399}
400
401/**********************************************************************/
404 bool is_resource_near_tile(const struct civ_map *nmap,
405 const struct tile *ptile,
406 const struct extra_type *pres,
407 bool check_self)
408{
409 if (pres == NULL) {
410 return FALSE;
411 }
412
413 adjc_iterate(nmap, ptile, adjc_tile) {
414 if (tile_resource(adjc_tile) == pres) {
415 return TRUE;
416 }
417 } adjc_iterate_end;
418
419 return check_self && tile_resource(ptile) == pres;
420}
421
422/**********************************************************************/
426 bool is_terrain_flag_card_near(const struct civ_map *nmap,
427 const struct tile *ptile,
428 enum terrain_flag_id flag)
429{
430 cardinal_adjc_iterate(nmap, ptile, adjc_tile) {
431 struct terrain* pterrain = tile_terrain(adjc_tile);
432
433 if (T_UNKNOWN != pterrain
434 && terrain_has_flag(pterrain, flag)) {
435 return TRUE;
436 }
437 } cardinal_adjc_iterate_end;
438
439 return FALSE;
440}
441
442/**********************************************************************/
446 bool is_terrain_flag_near_tile(const struct civ_map *nmap,
447 const struct tile *ptile,
448 enum terrain_flag_id flag)
449{
450 adjc_iterate(nmap, ptile, adjc_tile) {
451 struct terrain* pterrain = tile_terrain(adjc_tile);
452
453 if (T_UNKNOWN != pterrain
454 && terrain_has_flag(pterrain, flag)) {
455 return TRUE;
456 }
457 } adjc_iterate_end;
458
459 return FALSE;
460}
461
462/**********************************************************************/
466 int count_terrain_flag_near_tile(const struct civ_map *nmap,
467 const struct tile *ptile,
468 bool cardinal_only, bool percentage,
469 enum terrain_flag_id flag)
470{
471 int count = 0, total = 0;
472
473 variable_adjc_iterate(nmap, ptile, adjc_tile, cardinal_only) {
474 struct terrain *pterrain = tile_terrain(adjc_tile);
475
476 if (T_UNKNOWN != pterrain
477 && terrain_has_flag(pterrain, flag)) {
478 count++;
479 }
480 total++;
481 } variable_adjc_iterate_end;
482
483 if (percentage && count > 0) { /* Latter condition avoids div by zero */
484 count = count * 100 / total;
485 }
486
487 return count;
488}
489
490/**********************************************************************/
496 const char *get_infrastructure_text(bv_extras extras)
497{
498 static char s[256];
499 char *p;
500 int len;
501
502 s[0] = '\0';
503
504 extra_type_iterate(pextra) {
505 if (pextra->category == ECAT_INFRA
506 && BV_ISSET(extras, extra_index(pextra))) {
507 bool hidden = FALSE;
508
509 extra_type_iterate(top) {
510 int topi = extra_index(top);
511
512 if (BV_ISSET(pextra->hidden_by, topi)
513 && BV_ISSET(extras, topi)) {
514 hidden = TRUE;
515 break;
516 }
517 } extra_type_iterate_end;
518
519 if (!hidden) {
520 cat_snprintf(s, sizeof(s), "%s/", extra_name_translation(pextra));
521 }
522 }
523 } extra_type_iterate_end;
524
525 len = strlen(s);
526 p = s + len - 1;
527 if (len > 0 && *p == '/') {
528 *p = '\0';
529 }
530
531 return s;
532}
533
534/**********************************************************************/
538 struct extra_type *get_preferred_pillage(bv_extras extras)
539{
540 /* Semi-arbitrary preference order reflecting previous behavior */
541 static const enum extra_cause prefs[] = {
542 EC_IRRIGATION,
543 EC_MINE,
544 EC_BASE,
545 EC_ROAD,
546 EC_HUT,
547 EC_APPEARANCE,
548 EC_POLLUTION,
549 EC_FALLOUT,
550 EC_RESOURCE,
551 EC_NONE
552 };
553 int i;
554
555 for (i = 0; i < ARRAY_SIZE(prefs); i++) {
556 extra_type_by_cause_iterate_rev(prefs[i], pextra) {
557 if (is_extra_removed_by(pextra, ERM_PILLAGE)
558 && BV_ISSET(extras, extra_index(pextra))) {
559 return pextra;
560 }
561 } extra_type_by_cause_iterate_rev_end;
562 }
563
564 return NULL;
565}
566
567/**********************************************************************/
570 enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
571{
572 return pterrain->tclass;
573}
574
575/**********************************************************************/
579 bool is_terrain_class_card_near(const struct civ_map *nmap,
580 const struct tile *ptile,
581 enum terrain_class tclass)
582{
583 cardinal_adjc_iterate(nmap, ptile, adjc_tile) {
584 struct terrain* pterrain = tile_terrain(adjc_tile);
585
586 if (pterrain != T_UNKNOWN) {
587 if (terrain_type_terrain_class(pterrain) == tclass) {
588 return TRUE;
589 }
590 }
591 } cardinal_adjc_iterate_end;
592
593 return FALSE;
594}
595
596/**********************************************************************/
600 bool is_terrain_class_near_tile(const struct civ_map *nmap,
601 const struct tile *ptile,
602 enum terrain_class tclass)
603{
604 adjc_iterate(nmap, ptile, adjc_tile) {
605 struct terrain* pterrain = tile_terrain(adjc_tile);
606
607 if (pterrain != T_UNKNOWN) {
608 if (terrain_type_terrain_class(pterrain) == tclass) {
609 return TRUE;
610 }
611 }
612 } adjc_iterate_end;
613
614 return FALSE;
615}
616
617/**********************************************************************/
621 int count_terrain_class_near_tile(const struct civ_map *nmap,
622 const struct tile *ptile,
623 bool cardinal_only, bool percentage,
624 enum terrain_class tclass)
625{
626 int count = 0, total = 0;
627
628 variable_adjc_iterate(nmap, ptile, adjc_tile, cardinal_only) {
629 struct terrain *pterrain = tile_terrain(adjc_tile);
630
631 if (T_UNKNOWN != pterrain
632 && terrain_type_terrain_class(pterrain) == tclass) {
633 count++;
634 }
635 total++;
636 } variable_adjc_iterate_end;
637
638 if (percentage && count > 0) { /* Latter condition avoids div by zero */
639 count = count * 100 / total;
640 }
641
642 return count;
643}
644
645/**********************************************************************/
649 const char *terrain_class_name_translation(enum terrain_class tclass)
650{
651 if (!terrain_class_is_valid(tclass)) {
652 return NULL;
653 }
654
655 return _(terrain_class_name(tclass));
656}
657
658/**********************************************************************/
661 bool terrain_can_support_alteration(const struct terrain *pterrain,
662 enum terrain_alteration alter)
663{
664 switch (alter) {
665 case TA_CAN_IRRIGATE:
666 return (pterrain->irrigation_time > 0);
667 case TA_CAN_MINE:
668 return (pterrain->mining_time > 0);
669 case TA_CAN_ROAD:
670 return (pterrain->road_time > 0);
671 default:
672 break;
673 }
674
675 fc_assert(FALSE);
676 return FALSE;
677}
678
679/**********************************************************************/
682 int terrain_extra_build_time(const struct terrain *pterrain,
683 enum unit_activity activity,
684 const struct extra_type *tgt)
685{
686 int factor;
687
688 if (tgt != NULL && tgt->build_time != 0) {
689 /* Extra specific build time */
690 return tgt->build_time;
691 }
692
693 if (tgt == NULL) {
694 factor = 1;
695 } else {
696 factor = tgt->build_time_factor;
697 }
698
699 /* Terrain and activity specific build time */
700 switch (activity) {
701 case ACTIVITY_BASE:
702 return pterrain->base_time * factor;
703 case ACTIVITY_GEN_ROAD:
704 return pterrain->road_time * factor;
705 case ACTIVITY_IRRIGATE:
706 return pterrain->irrigation_time * factor;
707 case ACTIVITY_MINE:
708 return pterrain->mining_time * factor;
709 default:
710 fc_assert(FALSE);
711 return 0;
712 }
713}
714
715/**********************************************************************/
718 int terrain_extra_removal_time(const struct terrain *pterrain,
719 enum unit_activity activity,
720 const struct extra_type *tgt)
721{
722 int factor;
723
724 if (tgt != NULL && tgt->removal_time != 0) {
725 /* Extra specific removal time */
726 return tgt->removal_time;
727 }
728
729 if (tgt == NULL) {
730 factor = 1;
731 } else {
732 factor = tgt->removal_time_factor;
733 }
734
735 /* Terrain and activity specific removal time */
736 switch (activity) {
737 case ACTIVITY_POLLUTION:
738 return pterrain->clean_pollution_time * factor;
739 case ACTIVITY_FALLOUT:
740 return pterrain->clean_fallout_time * factor;
741 case ACTIVITY_PILLAGE:
742 return pterrain->pillage_time * factor;
743 default:
744 fc_assert(FALSE);
745 return 0;
746 }
747}
748
749/**********************************************************************/
752 void user_terrain_flags_init(void)
753{
754 int i;
755
756 for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
757 user_flag_init(&user_terrain_flags[i]);
758 }
759}
760
761/**********************************************************************/
764 void user_terrain_flags_free(void)
765{
766 int i;
767
768 for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
769 user_flag_free(&user_terrain_flags[i]);
770 }
771}
772
773/**********************************************************************/
776 void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name,
777 const char *helptxt)
778{
779 int tfid = id - TER_USER_1;
780
781 fc_assert_ret(id >= TER_USER_1 && id <= TER_USER_LAST);
782
783 if (user_terrain_flags[tfid].name != NULL) {
784 FC_FREE(user_terrain_flags[tfid].name);
785 user_terrain_flags[tfid].name = NULL;
786 }
787
788 if (name && name[0] != '\0') {
789 user_terrain_flags[tfid].name = fc_strdup(name);
790 }
791
792 if (user_terrain_flags[tfid].helptxt != NULL) {
793 FC_FREE(user_terrain_flags[tfid].helptxt);
794 user_terrain_flags[tfid].helptxt = NULL;
795 }
796
797 if (helptxt && helptxt[0] != '\0') {
798 user_terrain_flags[tfid].helptxt = fc_strdup(helptxt);
799 }
800}
801
802/**********************************************************************/
805 const char *terrain_flag_id_name_cb(enum terrain_flag_id flag)
806{
807 if (flag < TER_USER_1 || flag > TER_USER_LAST) {
808 return NULL;
809 }
810
811 return user_terrain_flags[flag-TER_USER_1].name;
812}
813
814/**********************************************************************/
817 const char *terrain_flag_helptxt(enum terrain_flag_id id)
818{
819 fc_assert(id >= TER_USER_1 && id <= TER_USER_LAST);
820
821 return user_terrain_flags[id - TER_USER_1].helptxt;
822}
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
extras
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
is_extra_removed_by
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:327
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
extras.h
extra_type_by_cause_iterate_rev
#define extra_type_by_cause_iterate_rev(_cause, _extra)
Definition extras.h:320
extra_type_by_cause_iterate_rev_end
#define extra_type_by_cause_iterate_rev_end
Definition extras.h:325
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:291
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:297
extra_index
#define extra_index(_e_)
Definition extras.h:177
Terrain_type_id
int Terrain_type_id
Definition fc_types.h:343
EC_NONE
#define EC_NONE
Definition fc_types.h:967
fcintl.h
_
#define _(String)
Definition fcintl.h:67
Qn_
#define Qn_(String)
Definition fcintl.h:89
user_flag_init
void user_flag_init(struct user_flag *flag)
Definition game.c:804
user_flag_free
void user_flag_free(struct user_flag *flag)
Definition game.c:813
game
struct civ_game game
Definition game.c:57
game.h
type
GType type
Definition repodlgs.c:1312
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
map.h
adjc_iterate_end
#define adjc_iterate_end
Definition map.h:427
cardinal_adjc_iterate_end
#define cardinal_adjc_iterate_end
Definition map.h:453
adjc_iterate
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:422
cardinal_adjc_iterate
#define cardinal_adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:449
mem.h
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
rule_name_get
static const char * rule_name_get(const struct name_translation *ptrans)
Definition name_translation.h:112
name_translation_get
static const char * name_translation_get(const struct name_translation *ptrans)
Definition name_translation.h:121
len
int len
Definition packhand.c:125
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:34
rgbcolor_destroy
void rgbcolor_destroy(struct rgbcolor *prgbcolor)
Definition rgbcolor.c:74
rgbcolor.h
road.h
shared.h
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
strvec_destroy
void strvec_destroy(struct strvec *psv)
Definition string_vector.c:71
string_vector.h
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:85
extra_type::resource
struct resource_type * resource
Definition extras.h:150
extra_type::removal_time
int removal_time
Definition extras.h:116
extra_type::build_time_factor
int build_time_factor
Definition extras.h:115
extra_type::data
struct extra_type::@24 data
extra_type::removal_time_factor
int removal_time_factor
Definition extras.h:117
extra_type::build_time
int build_time
Definition extras.h:114
packet_ruleset_control::terrain_count
int terrain_count
Definition packets_gen.h:1473
resource_type
Definition terrain.h:43
resource_type::self
struct extra_type * self
Definition terrain.h:51
terrain
Definition terrain.h:176
terrain::property
int property[MG_COUNT]
Definition terrain.h:239
terrain::resources
struct extra_type ** resources
Definition terrain.h:197
terrain::item_number
int item_number
Definition terrain.h:177
terrain::road_time
int road_time
Definition terrain.h:201
terrain::name
struct name_translation name
Definition terrain.h:178
terrain::clean_fallout_time
int clean_fallout_time
Definition terrain.h:220
terrain::animal
const struct unit_type * animal
Definition terrain.h:223
terrain::pillage_time
int pillage_time
Definition terrain.h:221
terrain::mining_time
int mining_time
Definition terrain.h:213
terrain::rgb
struct rgbcolor * rgb
Definition terrain.h:247
terrain::clean_pollution_time
int clean_pollution_time
Definition terrain.h:219
terrain::tclass
enum terrain_class tclass
Definition terrain.h:190
terrain::irrigation_time
int irrigation_time
Definition terrain.h:210
terrain::base_time
int base_time
Definition terrain.h:200
terrain::ruledit_dlg
void * ruledit_dlg
Definition terrain.h:180
terrain::identifier
char identifier
Definition terrain.h:184
terrain::ruledit_disabled
bool ruledit_disabled
Definition terrain.h:179
tile
Definition tile.h:49
tile::terrain
struct terrain * terrain
Definition tile.h:56
user_flag
Definition game.h:73
user_flag::name
char * name
Definition game.h:74
user_flag::helptxt
char * helptxt
Definition game.h:75
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
terrain_extra_removal_time
int terrain_extra_removal_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:718
user_terrain_flags_init
void user_terrain_flags_init(void)
Definition terrain.c:752
terrains_free
void terrains_free(void)
Definition terrain.c:59
terrain_by_rule_name
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:174
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:600
terrain_identifier
char terrain_identifier(const struct terrain *pterrain)
Definition terrain.c:114
terrain_count
Terrain_type_id terrain_count(void)
Definition terrain.c:106
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:284
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:621
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:579
terrain_by_translated_name
struct terrain * terrain_by_translated_name(const char *name)
Definition terrain.c:190
terrain_class_name_translation
const char * terrain_class_name_translation(enum terrain_class tclass)
Definition terrain.c:649
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:466
get_infrastructure_text
const char * get_infrastructure_text(bv_extras extras)
Definition terrain.c:496
terrain_flag_id_name_cb
const char * terrain_flag_id_name_cb(enum terrain_flag_id flag)
Definition terrain.c:805
terrain_index
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:126
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:383
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
variable_adjc_iterate
#define variable_adjc_iterate(nmap, center_tile, _tile, card_only)
Definition terrain.c:293
terrain_array_first
struct terrain * terrain_array_first(void)
Definition terrain.c:84
rand_terrain_by_flag
struct terrain * rand_terrain_by_flag(enum terrain_flag_id flag)
Definition terrain.c:205
terrain_by_number
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:144
terrain_can_support_alteration
bool terrain_can_support_alteration(const struct terrain *pterrain, enum terrain_alteration alter)
Definition terrain.c:661
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:315
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
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:404
resource_types_free
void resource_types_free(void)
Definition terrain.c:276
user_terrain_flags_free
void user_terrain_flags_free(void)
Definition terrain.c:764
terrain_type_terrain_class
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:570
terrain_flag_helptxt
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Definition terrain.c:817
terrain_has_resource
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:243
resource_type_init
struct resource_type * resource_type_init(struct extra_type *pextra)
Definition terrain.c:260
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:446
get_preferred_pillage
struct extra_type * get_preferred_pillage(bv_extras extras)
Definition terrain.c:538
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:776
terrain_array_last
const struct terrain * terrain_array_last(void)
Definition terrain.c:95
civ_terrains
static struct terrain civ_terrains[MAX_NUM_TERRAINS]
Definition terrain.c:36
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:682
user_terrain_flags
static struct user_flag user_terrain_flags[MAX_NUM_USER_TER_FLAGS]
Definition terrain.c:37
terrain_number
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:135
terrain_by_identifier
struct terrain * terrain_by_identifier(const char identifier)
Definition terrain.c:157
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:426
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:357
variable_adjc_iterate_end
#define variable_adjc_iterate_end
Definition terrain.c:308
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:336
terrain.h
terrain_type_iterate
#define terrain_type_iterate(_p)
Definition terrain.h:358
T_UNKNOWN
#define T_UNKNOWN
Definition terrain.h:57
TERRAIN_UNKNOWN_IDENTIFIER
#define TERRAIN_UNKNOWN_IDENTIFIER
Definition terrain.h:188
terrain_type_iterate_end
#define terrain_type_iterate_end
Definition terrain.h:364
MAX_NUM_TERRAINS
#define MAX_NUM_TERRAINS
Definition terrain.h:64
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
MAX_NUM_USER_TER_FLAGS
#define MAX_NUM_USER_TER_FLAGS
Definition terrain.h:146
tile_resource
#define tile_resource(_tile)
Definition tile.h:101
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109