Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/tile.c Source File

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
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/************************************************************************/
196 int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile,
197 const struct unit_type *punittype)
198{
199 int max_friendliness_range = -1;
200
201 extra_type_by_cause_iterate(EC_NOT_AGGRESSIVE, pextra) {
202 if (tile_has_extra(ptile, pextra)
203 && is_native_extra_to_utype(pextra, punittype)
204 && pextra->no_aggr_near_city > max_friendliness_range) {
205 max_friendliness_range = pextra->no_aggr_near_city;
206 }
207 } extra_type_by_cause_iterate_end;
208
209 return max_friendliness_range;
210}
211
212/************************************************************************/
215 bool 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)
222 && territory_claiming_base(pbase)) {
223 return TRUE;
224 }
225 } extra_type_list_iterate_end;
226
227 return FALSE;
228}
229
230/************************************************************************/
233 int tile_extras_defense_bonus(const struct tile *ptile,
234 const struct unit_type *punittype)
235{
236 return tile_extras_class_defense_bonus(ptile, utype_class(punittype));
237}
238
239/************************************************************************/
242 int 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
249 extra_type_by_cause_iterate(EC_NATURAL_DEFENSIVE, pextra) {
250 if (tile_has_extra(ptile, pextra)
251 && is_native_extra_to_uclass(pextra, pclass)) {
252 natural_bonus += pextra->defense_bonus;
253 }
254 } extra_type_by_cause_iterate_end;
255
256 extra_type_by_cause_iterate(EC_DEFENSIVE, pextra) {
257 if (tile_has_extra(ptile, pextra)
258 && is_native_extra_to_uclass(pextra, pclass)) {
259 fortification_bonus += pextra->defense_bonus;
260 }
261 } extra_type_by_cause_iterate_end;
262
263 total_bonus = (100 + natural_bonus) * (100 + fortification_bonus) / 100 - 100;
264
265 return total_bonus;
266}
267
268/************************************************************************/
271 int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
272{
273 int const_incr = 0;
274 int incr = 0;
275
276 extra_type_by_cause_iterate(EC_ROAD, pextra) {
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 }
283 } extra_type_by_cause_iterate_end;
284
285 return const_incr + incr * tile_terrain(ptile)->road_output_incr_pct[o] / 100;
286}
287
288/************************************************************************/
291 int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
292{
293 int bonus = 0;
294
295 extra_type_by_cause_iterate(EC_ROAD, pextra) {
296 if (tile_has_extra(ptile, pextra)) {
297 struct road_type *proad = extra_road_get(pextra);
298
299 bonus += proad->tile_bonus[o];
300 }
301 } extra_type_by_cause_iterate_end;
302
303 return bonus;
304}
305
306/************************************************************************/
309 bool tile_has_refuel_extra(const struct tile *ptile,
310 const struct unit_class *uclass)
311{
312 extra_type_list_iterate(uclass->cache.refuel_extras, pextra) {
313 if (tile_has_extra(ptile, pextra)) {
314 return TRUE;
315 }
316 } extra_type_list_iterate_end;
317
318 return FALSE;
319}
320
321/************************************************************************/
324 bool 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 }
331 } extra_type_list_iterate_end;
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/************************************************************************/
349 void 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/************************************************************************/
373 Continent_id tile_continent(const struct tile *ptile)
374{
375 return ptile->continent;
376}
377#endif
378
379/************************************************************************/
382 void tile_set_continent(struct tile *ptile, Continent_id val)
383{
384 ptile->continent = val;
385}
386
387/************************************************************************/
392 enum 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/************************************************************************/
407 bool tile_is_seen(const struct tile *target_tile,
408 const struct player *pow_player)
409{
410 return tile_get_known(target_tile, pow_player) == TILE_KNOWN_SEEN;
411}
412
413/************************************************************************/
418 int 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);
422 int eff = get_target_bonus_effects(NULL,
423 &(const struct req_context) {
424 .tile = ptile,
425 .activity = activity,
426 .extra = tgt
427 }, NULL, EFT_ACTIVITY_TIME);
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;
440 case ACTIVITY_TRANSFORM:
441 return pterrain->transform_time * ACTIVITY_FACTOR;
442 case ACTIVITY_CULTIVATE:
443 return pterrain->cultivate_time * ACTIVITY_FACTOR;
444 case ACTIVITY_PLANT:
445 return pterrain->plant_time * ACTIVITY_FACTOR;
446 case ACTIVITY_IRRIGATE:
447 case ACTIVITY_MINE:
448 case ACTIVITY_BASE:
449 case ACTIVITY_GEN_ROAD:
450 return terrain_extra_build_time(pterrain, activity, tgt) * ACTIVITY_FACTOR;
451 case ACTIVITY_IDLE:
452 case ACTIVITY_FORTIFIED:
453 case ACTIVITY_SENTRY:
454 case ACTIVITY_GOTO:
455 case ACTIVITY_EXPLORE:
456 case ACTIVITY_FORTIFYING:
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/************************************************************************/
468 static 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/************************************************************************/
481 static 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/************************************************************************/
496 void 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)
504 || extra_has_flag(pextra, EF_TERR_CHANGE_REMOVES))) {
505 tile_destroy_extra(ptile, pextra);
506 }
507 } extra_type_iterate_end;
508}
509
510/************************************************************************/
513 static 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 }
526 } extra_deps_iterate_end;
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/************************************************************************/
541 static 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
549 extra_type_iterate(pdepending) {
550 if (tile_has_extra(ptile, pdepending)) {
551 extra_deps_iterate(&(pdepending->reqs), pdep) {
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 }
558 } extra_deps_iterate_end;
559 }
560 } extra_type_iterate_end;
561
562 tile_destroy_extra(ptile, pextra);
563
564 return TRUE;
565}
566
567/************************************************************************/
575 bool 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 }
588 } extra_type_iterate_end;
589
590 return TRUE;
591}
592
593/************************************************************************/
601 bool 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/************************************************************************/
615 static 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/************************************************************************/
628 static 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/************************************************************************/
641 static 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/************************************************************************/
654 static 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/************************************************************************/
667 static 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/************************************************************************/
681 bool tile_apply_activity(struct tile *ptile, Activity_type_id act,
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
695 case ACTIVITY_TRANSFORM:
696 tile_transform(ptile);
697 return TRUE;
698
699 case ACTIVITY_CULTIVATE:
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:
709 case ACTIVITY_GEN_ROAD:
710 case ACTIVITY_CLEAN:
711 /* Do nothing - not implemented */
712 return FALSE;
713
714 case ACTIVITY_IDLE:
715 case ACTIVITY_FORTIFIED:
716 case ACTIVITY_SENTRY:
717 case ACTIVITY_GOTO:
718 case ACTIVITY_EXPLORE:
719 case ACTIVITY_CONVERT:
720 case ACTIVITY_FORTIFYING:
721 case ACTIVITY_LAST:
722 /* Do nothing - these activities have no effect
723 on terrain type or tile extras */
724 return FALSE;
725 }
726
727 fc_assert(FALSE);
728
729 return FALSE;
730}
731
732/************************************************************************/
736 static 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
752 fc_strlcat(buf, extra_name_translation(pextra), bufsz);
753
754 return TRUE;
755 }
756
757 return prevp;
758}
759
760/************************************************************************/
771 const char *tile_get_info_text(const struct tile *ptile,
772 bool include_nuisances, int linebreaks)
773{
774 static char s[256];
775 bool pollution;
776 bool lb = FALSE;
777 int bufsz = sizeof(s);
778
779 sz_strlcpy(s, terrain_name_translation(tile_terrain(ptile)));
780 if (linebreaks & TILE_LB_TERRAIN_RIVER) {
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 }
794 sz_strlcat(s, extra_name_translation(pextra));
795 }
796 } extra_type_iterate_end;
797 if (linebreaks & TILE_LB_RIVER_RESOURCE) {
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)",
810 extra_name_translation(ptile->resource));
811 }
812 if (linebreaks & TILE_LB_RESOURCE_POLL) {
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 }
824 } extra_type_iterate_end;
825 if (pollution) {
826 sz_strlcat(s, "]");
827 }
828 }
829
830 return s;
831}
832
833/************************************************************************/
836 bool 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/************************************************************************/
844 bool 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/************************************************************************/
852 bool tile_has_river(const struct tile *ptile)
853{
854 /* TODO: Have a list of rivers and iterate only that */
855 extra_type_by_cause_iterate(EC_ROAD, priver) {
856 if (tile_has_extra(ptile, priver)
857 && road_has_flag(extra_road_get(priver), RF_RIVER)) {
858 return TRUE;
859 }
860 } extra_type_by_cause_iterate_end;
861
862 return FALSE;
863}
864
865/************************************************************************/
868 bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
869{
870 extra_type_by_cause_iterate(EC_ROAD, pextra) {
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 }
878 } extra_type_by_cause_iterate_end;
879
880 return FALSE;
881}
882
883/************************************************************************/
886 bool 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 }
893 } extra_type_iterate_end;
894
895 return FALSE;
896}
897
898/************************************************************************/
901 bool tile_has_conflicting_extra(const struct tile *ptile,
902 const struct extra_type *pextra)
903{
904 extra_type_iterate(pconfl) {
905 if (BV_ISSET(pextra->conflicts, extra_index(pconfl))
906 && tile_has_extra(ptile, pconfl)) {
907 return TRUE;
908 }
909 } extra_type_iterate_end;
910
911 return FALSE;
912}
913
914/************************************************************************/
917 bool 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 }
933 } extra_type_iterate_end;
934
935 return !hidden;
936}
937
938/************************************************************************/
941 bool 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 }
947 } extra_type_by_cause_iterate_end;
948
949 return FALSE;
950}
951
952/************************************************************************/
955 void 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/************************************************************************/
965 void 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/************************************************************************/
981 struct 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 }
1012 } extra_type_iterate_end;
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;
1020 vtile->spec_sprite = NULL;
1021 }
1022
1023 return vtile;
1024}
1025
1026/************************************************************************/
1033 void tile_virtual_destroy(struct tile *vtile)
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)) {
1044 unit_virtual_destroy(vunit);
1045 }
1046 } unit_list_iterate_end;
1047 unit_list_destroy(vtile->units);
1048 vtile->units = NULL;
1049 }
1050
1051 vcity = tile_city(vtile);
1052 if (vcity) {
1053 if (city_is_virtual(vcity)) {
1054 destroy_city_virtual(vcity);
1055 }
1056 tile_set_worked(vtile, NULL);
1057 }
1058
1059 free(vtile);
1060}
1061
1062/************************************************************************/
1065 bool 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/************************************************************************/
1083 void *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/************************************************************************/
1095 bool 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/************************************************************************/
1129 bool tile_is_placing(const struct tile *ptile)
1130{
1131 return ptile->placing != NULL;
1132}
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:3577
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
destroy_city_virtual
void destroy_city_virtual(struct city *pcity)
Definition city.c:3504
is_city_center
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:856
incite_cost
char * incite_cost
Definition comments.c:74
target_tile
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
get_target_bonus_effects
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
extra_number
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
extra_has_flag
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:861
is_native_tile_to_extra
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:633
is_native_extra_to_utype
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:852
can_extras_coexist
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:1003
is_native_extra_to_uclass
bool is_native_extra_to_uclass(const struct extra_type *pextra, const struct unit_class *pclass)
Definition extras.c:843
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:315
extra_deps_iterate
#define extra_deps_iterate(_reqs, _dep)
Definition extras.h:371
extra_type_list_iterate
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:321
extra_index
#define extra_index(_e_)
Definition extras.h:183
extra_deps_iterate_end
#define extra_deps_iterate_end
Definition extras.h:379
extra_type_list_iterate_end
#define extra_type_list_iterate_end
Definition extras.h:167
extra_base_get
#define extra_base_get(_e_)
Definition extras.h:190
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:191
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:339
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
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:382
EC_NATURAL_DEFENSIVE
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:1117
EC_NOT_AGGRESSIVE
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:1118
EC_DEFENSIVE
#define EC_DEFENSIVE
Definition fc_types.h:1116
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:100
Continent_id
signed short Continent_id
Definition fc_types.h:375
BORDERS_DISABLED
@ BORDERS_DISABLED
Definition fc_types.h:1038
game
struct civ_game game
Definition game.c:62
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:1014
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_INT_TO_PTR
#define FC_INT_TO_PTR(i)
Definition shared.h:94
base_type
Definition base.h:41
city
Definition city.h:320
city::owner
struct player * owner
Definition city.h:323
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:88
extra_type::conflicts
bv_extras conflicts
Definition extras.h:133
extra_type::reqs
struct requirement_vector reqs
Definition extras.h:106
extra_type::hidden_by
bv_extras hidden_by
Definition extras.h:134
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:130
player
Definition player.h:247
player::tile_known
struct dbv tile_known
Definition player.h:308
req_context
Definition requirements.h:100
resource_type
Definition terrain.h:43
road_type
Definition road.h:71
terrain
Definition terrain.h:182
terrain::cultivate_result
struct terrain * cultivate_result
Definition terrain.h:215
terrain::plant_time
int plant_time
Definition terrain.h:219
terrain::plant_result
struct terrain * plant_result
Definition terrain.h:218
terrain::cultivate_time
int cultivate_time
Definition terrain.h:216
terrain::transform_time
int transform_time
Definition terrain.h:231
terrain::transform_result
struct terrain * transform_result
Definition terrain.h:229
tile
Definition tile.h:50
tile::spec_sprite
char * spec_sprite
Definition tile.h:66
tile::label
char * label
Definition tile.h:65
tile::index
int index
Definition tile.h:51
tile::extras
bv_extras extras
Definition tile.h:55
tile::resource
struct extra_type * resource
Definition tile.h:56
tile::extras_owner
struct player * extras_owner
Definition tile.h:63
tile::terrain
struct terrain * terrain
Definition tile.h:57
tile::placing
struct extra_type * placing
Definition tile.h:61
tile::worked
struct city * worked
Definition tile.h:59
tile::owner
struct player * owner
Definition tile.h:60
tile::continent
Continent_id continent
Definition tile.h:54
tile::claimer
struct tile * claimer
Definition tile.h:64
unit_class
Definition unittype.h:149
unit_class::refuel_extras
struct extra_type_list * refuel_extras
Definition unittype.h:168
unit_class::cache
struct unit_class::@86 cache
unit_type
Definition unittype.h:500
fc_strlcat
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:836
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
sz_strlcat
#define sz_strlcat(dest, src)
Definition support.h:190
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:735
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
terrain_rule_name
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
terrain_has_resource
bool terrain_has_resource(const struct terrain *pterrain, const struct extra_type *presource)
Definition terrain.c:255
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:699
terrain_number
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
T_NONE
#define T_NONE
Definition terrain.h:56
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
tile_extras_class_defense_bonus
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:242
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:736
tile_cultivate
static void tile_cultivate(struct tile *ptile)
Definition tile.c:667
tile_add_extra
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:955
tile_roads_output_bonus
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:291
tile_has_extra_flag
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:886
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
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:1033
tile_extra_apply
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:575
tile_irrigate
static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:615
tile_has_river
bool tile_has_river(const struct tile *ptile)
Definition tile.c:852
tile_destroy_extra
static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:481
tile_is_placing
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1129
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:681
tile_map_check
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1065
tile_transform
static void tile_transform(struct tile *ptile)
Definition tile.c:641
tile_has_base
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:836
tile_remove_extra
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:965
tile_change_terrain
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:496
tile_has_visible_extra
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:917
tile_has_refuel_extra
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:309
tile_extras_defense_bonus
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:233
tile_mine
static void tile_mine(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:628
tile_has_road
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:844
tile_has_conflicting_extra
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:901
tile_plant
static void tile_plant(struct tile *ptile)
Definition tile.c:654
tile_create_extra
static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
Definition tile.c:468
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:407
add_recursive_extras
static bool add_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:513
tile_activity_time
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:418
tile_virtual_new
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:981
tile_has_native_base
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:324
tile_roads_output_incr
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:271
tile_hash_key
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1083
tile_extra_rm_apply
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
tile_set_label
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1095
rm_recursive_extras
static bool rm_recursive_extras(struct tile *ptile, struct extra_type *pextra, int rec)
Definition tile.c:541
tile_set_resource
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:349
tile_has_not_aggressive_extra_for_unit
int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:196
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
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:771
tile_has_road_flag
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:868
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:941
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:382
tile.h
TILE_LB_RIVER_RESOURCE
#define TILE_LB_RIVER_RESOURCE
Definition tile.h:176
tile_claimer
#define tile_claimer(_tile)
Definition tile.h:100
TILE_LB_RESOURCE_POLL
#define TILE_LB_RESOURCE_POLL
Definition tile.h:177
tile_index
#define tile_index(_pt_)
Definition tile.h:88
tile_resource_is_valid
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:103
tile_worked
#define tile_worked(_tile)
Definition tile.h:114
tile_resource
#define tile_resource(_tile)
Definition tile.h:102
known_type
known_type
Definition tile.h:35
TILE_KNOWN_UNSEEN
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
TILE_UNKNOWN
@ TILE_UNKNOWN
Definition tile.h:36
TILE_KNOWN_SEEN
@ TILE_KNOWN_SEEN
Definition tile.h:38
ACTIVITY_FACTOR
#define ACTIVITY_FACTOR
Definition tile.h:165
TILE_LB_TERRAIN_RIVER
#define TILE_LB_TERRAIN_RIVER
Definition tile.h:175
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:110
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:43
tile_continent
#define tile_continent(_tile)
Definition tile.h:92
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
TILE_INDEX_NONE
#define TILE_INDEX_NONE
Definition tile.h:48
tile_owner
#define tile_owner(_tile)
Definition tile.h:96
is_targeted_activity
bool is_targeted_activity(enum unit_activity activity)
Definition unit.c:1610
unit_virtual_destroy
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1725
unit_is_virtual
bool unit_is_virtual(const struct unit *punit)
Definition unit.c:2266
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:749