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 /* City might have been arranged since it was originally put to the queue.
167 * Make sure needs_arrange is set again. */
168 if (pcity->server.needs_arrange == CNA_NOT) {
170 }
171 return;
172 }
173
175 city_freeze_workers(pcity);
176 if (pcity->server.needs_arrange == CNA_NOT) {
178 }
179}
180
181/************************************************************************/
185static bool city_workers_queue_remove(struct city *pcity)
186{
188 return FALSE;
189 }
190
192}
193
194/************************************************************************/
211
212/************************************************************************/
220static int evaluate_city_name_priority(struct tile *ptile,
221 const struct nation_city *pncity,
223{
224 /* Lower values mean higher priority. */
227
228 /* Increasing this value will increase the difference caused by
229 (non-)matching terrain. A matching terrain is mult_factor
230 "better" than an unlisted terrain, which is mult_factor
231 "better" than a non-matching terrain. */
232 const float mult_factor = 1.4;
233 bool river = FALSE;
234
235 /*
236 * If natural city names aren't being used, we just return the
237 * base value. This will have the effect of the first-listed
238 * city being used. We do this here rather than special-casing
239 * it elsewhere because this localizes everything to this
240 * function, even though it's a bit inefficient.
241 */
243 return default_priority;
244 }
245
246 /*
247 * Assuming we're using the natural city naming system, we use
248 * an internal alorithm to calculate the priority of each name.
249 * It's a pretty fuzzy algorithm; we basically do the following:
250 * - Change the priority scale from 0..n to 10..n+10. This means
251 * each successive city is 10% lower priority than the first.
252 * - Multiply by a semi-random number. This has the effect of
253 * decreasing rounding errors in the successive calculations,
254 * as well as introducing a smallish random effect.
255 * - Check over all the applicable terrains, and
256 * multiply or divide the priority based on whether or not
257 * the terrain matches. See comment below.
258 */
259
260 priority += 10.0;
261 priority *= 10.0 + fc_rand(5);
262
263 /*
264 * The terrain priority in the struct nation_city will be either
265 * -1, 0, or 1. We therefore take this as-is if the terrain is
266 * present, or negate it if not.
267 *
268 * The reason we multiply as well as divide the value is so
269 * that cities that don't care what terrain they are on (which
270 * is the default) will be left in the middle of the pack. If
271 * we _only_ multiplied (or divided), then cities that had more
272 * terrain labels would have their priorities hurt (or helped).
273 */
276 if (tile_has_extra(ptile, priver)
278 river = TRUE;
279 break;
280 }
282 if (!river) {
284 }
285
286 switch (goodness) {
287 case NCP_DISLIKE:
289 break;
290 case NCP_NONE:
291 break;
292 case NCP_LIKE:
294 break;
295 }
296
297 terrain_type_iterate(pterrain) {
298 /* Now we do the same for every available terrain. */
300 if (!is_terrain_near_tile(&(wld.map), ptile, pterrain, TRUE)) {
302 }
303 switch (goodness) {
304 case NCP_DISLIKE:
306 break;
307 case NCP_NONE:
308 break;
309 case NCP_LIKE:
311 }
313
314 return (int) priority;
315}
316
317/************************************************************************/
321static bool is_default_city_name(const char *name, struct player *pplayer)
322{
324 pncity) {
326 return TRUE;
327 }
329 return FALSE;
330}
331
332/************************************************************************/
339static const char *search_for_city_name(struct tile *ptile,
340 const struct nation_city_list *
341 default_cities,
342 struct player *pplayer)
343{
344 int choice = 0, priority, best_priority = -1;
345 const char *name, *best_name = NULL;
346
347 nation_city_list_iterate(default_cities, pncity) {
350 && is_allowed_city_name(pplayer, name, NULL, 0)) {
351 priority = evaluate_city_name_priority(ptile, pncity, choice++);
352 if (-1 == best_priority || priority < best_priority) {
354 best_name = name;
355 }
356 }
358
359 return best_name;
360}
361
362/************************************************************************/
374bool is_allowed_city_name(struct player *pplayer, const char *cityname,
375 char *error_buf, size_t bufsz)
376{
377 struct connection *pconn = conn_by_user(pplayer->username);
378
379 /* Mode 1: A city name has to be unique for each player. */
381 && city_list_find_name(pplayer->cities, cityname)) {
382 if (error_buf) {
383 fc_snprintf(error_buf, bufsz, _("You already have a city called %s."),
384 cityname);
385 }
386 return FALSE;
387 }
388
389 /* Modes 2,3: A city name has to be globally unique. */
393 if (error_buf) {
395 _("A city called %s already exists."), cityname);
396 }
397 return FALSE;
398 }
399
400 /* General rule: any name in our ruleset is allowed. */
401 if (is_default_city_name(cityname, pplayer)) {
402 return TRUE;
403 }
404
405 /*
406 * Mode 3: Check that the proposed city name is not in another
407 * player's default city names. Note the name will already have been
408 * allowed if it is in this player's default city names list.
409 */
411 struct player *pother = NULL;
412
414 if (player2 != pplayer && is_default_city_name(cityname, player2)) {
415 pother = player2;
416 break;
417 }
419
420 if (pother != NULL) {
421 if (error_buf) {
423 _("Can't use %s as a city name. It is reserved for %s."),
425 }
426 return FALSE;
427 }
428 }
429
430 /* To prevent abuse, only players with HACK access (usually local
431 * connections) can use non-ascii names. Otherwise players could use
432 * confusing garbage names in multi-player games.
433 *
434 * We can even reach here for an AI player, if all the cities of the
435 * original nation are exhausted and the backup nations have non-ascii
436 * names in them. */
438 && (!pconn || pconn->access_level != ALLOW_HACK)) {
439 if (error_buf) {
441 _("%s is not a valid name. Only ASCII or "
442 "ruleset names are allowed for cities."),
443 cityname);
444 }
445 return FALSE;
446 }
447
448
449 return TRUE;
450}
451
452/************************************************************************/
458const char *city_name_suggestion(struct player *pplayer, struct tile *ptile)
459{
460 struct nation_type *pnation = nation_of_player(pplayer);
461 const char *name;
462
463 log_verbose("Suggesting city name for %s at (%d,%d)",
464 player_name(pplayer), TILE_XY(ptile));
465
466 /* First try default city names. */
467 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
468 if (NULL != name) {
469 log_debug("Default city name found: %s.", name);
470 return name;
471 }
472
473 /* Not found... Let's try a straightforward algorithm to look through
474 * nations to find a city name.
475 *
476 * We start by adding the player's nation to the queue. Then we proceed:
477 * - Pick a random nation from the queue.
478 * - If it has a valid city name, use that.
479 * - Otherwise, add all parent and child nations to the queue.
480 * - If the queue is empty, add all remaining nations to it and continue.
481 *
482 * Variables used:
483 * - nation_list is a queue of nations to look through.
484 * - nations_selected tells whether each nation is in the queue already
485 * - queue_size gives the size of the queue (number of nations in it).
486 * - i is the current position in the queue.
487 * Note that nations aren't removed from the queue after they're processed.
488 * New nations are just added onto the end. */
489 {
492 int queue_size = 1, i = 0, idx;
493
495 nation_list[0] = pnation;
497
498 while (i < nation_count()) {
499 for (; i < queue_size; i++) {
500
501 if (0 < i) {
502 /* Pick a random nation from the queue. */
503 const int which = i + fc_rand(queue_size - i);
504 struct nation_type *tmp = nation_list[i];
505
508
509 pnation = nation_list[i];
510 log_debug("Looking through %s.", nation_rule_name(pnation));
511 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
512
513 if (NULL != name) {
514 return name;
515 }
516 }
517
518 /* Append the nation's civil war nations into the search tree. */
520 idx = nation_index(n);
521 if (!nations_selected[idx]) {
523 nations_selected[idx] = TRUE;
524 queue_size++;
525 log_debug("Child %s.", nation_rule_name(n));
526 }
528
529 /* Append the nation's parent nations into the search tree. */
531 idx = nation_index(n);
532 if (!nations_selected[idx]) {
534 nations_selected[idx] = TRUE;
535 queue_size++;
536 log_debug("Parent %s.", nation_rule_name(n));
537 }
539 }
540
541 /* Still not found; append all remaining nations. */
543 idx = nation_index(n);
544 if (!nations_selected[idx]) {
547 queue_size++;
548 log_debug("Misc nation %s.", nation_rule_name(n));
549 }
551 }
552 }
553
554 /* Not found in rulesets, make a default name. */
555 {
556 static char tempname[MAX_LEN_CITYNAME];
557 int i;
558
559 log_debug("City name not found in rulesets.");
560 for (i = 1; i <= map_num_tiles(); i++ ) {
561 fc_snprintf(tempname, MAX_LEN_CITYNAME, _("City no. %d"), i);
563 return tempname;
564 }
565 }
566
567 fc_assert_msg(FALSE, "Failed to generate a city name.");
568 sz_strlcpy(tempname, _("A poorly-named city"));
569 return tempname;
570 }
571}
572
573/************************************************************************/
576int build_points_left(struct city *pcity)
577{
579
580 return cost - pcity->shield_stock;
581}
582
583/************************************************************************/
590static void transfer_unit(struct unit *punit, struct city *tocity,
591 bool rehome, bool verbose)
592{
595
596 /* Transferring a dying GameLoss unit as part of the loot for
597 * killing it caused gna bug #23676. */
599 "Tried to transfer the dying unit %d.",
600 punit->id);
601
602 if (from_player == to_player) {
604 log_verbose("Changed homecity of %s %s to %s",
608 if (verbose) {
611 _("Changed homecity of %s to %s."),
614 }
615 } else {
616 struct tile *utile = unit_tile(punit);
617 struct city *in_city = tile_city(utile);
618
621 /* This is a unique unit that to_player already has. A transfer would
622 * break the rule that a player only may have one unit of each unique
623 * unit type. */
624
625 log_debug("%s already have a %s. Can't transfer from %s",
629
631 /* Try to save game loss units. */
632 bounce_unit(punit, verbose);
633 } else {
634 /* Kill the unique unit. */
635
636 if (verbose) {
639 /* TRANS: Americans ... Leader */
640 _("The %s already have a %s. Can't transfer yours."),
643 }
644
646 }
647
648 return;
649 }
650
651 if (in_city) {
652 log_verbose("Transferred %s in %s from %s to %s",
656 if (verbose) {
659 _("Transferred %s in %s from %s to %s."),
664 }
665 } else if (can_unit_exist_at_tile(&(wld.map), punit, tocity->tile)) {
666 log_verbose("Transferred %s from %s to %s",
670 if (verbose) {
673 _("Transferred %s from %s to %s."),
677 }
678 } else {
679 log_verbose("Could not transfer %s from %s to %s",
683 if (verbose) {
686 /* TRANS: Polish Destroyer ... German <city> */
687 _("%s %s lost in transfer to %s %s"),
692 }
694 return;
695 }
696
698 }
700}
701
702/************************************************************************/
721void transfer_city_units(struct player *pplayer, struct player *pvictim,
722 struct unit_list *units, struct city *pcity,
723 struct city *exclude_city,
724 int kill_outside, bool verbose)
725{
726 struct tile *ptile = pcity->tile;
727 int saved_id = pcity->id;
728 const char *name = city_name_get(pcity);
729
730 /* Transfer enemy units in the city to the new owner.
731 * Only relevant if we are transferring to another player. */
732 if (pplayer != pvictim) {
734 if (vunit->server.dying) {
735 /* Don't transfer or bounce a dying unit. It will soon be gone
736 * anyway.
737 *
738 * Bouncing a dying unit isn't a good idea.
739 * Remaining death handling may do things meant for its current
740 * location to the new location. (Example: Stack death)
741 * bounce_unit() will wipe the unit if it can't be bounced. Wiping
742 * the dying unit isn't a good idea. The remaining death handling
743 * code will try to read from it.
744 *
745 * Transferring a dying GameLoss unit as part of the loot for
746 * killing it caused gna bug #23676. */
747 continue;
748 }
749
750 /* Don't transfer units already owned by new city-owner --wegge */
751 if (unit_owner(vunit) == pvictim) {
752 /* Determine whether unit was homeless. If it was, we don't give
753 * it a homecity, only change ownership.
754 * We have to search the transferred city's former units because
755 * the unit may have been made only temporarily homeless during
756 * city transfer. */
757 bool homeless = (vunit->homecity == 0)
759
760 /* vunit may die during transfer_unit().
761 * unit_list_remove() is still safe using vunit pointer, as
762 * pointer is not used for dereferencing, only as value.
763 * Not sure if it would be safe to unlink first and transfer only
764 * after that. Not sure if it is correct to unlink at all in
765 * some cases, depending which list 'units' points to. */
766 transfer_unit(vunit, pcity, !homeless, verbose);
768 } else if (!pplayers_allied(pplayer, unit_owner(vunit))) {
769 /* the owner of vunit is allied to pvictim but not to pplayer */
770 bounce_unit(vunit, verbose);
771 }
773 }
774
775 if (!city_exist(saved_id)) {
776 saved_id = 0;
777 }
778
779 /* Any remaining units supported by the city are either given new home
780 cities or maybe destroyed */
783
784 if (vunit->server.dying) {
785 /* Don't transfer or destroy a dying unit. It will soon be gone
786 * anyway.
787 *
788 * Transferring a dying GameLoss unit as part of the loot for
789 * killing it caused gna bug #23676. */
790 continue;
791 }
792
795 /* unit is in another city: make that the new homecity,
796 * unless that city is actually the same city (happens if disbanding)
797 * Unit had a homecity since it was supported, so rehome. */
799 } else if ((kill_outside == -1
801 && saved_id) {
802 /* else transfer to specified city. */
803 transfer_unit(vunit, pcity, TRUE, verbose);
804 if (unit_tile(vunit) == ptile && !pplayers_allied(pplayer, pvictim)) {
805 /* Unit is inside city being transferred, bounce it */
807 }
808 } else {
809 /* The unit is lost. Call notify_player (in all other cases it is
810 * called automatically). */
811 log_verbose("Lost %s %s at (%d,%d) when %s was lost.",
814 if (verbose) {
817 _("%s lost along with control of %s."),
819 }
821 }
823
824#ifdef FREECIV_DEBUG
826 if (punit->server.dying) {
827 /* Leave the dying alone. */
828 continue;
829 }
830
831 fc_assert(punit->homecity == pcity->id);
832 fc_assert(unit_owner(punit) == pplayer);
834#endif /* FREECIV_DEBUG */
835}
836
837/************************************************************************/
856struct city *find_closest_city(const struct tile *ptile,
857 const struct city *pexclcity,
858 const struct player *pplayer,
859 bool only_ocean, bool only_continent,
860 bool only_known, bool only_player,
861 bool only_enemy, const struct unit_class *pclass)
862{
864 struct city *best_city = NULL;
865 int best_dist = -1;
866
867 fc_assert_ret_val(ptile != NULL, NULL);
868
869 if (pplayer != NULL && only_player && only_enemy) {
870 log_error("Non of my own cities will be at war with me!");
871 return NULL;
872 }
873
874 con = tile_continent(ptile);
875
877 if (pplayer != NULL && only_player && pplayer != aplayer) {
878 /* only cities of player 'pplayer' */
879 continue;
880 }
881
882 if (pplayer != NULL && only_enemy
883 && !pplayers_at_war(pplayer, aplayer)) {
884 /* only cities of players at war with player 'pplayer' */
885 continue;
886 }
887
888 city_list_iterate(aplayer->cities, pcity) {
889 int city_dist;
890
891 if (pexclcity && pexclcity == pcity) {
892 /* not this city */
893 continue;
894 }
895
896 city_dist = real_map_distance(ptile, city_tile(pcity));
897
898 /* Find the closest city matching the requirements.
899 * - closer than the current best city
900 * - (if required) on the same continent
901 * - (if required) adjacent to ocean
902 * - (if required) only cities known by the player
903 * - (if required) only cities native to the class */
904 if ((best_dist == -1 || city_dist < best_dist)
905 && (!only_continent || con == tile_continent(pcity->tile))
907 city_tile(pcity), TC_OCEAN))
908 && (!only_known
909 || (map_is_known(city_tile(pcity), pplayer)
910 && map_get_player_site(city_tile(pcity), pplayer)->identity
912 && (pclass == NULL
913 || is_native_near_tile(&(wld.map), pclass, city_tile(pcity)))) {
915 best_city = pcity;
916 }
919
920 return best_city;
921}
922
923/************************************************************************/
928static void raze_city(struct city *pcity)
929{
930 int razechance = game.server.razechance;
931 bool city_remains = TRUE;
932
933 /* land barbarians are more likely to destroy city improvements */
934 if (is_land_barbarian(city_owner(pcity))) {
935 razechance += 30;
936 }
937
938 city_built_iterate(pcity, pimprove) {
939 /* Small wonders should have already been removed by
940 * transfer_city() (with 100% probability). */
941 fc_assert(!is_small_wonder(pimprove));
942 if (is_improvement(pimprove) && (fc_rand(100) < razechance)) {
943 /* FIXME: Should maybe have conquering unit instead of NULL as destroyer */
944 city_remains = building_removed(pcity, pimprove, "razed", NULL);
945 if (!city_remains) {
946 break;
947 }
948 }
950
951 if (city_remains) {
953 pcity->shield_stock = 0;
954 }
955}
956
957/************************************************************************/
961static void reestablish_city_trade_routes(struct city *pcity)
962{
964 bool keep_route;
965 struct trade_route *back;
966 struct city *partner = game_city_by_number(proute->partner);
967
968 /* Remove the city's trade routes (old owner).
969 * Do not announce removal as we might restore the route immediately below */
971
972 keep_route = can_cities_trade(pcity, partner)
973 && can_establish_trade_route(pcity, partner);
974
975 if (!keep_route) {
976 enum trade_route_type type = cities_trade_route_type(pcity, partner);
978
979 if (settings->cancelling != TRI_CANCEL) {
981 }
982 }
983
984 /* Readd the city's trade route (new owner) */
985 if (keep_route) {
988 } else {
989 free(proute);
990 free(back);
991
992 /* Now announce the trade route removal */
993 announce_trade_route_removal(pcity, partner, FALSE);
994 }
995
996 /* Refresh regardless; either it lost a trade route or the trade
997 * route revenue changed. */
998 city_refresh(partner);
999 send_city_info(city_owner(partner), partner);
1000
1001 /* Give the new owner infos about the city which has a trade route
1002 * with the transferred city. */
1004 struct player *owner = city_owner(pcity);
1005
1006 map_show_tile(owner, partner->tile);
1007 update_dumb_city(owner, partner);
1008 send_city_info(owner, partner);
1009 }
1011}
1012
1013/************************************************************************/
1018static void build_free_small_wonders(struct player *pplayer,
1020{
1021 int size = city_list_size(pplayer->cities);
1022
1023 if (!game.server.savepalace) {
1024 /* Nothing to do */
1025 return;
1026 }
1027
1028 if (size == 0) {
1029 /* The last city was removed or transferred to the enemy.
1030 * If the victim survives to found or acquire another city, they'll
1031 * get any savepalace initial buildings then. */
1032 return;
1033 }
1034
1035 improvement_iterate(pimprove) {
1038 /* FIXME: instead, find central city */
1039 struct city *pnew_city = city_list_get(pplayer->cities, fc_rand(size));
1040
1041 fc_assert_action(NULL == city_from_small_wonder(pplayer, pimprove),
1042 continue);
1043
1045
1046 /*
1047 * send_player_cities will recalculate all cities and send them to
1048 * the client.
1049 */
1050 send_player_cities(pplayer);
1051
1053 /* FIXME: should already be notified about city loss? */
1054 /* TRANS: <building> ... <city> */
1055 _("A replacement %s was built in %s."),
1058 /*
1059 * The enemies want to see the new capital in their intelligence
1060 * report.
1061 */
1063 }
1065}
1066
1067/************************************************************************/
1076bool transfer_city(struct player *ptaker, struct city *pcity,
1078 bool resolve_stack, bool raze, bool build_free)
1079{
1081 struct vision *old_vision, *new_vision;
1082 struct unit_list *old_city_units = unit_list_new();
1083 struct player *pgiver = city_owner(pcity);
1084 struct tile *pcenter = city_tile(pcity);
1085 int saved_id = pcity->id;
1086 bool city_remains = TRUE;
1087 bool had_great_wonders = FALSE;
1092 bool taker_had_no_cities = (city_list_size(ptaker->cities) == 0);
1093 bool new_extras;
1094 int units_num = 0;
1095 const int ul_size = unit_list_size(pcenter->units);
1096 int central_units[ul_size + 1];
1098 int i;
1099 const struct civ_map *nmap = &(wld.map);
1100
1102
1106
1107 if (units_num > 0) {
1109
1110 /* Remember what player see what unit. */
1111 for (i = 0; i < units_num; i++) {
1113
1118 }
1120 }
1121
1122 fc_assert(i == units_num);
1123 }
1124
1125 /* Remove AI control of the old owner. */
1126 CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity);
1127
1128 /* Forget old tasks */
1129 clear_worker_tasks(pcity);
1130
1131 /* Forget old rally point */
1133
1134 /* Activate AI control of the new owner. */
1135 CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
1136
1137 city_freeze_workers(pcity);
1138
1141 /* Mark unit to have no homecity at all.
1142 * 1. We remove unit from units_supported list here,
1143 * real_change_unit_homecity() should not attempt it.
1144 * 2. Otherwise we might delete the homecity from under the unit
1145 * in the client */
1146 punit->homecity = 0;
1150
1151 /* Remove all global improvement effects that this city confers (but
1152 then restore the local improvement list - we need this to restore the
1153 global effects for the new city owner) */
1155 city_built_iterate(pcity, pimprove) {
1156 if (is_small_wonder(pimprove)) {
1157 /* Small wonders are really removed (not restored later). */
1158 building_removed(pcity, pimprove, "conquered", NULL);
1160 } else {
1161 city_remove_improvement(pcity, pimprove);
1162 if (is_great_wonder(pimprove)) {
1164 }
1165 /* Note: internal turn here, next city_built_iterate(). */
1166 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
1167 }
1169
1171 old_vision = pcity->server.vision;
1173 pcity->server.vision = new_vision;
1176
1178
1180 && city_list_find_name(ptaker->cities, city_name_get(pcity))) {
1181 char *old_city_name = fc_strdup(city_name_get(pcity));
1182
1185 _("You already had a city called %s."
1186 " The city was renamed to %s."),
1188 city_link(pcity));
1189
1191 }
1192
1193 /* Has to follow the unfog call above. */
1194 city_list_remove(pgiver->cities, pcity);
1196 /* city_thaw_workers_queue() later */
1197
1198 pcity->owner = ptaker;
1199 pcity->capital = CAPITAL_NOT;
1200 pcity->acquire_t = CACQ_CONQUEST;
1202 city_list_prepend(ptaker->cities, pcity);
1203
1204 if (could_see_unit != NULL) {
1205 /* Hide/reveal units. Do it after vision have been given to taker, city
1206 * owner has been changed, and before any script could be spawned. */
1207 for (i = 0; i < units_num; i++) {
1209
1213 && !aunit->server.dying) {
1214 /* Reveal 'aunit'. */
1215 send_unit_info(aplayer->connections, aunit);
1216 }
1217 } else {
1219 /* Hide 'aunit'. */
1221 }
1222 }
1224 }
1225
1226 fc_assert(i == units_num);
1227
1230 }
1231
1233 pcity, NULL,
1235 /* The units themselves are already freed by transfer_city_units(). */
1237
1238 if (resolve_stack) {
1240 }
1241
1242 if (!city_exist(saved_id)) {
1244 }
1245
1246 /* Reset turns owner counters */
1247 if (city_remains) {
1249 if (pcount->type == CB_CITY_OWNED_TURNS) {
1250 pcity->counter_values[pcount->index] = 0;
1251 }
1253 }
1254
1255 if (city_remains) {
1256 /* Update the city's trade routes. */
1258
1259 /* Clear CMA. */
1260 if (pcity->cm_parameter) {
1261 free(pcity->cm_parameter);
1262 pcity->cm_parameter = NULL;
1263 }
1264
1265 city_refresh(pcity);
1266 }
1267
1268 /*
1269 * maybe_make_contact() MUST be called before city_map_update_all(),
1270 * since the diplomacy status can influence whether a tile is available.
1271 */
1273
1274 if (city_remains) {
1275 struct extra_type *upgradet;
1276
1277 if (raze) {
1278 raze_city(pcity);
1279 }
1280
1281 if (taker_had_no_cities) {
1282 /* If conqueror previously had no cities, we might need to give
1283 * them a palace etc */
1284 if (build_free) {
1286 } /* Else caller should probably ensure palace is built */
1287
1288 BV_SET(ptaker->flags, PLRF_FIRST_CITY);
1289 }
1290
1292
1293 /* Restore any global improvement effects that this city confers */
1294 city_built_iterate(pcity, pimprove) {
1296 _("Transfer of %s"));
1298
1299 /* Set production to something valid for pplayer, if not.
1300 * (previously allowed building obsolete units.) */
1301 if (!can_city_build_now(nmap, pcity, &pcity->production)) {
1303 }
1304
1305 /* What wasn't obsolete for the old owner may be so now. */
1307
1309
1310 if (new_extras) {
1311 const char *clink = city_link(pcity);
1312
1314 _("The people in %s are stunned by your "
1315 "technological insight!"),
1316 clink);
1317
1318 if (upgradet != NULL) {
1320 _("Workers spontaneously gather and upgrade "
1321 "%s with %s."),
1323 } else {
1325 _("Workers spontaneously gather and upgrade "
1326 "%s infrastructure."),
1327 clink);
1328 }
1330 }
1331
1332 /* Build a new palace for free if the player lost their capital and
1333 savepalace is on. */
1335
1336 /* Refresh the city's vision range, since it might be different
1337 * under the new owner. */
1338 city_refresh_vision(pcity);
1339
1340 /* Update the national borders, within the current vision and culture.
1341 * This could leave a border ring around the city, updated later by
1342 * map_calculate_borders() at the next turn.
1343 */
1345 /* city_thaw_workers_queue() later */
1346
1347 auto_arrange_workers(pcity); /* does city_map_update_all() */
1348 city_thaw_workers(pcity);
1349 city_thaw_workers_queue(); /* after old city has a chance to work! */
1351 /* no sanity check here as the city is not refreshed! */
1352 }
1353
1354 if (city_remains) {
1355 /* Send city with updated owner information to giver and to everyone
1356 * having shared vision pact with them before they may
1357 * lose vision to it. When we later send info to everybody seeing the city,
1358 * they may not be included. */
1359 send_city_info(NULL, pcity);
1360 }
1361
1362 /* Remove the sight points from the giver. */
1363 vision_clear_sight(old_vision);
1364 vision_free(old_vision);
1365
1366 /* Send wonder infos. */
1367 if (had_great_wonders) {
1369 if (city_remains) {
1371
1372 /* Refresh all cities of the taker to account for possible changes due
1373 * to player wide effects. */
1374 city_list_iterate(ptaker->cities, acity) {
1377 } else {
1378 /* Refresh all cities to account for possible global effects. */
1382 }
1383 }
1385 /* No need to send to detached connections. */
1387
1388 /* Refresh all cities of the giver to account for possible changes due
1389 * to player wide effects. */
1390 city_list_iterate(pgiver->cities, acity) {
1393 }
1394
1395 /* Refresh all cities in the queue. */
1397 /* After the refresh the sanity check can be done. */
1398 sanity_check_city(pcity);
1399
1400 if (city_remains) {
1401 /* Send information about conquered city to all players. */
1402 send_city_info(NULL, pcity);
1403 }
1404
1405 /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to
1406 * refresh all cities for the player. */
1410 }
1414 }
1415
1416 if (pgiver->primary_capital_id == saved_id) {
1418 }
1419
1420 sync_cities();
1421
1422 CALL_FUNC_EACH_AI(city_info, pcity);
1423
1424 return city_remains;
1425}
1426
1427/************************************************************************/
1435{
1436 struct player *pplayer;
1437 struct nation_type *nation;
1438 int i;
1440 bool first_city;
1441
1442 fc_assert_ret(NULL != pcity);
1443 pplayer = city_owner(pcity);
1444 fc_assert_ret(NULL != pplayer);
1445 nation = nation_of_player(pplayer);
1446 fc_assert_ret(NULL != nation);
1447
1448 /* If this isn't the first city a player has ever had, they only get
1449 * any initial buildings with the SaveSmallWonder flag, and then only
1450 * if savepalace is enabled. */
1452
1455
1456 /* Global free buildings. */
1457 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1459 struct impr_type *pimprove;
1460
1461 if (n == B_LAST) {
1462 break;
1463 }
1464
1465 pimprove = improvement_by_number(n);
1466 fc_assert_action(!is_great_wonder(pimprove), continue);
1467 if (first_city
1471 /* TRANS: Reason that a building was added to the city.
1472 * Building is given for free to player's first city. */
1473 Q_("?initbldg:Free %s"));
1474 if (is_small_wonder(pimprove)) {
1476 }
1477 }
1478 }
1479
1480 /* Nation specific free buildings. */
1481 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1482 Impr_type_id n = nation->init_buildings[i];
1483 struct impr_type *pimprove;
1484
1485 if (n == B_LAST) {
1486 break;
1487 }
1488
1489 pimprove = improvement_by_number(n);
1490 if (first_city
1494 /* TRANS: Reason that a building was added to the city.
1495 * Building is given for free to player's first city. */
1496 Q_("?initbldg:Free %s"));
1497 if (is_small_wonder(pimprove)) {
1499 } else if (is_great_wonder(pimprove)) {
1501 }
1502 }
1503 }
1504
1505 /* Update wonder infos. */
1506 if (has_great_wonders) {
1508 /* No need to send to detached connections. */
1509 send_player_info_c(pplayer, NULL);
1510 } else if (has_small_wonders) {
1511 /* No need to send to detached connections. */
1512 send_player_info_c(pplayer, NULL);
1513 }
1514}
1515
1516/************************************************************************/
1519void create_city(struct player *pplayer, struct tile *ptile,
1520 const char *name, struct player *nationality)
1521{
1522 struct player *saved_owner = tile_owner(ptile);
1523 struct tile *saved_claimer = tile_claimer(ptile);
1524 struct city *pwork = tile_worked(ptile);
1525 struct city *pcity;
1528 const struct civ_map *nmap = &(wld.map);
1529
1530 log_debug("create_city() %s", name);
1531
1532 pcity = create_city_virtual(pplayer, ptile, name);
1533
1534 /* Remove units no more seen. Do it before city is really put into the
1535 * game. */
1536 players_iterate(other_player) {
1537 if (can_player_see_units_in_city(other_player, pcity)
1538 || !map_is_known_and_seen(ptile, other_player, V_MAIN)) {
1539 continue;
1540 }
1541 unit_list_iterate(ptile->units, punit) {
1542 if (can_player_see_unit(other_player, punit)) {
1543 unit_goes_out_of_sight(other_player, punit);
1544 }
1547
1548 adv_city_alloc(pcity);
1549
1550 tile_set_owner(ptile, pplayer, ptile); /* Temporarily */
1552 pcity->id = identity_number();
1553
1555 idex_register_city(&wld, pcity);
1557
1558 if (city_list_size(pplayer->cities) == 0) {
1559 /* Free initial buildings, or at least a palace if they were
1560 * previously careless enough to lose all their cities */
1562 BV_SET(pplayer->flags, PLRF_FIRST_CITY);
1563 }
1564
1565 /* Set up citizens nationality. */
1566 citizens_init(pcity);
1567
1568 /* Place a worker at the is_city_center() is_free_worked().
1569 * It is possible to build a city on a tile that is already worked;
1570 * this will displace the worker on the newly-built city's tile -- Syela */
1571 tile_set_worked(ptile, pcity); /* instead of city_map_update_worker() */
1572
1573 if (NULL != pwork) {
1574 /* was previously worked by another city */
1575 /* Turn citizen into specialist. */
1576 pwork->specialists[DEFAULT_SPECIALIST]++;
1577 /* One less citizen. Citizen sanity will be handled later in
1578 * city_thaw_workers_queue() */
1579 pwork->server.synced = FALSE;
1581 }
1582
1583 /* Update citizens. */
1584 citizens_update(pcity, nationality);
1585
1586 /* Restore the old-owner information so removal
1587 * of territory claiming bases can work relative to it. */
1589
1590 /* Destroy any extras that don't belong in the city. */
1591 extra_type_iterate(pextra) {
1592 if (tile_has_extra(ptile, pextra)
1593 && !is_native_tile_to_extra(pextra, ptile)) {
1594 destroy_extra(ptile, pextra);
1595 }
1597
1598 /* Build any extras that the city should have. */
1599 upgrade_city_extras(pcity, NULL);
1600
1601 /* Claim the ground we stand on */
1602 map_claim_ownership(ptile, pplayer, ptile, TRUE);
1603
1604 /* Before arranging workers to show unknown land */
1605 pcity->server.vision = vision_new(pplayer, ptile);
1607 city_refresh_vision(pcity);
1608 city_list_prepend(pplayer->cities, pcity);
1609
1610 /* This is dependent on the current vision, so must be done after
1611 * vision is prepared and before arranging workers. */
1612 map_claim_border(ptile, pplayer, -1);
1613 /* city_thaw_workers_queue() later */
1614
1615 /* Refresh the city. First a city refresh is done (this shouldn't
1616 * send any packets to the client because the city has no supported units)
1617 * then rearrange the workers. Note that auto_arrange_workers does its
1618 * own refresh call; it is safest to do our own controlled city_refresh
1619 * first. */
1620 city_refresh(pcity);
1621 auto_arrange_workers(pcity);
1622 city_thaw_workers_queue(); /* after new city has a chance to work! */
1624
1625 /* Bases destroyed earlier may have had watchtower effect. Refresh
1626 * unit vision. */
1628
1629 update_tile_knowledge(ptile);
1630
1633 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1634 * cities for the player. */
1635 city_refresh_for_player(pplayer);
1636 }
1637
1638 pcity->server.synced = FALSE;
1639 send_city_info(NULL, pcity);
1640 sync_cities(); /* Will also send pwork. */
1641
1642 notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server,
1643 _("You have founded %s."),
1644 city_link(pcity));
1645 maybe_make_contact(ptile, city_owner(pcity));
1646
1647 unit_list_iterate((ptile)->units, punit) {
1649
1650 /* Catch fortress building, transforming into ocean, etc. */
1653 }
1654
1655 /* Update happiness (the unit may no longer cause unrest). */
1656 if (home) {
1657 if (city_refresh(home)) {
1658 /* Shouldn't happen, but better be safe than sorry. */
1660 }
1663 }
1665
1666 sanity_check_city(pcity);
1667
1668 script_server_signal_emit("city_built", pcity);
1669
1670 CALL_FUNC_EACH_AI(city_created, pcity);
1671 CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
1672}
1673
1674/************************************************************************/
1680bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1681 const char *name)
1682{
1683 const struct civ_map *nmap = &(wld.map);
1684
1685 if (is_enemy_unit_tile(ptile, pplayer)
1686 || !city_can_be_built_here(nmap, ptile, NULL, FALSE)) {
1687 return FALSE;
1688 }
1689
1690 if (!pplayer->is_alive) {
1691 pplayer->is_alive = TRUE;
1692 send_player_info_c(pplayer, NULL);
1693 }
1694
1695 if (name == NULL || name[0] == '\0') {
1696 name = city_name_suggestion(pplayer, ptile);
1697 }
1698
1699 map_show_tile(pplayer, ptile);
1700 create_city(pplayer, ptile, name, pplayer);
1701
1702 return TRUE;
1703}
1704
1705/************************************************************************/
1708void remove_city(struct city *pcity)
1709{
1710 struct player *powner = city_owner(pcity);
1711 struct tile *pcenter = city_tile(pcity);
1713 struct vision *old_vision;
1714 int id = pcity->id; /* We need this even after memory has been freed */
1715 bool had_great_wonders = FALSE;
1718 struct dbv tile_processed;
1719 struct tile_list *process_queue;
1720 const char *ctl = city_tile_link(pcity);
1721 const struct civ_map *nmap = &(wld.map);
1722
1723 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1724 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1725
1727 city_built_iterate(pcity, pimprove) {
1728 building_removed(pcity, pimprove, "city_destroyed", NULL);
1729
1730 if (is_small_wonder(pimprove)) {
1732 } else if (is_great_wonder(pimprove)) {
1734 }
1736
1737 /* Rehome units in other cities */
1740
1741 if (new_home_city
1742 && new_home_city != pcity
1743 && city_owner(new_home_city) == powner
1744 && !punit->server.dying) {
1746 }
1748
1749 /* Make sure ships are not left on land when city is removed. */
1751 bool moved;
1752 const struct unit_type *punittype = unit_type_get(punit);
1753
1754 /* can_exist_at_tile() would give wrong results, as
1755 * the city is still on map. */
1758 || is_safe_ocean(nmap, pcenter))) {
1759 continue;
1760 }
1761
1763 moved = FALSE;
1765 struct unit *ptrans;
1766
1769 /* Move */
1771 /* It may be impossible to survive at the tile even if it is
1772 * native. See UTYF_COAST_STRICT */
1774 } else {
1775 ptrans = NULL;
1776 }
1780 NULL) != NULL) {
1781 moved = TRUE;
1782 }
1783 if (moved) {
1786 _("Moved %s out of disbanded city %s "
1787 "since it cannot stay on %s."),
1790 break;
1791 }
1792 }
1793 }
1795 if (!moved) {
1798 _("When %s was disbanded your %s could not "
1799 "get out, and it was therefore lost."),
1800 ctl,
1803 }
1805
1809 struct tile *ptile = tile_list_front(process_queue);
1810
1813 adjc_iterate(nmap, ptile, piter) {
1814 struct city *other_city;
1815
1817 continue;
1818 }
1820 if (other_city != NULL) {
1821 /* Adjacent tile has a city that may have been part of same channel */
1826
1832 _("When %s was disbanded your %s in %s was trapped, "
1833 "and it was therefore lost."),
1834 ctl,
1838 }
1840 } else {
1842 }
1844 }
1845
1848
1849 if (!city_exist(id)) {
1850 /* Wiping trapped units caused city to disappear. */
1851 return;
1852 }
1853
1854 /* Any remaining supported units are destroyed */
1858
1859 if (!city_exist(id)) {
1860 /* Wiping supported units caused city to disappear. */
1861 return;
1862 }
1863
1865 struct trade_route *pback = remove_trade_route(pcity, proute,
1866 TRUE, TRUE);
1867
1868 FC_FREE(proute);
1869 FC_FREE(pback);
1871
1876
1877 /* idex_unregister_city() is called in game_remove_city() below */
1878
1879 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1880 still be alive in the client, or in the player map. The number of
1881 removed cities is small, so the loss is acceptable.
1882 */
1883
1884 old_vision = pcity->server.vision;
1885 pcity->server.vision = NULL;
1887 adv_city_free(pcity);
1888
1889 /* Remove city from the map. */
1891
1892 /* Reveal units. */
1893 players_iterate(other_player) {
1894 if (can_player_see_units_in_city(other_player, pcity)
1895 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1896 continue;
1897 }
1899 if (can_player_see_unit(other_player, punit)) {
1900 send_unit_info(other_player->connections, punit);
1901 }
1904
1906 game_remove_city(&wld, pcity);
1908
1909 /* Remove any extras that were only there because the city was there. */
1910 extra_type_iterate(pextra) {
1911 if (tile_has_extra(pcenter, pextra)
1912 && !is_native_tile_to_extra(pextra, pcenter)) {
1914 }
1916
1917 players_iterate(other_player) {
1918 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1919 reality_check_city(other_player, pcenter);
1920 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1921 map_show_tile(other_player, pcenter);
1922 }
1924
1926 if (NULL == pconn->playing && pconn->observer) {
1927 /* For detached observers we have to send a specific packet. This is
1928 * a hack necessitated by the private map that exists for players but
1929 * not observers. */
1931 }
1933
1934 if (old_vision != NULL) {
1935 vision_clear_sight(old_vision);
1936 vision_free(old_vision);
1937 }
1938
1939 /* Infrastructures may have changed. */
1941
1942 /* Build a new palace for free if the player lost their capital and
1943 savepalace is on. */
1945
1946 /* Update wonder infos. */
1947 if (had_great_wonders) {
1949 /* No need to send to detached connections. */
1950 send_player_info_c(powner, NULL);
1951 } else if (BV_ISSET_ANY(had_small_wonders)) {
1952 /* No need to send to detached connections. */
1953 send_player_info_c(powner, NULL);
1954 }
1955
1958 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1959 * cities for the player. */
1961 }
1962
1963 sync_cities();
1964
1965 /* At least sentried helicopters need to go idle, maybe others.
1966 * In alien ruleset, city center might have provided water source
1967 * for adjacent tile. */
1969}
1970
1971/************************************************************************/
1987bool unit_conquer_city(struct unit *punit, struct city *pcity)
1988{
1989 bool try_civil_war = FALSE;
1990 bool city_remains;
1991 int coins;
1992 struct player *pplayer = unit_owner(punit);
1993 struct player *cplayer = city_owner(pcity);
1994#ifndef FREECIV_NDEBUG
1995 const struct unit_type *utype = unit_type_get(punit);
1996#endif
1997
1998 /* If not at war, may peacefully enter city. */
2000 "Can't conquer city during peace.");
2001
2002 /* If we cannot occupy the city, this unit entering will not trigger the
2003 * effects below. */
2007 FALSE, "Bad unit for city occupation.");
2008
2009 /* A transported unit trying to conquer a city should already have been
2010 * unloaded. */
2012 "Can't conquer city while transported.");
2013
2014 /* Okay, we're at war - invader captures/destroys city... */
2015
2016 /* If a capital is captured, then spark off a civil war
2017 - Kris Bubendorfer
2018 Also check spaceships --dwp
2019 */
2020
2021 if (is_capital(pcity)
2022 && (cplayer->spaceship.state == SSHIP_STARTED
2023 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
2025 }
2026
2027 if (is_capital(pcity)
2032 }
2033
2034 /*
2035 * We later remove a citizen. Lets check if we can save this since
2036 * the city will be destroyed.
2037 */
2038 if (city_size_get(pcity) <= 1) {
2039 int saved_id = pcity->id;
2040
2042 _("You destroy %s completely."),
2043 city_tile_link(pcity));
2045 _("%s has been destroyed by %s."),
2046 city_tile_link(pcity), player_name(pplayer));
2047 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2048
2049 /* We cant't be sure of city existence after running some script */
2050 if (city_exist(saved_id)) {
2051 remove_city(pcity);
2052 }
2053
2054 if (try_civil_war) {
2056 }
2057 return TRUE;
2058 }
2059
2061 coins = MIN(coins,
2062 fc_rand((coins / 20) + 1)
2063 + (coins * (city_size_get(pcity))) / 200);
2064 pplayer->economic.gold += coins;
2065 cplayer->economic.gold -= coins;
2066 send_player_info_c(pplayer, pplayer->connections);
2067 send_player_info_c(cplayer, cplayer->connections);
2068 if (pcity->original != pplayer) {
2069 if (coins > 0) {
2071 PL_("You conquer %s; your lootings accumulate"
2072 " to %d gold!",
2073 "You conquer %s; your lootings accumulate"
2074 " to %d gold!", coins),
2075 city_link(pcity),
2076 coins);
2078 PL_("%s conquered %s and looted %d gold"
2079 " from the city.",
2080 "%s conquered %s and looted %d gold"
2081 " from the city.", coins),
2082 player_name(pplayer),
2083 city_link(pcity),
2084 coins);
2085 } else {
2087 _("You conquer %s."),
2088 city_link(pcity));
2090 _("%s conquered %s."),
2091 player_name(pplayer),
2092 city_link(pcity));
2093 }
2094 } else {
2095 if (coins > 0) {
2097 PL_("You have liberated %s!"
2098 " Lootings accumulate to %d gold.",
2099 "You have liberated %s!"
2100 " Lootings accumulate to %d gold.", coins),
2101 city_link(pcity),
2102 coins);
2104 PL_("%s liberated %s and looted %d gold"
2105 " from the city.",
2106 "%s liberated %s and looted %d gold"
2107 " from the city.", coins),
2108 player_name(pplayer),
2109 city_link(pcity),
2110 coins);
2111 } else {
2113 _("You have liberated %s!"),
2114 city_link(pcity));
2116 _("%s liberated %s."),
2117 player_name(pplayer),
2118 city_link(pcity));
2119 }
2120 }
2121
2123 /* Just try to steal. Ignore failures to get tech */
2124 steal_a_tech(pplayer, cplayer, A_UNSET);
2125 }
2126
2127 /* We transfer the city first so that it is in a consistent state when
2128 * the size is reduced. */
2129 /* FIXME: maybe it should be a ruleset option whether barbarians get
2130 * free buildings such as palaces? */
2131 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2132 !is_barbarian(pplayer));
2133
2134 if (city_remains) {
2135 /* reduce size should not destroy this city */
2136 fc_assert(city_size_get(pcity) > 1);
2137 city_reduce_size(pcity, 1, pplayer, "conquest");
2138 }
2139
2140 if (try_civil_war) {
2142 }
2143
2144 if (city_remains) {
2145 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2146 "conquest");
2147 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2148 }
2149
2150 return TRUE;
2151}
2152
2153/************************************************************************/
2156static int city_citywalls_gfx(const struct city *pcity)
2157{
2158 int walls = get_city_bonus(pcity, EFT_VISIBLE_WALLS);
2159
2160 return walls > 0 ? walls : 0;
2161}
2162
2163/************************************************************************/
2167{
2169
2171 return formerly;
2172}
2173
2174/************************************************************************/
2177static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2178 struct packet_city_short_info *packet)
2179{
2180 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2181
2182 packet->id = pdcity->identity;
2184
2185 if (pdcity->original != NULL) {
2186 packet->original = player_number(pdcity->original);
2187 } else {
2189 }
2190
2191 packet->tile = tile_index(ptile);
2192 if (pdcity->name == NULL) {
2193 packet->name[0] = '\0';
2194 } else {
2195 sz_strlcpy(packet->name, pdcity->name);
2196 }
2197
2198 packet->size = vision_site_size_get(pdcity);
2199
2200 packet->occupied = pdcity->occupied;
2201 packet->walls = pdcity->walls;
2202 packet->style = pdcity->style;
2203 packet->city_image = pdcity->city_image;
2204 packet->capital = pdcity->capital;
2205
2206 packet->happy = pdcity->happy;
2207 packet->unhappy = pdcity->unhappy;
2208
2209 packet->improvements = pdcity->improvements;
2210}
2211
2212/************************************************************************/
2216void refresh_dumb_city(struct city *pcity)
2217{
2218 players_iterate(pplayer) {
2219 if (player_can_see_city_externals(pplayer, pcity)) {
2220 if (update_dumb_city(pplayer, pcity)) {
2221 struct packet_city_short_info packet;
2222
2223 if (city_owner(pcity) != pplayer) {
2224 /* Don't send the short_city information to someone who can see the
2225 * city's internals. Doing so would really confuse the client. */
2226 package_dumb_city(pplayer, pcity->tile, &packet);
2227 lsend_packet_city_short_info(pplayer->connections, &packet);
2228 }
2229 }
2230 }
2232
2233 /* Don't send to non-player observers since they don't have 'dumb city'
2234 * information. */
2235}
2236
2237/************************************************************************/
2245void broadcast_city_info(struct city *pcity)
2246{
2247 struct packet_city_info packet;
2252 struct player *powner = city_owner(pcity);
2253 struct trade_route_packet_list *routes;
2255
2256 /* Send to everyone who can see the city. */
2257
2258 if (pcity->server.needs_arrange != CNA_NOT) {
2259 /* Send city only when it's in sane state.
2260 * If it's not, it will be sent to everyone once
2261 * rearrangement has been finished. */
2263
2264 return;
2265 }
2266
2267 if (any_web_conns()) {
2269 } else {
2270 webp_ptr = NULL;
2271 }
2272
2273 routes = trade_route_packet_list_new();
2274 package_city(pcity, &packet, &nat_packet, &rally_packet,
2275 webp_ptr, routes, FALSE);
2276
2277 players_iterate(pplayer) {
2278 if (!send_city_suppressed || pplayer != powner) {
2279 if (can_player_see_city_internals(pplayer, pcity)) {
2280 update_dumb_city(pplayer, pcity);
2281 packet.original = city_original_owner(pcity, pplayer);
2282 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2283 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2284 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2285 web_lsend_packet(city_info_addition, pplayer->connections,
2286 webp_ptr, FALSE);
2288 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2290 } else if (player_can_see_city_externals(pplayer, pcity)) {
2291 reality_check_city(pplayer, pcity->tile);
2292 update_dumb_city(pplayer, pcity);
2293 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2294 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2295 }
2296 }
2298
2299 /* Send to global observers. */
2300 packet.original = city_original_owner(pcity, NULL);
2307 }
2309
2314}
2315
2316/************************************************************************/
2321{
2322 conn_list_do_buffer(dest);
2323 conn_list_iterate(dest, pconn) {
2324 struct player *pplayer = pconn->playing;
2325
2326 if (!pplayer && !pconn->observer) {
2327 continue;
2328 }
2329 whole_map_iterate(&(wld.map), ptile) {
2330 if (!pplayer || NULL != map_get_player_site(ptile, pplayer)) {
2331 send_city_info_at_tile(pplayer, pconn->self, NULL, ptile);
2332 }
2334 }
2337 flush_packets();
2338}
2339
2340/************************************************************************/
2343void send_player_cities(struct player *pplayer)
2344{
2345 city_list_iterate(pplayer->cities, pcity) {
2346 if (city_refresh(pcity)) {
2347 log_error("%s radius changed while sending to player.",
2348 city_name_get(pcity));
2349
2350 /* Make sure that no workers in illegal position outside radius. */
2351 auto_arrange_workers(pcity);
2352 }
2353 send_city_info(pplayer, pcity);
2354 }
2356}
2357
2358/************************************************************************/
2363void send_city_info(struct player *dest, struct city *pcity)
2364{
2365 struct player *powner = city_owner(pcity);
2366
2367 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2368 return;
2369 }
2370
2371 if (dest == powner && send_city_suppressed) {
2372 return;
2373 }
2374
2375 if (!dest || dest == powner) {
2376 pcity->server.synced = TRUE;
2377 }
2378
2379 if (!dest) {
2380 broadcast_city_info(pcity);
2381 } else {
2382 send_city_info_at_tile(dest, dest->connections, pcity, pcity->tile);
2383 }
2384
2385 /* Sending counters */
2386 city_counters_refresh(pcity);
2387
2389 && player_list_size(team_members(powner->team)) > 1) {
2390 /* We want to send the new total bulbs production of the team. */
2392 }
2393}
2394
2395/************************************************************************/
2416 struct city *pcity, struct tile *ptile)
2417{
2418 struct packet_city_info packet;
2423 struct player *powner = NULL;
2424 struct trade_route_packet_list *routes = NULL;
2426
2427 if (!pcity) {
2428 pcity = tile_city(ptile);
2429 }
2430 if (pcity != NULL && pcity->server.needs_arrange != CNA_NOT) {
2432
2433 return;
2434 }
2435 if (pcity) {
2436 powner = city_owner(pcity);
2437 }
2438
2439 if (any_web_conns()) {
2441 } else {
2442 webp_ptr = NULL;
2443 }
2444
2445 if (powner != NULL && powner == pviewer) {
2446 /* Send info to owner */
2447 /* This case implies powner non-NULL which means pcity non-NULL */
2448 if (!send_city_suppressed) {
2449 /* Wait that city has been rearranged, if it's currently
2450 * not in sane state. */
2451
2452 routes = trade_route_packet_list_new();
2453
2454 /* Send all info to the owner */
2455 update_dumb_city(powner, pcity);
2456 package_city(pcity, &packet, &nat_packet, &rally_packet,
2457 webp_ptr, routes, FALSE);
2458 packet.original = city_original_owner(pcity, pviewer);
2459 lsend_packet_city_info(dest, &packet, FALSE);
2466 if (dest == powner->connections) {
2467 /* HACK: send also a copy to global observers. */
2468 packet.original = city_original_owner(pcity, NULL);
2475 }
2477 }
2478 }
2479 } else {
2480 /* send info to non-owner */
2481 if (!pviewer) { /* observer */
2482 if (pcity) {
2483 routes = trade_route_packet_list_new();
2484
2485 /* Should be dumb_city info? */
2486 package_city(pcity, &packet, &nat_packet, &rally_packet,
2487 webp_ptr, routes, FALSE);
2488 lsend_packet_city_info(dest, &packet, FALSE);
2495 }
2496 } else {
2497 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2498 if (pcity) { /* it's there and we see it; update and send */
2499 update_dumb_city(pviewer, pcity);
2502 }
2503 } else { /* not seen; send old info */
2504 if (map_is_known(ptile, pviewer)
2505 && map_get_player_site(ptile, pviewer) != NULL) {
2508 }
2509 }
2510 }
2511 }
2512
2513 if (routes != NULL) {
2518 }
2519}
2520
2521/************************************************************************/
2526void package_city(struct city *pcity, struct packet_city_info *packet,
2530 struct trade_route_packet_list *routes,
2531 bool dipl_invest)
2532{
2533 int i;
2534 int ppl = 0;
2535
2537
2538 packet->id = pcity->id;
2539 packet->owner = player_number(city_owner(pcity));
2540
2541 packet->tile = tile_index(city_tile(pcity));
2542 sz_strlcpy(packet->name, city_name_get(pcity));
2543
2544 packet->size = city_size_get(pcity);
2545 for (i = 0; i < FEELING_LAST; i++) {
2546 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2547 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2548 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2549 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2550 if (i == 0) {
2551 ppl += packet->ppl_happy[i];
2552 ppl += packet->ppl_content[i];
2553 ppl += packet->ppl_unhappy[i];
2554 ppl += packet->ppl_angry[i];
2555 }
2556 }
2557 /* The number of data in specialists[] array */
2560 packet->specialists[sp] = pcity->specialists[sp];
2561 ppl += packet->specialists[sp];
2563
2564 /* The nationality of the citizens. */
2565 nat_packet->id = pcity->id;
2566 nat_packet->nationalities_count = 0;
2568 int cit = 0;
2569
2570 player_slots_iterate(pslot) {
2571 citizens nationality = citizens_nation_get(pcity, pslot);
2572 if (nationality != 0) {
2573 /* This player should exist! */
2575
2576 nat_packet->nation_id[nat_packet->nationalities_count]
2577 = player_slot_index(pslot);
2578 nat_packet->nation_citizens[nat_packet->nationalities_count]
2579 = nationality;
2580 nat_packet->nationalities_count++;
2581
2582 cit += nationality;
2583 }
2585
2586 fc_assert(cit == packet->size);
2587 }
2588
2589 packet->history = pcity->history;
2590 packet->culture = city_culture(pcity);
2591 packet->buy_cost = city_production_buy_gold_cost(pcity);
2592
2593 if (packet->size != ppl) {
2594 static bool recursion = FALSE;
2595
2596 if (recursion) {
2597 /* Recursion didn't help. Do not enter infinite recursive loop.
2598 * Package city as it is. */
2599 log_error("Failed to fix inconsistent city size.");
2600 recursion = FALSE;
2601 } else {
2602 /* Note: If you get this error and try to debug the cause, you may find
2603 * using check_city_feelings() in some key points useful. */
2604 /* Have this as an fc_assert() first, so one can use '-F' to caught these in
2605 * debugger. */
2606 fc_assert(packet->size == ppl);
2607
2608 /* In all builds have an error message shown. */
2609 log_error("City size %d, citizen count %d for %s",
2610 packet->size, ppl, city_name_get(pcity));
2611
2612 /* Try to fix */
2613 city_refresh(pcity);
2614 auto_arrange_workers(pcity);
2615
2616 /* And repackage */
2617 recursion = TRUE;
2618 package_city(pcity, packet, nat_packet, rally_packet,
2619 web_packet, routes, dipl_invest);
2620 recursion = FALSE;
2621
2622 return;
2623 }
2624 }
2625
2626 packet->city_radius_sq = pcity->city_radius_sq;
2627
2628 i = 0;
2631
2632 tri_packet->city = pcity->id;
2633 tri_packet->index = i;
2634 tri_packet->partner = proute->partner;
2635 tri_packet->value = proute->value;
2636 tri_packet->direction = proute->dir;
2637 tri_packet->goods = goods_number(proute->goods);
2638
2640
2641 i++;
2643
2644 packet->trade_route_count = i;
2645
2647 packet->surplus[o] = pcity->surplus[o];
2648 packet->waste[o] = pcity->waste[o];
2649 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2650 packet->prod[o] = pcity->prod[o];
2651 packet->citizen_base[o] = pcity->citizen_base[o];
2652 packet->usage[o] = pcity->usage[o];
2654
2655 packet->food_stock = pcity->food_stock;
2656 packet->shield_stock = pcity->shield_stock;
2657 packet->pollution = pcity->pollution;
2658 packet->illness_trade = pcity->illness_trade;
2659 packet->city_options = pcity->city_options;
2660 packet->wl_cb = pcity->wlcb;
2661
2662 if (!dipl_invest) {
2663 packet->acquire_type = pcity->acquire_t;
2664 } else {
2665 /* Dummy value */
2666 packet->acquire_type = CACQ_CONQUEST;
2667 }
2668
2669 packet->production_kind = pcity->production.kind;
2670 packet->production_value = universal_number(&pcity->production);
2671
2672 packet->turn_last_built = pcity->turn_last_built;
2673 packet->turn_founded = pcity->turn_founded;
2674
2675 packet->changed_from_kind = pcity->changed_from.kind;
2677
2679 packet->disbanded_shields = pcity->disbanded_shields;
2680 packet->caravan_shields = pcity->caravan_shields;
2682
2683 worklist_copy(&packet->worklist, &pcity->worklist);
2685
2686 packet->airlift = pcity->airlift;
2687 packet->did_buy = pcity->did_buy;
2688 packet->did_sell = pcity->did_sell;
2689 packet->was_happy = pcity->was_happy;
2690 packet->had_famine = pcity->had_famine;
2691
2692 packet->walls = city_citywalls_gfx(pcity);
2693 packet->style = pcity->style;
2694 packet->city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2695 packet->capital = pcity->capital;
2696 packet->steal = pcity->steal;
2697
2698 rally_packet->id = pcity->id;
2699 rally_packet->length = pcity->rally_point.length;
2700 rally_packet->persistent = pcity->rally_point.persistent;
2701 rally_packet->vigilant = pcity->rally_point.vigilant;
2702 if (pcity->rally_point.length) {
2703 memcpy(rally_packet->orders, pcity->rally_point.orders,
2704 pcity->rally_point.length * sizeof(struct unit_order));
2705 }
2706
2707 BV_CLR_ALL(packet->improvements);
2708 improvement_iterate(pimprove) {
2709 if (city_has_building(pcity, pimprove)) {
2710 BV_SET(packet->improvements, improvement_index(pimprove));
2711 }
2713
2714#ifdef FREECIV_WEB
2715 if (web_packet != NULL) {
2716 struct tile *pcenter = city_tile(pcity);
2717 const struct civ_map *nmap = &(wld.map);
2718
2719 BV_CLR_ALL(web_packet->can_build_unit);
2720 BV_CLR_ALL(web_packet->can_build_improvement);
2721
2722 web_packet->id = pcity->id;
2723
2724 if (pcity->cm_parameter != NULL) {
2725 web_packet->cma_enabled = TRUE;
2726 cm_copy_parameter(&web_packet->cm_parameter, pcity->cm_parameter);
2727 } else {
2728 web_packet->cma_enabled = FALSE;
2729 memset(&web_packet->cm_parameter, 0, sizeof(web_packet->cm_parameter));
2730 }
2731
2732 web_packet->granary_size = city_granary_size(city_size_get(pcity));
2733 web_packet->granary_turns = city_turns_to_grow(pcity);
2734
2735 improvement_iterate(pimprove) {
2736 if (can_city_build_improvement_now(pcity, pimprove)) {
2737 BV_SET(web_packet->can_build_improvement, improvement_index(pimprove));
2738 }
2740
2742 if (can_city_build_unit_now(nmap, pcity, punittype)) {
2743 BV_SET(web_packet->can_build_unit, utype_index(punittype));
2744 }
2746
2747 i = 0;
2749 web_packet->output_food[i] = city_tile_output_now(pcity, ptile, O_FOOD);
2750 web_packet->output_shield[i] = city_tile_output_now(pcity, ptile, O_SHIELD);
2751 web_packet->output_trade[i] = city_tile_output_now(pcity, ptile, O_TRADE);
2752
2753 i++;
2755 }
2756#endif /* FREECIV_WEB */
2757}
2758
2759/************************************************************************/
2769bool update_dumb_city(struct player *pplayer, struct city *pcity)
2770{
2771 bv_imprs improvements;
2772 struct tile *pcenter = city_tile(pcity);
2773 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2774 /* pcity->client.occupied isn't used at the server, so we go straight to the
2775 * unit list to check the occupied status. */
2776 bool occupied = (unit_list_size(pcenter->units) > 0);
2777 int walls = city_citywalls_gfx(pcity);
2778 bool happy = city_happy(pcity);
2779 bool unhappy = city_unhappy(pcity);
2780 int style = pcity->style;
2782 enum capital_type capital = pcity->capital;
2783
2784 /* Only someone knowing the tile should ever know a city on it. */
2785 fc_assert(map_is_known(pcenter, pplayer));
2786
2788 improvement_iterate(pimprove) {
2789 if (is_improvement_visible(pimprove)
2790 && city_has_building(pcity, pimprove)) {
2792 }
2794
2795 if (NULL == pdcity) {
2796 pdcity = vision_site_new_from_city(pcity, pplayer);
2798 } else if (pdcity->location != pcenter) {
2799 log_error("Trying to update bad city (wrong location) "
2800 "at %i,%i for player %s",
2801 TILE_XY(pcity->tile), player_name(pplayer));
2802 fc_assert(pdcity->location == pcenter);
2803 pdcity->location = pcenter; /* ?? */
2804 } else if (pdcity->identity != pcity->id) {
2805 log_error("Trying to update old city (wrong identity) "
2806 "at %i,%i for player %s",
2807 TILE_XY(city_tile(pcity)), player_name(pplayer));
2808 fc_assert(pdcity->identity == pcity->id);
2809 pdcity->identity = pcity->id; /* ?? */
2810 } else if (pdcity->occupied == occupied
2811 && pdcity->walls == walls
2812 && pdcity->happy == happy
2813 && pdcity->unhappy == unhappy
2814 && pdcity->style == style
2815 && pdcity->city_image == city_image
2816 && pdcity->capital == capital
2817 && BV_ARE_EQUAL(pdcity->improvements, improvements)
2819 && vision_site_owner(pdcity) == city_owner(pcity)
2820 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2821 return FALSE;
2822 }
2823
2824 vision_site_update_from_city(pdcity, pcity, pplayer);
2825 pdcity->occupied = occupied;
2826 pdcity->walls = walls;
2827 pdcity->style = style;
2828 pdcity->city_image = city_image;
2829 pdcity->capital = capital;
2830 pdcity->happy = happy;
2831 pdcity->unhappy = unhappy;
2832 pdcity->improvements = improvements;
2833
2834 return TRUE;
2835}
2836
2837/************************************************************************/
2840void reality_check_city(struct player *pplayer, struct tile *ptile)
2841{
2842 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2843
2844 if (pdcity) {
2845 struct city *pcity = tile_city(ptile);
2846
2847 if (!pcity || pcity->id != pdcity->identity) {
2848 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2849
2850 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2851 fc_assert_ret(playtile->site == pdcity);
2852 playtile->site = NULL;
2854 }
2855 }
2856}
2857
2858/************************************************************************/
2861void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2862{
2863 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2864
2865 if (pdcity) {
2866 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2867
2868 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2869 fc_assert_ret(playtile->site == pdcity);
2870 playtile->site = NULL;
2872 }
2873}
2874
2875/************************************************************************/
2879static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2880 bool source_gone)
2881{
2882 struct player *plr1 = city_owner(pc1);
2883 struct player *plr2 = city_owner(pc2);
2886
2889
2890 if (plr1 == plr2) {
2891 if (source_gone) {
2894 _("Trade between %s and %s lost along with city."),
2896 } else {
2899 _("Trade route between %s and %s canceled."),
2901 }
2902 } else {
2903 if (source_gone) {
2906 /* TRANS: "...between Spanish city Madrid and Paris..." */
2907 _("Trade between %s city %s and %s lost along with "
2908 "their city."),
2910 /* It's implicit to removed city's owner that that city no longer
2911 * has trade routes, so say nothing in that case */
2912 } else {
2915 _("Sorry, the %s canceled the trade route "
2916 "from %s to your city %s."),
2920 /* TRANS: "...from Paris to Spanish city Madrid." */
2921 _("We canceled the trade route "
2922 "from %s to %s city %s."),
2924 }
2925 }
2926}
2927
2928/************************************************************************/
2937 bool announce, bool source_gone)
2938{
2939 struct city *pc2 = game_city_by_number(proute->partner);
2940 struct trade_route *back_route = NULL;
2941
2943
2945
2946 if (pc2 != NULL) {
2948 if (pc1->id == pback->partner) {
2949 back_route = pback;
2950 }
2952
2953 if (back_route != NULL) {
2955 }
2956
2957 if (announce) {
2959
2962 }
2963 }
2964
2965 return back_route;
2966}
2967
2968/**********************************************************************/
2971bool city_illness_strike(struct city *pcity)
2972{
2974 ftc_server,
2975 _("%s has been struck by a plague! Population lost!"),
2976 city_link(pcity));
2977 if (city_reduce_size(pcity, 1, NULL, "plague")) {
2978 pcity->turn_plague = game.info.turn;
2979
2980 /* recalculate illness */
2981 pcity->server.illness
2982 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade),
2983 NULL);
2984
2985 return TRUE;
2986 }
2987
2988 return FALSE;
2989}
2990
2991/************************************************************************/
2997void do_sell_building(struct player *pplayer, struct city *pcity,
2998 struct impr_type *pimprove, const char *reason)
2999{
3000 if (can_city_sell_building(pcity, pimprove)) {
3001 pplayer->economic.gold += impr_sell_gold(pimprove);
3002 building_lost(pcity, pimprove, reason, NULL);
3003 }
3004}
3005
3006/************************************************************************/
3018struct city
3019*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
3020 struct player **oldcity_owner)
3021{
3022 struct city *oldcity = NULL;
3023
3024 fc_assert_ret_val(!city_has_building(pcity, pimprove), NULL);
3025 if (is_great_wonder(pimprove)) {
3026 if (!(oldcity = city_from_great_wonder(pimprove))) {
3027 oldcity = pcity;
3028 }
3030 } else if (is_small_wonder(pimprove)) {
3031 if (!(oldcity
3032 = city_from_small_wonder(city_owner(pcity), pimprove))) {
3033 oldcity = pcity;
3034 }
3035 }
3036 if (oldcity && oldcity != pcity) {
3039 _("Moving %s"));
3040 } else {
3042 _("Acquiring %s"));
3043 }
3044
3045 return oldcity;
3046}
3047
3048/************************************************************************/
3051bool building_removed(struct city *pcity, const struct impr_type *pimprove,
3052 const char *reason, struct unit *destroyer)
3053{
3054 int backup = pcity->id;
3055
3056 city_remove_improvement(pcity, pimprove);
3057
3058 script_server_signal_emit("building_lost", pcity, pimprove, reason,
3059 destroyer);
3060
3061 return city_exist(backup);
3062}
3063
3064/************************************************************************/
3068void building_lost(struct city *pcity, const struct impr_type *pimprove,
3069 const char *reason, struct unit *destroyer)
3070{
3071 struct player *owner = city_owner(pcity);
3072 bool was_capital = is_capital(pcity);
3073 bool city_remains;
3074
3075 city_remains = building_removed(pcity, pimprove, reason, destroyer);
3076
3077 if ((was_capital && (!city_remains || !is_capital(pcity)))
3078 && (owner->spaceship.state == SSHIP_STARTED
3079 || owner->spaceship.state == SSHIP_LAUNCHED)) {
3080 /* If the capital was lost (by destruction of the palace) production on
3081 * the spaceship is lost. */
3083 }
3084
3085 if (city_remains) {
3086 /* update city; influence of effects (buildings, ...) on unit upkeep */
3087 if (city_refresh(pcity)) {
3088 auto_arrange_workers(pcity);
3089 }
3090
3091 /* Re-update the city's visible area. This updates fog if the vision
3092 * range increases or decreases. */
3093 city_refresh_vision(pcity);
3094 }
3095}
3096
3097/************************************************************************/
3106{
3107 const struct unit_type *ut = unit_type_get(punit);
3108 struct player *plr = unit_owner(punit);
3109 bool update = FALSE;
3110 int cost;
3111
3113 cost = utype_upkeep_cost(ut, plr, o);
3114 if (cost > 0) {
3115 if (free_uk[o] > cost) {
3116 free_uk[o] -= cost;
3117 cost = 0;
3118 } else {
3119 cost -= free_uk[o];
3120 free_uk[o] = 0;
3121 }
3122 }
3123
3124 if (cost != punit->upkeep[o]) {
3125 update = TRUE;
3126 punit->upkeep[o] = cost;
3127 }
3129
3130 if (update) {
3131 /* Update unit information to the player and global observers. */
3133 }
3134}
3135
3136/************************************************************************/
3156void city_units_upkeep(const struct city *pcity)
3157{
3158 int free_uk[O_LAST];
3159
3160 if (!pcity || !pcity->units_supported
3161 || unit_list_size(pcity->units_supported) < 1) {
3162 return;
3163 }
3164
3169
3170 /* Save the upkeep for all units in the corresponding punit struct */
3174}
3175
3176/************************************************************************/
3179void change_build_target(struct player *pplayer, struct city *pcity,
3180 struct universal *target,
3181 enum event_type event)
3182{
3183 const char *name;
3184 const char *source;
3185
3186 /* If the city is already building this thing, don't do anything */
3187 if (are_universals_equal(&pcity->production, target)) {
3188 return;
3189 }
3190
3191 /* Is the city no longer building a wonder? */
3192 if (VUT_IMPROVEMENT == pcity->production.kind
3194 && event != E_IMP_AUTO
3195 && event != E_WORKLIST) {
3196 /* If the build target is changed because of an advisor's suggestion or
3197 because the worklist advances, then the wonder was completed --
3198 don't announce that the player has *stopped* building that wonder.
3199 */
3201 _("The %s have stopped building The %s in %s."),
3202 nation_plural_for_player(pplayer),
3204 city_link(pcity));
3205 }
3206
3207 /* Manage the city change-production penalty.
3208 (May penalize, restore or do nothing to the shield_stock.) */
3209 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3210 pcity->shield_stock = city_change_production_penalty(pcity, target);
3211 }
3212
3213 /* Change build target. */
3214 pcity->production = *target;
3215
3216 /* What's the name of the target? */
3218
3219 switch (event) {
3220 case E_WORKLIST:
3221 /* TRANS: Possible 'source' of the production change
3222 * (in "<city> is building ..." sentence). Preserve leading space. */
3223 source = _(" from the worklist");
3224 break;
3225 case E_IMP_AUTO:
3226 /* TRANS: Possible 'source' of the production change
3227 * (in "<city> is building ..." sentence). Preserve leading space. */
3228 source = _(" as suggested by the advisor");
3229 break;
3230 default:
3231 source = "";
3232 break;
3233 }
3234
3235 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3236 city_name_get(pcity), name, source);
3237
3238 /* Tell the player what's up. */
3239 /* FIXME: this may give bad grammar when translated if the 'source'
3240 * string can have multiple values. */
3241 notify_player(pplayer, city_tile(pcity), event, ftc_server,
3242 /* TRANS: "<city> is building <production><source>."
3243 * 'source' might be an empty string, or a clause like
3244 * " from the worklist". */
3245 _("%s is building %s%s."),
3246 city_link(pcity),
3247 name, source);
3248
3249 /* If the city is building a wonder, tell the rest of the world
3250 about it. */
3251 if (VUT_IMPROVEMENT == pcity->production.kind
3254 _("The %s have started building The %s in %s."),
3255 nation_plural_for_player(pplayer),
3256 name,
3257 city_link(pcity));
3258 }
3259}
3260
3261/************************************************************************/
3268void city_map_update_empty(struct city *pcity, struct tile *ptile)
3269{
3270 tile_set_worked(ptile, NULL);
3271 send_tile_info(NULL, ptile, FALSE);
3272 pcity->server.synced = FALSE;
3273}
3274
3275/************************************************************************/
3282void city_map_update_worker(struct city *pcity, struct tile *ptile)
3283{
3284 tile_set_worked(ptile, pcity);
3285 send_tile_info(NULL, ptile, FALSE);
3286 pcity->server.synced = FALSE;
3287}
3288
3289/************************************************************************/
3294static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3295{
3296 struct city *pwork = tile_worked(ptile);
3297
3298 if (NULL != pwork
3299 && !is_free_worked(pwork, ptile)
3300 && !city_can_work_tile(pwork, ptile)) {
3301 tile_set_worked(ptile, NULL);
3302 send_tile_info(NULL, ptile, FALSE);
3303
3304 pwork->specialists[DEFAULT_SPECIALIST]++; /* keep city sanity */
3305 pwork->server.synced = FALSE;
3306
3307 if (queued) {
3308 city_freeze_workers_queue(pwork); /* place the displaced later */
3309 } else {
3310 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3313 }
3314 return TRUE;
3315 }
3316
3317 return FALSE;
3318}
3319
3320/************************************************************************/
3326{
3327 return city_map_update_tile_direct(ptile, TRUE);
3328}
3329
3330/************************************************************************/
3334{
3335 return city_map_update_tile_direct(ptile, FALSE);
3336}
3337
3338/************************************************************************/
3342void sync_cities(void)
3343{
3345 return;
3346 }
3347
3348 players_iterate(pplayer) {
3349 city_list_iterate(pplayer->cities, pcity) {
3350 if (!pcity->server.synced) {
3351 /* sending will set to TRUE. */
3352 send_city_info(pplayer, pcity);
3353 }
3356}
3357
3358/************************************************************************/
3361void city_map_update_all(struct city *pcity)
3362{
3363 struct tile *pcenter = city_tile(pcity);
3364 const struct civ_map *nmap = &(wld.map);
3365
3367 ptile, _index, _x, _y) {
3368 /* bypass city_map_update_tile_now() for efficiency */
3371}
3372
3373/************************************************************************/
3377{
3378 city_list_iterate(pplayer->cities, pcity) {
3379 city_freeze_workers(pcity);
3380 city_map_update_all(pcity);
3381 city_thaw_workers(pcity);
3383}
3384
3385/************************************************************************/
3396{
3397 adjc_iterate(&(wld.map), ptile, tile1) {
3398 struct city *pcity = tile_city(tile1);
3399
3400 if (pcity) {
3401 struct player *pplayer = city_owner(pcity);
3402 const struct req_context city_ctxt = {
3403 .player = pplayer,
3404 .city = pcity,
3405 .tile = pcity->tile,
3406 };
3407
3408 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3409 city_built_iterate(pcity, pimprove) {
3410 if (!can_city_sell_building(pcity, pimprove)) {
3411 continue;
3412 }
3413
3414 requirement_vector_iterate(&pimprove->reqs, preq) {
3415 if ((VUT_TERRAIN == preq->source.kind
3416 || VUT_TERRAINCLASS == preq->source.kind
3417 || VUT_TERRFLAG == preq->source.kind)
3419 int price = impr_sell_gold(pimprove);
3420
3421 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3423 PL_("You sell %s in %s (now landlocked)"
3424 " for %d gold.",
3425 "You sell %s in %s (now landlocked)"
3426 " for %d gold.", price),
3428 city_link(pcity), price);
3429 }
3432 }
3434}
3435
3436/************************************************************************/
3442void city_refresh_vision(struct city *pcity)
3443{
3444 if (pcity->server.vision != NULL) {
3445 v_radius_t vision_radius_sq
3447
3448 vision_change_sight(pcity->server.vision, vision_radius_sq);
3449 ASSERT_VISION(pcity->server.vision);
3450 }
3451}
3452
3453/************************************************************************/
3458{
3459 city_list_iterate(pplayer->cities, pcity) {
3460 city_refresh_vision(pcity);
3462}
3463
3464/************************************************************************/
3468{
3469 fc_assert_ret_val(pcity != NULL, FALSE);
3470
3475 const struct civ_map *nmap = &(wld.map);
3476
3477 /* Check minimum / maximum allowed city radii */
3480
3482 /* No change */
3483 return FALSE;
3484 }
3485
3486 /* Get number of city tiles for each radii */
3489
3491 /* A change of the squared city radius but no change of the number of
3492 * city tiles */
3493 return FALSE;;
3494 }
3495
3496 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3498
3499 /* Workers map before */
3500 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3501 city_name_get(pcity), pcity->id, city_size_get(pcity),
3502 city_specialists(pcity));
3504
3506
3508 /* Increased number of city tiles */
3509 city_refresh_vision(pcity);
3510 } else {
3511 /* Reduced number of city tiles */
3512 int workers = 0;
3513
3514 /* Remove workers from the tiles removed rom the city map */
3516 city_x, city_y) {
3517 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3519 city_y);
3520
3521 if (ptile && pcity == tile_worked(ptile)) {
3522 city_map_update_empty(pcity, ptile);
3523 workers++;
3524 }
3526
3527 /* add workers to free city tiles */
3528 if (workers > 0) {
3529 int radius_sq = city_map_radius_sq_get(pcity);
3530
3532 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3533 city_x, city_y);
3534
3535 if (ptile && !is_free_worked(pcity, ptile)
3536 && tile_worked(ptile) != pcity
3537 && city_can_work_tile(pcity, ptile)) {
3538 city_map_update_worker(pcity, ptile);
3539 workers--;
3540 }
3541
3542 if (workers <= 0) {
3543 break;
3544 }
3546 }
3547
3548 /* If there are still workers they will be updated to specialists */
3549 if (workers > 0) {
3550 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3551 }
3552
3553 city_refresh_vision(pcity);
3554 }
3555
3556 /* City removal might be ongoing, and advisor data already deleted */
3557 if (pcity->server.adv != NULL) {
3558 /* If city is under AI control, update it */
3559 adv_city_update(pcity);
3560 }
3561
3563 ftc_server, _("The size of the city map of %s is %s."),
3564 city_name_get(pcity),
3565 city_tiles_old < city_tiles_new ? _("increased")
3566 : _("reduced"));
3567
3568 /* Workers map after */
3569 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3570 city_name_get(pcity), pcity->id, city_size_get(pcity),
3571 city_specialists(pcity));
3573
3574 return TRUE;
3575}
3576
3577/************************************************************************/
3580void clear_worker_task(struct city *pcity, struct worker_task *ptask)
3581{
3582 struct packet_worker_task packet;
3583
3584 if (ptask == NULL) {
3585 return;
3586 }
3587
3589
3590 packet.city_id = pcity->id;
3591 packet.tile_id = tile_index(ptask->ptile);
3592 packet.activity = ACTIVITY_LAST;
3593 packet.tgt = 0;
3594 packet.want = 0;
3595
3596 free(ptask);
3597
3600}
3601
3602/************************************************************************/
3605void clear_worker_tasks(struct city *pcity)
3606{
3607 while (worker_task_list_size(pcity->task_reqs) > 0) {
3609 }
3610}
3611
3612/************************************************************************/
3616{
3617 struct packet_worker_task packet;
3618
3619 packet.city_id = pcity->id;
3620
3622 packet.tile_id = tile_index(ptask->ptile);
3623 packet.activity = ptask->act;
3624 if (ptask->tgt == NULL) {
3625 packet.tgt = -1;
3626 } else {
3627 packet.tgt = extra_number(ptask->tgt);
3628 }
3629 packet.want = ptask->want;
3630
3634}
3635
3636/************************************************************************/
3639int city_production_buy_gold_cost(const struct city *pcity)
3640{
3641 int build = pcity->shield_stock;
3642
3643 switch (pcity->production.kind) {
3644 case VUT_IMPROVEMENT:
3645 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3646 build);
3647 case VUT_UTYPE:
3648 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3649 build);
3650 default:
3651 break;
3652 };
3653
3654 return FC_INFINITY;
3655}
3656
3657/************************************************************************/
3662 const struct impr_type *pimprove,
3663 const char *format)
3664{
3665 if (is_wonder(pimprove)) {
3666 /* Only wonders may grant governments */
3667 struct cur_govs_data *govs_data;
3668 char buf[250];
3669
3671 city_add_improvement(pcity, pimprove);
3672
3673 fc_snprintf(buf, sizeof(buf), format, improvement_name_translation(pimprove));
3674
3675 players_iterate_alive(pplayer) {
3678
3680 } else {
3681 city_add_improvement(pcity, pimprove);
3682 }
3683}
3684
3685/************************************************************************/
3689int city_original_owner(const struct city *pcity,
3690 const struct player *known_for)
3691{
3692 if (pcity->original == NULL) {
3693 /* Nobody knows */
3694 return MAX_NUM_PLAYER_SLOTS;
3695 }
3696
3697 if (pcity->original != known_for
3698 || known_for == NULL) {
3699 /* Players know what they have built themselves,
3700 * global observer knows everything. */
3701 return player_number(pcity->original);
3702 }
3703
3704 return MAX_NUM_PLAYER_SLOTS;
3705}
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:387
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
#define n
Definition astring.c:77
bool is_land_barbarian(struct player *pplayer)
Definition barbarian.c:75
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:144
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:113
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_ISSET_ANY(vec)
Definition bitvector.h:109
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
void citizens_init(struct city *pcity)
Definition citizens.c:32
void citizens_convert_conquest(struct city *pcity)
void citizens_update(struct city *pcity, struct player *plr)
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3601
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:148
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:737
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1145
int city_granary_size(int city_size)
Definition city.c:2132
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2196
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1087
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:305
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1240
bool is_capital(const struct city *pcity)
Definition city.c:1579
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3371
struct output_type * get_output_type(Output_type_id output)
Definition city.c:638
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2186
bool city_unhappy(const struct city *pcity)
Definition city.c:1626
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3430
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1679
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2870
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1886
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1487
bool city_happy(const struct city *pcity)
Definition city.c:1614
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3357
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1384
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:446
citizens city_specialists(const struct city *pcity)
Definition city.c:3317
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1695
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1013
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:947
int city_map_tiles(int city_radius_sq)
Definition city.c:171
bool city_exist(int id)
Definition city.c:3572
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1996
void city_rally_point_clear(struct city *pcity)
Definition city.c:3626
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:700
#define cities_iterate_end
Definition city.h:517
@ CNA_BROADCAST_PENDING
Definition city.h:308
@ CNA_NOT
Definition city.h:306
@ CNA_NORMAL
Definition city.h:307
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
#define cities_iterate(pcity)
Definition city.h:512
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:214
@ CITIZEN_ANGRY
Definition city.h:271
@ CITIZEN_HAPPY
Definition city.h:268
@ CITIZEN_CONTENT
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:270
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:84
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
Definition city.h:188
#define output_type_iterate(output)
Definition city.h:845
#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:834
#define city_map_iterate_without_index_end
Definition city.h:184
#define city_built_iterate_end
Definition city.h:840
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:180
#define output_type_iterate_end
Definition city.h:851
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3268
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:2526
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3333
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:458
static int city_citywalls_gfx(const struct city *pcity)
Definition citytools.c:2156
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3294
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3615
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3639
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2363
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2769
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:3019
static void raze_city(struct city *pcity)
Definition citytools.c:928
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1434
static bool city_workers_queue_remove(struct city *pcity)
Definition citytools.c:185
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:856
void refresh_dumb_city(struct city *pcity)
Definition citytools.c:2216
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2177
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1519
bool send_city_suppression(bool now)
Definition citytools.c:2166
static bool send_city_suppressed
Definition citytools.c:102
void sync_cities(void)
Definition citytools.c:3342
static const char * search_for_city_name(struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
Definition citytools.c:339
static void announce_trade_route_removal(struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
Definition citytools.c:2879
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:3105
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3457
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3689
static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders)
Definition citytools.c:1018
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3467
int build_points_left(struct city *pcity)
Definition citytools.c:576
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3179
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3051
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3376
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2971
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3325
void city_thaw_workers(struct city *pcity)
Definition citytools.c:147
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2861
static bool is_default_city_name(const char *name, struct player *pplayer)
Definition citytools.c:321
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3068
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1987
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3580
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:961
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3156
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3605
bool is_allowed_city_name(struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
Definition citytools.c:374
static void transfer_unit(struct unit *punit, struct city *tocity, bool rehome, bool verbose)
Definition citytools.c:590
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
Definition citytools.c:3395
void remove_city(struct city *pcity)
Definition citytools.c:1708
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:2997
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:2936
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1680
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2415
static int evaluate_city_name_priority(struct tile *ptile, const struct nation_city *pncity, int default_priority)
Definition citytools.c:220
void city_thaw_workers_queue(void)
Definition citytools.c:198
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2245
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:1076
void city_add_improvement_with_gov_notice(struct city *pcity, const struct impr_type *pimprove, const char *format)
Definition citytools.c:3661
void send_player_cities(struct player *pplayer)
Definition citytools.c:2343
void city_map_update_all(struct city *pcity)
Definition citytools.c:3361
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:721
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Definition citytools.c:3282
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2840
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2320
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3442
#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:367
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:198
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3544
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4583
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:763
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:183
void city_refresh_queue_processing(void)
Definition cityturn.c:214
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:236
enum announce_type announce
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2174
char * incite_cost
Definition comments.c:75
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:388
int Impr_type_id
Definition fc_types.h:376
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
@ RPT_CERTAIN
Definition fc_types.h:701
#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:372
#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:319
@ 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:226
static GtkWidget * source
Definition gotodlg.c:58
GType type
Definition repodlgs.c:1313
static const int bufsz
Definition helpdlg.c:70
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_PRODCHGPEN
Definition handicaps.h:35
void idex_register_city(struct world *iworld, struct city *pcity)
Definition idex.c:67
struct impr_type * improvement_by_number(const Impr_type_id id)
int impr_sell_gold(const struct impr_type *pimprove)
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
bool is_improvement_visible(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
struct city * city_from_great_wonder(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
void adv_city_free(struct city *pcity)
Definition infracache.c: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
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Definition map.c:667
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:2533
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2207
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:2621
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:1367
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:2724
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1159
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2286
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1439
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:241
void map_clear_border(struct tile *ptile)
Definition maphand.c:2237
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1382
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2521
#define map_get_player_site(_ptile_, _pplayer_)
Definition maphand.h:93
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:290
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:291
#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:3204
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2955
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2361
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3005
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2908
void update_capital(struct player *pplayer)
Definition plrhand.c:731
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
#define allowed_nations_iterate_end
Definition plrhand.h:73
#define fc_rand(_size)
Definition rand.h:56
bool is_req_active(const struct req_context *context, const struct 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
enum city_wl_cancel_behavior wlcb
Definition city.h:404
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
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:131
struct civ_game::@31::@35::@39 mutexes
bool vision_reveal_tiles
Definition game.h:204
struct conn_list * glob_observers
Definition game.h:98
fc_mutex city_list
Definition game.h:274
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:171
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:111
bool savepalace
Definition game.h:191
struct civ_game::@31::@35 server
struct civ_game::@30 rgame
int razechance
Definition game.h:180
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]
enum city_acquire_type acquire_type
int ppl_unhappy[FEELING_LAST]
int citizen_base[O_LAST]
enum city_wl_cancel_behavior wl_cb
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:902
universals_u value
Definition fc_types.h:901
bool happy
Definition vision.h:120
bv_imprs improvements
Definition vision.h:126
int walls
Definition vision.h:119
int style
Definition vision.h:122
bool unhappy
Definition vision.h:121
int city_image
Definition vision.h:123
bool occupied
Definition vision.h:118
enum capital_type capital
Definition vision.h:124
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:195
#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:1538
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1234
void notify_new_government_options(struct player *pplayer, struct cur_govs_data *data, const char *reason)
Definition techtools.c:1552
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:1518
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:721
const struct impr_type * building
Definition fc_types.h:714
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1922
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:841
#define unit_tile(_pu)
Definition unit.h:397
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:420
#define unit_owner(_pu)
Definition unit.h:396
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6471
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:4016
#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:1394
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2709
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2722
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:796
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2131
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4857
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1221
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:855
#define unit_type_iterate_end
Definition unittype.h:862
struct vision_site * vision_site_new_from_city(const struct city *pcity, const struct player *watcher)
Definition vision.c:102
citizens vision_site_size_get(const struct vision_site *psite)
Definition vision.c:170
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_site_update_from_city(struct vision_site *psite, const struct city *pcity, const struct player *watcher)
Definition vision.c:123
void vision_free(struct vision *vision)
Definition vision.c:50
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:129
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