Freeciv-3.1
Loading...
Searching...
No Matches
citytools.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#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22/* utility */
23#include "bitvector.h"
24#include "fcintl.h"
25#include "log.h"
26#include "mem.h"
27#include "rand.h"
28#include "shared.h"
29#include "support.h"
30
31/* common */
32#include "ai.h"
33#include "base.h"
34#include "citizens.h"
35#include "city.h"
36#include "culture.h"
37#include "events.h"
38#include "game.h"
39#include "government.h"
40#include "improvement.h"
41#include "idex.h"
42#include "map.h"
43#include "movement.h"
44#include "player.h"
45#include "requirements.h"
46#include "research.h"
47#include "road.h"
48#include "specialist.h"
49#include "tech.h"
50#include "traderoutes.h"
51#include "unit.h"
52#include "unitlist.h"
53#include "vision.h"
54
55/* common/aicore */
56#include "cm.h"
57
58/* common/scriptcore */
59#include "luascript_types.h"
60
61/* server */
62#include "actiontools.h"
63#include "barbarian.h"
64#include "citizenshand.h"
65#include "cityturn.h"
66#include "gamehand.h" /* send_game_info() */
67#include "maphand.h"
68#include "notify.h"
69#include "plrhand.h"
70#include "sanitycheck.h"
71#include "sernet.h"
72#include "spacerace.h"
73#include "srv_main.h"
74#include "techtools.h"
75#include "unithand.h"
76#include "unittools.h"
77
78/* server/advisors */
79#include "advbuilding.h"
80#include "advgoto.h"
81#include "autosettlers.h"
82#include "infracache.h"
83
84/* server/scripting */
85#include "script_server.h"
86
87/* ai */
88#include "handicaps.h"
89
90/* ai */
91#include "handicaps.h"
92
93#include "citytools.h"
94
95
96/* Queue for pending auto_arrange_workers() */
97static struct city_list *arrange_workers_queue = NULL;
98
99/* Suppress sending cities during game_load() and end_phase() */
101
102static bool city_workers_queue_remove(struct city *pcity);
103
104static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
105 bool source_gone)
106 fc__attribute((nonnull (1, 2)));
107
108/************************************************************************/
135void city_freeze_workers(struct city *pcity)
136{
137 pcity->server.workers_frozen++;
138}
139
140/************************************************************************/
145void city_thaw_workers(struct city *pcity)
146{
147 pcity->server.workers_frozen--;
148 fc_assert(pcity->server.workers_frozen >= 0);
149 if (pcity->server.workers_frozen == 0
150 && pcity->server.needs_arrange != CNA_NOT) {
151 city_refresh(pcity); /* Citizen count sanity */
153 }
154}
155
156/************************************************************************/
160{
161 if (NULL == arrange_workers_queue) {
162 arrange_workers_queue = city_list_new();
163 } else if (city_list_find_number(arrange_workers_queue, pcity->id)) {
164 /* City might have been arranged since it was originally put to the queue.
165 * Make sure needs_arrange is set again. */
166 if (pcity->server.needs_arrange == CNA_NOT) {
168 }
169 return;
170 }
171
172 city_list_prepend(arrange_workers_queue, pcity);
173 city_freeze_workers(pcity);
174 if (pcity->server.needs_arrange == CNA_NOT) {
176 }
177}
178
179/************************************************************************/
183static bool city_workers_queue_remove(struct city *pcity)
184{
185 if (arrange_workers_queue == NULL) {
186 return FALSE;
187 }
188
189 return city_list_remove(arrange_workers_queue, pcity);
190}
191
192/************************************************************************/
197{
198 if (NULL == arrange_workers_queue) {
199 return;
200 }
201
203 city_thaw_workers(pcity);
205
206 city_list_destroy(arrange_workers_queue);
208}
209
210/************************************************************************/
218static int evaluate_city_name_priority(struct tile *ptile,
219 const struct nation_city *pncity,
220 int default_priority)
221{
222 /* Lower values mean higher priority. */
223 float priority = (float)default_priority;
224 enum nation_city_preference goodness;
225
226 /* Increasing this value will increase the difference caused by
227 (non-)matching terrain. A matching terrain is mult_factor
228 "better" than an unlisted terrain, which is mult_factor
229 "better" than a non-matching terrain. */
230 const float mult_factor = 1.4;
231 bool river = FALSE;
232
233 /*
234 * If natural city names aren't being used, we just return the
235 * base value. This will have the effect of the first-listed
236 * city being used. We do this here rather than special-casing
237 * it elsewhere because this localizes everything to this
238 * function, even though it's a bit inefficient.
239 */
241 return default_priority;
242 }
243
244 /*
245 * Assuming we're using the natural city naming system, we use
246 * an internal alorithm to calculate the priority of each name.
247 * It's a pretty fuzzy algorithm; we basically do the following:
248 * - Change the priority scale from 0..n to 10..n+10. This means
249 * each successive city is 10% lower priority than the first.
250 * - Multiply by a semi-random number. This has the effect of
251 * decreasing rounding errors in the successive calculations,
252 * as well as introducing a smallish random effect.
253 * - Check over all the applicable terrains, and
254 * multiply or divide the priority based on whether or not
255 * the terrain matches. See comment below.
256 */
257
258 priority += 10.0;
259 priority *= 10.0 + fc_rand(5);
260
261 /*
262 * The terrain priority in the struct nation_city will be either
263 * -1, 0, or 1. We therefore take this as-is if the terrain is
264 * present, or negate it if not.
265 *
266 * The reason we multiply as well as divide the value is so
267 * that cities that don't care what terrain they are on (which
268 * is the default) will be left in the middle of the pack. If
269 * we _only_ multiplied (or divided), then cities that had more
270 * terrain labels would have their priorities hurt (or helped).
271 */
272 goodness = nation_city_river_preference(pncity);
273 extra_type_by_cause_iterate(EC_ROAD, priver) {
274 if (tile_has_extra(ptile, priver)
275 && road_has_flag(extra_road_get(priver), RF_RIVER)) {
276 river = TRUE;
277 break;
278 }
280 if (!river) {
281 goodness = nation_city_preference_revert(goodness);
282 }
283
284 switch (goodness) {
285 case NCP_DISLIKE:
286 priority *= mult_factor;
287 break;
288 case NCP_NONE:
289 break;
290 case NCP_LIKE:
291 priority /= mult_factor;
292 break;
293 }
294
295 terrain_type_iterate(pterrain) {
296 /* Now we do the same for every available terrain. */
297 goodness = nation_city_terrain_preference(pncity, pterrain);
298 if (!is_terrain_near_tile(&(wld.map), ptile, pterrain, TRUE)) {
299 goodness = nation_city_preference_revert(goodness);
300 }
301 switch (goodness) {
302 case NCP_DISLIKE:
303 priority *= mult_factor;
304 break;
305 case NCP_NONE:
306 break;
307 case NCP_LIKE:
308 priority /= mult_factor;
309 }
311
312 return (int) priority;
313}
314
315/************************************************************************/
319static bool is_default_city_name(const char *name, struct player *pplayer)
320{
322 pncity) {
323 if (0 == fc_strcasecmp(name, nation_city_name(pncity))) {
324 return TRUE;
325 }
327 return FALSE;
328}
329
330/************************************************************************/
337static const char *search_for_city_name(struct tile *ptile,
338 const struct nation_city_list *
339 default_cities,
340 struct player *pplayer)
341{
342 int choice = 0, priority, best_priority = -1;
343 const char *name, *best_name = NULL;
344
345 nation_city_list_iterate(default_cities, pncity) {
346 name = nation_city_name(pncity);
347 if (NULL == game_city_by_name(name)
348 && is_allowed_city_name(pplayer, name, NULL, 0)) {
349 priority = evaluate_city_name_priority(ptile, pncity, choice++);
350 if (-1 == best_priority || priority < best_priority) {
351 best_priority = priority;
352 best_name = name;
353 }
354 }
356
357 return best_name;
358}
359
360/************************************************************************/
372bool is_allowed_city_name(struct player *pplayer, const char *cityname,
373 char *error_buf, size_t bufsz)
374{
375 struct connection *pconn = conn_by_user(pplayer->username);
376
377 /* Mode 1: A city name has to be unique for each player. */
379 && city_list_find_name(pplayer->cities, cityname)) {
380 if (error_buf) {
381 fc_snprintf(error_buf, bufsz, _("You already have a city called %s."),
382 cityname);
383 }
384 return FALSE;
385 }
386
387 /* Modes 2,3: A city name has to be globally unique. */
390 && game_city_by_name(cityname)) {
391 if (error_buf) {
392 fc_snprintf(error_buf, bufsz,
393 _("A city called %s already exists."), cityname);
394 }
395 return FALSE;
396 }
397
398 /* General rule: any name in our ruleset is allowed. */
399 if (is_default_city_name(cityname, pplayer)) {
400 return TRUE;
401 }
402
403 /*
404 * Mode 3: Check that the proposed city name is not in another
405 * player's default city names. Note the name will already have been
406 * allowed if it is in this player's default city names list.
407 */
409 struct player *pother = NULL;
410
411 players_iterate(player2) {
412 if (player2 != pplayer && is_default_city_name(cityname, player2)) {
413 pother = player2;
414 break;
415 }
417
418 if (pother != NULL) {
419 if (error_buf) {
420 fc_snprintf(error_buf, bufsz,
421 _("Can't use %s as a city name. It is reserved for %s."),
422 cityname, nation_plural_for_player(pother));
423 }
424 return FALSE;
425 }
426 }
427
428 /* To prevent abuse, only players with HACK access (usually local
429 * connections) can use non-ascii names. Otherwise players could use
430 * confusing garbage names in multi-player games.
431 *
432 * We can even reach here for an AI player, if all the cities of the
433 * original nation are exhausted and the backup nations have non-ascii
434 * names in them. */
435 if (!is_ascii_name(cityname)
436 && (!pconn || pconn->access_level != ALLOW_HACK)) {
437 if (error_buf) {
438 fc_snprintf(error_buf, bufsz,
439 _("%s is not a valid name. Only ASCII or "
440 "ruleset names are allowed for cities."),
441 cityname);
442 }
443 return FALSE;
444 }
445
446
447 return TRUE;
448}
449
450/************************************************************************/
456const char *city_name_suggestion(struct player *pplayer, struct tile *ptile)
457{
458 struct nation_type *pnation = nation_of_player(pplayer);
459 const char *name;
460
461 log_verbose("Suggesting city name for %s at (%d,%d)",
462 player_name(pplayer), TILE_XY(ptile));
463
464 /* First try default city names. */
465 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
466 if (NULL != name) {
467 log_debug("Default city name found: %s.", name);
468 return name;
469 }
470
471 /* Not found... Let's try a straightforward algorithm to look through
472 * nations to find a city name.
473 *
474 * We start by adding the player's nation to the queue. Then we proceed:
475 * - Pick a random nation from the queue.
476 * - If it has a valid city name, use that.
477 * - Otherwise, add all parent and child nations to the queue.
478 * - If the queue is empty, add all remaining nations to it and continue.
479 *
480 * Variables used:
481 * - nation_list is a queue of nations to look through.
482 * - nations_selected tells whether each nation is in the queue already
483 * - queue_size gives the size of the queue (number of nations in it).
484 * - i is the current position in the queue.
485 * Note that nations aren't removed from the queue after they're processed.
486 * New nations are just added onto the end. */
487 {
488 struct nation_type *nation_list[nation_count()];
489 bool nations_selected[nation_count()];
490 int queue_size = 1, i = 0, idx;
491
492 memset(nations_selected, 0, sizeof(nations_selected));
493 nation_list[0] = pnation;
494 nations_selected[nation_index(pnation)] = TRUE;
495
496 while (i < nation_count()) {
497 for (; i < queue_size; i++) {
498
499 if (0 < i) {
500 /* Pick a random nation from the queue. */
501 const int which = i + fc_rand(queue_size - i);
502 struct nation_type *tmp = nation_list[i];
503
504 nation_list[i] = nation_list[which];
505 nation_list[which] = tmp;
506
507 pnation = nation_list[i];
508 log_debug("Looking through %s.", nation_rule_name(pnation));
509 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
510
511 if (NULL != name) {
512 return name;
513 }
514 }
515
516 /* Append the nation's civil war nations into the search tree. */
518 idx = nation_index(n);
519 if (!nations_selected[idx]) {
520 nation_list[queue_size] = n;
521 nations_selected[idx] = TRUE;
522 queue_size++;
523 log_debug("Child %s.", nation_rule_name(n));
524 }
526
527 /* Append the nation's parent nations into the search tree. */
529 idx = nation_index(n);
530 if (!nations_selected[idx]) {
531 nation_list[queue_size] = n;
532 nations_selected[idx] = TRUE;
533 queue_size++;
534 log_debug("Parent %s.", nation_rule_name(n));
535 }
537 }
538
539 /* Still not found; append all remaining nations. */
541 idx = nation_index(n);
542 if (!nations_selected[idx]) {
543 nation_list[queue_size] = n;
544 nations_selected[nation_index(n)] = TRUE;
545 queue_size++;
546 log_debug("Misc nation %s.", nation_rule_name(n));
547 }
549 }
550 }
551
552 /* Not found in rulesets, make a default name. */
553 {
554 static char tempname[MAX_LEN_CITYNAME];
555 int i;
556
557 log_debug("City name not found in rulesets.");
558 for (i = 1; i <= map_num_tiles(); i++ ) {
559 fc_snprintf(tempname, MAX_LEN_CITYNAME, _("City no. %d"), i);
560 if (NULL == game_city_by_name(tempname)) {
561 return tempname;
562 }
563 }
564
565 fc_assert_msg(FALSE, "Failed to generate a city name.");
566 sz_strlcpy(tempname, _("A poorly-named city"));
567 return tempname;
568 }
569}
570
571/************************************************************************/
574int build_points_left(struct city *pcity)
575{
577
578 return cost - pcity->shield_stock;
579}
580
581/************************************************************************/
588static void transfer_unit(struct unit *punit, struct city *tocity,
589 bool rehome, bool verbose)
590{
591 struct player *from_player = unit_owner(punit);
592 struct player *to_player = city_owner(tocity);
593
594 /* Transferring a dying GameLoss unit as part of the loot for
595 * killing it caused gna bug #23676. */
597 "Tried to transfer the dying unit %d.",
598 punit->id);
599
600 if (from_player == to_player) {
601 fc_assert_ret(rehome);
602 log_verbose("Changed homecity of %s %s to %s",
605 city_name_get(tocity));
606 if (verbose) {
607 notify_player(from_player, unit_tile(punit),
608 E_UNIT_RELOCATED, ftc_server,
609 _("Changed homecity of %s to %s."),
611 city_link(tocity));
612 }
613 } else {
614 struct tile *utile = unit_tile(punit);
615 struct city *in_city = tile_city(utile);
616
619 /* This is a unique unit that to_player already has. A transfer would
620 * break the rule that a player only may have one unit of each unique
621 * unit type. */
622
623 log_debug("%s already have a %s. Can't transfer from %s",
626 nation_rule_name(nation_of_player(from_player)));
627
628 if (utype_has_flag(unit_type_get(punit), UTYF_GAMELOSS)) {
629 /* Try to save game loss units. */
630 bounce_unit(punit, verbose);
631 } else {
632 /* Kill the unique unit. */
633
634 if (verbose) {
635 notify_player(from_player, unit_tile(punit),
636 E_UNIT_LOST_MISC, ftc_server,
637 /* TRANS: Americans ... Leader */
638 _("The %s already have a %s. Can't transfer yours."),
639 nation_plural_for_player(to_player),
641 }
642
643 wipe_unit(punit, ULR_CITY_LOST, NULL);
644 }
645
646 return;
647 }
648
649 if (in_city) {
650 log_verbose("Transferred %s in %s from %s to %s",
654 if (verbose) {
655 notify_player(from_player, unit_tile(punit),
656 E_UNIT_RELOCATED, ftc_server,
657 _("Transferred %s in %s from %s to %s."),
659 city_link(in_city),
660 nation_plural_for_player(from_player),
661 nation_plural_for_player(to_player));
662 }
663 } else if (can_unit_exist_at_tile(&(wld.map), punit, tocity->tile)) {
664 log_verbose("Transferred %s from %s to %s",
668 if (verbose) {
669 notify_player(from_player, unit_tile(punit),
670 E_UNIT_RELOCATED, ftc_server,
671 _("Transferred %s from %s to %s."),
673 nation_plural_for_player(from_player),
674 nation_plural_for_player(to_player));
675 }
676 } else {
677 log_verbose("Could not transfer %s from %s to %s",
681 if (verbose) {
682 notify_player(from_player, unit_tile(punit),
683 E_UNIT_LOST_MISC, ftc_server,
684 /* TRANS: Polish Destroyer ... German <city> */
685 _("%s %s lost in transfer to %s %s"),
686 nation_adjective_for_player(from_player),
689 city_link(tocity));
690 }
691 wipe_unit(punit, ULR_CITY_LOST, NULL);
692 return;
693 }
694
695 maybe_make_contact(utile, to_player);
696 }
697 unit_change_homecity_handling(punit, tocity, rehome);
698}
699
700/************************************************************************/
719void transfer_city_units(struct player *pplayer, struct player *pvictim,
720 struct unit_list *units, struct city *pcity,
721 struct city *exclude_city,
722 int kill_outside, bool verbose)
723{
724 struct tile *ptile = pcity->tile;
725 int saved_id = pcity->id;
726 const char *name = city_name_get(pcity);
727
728 /* Transfer enemy units in the city to the new owner.
729 * Only relevant if we are transferring to another player. */
730 if (pplayer != pvictim) {
731 unit_list_iterate_safe((ptile)->units, vunit) {
732 if (vunit->server.dying) {
733 /* Don't transfer or bounce a dying unit. It will soon be gone
734 * anyway.
735 *
736 * Bouncing a dying unit isn't a good idea.
737 * Remaining death handling may do things meant for its current
738 * location to the new location. (Example: Stack death)
739 * bounce_unit() will wipe the unit if it can't be bounced. Wiping
740 * the dying unit isn't a good idea. The remaining death handling
741 * code will try to read from it.
742 *
743 * Transferring a dying GameLoss unit as part of the loot for
744 * killing it caused gna bug #23676. */
745 continue;
746 }
747
748 /* Don't transfer units already owned by new city-owner --wegge */
749 if (unit_owner(vunit) == pvictim) {
750 /* Determine whether unit was homeless. If it was, we don't give
751 * it a homecity, only change ownership.
752 * We have to search the transferred city's former units because
753 * the unit may have been made only temporarily homeless during
754 * city transfer. */
755 bool homeless = (vunit->homecity == 0)
756 && !unit_list_search(units, vunit);
757
758 /* vunit may die during transfer_unit().
759 * unit_list_remove() is still safe using vunit pointer, as
760 * pointer is not used for dereferencing, only as value.
761 * Not sure if it would be safe to unlink first and transfer only
762 * after that. Not sure if it is correct to unlink at all in
763 * some cases, depending which list 'units' points to. */
764 transfer_unit(vunit, pcity, !homeless, verbose);
765 unit_list_remove(units, vunit);
766 } else if (!pplayers_allied(pplayer, unit_owner(vunit))) {
767 /* the owner of vunit is allied to pvictim but not to pplayer */
768 bounce_unit(vunit, verbose);
769 }
771 }
772
773 if (!city_exist(saved_id)) {
774 saved_id = 0;
775 }
776
777 /* Any remaining units supported by the city are either given new home
778 cities or maybe destroyed */
780 struct city *new_home_city = tile_city(unit_tile(vunit));
781
782 if (vunit->server.dying) {
783 /* Don't transfer or destroy a dying unit. It will soon be gone
784 * anyway.
785 *
786 * Transferring a dying GameLoss unit as part of the loot for
787 * killing it caused gna bug #23676. */
788 continue;
789 }
790
791 if (new_home_city && new_home_city != exclude_city
792 && city_owner(new_home_city) == unit_owner(vunit)) {
793 /* unit is in another city: make that the new homecity,
794 * unless that city is actually the same city (happens if disbanding)
795 * Unit had a homecity since it was supported, so rehome. */
796 transfer_unit(vunit, new_home_city, TRUE, verbose);
797 } else if ((kill_outside == -1
798 || real_map_distance(unit_tile(vunit), ptile) <= kill_outside)
799 && saved_id) {
800 /* else transfer to specified city. */
801 transfer_unit(vunit, pcity, TRUE, verbose);
802 if (unit_tile(vunit) == ptile && !pplayers_allied(pplayer, pvictim)) {
803 /* Unit is inside city being transferred, bounce it */
804 bounce_unit(vunit, TRUE);
805 }
806 } else {
807 /* The unit is lost. Call notify_player (in all other cases it is
808 * called automatically). */
809 log_verbose("Lost %s %s at (%d,%d) when %s was lost.",
811 unit_rule_name(vunit), TILE_XY(unit_tile(vunit)), name);
812 if (verbose) {
813 notify_player(unit_owner(vunit), unit_tile(vunit),
814 E_UNIT_LOST_MISC, ftc_server,
815 _("%s lost along with control of %s."),
816 unit_tile_link(vunit), name);
817 }
818 wipe_unit(vunit, ULR_CITY_LOST, NULL);
819 }
821
822#ifdef FREECIV_DEBUG
824 if (punit->server.dying) {
825 /* Leave the dying alone. */
826 continue;
827 }
828
829 fc_assert(punit->homecity == pcity->id);
830 fc_assert(unit_owner(punit) == pplayer);
832#endif /* FREECIV_DEBUG */
833}
834
835/************************************************************************/
854struct city *find_closest_city(const struct tile *ptile,
855 const struct city *pexclcity,
856 const struct player *pplayer,
857 bool only_ocean, bool only_continent,
858 bool only_known, bool only_player,
859 bool only_enemy, const struct unit_class *pclass)
860{
861 Continent_id con;
862 struct city *best_city = NULL;
863 int best_dist = -1;
864
865 fc_assert_ret_val(ptile != NULL, NULL);
866
867 if (pplayer != NULL && only_player && only_enemy) {
868 log_error("Non of my own cities will be at war with me!");
869 return NULL;
870 }
871
872 con = tile_continent(ptile);
873
874 players_iterate(aplayer) {
875 if (pplayer != NULL && only_player && pplayer != aplayer) {
876 /* only cities of player 'pplayer' */
877 continue;
878 }
879
880 if (pplayer != NULL && only_enemy
881 && !pplayers_at_war(pplayer, aplayer)) {
882 /* only cities of players at war with player 'pplayer' */
883 continue;
884 }
885
886 city_list_iterate(aplayer->cities, pcity) {
887 int city_dist;
888
889 if (pexclcity && pexclcity == pcity) {
890 /* not this city */
891 continue;
892 }
893
894 city_dist = real_map_distance(ptile, city_tile(pcity));
895
896 /* Find the closest city matching the requirements.
897 * - closer than the current best city
898 * - (if required) on the same continent
899 * - (if required) adjacent to ocean
900 * - (if required) only cities known by the player
901 * - (if required) only cities native to the class */
902 if ((best_dist == -1 || city_dist < best_dist)
903 && (!only_continent || con == tile_continent(pcity->tile))
904 && (!only_ocean || is_terrain_class_near_tile(&(wld.map),
905 city_tile(pcity), TC_OCEAN))
906 && (!only_known
907 || (map_is_known(city_tile(pcity), pplayer)
908 && map_get_player_site(city_tile(pcity), pplayer)->identity
910 && (pclass == NULL
911 || is_native_near_tile(&(wld.map), pclass, city_tile(pcity)))) {
912 best_dist = city_dist;
913 best_city = pcity;
914 }
917
918 return best_city;
919}
920
921/************************************************************************/
926static void raze_city(struct city *pcity)
927{
928 int razechance = game.server.razechance;
929 bool city_remains = TRUE;
930
931 /* land barbarians are more likely to destroy city improvements */
932 if (is_land_barbarian(city_owner(pcity))) {
933 razechance += 30;
934 }
935
936 city_built_iterate(pcity, pimprove) {
937 /* Small wonders should have already been removed by
938 * transfer_city() (with 100% probability). */
939 fc_assert(!is_small_wonder(pimprove));
940 if (is_improvement(pimprove) && (fc_rand(100) < razechance)) {
941 /* FIXME: Should maybe have conquering unit instead of NULL as destroyer */
942 city_remains = building_removed(pcity, pimprove, "razed", NULL);
943 if (!city_remains) {
944 break;
945 }
946 }
948
949 if (city_remains) {
951 pcity->shield_stock = 0;
952 }
953}
954
955/************************************************************************/
959static void reestablish_city_trade_routes(struct city *pcity)
960{
961 trade_routes_iterate_safe(pcity, proute) {
962 bool keep_route;
963 struct trade_route *back;
964 struct city *partner = game_city_by_number(proute->partner);
965
966 /* Remove the city's trade routes (old owner).
967 * Do not announce removal as we might restore the route immediately below */
968 back = remove_trade_route(pcity, proute, FALSE, FALSE);
969
970 keep_route = can_cities_trade(pcity, partner)
971 && can_establish_trade_route(pcity, partner);
972
973 if (!keep_route) {
974 enum trade_route_type type = cities_trade_route_type(pcity, partner);
976
977 if (settings->cancelling != TRI_CANCEL) {
978 keep_route = TRUE;
979 }
980 }
981
982 /* Readd the city's trade route (new owner) */
983 if (keep_route) {
984 trade_route_list_append(pcity->routes, proute);
985 trade_route_list_append(partner->routes, back);
986 } else {
987 free(proute);
988 free(back);
989
990 /* Now announce the trade route removal */
991 announce_trade_route_removal(pcity, partner, FALSE);
992 }
993
994 /* Refresh regardless; either it lost a trade route or the trade
995 * route revenue changed. */
996 city_refresh(partner);
997 send_city_info(city_owner(partner), partner);
998
999 /* Give the new owner infos about the city which has a trade route
1000 * with the transferred city. */
1001 map_show_tile(city_owner(pcity), partner->tile);
1002 update_dumb_city(city_owner(pcity), partner);
1003 send_city_info(city_owner(pcity), partner);
1005}
1006
1007/************************************************************************/
1012static void build_free_small_wonders(struct player *pplayer,
1013 bv_imprs *had_small_wonders)
1014{
1015 int size = city_list_size(pplayer->cities);
1016
1017 if (!game.server.savepalace) {
1018 /* Nothing to do */
1019 return;
1020 }
1021
1022 if (size == 0) {
1023 /* The last city was removed or transferred to the enemy.
1024 * If the victim survives to found or acquire another city, they'll
1025 * get any savepalace initial buildings then. */
1026 return;
1027 }
1028
1029 improvement_iterate(pimprove) {
1030 if (improvement_has_flag(pimprove, IF_SAVE_SMALL_WONDER)
1031 && BV_ISSET(*had_small_wonders, improvement_index(pimprove))) {
1032 /* FIXME: instead, find central city */
1033 struct city *pnew_city = city_list_get(pplayer->cities, fc_rand(size));
1034
1035 fc_assert_action(NULL == city_from_small_wonder(pplayer, pimprove),
1036 continue);
1037
1038 city_add_improvement(pnew_city, pimprove);
1039
1040 /*
1041 * send_player_cities will recalculate all cities and send them to
1042 * the client.
1043 */
1044 send_player_cities(pplayer);
1045
1046 notify_player(pplayer, city_tile(pnew_city), E_IMP_BUILD, ftc_server,
1047 /* FIXME: should already be notified about city loss? */
1048 /* TRANS: <building> ... <city> */
1049 _("A replacement %s was built in %s."),
1051 city_link(pnew_city));
1052 /*
1053 * The enemies want to see the new capital in their intelligence
1054 * report.
1055 */
1056 send_city_info(NULL, pnew_city);
1057 }
1059}
1060
1061/************************************************************************/
1070bool transfer_city(struct player *ptaker, struct city *pcity,
1071 int kill_outside, bool transfer_unit_verbose,
1072 bool resolve_stack, bool raze, bool build_free)
1073{
1074 bv_imprs had_small_wonders;
1075 struct vision *old_vision, *new_vision;
1076 struct unit_list *old_city_units = unit_list_new();
1077 struct player *pgiver = city_owner(pcity);
1078 struct tile *pcenter = city_tile(pcity);
1079 int saved_id = pcity->id;
1080 bool city_remains = TRUE;
1081 bool had_great_wonders = FALSE;
1082 const citizens old_taker_content_citizens = player_content_citizens(ptaker);
1083 const citizens old_giver_content_citizens = player_content_citizens(pgiver);
1084 const citizens old_taker_angry_citizens = player_angry_citizens(ptaker);
1085 const citizens old_giver_angry_citizens = player_angry_citizens(pgiver);
1086 bool taker_had_no_cities = (city_list_size(ptaker->cities) == 0);
1087 bool new_extras;
1088 int units_num = 0;
1089 const int ul_size = unit_list_size(pcenter->units);
1090 int central_units[ul_size + 1];
1091 bv_player *could_see_unit = NULL;
1092 int i;
1093 const struct civ_map *nmap = &(wld.map);
1094
1095 fc_assert_ret_val(pgiver != ptaker, TRUE);
1096
1097 unit_list_iterate(pcenter->units, punit) {
1098 central_units[units_num++] = punit->id;
1100
1101 if (units_num > 0) {
1102 could_see_unit = fc_calloc(sizeof(*could_see_unit), units_num);
1103
1104 /* Remember what player see what unit. */
1105 for (i = 0; i < units_num; i++) {
1106 struct unit *aunit = game_unit_by_number(central_units[i]);
1107
1108 BV_CLR_ALL(could_see_unit[i]);
1109 players_iterate(aplayer) {
1110 if (can_player_see_unit(aplayer, aunit)) {
1111 BV_SET(could_see_unit[i], player_index(aplayer));
1112 }
1114 }
1115
1116 fc_assert(i == units_num);
1117 }
1118
1119 /* Remove AI control of the old owner. */
1120 CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity);
1121
1122 /* Forget old tasks */
1123 clear_worker_tasks(pcity);
1124
1125 /* Forget old rally point */
1127
1128 /* Activate AI control of the new owner. */
1129 CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
1130
1131 city_freeze_workers(pcity);
1132
1134 unit_list_prepend(old_city_units, punit);
1135 /* Mark unit to have no homecity at all.
1136 * 1. We remove unit from units_supported list here,
1137 * real_change_unit_homecity() should not attempt it.
1138 * 2. Otherwise we might delete the homecity from under the unit
1139 * in the client */
1140 punit->homecity = 0;
1141 send_unit_info(NULL, punit);
1143 unit_list_clear(pcity->units_supported);
1144
1145 /* Remove all global improvement effects that this city confers (but
1146 then restore the local improvement list - we need this to restore the
1147 global effects for the new city owner) */
1148 BV_CLR_ALL(had_small_wonders);
1149 city_built_iterate(pcity, pimprove) {
1150 if (is_small_wonder(pimprove)) {
1151 /* Small wonders are really removed (not restored later). */
1152 building_removed(pcity, pimprove, "conquered", NULL);
1153 BV_SET(had_small_wonders, improvement_index(pimprove));
1154 } else {
1155 city_remove_improvement(pcity, pimprove);
1156 if (is_great_wonder(pimprove)) {
1157 had_great_wonders = TRUE;
1158 }
1159 /* Note: internal turn here, next city_built_iterate(). */
1160 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
1161 }
1163
1164 give_citymap_from_player_to_player(pcity, pgiver, ptaker);
1165 old_vision = pcity->server.vision;
1166 new_vision = vision_new(ptaker, pcenter);
1167 pcity->server.vision = new_vision;
1169 vision_change_sight(new_vision, old_vision->radius_sq);
1170
1171 ASSERT_VISION(new_vision);
1172
1174 && city_list_find_name(ptaker->cities, city_name_get(pcity))) {
1175 char *old_city_name = fc_strdup(city_name_get(pcity));
1176
1177 city_name_set(pcity, city_name_suggestion(ptaker, pcenter));
1178 notify_player(ptaker, pcenter, E_BAD_COMMAND, ftc_server,
1179 _("You already had a city called %s."
1180 " The city was renamed to %s."),
1181 old_city_name,
1182 city_link(pcity));
1183
1184 free(old_city_name);
1185 }
1186
1187 /* Has to follow the unfog call above. */
1188 city_list_remove(pgiver->cities, pcity);
1189 map_clear_border(pcenter);
1190 /* city_thaw_workers_queue() later */
1191
1192 pcity->owner = ptaker;
1193 pcity->capital = CAPITAL_NOT;
1194 map_claim_ownership(pcenter, ptaker, pcenter, TRUE);
1195 city_list_prepend(ptaker->cities, pcity);
1196
1197 if (could_see_unit != NULL) {
1198 /* Hide/reveal units. Do it after vision have been given to taker, city
1199 * owner has been changed, and before any script could be spawned. */
1200 for (i = 0; i < units_num; i++) {
1201 struct unit *aunit = game_unit_by_number(central_units[i]);
1202
1203 players_iterate(aplayer) {
1204 if (can_player_see_unit(aplayer, aunit)) {
1205 if (!BV_ISSET(could_see_unit[i], player_index(aplayer))
1206 && !aunit->server.dying) {
1207 /* Reveal 'aunit'. */
1208 send_unit_info(aplayer->connections, aunit);
1209 }
1210 } else {
1211 if (BV_ISSET(could_see_unit[i], player_index(aplayer))) {
1212 /* Hide 'aunit'. */
1213 unit_goes_out_of_sight(aplayer, aunit);
1214 }
1215 }
1217 }
1218
1219 fc_assert(i == units_num);
1220
1221 free(could_see_unit);
1222 could_see_unit = NULL;
1223 }
1224
1225 transfer_city_units(ptaker, pgiver, old_city_units,
1226 pcity, NULL,
1227 kill_outside, transfer_unit_verbose);
1228 /* The units themselves are already freed by transfer_city_units(). */
1229 unit_list_destroy(old_city_units);
1230
1231 if (resolve_stack) {
1232 resolve_unit_stacks(pgiver, ptaker, transfer_unit_verbose);
1233 }
1234
1235 if (!city_exist(saved_id)) {
1236 city_remains = FALSE;
1237 }
1238
1239 if (city_remains) {
1240 /* Update the city's trade routes. */
1242
1243 /* Clear CMA. */
1244 if (pcity->cm_parameter) {
1245 free(pcity->cm_parameter);
1246 pcity->cm_parameter = NULL;
1247 }
1248
1249 city_refresh(pcity);
1250 }
1251
1252 /*
1253 * maybe_make_contact() MUST be called before city_map_update_all(),
1254 * since the diplomacy status can influence whether a tile is available.
1255 */
1256 maybe_make_contact(pcenter, ptaker);
1257
1258 if (city_remains) {
1259 struct extra_type *upgradet;
1260
1261 if (raze) {
1262 raze_city(pcity);
1263 }
1264
1265 if (taker_had_no_cities) {
1266 /* If conqueror previously had no cities, we might need to give
1267 * them a palace etc */
1268 if (build_free) {
1270 } /* else caller should probably ensure palace is built */
1271 ptaker->server.got_first_city = TRUE;
1272 }
1273
1275
1276 /* Restore any global improvement effects that this city confers */
1277 city_built_iterate(pcity, pimprove) {
1278 city_add_improvement(pcity, pimprove);
1280
1281 /* Set production to something valid for pplayer, if not.
1282 * (previously allowed building obsolete units.) */
1283 if (!can_city_build_now(nmap, pcity, &pcity->production)) {
1284 advisor_choose_build(ptaker, pcity);
1285 }
1286
1287 /* What wasn't obsolete for the old owner may be so now. */
1289
1290 new_extras = upgrade_city_extras(pcity, &upgradet);
1291
1292 if (new_extras) {
1293 const char *clink = city_link(pcity);
1294
1295 notify_player(ptaker, pcenter, E_CITY_TRANSFER, ftc_server,
1296 _("The people in %s are stunned by your "
1297 "technological insight!"),
1298 clink);
1299
1300 if (upgradet != NULL) {
1301 notify_player(ptaker, pcenter, E_CITY_TRANSFER, ftc_server,
1302 _("Workers spontaneously gather and upgrade "
1303 "%s with %s."),
1304 clink, extra_name_translation(upgradet));
1305 } else {
1306 notify_player(ptaker, pcenter, E_CITY_TRANSFER, ftc_server,
1307 _("Workers spontaneously gather and upgrade "
1308 "%s infrastructure."),
1309 clink);
1310 }
1311 update_tile_knowledge(pcenter);
1312 }
1313
1314 /* Build a new palace for free if the player lost their capital and
1315 savepalace is on. */
1316 build_free_small_wonders(pgiver, &had_small_wonders);
1317
1318 /* Refresh the city's vision range, since it might be different
1319 * under the new owner. */
1320 city_refresh_vision(pcity);
1321
1322 /* Update the national borders, within the current vision and culture.
1323 * This could leave a border ring around the city, updated later by
1324 * map_calculate_borders() at the next turn.
1325 */
1326 map_claim_border(pcenter, ptaker, -1);
1327 /* city_thaw_workers_queue() later */
1328
1329 auto_arrange_workers(pcity); /* does city_map_update_all() */
1330 city_thaw_workers(pcity);
1331 city_thaw_workers_queue(); /* after old city has a chance to work! */
1333 /* no sanity check here as the city is not refreshed! */
1334 }
1335
1336 if (city_remains) {
1337 /* Send city with updated owner information to giver and to everyone
1338 * having shared vision pact with them before they may
1339 * lose vision to it. When we later send info to everybody seeing the city,
1340 * they may not be included. */
1341 send_city_info(NULL, pcity);
1342 }
1343
1344 /* Remove the sight points from the giver. */
1345 vision_clear_sight(old_vision);
1346 vision_free(old_vision);
1347
1348 /* Send wonder infos. */
1349 if (had_great_wonders) {
1350 send_game_info(NULL);
1351 if (city_remains) {
1352 send_player_info_c(ptaker, NULL);
1353
1354 /* Refresh all cities of the taker to account for possible changes due
1355 * to player wide effects. */
1356 city_list_iterate(ptaker->cities, acity) {
1359 } else {
1360 /* Refresh all cities to account for possible global effects. */
1361 cities_iterate(acity) {
1364 }
1365 }
1366 if (BV_ISSET_ANY(had_small_wonders) || had_great_wonders) {
1367 /* No need to send to detached connections. */
1368 send_player_info_c(pgiver, NULL);
1369
1370 /* Refresh all cities of the giver to account for possible changes due
1371 * to player wide effects. */
1372 city_list_iterate(pgiver->cities, acity) {
1375 }
1376
1377 /* Refresh all cities in the queue. */
1379 /* After the refresh the sanity check can be done. */
1380 sanity_check_city(pcity);
1381
1382 if (city_remains) {
1383 /* Send information about conquered city to all players. */
1384 send_city_info(NULL, pcity);
1385 }
1386
1387 /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to
1388 * refresh all cities for the player. */
1389 if (old_taker_content_citizens != player_content_citizens(ptaker)
1390 || old_taker_angry_citizens != player_angry_citizens(ptaker)) {
1392 }
1393 if (old_giver_content_citizens != player_content_citizens(pgiver)
1394 || old_giver_angry_citizens != player_angry_citizens(pgiver)) {
1396 }
1397
1398 if (pgiver->primary_capital_id == saved_id) {
1399 update_capital(pgiver);
1400 }
1401
1402 sync_cities();
1403
1404 CALL_FUNC_EACH_AI(city_info, pcity);
1405
1406 return city_remains;
1407}
1408
1409/************************************************************************/
1417{
1418 struct player *pplayer;
1419 struct nation_type *nation;
1420 int i;
1421 bool has_small_wonders, has_great_wonders;
1422 bool first_city;
1423
1424 fc_assert_ret(NULL != pcity);
1425 pplayer = city_owner(pcity);
1426 fc_assert_ret(NULL != pplayer);
1427 nation = nation_of_player(pplayer);
1428 fc_assert_ret(NULL != nation);
1429
1430 /* If this isn't the first city a player has ever had, they only get
1431 * any initial buildings with the SaveSmallWonder flag, and then only
1432 * if savepalace is enabled. */
1433 first_city = !pplayer->server.got_first_city;
1434
1435 has_small_wonders = FALSE;
1436 has_great_wonders = FALSE;
1437
1438 /* Global free buildings. */
1439 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1441 struct impr_type *pimprove;
1442
1443 if (n == B_LAST) {
1444 break;
1445 }
1446
1447 pimprove = improvement_by_number(n);
1448 fc_assert_action(!is_great_wonder(pimprove), continue);
1449 if (first_city
1451 && improvement_has_flag(pimprove, IF_SAVE_SMALL_WONDER))) {
1452 city_add_improvement(pcity, pimprove);
1453 if (is_small_wonder(pimprove)) {
1454 has_small_wonders = TRUE;
1455 }
1456 }
1457 }
1458
1459 /* Nation specific free buildings. */
1460 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1461 Impr_type_id n = nation->init_buildings[i];
1462 struct impr_type *pimprove;
1463
1464 if (n == B_LAST) {
1465 break;
1466 }
1467
1468 pimprove = improvement_by_number(n);
1469 if (first_city
1471 && improvement_has_flag(pimprove, IF_SAVE_SMALL_WONDER))) {
1472 city_add_improvement(pcity, pimprove);
1473 if (is_small_wonder(pimprove)) {
1474 has_small_wonders = TRUE;
1475 } else if (is_great_wonder(pimprove)) {
1476 has_great_wonders = TRUE;
1477 }
1478 }
1479 }
1480
1481 /* Update wonder infos. */
1482 if (has_great_wonders) {
1483 send_game_info(NULL);
1484 /* No need to send to detached connections. */
1485 send_player_info_c(pplayer, NULL);
1486 } else if (has_small_wonders) {
1487 /* No need to send to detached connections. */
1488 send_player_info_c(pplayer, NULL);
1489 }
1490}
1491
1492/************************************************************************/
1495void create_city(struct player *pplayer, struct tile *ptile,
1496 const char *name, struct player *nationality)
1497{
1498 struct player *saved_owner = tile_owner(ptile);
1499 struct tile *saved_claimer = tile_claimer(ptile);
1500 struct city *pwork = tile_worked(ptile);
1501 struct city *pcity;
1502 const citizens old_content_citizens = player_content_citizens(pplayer);
1503 const citizens old_angry_citizens = player_angry_citizens(pplayer);
1504 const struct civ_map *nmap = &(wld.map);
1505
1506 log_debug("create_city() %s", name);
1507
1508 pcity = create_city_virtual(pplayer, ptile, name);
1509
1510 /* Remove units no more seen. Do it before city is really put into the
1511 * game. */
1512 players_iterate(other_player) {
1513 if (can_player_see_units_in_city(other_player, pcity)
1514 || !map_is_known_and_seen(ptile, other_player, V_MAIN)) {
1515 continue;
1516 }
1517 unit_list_iterate(ptile->units, punit) {
1518 if (can_player_see_unit(other_player, punit)) {
1519 unit_goes_out_of_sight(other_player, punit);
1520 }
1523
1524 adv_city_alloc(pcity);
1525
1526 tile_set_owner(ptile, pplayer, ptile); /* Temporarily */
1527 city_choose_build_default(nmap, pcity);
1528 pcity->id = identity_number();
1529
1531 idex_register_city(&wld, pcity);
1533
1534 if (city_list_size(pplayer->cities) == 0) {
1535 /* Free initial buildings, or at least a palace if they were
1536 * previously careless enough to lose all their cities */
1538 pplayer->server.got_first_city = TRUE;
1539 }
1540
1541 /* Set up citizens nationality. */
1542 citizens_init(pcity);
1543
1544 /* Place a worker at the is_city_center() is_free_worked().
1545 * It is possible to build a city on a tile that is already worked;
1546 * this will displace the worker on the newly-built city's tile -- Syela */
1547 tile_set_worked(ptile, pcity); /* instead of city_map_update_worker() */
1548
1549 if (NULL != pwork) {
1550 /* was previously worked by another city */
1551 /* Turn citizen into specialist. */
1553 /* One less citizen. Citizen sanity will be handled later in
1554 * city_thaw_workers_queue() */
1555 pwork->server.synced = FALSE;
1557 }
1558
1559 /* Update citizens. */
1560 citizens_update(pcity, nationality);
1561
1562 /* Restore the old-owner information so removal
1563 * of territory claiming bases can work relative to it. */
1564 tile_set_owner(ptile, saved_owner, saved_claimer);
1565
1566 /* Destroy any extras that don't belong in the city. */
1567 extra_type_iterate(pextra) {
1568 if (tile_has_extra(ptile, pextra)
1569 && !is_native_tile_to_extra(pextra, ptile)) {
1570 destroy_extra(ptile, pextra);
1571 }
1573
1574 /* Build any extras that the city should have. */
1575 upgrade_city_extras(pcity, NULL);
1576
1577 /* Claim the ground we stand on */
1578 map_claim_ownership(ptile, pplayer, ptile, TRUE);
1579
1580 /* Before arranging workers to show unknown land */
1581 pcity->server.vision = vision_new(pplayer, ptile);
1583 city_refresh_vision(pcity);
1584 city_list_prepend(pplayer->cities, pcity);
1585
1586 /* This is dependent on the current vision, so must be done after
1587 * vision is prepared and before arranging workers. */
1588 map_claim_border(ptile, pplayer, -1);
1589 /* city_thaw_workers_queue() later */
1590
1591 /* Refresh the city. First a city refresh is done (this shouldn't
1592 * send any packets to the client because the city has no supported units)
1593 * then rearrange the workers. Note that auto_arrange_workers does its
1594 * own refresh call; it is safest to do our own controlled city_refresh
1595 * first. */
1596 city_refresh(pcity);
1597 auto_arrange_workers(pcity);
1598 city_thaw_workers_queue(); /* after new city has a chance to work! */
1600
1601 /* Bases destroyed earlier may have had watchtower effect. Refresh
1602 * unit vision. */
1604
1605 update_tile_knowledge(ptile);
1606
1607 if (old_content_citizens != player_content_citizens(pplayer)
1608 || old_angry_citizens != player_angry_citizens(pplayer)) {
1609 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1610 * cities for the player. */
1611 city_refresh_for_player(pplayer);
1612 }
1613
1614 pcity->server.synced = FALSE;
1615 send_city_info(NULL, pcity);
1616 sync_cities(); /* Will also send pwork. */
1617
1618 notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server,
1619 _("You have founded %s."),
1620 city_link(pcity));
1621 maybe_make_contact(ptile, city_owner(pcity));
1622
1623 unit_list_iterate((ptile)->units, punit) {
1624 struct city *home = game_city_by_number(punit->homecity);
1625
1626 /* Catch fortress building, transforming into ocean, etc. */
1629 }
1630
1631 /* Update happiness (the unit may no longer cause unrest). */
1632 if (home) {
1633 if (city_refresh(home)) {
1634 /* Shouldn't happen, but better be safe than sorry. */
1636 }
1637 sanity_check_city(home);
1638 send_city_info(city_owner(home), home);
1639 }
1641
1642 sanity_check_city(pcity);
1643
1644 script_server_signal_emit("city_built", pcity);
1645
1646 CALL_FUNC_EACH_AI(city_created, pcity);
1647 CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
1648}
1649
1650/************************************************************************/
1656bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1657 const char *name)
1658{
1659 const struct civ_map *nmap = &(wld.map);
1660
1661 if (is_enemy_unit_tile(ptile, pplayer)
1662 || !city_can_be_built_here(nmap, ptile, NULL, FALSE)) {
1663 return FALSE;
1664 }
1665
1666 if (!pplayer->is_alive) {
1667 pplayer->is_alive = TRUE;
1668 send_player_info_c(pplayer, NULL);
1669 }
1670
1671 if (name == NULL || name[0] == '\0') {
1672 name = city_name_suggestion(pplayer, ptile);
1673 }
1674
1675 map_show_tile(pplayer, ptile);
1676 create_city(pplayer, ptile, name, pplayer);
1677
1678 return TRUE;
1679}
1680
1681/************************************************************************/
1684void remove_city(struct city *pcity)
1685{
1686 struct player *powner = city_owner(pcity);
1687 struct tile *pcenter = city_tile(pcity);
1688 bv_imprs had_small_wonders;
1689 struct vision *old_vision;
1690 int id = pcity->id; /* We need this even after memory has been freed */
1691 bool had_great_wonders = FALSE;
1692 const citizens old_content_citizens = player_content_citizens(powner);
1693 const citizens old_angry_citizens = player_angry_citizens(powner);
1694 struct dbv tile_processed;
1695 struct tile_list *process_queue;
1696 const char *ctl = city_tile_link(pcity);
1697 const struct civ_map *nmap = &(wld.map);
1698
1699 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1700 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1701
1702 BV_CLR_ALL(had_small_wonders);
1703 city_built_iterate(pcity, pimprove) {
1704 building_removed(pcity, pimprove, "city_destroyed", NULL);
1705
1706 if (is_small_wonder(pimprove)) {
1707 BV_SET(had_small_wonders, improvement_index(pimprove));
1708 } else if (is_great_wonder(pimprove)) {
1709 had_great_wonders = TRUE;
1710 }
1712
1713 /* Rehome units in other cities */
1715 struct city *new_home_city = tile_city(unit_tile(punit));
1716
1717 if (new_home_city
1718 && new_home_city != pcity
1719 && city_owner(new_home_city) == powner
1720 && !punit->server.dying) {
1721 transfer_unit(punit, new_home_city, TRUE, TRUE);
1722 }
1724
1725 /* Make sure ships are not left on land when city is removed. */
1727 bool moved;
1728 const struct unit_type *punittype = unit_type_get(punit);
1729
1730 /* can_exist_at_tile() would give wrong results, as
1731 * the city is still on map. */
1732 if (is_native_tile(punittype, pcenter)
1733 && (!utype_has_flag(punittype, UTYF_COAST_STRICT)
1734 || is_safe_ocean(nmap, pcenter))) {
1735 continue;
1736 }
1737
1738 unit_activity_handling(punit, ACTIVITY_IDLE);
1739 moved = FALSE;
1740 adjc_iterate(nmap, pcenter, tile1) {
1741 struct unit *ptrans;
1742
1743 if (!moved && can_exist_at_tile(nmap, punittype, tile1)) {
1744 if (adv_could_unit_move_to_tile(punit, tile1) == 1) {
1745 /* Move */
1746 if (!can_unit_survive_at_tile(nmap, punit, tile1)) {
1747 /* It may be impossible to survive at the tile even if it is
1748 * native. See UTYF_COAST_STRICT */
1749 ptrans = transporter_for_unit_at(punit, tile1);
1750 } else {
1751 ptrans = NULL;
1752 }
1753 if (action_auto_perf_unit_do(AAPC_CITY_GONE, punit,
1754 tile_owner(tile1), NULL, NULL,
1755 tile1, tile_city(tile1), ptrans,
1756 NULL) != NULL) {
1757 moved = TRUE;
1758 }
1759 if (moved) {
1761 E_UNIT_RELOCATED, ftc_server,
1762 _("Moved %s out of disbanded city %s "
1763 "since it cannot stay on %s."),
1764 unit_link(punit), ctl,
1766 break;
1767 }
1768 }
1769 }
1771 if (!moved) {
1773 E_UNIT_LOST_MISC, ftc_server,
1774 _("When %s was disbanded your %s could not "
1775 "get out, and it was therefore lost."),
1776 ctl,
1778 wipe_unit(punit, ULR_CITY_LOST, NULL);
1779 }
1781
1782 process_queue = tile_list_new();
1783 dbv_init(&tile_processed, map_num_tiles());
1784 for (tile_list_append(process_queue, pcenter); tile_list_size(process_queue) > 0;) {
1785 struct tile *ptile = tile_list_front(process_queue);
1786
1787 tile_list_pop_front(process_queue);
1788 dbv_set(&tile_processed, tile_index(ptile));
1789 adjc_iterate(nmap, ptile, piter) {
1790 struct city *other_city;
1791
1792 if (dbv_isset(&tile_processed, tile_index(piter))) {
1793 continue;
1794 }
1795 other_city = tile_city(piter);
1796 if (other_city != NULL) {
1797 /* Adjacent tile has a city that may have been part of same channel */
1798 dbv_set(&tile_processed, tile_index(piter));
1799 tile_list_append(process_queue, piter);
1800 unit_list_iterate_safe(piter->units, punit) {
1801 struct unit_class *pclass = utype_class(punit->utype);
1802
1803 if (!uclass_has_flag(pclass, UCF_BUILD_ANYWHERE)
1804 && !is_native_tile(punit->utype, piter)
1805 && !is_city_channel_tile(nmap, pclass, piter, pcenter)) {
1807 E_UNIT_LOST_MISC, ftc_server,
1808 _("When %s was disbanded your %s in %s was trapped, "
1809 "and it was therefore lost."),
1810 ctl,
1812 city_link(other_city));
1813 wipe_unit(punit, ULR_CITY_LOST, NULL);
1814 }
1816 } else {
1817 dbv_set(&tile_processed, tile_index(piter));
1818 }
1820 }
1821
1822 dbv_free(&tile_processed);
1823 tile_list_destroy(process_queue);
1824
1825 if (!city_exist(id)) {
1826 /* Wiping trapped units caused city to disappear. */
1827 return;
1828 }
1829
1830 /* Any remaining supported units are destroyed */
1832 wipe_unit(punit, ULR_CITY_LOST, NULL);
1834
1835 if (!city_exist(id)) {
1836 /* Wiping supported units caused city to disappear. */
1837 return;
1838 }
1839
1840 trade_routes_iterate_safe(pcity, proute) {
1841 struct trade_route *pback = remove_trade_route(pcity, proute,
1842 TRUE, TRUE);
1843
1844 FC_FREE(proute);
1845 FC_FREE(pback);
1847
1848 map_clear_border(pcenter);
1852
1853 /* idex_unregister_city() is called in game_remove_city() below */
1854
1855 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1856 still be alive in the client, or in the player map. The number of
1857 removed cities is small, so the loss is acceptable.
1858 */
1859
1860 old_vision = pcity->server.vision;
1861 pcity->server.vision = NULL;
1863 adv_city_free(pcity);
1864
1865 /* Remove city from the map. */
1866 tile_set_worked(pcenter, NULL);
1867
1868 /* Reveal units. */
1869 players_iterate(other_player) {
1870 if (can_player_see_units_in_city(other_player, pcity)
1871 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1872 continue;
1873 }
1874 unit_list_iterate(pcenter->units, punit) {
1875 if (can_player_see_unit(other_player, punit)) {
1876 send_unit_info(other_player->connections, punit);
1877 }
1880
1882 game_remove_city(&wld, pcity);
1884
1885 /* Remove any extras that were only there because the city was there. */
1886 extra_type_iterate(pextra) {
1887 if (tile_has_extra(pcenter, pextra)
1888 && !is_native_tile_to_extra(pextra, pcenter)) {
1889 tile_extra_rm_apply(pcenter, pextra);
1890 }
1892
1893 players_iterate(other_player) {
1894 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1895 reality_check_city(other_player, pcenter);
1896 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1897 map_show_tile(other_player, pcenter);
1898 }
1900
1902 if (NULL == pconn->playing && pconn->observer) {
1903 /* For detached observers we have to send a specific packet. This is
1904 * a hack necessitated by the private map that exists for players but
1905 * not observers. */
1906 dsend_packet_city_remove(pconn, id, id);
1907 }
1909
1910 if (old_vision != NULL) {
1911 vision_clear_sight(old_vision);
1912 vision_free(old_vision);
1913 }
1914
1915 /* Infrastructures may have changed. */
1916 send_tile_info(NULL, pcenter, FALSE);
1917
1918 /* Build a new palace for free if the player lost their capital and
1919 savepalace is on. */
1920 build_free_small_wonders(powner, &had_small_wonders);
1921
1922 /* Update wonder infos. */
1923 if (had_great_wonders) {
1924 send_game_info(NULL);
1925 /* No need to send to detached connections. */
1926 send_player_info_c(powner, NULL);
1927 } else if (BV_ISSET_ANY(had_small_wonders)) {
1928 /* No need to send to detached connections. */
1929 send_player_info_c(powner, NULL);
1930 }
1931
1932 if (old_content_citizens != player_content_citizens(powner)
1933 || old_angry_citizens != player_angry_citizens(powner)) {
1934 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1935 * cities for the player. */
1937 }
1938
1939 sync_cities();
1940
1941 /* At least sentried helicopters need to go idle, maybe others.
1942 * In alien ruleset, city center might have provided water source
1943 * for adjacent tile. */
1945}
1946
1947/************************************************************************/
1963bool unit_conquer_city(struct unit *punit, struct city *pcity)
1964{
1965 bool try_civil_war = FALSE;
1966 bool city_remains;
1967 int coins;
1968 struct player *pplayer = unit_owner(punit);
1969 struct player *cplayer = city_owner(pcity);
1970
1971 /* If not at war, may peacefully enter city. */
1972 fc_assert_ret_val_msg(pplayers_at_war(pplayer, cplayer), FALSE,
1973 "Can't conquer city during peace.");
1974
1975 /* If we cannot occupy the city, this unit entering will not trigger the
1976 * effects below. */
1979 ACTION_PARADROP_CONQUER)
1981 ACTION_PARADROP_FRIGHTEN_CONQUER)
1983 ACTION_PARADROP_ENTER_CONQUER),
1984 FALSE, "Bad unit for city occupation.");
1985
1986 /* A transported unit trying to conquer a city should already have been
1987 * unloaded. */
1989 "Can't conquer city while transported.");
1990
1991 /* Okay, we're at war - invader captures/destroys city... */
1992
1993 /* If a capital is captured, then spark off a civil war
1994 - Kris Bubendorfer
1995 Also check spaceships --dwp
1996 */
1997
1998 if (is_capital(pcity)
1999 && (cplayer->spaceship.state == SSHIP_STARTED
2000 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
2001 spaceship_lost(cplayer);
2002 }
2003
2004 if (is_capital(pcity)
2005 && civil_war_possible(cplayer, TRUE, TRUE)
2007 && civil_war_triggered(cplayer)) {
2008 try_civil_war = TRUE;
2009 }
2010
2011 /*
2012 * We later remove a citizen. Lets check if we can save this since
2013 * the city will be destroyed.
2014 */
2015 if (city_size_get(pcity) <= 1) {
2016 int saved_id = pcity->id;
2017
2018 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2019 _("You destroy %s completely."),
2020 city_tile_link(pcity));
2021 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2022 _("%s has been destroyed by %s."),
2023 city_tile_link(pcity), player_name(pplayer));
2024 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2025
2026 /* We cant't be sure of city existence after running some script */
2027 if (city_exist(saved_id)) {
2028 remove_city(pcity);
2029 }
2030
2031 if (try_civil_war) {
2032 (void) civil_war(cplayer);
2033 }
2034 return TRUE;
2035 }
2036
2037 coins = cplayer->economic.gold;
2038 coins = MIN(coins,
2039 fc_rand((coins / 20) + 1)
2040 + (coins * (city_size_get(pcity))) / 200);
2041 pplayer->economic.gold += coins;
2042 cplayer->economic.gold -= coins;
2043 send_player_info_c(pplayer, pplayer->connections);
2044 send_player_info_c(cplayer, cplayer->connections);
2045 if (pcity->original != pplayer) {
2046 if (coins > 0) {
2047 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2048 PL_("You conquer %s; your lootings accumulate"
2049 " to %d gold!",
2050 "You conquer %s; your lootings accumulate"
2051 " to %d gold!", coins),
2052 city_link(pcity),
2053 coins);
2054 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2055 PL_("%s conquered %s and looted %d gold"
2056 " from the city.",
2057 "%s conquered %s and looted %d gold"
2058 " from the city.", coins),
2059 player_name(pplayer),
2060 city_link(pcity),
2061 coins);
2062 } else {
2063 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2064 _("You conquer %s."),
2065 city_link(pcity));
2066 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2067 _("%s conquered %s."),
2068 player_name(pplayer),
2069 city_link(pcity));
2070 }
2071 } else {
2072 if (coins > 0) {
2073 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2074 PL_("You have liberated %s!"
2075 " Lootings accumulate to %d gold.",
2076 "You have liberated %s!"
2077 " Lootings accumulate to %d gold.", coins),
2078 city_link(pcity),
2079 coins);
2080 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2081 PL_("%s liberated %s and looted %d gold"
2082 " from the city.",
2083 "%s liberated %s and looted %d gold"
2084 " from the city.", coins),
2085 player_name(pplayer),
2086 city_link(pcity),
2087 coins);
2088 } else {
2089 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2090 _("You have liberated %s!"),
2091 city_link(pcity));
2092 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2093 _("%s liberated %s."),
2094 player_name(pplayer),
2095 city_link(pcity));
2096 }
2097 }
2098
2099 if (fc_rand(100) < get_unit_bonus(punit, EFT_CONQUEST_TECH_PCT)) {
2100 /* Just try to steal. Ignore failures to get tech */
2101 steal_a_tech(pplayer, cplayer, A_UNSET);
2102 }
2103
2104 /* We transfer the city first so that it is in a consistent state when
2105 * the size is reduced. */
2106 /* FIXME: maybe it should be a ruleset option whether barbarians get
2107 * free buildings such as palaces? */
2108 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2109 !is_barbarian(pplayer));
2110
2111 if (city_remains) {
2112 /* reduce size should not destroy this city */
2113 fc_assert(city_size_get(pcity) > 1);
2114 city_reduce_size(pcity, 1, pplayer, "conquest");
2115 }
2116
2117 if (try_civil_war) {
2118 (void) civil_war(cplayer);
2119 }
2120
2121 if (city_remains) {
2122 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2123 "conquest");
2124 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2125 }
2126
2127 return TRUE;
2128}
2129
2130/************************************************************************/
2133static int city_citywalls_gfx(const struct city *pcity)
2134{
2135 int walls = get_city_bonus(pcity, EFT_VISIBLE_WALLS);
2136
2137 return walls > 0 ? walls : 0;
2138}
2139
2140/************************************************************************/
2144{
2145 bool formerly = send_city_suppressed;
2146
2148 return formerly;
2149}
2150
2151/************************************************************************/
2154static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2155 struct packet_city_short_info *packet)
2156{
2157 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2158
2159 packet->id32 = pdcity->identity;
2160 packet->id16 = packet->id32;
2161 packet->owner = player_number(vision_site_owner(pdcity));
2162
2163 packet->tile = tile_index(ptile);
2164 if (pdcity->name == NULL) {
2165 packet->name[0] = '\0';
2166 } else {
2167 sz_strlcpy(packet->name, pdcity->name);
2168 }
2169
2170 packet->size = vision_site_size_get(pdcity);
2171
2172 packet->occupied = pdcity->occupied;
2173 packet->walls = pdcity->walls;
2174 packet->style = pdcity->style;
2175 packet->city_image = pdcity->city_image;
2176 packet->capital = pdcity->capital;
2177
2178 packet->happy = pdcity->happy;
2179 packet->unhappy = pdcity->unhappy;
2180
2181 packet->improvements = pdcity->improvements;
2182}
2183
2184/************************************************************************/
2188void refresh_dumb_city(struct city *pcity)
2189{
2190 players_iterate(pplayer) {
2191 if (player_can_see_city_externals(pplayer, pcity)) {
2192 if (update_dumb_city(pplayer, pcity)) {
2193 struct packet_city_short_info packet;
2194
2195 if (city_owner(pcity) != pplayer) {
2196 /* Don't send the short_city information to someone who can see the
2197 * city's internals. Doing so would really confuse the client. */
2198 package_dumb_city(pplayer, pcity->tile, &packet);
2199 lsend_packet_city_short_info(pplayer->connections, &packet);
2200 }
2201 }
2202 }
2204
2205 /* Don't send to non-player observers since they don't have 'dumb city'
2206 * information. */
2207}
2208
2209/************************************************************************/
2217void broadcast_city_info(struct city *pcity)
2218{
2219 struct packet_city_info packet;
2220 struct packet_city_nationalities nat_packet;
2221 struct packet_city_rally_point rally_packet;
2222 struct packet_web_city_info_addition web_packet;
2223 struct packet_city_short_info sc_pack;
2224 struct player *powner = city_owner(pcity);
2225 struct trade_route_packet_list *routes;
2226
2227 /* Send to everyone who can see the city. */
2228
2229 if (pcity->server.needs_arrange != CNA_NOT) {
2230 /* Send city only when it's in sane state.
2231 * If it's not, it will be sent to everyone once
2232 * rearrangement has been finished. */
2234
2235 return;
2236 }
2237
2238 routes = trade_route_packet_list_new();
2239 package_city(pcity, &packet, &nat_packet, &rally_packet,
2240 &web_packet, routes, FALSE);
2241
2242 players_iterate(pplayer) {
2243 if (!send_city_suppressed || pplayer != powner) {
2244 if (can_player_see_city_internals(pplayer, pcity)) {
2245 update_dumb_city(pplayer, pcity);
2246 packet.original = city_original_owner(pcity, pplayer);
2247 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2248 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2249 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2250 web_lsend_packet(city_info_addition, pplayer->connections, &web_packet, FALSE);
2251 trade_route_packet_list_iterate(routes, route_packet) {
2252 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2254 } else if (player_can_see_city_externals(pplayer, pcity)) {
2255 reality_check_city(pplayer, pcity->tile);
2256 update_dumb_city(pplayer, pcity);
2257 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2258 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2259 }
2260 }
2262
2263 /* Send to global observers. */
2264 packet.original = city_original_owner(pcity, NULL);
2266 if (conn_is_global_observer(pconn)) {
2267 send_packet_city_info(pconn, &packet, FALSE);
2268 send_packet_city_nationalities(pconn, &nat_packet, FALSE);
2269 send_packet_city_rally_point(pconn, &rally_packet, FALSE);
2270 web_send_packet(city_info_addition, pconn, &web_packet, FALSE);
2271 }
2273
2274 trade_route_packet_list_iterate(routes, route_packet) {
2275 FC_FREE(route_packet);
2277 trade_route_packet_list_destroy(routes);
2278}
2279
2280/************************************************************************/
2284void send_all_known_cities(struct conn_list *dest)
2285{
2286 conn_list_do_buffer(dest);
2287 conn_list_iterate(dest, pconn) {
2288 struct player *pplayer = pconn->playing;
2289
2290 if (!pplayer && !pconn->observer) {
2291 continue;
2292 }
2293 whole_map_iterate(&(wld.map), ptile) {
2294 if (!pplayer || NULL != map_get_player_site(ptile, pplayer)) {
2295 send_city_info_at_tile(pplayer, pconn->self, NULL, ptile);
2296 }
2298 }
2301 flush_packets();
2302}
2303
2304/************************************************************************/
2307void send_player_cities(struct player *pplayer)
2308{
2309 city_list_iterate(pplayer->cities, pcity) {
2310 if (city_refresh(pcity)) {
2311 log_error("%s radius changed while sending to player.",
2312 city_name_get(pcity));
2313
2314 /* Make sure that no workers in illegal position outside radius. */
2315 auto_arrange_workers(pcity);
2316 }
2317 send_city_info(pplayer, pcity);
2318 }
2320}
2321
2322/************************************************************************/
2327void send_city_info(struct player *dest, struct city *pcity)
2328{
2329 struct player *powner = city_owner(pcity);
2330
2331 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2332 return;
2333 }
2334
2335 if (dest == powner && send_city_suppressed) {
2336 return;
2337 }
2338
2339 if (!dest || dest == powner) {
2340 pcity->server.synced = TRUE;
2341 }
2342
2343 if (!dest) {
2344 broadcast_city_info(pcity);
2345 } else {
2346 send_city_info_at_tile(dest, dest->connections, pcity, pcity->tile);
2347 }
2348
2350 && player_list_size(team_members(powner->team)) > 1) {
2351 /* We want to send the new total bulbs production of the team. */
2352 send_research_info(research_get(powner), NULL);
2353 }
2354}
2355
2356/************************************************************************/
2376void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest,
2377 struct city *pcity, struct tile *ptile)
2378{
2379 struct packet_city_info packet;
2380 struct packet_city_nationalities nat_packet;
2381 struct packet_city_rally_point rally_packet;
2382 struct packet_web_city_info_addition web_packet;
2383 struct packet_city_short_info sc_pack;
2384 struct player *powner = NULL;
2385 struct trade_route_packet_list *routes = NULL;
2386
2387 if (!pcity) {
2388 pcity = tile_city(ptile);
2389 }
2390 if (pcity != NULL && pcity->server.needs_arrange != CNA_NOT) {
2392
2393 return;
2394 }
2395 if (pcity) {
2396 powner = city_owner(pcity);
2397 }
2398
2399 if (powner != NULL && powner == pviewer) {
2400 /* Send info to owner */
2401 /* This case implies powner non-NULL which means pcity non-NULL */
2402 if (!send_city_suppressed) {
2403 /* Wait that city has been rearranged, if it's currently
2404 * not in sane state. */
2405
2406 routes = trade_route_packet_list_new();
2407
2408 /* Send all info to the owner */
2409 update_dumb_city(powner, pcity);
2410 package_city(pcity, &packet, &nat_packet, &rally_packet,
2411 &web_packet, routes, FALSE);
2412 packet.original = city_original_owner(pcity, pviewer);
2413 lsend_packet_city_info(dest, &packet, FALSE);
2414 lsend_packet_city_nationalities(dest, &nat_packet, FALSE);
2415 lsend_packet_city_rally_point(dest, &rally_packet, FALSE);
2416 web_lsend_packet(city_info_addition, dest, &web_packet, FALSE);
2417 trade_route_packet_list_iterate(routes, route_packet) {
2418 lsend_packet_trade_route_info(dest, route_packet);
2420 if (dest == powner->connections) {
2421 /* HACK: send also a copy to global observers. */
2422 packet.original = city_original_owner(pcity, NULL);
2424 if (conn_is_global_observer(pconn)) {
2425 send_packet_city_info(pconn, &packet, FALSE);
2426 trade_route_packet_list_iterate(routes, route_packet) {
2427 send_packet_trade_route_info(pconn, route_packet);
2429 }
2431 }
2432 }
2433 } else {
2434 /* send info to non-owner */
2435 if (!pviewer) { /* observer */
2436 if (pcity) {
2437 routes = trade_route_packet_list_new();
2438
2439 /* Should be dumb_city info? */
2440 package_city(pcity, &packet, &nat_packet, &rally_packet,
2441 &web_packet, routes, FALSE);
2442 lsend_packet_city_info(dest, &packet, FALSE);
2443 lsend_packet_city_nationalities(dest, &nat_packet, FALSE);
2444 lsend_packet_city_rally_point(dest, &rally_packet, FALSE);
2445 web_lsend_packet(city_info_addition, dest, &web_packet, FALSE);
2446 trade_route_packet_list_iterate(routes, route_packet) {
2447 lsend_packet_trade_route_info(dest, route_packet);
2449 }
2450 } else {
2451 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2452 if (pcity) { /* it's there and we see it; update and send */
2453 update_dumb_city(pviewer, pcity);
2454 package_dumb_city(pviewer, ptile, &sc_pack);
2455 lsend_packet_city_short_info(dest, &sc_pack);
2456 }
2457 } else { /* not seen; send old info */
2458 if (map_is_known(ptile, pviewer)
2459 && map_get_player_site(ptile, pviewer) != NULL) {
2460 package_dumb_city(pviewer, ptile, &sc_pack);
2461 lsend_packet_city_short_info(dest, &sc_pack);
2462 }
2463 }
2464 }
2465 }
2466
2467 if (routes != NULL) {
2468 trade_route_packet_list_iterate(routes, route_packet) {
2469 FC_FREE(route_packet);
2471 trade_route_packet_list_destroy(routes);
2472 }
2473}
2474
2475/************************************************************************/
2480void package_city(struct city *pcity, struct packet_city_info *packet,
2481 struct packet_city_nationalities *nat_packet,
2482 struct packet_city_rally_point *rally_packet,
2483 struct packet_web_city_info_addition *web_packet,
2484 struct trade_route_packet_list *routes,
2485 bool dipl_invest)
2486{
2487 int i;
2488 int ppl = 0;
2489
2491
2492 packet->id32 = pcity->id;
2493 packet->id16 = packet->id32;
2494 packet->owner = player_number(city_owner(pcity));
2495
2496 packet->tile = tile_index(city_tile(pcity));
2497 sz_strlcpy(packet->name, city_name_get(pcity));
2498
2499 packet->size = city_size_get(pcity);
2500 for (i = 0; i < FEELING_LAST; i++) {
2501 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2502 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2503 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2504 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2505 if (i == 0) {
2506 ppl += packet->ppl_happy[i];
2507 ppl += packet->ppl_content[i];
2508 ppl += packet->ppl_unhappy[i];
2509 ppl += packet->ppl_angry[i];
2510 }
2511 }
2512 /* The number of data in specialists[] array */
2515 packet->specialists[sp] = pcity->specialists[sp];
2516 ppl += packet->specialists[sp];
2518
2519 /* The nationality of the citizens. */
2520 nat_packet->id32 = pcity->id;
2521 nat_packet->id16 = nat_packet->id32;
2522 nat_packet->nationalities_count = 0;
2524 int cit = 0;
2525
2526 player_slots_iterate(pslot) {
2527 citizens nationality = citizens_nation_get(pcity, pslot);
2528 if (nationality != 0) {
2529 /* This player should exist! */
2530 fc_assert(player_slot_get_player(pslot) != NULL);
2531
2532 nat_packet->nation_id[nat_packet->nationalities_count]
2533 = player_slot_index(pslot);
2534 nat_packet->nation_citizens[nat_packet->nationalities_count]
2535 = nationality;
2536 nat_packet->nationalities_count++;
2537
2538 cit += nationality;
2539 }
2541
2542 fc_assert(cit == packet->size);
2543 }
2544
2545 packet->history = pcity->history;
2546 packet->culture = city_culture(pcity);
2547 packet->buy_cost = city_production_buy_gold_cost(pcity);
2548
2549 if (packet->size != ppl) {
2550 static bool recursion = FALSE;
2551
2552 if (recursion) {
2553 /* Recursion didn't help. Do not enter infinite recursive loop.
2554 * Package city as it is. */
2555 log_error("Failed to fix inconsistent city size.");
2556 recursion = FALSE;
2557 } else {
2558 /* Note: If you get this error and try to debug the cause, you may find
2559 * using check_city_feelings() in some key points useful. */
2560 /* Have this as an fc_assert() first, so one can use '-F' to caught these in
2561 * debugger. */
2562 fc_assert(packet->size == ppl);
2563
2564 /* In all builds have an error message shown. */
2565 log_error("City size %d, citizen count %d for %s",
2566 packet->size, ppl, city_name_get(pcity));
2567
2568 /* Try to fix */
2569 city_refresh(pcity);
2570 auto_arrange_workers(pcity);
2571
2572 /* And repackage */
2573 recursion = TRUE;
2574 package_city(pcity, packet, nat_packet, rally_packet,
2575 web_packet, routes, dipl_invest);
2576 recursion = FALSE;
2577
2578 return;
2579 }
2580 }
2581
2582 packet->city_radius_sq = pcity->city_radius_sq;
2583
2584 i = 0;
2585 trade_routes_iterate(pcity, proute) {
2586 struct packet_trade_route_info *tri_packet = fc_malloc(sizeof(struct packet_trade_route_info));
2587
2588 tri_packet->city32 = pcity->id;
2589 tri_packet->city16 = tri_packet->city32;
2590 tri_packet->index = i;
2591 tri_packet->partner32 = proute->partner;
2592 tri_packet->partner16 = tri_packet->partner32;
2593 tri_packet->value = proute->value;
2594 tri_packet->direction = proute->dir;
2595 tri_packet->goods = goods_number(proute->goods);
2596
2597 trade_route_packet_list_append(routes, tri_packet);
2598
2599 i++;
2601
2602 packet->trade_route_count = i;
2603
2605 packet->surplus[o] = pcity->surplus[o];
2606 packet->waste[o] = pcity->waste[o];
2607 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2608 packet->prod[o] = pcity->prod[o];
2609 packet->citizen_base[o] = pcity->citizen_base[o];
2610 packet->usage[o] = pcity->usage[o];
2612
2613 packet->food_stock = pcity->food_stock;
2614 packet->shield_stock = pcity->shield_stock;
2615 packet->pollution = pcity->pollution;
2616 packet->illness_trade = pcity->illness_trade;
2617 packet->city_options = pcity->city_options;
2618
2619 packet->production_kind = pcity->production.kind;
2620 packet->production_value = universal_number(&pcity->production);
2621
2622 packet->turn_last_built=pcity->turn_last_built;
2623 packet->turn_founded = pcity->turn_founded;
2624
2625 packet->changed_from_kind = pcity->changed_from.kind;
2627
2629 packet->disbanded_shields=pcity->disbanded_shields;
2630 packet->caravan_shields=pcity->caravan_shields;
2632
2633 worklist_copy(&packet->worklist, &pcity->worklist);
2634 packet->diplomat_investigate=dipl_invest;
2635
2636 packet->airlift = pcity->airlift;
2637 packet->did_buy = pcity->did_buy;
2638 packet->did_sell = pcity->did_sell;
2639 packet->was_happy = pcity->was_happy;
2640
2641 packet->walls = city_citywalls_gfx(pcity);
2642 packet->style = pcity->style;
2643 packet->city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2644 packet->capital = pcity->capital;
2645 packet->steal = pcity->steal;
2646
2647 rally_packet->city_id32 = pcity->id;
2648 rally_packet->city_id16 = rally_packet->city_id32;
2649 rally_packet->length = pcity->rally_point.length;
2650 rally_packet->persistent = pcity->rally_point.persistent;
2651 rally_packet->vigilant = pcity->rally_point.vigilant;
2652 if (pcity->rally_point.length) {
2653 memcpy(rally_packet->orders, pcity->rally_point.orders,
2654 pcity->rally_point.length * sizeof(struct unit_order));
2655 }
2656
2657 BV_CLR_ALL(packet->improvements);
2658 improvement_iterate(pimprove) {
2659 if (city_has_building(pcity, pimprove)) {
2660 BV_SET(packet->improvements, improvement_index(pimprove));
2661 }
2663
2664#ifdef FREECIV_WEB
2665 web_packet->id32 = pcity->id;
2666 web_packet->id16 = web_packet->id32;
2667
2668 web_packet->granary_size = city_granary_size(city_size_get(pcity));
2669 web_packet->granary_turns = city_turns_to_grow(pcity);
2670#endif /* FREECIV_WEB */
2671}
2672
2673/************************************************************************/
2683bool update_dumb_city(struct player *pplayer, struct city *pcity)
2684{
2685 bv_imprs improvements;
2686 struct tile *pcenter = city_tile(pcity);
2687 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2688 /* pcity->client.occupied isn't used at the server, so we go straight to the
2689 * unit list to check the occupied status. */
2690 bool occupied = (unit_list_size(pcenter->units) > 0);
2691 int walls = city_citywalls_gfx(pcity);
2692 bool happy = city_happy(pcity);
2693 bool unhappy = city_unhappy(pcity);
2694 int style = pcity->style;
2695 int city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2696 enum capital_type capital = pcity->capital;
2697
2699 improvement_iterate(pimprove) {
2700 if (is_improvement_visible(pimprove)
2701 && city_has_building(pcity, pimprove)) {
2703 }
2705
2706 if (NULL == pdcity) {
2707 pdcity = vision_site_new_from_city(pcity);
2708 change_playertile_site(map_get_player_tile(pcenter, pplayer), pdcity);
2709 } else if (pdcity->location != pcenter) {
2710 log_error("Trying to update bad city (wrong location) "
2711 "at %i,%i for player %s",
2712 TILE_XY(pcity->tile), player_name(pplayer));
2713 fc_assert(pdcity->location == pcenter);
2714 pdcity->location = pcenter; /* ?? */
2715 } else if (pdcity->identity != pcity->id) {
2716 log_error("Trying to update old city (wrong identity) "
2717 "at %i,%i for player %s",
2718 TILE_XY(city_tile(pcity)), player_name(pplayer));
2719 fc_assert(pdcity->identity == pcity->id);
2720 pdcity->identity = pcity->id; /* ?? */
2721 } else if (pdcity->occupied == occupied
2722 && pdcity->walls == walls
2723 && pdcity->happy == happy
2724 && pdcity->unhappy == unhappy
2725 && pdcity->style == style
2726 && pdcity->city_image == city_image
2727 && pdcity->capital == capital
2729 && vision_site_size_get(pdcity) == city_size_get(pcity)
2730 && vision_site_owner(pdcity) == city_owner(pcity)
2731 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2732 return FALSE;
2733 }
2734
2735 vision_site_update_from_city(pdcity, pcity);
2736 pdcity->occupied = occupied;
2737 pdcity->walls = walls;
2738 pdcity->style = style;
2739 pdcity->city_image = city_image;
2740 pdcity->capital = capital;
2741 pdcity->happy = happy;
2742 pdcity->unhappy = unhappy;
2743 pdcity->improvements = improvements;
2744
2745 return TRUE;
2746}
2747
2748/************************************************************************/
2751void reality_check_city(struct player *pplayer, struct tile *ptile)
2752{
2753 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2754
2755 if (pdcity) {
2756 struct city *pcity = tile_city(ptile);
2757
2758 if (!pcity || pcity->id != pdcity->identity) {
2759 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2760
2762 pdcity->identity, pdcity->identity);
2763 fc_assert_ret(playtile->site == pdcity);
2764 playtile->site = NULL;
2765 vision_site_destroy(pdcity);
2766 }
2767 }
2768}
2769
2770/************************************************************************/
2773void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2774{
2775 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2776
2777 if (pdcity) {
2778 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2779
2781 pdcity->identity, pdcity->identity);
2782 fc_assert_ret(playtile->site == pdcity);
2783 playtile->site = NULL;
2784 vision_site_destroy(pdcity);
2785 }
2786}
2787
2788/************************************************************************/
2792static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2793 bool source_gone)
2794{
2795 struct player *plr1 = city_owner(pc1);
2796 struct player *plr2 = city_owner(pc2);
2797 char city1_link[MAX_LEN_LINK];
2798 char city2_link[MAX_LEN_LINK];
2799
2800 sz_strlcpy(city1_link, city_link(pc1));
2801 sz_strlcpy(city2_link, city_link(pc2));
2802
2803 if (plr1 == plr2) {
2804 if (source_gone) {
2805 notify_player(plr2, city_tile(pc2),
2806 E_CARAVAN_ACTION, ftc_server,
2807 _("Trade between %s and %s lost along with city."),
2808 city1_link, city2_link);
2809 } else {
2810 notify_player(plr1, city_tile(pc1),
2811 E_CARAVAN_ACTION, ftc_server,
2812 _("Trade route between %s and %s canceled."),
2813 city1_link, city2_link);
2814 }
2815 } else {
2816 if (source_gone) {
2817 notify_player(plr2, city_tile(pc2),
2818 E_CARAVAN_ACTION, ftc_server,
2819 /* TRANS: "...between Spanish city Madrid and Paris..." */
2820 _("Trade between %s city %s and %s lost along with "
2821 "their city."),
2822 nation_adjective_for_player(plr1), city1_link, city2_link);
2823 /* It's implicit to removed city's owner that that city no longer
2824 * has trade routes, so say nothing in that case */
2825 } else {
2826 notify_player(plr2, city_tile(pc2),
2827 E_CARAVAN_ACTION, ftc_server,
2828 _("Sorry, the %s canceled the trade route "
2829 "from %s to your city %s."),
2830 nation_plural_for_player(plr1), city1_link, city2_link);
2831 notify_player(plr1, city_tile(pc1),
2832 E_CARAVAN_ACTION, ftc_server,
2833 /* TRANS: "...from Paris to Spanish city Madrid." */
2834 _("We canceled the trade route "
2835 "from %s to %s city %s."),
2836 city1_link, nation_adjective_for_player(plr2), city2_link);
2837 }
2838 }
2839}
2840
2841/************************************************************************/
2849struct trade_route *remove_trade_route(struct city *pc1, struct trade_route *proute,
2850 bool announce, bool source_gone)
2851{
2852 struct city *pc2 = game_city_by_number(proute->partner);
2853 struct trade_route *back_route = NULL;
2854
2855 fc_assert_ret_val(pc1 && proute, NULL);
2856
2857 trade_route_list_remove(pc1->routes, proute);
2858
2859 if (pc2 != NULL) {
2860 trade_routes_iterate(pc2, pback) {
2861 if (pc1->id == pback->partner) {
2862 back_route = pback;
2863 }
2865
2866 if (back_route != NULL) {
2867 trade_route_list_remove(pc2->routes, back_route);
2868 }
2869
2870 if (announce) {
2871 announce_trade_route_removal(pc1, pc2, source_gone);
2872
2873 city_refresh(pc2);
2874 send_city_info(city_owner(pc2), pc2);
2875 }
2876 }
2877
2878 return back_route;
2879}
2880
2881/**********************************************************************/
2884bool city_illness_strike(struct city *pcity)
2885{
2886 notify_player(city_owner(pcity), city_tile(pcity), E_CITY_PLAGUE,
2887 ftc_server,
2888 _("%s has been struck by a plague! Population lost!"),
2889 city_link(pcity));
2890 if (city_reduce_size(pcity, 1, NULL, "plague")) {
2891 pcity->turn_plague = game.info.turn;
2892
2893 /* recalculate illness */
2894 pcity->server.illness
2895 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade),
2896 NULL);
2897
2898 return TRUE;
2899 }
2900
2901 return FALSE;
2902}
2903
2904/************************************************************************/
2910void do_sell_building(struct player *pplayer, struct city *pcity,
2911 struct impr_type *pimprove, const char *reason)
2912{
2913 if (can_city_sell_building(pcity, pimprove)) {
2914 pplayer->economic.gold += impr_sell_gold(pimprove);
2915 building_lost(pcity, pimprove, reason, NULL);
2916 }
2917}
2918
2919/************************************************************************/
2931struct city
2932*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
2933 struct player **oldcity_owner)
2934{
2935 struct city *oldcity = NULL;
2936
2937 fc_assert_ret_val(!city_has_building(pcity, pimprove), NULL);
2938 if (is_great_wonder(pimprove)) {
2939 if (!(oldcity = city_from_great_wonder(pimprove))) {
2940 oldcity = pcity;
2941 }
2942 *oldcity_owner = city_owner(oldcity);
2943 } else if (is_small_wonder(pimprove)) {
2944 if (!(oldcity
2945 = city_from_small_wonder(city_owner(pcity), pimprove))) {
2946 oldcity = pcity;
2947 }
2948 }
2949 if (oldcity && oldcity != pcity) {
2950 city_remove_improvement(oldcity, pimprove);
2951 }
2952
2953 city_add_improvement(pcity, pimprove);
2954 return oldcity;
2955}
2956
2957/************************************************************************/
2960bool building_removed(struct city *pcity, const struct impr_type *pimprove,
2961 const char *reason, struct unit *destroyer)
2962{
2963 int backup = pcity->id;
2964
2965 city_remove_improvement(pcity, pimprove);
2966
2967 script_server_signal_emit("building_lost", pcity, pimprove, reason,
2968 destroyer);
2969
2970 return city_exist(backup);
2971}
2972
2973/************************************************************************/
2977void building_lost(struct city *pcity, const struct impr_type *pimprove,
2978 const char *reason, struct unit *destroyer)
2979{
2980 struct player *owner = city_owner(pcity);
2981 bool was_capital = is_capital(pcity);
2982 bool city_remains;
2983
2984 city_remains = building_removed(pcity, pimprove, reason, destroyer);
2985
2986 if ((was_capital && (!city_remains || !is_capital(pcity)))
2987 && (owner->spaceship.state == SSHIP_STARTED
2988 || owner->spaceship.state == SSHIP_LAUNCHED)) {
2989 /* If the capital was lost (by destruction of the palace) production on
2990 * the spaceship is lost. */
2992 }
2993
2994 if (city_remains) {
2995 /* update city; influence of effects (buildings, ...) on unit upkeep */
2996 if (city_refresh(pcity)) {
2997 auto_arrange_workers(pcity);
2998 }
2999
3000 /* Re-update the city's visible area. This updates fog if the vision
3001 * range increases or decreases. */
3002 city_refresh_vision(pcity);
3003 }
3004}
3005
3006/************************************************************************/
3026void city_units_upkeep(const struct city *pcity)
3027{
3028 int free_uk[O_LAST];
3029
3030 if (!pcity || !pcity->units_supported
3031 || unit_list_size(pcity->units_supported) < 1) {
3032 return;
3033 }
3034
3036 free_uk[o] = get_city_output_bonus(pcity, get_output_type(o),
3037 EFT_UNIT_UPKEEP_FREE_PER_CITY);
3039
3040 /* Save the upkeep for all units in the corresponding punit struct */
3042 const struct unit_type *ut = unit_type_get(punit);
3043 struct player *plr = unit_owner(punit);
3044 bool update = FALSE;
3045 int cost;
3046
3048 cost = utype_upkeep_cost(ut, plr, o);
3049 if (cost > 0) {
3050 if (free_uk[o] > cost) {
3051 free_uk[o] -= cost;
3052 cost = 0;
3053 } else {
3054 cost -= free_uk[o];
3055 free_uk[o] = 0;
3056 }
3057 }
3058
3059 if (cost != punit->upkeep[o]) {
3060 update = TRUE;
3061 punit->upkeep[o] = cost;
3062 }
3064
3065 if (update) {
3066 /* Update unit information to the player and global observers. */
3067 send_unit_info(NULL, punit);
3068 }
3070}
3071
3072/************************************************************************/
3075void change_build_target(struct player *pplayer, struct city *pcity,
3076 struct universal *target,
3077 enum event_type event)
3078{
3079 const char *name;
3080 const char *source;
3081
3082 /* If the city is already building this thing, don't do anything */
3083 if (are_universals_equal(&pcity->production, target)) {
3084 return;
3085 }
3086
3087 /* Is the city no longer building a wonder? */
3088 if (VUT_IMPROVEMENT == pcity->production.kind
3090 && event != E_IMP_AUTO
3091 && event != E_WORKLIST) {
3092 /* If the build target is changed because of an advisor's suggestion or
3093 because the worklist advances, then the wonder was completed --
3094 don't announce that the player has *stopped* building that wonder.
3095 */
3096 notify_player(NULL, city_tile(pcity), E_WONDER_STOPPED, ftc_server,
3097 _("The %s have stopped building The %s in %s."),
3098 nation_plural_for_player(pplayer),
3100 city_link(pcity));
3101 }
3102
3103 /* Manage the city change-production penalty.
3104 (May penalize, restore or do nothing to the shield_stock.) */
3105 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3106 pcity->shield_stock = city_change_production_penalty(pcity, target);
3107 }
3108
3109 /* Change build target. */
3110 pcity->production = *target;
3111
3112 /* What's the name of the target? */
3114
3115 switch (event) {
3116 case E_WORKLIST:
3117 /* TRANS: Possible 'source' of the production change
3118 * (in "<city> is building ..." sentence). Preserve leading space. */
3119 source = _(" from the worklist");
3120 break;
3121 case E_IMP_AUTO:
3122 /* TRANS: Possible 'source' of the production change
3123 * (in "<city> is building ..." sentence). Preserve leading space. */
3124 source = _(" as suggested by the advisor");
3125 break;
3126 default:
3127 source = "";
3128 break;
3129 }
3130
3131 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3132 city_name_get(pcity), name, source);
3133
3134 /* Tell the player what's up. */
3135 /* FIXME: this may give bad grammar when translated if the 'source'
3136 * string can have multiple values. */
3137 notify_player(pplayer, city_tile(pcity), event, ftc_server,
3138 /* TRANS: "<city> is building <production><source>."
3139 * 'source' might be an empty string, or a clause like
3140 * " from the worklist". */
3141 _("%s is building %s%s."),
3142 city_link(pcity),
3143 name, source);
3144
3145 /* If the city is building a wonder, tell the rest of the world
3146 about it. */
3147 if (VUT_IMPROVEMENT == pcity->production.kind
3149 notify_player(NULL, city_tile(pcity), E_WONDER_STARTED, ftc_server,
3150 _("The %s have started building The %s in %s."),
3151 nation_plural_for_player(pplayer),
3152 name,
3153 city_link(pcity));
3154 }
3155}
3156
3157/************************************************************************/
3164void city_map_update_empty(struct city *pcity, struct tile *ptile)
3165{
3166 tile_set_worked(ptile, NULL);
3167 send_tile_info(NULL, ptile, FALSE);
3168 pcity->server.synced = FALSE;
3169}
3170
3171/************************************************************************/
3178void city_map_update_worker(struct city *pcity, struct tile *ptile)
3179{
3180 tile_set_worked(ptile, pcity);
3181 send_tile_info(NULL, ptile, FALSE);
3182 pcity->server.synced = FALSE;
3183}
3184
3185/************************************************************************/
3190static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3191{
3192 struct city *pwork = tile_worked(ptile);
3193
3194 if (NULL != pwork
3195 && !is_free_worked(pwork, ptile)
3196 && !city_can_work_tile(pwork, ptile)) {
3197 tile_set_worked(ptile, NULL);
3198 send_tile_info(NULL, ptile, FALSE);
3199
3200 pwork->specialists[DEFAULT_SPECIALIST]++; /* keep city sanity */
3201 pwork->server.synced = FALSE;
3202
3203 if (queued) {
3204 city_freeze_workers_queue(pwork); /* place the displaced later */
3205 } else {
3206 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3207 auto_arrange_workers(pwork);
3208 send_city_info(NULL, pwork);
3209 }
3210 return TRUE;
3211 }
3212
3213 return FALSE;
3214}
3215
3216/************************************************************************/
3222{
3223 return city_map_update_tile_direct(ptile, TRUE);
3224}
3225
3226/************************************************************************/
3230{
3231 return city_map_update_tile_direct(ptile, FALSE);
3232}
3233
3234/************************************************************************/
3238void sync_cities(void)
3239{
3241 return;
3242 }
3243
3244 players_iterate(pplayer) {
3245 city_list_iterate(pplayer->cities, pcity) {
3246 if (!pcity->server.synced) {
3247 /* sending will set to TRUE. */
3248 send_city_info(pplayer, pcity);
3249 }
3252}
3253
3254/************************************************************************/
3257void city_map_update_all(struct city *pcity)
3258{
3259 struct tile *pcenter = city_tile(pcity);
3260 const struct civ_map *nmap = &(wld.map);
3261
3263 ptile, _index, _x, _y) {
3264 /* bypass city_map_update_tile_now() for efficiency */
3267}
3268
3269/************************************************************************/
3273{
3274 city_list_iterate(pplayer->cities, pcity) {
3275 city_freeze_workers(pcity);
3276 city_map_update_all(pcity);
3277 city_thaw_workers(pcity);
3279}
3280
3281/************************************************************************/
3292{
3293 adjc_iterate(&(wld.map), ptile, tile1) {
3294 struct city *pcity = tile_city(tile1);
3295
3296 if (pcity) {
3297 struct player *pplayer = city_owner(pcity);
3298 const struct req_context city_ctxt = {
3299 .player = pplayer,
3300 .city = pcity,
3301 .tile = pcity->tile,
3302 };
3303
3304 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3305 city_built_iterate(pcity, pimprove) {
3306 if (!can_city_sell_building(pcity, pimprove)) {
3307 continue;
3308 }
3309
3310 requirement_vector_iterate(&pimprove->reqs, preq) {
3311 if ((VUT_TERRAIN == preq->source.kind
3312 || VUT_TERRAINCLASS == preq->source.kind
3313 || VUT_TERRFLAG == preq->source.kind)
3314 && !is_req_active(&city_ctxt, NULL, preq, RPT_CERTAIN)) {
3315 int price = impr_sell_gold(pimprove);
3316
3317 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3318 notify_player(pplayer, tile1, E_IMP_SOLD, ftc_server,
3319 PL_("You sell %s in %s (now landlocked)"
3320 " for %d gold.",
3321 "You sell %s in %s (now landlocked)"
3322 " for %d gold.", price),
3324 city_link(pcity), price);
3325 }
3328 }
3330}
3331
3332/************************************************************************/
3338void city_refresh_vision(struct city *pcity)
3339{
3340 if (pcity->server.vision != NULL) {
3341 v_radius_t vision_radius_sq
3342 = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2);
3343
3344 vision_change_sight(pcity->server.vision, vision_radius_sq);
3345 ASSERT_VISION(pcity->server.vision);
3346 }
3347}
3348
3349/************************************************************************/
3354{
3355 city_list_iterate(pplayer->cities, pcity) {
3356 city_refresh_vision(pcity);
3358}
3359
3360/************************************************************************/
3364{
3365 fc_assert_ret_val(pcity != NULL, FALSE);
3366
3367 int city_tiles_old, city_tiles_new;
3368 int city_radius_sq_old = city_map_radius_sq_get(pcity);
3369 int city_radius_sq_new = game.info.init_city_radius_sq
3370 + get_city_bonus(pcity, EFT_CITY_RADIUS_SQ);
3371 const struct civ_map *nmap = &(wld.map);
3372
3373 /* Check minimum / maximum allowed city radii */
3374 city_radius_sq_new = CLIP(CITY_MAP_MIN_RADIUS_SQ, city_radius_sq_new,
3376
3377 if (city_radius_sq_new == city_radius_sq_old) {
3378 /* No change */
3379 return FALSE;
3380 }
3381
3382 /* Get number of city tiles for each radii */
3383 city_tiles_old = city_map_tiles(city_radius_sq_old);
3384 city_tiles_new = city_map_tiles(city_radius_sq_new);
3385
3386 if (city_tiles_old == city_tiles_new) {
3387 /* A change of the squared city radius but no change of the number of
3388 * city tiles */
3389 return FALSE;;
3390 }
3391
3392 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3393 pcity->id, city_radius_sq_old, city_radius_sq_new);
3394
3395 /* Workers map before */
3396 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3397 city_name_get(pcity), pcity->id, city_size_get(pcity),
3398 city_specialists(pcity));
3400
3401 city_map_radius_sq_set(pcity, city_radius_sq_new);
3402
3403 if (city_tiles_old < city_tiles_new) {
3404 /* Increased number of city tiles */
3405 city_refresh_vision(pcity);
3406 } else {
3407 /* Reduced number of city tiles */
3408 int workers = 0;
3409
3410 /* Remove workers from the tiles removed rom the city map */
3411 city_map_iterate_radius_sq(city_radius_sq_new, city_radius_sq_old,
3412 city_x, city_y) {
3413 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3414 city_radius_sq_old, city_x,
3415 city_y);
3416
3417 if (ptile && pcity == tile_worked(ptile)) {
3418 city_map_update_empty(pcity, ptile);
3419 workers++;
3420 }
3422
3423 /* add workers to free city tiles */
3424 if (workers > 0) {
3425 int radius_sq = city_map_radius_sq_get(pcity);
3426
3427 city_map_iterate_without_index(radius_sq, city_x, city_y) {
3428 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3429 city_x, city_y);
3430
3431 if (ptile && !is_free_worked(pcity, ptile)
3432 && tile_worked(ptile) != pcity
3433 && city_can_work_tile(pcity, ptile)) {
3434 city_map_update_worker(pcity, ptile);
3435 workers--;
3436 }
3437
3438 if (workers <= 0) {
3439 break;
3440 }
3442 }
3443
3444 /* If there are still workers they will be updated to specialists */
3445 if (workers > 0) {
3446 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3447 }
3448
3449 city_refresh_vision(pcity);
3450 }
3451
3452 /* City removal might be ongoing, and advisor data already deleted */
3453 if (pcity->server.adv != NULL) {
3454 /* If city is under AI control, update it */
3455 adv_city_update(pcity);
3456 }
3457
3458 notify_player(city_owner(pcity), city_tile(pcity), E_CITY_RADIUS_SQ,
3459 ftc_server, _("The size of the city map of %s is %s."),
3460 city_name_get(pcity),
3461 city_tiles_old < city_tiles_new ? _("increased")
3462 : _("reduced"));
3463
3464 /* Workers map after */
3465 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3466 city_name_get(pcity), pcity->id, city_size_get(pcity),
3467 city_specialists(pcity));
3469
3470 return TRUE;
3471}
3472
3473/************************************************************************/
3476void clear_worker_task(struct city *pcity, struct worker_task *ptask)
3477{
3478 struct packet_worker_task packet;
3479
3480 if (ptask == NULL) {
3481 return;
3482 }
3483
3484 worker_task_list_remove(pcity->task_reqs, ptask);
3485
3486 packet.city_id32 = pcity->id;
3487 packet.city_id16 = packet.city_id32;
3488 packet.tile_id = tile_index(ptask->ptile);
3489 packet.activity = ACTIVITY_LAST;
3490 packet.tgt = 0;
3491 packet.want = 0;
3492
3493 free(ptask);
3494
3497}
3498
3499/************************************************************************/
3502void clear_worker_tasks(struct city *pcity)
3503{
3504 while (worker_task_list_size(pcity->task_reqs) > 0) {
3505 clear_worker_task(pcity, worker_task_list_get(pcity->task_reqs, 0));
3506 }
3507}
3508
3509/************************************************************************/
3513{
3514 struct packet_worker_task packet;
3515
3516 packet.city_id32 = pcity->id;
3517 packet.city_id16 = packet.city_id32;
3518
3519 worker_task_list_iterate(pcity->task_reqs, ptask) {
3520 packet.tile_id = tile_index(ptask->ptile);
3521 packet.activity = ptask->act;
3522 if (ptask->tgt == NULL) {
3523 packet.tgt = -1;
3524 } else {
3525 packet.tgt = extra_number(ptask->tgt);
3526 }
3527 packet.want = ptask->want;
3528
3532}
3533
3534/************************************************************************/
3537int city_production_buy_gold_cost(const struct city *pcity)
3538{
3539 int build = pcity->shield_stock;
3540
3541 switch (pcity->production.kind) {
3542 case VUT_IMPROVEMENT:
3543 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3544 build);
3545 case VUT_UTYPE:
3546 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3547 build);
3548 default:
3549 break;
3550 };
3551
3552 return FC_INFINITY;
3553}
3554
3555/************************************************************************/
3559int city_original_owner(const struct city *pcity,
3560 const struct player *known_for)
3561{
3562 if (pcity->original == NULL) {
3563 /* Nobody knows */
3564 return MAX_NUM_PLAYER_SLOTS;
3565 }
3566
3567 if (pcity->original != known_for
3568 || known_for == NULL) {
3569 /* Players know what they have built themselves,
3570 * global observer knows everything. */
3571 return player_number(pcity->original);
3572 }
3573
3574 return MAX_NUM_PLAYER_SLOTS;
3575}
const struct action * action_auto_perf_unit_do(const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit, const struct extra_type *target_extra)
void advisor_choose_build(struct player *pplayer, struct city *pcity)
int adv_could_unit_move_to_tile(struct unit *punit, struct tile *dest_tile)
Definition advgoto.c:348
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
#define n
Definition astring.c:77
bool is_land_barbarian(struct player *pplayer)
Definition barbarian.c:75
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:144
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:113
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_ISSET_ANY(vec)
Definition bitvector.h:109
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
void citizens_init(struct city *pcity)
Definition citizens.c:32
void citizens_convert_conquest(struct city *pcity)
void citizens_update(struct city *pcity, struct player *plr)
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3500
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:143
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:722
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1123
int city_granary_size(int city_size)
Definition city.c:2104
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2168
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1065
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:300
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1216
bool is_capital(const struct city *pcity)
Definition city.c:1552
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3284
struct output_type * get_output_type(Output_type_id output)
Definition city.c:633
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2158
bool city_unhappy(const struct city *pcity)
Definition city.c:1599
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3343
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1652
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2772
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1859
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1460
bool city_happy(const struct city *pcity)
Definition city.c:1587
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3270
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:441
citizens city_specialists(const struct city *pcity)
Definition city.c:3230
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1668
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:991
int city_map_tiles(int city_radius_sq)
Definition city.c:166
bool city_exist(int id)
Definition city.c:3471
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1429
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1969
void city_rally_point_clear(struct city *pcity)
Definition city.c:3525
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:695
#define cities_iterate_end
Definition city.h:497
@ CNA_BROADCAST_PENDING
Definition city.h:300
@ CNA_NOT
Definition city.h:298
@ CNA_NORMAL
Definition city.h:299
#define city_list_iterate(citylist, pcity)
Definition city.h:488
#define city_tile(_pcity_)
Definition city.h:544
#define cities_iterate(pcity)
Definition city.h:492
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:78
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:206
@ CITIZEN_ANGRY
Definition city.h:263
@ CITIZEN_HAPPY
Definition city.h:260
@ CITIZEN_CONTENT
Definition city.h:261
@ CITIZEN_UNHAPPY
Definition city.h:262
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:76
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
Definition city.h:180
#define output_type_iterate(output)
Definition city.h:821
#define city_owner(_pcity_)
Definition city.h:543
#define city_tile_iterate_skip_free_worked_end
Definition city.h:214
#define city_list_iterate_end
Definition city.h:490
#define city_map_iterate_radius_sq_end
Definition city.h:185
@ FEELING_LAST
Definition city.h:277
#define city_built_iterate(_pcity, _p)
Definition city.h:810
#define city_map_iterate_without_index_end
Definition city.h:176
#define city_built_iterate_end
Definition city.h:816
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:172
#define output_type_iterate_end
Definition city.h:827
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3164
void city_freeze_workers_queue(struct city *pcity)
Definition citytools.c:159
void package_city(struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct trade_route_packet_list *routes, bool dipl_invest)
Definition citytools.c:2480
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3229
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:456
static int city_citywalls_gfx(const struct city *pcity)
Definition citytools.c:2133
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3190
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3512
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3537
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2327
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2683
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:2932
static void raze_city(struct city *pcity)
Definition citytools.c:926
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1416
static bool city_workers_queue_remove(struct city *pcity)
Definition citytools.c:183
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:854
void refresh_dumb_city(struct city *pcity)
Definition citytools.c:2188
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2154
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1495
bool send_city_suppression(bool now)
Definition citytools.c:2143
static bool send_city_suppressed
Definition citytools.c:100
void sync_cities(void)
Definition citytools.c:3238
static const char * search_for_city_name(struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
Definition citytools.c:337
static void announce_trade_route_removal(struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
Definition citytools.c:2792
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:135
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3353
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3559
static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders)
Definition citytools.c:1012
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3363
int build_points_left(struct city *pcity)
Definition citytools.c:574
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3075
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:2960
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3272
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2884
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3221
void city_thaw_workers(struct city *pcity)
Definition citytools.c:145
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2773
static bool is_default_city_name(const char *name, struct player *pplayer)
Definition citytools.c:319
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:2977
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1963
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3476
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:959
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3026
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3502
bool is_allowed_city_name(struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
Definition citytools.c:372
static void transfer_unit(struct unit *punit, struct city *tocity, bool rehome, bool verbose)
Definition citytools.c:588
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
Definition citytools.c:3291
void remove_city(struct city *pcity)
Definition citytools.c:1684
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:2910
static struct city_list * arrange_workers_queue
Definition citytools.c:97
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2849
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1656
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2376
static int evaluate_city_name_priority(struct tile *ptile, const struct nation_city *pncity, int default_priority)
Definition citytools.c:218
void city_thaw_workers_queue(void)
Definition citytools.c:196
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2217
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Definition citytools.c:1070
void send_player_cities(struct player *pplayer)
Definition citytools.c:2307
void city_map_update_all(struct city *pcity)
Definition citytools.c:3257
void transfer_city_units(struct player *pplayer, struct player *pvictim, struct unit_list *units, struct city *pcity, struct city *exclude_city, int kill_outside, bool verbose)
Definition citytools.c:719
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Definition citytools.c:3178
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2751
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2284
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3338
#define trade_route_packet_list_iterate_end
Definition citytools.h:28
#define LOG_BUILD_TARGET
Definition citytools.h:21
#define trade_route_packet_list_iterate(ptrlist, ptr)
Definition citytools.h:26
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:369
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:200
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3379
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:808
bool city_refresh(struct city *pcity)
Definition cityturn.c:161
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:185
void city_refresh_queue_processing(void)
Definition cityturn.c:216
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:238
enum announce_type announce
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:365
struct connection * conn_by_user(const char *user_name)
Definition connection.c:376
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:355
bool conn_is_global_observer(const struct connection *pconn)
Definition connection.c:750
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
#define conn_list_iterate_end
Definition connection.h:115
int city_culture(const struct city *pcity)
Definition culture.c:29
static void homeless(QVariant data1, QVariant data2)
Definition dialogs.cpp:2397
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:73
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 int cost
Definition dialogs_g.h:73
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:992
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:906
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
enum event_type event
Definition events.c:81
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:608
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_type_iterate_end
Definition extras.h:297
#define extra_road_get(_e_)
Definition extras.h:185
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
#define MAX_NUM_BUILDING_LIST
Definition fc_types.h:46
unsigned char citizens
Definition fc_types.h:358
int Impr_type_id
Definition fc_types.h:346
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
@ RPT_CERTAIN
Definition fc_types.h:586
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
@ O_LAST
Definition fc_types.h:91
#define MAX_LEN_CITYNAME
Definition fc_types.h:67
signed short Continent_id
Definition fc_types.h:342
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
void fc_allocate_mutex(fc_mutex *mutex)
void fc_release_mutex(fc_mutex *mutex)
const char * city_tile_link(const struct city *pcity)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
const char * unit_link(const struct unit *punit)
const char * unit_tile_link(const struct unit *punit)
#define MAX_LEN_LINK
struct civ_game game
Definition game.c:57
struct city * game_city_by_name(const char *name)
Definition game.c:83
struct world wld
Definition game.c:58
struct unit * game_unit_by_number(int id)
Definition game.c:111
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:173
struct city * game_city_by_number(int id)
Definition game.c:102
@ CNM_PLAYER_UNIQUE
Definition game.h:46
@ CNM_GLOBAL_UNIQUE
Definition game.h:47
@ CNM_NO_STEALING
Definition game.h:48
void send_game_info(struct conn_list *dest)
Definition gamehand.c:905
struct city * owner
Definition citydlg.c:219
static GtkWidget * source
Definition gotodlg.c:58
GType type
Definition repodlgs.c:1312
static const int bufsz
Definition helpdlg.c:70
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_PRODCHGPEN
Definition handicaps.h:35
void idex_register_city(struct world *iworld, struct city *pcity)
Definition idex.c:66
struct impr_type * improvement_by_number(const Impr_type_id id)
int impr_sell_gold(const struct impr_type *pimprove)
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
bool is_improvement_visible(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
struct city * city_from_great_wonder(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
void adv_city_free(struct city *pcity)
Definition infracache.c:501
void adv_city_update(struct city *pcity)
Definition infracache.c:462
void adv_city_alloc(struct city *pcity)
Definition infracache.c:488
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:205
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_base(level, message,...)
Definition log.h:94
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
int map_num_tiles(void)
Definition map.c:1012
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Definition map.c:665
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:628
#define adjc_iterate_end
Definition map.h:427
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:422
#define whole_map_iterate(_map, _tile)
Definition map.h:539
#define whole_map_iterate_end
Definition map.h:548
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2517
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2191
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:886
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2605
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:488
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1346
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:760
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:415
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2708
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:900
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1140
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2270
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1427
struct vision_site * map_get_player_site(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1359
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:238
void map_clear_border(struct tile *ptile)
Definition maphand.c:2221
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1370
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2505
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:275
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:316
bool is_city_channel_tile(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
Definition movement.c:228
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:476
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:450
const char * nation_city_name(const struct nation_city *pncity)
Definition nation.c:411
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Definition nation.c:330
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
enum nation_city_preference nation_city_preference_revert(enum nation_city_preference prefer)
Definition nation.c:370
Nation_type_id nation_count(void)
Definition nation.c:506
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:462
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
enum nation_city_preference nation_city_terrain_preference(const struct nation_city *pncity, const struct terrain *pterrain)
Definition nation.c:421
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Definition nation.c:433
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:497
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:83
nation_city_preference
Definition nation.h:38
@ NCP_NONE
Definition nation.h:40
@ NCP_DISLIKE
Definition nation.h:39
@ NCP_LIKE
Definition nation.h:41
#define nation_city_list_iterate(citylist, pncity)
Definition nation.h:47
#define nation_list_iterate_end
Definition nation.h:85
#define nation_city_list_iterate_end
Definition nation.h:49
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
#define web_send_packet(packetname,...)
Definition packets.h:52
#define web_lsend_packet(packetname,...)
Definition packets.h:53
int send_packet_city_rally_point(struct connection *pc, const struct packet_city_rally_point *packet, bool force_to_send)
void lsend_packet_city_nationalities(struct conn_list *dest, const struct packet_city_nationalities *packet, bool force_to_send)
void dlsend_packet_city_remove(struct conn_list *dest, int city_id16, int city_id32)
int dsend_packet_city_remove(struct connection *pc, int city_id16, int city_id32)
int send_packet_city_info(struct connection *pc, const struct packet_city_info *packet, bool force_to_send)
void lsend_packet_trade_route_info(struct conn_list *dest, const struct packet_trade_route_info *packet)
int send_packet_trade_route_info(struct connection *pc, const struct packet_trade_route_info *packet)
void lsend_packet_city_info(struct conn_list *dest, const struct packet_city_info *packet, bool force_to_send)
int send_packet_city_nationalities(struct connection *pc, const struct packet_city_nationalities *packet, bool force_to_send)
void lsend_packet_city_short_info(struct conn_list *dest, const struct packet_city_short_info *packet)
void lsend_packet_worker_task(struct conn_list *dest, const struct packet_worker_task *packet)
void lsend_packet_city_rally_point(struct conn_list *dest, const struct packet_city_rally_point *packet, bool force_to_send)
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1084
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1364
int player_slot_index(const struct player_slot *pslot)
Definition player.c:419
int player_index(const struct player *pplayer)
Definition player.c:820
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1143
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1113
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:430
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1129
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
#define player_slots_iterate(_pslot)
Definition player.h:521
#define is_ai(plr)
Definition player.h:234
#define player_slots_iterate_end
Definition player.h:525
int normal_player_count(void)
Definition plrhand.c:3034
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2785
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2191
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:2835
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2738
void update_capital(struct player *pplayer)
Definition plrhand.c:612
#define allowed_nations_iterate(pnation)
Definition plrhand.h:67
#define allowed_nations_iterate_end
Definition plrhand.h:71
#define fc_rand(_size)
Definition rand.h:34
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
int universal_number(const struct universal *source)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
struct research * research_get(const struct player *pplayer)
Definition research.c:126
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
#define sanity_check_city(x)
Definition sanitycheck.h:41
void script_server_signal_emit(const char *signal_name,...)
void script_server_remove_exported_object(void *object)
static struct connection connections[MAX_NUM_CONNECTIONS]
Definition sernet.c:94
void flush_packets(void)
Definition sernet.c:379
static struct setting settings[]
Definition settings.c:1378
bool is_ascii_name(const char *name)
Definition shared.c:282
#define CLIP(lower, current, upper)
Definition shared.h:57
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
void spaceship_lost(struct player *pplayer)
Definition spacerace.c:430
@ SSHIP_STARTED
Definition spaceship.h:84
@ SSHIP_LAUNCHED
Definition spaceship.h:85
Specialist_type_id specialist_count(void)
Definition specialist.c:71
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
#define DEFAULT_SPECIALIST
Definition specialist.h:43
SPECPQ_PRIORITY_TYPE priority
Definition specpq.h:86
size_t size
Definition specvec.h:72
static int recursion[AIT_LAST]
Definition srv_log.c:44
int identity_number(void)
Definition srv_main.c:1952
enum server_states server_state(void)
Definition srv_main.c:323
int turn
Definition city.h:238
Definition city.h:309
struct worker_task_list * task_reqs
Definition city.h:395
int turn_last_built
Definition city.h:373
int surplus[O_LAST]
Definition city.h:343
int food_stock
Definition city.h:354
struct built_status built[B_LAST]
Definition city.h:380
struct player * original
Definition city.h:313
int history
Definition city.h:393
int pollution
Definition city.h:356
bool did_sell
Definition city.h:367
int id
Definition city.h:315
int last_turns_shield_surplus
Definition city.h:378
enum capital_type capital
Definition city.h:317
int disbanded_shields
Definition city.h:377
int waste[O_LAST]
Definition city.h:344
int workers_frozen
Definition city.h:420
int turn_plague
Definition city.h:361
bv_city_options city_options
Definition city.h:389
int city_radius_sq
Definition city.h:362
bool was_happy
Definition city.h:368
struct player * owner
Definition city.h:312
int turn_founded
Definition city.h:372
int airlift
Definition city.h:365
int citizen_base[O_LAST]
Definition city.h:347
int caravan_shields
Definition city.h:376
bool did_buy
Definition city.h:366
struct trade_route_list * routes
Definition city.h:332
enum city_needs_arrange needs_arrange
Definition city.h:424
int usage[O_LAST]
Definition city.h:348
struct worklist worklist
Definition city.h:387
struct universal production
Definition city.h:382
struct unit_order * orders
Definition city.h:405
struct city::@16 rally_point
struct adv_city * adv
Definition city.h:435
bool vigilant
Definition city.h:404
int steal
Definition city.h:397
int unhappy_penalty[O_LAST]
Definition city.h:345
int illness
Definition city.h:417
int before_change_shields
Definition city.h:375
int style
Definition city.h:316
size_t length
Definition city.h:400
bool synced
Definition city.h:431
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:321
citizens specialists[SP_MAX]
Definition city.h:324
struct tile * tile
Definition city.h:311
int shield_stock
Definition city.h:355
int prod[O_LAST]
Definition city.h:346
struct vision * vision
Definition city.h:438
struct city::@17::@19 server
struct cm_parameter * cm_parameter
Definition city.h:408
struct universal changed_from
Definition city.h:385
struct unit_list * units_supported
Definition city.h:391
int illness_trade
Definition city.h:357
bool persistent
Definition city.h:402
enum city_names_mode allowed_city_names
Definition game.h:126
struct civ_game::@29 rgame
struct civ_game::@30::@34 server
bool vision_reveal_tiles
Definition game.h:199
struct conn_list * glob_observers
Definition game.h:98
fc_mutex city_list
Definition game.h:267
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
bool natural_city_names
Definition game.h:166
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:108
struct civ_game::@30::@34::@38 mutexes
bool savepalace
Definition game.h:186
int razechance
Definition game.h:175
enum cmdlevel access_level
Definition connection.h:182
int init_buildings[MAX_NUM_BUILDING_LIST]
Definition nation.h:122
struct nation_list * parent_nations
Definition nation.h:135
struct nation_type::@50::@52 server
struct nation_list * civilwar_nations
Definition nation.h:134
int last_turns_shield_surplus
int usage[O_LAST]
int ppl_content[FEELING_LAST]
bv_city_options city_options
enum capital_type capital
int surplus[O_LAST]
int ppl_unhappy[FEELING_LAST]
int citizen_base[O_LAST]
int specialists[SP_MAX]
int ppl_angry[FEELING_LAST]
bv_imprs improvements
struct worklist worklist
char name[MAX_LEN_CITYNAME]
int ppl_happy[FEELING_LAST]
int prod[O_LAST]
int unhappy_penalty[O_LAST]
int waste[O_LAST]
int nation_id[MAX_CITY_NATIONALITIES]
int nation_citizens[MAX_CITY_NATIONALITIES]
struct unit_order orders[MAX_LEN_ROUTE]
enum capital_type capital
char name[MAX_LEN_CITYNAME]
enum route_direction direction
enum unit_activity activity
enum spaceship_state state
Definition spaceship.h:108
struct vision_site * site
Definition maphand.h:31
struct city_list * cities
Definition player.h:281
int primary_capital_id
Definition player.h:275
bool got_first_city
Definition player.h:320
char username[MAX_LEN_NAME]
Definition player.h:252
struct team * team
Definition player.h:261
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
struct player_economic economic
Definition player.h:284
struct player_spaceship spaceship
Definition player.h:286
struct player::@69::@71 server
const struct player * player
Definition tile.h:49
struct unit_list * units
Definition tile.h:57
Definition unit.h:138
int upkeep[O_LAST]
Definition unit.h:148
int id
Definition unit.h:145
bool moved
Definition unit.h:173
struct unit::@80::@83 server
int homecity
Definition unit.h:146
struct unit * transporter
Definition unit.h:183
const struct unit_type * utype
Definition unit.h:139
bool dying
Definition unit.h:248
enum universals_n kind
Definition fc_types.h:758
universals_u value
Definition fc_types.h:757
char * name
Definition vision.h:110
bool happy
Definition vision.h:119
bv_imprs improvements
Definition vision.h:125
struct tile * location
Definition vision.h:111
int identity
Definition vision.h:114
int walls
Definition vision.h:118
int style
Definition vision.h:121
bool unhappy
Definition vision.h:120
int city_image
Definition vision.h:122
bool occupied
Definition vision.h:117
enum capital_type capital
Definition vision.h:123
v_radius_t radius_sq
Definition vision.h:92
struct tile * ptile
Definition workertask.h:22
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define sz_strlcpy(dest, src)
Definition support.h:167
#define fc__attribute(x)
Definition support.h:89
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
#define A_UNSET
Definition tech.h:48
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1208
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:600
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
bool is_terrain_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:336
#define terrain_type_iterate(_p)
Definition terrain.h:358
#define terrain_type_iterate_end
Definition terrain.h:364
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
#define tile_claimer(_tile)
Definition tile.h:99
#define tile_index(_pt_)
Definition tile.h:87
#define tile_worked(_tile)
Definition tile.h:113
#define tile_terrain(_tile)
Definition tile.h:109
#define TILE_XY(ptile)
Definition tile.h:42
#define tile_continent(_tile)
Definition tile.h:91
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
#define tile_owner(_tile)
Definition tile.h:95
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
Goods_type_id goods_number(const struct goods_type *pgood)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
#define trade_routes_iterate_safe_end
@ TRI_CANCEL
Definition traderoutes.h:32
#define trade_routes_iterate_end
#define trade_routes_iterate_safe(c, proute)
#define trade_routes_iterate(c, proute)
trade_route_type
Definition traderoutes.h:37
const struct unit_type * utype
Definition fc_types.h:604
const struct impr_type * building
Definition fc_types.h:598
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1906
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:845
#define unit_tile(_pu)
Definition unit.h:395
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:418
#define unit_owner(_pu)
Definition unit.h:394
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6179
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:3855
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1414
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2781
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2794
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:788
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2247
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4869
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1241
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Definition unittype.c:1544
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1639
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1979
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:258
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753
#define utype_class(_t_)
Definition unittype.h:736
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604
void vision_site_update_from_city(struct vision_site *psite, const struct city *pcity)
Definition vision.c:115
citizens vision_site_size_get(const struct vision_site *psite)
Definition vision.c:155
struct vision * vision_new(struct player *pplayer, struct tile *ptile)
Definition vision.c:33
bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
Definition vision.c:62
void vision_free(struct vision *vision)
Definition vision.c:50
struct vision_site * vision_site_new_from_city(const struct city *pcity)
Definition vision.c:101
void vision_site_destroy(struct vision_site *psite)
Definition vision.c:74
#define ASSERT_VISION(v)
Definition vision.h:98
#define V_RADIUS(main_sq, invis_sq, subs_sq)
Definition vision.h:96
#define vision_site_owner(v)
Definition vision.h:128
short int v_radius_t[V_COUNT]
Definition vision.h:83
#define worker_task_list_iterate(tasklist, ptask)
Definition workertask.h:33
#define worker_task_list_iterate_end
Definition workertask.h:35
void worklist_copy(struct worklist *dst, const struct worklist *src)
Definition worklist.c:112