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

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
34 static 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/************************************************************************/
69 void tile_set_owner(struct tile *ptile, struct player *pplayer,
70 struct tile *claimer)
71{
72 if (BORDERS_DISABLED != game.info.borders
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/************************************************************************/
83 struct 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/************************************************************************/
106 void 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/************************************************************************/
124 void 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/************************************************************************/
166 const bv_extras *tile_extras_null(void)
167{
168 static bool empty_cleared = FALSE;
169
170 if (!empty_cleared) {
171 BV_CLR_ALL(empty_extras);
172 empty_cleared = TRUE;
173 }
174
175 return &(empty_extras);
176}
177
178/************************************************************************/
181 const 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/************************************************************************/
193 bool tile_has_not_aggressive_extra_for_unit(const struct tile *ptile,
194 const struct unit_type *punittype)
195{
196 extra_type_by_cause_iterate(EC_NOT_AGGRESSIVE, pextra) {
197 if (tile_has_extra(ptile, pextra)
198 && is_native_extra_to_utype(pextra, punittype)) {
199 return TRUE;
200 }
201 } extra_type_by_cause_iterate_end;
202
203 return FALSE;
204}
205
206/************************************************************************/
209 bool 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 }
219 } extra_type_list_iterate_end;
220
221 return FALSE;
222}
223
224/************************************************************************/
227 int 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/************************************************************************/
236 int 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
243 extra_type_by_cause_iterate(EC_NATURAL_DEFENSIVE, pextra) {
244 if (tile_has_extra(ptile, pextra)
245 && is_native_extra_to_uclass(pextra, pclass)) {
246 natural_bonus += pextra->defense_bonus;
247 }
248 } extra_type_by_cause_iterate_end;
249
250 extra_type_by_cause_iterate(EC_DEFENSIVE, pextra) {
251 if (tile_has_extra(ptile, pextra)
252 && is_native_extra_to_uclass(pextra, pclass)) {
253 fortification_bonus += pextra->defense_bonus;
254 }
255 } extra_type_by_cause_iterate_end;
256
257 total_bonus = (100 + natural_bonus) * (100 + fortification_bonus) / 100 - 100;
258
259 return total_bonus;
260}
261
262/************************************************************************/
265 int 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 }
277 } extra_type_by_cause_iterate_end;
278
279 return const_incr + incr * tile_terrain(ptile)->road_output_incr_pct[o] / 100;
280}
281
282/************************************************************************/
285 int 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 }
295 } extra_type_by_cause_iterate_end;
296
297 return bonus;
298}
299
300/************************************************************************/
303 bool tile_has_refuel_extra(const struct tile *ptile,
304 const struct unit_class *uclass)
305{
306 extra_type_list_iterate(uclass->cache.refuel_extras, pextra) {
307 if (tile_has_extra(ptile, pextra)) {
308 return TRUE;
309 }
310 } extra_type_list_iterate_end;
311
312 return FALSE;
313}
314
315/************************************************************************/
318 bool 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 }
325 } extra_type_list_iterate_end;
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/************************************************************************/
343 void 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/************************************************************************/
367 Continent_id tile_continent(const struct tile *ptile)
368{
369 return ptile->continent;
370}
371#endif
372
373/************************************************************************/
376 void tile_set_continent(struct tile *ptile, Continent_id val)
377{
378 ptile->continent = val;
379}
380
381/************************************************************************/
386 enum 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/************************************************************************/
401 bool 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/************************************************************************/
412 int 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/************************************************************************/
445 static 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/************************************************************************/
458 static 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/************************************************************************/
473 void 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 }
484 } extra_type_iterate_end;
485}
486
487/************************************************************************/
490 static 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 }
503 } extra_deps_iterate_end;
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/************************************************************************/
518 static 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 }
535 } extra_deps_iterate_end;
536 }
537 } extra_type_iterate_end;
538
539 tile_destroy_extra(ptile, pextra);
540
541 return TRUE;
542}
543
544/************************************************************************/
552 bool 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 }
565 } extra_type_iterate_end;
566
567 return TRUE;
568}
569
570/************************************************************************/
578 bool 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/************************************************************************/
592 static 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/************************************************************************/
605 static 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/************************************************************************/
618 static 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/************************************************************************/
631 static 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/************************************************************************/
644 static 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/************************************************************************/
658 bool tile_apply_activity(struct tile *ptile, Activity_type_id act,
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:
688 fc_assert(FALSE);
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 }
713 fc_assert(FALSE);
714 return FALSE;
715}
716
717/************************************************************************/
721 static 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
737 fc_strlcat(buf, extra_name_translation(pextra), bufsz);
738
739 return TRUE;
740 }
741
742 return prevp;
743}
744
745/************************************************************************/
756 const 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
764 sz_strlcpy(s, terrain_name_translation(tile_terrain(ptile)));
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 }
779 sz_strlcat(s, extra_name_translation(pextra));
780 }
781 } extra_type_iterate_end;
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)",
795 extra_name_translation(ptile->resource));
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 }
809 } extra_type_iterate_end;
810 if (pollution) {
811 sz_strlcat(s, "]");
812 }
813 }
814
815 return s;
816}
817
818/************************************************************************/
821 bool 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/************************************************************************/
829 bool 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/************************************************************************/
837 bool 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 }
845 } extra_type_by_cause_iterate_end;
846
847 return FALSE;
848}
849
850/************************************************************************/
853 bool 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 }
863 } extra_type_by_cause_iterate_end;
864
865 return FALSE;
866}
867
868/************************************************************************/
871 bool 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 }
878 } extra_type_iterate_end;
879
880 return FALSE;
881}
882
883/************************************************************************/
886 bool 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 }
894 } extra_type_iterate_end;
895
896 return FALSE;
897}
898
899/************************************************************************/
902 bool 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 }
918 } extra_type_iterate_end;
919
920 return !hidden;
921}
922
923/************************************************************************/
926 bool 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 }
932 } extra_type_by_cause_iterate_end;
933
934 return FALSE;
935}
936
937/************************************************************************/
940 void 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/************************************************************************/
950 void 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/************************************************************************/
966 struct 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 }
997 } extra_type_iterate_end;
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/************************************************************************/
1018 void 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 }
1031 } unit_list_iterate_end;
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/************************************************************************/
1050 bool 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/************************************************************************/
1068 void *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/************************************************************************/
1080 bool 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/************************************************************************/
1114 bool tile_is_placing(const struct tile *ptile)
1115{
1116 return ptile->placing != NULL;
1117}
base_extra_get
struct extra_type * base_extra_get(const struct base_type *pbase)
Definition base.c:101
territory_claiming_base
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:158
dbv_isset
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
bitvector.h
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
BV_CLR
#define BV_CLR(bv, bit)
Definition bitvector.h:86
city_is_virtual
bool city_is_virtual(const struct city *pcity)
Definition city.c:3484
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1111
destroy_city_virtual
void destroy_city_virtual(struct city *pcity)
Definition city.c:3415
is_city_center
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:835
target_tile
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:56
extra_number
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
extra_has_flag
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:810
is_native_tile_to_extra
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:608
is_native_extra_to_utype
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:801
can_extras_coexist
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:952
is_native_extra_to_uclass
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:792
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:291
extra_deps_iterate
#define extra_deps_iterate(_reqs, _dep)
Definition extras.h:338
extra_type_list_iterate
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:159
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:297
extra_index
#define extra_index(_e_)
Definition extras.h:177
extra_deps_iterate_end
#define extra_deps_iterate_end
Definition extras.h:346
extra_type_list_iterate_end
#define extra_type_list_iterate_end
Definition extras.h:161
extra_base_get
#define extra_base_get(_e_)
Definition extras.h:184
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:185
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:315
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
fc_funcs
const struct functions * fc_funcs
Definition fc_interface.c:38
fc_interface.h
is_server
static bool is_server(void)
Definition fc_interface.h:69
Activity_type_id
enum unit_activity Activity_type_id
Definition fc_types.h:349
EC_NATURAL_DEFENSIVE
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:970
EC_NOT_AGGRESSIVE
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:971
EC_DEFENSIVE
#define EC_DEFENSIVE
Definition fc_types.h:969
MAX_EXTRA_TYPES
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
MAX_LEN_MAP_LABEL
#define MAX_LEN_MAP_LABEL
Definition fc_types.h:68
output_type_id
output_type_id
Definition fc_types.h:90
Continent_id
signed short Continent_id
Definition fc_types.h:342
BORDERS_DISABLED
@ BORDERS_DISABLED
Definition fc_types.h:891
game
struct civ_game game
Definition game.c:57
game.h
bufsz
static const int bufsz
Definition helpdlg.c:70
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
log_error
#define log_error(message,...)
Definition log.h:103
map_num_tiles
int map_num_tiles(void)
Definition map.c:1012
map_is_empty
bool map_is_empty(void)
Definition map.c:149
map.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
movement.h
road_extra_get
struct extra_type * road_extra_get(const struct road_type *proad)
Definition road.c:42
road_has_flag
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
road.h
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
FC_INT_TO_PTR
#define FC_INT_TO_PTR(i)
Definition shared.h:94
base_type
Definition base.h:41
city
Definition city.h:309
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_map
Definition map_types.h:71
civ_map::tiles
struct tile * tiles
Definition map_types.h:80
extra_type
Definition extras.h:85
extra_type::conflicts
bv_extras conflicts
Definition extras.h:129
extra_type::reqs
struct requirement_vector reqs
Definition extras.h:102
extra_type::hidden_by
bv_extras hidden_by
Definition extras.h:130
functions::player_tile_vision_get
bool(* player_tile_vision_get)(const struct tile *ptile, const struct player *pplayer, enum vision_layer vision)
Definition fc_interface.h:46
functions::destroy_extra
void(* destroy_extra)(struct tile *ptile, struct extra_type *pextra)
Definition fc_interface.h:42
functions::create_extra
void(* create_extra)(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition fc_interface.h:40
packet_game_info::borders
enum borders_mode borders
Definition packets_gen.h:133
player
Definition player.h:249
player::tile_known
struct dbv tile_known
Definition player.h:306
resource_type
Definition terrain.h:43
road_type
Definition road.h:75
road_type::tile_bonus
int tile_bonus[O_LAST]
Definition road.h:82
road_type::tile_incr_const
int tile_incr_const[O_LAST]
Definition road.h:80
road_type::tile_incr
int tile_incr[O_LAST]
Definition road.h:81
terrain
Definition terrain.h:176
terrain::cultivate_result
struct terrain * cultivate_result
Definition terrain.h:203
terrain::plant_time
int plant_time
Definition terrain.h:207
terrain::plant_result
struct terrain * plant_result
Definition terrain.h:206
terrain::cultivate_time
int cultivate_time
Definition terrain.h:204
terrain::transform_time
int transform_time
Definition terrain.h:218
terrain::transform_result
struct terrain * transform_result
Definition terrain.h:217
tile
Definition tile.h:49
tile::spec_sprite
char * spec_sprite
Definition tile.h:65
tile::label
char * label
Definition tile.h:64
tile::index
int index
Definition tile.h:50
tile::extras
bv_extras extras
Definition tile.h:54
tile::resource
struct extra_type * resource
Definition tile.h:55
tile::units
struct unit_list * units
Definition tile.h:57
tile::extras_owner
struct player * extras_owner
Definition tile.h:62
tile::terrain
struct terrain * terrain
Definition tile.h:56
tile::placing
struct extra_type * placing
Definition tile.h:60
tile::worked
struct city * worked
Definition tile.h:58
tile::owner
struct player * owner
Definition tile.h:59
tile::continent
Continent_id continent
Definition tile.h:53
tile::claimer
struct tile * claimer
Definition tile.h:63
unit_class
Definition unittype.h:136
unit_class::cache
struct unit_class::@85 cache
unit_class::refuel_extras
struct extra_type_list * refuel_extras
Definition unittype.h:155
unit_type
Definition unittype.h:481
fc_strlcat
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:832
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
sz_strlcat
#define sz_strlcat(dest, src)
Definition support.h:162
terrain_extra_removal_time
int terrain_extra_removal_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:718
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
terrain_has_resource
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:243
terrain_extra_build_time
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:682
terrain_number
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:135
T_NONE
#define T_NONE
Definition terrain.h:56
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:269
tile_extras_class_defense_bonus
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:236
tile_info_pollution
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
tile_cultivate
static void tile_cultivate(struct tile *ptile)
Definition tile.c:644
tile_add_extra
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:940
tile_roads_output_bonus
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:285
tile_has_extra_flag
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:871
tile_has_not_aggressive_extra_for_unit
bool tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:193
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
tile_set_terrain
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:124
tile_virtual_destroy
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1018
tile_extra_apply
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:552
tile_irrigate
static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:592
tile_has_river
bool tile_has_river(const struct tile *ptile)
Definition tile.c:837
tile_destroy_extra
static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:458
tile_is_placing
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1114
tile_extras_null
const bv_extras * tile_extras_null(void)
Definition tile.c:166
tile_apply_activity
bool tile_apply_activity(struct tile *ptile, Activity_type_id act, struct extra_type *tgt)
Definition tile.c:658
tile_map_check
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1050
tile_transform
static void tile_transform(struct tile *ptile)
Definition tile.c:618
tile_has_base
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:821
tile_remove_extra
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:950
tile_change_terrain
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:473
tile_has_visible_extra
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:902
tile_has_refuel_extra
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:303
tile_extras_defense_bonus
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:227
tile_mine
static void tile_mine(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:605
tile_has_road
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:829
tile_has_conflicting_extra
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:886
tile_plant
static void tile_plant(struct tile *ptile)
Definition tile.c:631
tile_create_extra
static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:445
tile_set_owner
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
tile_is_seen
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:401
add_recursive_extras
static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:490
tile_activity_time
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:412
tile_virtual_new
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:966
tile_has_native_base
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:318
tile_roads_output_incr
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:265
tile_hash_key
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1068
tile_extra_rm_apply
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
tile_set_label
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1080
rm_recursive_extras
static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:518
tile_set_resource
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:343
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
tile_extras_safe
const bv_extras * tile_extras_safe(const struct tile *ptile)
Definition tile.c:181
tile_get_info_text
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:756
tile_has_road_flag
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:853
empty_extras
static bv_extras empty_extras
Definition tile.c:34
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_has_cause_extra
bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause)
Definition tile.c:926
tile_set_worked
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
tile_set_continent
void tile_set_continent(struct tile *ptile, Continent_id val)
Definition tile.c:376
tile.h
TILE_LB_RIVER_RESOURCE
#define TILE_LB_RIVER_RESOURCE
Definition tile.h:175
tile_claimer
#define tile_claimer(_tile)
Definition tile.h:99
TILE_LB_RESOURCE_POLL
#define TILE_LB_RESOURCE_POLL
Definition tile.h:176
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tile_resource_is_valid
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:102
tile_worked
#define tile_worked(_tile)
Definition tile.h:113
tile_resource
#define tile_resource(_tile)
Definition tile.h:101
known_type
known_type
Definition tile.h:34
TILE_KNOWN_UNSEEN
@ TILE_KNOWN_UNSEEN
Definition tile.h:36
TILE_UNKNOWN
@ TILE_UNKNOWN
Definition tile.h:35
TILE_KNOWN_SEEN
@ TILE_KNOWN_SEEN
Definition tile.h:37
ACTIVITY_FACTOR
#define ACTIVITY_FACTOR
Definition tile.h:164
TILE_LB_TERRAIN_RIVER
#define TILE_LB_TERRAIN_RIVER
Definition tile.h:174
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:42
tile_continent
#define tile_continent(_tile)
Definition tile.h:91
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
TILE_INDEX_NONE
#define TILE_INDEX_NONE
Definition tile.h:47
tile_owner
#define tile_owner(_tile)
Definition tile.h:95
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1715
unit_is_virtual
bool unit_is_virtual(const struct unit *punit)
Definition unit.c:2256
unit.h
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
utype_class
#define utype_class(_t_)
Definition unittype.h:736