Freeciv-3.2
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) != NULL || ptile->owner != NULL)) {
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 (NULL != pcity && is_city_center(pcity, ptile)) {
88 return pcity;
89 }
90 return NULL;
91}
92
93#ifndef tile_worked
94/************************************************************************/
97struct city *tile_worked(const struct tile *ptile)
98{
99 return ptile->worked;
100}
101#endif
102
103/************************************************************************/
106void tile_set_worked(struct tile *ptile, struct city *pcity)
107{
108 ptile->worked = pcity;
109}
110
111#ifndef tile_terrain
112/************************************************************************/
115struct terrain *tile_terrain(const struct tile *ptile)
116{
117 return ptile->terrain;
118}
119#endif
120
121/************************************************************************/
124void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
125{
126 /* The terrain change is valid if one of the following is TRUE:
127 * - pterrain is NULL (= unknown terrain)
128 * - ptile is a virtual tile, or otherwise not on the map being checked
129 * - pterrain does not has the flag TER_NO_CITIES
130 * - there is no city on ptile
131 * - client may have had tile fogged and is receiving terrain change before
132 * city removal
133 * This should be read as: The terrain change is INVALID if a terrain with
134 * the flag TER_NO_CITIES is given for a real tile with a city (i.e. all
135 * check evaluate to TRUE). */
136
137 /* Assert disabled for now, so we don't need to make this function
138 * care about what map is being changed. */
139#if 0
140 fc_assert_msg(NULL == pterrain
141 || !is_server()
142 || !tile_map_check(nmap, ptile)
143 || !terrain_has_flag(pterrain, TER_NO_CITIES)
144 || NULL == tile_city(ptile),
145 "At (%d, %d), the terrain \"%s\" (nb %d) doesn't "
146 "support cities, whereas \"%s\" (nb %d) is built there.",
147 TILE_XY(ptile), terrain_rule_name(pterrain),
148 terrain_number(pterrain), city_name_get(tile_city(ptile)),
149 tile_city(ptile)->id);
150#endif /* 0 */
151
152 ptile->terrain = pterrain;
153 if (ptile->resource != NULL) {
154 if (NULL != pterrain
155 && terrain_has_resource(pterrain, ptile->resource)) {
156 BV_SET(ptile->extras, extra_index(ptile->resource));
157 } else {
158 BV_CLR(ptile->extras, extra_index(ptile->resource));
159 }
160 }
161}
162
163/************************************************************************/
167{
168 static bool empty_cleared = FALSE;
169
170 if (!empty_cleared) {
173 }
174
175 return &(empty_extras);
176}
177
178/************************************************************************/
181const bv_extras *tile_extras_safe(const struct tile *ptile)
182{
183 if (!ptile) {
184 return tile_extras_null();
185 }
186
187 return &(ptile->extras);
188}
189
190/************************************************************************/
197 const struct unit_type *punittype)
198{
199 int max_friendliness_range = -1;
200
202 if (tile_has_extra(ptile, pextra)
204 && pextra->no_aggr_near_city > max_friendliness_range) {
205 max_friendliness_range = pextra->no_aggr_near_city;
206 }
208
210}
211
212/************************************************************************/
215bool tile_has_claimable_base(const struct tile *ptile,
216 const struct unit_type *punittype)
217{
218 extra_type_list_iterate(utype_class(punittype)->cache.native_bases, pextra) {
219 struct base_type *pbase = extra_base_get(pextra);
220
221 if (tile_has_extra(ptile, pextra)
223 return TRUE;
224 }
226
227 return FALSE;
228}
229
230/************************************************************************/
233int tile_extras_defense_bonus(const struct tile *ptile,
234 const struct unit_type *punittype)
235{
237}
238
239/************************************************************************/
242int tile_extras_class_defense_bonus(const struct tile *ptile,
243 const struct unit_class *pclass)
244{
245 int natural_bonus = 0;
246 int fortification_bonus = 0;
247 int total_bonus;
248
250 if (tile_has_extra(ptile, pextra)
251 && is_native_extra_to_uclass(pextra, pclass)) {
252 natural_bonus += pextra->defense_bonus;
253 }
255
257 if (tile_has_extra(ptile, pextra)
258 && is_native_extra_to_uclass(pextra, pclass)) {
259 fortification_bonus += pextra->defense_bonus;
260 }
262
263 total_bonus = (100 + natural_bonus) * (100 + fortification_bonus) / 100 - 100;
264
265 return total_bonus;
266}
267
268/************************************************************************/
271int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
272{
273 int const_incr = 0;
274 int incr = 0;
275
277 if (tile_has_extra(ptile, pextra)) {
278 struct road_type *proad = extra_road_get(pextra);
279
280 const_incr += proad->tile_incr_const[o];
281 incr += proad->tile_incr[o];
282 }
284
285 return const_incr + incr * tile_terrain(ptile)->road_output_incr_pct[o] / 100;
286}
287
288/************************************************************************/
291int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
292{
293 int bonus = 0;
294
296 if (tile_has_extra(ptile, pextra)) {
297 struct road_type *proad = extra_road_get(pextra);
298
299 bonus += proad->tile_bonus[o];
300 }
302
303 return bonus;
304}
305
306/************************************************************************/
309bool tile_has_refuel_extra(const struct tile *ptile,
310 const struct unit_class *uclass)
311{
313 if (tile_has_extra(ptile, pextra)) {
314 return TRUE;
315 }
317
318 return FALSE;
319}
320
321/************************************************************************/
324bool tile_has_native_base(const struct tile *ptile,
325 const struct unit_type *punittype)
326{
327 extra_type_list_iterate(utype_class(punittype)->cache.native_bases, pextra) {
328 if (tile_has_extra(ptile, pextra)) {
329 return TRUE;
330 }
332
333 return FALSE;
334}
335
336#ifndef tile_resource
337/************************************************************************/
340const struct resource_type *tile_resource(const struct tile *ptile)
341{
342 return ptile->resource;
343}
344#endif
345
346/************************************************************************/
349void tile_set_resource(struct tile *ptile, struct extra_type *presource)
350{
351 if (presource == ptile->resource) {
352 return; /* No change */
353 }
354
355 if (ptile->resource != NULL) {
356 tile_remove_extra(ptile, ptile->resource);
357 }
358 if (presource != NULL) {
359 if (ptile->terrain && terrain_has_resource(ptile->terrain, presource)) {
360 tile_add_extra(ptile, presource);
361 }
362 }
363
364 ptile->resource = presource;
365}
366
367#ifndef tile_continent
368/************************************************************************/
373Continent_id tile_continent(const struct tile *ptile)
374{
375 return ptile->continent;
376}
377#endif
378
379/************************************************************************/
382void tile_set_continent(struct tile *ptile, Continent_id val)
383{
384 ptile->continent = val;
385}
386
387/************************************************************************/
392enum known_type tile_get_known(const struct tile *ptile,
393 const struct player *pplayer)
394{
395 if (!dbv_isset(&pplayer->tile_known, tile_index(ptile))) {
396 return TILE_UNKNOWN;
397 } else if (!fc_funcs->player_tile_vision_get(ptile, pplayer, V_MAIN)) {
398 return TILE_KNOWN_UNSEEN;
399 } else {
400 return TILE_KNOWN_SEEN;
401 }
402}
403
404/************************************************************************/
407bool tile_is_seen(const struct tile *target_tile,
408 const struct player *pow_player)
409{
411}
412
413/************************************************************************/
418int tile_activity_time(enum unit_activity activity, const struct tile *ptile,
419 const struct extra_type *tgt)
420{
421 struct terrain *pterrain = tile_terrain(ptile);
423 &(const struct req_context) {
424 .tile = ptile,
425 .activity = activity,
426 .extra = tgt
428
429 fc_assert(tgt != NULL || !is_targeted_activity(activity));
430
431 if (eff > 0) {
432 /* Use effect provided value */
433 return eff * ACTIVITY_FACTOR;
434 }
435
436 switch (activity) {
437 case ACTIVITY_CLEAN:
438 case ACTIVITY_PILLAGE:
439 return terrain_extra_removal_time(pterrain, activity, tgt) * ACTIVITY_FACTOR;
441 return pterrain->transform_time * ACTIVITY_FACTOR;
443 return pterrain->cultivate_time * ACTIVITY_FACTOR;
444 case ACTIVITY_PLANT:
445 return pterrain->plant_time * ACTIVITY_FACTOR;
447 case ACTIVITY_MINE:
448 case ACTIVITY_BASE:
450 return terrain_extra_build_time(pterrain, activity, tgt) * ACTIVITY_FACTOR;
451 case ACTIVITY_IDLE:
453 case ACTIVITY_SENTRY:
454 case ACTIVITY_GOTO:
455 case ACTIVITY_EXPLORE:
457 case ACTIVITY_CONVERT:
458 case ACTIVITY_LAST:
459 return 0; /* FIXME: Should some of these be asserted against */
460 }
461
462 return 0;
463}
464
465/************************************************************************/
468static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
469{
470 if (fc_funcs->create_extra != NULL) {
471 /* Assume callback calls tile_add_extra() itself. */
472 fc_funcs->create_extra(ptile, pextra, NULL);
473 } else {
474 tile_add_extra(ptile, pextra);
475 }
476}
477
478/************************************************************************/
481static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
482{
483 if (fc_funcs->destroy_extra != NULL) {
484 /* Assume callback calls tile_remove_extra() itself. */
485 fc_funcs->destroy_extra(ptile, pextra);
486 } else {
487 tile_remove_extra(ptile, pextra);
488 }
489}
490
491/************************************************************************/
496void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
497{
498 tile_set_terrain(ptile, pterrain);
499
500 /* Remove unsupported extras */
501 extra_type_iterate(pextra) {
502 if (tile_has_extra(ptile, pextra)
503 && (!is_native_tile_to_extra(pextra, ptile)
505 tile_destroy_extra(ptile, pextra);
506 }
508}
509
510/************************************************************************/
513static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra,
514 int rec)
515{
516 if (rec > MAX_EXTRA_TYPES) {
517 /* Infinite recursion */
518 return FALSE;
519 }
520
521 /* First place dependency extras */
522 extra_deps_iterate(&(pextra->reqs), pdep) {
523 if (!tile_has_extra(ptile, pdep)) {
524 add_recursive_extras(ptile, pdep, rec + 1);
525 }
527
528 /* Is tile native for extra after that? */
529 if (!is_native_tile_to_extra(pextra, ptile)) {
530 return FALSE;
531 }
532
533 tile_create_extra(ptile, pextra);
534
535 return TRUE;
536}
537
538/************************************************************************/
541static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra,
542 int rec)
543{
544 if (rec > MAX_EXTRA_TYPES) {
545 /* Infinite recursion */
546 return FALSE;
547 }
548
550 if (tile_has_extra(ptile, pdepending)) {
552 if (pdep == pextra) {
553 /* Depends on what we are going to remove */
554 if (!rm_recursive_extras(ptile, pdepending, rec + 1)) {
555 return FALSE;
556 }
557 }
559 }
561
562 tile_destroy_extra(ptile, pextra);
563
564 return TRUE;
565}
566
567/************************************************************************/
575bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
576{
577 /* Add extra with its dependencies */
578 if (!add_recursive_extras(ptile, tgt, 0)) {
579 return FALSE;
580 }
581
582 /* Remove conflicting extras */
583 extra_type_iterate(pextra) {
584 if (tile_has_extra(ptile, pextra)
585 && !can_extras_coexist(pextra, tgt)) {
586 tile_destroy_extra(ptile, pextra);
587 }
589
590 return TRUE;
591}
592
593/************************************************************************/
601bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
602{
603 /* Remove extra with everything depending on it. */
604 if (!rm_recursive_extras(ptile, tgt, 0)) {
605 return FALSE;
606 }
607
608 return TRUE;
609}
610
611/************************************************************************/
615static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
616{
617 fc_assert(tgt != NULL);
618
619 if (tgt != NULL) {
620 tile_extra_apply(ptile, tgt);
621 }
622}
623
624/************************************************************************/
628static void tile_mine(struct tile *ptile, struct extra_type *tgt)
629{
630 fc_assert(tgt != NULL);
631
632 if (tgt != NULL) {
633 tile_extra_apply(ptile, tgt);
634 }
635}
636
637/************************************************************************/
641static void tile_transform(struct tile *ptile)
642{
643 struct terrain *pterrain = tile_terrain(ptile);
644
645 if (pterrain->transform_result != T_NONE) {
646 tile_change_terrain(ptile, pterrain->transform_result);
647 }
648}
649
650/************************************************************************/
654static void tile_plant(struct tile *ptile)
655{
656 struct terrain *pterrain = tile_terrain(ptile);
657
658 if (pterrain->plant_result != T_NONE) {
659 tile_change_terrain(ptile, pterrain->plant_result);
660 }
661}
662
663/************************************************************************/
667static void tile_cultivate(struct tile *ptile)
668{
669 struct terrain *pterrain = tile_terrain(ptile);
670
671 if (pterrain->cultivate_result != T_NONE) {
672 tile_change_terrain(ptile, pterrain->cultivate_result);
673 }
674}
675
676/************************************************************************/
682 struct extra_type *tgt)
683{
684 /* FIXME: for irrigate, mine, and transform we always return TRUE
685 * even if the activity fails. */
686 switch (act) {
687 case ACTIVITY_MINE:
688 tile_mine(ptile, tgt);
689 return TRUE;
690
691 case ACTIVITY_IRRIGATE:
692 tile_irrigate(ptile, tgt);
693 return TRUE;
694
696 tile_transform(ptile);
697 return TRUE;
698
700 tile_cultivate(ptile);
701 return TRUE;
702
703 case ACTIVITY_PLANT:
704 tile_plant(ptile);
705 return TRUE;
706
707 case ACTIVITY_PILLAGE:
708 case ACTIVITY_BASE:
710 case ACTIVITY_CLEAN:
711 /* Do nothing - not implemented */
712 return FALSE;
713
714 case ACTIVITY_IDLE:
716 case ACTIVITY_SENTRY:
717 case ACTIVITY_GOTO:
718 case ACTIVITY_EXPLORE:
719 case ACTIVITY_CONVERT:
721 case ACTIVITY_LAST:
722 /* Do nothing - these activities have no effect
723 on terrain type or tile extras */
724 return FALSE;
725 }
726
728
729 return FALSE;
730}
731
732/************************************************************************/
736static bool tile_info_pollution(char *buf, int bufsz,
737 const struct tile *ptile,
738 struct extra_type *pextra,
739 bool prevp, bool linebreak)
740{
741 if (tile_has_visible_extra(ptile, pextra)) {
742 if (!prevp) {
743 if (linebreak) {
744 fc_strlcat(buf, "\n[", bufsz);
745 } else {
746 fc_strlcat(buf, " [", bufsz);
747 }
748 } else {
749 fc_strlcat(buf, "/", bufsz);
750 }
751
753
754 return TRUE;
755 }
756
757 return prevp;
758}
759
760/************************************************************************/
771const char *tile_get_info_text(const struct tile *ptile,
773{
774 static char s[256];
775 bool pollution;
776 bool lb = FALSE;
777 int bufsz = sizeof(s);
778
781 /* Linebreak needed before next text */
782 lb = TRUE;
783 }
784
785 extra_type_iterate(pextra) {
786 if (pextra->category == ECAT_NATURAL
787 && tile_has_visible_extra(ptile, pextra)) {
788 if (lb) {
789 sz_strlcat(s, "\n");
790 lb = FALSE;
791 } else {
792 sz_strlcat(s, "/");
793 }
795 }
798 /* New linebreak requested */
799 lb = TRUE;
800 }
801
802 if (tile_resource_is_valid(ptile)) {
803 if (lb) {
804 sz_strlcat(s, "\n");
805 lb = FALSE;
806 } else {
807 sz_strlcat(s, " ");
808 }
809 cat_snprintf(s, sizeof(s), "(%s)",
811 }
813 /* New linebreak requested */
814 lb = TRUE;
815 }
816
817 if (include_nuisances) {
818 pollution = FALSE;
819 extra_type_iterate(pextra) {
820 if (pextra->category == ECAT_NUISANCE) {
821 pollution = tile_info_pollution(s, bufsz, ptile, pextra, pollution,
822 lb);
823 }
825 if (pollution) {
826 sz_strlcat(s, "]");
827 }
828 }
829
830 return s;
831}
832
833/************************************************************************/
836bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
837{
838 return tile_has_extra(ptile, base_extra_get(pbase));
839}
840
841/************************************************************************/
844bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
845{
846 return tile_has_extra(ptile, road_extra_get(proad));
847}
848
849/************************************************************************/
852bool tile_has_river(const struct tile *ptile)
853{
854 /* TODO: Have a list of rivers and iterate only that */
856 if (tile_has_extra(ptile, priver)
858 return TRUE;
859 }
861
862 return FALSE;
863}
864
865/************************************************************************/
868bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
869{
871 if (tile_has_extra(ptile, pextra)) {
872 struct road_type *proad = extra_road_get(pextra);
873
874 if (road_has_flag(proad, flag)) {
875 return TRUE;
876 }
877 }
879
880 return FALSE;
881}
882
883/************************************************************************/
886bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
887{
888 extra_type_iterate(pextra) {
889 if (tile_has_extra(ptile, pextra)
890 && extra_has_flag(pextra, flag)) {
891 return TRUE;
892 }
894
895 return FALSE;
896}
897
898/************************************************************************/
901bool tile_has_conflicting_extra(const struct tile *ptile,
902 const struct extra_type *pextra)
903{
905 if (BV_ISSET(pextra->conflicts, extra_index(pconfl))
906 && tile_has_extra(ptile, pconfl)) {
907 return TRUE;
908 }
910
911 return FALSE;
912}
913
914/************************************************************************/
917bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
918{
919 bool hidden = FALSE;
920
921 if (!BV_ISSET(ptile->extras, extra_index(pextra))) {
922 return FALSE;
923 }
924
925 extra_type_iterate(top) {
926 int topi = extra_index(top);
927
928 if (BV_ISSET(pextra->hidden_by, topi)
929 && BV_ISSET(ptile->extras, topi)) {
930 hidden = TRUE;
931 break;
932 }
934
935 return !hidden;
936}
937
938/************************************************************************/
941bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause)
942{
943 extra_type_by_cause_iterate(cause, pextra) {
944 if (tile_has_extra(ptile, pextra)) {
945 return TRUE;
946 }
948
949 return FALSE;
950}
951
952/************************************************************************/
955void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
956{
957 if (pextra != NULL) {
958 BV_SET(ptile->extras, extra_index(pextra));
959 }
960}
961
962/************************************************************************/
965void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
966{
967 if (pextra != NULL) {
968 BV_CLR(ptile->extras, extra_index(pextra));
969 if (ptile->resource == pextra) {
970 ptile->resource = NULL;
971 }
972 }
973}
974
975/************************************************************************/
981struct tile *tile_virtual_new(const struct tile *ptile)
982{
983 struct tile *vtile;
984
985 vtile = fc_calloc(1, sizeof(*vtile));
986
987 /* initialise some values */
988 vtile->index = TILE_INDEX_NONE;
989 vtile->continent = -1;
990
991 BV_CLR_ALL(vtile->extras);
992 vtile->resource = NULL;
993 vtile->terrain = NULL;
994 vtile->units = unit_list_new();
995 vtile->worked = NULL;
996 vtile->owner = NULL;
997 vtile->placing = NULL;
998 vtile->extras_owner = NULL;
999 vtile->claimer = NULL;
1000 vtile->spec_sprite = NULL;
1001
1002 if (ptile) {
1003 /* Used by is_city_center to give virtual tiles the output bonuses
1004 * they deserve. */
1005 vtile->index = tile_index(ptile);
1006
1007 /* Copy all but the unit list. */
1008 extra_type_iterate(pextra) {
1009 if (BV_ISSET(ptile->extras, extra_number(pextra))) {
1010 BV_SET(vtile->extras, extra_number(pextra));
1011 }
1013
1014 vtile->resource = ptile->resource;
1015 vtile->terrain = ptile->terrain;
1016 vtile->worked = ptile->worked;
1017 vtile->owner = ptile->owner;
1018 vtile->extras_owner = ptile->extras_owner;
1019 vtile->claimer = ptile->claimer;
1021 }
1022
1023 return vtile;
1024}
1025
1026/************************************************************************/
1034{
1035 struct city *vcity;
1036
1037 if (!vtile) {
1038 return;
1039 }
1040
1041 if (vtile->units) {
1042 unit_list_iterate(vtile->units, vunit) {
1043 if (unit_is_virtual(vunit)) {
1045 }
1047 unit_list_destroy(vtile->units);
1048 vtile->units = NULL;
1049 }
1050
1052 if (vcity) {
1053 if (city_is_virtual(vcity)) {
1055 }
1057 }
1058
1059 free(vtile);
1060}
1061
1062/************************************************************************/
1065bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
1066{
1067 int tindex;
1068
1069 if (!vtile || map_is_empty()) {
1070 return FALSE;
1071 }
1072
1073 tindex = tile_index(vtile);
1074 fc_assert_ret_val(0 <= tindex && tindex < map_num_tiles(), FALSE);
1075
1076 return (vtile == nmap->tiles + tindex);
1077}
1078
1079/************************************************************************/
1083void *tile_hash_key(const struct tile *ptile)
1084{
1085 void *key = 0; /* Initialize whole sizeof(void *) */
1086
1087 key = FC_INT_TO_PTR(ptile->index);
1088
1089 return key;
1090}
1091
1092/************************************************************************/
1095bool tile_set_label(struct tile *ptile, const char *label)
1096{
1097 bool changed = FALSE;
1098
1099 /* Handle empty label as NULL label */
1100 if (label != NULL && label[0] == '\0') {
1101 label = NULL;
1102 }
1103
1104 if (ptile->label != NULL) {
1105 if (label == NULL) {
1106 changed = TRUE;
1107 } else if (strcmp(ptile->label, label)) {
1108 changed = TRUE;
1109 }
1110 FC_FREE(ptile->label);
1111 ptile->label = NULL;
1112 } else if (label != NULL) {
1113 changed = TRUE;
1114 }
1115
1116 if (label != NULL) {
1117 if (strlen(label) >= MAX_LEN_MAP_LABEL) {
1118 log_error("Overlong map label '%s'", label);
1119 }
1120 ptile->label = fc_strdup(label);
1121 }
1122
1123 return changed;
1124}
1125
1126/************************************************************************/
1129bool tile_is_placing(const struct tile *ptile)
1130{
1131 return ptile->placing != NULL;
1132}
struct extra_type * base_extra_get(const struct base_type *pbase)
Definition base.c:101
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:158
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
bool city_is_virtual(const struct city *pcity)
Definition city.c:3589
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
void destroy_city_virtual(struct city *pcity)
Definition city.c:3516
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:868
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
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:861
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:633
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:852
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:1003
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:843
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:379
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:1116
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:1117
#define EC_DEFENSIVE
Definition fc_types.h:1115
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
#define MAX_LEN_MAP_LABEL
Definition fc_types.h:68
output_type_id
Definition fc_types.h:100
signed short Continent_id
Definition fc_types.h:372
@ BORDERS_DISABLED
Definition fc_types.h:1037
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:181
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_error(message,...)
Definition log.h:103
int map_num_tiles(void)
Definition map.c:1014
bool map_is_empty(void)
Definition map.c:149
#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:410
#define FC_INT_TO_PTR(i)
Definition shared.h:94
Definition city.h:320
struct player * owner
Definition city.h:323
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:308
struct terrain * cultivate_result
Definition terrain.h:215
int plant_time
Definition terrain.h:219
struct terrain * plant_result
Definition terrain.h:218
int cultivate_time
Definition terrain.h:216
int transform_time
Definition terrain.h:231
struct terrain * transform_result
Definition terrain.h:229
Definition tile.h:50
char * spec_sprite
Definition tile.h:66
char * label
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 extra_type_list * refuel_extras
Definition unittype.h:168
struct unit_class::@86 cache
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:836
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
#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:735
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:255
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:699
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
#define T_NONE
Definition terrain.h:56
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:242
static bool tile_info_pollution(char *buf, int bufsz, const struct tile *ptile, struct extra_type *pextra, bool prevp, bool linebreak)
Definition tile.c:736
static void tile_cultivate(struct tile *ptile)
Definition tile.c:667
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:955
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:291
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:886
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:124
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1033
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:575
static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:615
bool tile_has_river(const struct tile *ptile)
Definition tile.c:852
static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:481
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1129
const bv_extras * tile_extras_null(void)
Definition tile.c:166
bool tile_apply_activity(struct tile *ptile, Activity_type_id act, struct extra_type *tgt)
Definition tile.c:681
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1065
static void tile_transform(struct tile *ptile)
Definition tile.c:641
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:836
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:965
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:496
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:917
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:309
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:233
static void tile_mine(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:628
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:844
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:901
static void tile_plant(struct tile *ptile)
Definition tile.c:654
static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:468
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:407
static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:513
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:418
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:981
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:324
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:271
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1083
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1095
static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:541
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:349
int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:196
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
const bv_extras * tile_extras_safe(const struct tile *ptile)
Definition tile.c:181
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:771
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:868
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:941
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
void tile_set_continent(struct tile *ptile, Continent_id val)
Definition tile.c:382
#define TILE_LB_RIVER_RESOURCE
Definition tile.h:176
#define tile_claimer(_tile)
Definition tile.h:100
#define TILE_LB_RESOURCE_POLL
Definition tile.h:177
#define tile_index(_pt_)
Definition tile.h:88
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:103
#define tile_worked(_tile)
Definition tile.h:114
#define tile_resource(_tile)
Definition tile.h:102
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:165
#define TILE_LB_TERRAIN_RIVER
Definition tile.h:175
#define tile_terrain(_tile)
Definition tile.h:110
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_continent(_tile)
Definition tile.h:92
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
#define TILE_INDEX_NONE
Definition tile.h:48
#define tile_owner(_tile)
Definition tile.h:96
bool is_targeted_activity(enum unit_activity activity)
Definition unit.c:1614
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1729
bool unit_is_virtual(const struct unit *punit)
Definition unit.c:2270
#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:749