Freeciv-3.4
Loading...
Searching...
No Matches
tile.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - 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 "bitvector.h"
20#include "log.h"
21#include "support.h"
22
23/* common */
24#include "fc_interface.h"
25#include "game.h"
26#include "map.h"
27#include "movement.h"
28#include "road.h"
29#include "unit.h"
30#include "unitlist.h"
31
32#include "tile.h"
33
35
36#ifndef tile_index
37/************************************************************************/
40int tile_index(const struct tile *ptile)
41{
42 return ptile->index;
43}
44#endif
45
46#ifndef tile_owner
47/************************************************************************/
50struct player *tile_owner(const struct tile *ptile)
51{
52 return ptile->owner;
53}
54#endif
55
56#ifndef tile_claimer
57/************************************************************************/
60struct tile *tile_claimer(const struct tile *ptile)
61{
62 return ptile->claimer;
63}
64#endif
65
66/************************************************************************/
69void tile_set_owner(struct tile *ptile, struct player *pplayer,
70 struct tile *claimer)
71{
73 /* City tiles are always owned by the city owner. */
74 || (tile_city(ptile) != nullptr || ptile->owner != nullptr)) {
75 ptile->owner = pplayer;
76 ptile->claimer = claimer;
77 }
78}
79
80/************************************************************************/
83struct city *tile_city(const struct tile *ptile)
84{
85 struct city *pcity = ptile->worked;
86
87 if (pcity != nullptr && is_city_center(pcity, ptile)) {
88 return pcity;
89 }
90
91 return nullptr;
92}
93
94#ifndef tile_worked
95/************************************************************************/
98struct city *tile_worked(const struct tile *ptile)
99{
100 return ptile->worked;
101}
102#endif
103
104/************************************************************************/
107void tile_set_worked(struct tile *ptile, struct city *pcity)
108{
109 ptile->worked = pcity;
110}
111
112#ifndef tile_terrain
113/************************************************************************/
116struct terrain *tile_terrain(const struct tile *ptile)
117{
118 return ptile->terrain;
119}
120#endif
121
122/************************************************************************/
125void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
126{
127 /* The terrain change is valid if one of the following is TRUE:
128 * - pterrain is nullptr (= unknown terrain)
129 * - ptile is a virtual tile, or otherwise not on the map being checked
130 * - pterrain does not has the flag TER_NO_CITIES
131 * - there is no city on ptile
132 * - client may have had tile fogged and is receiving terrain change before
133 * city removal
134 * This should be read as: The terrain change is INVALID if a terrain with
135 * the flag TER_NO_CITIES is given for a real tile with a city (i.e. all
136 * check evaluate to TRUE). */
137
138 /* Assert disabled for now, so we don't need to make this function
139 * care about what map is being changed. */
140#if 0
141 fc_assert_msg(pterrain == nullptr
142 || !is_server()
143 || !tile_map_check(nmap, ptile)
144 || !terrain_has_flag(pterrain, TER_NO_CITIES)
145 || tile_city(ptile) == nullptr,
146 "At (%d, %d), the terrain \"%s\" (nb %d) doesn't "
147 "support cities, whereas \"%s\" (nb %d) is built there.",
148 TILE_XY(ptile), terrain_rule_name(pterrain),
149 terrain_number(pterrain), city_name_get(tile_city(ptile)),
150 tile_city(ptile)->id);
151#endif /* 0 */
152
153 ptile->terrain = pterrain;
154 if (ptile->resource != nullptr) {
155 if (pterrain != nullptr
156 && terrain_has_resource(pterrain, ptile->resource)) {
157 BV_SET(ptile->extras, extra_index(ptile->resource));
158 } else {
159 BV_CLR(ptile->extras, extra_index(ptile->resource));
160 }
161 }
162}
163
164/************************************************************************/
168{
169 static bool empty_cleared = FALSE;
170
171 if (!empty_cleared) {
174 }
175
176 return &(empty_extras);
177}
178
179/************************************************************************/
182const bv_extras *tile_extras_safe(const struct tile *ptile)
183{
184 if (!ptile) {
185 return tile_extras_null();
186 }
187
188 return &(ptile->extras);
189}
190
191/************************************************************************/
198 const struct unit_type *punittype)
199{
200 int max_friendliness_range = -1;
201
203 if (tile_has_extra(ptile, pextra)
205 && pextra->no_aggr_near_city > max_friendliness_range) {
206 max_friendliness_range = pextra->no_aggr_near_city;
207 }
209
211}
212
213/************************************************************************/
216bool tile_has_claimable_base(const struct tile *ptile,
217 const struct unit_type *punittype)
218{
219 extra_type_list_iterate(utype_class(punittype)->cache.native_bases, pextra) {
220 struct base_type *pbase = extra_base_get(pextra);
221
222 if (tile_has_extra(ptile, pextra)
224 return TRUE;
225 }
227
228 return FALSE;
229}
230
231/************************************************************************/
234int tile_extras_defense_bonus(const struct tile *ptile,
235 const struct unit_type *punittype)
236{
238}
239
240/************************************************************************/
243int tile_extras_class_defense_bonus(const struct tile *ptile,
244 const struct unit_class *pclass)
245{
246 int natural_bonus = 0;
247 int fortification_bonus = 0;
248 int total_bonus;
249
251 if (tile_has_extra(ptile, pextra)
252 && is_native_extra_to_uclass(pextra, pclass)) {
253 natural_bonus += pextra->defense_bonus;
254 }
256
258 if (tile_has_extra(ptile, pextra)
259 && is_native_extra_to_uclass(pextra, pclass)) {
260 fortification_bonus += pextra->defense_bonus;
261 }
263
264 total_bonus = (100 + natural_bonus) * (100 + fortification_bonus) / 100 - 100;
265
266 return total_bonus;
267}
268
269/************************************************************************/
272int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
273{
274 int const_incr = 0;
275 int incr = 0;
276
278 if (tile_has_extra(ptile, pextra)) {
279 struct road_type *proad = extra_road_get(pextra);
280
281 const_incr += proad->tile_incr_const[o];
282 incr += proad->tile_incr[o];
283 }
285
286 return const_incr + incr * tile_terrain(ptile)->road_output_incr_pct[o] / 100;
287}
288
289/************************************************************************/
292int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
293{
294 int bonus = 0;
295
297 if (tile_has_extra(ptile, pextra)) {
298 struct road_type *proad = extra_road_get(pextra);
299
300 bonus += proad->tile_bonus[o];
301 }
303
304 return bonus;
305}
306
307/************************************************************************/
310bool tile_has_refuel_extra(const struct tile *ptile,
311 const struct unit_class *uclass)
312{
314 if (tile_has_extra(ptile, pextra)) {
315 return TRUE;
316 }
318
319 return FALSE;
320}
321
322/************************************************************************/
325bool tile_has_native_base(const struct tile *ptile,
326 const struct unit_type *punittype)
327{
328 extra_type_list_iterate(utype_class(punittype)->cache.native_bases, pextra) {
329 if (tile_has_extra(ptile, pextra)) {
330 return TRUE;
331 }
333
334 return FALSE;
335}
336
337#ifndef tile_resource
338/************************************************************************/
341const struct resource_type *tile_resource(const struct tile *ptile)
342{
343 return ptile->resource;
344}
345#endif
346
347/************************************************************************/
350void tile_set_resource(struct tile *ptile, struct extra_type *presource)
351{
352 if (presource == ptile->resource) {
353 return; /* No change */
354 }
355
356 if (ptile->resource != nullptr) {
357 tile_remove_extra(ptile, ptile->resource);
358 }
359 if (presource != nullptr) {
360 if (ptile->terrain && terrain_has_resource(ptile->terrain, presource)) {
361 tile_add_extra(ptile, presource);
362 }
363 }
364
365 ptile->resource = presource;
366}
367
368#ifndef tile_continent
369/************************************************************************/
374Continent_id tile_continent(const struct tile *ptile)
375{
376 return ptile->continent;
377}
378#endif
379
380/************************************************************************/
383void tile_set_continent(struct tile *ptile, Continent_id val)
384{
385 ptile->continent = val;
386}
387
388/************************************************************************/
393enum known_type tile_get_known(const struct tile *ptile,
394 const struct player *pplayer)
395{
396 if (!dbv_isset(&pplayer->tile_known, tile_index(ptile))) {
397 return TILE_UNKNOWN;
398 } else if (!fc_funcs->player_tile_vision_get(ptile, pplayer, V_MAIN)) {
399 return TILE_KNOWN_UNSEEN;
400 } else {
401 return TILE_KNOWN_SEEN;
402 }
403}
404
405/************************************************************************/
408bool tile_is_seen(const struct tile *target_tile,
409 const struct player *pow_player)
410{
412}
413
414/************************************************************************/
419int tile_activity_time(enum unit_activity activity, const struct tile *ptile,
420 const struct extra_type *tgt)
421{
422 struct terrain *pterrain = tile_terrain(ptile);
423 int eff = get_target_bonus_effects(nullptr,
424 &(const struct req_context) {
425 .tile = ptile,
426 .activity = activity,
427 .extra = tgt
428 }, nullptr, EFT_ACTIVITY_TIME);
429
430 fc_assert(tgt != nullptr || !is_targeted_activity(activity));
431
432 if (eff > 0) {
433 /* Use effect provided value */
434 return eff * ACTIVITY_FACTOR;
435 }
436
437 switch (activity) {
438 case ACTIVITY_CLEAN:
439 case ACTIVITY_PILLAGE:
440 return terrain_extra_removal_time(pterrain, activity, tgt) * ACTIVITY_FACTOR;
442 return pterrain->transform_time * ACTIVITY_FACTOR;
444 return pterrain->cultivate_time * ACTIVITY_FACTOR;
445 case ACTIVITY_PLANT:
446 return pterrain->plant_time * ACTIVITY_FACTOR;
448 case ACTIVITY_MINE:
449 case ACTIVITY_BASE:
451 return terrain_extra_build_time(pterrain, activity, tgt) * ACTIVITY_FACTOR;
452 case ACTIVITY_IDLE:
454 case ACTIVITY_SENTRY:
455 case ACTIVITY_GOTO:
456 case ACTIVITY_EXPLORE:
458 case ACTIVITY_CONVERT:
459 case ACTIVITY_LAST:
460 return 0; /* FIXME: Should some of these be asserted against */
461 }
462
463 return 0;
464}
465
466/************************************************************************/
469static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
470{
471 if (fc_funcs->create_extra != nullptr) {
472 /* Assume callback calls tile_add_extra() itself. */
473 fc_funcs->create_extra(ptile, pextra, nullptr);
474 } else {
475 tile_add_extra(ptile, pextra);
476 }
477}
478
479/************************************************************************/
482static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
483{
484 if (fc_funcs->destroy_extra != nullptr) {
485 /* Assume callback calls tile_remove_extra() itself. */
486 fc_funcs->destroy_extra(ptile, pextra);
487 } else {
488 tile_remove_extra(ptile, pextra);
489 }
490}
491
492/************************************************************************/
497void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
498{
499 tile_set_terrain(ptile, pterrain);
500
501 /* Remove unsupported extras */
502 extra_type_iterate(pextra) {
503 if (tile_has_extra(ptile, pextra)
504 && (!is_native_tile_to_extra(pextra, ptile)
506 tile_destroy_extra(ptile, pextra);
507 }
509}
510
511/************************************************************************/
514static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra,
515 int rec)
516{
517 if (rec > MAX_EXTRA_TYPES) {
518 /* Infinite recursion */
519 return FALSE;
520 }
521
522 /* First place dependency extras */
523 extra_deps_iterate(&(pextra->reqs), pdep) {
524 if (!tile_has_extra(ptile, pdep)) {
525 add_recursive_extras(ptile, pdep, rec + 1);
526 }
528
529 /* Is tile native for extra after that? */
530 if (!is_native_tile_to_extra(pextra, ptile)) {
531 return FALSE;
532 }
533
534 tile_create_extra(ptile, pextra);
535
536 return TRUE;
537}
538
539/************************************************************************/
542static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra,
543 int rec)
544{
545 if (rec > MAX_EXTRA_TYPES) {
546 /* Infinite recursion */
547 return FALSE;
548 }
549
551 if (tile_has_extra(ptile, pdepending)) {
553 if (pdep == pextra) {
554 /* Depends on what we are going to remove */
555 if (!rm_recursive_extras(ptile, pdepending, rec + 1)) {
556 return FALSE;
557 }
558 }
560 }
562
563 tile_destroy_extra(ptile, pextra);
564
565 return TRUE;
566}
567
568/************************************************************************/
576bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
577{
578 /* Add extra with its dependencies */
579 if (!add_recursive_extras(ptile, tgt, 0)) {
580 return FALSE;
581 }
582
583 /* Remove conflicting extras */
584 extra_type_iterate(pextra) {
585 if (tile_has_extra(ptile, pextra)
586 && !can_extras_coexist(pextra, tgt)) {
587 tile_destroy_extra(ptile, pextra);
588 }
590
591 return TRUE;
592}
593
594/************************************************************************/
602bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
603{
604 /* Remove extra with everything depending on it. */
605 if (!rm_recursive_extras(ptile, tgt, 0)) {
606 return FALSE;
607 }
608
609 return TRUE;
610}
611
612/************************************************************************/
616static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
617{
618 fc_assert(tgt != nullptr);
619
620 if (tgt != nullptr) {
621 tile_extra_apply(ptile, tgt);
622 }
623}
624
625/************************************************************************/
629static void tile_mine(struct tile *ptile, struct extra_type *tgt)
630{
631 fc_assert(tgt != nullptr);
632
633 if (tgt != nullptr) {
634 tile_extra_apply(ptile, tgt);
635 }
636}
637
638/************************************************************************/
642static void tile_transform(struct tile *ptile)
643{
644 struct terrain *pterrain = tile_terrain(ptile);
645
646 if (pterrain->transform_result != T_NONE) {
647 tile_change_terrain(ptile, pterrain->transform_result);
648 }
649}
650
651/************************************************************************/
655static void tile_plant(struct tile *ptile)
656{
657 struct terrain *pterrain = tile_terrain(ptile);
658
659 if (pterrain->plant_result != T_NONE) {
660 tile_change_terrain(ptile, pterrain->plant_result);
661 }
662}
663
664/************************************************************************/
668static void tile_cultivate(struct tile *ptile)
669{
670 struct terrain *pterrain = tile_terrain(ptile);
671
672 if (pterrain->cultivate_result != T_NONE) {
673 tile_change_terrain(ptile, pterrain->cultivate_result);
674 }
675}
676
677/************************************************************************/
683 struct extra_type *tgt)
684{
685 /* FIXME: for irrigate, mine, and transform we always return TRUE
686 * even if the activity fails. */
687 switch (act) {
688 case ACTIVITY_MINE:
689 tile_mine(ptile, tgt);
690 return TRUE;
691
693 tile_irrigate(ptile, tgt);
694 return TRUE;
695
697 tile_transform(ptile);
698 return TRUE;
699
701 tile_cultivate(ptile);
702 return TRUE;
703
704 case ACTIVITY_PLANT:
705 tile_plant(ptile);
706 return TRUE;
707
708 case ACTIVITY_PILLAGE:
709 case ACTIVITY_BASE:
711 case ACTIVITY_CLEAN:
712 /* Do nothing - not implemented */
713 return FALSE;
714
715 case ACTIVITY_IDLE:
717 case ACTIVITY_SENTRY:
718 case ACTIVITY_GOTO:
719 case ACTIVITY_EXPLORE:
720 case ACTIVITY_CONVERT:
722 case ACTIVITY_LAST:
723 /* Do nothing - these activities have no effect
724 on terrain type or tile extras */
725 return FALSE;
726 }
727
729
730 return FALSE;
731}
732
733/************************************************************************/
737static bool tile_info_pollution(char *buf, int bufsz,
738 const struct tile *ptile,
739 struct extra_type *pextra,
740 bool prevp, bool linebreak)
741{
742 if (tile_has_visible_extra(ptile, pextra)) {
743 if (!prevp) {
744 if (linebreak) {
745 fc_strlcat(buf, "\n[", bufsz);
746 } else {
747 fc_strlcat(buf, " [", bufsz);
748 }
749 } else {
750 fc_strlcat(buf, "/", bufsz);
751 }
752
754
755 return TRUE;
756 }
757
758 return prevp;
759}
760
761/************************************************************************/
772const char *tile_get_info_text(const struct tile *ptile,
774{
775 static char s[256];
776 bool pollution;
777 bool lb = FALSE;
778 int bufsz = sizeof(s);
779
782 /* Linebreak needed before next text */
783 lb = TRUE;
784 }
785
786 extra_type_iterate(pextra) {
787 if (pextra->category == ECAT_NATURAL
788 && tile_has_visible_extra(ptile, pextra)) {
789 if (lb) {
790 sz_strlcat(s, "\n");
791 lb = FALSE;
792 } else {
793 sz_strlcat(s, "/");
794 }
796 }
799 /* New linebreak requested */
800 lb = TRUE;
801 }
802
803 if (tile_resource_is_valid(ptile)) {
804 if (lb) {
805 sz_strlcat(s, "\n");
806 lb = FALSE;
807 } else {
808 sz_strlcat(s, " ");
809 }
810 cat_snprintf(s, sizeof(s), "(%s)",
812 }
814 /* New linebreak requested */
815 lb = TRUE;
816 }
817
818 if (include_nuisances) {
819 pollution = FALSE;
820 extra_type_iterate(pextra) {
821 if (pextra->category == ECAT_NUISANCE) {
822 pollution = tile_info_pollution(s, bufsz, ptile, pextra, pollution,
823 lb);
824 }
826 if (pollution) {
827 sz_strlcat(s, "]");
828 }
829 }
830
831 return s;
832}
833
834/************************************************************************/
837bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
838{
839 return tile_has_extra(ptile, base_extra_get(pbase));
840}
841
842/************************************************************************/
845bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
846{
847 return tile_has_extra(ptile, road_extra_get(proad));
848}
849
850/************************************************************************/
853bool tile_has_river(const struct tile *ptile)
854{
855 /* TODO: Have a list of rivers and iterate only that */
857 if (tile_has_extra(ptile, priver)
859 return TRUE;
860 }
862
863 return FALSE;
864}
865
866/************************************************************************/
869bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
870{
872 if (tile_has_extra(ptile, pextra)) {
873 struct road_type *proad = extra_road_get(pextra);
874
875 if (road_has_flag(proad, flag)) {
876 return TRUE;
877 }
878 }
880
881 return FALSE;
882}
883
884/************************************************************************/
887bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
888{
889 extra_type_iterate(pextra) {
890 if (tile_has_extra(ptile, pextra)
891 && extra_has_flag(pextra, flag)) {
892 return TRUE;
893 }
895
896 return FALSE;
897}
898
899/************************************************************************/
902bool tile_has_conflicting_extra(const struct tile *ptile,
903 const struct extra_type *pextra)
904{
906 if (BV_ISSET(pextra->conflicts, extra_index(pconfl))
907 && tile_has_extra(ptile, pconfl)) {
908 return TRUE;
909 }
911
912 return FALSE;
913}
914
915/************************************************************************/
918bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
919{
920 bool hidden = FALSE;
921
922 if (!BV_ISSET(ptile->extras, extra_index(pextra))) {
923 return FALSE;
924 }
925
926 extra_type_iterate(top) {
927 int topi = extra_index(top);
928
929 if (BV_ISSET(pextra->hidden_by, topi)
930 && BV_ISSET(ptile->extras, topi)) {
931 hidden = TRUE;
932 break;
933 }
935
936 return !hidden;
937}
938
939/************************************************************************/
942bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause)
943{
944 extra_type_by_cause_iterate(cause, pextra) {
945 if (tile_has_extra(ptile, pextra)) {
946 return TRUE;
947 }
949
950 return FALSE;
951}
952
953/************************************************************************/
956void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
957{
958 if (pextra != nullptr) {
959 BV_SET(ptile->extras, extra_index(pextra));
960 }
961}
962
963/************************************************************************/
966void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
967{
968 if (pextra != nullptr) {
969 BV_CLR(ptile->extras, extra_index(pextra));
970 if (ptile->resource == pextra) {
971 ptile->resource = nullptr;
972 }
973 }
974}
975
976/************************************************************************/
982struct tile *tile_virtual_new(const struct tile *ptile)
983{
984 struct tile *vtile;
985
986 vtile = fc_calloc(1, sizeof(*vtile));
987
988 /* Initialise some values */
989 vtile->index = TILE_INDEX_NONE;
990 vtile->continent = -1;
991
992 BV_CLR_ALL(vtile->extras);
993 vtile->resource = nullptr;
994 vtile->terrain = nullptr;
995 vtile->units = unit_list_new();
996 vtile->worked = nullptr;
997 vtile->owner = nullptr;
998 vtile->placing = nullptr;
999 vtile->extras_owner = nullptr;
1000 vtile->claimer = nullptr;
1001 vtile->altitude = 0;
1002 vtile->spec_sprite = nullptr;
1003
1004 if (ptile != nullptr) {
1005 /* Used by is_city_center() to give virtual tiles the output bonuses
1006 * they deserve. */
1007 vtile->index = tile_index(ptile);
1008
1009 /* Copy all but the unit list. */
1010 extra_type_iterate(pextra) {
1011 if (BV_ISSET(ptile->extras, extra_number(pextra))) {
1012 BV_SET(vtile->extras, extra_number(pextra));
1013 }
1015
1016 vtile->resource = ptile->resource;
1017 vtile->terrain = ptile->terrain;
1018 vtile->worked = ptile->worked;
1019 vtile->owner = ptile->owner;
1020 vtile->extras_owner = ptile->extras_owner;
1021 vtile->claimer = ptile->claimer;
1022 vtile->altitude = ptile->altitude;
1023 vtile->spec_sprite = nullptr;
1024 }
1025
1026 return vtile;
1027}
1028
1029/************************************************************************/
1037{
1038 struct city *vcity;
1039
1040 if (!vtile) {
1041 return;
1042 }
1043
1044 if (vtile->units) {
1045 unit_list_iterate(vtile->units, vunit) {
1046 if (unit_is_virtual(vunit)) {
1048 }
1050 unit_list_destroy(vtile->units);
1051 vtile->units = nullptr;
1052 }
1053
1055 if (vcity) {
1056 if (city_is_virtual(vcity)) {
1058 }
1059 tile_set_worked(vtile, nullptr);
1060 }
1061
1062 free(vtile);
1063}
1064
1065/************************************************************************/
1068bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
1069{
1070 int tindex;
1071
1072 if (!vtile || map_is_empty()) {
1073 return FALSE;
1074 }
1075
1076 tindex = tile_index(vtile);
1077 fc_assert_ret_val(0 <= tindex && tindex < map_num_tiles(), FALSE);
1078
1079 return (vtile == nmap->tiles + tindex);
1080}
1081
1082/************************************************************************/
1086void *tile_hash_key(const struct tile *ptile)
1087{
1088 void *key = 0; /* Initialize whole sizeof(void *) */
1089
1090 key = FC_INT_TO_PTR(ptile->index);
1091
1092 return key;
1093}
1094
1095/************************************************************************/
1098bool tile_set_label(struct tile *ptile, const char *label)
1099{
1100 bool changed = FALSE;
1101
1102 /* Handle empty label as nullptr label */
1103 if (label != nullptr && label[0] == '\0') {
1104 label = nullptr;
1105 }
1106
1107 if (ptile->label != nullptr) {
1108 if (label == nullptr) {
1109 changed = TRUE;
1110 } else if (strcmp(ptile->label, label)) {
1111 changed = TRUE;
1112 }
1113 FC_FREE(ptile->label);
1114 ptile->label = nullptr;
1115 } else if (label != nullptr) {
1116 changed = TRUE;
1117 }
1118
1119 if (label != nullptr) {
1120 if (strlen(label) >= MAX_LEN_MAP_LABEL) {
1121 log_error("Overlong map label '%s'", label);
1122 }
1123 ptile->label = fc_strdup(label);
1124 }
1125
1126 return changed;
1127}
1128
1129/************************************************************************/
1132bool tile_is_placing(const struct tile *ptile)
1133{
1134 return ptile->placing != nullptr;
1135}
struct extra_type * base_extra_get(const struct base_type *pbase)
Definition base.c:105
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:162
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_CLR(bv, bit)
Definition bitvector.h:94
bool city_is_virtual(const struct city *pcity)
Definition city.c:3629
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
void destroy_city_virtual(struct city *pcity)
Definition city.c:3556
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:869
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:875
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:641
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:866
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:1017
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:857
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_deps_iterate(_reqs, _dep)
Definition extras.h:371
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_iterate_end
Definition extras.h:321
#define extra_index(_e_)
Definition extras.h:183
#define extra_deps_iterate_end
Definition extras.h:379
#define extra_type_list_iterate_end
Definition extras.h:167
#define extra_base_get(_e_)
Definition extras.h:190
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
const struct functions * fc_funcs
static bool is_server(void)
enum unit_activity Activity_type_id
Definition fc_types.h:239
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:809
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:810
#define EC_DEFENSIVE
Definition fc_types.h:808
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
#define MAX_LEN_MAP_LABEL
Definition fc_types.h:69
output_type_id
Definition fc_types.h:101
signed short Continent_id
Definition fc_types.h:232
@ BORDERS_DISABLED
Definition fc_types.h:730
struct civ_game game
Definition game.c:62
static const int bufsz
Definition helpdlg.c:70
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_error(message,...)
Definition log.h:104
int map_num_tiles(void)
Definition map.c:1152
bool map_is_empty(void)
Definition map.c:148
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
struct extra_type * road_extra_get(const struct road_type *proad)
Definition road.c:42
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:416
#define FC_INT_TO_PTR(i)
Definition shared.h:94
Definition city.h:318
struct player * owner
Definition city.h:321
struct packet_game_info info
Definition game.h:89
bv_extras conflicts
Definition extras.h:133
struct requirement_vector reqs
Definition extras.h:106
bv_extras hidden_by
Definition extras.h:134
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
void(* destroy_extra)(struct tile *ptile, struct extra_type *pextra)
void(* create_extra)(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
enum borders_mode borders
struct dbv tile_known
Definition player.h:310
struct terrain * cultivate_result
Definition terrain.h:108
int plant_time
Definition terrain.h:112
struct terrain * plant_result
Definition terrain.h:111
int cultivate_time
Definition terrain.h:109
int transform_time
Definition terrain.h:124
struct terrain * transform_result
Definition terrain.h:122
Definition tile.h:50
char * label
Definition tile.h:66
int altitude
Definition tile.h:65
int index
Definition tile.h:51
bv_extras extras
Definition tile.h:55
struct extra_type * resource
Definition tile.h:56
struct player * extras_owner
Definition tile.h:63
struct terrain * terrain
Definition tile.h:57
struct extra_type * placing
Definition tile.h:61
struct city * worked
Definition tile.h:59
struct player * owner
Definition tile.h:60
Continent_id continent
Definition tile.h:54
struct tile * claimer
Definition tile.h:64
struct unit_class::@89 cache
struct extra_type_list * refuel_extras
Definition unittype.h:168
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:822
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
int terrain_extra_removal_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:739
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:241
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:250
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:258
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:703
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:149
#define T_NONE
Definition terrain.h:61
#define terrain_has_flag(terr, flag)
Definition terrain.h:176
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:243
static bool tile_info_pollution(char *buf, int bufsz, const struct tile *ptile, struct extra_type *pextra, bool prevp, bool linebreak)
Definition tile.c:737
static void tile_cultivate(struct tile *ptile)
Definition tile.c:668
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:956
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:292
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:887
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:216
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:125
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1036
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:576
static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:616
bool tile_has_river(const struct tile *ptile)
Definition tile.c:853
static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:482
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1132
const bv_extras * tile_extras_null(void)
Definition tile.c:167
bool tile_apply_activity(struct tile *ptile, Activity_type_id act, struct extra_type *tgt)
Definition tile.c:682
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1068
static void tile_transform(struct tile *ptile)
Definition tile.c:642
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:837
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:966
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:497
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:918
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:310
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:234
static void tile_mine(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:629
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:845
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:902
static void tile_plant(struct tile *ptile)
Definition tile.c:655
static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:469
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:408
static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:514
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:419
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:982
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:325
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:272
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1086
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:602
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1098
static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:542
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:350
int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:197
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:393
const bv_extras * tile_extras_safe(const struct tile *ptile)
Definition tile.c:182
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:772
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:869
static bv_extras empty_extras
Definition tile.c:34
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause)
Definition tile.c:942
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:107
void tile_set_continent(struct tile *ptile, Continent_id val)
Definition tile.c:383
#define TILE_LB_RIVER_RESOURCE
Definition tile.h:181
#define tile_claimer(_tile)
Definition tile.h:101
#define TILE_LB_RESOURCE_POLL
Definition tile.h:182
#define tile_index(_pt_)
Definition tile.h:89
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:108
#define tile_worked(_tile)
Definition tile.h:119
#define tile_resource(_tile)
Definition tile.h:103
known_type
Definition tile.h:35
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define ACTIVITY_FACTOR
Definition tile.h:170
#define TILE_LB_TERRAIN_RIVER
Definition tile.h:180
#define tile_terrain(_tile)
Definition tile.h:115
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_continent(_tile)
Definition tile.h:93
#define tile_has_extra(ptile, pextra)
Definition tile.h:152
#define TILE_INDEX_NONE
Definition tile.h:48
#define tile_owner(_tile)
Definition tile.h:97
bool is_targeted_activity(enum unit_activity activity)
Definition unit.c:1678
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1793
bool unit_is_virtual(const struct unit *punit)
Definition unit.c:2334
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
#define utype_class(_t_)
Definition unittype.h:756