Freeciv-3.2
Loading...
Searching...
No Matches
maphand.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 "fcintl.h"
21#include "log.h"
22#include "mem.h"
23#include "rand.h"
24#include "support.h"
25
26/* common */
27#include "ai.h"
28#include "base.h"
29#include "borders.h"
30#include "events.h"
31#include "game.h"
32#include "map.h"
33#include "movement.h"
34#include "nation.h"
35#include "packets.h"
36#include "player.h"
37#include "road.h"
38#include "specialist.h"
39#include "unit.h"
40#include "unitlist.h"
41#include "vision.h"
42
43/* server */
44#include "citytools.h"
45#include "cityturn.h"
46#include "notify.h"
47#include "plrhand.h"
48#include "sanitycheck.h"
49#include "sernet.h"
50#include "srv_main.h"
51#include "unithand.h"
52#include "unittools.h"
53
54/* server/advisors */
55#include "advdata.h"
56
57/* server/generator */
58#include "mapgen_utils.h"
59
60#include "maphand.h"
61
62#define MAXIMUM_CLAIMED_OCEAN_SIZE (20)
63
64/* Suppress send_tile_info() during game_load() */
66
67static void player_tile_init(struct tile *ptile, struct player *pplayer);
68static void player_tile_free(struct tile *ptile, struct player *pplayer);
70 struct player *pdest,
71 struct tile *ptile);
72static void shared_vision_change_seen(struct player *pplayer,
73 struct tile *ptile,
74 const v_radius_t change,
75 bool can_reveal_tiles);
76static void map_change_seen(struct player *pplayer,
77 struct tile *ptile,
78 const v_radius_t change,
79 bool can_reveal_tiles);
80static void map_change_own_seen(struct player *pplayer,
81 struct tile *ptile,
82 const v_radius_t change);
83static inline int map_get_seen(const struct player *pplayer,
84 const struct tile *ptile,
85 enum vision_layer vlayer);
86static inline bool map_is_also_seen(const struct tile *ptile,
87 const struct player *pplayer,
88 enum vision_layer vlayer);
89
90static bool is_claimable_ocean(struct tile *ptile, struct tile *source,
91 struct player *pplayer);
92
93/**********************************************************************/
96static bool is_terrain_ecologically_wet(struct tile *ptile)
97{
98 return (is_terrain_class_near_tile(&(wld.map), ptile, TC_OCEAN)
99 || tile_has_river(ptile)
100 || count_river_near_tile(&(wld.map), ptile, NULL) > 0);
101}
102
103/**********************************************************************/
107{
110 _("Global warming has occurred!"));
112 _("Coastlines have been flooded and vast "
113 "ranges of grassland have become deserts."));
114}
115
116/**********************************************************************/
120{
123 _("Nuclear winter has occurred!"));
125 _("Wetlands have dried up and vast "
126 "ranges of grassland have become tundra."));
127}
128
129/**********************************************************************/
134{
135 int k = map_num_tiles();
136 bool used[k];
137 const struct civ_map *nmap = &(wld.map);
138
139 memset(used, 0, sizeof(used));
140
141 log_verbose("Climate change: %s (%d)",
142 warming ? "Global warming" : "Nuclear winter", effect);
143
144 while (effect > 0 && (k--) > 0) {
145 struct terrain *old, *candidates[2], *new;
146 struct tile *ptile;
147 int i;
148
149 do {
150 /* We want to transform a tile at most once due to a climate change. */
151 ptile = rand_map_pos(&(wld.map));
152 } while (used[tile_index(ptile)]);
153 used[tile_index(ptile)] = TRUE;
154
155 old = tile_terrain(ptile);
156 /* Prefer the transformation that's appropriate to the ambient moisture,
157 * but be prepared to fall back in exceptional circumstances */
158 {
159 struct terrain *wetter, *drier;
160
163 if (is_terrain_ecologically_wet(ptile)) {
164 candidates[0] = wetter;
165 candidates[1] = drier;
166 } else {
167 candidates[0] = drier;
168 candidates[1] = wetter;
169 }
170 }
171
172 /* If the preferred transformation is ruled out for some exceptional reason
173 * specific to this tile, fall back to the other, rather than letting this
174 * tile be immune to change. */
175 for (i = 0; i < 2; i++) {
176 new = candidates[i];
177
178 /* If the preferred transformation simply hasn't been specified
179 * for this terrain at all, don't fall back to the other. */
180 if (new == T_NONE) {
181 break;
182 }
183
184 if (tile_city(ptile) != NULL && terrain_has_flag(new, TER_NO_CITIES)) {
185 /* do not change to a terrain with the flag TER_NO_CITIES if the tile
186 * has a city */
187 continue;
188 }
189
190 /* Only change between water and land at coastlines, and between
191 * frozen and unfrozen at ice margin */
192 if (!terrain_surroundings_allow_change(nmap, ptile, new)) {
193 continue;
194 }
195
196 /* OK! */
197 break;
198 }
199 if (i == 2) {
200 /* Neither transformation was permitted. Give up. */
201 continue;
202 }
203
204 if (new != T_NONE && old != new) {
205 effect--;
206
207 /* Check terrain changing activities.
208 These would not be caught by the check if unit can continue activity
209 after the terrain change has taken place, as the activity itself is still
210 legal, but would be towards different terrain, and terrain types are not
211 activity targets (target is NULL) */
212 unit_list_iterate(ptile->units, punit) {
213 if (punit->activity_target == NULL) {
214 /* Target is always NULL for terrain changing activities. */
219 }
220 }
222
223 /* Really change the terrain. */
224 tile_change_terrain(ptile, new);
225 check_terrain_change(ptile, old);
227
229
230 } else if (old == new) {
231 /* This counts toward a climate change although nothing is changed. */
232 effect--;
233 }
234 }
235}
236
237/**********************************************************************/
241bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
242{
243 struct tile *ptile = pcity->tile;
244 struct player *pplayer = city_owner(pcity);
245 bool upgradet = FALSE;
246
247 extra_type_iterate(pextra) {
248 if (!tile_has_extra(ptile, pextra)) {
251 && player_can_build_extra(pextra, pplayer, ptile)
252 && !tile_has_conflicting_extra(ptile, pextra))) {
253 tile_add_extra(pcity->tile, pextra);
254 if (gained != NULL) {
255 if (upgradet) {
256 *gained = NULL;
257 } else {
258 *gained = pextra;
259 }
260 }
261 upgradet = TRUE;
262 }
263 }
265
266 return upgradet;
267}
268
269/**********************************************************************/
276void upgrade_all_city_extras(struct player *pplayer, bool discovery)
277{
278 int cities_upgradet = 0;
279 struct extra_type *upgradet = NULL;
280 bool multiple_types = FALSE;
281 int cities_total = city_list_size(pplayer->cities);
282 int percent;
283
285
286 city_list_iterate(pplayer->cities, pcity) {
287 struct extra_type *new_upgrade;
288
289 if (upgrade_city_extras(pcity, &new_upgrade)) {
290 update_tile_knowledge(pcity->tile);
292 if (new_upgrade == NULL) {
293 /* This single city alone had multiple types */
295 } else if (upgradet == NULL) {
296 /* First gained */
298 } else if (upgradet != new_upgrade) {
299 /* Different type from what another city got. */
301 }
302 }
304
305 if (cities_total > 0) {
307 } else {
308 percent = 0;
309 }
310
311 if (cities_upgradet > 0) {
312 if (discovery) {
313 if (percent >= 75) {
315 _("New hope sweeps like fire through the country as "
316 "the discovery of new infrastructure building technology "
317 "is announced."));
318 }
319 } else {
320 if (percent >= 75) {
322 _("The people are pleased to hear that your "
323 "scientists finally know about new infrastructure building "
324 "technology."));
325 }
326 }
327
328 if (multiple_types) {
330 _("Workers spontaneously gather and upgrade all "
331 "possible cities with better infrastructure."));
332 } else {
334 _("Workers spontaneously gather and upgrade all "
335 "possible cities with %s."), extra_name_translation(upgradet));
336 }
337 }
338
340}
341
342/**********************************************************************/
346{
347 return BV_ISSET(me->server.really_gives_vision, player_index(them));
348}
349
350/**********************************************************************/
353static void buffer_shared_vision(struct player *pplayer)
354{
356 if (really_gives_vision(pplayer, pplayer2)) {
358 conn_list_do_buffer(pplayer2->connections);
359 }
363}
364
365/**********************************************************************/
368static void unbuffer_shared_vision(struct player *pplayer)
369{
371 if (really_gives_vision(pplayer, pplayer2)) {
372 conn_list_do_unbuffer(pplayer2->connections);
374 }
378}
379
380/**********************************************************************/
396
397/**********************************************************************/
414
415/**********************************************************************/
419 struct player *pfrom, struct player *pdest)
420{
421 struct tile *pcenter = city_tile(pcity);
422 const struct civ_map *nmap = &(wld.map);
423
425
429
432 sync_cities();
433}
434
435/**********************************************************************/
445{
446 int tiles_sent;
447
448 if (!dest) {
449 dest = game.est_connections;
450 }
451
452 /* send whole map piece by piece to each player to balance the load
453 of the send buffers better */
454 tiles_sent = 0;
456
457 whole_map_iterate(&(wld.map), ptile) {
458 tiles_sent++;
459 if ((tiles_sent % wld.map.xsize) == 0) {
463 }
464
465 send_tile_info(dest, ptile, FALSE);
467
470}
471
472/**********************************************************************/
476{
478
480 return formerly;
481}
482
483/**********************************************************************/
491void send_tile_info(struct conn_list *dest, struct tile *ptile,
492 bool send_unknown)
493{
494 struct packet_tile_info info;
495 const struct player *owner;
496 const struct player *eowner;
497
498 if (dest == NULL) {
499 CALL_FUNC_EACH_AI(tile_info, ptile);
500 }
501
503 return;
504 }
505
506 if (!dest) {
507 dest = game.est_connections;
508 }
509
510 info.tile = tile_index(ptile);
511
512 if (ptile->spec_sprite) {
513 sz_strlcpy(info.spec_sprite, ptile->spec_sprite);
514 } else {
515 info.spec_sprite[0] = '\0';
516 }
517
518 conn_list_iterate(dest, pconn) {
519 struct player *pplayer = pconn->playing;
520 bool known;
521
522 if (NULL == pplayer && !pconn->observer) {
523 continue;
524 }
525
526 if (pplayer != NULL) {
527 known = map_is_known(ptile, pplayer);
528 }
529
530 if (pplayer == NULL || (known && map_is_also_seen(ptile, pplayer, V_MAIN))) {
531 struct extra_type *resource;
532
533 info.known = TILE_KNOWN_SEEN;
534 info.continent = tile_continent(ptile);
535 owner = tile_owner(ptile);
536 eowner = extra_owner(ptile);
538 info.extras_owner = (eowner ? player_number(eowner) : MAP_TILE_OWNER_NULL);
539 info.worked = (NULL != tile_worked(ptile))
540 ? tile_worked(ptile)->id
542
543 info.terrain = (NULL != tile_terrain(ptile))
545 : terrain_count();
546
547 resource = tile_resource(ptile);
548 if (resource != NULL
549 && (pplayer == NULL
550 || player_knows_extra_exist(pplayer, resource, ptile))) {
552 } else {
554 }
555
556 info.placing = (NULL != ptile->placing)
557 ? extra_number(ptile->placing)
558 : -1;
559 info.place_turn = (NULL != ptile->placing)
560 ? game.info.turn + ptile->infra_turns
561 : 0;
562
563 if (pplayer != NULL) {
564 dbv_to_bv(info.extras.vec, &(map_get_player_tile(ptile, pplayer)->extras));
565 } else {
566 info.extras = ptile->extras;
567 }
568
569 if (ptile->label != NULL) {
570 /* Always leave final '\0' in place */
571 strncpy(info.label, ptile->label, sizeof(info.label) - 1);
572 } else {
573 info.label[0] = '\0';
574 }
575
577 } else if (pplayer != NULL && known) {
578 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
580
582 info.continent = tile_continent(ptile);
584 ? plrtile->owner
585 : tile_owner(ptile));
586 eowner = plrtile->extras_owner;
588 info.extras_owner = (eowner ? player_number(eowner) : MAP_TILE_OWNER_NULL);
589 info.worked = (NULL != psite)
590 ? psite->identity
592
593 info.terrain = (NULL != plrtile->terrain)
594 ? terrain_number(plrtile->terrain)
595 : terrain_count();
596 info.resource = (NULL != plrtile->resource)
597 ? extra_number(plrtile->resource)
599 info.placing = -1;
600 info.place_turn = 0;
601
602 dbv_to_bv(info.extras.vec, &(plrtile->extras));
603
604 /* Labels never change, so they are not subject to fog of war */
605 if (ptile->label != NULL) {
606 sz_strlcpy(info.label, ptile->label);
607 } else {
608 info.label[0] = '\0';
609 }
610
612 } else if (send_unknown) {
613 info.known = TILE_UNKNOWN;
614 info.continent = 0;
618
619 info.terrain = terrain_count();
621 info.placing = -1;
622 info.place_turn = 0;
623
624 BV_CLR_ALL(info.extras);
625
626 info.label[0] = '\0';
627
629 }
630 }
632}
633
634/**********************************************************************/
640static bool unit_is_on_layer(const struct unit *punit,
641 enum vision_layer vlayer)
642{
643 return unit_type_get(punit)->vlayer == vlayer;
644}
645
646/**********************************************************************/
649void send_map_info(struct conn_list *dest)
650{
651 struct packet_map_info minfo;
652
654 minfo.ysize = wld.map.ysize;
655 minfo.topology_id = wld.map.topology_id;
656 minfo.wrap_id = wld.map.wrap_id;
657 minfo.north_latitude = wld.map.north_latitude;
658 minfo.south_latitude = wld.map.south_latitude;
659
661}
662
663/**********************************************************************/
667static void shared_vision_change_seen(struct player *pplayer,
668 struct tile *ptile,
669 const v_radius_t change,
670 bool can_reveal_tiles)
671{
672 map_change_own_seen(pplayer, ptile, change);
673 map_change_seen(pplayer, ptile, change, can_reveal_tiles);
674
676 if (really_gives_vision(pplayer, pplayer2)) {
677 map_change_seen(pplayer2, ptile, change, can_reveal_tiles);
678 }
680}
681
682/**********************************************************************/
685void map_vision_update(struct player *pplayer, struct tile *ptile,
688 bool can_reveal_tiles)
689{
690 v_radius_t change;
691 int max_radius;
692
696 return;
697 }
698
699 /* Determines 'max_radius' value. */
700 max_radius = 0;
702 if (max_radius < old_radius_sq[v]) {
704 }
705 if (max_radius < new_radius_sq[v]) {
707 }
709
710#ifdef FREECIV_DEBUG
711 log_debug("Updating vision at (%d, %d) in a radius of %d.",
712 TILE_XY(ptile), max_radius);
714 log_debug(" vision layer %d is changing from %d to %d.",
715 v, old_radius_sq[v], new_radius_sq[v]);
717#endif /* FREECIV_DEBUG */
718
719 buffer_shared_vision(pplayer);
720 circle_dxyr_iterate(&(wld.map), ptile, max_radius, tile1, dx, dy, dr) {
722 if (dr > old_radius_sq[v] && dr <= new_radius_sq[v]) {
723 change[v] = 1;
724 } else if (dr > new_radius_sq[v] && dr <= old_radius_sq[v]) {
725 change[v] = -1;
726 } else {
727 change[v] = 0;
728 }
730 shared_vision_change_seen(pplayer, tile1, change, can_reveal_tiles);
732 unbuffer_shared_vision(pplayer);
733}
734
735/**********************************************************************/
740void map_set_border_vision(struct player *pplayer,
741 const bool is_enabled)
742{
743 const v_radius_t radius_sq = V_RADIUS(is_enabled ? 1 : -1, 0, 0);
744
745 if (pplayer->server.border_vision == is_enabled) {
746 /* No change. Changing the seen count beyond what already exists would
747 * be a bug. */
748 return;
749 }
750
751 /* Set the new border seer value. */
753
754 whole_map_iterate(&(wld.map), ptile) {
755 if (pplayer == ptile->owner) {
756 /* The tile is within the player's borders. */
757 shared_vision_change_seen(pplayer, ptile, radius_sq, TRUE);
758 }
760}
761
762/**********************************************************************/
768void map_show_tile(struct player *src_player, struct tile *ptile)
769{
770 static int recurse = 0;
771
772 log_debug("Showing %i,%i to %s", TILE_XY(ptile), player_name(src_player));
773
774 fc_assert(recurse == 0);
775 recurse++;
776
777 players_iterate(pplayer) {
778 if (pplayer == src_player || really_gives_vision(src_player, pplayer)) {
779 struct city *pcity;
780
781 if (!map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
782 map_set_known(ptile, pplayer);
783
784 /* As the tile may be fogged send_tile_info won't always do this for us */
785 update_player_tile_knowledge(pplayer, ptile);
786 update_player_tile_last_seen(pplayer, ptile);
787
788 send_tile_info(pplayer->connections, ptile, FALSE);
789
790 /* Remove old cities that exist no more */
791 reality_check_city(pplayer, ptile);
792
793 if ((pcity = tile_city(ptile))) {
794 /* As the tile may be fogged send_city_info won't do this for us */
795 update_dumb_city(pplayer, pcity);
796 send_city_info(pplayer, pcity);
797 }
798
800 if (0 < map_get_seen(pplayer, ptile, v)) {
801 unit_list_iterate(ptile->units, punit) {
802 if (unit_is_on_layer(punit, v)) {
803 send_unit_info(pplayer->connections, punit);
804 }
806 }
808 }
809 }
811
812 recurse--;
813}
814
815/**********************************************************************/
820void map_hide_tile(struct player *src_player, struct tile *ptile)
821{
822 static int recurse = 0;
823
824 log_debug("Hiding %d,%d to %s", TILE_XY(ptile), player_name(src_player));
825
826 fc_assert(recurse == 0);
827 recurse++;
828
829 players_iterate(pplayer) {
830 if (pplayer == src_player || really_gives_vision(src_player, pplayer)) {
831 if (map_is_known(ptile, pplayer)) {
832 if (0 < map_get_seen(pplayer, ptile, V_MAIN)) {
833 update_player_tile_last_seen(pplayer, ptile);
834 }
835
836 /* Remove city. */
837 remove_dumb_city(pplayer, ptile);
838
839 /* Remove units. */
841 if (0 < map_get_seen(pplayer, ptile, v)) {
842 unit_list_iterate(ptile->units, punit) {
843 if (unit_is_on_layer(punit, v)) {
845 }
847 }
849 }
850
851 map_clear_known(ptile, pplayer);
852
853 send_tile_info(pplayer->connections, ptile, TRUE);
854 }
856
857 recurse--;
858}
859
860/**********************************************************************/
864void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
865{
866 buffer_shared_vision(pplayer);
867
868 circle_iterate(&(wld.map), ptile, radius_sq, tile1) {
869 map_show_tile(pplayer, tile1);
871
872 unbuffer_shared_vision(pplayer);
873}
874
875/**********************************************************************/
879void map_show_all(struct player *pplayer)
880{
881 buffer_shared_vision(pplayer);
882
883 whole_map_iterate(&(wld.map), ptile) {
884 map_show_tile(pplayer, ptile);
886
887 unbuffer_shared_vision(pplayer);
888}
889
890/**********************************************************************/
894bool map_is_known(const struct tile *ptile, const struct player *pplayer)
895{
896 if (pplayer->tile_known.vec == NULL) {
897 /* Player map not initialized yet */
898 return FALSE;
899 }
900
901 return dbv_isset(&pplayer->tile_known, tile_index(ptile));
902}
903
904/**********************************************************************/
909static inline bool map_is_also_seen(const struct tile *ptile,
910 const struct player *pplayer,
911 enum vision_layer vlayer)
912{
913 return map_get_seen(pplayer, ptile, vlayer) > 0;
914}
915
916/**********************************************************************/
920bool map_is_known_and_seen(const struct tile *ptile,
921 const struct player *pplayer,
922 enum vision_layer vlayer)
923{
924 return map_is_known(ptile, pplayer) && map_is_also_seen(ptile, pplayer, vlayer);
925}
926
927/**********************************************************************/
934static inline int map_get_seen(const struct player *pplayer,
935 const struct tile *ptile,
936 enum vision_layer vlayer)
937{
938 return map_get_player_tile(ptile, pplayer)->seen_count[vlayer];
939}
940
941/**********************************************************************/
947void map_change_seen(struct player *pplayer,
948 struct tile *ptile,
949 const v_radius_t change,
950 bool can_reveal_tiles)
951{
952 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
953 bool revealing_tile = FALSE;
954
955#ifdef FREECIV_DEBUG
956 log_debug("%s() for player %s (nb %d) at (%d, %d).",
957 __FUNCTION__, player_name(pplayer), player_number(pplayer),
958 TILE_XY(ptile));
960 log_debug(" vision layer %d is changing from %d to %d.",
961 v, plrtile->seen_count[v], plrtile->seen_count[v] + change[v]);
963#endif /* FREECIV_DEBUG */
964
965 /* Removes units out of vision. First, check invisible layers because
966 * we must remove all units before fog of war because clients expect
967 * the tile is empty when it is fogged. */
968 if (0 > change[V_INVIS]
969 && plrtile->seen_count[V_INVIS] == -change[V_INVIS]) {
970 log_debug("(%d, %d): hiding invisible units to player %s (nb %d).",
971 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
972
973 unit_list_iterate(ptile->units, punit) {
975 && can_player_see_unit(pplayer, punit)
976 && (plrtile->seen_count[V_MAIN] + change[V_MAIN] <= 0
977 || !pplayers_allied(pplayer, unit_owner(punit)))) {
978 /* Allied units on seen tiles (V_MAIN) are always seen.
979 * That's how can_player_see_unit_at() works. */
981 }
983 }
984 if (0 > change[V_SUBSURFACE]
985 && plrtile->seen_count[V_SUBSURFACE] == -change[V_SUBSURFACE]) {
986 log_debug("(%d, %d): hiding subsurface units to player %s (nb %d).",
987 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
988
989 unit_list_iterate(ptile->units, punit) {
991 && can_player_see_unit(pplayer, punit)) {
993 }
995 }
996
997 if (0 > change[V_MAIN]
998 && plrtile->seen_count[V_MAIN] == -change[V_MAIN]) {
999 log_debug("(%d, %d): hiding visible units to player %s (nb %d).",
1000 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
1001
1002 unit_list_iterate(ptile->units, punit) {
1004 && can_player_see_unit(pplayer, punit)) {
1005 unit_goes_out_of_sight(pplayer, punit);
1006 }
1008 }
1009
1011 /* Avoid underflow. */
1012 fc_assert(0 <= change[v] || -change[v] <= plrtile->seen_count[v]);
1013 plrtile->seen_count[v] += change[v];
1015
1016 /* V_MAIN vision ranges must always be more than invisible ranges
1017 * (see comment in common/vision.h), so we assume that the V_MAIN
1018 * seen count cannot be inferior to V_INVIS or V_SUBSURFACE seen count.
1019 * Moreover, when the fog of war is disabled, V_MAIN has an extra
1020 * seen count point. */
1021 fc_assert(plrtile->seen_count[V_INVIS] + !game.info.fogofwar
1022 <= plrtile->seen_count[V_MAIN]);
1024 <= plrtile->seen_count[V_MAIN]);
1025
1026 if (!map_is_known(ptile, pplayer)) {
1027 if (0 < plrtile->seen_count[V_MAIN] && can_reveal_tiles) {
1028 log_debug("(%d, %d): revealing tile to player %s (nb %d).",
1029 TILE_XY(ptile), player_name(pplayer),
1030 player_number(pplayer));
1031
1032 map_set_known(ptile, pplayer);
1034 } else {
1035 return;
1036 }
1037 }
1038
1039 /* Fog the tile. */
1040 if (0 > change[V_MAIN] && 0 == plrtile->seen_count[V_MAIN]) {
1041 struct city *pcity;
1042
1043 log_debug("(%d, %d): fogging tile for player %s (nb %d).",
1044 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
1045
1046 pcity = ptile->worked;
1047
1048 if (pcity != NULL && city_owner(pcity) == pplayer) {
1049 city_map_update_empty(pcity, ptile);
1051 if (pcity->server.needs_arrange == CNA_NOT) {
1053 }
1054 }
1055
1056 update_player_tile_last_seen(pplayer, ptile);
1058 plrtile->owner = tile_owner(ptile);
1059 }
1060 plrtile->extras_owner = extra_owner(ptile);
1061 send_tile_info(pplayer->connections, ptile, FALSE);
1062 }
1063
1064 if ((revealing_tile && 0 < plrtile->seen_count[V_MAIN])
1065 || (0 < change[V_MAIN]
1066 /* plrtile->seen_count[V_MAIN] Always set to 1
1067 * when the fog of war is disabled. */
1068 && (change[V_MAIN] + !game.info.fogofwar
1069 == (plrtile->seen_count[V_MAIN])))) {
1070 struct city *pcity;
1071
1072 log_debug("(%d, %d): unfogging tile for player %s (nb %d).",
1073 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
1074
1075 /* Send info about the tile itself.
1076 * It has to be sent first because the client needs correct
1077 * continent number before it can handle following packets
1078 */
1079 update_player_tile_knowledge(pplayer, ptile);
1080 send_tile_info(pplayer->connections, ptile, FALSE);
1081
1082 /* Discover units. */
1083 unit_list_iterate(ptile->units, punit) {
1084 /* Be sure not to revive dead unit on client when it's not yet
1085 * removed from the tile. This could happen when "unit_lost" lua script
1086 * somehow causes tile of the dead unit to unfog again. */
1088 && !punit->server.dying) {
1089 send_unit_info(pplayer->connections, punit);
1090 }
1092
1093 /* Discover cities. */
1094 reality_check_city(pplayer, ptile);
1095
1096 if (NULL != (pcity = tile_city(ptile))) {
1097 send_city_info(pplayer, pcity);
1098 }
1099 }
1100
1101 if ((revealing_tile && 0 < plrtile->seen_count[V_INVIS])
1102 || (0 < change[V_INVIS]
1103 && change[V_INVIS] == plrtile->seen_count[V_INVIS])) {
1104 log_debug("(%d, %d): revealing invisible units to player %s (nb %d).",
1105 TILE_XY(ptile), player_name(pplayer),
1106 player_number(pplayer));
1107 /* Discover units. */
1108 unit_list_iterate(ptile->units, punit) {
1110 send_unit_info(pplayer->connections, punit);
1111 }
1113 }
1114 if ((revealing_tile && 0 < plrtile->seen_count[V_SUBSURFACE])
1115 || (0 < change[V_SUBSURFACE]
1116 && change[V_SUBSURFACE] == plrtile->seen_count[V_SUBSURFACE])) {
1117 log_debug("(%d, %d): revealing subsurface units to player %s (nb %d).",
1118 TILE_XY(ptile), player_name(pplayer),
1119 player_number(pplayer));
1120 /* Discover units. */
1121 unit_list_iterate(ptile->units, punit) {
1123 send_unit_info(pplayer->connections, punit);
1124 }
1126 }
1127}
1128
1129/**********************************************************************/
1136static inline int player_tile_own_seen(const struct player_tile *plrtile,
1137 enum vision_layer vlayer)
1138{
1139 return plrtile->own_seen[vlayer];
1140}
1141
1142/**********************************************************************/
1145static void map_change_own_seen(struct player *pplayer,
1146 struct tile *ptile,
1147 const v_radius_t change)
1148{
1149 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1150
1152 plrtile->own_seen[v] += change[v];
1154}
1155
1156/**********************************************************************/
1160 struct vision_site *new_site)
1161{
1162 if (ptile->site == new_site) {
1163 /* Do nothing. */
1164 return;
1165 }
1166
1167 if (ptile->site != NULL) {
1168 /* Releasing old site from tile */
1169 vision_site_destroy(ptile->site);
1170 }
1171
1172 ptile->site = new_site;
1173}
1174
1175/**********************************************************************/
1178void map_set_known(struct tile *ptile, struct player *pplayer)
1179{
1180 dbv_set(&pplayer->tile_known, tile_index(ptile));
1181}
1182
1183/**********************************************************************/
1186void map_clear_known(struct tile *ptile, struct player *pplayer)
1187{
1188 dbv_clr(&pplayer->tile_known, tile_index(ptile));
1189}
1190
1191/**********************************************************************/
1196void map_know_and_see_all(struct player *pplayer)
1197{
1198 const v_radius_t radius_sq = V_RADIUS(1, 1, 1);
1199
1200 buffer_shared_vision(pplayer);
1201 whole_map_iterate(&(wld.map), ptile) {
1202 map_change_seen(pplayer, ptile, radius_sq, TRUE);
1204 unbuffer_shared_vision(pplayer);
1205}
1206
1207/**********************************************************************/
1211{
1212 players_iterate(pplayer) {
1213 map_know_and_see_all(pplayer);
1215}
1216
1217/**********************************************************************/
1221void player_map_init(struct player *pplayer)
1222{
1223 pplayer->server.private_map
1224 = fc_realloc(pplayer->server.private_map,
1225 MAP_INDEX_SIZE * sizeof(*pplayer->server.private_map));
1226
1227 whole_map_iterate(&(wld.map), ptile) {
1228 player_tile_init(ptile, pplayer);
1230
1232}
1233
1234/**********************************************************************/
1237void player_map_free(struct player *pplayer)
1238{
1239 if (!pplayer->server.private_map) {
1240 return;
1241 }
1242
1243 whole_map_iterate(&(wld.map), ptile) {
1244 player_tile_free(ptile, pplayer);
1246
1247 free(pplayer->server.private_map);
1248 pplayer->server.private_map = NULL;
1249
1250 dbv_free(&pplayer->tile_known);
1251}
1252
1253/**********************************************************************/
1258void remove_player_from_maps(struct player *pplayer)
1259{
1260 /* only after removing borders! */
1262 whole_map_iterate(&(wld.map), ptile) {
1263 /* Clear all players' knowledge about the removed player, and free
1264 * data structures (including those in removed player's player map). */
1265 bool reality_changed = FALSE;
1266
1268 struct player_tile *aplrtile;
1269 bool changed = FALSE;
1270
1271 if (!aplayer->server.private_map) {
1272 continue;
1273 }
1275
1276 /* Free vision sites (cities) for removed and other players */
1277 if (aplrtile && aplrtile->site
1278 && vision_site_owner(aplrtile->site) == pplayer) {
1280 changed = TRUE;
1281 }
1282
1283 /* Remove references to player from others' maps */
1284 if (aplrtile->owner == pplayer) {
1285 aplrtile->owner = NULL;
1286 changed = TRUE;
1287 }
1288 if (aplrtile->extras_owner == pplayer) {
1289 aplrtile->extras_owner = NULL;
1290 changed = TRUE;
1291 }
1292
1293 /* Must ensure references to dying player are gone from clients
1294 * before player is destroyed */
1295 if (changed) {
1296 /* This will use player tile if fogged */
1297 send_tile_info(pplayer->connections, ptile, FALSE);
1298 }
1300
1301 /* Clear removed player's knowledge */
1302 if (pplayer->tile_known.vec) {
1303 map_clear_known(ptile, pplayer);
1304 }
1305
1306 /* Free all claimed tiles. */
1307 if (tile_owner(ptile) == pplayer) {
1308 tile_set_owner(ptile, NULL, NULL);
1310 }
1311 if (extra_owner(ptile) == pplayer) {
1312 ptile->extras_owner = NULL;
1314 }
1315
1316 if (reality_changed) {
1317 /* Update anyone who can see the tile (e.g. global observers) */
1318 send_tile_info(NULL, ptile, FALSE);
1319 }
1322}
1323
1324/**********************************************************************/
1328static void player_tile_init(struct tile *ptile, struct player *pplayer)
1329{
1330 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1331
1332 plrtile->terrain = T_UNKNOWN;
1333 plrtile->resource = NULL;
1334 plrtile->owner = NULL;
1335 plrtile->extras_owner = NULL;
1336 plrtile->site = NULL;
1337 dbv_init(&(plrtile->extras), extra_count());
1339 plrtile->last_updated = game.info.turn;
1340 } else {
1341 plrtile->last_updated = game.info.year;
1342 }
1343
1344 plrtile->seen_count[V_MAIN] = !game.server.fogofwar_old;
1345 plrtile->seen_count[V_INVIS] = 0;
1346 plrtile->seen_count[V_SUBSURFACE] = 0;
1347 memcpy(plrtile->own_seen, plrtile->seen_count, sizeof(v_radius_t));
1348}
1349
1350/**********************************************************************/
1353static void player_tile_free(struct tile *ptile, struct player *pplayer)
1354{
1355 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1356
1357 if (plrtile->site != NULL) {
1359 }
1360
1361 dbv_free(&(plrtile->extras));
1362}
1363
1364/**********************************************************************/
1367struct vision_site *map_get_player_city(const struct tile *ptile,
1368 const struct player *pplayer)
1369{
1370 struct vision_site *psite = map_get_player_site(ptile, pplayer);
1371
1372 fc_assert_ret_val(psite == NULL || psite->location == ptile, NULL);
1373
1374 return psite;
1375}
1376
1377/**********************************************************************/
1382struct player_tile *map_get_player_tile(const struct tile *ptile,
1383 const struct player *pplayer)
1384{
1386
1387 return pplayer->server.private_map + tile_index(ptile);
1388}
1389
1390/**********************************************************************/
1398bool update_player_tile_knowledge(struct player *pplayer, struct tile *ptile)
1399{
1400 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1401
1402 if (plrtile->terrain != ptile->terrain
1403 || !bv_match_dbv(&(plrtile->extras), ptile->extras.vec)
1404 || plrtile->resource != ptile->resource
1405 || plrtile->owner != tile_owner(ptile)
1406 || plrtile->extras_owner != extra_owner(ptile)) {
1407 plrtile->terrain = ptile->terrain;
1408 extra_type_iterate(pextra) {
1409 if (player_knows_extra_exist(pplayer, pextra, ptile)) {
1410 dbv_set(&(plrtile->extras), extra_number(pextra));
1411 } else {
1412 dbv_clr(&(plrtile->extras), extra_number(pextra));
1413 }
1415 if (ptile->resource != NULL
1416 && player_knows_extra_exist(pplayer, ptile->resource, ptile)) {
1417 plrtile->resource = ptile->resource;
1418 } else {
1420 }
1421 plrtile->owner = tile_owner(ptile);
1422 plrtile->extras_owner = extra_owner(ptile);
1423
1424 return TRUE;
1425 }
1426
1427 return FALSE;
1428}
1429
1430/**********************************************************************/
1439void update_tile_knowledge(struct tile *ptile)
1440{
1441 if (server_state() == S_S_INITIAL) {
1442 return;
1443 }
1444
1445 /* Players */
1446 players_iterate(pplayer) {
1447 if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
1448 if (update_player_tile_knowledge(pplayer, ptile)) {
1449 send_tile_info(pplayer->connections, ptile, FALSE);
1450 }
1451 }
1453
1454 /* Global observers */
1456 struct player *pplayer = pconn->playing;
1457
1458 if (NULL == pplayer && pconn->observer) {
1459 send_tile_info(pconn->self, ptile, FALSE);
1460 }
1462}
1463
1464/**********************************************************************/
1468 struct tile *ptile)
1469{
1471 map_get_player_tile(ptile, pplayer)->last_updated = game.info.turn;
1472 } else {
1473 map_get_player_tile(ptile, pplayer)->last_updated = game.info.year;
1474 }
1475}
1476
1477/**********************************************************************/
1486 struct player *pdest,
1487 struct tile *ptile)
1488{
1489 if (!map_is_known_and_seen(ptile, pdest, V_MAIN)) {
1490 /* I can just hear people scream as they try to comprehend this if :).
1491 * Let me try in words:
1492 * 1) if the tile is seen by pfrom the info is sent to pdest
1493 * OR
1494 * 2) if the tile is known by pfrom AND (they have more recent info
1495 * OR it is not known by pdest)
1496 */
1498 || (map_is_known(ptile, pfrom)
1499 && (((map_get_player_tile(ptile, pfrom)->last_updated
1500 > map_get_player_tile(ptile, pdest)->last_updated))
1501 || !map_is_known(ptile, pdest)))) {
1502 struct player_tile *from_tile, *dest_tile;
1503
1505 dest_tile = map_get_player_tile(ptile, pdest);
1506 /* Update and send tile knowledge */
1507 map_set_known(ptile, pdest);
1508 dest_tile->terrain = from_tile->terrain;
1509 dbv_copy(&(dest_tile->extras), &(from_tile->extras));
1510 dest_tile->resource = from_tile->resource;
1511 dest_tile->owner = from_tile->owner;
1512 dest_tile->extras_owner = from_tile->extras_owner;
1513 dest_tile->last_updated = from_tile->last_updated;
1514 send_tile_info(pdest->connections, ptile, FALSE);
1515
1516 /* Update and send city knowledge */
1517 /* Remove outdated cities */
1518 if (dest_tile->site) {
1519 if (!from_tile->site) {
1520 /* As the city was gone on the newer from_tile
1521 it will be removed by this function */
1522 reality_check_city(pdest, ptile);
1523 } else { /* We have a dest_city. update */
1524 if (from_tile->site->identity
1525 != dest_tile->site->identity) {
1526 /* As the city was gone on the newer from_tile
1527 it will be removed by this function */
1528 reality_check_city(pdest, ptile);
1529 }
1530 }
1531 }
1532
1533 /* Set and send new city info */
1534 if (from_tile->site) {
1535 if (!dest_tile->site) {
1536 /* We cannot assign new vision site with change_playertile_site(),
1537 * since location is not yet set up for new site */
1538 dest_tile->site = vision_site_copy(from_tile->site);
1539 }
1540 /* Note that we don't care if receiver knows vision source city
1541 * or not. */
1542 send_city_info_at_tile(pdest, pdest->connections, NULL, ptile);
1543 }
1544
1546
1547 return TRUE;
1548 }
1549 }
1550
1551 return FALSE;
1552}
1553
1554/**********************************************************************/
1568
1569/**********************************************************************/
1579 struct player *pdest,
1580 struct tile *ptile)
1581{
1583
1587 }
1589
1590 return updt;
1591}
1592
1593/**********************************************************************/
1599{
1600 int added;
1601
1602 players_iterate(pplayer) {
1603 pplayer->server.really_gives_vision = pplayer->gives_shared_vision;
1605
1606 /* In words: This terminates when it has run a round without adding
1607 a dependency. One loop only propagates dependencies one level deep,
1608 which is why we keep doing it as long as changes occur. */
1609 do {
1610 added = 0;
1611 players_iterate(pplayer) {
1613 if (really_gives_vision(pplayer, pplayer2)
1614 && pplayer != pplayer2) {
1617 && !really_gives_vision(pplayer, pplayer3)
1618 && pplayer != pplayer3) {
1619 BV_SET(pplayer->server.really_gives_vision, player_index(pplayer3));
1620 added++;
1621 }
1623 }
1626 } while (added > 0);
1627}
1628
1629/**********************************************************************/
1633{
1635
1636 if (pfrom == pto) {
1637 return;
1638 }
1639
1641 log_error("Trying to give shared vision from %s to %s, "
1642 "but that vision is already given!",
1644 return;
1645 }
1646
1647 players_iterate(pplayer) {
1648 save_vision[player_index(pplayer)] = pplayer->server.really_gives_vision;
1650
1651 BV_SET(pfrom->gives_shared_vision, player_index(pto));
1653 log_debug("giving shared vision from %s to %s",
1655
1656 players_iterate(pplayer) {
1657 buffer_shared_vision(pplayer);
1659 if (really_gives_vision(pplayer, pplayer2)
1660 && !BV_ISSET(save_vision[player_index(pplayer)],
1662 log_debug("really giving shared vision from %s to %s",
1663 player_name(pplayer), player_name(pplayer2));
1664 whole_map_iterate(&(wld.map), ptile) {
1665 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1666 const v_radius_t change =
1670
1671 if (0 < change[V_MAIN] || 0 < change[V_INVIS]) {
1672 map_change_seen(pplayer2, ptile, change,
1673 map_is_known(ptile, pplayer));
1674 }
1676
1677 /* Squares that are not seen, but which pfrom may have more recent
1678 knowledge of */
1680 }
1682 unbuffer_shared_vision(pplayer);
1684
1685 if (S_S_RUNNING == server_state()) {
1687 }
1688}
1689
1690/**********************************************************************/
1694{
1696
1698 if (!gives_shared_vision(pfrom, pto)) {
1699 log_error("Tried removing the shared vision from %s to %s, "
1700 "but it did not exist in the first place!",
1702 return;
1703 }
1704
1705 players_iterate(pplayer) {
1706 save_vision[player_index(pplayer)] = pplayer->server.really_gives_vision;
1708
1709 log_debug("removing shared vision from %s to %s",
1711
1712 BV_CLR(pfrom->gives_shared_vision, player_index(pto));
1714
1715 players_iterate(pplayer) {
1716 buffer_shared_vision(pplayer);
1718 if (!really_gives_vision(pplayer, pplayer2)
1719 && BV_ISSET(save_vision[player_index(pplayer)],
1721 log_debug("really removing shared vision from %s to %s",
1722 player_name(pplayer), player_name(pplayer2));
1723 whole_map_iterate(&(wld.map), ptile) {
1724 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1725 const v_radius_t change =
1729
1730 if (0 > change[V_MAIN] || 0 > change[V_INVIS]) {
1731 map_change_seen(pplayer2, ptile, change, FALSE);
1732 }
1734 }
1736 unbuffer_shared_vision(pplayer);
1738
1739 if (S_S_RUNNING == server_state()) {
1741 }
1742}
1743
1744/**********************************************************************/
1748{
1749 const v_radius_t radius_sq = V_RADIUS(-1, 0, 0);
1750
1752
1753 buffer_shared_vision(pplayer);
1754 whole_map_iterate(&(wld.map), ptile) {
1755 map_change_seen(pplayer, ptile, radius_sq, FALSE);
1757 unbuffer_shared_vision(pplayer);
1758}
1759
1760/**********************************************************************/
1764{
1765 players_iterate(pplayer) {
1766 enable_fog_of_war_player(pplayer);
1768}
1769
1770/**********************************************************************/
1774{
1775 const v_radius_t radius_sq = V_RADIUS(1, 0, 0);
1776
1778
1779 buffer_shared_vision(pplayer);
1780 whole_map_iterate(&(wld.map), ptile) {
1781 map_change_seen(pplayer, ptile, radius_sq, FALSE);
1783 unbuffer_shared_vision(pplayer);
1784}
1785
1786/**********************************************************************/
1790{
1791 players_iterate(pplayer) {
1794}
1795
1796/**********************************************************************/
1805static void ocean_to_land_fix_rivers(struct tile *ptile)
1806{
1807 cardinal_adjc_iterate(&(wld.map), ptile, tile1) {
1808 bool ocean_near = FALSE;
1809
1811 if (is_ocean_tile(tile2))
1812 ocean_near = TRUE;
1814
1815 if (!ocean_near) {
1816 /* If ruleset has several river types defined, this
1817 * may cause same tile to contain more than one river. */
1821 tile_add_extra(ptile, priver);
1822 }
1824 }
1826}
1827
1828/**********************************************************************/
1832 struct tile *from)
1833{
1834 bool unit_alive = TRUE;
1835
1836 /* Look for a nearby safe tile */
1837 adjc_iterate(&(wld.map), from, ptile2) {
1841 log_verbose("Moved %s %s due to changing terrain at (%d,%d).",
1846 _("Moved your %s due to changing terrain."),
1847 unit_link(punit));
1848
1849 /* TODO: should a unit be able to bounce to a transport like is
1850 * done below? What if the unit can't legally enter the transport,
1851 * say because the transport is Unreachable and the unit doesn't
1852 * have it in its embarks field or because "Transport Embark"
1853 * isn't enabled? Kept like it was to preserve the old rules for
1854 * now. -- Sveinung */
1859 }
1860 break;
1861 }
1863
1864 if (unit_alive && unit_tile(punit) == from) {
1865 /* If we get here we could not move punit. */
1866
1867 /* Try to bounce transported units. */
1869 struct unit_list *pcargo_units;
1870
1875 }
1876 }
1877}
1878
1879/**********************************************************************/
1885static void check_units_single_tile(struct tile *ptile)
1886{
1887 const struct civ_map *nmap = &(wld.map);
1888
1890 int id = punit->id;
1891
1892 /* Top-level transports only. Each handle their own cargo */
1894 && !can_unit_exist_at_tile(nmap, punit, ptile)) {
1896
1897 if (unit_is_alive(id) && unit_tile(punit) == ptile) {
1898 log_verbose("Disbanded %s %s due to changing terrain "
1899 "at (%d, %d).",
1901 unit_rule_name(punit), TILE_XY(ptile));
1904 _("Disbanded your %s due to changing terrain."),
1907 }
1908 }
1910}
1911
1912/**********************************************************************/
1920{
1921 const struct civ_map *nmap = &(wld.map);
1922
1923 /* Check this tile for direct effect on its units */
1925 /* We have to check adjacent tiles too, in case units in cities are now
1926 * illegal (e.g., boat in a city that has become landlocked),
1927 * and in case of CoastStrict units losing their adjacent coast. */
1928 adjc_iterate(nmap, ptile, ptile2) {
1931}
1932
1933/**********************************************************************/
1938 const struct terrain *newter)
1939{
1941
1942 if (!oldter || !newter) {
1943 return FALSE;
1944 }
1945
1948
1949 return (old_is_ocean && !new_is_ocean)
1950 || (!old_is_ocean && new_is_ocean);
1951}
1952
1953/**********************************************************************/
1956void terrain_changed(struct tile *ptile)
1957{
1958 struct city *pcity = tile_city(ptile);
1959
1960 if (pcity != NULL) {
1961 /* Tile is city center and new terrain may support better extras. */
1962 upgrade_city_extras(pcity, NULL);
1963 }
1964
1966}
1967
1968/**********************************************************************/
1976 struct terrain *oldter,
1977 bool extend_rivers)
1978{
1979 if (is_ocean(oldter) && !is_ocean_tile(ptile)) {
1980 if (extend_rivers) {
1982 }
1984 }
1985
1986 terrain_changed(ptile);
1987}
1988
1989/**********************************************************************/
1995void check_terrain_change(struct tile *ptile, struct terrain *oldter)
1996{
1997 struct terrain *newter = tile_terrain(ptile);
1998 struct tile *claimer;
1999 bool cont_reassigned = FALSE;
2000
2001 /* Check if new terrain is a freshwater terrain next to non-freshwater.
2002 * In that case, the new terrain is *changed*. */
2004 bool nonfresh = FALSE;
2005
2006 adjc_iterate(&(wld.map), ptile, atile) {
2009 nonfresh = TRUE;
2010 break;
2011 }
2013 if (nonfresh) {
2014 /* Need to pick a new, non-freshwater ocean type for this tile.
2015 * We don't want e.g. Deep Ocean to be propagated to this tile
2016 * and then to a whole lake by the flooding below, so we pick
2017 * the shallowest non-fresh oceanic type.
2018 * Prefer terrain that matches the frozenness of the target. */
2021 }
2022 }
2023
2027
2028 phase_players_iterate(pplayer) {
2029 if (is_adv_data_phase_open(pplayer)) {
2030 /* Player is using continent numbers that they would assume to remain accurate.
2031 * Force refresh:
2032 * 1) Close the phase, so that it can be opened
2033 * 2) Open the phase, recalculating
2034 */
2035 adv_data_phase_done(pplayer);
2036 adv_data_phase_init(pplayer, FALSE);
2037 }
2039 }
2040
2042
2043 /* Check for saltwater filling freshwater lake */
2046 adjc_iterate(&(wld.map), ptile, atile) {
2048 struct terrain *aold = tile_terrain(atile);
2049
2052 TER_FROZEN)));
2053
2054 /* Recursive, but as lakes are of limited size, this
2055 * won't recurse so much as to cause stack problems. */
2058 }
2060 }
2061
2062 if (cont_reassigned) {
2064 }
2065
2066 claimer = tile_claimer(ptile);
2067 if (claimer != NULL) {
2068 /* Make sure map_claim_border() conditions are still satisfied */
2069 if (is_ocean_tile(ptile)) {
2070 /* Only certain water tiles are claimable */
2071 if (!is_claimable_ocean(ptile, claimer, tile_owner(ptile))) {
2072 map_clear_border(ptile);
2073 }
2074 } else {
2075 /* Only land tiles on the same island as the border source
2076 * are claimable */
2077 if (tile_continent(ptile) != tile_continent(claimer)) {
2078 map_clear_border(ptile);
2079 }
2080 }
2081 }
2082
2083 sanity_check_tile(ptile);
2084}
2085
2086/**********************************************************************/
2097static bool is_claimable_ocean(struct tile *ptile, struct tile *source,
2098 struct player *pplayer)
2099{
2100 Continent_id cont = tile_continent(ptile);
2102 int ocean_tiles;
2103 bool other_continent;
2104
2106 && get_lake_surrounders(cont) == source_cont) {
2107 return TRUE;
2108 }
2109
2110 if (ptile == source) {
2111 /* Source itself is always claimable. */
2112 return TRUE;
2113 }
2114
2117 return TRUE;
2118 }
2119
2120 ocean_tiles = 0;
2122 adjc_iterate(&(wld.map), ptile, adj_tile) {
2124 if (adj_tile == source) {
2125 /* Water next to border source is always claimable */
2126 return TRUE;
2127 }
2128 if (adj_cont == cont) {
2129 ocean_tiles++;
2130 } else if (adj_cont != source_cont) {
2131 /* This water is adjacent to a continent different from the one
2132 * the border source is on */
2134 }
2136 if (!other_continent && ocean_tiles <= 2) {
2137 return TRUE;
2138 } else {
2139 return FALSE;
2140 }
2141}
2142
2143/**********************************************************************/
2146static void map_unit_homecity_enqueue(struct tile *ptile)
2147{
2148 unit_list_iterate(ptile->units, punit) {
2150
2151 if (NULL == phome) {
2152 continue;
2153 }
2154
2157}
2158
2159/**********************************************************************/
2162static void map_claim_border_ownership(struct tile *ptile,
2163 struct player *powner,
2164 struct tile *psource)
2165{
2166 struct player *ploser = tile_owner(ptile);
2167
2168 if ((ploser != powner && ploser != NULL)
2171 || ploser->server.border_vision)) {
2172 const v_radius_t radius_sq = V_RADIUS(-1, 0, 0);
2173
2174 shared_vision_change_seen(ploser, ptile, radius_sq, FALSE);
2175 }
2176
2177 if (powner != NULL
2180 || powner->server.border_vision)) {
2181 const v_radius_t radius_sq = V_RADIUS(1, 0, 0);
2182
2183 shared_vision_change_seen(powner, ptile, radius_sq, TRUE);
2184 }
2185
2186 tile_set_owner(ptile, powner, psource);
2187
2188 /* Needed only when foggedborders enabled, but we do it unconditionally
2189 * in case foggedborders ever gets enabled later. Better to have correct
2190 * information in player map just in case. */
2191 update_tile_knowledge(ptile);
2192
2193 if (ploser != powner) {
2196 }
2197
2198 if (!city_map_update_tile_frozen(ptile)) {
2199 send_tile_info(NULL, ptile, FALSE);
2200 }
2201 }
2202}
2203
2204/**********************************************************************/
2207void map_claim_ownership(struct tile *ptile, struct player *powner,
2208 struct tile *psource, bool claim_bases)
2209{
2210 map_claim_border_ownership(ptile, powner, psource);
2211
2212 if (claim_bases) {
2213 tile_claim_bases(ptile, powner);
2214 }
2215}
2216
2217/**********************************************************************/
2220void tile_claim_bases(struct tile *ptile, struct player *powner)
2221{
2222 struct player *base_loser = extra_owner(ptile);
2223
2224 /* This MUST be before potentially recursive call to map_claim_base(),
2225 * so that the recursive call will get new owner == base_loser and
2226 * abort recursion. */
2227 ptile->extras_owner = powner;
2228
2230 map_claim_base(ptile, pextra, powner, base_loser);
2232}
2233
2234/**********************************************************************/
2237void map_clear_border(struct tile *ptile)
2238{
2239 int radius_sq = tile_border_source_radius_sq(ptile);
2240
2241 circle_dxyr_iterate(&(wld.map), ptile, radius_sq, dtile, dx, dy, dr) {
2242 struct tile *claimer = tile_claimer(dtile);
2243
2244 if (claimer == ptile) {
2246 }
2248}
2249
2250/**********************************************************************/
2254void map_update_border(struct tile *ptile, struct player *owner,
2256{
2258 /* No change */
2259 return;
2260 }
2261
2263 return;
2264 }
2265
2268 } else {
2269 circle_dxyr_iterate(&(wld.map), ptile, old_radius_sq, dtile, dx, dy, dr) {
2270 if (dr > new_radius_sq) {
2271 struct tile *claimer = tile_claimer(dtile);
2272
2273 if (claimer == ptile) {
2275 }
2276 }
2278 }
2279}
2280
2281/**********************************************************************/
2286void map_claim_border(struct tile *ptile, struct player *owner,
2287 int radius_sq)
2288{
2290 return;
2291 }
2292
2293 if (owner == NULL) {
2294 /* Clear the border instead of claiming. Code below this block
2295 * cannot handle NULL owner. */
2296 map_clear_border(ptile);
2297
2298 return;
2299 }
2300
2301 if (radius_sq < 0) {
2302 radius_sq = tile_border_source_radius_sq(ptile);
2303 }
2304
2305 circle_dxyr_iterate(&(wld.map), ptile, radius_sq, dtile, dx, dy, dr) {
2306 struct tile *dclaimer = tile_claimer(dtile);
2307
2308 if (dclaimer == ptile) {
2309 /* Already claimed by the ptile */
2310 continue;
2311 }
2312
2313 if (dr != 0 && is_border_source(dtile)) {
2314 /* Do not claim border sources other than self */
2315 /* Note that this is extremely important at the moment for
2316 * base claiming to work correctly in case there's two
2317 * fortresses near each other. There could be infinite
2318 * recursion in them claiming each other. */
2319 continue;
2320 }
2321
2323 continue;
2324 }
2325
2326 /* Always claim source itself (distance, dr, to it 0) */
2327 if (dr != 0 && NULL != dclaimer && dclaimer != ptile) {
2328 struct city *ccity = tile_city(dclaimer);
2330
2331 if (ccity != NULL) {
2332 /* Previously claimed by city */
2333 int city_x, city_y;
2334
2336
2340 /* Tile is within region permanently claimed by city */
2341 continue;
2342 }
2343 }
2344
2347
2348 if (strength_new <= strength_old) {
2349 /* Stronger shall prevail,
2350 * in case of equal strength older shall prevail */
2351 continue;
2352 }
2353 }
2354
2355 if (is_ocean_tile(dtile)) {
2356 /* Only certain water tiles are claimable */
2357 if (is_claimable_ocean(dtile, ptile, owner)) {
2358 map_claim_ownership(dtile, owner, ptile, dr == 0);
2359 }
2360 } else {
2361 /* Only land tiles on the same island as the border source
2362 * are claimable */
2363 if (tile_continent(dtile) == tile_continent(ptile)) {
2364 map_claim_ownership(dtile, owner, ptile, dr == 0);
2365 }
2366 }
2368}
2369
2370/**********************************************************************/
2374{
2376 return;
2377 }
2378
2379 if (wld.map.tiles == NULL) {
2380 /* Map not yet initialized */
2381 return;
2382 }
2383
2384 log_verbose("map_calculate_borders()");
2385
2386 whole_map_iterate(&(wld.map), ptile) {
2387 if (is_border_source(ptile)) {
2388 map_claim_border(ptile, ptile->owner, -1);
2389 }
2391
2392 log_verbose("map_calculate_borders() workers");
2395}
2396
2397/**********************************************************************/
2400void map_claim_base(struct tile *ptile, struct extra_type *pextra,
2401 struct player *powner, struct player *ploser)
2402{
2403 struct base_type *pbase;
2405 int units_num = 0;
2406 int ul_size;
2407
2408 if (!tile_has_extra(ptile, pextra)) {
2409 return;
2410 }
2411
2412 if (pextra->eus != EUS_NORMAL) {
2413 ul_size = unit_list_size(ptile->units);
2414 } else {
2415 ul_size = 0;
2416 }
2417
2418 int stored_units[ul_size + 1];
2419
2420 if (ul_size > 0) {
2421 int i;
2422
2424
2425 unit_list_iterate(ptile->units, aunit) {
2426 stored_units[units_num++] = aunit->id;
2428
2430
2431 for (i = 0; i < units_num; i++) {
2433
2438 }
2440 }
2441 }
2442
2443 pbase = extra_base_get(pextra);
2444
2446
2447 /* Transfer base provided vision to new owner */
2448 if (powner != NULL) {
2449 const v_radius_t old_radius_sq = V_RADIUS(-1, -1, -1);
2450 const v_radius_t new_radius_sq = V_RADIUS(pbase->vision_main_sq,
2451 pbase->vision_invis_sq,
2452 pbase->vision_subs_sq);
2453
2456 }
2457
2458 if (ploser != NULL) {
2459 const v_radius_t old_radius_sq = V_RADIUS(pbase->vision_main_sq,
2460 pbase->vision_invis_sq,
2461 pbase->vision_subs_sq);
2462 const v_radius_t new_radius_sq = V_RADIUS(-1, -1, -1);
2463
2466 }
2467
2469 && territory_claiming_base(pbase) && powner != ploser) {
2470 /* Clear borders from old owner. New owner may not know all those
2471 * tiles and thus does not claim them when borders mode is less
2472 * than EXPAND. */
2473 if (ploser != NULL) {
2474 /* Set this particular tile owner by NULL so in recursion
2475 * both loser and owner will be NULL. */
2476 map_claim_border_ownership(ptile, NULL, ptile);
2477 map_clear_border(ptile);
2478 }
2479
2480 /* We here first claim this tile ownership -> now on extra_owner()
2481 * will return new owner. Then we claim border, which will recursively
2482 * lead to this tile and base being claimed. But at that point
2483 * ploser == powner and above check will abort the recursion. */
2484 if (powner != NULL) {
2485 map_claim_border_ownership(ptile, powner, ptile);
2486 map_claim_border(ptile, powner, -1);
2487 }
2490 }
2491
2492 if (units_num > 0) {
2493 int i;
2494
2495 for (i = 0; i < units_num; i++) {
2497
2501 send_unit_info(aplayer->connections, aunit);
2502 }
2503 } else {
2506 }
2507 }
2509 }
2510
2512 }
2513}
2514
2515/**********************************************************************/
2521void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
2522{
2524 radius_sq, vision->can_reveal_tiles);
2525 memcpy(vision->radius_sq, radius_sq, sizeof(v_radius_t));
2526}
2527
2528/**********************************************************************/
2534{
2535 const v_radius_t vision_radius_sq = V_RADIUS(-1, -1, -1);
2536
2537 vision_change_sight(vision, vision_radius_sq);
2538
2539 /* Owner of some city might have lost vision of a tile previously worked */
2540 players_iterate(pplayer) {
2541 city_list_iterate(pplayer->cities, pcity) {
2542 /* We are not interested about CNA_BROADCAST_PENDING, as the vision loss has
2543 * not set it, and whatever set it should take care of it. */
2544 if (pcity->server.needs_arrange == CNA_NORMAL) {
2545 city_refresh(pcity);
2546 auto_arrange_workers(pcity);
2547 pcity->server.needs_arrange = CNA_NOT;
2548 }
2551}
2552
2553/**********************************************************************/
2556void create_extra(struct tile *ptile, struct extra_type *pextra,
2557 struct player *pplayer)
2558{
2559 bool extras_removed = FALSE;
2560
2562 if (tile_has_extra(ptile, old_extra)
2563 && !can_extras_coexist(old_extra, pextra)) {
2564 destroy_extra(ptile, old_extra);
2566 }
2568
2569 if (pextra->eus != EUS_NORMAL) {
2570 unit_list_iterate(ptile->units, aunit) {
2573 if (!pplayers_allied(pplayer, aplayer)
2576 }
2578 }
2580 }
2581
2582 tile_add_extra(ptile, pextra);
2583
2584 /* Watchtower might become effective. */
2586
2587 if (pextra->data.base != NULL) {
2588 /* Claim bases on tile */
2589 if (pplayer) {
2590 struct player *old_owner = extra_owner(ptile);
2591
2592 /* Created base from NULL -> pplayer */
2593 map_claim_base(ptile, pextra, pplayer, NULL);
2594
2595 if (old_owner != pplayer) {
2596 /* Existing bases from old_owner -> pplayer */
2598 if (oldbase != pextra) {
2599 map_claim_base(ptile, oldbase, pplayer, old_owner);
2600 }
2602
2603 ptile->extras_owner = pplayer;
2604 }
2605 } else {
2606 /* Player who already owns bases on tile claims new base */
2607 map_claim_base(ptile, pextra, extra_owner(ptile), NULL);
2608 }
2609 }
2610
2611 if (extras_removed) {
2612 /* Maybe conflicting extra that was removed was the only thing
2613 * making tile native to some unit. */
2615 }
2616}
2617
2618/**********************************************************************/
2621void destroy_extra(struct tile *ptile, struct extra_type *pextra)
2622{
2624 bool real = tile_map_check(&(wld.map), ptile);
2625
2626 /* Remember what players were able to see the base. */
2627 if (real) {
2629 players_iterate(pplayer) {
2630 if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
2631 BV_SET(base_seen, player_index(pplayer));
2632 }
2634 }
2635
2636 if (real && is_extra_caused_by(pextra, EC_BASE)) {
2637 struct base_type *pbase = extra_base_get(pextra);
2638 struct player *owner = extra_owner(ptile);
2639
2641 map_clear_border(ptile);
2642 }
2643
2644 if (NULL != owner
2645 && (0 <= pbase->vision_main_sq || 0 <= pbase->vision_invis_sq)) {
2646 /* Base provides vision, but no borders. */
2648 V_RADIUS(0 <= pbase->vision_main_sq ? pbase->vision_main_sq : -1,
2649 0 <= pbase->vision_invis_sq ? pbase->vision_invis_sq : -1,
2650 0 <= pbase->vision_subs_sq ? pbase->vision_subs_sq : -1);
2651 const v_radius_t new_radius_sq = V_RADIUS(-1, -1, -1);
2652
2655 }
2656 }
2657
2658 tile_remove_extra(ptile, pextra);
2659
2660 if (real) {
2661 /* Remove base from vision of players which were able to see the base. */
2662 players_iterate(pplayer) {
2663 if (BV_ISSET(base_seen, player_index(pplayer))
2664 && update_player_tile_knowledge(pplayer, ptile)) {
2665 send_tile_info(pplayer->connections, ptile, FALSE);
2666 }
2668
2669 if (pextra->eus != EUS_NORMAL) {
2670 struct player *eowner = extra_owner(ptile);
2671
2672 unit_list_iterate(ptile->units, aunit) {
2676 && !pplayers_allied(aplayer, eowner)) {
2677 send_unit_info(aplayer->connections, aunit);
2678 }
2680 }
2682 }
2683 }
2684}
2685
2686/**********************************************************************/
2697 int prob, bool reveal_cities)
2698{
2699 bool updt = FALSE;
2700
2702
2703 whole_map_iterate(&(wld.map), ptile) {
2704 if (fc_rand(100) < prob) {
2706 } else if (reveal_cities && NULL != tile_city(ptile)) {
2708 }
2710
2712
2713 return updt;
2714}
2715
2716/**********************************************************************/
2725{
2726 struct city *pcity = ptile->worked;
2727
2728 /* Check the unit activities. */
2730
2731 if (pcity != NULL && !is_free_worked(pcity, ptile)
2732 && get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) {
2733 city_map_update_empty(pcity, ptile);
2735
2736 if (refresh_city) {
2737 auto_arrange_workers(pcity);
2738 send_city_info(NULL, pcity);
2739 }
2740 }
2741}
bool is_adv_data_phase_open(struct player *pplayer)
Definition advdata.c:243
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:263
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:565
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:158
bool bv_match_dbv(const struct dbv *match, const unsigned char *src)
Definition bitvector.c:205
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:144
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
void dbv_copy(struct dbv *dest, const struct dbv *src)
Definition bitvector.c:222
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
void dbv_clr(struct dbv *pdbv, int bit)
Definition bitvector.c:167
void dbv_to_bv(unsigned char *dest, const struct dbv *src)
Definition bitvector.c:235
#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
int tile_border_source_radius_sq(struct tile *ptile)
Definition borders.c:33
bool is_border_source(struct tile *ptile)
Definition borders.c:116
int tile_border_strength(struct tile *ptile, struct tile *source)
Definition borders.c:101
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3601
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:770
@ CNA_NOT
Definition city.h:306
@ CNA_NORMAL
Definition city.h:307
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
#define city_owner(_pcity_)
Definition city.h:563
#define city_list_iterate_end
Definition city.h:510
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
#define city_tile_iterate_end
Definition city.h:238
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3268
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2363
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2769
void sync_cities(void)
Definition citytools.c:3342
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3325
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2861
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
Definition citytools.c:3395
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2415
void city_thaw_workers_queue(void)
Definition citytools.c:198
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2840
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:367
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:198
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
void city_refresh_queue_processing(void)
Definition cityturn.c:214
char * incite_cost
Definition comments.c:75
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:366
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:732
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:356
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:720
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_list_iterate_end
Definition connection.h:110
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
int get_city_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:916
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1114
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:861
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:468
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:852
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:1003
int extra_count(void)
Definition extras.c:153
bool player_knows_extra_exist(const struct player *pplayer, const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1149
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define is_extra_caused_by(e, c)
Definition extras.h:203
#define extra_base_get(_e_)
Definition extras.h:190
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
@ HB_DISABLED
Definition fc_types.h:1290
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
signed short Continent_id
Definition fc_types.h:372
@ BORDERS_DISABLED
Definition fc_types.h:1037
@ BORDERS_SEE_INSIDE
Definition fc_types.h:1039
@ BORDERS_EXPAND
Definition fc_types.h:1040
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:92
#define _(String)
Definition fcintl.h:67
const struct ft_color ftc_server
const char * unit_link(const struct unit *punit)
const char * unit_tile_link(const struct unit *punit)
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
struct city * game_city_by_number(int id)
Definition game.c:107
struct city * owner
Definition citydlg.c:226
static GtkWidget * source
Definition gotodlg.c:58
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
#define log_error(message,...)
Definition log.h:103
int map_num_tiles(void)
Definition map.c:1014
struct tile * rand_map_pos(const struct civ_map *nmap)
Definition map.c:1088
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:614
bool terrain_surroundings_allow_change(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain)
Definition map.c:742
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1073
#define adjc_iterate_end
Definition map.h:433
#define MAP_INDEX_SIZE
Definition map.h:137
#define circle_dxyr_iterate(nmap, center_tile, sq_radius, _tile, dx, dy, dr)
Definition map.h:409
#define cardinal_adjc_iterate_end
Definition map.h:459
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:428
#define circle_dxyr_iterate_end
Definition map.h:420
#define cardinal_adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:455
#define circle_iterate(nmap, center_tile, sq_radius, tile_itr)
Definition map.h:401
#define whole_map_iterate(_map, _tile)
Definition map.h:545
#define MAP_TILE_OWNER_NULL
Definition map.h:602
#define whole_map_iterate_end
Definition map.h:554
#define circle_iterate_end
Definition map.h:404
void assign_continent_numbers(void)
int get_ocean_size(Continent_id id)
struct terrain * most_shallow_ocean(bool frozen)
int get_lake_surrounders(Continent_id cont)
void player_map_init(struct player *pplayer)
Definition maphand.c:1221
static void terrain_change_bounce_single_unit(struct unit *punit, struct tile *from)
Definition maphand.c:1831
void update_player_tile_last_seen(struct player *pplayer, struct tile *ptile)
Definition maphand.c:1467
static void shared_vision_change_seen(struct player *pplayer, struct tile *ptile, const v_radius_t change, bool can_reveal_tiles)
Definition maphand.c:667
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2533
void map_claim_base(struct tile *ptile, struct extra_type *pextra, struct player *powner, struct player *ploser)
Definition maphand.c:2400
void map_set_border_vision(struct player *pplayer, const bool is_enabled)
Definition maphand.c:740
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2207
static int player_tile_own_seen(const struct player_tile *plrtile, enum vision_layer vlayer)
Definition maphand.c:1136
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:894
static bool map_is_also_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:909
void send_map_info(struct conn_list *dest)
Definition maphand.c:649
static bool really_give_tile_info_from_player_to_player(struct player *pfrom, struct player *pdest, struct tile *ptile)
Definition maphand.c:1485
bool send_tile_suppression(bool now)
Definition maphand.c:475
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2621
static void check_units_single_tile(struct tile *ptile)
Definition maphand.c:1885
static void really_give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:1558
void disable_fog_of_war(void)
Definition maphand.c:1789
bool really_gives_vision(struct player *me, struct player *them)
Definition maphand.c:345
static bool unit_is_on_layer(const struct unit *punit, enum vision_layer vlayer)
Definition maphand.c:640
void map_know_and_see_all(struct player *pplayer)
Definition maphand.c:1196
static void map_change_own_seen(struct player *pplayer, struct tile *ptile, const v_radius_t change)
Definition maphand.c:1145
void show_map_to_all(void)
Definition maphand.c:1210
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:491
bool update_player_tile_knowledge(struct player *pplayer, struct tile *ptile)
Definition maphand.c:1398
static int map_get_seen(const struct player *pplayer, const struct tile *ptile, enum vision_layer vlayer)
Definition maphand.c:934
static void ocean_to_land_fix_rivers(struct tile *ptile)
Definition maphand.c:1805
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:384
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:444
void bounce_units_on_terrain_change(struct tile *ptile)
Definition maphand.c:1919
void give_seamap_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:400
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1693
bool need_to_reassign_continents(const struct terrain *oldter, const struct terrain *newter)
Definition maphand.c:1937
static bool is_claimable_ocean(struct tile *ptile, struct tile *source, struct player *pplayer)
Definition maphand.c:2097
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1367
static bool is_terrain_ecologically_wet(struct tile *ptile)
Definition maphand.c:96
void tile_claim_bases(struct tile *ptile, struct player *powner)
Definition maphand.c:2220
void disable_fog_of_war_player(struct player *pplayer)
Definition maphand.c:1773
void climate_change(bool warming, int effect)
Definition maphand.c:133
void enable_fog_of_war(void)
Definition maphand.c:1763
static bool send_tile_suppressed
Definition maphand.c:65
static void create_vision_dependencies(void)
Definition maphand.c:1598
void upgrade_all_city_extras(struct player *pplayer, bool discovery)
Definition maphand.c:276
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2556
void map_update_border(struct tile *ptile, struct player *owner, int old_radius_sq, int new_radius_sq)
Definition maphand.c:2254
void map_set_known(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1178
void map_show_all(struct player *pplayer)
Definition maphand.c:879
static void map_unit_homecity_enqueue(struct tile *ptile)
Definition maphand.c:2146
static void map_change_seen(struct player *pplayer, struct tile *ptile, const v_radius_t change, bool can_reveal_tiles)
Definition maphand.c:947
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:768
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:418
void nuclear_winter(int effect)
Definition maphand.c:119
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2724
static void player_tile_init(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1328
void terrain_changed(struct tile *ptile)
Definition maphand.c:1956
void player_map_free(struct player *pplayer)
Definition maphand.c:1237
static void unbuffer_shared_vision(struct player *pplayer)
Definition maphand.c:368
static void map_claim_border_ownership(struct tile *ptile, struct player *powner, struct tile *psource)
Definition maphand.c:2162
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1159
void map_calculate_borders(void)
Definition maphand.c:2373
void fix_tile_on_terrain_change(struct tile *ptile, struct terrain *oldter, bool extend_rivers)
Definition maphand.c:1975
void enable_fog_of_war_player(struct player *pplayer)
Definition maphand.c:1747
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
Definition maphand.c:864
void map_vision_update(struct player *pplayer, struct tile *ptile, const v_radius_t old_radius_sq, const v_radius_t new_radius_sq, bool can_reveal_tiles)
Definition maphand.c:685
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2286
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1439
void remove_player_from_maps(struct player *pplayer)
Definition maphand.c:1258
void give_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1632
void check_terrain_change(struct tile *ptile, struct terrain *oldter)
Definition maphand.c:1995
bool give_distorted_map(struct player *pfrom, struct player *pto, int prob, bool reveal_cities)
Definition maphand.c:2696
void map_hide_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:820
static void buffer_shared_vision(struct player *pplayer)
Definition maphand.c:353
static bool give_tile_info_from_player_to_player(struct player *pfrom, struct player *pdest, struct tile *ptile)
Definition maphand.c:1578
void global_warming(int effect)
Definition maphand.c:106
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:241
void map_clear_border(struct tile *ptile)
Definition maphand.c:2237
void map_clear_known(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1186
static void player_tile_free(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1353
#define MAXIMUM_CLAIMED_OCEAN_SIZE
Definition maphand.c:62
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1382
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2521
#define map_get_player_site(_ptile_, _pplayer_)
Definition maphand.h:93
#define map_get_playermap_site(_plrtile_)
Definition maphand.h:92
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void dlsend_packet_edit_fogofwar_state(struct conn_list *dest, bool enabled)
void lsend_packet_map_info(struct conn_list *dest, const struct packet_map_info *packet)
int send_packet_tile_info(struct connection *pc, const struct packet_tile_info *packet)
int num_known_tech_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1273
int player_slot_count(void)
Definition player.c:418
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
int player_index(const struct player *pplayer)
Definition player.c:829
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1485
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
#define phase_players_iterate(pplayer)
Definition plrhand.h:113
#define phase_players_iterate_end
Definition plrhand.h:118
#define fc_rand(_size)
Definition rand.h:56
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
int count_river_near_tile(struct civ_map *nmap, const struct tile *ptile, const struct extra_type *priver)
Definition road.c:334
#define sanity_check_tile(x)
Definition sanitycheck.h:42
void flush_packets(void)
Definition sernet.c:381
#define DEFAULT_SPECIALIST
Definition specialist.h:43
enum server_states server_state(void)
Definition srv_main.c:333
Definition city.h:320
enum city_needs_arrange needs_arrange
Definition city.h:441
citizens specialists[SP_MAX]
Definition city.h:336
struct tile * tile
Definition city.h:322
struct city::@17::@19 server
bool last_updated_year
Definition game.h:240
bool vision_reveal_tiles
Definition game.h:204
bool fogofwar_old
Definition game.h:238
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
struct packet_scenario_info scenario
Definition game.h:87
bool foggedborders
Definition game.h:151
struct civ_game::@31::@35 server
struct tile * tiles
Definition map_types.h:83
int xsize
Definition map_types.h:78
int ysize
Definition map_types.h:78
int north_latitude
Definition map_types.h:79
int south_latitude
Definition map_types.h:80
int topology_id
Definition map_types.h:72
int wrap_id
Definition map_types.h:73
unsigned char * vec
Definition bitvector.h:34
struct resource_type * resource
Definition extras.h:156
struct extra_type::@25 data
enum extra_unit_seen_type eus
Definition extras.h:128
struct base_type * base
Definition extras.h:154
enum borders_mode borders
enum happyborders_type happyborders
int border_city_permanent_radius_sq
Resource_type_id resource
enum known_type known
char label[MAX_LEN_MAP_LABEL]
Continent_id continent
Definition packets_gen.h:99
Terrain_type_id terrain
char spec_sprite[MAX_LEN_NAME]
struct player * extras_owner
Definition maphand.h:35
v_radius_t seen_count
Definition maphand.h:43
struct vision_site * site
Definition maphand.h:31
struct terrain * terrain
Definition maphand.h:33
struct dbv extras
Definition maphand.h:36
short last_updated
Definition maphand.h:44
struct player * owner
Definition maphand.h:34
struct extra_type * resource
Definition maphand.h:32
struct city_list * cities
Definition player.h:279
struct dbv tile_known
Definition player.h:308
struct conn_list * connections
Definition player.h:296
struct player_tile * private_map
Definition player.h:322
bool border_vision
Definition player.h:325
struct player::@70::@72 server
struct terrain * cooler_wetter_result
Definition terrain.h:241
struct terrain * cooler_drier_result
Definition terrain.h:241
struct terrain * warmer_wetter_result
Definition terrain.h:240
struct terrain * warmer_drier_result
Definition terrain.h:240
Definition tile.h:50
char * spec_sprite
Definition tile.h:66
char * label
Definition tile.h:65
bv_extras extras
Definition tile.h:55
struct extra_type * resource
Definition tile.h:56
struct unit_list * units
Definition tile.h:58
struct player * extras_owner
Definition tile.h:63
struct terrain * terrain
Definition tile.h:57
int infra_turns
Definition tile.h:62
struct extra_type * placing
Definition tile.h:61
struct city * worked
Definition tile.h:59
struct tile * claimer
Definition tile.h:64
enum vision_layer vlayer
Definition unittype.h:569
Definition unit.h:138
enum unit_activity activity
Definition unit.h:157
int id
Definition unit.h:145
struct unit::@81::@84 server
struct extra_type * activity_target
Definition unit.h:164
int homecity
Definition unit.h:146
bool dying
Definition unit.h:250
int identity
Definition vision.h:115
struct tile * tile
Definition vision.h:88
bool can_reveal_tiles
Definition vision.h:89
v_radius_t radius_sq
Definition vision.h:92
struct player * player
Definition vision.h:87
struct civ_map map
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:612
Terrain_type_id terrain_count(void)
Definition terrain.c:118
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
#define T_UNKNOWN
Definition terrain.h:57
#define is_ocean(pterrain)
Definition terrain.h:301
#define is_ocean_tile(ptile)
Definition terrain.h:303
#define T_NONE
Definition terrain.h:56
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:955
bool tile_has_river(const struct tile *ptile)
Definition tile.c:852
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1065
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:965
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:496
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:901
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_claimer(_tile)
Definition tile.h:100
#define tile_index(_pt_)
Definition tile.h:88
#define tile_worked(_tile)
Definition tile.h:114
#define tile_resource(_tile)
Definition tile.h:102
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:110
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_continent(_tile)
Definition tile.h:92
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
#define tile_owner(_tile)
Definition tile.h:96
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1783
bool unit_is_alive(int id)
Definition unit.c:2253
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2425
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2451
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:432
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6471
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2709
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2722
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:796
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2131
void unit_activities_cancel_all_illegal_area(const struct tile *ptile)
Definition unittools.c:841
bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, struct unit *embark_to, bool find_embark_target, bool conquer_city_allowed, bool conquer_extras_allowed, bool enter_hut, bool frighten_hut)
Definition unittools.c:3918
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4857
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
struct vision_site * vision_site_copy(const struct vision_site *psite)
Definition vision.c:150
void vision_site_destroy(struct vision_site *psite)
Definition vision.c:74
#define V_RADIUS(main_sq, invis_sq, subs_sq)
Definition vision.h:96
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_site_owner(v)
Definition vision.h:129
short int v_radius_t[V_COUNT]
Definition vision.h:83
#define vision_layer_iterate_end
Definition vision.h:80