Freeciv-3.2
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 "autosettlers.h"
84#include "infracache.h"
85
86/* server/scripting */
87#include "script_server.h"
88
89/* ai */
90#include "handicaps.h"
91
92/* ai */
93#include "handicaps.h"
94
95#include "citytools.h"
96
97
98/* Queue for pending auto_arrange_workers() */
99static struct city_list *arrange_workers_queue = NULL;
100
101/* Suppress sending cities during game_load() and end_phase() */
103
104static bool city_workers_queue_remove(struct city *pcity);
105
106static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
107 bool source_gone)
108 fc__attribute((nonnull (1, 2)));
109
110/************************************************************************/
137void city_freeze_workers(struct city *pcity)
138{
139 pcity->server.workers_frozen++;
140}
141
142/************************************************************************/
147void city_thaw_workers(struct city *pcity)
148{
149 pcity->server.workers_frozen--;
150 fc_assert(pcity->server.workers_frozen >= 0);
151 if (pcity->server.workers_frozen == 0
152 && pcity->server.needs_arrange != CNA_NOT) {
153 city_refresh(pcity); /* Citizen count sanity */
155 }
156}
157
158/************************************************************************/
162{
165 } else if (city_list_find_number(arrange_workers_queue, pcity->id)) {
166 return;
167 }
168
170 city_freeze_workers(pcity);
171 if (pcity->server.needs_arrange == CNA_NOT) {
173 }
174}
175
176/************************************************************************/
180static bool city_workers_queue_remove(struct city *pcity)
181{
183 return FALSE;
184 }
185
187}
188
189/************************************************************************/
206
207/************************************************************************/
215static int evaluate_city_name_priority(struct tile *ptile,
216 const struct nation_city *pncity,
218{
219 /* Lower values mean higher priority. */
222
223 /* Increasing this value will increase the difference caused by
224 (non-)matching terrain. A matching terrain is mult_factor
225 "better" than an unlisted terrain, which is mult_factor
226 "better" than a non-matching terrain. */
227 const float mult_factor = 1.4;
228 bool river = FALSE;
229
230 /*
231 * If natural city names aren't being used, we just return the
232 * base value. This will have the effect of the first-listed
233 * city being used. We do this here rather than special-casing
234 * it elsewhere because this localizes everything to this
235 * function, even though it's a bit inefficient.
236 */
238 return default_priority;
239 }
240
241 /*
242 * Assuming we're using the natural city naming system, we use
243 * an internal alorithm to calculate the priority of each name.
244 * It's a pretty fuzzy algorithm; we basically do the following:
245 * - Change the priority scale from 0..n to 10..n+10. This means
246 * each successive city is 10% lower priority than the first.
247 * - Multiply by a semi-random number. This has the effect of
248 * decreasing rounding errors in the successive calculations,
249 * as well as introducing a smallish random effect.
250 * - Check over all the applicable terrains, and
251 * multiply or divide the priority based on whether or not
252 * the terrain matches. See comment below.
253 */
254
255 priority += 10.0;
256 priority *= 10.0 + fc_rand(5);
257
258 /*
259 * The terrain priority in the struct nation_city will be either
260 * -1, 0, or 1. We therefore take this as-is if the terrain is
261 * present, or negate it if not.
262 *
263 * The reason we multiply as well as divide the value is so
264 * that cities that don't care what terrain they are on (which
265 * is the default) will be left in the middle of the pack. If
266 * we _only_ multiplied (or divided), then cities that had more
267 * terrain labels would have their priorities hurt (or helped).
268 */
271 if (tile_has_extra(ptile, priver)
273 river = TRUE;
274 break;
275 }
277 if (!river) {
279 }
280
281 switch (goodness) {
282 case NCP_DISLIKE:
284 break;
285 case NCP_NONE:
286 break;
287 case NCP_LIKE:
289 break;
290 }
291
292 terrain_type_iterate(pterrain) {
293 /* Now we do the same for every available terrain. */
295 if (!is_terrain_near_tile(&(wld.map), ptile, pterrain, TRUE)) {
297 }
298 switch (goodness) {
299 case NCP_DISLIKE:
301 break;
302 case NCP_NONE:
303 break;
304 case NCP_LIKE:
306 }
308
309 return (int) priority;
310}
311
312/************************************************************************/
316static bool is_default_city_name(const char *name, struct player *pplayer)
317{
319 pncity) {
321 return TRUE;
322 }
324 return FALSE;
325}
326
327/************************************************************************/
334static const char *search_for_city_name(struct tile *ptile,
335 const struct nation_city_list *
336 default_cities,
337 struct player *pplayer)
338{
339 int choice = 0, priority, best_priority = -1;
340 const char *name, *best_name = NULL;
341
342 nation_city_list_iterate(default_cities, pncity) {
345 && is_allowed_city_name(pplayer, name, NULL, 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 = NULL;
407
409 if (player2 != pplayer && is_default_city_name(cityname, player2)) {
410 pother = player2;
411 break;
412 }
414
415 if (pother != NULL) {
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 the
430 * original nation are exhausted and the backup nations have non-ascii
431 * 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 (NULL != name) {
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 (NULL != name) {
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);
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
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 }
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 }
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 = NULL;
860 int best_dist = -1;
861
862 fc_assert_ret_val(ptile != NULL, NULL);
863
864 if (pplayer != NULL && only_player && only_enemy) {
865 log_error("Non of my own cities will be at war with me!");
866 return NULL;
867 }
868
869 con = tile_continent(ptile);
870
872 if (pplayer != NULL && only_player && pplayer != aplayer) {
873 /* only cities of player 'pplayer' */
874 continue;
875 }
876
877 if (pplayer != NULL && 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 == NULL
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 of NULL as destroyer */
939 city_remains = building_removed(pcity, pimprove, "razed", NULL);
940 if (!city_remains) {
941 break;
942 }
943 }
945
946 if (city_remains) {
948 pcity->shield_stock = 0;
949 }
950}
951
952/************************************************************************/
956static void reestablish_city_trade_routes(struct city *pcity)
957{
959 bool keep_route;
960 struct trade_route *back;
961 struct city *partner = game_city_by_number(proute->partner);
962
963 /* Remove the city's trade routes (old owner).
964 * Do not announce removal as we might restore the route immediately below */
966
967 keep_route = can_cities_trade(pcity, partner)
968 && can_establish_trade_route(pcity, partner);
969
970 if (!keep_route) {
971 enum trade_route_type type = cities_trade_route_type(pcity, partner);
973
974 if (settings->cancelling != TRI_CANCEL) {
976 }
977 }
978
979 /* Readd the city's trade route (new owner) */
980 if (keep_route) {
983 } else {
984 free(proute);
985 free(back);
986
987 /* Now announce the trade route removal */
988 announce_trade_route_removal(pcity, partner, FALSE);
989 }
990
991 /* Refresh regardless; either it lost a trade route or the trade
992 * route revenue changed. */
993 city_refresh(partner);
994 send_city_info(city_owner(partner), partner);
995
996 /* Give the new owner infos about the city which has a trade route
997 * with the transferred city. */
999 struct player *owner = city_owner(pcity);
1000
1001 map_show_tile(owner, partner->tile);
1002 update_dumb_city(owner, partner);
1003 send_city_info(owner, partner);
1004 }
1006}
1007
1008/************************************************************************/
1013static void build_free_small_wonders(struct player *pplayer,
1015{
1016 int size = city_list_size(pplayer->cities);
1017
1018 if (!game.server.savepalace) {
1019 /* Nothing to do */
1020 return;
1021 }
1022
1023 if (size == 0) {
1024 /* The last city was removed or transferred to the enemy.
1025 * If the victim survives to found or acquire another city, they'll
1026 * get any savepalace initial buildings then. */
1027 return;
1028 }
1029
1030 improvement_iterate(pimprove) {
1033 /* FIXME: instead, find central city */
1034 struct city *pnew_city = city_list_get(pplayer->cities, fc_rand(size));
1035
1036 fc_assert_action(NULL == city_from_small_wonder(pplayer, pimprove),
1037 continue);
1038
1040
1041 /*
1042 * send_player_cities will recalculate all cities and send them to
1043 * the client.
1044 */
1045 send_player_cities(pplayer);
1046
1048 /* FIXME: should already be notified about city loss? */
1049 /* TRANS: <building> ... <city> */
1050 _("A replacement %s was built in %s."),
1053 /*
1054 * The enemies want to see the new capital in their intelligence
1055 * report.
1056 */
1058 }
1060}
1061
1062/************************************************************************/
1071bool transfer_city(struct player *ptaker, struct city *pcity,
1073 bool resolve_stack, bool raze, bool build_free)
1074{
1076 struct vision *old_vision, *new_vision;
1077 struct unit_list *old_city_units = unit_list_new();
1078 struct player *pgiver = city_owner(pcity);
1079 struct tile *pcenter = city_tile(pcity);
1080 int saved_id = pcity->id;
1081 bool city_remains = TRUE;
1082 bool had_great_wonders = FALSE;
1087 bool taker_had_no_cities = (city_list_size(ptaker->cities) == 0);
1088 bool new_extras;
1089 int units_num = 0;
1090 const int ul_size = unit_list_size(pcenter->units);
1091 int central_units[ul_size + 1];
1093 int i;
1094
1096
1100
1101 if (units_num > 0) {
1103
1104 /* Remember what player see what unit. */
1105 for (i = 0; i < units_num; i++) {
1107
1112 }
1114 }
1115
1116 fc_assert(i == units_num);
1117 }
1118
1119 /* Remove AI control of the old owner. */
1120 CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity);
1121
1122 /* Forget old tasks */
1123 clear_worker_tasks(pcity);
1124
1125 /* Forget old rally point */
1127
1128 /* Activate AI control of the new owner. */
1129 CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
1130
1131 city_freeze_workers(pcity);
1132
1135 /* Mark unit to have no homecity at all.
1136 * 1. We remove unit from units_supported list here,
1137 * real_change_unit_homecity() should not attempt it.
1138 * 2. Otherwise we might delete the homecity from under the unit
1139 * in the client */
1140 punit->homecity = 0;
1144
1145 /* Remove all global improvement effects that this city confers (but
1146 then restore the local improvement list - we need this to restore the
1147 global effects for the new city owner) */
1149 city_built_iterate(pcity, pimprove) {
1150 if (is_small_wonder(pimprove)) {
1151 /* Small wonders are really removed (not restored later). */
1152 building_removed(pcity, pimprove, "conquered", NULL);
1154 } else {
1155 city_remove_improvement(pcity, pimprove);
1156 if (is_great_wonder(pimprove)) {
1158 }
1159 /* Note: internal turn here, next city_built_iterate(). */
1160 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
1161 }
1163
1165 old_vision = pcity->server.vision;
1167 pcity->server.vision = new_vision;
1170
1172
1174 && city_list_find_name(ptaker->cities, city_name_get(pcity))) {
1175 char *old_city_name = fc_strdup(city_name_get(pcity));
1176
1179 _("You already had a city called %s."
1180 " The city was renamed to %s."),
1182 city_link(pcity));
1183
1185 }
1186
1187 /* Has to follow the unfog call above. */
1188 city_list_remove(pgiver->cities, pcity);
1190 /* city_thaw_workers_queue() later */
1191
1192 pcity->owner = ptaker;
1193 pcity->capital = CAPITAL_NOT;
1194 pcity->acquire_t = CACQ_CONQUEST;
1196 city_list_prepend(ptaker->cities, pcity);
1197
1198 if (could_see_unit != NULL) {
1199 /* Hide/reveal units. Do it after vision have been given to taker, city
1200 * owner has been changed, and before any script could be spawned. */
1201 for (i = 0; i < units_num; i++) {
1203
1207 && !aunit->server.dying) {
1208 /* Reveal 'aunit'. */
1209 send_unit_info(aplayer->connections, aunit);
1210 }
1211 } else {
1213 /* Hide 'aunit'. */
1215 }
1216 }
1218 }
1219
1220 fc_assert(i == units_num);
1221
1224 }
1225
1227 pcity, NULL,
1229 /* The units themselves are already freed by transfer_city_units(). */
1231
1232 if (resolve_stack) {
1234 }
1235
1236 if (!city_exist(saved_id)) {
1238 }
1239
1240 /* Reset turns owner counters */
1241 if (city_remains) {
1243 if (pcount->type == CB_CITY_OWNED_TURNS) {
1244 pcity->counter_values[pcount->index] = 0;
1245 }
1247 }
1248
1249 if (city_remains) {
1250 /* Update the city's trade routes. */
1252
1253 /* Clear CMA. */
1254 if (pcity->cm_parameter) {
1255 free(pcity->cm_parameter);
1256 pcity->cm_parameter = NULL;
1257 }
1258
1259 city_refresh(pcity);
1260 }
1261
1262 /*
1263 * maybe_make_contact() MUST be called before city_map_update_all(),
1264 * since the diplomacy status can influence whether a tile is available.
1265 */
1267
1268 if (city_remains) {
1269 struct extra_type *upgradet;
1270
1271 if (raze) {
1272 raze_city(pcity);
1273 }
1274
1275 if (taker_had_no_cities) {
1276 /* If conqueror previously had no cities, we might need to give
1277 * them a palace etc */
1278 if (build_free) {
1280 } /* Else caller should probably ensure palace is built */
1281
1282 BV_SET(ptaker->flags, PLRF_FIRST_CITY);
1283 }
1284
1286
1287 /* Restore any global improvement effects that this city confers */
1288 city_built_iterate(pcity, pimprove) {
1290 _("Transfer of %s"));
1292
1293 /* Set production to something valid for pplayer, if not.
1294 * (previously allowed building obsolete units.) */
1295 if (!can_city_build_now(pcity, &pcity->production)) {
1297 }
1298
1299 /* What wasn't obsolete for the old owner may be so now. */
1301
1303
1304 if (new_extras) {
1305 const char *clink = city_link(pcity);
1306
1308 _("The people in %s are stunned by your "
1309 "technological insight!"),
1310 clink);
1311
1312 if (upgradet != NULL) {
1314 _("Workers spontaneously gather and upgrade "
1315 "%s with %s."),
1317 } else {
1319 _("Workers spontaneously gather and upgrade "
1320 "%s infrastructure."),
1321 clink);
1322 }
1324 }
1325
1326 /* Build a new palace for free if the player lost their capital and
1327 savepalace is on. */
1329
1330 /* Refresh the city's vision range, since it might be different
1331 * under the new owner. */
1332 city_refresh_vision(pcity);
1333
1334 /* Update the national borders, within the current vision and culture.
1335 * This could leave a border ring around the city, updated later by
1336 * map_calculate_borders() at the next turn.
1337 */
1339 /* city_thaw_workers_queue() later */
1340
1341 auto_arrange_workers(pcity); /* does city_map_update_all() */
1342 city_thaw_workers(pcity);
1343 city_thaw_workers_queue(); /* after old city has a chance to work! */
1345 /* no sanity check here as the city is not refreshed! */
1346 }
1347
1348 if (city_remains) {
1349 /* Send city with updated owner information to giver and to everyone
1350 * having shared vision pact with them before they may
1351 * lose vision to it. When we later send info to everybody seeing the city,
1352 * they may not be included. */
1353 send_city_info(NULL, pcity);
1354 }
1355
1356 /* Remove the sight points from the giver. */
1357 vision_clear_sight(old_vision);
1358 vision_free(old_vision);
1359
1360 /* Send wonder infos. */
1361 if (had_great_wonders) {
1363 if (city_remains) {
1365
1366 /* Refresh all cities of the taker to account for possible changes due
1367 * to player wide effects. */
1368 city_list_iterate(ptaker->cities, acity) {
1371 } else {
1372 /* Refresh all cities to account for possible global effects. */
1376 }
1377 }
1379 /* No need to send to detached connections. */
1381
1382 /* Refresh all cities of the giver to account for possible changes due
1383 * to player wide effects. */
1384 city_list_iterate(pgiver->cities, acity) {
1387 }
1388
1389 /* Refresh all cities in the queue. */
1391 /* After the refresh the sanity check can be done. */
1392 sanity_check_city(pcity);
1393
1394 if (city_remains) {
1395 /* Send information about conquered city to all players. */
1396 send_city_info(NULL, pcity);
1397 }
1398
1399 /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to
1400 * refresh all cities for the player. */
1404 }
1408 }
1409
1410 if (pgiver->primary_capital_id == saved_id) {
1412 }
1413
1414 sync_cities();
1415
1416 CALL_FUNC_EACH_AI(city_info, pcity);
1417
1418 return city_remains;
1419}
1420
1421/************************************************************************/
1429{
1430 struct player *pplayer;
1431 struct nation_type *nation;
1432 int i;
1434 bool first_city;
1435
1436 fc_assert_ret(NULL != pcity);
1437 pplayer = city_owner(pcity);
1438 fc_assert_ret(NULL != pplayer);
1439 nation = nation_of_player(pplayer);
1440 fc_assert_ret(NULL != nation);
1441
1442 /* If this isn't the first city a player has ever had, they only get
1443 * any initial buildings with the SaveSmallWonder flag, and then only
1444 * if savepalace is enabled. */
1446
1449
1450 /* Global free buildings. */
1451 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1453 struct impr_type *pimprove;
1454
1455 if (n == B_LAST) {
1456 break;
1457 }
1458
1459 pimprove = improvement_by_number(n);
1460 fc_assert_action(!is_great_wonder(pimprove), continue);
1461 if (first_city
1465 /* TRANS: Reason that a building was added to the city.
1466 * Building is given for free to player's first city. */
1467 Q_("?initbldg:Free %s"));
1468 if (is_small_wonder(pimprove)) {
1470 }
1471 }
1472 }
1473
1474 /* Nation specific free buildings. */
1475 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1476 Impr_type_id n = nation->init_buildings[i];
1477 struct impr_type *pimprove;
1478
1479 if (n == B_LAST) {
1480 break;
1481 }
1482
1483 pimprove = improvement_by_number(n);
1484 if (first_city
1488 /* TRANS: Reason that a building was added to the city.
1489 * Building is given for free to player's first city. */
1490 Q_("?initbldg:Free %s"));
1491 if (is_small_wonder(pimprove)) {
1493 } else if (is_great_wonder(pimprove)) {
1495 }
1496 }
1497 }
1498
1499 /* Update wonder infos. */
1500 if (has_great_wonders) {
1502 /* No need to send to detached connections. */
1503 send_player_info_c(pplayer, NULL);
1504 } else if (has_small_wonders) {
1505 /* No need to send to detached connections. */
1506 send_player_info_c(pplayer, NULL);
1507 }
1508}
1509
1510/************************************************************************/
1513void create_city(struct player *pplayer, struct tile *ptile,
1514 const char *name, struct player *nationality)
1515{
1516 struct player *saved_owner = tile_owner(ptile);
1517 struct tile *saved_claimer = tile_claimer(ptile);
1518 struct city *pwork = tile_worked(ptile);
1519 struct city *pcity;
1522
1523 log_debug("create_city() %s", name);
1524
1525 pcity = create_city_virtual(pplayer, ptile, name);
1526
1527 /* Remove units no more seen. Do it before city is really put into the
1528 * game. */
1529 players_iterate(other_player) {
1530 if (can_player_see_units_in_city(other_player, pcity)
1531 || !map_is_known_and_seen(ptile, other_player, V_MAIN)) {
1532 continue;
1533 }
1534 unit_list_iterate(ptile->units, punit) {
1535 if (can_player_see_unit(other_player, punit)) {
1536 unit_goes_out_of_sight(other_player, punit);
1537 }
1540
1541 adv_city_alloc(pcity);
1542
1543 tile_set_owner(ptile, pplayer, ptile); /* Temporarily */
1545 pcity->id = identity_number();
1546
1548 idex_register_city(&wld, pcity);
1550
1551 if (city_list_size(pplayer->cities) == 0) {
1552 /* Free initial buildings, or at least a palace if they were
1553 * previously careless enough to lose all their cities */
1555 BV_SET(pplayer->flags, PLRF_FIRST_CITY);
1556 }
1557
1558 /* Set up citizens nationality. */
1559 citizens_init(pcity);
1560
1561 /* Place a worker at the is_city_center() is_free_worked().
1562 * It is possible to build a city on a tile that is already worked;
1563 * this will displace the worker on the newly-built city's tile -- Syela */
1564 tile_set_worked(ptile, pcity); /* instead of city_map_update_worker() */
1565
1566 if (NULL != pwork) {
1567 /* was previously worked by another city */
1568 /* Turn citizen into specialist. */
1569 pwork->specialists[DEFAULT_SPECIALIST]++;
1570 /* One less citizen. Citizen sanity will be handled later in
1571 * city_thaw_workers_queue() */
1572 pwork->server.synced = FALSE;
1574 }
1575
1576 /* Update citizens. */
1578
1579 /* Restore the old-owner information so removal
1580 * of territory claiming bases can work relative to it. */
1582
1583 /* Destroy any extras that don't belong in the city. */
1584 extra_type_iterate(pextra) {
1585 if (tile_has_extra(ptile, pextra)
1586 && !is_native_tile_to_extra(pextra, ptile)) {
1587 destroy_extra(ptile, pextra);
1588 }
1590
1591 /* Build any extras that the city should have. */
1592 upgrade_city_extras(pcity, NULL);
1593
1594 /* Claim the ground we stand on */
1595 map_claim_ownership(ptile, pplayer, ptile, TRUE);
1596
1597 /* Before arranging workers to show unknown land */
1598 pcity->server.vision = vision_new(pplayer, ptile);
1600 city_refresh_vision(pcity);
1601 city_list_prepend(pplayer->cities, pcity);
1602
1603 /* This is dependent on the current vision, so must be done after
1604 * vision is prepared and before arranging workers. */
1605 map_claim_border(ptile, pplayer, -1);
1606 /* city_thaw_workers_queue() later */
1607
1608 /* Refresh the city. First a city refresh is done (this shouldn't
1609 * send any packets to the client because the city has no supported units)
1610 * then rearrange the workers. Note that auto_arrange_workers does its
1611 * own refresh call; it is safest to do our own controlled city_refresh
1612 * first. */
1613 city_refresh(pcity);
1614 auto_arrange_workers(pcity);
1615 city_thaw_workers_queue(); /* after new city has a chance to work! */
1617
1618 /* Bases destroyed earlier may have had watchtower effect. Refresh
1619 * unit vision. */
1621
1622 update_tile_knowledge(ptile);
1623
1626 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1627 * cities for the player. */
1628 city_refresh_for_player(pplayer);
1629 }
1630
1631 pcity->server.synced = FALSE;
1632 send_city_info(NULL, pcity);
1633 sync_cities(); /* Will also send pwork. */
1634
1635 notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server,
1636 _("You have founded %s."),
1637 city_link(pcity));
1638 maybe_make_contact(ptile, city_owner(pcity));
1639
1640 unit_list_iterate((ptile)->units, punit) {
1642
1643 /* Catch fortress building, transforming into ocean, etc. */
1646 }
1647
1648 /* Update happiness (the unit may no longer cause unrest). */
1649 if (home) {
1650 if (city_refresh(home)) {
1651 /* Shouldn't happen, but better be safe than sorry. */
1653 }
1656 }
1658
1659 sanity_check_city(pcity);
1660
1661 script_server_signal_emit("city_built", pcity);
1662
1663 CALL_FUNC_EACH_AI(city_created, pcity);
1664 CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
1665}
1666
1667/************************************************************************/
1673bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1674 const char *name)
1675{
1676 if (is_enemy_unit_tile(ptile, pplayer)
1677 || !city_can_be_built_here(ptile, NULL, FALSE)) {
1678 return FALSE;
1679 }
1680
1681 if (!pplayer->is_alive) {
1682 pplayer->is_alive = TRUE;
1683 send_player_info_c(pplayer, NULL);
1684 }
1685
1686 if (name == NULL || name[0] == '\0') {
1687 name = city_name_suggestion(pplayer, ptile);
1688 }
1689
1690 map_show_tile(pplayer, ptile);
1691 create_city(pplayer, ptile, name, pplayer);
1692
1693 return TRUE;
1694}
1695
1696/************************************************************************/
1699void remove_city(struct city *pcity)
1700{
1701 struct player *powner = city_owner(pcity);
1702 struct tile *pcenter = city_tile(pcity);
1704 struct vision *old_vision;
1705 int id = pcity->id; /* We need this even after memory has been freed */
1706 bool had_great_wonders = FALSE;
1709 struct dbv tile_processed;
1710 struct tile_list *process_queue;
1711 const char *ctl = city_tile_link(pcity);
1712
1713 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1714 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1715
1717 city_built_iterate(pcity, pimprove) {
1718 building_removed(pcity, pimprove, "city_destroyed", NULL);
1719
1720 if (is_small_wonder(pimprove)) {
1722 } else if (is_great_wonder(pimprove)) {
1724 }
1726
1727 /* Rehome units in other cities */
1730
1731 if (new_home_city
1732 && new_home_city != pcity
1733 && city_owner(new_home_city) == powner
1734 && !punit->server.dying) {
1736 }
1738
1739 /* Make sure ships are not left on land when city is removed. */
1741 bool moved;
1742 const struct unit_type *punittype = unit_type_get(punit);
1743
1745 continue;
1746 }
1747
1749 moved = FALSE;
1751 struct unit *ptrans;
1752
1753 if (!moved && is_native_tile(punittype, tile1)) {
1755 /* Move */
1757 /* It may be impossible to survive at the tile even if it is
1758 * native. See UTYF_COAST_STRICT */
1760 } else {
1761 ptrans = NULL;
1762 }
1766 NULL) != NULL) {
1767 moved = TRUE;
1768 }
1769 if (moved) {
1772 _("Moved %s out of disbanded city %s "
1773 "since it cannot stay on %s."),
1776 break;
1777 }
1778 }
1779 }
1781 if (!moved) {
1784 _("When %s was disbanded your %s could not "
1785 "get out, and it was therefore lost."),
1786 ctl,
1789 }
1791
1795 struct tile *ptile = tile_list_front(process_queue);
1796
1799 adjc_iterate(&(wld.map), ptile, piter) {
1800 struct city *other_city;
1801
1803 continue;
1804 }
1806 if (other_city != NULL) {
1807 /* Adjacent tile has a city that may have been part of same channel */
1812
1818 _("When %s was disbanded your %s in %s was trapped, "
1819 "and it was therefore lost."),
1820 ctl,
1824 }
1826 } else {
1828 }
1830 }
1831
1834
1835 if (!city_exist(id)) {
1836 /* Wiping trapped units caused city to disappear. */
1837 return;
1838 }
1839
1840 /* Any remaining supported units are destroyed */
1844
1845 if (!city_exist(id)) {
1846 /* Wiping supported units caused city to disappear. */
1847 return;
1848 }
1849
1851 struct trade_route *pback = remove_trade_route(pcity, proute,
1852 TRUE, TRUE);
1853
1854 FC_FREE(proute);
1855 FC_FREE(pback);
1857
1862
1863 /* idex_unregister_city() is called in game_remove_city() below */
1864
1865 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1866 still be alive in the client, or in the player map. The number of
1867 removed cities is small, so the loss is acceptable.
1868 */
1869
1870 old_vision = pcity->server.vision;
1871 pcity->server.vision = NULL;
1873 adv_city_free(pcity);
1874
1875 /* Remove city from the map. */
1877
1878 /* Reveal units. */
1879 players_iterate(other_player) {
1880 if (can_player_see_units_in_city(other_player, pcity)
1881 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1882 continue;
1883 }
1885 if (can_player_see_unit(other_player, punit)) {
1886 send_unit_info(other_player->connections, punit);
1887 }
1890
1892 game_remove_city(&wld, pcity);
1894
1895 /* Remove any extras that were only there because the city was there. */
1896 extra_type_iterate(pextra) {
1897 if (tile_has_extra(pcenter, pextra)
1898 && !is_native_tile_to_extra(pextra, pcenter)) {
1900 }
1902
1903 players_iterate(other_player) {
1904 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1905 reality_check_city(other_player, pcenter);
1906 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1907 map_show_tile(other_player, pcenter);
1908 }
1910
1912 if (NULL == pconn->playing && pconn->observer) {
1913 /* For detached observers we have to send a specific packet. This is
1914 * a hack necessitated by the private map that exists for players but
1915 * not observers. */
1917 }
1919
1920 if (old_vision != NULL) {
1921 vision_clear_sight(old_vision);
1922 vision_free(old_vision);
1923 }
1924
1925 /* Infrastructures may have changed. */
1927
1928 /* Build a new palace for free if the player lost their capital and
1929 savepalace is on. */
1931
1932 /* Update wonder infos. */
1933 if (had_great_wonders) {
1935 /* No need to send to detached connections. */
1936 send_player_info_c(powner, NULL);
1937 } else if (BV_ISSET_ANY(had_small_wonders)) {
1938 /* No need to send to detached connections. */
1939 send_player_info_c(powner, NULL);
1940 }
1941
1944 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1945 * cities for the player. */
1947 }
1948
1949 sync_cities();
1950
1951 /* At least sentried helicopters need to go idle, maybe others.
1952 * In alien ruleset, city center might have provided water source
1953 * for adjacent tile. */
1955}
1956
1957/************************************************************************/
1973bool unit_conquer_city(struct unit *punit, struct city *pcity)
1974{
1975 bool try_civil_war = FALSE;
1976 bool city_remains;
1977 int coins;
1978 struct player *pplayer = unit_owner(punit);
1979 struct player *cplayer = city_owner(pcity);
1980#ifndef FREECIV_NDEBUG
1981 const struct unit_type *utype = unit_type_get(punit);
1982#endif
1983
1984 /* If not at war, may peacefully enter city. */
1986 "Can't conquer city during peace.");
1987
1988 /* If we cannot occupy the city, this unit entering will not trigger the
1989 * effects below. */
1993 FALSE, "Bad unit for city occupation.");
1994
1995 /* A transported unit trying to conquer a city should already have been
1996 * unloaded. */
1998 "Can't conquer city while transported.");
1999
2000 /* Okay, we're at war - invader captures/destroys city... */
2001
2002 /* If a capital is captured, then spark off a civil war
2003 - Kris Bubendorfer
2004 Also check spaceships --dwp
2005 */
2006
2007 if (is_capital(pcity)
2008 && (cplayer->spaceship.state == SSHIP_STARTED
2009 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
2011 }
2012
2013 if (is_capital(pcity)
2018 }
2019
2020 /*
2021 * We later remove a citizen. Lets check if we can save this since
2022 * the city will be destroyed.
2023 */
2024 if (city_size_get(pcity) <= 1) {
2025 int saved_id = pcity->id;
2026
2028 _("You destroy %s completely."),
2029 city_tile_link(pcity));
2031 _("%s has been destroyed by %s."),
2032 city_tile_link(pcity), player_name(pplayer));
2033 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2034
2035 /* We cant't be sure of city existence after running some script */
2036 if (city_exist(saved_id)) {
2037 remove_city(pcity);
2038 }
2039
2040 if (try_civil_war) {
2042 }
2043 return TRUE;
2044 }
2045
2047 coins = MIN(coins,
2048 fc_rand((coins / 20) + 1)
2049 + (coins * (city_size_get(pcity))) / 200);
2050 pplayer->economic.gold += coins;
2051 cplayer->economic.gold -= coins;
2052 send_player_info_c(pplayer, pplayer->connections);
2053 send_player_info_c(cplayer, cplayer->connections);
2054 if (pcity->original != pplayer) {
2055 if (coins > 0) {
2057 PL_("You conquer %s; your lootings accumulate"
2058 " to %d gold!",
2059 "You conquer %s; your lootings accumulate"
2060 " to %d gold!", coins),
2061 city_link(pcity),
2062 coins);
2064 PL_("%s conquered %s and looted %d gold"
2065 " from the city.",
2066 "%s conquered %s and looted %d gold"
2067 " from the city.", coins),
2068 player_name(pplayer),
2069 city_link(pcity),
2070 coins);
2071 } else {
2073 _("You conquer %s."),
2074 city_link(pcity));
2076 _("%s conquered %s."),
2077 player_name(pplayer),
2078 city_link(pcity));
2079 }
2080 } else {
2081 if (coins > 0) {
2083 PL_("You have liberated %s!"
2084 " Lootings accumulate to %d gold.",
2085 "You have liberated %s!"
2086 " Lootings accumulate to %d gold.", coins),
2087 city_link(pcity),
2088 coins);
2090 PL_("%s liberated %s and looted %d gold"
2091 " from the city.",
2092 "%s liberated %s and looted %d gold"
2093 " from the city.", coins),
2094 player_name(pplayer),
2095 city_link(pcity),
2096 coins);
2097 } else {
2099 _("You have liberated %s!"),
2100 city_link(pcity));
2102 _("%s liberated %s."),
2103 player_name(pplayer),
2104 city_link(pcity));
2105 }
2106 }
2107
2109 /* Just try to steal. Ignore failures to get tech */
2110 steal_a_tech(pplayer, cplayer, A_UNSET);
2111 }
2112
2113 /* We transfer the city first so that it is in a consistent state when
2114 * the size is reduced. */
2115 /* FIXME: maybe it should be a ruleset option whether barbarians get
2116 * free buildings such as palaces? */
2117 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2118 !is_barbarian(pplayer));
2119
2120 if (city_remains) {
2121 /* reduce size should not destroy this city */
2122 fc_assert(city_size_get(pcity) > 1);
2123 city_reduce_size(pcity, 1, pplayer, "conquest");
2124 }
2125
2126 if (try_civil_war) {
2128 }
2129
2130 if (city_remains) {
2131 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2132 "conquest");
2133 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2134 }
2135
2136 return TRUE;
2137}
2138
2139/************************************************************************/
2142static int city_citywalls_gfx(const struct city *pcity)
2143{
2144 int walls = get_city_bonus(pcity, EFT_VISIBLE_WALLS);
2145
2146 return walls > 0 ? walls : 0;
2147}
2148
2149/************************************************************************/
2153{
2155
2157 return formerly;
2158}
2159
2160/************************************************************************/
2163static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2164 struct packet_city_short_info *packet)
2165{
2166 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2167
2168 packet->id = pdcity->identity;
2170
2171 packet->tile = tile_index(ptile);
2172 if (pdcity->name == NULL) {
2173 packet->name[0] = '\0';
2174 } else {
2175 sz_strlcpy(packet->name, pdcity->name);
2176 }
2177
2178 packet->size = vision_site_size_get(pdcity);
2179
2180 packet->occupied = pdcity->occupied;
2181 packet->walls = pdcity->walls;
2182 packet->style = pdcity->style;
2183 packet->city_image = pdcity->city_image;
2184 packet->capital = pdcity->capital;
2185
2186 packet->happy = pdcity->happy;
2187 packet->unhappy = pdcity->unhappy;
2188
2189 packet->improvements = pdcity->improvements;
2190}
2191
2192/************************************************************************/
2196void refresh_dumb_city(struct city *pcity)
2197{
2198 players_iterate(pplayer) {
2199 if (player_can_see_city_externals(pplayer, pcity)) {
2200 if (update_dumb_city(pplayer, pcity)) {
2201 struct packet_city_short_info packet;
2202
2203 if (city_owner(pcity) != pplayer) {
2204 /* Don't send the short_city information to someone who can see the
2205 * city's internals. Doing so would really confuse the client. */
2206 package_dumb_city(pplayer, pcity->tile, &packet);
2207 lsend_packet_city_short_info(pplayer->connections, &packet);
2208 }
2209 }
2210 }
2212
2213 /* Don't send to non-player observers since they don't have 'dumb city'
2214 * information. */
2215}
2216
2217/************************************************************************/
2225void broadcast_city_info(struct city *pcity)
2226{
2227 struct packet_city_info packet;
2232 struct player *powner = city_owner(pcity);
2233 struct trade_route_packet_list *routes;
2235
2236 /* Send to everyone who can see the city. */
2237
2238 if (pcity->server.needs_arrange != CNA_NOT) {
2239 /* Send city only when it's in sane state.
2240 * If it's not, it will be sent to everyone once
2241 * rearrangement has been finished. */
2243
2244 return;
2245 }
2246
2247 if (any_web_conns()) {
2249 } else {
2250 webp_ptr = NULL;
2251 }
2252
2253 routes = trade_route_packet_list_new();
2254 package_city(pcity, &packet, &nat_packet, &rally_packet,
2255 webp_ptr, routes, FALSE);
2256
2257 players_iterate(pplayer) {
2258 if (!send_city_suppressed || pplayer != powner) {
2259 if (can_player_see_city_internals(pplayer, pcity)) {
2260 update_dumb_city(pplayer, pcity);
2261 packet.original = city_original_owner(pcity, pplayer);
2262 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2263 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2264 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2265 web_lsend_packet(city_info_addition, pplayer->connections,
2266 webp_ptr, FALSE);
2268 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2270 } else if (player_can_see_city_externals(pplayer, pcity)) {
2271 reality_check_city(pplayer, pcity->tile);
2272 update_dumb_city(pplayer, pcity);
2273 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2274 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2275 }
2276 }
2278
2279 /* Send to global observers. */
2280 packet.original = city_original_owner(pcity, NULL);
2287 }
2289
2294}
2295
2296/************************************************************************/
2301{
2302 conn_list_do_buffer(dest);
2303 conn_list_iterate(dest, pconn) {
2304 struct player *pplayer = pconn->playing;
2305
2306 if (!pplayer && !pconn->observer) {
2307 continue;
2308 }
2309 whole_map_iterate(&(wld.map), ptile) {
2310 if (!pplayer || NULL != map_get_player_site(ptile, pplayer)) {
2311 send_city_info_at_tile(pplayer, pconn->self, NULL, ptile);
2312 }
2314 }
2317 flush_packets();
2318}
2319
2320/************************************************************************/
2323void send_player_cities(struct player *pplayer)
2324{
2325 city_list_iterate(pplayer->cities, pcity) {
2326 if (city_refresh(pcity)) {
2327 log_error("%s radius changed while sending to player.",
2328 city_name_get(pcity));
2329
2330 /* Make sure that no workers in illegal position outside radius. */
2331 auto_arrange_workers(pcity);
2332 }
2333 send_city_info(pplayer, pcity);
2334 }
2336}
2337
2338/************************************************************************/
2343void send_city_info(struct player *dest, struct city *pcity)
2344{
2345 struct player *powner = city_owner(pcity);
2346
2347 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2348 return;
2349 }
2350
2351 if (dest == powner && send_city_suppressed) {
2352 return;
2353 }
2354
2355 if (!dest || dest == powner) {
2356 pcity->server.synced = TRUE;
2357 }
2358
2359 if (!dest) {
2360 broadcast_city_info(pcity);
2361 } else {
2362 send_city_info_at_tile(dest, dest->connections, pcity, pcity->tile);
2363 }
2364
2365 /* Sending counters */
2366 city_counters_refresh(pcity);
2367
2369 && player_list_size(team_members(powner->team)) > 1) {
2370 /* We want to send the new total bulbs production of the team. */
2372 }
2373}
2374
2375/************************************************************************/
2396 struct city *pcity, struct tile *ptile)
2397{
2398 struct packet_city_info packet;
2403 struct player *powner = NULL;
2404 struct trade_route_packet_list *routes = NULL;
2406
2407 if (!pcity) {
2408 pcity = tile_city(ptile);
2409 }
2410 if (pcity != NULL && pcity->server.needs_arrange != CNA_NOT) {
2412
2413 return;
2414 }
2415 if (pcity) {
2416 powner = city_owner(pcity);
2417 }
2418
2419 if (any_web_conns()) {
2421 } else {
2422 webp_ptr = NULL;
2423 }
2424
2425 if (powner != NULL && powner == pviewer) {
2426 /* Send info to owner */
2427 /* This case implies powner non-NULL which means pcity non-NULL */
2428 if (!send_city_suppressed) {
2429 /* Wait that city has been rearranged, if it's currently
2430 * not in sane state. */
2431
2432 routes = trade_route_packet_list_new();
2433
2434 /* Send all info to the owner */
2435 update_dumb_city(powner, pcity);
2436 package_city(pcity, &packet, &nat_packet, &rally_packet,
2437 webp_ptr, routes, FALSE);
2438 packet.original = city_original_owner(pcity, pviewer);
2439 lsend_packet_city_info(dest, &packet, FALSE);
2446 if (dest == powner->connections) {
2447 /* HACK: send also a copy to global observers. */
2448 packet.original = city_original_owner(pcity, NULL);
2455 }
2457 }
2458 }
2459 } else {
2460 /* send info to non-owner */
2461 if (!pviewer) { /* observer */
2462 if (pcity) {
2463 routes = trade_route_packet_list_new();
2464
2465 /* Should be dumb_city info? */
2466 package_city(pcity, &packet, &nat_packet, &rally_packet,
2467 webp_ptr, routes, FALSE);
2468 lsend_packet_city_info(dest, &packet, FALSE);
2475 }
2476 } else {
2477 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2478 if (pcity) { /* it's there and we see it; update and send */
2479 update_dumb_city(pviewer, pcity);
2482 }
2483 } else { /* not seen; send old info */
2484 if (map_is_known(ptile, pviewer)
2485 && map_get_player_site(ptile, pviewer) != NULL) {
2488 }
2489 }
2490 }
2491 }
2492
2493 if (routes != NULL) {
2498 }
2499}
2500
2501/************************************************************************/
2506void package_city(struct city *pcity, struct packet_city_info *packet,
2510 struct trade_route_packet_list *routes,
2511 bool dipl_invest)
2512{
2513 int i;
2514 int ppl = 0;
2515
2517
2518 packet->id = pcity->id;
2519 packet->owner = player_number(city_owner(pcity));
2520
2521 packet->tile = tile_index(city_tile(pcity));
2522 sz_strlcpy(packet->name, city_name_get(pcity));
2523
2524 packet->size = city_size_get(pcity);
2525 for (i = 0; i < FEELING_LAST; i++) {
2526 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2527 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2528 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2529 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2530 if (i == 0) {
2531 ppl += packet->ppl_happy[i];
2532 ppl += packet->ppl_content[i];
2533 ppl += packet->ppl_unhappy[i];
2534 ppl += packet->ppl_angry[i];
2535 }
2536 }
2537 /* The number of data in specialists[] array */
2540 packet->specialists[sp] = pcity->specialists[sp];
2541 ppl += packet->specialists[sp];
2543
2544 /* The nationality of the citizens. */
2545 nat_packet->id = pcity->id;
2546 nat_packet->nationalities_count = 0;
2548 int cit = 0;
2549
2550 player_slots_iterate(pslot) {
2551 citizens nationality = citizens_nation_get(pcity, pslot);
2552 if (nationality != 0) {
2553 /* This player should exist! */
2555
2556 nat_packet->nation_id[nat_packet->nationalities_count]
2557 = player_slot_index(pslot);
2558 nat_packet->nation_citizens[nat_packet->nationalities_count]
2559 = nationality;
2560 nat_packet->nationalities_count++;
2561
2562 cit += nationality;
2563 }
2565
2566 fc_assert(cit == packet->size);
2567 }
2568
2569 packet->history = pcity->history;
2570 packet->culture = city_culture(pcity);
2571 packet->buy_cost = city_production_buy_gold_cost(pcity);
2572
2573 if (packet->size != ppl) {
2574 static bool recursion = FALSE;
2575
2576 if (recursion) {
2577 /* Recursion didn't help. Do not enter infinite recursive loop.
2578 * Package city as it is. */
2579 log_error("Failed to fix inconsistent city size.");
2580 recursion = FALSE;
2581 } else {
2582 /* Note: If you get this error and try to debug the cause, you may find
2583 * using check_city_feelings() in some key points useful. */
2584 /* Have this as an fc_assert() first, so one can use '-F' to caught these in
2585 * debugger. */
2586 fc_assert(packet->size == ppl);
2587
2588 /* In all builds have an error message shown. */
2589 log_error("City size %d, citizen count %d for %s",
2590 packet->size, ppl, city_name_get(pcity));
2591
2592 /* Try to fix */
2593 city_refresh(pcity);
2594 auto_arrange_workers(pcity);
2595
2596 /* And repackage */
2597 recursion = TRUE;
2598 package_city(pcity, packet, nat_packet, rally_packet,
2599 web_packet, routes, dipl_invest);
2600 recursion = FALSE;
2601
2602 return;
2603 }
2604 }
2605
2606 packet->city_radius_sq = pcity->city_radius_sq;
2607
2608 i = 0;
2611
2612 tri_packet->city = pcity->id;
2613 tri_packet->index = i;
2614 tri_packet->partner = proute->partner;
2615 tri_packet->value = proute->value;
2616 tri_packet->direction = proute->dir;
2617 tri_packet->goods = goods_number(proute->goods);
2618
2620
2621 i++;
2623
2624 packet->trade_route_count = i;
2625
2627 packet->surplus[o] = pcity->surplus[o];
2628 packet->waste[o] = pcity->waste[o];
2629 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2630 packet->prod[o] = pcity->prod[o];
2631 packet->citizen_base[o] = pcity->citizen_base[o];
2632 packet->usage[o] = pcity->usage[o];
2634
2635 packet->food_stock = pcity->food_stock;
2636 packet->shield_stock = pcity->shield_stock;
2637 packet->pollution = pcity->pollution;
2638 packet->illness_trade = pcity->illness_trade;
2639 packet->city_options = pcity->city_options;
2640
2641 packet->production_kind = pcity->production.kind;
2642 packet->production_value = universal_number(&pcity->production);
2643
2644 packet->turn_last_built = pcity->turn_last_built;
2645 packet->turn_founded = pcity->turn_founded;
2646
2647 packet->changed_from_kind = pcity->changed_from.kind;
2649
2651 packet->disbanded_shields = pcity->disbanded_shields;
2652 packet->caravan_shields = pcity->caravan_shields;
2654
2655 worklist_copy(&packet->worklist, &pcity->worklist);
2657
2658 packet->airlift = pcity->airlift;
2659 packet->did_buy = pcity->did_buy;
2660 packet->did_sell = pcity->did_sell;
2661 packet->was_happy = pcity->was_happy;
2662 packet->had_famine = pcity->had_famine;
2663
2664 packet->walls = city_citywalls_gfx(pcity);
2665 packet->style = pcity->style;
2666 packet->city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2667 packet->capital = pcity->capital;
2668 packet->steal = pcity->steal;
2669
2670 rally_packet->id = pcity->id;
2671 rally_packet->length = pcity->rally_point.length;
2672 rally_packet->persistent = pcity->rally_point.persistent;
2673 rally_packet->vigilant = pcity->rally_point.vigilant;
2674 if (pcity->rally_point.length) {
2675 memcpy(rally_packet->orders, pcity->rally_point.orders,
2676 pcity->rally_point.length * sizeof(struct unit_order));
2677 }
2678
2679 BV_CLR_ALL(packet->improvements);
2680 improvement_iterate(pimprove) {
2681 if (city_has_building(pcity, pimprove)) {
2682 BV_SET(packet->improvements, improvement_index(pimprove));
2683 }
2685
2686#ifdef FREECIV_WEB
2687 if (web_packet != NULL) {
2688 struct tile *pcenter = city_tile(pcity);
2689
2690 BV_CLR_ALL(web_packet->can_build_unit);
2691 BV_CLR_ALL(web_packet->can_build_improvement);
2692
2693 web_packet->id = pcity->id;
2694
2695 if (pcity->cm_parameter != NULL) {
2696 web_packet->cma_enabled = TRUE;
2697 cm_copy_parameter(&web_packet->cm_parameter, pcity->cm_parameter);
2698 } else {
2699 web_packet->cma_enabled = FALSE;
2700 memset(&web_packet->cm_parameter, 0, sizeof(web_packet->cm_parameter));
2701 }
2702
2703 web_packet->granary_size = city_granary_size(city_size_get(pcity));
2704 web_packet->granary_turns = city_turns_to_grow(pcity);
2705
2706 improvement_iterate(pimprove) {
2707 if (can_city_build_improvement_now(pcity, pimprove)) {
2708 BV_SET(web_packet->can_build_improvement, improvement_index(pimprove));
2709 }
2711
2713 if (can_city_build_unit_now(pcity, punittype)) {
2714 BV_SET(web_packet->can_build_unit, utype_index(punittype));
2715 }
2717
2718 i = 0;
2720 web_packet->output_food[i] = city_tile_output_now(pcity, ptile, O_FOOD);
2721 web_packet->output_shield[i] = city_tile_output_now(pcity, ptile, O_SHIELD);
2722 web_packet->output_trade[i] = city_tile_output_now(pcity, ptile, O_TRADE);
2723
2724 i++;
2726 }
2727#endif /* FREECIV_WEB */
2728}
2729
2730/************************************************************************/
2740bool update_dumb_city(struct player *pplayer, struct city *pcity)
2741{
2742 bv_imprs improvements;
2743 struct tile *pcenter = city_tile(pcity);
2744 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2745 /* pcity->client.occupied isn't used at the server, so we go straight to the
2746 * unit list to check the occupied status. */
2747 bool occupied = (unit_list_size(pcenter->units) > 0);
2748 int walls = city_citywalls_gfx(pcity);
2749 bool happy = city_happy(pcity);
2750 bool unhappy = city_unhappy(pcity);
2751 int style = pcity->style;
2753 enum capital_type capital = pcity->capital;
2754
2755 /* Only someone knowing the tile should ever know a city on it. */
2756 fc_assert(map_is_known(pcenter, pplayer));
2757
2759 improvement_iterate(pimprove) {
2760 if (is_improvement_visible(pimprove)
2761 && city_has_building(pcity, pimprove)) {
2763 }
2765
2766 if (NULL == pdcity) {
2769 } else if (pdcity->location != pcenter) {
2770 log_error("Trying to update bad city (wrong location) "
2771 "at %i,%i for player %s",
2772 TILE_XY(pcity->tile), player_name(pplayer));
2773 fc_assert(pdcity->location == pcenter);
2774 pdcity->location = pcenter; /* ?? */
2775 } else if (pdcity->identity != pcity->id) {
2776 log_error("Trying to update old city (wrong identity) "
2777 "at %i,%i for player %s",
2778 TILE_XY(city_tile(pcity)), player_name(pplayer));
2779 fc_assert(pdcity->identity == pcity->id);
2780 pdcity->identity = pcity->id; /* ?? */
2781 } else if (pdcity->occupied == occupied
2782 && pdcity->walls == walls
2783 && pdcity->happy == happy
2784 && pdcity->unhappy == unhappy
2785 && pdcity->style == style
2786 && pdcity->city_image == city_image
2787 && pdcity->capital == capital
2788 && BV_ARE_EQUAL(pdcity->improvements, improvements)
2790 && vision_site_owner(pdcity) == city_owner(pcity)
2791 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2792 return FALSE;
2793 }
2794
2796 pdcity->occupied = occupied;
2797 pdcity->walls = walls;
2798 pdcity->style = style;
2799 pdcity->city_image = city_image;
2800 pdcity->capital = capital;
2801 pdcity->happy = happy;
2802 pdcity->unhappy = unhappy;
2803 pdcity->improvements = improvements;
2804
2805 return TRUE;
2806}
2807
2808/************************************************************************/
2811void reality_check_city(struct player *pplayer, struct tile *ptile)
2812{
2813 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2814
2815 if (pdcity) {
2816 struct city *pcity = tile_city(ptile);
2817
2818 if (!pcity || pcity->id != pdcity->identity) {
2819 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2820
2821 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2822 fc_assert_ret(playtile->site == pdcity);
2823 playtile->site = NULL;
2825 }
2826 }
2827}
2828
2829/************************************************************************/
2832void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2833{
2834 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2835
2836 if (pdcity) {
2837 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2838
2839 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2840 fc_assert_ret(playtile->site == pdcity);
2841 playtile->site = NULL;
2843 }
2844}
2845
2846/************************************************************************/
2850static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2851 bool source_gone)
2852{
2853 struct player *plr1 = city_owner(pc1);
2854 struct player *plr2 = city_owner(pc2);
2857
2860
2861 if (plr1 == plr2) {
2862 if (source_gone) {
2865 _("Trade between %s and %s lost along with city."),
2867 } else {
2870 _("Trade route between %s and %s canceled."),
2872 }
2873 } else {
2874 if (source_gone) {
2877 /* TRANS: "...between Spanish city Madrid and Paris..." */
2878 _("Trade between %s city %s and %s lost along with "
2879 "their city."),
2881 /* It's implicit to removed city's owner that that city no longer
2882 * has trade routes, so say nothing in that case */
2883 } else {
2886 _("Sorry, the %s canceled the trade route "
2887 "from %s to your city %s."),
2891 /* TRANS: "...from Paris to Spanish city Madrid." */
2892 _("We canceled the trade route "
2893 "from %s to %s city %s."),
2895 }
2896 }
2897}
2898
2899/************************************************************************/
2908 bool announce, bool source_gone)
2909{
2910 struct city *pc2 = game_city_by_number(proute->partner);
2911 struct trade_route *back_route = NULL;
2912
2914
2916
2917 if (pc2 != NULL) {
2919 if (pc1->id == pback->partner) {
2920 back_route = pback;
2921 }
2923
2924 if (back_route != NULL) {
2926 }
2927
2928 if (announce) {
2930
2933 }
2934 }
2935
2936 return back_route;
2937}
2938
2939/**********************************************************************/
2942bool city_illness_strike(struct city *pcity)
2943{
2945 ftc_server,
2946 _("%s has been struck by a plague! Population lost!"),
2947 city_link(pcity));
2948 if (city_reduce_size(pcity, 1, NULL, "plague")) {
2949 pcity->turn_plague = game.info.turn;
2950
2951 /* recalculate illness */
2952 pcity->server.illness
2953 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade),
2954 NULL);
2955
2956 return TRUE;
2957 }
2958
2959 return FALSE;
2960}
2961
2962/************************************************************************/
2968void do_sell_building(struct player *pplayer, struct city *pcity,
2969 struct impr_type *pimprove, const char *reason)
2970{
2971 if (can_city_sell_building(pcity, pimprove)) {
2972 pplayer->economic.gold += impr_sell_gold(pimprove);
2973 building_lost(pcity, pimprove, reason, NULL);
2974 }
2975}
2976
2977/************************************************************************/
2989struct city
2990*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
2991 struct player **oldcity_owner)
2992{
2993 struct city *oldcity = NULL;
2994
2995 fc_assert_ret_val(!city_has_building(pcity, pimprove), NULL);
2996 if (is_great_wonder(pimprove)) {
2997 if (!(oldcity = city_from_great_wonder(pimprove))) {
2998 oldcity = pcity;
2999 }
3001 } else if (is_small_wonder(pimprove)) {
3002 if (!(oldcity
3003 = city_from_small_wonder(city_owner(pcity), pimprove))) {
3004 oldcity = pcity;
3005 }
3006 }
3007 if (oldcity && oldcity != pcity) {
3010 _("Moving %s"));
3011 } else {
3013 _("Acquiring %s"));
3014 }
3015
3016 return oldcity;
3017}
3018
3019/************************************************************************/
3022bool building_removed(struct city *pcity, const struct impr_type *pimprove,
3023 const char *reason, struct unit *destroyer)
3024{
3025 int backup = pcity->id;
3026
3027 city_remove_improvement(pcity, pimprove);
3028
3029 script_server_signal_emit("building_lost", pcity, pimprove, reason,
3030 destroyer);
3031
3032 return city_exist(backup);
3033}
3034
3035/************************************************************************/
3039void building_lost(struct city *pcity, const struct impr_type *pimprove,
3040 const char *reason, struct unit *destroyer)
3041{
3042 struct player *owner = city_owner(pcity);
3043 bool was_capital = is_capital(pcity);
3044 bool city_remains;
3045
3046 city_remains = building_removed(pcity, pimprove, reason, destroyer);
3047
3048 if ((was_capital && (!city_remains || !is_capital(pcity)))
3049 && (owner->spaceship.state == SSHIP_STARTED
3050 || owner->spaceship.state == SSHIP_LAUNCHED)) {
3051 /* If the capital was lost (by destruction of the palace) production on
3052 * the spaceship is lost. */
3054 }
3055
3056 if (city_remains) {
3057 /* update city; influence of effects (buildings, ...) on unit upkeep */
3058 if (city_refresh(pcity)) {
3059 auto_arrange_workers(pcity);
3060 }
3061
3062 /* Re-update the city's visible area. This updates fog if the vision
3063 * range increases or decreases. */
3064 city_refresh_vision(pcity);
3065 }
3066}
3067
3068/************************************************************************/
3077{
3078 const struct unit_type *ut = unit_type_get(punit);
3079 struct player *plr = unit_owner(punit);
3080 bool update = FALSE;
3081 int cost;
3082
3084 cost = utype_upkeep_cost(ut, plr, o);
3085 if (cost > 0) {
3086 if (free_uk[o] > cost) {
3087 free_uk[o] -= cost;
3088 cost = 0;
3089 } else {
3090 cost -= free_uk[o];
3091 free_uk[o] = 0;
3092 }
3093 }
3094
3095 if (cost != punit->upkeep[o]) {
3096 update = TRUE;
3097 punit->upkeep[o] = cost;
3098 }
3100
3101 if (update) {
3102 /* Update unit information to the player and global observers. */
3104 }
3105}
3106
3107/************************************************************************/
3127void city_units_upkeep(const struct city *pcity)
3128{
3129 int free_uk[O_LAST];
3130
3131 if (!pcity || !pcity->units_supported
3132 || unit_list_size(pcity->units_supported) < 1) {
3133 return;
3134 }
3135
3140
3141 /* Save the upkeep for all units in the corresponding punit struct */
3145}
3146
3147/************************************************************************/
3150void change_build_target(struct player *pplayer, struct city *pcity,
3151 struct universal *target,
3152 enum event_type event)
3153{
3154 const char *name;
3155 const char *source;
3156
3157 /* If the city is already building this thing, don't do anything */
3158 if (are_universals_equal(&pcity->production, target)) {
3159 return;
3160 }
3161
3162 /* Is the city no longer building a wonder? */
3163 if (VUT_IMPROVEMENT == pcity->production.kind
3165 && event != E_IMP_AUTO
3166 && event != E_WORKLIST) {
3167 /* If the build target is changed because of an advisor's suggestion or
3168 because the worklist advances, then the wonder was completed --
3169 don't announce that the player has *stopped* building that wonder.
3170 */
3172 _("The %s have stopped building The %s in %s."),
3173 nation_plural_for_player(pplayer),
3175 city_link(pcity));
3176 }
3177
3178 /* Manage the city change-production penalty.
3179 (May penalize, restore or do nothing to the shield_stock.) */
3180 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3181 pcity->shield_stock = city_change_production_penalty(pcity, target);
3182 }
3183
3184 /* Change build target. */
3185 pcity->production = *target;
3186
3187 /* What's the name of the target? */
3189
3190 switch (event) {
3191 case E_WORKLIST:
3192 /* TRANS: Possible 'source' of the production change
3193 * (in "<city> is building ..." sentence). Preserve leading space. */
3194 source = _(" from the worklist");
3195 break;
3196 case E_IMP_AUTO:
3197 /* TRANS: Possible 'source' of the production change
3198 * (in "<city> is building ..." sentence). Preserve leading space. */
3199 source = _(" as suggested by the advisor");
3200 break;
3201 default:
3202 source = "";
3203 break;
3204 }
3205
3206 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3207 city_name_get(pcity), name, source);
3208
3209 /* Tell the player what's up. */
3210 /* FIXME: this may give bad grammar when translated if the 'source'
3211 * string can have multiple values. */
3212 notify_player(pplayer, city_tile(pcity), event, ftc_server,
3213 /* TRANS: "<city> is building <production><source>."
3214 * 'source' might be an empty string, or a clause like
3215 * " from the worklist". */
3216 _("%s is building %s%s."),
3217 city_link(pcity),
3218 name, source);
3219
3220 /* If the city is building a wonder, tell the rest of the world
3221 about it. */
3222 if (VUT_IMPROVEMENT == pcity->production.kind
3225 _("The %s have started building The %s in %s."),
3226 nation_plural_for_player(pplayer),
3227 name,
3228 city_link(pcity));
3229 }
3230}
3231
3232/************************************************************************/
3239void city_map_update_empty(struct city *pcity, struct tile *ptile)
3240{
3241 tile_set_worked(ptile, NULL);
3242 send_tile_info(NULL, ptile, FALSE);
3243 pcity->server.synced = FALSE;
3244}
3245
3246/************************************************************************/
3253void city_map_update_worker(struct city *pcity, struct tile *ptile)
3254{
3255 tile_set_worked(ptile, pcity);
3256 send_tile_info(NULL, ptile, FALSE);
3257 pcity->server.synced = FALSE;
3258}
3259
3260/************************************************************************/
3265static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3266{
3267 struct city *pwork = tile_worked(ptile);
3268
3269 if (NULL != pwork
3270 && !is_free_worked(pwork, ptile)
3271 && !city_can_work_tile(pwork, ptile)) {
3272 tile_set_worked(ptile, NULL);
3273 send_tile_info(NULL, ptile, FALSE);
3274
3275 pwork->specialists[DEFAULT_SPECIALIST]++; /* keep city sanity */
3276 pwork->server.synced = FALSE;
3277
3278 if (queued) {
3279 city_freeze_workers_queue(pwork); /* place the displaced later */
3280 } else {
3281 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3284 }
3285 return TRUE;
3286 }
3287
3288 return FALSE;
3289}
3290
3291/************************************************************************/
3297{
3298 return city_map_update_tile_direct(ptile, TRUE);
3299}
3300
3301/************************************************************************/
3305{
3306 return city_map_update_tile_direct(ptile, FALSE);
3307}
3308
3309/************************************************************************/
3313void sync_cities(void)
3314{
3316 return;
3317 }
3318
3319 players_iterate(pplayer) {
3320 city_list_iterate(pplayer->cities, pcity) {
3321 if (!pcity->server.synced) {
3322 /* sending will set to TRUE. */
3323 send_city_info(pplayer, pcity);
3324 }
3327}
3328
3329/************************************************************************/
3332void city_map_update_all(struct city *pcity)
3333{
3334 struct tile *pcenter = city_tile(pcity);
3335 const struct civ_map *nmap = &(wld.map);
3336
3338 ptile, _index, _x, _y) {
3339 /* bypass city_map_update_tile_now() for efficiency */
3342}
3343
3344/************************************************************************/
3348{
3349 city_list_iterate(pplayer->cities, pcity) {
3350 city_freeze_workers(pcity);
3351 city_map_update_all(pcity);
3352 city_thaw_workers(pcity);
3354}
3355
3356/************************************************************************/
3367{
3368 adjc_iterate(&(wld.map), ptile, tile1) {
3369 struct city *pcity = tile_city(tile1);
3370
3371 if (pcity) {
3372 struct player *pplayer = city_owner(pcity);
3373 const struct req_context city_ctxt = {
3374 .player = pplayer,
3375 .city = pcity,
3376 .tile = pcity->tile,
3377 };
3378
3379 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3380 city_built_iterate(pcity, pimprove) {
3381 if (!can_city_sell_building(pcity, pimprove)) {
3382 continue;
3383 }
3384
3385 requirement_vector_iterate(&pimprove->reqs, preq) {
3386 if ((VUT_TERRAIN == preq->source.kind
3387 || VUT_TERRAINCLASS == preq->source.kind
3388 || VUT_TERRFLAG == preq->source.kind)
3390 int price = impr_sell_gold(pimprove);
3391
3392 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3394 PL_("You sell %s in %s (now landlocked)"
3395 " for %d gold.",
3396 "You sell %s in %s (now landlocked)"
3397 " for %d gold.", price),
3399 city_link(pcity), price);
3400 }
3403 }
3405}
3406
3407/************************************************************************/
3413void city_refresh_vision(struct city *pcity)
3414{
3415 if (pcity->server.vision != NULL) {
3416 v_radius_t vision_radius_sq
3418
3419 vision_change_sight(pcity->server.vision, vision_radius_sq);
3420 ASSERT_VISION(pcity->server.vision);
3421 }
3422}
3423
3424/************************************************************************/
3429{
3430 city_list_iterate(pplayer->cities, pcity) {
3431 city_refresh_vision(pcity);
3433}
3434
3435/************************************************************************/
3439{
3440 fc_assert_ret_val(pcity != NULL, FALSE);
3441
3446 const struct civ_map *nmap = &(wld.map);
3447
3448 /* Check minimum / maximum allowed city radii */
3451
3453 /* No change */
3454 return FALSE;
3455 }
3456
3457 /* Get number of city tiles for each radii */
3460
3462 /* A change of the squared city radius but no change of the number of
3463 * city tiles */
3464 return FALSE;;
3465 }
3466
3467 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3469
3470 /* Workers map before */
3471 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3472 city_name_get(pcity), pcity->id, city_size_get(pcity),
3473 city_specialists(pcity));
3475
3477
3479 /* Increased number of city tiles */
3480 city_refresh_vision(pcity);
3481 } else {
3482 /* Reduced number of city tiles */
3483 int workers = 0;
3484
3485 /* Remove workers from the tiles removed rom the city map */
3487 city_x, city_y) {
3488 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3490 city_y);
3491
3492 if (ptile && pcity == tile_worked(ptile)) {
3493 city_map_update_empty(pcity, ptile);
3494 workers++;
3495 }
3497
3498 /* add workers to free city tiles */
3499 if (workers > 0) {
3500 int radius_sq = city_map_radius_sq_get(pcity);
3501
3503 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3504 city_x, city_y);
3505
3506 if (ptile && !is_free_worked(pcity, ptile)
3507 && tile_worked(ptile) != pcity
3508 && city_can_work_tile(pcity, ptile)) {
3509 city_map_update_worker(pcity, ptile);
3510 workers--;
3511 }
3512
3513 if (workers <= 0) {
3514 break;
3515 }
3517 }
3518
3519 /* If there are still workers they will be updated to specialists */
3520 if (workers > 0) {
3521 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3522 }
3523
3524 city_refresh_vision(pcity);
3525 }
3526
3527 /* City removal might be ongoing, and advisor data already deleted */
3528 if (pcity->server.adv != NULL) {
3529 /* If city is under AI control, update it */
3530 adv_city_update(pcity);
3531 }
3532
3534 ftc_server, _("The size of the city map of %s is %s."),
3535 city_name_get(pcity),
3536 city_tiles_old < city_tiles_new ? _("increased")
3537 : _("reduced"));
3538
3539 /* Workers map after */
3540 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3541 city_name_get(pcity), pcity->id, city_size_get(pcity),
3542 city_specialists(pcity));
3544
3545 return TRUE;
3546}
3547
3548/************************************************************************/
3551void clear_worker_task(struct city *pcity, struct worker_task *ptask)
3552{
3553 struct packet_worker_task packet;
3554
3555 if (ptask == NULL) {
3556 return;
3557 }
3558
3560
3561 packet.city_id = pcity->id;
3562 packet.tile_id = tile_index(ptask->ptile);
3563 packet.activity = ACTIVITY_LAST;
3564 packet.tgt = 0;
3565 packet.want = 0;
3566
3567 free(ptask);
3568
3571}
3572
3573/************************************************************************/
3576void clear_worker_tasks(struct city *pcity)
3577{
3578 while (worker_task_list_size(pcity->task_reqs) > 0) {
3580 }
3581}
3582
3583/************************************************************************/
3587{
3588 struct packet_worker_task packet;
3589
3590 packet.city_id = pcity->id;
3591
3593 packet.tile_id = tile_index(ptask->ptile);
3594 packet.activity = ptask->act;
3595 if (ptask->tgt == NULL) {
3596 packet.tgt = -1;
3597 } else {
3598 packet.tgt = extra_number(ptask->tgt);
3599 }
3600 packet.want = ptask->want;
3601
3605}
3606
3607/************************************************************************/
3610int city_production_buy_gold_cost(const struct city *pcity)
3611{
3612 int build = pcity->shield_stock;
3613
3614 switch (pcity->production.kind) {
3615 case VUT_IMPROVEMENT:
3616 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3617 build);
3618 case VUT_UTYPE:
3619 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3620 build);
3621 default:
3622 break;
3623 };
3624
3625 return FC_INFINITY;
3626}
3627
3628/************************************************************************/
3633 const struct impr_type *pimprove,
3634 const char *format)
3635{
3636 if (is_wonder(pimprove)) {
3637 /* Only wonders may grant governments */
3638 struct cur_govs_data *govs_data;
3639 char buf[250];
3640
3642 city_add_improvement(pcity, pimprove);
3643
3644 fc_snprintf(buf, sizeof(buf), format, improvement_name_translation(pimprove));
3645
3646 players_iterate_alive(pplayer) {
3649
3651 } else {
3652 city_add_improvement(pcity, pimprove);
3653 }
3654}
3655
3656/************************************************************************/
3660int city_original_owner(const struct city *pcity,
3661 const struct player *known_for)
3662{
3663 if (pcity->original == NULL) {
3664 /* Nobody knows */
3665 return MAX_NUM_PLAYER_SLOTS;
3666 }
3667
3668 if (pcity->original != known_for
3669 || known_for == NULL) {
3670 /* Players know what they have built themselves,
3671 * global observer knows everything. */
3672 return player_number(pcity->original);
3673 }
3674
3675 return MAX_NUM_PLAYER_SLOTS;
3676}
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:354
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
#define n
Definition astring.c:77
bool is_land_barbarian(struct player *pplayer)
Definition barbarian.c:75
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:144
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:113
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_ISSET_ANY(vec)
Definition bitvector.h:109
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
void citizens_init(struct city *pcity)
Definition citizens.c:32
void citizens_convert_conquest(struct city *pcity)
void citizens_update(struct city *pcity, struct player *plr)
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3589
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:147
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:736
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1136
int city_granary_size(int city_size)
Definition city.c:2123
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2187
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Definition city.c:1006
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:304
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
bool is_capital(const struct city *pcity)
Definition city.c:1571
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3359
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1478
struct output_type * get_output_type(Output_type_id output)
Definition city.c:637
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:853
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2177
bool city_unhappy(const struct city *pcity)
Definition city.c:1618
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3418
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1671
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2861
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1878
bool city_happy(const struct city *pcity)
Definition city.c:1606
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3345
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1375
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:136
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:445
citizens city_specialists(const struct city *pcity)
Definition city.c:3305
void city_choose_build_default(struct city *pcity)
Definition city.c:1078
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1687
int city_map_tiles(int city_radius_sq)
Definition city.c:170
bool city_exist(int id)
Definition city.c:3560
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1447
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1988
void city_rally_point_clear(struct city *pcity)
Definition city.c:3614
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:945
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:699
#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:833
#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:822
#define city_map_iterate_without_index_end
Definition city.h:184
#define city_built_iterate_end
Definition city.h:828
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:180
#define output_type_iterate_end
Definition city.h:839
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3239
void city_freeze_workers_queue(struct city *pcity)
Definition citytools.c:161
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:2506
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3304
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:2142
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3265
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3586
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3610
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2343
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2740
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:2990
static void raze_city(struct city *pcity)
Definition citytools.c:923
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1428
static bool city_workers_queue_remove(struct city *pcity)
Definition citytools.c:180
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:2196
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2163
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1513
bool send_city_suppression(bool now)
Definition citytools.c:2152
static bool send_city_suppressed
Definition citytools.c:102
void sync_cities(void)
Definition citytools.c:3313
static const char * search_for_city_name(struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
Definition citytools.c:334
static void announce_trade_route_removal(struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
Definition citytools.c:2850
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:137
void update_unit_upkeep(struct unit *punit, int free_uk[O_LAST])
Definition citytools.c:3076
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3428
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3660
static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders)
Definition citytools.c:1013
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3438
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:3150
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3022
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3347
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2942
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3296
void city_thaw_workers(struct city *pcity)
Definition citytools.c:147
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2832
static bool is_default_city_name(const char *name, struct player *pplayer)
Definition citytools.c:316
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3039
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1973
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3551
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:956
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3127
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3576
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:3366
void remove_city(struct city *pcity)
Definition citytools.c:1699
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:2968
static struct city_list * arrange_workers_queue
Definition citytools.c:99
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2907
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1673
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2395
static int evaluate_city_name_priority(struct tile *ptile, const struct nation_city *pncity, int default_priority)
Definition citytools.c:215
void city_thaw_workers_queue(void)
Definition citytools.c:193
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2225
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:1071
void city_add_improvement_with_gov_notice(struct city *pcity, const struct impr_type *pimprove, const char *format)
Definition citytools.c:3632
void send_player_cities(struct player *pplayer)
Definition citytools.c:2323
void city_map_update_all(struct city *pcity)
Definition citytools.c:3332
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:3253
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2811
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2300
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3413
#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:366
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:197
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3536
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4575
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:762
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:182
void city_refresh_queue_processing(void)
Definition cityturn.c:213
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:235
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:2418
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:846
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1070
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:984
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
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:633
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:391
int Impr_type_id
Definition fc_types.h:379
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
@ RPT_CERTAIN
Definition fc_types.h:704
#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:375
#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:62
struct city * game_city_by_name(const char *name)
Definition game.c:88
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:178
struct city * game_city_by_number(int id)
Definition game.c:107
#define any_web_conns()
Definition game.h:315
@ 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:907
struct city * owner
Definition citydlg.c:220
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:501
void adv_city_update(struct city *pcity)
Definition infracache.c:462
void adv_city_alloc(struct city *pcity)
Definition infracache.c:488
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:205
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_base(level, message,...)
Definition log.h:94
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
int map_num_tiles(void)
Definition map.c:1014
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
#define adjc_iterate_end
Definition map.h:433
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:428
#define whole_map_iterate(_map, _tile)
Definition map.h:545
#define whole_map_iterate_end
Definition map.h:554
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2511
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2185
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:894
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2586
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:1364
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:768
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:418
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2689
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1156
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2264
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1436
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:2215
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1379
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2499
#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_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:331
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:243
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:491
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:465
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:1990
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:1405
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:537
#define players_iterate(_pplayer)
Definition player.h:532
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
#define player_slots_iterate(_pslot)
Definition player.h:523
#define is_ai(plr)
Definition player.h:230
#define players_iterate_alive_end
Definition player.h:547
#define player_slots_iterate_end
Definition player.h:527
#define players_iterate_alive(_pplayer)
Definition player.h:542
int normal_player_count(void)
Definition plrhand.c:3200
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2951
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2357
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1142
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3001
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2904
void update_capital(struct player *pplayer)
Definition plrhand.c:729
#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 player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
int universal_number(const struct universal *source)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
struct research * research_get(const struct player *pplayer)
Definition research.c:128
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
#define sanity_check_city(x)
Definition sanitycheck.h:41
void script_server_signal_emit(const char *signal_name,...)
void script_server_remove_exported_object(void *object)
static struct connection connections[MAX_NUM_CONNECTIONS]
Definition sernet.c:94
void flush_packets(void)
Definition sernet.c:381
static struct setting settings[]
Definition settings.c:1473
bool is_ascii_name(const char *name)
Definition shared.c:283
#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:2020
enum server_states server_state(void)
Definition srv_main.c:333
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:270
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:279
bv_plr_flags flags
Definition player.h:290
char username[MAX_LEN_NAME]
Definition player.h:250
struct team * team
Definition player.h:259
struct conn_list * connections
Definition player.h:296
bool is_alive
Definition player.h:266
struct player_economic economic
Definition player.h:282
const struct player * player
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition unit.h:138
int upkeep[O_LAST]
Definition unit.h:148
int id
Definition unit.h:145
bool moved
Definition unit.h:173
struct unit::@81::@84 server
struct tile * tile
Definition unit.h:140
int homecity
Definition unit.h:146
struct unit * transporter
Definition unit.h:183
const struct unit_type * utype
Definition unit.h:139
bool dying
Definition unit.h:250
enum universals_n kind
Definition fc_types.h:903
universals_u value
Definition fc_types.h:902
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:974
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#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:373
#define terrain_type_iterate_end
Definition terrain.h:379
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:100
#define tile_index(_pt_)
Definition tile.h:88
#define tile_worked(_tile)
Definition tile.h:114
#define tile_terrain(_tile)
Definition tile.h:110
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_continent(_tile)
Definition tile.h:92
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
#define tile_owner(_tile)
Definition tile.h:96
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
Goods_type_id goods_number(const struct goods_type *pgood)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
#define trade_routes_iterate_safe_end
@ TRI_CANCEL
Definition traderoutes.h:32
#define trade_routes_iterate_end
#define trade_routes_iterate_safe(c, proute)
#define trade_routes_iterate(c, proute)
trade_route_type
Definition traderoutes.h:37
const struct unit_type * utype
Definition fc_types.h:724
const struct impr_type * building
Definition fc_types.h:717
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1918
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:838
#define unit_tile(_pu)
Definition unit.h:390
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:413
#define unit_owner(_pu)
Definition unit.h:389
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6468
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:4014
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1398
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2712
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2725
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:800
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2135
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4855
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1225
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:766
#define utype_class(_t_)
Definition unittype.h:749
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
#define unit_type_iterate(_p)
Definition unittype.h:852
#define unit_type_iterate_end
Definition unittype.h:859
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