Freeciv-3.1
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
34static bv_extras empty_extras;
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/************************************************************************/
166const bv_extras *tile_extras_null(void)
167{
168 static bool empty_cleared = FALSE;
169
170 if (!empty_cleared) {
172 empty_cleared = TRUE;
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/************************************************************************/
194 const struct unit_type *punittype)
195{
197 if (tile_has_extra(ptile, pextra)
198 && is_native_extra_to_utype(pextra, punittype)) {
199 return TRUE;
200 }
202
203 return FALSE;
204}
205
206/************************************************************************/
209bool tile_has_claimable_base(const struct tile *ptile,
210 const struct unit_type *punittype)
211{
212 extra_type_list_iterate(utype_class(punittype)->cache.native_bases, pextra) {
213 struct base_type *pbase = extra_base_get(pextra);
214
215 if (tile_has_extra(ptile, pextra)
216 && territory_claiming_base(pbase)) {
217 return TRUE;
218 }
220
221 return FALSE;
222}
223
224/************************************************************************/
227int tile_extras_defense_bonus(const struct tile *ptile,
228 const struct unit_type *punittype)
229{
230 return tile_extras_class_defense_bonus(ptile, utype_class(punittype));
231}
232
233/************************************************************************/
236int tile_extras_class_defense_bonus(const struct tile *ptile,
237 const struct unit_class *pclass)
238{
239 int natural_bonus = 0;
240 int fortification_bonus = 0;
241 int total_bonus;
242
244 if (tile_has_extra(ptile, pextra)
245 && is_native_extra_to_uclass(pextra, pclass)) {
246 natural_bonus += pextra->defense_bonus;
247 }
249
251 if (tile_has_extra(ptile, pextra)
252 && is_native_extra_to_uclass(pextra, pclass)) {
253 fortification_bonus += pextra->defense_bonus;
254 }
256
257 total_bonus = (100 + natural_bonus) * (100 + fortification_bonus) / 100 - 100;
258
259 return total_bonus;
260}
261
262/************************************************************************/
265int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
266{
267 int const_incr = 0;
268 int incr = 0;
269
270 extra_type_by_cause_iterate(EC_ROAD, pextra) {
271 if (tile_has_extra(ptile, pextra)) {
272 struct road_type *proad = extra_road_get(pextra);
273
274 const_incr += proad->tile_incr_const[o];
275 incr += proad->tile_incr[o];
276 }
278
279 return const_incr + incr * tile_terrain(ptile)->road_output_incr_pct[o] / 100;
280}
281
282/************************************************************************/
285int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
286{
287 int bonus = 0;
288
289 extra_type_by_cause_iterate(EC_ROAD, pextra) {
290 if (tile_has_extra(ptile, pextra)) {
291 struct road_type *proad = extra_road_get(pextra);
292
293 bonus += proad->tile_bonus[o];
294 }
296
297 return bonus;
298}
299
300/************************************************************************/
303bool tile_has_refuel_extra(const struct tile *ptile,
304 const struct unit_class *uclass)
305{
307 if (tile_has_extra(ptile, pextra)) {
308 return TRUE;
309 }
311
312 return FALSE;
313}
314
315/************************************************************************/
318bool tile_has_native_base(const struct tile *ptile,
319 const struct unit_type *punittype)
320{
321 extra_type_list_iterate(utype_class(punittype)->cache.native_bases, pextra) {
322 if (tile_has_extra(ptile, pextra)) {
323 return TRUE;
324 }
326
327 return FALSE;
328}
329
330#ifndef tile_resource
331/************************************************************************/
334const struct resource_type *tile_resource(const struct tile *ptile)
335{
336 return ptile->resource;
337}
338#endif
339
340/************************************************************************/
343void tile_set_resource(struct tile *ptile, struct extra_type *presource)
344{
345 if (presource == ptile->resource) {
346 return; /* No change */
347 }
348
349 if (ptile->resource != NULL) {
350 tile_remove_extra(ptile, ptile->resource);
351 }
352 if (presource != NULL) {
353 if (ptile->terrain && terrain_has_resource(ptile->terrain, presource)) {
354 tile_add_extra(ptile, presource);
355 }
356 }
357
358 ptile->resource = presource;
359}
360
361#ifndef tile_continent
362/************************************************************************/
367Continent_id tile_continent(const struct tile *ptile)
368{
369 return ptile->continent;
370}
371#endif
372
373/************************************************************************/
376void tile_set_continent(struct tile *ptile, Continent_id val)
377{
378 ptile->continent = val;
379}
380
381/************************************************************************/
386enum known_type tile_get_known(const struct tile *ptile,
387 const struct player *pplayer)
388{
389 if (!dbv_isset(&pplayer->tile_known, tile_index(ptile))) {
390 return TILE_UNKNOWN;
391 } else if (!fc_funcs->player_tile_vision_get(ptile, pplayer, V_MAIN)) {
392 return TILE_KNOWN_UNSEEN;
393 } else {
394 return TILE_KNOWN_SEEN;
395 }
396}
397
398/************************************************************************/
401bool tile_is_seen(const struct tile *target_tile,
402 const struct player *pow_player)
403{
404 return tile_get_known(target_tile, pow_player) == TILE_KNOWN_SEEN;
405}
406
407/************************************************************************/
412int tile_activity_time(enum unit_activity activity, const struct tile *ptile,
413 const struct extra_type *tgt)
414{
415 struct terrain *pterrain = tile_terrain(ptile);
416
417 /* Make sure nobody uses old activities */
418 fc_assert_ret_val(activity != ACTIVITY_FORTRESS
419 && activity != ACTIVITY_AIRBASE, FC_INFINITY);
420
421 switch (activity) {
422 case ACTIVITY_POLLUTION:
423 case ACTIVITY_FALLOUT:
424 case ACTIVITY_PILLAGE:
425 return terrain_extra_removal_time(pterrain, activity, tgt) * ACTIVITY_FACTOR;
426 case ACTIVITY_TRANSFORM:
427 return pterrain->transform_time * ACTIVITY_FACTOR;
428 case ACTIVITY_CULTIVATE:
429 return pterrain->cultivate_time * ACTIVITY_FACTOR;
430 case ACTIVITY_PLANT:
431 return pterrain->plant_time * ACTIVITY_FACTOR;
432 case ACTIVITY_IRRIGATE:
433 case ACTIVITY_MINE:
434 case ACTIVITY_BASE:
435 case ACTIVITY_GEN_ROAD:
436 return terrain_extra_build_time(pterrain, activity, tgt) * ACTIVITY_FACTOR;
437 default:
438 return 0;
439 }
440}
441
442/************************************************************************/
445static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
446{
447 if (fc_funcs->create_extra != NULL) {
448 /* Assume callback calls tile_add_extra() itself. */
449 fc_funcs->create_extra(ptile, pextra, NULL);
450 } else {
451 tile_add_extra(ptile, pextra);
452 }
453}
454
455/************************************************************************/
458static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
459{
460 if (fc_funcs->destroy_extra != NULL) {
461 /* Assume callback calls tile_remove_extra() itself. */
462 fc_funcs->destroy_extra(ptile, pextra);
463 } else {
464 tile_remove_extra(ptile, pextra);
465 }
466}
467
468/************************************************************************/
473void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
474{
475 tile_set_terrain(ptile, pterrain);
476
477 /* Remove unsupported extras */
478 extra_type_iterate(pextra) {
479 if (tile_has_extra(ptile, pextra)
480 && (!is_native_tile_to_extra(pextra, ptile)
481 || extra_has_flag(pextra, EF_TERR_CHANGE_REMOVES))) {
482 tile_destroy_extra(ptile, pextra);
483 }
485}
486
487/************************************************************************/
490static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra,
491 int rec)
492{
493 if (rec > MAX_EXTRA_TYPES) {
494 /* Infinite recursion */
495 return FALSE;
496 }
497
498 /* First place dependency extras */
499 extra_deps_iterate(&(pextra->reqs), pdep) {
500 if (!tile_has_extra(ptile, pdep)) {
501 add_recursive_extras(ptile, pdep, rec + 1);
502 }
504
505 /* Is tile native for extra after that? */
506 if (!is_native_tile_to_extra(pextra, ptile)) {
507 return FALSE;
508 }
509
510 tile_create_extra(ptile, pextra);
511
512 return TRUE;
513}
514
515/************************************************************************/
518static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra,
519 int rec)
520{
521 if (rec > MAX_EXTRA_TYPES) {
522 /* Infinite recursion */
523 return FALSE;
524 }
525
526 extra_type_iterate(pdepending) {
527 if (tile_has_extra(ptile, pdepending)) {
528 extra_deps_iterate(&(pdepending->reqs), pdep) {
529 if (pdep == pextra) {
530 /* Depends on what we are going to remove */
531 if (!rm_recursive_extras(ptile, pdepending, rec + 1)) {
532 return FALSE;
533 }
534 }
536 }
538
539 tile_destroy_extra(ptile, pextra);
540
541 return TRUE;
542}
543
544/************************************************************************/
552bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
553{
554 /* Add extra with its dependencies */
555 if (!add_recursive_extras(ptile, tgt, 0)) {
556 return FALSE;
557 }
558
559 /* Remove conflicting extras */
560 extra_type_iterate(pextra) {
561 if (tile_has_extra(ptile, pextra)
562 && !can_extras_coexist(pextra, tgt)) {
563 tile_destroy_extra(ptile, pextra);
564 }
566
567 return TRUE;
568}
569
570/************************************************************************/
578bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
579{
580 /* Remove extra with everything depending on it. */
581 if (!rm_recursive_extras(ptile, tgt, 0)) {
582 return FALSE;
583 }
584
585 return TRUE;
586}
587
588/************************************************************************/
592static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
593{
594 fc_assert(tgt != NULL);
595
596 if (tgt != NULL) {
597 tile_extra_apply(ptile, tgt);
598 }
599}
600
601/************************************************************************/
605static void tile_mine(struct tile *ptile, struct extra_type *tgt)
606{
607 fc_assert(tgt != NULL);
608
609 if (tgt != NULL) {
610 tile_extra_apply(ptile, tgt);
611 }
612}
613
614/************************************************************************/
618static void tile_transform(struct tile *ptile)
619{
620 struct terrain *pterrain = tile_terrain(ptile);
621
622 if (pterrain->transform_result != T_NONE) {
623 tile_change_terrain(ptile, pterrain->transform_result);
624 }
625}
626
627/************************************************************************/
631static void tile_plant(struct tile *ptile)
632{
633 struct terrain *pterrain = tile_terrain(ptile);
634
635 if (pterrain->plant_result != T_NONE) {
636 tile_change_terrain(ptile, pterrain->plant_result);
637 }
638}
639
640/************************************************************************/
644static void tile_cultivate(struct tile *ptile)
645{
646 struct terrain *pterrain = tile_terrain(ptile);
647
648 if (pterrain->cultivate_result != T_NONE) {
649 tile_change_terrain(ptile, pterrain->cultivate_result);
650 }
651}
652
653/************************************************************************/
659 struct extra_type *tgt)
660{
661 /* FIXME: for irrigate, mine, and transform we always return TRUE
662 * even if the activity fails. */
663 switch (act) {
664 case ACTIVITY_MINE:
665 tile_mine(ptile, tgt);
666 return TRUE;
667
668 case ACTIVITY_IRRIGATE:
669 tile_irrigate(ptile, tgt);
670 return TRUE;
671
672 case ACTIVITY_TRANSFORM:
673 tile_transform(ptile);
674 return TRUE;
675
676 case ACTIVITY_CULTIVATE:
677 tile_cultivate(ptile);
678 return TRUE;
679
680 case ACTIVITY_PLANT:
681 tile_plant(ptile);
682 return TRUE;
683
684 case ACTIVITY_OLD_ROAD:
685 case ACTIVITY_OLD_RAILROAD:
686 case ACTIVITY_FORTRESS:
687 case ACTIVITY_AIRBASE:
689 return FALSE;
690
691 case ACTIVITY_PILLAGE:
692 case ACTIVITY_BASE:
693 case ACTIVITY_GEN_ROAD:
694 case ACTIVITY_POLLUTION:
695 case ACTIVITY_FALLOUT:
696 /* do nothing - not implemented */
697 return FALSE;
698
699 case ACTIVITY_IDLE:
700 case ACTIVITY_FORTIFIED:
701 case ACTIVITY_SENTRY:
702 case ACTIVITY_GOTO:
703 case ACTIVITY_EXPLORE:
704 case ACTIVITY_CONVERT:
705 case ACTIVITY_UNKNOWN:
706 case ACTIVITY_FORTIFYING:
707 case ACTIVITY_PATROL_UNUSED:
708 case ACTIVITY_LAST:
709 /* do nothing - these activities have no effect
710 on terrain type or tile extras */
711 return FALSE;
712 }
714 return FALSE;
715}
716
717/************************************************************************/
721static bool tile_info_pollution(char *buf, int bufsz,
722 const struct tile *ptile,
723 struct extra_type *pextra,
724 bool prevp, bool linebreak)
725{
726 if (tile_has_visible_extra(ptile, pextra)) {
727 if (!prevp) {
728 if (linebreak) {
729 fc_strlcat(buf, "\n[", bufsz);
730 } else {
731 fc_strlcat(buf, " [", bufsz);
732 }
733 } else {
734 fc_strlcat(buf, "/", bufsz);
735 }
736
738
739 return TRUE;
740 }
741
742 return prevp;
743}
744
745/************************************************************************/
756const char *tile_get_info_text(const struct tile *ptile,
757 bool include_nuisances, int linebreaks)
758{
759 static char s[256];
760 bool pollution;
761 bool lb = FALSE;
762 int bufsz = sizeof(s);
763
765 if (linebreaks & TILE_LB_TERRAIN_RIVER) {
766 /* Linebreak needed before next text */
767 lb = TRUE;
768 }
769
770 extra_type_iterate(pextra) {
771 if (pextra->category == ECAT_NATURAL
772 && tile_has_visible_extra(ptile, pextra)) {
773 if (lb) {
774 sz_strlcat(s, "\n");
775 lb = FALSE;
776 } else {
777 sz_strlcat(s, "/");
778 }
780 }
782 if (linebreaks & TILE_LB_RIVER_RESOURCE) {
783 /* New linebreak requested */
784 lb = TRUE;
785 }
786
787 if (tile_resource_is_valid(ptile)) {
788 if (lb) {
789 sz_strlcat(s, "\n");
790 lb = FALSE;
791 } else {
792 sz_strlcat(s, " ");
793 }
794 cat_snprintf(s, sizeof(s), "(%s)",
796 }
797 if (linebreaks & TILE_LB_RESOURCE_POLL) {
798 /* New linebreak requested */
799 lb = TRUE;
800 }
801
802 if (include_nuisances) {
803 pollution = FALSE;
804 extra_type_iterate(pextra) {
805 if (pextra->category == ECAT_NUISANCE) {
806 pollution = tile_info_pollution(s, bufsz, ptile, pextra, pollution,
807 lb);
808 }
810 if (pollution) {
811 sz_strlcat(s, "]");
812 }
813 }
814
815 return s;
816}
817
818/************************************************************************/
821bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
822{
823 return tile_has_extra(ptile, base_extra_get(pbase));
824}
825
826/************************************************************************/
829bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
830{
831 return tile_has_extra(ptile, road_extra_get(proad));
832}
833
834/************************************************************************/
837bool tile_has_river(const struct tile *ptile)
838{
839 /* TODO: Have a list of rivers and iterate only that */
840 extra_type_by_cause_iterate(EC_ROAD, priver) {
841 if (tile_has_extra(ptile, priver)
842 && road_has_flag(extra_road_get(priver), RF_RIVER)) {
843 return TRUE;
844 }
846
847 return FALSE;
848}
849
850/************************************************************************/
853bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
854{
855 extra_type_by_cause_iterate(EC_ROAD, pextra) {
856 if (tile_has_extra(ptile, pextra)) {
857 struct road_type *proad = extra_road_get(pextra);
858
859 if (road_has_flag(proad, flag)) {
860 return TRUE;
861 }
862 }
864
865 return FALSE;
866}
867
868/************************************************************************/
871bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
872{
873 extra_type_iterate(pextra) {
874 if (tile_has_extra(ptile, pextra)
875 && extra_has_flag(pextra, flag)) {
876 return TRUE;
877 }
879
880 return FALSE;
881}
882
883/************************************************************************/
886bool tile_has_conflicting_extra(const struct tile *ptile,
887 const struct extra_type *pextra)
888{
889 extra_type_iterate(pconfl) {
890 if (BV_ISSET(pextra->conflicts, extra_index(pconfl))
891 && tile_has_extra(ptile, pconfl)) {
892 return TRUE;
893 }
895
896 return FALSE;
897}
898
899/************************************************************************/
902bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
903{
904 bool hidden = FALSE;
905
906 if (!BV_ISSET(ptile->extras, extra_index(pextra))) {
907 return FALSE;
908 }
909
910 extra_type_iterate(top) {
911 int topi = extra_index(top);
912
913 if (BV_ISSET(pextra->hidden_by, topi)
914 && BV_ISSET(ptile->extras, topi)) {
915 hidden = TRUE;
916 break;
917 }
919
920 return !hidden;
921}
922
923/************************************************************************/
926bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause)
927{
928 extra_type_by_cause_iterate(cause, pextra) {
929 if (tile_has_extra(ptile, pextra)) {
930 return TRUE;
931 }
933
934 return FALSE;
935}
936
937/************************************************************************/
940void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
941{
942 if (pextra != NULL) {
943 BV_SET(ptile->extras, extra_index(pextra));
944 }
945}
946
947/************************************************************************/
950void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
951{
952 if (pextra != NULL) {
953 BV_CLR(ptile->extras, extra_index(pextra));
954 if (ptile->resource == pextra) {
955 ptile->resource = NULL;
956 }
957 }
958}
959
960/************************************************************************/
966struct tile *tile_virtual_new(const struct tile *ptile)
967{
968 struct tile *vtile;
969
970 vtile = fc_calloc(1, sizeof(*vtile));
971
972 /* initialise some values */
973 vtile->index = TILE_INDEX_NONE;
974 vtile->continent = -1;
975
976 BV_CLR_ALL(vtile->extras);
977 vtile->resource = NULL;
978 vtile->terrain = NULL;
979 vtile->units = unit_list_new();
980 vtile->worked = NULL;
981 vtile->owner = NULL;
982 vtile->placing = NULL;
983 vtile->extras_owner = NULL;
984 vtile->claimer = NULL;
985 vtile->spec_sprite = NULL;
986
987 if (ptile) {
988 /* Used by is_city_center to give virtual tiles the output bonuses
989 * they deserve. */
990 vtile->index = tile_index(ptile);
991
992 /* Copy all but the unit list. */
993 extra_type_iterate(pextra) {
994 if (BV_ISSET(ptile->extras, extra_number(pextra))) {
995 BV_SET(vtile->extras, extra_number(pextra));
996 }
998
999 vtile->resource = ptile->resource;
1000 vtile->terrain = ptile->terrain;
1001 vtile->worked = ptile->worked;
1002 vtile->owner = ptile->owner;
1003 vtile->extras_owner = ptile->extras_owner;
1004 vtile->claimer = ptile->claimer;
1005 vtile->spec_sprite = NULL;
1006 }
1007
1008 return vtile;
1009}
1010
1011/************************************************************************/
1018void tile_virtual_destroy(struct tile *vtile)
1019{
1020 struct city *vcity;
1021
1022 if (!vtile) {
1023 return;
1024 }
1025
1026 if (vtile->units) {
1027 unit_list_iterate(vtile->units, vunit) {
1028 if (unit_is_virtual(vunit)) {
1029 unit_virtual_destroy(vunit);
1030 }
1032 unit_list_destroy(vtile->units);
1033 vtile->units = NULL;
1034 }
1035
1036 vcity = tile_city(vtile);
1037 if (vcity) {
1038 if (city_is_virtual(vcity)) {
1039 destroy_city_virtual(vcity);
1040 }
1041 tile_set_worked(vtile, NULL);
1042 }
1043
1044 free(vtile);
1045}
1046
1047/************************************************************************/
1050bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
1051{
1052 int tindex;
1053
1054 if (!vtile || map_is_empty()) {
1055 return FALSE;
1056 }
1057
1058 tindex = tile_index(vtile);
1059 fc_assert_ret_val(0 <= tindex && tindex < map_num_tiles(), FALSE);
1060
1061 return (vtile == nmap->tiles + tindex);
1062}
1063
1064/************************************************************************/
1068void *tile_hash_key(const struct tile *ptile)
1069{
1070 void *key = 0; /* Initialize whole sizeof(void *) */
1071
1072 key = FC_INT_TO_PTR(ptile->index);
1073
1074 return key;
1075}
1076
1077/************************************************************************/
1080bool tile_set_label(struct tile *ptile, const char *label)
1081{
1082 bool changed = FALSE;
1083
1084 /* Handle empty label as NULL label */
1085 if (label != NULL && label[0] == '\0') {
1086 label = NULL;
1087 }
1088
1089 if (ptile->label != NULL) {
1090 if (label == NULL) {
1091 changed = TRUE;
1092 } else if (strcmp(ptile->label, label)) {
1093 changed = TRUE;
1094 }
1095 FC_FREE(ptile->label);
1096 ptile->label = NULL;
1097 } else if (label != NULL) {
1098 changed = TRUE;
1099 }
1100
1101 if (label != NULL) {
1102 if (strlen(label) >= MAX_LEN_MAP_LABEL) {
1103 log_error("Overlong map label '%s'", label);
1104 }
1105 ptile->label = fc_strdup(label);
1106 }
1107
1108 return changed;
1109}
1110
1111/************************************************************************/
1114bool tile_is_placing(const struct tile *ptile)
1115{
1116 return ptile->placing != NULL;
1117}
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:3488
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
void destroy_city_virtual(struct city *pcity)
Definition city.c:3419
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:844
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:56
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:810
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:608
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:801
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:952
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:792
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_deps_iterate(_reqs, _dep)
Definition extras.h:338
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:159
#define extra_type_iterate_end
Definition extras.h:297
#define extra_index(_e_)
Definition extras.h:177
#define extra_deps_iterate_end
Definition extras.h:346
#define extra_type_list_iterate_end
Definition extras.h:161
#define extra_base_get(_e_)
Definition extras.h:184
#define extra_road_get(_e_)
Definition extras.h:185
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
const struct functions * fc_funcs
static bool is_server(void)
enum unit_activity Activity_type_id
Definition fc_types.h:349
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:970
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:971
#define EC_DEFENSIVE
Definition fc_types.h:969
#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:90
signed short Continent_id
Definition fc_types.h:342
@ BORDERS_DISABLED
Definition fc_types.h:891
struct civ_game game
Definition game.c:57
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:1012
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_INFINITY
Definition shared.h:36
#define FC_INT_TO_PTR(i)
Definition shared.h:94
Definition city.h:309
struct packet_game_info info
Definition game.h:89
struct tile * tiles
Definition map_types.h:80
bv_extras conflicts
Definition extras.h:129
struct requirement_vector reqs
Definition extras.h:102
bv_extras hidden_by
Definition extras.h:130
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:306
int tile_bonus[O_LAST]
Definition road.h:82
int tile_incr_const[O_LAST]
Definition road.h:80
int tile_incr[O_LAST]
Definition road.h:81
struct terrain * cultivate_result
Definition terrain.h:203
int plant_time
Definition terrain.h:207
struct terrain * plant_result
Definition terrain.h:206
int cultivate_time
Definition terrain.h:204
int transform_time
Definition terrain.h:218
struct terrain * transform_result
Definition terrain.h:217
Definition tile.h:49
char * spec_sprite
Definition tile.h:65
char * label
Definition tile.h:64
int index
Definition tile.h:50
bv_extras extras
Definition tile.h:54
struct extra_type * resource
Definition tile.h:55
struct unit_list * units
Definition tile.h:57
struct player * extras_owner
Definition tile.h:62
struct terrain * terrain
Definition tile.h:56
struct extra_type * placing
Definition tile.h:60
struct city * worked
Definition tile.h:58
struct player * owner
Definition tile.h:59
Continent_id continent
Definition tile.h:53
struct tile * claimer
Definition tile.h:63
struct unit_class::@85 cache
struct extra_type_list * refuel_extras
Definition unittype.h:155
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:832
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:168
int terrain_extra_removal_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:718
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:243
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:682
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:135
#define T_NONE
Definition terrain.h:56
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:236
static bool tile_info_pollution(char *buf, int bufsz, const struct tile *ptile, struct extra_type *pextra, bool prevp, bool linebreak)
Definition tile.c:721
static void tile_cultivate(struct tile *ptile)
Definition tile.c:644
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:940
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:285
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:871
bool tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:193
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:124
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1018
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:552
static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:592
bool tile_has_river(const struct tile *ptile)
Definition tile.c:837
static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:458
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1114
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:658
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1050
static void tile_transform(struct tile *ptile)
Definition tile.c:618
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:821
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:950
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:473
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:902
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:303
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:227
static void tile_mine(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:605
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:829
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:886
static void tile_plant(struct tile *ptile)
Definition tile.c:631
static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:445
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:401
static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:490
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:412
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:966
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:318
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:265
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1068
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1080
static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:518
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:343
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
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:756
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:853
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:926
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:376
#define TILE_LB_RIVER_RESOURCE
Definition tile.h:175
#define tile_claimer(_tile)
Definition tile.h:99
#define TILE_LB_RESOURCE_POLL
Definition tile.h:176
#define tile_index(_pt_)
Definition tile.h:87
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:102
#define tile_worked(_tile)
Definition tile.h:113
#define tile_resource(_tile)
Definition tile.h:101
known_type
Definition tile.h:34
@ TILE_KNOWN_UNSEEN
Definition tile.h:36
@ TILE_UNKNOWN
Definition tile.h:35
@ TILE_KNOWN_SEEN
Definition tile.h:37
#define ACTIVITY_FACTOR
Definition tile.h:164
#define TILE_LB_TERRAIN_RIVER
Definition tile.h:174
#define tile_terrain(_tile)
Definition tile.h:109
#define TILE_XY(ptile)
Definition tile.h:42
#define tile_continent(_tile)
Definition tile.h:91
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
#define TILE_INDEX_NONE
Definition tile.h:47
#define tile_owner(_tile)
Definition tile.h:95
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1713
bool unit_is_virtual(const struct unit *punit)
Definition unit.c:2254
#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:736