Freeciv-3.3
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 "counters.h"
37#include "culture.h"
38#include "events.h"
39#include "game.h"
40#include "government.h"
41#include "improvement.h"
42#include "idex.h"
43#include "map.h"
44#include "movement.h"
45#include "packets.h"
46#include "player.h"
47#include "requirements.h"
48#include "research.h"
49#include "road.h"
50#include "specialist.h"
51#include "tech.h"
52#include "traderoutes.h"
53#include "unit.h"
54#include "unitlist.h"
55#include "vision.h"
56
57/* common/aicore */
58#include "cm.h"
59
60/* common/scriptcore */
61#include "luascript_types.h"
62
63/* server */
64#include "actiontools.h"
65#include "barbarian.h"
66#include "citizenshand.h"
67#include "cityturn.h"
68#include "gamehand.h" /* send_game_info() */
69#include "maphand.h"
70#include "notify.h"
71#include "plrhand.h"
72#include "sanitycheck.h"
73#include "sernet.h"
74#include "spacerace.h"
75#include "srv_main.h"
76#include "techtools.h"
77#include "unithand.h"
78#include "unittools.h"
79
80/* server/advisors */
81#include "advbuilding.h"
82#include "advgoto.h"
83#include "infracache.h"
84
85/* server/scripting */
86#include "script_server.h"
87
88/* ai */
89#include "handicaps.h"
90
91/* ai */
92#include "handicaps.h"
93
94#include "citytools.h"
95
96
97/* Queue for pending auto_arrange_workers() */
98static struct city_list *arrange_workers_queue = nullptr;
99
100/* Suppress sending cities during game_load() and end_phase() */
102
103static bool city_workers_queue_remove(struct city *pcity);
104
105static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
106 bool source_gone)
107 fc__attribute((nonnull (1, 2)));
108
109/************************************************************************/
136void city_freeze_workers(struct city *pcity)
137{
138 pcity->server.workers_frozen++;
139}
140
141/************************************************************************/
146void city_thaw_workers(struct city *pcity)
147{
148 pcity->server.workers_frozen--;
149 fc_assert(pcity->server.workers_frozen >= 0);
150 if (pcity->server.workers_frozen == 0
151 && pcity->server.needs_arrange != CNA_NOT) {
152 city_refresh(pcity); /* Citizen count sanity */
154 }
155}
156
157/************************************************************************/
161{
162 if (arrange_workers_queue == nullptr) {
164 } else if (city_list_find_number(arrange_workers_queue, pcity->id)) {
165 return;
166 }
167
169 city_freeze_workers(pcity);
170 if (pcity->server.needs_arrange == CNA_NOT) {
172 }
173}
174
175/************************************************************************/
179static bool city_workers_queue_remove(struct city *pcity)
180{
181 if (arrange_workers_queue == nullptr) {
182 return FALSE;
183 }
184
186}
187
188/************************************************************************/
193{
194 if (arrange_workers_queue == nullptr) {
195 return;
196 }
197
199 city_thaw_workers(pcity);
201
203 arrange_workers_queue = nullptr;
204}
205
206/************************************************************************/
214static int evaluate_city_name_priority(struct tile *ptile,
215 const struct nation_city *pncity,
217{
218 /* Lower values mean higher priority. */
221
222 /* Increasing this value will increase the difference caused by
223 (non-)matching terrain. A matching terrain is mult_factor
224 "better" than an unlisted terrain, which is mult_factor
225 "better" than a non-matching terrain. */
226 const float mult_factor = 1.4;
227 bool river = FALSE;
228
229 /*
230 * If natural city names aren't being used, we just return
231 * the base value. This will have the effect of the first-listed
232 * city being used. We do this here rather than special-casing
233 * it elsewhere because this localizes everything to this
234 * function, even though it's a bit inefficient.
235 */
237 return default_priority;
238 }
239
240 /*
241 * Assuming we're using the natural city naming system, we use
242 * an internal alorithm to calculate the priority of each name.
243 * It's a pretty fuzzy algorithm; we basically do the following:
244 * - Change the priority scale from 0..n to 10..n+10. This means
245 * each successive city is 10% lower priority than the first.
246 * - Multiply by a semi-random number. This has the effect of
247 * decreasing rounding errors in the successive calculations,
248 * as well as introducing a smallish random effect.
249 * - Check over all the applicable terrains, and
250 * multiply or divide the priority based on whether or not
251 * the terrain matches. See comment below.
252 */
253
254 priority += 10.0;
255 priority *= 10.0 + fc_rand(5);
256
257 /*
258 * The terrain priority in the struct nation_city will be either
259 * -1, 0, or 1. We therefore take this as-is if the terrain is
260 * present, or negate it if not.
261 *
262 * The reason we multiply as well as divide the value is so
263 * that cities that don't care what terrain they are on (which
264 * is the default) will be left in the middle of the pack.
265 * If we _only_ multiplied (or divided), then cities that had more
266 * terrain labels would have their priorities hurt (or helped).
267 */
270 if (tile_has_extra(ptile, priver)
272 river = TRUE;
273 break;
274 }
276 if (!river) {
278 }
279
280 switch (goodness) {
281 case NCP_DISLIKE:
283 break;
284 case NCP_NONE:
285 break;
286 case NCP_LIKE:
288 break;
289 }
290
291 terrain_type_iterate(pterrain) {
292 /* Now we do the same for every available terrain. */
294 if (!is_terrain_near_tile(&(wld.map), ptile, pterrain, TRUE)) {
296 }
297 switch (goodness) {
298 case NCP_DISLIKE:
300 break;
301 case NCP_NONE:
302 break;
303 case NCP_LIKE:
305 }
307
308 return (int) priority;
309}
310
311/************************************************************************/
315static bool is_default_city_name(const char *name, struct player *pplayer)
316{
318 pncity) {
320 return TRUE;
321 }
323 return FALSE;
324}
325
326/************************************************************************/
333static const char *search_for_city_name(struct tile *ptile,
334 const struct nation_city_list *
335 default_cities,
336 struct player *pplayer)
337{
338 int choice = 0, priority, best_priority = -1;
339 const char *name;
340 const char *best_name = nullptr;
341
342 nation_city_list_iterate(default_cities, pncity) {
344 if (game_city_by_name(name) == nullptr
345 && is_allowed_city_name(pplayer, name, nullptr, 0)) {
346 priority = evaluate_city_name_priority(ptile, pncity, choice++);
347 if (-1 == best_priority || priority < best_priority) {
349 best_name = name;
350 }
351 }
353
354 return best_name;
355}
356
357/************************************************************************/
369bool is_allowed_city_name(struct player *pplayer, const char *cityname,
370 char *error_buf, size_t bufsz)
371{
372 struct connection *pconn = conn_by_user(pplayer->username);
373
374 /* Mode 1: A city name has to be unique for each player. */
376 && city_list_find_name(pplayer->cities, cityname)) {
377 if (error_buf) {
378 fc_snprintf(error_buf, bufsz, _("You already have a city called %s."),
379 cityname);
380 }
381 return FALSE;
382 }
383
384 /* Modes 2,3: A city name has to be globally unique. */
388 if (error_buf) {
390 _("A city called %s already exists."), cityname);
391 }
392 return FALSE;
393 }
394
395 /* General rule: any name in our ruleset is allowed. */
396 if (is_default_city_name(cityname, pplayer)) {
397 return TRUE;
398 }
399
400 /*
401 * Mode 3: Check that the proposed city name is not in another
402 * player's default city names. Note the name will already have been
403 * allowed if it is in this player's default city names list.
404 */
406 struct player *pother = nullptr;
407
409 if (player2 != pplayer && is_default_city_name(cityname, player2)) {
410 pother = player2;
411 break;
412 }
414
415 if (pother != nullptr) {
416 if (error_buf) {
418 _("Can't use %s as a city name. It is reserved for %s."),
420 }
421 return FALSE;
422 }
423 }
424
425 /* To prevent abuse, only players with HACK access (usually local
426 * connections) can use non-ascii names. Otherwise players could use
427 * confusing garbage names in multi-player games.
428 *
429 * We can even reach here for an AI player, if all the cities of
430 * the original nation are exhausted and the backup nations have
431 * non-ascii names in them. */
433 && (!pconn || pconn->access_level != ALLOW_HACK)) {
434 if (error_buf) {
436 _("%s is not a valid name. Only ASCII or "
437 "ruleset names are allowed for cities."),
438 cityname);
439 }
440 return FALSE;
441 }
442
443
444 return TRUE;
445}
446
447/************************************************************************/
453const char *city_name_suggestion(struct player *pplayer, struct tile *ptile)
454{
455 struct nation_type *pnation = nation_of_player(pplayer);
456 const char *name;
457
458 log_verbose("Suggesting city name for %s at (%d,%d)",
459 player_name(pplayer), TILE_XY(ptile));
460
461 /* First try default city names. */
462 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
463 if (name != nullptr) {
464 log_debug("Default city name found: %s.", name);
465 return name;
466 }
467
468 /* Not found... Let's try a straightforward algorithm to look through
469 * nations to find a city name.
470 *
471 * We start by adding the player's nation to the queue. Then we proceed:
472 * - Pick a random nation from the queue.
473 * - If it has a valid city name, use that.
474 * - Otherwise, add all parent and child nations to the queue.
475 * - If the queue is empty, add all remaining nations to it and continue.
476 *
477 * Variables used:
478 * - nation_list is a queue of nations to look through.
479 * - nations_selected tells whether each nation is in the queue already
480 * - queue_size gives the size of the queue (number of nations in it).
481 * - i is the current position in the queue.
482 * Note that nations aren't removed from the queue after they're processed.
483 * New nations are just added onto the end. */
484 {
487 int queue_size = 1, i = 0, idx;
488
490 nation_list[0] = pnation;
492
493 while (i < nation_count()) {
494 for (; i < queue_size; i++) {
495
496 if (0 < i) {
497 /* Pick a random nation from the queue. */
498 const int which = i + fc_rand(queue_size - i);
499 struct nation_type *tmp = nation_list[i];
500
503
504 pnation = nation_list[i];
505 log_debug("Looking through %s.", nation_rule_name(pnation));
506 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
507
508 if (name != nullptr) {
509 return name;
510 }
511 }
512
513 /* Append the nation's civil war nations into the search tree. */
515 idx = nation_index(n);
516 if (!nations_selected[idx]) {
518 nations_selected[idx] = TRUE;
519 queue_size++;
520 log_debug("Child %s.", nation_rule_name(n));
521 }
523
524 /* Append the nation's parent nations into the search tree. */
526 idx = nation_index(n);
527 if (!nations_selected[idx]) {
529 nations_selected[idx] = TRUE;
530 queue_size++;
531 log_debug("Parent %s.", nation_rule_name(n));
532 }
534 }
535
536 /* Still not found; append all remaining nations. */
538 idx = nation_index(n);
539 if (!nations_selected[idx]) {
542 queue_size++;
543 log_debug("Misc nation %s.", nation_rule_name(n));
544 }
546 }
547 }
548
549 /* Not found in rulesets, make a default name. */
550 {
551 static char tempname[MAX_LEN_CITYNAME];
552 int i;
553
554 log_debug("City name not found in rulesets.");
555 for (i = 1; i <= map_num_tiles(); i++ ) {
556 fc_snprintf(tempname, MAX_LEN_CITYNAME, _("City no. %d"), i);
557 if (game_city_by_name(tempname) == nullptr) {
558 return tempname;
559 }
560 }
561
562 fc_assert_msg(FALSE, "Failed to generate a city name.");
563 sz_strlcpy(tempname, _("A poorly-named city"));
564 return tempname;
565 }
566}
567
568/************************************************************************/
571int build_points_left(struct city *pcity)
572{
574
575 return cost - pcity->shield_stock;
576}
577
578/************************************************************************/
585static void transfer_unit(struct unit *punit, struct city *tocity,
586 bool rehome, bool verbose)
587{
590
591 /* Transferring a dying GameLoss unit as part of the loot for
592 * killing it caused gna bug #23676. */
594 "Tried to transfer the dying unit %d.",
595 punit->id);
596
597 if (from_player == to_player) {
599 log_verbose("Changed homecity of %s %s to %s",
603 if (verbose) {
606 _("Changed homecity of %s to %s."),
609 }
610 } else {
611 struct tile *utile = unit_tile(punit);
612 struct city *in_city = tile_city(utile);
613
616 /* This is a unique unit that to_player already has. A transfer would
617 * break the rule that a player only may have one unit of each unique
618 * unit type. */
619
620 log_debug("%s already have a %s. Can't transfer from %s",
624
626 /* Try to save game loss units. */
627 bounce_unit(punit, verbose);
628 } else {
629 /* Kill the unique unit. */
630
631 if (verbose) {
634 /* TRANS: Americans ... Leader */
635 _("The %s already have a %s. Can't transfer yours."),
638 }
639
640 wipe_unit(punit, ULR_CITY_LOST, nullptr);
641 }
642
643 return;
644 }
645
646 if (in_city) {
647 log_verbose("Transferred %s in %s from %s to %s",
651 if (verbose) {
654 _("Transferred %s in %s from %s to %s."),
659 }
660 } else if (can_unit_exist_at_tile(&(wld.map), punit, tocity->tile)) {
661 log_verbose("Transferred %s from %s to %s",
665 if (verbose) {
668 _("Transferred %s from %s to %s."),
672 }
673 } else {
674 log_verbose("Could not transfer %s from %s to %s",
678 if (verbose) {
681 /* TRANS: Polish Destroyer ... German <city> */
682 _("%s %s lost in transfer to %s %s"),
687 }
688 wipe_unit(punit, ULR_CITY_LOST, nullptr);
689 return;
690 }
691
693 }
695}
696
697/************************************************************************/
716void transfer_city_units(struct player *pplayer, struct player *pvictim,
717 struct unit_list *units, struct city *pcity,
718 struct city *exclude_city,
719 int kill_outside, bool verbose)
720{
721 struct tile *ptile = pcity->tile;
722 int saved_id = pcity->id;
723 const char *name = city_name_get(pcity);
724
725 /* Transfer enemy units in the city to the new owner.
726 * Only relevant if we are transferring to another player. */
727 if (pplayer != pvictim) {
729 if (vunit->server.dying) {
730 /* Don't transfer or bounce a dying unit. It will soon be gone
731 * anyway.
732 *
733 * Bouncing a dying unit isn't a good idea.
734 * Remaining death handling may do things meant for its current
735 * location to the new location. (Example: Stack death)
736 * bounce_unit() will wipe the unit if it can't be bounced. Wiping
737 * the dying unit isn't a good idea. The remaining death handling
738 * code will try to read from it.
739 *
740 * Transferring a dying GameLoss unit as part of the loot for
741 * killing it caused gna bug #23676. */
742 continue;
743 }
744
745 /* Don't transfer units already owned by new city-owner --wegge */
746 if (unit_owner(vunit) == pvictim) {
747 /* Determine whether unit was homeless. If it was, we don't give
748 * it a homecity, only change ownership.
749 * We have to search the transferred city's former units because
750 * the unit may have been made only temporarily homeless during
751 * city transfer. */
752 bool homeless = (vunit->homecity == 0)
754
755 /* vunit may die during transfer_unit().
756 * unit_list_remove() is still safe using vunit pointer, as
757 * pointer is not used for dereferencing, only as value.
758 * Not sure if it would be safe to unlink first and transfer only
759 * after that. Not sure if it is correct to unlink at all in
760 * some cases, depending which list 'units' points to. */
761 transfer_unit(vunit, pcity, !homeless, verbose);
763 } else if (!pplayers_allied(pplayer, unit_owner(vunit))) {
764 /* The owner of vunit is allied to pvictim but not to pplayer */
765 bounce_unit(vunit, verbose);
766 }
768 }
769
770 if (!city_exist(saved_id)) {
771 saved_id = 0;
772 }
773
774 /* Any remaining units supported by the city are either given new home
775 * cities or maybe destroyed */
778
779 if (vunit->server.dying) {
780 /* Don't transfer or destroy a dying unit. It will soon be gone
781 * anyway.
782 *
783 * Transferring a dying GameLoss unit as part of the loot for
784 * killing it caused gna bug #23676. */
785 continue;
786 }
787
790 /* Unit is in another city: make that the new homecity,
791 * unless that city is actually the same city (happens if disbanding)
792 * Unit had a homecity since it was supported, so rehome. */
794 } else if ((kill_outside == -1
796 && saved_id) {
797 /* Else transfer to specified city. */
798 transfer_unit(vunit, pcity, TRUE, verbose);
799 if (unit_tile(vunit) == ptile && !pplayers_allied(pplayer, pvictim)) {
800 /* Unit is inside city being transferred, bounce it. */
802 }
803 } else {
804 /* The unit is lost. Call notify_player (in all other cases it is
805 * called automatically). */
806 log_verbose("Lost %s %s at (%d,%d) when %s was lost.",
809 if (verbose) {
812 _("%s lost along with control of %s."),
814 }
815 wipe_unit(vunit, ULR_CITY_LOST, nullptr);
816 }
818
819#ifdef FREECIV_DEBUG
821 if (punit->server.dying) {
822 /* Leave the dying alone. */
823 continue;
824 }
825
826 fc_assert(punit->homecity == pcity->id);
827 fc_assert(unit_owner(punit) == pplayer);
829#endif /* FREECIV_DEBUG */
830}
831
832/************************************************************************/
851struct city *find_closest_city(const struct tile *ptile,
852 const struct city *pexclcity,
853 const struct player *pplayer,
854 bool only_ocean, bool only_continent,
855 bool only_known, bool only_player,
856 bool only_enemy, const struct unit_class *pclass)
857{
859 struct city *best_city = nullptr;
860 int best_dist = -1;
861
862 fc_assert_ret_val(ptile != nullptr, nullptr);
863
864 if (pplayer != nullptr && only_player && only_enemy) {
865 log_error("Non of my own cities will be at war with me!");
866 return nullptr;
867 }
868
869 con = tile_continent(ptile);
870
872 if (pplayer != nullptr && only_player && pplayer != aplayer) {
873 /* Only cities of player 'pplayer' */
874 continue;
875 }
876
877 if (pplayer != nullptr && only_enemy
878 && !pplayers_at_war(pplayer, aplayer)) {
879 /* Only cities of players at war with player 'pplayer' */
880 continue;
881 }
882
883 city_list_iterate(aplayer->cities, pcity) {
884 int city_dist;
885
886 if (pexclcity && pexclcity == pcity) {
887 /* not this city */
888 continue;
889 }
890
891 city_dist = real_map_distance(ptile, city_tile(pcity));
892
893 /* Find the closest city matching the requirements.
894 * - closer than the current best city
895 * - (if required) on the same continent
896 * - (if required) adjacent to ocean
897 * - (if required) only cities known by the player
898 * - (if required) only cities native to the class */
899 if ((best_dist == -1 || city_dist < best_dist)
900 && (!only_continent || con == tile_continent(pcity->tile))
902 city_tile(pcity), TC_OCEAN))
903 && (!only_known
904 || (map_is_known(city_tile(pcity), pplayer)
905 && map_get_player_site(city_tile(pcity), pplayer)->identity
907 && (pclass == nullptr
908 || is_native_near_tile(&(wld.map), pclass, city_tile(pcity)))) {
910 best_city = pcity;
911 }
914
915 return best_city;
916}
917
918/************************************************************************/
923static void raze_city(struct city *pcity)
924{
925 int razechance = game.server.razechance;
926 bool city_remains = TRUE;
927
928 /* Land barbarians are more likely to destroy city improvements */
929 if (is_land_barbarian(city_owner(pcity))) {
930 razechance += 30;
931 }
932
933 city_built_iterate(pcity, pimprove) {
934 /* Small wonders should have already been removed by
935 * transfer_city() (with 100% probability). */
936 fc_assert(!is_small_wonder(pimprove));
937 if (is_improvement(pimprove) && (fc_rand(100) < razechance)) {
938 /* FIXME: Should maybe have conquering unit instead
939 * of nullptr as destroyer */
940 city_remains = building_removed(pcity, pimprove, "razed", nullptr);
941 if (!city_remains) {
942 break;
943 }
944 }
946
947 if (city_remains) {
949 pcity->shield_stock = 0;
950 }
951}
952
953/************************************************************************/
957static void reestablish_city_trade_routes(struct city *pcity)
958{
960 bool keep_route;
961 struct trade_route *back;
962 struct city *partner = game_city_by_number(proute->partner);
963
964 /* Remove the city's trade routes (old owner).
965 * Do not announce removal as we might restore the route immediately below */
967
968 keep_route = can_cities_trade(pcity, partner)
969 && can_establish_trade_route(pcity, partner, proute->goods->priority);
970
971 if (!keep_route) {
972 enum trade_route_type type = cities_trade_route_type(pcity, partner);
974
975 if (settings->cancelling != TRI_CANCEL) {
977 }
978 }
979
980 /* Readd the city's trade route (new owner) */
981 if (keep_route) {
984 } else {
985 free(proute);
986 free(back);
987
988 /* Now announce the trade route removal */
989 announce_trade_route_removal(pcity, partner, FALSE);
990 }
991
992 /* Refresh regardless; either it lost a trade route or the trade
993 * route revenue changed. */
994 city_refresh(partner);
995 send_city_info(city_owner(partner), partner);
996
997 /* Give the new owner infos about the city which has a trade route
998 * with the transferred city. */
1000 struct player *owner = city_owner(pcity);
1001
1002 map_show_tile(owner, partner->tile);
1003 update_dumb_city(owner, partner);
1004 send_city_info(owner, partner);
1005 }
1007}
1008
1009/************************************************************************/
1014static void build_free_small_wonders(struct player *pplayer,
1016{
1017 int size = city_list_size(pplayer->cities);
1018
1019 if (!game.server.savepalace) {
1020 /* Nothing to do */
1021 return;
1022 }
1023
1024 if (size == 0) {
1025 /* The last city was removed or transferred to the enemy.
1026 * If the victim survives to found or acquire another city, they'll
1027 * get any savepalace initial buildings then. */
1028 return;
1029 }
1030
1031 improvement_iterate(pimprove) {
1034 /* FIXME: instead, find central city */
1035 struct city *pnew_city = city_list_get(pplayer->cities, fc_rand(size));
1036
1037 fc_assert_action(city_from_small_wonder(pplayer, pimprove) == nullptr,
1038 continue);
1039
1041
1042 /*
1043 * send_player_cities() will recalculate all cities and send them to
1044 * the client.
1045 */
1046 send_player_cities(pplayer);
1047
1049 /* FIXME: should already be notified about city loss? */
1050 /* TRANS: <building> ... <city> */
1051 _("A replacement %s was built in %s."),
1054 /*
1055 * The enemies want to see the new capital in their intelligence
1056 * report.
1057 */
1058 send_city_info(nullptr, pnew_city);
1059 }
1061}
1062
1063/************************************************************************/
1072bool transfer_city(struct player *ptaker, struct city *pcity,
1074 bool resolve_stack, bool raze, bool build_free)
1075{
1077 struct vision *old_vision, *new_vision;
1078 struct unit_list *old_city_units = unit_list_new();
1079 struct player *pgiver = city_owner(pcity);
1080 struct tile *pcenter = city_tile(pcity);
1081 int saved_id = pcity->id;
1082 bool city_remains = TRUE;
1083 bool had_great_wonders = FALSE;
1088 bool taker_had_no_cities = (city_list_size(ptaker->cities) == 0);
1089 bool new_extras;
1090 int units_num = 0;
1091 const int ul_size = unit_list_size(pcenter->units);
1092 int central_units[ul_size + 1];
1093 bv_player *could_see_unit = nullptr;
1094 int i;
1095
1097
1101
1102 if (units_num > 0) {
1104
1105 /* Remember what player see what unit. */
1106 for (i = 0; i < units_num; i++) {
1108
1113 }
1115 }
1116
1117 fc_assert(i == units_num);
1118 }
1119
1120 /* Remove AI control of the old owner. */
1121 CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity);
1122
1123 /* Forget old tasks */
1124 clear_worker_tasks(pcity);
1125
1126 /* Forget old rally point */
1128
1129 /* Activate AI control of the new owner. */
1130 CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
1131
1132 city_freeze_workers(pcity);
1133
1136 /* Mark unit to have no homecity at all.
1137 * 1. We remove unit from units_supported list here,
1138 * real_change_unit_homecity() should not attempt it.
1139 * 2. Otherwise we might delete the homecity from under the unit
1140 * in the client */
1141 punit->homecity = 0;
1142 send_unit_info(nullptr, punit);
1145
1146 /* Remove all global improvement effects that this city confers (but
1147 then restore the local improvement list - we need this to restore
1148 the global effects for the new city owner) */
1150 city_built_iterate(pcity, pimprove) {
1151 if (is_small_wonder(pimprove)) {
1152 /* Small wonders are really removed (not restored later). */
1153 building_removed(pcity, pimprove, "conquered", nullptr);
1155 } else {
1156 city_remove_improvement(pcity, pimprove);
1157 if (is_great_wonder(pimprove)) {
1159 }
1160 /* Note: internal turn here, next city_built_iterate(). */
1161 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
1162 }
1164
1166 old_vision = pcity->server.vision;
1168 pcity->server.vision = new_vision;
1171
1173
1175 && city_list_find_name(ptaker->cities, city_name_get(pcity))) {
1176 char *old_city_name = fc_strdup(city_name_get(pcity));
1177
1180 _("You already had a city called %s."
1181 " The city was renamed to %s."),
1183 city_link(pcity));
1184
1186 }
1187
1188 /* Has to follow the unfog call above. */
1189 city_list_remove(pgiver->cities, pcity);
1191 /* city_thaw_workers_queue() later */
1192
1193 pcity->owner = ptaker;
1194 pcity->capital = CAPITAL_NOT;
1195 pcity->acquire_t = CACQ_CONQUEST;
1197 city_list_prepend(ptaker->cities, pcity);
1198
1199 if (could_see_unit != nullptr) {
1200 /* Hide/reveal units. Do it after vision have been given to taker, city
1201 * owner has been changed, and before any script could be spawned. */
1202 for (i = 0; i < units_num; i++) {
1204
1208 && !aunit->server.dying) {
1209 /* Reveal 'aunit'. */
1210 send_unit_info(aplayer->connections, aunit);
1211 }
1212 } else {
1214 /* Hide 'aunit'. */
1216 }
1217 }
1219 }
1220
1221 fc_assert(i == units_num);
1222
1224 could_see_unit = nullptr;
1225 }
1226
1228 pcity, nullptr,
1230 /* The units themselves are already freed by transfer_city_units(). */
1232
1233 if (resolve_stack) {
1235 }
1236
1237 if (!city_exist(saved_id)) {
1239 }
1240
1241 /* Reset turns owner counters */
1242 if (city_remains) {
1244 if (pcount->type == CB_CITY_OWNED_TURNS) {
1245 pcity->counter_values[pcount->index] = 0;
1246 }
1248 }
1249
1250 if (city_remains) {
1251 /* Update the city's trade routes. */
1253
1254 /* Clear CMA. */
1255 if (pcity->cm_parameter) {
1256 free(pcity->cm_parameter);
1257 pcity->cm_parameter = nullptr;
1258 }
1259
1260 city_refresh(pcity);
1261 }
1262
1263 /*
1264 * maybe_make_contact() MUST be called before city_map_update_all(),
1265 * since the diplomacy status can influence whether a tile is available.
1266 */
1268
1269 if (city_remains) {
1270 struct extra_type *upgradet;
1271
1272 if (raze) {
1273 raze_city(pcity);
1274 }
1275
1276 if (taker_had_no_cities) {
1277 /* If conqueror previously had no cities, we might need to give
1278 * them a palace etc */
1279 if (build_free) {
1281 } /* Else caller should probably ensure palace is built */
1282
1283 BV_SET(ptaker->flags, PLRF_FIRST_CITY);
1284 }
1285
1287
1288 /* Restore any global improvement effects that this city confers */
1289 city_built_iterate(pcity, pimprove) {
1291 _("Transfer of %s"));
1293
1294 /* Set production to something valid for pplayer, if not.
1295 * (previously allowed building obsolete units.) */
1296 if (!can_city_build_now(pcity, &pcity->production)) {
1298 }
1299
1300 /* What wasn't obsolete for the old owner may be so now. */
1302
1304
1305 if (new_extras) {
1306 const char *clink = city_link(pcity);
1307
1309 _("The people in %s are stunned by your "
1310 "technological insight!"),
1311 clink);
1312
1313 if (upgradet != nullptr) {
1315 _("Workers spontaneously gather and upgrade "
1316 "%s with %s."),
1318 } else {
1320 _("Workers spontaneously gather and upgrade "
1321 "%s infrastructure."),
1322 clink);
1323 }
1325 }
1326
1327 /* Build a new palace for free if the player lost their capital and
1328 savepalace is on. */
1330
1331 /* Refresh the city's vision range, since it might be different
1332 * under the new owner. */
1333 city_refresh_vision(pcity);
1334
1335 /* Update the national borders, within the current vision and culture.
1336 * This could leave a border ring around the city, updated later by
1337 * map_calculate_borders() at the next turn.
1338 */
1340 /* city_thaw_workers_queue() later */
1341
1342 auto_arrange_workers(pcity); /* Does city_map_update_all() */
1343 city_thaw_workers(pcity);
1344 city_thaw_workers_queue(); /* After old city has a chance to work! */
1346 /* No sanity check here as the city is not refreshed! */
1347 }
1348
1349 if (city_remains) {
1350 /* Send city with updated owner information to giver and to everyone
1351 * having shared vision pact with them before they may
1352 * lose vision to it. When we later send info to everybody seeing the city,
1353 * they may not be included. */
1354 send_city_info(nullptr, pcity);
1355 }
1356
1357 /* Remove the sight points from the giver. */
1358 vision_clear_sight(old_vision);
1359 vision_free(old_vision);
1360
1361 /* Send wonder infos. */
1362 if (had_great_wonders) {
1363 send_game_info(nullptr);
1364 if (city_remains) {
1365 send_player_info_c(ptaker, nullptr);
1366
1367 /* Refresh all cities of the taker to account for possible changes due
1368 * to player wide effects. */
1369 city_list_iterate(ptaker->cities, acity) {
1372 } else {
1373 /* Refresh all cities to account for possible global effects. */
1377 }
1378 }
1380 /* No need to send to detached connections. */
1381 send_player_info_c(pgiver, nullptr);
1382
1383 /* Refresh all cities of the giver to account for possible changes due
1384 * to player wide effects. */
1385 city_list_iterate(pgiver->cities, acity) {
1388 }
1389
1390 /* Refresh all cities in the queue. */
1392 /* After the refresh the sanity check can be done. */
1393 sanity_check_city(pcity);
1394
1395 if (city_remains) {
1396 /* Send information about conquered city to all players. */
1397 send_city_info(nullptr, pcity);
1398 }
1399
1400 /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to
1401 * refresh all cities for the player. */
1405 }
1409 }
1410
1411 if (pgiver->primary_capital_id == saved_id) {
1413 }
1414
1415 sync_cities();
1416
1417 CALL_FUNC_EACH_AI(city_info, pcity);
1418
1419 return city_remains;
1420}
1421
1422/************************************************************************/
1430{
1431 struct player *pplayer;
1432 struct nation_type *nation;
1433 int i;
1435 bool first_city;
1436
1437 fc_assert_ret(pcity != nullptr);
1438 pplayer = city_owner(pcity);
1439 fc_assert_ret(pplayer != nullptr);
1440 nation = nation_of_player(pplayer);
1441 fc_assert_ret(nation != nullptr);
1442
1443 /* If this isn't the first city a player has ever had, they only get
1444 * any initial buildings with the SaveSmallWonder flag, and then only
1445 * if savepalace is enabled. */
1447
1450
1451 /* Global free buildings. */
1452 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1454 struct impr_type *pimprove;
1455
1456 if (n == B_LAST) {
1457 break;
1458 }
1459
1460 pimprove = improvement_by_number(n);
1461 fc_assert_action(!is_great_wonder(pimprove), continue);
1462 if (first_city
1466 /* TRANS: Reason that a building was added to the city.
1467 * Building is given for free to player's first city. */
1468 Q_("?initbldg:Free %s"));
1469 if (is_small_wonder(pimprove)) {
1471 }
1472 }
1473 }
1474
1475 /* Nation specific free buildings. */
1476 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1477 Impr_type_id n = nation->init_buildings[i];
1478 struct impr_type *pimprove;
1479
1480 if (n == B_LAST) {
1481 break;
1482 }
1483
1484 pimprove = improvement_by_number(n);
1485 if (first_city
1489 /* TRANS: Reason that a building was added to the city.
1490 * Building is given for free to player's first city. */
1491 Q_("?initbldg:Free %s"));
1492 if (is_small_wonder(pimprove)) {
1494 } else if (is_great_wonder(pimprove)) {
1496 }
1497 }
1498 }
1499
1500 /* Update wonder infos. */
1501 if (has_great_wonders) {
1502 send_game_info(nullptr);
1503 /* No need to send to detached connections. */
1504 send_player_info_c(pplayer, nullptr);
1505 } else if (has_small_wonders) {
1506 /* No need to send to detached connections. */
1507 send_player_info_c(pplayer, nullptr);
1508 }
1509}
1510
1511/************************************************************************/
1514void create_city(struct player *pplayer, struct tile *ptile,
1515 const char *name, struct player *nationality)
1516{
1517 struct player *saved_owner = tile_owner(ptile);
1518 struct tile *saved_claimer = tile_claimer(ptile);
1519 struct city *pwork = tile_worked(ptile);
1520 struct city *pcity;
1523
1524 log_debug("create_city() %s", name);
1525
1526 pcity = create_city_virtual(pplayer, ptile, name);
1527
1528 /* Remove units no more seen. Do it before city is really put into
1529 * the game. */
1530 players_iterate(other_player) {
1531 if (can_player_see_units_in_city(other_player, pcity)
1532 || !map_is_known_and_seen(ptile, other_player, V_MAIN)) {
1533 continue;
1534 }
1535 unit_list_iterate(ptile->units, punit) {
1536 if (can_player_see_unit(other_player, punit)) {
1537 unit_goes_out_of_sight(other_player, punit);
1538 }
1541
1542 adv_city_alloc(pcity);
1543
1544 tile_set_owner(ptile, pplayer, ptile); /* Temporarily */
1546 pcity->id = identity_number();
1547
1549 idex_register_city(&wld, pcity);
1551
1552 if (city_list_size(pplayer->cities) == 0) {
1553 /* Free initial buildings, or at least a palace if they were
1554 * previously careless enough to lose all their cities */
1556 BV_SET(pplayer->flags, PLRF_FIRST_CITY);
1557 }
1558
1559 /* Set up citizens nationality. */
1560 citizens_init(pcity);
1561
1562 /* Place a worker at the is_city_center() is_free_worked().
1563 * It is possible to build a city on a tile that is already worked;
1564 * this will displace the worker on the newly-built city's tile -- Syela */
1565 tile_set_worked(ptile, pcity); /* Instead of city_map_update_worker() */
1566
1567 if (pwork != nullptr) {
1568 /* Was previously worked by another city */
1569 /* Turn citizen into specialist. */
1570 pwork->specialists[DEFAULT_SPECIALIST]++;
1571 /* One less citizen. Citizen sanity will be handled later in
1572 * city_thaw_workers_queue() */
1573 pwork->server.synced = FALSE;
1575 }
1576
1577 /* Update citizens. */
1579
1580 /* Restore the old-owner information so removal
1581 * of territory claiming bases can work relative to it. */
1583
1584 /* Destroy any extras that don't belong in the city. */
1585 extra_type_iterate(pextra) {
1586 if (tile_has_extra(ptile, pextra)
1587 && !is_native_tile_to_extra(pextra, ptile)) {
1588 destroy_extra(ptile, pextra);
1589 }
1591
1592 /* Build any extras that the city should have. */
1593 upgrade_city_extras(pcity, nullptr);
1594
1595 /* Claim the ground we stand on */
1596 map_claim_ownership(ptile, pplayer, ptile, TRUE);
1597
1598 /* Before arranging workers to show unknown land */
1599 pcity->server.vision = vision_new(pplayer, ptile);
1601 city_refresh_vision(pcity);
1602 city_list_prepend(pplayer->cities, pcity);
1603
1604 /* This is dependent on the current vision, so must be done after
1605 * vision is prepared and before arranging workers. */
1606 map_claim_border(ptile, pplayer, -1);
1607 /* city_thaw_workers_queue() later */
1608
1609 /* Refresh the city. First a city refresh is done (this shouldn't
1610 * send any packets to the client because the city has no supported units)
1611 * then rearrange the workers. Note that auto_arrange_workers() does its
1612 * own refresh call; it is safest to do our own controlled city_refresh()
1613 * first. */
1614 city_refresh(pcity);
1615 auto_arrange_workers(pcity);
1616 city_thaw_workers_queue(); /* After new city has a chance to work! */
1618
1619 /* Bases destroyed earlier may have had watchtower effect. Refresh
1620 * unit vision. */
1622
1623 update_tile_knowledge(ptile);
1624
1627 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1628 * cities for the player. */
1629 city_refresh_for_player(pplayer);
1630 }
1631
1632 pcity->server.synced = FALSE;
1633 send_city_info(nullptr, pcity);
1634 sync_cities(); /* Will also send pwork. */
1635
1636 notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server,
1637 _("You have founded %s."),
1638 city_link(pcity));
1639 maybe_make_contact(ptile, city_owner(pcity));
1640
1641 unit_list_iterate((ptile)->units, punit) {
1643
1644 /* Catch fortress building, transforming into ocean, etc. */
1647 }
1648
1649 /* Update happiness (the unit may no longer cause unrest). */
1650 if (home) {
1651 if (city_refresh(home)) {
1652 /* Shouldn't happen, but better be safe than sorry. */
1654 }
1657 }
1659
1660 sanity_check_city(pcity);
1661
1662 script_server_signal_emit("city_built", pcity);
1663
1664 CALL_FUNC_EACH_AI(city_created, pcity);
1665 CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
1666}
1667
1668/************************************************************************/
1674bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1675 const char *name)
1676{
1677 const struct civ_map *nmap = &(wld.map);
1678
1679 if (is_enemy_unit_tile(ptile, pplayer)
1680 || !city_can_be_built_here(nmap, ptile, nullptr, FALSE)) {
1681 return FALSE;
1682 }
1683
1684 if (!pplayer->is_alive) {
1685 pplayer->is_alive = TRUE;
1686 send_player_info_c(pplayer, nullptr);
1687 }
1688
1689 if (name == nullptr || name[0] == '\0') {
1690 name = city_name_suggestion(pplayer, ptile);
1691 }
1692
1693 map_show_tile(pplayer, ptile);
1694 create_city(pplayer, ptile, name, pplayer);
1695
1696 return TRUE;
1697}
1698
1699/************************************************************************/
1702void remove_city(struct city *pcity)
1703{
1704 struct player *powner = city_owner(pcity);
1705 struct tile *pcenter = city_tile(pcity);
1707 struct vision *old_vision;
1708 int id = pcity->id; /* We need this even after memory has been freed */
1709 bool had_great_wonders = FALSE;
1712 struct dbv tile_processed;
1713 struct tile_list *process_queue;
1714 const char *ctl = city_tile_link(pcity);
1715 const struct civ_map *nmap = &(wld.map);
1716
1717 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1718 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1719
1721 city_built_iterate(pcity, pimprove) {
1722 building_removed(pcity, pimprove, "city_destroyed", nullptr);
1723
1724 if (is_small_wonder(pimprove)) {
1726 } else if (is_great_wonder(pimprove)) {
1728 }
1730
1731 /* Rehome units in other cities */
1734
1735 if (new_home_city
1736 && new_home_city != pcity
1737 && city_owner(new_home_city) == powner
1738 && !punit->server.dying) {
1740 }
1742
1743 /* Make sure ships are not left on land when city is removed. */
1745 bool moved;
1746 const struct unit_type *punittype = unit_type_get(punit);
1747
1748 /* can_exist_at_tile() would give wrong results, as
1749 * the city is still on map. */
1752 || is_safe_ocean(nmap, pcenter))) {
1753 continue;
1754 }
1755
1757 moved = FALSE;
1759 struct unit *ptrans;
1760
1763 /* Move */
1765 /* It may be impossible to survive at the tile even if it is
1766 * native. See UTYF_COAST_STRICT */
1768 } else {
1769 ptrans = nullptr;
1770 }
1773 nullptr, nullptr,
1775 nullptr) != nullptr) {
1776 moved = TRUE;
1777 }
1778 if (moved) {
1781 _("Moved %s out of disbanded city %s "
1782 "since it cannot stay on %s."),
1785 break;
1786 }
1787 }
1788 }
1790 if (!moved) {
1793 _("When %s was disbanded your %s could not "
1794 "get out, and it was therefore lost."),
1795 ctl,
1797 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1798 }
1800
1804 struct tile *ptile = tile_list_front(process_queue);
1805
1808 adjc_iterate(nmap, ptile, piter) {
1809 struct city *other_city;
1810
1812 continue;
1813 }
1815 if (other_city != nullptr) {
1816 /* Adjacent tile has a city that may have been part of same channel */
1821
1827 _("When %s was disbanded your %s in %s was trapped, "
1828 "and it was therefore lost."),
1829 ctl,
1832 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1833 }
1835 } else {
1837 }
1839 }
1840
1843
1844 if (!city_exist(id)) {
1845 /* Wiping trapped units caused city to disappear. */
1846 return;
1847 }
1848
1849 /* Any remaining supported units are destroyed */
1851 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1853
1854 if (!city_exist(id)) {
1855 /* Wiping supported units caused city to disappear. */
1856 return;
1857 }
1858
1860 struct trade_route *pback = remove_trade_route(pcity, proute,
1861 TRUE, TRUE);
1862
1863 FC_FREE(proute);
1864 FC_FREE(pback);
1866
1871
1872 /* idex_unregister_city() is called in game_remove_city() below */
1873
1874 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1875 * still be alive in the client, or in the player map. The number of
1876 * removed cities is small, so the loss is acceptable. */
1877
1878 old_vision = pcity->server.vision;
1879 pcity->server.vision = nullptr;
1881 adv_city_free(pcity);
1882
1883 /* Remove city from the map. */
1884 tile_set_worked(pcenter, nullptr);
1885
1886 /* Reveal units. */
1887 players_iterate(other_player) {
1888 if (can_player_see_units_in_city(other_player, pcity)
1889 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1890 continue;
1891 }
1893 if (can_player_see_unit(other_player, punit)) {
1894 send_unit_info(other_player->connections, punit);
1895 }
1898
1900 game_remove_city(&wld, pcity);
1902
1903 /* Remove any extras that were only there because the city was there. */
1904 extra_type_iterate(pextra) {
1905 if (tile_has_extra(pcenter, pextra)
1906 && !is_native_tile_to_extra(pextra, pcenter)) {
1908 }
1910
1911 players_iterate(other_player) {
1912 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1913 reality_check_city(other_player, pcenter);
1914 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1915 map_show_tile(other_player, pcenter);
1916 }
1918
1920 if (pconn->playing == nullptr && pconn->observer) {
1921 /* For detached observers we have to send a specific packet. This is
1922 * a hack necessitated by the private map that exists for players but
1923 * not observers. */
1925 }
1927
1928 if (old_vision != NULL) {
1929 vision_clear_sight(old_vision);
1930 vision_free(old_vision);
1931 }
1932
1933 /* Infrastructures may have changed. */
1934 send_tile_info(nullptr, pcenter, FALSE);
1935
1936 /* Build a new palace for free if the player lost their capital and
1937 * savepalace is on. */
1939
1940 /* Update wonder infos. */
1941 if (had_great_wonders) {
1942 send_game_info(nullptr);
1943 /* No need to send to detached connections. */
1944 send_player_info_c(powner, nullptr);
1945 } else if (BV_ISSET_ANY(had_small_wonders)) {
1946 /* No need to send to detached connections. */
1947 send_player_info_c(powner, nullptr);
1948 }
1949
1952 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1953 * cities for the player. */
1955 }
1956
1957 sync_cities();
1958
1959 /* At least sentried helicopters need to go idle, maybe others.
1960 * In alien ruleset, city center might have provided water source
1961 * for adjacent tile. */
1963}
1964
1965/************************************************************************/
1981bool unit_conquer_city(struct unit *punit, struct city *pcity)
1982{
1983 bool try_civil_war = FALSE;
1984 bool city_remains;
1985 int coins;
1986 struct player *pplayer = unit_owner(punit);
1987 struct player *cplayer = city_owner(pcity);
1988#ifndef FREECIV_NDEBUG
1989 const struct unit_type *utype = unit_type_get(punit);
1990#endif
1991
1992 /* If not at war, may peacefully enter city. */
1994 "Can't conquer city during peace.");
1995
1996 /* If we cannot occupy the city, this unit entering will not trigger
1997 * effects below. */
2001 FALSE, "Bad unit for city occupation.");
2002
2003 /* A transported unit trying to conquer a city should already have been
2004 * unloaded. */
2006 "Can't conquer city while transported.");
2007
2008 /* Okay, we're at war - invader captures/destroys city... */
2009
2010 /* If a capital is captured, then spark off a civil war
2011 * - Kris Bubendorfer
2012 * Also check spaceships --dwp */
2013
2014 if (is_capital(pcity)
2015 && (cplayer->spaceship.state == SSHIP_STARTED
2016 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
2018 }
2019
2020 if (is_capital(pcity)
2025 }
2026
2027 /*
2028 * We later remove a citizen. Lets check if we can save this since
2029 * the city will be destroyed.
2030 */
2031 if (city_size_get(pcity) <= 1) {
2032 int saved_id = pcity->id;
2033
2035 _("You destroy %s completely."),
2036 city_tile_link(pcity));
2038 _("%s has been destroyed by %s."),
2039 city_tile_link(pcity), player_name(pplayer));
2040 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2041
2042 /* We cant't be sure of city existence after running some script */
2043 if (city_exist(saved_id)) {
2044 remove_city(pcity);
2045 }
2046
2047 if (try_civil_war) {
2049 }
2050 return TRUE;
2051 }
2052
2054 coins = MIN(coins,
2055 fc_rand((coins / 20) + 1)
2056 + (coins * (city_size_get(pcity))) / 200);
2057 pplayer->economic.gold += coins;
2058 cplayer->economic.gold -= coins;
2059 send_player_info_c(pplayer, pplayer->connections);
2060 send_player_info_c(cplayer, cplayer->connections);
2061 if (pcity->original != pplayer) {
2062 if (coins > 0) {
2064 PL_("You conquer %s; your lootings accumulate"
2065 " to %d gold!",
2066 "You conquer %s; your lootings accumulate"
2067 " to %d gold!", coins),
2068 city_link(pcity),
2069 coins);
2071 PL_("%s conquered %s and looted %d gold"
2072 " from the city.",
2073 "%s conquered %s and looted %d gold"
2074 " from the city.", coins),
2075 player_name(pplayer),
2076 city_link(pcity),
2077 coins);
2078 } else {
2080 _("You conquer %s."),
2081 city_link(pcity));
2083 _("%s conquered %s."),
2084 player_name(pplayer),
2085 city_link(pcity));
2086 }
2087 } else {
2088 if (coins > 0) {
2090 PL_("You have liberated %s!"
2091 " Lootings accumulate to %d gold.",
2092 "You have liberated %s!"
2093 " Lootings accumulate to %d gold.", coins),
2094 city_link(pcity),
2095 coins);
2097 PL_("%s liberated %s and looted %d gold"
2098 " from the city.",
2099 "%s liberated %s and looted %d gold"
2100 " from the city.", coins),
2101 player_name(pplayer),
2102 city_link(pcity),
2103 coins);
2104 } else {
2106 _("You have liberated %s!"),
2107 city_link(pcity));
2109 _("%s liberated %s."),
2110 player_name(pplayer),
2111 city_link(pcity));
2112 }
2113 }
2114
2116 /* Just try to steal. Ignore failures to get tech */
2117 steal_a_tech(pplayer, cplayer, A_UNSET);
2118 }
2119
2120 /* We transfer the city first so that it is in a consistent state when
2121 * the size is reduced. */
2122 /* FIXME: maybe it should be a ruleset option whether barbarians get
2123 * free buildings such as palaces? */
2124 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2125 !is_barbarian(pplayer));
2126
2127 if (city_remains) {
2128 /* Reduce size should not destroy this city */
2129 fc_assert(city_size_get(pcity) > 1);
2130 city_reduce_size(pcity, 1, pplayer, "conquest");
2131 }
2132
2133 if (try_civil_war) {
2135 }
2136
2137 if (city_remains) {
2138 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2139 "conquest");
2140 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2141 }
2142
2143 return TRUE;
2144}
2145
2146/************************************************************************/
2149static int city_citywalls_gfx(const struct city *pcity)
2150{
2151 int walls = get_city_bonus(pcity, EFT_VISIBLE_WALLS);
2152
2153 return walls > 0 ? walls : 0;
2154}
2155
2156/************************************************************************/
2160{
2162
2164 return formerly;
2165}
2166
2167/************************************************************************/
2170static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2171 struct packet_city_short_info *packet)
2172{
2173 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2174
2175 packet->id = pdcity->identity;
2177
2178 packet->tile = tile_index(ptile);
2179 if (pdcity->name == nullptr) {
2180 packet->name[0] = '\0';
2181 } else {
2182 sz_strlcpy(packet->name, pdcity->name);
2183 }
2184
2185 packet->size = vision_site_size_get(pdcity);
2186
2187 packet->occupied = pdcity->occupied;
2188 packet->walls = pdcity->walls;
2189 packet->style = pdcity->style;
2190 packet->city_image = pdcity->city_image;
2191 packet->capital = pdcity->capital;
2192
2193 packet->happy = pdcity->happy;
2194 packet->unhappy = pdcity->unhappy;
2195
2196 packet->improvements = pdcity->improvements;
2197}
2198
2199/************************************************************************/
2203void refresh_dumb_city(struct city *pcity)
2204{
2205 players_iterate(pplayer) {
2206 if (player_can_see_city_externals(pplayer, pcity)) {
2207 if (update_dumb_city(pplayer, pcity)) {
2208 struct packet_city_short_info packet;
2209
2210 if (city_owner(pcity) != pplayer) {
2211 /* Don't send the short_city information to someone who can see
2212 * city's internals. Doing so would really confuse the client. */
2213 package_dumb_city(pplayer, pcity->tile, &packet);
2214 lsend_packet_city_short_info(pplayer->connections, &packet);
2215 }
2216 }
2217 }
2219
2220 /* Don't send to non-player observers since they don't have 'dumb city'
2221 * information. */
2222}
2223
2224/************************************************************************/
2232void broadcast_city_info(struct city *pcity)
2233{
2234 struct packet_city_info packet;
2239 struct player *powner = city_owner(pcity);
2240 struct trade_route_packet_list *routes;
2242
2243 /* Send to everyone who can see the city. */
2244
2245 if (pcity->server.needs_arrange != CNA_NOT) {
2246 /* Send city only when it's in sane state.
2247 * If it's not, it will be sent to everyone once
2248 * rearrangement has been finished. */
2250
2251 return;
2252 }
2253
2254 if (any_web_conns()) {
2256 } else {
2257 webp_ptr = nullptr;
2258 }
2259
2260 routes = trade_route_packet_list_new();
2261 package_city(pcity, &packet, &nat_packet, &rally_packet,
2262 webp_ptr, routes, FALSE);
2263
2264 players_iterate(pplayer) {
2265 if (!send_city_suppressed || pplayer != powner) {
2266 if (can_player_see_city_internals(pplayer, pcity)) {
2267 update_dumb_city(pplayer, pcity);
2268 packet.original = city_original_owner(pcity, pplayer);
2269 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2270 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2271 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2272 web_lsend_packet(city_info_addition, pplayer->connections,
2273 webp_ptr, FALSE);
2275 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2277 } else if (player_can_see_city_externals(pplayer, pcity)) {
2278 reality_check_city(pplayer, pcity->tile);
2279 update_dumb_city(pplayer, pcity);
2280 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2281 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2282 }
2283 }
2285
2286 /* Send to global observers. */
2287 packet.original = city_original_owner(pcity, nullptr);
2294 }
2296
2301}
2302
2303/************************************************************************/
2308{
2309 conn_list_do_buffer(dest);
2310 conn_list_iterate(dest, pconn) {
2311 struct player *pplayer = pconn->playing;
2312
2313 if (!pplayer && !pconn->observer) {
2314 continue;
2315 }
2316 whole_map_iterate(&(wld.map), ptile) {
2317 if (pplayer == nullptr
2318 || map_get_player_site(ptile, pplayer) != nullptr) {
2319 send_city_info_at_tile(pplayer, pconn->self, nullptr, ptile);
2320 }
2322 }
2325 flush_packets();
2326}
2327
2328/************************************************************************/
2331void send_player_cities(struct player *pplayer)
2332{
2333 city_list_iterate(pplayer->cities, pcity) {
2334 if (city_refresh(pcity)) {
2335 log_error("%s radius changed while sending to player.",
2336 city_name_get(pcity));
2337
2338 /* Make sure that no workers in illegal position outside radius. */
2339 auto_arrange_workers(pcity);
2340 }
2341 send_city_info(pplayer, pcity);
2342 }
2344}
2345
2346/************************************************************************/
2351void send_city_info(struct player *dest, struct city *pcity)
2352{
2353 struct player *powner = city_owner(pcity);
2354
2355 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2356 return;
2357 }
2358
2359 if (dest == powner && send_city_suppressed) {
2360 return;
2361 }
2362
2363 if (!dest || dest == powner) {
2364 pcity->server.synced = TRUE;
2365 }
2366
2367 if (!dest) {
2368 broadcast_city_info(pcity);
2369 } else {
2370 send_city_info_at_tile(dest, dest->connections, pcity, pcity->tile);
2371 }
2372
2373 /* Sending counters */
2374 city_counters_refresh(pcity);
2375
2377 && player_list_size(team_members(powner->team)) > 1) {
2378 /* We want to send the new total bulbs production of the team. */
2379 send_research_info(research_get(powner), nullptr);
2380 }
2381}
2382
2383/************************************************************************/
2404 struct city *pcity, struct tile *ptile)
2405{
2406 struct packet_city_info packet;
2411 struct player *powner = nullptr;
2412 struct trade_route_packet_list *routes = nullptr;
2414
2415 if (!pcity) {
2416 pcity = tile_city(ptile);
2417 }
2418 if (pcity != nullptr && pcity->server.needs_arrange != CNA_NOT) {
2420
2421 return;
2422 }
2423 if (pcity) {
2424 powner = city_owner(pcity);
2425 }
2426
2427 if (any_web_conns()) {
2429 } else {
2430 webp_ptr = nullptr;
2431 }
2432
2433 if (powner != nullptr && powner == pviewer) {
2434 /* Send info to owner */
2435 /* This case implies powner non-nullptr which means pcity non-nullptr */
2436 if (!send_city_suppressed) {
2437 /* Wait that city has been rearranged, if it's currently
2438 * not in a sane state. */
2439
2440 routes = trade_route_packet_list_new();
2441
2442 /* Send all info to the owner */
2443 update_dumb_city(powner, pcity);
2444 package_city(pcity, &packet, &nat_packet, &rally_packet,
2445 webp_ptr, routes, FALSE);
2446 packet.original = city_original_owner(pcity, pviewer);
2447 lsend_packet_city_info(dest, &packet, FALSE);
2454 if (dest == powner->connections) {
2455 /* HACK: send also a copy to global observers. */
2456 packet.original = city_original_owner(pcity, nullptr);
2463 }
2465 }
2466 }
2467 } else {
2468 /* Send info to non-owner */
2469 if (!pviewer) { /* Observer */
2470 if (pcity) {
2471 routes = trade_route_packet_list_new();
2472
2473 /* Should be dumb_city info? */
2474 package_city(pcity, &packet, &nat_packet, &rally_packet,
2475 webp_ptr, routes, FALSE);
2476 lsend_packet_city_info(dest, &packet, FALSE);
2483 }
2484 } else {
2485 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2486 if (pcity) { /* It's there and we see it; update and send */
2487 update_dumb_city(pviewer, pcity);
2490 }
2491 } else { /* Not seen; send old info */
2492 if (map_is_known(ptile, pviewer)
2493 && map_get_player_site(ptile, pviewer) != nullptr) {
2496 }
2497 }
2498 }
2499 }
2500
2501 if (routes != nullptr) {
2506 }
2507}
2508
2509/************************************************************************/
2514void package_city(struct city *pcity, struct packet_city_info *packet,
2518 struct trade_route_packet_list *routes,
2519 bool dipl_invest)
2520{
2521 int i;
2522 int ppl = 0;
2523
2525
2526 packet->id = pcity->id;
2527 packet->owner = player_number(city_owner(pcity));
2528
2529 packet->tile = tile_index(city_tile(pcity));
2530 sz_strlcpy(packet->name, city_name_get(pcity));
2531
2532 packet->size = city_size_get(pcity);
2533 for (i = 0; i < FEELING_LAST; i++) {
2534 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2535 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2536 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2537 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2538 if (i == 0) {
2539 ppl += packet->ppl_happy[i];
2540 ppl += packet->ppl_content[i];
2541 ppl += packet->ppl_unhappy[i];
2542 ppl += packet->ppl_angry[i];
2543 }
2544 }
2545 /* The number of data in specialists[] array */
2548 packet->specialists[sp] = pcity->specialists[sp];
2549 ppl += packet->specialists[sp];
2551
2552 /* The nationality of the citizens. */
2553 nat_packet->id = pcity->id;
2554 nat_packet->nationalities_count = 0;
2556 int cit = 0;
2557
2558 player_slots_iterate(pslot) {
2559 citizens nationality = citizens_nation_get(pcity, pslot);
2560
2561 if (nationality != 0) {
2562 /* This player should exist! */
2563 fc_assert(player_slot_get_player(pslot) != nullptr);
2564
2565 nat_packet->nation_id[nat_packet->nationalities_count]
2566 = player_slot_index(pslot);
2567 nat_packet->nation_citizens[nat_packet->nationalities_count]
2568 = nationality;
2569 nat_packet->nationalities_count++;
2570
2571 cit += nationality;
2572 }
2574
2575 fc_assert(cit == packet->size);
2576 }
2577
2578 packet->history = pcity->history;
2579 packet->culture = city_culture(pcity);
2580 packet->buy_cost = city_production_buy_gold_cost(pcity);
2581
2582 if (packet->size != ppl) {
2583 static bool recursion = FALSE;
2584
2585 if (recursion) {
2586 /* Recursion didn't help. Do not enter infinite recursive loop.
2587 * Package city as it is. */
2588 log_error("Failed to fix inconsistent city size.");
2589 recursion = FALSE;
2590 } else {
2591 /* Note: If you get this error and try to debug the cause, you may find
2592 * using check_city_feelings() in some key points useful. */
2593 /* Have this as an fc_assert() first, so one can use '-F' to caught
2594 * these in debugger. */
2595 fc_assert(packet->size == ppl);
2596
2597 /* In all builds have an error message shown. */
2598 log_error("City size %d, citizen count %d for %s",
2599 packet->size, ppl, city_name_get(pcity));
2600
2601 /* Try to fix */
2602 city_refresh(pcity);
2603 auto_arrange_workers(pcity);
2604
2605 /* And repackage */
2606 recursion = TRUE;
2607 package_city(pcity, packet, nat_packet, rally_packet,
2608 web_packet, routes, dipl_invest);
2609 recursion = FALSE;
2610
2611 return;
2612 }
2613 }
2614
2615 packet->city_radius_sq = pcity->city_radius_sq;
2616
2617 i = 0;
2620 = fc_malloc(sizeof(struct packet_trade_route_info));
2621
2622 tri_packet->city = pcity->id;
2623 tri_packet->index = i;
2624 tri_packet->partner = proute->partner;
2625 tri_packet->value = proute->value;
2626 tri_packet->direction = proute->dir;
2627 tri_packet->goods = goods_number(proute->goods);
2628
2630
2631 i++;
2633
2634 packet->trade_route_count = i;
2635
2637 packet->surplus[o] = pcity->surplus[o];
2638 packet->waste[o] = pcity->waste[o];
2639 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2640 packet->prod[o] = pcity->prod[o];
2641 packet->citizen_base[o] = pcity->citizen_base[o];
2642 packet->usage[o] = pcity->usage[o];
2644
2645 packet->food_stock = pcity->food_stock;
2646 packet->shield_stock = pcity->shield_stock;
2647 packet->pollution = pcity->pollution;
2648 packet->illness_trade = pcity->illness_trade;
2649 packet->city_options = pcity->city_options;
2650
2651 packet->production_kind = pcity->production.kind;
2652 packet->production_value = universal_number(&pcity->production);
2653
2654 packet->turn_last_built = pcity->turn_last_built;
2655 packet->turn_founded = pcity->turn_founded;
2656
2657 packet->changed_from_kind = pcity->changed_from.kind;
2659
2661 packet->disbanded_shields = pcity->disbanded_shields;
2662 packet->caravan_shields = pcity->caravan_shields;
2664
2665 worklist_copy(&packet->worklist, &pcity->worklist);
2667
2668 packet->airlift = pcity->airlift;
2669 packet->did_buy = pcity->did_buy;
2670 packet->did_sell = pcity->did_sell;
2671 packet->was_happy = pcity->was_happy;
2672 packet->had_famine = pcity->had_famine;
2673
2674 packet->walls = city_citywalls_gfx(pcity);
2675 packet->style = pcity->style;
2676 packet->city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2677 packet->capital = pcity->capital;
2678 packet->steal = pcity->steal;
2679
2680 rally_packet->id = pcity->id;
2681 rally_packet->length = pcity->rally_point.length;
2682 rally_packet->persistent = pcity->rally_point.persistent;
2683 rally_packet->vigilant = pcity->rally_point.vigilant;
2684 if (pcity->rally_point.length) {
2685 memcpy(rally_packet->orders, pcity->rally_point.orders,
2686 pcity->rally_point.length * sizeof(struct unit_order));
2687 }
2688
2689 BV_CLR_ALL(packet->improvements);
2690 improvement_iterate(pimprove) {
2691 if (city_has_building(pcity, pimprove)) {
2692 BV_SET(packet->improvements, improvement_index(pimprove));
2693 }
2695
2696#ifdef FREECIV_WEB
2697 if (web_packet != nullptr) {
2698 struct tile *pcenter = city_tile(pcity);
2699 const struct civ_map *nmap = &(wld.map);
2700
2701 BV_CLR_ALL(web_packet->can_build_unit);
2702 BV_CLR_ALL(web_packet->can_build_improvement);
2703
2704 web_packet->id = pcity->id;
2705
2706 if (pcity->cm_parameter != nullptr) {
2707 web_packet->cma_enabled = TRUE;
2708 cm_copy_parameter(&web_packet->cm_parameter, pcity->cm_parameter);
2709 } else {
2710 web_packet->cma_enabled = FALSE;
2711 memset(&web_packet->cm_parameter, 0, sizeof(web_packet->cm_parameter));
2712 }
2713
2714 web_packet->granary_size = city_granary_size(city_size_get(pcity));
2715 web_packet->granary_turns = city_turns_to_grow(pcity);
2716
2717 improvement_iterate(pimprove) {
2718 if (can_city_build_improvement_now(pcity, pimprove)) {
2719 BV_SET(web_packet->can_build_improvement, improvement_index(pimprove));
2720 }
2722
2724 if (can_city_build_unit_now(pcity, punittype)) {
2725 BV_SET(web_packet->can_build_unit, utype_index(punittype));
2726 }
2728
2729 i = 0;
2731 web_packet->output_food[i] = city_tile_output_now(pcity, ptile, O_FOOD);
2732 web_packet->output_shield[i] = city_tile_output_now(pcity, ptile, O_SHIELD);
2733 web_packet->output_trade[i] = city_tile_output_now(pcity, ptile, O_TRADE);
2734
2735 i++;
2737 }
2738#endif /* FREECIV_WEB */
2739}
2740
2741/************************************************************************/
2751bool update_dumb_city(struct player *pplayer, struct city *pcity)
2752{
2753 bv_imprs improvements;
2754 struct tile *pcenter = city_tile(pcity);
2755 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2756 /* pcity->client.occupied isn't used at the server, so we go straight to
2757 * the unit list to check the occupied status. */
2758 bool occupied = (unit_list_size(pcenter->units) > 0);
2759 int walls = city_citywalls_gfx(pcity);
2760 bool happy = city_happy(pcity);
2761 bool unhappy = city_unhappy(pcity);
2762 int style = pcity->style;
2764 enum capital_type capital = pcity->capital;
2765
2766 /* Only someone knowing the tile should ever know a city on it. */
2767 fc_assert(map_is_known(pcenter, pplayer));
2768
2770 improvement_iterate(pimprove) {
2771 if (is_improvement_visible(pimprove)
2772 && city_has_building(pcity, pimprove)) {
2774 }
2776
2777 if (pdcity == nullptr) {
2780 } else if (pdcity->location != pcenter) {
2781 log_error("Trying to update bad city (wrong location) "
2782 "at %i,%i for player %s",
2783 TILE_XY(pcity->tile), player_name(pplayer));
2784 fc_assert(pdcity->location == pcenter);
2785 pdcity->location = pcenter; /* ?? */
2786 } else if (pdcity->identity != pcity->id) {
2787 log_error("Trying to update old city (wrong identity) "
2788 "at %i,%i for player %s",
2789 TILE_XY(city_tile(pcity)), player_name(pplayer));
2790 fc_assert(pdcity->identity == pcity->id);
2791 pdcity->identity = pcity->id; /* ?? */
2792 } else if (pdcity->occupied == occupied
2793 && pdcity->walls == walls
2794 && pdcity->happy == happy
2795 && pdcity->unhappy == unhappy
2796 && pdcity->style == style
2797 && pdcity->city_image == city_image
2798 && pdcity->capital == capital
2799 && BV_ARE_EQUAL(pdcity->improvements, improvements)
2801 && vision_site_owner(pdcity) == city_owner(pcity)
2802 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2803 return FALSE;
2804 }
2805
2807 pdcity->occupied = occupied;
2808 pdcity->walls = walls;
2809 pdcity->style = style;
2810 pdcity->city_image = city_image;
2811 pdcity->capital = capital;
2812 pdcity->happy = happy;
2813 pdcity->unhappy = unhappy;
2814 pdcity->improvements = improvements;
2815
2816 return TRUE;
2817}
2818
2819/************************************************************************/
2822void reality_check_city(struct player *pplayer, struct tile *ptile)
2823{
2824 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2825
2826 if (pdcity) {
2827 struct city *pcity = tile_city(ptile);
2828
2829 if (!pcity || pcity->id != pdcity->identity) {
2830 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2831
2832 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2833 fc_assert_ret(playtile->site == pdcity);
2834 playtile->site = nullptr;
2836 }
2837 }
2838}
2839
2840/************************************************************************/
2843void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2844{
2845 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2846
2847 if (pdcity) {
2848 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2849
2850 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2851 fc_assert_ret(playtile->site == pdcity);
2852 playtile->site = nullptr;
2854 }
2855}
2856
2857/************************************************************************/
2861static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2862 bool source_gone)
2863{
2864 struct player *plr1 = city_owner(pc1);
2865 struct player *plr2 = city_owner(pc2);
2868
2871
2872 if (plr1 == plr2) {
2873 if (source_gone) {
2876 _("Trade between %s and %s lost along with city."),
2878 } else {
2881 _("Trade route between %s and %s canceled."),
2883 }
2884 } else {
2885 if (source_gone) {
2888 /* TRANS: "...between Spanish city Madrid and Paris..." */
2889 _("Trade between %s city %s and %s lost along with "
2890 "their city."),
2892 /* It's implicit to removed city's owner that that city no longer
2893 * has trade routes, so say nothing in that case */
2894 } else {
2897 _("Sorry, the %s canceled the trade route "
2898 "from %s to your city %s."),
2902 /* TRANS: "...from Paris to Spanish city Madrid." */
2903 _("We canceled the trade route "
2904 "from %s to %s city %s."),
2906 }
2907 }
2908}
2909
2910/************************************************************************/
2919 struct trade_route *proute,
2920 bool announce, bool source_gone)
2921{
2922 struct city *pc2 = game_city_by_number(proute->partner);
2923 struct trade_route *back_route = nullptr;
2924
2925 fc_assert_ret_val(pc1 && proute, nullptr);
2926
2928
2929 if (pc2 != nullptr) {
2931 if (pc1->id == pback->partner) {
2932 back_route = pback;
2933 }
2935
2936 if (back_route != nullptr) {
2938 }
2939
2940 if (announce) {
2942
2945 }
2946 }
2947
2948 return back_route;
2949}
2950
2951/**********************************************************************/
2954bool city_illness_strike(struct city *pcity)
2955{
2957 ftc_server,
2958 _("%s has been struck by a plague! Population lost!"),
2959 city_link(pcity));
2960 if (city_reduce_size(pcity, 1, nullptr, "plague")) {
2961 pcity->turn_plague = game.info.turn;
2962
2963 /* Recalculate illness */
2964 pcity->server.illness = city_illness_calc(pcity, nullptr, nullptr,
2965 &(pcity->illness_trade),
2966 nullptr);
2967
2968 return TRUE;
2969 }
2970
2971 return FALSE;
2972}
2973
2974/************************************************************************/
2980void do_sell_building(struct player *pplayer, struct city *pcity,
2981 struct impr_type *pimprove, const char *reason)
2982{
2983 if (can_city_sell_building(pcity, pimprove)) {
2984 pplayer->economic.gold += impr_sell_gold(pimprove);
2985 building_lost(pcity, pimprove, reason, nullptr);
2986 }
2987}
2988
2989/************************************************************************/
3001struct city
3002*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
3003 struct player **oldcity_owner)
3004{
3005 struct city *oldcity = nullptr;
3006
3007 fc_assert_ret_val(!city_has_building(pcity, pimprove), nullptr);
3008
3009 if (is_great_wonder(pimprove)) {
3010 if (!(oldcity = city_from_great_wonder(pimprove))) {
3011 oldcity = pcity;
3012 }
3014 } else if (is_small_wonder(pimprove)) {
3015 if (!(oldcity
3016 = city_from_small_wonder(city_owner(pcity), pimprove))) {
3017 oldcity = pcity;
3018 }
3019 }
3020 if (oldcity && oldcity != pcity) {
3023 _("Moving %s"));
3024 } else {
3026 _("Acquiring %s"));
3027 }
3028
3029 return oldcity;
3030}
3031
3032/************************************************************************/
3035bool building_removed(struct city *pcity, const struct impr_type *pimprove,
3036 const char *reason, struct unit *destroyer)
3037{
3038 int backup = pcity->id;
3039
3040 city_remove_improvement(pcity, pimprove);
3041
3042 script_server_signal_emit("building_lost", pcity, pimprove, reason,
3043 destroyer);
3044
3045 return city_exist(backup);
3046}
3047
3048/************************************************************************/
3052void building_lost(struct city *pcity, const struct impr_type *pimprove,
3053 const char *reason, struct unit *destroyer)
3054{
3055 struct player *owner = city_owner(pcity);
3056 bool was_capital = is_capital(pcity);
3057 bool city_remains;
3058
3059 city_remains = building_removed(pcity, pimprove, reason, destroyer);
3060
3061 if ((was_capital && (!city_remains || !is_capital(pcity)))
3062 && (owner->spaceship.state == SSHIP_STARTED
3063 || owner->spaceship.state == SSHIP_LAUNCHED)) {
3064 /* If the capital was lost (by destruction of the palace) production on
3065 * the spaceship is lost. */
3067 }
3068
3069 if (city_remains) {
3070 /* Update city; influence of effects (buildings, ...) on unit upkeep */
3071 if (city_refresh(pcity)) {
3072 auto_arrange_workers(pcity);
3073 }
3074
3075 /* Re-update the city's visible area. This updates fog if the vision
3076 * range increases or decreases. */
3077 city_refresh_vision(pcity);
3078 }
3079}
3080
3081/************************************************************************/
3090{
3091 const struct unit_type *ut = unit_type_get(punit);
3092 struct player *plr = unit_owner(punit);
3093 bool update = FALSE;
3094 int cost;
3095
3097 cost = utype_upkeep_cost(ut, plr, o);
3098 if (cost > 0) {
3099 if (free_uk[o] > cost) {
3100 free_uk[o] -= cost;
3101 cost = 0;
3102 } else {
3103 cost -= free_uk[o];
3104 free_uk[o] = 0;
3105 }
3106 }
3107
3108 if (cost != punit->upkeep[o]) {
3109 update = TRUE;
3110 punit->upkeep[o] = cost;
3111 }
3113
3114 if (update) {
3115 /* Update unit information to the player and global observers. */
3116 send_unit_info(nullptr, punit);
3117 }
3118}
3119
3120/************************************************************************/
3140void city_units_upkeep(const struct city *pcity)
3141{
3142 int free_uk[O_LAST];
3143
3144 if (!pcity || !pcity->units_supported
3145 || unit_list_size(pcity->units_supported) < 1) {
3146 return;
3147 }
3148
3153
3154 /* Save the upkeep for all units in the corresponding punit struct */
3158}
3159
3160/************************************************************************/
3163void change_build_target(struct player *pplayer, struct city *pcity,
3164 struct universal *target,
3165 enum event_type event)
3166{
3167 const char *name;
3168 const char *source;
3169
3170 /* If the city is already building this thing, don't do anything */
3171 if (are_universals_equal(&pcity->production, target)) {
3172 return;
3173 }
3174
3175 /* Is the city no longer building a wonder? */
3176 if (VUT_IMPROVEMENT == pcity->production.kind
3178 && event != E_IMP_AUTO
3179 && event != E_WORKLIST) {
3180 /* If the build target is changed because of an advisor's suggestion or
3181 * because the worklist advances, then the wonder was completed --
3182 * don't announce that the player has *stopped* building that wonder.
3183 */
3185 _("The %s have stopped building The %s in %s."),
3186 nation_plural_for_player(pplayer),
3188 city_link(pcity));
3189 }
3190
3191 /* Manage the city change-production penalty.
3192 (May penalize, restore or do nothing to the shield_stock.) */
3193 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3194 pcity->shield_stock = city_change_production_penalty(pcity, target);
3195 }
3196
3197 /* Change build target. */
3198 pcity->production = *target;
3199
3200 /* What's the name of the target? */
3202
3203 switch (event) {
3204 case E_WORKLIST:
3205 /* TRANS: Possible 'source' of the production change
3206 * (in "<city> is building ..." sentence). Preserve leading space. */
3207 source = _(" from the worklist");
3208 break;
3209 case E_IMP_AUTO:
3210 /* TRANS: Possible 'source' of the production change
3211 * (in "<city> is building ..." sentence). Preserve leading space. */
3212 source = _(" as suggested by the advisor");
3213 break;
3214 default:
3215 source = "";
3216 break;
3217 }
3218
3219 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3220 city_name_get(pcity), name, source);
3221
3222 /* Tell the player what's up. */
3223 /* FIXME: this may give bad grammar when translated if the 'source'
3224 * string can have multiple values. */
3225 notify_player(pplayer, city_tile(pcity), event, ftc_server,
3226 /* TRANS: "<city> is building <production><source>."
3227 * 'source' might be an empty string, or a clause like
3228 * " from the worklist". */
3229 _("%s is building %s%s."),
3230 city_link(pcity),
3231 name, source);
3232
3233 /* If the city is building a wonder, tell the rest of the world
3234 about it. */
3235 if (VUT_IMPROVEMENT == pcity->production.kind
3238 _("The %s have started building The %s in %s."),
3239 nation_plural_for_player(pplayer),
3240 name,
3241 city_link(pcity));
3242 }
3243}
3244
3245/************************************************************************/
3252void city_map_update_empty(struct city *pcity, struct tile *ptile)
3253{
3254 tile_set_worked(ptile, nullptr);
3255 send_tile_info(nullptr, ptile, FALSE);
3256 pcity->server.synced = FALSE;
3257}
3258
3259/************************************************************************/
3266void city_map_update_worker(struct city *pcity, struct tile *ptile)
3267{
3268 tile_set_worked(ptile, pcity);
3269 send_tile_info(nullptr, ptile, FALSE);
3270 pcity->server.synced = FALSE;
3271}
3272
3273/************************************************************************/
3278static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3279{
3280 struct city *pwork = tile_worked(ptile);
3281
3282 if (pwork != nullptr
3283 && !is_free_worked(pwork, ptile)
3284 && !city_can_work_tile(pwork, ptile)) {
3285 tile_set_worked(ptile, nullptr);
3286 send_tile_info(nullptr, ptile, FALSE);
3287
3288 pwork->specialists[DEFAULT_SPECIALIST]++; /* Keep city sanity */
3289 pwork->server.synced = FALSE;
3290
3291 if (queued) {
3292 city_freeze_workers_queue(pwork); /* Place the displaced later */
3293 } else {
3294 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3296 send_city_info(nullptr, pwork);
3297 }
3298 return TRUE;
3299 }
3300
3301 return FALSE;
3302}
3303
3304/************************************************************************/
3310{
3311 return city_map_update_tile_direct(ptile, TRUE);
3312}
3313
3314/************************************************************************/
3318{
3319 return city_map_update_tile_direct(ptile, FALSE);
3320}
3321
3322/************************************************************************/
3326void sync_cities(void)
3327{
3329 return;
3330 }
3331
3332 players_iterate(pplayer) {
3333 city_list_iterate(pplayer->cities, pcity) {
3334 if (!pcity->server.synced) {
3335 /* Sending will set to TRUE. */
3336 send_city_info(pplayer, pcity);
3337 }
3340}
3341
3342/************************************************************************/
3345void city_map_update_all(struct city *pcity)
3346{
3347 struct tile *pcenter = city_tile(pcity);
3348 const struct civ_map *nmap = &(wld.map);
3349
3351 ptile, _index, _x, _y) {
3352 /* Bypass city_map_update_tile_now() for efficiency */
3355}
3356
3357/************************************************************************/
3361{
3362 city_list_iterate(pplayer->cities, pcity) {
3363 city_freeze_workers(pcity);
3364 city_map_update_all(pcity);
3365 city_thaw_workers(pcity);
3367}
3368
3369/************************************************************************/
3380{
3381 adjc_iterate(&(wld.map), ptile, tile1) {
3382 struct city *pcity = tile_city(tile1);
3383
3384 if (pcity) {
3385 struct player *pplayer = city_owner(pcity);
3386 const struct req_context city_ctxt = {
3387 .player = pplayer,
3388 .city = pcity,
3389 .tile = pcity->tile,
3390 };
3391
3392 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3393 city_built_iterate(pcity, pimprove) {
3394 if (!can_city_sell_building(pcity, pimprove)) {
3395 continue;
3396 }
3397
3398 requirement_vector_iterate(&pimprove->reqs, preq) {
3399 if ((VUT_TERRAIN == preq->source.kind
3400 || VUT_TERRAINCLASS == preq->source.kind
3401 || VUT_TERRFLAG == preq->source.kind)
3402 && !is_req_active(&city_ctxt, nullptr, preq, RPT_CERTAIN)) {
3403 int price = impr_sell_gold(pimprove);
3404
3405 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3407 PL_("You sell %s in %s (now landlocked)"
3408 " for %d gold.",
3409 "You sell %s in %s (now landlocked)"
3410 " for %d gold.", price),
3412 city_link(pcity), price);
3413 }
3416 }
3418}
3419
3420/************************************************************************/
3426void city_refresh_vision(struct city *pcity)
3427{
3428 if (pcity->server.vision != nullptr) {
3429 v_radius_t vision_radius_sq
3431
3432 vision_change_sight(pcity->server.vision, vision_radius_sq);
3433 ASSERT_VISION(pcity->server.vision);
3434 }
3435}
3436
3437/************************************************************************/
3442{
3443 city_list_iterate(pplayer->cities, pcity) {
3444 city_refresh_vision(pcity);
3446}
3447
3448/************************************************************************/
3452{
3453 fc_assert_ret_val(pcity != nullptr, FALSE);
3454
3459 const struct civ_map *nmap = &(wld.map);
3460
3461 /* Check minimum / maximum allowed city radii */
3464
3466 /* No change */
3467 return FALSE;
3468 }
3469
3470 /* Get number of city tiles for each radii */
3473
3475 /* A change of the squared city radius but no change of the number of
3476 * city tiles */
3477 return FALSE;
3478 }
3479
3480 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3482
3483 /* Workers map before */
3484 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3485 city_name_get(pcity), pcity->id, city_size_get(pcity),
3486 city_specialists(pcity));
3488
3490
3492 /* Increased number of city tiles */
3493 city_refresh_vision(pcity);
3494 } else {
3495 /* Reduced number of city tiles */
3496 int workers = 0;
3497
3498 /* Remove workers from the tiles removed rom the city map */
3500 city_x, city_y) {
3501 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3503 city_y);
3504
3505 if (ptile && pcity == tile_worked(ptile)) {
3506 city_map_update_empty(pcity, ptile);
3507 workers++;
3508 }
3510
3511 /* Add workers to free city tiles */
3512 if (workers > 0) {
3513 int radius_sq = city_map_radius_sq_get(pcity);
3514
3516 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3517 city_x, city_y);
3518
3519 if (ptile && !is_free_worked(pcity, ptile)
3520 && tile_worked(ptile) != pcity
3521 && city_can_work_tile(pcity, ptile)) {
3522 city_map_update_worker(pcity, ptile);
3523 workers--;
3524 }
3525
3526 if (workers <= 0) {
3527 break;
3528 }
3530 }
3531
3532 /* If there still are workers they will be updated to specialists */
3533 if (workers > 0) {
3534 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3535 }
3536
3537 city_refresh_vision(pcity);
3538 }
3539
3540 /* City removal might be ongoing, and advisor data already deleted */
3541 if (pcity->server.adv != nullptr) {
3542 /* If city is under AI control, update it */
3543 adv_city_update(pcity);
3544 }
3545
3547 ftc_server, _("The size of the city map of %s is %s."),
3548 city_name_get(pcity),
3549 city_tiles_old < city_tiles_new ? _("increased")
3550 : _("reduced"));
3551
3552 /* Workers map after */
3553 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3554 city_name_get(pcity), pcity->id, city_size_get(pcity),
3555 city_specialists(pcity));
3557
3558 return TRUE;
3559}
3560
3561/************************************************************************/
3564void clear_worker_task(struct city *pcity, struct worker_task *ptask)
3565{
3566 struct packet_worker_task packet;
3567
3568 if (ptask == nullptr) {
3569 return;
3570 }
3571
3573
3574 packet.city_id = pcity->id;
3575 packet.tile_id = tile_index(ptask->ptile);
3576 packet.activity = ACTIVITY_LAST;
3577 packet.tgt = 0;
3578 packet.want = 0;
3579
3580 free(ptask);
3581
3584}
3585
3586/************************************************************************/
3589void clear_worker_tasks(struct city *pcity)
3590{
3591 while (worker_task_list_size(pcity->task_reqs) > 0) {
3593 }
3594}
3595
3596/************************************************************************/
3600{
3601 struct packet_worker_task packet;
3602
3603 packet.city_id = pcity->id;
3604
3606 packet.tile_id = tile_index(ptask->ptile);
3607 packet.activity = ptask->act;
3608 if (ptask->tgt == nullptr) {
3609 packet.tgt = -1;
3610 } else {
3611 packet.tgt = extra_number(ptask->tgt);
3612 }
3613 packet.want = ptask->want;
3614
3618}
3619
3620/************************************************************************/
3623int city_production_buy_gold_cost(const struct city *pcity)
3624{
3625 int build = pcity->shield_stock;
3626
3627 switch (pcity->production.kind) {
3628 case VUT_IMPROVEMENT:
3629 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3630 build);
3631 case VUT_UTYPE:
3632 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3633 build);
3634 default:
3635 break;
3636 };
3637
3638 return FC_INFINITY;
3639}
3640
3641/************************************************************************/
3646 const struct impr_type *pimprove,
3647 const char *format)
3648{
3649 if (is_wonder(pimprove)) {
3650 /* Only wonders may grant governments */
3651 struct cur_govs_data *govs_data;
3652 char buf[250];
3653
3655 city_add_improvement(pcity, pimprove);
3656
3657 fc_snprintf(buf, sizeof(buf), format,
3659
3660 players_iterate_alive(pplayer) {
3663
3665 } else {
3666 city_add_improvement(pcity, pimprove);
3667 }
3668}
3669
3670/************************************************************************/
3674int city_original_owner(const struct city *pcity,
3675 const struct player *known_for)
3676{
3677 if (pcity->original == nullptr) {
3678 /* Nobody knows */
3679 return MAX_NUM_PLAYER_SLOTS;
3680 }
3681
3682 if (pcity->original != known_for
3683 || known_for == nullptr) {
3684 /* Players know what they have built themselves,
3685 * global observer knows everything. */
3686 return player_number(pcity->original);
3687 }
3688
3689 return MAX_NUM_PLAYER_SLOTS;
3690}
#define ACTION_NONE
Definition actions.h:55
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:359
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
#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:3597
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:148
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:737
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1141
int city_granary_size(int city_size)
Definition city.c:2129
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2193
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Definition city.c:1011
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:305
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1236
bool is_capital(const struct city *pcity)
Definition city.c:1575
const char * city_name_get(const struct city *pcity)
Definition city.c:1133
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3367
struct output_type * get_output_type(Output_type_id output)
Definition city.c:638
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2183
bool city_unhappy(const struct city *pcity)
Definition city.c:1622
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3426
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1675
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2867
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1882
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:1483
bool city_happy(const struct city *pcity)
Definition city.c:1610
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3353
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1380
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:446
citizens city_specialists(const struct city *pcity)
Definition city.c:3313
void city_choose_build_default(struct city *pcity)
Definition city.c:1083
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1691
int city_map_tiles(int city_radius_sq)
Definition city.c:171
bool city_exist(int id)
Definition city.c:3568
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1452
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1992
void city_rally_point_clear(struct city *pcity)
Definition city.c:3622
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:948
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:700
#define cities_iterate_end
Definition city.h:517
@ CNA_BROADCAST_PENDING
Definition city.h:308
@ CNA_NOT
Definition city.h:306
@ CNA_NORMAL
Definition city.h:307
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
#define cities_iterate(pcity)
Definition city.h:512
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:214
@ CITIZEN_ANGRY
Definition city.h:271
@ CITIZEN_HAPPY
Definition city.h:268
@ CITIZEN_CONTENT
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:270
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:84
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
Definition city.h:188
#define output_type_iterate(output)
Definition city.h:836
#define city_owner(_pcity_)
Definition city.h:563
#define city_tile_iterate_skip_free_worked_end
Definition city.h:222
#define city_list_iterate_end
Definition city.h:510
#define city_map_iterate_radius_sq_end
Definition city.h:193
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
@ FEELING_LAST
Definition city.h:285
#define city_tile_iterate_end
Definition city.h:238
#define city_built_iterate(_pcity, _p)
Definition city.h:825
#define city_map_iterate_without_index_end
Definition city.h:184
#define city_built_iterate_end
Definition city.h:831
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:180
#define output_type_iterate_end
Definition city.h:842
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3252
void city_freeze_workers_queue(struct city *pcity)
Definition citytools.c:160
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:2514
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3317
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:453
static int city_citywalls_gfx(const struct city *pcity)
Definition citytools.c:2149
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3278
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3599
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3623
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2351
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2751
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:3002
static void raze_city(struct city *pcity)
Definition citytools.c:923
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1429
static bool city_workers_queue_remove(struct city *pcity)
Definition citytools.c:179
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:851
void refresh_dumb_city(struct city *pcity)
Definition citytools.c:2203
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2170
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1514
bool send_city_suppression(bool now)
Definition citytools.c:2159
static bool send_city_suppressed
Definition citytools.c:101
void sync_cities(void)
Definition citytools.c:3326
static const char * search_for_city_name(struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
Definition citytools.c:333
static void announce_trade_route_removal(struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
Definition citytools.c:2861
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:136
void update_unit_upkeep(struct unit *punit, int free_uk[O_LAST])
Definition citytools.c:3089
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3441
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3674
static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders)
Definition citytools.c:1014
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3451
int build_points_left(struct city *pcity)
Definition citytools.c:571
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3163
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3035
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3360
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2954
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3309
void city_thaw_workers(struct city *pcity)
Definition citytools.c:146
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2843
static bool is_default_city_name(const char *name, struct player *pplayer)
Definition citytools.c:315
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3052
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1981
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3564
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:957
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3140
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3589
bool is_allowed_city_name(struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
Definition citytools.c:369
static void transfer_unit(struct unit *punit, struct city *tocity, bool rehome, bool verbose)
Definition citytools.c:585
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
Definition citytools.c:3379
void remove_city(struct city *pcity)
Definition citytools.c:1702
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:2980
static struct city_list * arrange_workers_queue
Definition citytools.c:98
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2918
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1674
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2403
static int evaluate_city_name_priority(struct tile *ptile, const struct nation_city *pncity, int default_priority)
Definition citytools.c:214
void city_thaw_workers_queue(void)
Definition citytools.c:192
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2232
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:1072
void city_add_improvement_with_gov_notice(struct city *pcity, const struct impr_type *pimprove, const char *format)
Definition citytools.c:3645
void send_player_cities(struct player *pplayer)
Definition citytools.c:2331
void city_map_update_all(struct city *pcity)
Definition citytools.c:3345
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:716
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Definition citytools.c:3266
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2822
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2307
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3426
#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:365
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:196
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3550
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4603
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:761
bool city_refresh(struct city *pcity)
Definition cityturn.c:158
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:181
void city_refresh_queue_processing(void)
Definition cityturn.c:212
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:234
enum announce_type announce
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2171
char * incite_cost
Definition comments.c:74
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:366
struct connection * conn_by_user(const char *user_name)
Definition connection.c:377
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:356
bool conn_is_global_observer(const struct connection *pconn)
Definition connection.c:753
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
#define conn_list_iterate_end
Definition connection.h:110
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
int city_culture(const struct city *pcity)
Definition culture.c:29
static void homeless(QVariant data1, QVariant data2)
Definition dialogs.cpp:2425
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
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:74
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1066
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:980
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
enum event_type event
Definition events.c:81
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:641
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
#define MAX_NUM_BUILDING_LIST
Definition fc_types.h:46
unsigned char citizens
Definition fc_types.h:392
int Impr_type_id
Definition fc_types.h:380
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
@ RPT_CERTAIN
Definition fc_types.h:678
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
#define MAX_LEN_CITYNAME
Definition fc_types.h:67
signed short Continent_id
Definition fc_types.h:376
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:92
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
void fc_mutex_allocate(fc_mutex *mutex)
void fc_mutex_release(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:61
struct city * game_city_by_name(const char *name)
Definition game.c:87
struct world wld
Definition game.c:62
struct unit * game_unit_by_number(int id)
Definition game.c:115
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:184
struct city * game_city_by_number(int id)
Definition game.c:106
#define any_web_conns()
Definition game.h:316
@ 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:910
struct city * owner
Definition citydlg.c:226
static GtkWidget * source
Definition gotodlg.c:58
GType type
Definition repodlgs.c:1313
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:67
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_wonder(const struct impr_type *pimprove)
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:502
void adv_city_update(struct city *pcity)
Definition infracache.c:463
void adv_city_alloc(struct city *pcity)
Definition infracache.c:489
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:1026
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Definition map.c:673
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:636
#define adjc_iterate_end
Definition map.h:419
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:414
#define whole_map_iterate(_map, _tile)
Definition map.h:531
#define whole_map_iterate_end
Definition map.h:540
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2538
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2212
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:901
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2626
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:491
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1374
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:775
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:418
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2729
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:927
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1166
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2291
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1446
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:241
void map_clear_border(struct tile *ptile)
Definition maphand.c:2242
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1389
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2526
#define map_get_player_site(_ptile_, _pplayer_)
Definition maphand.h:93
#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:289
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:318
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:330
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:242
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:490
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:464
const char * nation_city_name(const struct nation_city *pncity)
Definition nation.c:412
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Definition nation.c:331
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
enum nation_city_preference nation_city_preference_revert(enum nation_city_preference prefer)
Definition nation.c:371
Nation_type_id nation_count(void)
Definition nation.c:507
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
enum nation_city_preference nation_city_terrain_preference(const struct nation_city *pncity, const struct terrain *pterrain)
Definition nation.c:422
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Definition nation.c:434
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:84
nation_city_preference
Definition nation.h:39
@ NCP_NONE
Definition nation.h:41
@ NCP_DISLIKE
Definition nation.h:40
@ NCP_LIKE
Definition nation.h:42
#define nation_city_list_iterate(citylist, pncity)
Definition nation.h:48
#define nation_list_iterate_end
Definition nation.h:86
#define nation_city_list_iterate_end
Definition nation.h:50
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:292
#define web_send_packet(packetname, pconn,...)
Definition packets.h:56
#define web_lsend_packet(packetname,...)
Definition packets.h:57
int send_packet_city_rally_point(struct connection *pc, const struct packet_city_rally_point *packet, bool force_to_send)
void dlsend_packet_city_remove(struct conn_list *dest, int city_id)
void lsend_packet_city_nationalities(struct conn_list *dest, const struct packet_city_nationalities *packet, bool force_to_send)
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)
int dsend_packet_city_remove(struct connection *pc, int city_id)
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:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1996
int player_index(const struct player *pplayer)
Definition player.c:829
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1133
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1149
#define players_iterate_end
Definition player.h:539
#define players_iterate(_pplayer)
Definition player.h:534
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define player_slots_iterate(_pslot)
Definition player.h:525
#define is_ai(plr)
Definition player.h:232
#define players_iterate_alive_end
Definition player.h:549
#define player_slots_iterate_end
Definition player.h:529
#define players_iterate_alive(_pplayer)
Definition player.h:544
int normal_player_count(void)
Definition plrhand.c:3211
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2960
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2362
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3010
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2913
void update_capital(struct player *pplayer)
Definition plrhand.c:731
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
#define allowed_nations_iterate_end
Definition plrhand.h:73
#define fc_rand(_size)
Definition rand.h:56
bool is_req_active(const struct req_context *context, const struct req_context *other_context, 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:128
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:416
#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:376
static struct setting settings[]
Definition settings.c:1474
bool is_ascii_name(const char *name)
Definition shared.c:286
#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:431
@ 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:45
int identity_number(void)
Definition srv_main.c:2061
enum server_states server_state(void)
Definition srv_main.c:338
int turn
Definition city.h:246
Definition city.h:320
struct worker_task_list * task_reqs
Definition city.h:412
int turn_last_built
Definition city.h:387
int surplus[O_LAST]
Definition city.h:355
int food_stock
Definition city.h:367
struct built_status built[B_LAST]
Definition city.h:394
struct player * original
Definition city.h:324
int history
Definition city.h:410
int * counter_values
Definition city.h:408
int pollution
Definition city.h:369
bool did_sell
Definition city.h:380
int id
Definition city.h:326
int last_turns_shield_surplus
Definition city.h:392
enum capital_type capital
Definition city.h:328
int disbanded_shields
Definition city.h:391
int waste[O_LAST]
Definition city.h:356
int workers_frozen
Definition city.h:437
int turn_plague
Definition city.h:374
bv_city_options city_options
Definition city.h:403
int city_radius_sq
Definition city.h:375
bool was_happy
Definition city.h:381
struct player * owner
Definition city.h:323
enum city_acquire_type acquire_t
Definition city.h:329
int turn_founded
Definition city.h:386
int airlift
Definition city.h:378
int citizen_base[O_LAST]
Definition city.h:359
int caravan_shields
Definition city.h:390
bool did_buy
Definition city.h:379
struct trade_route_list * routes
Definition city.h:344
enum city_needs_arrange needs_arrange
Definition city.h:441
int usage[O_LAST]
Definition city.h:360
struct worklist worklist
Definition city.h:401
struct universal production
Definition city.h:396
struct unit_order * orders
Definition city.h:422
struct city::@16 rally_point
struct adv_city * adv
Definition city.h:452
citizens * nationality
Definition city.h:341
bool vigilant
Definition city.h:421
int steal
Definition city.h:414
int unhappy_penalty[O_LAST]
Definition city.h:357
int illness
Definition city.h:434
int before_change_shields
Definition city.h:389
int style
Definition city.h:327
bool had_famine
Definition city.h:382
size_t length
Definition city.h:417
bool synced
Definition city.h:448
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:333
citizens specialists[SP_MAX]
Definition city.h:336
struct tile * tile
Definition city.h:322
int shield_stock
Definition city.h:368
int prod[O_LAST]
Definition city.h:358
struct vision * vision
Definition city.h:455
struct city::@17::@19 server
struct cm_parameter * cm_parameter
Definition city.h:425
struct universal changed_from
Definition city.h:399
struct unit_list * units_supported
Definition city.h:406
int illness_trade
Definition city.h:370
bool persistent
Definition city.h:419
enum city_names_mode allowed_city_names
Definition game.h:127
struct civ_game::@31::@35::@39 mutexes
bool vision_reveal_tiles
Definition game.h:200
struct conn_list * glob_observers
Definition game.h:98
fc_mutex city_list
Definition game.h:271
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:167
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:109
bool savepalace
Definition game.h:187
struct civ_game::@31::@35 server
struct civ_game::@30 rgame
int razechance
Definition game.h:176
int init_buildings[MAX_NUM_BUILDING_LIST]
Definition nation.h:123
struct nation_list * parent_nations
Definition nation.h:136
struct nation_type::@51::@53 server
struct nation_list * civilwar_nations
Definition nation.h:135
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]
enum capital_type capital
char name[MAX_LEN_CITYNAME]
enum unit_activity activity
struct city_list * cities
Definition player.h:281
bv_plr_flags flags
Definition player.h:292
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
const struct player * player
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition unit.h:140
int upkeep[O_LAST]
Definition unit.h:150
int id
Definition unit.h:147
bool moved
Definition unit.h:176
struct unit::@81::@84 server
struct tile * tile
Definition unit.h:142
int homecity
Definition unit.h:148
struct unit * transporter
Definition unit.h:186
const struct unit_type * utype
Definition unit.h:141
bool dying
Definition unit.h:253
enum universals_n kind
Definition fc_types.h:880
universals_u value
Definition fc_types.h:879
bool happy
Definition vision.h:119
bv_imprs improvements
Definition vision.h:125
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 civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define sz_strlcpy(dest, src)
Definition support.h:189
#define fc__attribute(x)
Definition support.h:99
#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
void free_current_governments_data(struct cur_govs_data *data)
Definition techtools.c:1537
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1233
void notify_new_government_options(struct player *pplayer, struct cur_govs_data *data, const char *reason)
Definition techtools.c:1551
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
struct cur_govs_data * create_current_governments_data_all(void)
Definition techtools.c:1517
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:612
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
bool is_terrain_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:348
#define terrain_type_iterate(_p)
Definition terrain.h:266
#define terrain_type_iterate_end
Definition terrain.h:272
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:601
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:101
#define tile_index(_pt_)
Definition tile.h:89
#define tile_worked(_tile)
Definition tile.h:115
#define tile_terrain(_tile)
Definition tile.h:111
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_continent(_tile)
Definition tile.h:93
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
#define tile_owner(_tile)
Definition tile.h:97
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, int priority)
#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:698
const struct impr_type * building
Definition fc_types.h:691
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1960
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:866
#define unit_tile(_pu)
Definition unit.h:397
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:420
#define unit_owner(_pu)
Definition unit.h:396
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6613
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:4040
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void unit_make_contact(const struct unit *punit, struct tile *ptile, struct player *pplayer)
Definition unittools.c:5177
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1402
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2865
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2878
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:801
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2140
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:5018
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1226
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Definition unittype.c:1492
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:1587
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1927
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:387
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:264
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:859
#define unit_type_iterate_end
Definition unittype.h:866
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