Freeciv-3.3: /fast/freeciv/nightly/main/server/maphand.c Source File

Freeciv-3.3

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() */
65 static bool send_tile_suppressed = FALSE;
66
67static void player_tile_init(struct tile *ptile, struct player *pplayer);
68static void player_tile_free(struct tile *ptile, struct player *pplayer);
69static bool give_tile_info_from_player_to_player(struct player *pfrom,
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/**********************************************************************/
96 static 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/**********************************************************************/
106 void global_warming(int effect)
107{
108 climate_change(TRUE, effect);
109 notify_player(NULL, NULL, E_GLOBAL_ECO, ftc_server,
110 _("Global warming has occurred!"));
111 notify_player(NULL, NULL, E_GLOBAL_ECO, ftc_server,
112 _("Coastlines have been flooded and vast "
113 "ranges of grassland have become deserts."));
114}
115
116/**********************************************************************/
119 void nuclear_winter(int effect)
120{
121 climate_change(FALSE, effect);
122 notify_player(NULL, NULL, E_GLOBAL_ECO, ftc_server,
123 _("Nuclear winter has occurred!"));
124 notify_player(NULL, NULL, E_GLOBAL_ECO, ftc_server,
125 _("Wetlands have dried up and vast "
126 "ranges of grassland have become tundra."));
127}
128
129/**********************************************************************/
133 void climate_change(bool warming, int effect)
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
161 wetter = warming ? old->warmer_wetter_result : old->cooler_wetter_result;
162 drier = warming ? old->warmer_drier_result : old->cooler_drier_result;
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. */
215 if (punit->activity == ACTIVITY_CULTIVATE
216 || punit->activity == ACTIVITY_PLANT
217 || punit->activity == ACTIVITY_TRANSFORM) {
218 unit_activities_cancel(punit);
219 }
220 }
221 } unit_list_iterate_end;
222
223 /* Really change the terrain. */
224 tile_change_terrain(ptile, new);
225 check_terrain_change(ptile, old);
226 update_tile_knowledge(ptile);
227
228 tile_change_side_effects(ptile, FALSE);
229
230 } else if (old == new) {
231 /* This counts toward a climate change although nothing is changed. */
232 effect--;
233 }
234 }
235}
236
237/**********************************************************************/
241 bool 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)) {
249 if (extra_has_flag(pextra, EF_ALWAYS_ON_CITY_CENTER)
250 || (extra_has_flag(pextra, EF_AUTO_ON_CITY_CENTER)
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 }
264 } extra_type_iterate_end;
265
266 return upgradet;
267}
268
269/**********************************************************************/
276 void 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
284 conn_list_do_buffer(pplayer->connections);
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);
291 cities_upgradet++;
292 if (new_upgrade == NULL) {
293 /* This single city alone had multiple types */
294 multiple_types = TRUE;
295 } else if (upgradet == NULL) {
296 /* First gained */
297 upgradet = new_upgrade;
298 } else if (upgradet != new_upgrade) {
299 /* Different type from what another city got. */
300 multiple_types = TRUE;
301 }
302 }
303 } city_list_iterate_end;
304
305 if (cities_total > 0) {
306 percent = cities_upgradet * 100 / cities_total;
307 } else {
308 percent = 0;
309 }
310
311 if (cities_upgradet > 0) {
312 if (discovery) {
313 if (percent >= 75) {
314 notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
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) {
321 notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
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) {
329 notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
330 _("Workers spontaneously gather and upgrade all "
331 "possible cities with better infrastructure."));
332 } else {
333 notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
334 _("Workers spontaneously gather and upgrade all "
335 "possible cities with %s."), extra_name_translation(upgradet));
336 }
337 }
338
339 conn_list_do_unbuffer(pplayer->connections);
340}
341
342/**********************************************************************/
345 bool really_gives_vision(struct player *me, struct player *them)
346{
347 return BV_ISSET(me->server.really_gives_vision, player_index(them));
348}
349
350/**********************************************************************/
353 static void buffer_shared_vision(struct player *pplayer)
354{
355 players_iterate(pplayer2) {
356 if (really_gives_vision(pplayer, pplayer2)) {
357 conn_list_compression_freeze(pplayer2->connections);
358 conn_list_do_buffer(pplayer2->connections);
359 }
360 } players_iterate_end;
361 conn_list_compression_freeze(pplayer->connections);
362 conn_list_do_buffer(pplayer->connections);
363}
364
365/**********************************************************************/
368 static void unbuffer_shared_vision(struct player *pplayer)
369{
370 players_iterate(pplayer2) {
371 if (really_gives_vision(pplayer, pplayer2)) {
372 conn_list_do_unbuffer(pplayer2->connections);
373 conn_list_compression_thaw(pplayer2->connections);
374 }
375 } players_iterate_end;
376 conn_list_do_unbuffer(pplayer->connections);
377 conn_list_compression_thaw(pplayer->connections);
378}
379
380/**********************************************************************/
384 void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
385{
386 buffer_shared_vision(pdest);
387
388 whole_map_iterate(&(wld.map), ptile) {
389 give_tile_info_from_player_to_player(pfrom, pdest, ptile);
390 } whole_map_iterate_end;
391
392 unbuffer_shared_vision(pdest);
393 city_thaw_workers_queue();
394 sync_cities();
395}
396
397/**********************************************************************/
400 void give_seamap_from_player_to_player(struct player *pfrom, struct player *pdest)
401{
402 buffer_shared_vision(pdest);
403
404 whole_map_iterate(&(wld.map), ptile) {
405 if (is_ocean_tile(ptile)) {
406 give_tile_info_from_player_to_player(pfrom, pdest, ptile);
407 }
408 } whole_map_iterate_end;
409
410 unbuffer_shared_vision(pdest);
411 city_thaw_workers_queue();
412 sync_cities();
413}
414
415/**********************************************************************/
418 void give_citymap_from_player_to_player(struct city *pcity,
419 struct player *pfrom, struct player *pdest)
420{
421 struct tile *pcenter = city_tile(pcity);
422 const struct civ_map *nmap = &(wld.map);
423
424 buffer_shared_vision(pdest);
425
426 city_tile_iterate(nmap, city_map_radius_sq_get(pcity), pcenter, ptile) {
427 give_tile_info_from_player_to_player(pfrom, pdest, ptile);
428 } city_tile_iterate_end;
429
430 unbuffer_shared_vision(pdest);
431 city_thaw_workers_queue();
432 sync_cities();
433}
434
435/**********************************************************************/
444 void send_all_known_tiles(struct conn_list *dest)
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;
455 conn_list_do_buffer(dest);
456
457 whole_map_iterate(&(wld.map), ptile) {
458 tiles_sent++;
459 if ((tiles_sent % MAP_NATIVE_WIDTH) == 0) {
460 conn_list_do_unbuffer(dest);
461 flush_packets();
462 conn_list_do_buffer(dest);
463 }
464
465 send_tile_info(dest, ptile, FALSE);
466 } whole_map_iterate_end;
467
468 conn_list_do_unbuffer(dest);
469 flush_packets();
470}
471
472/**********************************************************************/
475 bool send_tile_suppression(bool now)
476{
477 bool formerly = send_tile_suppressed;
478
479 send_tile_suppressed = now;
480 return formerly;
481}
482
483/**********************************************************************/
491 void 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
502 if (send_tile_suppressed) {
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);
537 info.owner = (owner ? player_number(owner) : MAP_TILE_OWNER_NULL);
538 info.extras_owner = (eowner ? player_number(eowner) : MAP_TILE_OWNER_NULL);
539 info.worked = (NULL != tile_worked(ptile))
540 ? tile_worked(ptile)->id
541 : IDENTITY_NUMBER_ZERO;
542
543 info.terrain = (NULL != tile_terrain(ptile))
544 ? terrain_number(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))) {
551 info.resource = extra_number(resource);
552 } else {
553 info.resource = MAX_EXTRA_TYPES;
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
576 info.altitude = ptile->altitude;
577
578 send_packet_tile_info(pconn, &info);
579 } else if (pplayer != NULL && known) {
580 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
581 struct vision_site *psite = map_get_playermap_site(plrtile);
582
583 info.known = TILE_KNOWN_UNSEEN;
584 info.continent = tile_continent(ptile);
585 owner = (game.server.foggedborders
586 ? plrtile->owner
587 : tile_owner(ptile));
588 eowner = plrtile->extras_owner;
589 info.owner = (owner ? player_number(owner) : MAP_TILE_OWNER_NULL);
590 info.extras_owner = (eowner ? player_number(eowner) : MAP_TILE_OWNER_NULL);
591 info.worked = (NULL != psite)
592 ? psite->identity
593 : IDENTITY_NUMBER_ZERO;
594
595 info.terrain = (NULL != plrtile->terrain)
596 ? terrain_number(plrtile->terrain)
597 : terrain_count();
598 info.resource = (NULL != plrtile->resource)
599 ? extra_number(plrtile->resource)
600 : MAX_EXTRA_TYPES;
601 info.placing = -1;
602 info.place_turn = 0;
603
604 dbv_to_bv(info.extras.vec, &(plrtile->extras));
605
606 /* Labels never change, so they are not subject to fog of war */
607 if (ptile->label != NULL) {
608 sz_strlcpy(info.label, ptile->label);
609 } else {
610 info.label[0] = '\0';
611 }
612
613 info.altitude = ptile->altitude;
614
615 send_packet_tile_info(pconn, &info);
616 } else if (send_unknown) {
617 info.known = TILE_UNKNOWN;
618 info.continent = 0;
619 info.owner = MAP_TILE_OWNER_NULL;
620 info.extras_owner = MAP_TILE_OWNER_NULL;
621 info.worked = IDENTITY_NUMBER_ZERO;
622
623 info.terrain = terrain_count();
624 info.resource = MAX_EXTRA_TYPES;
625 info.placing = -1;
626 info.place_turn = 0;
627
628 BV_CLR_ALL(info.extras);
629
630 info.label[0] = '\0';
631
632 info.altitude = 0;
633
634 send_packet_tile_info(pconn, &info);
635 }
636 }
637 conn_list_iterate_end;
638}
639
640/**********************************************************************/
646 static bool unit_is_on_layer(const struct unit *punit,
647 enum vision_layer vlayer)
648{
649 return unit_type_get(punit)->vlayer == vlayer;
650}
651
652/**********************************************************************/
655 void send_map_info(struct conn_list *dest)
656{
657 struct packet_map_info minfo;
658
659 minfo.xsize = MAP_NATIVE_WIDTH;
660 minfo.ysize = MAP_NATIVE_HEIGHT;
661 minfo.topology_id = wld.map.topology_id;
662 minfo.wrap_id = wld.map.wrap_id;
663 minfo.north_latitude = wld.map.north_latitude;
664 minfo.south_latitude = wld.map.south_latitude;
665 minfo.altitude_info = wld.map.altitude_info;
666
667 lsend_packet_map_info(dest, &minfo);
668}
669
670/**********************************************************************/
674 static void shared_vision_change_seen(struct player *pplayer,
675 struct tile *ptile,
676 const v_radius_t change,
677 bool can_reveal_tiles)
678{
679 map_change_own_seen(pplayer, ptile, change);
680 map_change_seen(pplayer, ptile, change, can_reveal_tiles);
681
682 players_iterate(pplayer2) {
683 if (really_gives_vision(pplayer, pplayer2)) {
684 map_change_seen(pplayer2, ptile, change, can_reveal_tiles);
685 }
686 } players_iterate_end;
687}
688
689/**********************************************************************/
692 void map_vision_update(struct player *pplayer, struct tile *ptile,
693 const v_radius_t old_radius_sq,
694 const v_radius_t new_radius_sq,
695 bool can_reveal_tiles)
696{
697 v_radius_t change;
698 int max_radius;
699
700 if (old_radius_sq[V_MAIN] == new_radius_sq[V_MAIN]
701 && old_radius_sq[V_INVIS] == new_radius_sq[V_INVIS]
702 && old_radius_sq[V_SUBSURFACE] == new_radius_sq[V_SUBSURFACE]) {
703 return;
704 }
705
706 /* Determines 'max_radius' value. */
707 max_radius = 0;
708 vision_layer_iterate(v) {
709 if (max_radius < old_radius_sq[v]) {
710 max_radius = old_radius_sq[v];
711 }
712 if (max_radius < new_radius_sq[v]) {
713 max_radius = new_radius_sq[v];
714 }
715 } vision_layer_iterate_end;
716
717#ifdef FREECIV_DEBUG
718 log_debug("Updating vision at (%d, %d) in a radius of %d.",
719 TILE_XY(ptile), max_radius);
720 vision_layer_iterate(v) {
721 log_debug(" vision layer %d is changing from %d to %d.",
722 v, old_radius_sq[v], new_radius_sq[v]);
723 } vision_layer_iterate_end;
724#endif /* FREECIV_DEBUG */
725
726 buffer_shared_vision(pplayer);
727 circle_dxyr_iterate(&(wld.map), ptile, max_radius, tile1, dx, dy, dr) {
728 vision_layer_iterate(v) {
729 if (dr > old_radius_sq[v] && dr <= new_radius_sq[v]) {
730 change[v] = 1;
731 } else if (dr > new_radius_sq[v] && dr <= old_radius_sq[v]) {
732 change[v] = -1;
733 } else {
734 change[v] = 0;
735 }
736 } vision_layer_iterate_end;
737 shared_vision_change_seen(pplayer, tile1, change, can_reveal_tiles);
738 } circle_dxyr_iterate_end;
739 unbuffer_shared_vision(pplayer);
740}
741
742/**********************************************************************/
747 void map_set_border_vision(struct player *pplayer,
748 const bool is_enabled)
749{
750 const v_radius_t radius_sq = V_RADIUS(is_enabled ? 1 : -1, 0, 0);
751
752 if (pplayer->server.border_vision == is_enabled) {
753 /* No change. Changing the seen count beyond what already exists would
754 * be a bug. */
755 return;
756 }
757
758 /* Set the new border seer value. */
759 pplayer->server.border_vision = is_enabled;
760
761 whole_map_iterate(&(wld.map), ptile) {
762 if (pplayer == ptile->owner) {
763 /* The tile is within the player's borders. */
764 shared_vision_change_seen(pplayer, ptile, radius_sq, TRUE);
765 }
766 } whole_map_iterate_end;
767}
768
769/**********************************************************************/
775 void map_show_tile(struct player *src_player, struct tile *ptile)
776{
777 static int recurse = 0;
778
779 log_debug("Showing %i,%i to %s", TILE_XY(ptile), player_name(src_player));
780
781 fc_assert(recurse == 0);
782 recurse++;
783
784 players_iterate(pplayer) {
785 if (pplayer == src_player || really_gives_vision(src_player, pplayer)) {
786 struct city *pcity;
787
788 if (!map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
789 map_set_known(ptile, pplayer);
790
791 /* As the tile may be fogged send_tile_info won't always do this for us */
792 update_player_tile_knowledge(pplayer, ptile);
793 update_player_tile_last_seen(pplayer, ptile);
794
795 send_tile_info(pplayer->connections, ptile, FALSE);
796
797 /* Remove old cities that exist no more */
798 reality_check_city(pplayer, ptile);
799
800 if ((pcity = tile_city(ptile))) {
801 /* As the tile may be fogged send_city_info won't do this for us */
802 update_dumb_city(pplayer, pcity);
803 send_city_info(pplayer, pcity);
804 }
805
806 vision_layer_iterate(v) {
807 if (0 < map_get_seen(pplayer, ptile, v)) {
808 unit_list_iterate(ptile->units, punit) {
809 if (unit_is_on_layer(punit, v)) {
810 send_unit_info(pplayer->connections, punit);
811 }
812 } unit_list_iterate_end;
813 }
814 } vision_layer_iterate_end;
815 }
816 }
817 } players_iterate_end;
818
819 recurse--;
820}
821
822/**********************************************************************/
827 void map_hide_tile(struct player *src_player, struct tile *ptile)
828{
829 static int recurse = 0;
830
831 log_debug("Hiding %d,%d to %s", TILE_XY(ptile), player_name(src_player));
832
833 fc_assert(recurse == 0);
834 recurse++;
835
836 players_iterate(pplayer) {
837 if (pplayer == src_player || really_gives_vision(src_player, pplayer)) {
838 if (map_is_known(ptile, pplayer)) {
839 if (0 < map_get_seen(pplayer, ptile, V_MAIN)) {
840 update_player_tile_last_seen(pplayer, ptile);
841 }
842
843 /* Remove city. */
844 remove_dumb_city(pplayer, ptile);
845
846 /* Remove units. */
847 vision_layer_iterate(v) {
848 if (0 < map_get_seen(pplayer, ptile, v)) {
849 unit_list_iterate(ptile->units, punit) {
850 if (unit_is_on_layer(punit, v)) {
851 unit_goes_out_of_sight(pplayer, punit);
852 }
853 } unit_list_iterate_end;
854 }
855 } vision_layer_iterate_end;
856 }
857
858 map_clear_known(ptile, pplayer);
859
860 send_tile_info(pplayer->connections, ptile, TRUE);
861 }
862 } players_iterate_end;
863
864 recurse--;
865}
866
867/**********************************************************************/
871 void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
872{
873 buffer_shared_vision(pplayer);
874
875 circle_iterate(&(wld.map), ptile, radius_sq, tile1) {
876 map_show_tile(pplayer, tile1);
877 } circle_iterate_end;
878
879 unbuffer_shared_vision(pplayer);
880}
881
882/**********************************************************************/
886 void map_show_all(struct player *pplayer)
887{
888 buffer_shared_vision(pplayer);
889
890 whole_map_iterate(&(wld.map), ptile) {
891 map_show_tile(pplayer, ptile);
892 } whole_map_iterate_end;
893
894 unbuffer_shared_vision(pplayer);
895}
896
897/**********************************************************************/
901 bool map_is_known(const struct tile *ptile, const struct player *pplayer)
902{
903 if (pplayer->tile_known.vec == NULL) {
904 /* Player map not initialized yet */
905 return FALSE;
906 }
907
908 return dbv_isset(&pplayer->tile_known, tile_index(ptile));
909}
910
911/**********************************************************************/
916 static inline bool map_is_also_seen(const struct tile *ptile,
917 const struct player *pplayer,
918 enum vision_layer vlayer)
919{
920 return map_get_seen(pplayer, ptile, vlayer) > 0;
921}
922
923/**********************************************************************/
927 bool map_is_known_and_seen(const struct tile *ptile,
928 const struct player *pplayer,
929 enum vision_layer vlayer)
930{
931 return map_is_known(ptile, pplayer) && map_is_also_seen(ptile, pplayer, vlayer);
932}
933
934/**********************************************************************/
941 static inline int map_get_seen(const struct player *pplayer,
942 const struct tile *ptile,
943 enum vision_layer vlayer)
944{
945 return map_get_player_tile(ptile, pplayer)->seen_count[vlayer];
946}
947
948/**********************************************************************/
954 void map_change_seen(struct player *pplayer,
955 struct tile *ptile,
956 const v_radius_t change,
957 bool can_reveal_tiles)
958{
959 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
960 bool revealing_tile = FALSE;
961
962#ifdef FREECIV_DEBUG
963 log_debug("%s() for player %s (nb %d) at (%d, %d).",
964 __FUNCTION__, player_name(pplayer), player_number(pplayer),
965 TILE_XY(ptile));
966 vision_layer_iterate(v) {
967 log_debug(" vision layer %d is changing from %d to %d.",
968 v, plrtile->seen_count[v], plrtile->seen_count[v] + change[v]);
969 } vision_layer_iterate_end;
970#endif /* FREECIV_DEBUG */
971
972 /* Removes units out of vision. First, check invisible layers because
973 * we must remove all units before fog of war because clients expect
974 * the tile is empty when it is fogged. */
975 if (0 > change[V_INVIS]
976 && plrtile->seen_count[V_INVIS] == -change[V_INVIS]) {
977 log_debug("(%d, %d): hiding invisible units to player %s (nb %d).",
978 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
979
980 unit_list_iterate(ptile->units, punit) {
981 if (unit_is_on_layer(punit, V_INVIS)
982 && can_player_see_unit(pplayer, punit)
983 && (plrtile->seen_count[V_MAIN] + change[V_MAIN] <= 0
984 || !pplayers_allied(pplayer, unit_owner(punit)))) {
985 /* Allied units on seen tiles (V_MAIN) are always seen.
986 * That's how can_player_see_unit_at() works. */
987 unit_goes_out_of_sight(pplayer, punit);
988 }
989 } unit_list_iterate_end;
990 }
991 if (0 > change[V_SUBSURFACE]
992 && plrtile->seen_count[V_SUBSURFACE] == -change[V_SUBSURFACE]) {
993 log_debug("(%d, %d): hiding subsurface units to player %s (nb %d).",
994 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
995
996 unit_list_iterate(ptile->units, punit) {
997 if (unit_is_on_layer(punit, V_SUBSURFACE)
998 && can_player_see_unit(pplayer, punit)) {
999 unit_goes_out_of_sight(pplayer, punit);
1000 }
1001 } unit_list_iterate_end;
1002 }
1003
1004 if (0 > change[V_MAIN]
1005 && plrtile->seen_count[V_MAIN] == -change[V_MAIN]) {
1006 log_debug("(%d, %d): hiding visible units to player %s (nb %d).",
1007 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
1008
1009 unit_list_iterate(ptile->units, punit) {
1010 if (unit_is_on_layer(punit, V_MAIN)
1011 && can_player_see_unit(pplayer, punit)) {
1012 unit_goes_out_of_sight(pplayer, punit);
1013 }
1014 } unit_list_iterate_end;
1015 }
1016
1017 vision_layer_iterate(v) {
1018 /* Avoid underflow. */
1019 fc_assert(0 <= change[v] || -change[v] <= plrtile->seen_count[v]);
1020 plrtile->seen_count[v] += change[v];
1021 } vision_layer_iterate_end;
1022
1023 /* V_MAIN vision ranges must always be more than invisible ranges
1024 * (see comment in common/vision.h), so we assume that the V_MAIN
1025 * seen count cannot be inferior to V_INVIS or V_SUBSURFACE seen count.
1026 * Moreover, when the fog of war is disabled, V_MAIN has an extra
1027 * seen count point. */
1028 fc_assert(plrtile->seen_count[V_INVIS] + !game.info.fogofwar
1029 <= plrtile->seen_count[V_MAIN]);
1030 fc_assert(plrtile->seen_count[V_SUBSURFACE] + !game.info.fogofwar
1031 <= plrtile->seen_count[V_MAIN]);
1032
1033 if (!map_is_known(ptile, pplayer)) {
1034 if (0 < plrtile->seen_count[V_MAIN] && can_reveal_tiles) {
1035 log_debug("(%d, %d): revealing tile to player %s (nb %d).",
1036 TILE_XY(ptile), player_name(pplayer),
1037 player_number(pplayer));
1038
1039 map_set_known(ptile, pplayer);
1040 revealing_tile = TRUE;
1041 } else {
1042 return;
1043 }
1044 }
1045
1046 /* Fog the tile. */
1047 if (0 > change[V_MAIN] && 0 == plrtile->seen_count[V_MAIN]) {
1048 struct city *pcity;
1049
1050 log_debug("(%d, %d): fogging tile for player %s (nb %d).",
1051 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
1052
1053 pcity = ptile->worked;
1054
1055 if (pcity != NULL && city_owner(pcity) == pplayer) {
1056 city_map_update_empty(pcity, ptile);
1057 pcity->specialists[DEFAULT_SPECIALIST]++;
1058 if (pcity->server.needs_arrange == CNA_NOT) {
1059 pcity->server.needs_arrange = CNA_NORMAL;
1060 }
1061 }
1062
1063 update_player_tile_last_seen(pplayer, ptile);
1064 if (game.server.foggedborders) {
1065 plrtile->owner = tile_owner(ptile);
1066 }
1067 plrtile->extras_owner = extra_owner(ptile);
1068 send_tile_info(pplayer->connections, ptile, FALSE);
1069 }
1070
1071 if ((revealing_tile && 0 < plrtile->seen_count[V_MAIN])
1072 || (0 < change[V_MAIN]
1073 /* plrtile->seen_count[V_MAIN] Always set to 1
1074 * when the fog of war is disabled. */
1075 && (change[V_MAIN] + !game.info.fogofwar
1076 == (plrtile->seen_count[V_MAIN])))) {
1077 struct city *pcity;
1078
1079 log_debug("(%d, %d): unfogging tile for player %s (nb %d).",
1080 TILE_XY(ptile), player_name(pplayer), player_number(pplayer));
1081
1082 /* Send info about the tile itself.
1083 * It has to be sent first because the client needs correct
1084 * continent number before it can handle following packets
1085 */
1086 update_player_tile_knowledge(pplayer, ptile);
1087 send_tile_info(pplayer->connections, ptile, FALSE);
1088
1089 /* Discover units. */
1090 unit_list_iterate(ptile->units, punit) {
1091 /* Be sure not to revive dead unit on client when it's not yet
1092 * removed from the tile. This could happen when "unit_lost" lua script
1093 * somehow causes tile of the dead unit to unfog again. */
1094 if (unit_is_on_layer(punit, V_MAIN)
1095 && !punit->server.dying) {
1096 send_unit_info(pplayer->connections, punit);
1097 }
1098 } unit_list_iterate_end;
1099
1100 /* Discover cities. */
1101 reality_check_city(pplayer, ptile);
1102
1103 if (NULL != (pcity = tile_city(ptile))) {
1104 send_city_info(pplayer, pcity);
1105 }
1106 }
1107
1108 if ((revealing_tile && 0 < plrtile->seen_count[V_INVIS])
1109 || (0 < change[V_INVIS]
1110 && change[V_INVIS] == plrtile->seen_count[V_INVIS])) {
1111 log_debug("(%d, %d): revealing invisible units to player %s (nb %d).",
1112 TILE_XY(ptile), player_name(pplayer),
1113 player_number(pplayer));
1114 /* Discover units. */
1115 unit_list_iterate(ptile->units, punit) {
1116 if (unit_is_on_layer(punit, V_INVIS)) {
1117 send_unit_info(pplayer->connections, punit);
1118 }
1119 } unit_list_iterate_end;
1120 }
1121 if ((revealing_tile && 0 < plrtile->seen_count[V_SUBSURFACE])
1122 || (0 < change[V_SUBSURFACE]
1123 && change[V_SUBSURFACE] == plrtile->seen_count[V_SUBSURFACE])) {
1124 log_debug("(%d, %d): revealing subsurface units to player %s (nb %d).",
1125 TILE_XY(ptile), player_name(pplayer),
1126 player_number(pplayer));
1127 /* Discover units. */
1128 unit_list_iterate(ptile->units, punit) {
1129 if (unit_is_on_layer(punit, V_SUBSURFACE)) {
1130 send_unit_info(pplayer->connections, punit);
1131 }
1132 } unit_list_iterate_end;
1133 }
1134}
1135
1136/**********************************************************************/
1143 static inline int player_tile_own_seen(const struct player_tile *plrtile,
1144 enum vision_layer vlayer)
1145{
1146 return plrtile->own_seen[vlayer];
1147}
1148
1149/**********************************************************************/
1152 static void map_change_own_seen(struct player *pplayer,
1153 struct tile *ptile,
1154 const v_radius_t change)
1155{
1156 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1157
1158 vision_layer_iterate(v) {
1159 plrtile->own_seen[v] += change[v];
1160 } vision_layer_iterate_end;
1161}
1162
1163/**********************************************************************/
1166 void change_playertile_site(struct player_tile *ptile,
1167 struct vision_site *new_site)
1168{
1169 if (ptile->site == new_site) {
1170 /* Do nothing. */
1171 return;
1172 }
1173
1174 if (ptile->site != NULL) {
1175 /* Releasing old site from tile */
1176 vision_site_destroy(ptile->site);
1177 }
1178
1179 ptile->site = new_site;
1180}
1181
1182/**********************************************************************/
1185 void map_set_known(struct tile *ptile, struct player *pplayer)
1186{
1187 dbv_set(&pplayer->tile_known, tile_index(ptile));
1188}
1189
1190/**********************************************************************/
1193 void map_clear_known(struct tile *ptile, struct player *pplayer)
1194{
1195 dbv_clr(&pplayer->tile_known, tile_index(ptile));
1196}
1197
1198/**********************************************************************/
1203 void map_know_and_see_all(struct player *pplayer)
1204{
1205 const v_radius_t radius_sq = V_RADIUS(1, 1, 1);
1206
1207 buffer_shared_vision(pplayer);
1208 whole_map_iterate(&(wld.map), ptile) {
1209 map_change_seen(pplayer, ptile, radius_sq, TRUE);
1210 } whole_map_iterate_end;
1211 unbuffer_shared_vision(pplayer);
1212}
1213
1214/**********************************************************************/
1217 void show_map_to_all(void)
1218{
1219 players_iterate(pplayer) {
1220 map_know_and_see_all(pplayer);
1221 } players_iterate_end;
1222}
1223
1224/**********************************************************************/
1228 void player_map_init(struct player *pplayer)
1229{
1230 pplayer->server.private_map
1231 = fc_realloc(pplayer->server.private_map,
1232 MAP_INDEX_SIZE * sizeof(*pplayer->server.private_map));
1233
1234 whole_map_iterate(&(wld.map), ptile) {
1235 player_tile_init(ptile, pplayer);
1236 } whole_map_iterate_end;
1237
1238 dbv_init(&pplayer->tile_known, MAP_INDEX_SIZE);
1239}
1240
1241/**********************************************************************/
1244 void player_map_free(struct player *pplayer)
1245{
1246 if (!pplayer->server.private_map) {
1247 return;
1248 }
1249
1250 whole_map_iterate(&(wld.map), ptile) {
1251 player_tile_free(ptile, pplayer);
1252 } whole_map_iterate_end;
1253
1254 free(pplayer->server.private_map);
1255 pplayer->server.private_map = NULL;
1256
1257 dbv_free(&pplayer->tile_known);
1258}
1259
1260/**********************************************************************/
1265 void remove_player_from_maps(struct player *pplayer)
1266{
1267 /* only after removing borders! */
1268 conn_list_do_buffer(game.est_connections);
1269 whole_map_iterate(&(wld.map), ptile) {
1270 /* Clear all players' knowledge about the removed player, and free
1271 * data structures (including those in removed player's player map). */
1272 bool reality_changed = FALSE;
1273
1274 players_iterate(aplayer) {
1275 struct player_tile *aplrtile;
1276 bool changed = FALSE;
1277
1278 if (!aplayer->server.private_map) {
1279 continue;
1280 }
1281 aplrtile = map_get_player_tile(ptile, aplayer);
1282
1283 /* Free vision sites (cities) for removed and other players */
1284 if (aplrtile && aplrtile->site
1285 && vision_site_owner(aplrtile->site) == pplayer) {
1286 change_playertile_site(aplrtile, NULL);
1287 changed = TRUE;
1288 }
1289
1290 /* Remove references to player from others' maps */
1291 if (aplrtile->owner == pplayer) {
1292 aplrtile->owner = NULL;
1293 changed = TRUE;
1294 }
1295 if (aplrtile->extras_owner == pplayer) {
1296 aplrtile->extras_owner = NULL;
1297 changed = TRUE;
1298 }
1299
1300 /* Must ensure references to dying player are gone from clients
1301 * before player is destroyed */
1302 if (changed) {
1303 /* This will use player tile if fogged */
1304 send_tile_info(pplayer->connections, ptile, FALSE);
1305 }
1306 } players_iterate_end;
1307
1308 /* Clear removed player's knowledge */
1309 if (pplayer->tile_known.vec) {
1310 map_clear_known(ptile, pplayer);
1311 }
1312
1313 /* Free all claimed tiles. */
1314 if (tile_owner(ptile) == pplayer) {
1315 tile_set_owner(ptile, NULL, NULL);
1316 reality_changed = TRUE;
1317 }
1318 if (extra_owner(ptile) == pplayer) {
1319 ptile->extras_owner = NULL;
1320 reality_changed = TRUE;
1321 }
1322
1323 if (reality_changed) {
1324 /* Update anyone who can see the tile (e.g. global observers) */
1325 send_tile_info(NULL, ptile, FALSE);
1326 }
1327 } whole_map_iterate_end;
1328 conn_list_do_unbuffer(game.est_connections);
1329}
1330
1331/**********************************************************************/
1335 static void player_tile_init(struct tile *ptile, struct player *pplayer)
1336{
1337 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1338
1339 plrtile->terrain = T_UNKNOWN;
1340 plrtile->resource = NULL;
1341 plrtile->owner = NULL;
1342 plrtile->extras_owner = NULL;
1343 plrtile->site = NULL;
1344 dbv_init(&(plrtile->extras), extra_count());
1345 if (!game.server.last_updated_year) {
1346 plrtile->last_updated = game.info.turn;
1347 } else {
1348 plrtile->last_updated = game.info.year;
1349 }
1350
1351 plrtile->seen_count[V_MAIN] = !game.server.fogofwar_old;
1352 plrtile->seen_count[V_INVIS] = 0;
1353 plrtile->seen_count[V_SUBSURFACE] = 0;
1354 memcpy(plrtile->own_seen, plrtile->seen_count, sizeof(v_radius_t));
1355}
1356
1357/**********************************************************************/
1360 static void player_tile_free(struct tile *ptile, struct player *pplayer)
1361{
1362 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1363
1364 if (plrtile->site != NULL) {
1365 vision_site_destroy(plrtile->site);
1366 }
1367
1368 dbv_free(&(plrtile->extras));
1369}
1370
1371/**********************************************************************/
1374 struct vision_site *map_get_player_city(const struct tile *ptile,
1375 const struct player *pplayer)
1376{
1377 struct vision_site *psite = map_get_player_site(ptile, pplayer);
1378
1379 fc_assert_ret_val(psite == NULL || psite->location == ptile, NULL);
1380
1381 return psite;
1382}
1383
1384/**********************************************************************/
1389 struct player_tile *map_get_player_tile(const struct tile *ptile,
1390 const struct player *pplayer)
1391{
1392 fc_assert_ret_val(pplayer->server.private_map, NULL);
1393
1394 return pplayer->server.private_map + tile_index(ptile);
1395}
1396
1397/**********************************************************************/
1405 bool update_player_tile_knowledge(struct player *pplayer, struct tile *ptile)
1406{
1407 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1408
1409 if (plrtile->terrain != ptile->terrain
1410 || !bv_match_dbv(&(plrtile->extras), ptile->extras.vec)
1411 || plrtile->resource != ptile->resource
1412 || plrtile->owner != tile_owner(ptile)
1413 || plrtile->extras_owner != extra_owner(ptile)) {
1414 plrtile->terrain = ptile->terrain;
1415 extra_type_iterate(pextra) {
1416 if (player_knows_extra_exist(pplayer, pextra, ptile)) {
1417 dbv_set(&(plrtile->extras), extra_number(pextra));
1418 } else {
1419 dbv_clr(&(plrtile->extras), extra_number(pextra));
1420 }
1421 } extra_type_iterate_end;
1422 if (ptile->resource != NULL
1423 && player_knows_extra_exist(pplayer, ptile->resource, ptile)) {
1424 plrtile->resource = ptile->resource;
1425 } else {
1426 plrtile->resource = NULL;
1427 }
1428 plrtile->owner = tile_owner(ptile);
1429 plrtile->extras_owner = extra_owner(ptile);
1430
1431 return TRUE;
1432 }
1433
1434 return FALSE;
1435}
1436
1437/**********************************************************************/
1446 void update_tile_knowledge(struct tile *ptile)
1447{
1448 if (server_state() == S_S_INITIAL) {
1449 return;
1450 }
1451
1452 /* Players */
1453 players_iterate(pplayer) {
1454 if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
1455 if (update_player_tile_knowledge(pplayer, ptile)) {
1456 send_tile_info(pplayer->connections, ptile, FALSE);
1457 }
1458 }
1459 } players_iterate_end;
1460
1461 /* Global observers */
1462 conn_list_iterate(game.est_connections, pconn) {
1463 struct player *pplayer = pconn->playing;
1464
1465 if (NULL == pplayer && pconn->observer) {
1466 send_tile_info(pconn->self, ptile, FALSE);
1467 }
1468 } conn_list_iterate_end;
1469}
1470
1471/**********************************************************************/
1474 void update_player_tile_last_seen(struct player *pplayer,
1475 struct tile *ptile)
1476{
1477 if (!game.server.last_updated_year) {
1478 map_get_player_tile(ptile, pplayer)->last_updated = game.info.turn;
1479 } else {
1480 map_get_player_tile(ptile, pplayer)->last_updated = game.info.year;
1481 }
1482}
1483
1484/**********************************************************************/
1492 static bool really_give_tile_info_from_player_to_player(struct player *pfrom,
1493 struct player *pdest,
1494 struct tile *ptile)
1495{
1496 if (!map_is_known_and_seen(ptile, pdest, V_MAIN)) {
1497 /* I can just hear people scream as they try to comprehend this if :).
1498 * Let me try in words:
1499 * 1) if the tile is seen by pfrom the info is sent to pdest
1500 * OR
1501 * 2) if the tile is known by pfrom AND (they have more recent info
1502 * OR it is not known by pdest)
1503 */
1504 if (map_is_known_and_seen(ptile, pfrom, V_MAIN)
1505 || (map_is_known(ptile, pfrom)
1506 && (((map_get_player_tile(ptile, pfrom)->last_updated
1507 > map_get_player_tile(ptile, pdest)->last_updated))
1508 || !map_is_known(ptile, pdest)))) {
1509 struct player_tile *from_tile, *dest_tile;
1510
1511 from_tile = map_get_player_tile(ptile, pfrom);
1512 dest_tile = map_get_player_tile(ptile, pdest);
1513 /* Update and send tile knowledge */
1514 map_set_known(ptile, pdest);
1515 dest_tile->terrain = from_tile->terrain;
1516 dbv_copy(&(dest_tile->extras), &(from_tile->extras));
1517 dest_tile->resource = from_tile->resource;
1518 dest_tile->owner = from_tile->owner;
1519 dest_tile->extras_owner = from_tile->extras_owner;
1520 dest_tile->last_updated = from_tile->last_updated;
1521 send_tile_info(pdest->connections, ptile, FALSE);
1522
1523 /* Update and send city knowledge */
1524 /* Remove outdated cities */
1525 if (dest_tile->site) {
1526 if (!from_tile->site) {
1527 /* As the city was gone on the newer from_tile
1528 it will be removed by this function */
1529 reality_check_city(pdest, ptile);
1530 } else { /* We have a dest_city. update */
1531 if (from_tile->site->identity
1532 != dest_tile->site->identity) {
1533 /* As the city was gone on the newer from_tile
1534 it will be removed by this function */
1535 reality_check_city(pdest, ptile);
1536 }
1537 }
1538 }
1539
1540 /* Set and send new city info */
1541 if (from_tile->site) {
1542 if (!dest_tile->site) {
1543 /* We cannot assign new vision site with change_playertile_site(),
1544 * since location is not yet set up for new site */
1545 dest_tile->site = vision_site_copy(from_tile->site);
1546 }
1547 /* Note that we don't care if receiver knows vision source city
1548 * or not. */
1549 send_city_info_at_tile(pdest, pdest->connections, NULL, ptile);
1550 }
1551
1552 city_map_update_tile_frozen(ptile);
1553
1554 return TRUE;
1555 }
1556 }
1557
1558 return FALSE;
1559}
1560
1561/**********************************************************************/
1565 static void really_give_map_from_player_to_player(struct player *pfrom,
1566 struct player *pdest)
1567{
1568 whole_map_iterate(&(wld.map), ptile) {
1569 really_give_tile_info_from_player_to_player(pfrom, pdest, ptile);
1570 } whole_map_iterate_end;
1571
1572 city_thaw_workers_queue();
1573 sync_cities();
1574}
1575
1576/**********************************************************************/
1585 static bool give_tile_info_from_player_to_player(struct player *pfrom,
1586 struct player *pdest,
1587 struct tile *ptile)
1588{
1589 bool updt = really_give_tile_info_from_player_to_player(pfrom, pdest, ptile);
1590
1591 players_iterate(pplayer2) {
1592 if (really_gives_vision(pdest, pplayer2)) {
1593 updt |= really_give_tile_info_from_player_to_player(pfrom, pplayer2, ptile);
1594 }
1595 } players_iterate_end;
1596
1597 return updt;
1598}
1599
1600/**********************************************************************/
1605 static void create_vision_dependencies(void)
1606{
1607 int added;
1608
1609 players_iterate(pplayer) {
1610 pplayer->server.really_gives_vision = pplayer->gives_shared_vision;
1611 } players_iterate_end;
1612
1613 /* In words: This terminates when it has run a round without adding
1614 a dependency. One loop only propagates dependencies one level deep,
1615 which is why we keep doing it as long as changes occur. */
1616 do {
1617 added = 0;
1618 players_iterate(pplayer) {
1619 players_iterate(pplayer2) {
1620 if (really_gives_vision(pplayer, pplayer2)
1621 && pplayer != pplayer2) {
1622 players_iterate(pplayer3) {
1623 if (really_gives_vision(pplayer2, pplayer3)
1624 && !really_gives_vision(pplayer, pplayer3)
1625 && pplayer != pplayer3) {
1626 BV_SET(pplayer->server.really_gives_vision, player_index(pplayer3));
1627 added++;
1628 }
1629 } players_iterate_end;
1630 }
1631 } players_iterate_end;
1632 } players_iterate_end;
1633 } while (added > 0);
1634}
1635
1636/**********************************************************************/
1639 void give_shared_vision(struct player *pfrom, struct player *pto)
1640{
1641 bv_player save_vision[player_slot_count()];
1642
1643 if (pfrom == pto) {
1644 return;
1645 }
1646
1647 if (gives_shared_vision(pfrom, pto)) {
1648 log_error("Trying to give shared vision from %s to %s, "
1649 "but that vision is already given!",
1650 player_name(pfrom), player_name(pto));
1651 return;
1652 }
1653
1654 players_iterate(pplayer) {
1655 save_vision[player_index(pplayer)] = pplayer->server.really_gives_vision;
1656 } players_iterate_end;
1657
1658 BV_SET(pfrom->gives_shared_vision, player_index(pto));
1659 create_vision_dependencies();
1660 log_debug("giving shared vision from %s to %s",
1661 player_name(pfrom), player_name(pto));
1662
1663 players_iterate(pplayer) {
1664 buffer_shared_vision(pplayer);
1665 players_iterate(pplayer2) {
1666 if (really_gives_vision(pplayer, pplayer2)
1667 && !BV_ISSET(save_vision[player_index(pplayer)],
1668 player_index(pplayer2))) {
1669 log_debug("really giving shared vision from %s to %s",
1670 player_name(pplayer), player_name(pplayer2));
1671 whole_map_iterate(&(wld.map), ptile) {
1672 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1673 const v_radius_t change =
1674 V_RADIUS(player_tile_own_seen(plrtile, V_MAIN),
1675 player_tile_own_seen(plrtile, V_INVIS),
1676 player_tile_own_seen(plrtile, V_SUBSURFACE));
1677
1678 if (0 < change[V_MAIN] || 0 < change[V_INVIS]) {
1679 map_change_seen(pplayer2, ptile, change,
1680 map_is_known(ptile, pplayer));
1681 }
1682 } whole_map_iterate_end;
1683
1684 /* Squares that are not seen, but which pfrom may have more recent
1685 knowledge of */
1686 really_give_map_from_player_to_player(pplayer, pplayer2);
1687 }
1688 } players_iterate_end;
1689 unbuffer_shared_vision(pplayer);
1690 } players_iterate_end;
1691
1692 if (S_S_RUNNING == server_state()) {
1693 send_player_info_c(pfrom, NULL);
1694 }
1695}
1696
1697/**********************************************************************/
1700 void remove_shared_vision(struct player *pfrom, struct player *pto)
1701{
1702 bv_player save_vision[player_slot_count()];
1703
1704 fc_assert_ret(pfrom != pto);
1705 if (!gives_shared_vision(pfrom, pto)) {
1706 log_error("Tried removing the shared vision from %s to %s, "
1707 "but it did not exist in the first place!",
1708 player_name(pfrom), player_name(pto));
1709 return;
1710 }
1711
1712 players_iterate(pplayer) {
1713 save_vision[player_index(pplayer)] = pplayer->server.really_gives_vision;
1714 } players_iterate_end;
1715
1716 log_debug("removing shared vision from %s to %s",
1717 player_name(pfrom), player_name(pto));
1718
1719 BV_CLR(pfrom->gives_shared_vision, player_index(pto));
1720 create_vision_dependencies();
1721
1722 players_iterate(pplayer) {
1723 buffer_shared_vision(pplayer);
1724 players_iterate(pplayer2) {
1725 if (!really_gives_vision(pplayer, pplayer2)
1726 && BV_ISSET(save_vision[player_index(pplayer)],
1727 player_index(pplayer2))) {
1728 log_debug("really removing shared vision from %s to %s",
1729 player_name(pplayer), player_name(pplayer2));
1730 whole_map_iterate(&(wld.map), ptile) {
1731 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
1732 const v_radius_t change =
1733 V_RADIUS(-player_tile_own_seen(plrtile, V_MAIN),
1734 -player_tile_own_seen(plrtile, V_INVIS),
1735 -player_tile_own_seen(plrtile, V_SUBSURFACE));
1736
1737 if (0 > change[V_MAIN] || 0 > change[V_INVIS]) {
1738 map_change_seen(pplayer2, ptile, change, FALSE);
1739 }
1740 } whole_map_iterate_end;
1741 }
1742 } players_iterate_end;
1743 unbuffer_shared_vision(pplayer);
1744 } players_iterate_end;
1745
1746 if (S_S_RUNNING == server_state()) {
1747 send_player_info_c(pfrom, NULL);
1748 }
1749}
1750
1751/**********************************************************************/
1754 void enable_fog_of_war_player(struct player *pplayer)
1755{
1756 const v_radius_t radius_sq = V_RADIUS(-1, 0, 0);
1757
1758 buffer_shared_vision(pplayer);
1759 whole_map_iterate(&(wld.map), ptile) {
1760 map_change_seen(pplayer, ptile, radius_sq, FALSE);
1761 } whole_map_iterate_end;
1762 unbuffer_shared_vision(pplayer);
1763}
1764
1765/**********************************************************************/
1768 void enable_fog_of_war(void)
1769{
1770 players_iterate(pplayer) {
1771 enable_fog_of_war_player(pplayer);
1772 } players_iterate_end;
1773}
1774
1775/**********************************************************************/
1778 void disable_fog_of_war_player(struct player *pplayer)
1779{
1780 const v_radius_t radius_sq = V_RADIUS(1, 0, 0);
1781
1782 buffer_shared_vision(pplayer);
1783 whole_map_iterate(&(wld.map), ptile) {
1784 map_change_seen(pplayer, ptile, radius_sq, FALSE);
1785 } whole_map_iterate_end;
1786 unbuffer_shared_vision(pplayer);
1787}
1788
1789/**********************************************************************/
1792 void disable_fog_of_war(void)
1793{
1794 players_iterate(pplayer) {
1795 disable_fog_of_war_player(pplayer);
1796 } players_iterate_end;
1797}
1798
1799/**********************************************************************/
1808 static void ocean_to_land_fix_rivers(struct tile *ptile)
1809{
1810 cardinal_adjc_iterate(&(wld.map), ptile, tile1) {
1811 bool ocean_near = FALSE;
1812
1813 cardinal_adjc_iterate(&(wld.map), tile1, tile2) {
1814 if (is_ocean_tile(tile2))
1815 ocean_near = TRUE;
1816 } cardinal_adjc_iterate_end;
1817
1818 if (!ocean_near) {
1819 /* If ruleset has several river types defined, this
1820 * may cause same tile to contain more than one river. */
1821 extra_type_by_cause_iterate(EC_ROAD, priver) {
1822 if (tile_has_extra(tile1, priver)
1823 && road_has_flag(extra_road_get(priver), RF_RIVER)) {
1824 tile_add_extra(ptile, priver);
1825 }
1826 } extra_type_by_cause_iterate_end;
1827 }
1828 } cardinal_adjc_iterate_end;
1829}
1830
1831/**********************************************************************/
1834 static void terrain_change_bounce_single_unit(struct unit *punit,
1835 struct tile *from)
1836{
1837 bool unit_alive = TRUE;
1838 struct player *owner = unit_owner(punit);
1839
1840 /* Look for a nearby safe tile */
1841 adjc_iterate(&(wld.map), from, ptile2) {
1842 if (can_unit_exist_at_tile(&(wld.map), punit, ptile2)
1843 && !is_non_allied_unit_tile(ptile2, owner,
1844 unit_has_type_flag(punit, UTYF_FLAGLESS))
1845 && !is_non_allied_city_tile(ptile2, owner)) {
1846 log_verbose("Moved %s %s due to changing terrain at (%d,%d).",
1847 nation_rule_name(nation_of_unit(punit)),
1848 unit_rule_name(punit), TILE_XY(unit_tile(punit)));
1849 notify_player(owner, unit_tile(punit),
1850 E_UNIT_RELOCATED, ftc_server,
1851 _("Moved your %s due to changing terrain."),
1852 unit_link(punit));
1853
1854 /* TODO: should a unit be able to bounce to a transport like is
1855 * done below? What if the unit can't legally enter the transport,
1856 * say because the transport is Unreachable and the unit doesn't
1857 * have it in its embarks field or because "Transport Embark"
1858 * isn't enabled? Kept like it was to preserve the old rules for
1859 * now. -- Sveinung */
1860 unit_alive = unit_move(punit, ptile2, 0,
1861 NULL, TRUE, FALSE, FALSE, FALSE, FALSE);
1862 if (unit_alive && punit->activity == ACTIVITY_SENTRY) {
1863 unit_activity_handling(punit, ACTIVITY_IDLE, ACTION_NONE);
1864 }
1865 break;
1866 }
1867 } adjc_iterate_end;
1868
1869 if (unit_alive && unit_tile(punit) == from) {
1870 /* If we get here we could not move punit. */
1871
1872 /* Try to bounce transported units. */
1873 if (0 < get_transporter_occupancy(punit)) {
1874 struct unit_list *pcargo_units;
1875
1876 pcargo_units = unit_transport_cargo(punit);
1877 unit_list_iterate_safe(pcargo_units, pcargo) {
1878 terrain_change_bounce_single_unit(pcargo, from);
1879 } unit_list_iterate_safe_end;
1880 }
1881 }
1882}
1883
1884/**********************************************************************/
1890 static void check_units_single_tile(struct tile *ptile)
1891{
1892 const struct civ_map *nmap = &(wld.map);
1893
1894 unit_list_iterate_safe(ptile->units, punit) {
1895 int id = punit->id;
1896
1897 /* Top-level transports only. Each handle their own cargo */
1898 if (!unit_transported(punit)
1899 && !can_unit_exist_at_tile(nmap, punit, ptile)) {
1900 terrain_change_bounce_single_unit(punit, ptile);
1901
1902 if (unit_is_alive(id) && unit_tile(punit) == ptile) {
1903 log_verbose("Disbanded %s %s due to changing terrain "
1904 "at (%d, %d).",
1905 nation_rule_name(nation_of_unit(punit)),
1906 unit_rule_name(punit), TILE_XY(ptile));
1907 notify_player(unit_owner(punit), ptile,
1908 E_UNIT_LOST_MISC, ftc_server,
1909 _("Disbanded your %s due to changing terrain."),
1910 unit_tile_link(punit));
1911 wipe_unit(punit, ULR_NONNATIVE_TERR, NULL);
1912 }
1913 }
1914 } unit_list_iterate_safe_end;
1915}
1916
1917/**********************************************************************/
1924 void bounce_units_on_terrain_change(struct tile *ptile)
1925{
1926 const struct civ_map *nmap = &(wld.map);
1927
1928 /* Check this tile for direct effect on its units */
1929 check_units_single_tile(ptile);
1930 /* We have to check adjacent tiles too, in case units in cities are now
1931 * illegal (e.g., boat in a city that has become landlocked),
1932 * and in case of CoastStrict units losing their adjacent coast. */
1933 adjc_iterate(nmap, ptile, ptile2) {
1934 check_units_single_tile(ptile2);
1935 } adjc_iterate_end;
1936}
1937
1938/**********************************************************************/
1942 bool need_to_reassign_continents(const struct terrain *oldter,
1943 const struct terrain *newter)
1944{
1945 bool old_is_ocean, new_is_ocean;
1946
1947 if (!oldter || !newter) {
1948 return FALSE;
1949 }
1950
1951 old_is_ocean = is_ocean(oldter);
1952 new_is_ocean = is_ocean(newter);
1953
1954 return (old_is_ocean && !new_is_ocean)
1955 || (!old_is_ocean && new_is_ocean);
1956}
1957
1958/**********************************************************************/
1961 void terrain_changed(struct tile *ptile)
1962{
1963 struct city *pcity = tile_city(ptile);
1964
1965 if (pcity != NULL) {
1966 /* Tile is city center and new terrain may support better extras. */
1967 upgrade_city_extras(pcity, NULL);
1968 }
1969
1970 bounce_units_on_terrain_change(ptile);
1971}
1972
1973/**********************************************************************/
1980 void fix_tile_on_terrain_change(struct tile *ptile,
1981 struct terrain *oldter,
1982 bool extend_rivers)
1983{
1984 if (is_ocean(oldter) && !is_ocean_tile(ptile)) {
1985 if (extend_rivers) {
1986 ocean_to_land_fix_rivers(ptile);
1987 }
1988 city_landlocked_sell_coastal_improvements(ptile);
1989 }
1990
1991 terrain_changed(ptile);
1992}
1993
1994/**********************************************************************/
2000 void check_terrain_change(struct tile *ptile, struct terrain *oldter)
2001{
2002 struct terrain *newter = tile_terrain(ptile);
2003 struct tile *claimer;
2004 bool cont_reassigned = FALSE;
2005
2006 /* Check if new terrain is a freshwater terrain next to non-freshwater.
2007 * In that case, the new terrain is *changed*. */
2008 if (is_ocean(newter) && terrain_has_flag(newter, TER_FRESHWATER)) {
2009 bool nonfresh = FALSE;
2010
2011 adjc_iterate(&(wld.map), ptile, atile) {
2012 if (is_ocean(tile_terrain(atile))
2013 && !terrain_has_flag(tile_terrain(atile), TER_FRESHWATER)) {
2014 nonfresh = TRUE;
2015 break;
2016 }
2017 } adjc_iterate_end;
2018 if (nonfresh) {
2019 /* Need to pick a new, non-freshwater ocean type for this tile.
2020 * We don't want e.g. Deep Ocean to be propagated to this tile
2021 * and then to a whole lake by the flooding below, so we pick
2022 * the shallowest non-fresh oceanic type.
2023 * Prefer terrain that matches the frozenness of the target. */
2024 newter = most_shallow_ocean(terrain_has_flag(newter, TER_FROZEN));
2025 tile_change_terrain(ptile, newter);
2026 }
2027 }
2028
2029 if (need_to_reassign_continents(oldter, newter)) {
2030 assign_continent_numbers();
2031 cont_reassigned = TRUE;
2032
2033 phase_players_iterate(pplayer) {
2034 if (is_adv_data_phase_open(pplayer)) {
2035 /* Player is using continent numbers that they would assume to remain accurate.
2036 * Force refresh:
2037 * 1) Close the phase, so that it can be opened
2038 * 2) Open the phase, recalculating
2039 */
2040 adv_data_phase_done(pplayer);
2041 adv_data_phase_init(pplayer, FALSE);
2042 }
2043 } phase_players_iterate_end;
2044 }
2045
2046 fix_tile_on_terrain_change(ptile, oldter, TRUE);
2047
2048 /* Check for saltwater filling freshwater lake */
2049 if (game.scenario.lake_flooding
2050 && is_ocean(newter) && !terrain_has_flag(newter, TER_FRESHWATER)) {
2051 adjc_iterate(&(wld.map), ptile, atile) {
2052 if (terrain_has_flag(tile_terrain(atile), TER_FRESHWATER)) {
2053 struct terrain *aold = tile_terrain(atile);
2054
2055 tile_change_terrain(atile,
2056 most_shallow_ocean(terrain_has_flag(aold,
2057 TER_FROZEN)));
2058
2059 /* Recursive, but as lakes are of limited size, this
2060 * won't recurse so much as to cause stack problems. */
2061 check_terrain_change(atile, aold);
2062 update_tile_knowledge(atile);
2063 }
2064 } adjc_iterate_end;
2065 }
2066
2067 if (cont_reassigned) {
2068 send_all_known_tiles(NULL);
2069 }
2070
2071 claimer = tile_claimer(ptile);
2072 if (claimer != NULL) {
2073 /* Make sure map_claim_border() conditions are still satisfied */
2074 if (is_ocean_tile(ptile)) {
2075 /* Only certain water tiles are claimable */
2076 if (!is_claimable_ocean(ptile, claimer, tile_owner(ptile))) {
2077 map_clear_border(ptile);
2078 }
2079 } else {
2080 /* Only land tiles on the same island as the border source
2081 * are claimable */
2082 if (tile_continent(ptile) != tile_continent(claimer)) {
2083 map_clear_border(ptile);
2084 }
2085 }
2086 }
2087
2088 sanity_check_tile(ptile);
2089}
2090
2091/**********************************************************************/
2102 static bool is_claimable_ocean(struct tile *ptile, struct tile *source,
2103 struct player *pplayer)
2104{
2105 Continent_id cont = tile_continent(ptile);
2106 Continent_id source_cont = tile_continent(source);
2107 int ocean_tiles;
2108 bool other_continent;
2109
2110 if (get_ocean_size(-cont) <= MAXIMUM_CLAIMED_OCEAN_SIZE
2111 && get_lake_surrounders(cont) == source_cont) {
2112 return TRUE;
2113 }
2114
2115 if (ptile == source) {
2116 /* Source itself is always claimable. */
2117 return TRUE;
2118 }
2119
2120 if (num_known_tech_with_flag(pplayer, TF_CLAIM_OCEAN) > 0
2121 || (source_cont < 0 && num_known_tech_with_flag(pplayer, TF_CLAIM_OCEAN_LIMITED) > 0)) {
2122 return TRUE;
2123 }
2124
2125 ocean_tiles = 0;
2126 other_continent = FALSE;
2127 adjc_iterate(&(wld.map), ptile, adj_tile) {
2128 Continent_id adj_cont = tile_continent(adj_tile);
2129 if (adj_tile == source) {
2130 /* Water next to border source is always claimable */
2131 return TRUE;
2132 }
2133 if (adj_cont == cont) {
2134 ocean_tiles++;
2135 } else if (adj_cont != source_cont) {
2136 /* This water is adjacent to a continent different from the one
2137 * the border source is on */
2138 other_continent = TRUE;
2139 }
2140 } adjc_iterate_end;
2141 if (!other_continent && ocean_tiles <= 2) {
2142 return TRUE;
2143 } else {
2144 return FALSE;
2145 }
2146}
2147
2148/**********************************************************************/
2151 static void map_unit_homecity_enqueue(struct tile *ptile)
2152{
2153 unit_list_iterate(ptile->units, punit) {
2154 struct city *phome = game_city_by_number(punit->homecity);
2155
2156 if (NULL == phome) {
2157 continue;
2158 }
2159
2160 city_refresh_queue_add(phome);
2161 } unit_list_iterate_end;
2162}
2163
2164/**********************************************************************/
2167 static void map_claim_border_ownership(struct tile *ptile,
2168 struct player *powner,
2169 struct tile *psource)
2170{
2171 struct player *ploser = tile_owner(ptile);
2172
2173 if ((ploser != powner && ploser != NULL)
2174 && (BORDERS_SEE_INSIDE == game.info.borders
2175 || BORDERS_EXPAND == game.info.borders
2176 || ploser->server.border_vision)) {
2177 const v_radius_t radius_sq = V_RADIUS(-1, 0, 0);
2178
2179 shared_vision_change_seen(ploser, ptile, radius_sq, FALSE);
2180 }
2181
2182 if (powner != NULL
2183 && (BORDERS_SEE_INSIDE == game.info.borders
2184 || BORDERS_EXPAND == game.info.borders
2185 || powner->server.border_vision)) {
2186 const v_radius_t radius_sq = V_RADIUS(1, 0, 0);
2187
2188 shared_vision_change_seen(powner, ptile, radius_sq, TRUE);
2189 }
2190
2191 tile_set_owner(ptile, powner, psource);
2192
2193 /* Needed only when foggedborders enabled, but we do it unconditionally
2194 * in case foggedborders ever gets enabled later. Better to have correct
2195 * information in player map just in case. */
2196 update_tile_knowledge(ptile);
2197
2198 if (ploser != powner) {
2199 if (S_S_RUNNING == server_state() && game.info.happyborders != HB_DISABLED) {
2200 map_unit_homecity_enqueue(ptile);
2201 }
2202
2203 if (!city_map_update_tile_frozen(ptile)) {
2204 send_tile_info(NULL, ptile, FALSE);
2205 }
2206 }
2207}
2208
2209/**********************************************************************/
2212 void map_claim_ownership(struct tile *ptile, struct player *powner,
2213 struct tile *psource, bool claim_bases)
2214{
2215 map_claim_border_ownership(ptile, powner, psource);
2216
2217 if (claim_bases) {
2218 tile_claim_bases(ptile, powner);
2219 }
2220}
2221
2222/**********************************************************************/
2225 void tile_claim_bases(struct tile *ptile, struct player *powner)
2226{
2227 struct player *base_loser = extra_owner(ptile);
2228
2229 /* This MUST be before potentially recursive call to map_claim_base(),
2230 * so that the recursive call will get new owner == base_loser and
2231 * abort recursion. */
2232 ptile->extras_owner = powner;
2233
2234 extra_type_by_cause_iterate(EC_BASE, pextra) {
2235 map_claim_base(ptile, pextra, powner, base_loser);
2236 } extra_type_by_cause_iterate_end;
2237}
2238
2239/**********************************************************************/
2242 void map_clear_border(struct tile *ptile)
2243{
2244 int radius_sq = tile_border_source_radius_sq(ptile);
2245
2246 circle_dxyr_iterate(&(wld.map), ptile, radius_sq, dtile, dx, dy, dr) {
2247 struct tile *claimer = tile_claimer(dtile);
2248
2249 if (claimer == ptile) {
2250 map_claim_ownership(dtile, NULL, NULL, FALSE);
2251 }
2252 } circle_dxyr_iterate_end;
2253}
2254
2255/**********************************************************************/
2259 void map_update_border(struct tile *ptile, struct player *owner,
2260 int old_radius_sq, int new_radius_sq)
2261{
2262 if (old_radius_sq == new_radius_sq) {
2263 /* No change */
2264 return;
2265 }
2266
2267 if (BORDERS_DISABLED == game.info.borders) {
2268 return;
2269 }
2270
2271 if (old_radius_sq < new_radius_sq) {
2272 map_claim_border(ptile, owner, new_radius_sq);
2273 } else {
2274 circle_dxyr_iterate(&(wld.map), ptile, old_radius_sq, dtile, dx, dy, dr) {
2275 if (dr > new_radius_sq) {
2276 struct tile *claimer = tile_claimer(dtile);
2277
2278 if (claimer == ptile) {
2279 map_claim_ownership(dtile, NULL, NULL, FALSE);
2280 }
2281 }
2282 } circle_dxyr_iterate_end;
2283 }
2284}
2285
2286/**********************************************************************/
2291 void map_claim_border(struct tile *ptile, struct player *owner,
2292 int radius_sq)
2293{
2294 if (BORDERS_DISABLED == game.info.borders) {
2295 return;
2296 }
2297
2298 if (owner == NULL) {
2299 /* Clear the border instead of claiming. Code below this block
2300 * cannot handle NULL owner. */
2301 map_clear_border(ptile);
2302
2303 return;
2304 }
2305
2306 if (radius_sq < 0) {
2307 radius_sq = tile_border_source_radius_sq(ptile);
2308 }
2309
2310 circle_dxyr_iterate(&(wld.map), ptile, radius_sq, dtile, dx, dy, dr) {
2311 struct tile *dclaimer = tile_claimer(dtile);
2312
2313 if (dclaimer == ptile) {
2314 /* Already claimed by the ptile */
2315 continue;
2316 }
2317
2318 if (dr != 0 && is_border_source(dtile)) {
2319 /* Do not claim border sources other than self */
2320 /* Note that this is extremely important at the moment for
2321 * base claiming to work correctly in case there's two
2322 * fortresses near each other. There could be infinite
2323 * recursion in them claiming each other. */
2324 continue;
2325 }
2326
2327 if (!map_is_known(dtile, owner) && game.info.borders < BORDERS_EXPAND) {
2328 continue;
2329 }
2330
2331 /* Always claim source itself (distance, dr, to it 0) */
2332 if (dr != 0 && NULL != dclaimer && dclaimer != ptile) {
2333 struct city *ccity = tile_city(dclaimer);
2334 int strength_old, strength_new;
2335
2336 if (ccity != NULL) {
2337 /* Previously claimed by city */
2338 int city_x, city_y;
2339
2340 map_distance_vector(&city_x, &city_y, ccity->tile, dtile);
2341
2342 if (map_vector_to_sq_distance(city_x, city_y)
2343 <= city_map_radius_sq_get(ccity)
2344 + game.info.border_city_permanent_radius_sq) {
2345 /* Tile is within region permanently claimed by city */
2346 continue;
2347 }
2348 }
2349
2350 strength_old = tile_border_strength(dtile, dclaimer);
2351 strength_new = tile_border_strength(dtile, ptile);
2352
2353 if (strength_new <= strength_old) {
2354 /* Stronger shall prevail,
2355 * in case of equal strength older shall prevail */
2356 continue;
2357 }
2358 }
2359
2360 if (is_ocean_tile(dtile)) {
2361 /* Only certain water tiles are claimable */
2362 if (is_claimable_ocean(dtile, ptile, owner)) {
2363 map_claim_ownership(dtile, owner, ptile, dr == 0);
2364 }
2365 } else {
2366 /* Only land tiles on the same island as the border source
2367 * are claimable */
2368 if (tile_continent(dtile) == tile_continent(ptile)) {
2369 map_claim_ownership(dtile, owner, ptile, dr == 0);
2370 }
2371 }
2372 } circle_dxyr_iterate_end;
2373}
2374
2375/**********************************************************************/
2378 void map_calculate_borders(void)
2379{
2380 if (BORDERS_DISABLED == game.info.borders) {
2381 return;
2382 }
2383
2384 if (wld.map.tiles == NULL) {
2385 /* Map not yet initialized */
2386 return;
2387 }
2388
2389 log_verbose("map_calculate_borders()");
2390
2391 whole_map_iterate(&(wld.map), ptile) {
2392 if (is_border_source(ptile)) {
2393 map_claim_border(ptile, ptile->owner, -1);
2394 }
2395 } whole_map_iterate_end;
2396
2397 log_verbose("map_calculate_borders() workers");
2398 city_thaw_workers_queue();
2399 city_refresh_queue_processing();
2400}
2401
2402/**********************************************************************/
2405 void map_claim_base(struct tile *ptile, struct extra_type *pextra,
2406 struct player *powner, struct player *ploser)
2407{
2408 struct base_type *pbase;
2409 bv_player *could_see_unit = NULL;
2410 int units_num = 0;
2411 int ul_size;
2412
2413 if (!tile_has_extra(ptile, pextra)) {
2414 return;
2415 }
2416
2417 if (pextra->eus != EUS_NORMAL) {
2418 ul_size = unit_list_size(ptile->units);
2419 } else {
2420 ul_size = 0;
2421 }
2422
2423 int stored_units[ul_size + 1];
2424
2425 if (ul_size > 0) {
2426 int i;
2427
2428 could_see_unit = fc_malloc(sizeof(*could_see_unit) * ul_size);
2429
2430 unit_list_iterate(ptile->units, aunit) {
2431 stored_units[units_num++] = aunit->id;
2432 } unit_list_iterate_end;
2433
2434 fc_assert(units_num == ul_size);
2435
2436 for (i = 0; i < units_num; i++) {
2437 struct unit *aunit = game_unit_by_number(stored_units[i]);
2438
2439 BV_CLR_ALL(could_see_unit[i]);
2440 players_iterate(aplayer) {
2441 if (can_player_see_unit(aplayer, aunit)) {
2442 BV_SET(could_see_unit[i], player_index(aplayer));
2443 }
2444 } players_iterate_end;
2445 }
2446 }
2447
2448 pbase = extra_base_get(pextra);
2449
2450 fc_assert_ret(pbase != NULL);
2451
2452 /* Transfer base provided vision to new owner */
2453 if (powner != NULL) {
2454 const v_radius_t old_radius_sq = V_RADIUS(-1, -1, -1);
2455 const v_radius_t new_radius_sq = V_RADIUS(pbase->vision_main_sq,
2456 pbase->vision_invis_sq,
2457 pbase->vision_subs_sq);
2458
2459 map_vision_update(powner, ptile, old_radius_sq, new_radius_sq,
2460 game.server.vision_reveal_tiles);
2461 }
2462
2463 if (ploser != NULL) {
2464 const v_radius_t old_radius_sq = V_RADIUS(pbase->vision_main_sq,
2465 pbase->vision_invis_sq,
2466 pbase->vision_subs_sq);
2467 const v_radius_t new_radius_sq = V_RADIUS(-1, -1, -1);
2468
2469 map_vision_update(ploser, ptile, old_radius_sq, new_radius_sq,
2470 game.server.vision_reveal_tiles);
2471 }
2472
2473 if (BORDERS_DISABLED != game.info.borders
2474 && territory_claiming_base(pbase) && powner != ploser) {
2475 /* Clear borders from old owner. New owner may not know all those
2476 * tiles and thus does not claim them when borders mode is less
2477 * than EXPAND. */
2478 if (ploser != NULL) {
2479 /* Set this particular tile owner by NULL so in recursion
2480 * both loser and owner will be NULL. */
2481 map_claim_border_ownership(ptile, NULL, ptile);
2482 map_clear_border(ptile);
2483 }
2484
2485 /* We here first claim this tile ownership -> now on extra_owner()
2486 * will return new owner. Then we claim border, which will recursively
2487 * lead to this tile and base being claimed. But at that point
2488 * ploser == powner and above check will abort the recursion. */
2489 if (powner != NULL) {
2490 map_claim_border_ownership(ptile, powner, ptile);
2491 map_claim_border(ptile, powner, -1);
2492 }
2493 city_thaw_workers_queue();
2494 city_refresh_queue_processing();
2495 }
2496
2497 if (units_num > 0) {
2498 int i;
2499
2500 for (i = 0; i < units_num; i++) {
2501 struct unit *aunit = game_unit_by_number(stored_units[i]);
2502
2503 players_iterate(aplayer) {
2504 if (can_player_see_unit(aplayer, aunit)) {
2505 if (!BV_ISSET(could_see_unit[i], player_index(aplayer))) {
2506 send_unit_info(aplayer->connections, aunit);
2507 }
2508 } else {
2509 if (BV_ISSET(could_see_unit[i], player_index(aplayer))) {
2510 unit_goes_out_of_sight(aplayer, aunit);
2511 }
2512 }
2513 } players_iterate_end;
2514 }
2515
2516 free(could_see_unit);
2517 }
2518}
2519
2520/**********************************************************************/
2526 void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
2527{
2528 map_vision_update(vision->player, vision->tile, vision->radius_sq,
2529 radius_sq, vision->can_reveal_tiles);
2530 memcpy(vision->radius_sq, radius_sq, sizeof(v_radius_t));
2531}
2532
2533/**********************************************************************/
2538 void vision_clear_sight(struct vision *vision)
2539{
2540 const v_radius_t vision_radius_sq = V_RADIUS(-1, -1, -1);
2541
2542 vision_change_sight(vision, vision_radius_sq);
2543
2544 /* Owner of some city might have lost vision of a tile previously worked */
2545 players_iterate(pplayer) {
2546 city_list_iterate(pplayer->cities, pcity) {
2547 /* We are not interested about CNA_BROADCAST_PENDING, as the vision loss has
2548 * not set it, and whatever set it should take care of it. */
2549 if (pcity->server.needs_arrange == CNA_NORMAL) {
2550 city_refresh(pcity);
2551 auto_arrange_workers(pcity);
2552 pcity->server.needs_arrange = CNA_NOT;
2553 }
2554 } city_list_iterate_end;
2555 } players_iterate_end;
2556}
2557
2558/**********************************************************************/
2561 void create_extra(struct tile *ptile, struct extra_type *pextra,
2562 struct player *pplayer)
2563{
2564 bool extras_removed = FALSE;
2565
2566 extra_type_iterate(old_extra) {
2567 if (tile_has_extra(ptile, old_extra)
2568 && !can_extras_coexist(old_extra, pextra)) {
2569 destroy_extra(ptile, old_extra);
2570 extras_removed = TRUE;
2571 }
2572 } extra_type_iterate_end;
2573
2574 if (pextra->eus != EUS_NORMAL) {
2575 unit_list_iterate(ptile->units, aunit) {
2576 if (is_native_extra_to_utype(pextra, unit_type_get(aunit))) {
2577 players_iterate(aplayer) {
2578 if (!pplayers_allied(pplayer, aplayer)
2579 && can_player_see_unit(aplayer, aunit)) {
2580 unit_goes_out_of_sight(aplayer, aunit);
2581 }
2582 } players_iterate_end;
2583 }
2584 } unit_list_iterate_end;
2585 }
2586
2587 tile_add_extra(ptile, pextra);
2588
2589 /* Watchtower might become effective. */
2590 unit_list_refresh_vision(ptile->units);
2591
2592 if (pextra->data.base != NULL) {
2593 /* Claim bases on tile */
2594 if (pplayer) {
2595 struct player *old_owner = extra_owner(ptile);
2596
2597 /* Created base from NULL -> pplayer */
2598 map_claim_base(ptile, pextra, pplayer, NULL);
2599
2600 if (old_owner != pplayer) {
2601 /* Existing bases from old_owner -> pplayer */
2602 extra_type_by_cause_iterate(EC_BASE, oldbase) {
2603 if (oldbase != pextra) {
2604 map_claim_base(ptile, oldbase, pplayer, old_owner);
2605 }
2606 } extra_type_by_cause_iterate_end;
2607
2608 ptile->extras_owner = pplayer;
2609 }
2610 } else {
2611 /* Player who already owns bases on tile claims new base */
2612 map_claim_base(ptile, pextra, extra_owner(ptile), NULL);
2613 }
2614 }
2615
2616 if (extras_removed) {
2617 /* Maybe conflicting extra that was removed was the only thing
2618 * making tile native to some unit. */
2619 bounce_units_on_terrain_change(ptile);
2620 }
2621}
2622
2623/**********************************************************************/
2626 void destroy_extra(struct tile *ptile, struct extra_type *pextra)
2627{
2628 bv_player base_seen;
2629 bool real = tile_map_check(&(wld.map), ptile);
2630
2631 /* Remember what players were able to see the base. */
2632 if (real) {
2633 BV_CLR_ALL(base_seen);
2634 players_iterate(pplayer) {
2635 if (map_is_known_and_seen(ptile, pplayer, V_MAIN)) {
2636 BV_SET(base_seen, player_index(pplayer));
2637 }
2638 } players_iterate_end;
2639 }
2640
2641 if (real && is_extra_caused_by(pextra, EC_BASE)) {
2642 struct base_type *pbase = extra_base_get(pextra);
2643 struct player *owner = extra_owner(ptile);
2644
2645 if (territory_claiming_base(pbase)) {
2646 map_clear_border(ptile);
2647 }
2648
2649 if (NULL != owner
2650 && (0 <= pbase->vision_main_sq || 0 <= pbase->vision_invis_sq)) {
2651 /* Base provides vision, but no borders. */
2652 const v_radius_t old_radius_sq =
2653 V_RADIUS(0 <= pbase->vision_main_sq ? pbase->vision_main_sq : -1,
2654 0 <= pbase->vision_invis_sq ? pbase->vision_invis_sq : -1,
2655 0 <= pbase->vision_subs_sq ? pbase->vision_subs_sq : -1);
2656 const v_radius_t new_radius_sq = V_RADIUS(-1, -1, -1);
2657
2658 map_vision_update(owner, ptile, old_radius_sq, new_radius_sq,
2659 game.server.vision_reveal_tiles);
2660 }
2661 }
2662
2663 tile_remove_extra(ptile, pextra);
2664
2665 if (real) {
2666 /* Remove base from vision of players which were able to see the base. */
2667 players_iterate(pplayer) {
2668 if (BV_ISSET(base_seen, player_index(pplayer))
2669 && update_player_tile_knowledge(pplayer, ptile)) {
2670 send_tile_info(pplayer->connections, ptile, FALSE);
2671 }
2672 } players_iterate_end;
2673
2674 if (pextra->eus != EUS_NORMAL) {
2675 struct player *eowner = extra_owner(ptile);
2676
2677 unit_list_iterate(ptile->units, aunit) {
2678 if (is_native_extra_to_utype(pextra, unit_type_get(aunit))) {
2679 players_iterate(aplayer) {
2680 if (can_player_see_unit(aplayer, aunit)
2681 && !pplayers_allied(aplayer, eowner)) {
2682 send_unit_info(aplayer->connections, aunit);
2683 }
2684 } players_iterate_end;
2685 }
2686 } unit_list_iterate_end;
2687 }
2688 }
2689}
2690
2691/**********************************************************************/
2701 bool give_distorted_map(struct player *pfrom, struct player *pto,
2702 int prob, bool reveal_cities)
2703{
2704 bool updt = FALSE;
2705
2706 buffer_shared_vision(pto);
2707
2708 whole_map_iterate(&(wld.map), ptile) {
2709 if (fc_rand(100) < prob) {
2710 updt |= give_tile_info_from_player_to_player(pfrom, pto, ptile);
2711 } else if (reveal_cities && NULL != tile_city(ptile)) {
2712 updt|= give_tile_info_from_player_to_player(pfrom, pto, ptile);
2713 }
2714 } whole_map_iterate_end;
2715
2716 unbuffer_shared_vision(pto);
2717
2718 return updt;
2719}
2720
2721/**********************************************************************/
2729 void tile_change_side_effects(struct tile *ptile, bool refresh_city)
2730{
2731 struct city *pcity = ptile->worked;
2732
2733 /* Check the unit activities. */
2734 unit_activities_cancel_all_illegal_area(ptile);
2735
2736 if (pcity != NULL && !is_free_worked(pcity, ptile)
2737 && get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) {
2738 city_map_update_empty(pcity, ptile);
2739 pcity->specialists[DEFAULT_SPECIALIST]++;
2740
2741 if (refresh_city) {
2742 auto_arrange_workers(pcity);
2743 send_city_info(NULL, pcity);
2744 }
2745 }
2746}
ACTION_NONE
#define ACTION_NONE
Definition actions.h:55
is_adv_data_phase_open
bool is_adv_data_phase_open(struct player *pplayer)
Definition advdata.c:242
adv_data_phase_init
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:262
adv_data_phase_done
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:564
advdata.h
ai.h
CALL_FUNC_EACH_AI
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
territory_claiming_base
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:162
base.h
bv_match_dbv
bool bv_match_dbv(const struct dbv *match, const unsigned char *src)
Definition bitvector.c:205
dbv_init
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
dbv_set
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:144
dbv_isset
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
dbv_copy
void dbv_copy(struct dbv *dest, const struct dbv *src)
Definition bitvector.c:222
dbv_free
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
dbv_clr
void dbv_clr(struct dbv *pdbv, int bit)
Definition bitvector.c:167
dbv_to_bv
void dbv_to_bv(unsigned char *dest, const struct dbv *src)
Definition bitvector.c:235
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
tile_border_source_radius_sq
int tile_border_source_radius_sq(struct tile *ptile)
Definition borders.c:33
is_border_source
bool is_border_source(struct tile *ptile)
Definition borders.c:116
tile_border_strength
int tile_border_strength(struct tile *ptile, struct tile *source)
Definition borders.c:101
borders.h
is_free_worked
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3597
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
is_non_allied_city_tile
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:763
CNA_NOT
@ CNA_NOT
Definition city.h:306
CNA_NORMAL
@ CNA_NORMAL
Definition city.h:307
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_tile
#define city_tile(_pcity_)
Definition city.h:564
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
city_tile_iterate
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
city_tile_iterate_end
#define city_tile_iterate_end
Definition city.h:238
city_map_update_empty
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3252
send_city_info
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2351
update_dumb_city
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2751
sync_cities
void sync_cities(void)
Definition citytools.c:3326
city_map_update_tile_frozen
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3309
remove_dumb_city
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2843
city_landlocked_sell_coastal_improvements
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
Definition citytools.c:3379
send_city_info_at_tile
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2403
city_thaw_workers_queue
void city_thaw_workers_queue(void)
Definition citytools.c:192
reality_check_city
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2822
citytools.h
auto_arrange_workers
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:365
city_refresh_queue_add
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:196
city_refresh
bool city_refresh(struct city *pcity)
Definition cityturn.c:158
city_refresh_queue_processing
void city_refresh_queue_processing(void)
Definition cityturn.c:212
cityturn.h
incite_cost
char * incite_cost
Definition comments.c:74
conn_list_do_unbuffer
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:366
conn_list_compression_thaw
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:732
conn_list_do_buffer
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:356
conn_list_compression_freeze
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:720
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:110
punit
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
get_city_tile_output_bonus
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:912
events.h
extra_owner
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1128
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:875
player_can_build_extra
bool player_can_build_extra(const struct extra_type *pextra, const struct player *pplayer, const struct tile *ptile)
Definition extras.c:468
extras
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
is_native_extra_to_utype
bool is_native_extra_to_utype(const struct extra_type *pextra, const struct unit_type *punittype)
Definition extras.c:866
can_extras_coexist
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:1017
extra_count
int extra_count(void)
Definition extras.c:153
player_knows_extra_exist
bool player_knows_extra_exist(const struct player *pplayer, const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1167
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_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:321
is_extra_caused_by
#define is_extra_caused_by(e, c)
Definition extras.h:203
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
HB_DISABLED
@ HB_DISABLED
Definition fc_types.h:1271
MAX_EXTRA_TYPES
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
Continent_id
signed short Continent_id
Definition fc_types.h:376
BORDERS_DISABLED
@ BORDERS_DISABLED
Definition fc_types.h:1017
BORDERS_SEE_INSIDE
@ BORDERS_SEE_INSIDE
Definition fc_types.h:1019
BORDERS_EXPAND
@ BORDERS_EXPAND
Definition fc_types.h:1020
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:92
fcintl.h
_
#define _(String)
Definition fcintl.h:67
ftc_server
const struct ft_color ftc_server
Definition featured_text.c:77
unit_link
const char * unit_link(const struct unit *punit)
Definition featured_text.c:1126
unit_tile_link
const char * unit_tile_link(const struct unit *punit)
Definition featured_text.c:1143
game
struct civ_game game
Definition game.c:61
wld
struct world wld
Definition game.c:62
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:115
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:106
game.h
owner
struct city * owner
Definition citydlg.c:226
source
static GtkWidget * source
Definition gotodlg.c:58
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
log_verbose
#define log_verbose(message,...)
Definition log.h:109
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_debug
#define log_debug(message,...)
Definition log.h:115
log_error
#define log_error(message,...)
Definition log.h:103
map_num_tiles
int map_num_tiles(void)
Definition map.c:1026
rand_map_pos
struct tile * rand_map_pos(const struct civ_map *nmap)
Definition map.c:1102
map_vector_to_sq_distance
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:620
terrain_surroundings_allow_change
bool terrain_surroundings_allow_change(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain)
Definition map.c:748
map_distance_vector
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1087
map.h
adjc_iterate_end
#define adjc_iterate_end
Definition map.h:419
circle_dxyr_iterate
#define circle_dxyr_iterate(nmap, center_tile, sq_radius, _tile, dx, dy, dr)
Definition map.h:395
cardinal_adjc_iterate_end
#define cardinal_adjc_iterate_end
Definition map.h:445
adjc_iterate
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:414
circle_dxyr_iterate_end
#define circle_dxyr_iterate_end
Definition map.h:406
cardinal_adjc_iterate
#define cardinal_adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:441
circle_iterate
#define circle_iterate(nmap, center_tile, sq_radius, tile_itr)
Definition map.h:387
whole_map_iterate
#define whole_map_iterate(_map, _tile)
Definition map.h:531
MAP_TILE_OWNER_NULL
#define MAP_TILE_OWNER_NULL
Definition map.h:588
whole_map_iterate_end
#define whole_map_iterate_end
Definition map.h:540
circle_iterate_end
#define circle_iterate_end
Definition map.h:390
assign_continent_numbers
void assign_continent_numbers(void)
Definition mapgen_utils.c:452
get_ocean_size
int get_ocean_size(Continent_id id)
Definition mapgen_utils.c:438
most_shallow_ocean
struct terrain * most_shallow_ocean(bool frozen)
Definition mapgen_utils.c:500
get_lake_surrounders
int get_lake_surrounders(Continent_id cont)
Definition mapgen_utils.c:420
mapgen_utils.h
player_map_init
void player_map_init(struct player *pplayer)
Definition maphand.c:1228
terrain_change_bounce_single_unit
static void terrain_change_bounce_single_unit(struct unit *punit, struct tile *from)
Definition maphand.c:1834
update_player_tile_last_seen
void update_player_tile_last_seen(struct player *pplayer, struct tile *ptile)
Definition maphand.c:1474
shared_vision_change_seen
static void shared_vision_change_seen(struct player *pplayer, struct tile *ptile, const v_radius_t change, bool can_reveal_tiles)
Definition maphand.c:674
vision_clear_sight
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2538
map_claim_base
void map_claim_base(struct tile *ptile, struct extra_type *pextra, struct player *powner, struct player *ploser)
Definition maphand.c:2405
map_set_border_vision
void map_set_border_vision(struct player *pplayer, const bool is_enabled)
Definition maphand.c:747
map_claim_ownership
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2212
player_tile_own_seen
static int player_tile_own_seen(const struct player_tile *plrtile, enum vision_layer vlayer)
Definition maphand.c:1143
map_is_known
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:901
map_is_also_seen
static bool map_is_also_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:916
send_map_info
void send_map_info(struct conn_list *dest)
Definition maphand.c:655
really_give_tile_info_from_player_to_player
static bool really_give_tile_info_from_player_to_player(struct player *pfrom, struct player *pdest, struct tile *ptile)
Definition maphand.c:1492
send_tile_suppression
bool send_tile_suppression(bool now)
Definition maphand.c:475
destroy_extra
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2626
check_units_single_tile
static void check_units_single_tile(struct tile *ptile)
Definition maphand.c:1890
really_give_map_from_player_to_player
static void really_give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:1565
disable_fog_of_war
void disable_fog_of_war(void)
Definition maphand.c:1792
really_gives_vision
bool really_gives_vision(struct player *me, struct player *them)
Definition maphand.c:345
unit_is_on_layer
static bool unit_is_on_layer(const struct unit *punit, enum vision_layer vlayer)
Definition maphand.c:646
map_know_and_see_all
void map_know_and_see_all(struct player *pplayer)
Definition maphand.c:1203
map_change_own_seen
static void map_change_own_seen(struct player *pplayer, struct tile *ptile, const v_radius_t change)
Definition maphand.c:1152
show_map_to_all
void show_map_to_all(void)
Definition maphand.c:1217
send_tile_info
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:491
update_player_tile_knowledge
bool update_player_tile_knowledge(struct player *pplayer, struct tile *ptile)
Definition maphand.c:1405
map_get_seen
static int map_get_seen(const struct player *pplayer, const struct tile *ptile, enum vision_layer vlayer)
Definition maphand.c:941
ocean_to_land_fix_rivers
static void ocean_to_land_fix_rivers(struct tile *ptile)
Definition maphand.c:1808
give_map_from_player_to_player
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:384
send_all_known_tiles
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:444
bounce_units_on_terrain_change
void bounce_units_on_terrain_change(struct tile *ptile)
Definition maphand.c:1924
give_seamap_from_player_to_player
void give_seamap_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:400
remove_shared_vision
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1700
need_to_reassign_continents
bool need_to_reassign_continents(const struct terrain *oldter, const struct terrain *newter)
Definition maphand.c:1942
is_claimable_ocean
static bool is_claimable_ocean(struct tile *ptile, struct tile *source, struct player *pplayer)
Definition maphand.c:2102
map_get_player_city
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1374
is_terrain_ecologically_wet
static bool is_terrain_ecologically_wet(struct tile *ptile)
Definition maphand.c:96
tile_claim_bases
void tile_claim_bases(struct tile *ptile, struct player *powner)
Definition maphand.c:2225
disable_fog_of_war_player
void disable_fog_of_war_player(struct player *pplayer)
Definition maphand.c:1778
climate_change
void climate_change(bool warming, int effect)
Definition maphand.c:133
enable_fog_of_war
void enable_fog_of_war(void)
Definition maphand.c:1768
send_tile_suppressed
static bool send_tile_suppressed
Definition maphand.c:65
create_vision_dependencies
static void create_vision_dependencies(void)
Definition maphand.c:1605
upgrade_all_city_extras
void upgrade_all_city_extras(struct player *pplayer, bool discovery)
Definition maphand.c:276
create_extra
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2561
map_update_border
void map_update_border(struct tile *ptile, struct player *owner, int old_radius_sq, int new_radius_sq)
Definition maphand.c:2259
map_set_known
void map_set_known(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1185
map_show_all
void map_show_all(struct player *pplayer)
Definition maphand.c:886
map_unit_homecity_enqueue
static void map_unit_homecity_enqueue(struct tile *ptile)
Definition maphand.c:2151
map_change_seen
static void map_change_seen(struct player *pplayer, struct tile *ptile, const v_radius_t change, bool can_reveal_tiles)
Definition maphand.c:954
map_show_tile
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:775
give_citymap_from_player_to_player
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:418
nuclear_winter
void nuclear_winter(int effect)
Definition maphand.c:119
tile_change_side_effects
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2729
player_tile_init
static void player_tile_init(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1335
terrain_changed
void terrain_changed(struct tile *ptile)
Definition maphand.c:1961
player_map_free
void player_map_free(struct player *pplayer)
Definition maphand.c:1244
unbuffer_shared_vision
static void unbuffer_shared_vision(struct player *pplayer)
Definition maphand.c:368
map_claim_border_ownership
static void map_claim_border_ownership(struct tile *ptile, struct player *powner, struct tile *psource)
Definition maphand.c:2167
map_is_known_and_seen
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:927
change_playertile_site
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1166
map_calculate_borders
void map_calculate_borders(void)
Definition maphand.c:2378
fix_tile_on_terrain_change
void fix_tile_on_terrain_change(struct tile *ptile, struct terrain *oldter, bool extend_rivers)
Definition maphand.c:1980
enable_fog_of_war_player
void enable_fog_of_war_player(struct player *pplayer)
Definition maphand.c:1754
map_show_circle
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
Definition maphand.c:871
map_vision_update
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:692
map_claim_border
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2291
update_tile_knowledge
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1446
remove_player_from_maps
void remove_player_from_maps(struct player *pplayer)
Definition maphand.c:1265
give_shared_vision
void give_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1639
check_terrain_change
void check_terrain_change(struct tile *ptile, struct terrain *oldter)
Definition maphand.c:2000
give_distorted_map
bool give_distorted_map(struct player *pfrom, struct player *pto, int prob, bool reveal_cities)
Definition maphand.c:2701
map_hide_tile
void map_hide_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:827
buffer_shared_vision
static void buffer_shared_vision(struct player *pplayer)
Definition maphand.c:353
give_tile_info_from_player_to_player
static bool give_tile_info_from_player_to_player(struct player *pfrom, struct player *pdest, struct tile *ptile)
Definition maphand.c:1585
global_warming
void global_warming(int effect)
Definition maphand.c:106
upgrade_city_extras
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:241
map_clear_border
void map_clear_border(struct tile *ptile)
Definition maphand.c:2242
map_clear_known
void map_clear_known(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1193
player_tile_free
static void player_tile_free(struct tile *ptile, struct player *pplayer)
Definition maphand.c:1360
MAXIMUM_CLAIMED_OCEAN_SIZE
#define MAXIMUM_CLAIMED_OCEAN_SIZE
Definition maphand.c:62
map_get_player_tile
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1389
vision_change_sight
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2526
maphand.h
map_get_player_site
#define map_get_player_site(_ptile_, _pplayer_)
Definition maphand.h:93
map_get_playermap_site
#define map_get_playermap_site(_plrtile_)
Definition maphand.h:92
mem.h
fc_realloc
#define fc_realloc(ptr, sz)
Definition mem.h:36
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
can_unit_exist_at_tile
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:318
movement.h
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
nation_of_unit
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
nation.h
notify_player
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:292
notify.h
packets.h
lsend_packet_map_info
void lsend_packet_map_info(struct conn_list *dest, const struct packet_map_info *packet)
Definition packets_gen.c:12289
send_packet_tile_info
int send_packet_tile_info(struct connection *pc, const struct packet_tile_info *packet)
Definition packets_gen.c:3812
num_known_tech_with_flag
int num_known_tech_with_flag(const struct player *pplayer, enum tech_flag_id flag)
Definition player.c:1273
player_slot_count
int player_slot_count(void)
Definition player.c:418
player_number
int player_number(const struct player *pplayer)
Definition player.c:837
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
can_player_see_unit
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
player_index
int player_index(const struct player *pplayer)
Definition player.c:829
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1489
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:539
players_iterate
#define players_iterate(_pplayer)
Definition player.h:534
send_player_info_c
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
plrhand.h
phase_players_iterate
#define phase_players_iterate(pplayer)
Definition plrhand.h:113
phase_players_iterate_end
#define phase_players_iterate_end
Definition plrhand.h:118
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:56
road_has_flag
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:416
count_river_near_tile
int count_river_near_tile(struct civ_map *nmap, const struct tile *ptile, const struct extra_type *priver)
Definition road.c:340
road.h
sanitycheck.h
sanity_check_tile
#define sanity_check_tile(x)
Definition sanitycheck.h:42
flush_packets
void flush_packets(void)
Definition sernet.c:376
sernet.h
specialist.h
DEFAULT_SPECIALIST
#define DEFAULT_SPECIALIST
Definition specialist.h:43
server_state
enum server_states server_state(void)
Definition srv_main.c:338
srv_main.h
base_type
Definition base.h:41
city
Definition city.h:320
city::needs_arrange
enum city_needs_arrange needs_arrange
Definition city.h:441
city::specialists
citizens specialists[SP_MAX]
Definition city.h:336
city::tile
struct tile * tile
Definition city.h:322
city::server
struct city::@17::@19 server
civ_game::last_updated_year
bool last_updated_year
Definition game.h:236
civ_game::vision_reveal_tiles
bool vision_reveal_tiles
Definition game.h:200
civ_game::fogofwar_old
bool fogofwar_old
Definition game.h:234
civ_game::est_connections
struct conn_list * est_connections
Definition game.h:97
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::scenario
struct packet_scenario_info scenario
Definition game.h:87
civ_game::foggedborders
bool foggedborders
Definition game.h:147
civ_game::server
struct civ_game::@31::@35 server
civ_map
Definition map_types.h:71
civ_map::tiles
struct tile * tiles
Definition map_types.h:84
civ_map::north_latitude
int north_latitude
Definition map_types.h:80
civ_map::south_latitude
int south_latitude
Definition map_types.h:81
civ_map::altitude_info
bool altitude_info
Definition map_types.h:74
civ_map::topology_id
int topology_id
Definition map_types.h:72
civ_map::wrap_id
int wrap_id
Definition map_types.h:73
dbv::vec
unsigned char * vec
Definition bitvector.h:34
effect
Definition effects.h:40
extra_type
Definition extras.h:88
extra_type::resource
struct resource_type * resource
Definition extras.h:156
extra_type::data
struct extra_type::@25 data
extra_type::eus
enum extra_unit_seen_type eus
Definition extras.h:128
extra_type::base
struct base_type * base
Definition extras.h:154
packet_game_info::borders
enum borders_mode borders
Definition packets_gen.h:133
packet_game_info::happyborders
enum happyborders_type happyborders
Definition packets_gen.h:181
packet_game_info::turn
int turn
Definition packets_gen.h:245
packet_game_info::year
int year
Definition packets_gen.h:247
packet_game_info::border_city_permanent_radius_sq
int border_city_permanent_radius_sq
Definition packets_gen.h:132
packet_game_info::fogofwar
bool fogofwar
Definition packets_gen.h:154
packet_map_info
Definition packets_gen.h:271
packet_map_info::xsize
int xsize
Definition packets_gen.h:272
packet_scenario_info::lake_flooding
bool lake_flooding
Definition packets_gen.h:1598
packet_tile_info
Definition packets_gen.h:101
packet_tile_info::resource
Resource_type_id resource
Definition packets_gen.h:109
packet_tile_info::extras
bv_extras extras
Definition packets_gen.h:110
packet_tile_info::place_turn
int place_turn
Definition packets_gen.h:112
packet_tile_info::placing
int placing
Definition packets_gen.h:111
packet_tile_info::owner
int owner
Definition packets_gen.h:105
packet_tile_info::known
enum known_type known
Definition packets_gen.h:104
packet_tile_info::label
char label[MAX_LEN_MAP_LABEL]
Definition packets_gen.h:115
packet_tile_info::extras_owner
int extras_owner
Definition packets_gen.h:106
packet_tile_info::tile
int tile
Definition packets_gen.h:102
packet_tile_info::continent
Continent_id continent
Definition packets_gen.h:103
packet_tile_info::terrain
Terrain_type_id terrain
Definition packets_gen.h:108
packet_tile_info::worked
int worked
Definition packets_gen.h:107
packet_tile_info::altitude
int altitude
Definition packets_gen.h:113
packet_tile_info::spec_sprite
char spec_sprite[MAX_LEN_NAME]
Definition packets_gen.h:114
player_tile
Definition maphand.h:30
player_tile::extras_owner
struct player * extras_owner
Definition maphand.h:35
player_tile::seen_count
v_radius_t seen_count
Definition maphand.h:43
player_tile::site
struct vision_site * site
Definition maphand.h:31
player_tile::terrain
struct terrain * terrain
Definition maphand.h:33
player_tile::extras
struct dbv extras
Definition maphand.h:36
player_tile::last_updated
short last_updated
Definition maphand.h:44
player_tile::owner
struct player * owner
Definition maphand.h:34
player_tile::resource
struct extra_type * resource
Definition maphand.h:32
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::tile_known
struct dbv tile_known
Definition player.h:310
player::connections
struct conn_list * connections
Definition player.h:298
player::private_map
struct player_tile * private_map
Definition player.h:324
player::border_vision
bool border_vision
Definition player.h:327
player::server
struct player::@70::@72 server
terrain
Definition terrain.h:75
terrain::cooler_wetter_result
struct terrain * cooler_wetter_result
Definition terrain.h:134
terrain::cooler_drier_result
struct terrain * cooler_drier_result
Definition terrain.h:134
terrain::warmer_wetter_result
struct terrain * warmer_wetter_result
Definition terrain.h:133
terrain::warmer_drier_result
struct terrain * warmer_drier_result
Definition terrain.h:133
tile
Definition tile.h:50
tile::spec_sprite
char * spec_sprite
Definition tile.h:67
tile::label
char * label
Definition tile.h:66
tile::altitude
int altitude
Definition tile.h:65
tile::extras
bv_extras extras
Definition tile.h:55
tile::resource
struct extra_type * resource
Definition tile.h:56
tile::units
struct unit_list * units
Definition tile.h:58
tile::extras_owner
struct player * extras_owner
Definition tile.h:63
tile::terrain
struct terrain * terrain
Definition tile.h:57
tile::infra_turns
int infra_turns
Definition tile.h:62
tile::placing
struct extra_type * placing
Definition tile.h:61
tile::worked
struct city * worked
Definition tile.h:59
tile::claimer
struct tile * claimer
Definition tile.h:64
unit_type::vlayer
enum vision_layer vlayer
Definition unittype.h:576
unit
Definition unit.h:140
unit::activity
enum unit_activity activity
Definition unit.h:159
unit::id
int id
Definition unit.h:147
unit::server
struct unit::@81::@84 server
unit::activity_target
struct extra_type * activity_target
Definition unit.h:167
unit::homecity
int homecity
Definition unit.h:148
unit::dying
bool dying
Definition unit.h:253
vision_site
Definition vision.h:109
vision_site::identity
int identity
Definition vision.h:114
vision
Definition vision.h:85
vision::tile
struct tile * tile
Definition vision.h:88
vision::can_reveal_tiles
bool can_reveal_tiles
Definition vision.h:89
vision::radius_sq
v_radius_t radius_sq
Definition vision.h:92
vision::player
struct player * player
Definition vision.h:87
world::map
struct civ_map map
Definition world_object.h:38
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
is_terrain_class_near_tile
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:612
terrain_count
Terrain_type_id terrain_count(void)
Definition terrain.c:118
terrain_number
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
T_UNKNOWN
#define T_UNKNOWN
Definition terrain.h:62
is_ocean
#define is_ocean(pterrain)
Definition terrain.h:194
is_ocean_tile
#define is_ocean_tile(ptile)
Definition terrain.h:196
T_NONE
#define T_NONE
Definition terrain.h:61
terrain_has_flag
#define terrain_has_flag(terr, flag)
Definition terrain.h:176
tile_add_extra
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:955
tile_has_river
bool tile_has_river(const struct tile *ptile)
Definition tile.c:852
tile_map_check
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1067
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_conflicting_extra
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:901
tile_set_owner
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_claimer
#define tile_claimer(_tile)
Definition tile.h:101
tile_index
#define tile_index(_pt_)
Definition tile.h:89
tile_worked
#define tile_worked(_tile)
Definition tile.h:115
tile_resource
#define tile_resource(_tile)
Definition tile.h:103
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
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:111
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:43
tile_continent
#define tile_continent(_tile)
Definition tile.h:93
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
tile_owner
#define tile_owner(_tile)
Definition tile.h:97
get_transporter_occupancy
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1821
unit_is_alive
bool unit_is_alive(int id)
Definition unit.c:2291
unit_transported
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2483
unit_transport_cargo
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Definition unit.c:2509
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:397
unit_owner
#define unit_owner(_pu)
Definition unit.h:396
is_non_allied_unit_tile
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer, bool everyone_non_allied)
Definition unit.h:433
unit_activity_handling
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6613
unithand.h
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_safe
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_list_iterate_safe_end
#define unit_list_iterate_safe_end
Definition unitlist.h:61
unit_goes_out_of_sight
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2865
send_unit_info
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2878
unit_activities_cancel
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:801
wipe_unit
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2140
unit_activities_cancel_all_illegal_area
void unit_activities_cancel_all_illegal_area(const struct tile *ptile)
Definition unittools.c:846
unit_move
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:4075
unit_list_refresh_vision
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:5018
unittools.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
vision_site_copy
struct vision_site * vision_site_copy(const struct vision_site *psite)
Definition vision.c:135
vision_site_destroy
void vision_site_destroy(struct vision_site *psite)
Definition vision.c:74
vision.h
V_RADIUS
#define V_RADIUS(main_sq, invis_sq, subs_sq)
Definition vision.h:96
vision_layer_iterate
#define vision_layer_iterate(v)
Definition vision.h:77
vision_site_owner
#define vision_site_owner(v)
Definition vision.h:128
v_radius_t
short int v_radius_t[V_COUNT]
Definition vision.h:83
vision_layer_iterate_end
#define vision_layer_iterate_end
Definition vision.h:80
MAP_NATIVE_WIDTH
#define MAP_NATIVE_WIDTH
Definition world_object.h:55
MAP_INDEX_SIZE
#define MAP_INDEX_SIZE
Definition world_object.h:52
MAP_NATIVE_HEIGHT
#define MAP_NATIVE_HEIGHT
Definition world_object.h:56