Freeciv-3.3
Loading...
Searching...
No Matches
citytools.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22/* utility */
23#include "bitvector.h"
24#include "fcintl.h"
25#include "log.h"
26#include "mem.h"
27#include "rand.h"
28#include "shared.h"
29#include "support.h"
30
31/* common */
32#include "ai.h"
33#include "base.h"
34#include "citizens.h"
35#include "city.h"
36#include "counters.h"
37#include "culture.h"
38#include "events.h"
39#include "game.h"
40#include "government.h"
41#include "improvement.h"
42#include "idex.h"
43#include "map.h"
44#include "movement.h"
45#include "packets.h"
46#include "player.h"
47#include "requirements.h"
48#include "research.h"
49#include "road.h"
50#include "specialist.h"
51#include "tech.h"
52#include "traderoutes.h"
53#include "unit.h"
54#include "unitlist.h"
55#include "vision.h"
56
57/* common/aicore */
58#include "cm.h"
59
60/* common/scriptcore */
61#include "luascript_types.h"
62
63/* server */
64#include "actiontools.h"
65#include "barbarian.h"
66#include "citizenshand.h"
67#include "cityturn.h"
68#include "gamehand.h" /* send_game_info() */
69#include "maphand.h"
70#include "notify.h"
71#include "plrhand.h"
72#include "sanitycheck.h"
73#include "sernet.h"
74#include "spacerace.h"
75#include "srv_main.h"
76#include "techtools.h"
77#include "unithand.h"
78#include "unittools.h"
79
80/* server/advisors */
81#include "advbuilding.h"
82#include "advgoto.h"
83#include "infracache.h"
84
85/* server/scripting */
86#include "script_server.h"
87
88/* ai */
89#include "handicaps.h"
90
91/* ai */
92#include "handicaps.h"
93
94#include "citytools.h"
95
96
97/* Queue for pending auto_arrange_workers() */
98static struct city_list *arrange_workers_queue = nullptr;
99
100/* Suppress sending cities during game_load() and end_phase() */
102
103static bool city_workers_queue_remove(struct city *pcity);
104
105static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
106 bool source_gone)
107 fc__attribute((nonnull (1, 2)));
108
109/************************************************************************/
137{
138 pcity->server.workers_frozen++;
139}
140
141/************************************************************************/
147{
148 pcity->server.workers_frozen--;
149 fc_assert(pcity->server.workers_frozen >= 0);
150 if (pcity->server.workers_frozen == 0
151 && pcity->server.needs_arrange != CNA_NOT) {
152 city_refresh(pcity); /* Citizen count sanity */
154 }
155}
156
157/************************************************************************/
161{
162 if (arrange_workers_queue == nullptr) {
165 /* City might have been arranged since it was originally put to the queue.
166 * Make sure needs_arrange is set again. */
167 if (pcity->server.needs_arrange == CNA_NOT) {
168 pcity->server.needs_arrange = CNA_NORMAL;
169 }
170 return;
171 }
172
175 if (pcity->server.needs_arrange == CNA_NOT) {
176 pcity->server.needs_arrange = CNA_NORMAL;
177 }
178}
179
180/************************************************************************/
185{
186 if (arrange_workers_queue == nullptr) {
187 return FALSE;
188 }
189
191}
192
193/************************************************************************/
210
211/************************************************************************/
219static int evaluate_city_name_priority(struct tile *ptile,
220 const struct nation_city *pncity,
222{
223 /* Lower values mean higher priority. */
226
227 /* Increasing this value will increase the difference caused by
228 (non-)matching terrain. A matching terrain is mult_factor
229 "better" than an unlisted terrain, which is mult_factor
230 "better" than a non-matching terrain. */
231 const float mult_factor = 1.4;
232 bool river = FALSE;
233
234 /*
235 * If natural city names aren't being used, we just return
236 * the base value. This will have the effect of the first-listed
237 * city being used. We do this here rather than special-casing
238 * it elsewhere because this localizes everything to this
239 * function, even though it's a bit inefficient.
240 */
242 return default_priority;
243 }
244
245 /*
246 * Assuming we're using the natural city naming system, we use
247 * an internal alorithm to calculate the priority of each name.
248 * It's a pretty fuzzy algorithm; we basically do the following:
249 * - Change the priority scale from 0..n to 10..n+10. This means
250 * each successive city is 10% lower priority than the first.
251 * - Multiply by a semi-random number. This has the effect of
252 * decreasing rounding errors in the successive calculations,
253 * as well as introducing a smallish random effect.
254 * - Check over all the applicable terrains, and
255 * multiply or divide the priority based on whether or not
256 * the terrain matches. See comment below.
257 */
258
259 priority += 10.0;
260 priority *= 10.0 + fc_rand(5);
261
262 /*
263 * The terrain priority in the struct nation_city will be either
264 * -1, 0, or 1. We therefore take this as-is if the terrain is
265 * present, or negate it if not.
266 *
267 * The reason we multiply as well as divide the value is so
268 * that cities that don't care what terrain they are on (which
269 * is the default) will be left in the middle of the pack.
270 * If we _only_ multiplied (or divided), then cities that had more
271 * terrain labels would have their priorities hurt (or helped).
272 */
275 if (tile_has_extra(ptile, priver)
277 river = TRUE;
278 break;
279 }
281 if (!river) {
283 }
284
285 switch (goodness) {
286 case NCP_DISLIKE:
288 break;
289 case NCP_NONE:
290 break;
291 case NCP_LIKE:
293 break;
294 }
295
296 terrain_type_iterate(pterrain) {
297 /* Now we do the same for every available terrain. */
299 if (!is_terrain_near_tile(&(wld.map), ptile, pterrain, TRUE)) {
301 }
302 switch (goodness) {
303 case NCP_DISLIKE:
305 break;
306 case NCP_NONE:
307 break;
308 case NCP_LIKE:
310 }
312
313 return (int) priority;
314}
315
316/************************************************************************/
320static bool is_default_city_name(const char *name, struct player *pplayer)
321{
323 pncity) {
325 return TRUE;
326 }
328 return FALSE;
329}
330
331/************************************************************************/
338static const char *search_for_city_name(struct tile *ptile,
339 const struct nation_city_list *
340 default_cities,
341 struct player *pplayer)
342{
343 int choice = 0, priority, best_priority = -1;
344 const char *name;
345 const char *best_name = nullptr;
346
347 nation_city_list_iterate(default_cities, pncity) {
349 if (game_city_by_name(name) == nullptr
350 && is_allowed_city_name(pplayer, name, nullptr, 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. */
392 && game_city_by_name(cityname)) {
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 = nullptr;
412
414 if (player2 != pplayer && is_default_city_name(cityname, player2)) {
415 pother = player2;
416 break;
417 }
419
420 if (pother != nullptr) {
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
435 * the original nation are exhausted and the backup nations have
436 * non-ascii names in them. */
437 if (!is_ascii_name(cityname)
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 (name != nullptr) {
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 (name != nullptr) {
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);
562 if (game_city_by_name(tempname) == nullptr) {
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/************************************************************************/
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
645 wipe_unit(punit, ULR_CITY_LOST, nullptr);
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 }
693 wipe_unit(punit, ULR_CITY_LOST, nullptr);
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 }
820 wipe_unit(vunit, ULR_CITY_LOST, nullptr);
821 }
823
824#ifdef FREECIV_DEBUG
825 unit_list_iterate(pcity->units_supported, punit) {
826 if (punit->server.dying) {
827 /* Leave the dying alone. */
828 continue;
829 }
830
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 = nullptr;
865 int best_dist = -1;
866
867 fc_assert_ret_val(ptile != nullptr, nullptr);
868
869 if (pplayer != nullptr && only_player && only_enemy) {
870 log_error("Non of my own cities will be at war with me!");
871 return nullptr;
872 }
873
874 con = tile_continent(ptile);
875
877 if (pplayer != nullptr && only_player && pplayer != aplayer) {
878 /* Only cities of player 'pplayer' */
879 continue;
880 }
881
882 if (pplayer != nullptr && only_enemy
883 && !pplayers_at_war(pplayer, aplayer)) {
884 /* Only cities of players at war with player 'pplayer' */
885 continue;
886 }
887
889 int city_dist;
890
891 if (pexclcity && pexclcity == pcity) {
892 /* not this city */
893 continue;
894 }
895
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)
908 && (!only_known
909 || (map_is_known(city_tile(pcity), pplayer)
910 && map_get_player_site(city_tile(pcity), pplayer)->identity
912 && (pclass == nullptr
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 */
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
944 * of nullptr as destroyer */
945 city_remains = building_removed(pcity, pimprove, "razed", nullptr);
946 if (!city_remains) {
947 break;
948 }
949 }
951
952 if (city_remains) {
954 pcity->shield_stock = 0;
955 }
956}
957
958/************************************************************************/
963{
965 bool keep_route;
966 struct trade_route *back;
967 struct city *partner = game_city_by_number(proute->partner);
968
969 /* Remove the city's trade routes (old owner).
970 * Do not announce removal as we might restore the route immediately below */
972
974 && can_establish_trade_route(pcity, partner, proute->goods->replace_priority);
975
976 if (!keep_route) {
979
980 if (settings->cancelling != TRI_CANCEL) {
982 }
983 }
984
985 /* Readd the city's trade route (new owner) */
986 if (keep_route) {
989 } else {
990 free(proute);
991 free(back);
992
993 /* Now announce the trade route removal */
995 }
996
997 /* Refresh regardless; either it lost a trade route or the trade
998 * route revenue changed. */
999 city_refresh(partner);
1000 send_city_info(city_owner(partner), partner);
1001
1002 /* Give the new owner infos about the city which has a trade route
1003 * with the transferred city. */
1005 struct player *owner = city_owner(pcity);
1006
1007 map_show_tile(owner, partner->tile);
1008 update_dumb_city(owner, partner);
1009 send_city_info(owner, partner);
1010 }
1012}
1013
1014/************************************************************************/
1019static void build_free_small_wonders(struct player *pplayer,
1021{
1022 int size = city_list_size(pplayer->cities);
1023
1024 if (!game.server.savepalace) {
1025 /* Nothing to do */
1026 return;
1027 }
1028
1029 if (size == 0) {
1030 /* The last city was removed or transferred to the enemy.
1031 * If the victim survives to found or acquire another city, they'll
1032 * get any savepalace initial buildings then. */
1033 return;
1034 }
1035
1036 improvement_iterate(pimprove) {
1039 /* FIXME: instead, find central city */
1040 struct city *pnew_city = city_list_get(pplayer->cities, fc_rand(size));
1041
1042 fc_assert_action(city_from_small_wonder(pplayer, pimprove) == nullptr,
1043 continue);
1044
1046
1047 /*
1048 * send_player_cities() will recalculate all cities and send them to
1049 * the client.
1050 */
1051 send_player_cities(pplayer);
1052
1054 /* FIXME: should already be notified about city loss? */
1055 /* TRANS: <building> ... <city> */
1056 _("A replacement %s was built in %s."),
1059 /*
1060 * The enemies want to see the new capital in their intelligence
1061 * report.
1062 */
1063 send_city_info(nullptr, pnew_city);
1064 }
1066}
1067
1068/************************************************************************/
1077bool transfer_city(struct player *ptaker, struct city *pcity,
1079 bool resolve_stack, bool raze, bool build_free)
1080{
1082 struct vision *old_vision, *new_vision;
1083 struct unit_list *old_city_units = unit_list_new();
1084 struct player *pgiver = city_owner(pcity);
1085 struct tile *pcenter = city_tile(pcity);
1086 int saved_id = pcity->id;
1087 bool city_remains = TRUE;
1088 bool had_great_wonders = FALSE;
1093 bool taker_had_no_cities = (city_list_size(ptaker->cities) == 0);
1094 bool new_extras;
1095 int units_num = 0;
1096 const int ul_size = unit_list_size(pcenter->units);
1097 int central_units[ul_size + 1];
1098 bv_player *could_see_unit = nullptr;
1099 int i;
1100 const struct civ_map *nmap = &(wld.map);
1101
1103
1107
1108 if (units_num > 0) {
1110
1111 /* Remember what player see what unit. */
1112 for (i = 0; i < units_num; i++) {
1114
1119 }
1121 }
1122
1123 fc_assert(i == units_num);
1124 }
1125
1126 /* Remove AI control of the old owner. */
1127 CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity);
1128
1129 /* Forget old tasks */
1131
1132 /* Forget old rally point */
1134
1135 /* Activate AI control of the new owner. */
1136 CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
1137
1139
1140 unit_list_iterate(pcity->units_supported, punit) {
1142 /* Mark unit to have no homecity at all.
1143 * 1. We remove unit from units_supported list here,
1144 * real_change_unit_homecity() should not attempt it.
1145 * 2. Otherwise we might delete the homecity from under the unit
1146 * in the client */
1147 punit->homecity = 0;
1148 send_unit_info(nullptr, punit);
1150 unit_list_clear(pcity->units_supported);
1151
1152 /* Remove all global improvement effects that this city confers (but
1153 then restore the local improvement list - we need this to restore
1154 the global effects for the new city owner) */
1156 city_built_iterate(pcity, pimprove) {
1157 if (is_small_wonder(pimprove)) {
1158 /* Small wonders are really removed (not restored later). */
1159 building_removed(pcity, pimprove, "conquered", nullptr);
1161 } else {
1162 city_remove_improvement(pcity, pimprove);
1163 if (is_great_wonder(pimprove)) {
1165 }
1166 /* Note: internal turn here, next city_built_iterate(). */
1167 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
1168 }
1170
1172 old_vision = pcity->server.vision;
1177
1179
1183
1186 _("You already had a city called %s."
1187 " The city was renamed to %s."),
1189 city_link(pcity));
1190
1192 }
1193
1194 /* Has to follow the unfog call above. */
1195 city_list_remove(pgiver->cities, pcity);
1197 /* city_thaw_workers_queue() later */
1198
1199 pcity->owner = ptaker;
1200 pcity->capital = CAPITAL_NOT;
1201 pcity->acquire_t = CACQ_CONQUEST;
1203 city_list_prepend(ptaker->cities, pcity);
1204
1205 if (could_see_unit != nullptr) {
1206 /* Hide/reveal units. Do it after vision have been given to taker, city
1207 * owner has been changed, and before any script could be spawned. */
1208 for (i = 0; i < units_num; i++) {
1210
1214 && !aunit->server.dying) {
1215 /* Reveal 'aunit'. */
1216 send_unit_info(aplayer->connections, aunit);
1217 }
1218 } else {
1220 /* Hide 'aunit'. */
1222 }
1223 }
1225 }
1226
1227 fc_assert(i == units_num);
1228
1230 could_see_unit = nullptr;
1231 }
1232
1234 pcity, nullptr,
1236 /* The units themselves are already freed by transfer_city_units(). */
1238
1239 if (resolve_stack) {
1241 }
1242
1243 if (!city_exist(saved_id)) {
1245 }
1246
1247 /* Reset turns owner counters */
1248 if (city_remains) {
1250 if (pcount->type == CB_CITY_OWNED_TURNS) {
1251 pcity->counter_values[pcount->index] = 0;
1252 }
1254 }
1255
1256 if (city_remains) {
1257 /* Update the city's trade routes. */
1259
1260 /* Clear CMA. */
1261 if (pcity->cm_parameter) {
1262 free(pcity->cm_parameter);
1263 pcity->cm_parameter = nullptr;
1264 }
1265
1267 }
1268
1269 /*
1270 * maybe_make_contact() MUST be called before city_map_update_all(),
1271 * since the diplomacy status can influence whether a tile is available.
1272 */
1274
1275 if (city_remains) {
1276 struct extra_type *upgradet;
1277
1278 if (raze) {
1280 }
1281
1282 if (taker_had_no_cities) {
1283 /* If conqueror previously had no cities, we might need to give
1284 * them a palace etc */
1285 if (build_free) {
1287 } /* Else caller should probably ensure palace is built */
1288
1289 BV_SET(ptaker->flags, PLRF_FIRST_CITY);
1290 }
1291
1293
1294 /* Restore any global improvement effects that this city confers */
1295 city_built_iterate(pcity, pimprove) {
1297 _("Transfer of %s"));
1299
1300 /* Set production to something valid for pplayer, if not.
1301 * (previously allowed building obsolete units.) */
1302 if (!can_city_build_now(nmap, pcity, &pcity->production)) {
1304 }
1305
1306 /* What wasn't obsolete for the old owner may be so now. */
1308
1310
1311 if (new_extras) {
1312 const char *clink = city_link(pcity);
1313
1315 _("The people in %s are stunned by your "
1316 "technological insight!"),
1317 clink);
1318
1319 if (upgradet != nullptr) {
1321 _("Workers spontaneously gather and upgrade "
1322 "%s with %s."),
1324 } else {
1326 _("Workers spontaneously gather and upgrade "
1327 "%s infrastructure."),
1328 clink);
1329 }
1331 }
1332
1333 /* Build a new palace for free if the player lost their capital and
1334 savepalace is on. */
1336
1337 /* Refresh the city's vision range, since it might be different
1338 * under the new owner. */
1340
1341 /* Update the national borders, within the current vision and culture.
1342 * This could leave a border ring around the city, updated later by
1343 * map_calculate_borders() at the next turn.
1344 */
1346 /* city_thaw_workers_queue() later */
1347
1348 auto_arrange_workers(pcity); /* Does city_map_update_all() */
1350 city_thaw_workers_queue(); /* After old city has a chance to work! */
1352 /* No sanity check here as the city is not refreshed! */
1353 }
1354
1355 if (city_remains) {
1356 /* Send city with updated owner information to giver and to everyone
1357 * having shared vision pact with them before they may
1358 * lose vision to it. When we later send info to everybody seeing the city,
1359 * they may not be included. */
1360 send_city_info(nullptr, pcity);
1361 }
1362
1363 /* Remove the sight points from the giver. */
1364 vision_clear_sight(old_vision);
1365 vision_free(old_vision);
1366
1367 /* Send wonder infos. */
1368 if (had_great_wonders) {
1369 send_game_info(nullptr);
1370 if (city_remains) {
1371 send_player_info_c(ptaker, nullptr);
1372
1373 /* Refresh all cities of the taker to account for possible changes due
1374 * to player wide effects. */
1375 city_list_iterate(ptaker->cities, acity) {
1378 } else {
1379 /* Refresh all cities to account for possible global effects. */
1383 }
1384 }
1386 /* No need to send to detached connections. */
1387 send_player_info_c(pgiver, nullptr);
1388
1389 /* Refresh all cities of the giver to account for possible changes due
1390 * to player wide effects. */
1391 city_list_iterate(pgiver->cities, acity) {
1394 }
1395
1396 /* Refresh all cities in the queue. */
1398 /* After the refresh the sanity check can be done. */
1400
1401 if (city_remains) {
1402 /* Send information about conquered city to all players. */
1403 send_city_info(nullptr, pcity);
1404 }
1405
1406 /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to
1407 * refresh all cities for the player. */
1411 }
1415 }
1416
1417 if (pgiver->primary_capital_id == saved_id) {
1419 }
1420
1421 sync_cities();
1422
1423 CALL_FUNC_EACH_AI(city_info, pcity);
1424
1425 return city_remains;
1426}
1427
1428/************************************************************************/
1436{
1437 struct player *pplayer;
1438 struct nation_type *nation;
1439 int i;
1441 bool first_city;
1442
1443 fc_assert_ret(pcity != nullptr);
1444 pplayer = city_owner(pcity);
1445 fc_assert_ret(pplayer != nullptr);
1446 nation = nation_of_player(pplayer);
1447 fc_assert_ret(nation != nullptr);
1448
1449 /* If this isn't the first city a player has ever had, they only get
1450 * any initial buildings with the SaveSmallWonder flag, and then only
1451 * if savepalace is enabled. */
1453
1456
1457 /* Global free buildings. */
1458 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1460 struct impr_type *pimprove;
1461
1462 if (n == B_LAST) {
1463 break;
1464 }
1465
1466 pimprove = improvement_by_number(n);
1467 fc_assert_action(!is_great_wonder(pimprove), continue);
1468 if (first_city
1472 /* TRANS: Reason that a building was added to the city.
1473 * Building is given for free to player's first city. */
1474 Q_("?initbldg:Free %s"));
1475 if (is_small_wonder(pimprove)) {
1477 }
1478 }
1479 }
1480
1481 /* Nation specific free buildings. */
1482 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1483 Impr_type_id n = nation->init_buildings[i];
1484 struct impr_type *pimprove;
1485
1486 if (n == B_LAST) {
1487 break;
1488 }
1489
1490 pimprove = improvement_by_number(n);
1491 if (first_city
1495 /* TRANS: Reason that a building was added to the city.
1496 * Building is given for free to player's first city. */
1497 Q_("?initbldg:Free %s"));
1498 if (is_small_wonder(pimprove)) {
1500 } else if (is_great_wonder(pimprove)) {
1502 }
1503 }
1504 }
1505
1506 /* Update wonder infos. */
1507 if (has_great_wonders) {
1508 send_game_info(nullptr);
1509 /* No need to send to detached connections. */
1510 send_player_info_c(pplayer, nullptr);
1511 } else if (has_small_wonders) {
1512 /* No need to send to detached connections. */
1513 send_player_info_c(pplayer, nullptr);
1514 }
1515}
1516
1517/************************************************************************/
1520void create_city(struct player *pplayer, struct tile *ptile,
1521 const char *name, struct player *nationality)
1522{
1523 struct player *saved_owner = tile_owner(ptile);
1524 struct tile *saved_claimer = tile_claimer(ptile);
1525 struct city *pwork = tile_worked(ptile);
1526 struct city *pcity;
1529 const struct civ_map *nmap = &(wld.map);
1530
1531 log_debug("create_city() %s", name);
1532
1533 pcity = create_city_virtual(pplayer, ptile, name);
1534
1535 /* Remove units no more seen. Do it before city is really put into
1536 * the game. */
1537 players_iterate(other_player) {
1538 if (can_player_see_units_in_city(other_player, pcity)
1539 || !map_is_known_and_seen(ptile, other_player, V_MAIN)) {
1540 continue;
1541 }
1542 unit_list_iterate(ptile->units, punit) {
1543 if (can_player_see_unit(other_player, punit)) {
1544 unit_goes_out_of_sight(other_player, punit);
1545 }
1548
1550
1551 tile_set_owner(ptile, pplayer, ptile); /* Temporarily */
1554
1558
1559 if (city_list_size(pplayer->cities) == 0) {
1560 /* Free initial buildings, or at least a palace if they were
1561 * previously careless enough to lose all their cities */
1563 BV_SET(pplayer->flags, PLRF_FIRST_CITY);
1564 }
1565
1566 /* Set up citizens nationality. */
1568
1569 /* Place a worker at the is_city_center() is_free_worked().
1570 * It is possible to build a city on a tile that is already worked;
1571 * this will displace the worker on the newly-built city's tile -- Syela */
1572 tile_set_worked(ptile, pcity); /* Instead of city_map_update_worker() */
1573
1574 if (pwork != nullptr) {
1575 /* Was previously worked by another city */
1576 /* Turn citizen into specialist. */
1577 pwork->specialists[DEFAULT_SPECIALIST]++;
1578 /* One less citizen. Citizen sanity will be handled later in
1579 * city_thaw_workers_queue() */
1580 pwork->server.synced = FALSE;
1582 }
1583
1584 /* Update citizens. */
1585 citizens_update(pcity, nationality);
1586
1587 /* Restore the old-owner information so removal
1588 * of territory claiming bases can work relative to it. */
1590
1591 /* Destroy any extras that don't belong in the city. */
1592 extra_type_iterate(pextra) {
1593 if (tile_has_extra(ptile, pextra)
1594 && !is_native_tile_to_extra(pextra, ptile)) {
1595 destroy_extra(ptile, pextra);
1596 }
1598
1599 /* Build any extras that the city should have. */
1600 upgrade_city_extras(pcity, nullptr);
1601
1602 /* Claim the ground we stand on */
1603 map_claim_ownership(ptile, pplayer, ptile, TRUE);
1604
1605 /* Before arranging workers to show unknown land */
1606 pcity->server.vision = vision_new(pplayer, ptile);
1609 city_list_prepend(pplayer->cities, pcity);
1610
1611 /* This is dependent on the current vision, so must be done after
1612 * vision is prepared and before arranging workers. */
1613 map_claim_border(ptile, pplayer, -1);
1614 /* city_thaw_workers_queue() later */
1615
1616 /* Refresh the city. First a city refresh is done (this shouldn't
1617 * send any packets to the client because the city has no supported units)
1618 * then rearrange the workers. Note that auto_arrange_workers() does its
1619 * own refresh call; it is safest to do our own controlled city_refresh()
1620 * first. */
1623 city_thaw_workers_queue(); /* After new city has a chance to work! */
1625
1626 /* Bases destroyed earlier may have had watchtower effect. Refresh
1627 * unit vision. */
1629
1630 update_tile_knowledge(ptile);
1631
1634 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1635 * cities for the player. */
1636 city_refresh_for_player(pplayer);
1637 }
1638
1639 pcity->server.synced = FALSE;
1640 send_city_info(nullptr, pcity);
1641 sync_cities(); /* Will also send pwork. */
1642
1643 notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server,
1644 _("You have founded %s."),
1645 city_link(pcity));
1647
1648 unit_list_iterate((ptile)->units, punit) {
1650
1651 /* Catch fortress building, transforming into ocean, etc. */
1654 }
1655
1656 /* Update happiness (the unit may no longer cause unrest). */
1657 if (home) {
1658 if (city_refresh(home)) {
1659 /* Shouldn't happen, but better be safe than sorry. */
1661 }
1664 }
1666
1668
1669 script_server_signal_emit("city_built", pcity);
1670
1671 CALL_FUNC_EACH_AI(city_created, pcity);
1672 CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
1673}
1674
1675/************************************************************************/
1681bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1682 const char *name, struct player *nationality)
1683{
1684 const struct civ_map *nmap = &(wld.map);
1685
1686 if (is_enemy_unit_tile(ptile, pplayer)
1687 || !city_can_be_built_here(nmap, ptile, nullptr, FALSE)) {
1688 return FALSE;
1689 }
1690
1691 if (!pplayer->is_alive) {
1692 pplayer->is_alive = TRUE;
1693 send_player_info_c(pplayer, nullptr);
1694 }
1695
1696 if (name == nullptr || name[0] == '\0') {
1697 name = city_name_suggestion(pplayer, ptile);
1698 }
1699
1700 if (nationality == nullptr) {
1701 nationality = pplayer;
1702 }
1703
1704 map_show_tile(pplayer, ptile);
1705 create_city(pplayer, ptile, name, nationality);
1706
1707 return TRUE;
1708}
1709
1710/************************************************************************/
1714{
1715 struct player *powner = city_owner(pcity);
1716 struct tile *pcenter = city_tile(pcity);
1718 struct vision *old_vision;
1719 int id = pcity->id; /* We need this even after memory has been freed */
1720 bool had_great_wonders = FALSE;
1723 struct dbv tile_processed;
1724 struct tile_list *process_queue;
1725 const char *ctl = city_tile_link(pcity);
1726 const struct civ_map *nmap = &(wld.map);
1727
1728 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1729 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1730
1732 city_built_iterate(pcity, pimprove) {
1733 building_removed(pcity, pimprove, "city_destroyed", nullptr);
1734
1735 if (is_small_wonder(pimprove)) {
1737 } else if (is_great_wonder(pimprove)) {
1739 }
1741
1742 /* Rehome units in other cities */
1743 unit_list_iterate_safe(pcity->units_supported, punit) {
1745
1746 if (new_home_city
1747 && new_home_city != pcity
1748 && city_owner(new_home_city) == powner
1749 && !punit->server.dying) {
1751 }
1753
1754 /* Make sure ships are not left on land when city is removed. */
1756 bool moved;
1757 const struct unit_type *punittype = unit_type_get(punit);
1758
1759 /* can_exist_at_tile() would give wrong results, as
1760 * the city is still on map. */
1763 || is_safe_ocean(nmap, pcenter))) {
1764 continue;
1765 }
1766
1768 moved = FALSE;
1770 struct unit *ptrans;
1771
1774 /* Move */
1776 /* It may be impossible to survive at the tile even if it is
1777 * native. See UTYF_COAST_STRICT */
1779 } else {
1780 ptrans = nullptr;
1781 }
1784 nullptr, nullptr,
1786 nullptr) != nullptr) {
1787 moved = TRUE;
1788 }
1789 if (moved) {
1792 _("Moved %s out of disbanded city %s "
1793 "since it cannot stay on %s."),
1796 break;
1797 }
1798 }
1799 }
1801 if (!moved) {
1804 _("When %s was disbanded your %s could not "
1805 "get out, and it was therefore lost."),
1806 ctl,
1808 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1809 }
1811
1815 struct tile *ptile = tile_list_front(process_queue);
1816
1819 adjc_iterate(nmap, ptile, piter) {
1820 struct city *other_city;
1821
1823 continue;
1824 }
1826 if (other_city != nullptr) {
1827 /* Adjacent tile has a city that may have been part of same channel */
1832
1838 _("When %s was disbanded your %s in %s was trapped, "
1839 "and it was therefore lost."),
1840 ctl,
1843 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1844 }
1846 } else {
1848 }
1850 }
1851
1854
1855 if (!city_exist(id)) {
1856 /* Wiping trapped units caused city to disappear. */
1857 return;
1858 }
1859
1860 /* Any remaining supported units are destroyed */
1861 unit_list_iterate_safe(pcity->units_supported, punit) {
1862 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1864
1865 if (!city_exist(id)) {
1866 /* Wiping supported units caused city to disappear. */
1867 return;
1868 }
1869
1872 TRUE, TRUE);
1873
1874 FC_FREE(proute);
1875 FC_FREE(pback);
1877
1882
1883 /* idex_unregister_city() is called in game_remove_city() below */
1884
1885 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1886 * still be alive in the client, or in the player map. The number of
1887 * removed cities is small, so the loss is acceptable. */
1888
1889 old_vision = pcity->server.vision;
1890 pcity->server.vision = nullptr;
1893
1894 /* Remove city from the map. */
1895 tile_set_worked(pcenter, nullptr);
1896
1897 /* Reveal units. */
1898 players_iterate(other_player) {
1899 if (can_player_see_units_in_city(other_player, pcity)
1900 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1901 continue;
1902 }
1904 if (can_player_see_unit(other_player, punit)) {
1905 send_unit_info(other_player->connections, punit);
1906 }
1909
1913
1914 /* Remove any extras that were only there because the city was there. */
1915 extra_type_iterate(pextra) {
1916 if (tile_has_extra(pcenter, pextra)
1917 && !is_native_tile_to_extra(pextra, pcenter)) {
1919 }
1921
1922 players_iterate(other_player) {
1923 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1924 reality_check_city(other_player, pcenter);
1925 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1926 map_show_tile(other_player, pcenter);
1927 }
1929
1931 if (pconn->playing == nullptr && pconn->observer) {
1932 /* For detached observers we have to send a specific packet. This is
1933 * a hack necessitated by the private map that exists for players but
1934 * not observers. */
1936 }
1938
1939 if (old_vision != NULL) {
1940 vision_clear_sight(old_vision);
1941 vision_free(old_vision);
1942 }
1943
1944 /* Infrastructures may have changed. */
1945 send_tile_info(nullptr, pcenter, FALSE);
1946
1947 /* Build a new palace for free if the player lost their capital and
1948 * savepalace is on. */
1950
1951 /* Update wonder infos. */
1952 if (had_great_wonders) {
1953 send_game_info(nullptr);
1954 /* No need to send to detached connections. */
1955 send_player_info_c(powner, nullptr);
1956 } else if (BV_ISSET_ANY(had_small_wonders)) {
1957 /* No need to send to detached connections. */
1958 send_player_info_c(powner, nullptr);
1959 }
1960
1963 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1964 * cities for the player. */
1966 }
1967
1968 sync_cities();
1969
1970 /* At least sentried helicopters need to go idle, maybe others.
1971 * In alien ruleset, city center might have provided water source
1972 * for adjacent tile. */
1974}
1975
1976/************************************************************************/
1992bool unit_conquer_city(struct unit *punit, struct city *pcity)
1993{
1994 bool try_civil_war = FALSE;
1995 bool city_remains;
1996 int coins;
1997 struct player *pplayer = unit_owner(punit);
1998 struct player *cplayer = city_owner(pcity);
1999#ifndef FREECIV_NDEBUG
2000 const struct unit_type *utype = unit_type_get(punit);
2001#endif
2002
2003 /* If not at war, may peacefully enter city. */
2005 "Can't conquer city during peace.");
2006
2007 /* If we cannot occupy the city, this unit entering will not trigger
2008 * effects below. */
2012 FALSE, "Bad unit for city occupation.");
2013
2014 /* A transported unit trying to conquer a city should already have been
2015 * unloaded. */
2017 "Can't conquer city while transported.");
2018
2019 /* Okay, we're at war - invader captures/destroys city... */
2020
2021 /* If a capital is captured, then spark off a civil war
2022 * - Kris Bubendorfer
2023 * Also check spaceships --dwp */
2024
2025 if (is_capital(pcity)
2026 && (cplayer->spaceship.state == SSHIP_STARTED
2027 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
2029 }
2030
2031 if (is_capital(pcity)
2036 }
2037
2038 /*
2039 * We later remove a citizen. Lets check if we can save this since
2040 * the city will be destroyed.
2041 */
2042 if (city_size_get(pcity) <= 1) {
2043 int saved_id = pcity->id;
2044
2046 _("You destroy %s completely."),
2049 _("%s has been destroyed by %s."),
2050 city_tile_link(pcity), player_name(pplayer));
2051 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2052
2053 /* We cant't be sure of city existence after running some script */
2054 if (city_exist(saved_id)) {
2056 }
2057
2058 if (try_civil_war) {
2060 }
2061 return TRUE;
2062 }
2063
2065 coins = MIN(coins,
2066 fc_rand((coins / 20) + 1)
2067 + (coins * (city_size_get(pcity))) / 200);
2068 pplayer->economic.gold += coins;
2069 cplayer->economic.gold -= coins;
2070 send_player_info_c(pplayer, pplayer->connections);
2071 send_player_info_c(cplayer, cplayer->connections);
2072 if (pcity->original != pplayer) {
2073 if (coins > 0) {
2075 PL_("You conquer %s; your lootings accumulate"
2076 " to %d gold!",
2077 "You conquer %s; your lootings accumulate"
2078 " to %d gold!", coins),
2080 coins);
2082 PL_("%s conquered %s and looted %d gold"
2083 " from the city.",
2084 "%s conquered %s and looted %d gold"
2085 " from the city.", coins),
2086 player_name(pplayer),
2088 coins);
2089 } else {
2091 _("You conquer %s."),
2092 city_link(pcity));
2094 _("%s conquered %s."),
2095 player_name(pplayer),
2096 city_link(pcity));
2097 }
2098 } else {
2099 if (coins > 0) {
2101 PL_("You have liberated %s!"
2102 " Lootings accumulate to %d gold.",
2103 "You have liberated %s!"
2104 " Lootings accumulate to %d gold.", coins),
2106 coins);
2108 PL_("%s liberated %s and looted %d gold"
2109 " from the city.",
2110 "%s liberated %s and looted %d gold"
2111 " from the city.", coins),
2112 player_name(pplayer),
2114 coins);
2115 } else {
2117 _("You have liberated %s!"),
2118 city_link(pcity));
2120 _("%s liberated %s."),
2121 player_name(pplayer),
2122 city_link(pcity));
2123 }
2124 }
2125
2127 /* Just try to steal. Ignore failures to get tech */
2128 steal_a_tech(pplayer, cplayer, A_UNSET);
2129 }
2130
2131 /* We transfer the city first so that it is in a consistent state when
2132 * the size is reduced. */
2133 /* FIXME: maybe it should be a ruleset option whether barbarians get
2134 * free buildings such as palaces? */
2135 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2136 !is_barbarian(pplayer));
2137
2138 if (city_remains) {
2139 /* Reduce size should not destroy this city */
2141 city_reduce_size(pcity, 1, pplayer, "conquest");
2142 }
2143
2144 if (try_civil_war) {
2146 }
2147
2148 if (city_remains) {
2149 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2150 "conquest");
2151 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2152 }
2153
2154 return TRUE;
2155}
2156
2157/************************************************************************/
2160static int city_citywalls_gfx(const struct city *pcity)
2161{
2163
2164 return walls > 0 ? walls : 0;
2165}
2166
2167/************************************************************************/
2171{
2173
2175 return formerly;
2176}
2177
2178/************************************************************************/
2181static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2182 struct packet_city_short_info *packet)
2183{
2184 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2185
2186 packet->id = pdcity->identity;
2188
2189 if (pdcity->original != NULL) {
2190 packet->original = player_number(pdcity->original);
2191 } else {
2193 }
2194
2195 packet->tile = tile_index(ptile);
2196 if (pdcity->name == nullptr) {
2197 packet->name[0] = '\0';
2198 } else {
2199 sz_strlcpy(packet->name, pdcity->name);
2200 }
2201
2202 packet->size = vision_site_size_get(pdcity);
2203
2204 packet->occupied = pdcity->occupied;
2205 packet->walls = pdcity->walls;
2206 packet->style = pdcity->style;
2207 packet->city_image = pdcity->city_image;
2208 packet->capital = pdcity->capital;
2209
2210 packet->happy = pdcity->happy;
2211 packet->unhappy = pdcity->unhappy;
2212
2213 packet->improvements = pdcity->improvements;
2214}
2215
2216/************************************************************************/
2221{
2222 players_iterate(pplayer) {
2223 if (player_can_see_city_externals(pplayer, pcity)) {
2224 if (update_dumb_city(pplayer, pcity)) {
2225 struct packet_city_short_info packet;
2226
2227 if (city_owner(pcity) != pplayer) {
2228 /* Don't send the short_city information to someone who can see
2229 * city's internals. Doing so would really confuse the client. */
2230 package_dumb_city(pplayer, pcity->tile, &packet);
2231 lsend_packet_city_short_info(pplayer->connections, &packet);
2232 }
2233 }
2234 }
2236
2237 /* Don't send to non-player observers since they don't have 'dumb city'
2238 * information. */
2239}
2240
2241/************************************************************************/
2250{
2251 struct packet_city_info packet;
2256 struct player *powner = city_owner(pcity);
2257 struct trade_route_packet_list *routes;
2259
2260 /* Send to everyone who can see the city. */
2261
2262 if (pcity->server.needs_arrange != CNA_NOT) {
2263 /* Send city only when it's in sane state.
2264 * If it's not, it will be sent to everyone once
2265 * rearrangement has been finished. */
2266 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2267
2268 return;
2269 }
2270
2271 if (any_web_conns()) {
2273 } else {
2274 webp_ptr = nullptr;
2275 }
2276
2277 routes = trade_route_packet_list_new();
2279 webp_ptr, routes, FALSE);
2280
2281 players_iterate(pplayer) {
2282 if (!send_city_suppressed || pplayer != powner) {
2283 if (can_player_see_city_internals(pplayer, pcity)) {
2284 update_dumb_city(pplayer, pcity);
2285 packet.original = city_original_owner(pcity, pplayer);
2286 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2287 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2288 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2289 web_lsend_packet(city_info_addition, pplayer->connections,
2290 webp_ptr, FALSE);
2292 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2294 } else if (player_can_see_city_externals(pplayer, pcity)) {
2295 reality_check_city(pplayer, pcity->tile);
2296 update_dumb_city(pplayer, pcity);
2297 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2298 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2299 }
2300 }
2302
2303 /* Send to global observers. */
2304 packet.original = city_original_owner(pcity, nullptr);
2311 }
2313
2318}
2319
2320/************************************************************************/
2325{
2326 conn_list_do_buffer(dest);
2327 conn_list_iterate(dest, pconn) {
2328 struct player *pplayer = pconn->playing;
2329
2330 if (!pplayer && !pconn->observer) {
2331 continue;
2332 }
2333 whole_map_iterate(&(wld.map), ptile) {
2334 if (pplayer == nullptr
2335 || map_get_player_site(ptile, pplayer) != nullptr) {
2336 send_city_info_at_tile(pplayer, pconn->self, nullptr, ptile);
2337 }
2339 }
2342 flush_packets();
2343}
2344
2345/************************************************************************/
2348void send_player_cities(struct player *pplayer)
2349{
2350 city_list_iterate(pplayer->cities, pcity) {
2351 if (city_refresh(pcity)) {
2352 log_error("%s radius changed while sending to player.",
2354
2355 /* Make sure that no workers in illegal position outside radius. */
2357 }
2358 send_city_info(pplayer, pcity);
2359 }
2361}
2362
2363/************************************************************************/
2368void send_city_info(struct player *dest, struct city *pcity)
2369{
2370 struct player *powner = city_owner(pcity);
2371
2372 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2373 return;
2374 }
2375
2376 if (dest == powner && send_city_suppressed) {
2377 return;
2378 }
2379
2380 if (!dest || dest == powner) {
2381 pcity->server.synced = TRUE;
2382 }
2383
2384 if (!dest) {
2386 } else {
2388 }
2389
2390 /* Sending counters */
2392
2394 && player_list_size(team_members(powner->team)) > 1) {
2395 /* We want to send the new total bulbs production of the team. */
2396 send_research_info(research_get(powner), nullptr);
2397 }
2398}
2399
2400/************************************************************************/
2421 struct city *pcity, struct tile *ptile)
2422{
2423 struct packet_city_info packet;
2428 struct player *powner = nullptr;
2429 struct trade_route_packet_list *routes = nullptr;
2431
2432 if (!pcity) {
2433 pcity = tile_city(ptile);
2434 }
2435 if (pcity != nullptr && pcity->server.needs_arrange != CNA_NOT) {
2436 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2437
2438 return;
2439 }
2440 if (pcity) {
2441 powner = city_owner(pcity);
2442 }
2443
2444 if (any_web_conns()) {
2446 } else {
2447 webp_ptr = nullptr;
2448 }
2449
2450 if (powner != nullptr && powner == pviewer) {
2451 /* Send info to owner */
2452 /* This case implies powner non-nullptr which means pcity non-nullptr */
2453 if (!send_city_suppressed) {
2454 /* Wait that city has been rearranged, if it's currently
2455 * not in a sane state. */
2456
2457 routes = trade_route_packet_list_new();
2458
2459 /* Send all info to the owner */
2460 update_dumb_city(powner, pcity);
2462 webp_ptr, routes, FALSE);
2464 lsend_packet_city_info(dest, &packet, FALSE);
2471 if (dest == powner->connections) {
2472 /* HACK: send also a copy to global observers. */
2473 packet.original = city_original_owner(pcity, nullptr);
2480 }
2482 }
2483 }
2484 } else {
2485 /* Send info to non-owner */
2486 if (!pviewer) { /* Observer */
2487 if (pcity) {
2488 routes = trade_route_packet_list_new();
2489
2490 /* Should be dumb_city info? */
2492 webp_ptr, routes, FALSE);
2493 lsend_packet_city_info(dest, &packet, FALSE);
2500 }
2501 } else {
2502 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2503 if (pcity) { /* It's there and we see it; update and send */
2507 }
2508 } else { /* Not seen; send old info */
2509 if (map_is_known(ptile, pviewer)
2510 && map_get_player_site(ptile, pviewer) != nullptr) {
2513 }
2514 }
2515 }
2516 }
2517
2518 if (routes != nullptr) {
2523 }
2524}
2525
2526/************************************************************************/
2531void package_city(struct city *pcity, struct packet_city_info *packet,
2535 struct trade_route_packet_list *routes,
2536 bool dipl_invest)
2537{
2538 int i;
2539 int ppl = 0;
2540
2541 fc_assert(!pcity->server.needs_arrange);
2542
2543 packet->id = pcity->id;
2544 packet->owner = player_number(city_owner(pcity));
2545
2546 packet->tile = tile_index(city_tile(pcity));
2548
2549 packet->size = city_size_get(pcity);
2550 for (i = 0; i < FEELING_LAST; i++) {
2551 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2552 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2553 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2554 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2555 if (i == 0) {
2556 ppl += packet->ppl_happy[i];
2557 ppl += packet->ppl_content[i];
2558 ppl += packet->ppl_unhappy[i];
2559 ppl += packet->ppl_angry[i];
2560 }
2561 }
2562 /* The number of data in specialists[] array */
2565 packet->specialists[sp] = pcity->specialists[sp];
2566 ppl += packet->specialists[sp];
2568
2569 /* The nationality of the citizens. */
2570 nat_packet->id = pcity->id;
2571 nat_packet->nationalities_count = 0;
2573 int cit = 0;
2574
2575 player_slots_iterate(pslot) {
2576 citizens nationality = citizens_nation_get(pcity, pslot);
2577
2578 if (nationality != 0) {
2579 /* This player should exist! */
2580 fc_assert(player_slot_get_player(pslot) != nullptr);
2581
2582 nat_packet->nation_id[nat_packet->nationalities_count]
2583 = player_slot_index(pslot);
2584 nat_packet->nation_citizens[nat_packet->nationalities_count]
2585 = nationality;
2586 nat_packet->nationalities_count++;
2587
2588 cit += nationality;
2589 }
2591
2592 fc_assert(cit == packet->size);
2593 }
2594
2595 packet->history = pcity->history;
2596 packet->culture = city_culture(pcity);
2598
2599 if (packet->size != ppl) {
2600 static bool recursion = FALSE;
2601
2602 if (recursion) {
2603 /* Recursion didn't help. Do not enter infinite recursive loop.
2604 * Package city as it is. */
2605 log_error("Failed to fix inconsistent city size.");
2606 recursion = FALSE;
2607 } else {
2608 /* Note: If you get this error and try to debug the cause, you may find
2609 * using check_city_feelings() in some key points useful. */
2610 /* Have this as an fc_assert() first, so one can use '-F' to caught
2611 * these in debugger. */
2612 fc_assert(packet->size == ppl);
2613
2614 /* In all builds have an error message shown. */
2615 log_error("City size %d, citizen count %d for %s",
2616 packet->size, ppl, city_name_get(pcity));
2617
2618 /* Try to fix */
2621
2622 /* And repackage */
2623 recursion = TRUE;
2625 web_packet, routes, dipl_invest);
2626 recursion = FALSE;
2627
2628 return;
2629 }
2630 }
2631
2632 packet->city_radius_sq = pcity->city_radius_sq;
2633
2634 i = 0;
2637 = fc_malloc(sizeof(struct packet_trade_route_info));
2638
2639 tri_packet->city = pcity->id;
2640 tri_packet->index = i;
2641 tri_packet->partner = proute->partner;
2642 tri_packet->value = proute->value;
2643 tri_packet->direction = proute->dir;
2644 tri_packet->goods = goods_number(proute->goods);
2645
2647
2648 i++;
2650
2651 packet->trade_route_count = i;
2652
2654 packet->surplus[o] = pcity->surplus[o];
2655 packet->waste[o] = pcity->waste[o];
2656 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2657 packet->prod[o] = pcity->prod[o];
2658 packet->citizen_base[o] = pcity->citizen_base[o];
2659 packet->usage[o] = pcity->usage[o];
2661
2662 packet->food_stock = pcity->food_stock;
2663 packet->shield_stock = pcity->shield_stock;
2664 packet->pollution = pcity->pollution;
2665 packet->illness_trade = pcity->illness_trade;
2666 packet->city_options = pcity->city_options;
2667 packet->wl_cb = pcity->wlcb;
2668
2669 if (!dipl_invest) {
2670 packet->acquire_type = pcity->acquire_t;
2671 } else {
2672 /* Dummy value */
2673 packet->acquire_type = CACQ_CONQUEST;
2674 }
2675
2676 packet->production_kind = pcity->production.kind;
2677 packet->production_value = universal_number(&pcity->production);
2678
2679 packet->turn_last_built = pcity->turn_last_built;
2680 packet->turn_founded = pcity->turn_founded;
2681
2682 packet->changed_from_kind = pcity->changed_from.kind;
2684
2685 packet->before_change_shields = pcity->before_change_shields;
2686 packet->disbanded_shields = pcity->disbanded_shields;
2687 packet->caravan_shields = pcity->caravan_shields;
2688 packet->last_turns_shield_surplus = pcity->last_turns_shield_surplus;
2689
2690 worklist_copy(&packet->worklist, &pcity->worklist);
2692
2693 packet->airlift = pcity->airlift;
2694 packet->did_buy = pcity->did_buy;
2695 packet->did_sell = pcity->did_sell;
2696 packet->was_happy = pcity->was_happy;
2697 packet->had_famine = pcity->had_famine;
2698
2699 packet->walls = city_citywalls_gfx(pcity);
2700 packet->style = pcity->style;
2702 packet->capital = pcity->capital;
2703 packet->steal = pcity->steal;
2704
2705 rally_packet->id = pcity->id;
2706 rally_packet->length = pcity->rally_point.length;
2707 rally_packet->persistent = pcity->rally_point.persistent;
2708 rally_packet->vigilant = pcity->rally_point.vigilant;
2709 if (pcity->rally_point.length) {
2710 memcpy(rally_packet->orders, pcity->rally_point.orders,
2711 pcity->rally_point.length * sizeof(struct unit_order));
2712 }
2713
2714 BV_CLR_ALL(packet->improvements);
2715 improvement_iterate(pimprove) {
2716 if (city_has_building(pcity, pimprove)) {
2717 BV_SET(packet->improvements, improvement_index(pimprove));
2718 }
2720
2721#ifdef FREECIV_WEB
2722 if (web_packet != nullptr) {
2723 struct tile *pcenter = city_tile(pcity);
2724 const struct civ_map *nmap = &(wld.map);
2725
2726 BV_CLR_ALL(web_packet->can_build_unit);
2727 BV_CLR_ALL(web_packet->can_build_improvement);
2728
2729 web_packet->id = pcity->id;
2730
2731 if (pcity->cm_parameter != nullptr) {
2732 web_packet->cma_enabled = TRUE;
2733 cm_copy_parameter(&web_packet->cm_parameter, pcity->cm_parameter);
2734 } else {
2735 web_packet->cma_enabled = FALSE;
2736 memset(&web_packet->cm_parameter, 0, sizeof(web_packet->cm_parameter));
2737 }
2738
2740 web_packet->granary_turns = city_turns_to_grow(pcity);
2741
2742 improvement_iterate(pimprove) {
2743 if (can_city_build_improvement_now(pcity, pimprove)) {
2744 BV_SET(web_packet->can_build_improvement, improvement_index(pimprove));
2745 }
2747
2750 BV_SET(web_packet->can_build_unit, utype_index(punittype));
2751 }
2753
2754 i = 0;
2756 web_packet->output_food[i] = city_tile_output_now(pcity, ptile, O_FOOD);
2757 web_packet->output_shield[i] = city_tile_output_now(pcity, ptile, O_SHIELD);
2758 web_packet->output_trade[i] = city_tile_output_now(pcity, ptile, O_TRADE);
2759
2760 i++;
2762 }
2763#endif /* FREECIV_WEB */
2764}
2765
2766/************************************************************************/
2776bool update_dumb_city(struct player *pplayer, struct city *pcity)
2777{
2778 bv_imprs improvements;
2779 struct tile *pcenter = city_tile(pcity);
2780 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2781 /* pcity->client.occupied isn't used at the server, so we go straight to
2782 * the unit list to check the occupied status. */
2783 bool occupied = (unit_list_size(pcenter->units) > 0);
2785 bool happy = city_happy(pcity);
2786 bool unhappy = city_unhappy(pcity);
2787 int style = pcity->style;
2789 enum capital_type capital = pcity->capital;
2790
2791 /* Only someone knowing the tile should ever know a city on it. */
2792 fc_assert(map_is_known(pcenter, pplayer));
2793
2795 improvement_iterate(pimprove) {
2796 if (is_improvement_visible(pimprove)
2797 && city_has_building(pcity, pimprove)) {
2799 }
2801
2802 if (pdcity == nullptr) {
2805 } else if (pdcity->location != pcenter) {
2806 log_error("Trying to update bad city (wrong location) "
2807 "at %i,%i for player %s",
2808 TILE_XY(pcity->tile), player_name(pplayer));
2809 fc_assert(pdcity->location == pcenter);
2810 pdcity->location = pcenter; /* ?? */
2811 } else if (pdcity->identity != pcity->id) {
2812 log_error("Trying to update old city (wrong identity) "
2813 "at %i,%i for player %s",
2814 TILE_XY(city_tile(pcity)), player_name(pplayer));
2815 fc_assert(pdcity->identity == pcity->id);
2816 pdcity->identity = pcity->id; /* ?? */
2817 } else if (pdcity->occupied == occupied
2818 && pdcity->walls == walls
2819 && pdcity->happy == happy
2820 && pdcity->unhappy == unhappy
2821 && pdcity->style == style
2822 && pdcity->city_image == city_image
2823 && pdcity->capital == capital
2824 && BV_ARE_EQUAL(pdcity->improvements, improvements)
2827 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2828 return FALSE;
2829 }
2830
2832 pdcity->occupied = occupied;
2833 pdcity->walls = walls;
2834 pdcity->style = style;
2835 pdcity->city_image = city_image;
2836 pdcity->capital = capital;
2837 pdcity->happy = happy;
2838 pdcity->unhappy = unhappy;
2839 pdcity->improvements = improvements;
2840
2841 return TRUE;
2842}
2843
2844/************************************************************************/
2847void reality_check_city(struct player *pplayer, struct tile *ptile)
2848{
2849 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2850
2851 if (pdcity) {
2852 struct city *pcity = tile_city(ptile);
2853
2854 if (!pcity || pcity->id != pdcity->identity) {
2855 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2856
2857 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2858 fc_assert_ret(playtile->site == pdcity);
2859 playtile->site = nullptr;
2861 }
2862 }
2863}
2864
2865/************************************************************************/
2868void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2869{
2870 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2871
2872 if (pdcity) {
2873 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2874
2875 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2876 fc_assert_ret(playtile->site == pdcity);
2877 playtile->site = nullptr;
2879 }
2880}
2881
2882/************************************************************************/
2886static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2887 bool source_gone)
2888{
2889 struct player *plr1 = city_owner(pc1);
2890 struct player *plr2 = city_owner(pc2);
2893
2896
2897 if (plr1 == plr2) {
2898 if (source_gone) {
2901 _("Trade between %s and %s lost along with city."),
2903 } else {
2906 _("Trade route between %s and %s canceled."),
2908 }
2909 } else {
2910 if (source_gone) {
2913 /* TRANS: "...between Spanish city Madrid and Paris..." */
2914 _("Trade between %s city %s and %s lost along with "
2915 "their city."),
2917 /* It's implicit to removed city's owner that that city no longer
2918 * has trade routes, so say nothing in that case */
2919 } else {
2922 _("Sorry, the %s canceled the trade route "
2923 "from %s to your city %s."),
2927 /* TRANS: "...from Paris to Spanish city Madrid." */
2928 _("We canceled the trade route "
2929 "from %s to %s city %s."),
2931 }
2932 }
2933}
2934
2935/************************************************************************/
2944 struct trade_route *proute,
2945 bool announce, bool source_gone)
2946{
2947 struct city *pc2 = game_city_by_number(proute->partner);
2948 struct trade_route *back_route = nullptr;
2949
2950 fc_assert_ret_val(pc1 && proute, nullptr);
2951
2953
2954 if (pc2 != nullptr) {
2956 if (pc1->id == pback->partner) {
2957 back_route = pback;
2958 }
2960
2961 if (back_route != nullptr) {
2963 }
2964
2965 if (announce) {
2967
2970 }
2971 }
2972
2973 return back_route;
2974}
2975
2976/**********************************************************************/
2980{
2982 ftc_server,
2983 _("%s has been struck by a plague! Population lost!"),
2984 city_link(pcity));
2985 if (city_reduce_size(pcity, 1, nullptr, "plague")) {
2986 pcity->turn_plague = game.info.turn;
2987
2988 /* Recalculate illness */
2989 pcity->server.illness = city_illness_calc(pcity, nullptr, nullptr,
2990 &(pcity->illness_trade),
2991 nullptr);
2992
2993 return TRUE;
2994 }
2995
2996 return FALSE;
2997}
2998
2999/************************************************************************/
3005void do_sell_building(struct player *pplayer, struct city *pcity,
3006 struct impr_type *pimprove, const char *reason)
3007{
3008 if (can_city_sell_building(pcity, pimprove)) {
3009 pplayer->economic.gold += impr_sell_gold(pimprove);
3010 building_lost(pcity, pimprove, reason, nullptr);
3011 }
3012}
3013
3014/************************************************************************/
3026struct city
3027*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
3028 struct player **oldcity_owner)
3029{
3030 struct city *oldcity = nullptr;
3031
3032 fc_assert_ret_val(!city_has_building(pcity, pimprove), nullptr);
3033
3034 if (is_great_wonder(pimprove)) {
3035 if (!(oldcity = city_from_great_wonder(pimprove))) {
3036 oldcity = pcity;
3037 }
3039 } else if (is_small_wonder(pimprove)) {
3040 if (!(oldcity
3041 = city_from_small_wonder(city_owner(pcity), pimprove))) {
3042 oldcity = pcity;
3043 }
3044 }
3045 if (oldcity && oldcity != pcity) {
3048 _("Moving %s"));
3049 } else {
3051 _("Acquiring %s"));
3052 }
3053
3054 return oldcity;
3055}
3056
3057/************************************************************************/
3060bool building_removed(struct city *pcity, const struct impr_type *pimprove,
3061 const char *reason, struct unit *destroyer)
3062{
3063 int backup = pcity->id;
3064
3065 city_remove_improvement(pcity, pimprove);
3066
3067 script_server_signal_emit("building_lost", pcity, pimprove, reason,
3068 destroyer);
3069
3070 return city_exist(backup);
3071}
3072
3073/************************************************************************/
3077void building_lost(struct city *pcity, const struct impr_type *pimprove,
3078 const char *reason, struct unit *destroyer)
3079{
3080 struct player *owner = city_owner(pcity);
3082 bool city_remains;
3083
3085
3086 if ((was_capital && (!city_remains || !is_capital(pcity)))
3087 && (owner->spaceship.state == SSHIP_STARTED
3088 || owner->spaceship.state == SSHIP_LAUNCHED)) {
3089 /* If the capital was lost (by destruction of the palace) production on
3090 * the spaceship is lost. */
3092 }
3093
3094 if (city_remains) {
3095 /* Update city; influence of effects (buildings, ...) on unit upkeep */
3096 if (city_refresh(pcity)) {
3098 }
3099
3100 /* Re-update the city's visible area. This updates fog if the vision
3101 * range increases or decreases. */
3103 }
3104}
3105
3106/************************************************************************/
3115{
3116 const struct unit_type *ut = unit_type_get(punit);
3117 struct player *plr = unit_owner(punit);
3118 bool update = FALSE;
3119 int cost;
3120
3122 cost = utype_upkeep_cost(ut, plr, o);
3123 if (cost > 0) {
3124 if (free_uk[o] > cost) {
3125 free_uk[o] -= cost;
3126 cost = 0;
3127 } else {
3128 cost -= free_uk[o];
3129 free_uk[o] = 0;
3130 }
3131 }
3132
3133 if (cost != punit->upkeep[o]) {
3134 update = TRUE;
3135 punit->upkeep[o] = cost;
3136 }
3138
3139 if (update) {
3140 /* Update unit information to the player and global observers. */
3141 send_unit_info(nullptr, punit);
3142 }
3143}
3144
3145/************************************************************************/
3165void city_units_upkeep(const struct city *pcity)
3166{
3167 int free_uk[O_LAST];
3168
3169 if (!pcity || !pcity->units_supported
3170 || unit_list_size(pcity->units_supported) < 1) {
3171 return;
3172 }
3173
3178
3179 /* Save the upkeep for all units in the corresponding punit struct */
3180 unit_list_iterate(pcity->units_supported, punit) {
3183}
3184
3185/************************************************************************/
3188void change_build_target(struct player *pplayer, struct city *pcity,
3189 struct universal *target,
3190 enum event_type event)
3191{
3192 const char *name;
3193 const char *source;
3194
3195 /* If the city is already building this thing, don't do anything */
3196 if (are_universals_equal(&pcity->production, target)) {
3197 return;
3198 }
3199
3200 /* Is the city no longer building a wonder? */
3201 if (VUT_IMPROVEMENT == pcity->production.kind
3202 && is_great_wonder(pcity->production.value.building)
3203 && event != E_IMP_AUTO
3204 && event != E_WORKLIST) {
3205 /* If the build target is changed because of an advisor's suggestion or
3206 * because the worklist advances, then the wonder was completed --
3207 * don't announce that the player has *stopped* building that wonder.
3208 */
3210 _("The %s have stopped building The %s in %s."),
3211 nation_plural_for_player(pplayer),
3213 city_link(pcity));
3214 }
3215
3216 /* Manage the city change-production penalty.
3217 (May penalize, restore or do nothing to the shield_stock.) */
3218 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3219 pcity->shield_stock = city_change_production_penalty(pcity, target);
3220 }
3221
3222 /* Change build target. */
3223 pcity->production = *target;
3224
3225 /* What's the name of the target? */
3227
3228 switch (event) {
3229 case E_WORKLIST:
3230 /* TRANS: Possible 'source' of the production change
3231 * (in "<city> is building ..." sentence). Preserve leading space. */
3232 source = _(" from the worklist");
3233 break;
3234 case E_IMP_AUTO:
3235 /* TRANS: Possible 'source' of the production change
3236 * (in "<city> is building ..." sentence). Preserve leading space. */
3237 source = _(" as suggested by the advisor");
3238 break;
3239 default:
3240 source = "";
3241 break;
3242 }
3243
3244 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3246
3247 /* Tell the player what's up. */
3248 /* FIXME: this may give bad grammar when translated if the 'source'
3249 * string can have multiple values. */
3251 /* TRANS: "<city> is building <production><source>."
3252 * 'source' might be an empty string, or a clause like
3253 * " from the worklist". */
3254 _("%s is building %s%s."),
3256 name, source);
3257
3258 /* If the city is building a wonder, tell the rest of the world
3259 about it. */
3260 if (VUT_IMPROVEMENT == pcity->production.kind
3261 && is_great_wonder(pcity->production.value.building)) {
3263 _("The %s have started building The %s in %s."),
3264 nation_plural_for_player(pplayer),
3265 name,
3266 city_link(pcity));
3267 }
3268}
3269
3270/************************************************************************/
3277void city_map_update_empty(struct city *pcity, struct tile *ptile)
3278{
3279 tile_set_worked(ptile, nullptr);
3280 send_tile_info(nullptr, ptile, FALSE);
3281 pcity->server.synced = FALSE;
3282}
3283
3284/************************************************************************/
3291void city_map_update_worker(struct city *pcity, struct tile *ptile)
3292{
3293 tile_set_worked(ptile, pcity);
3294 send_tile_info(nullptr, ptile, FALSE);
3295 pcity->server.synced = FALSE;
3296}
3297
3298/************************************************************************/
3303static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3304{
3305 struct city *pwork = tile_worked(ptile);
3306
3307 if (pwork != nullptr
3308 && !is_free_worked(pwork, ptile)
3309 && !city_can_work_tile(pwork, ptile)) {
3310 tile_set_worked(ptile, nullptr);
3311 send_tile_info(nullptr, ptile, FALSE);
3312
3313 pwork->specialists[DEFAULT_SPECIALIST]++; /* Keep city sanity */
3314 pwork->server.synced = FALSE;
3315
3316 if (queued) {
3317 city_freeze_workers_queue(pwork); /* Place the displaced later */
3318 } else {
3319 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3321 send_city_info(nullptr, pwork);
3322 }
3323 return TRUE;
3324 }
3325
3326 return FALSE;
3327}
3328
3329/************************************************************************/
3335{
3336 return city_map_update_tile_direct(ptile, TRUE);
3337}
3338
3339/************************************************************************/
3343{
3344 return city_map_update_tile_direct(ptile, FALSE);
3345}
3346
3347/************************************************************************/
3351void sync_cities(void)
3352{
3354 return;
3355 }
3356
3357 players_iterate(pplayer) {
3358 city_list_iterate(pplayer->cities, pcity) {
3359 if (!pcity->server.synced) {
3360 /* Sending will set to TRUE. */
3361 send_city_info(pplayer, pcity);
3362 }
3365}
3366
3367/************************************************************************/
3371{
3372 struct tile *pcenter = city_tile(pcity);
3373 const struct civ_map *nmap = &(wld.map);
3374
3376 ptile, _index, _x, _y) {
3377 /* Bypass city_map_update_tile_now() for efficiency */
3380}
3381
3382/************************************************************************/
3393
3394/************************************************************************/
3405{
3406 adjc_iterate(&(wld.map), ptile, tile1) {
3407 struct city *pcity = tile_city(tile1);
3408
3409 if (pcity) {
3410 struct player *pplayer = city_owner(pcity);
3411 const struct req_context city_ctxt = {
3412 .player = pplayer,
3413 .city = pcity,
3414 .tile = pcity->tile,
3415 };
3416
3417 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3418 city_built_iterate(pcity, pimprove) {
3419 if (!can_city_sell_building(pcity, pimprove)) {
3420 continue;
3421 }
3422
3423 requirement_vector_iterate(&pimprove->reqs, preq) {
3424 if ((VUT_TERRAIN == preq->source.kind
3425 || VUT_TERRAINCLASS == preq->source.kind
3426 || VUT_TERRFLAG == preq->source.kind)
3427 && !is_req_active(&city_ctxt, nullptr, preq, RPT_CERTAIN)) {
3428 int price = impr_sell_gold(pimprove);
3429
3430 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3432 PL_("You sell %s in %s (now landlocked)"
3433 " for %d gold.",
3434 "You sell %s in %s (now landlocked)"
3435 " for %d gold.", price),
3438 }
3441 }
3443}
3444
3445/************************************************************************/
3452{
3453 if (pcity->server.vision != nullptr) {
3454 v_radius_t vision_radius_sq
3456
3457 vision_change_sight(pcity->server.vision, vision_radius_sq);
3459 }
3460}
3461
3462/************************************************************************/
3467{
3468 city_list_iterate(pplayer->cities, pcity) {
3471}
3472
3473/************************************************************************/
3477{
3478 fc_assert_ret_val(pcity != nullptr, FALSE);
3479
3484 const struct civ_map *nmap = &(wld.map);
3485
3486 /* Check minimum / maximum allowed city radii */
3489
3491 /* No change */
3492 return FALSE;
3493 }
3494
3495 /* Get number of city tiles for each radii */
3498
3500 /* A change of the squared city radius but no change of the number of
3501 * city tiles */
3502 return FALSE;
3503 }
3504
3505 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3507
3508 /* Workers map before */
3509 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3513
3515
3517 /* Increased number of city tiles */
3519 } else {
3520 /* Reduced number of city tiles */
3521 int workers = 0;
3522
3523 /* Remove workers from the tiles removed rom the city map */
3525 city_x, city_y) {
3526 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3528 city_y);
3529
3530 if (ptile && pcity == tile_worked(ptile)) {
3532 workers++;
3533 }
3535
3536 /* Add workers to free city tiles */
3537 if (workers > 0) {
3538 int radius_sq = city_map_radius_sq_get(pcity);
3539
3541 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3542 city_x, city_y);
3543
3544 if (ptile && !is_free_worked(pcity, ptile)
3545 && tile_worked(ptile) != pcity
3546 && city_can_work_tile(pcity, ptile)) {
3548 workers--;
3549 }
3550
3551 if (workers <= 0) {
3552 break;
3553 }
3555 }
3556
3557 /* If there still are workers they will be updated to specialists */
3558 if (workers > 0) {
3559 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3560 }
3561
3563 }
3564
3565 /* City removal might be ongoing, and advisor data already deleted */
3566 if (pcity->server.adv != nullptr) {
3567 /* If city is under AI control, update it */
3569 }
3570
3572 ftc_server, _("The size of the city map of %s is %s."),
3574 city_tiles_old < city_tiles_new ? _("increased")
3575 : _("reduced"));
3576
3577 /* Workers map after */
3578 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3582
3583 return TRUE;
3584}
3585
3586/************************************************************************/
3590{
3591 struct packet_worker_task packet;
3592
3593 if (ptask == nullptr) {
3594 return;
3595 }
3596
3597 worker_task_list_remove(pcity->task_reqs, ptask);
3598
3599 packet.city_id = pcity->id;
3600 packet.tile_id = tile_index(ptask->ptile);
3601 packet.activity = ACTIVITY_LAST;
3602 packet.tgt = 0;
3603 packet.want = 0;
3604
3605 free(ptask);
3606
3609}
3610
3611/************************************************************************/
3615{
3616 while (worker_task_list_size(pcity->task_reqs) > 0) {
3618 }
3619}
3620
3621/************************************************************************/
3625{
3626 struct packet_worker_task packet;
3627
3628 packet.city_id = pcity->id;
3629
3630 worker_task_list_iterate(pcity->task_reqs, ptask) {
3631 packet.tile_id = tile_index(ptask->ptile);
3632 packet.activity = ptask->act;
3633 if (ptask->tgt == nullptr) {
3634 packet.tgt = -1;
3635 } else {
3636 packet.tgt = extra_number(ptask->tgt);
3637 }
3638 packet.want = ptask->want;
3639
3643}
3644
3645/************************************************************************/
3649{
3650 int build = pcity->shield_stock;
3651
3652 switch (pcity->production.kind) {
3653 case VUT_IMPROVEMENT:
3654 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3655 build);
3656 case VUT_UTYPE:
3657 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3658 build);
3659 default:
3660 break;
3661 };
3662
3663 return FC_INFINITY;
3664}
3665
3666/************************************************************************/
3671 const struct impr_type *pimprove,
3672 const char *format)
3673{
3674 if (is_wonder(pimprove)) {
3675 /* Only wonders may grant governments */
3676 struct cur_govs_data *govs_data;
3677 char buf[250];
3678
3680 city_add_improvement(pcity, pimprove);
3681
3682 fc_snprintf(buf, sizeof(buf), format,
3684
3685 players_iterate_alive(pplayer) {
3688
3690 } else {
3691 city_add_improvement(pcity, pimprove);
3692 }
3693}
3694
3695/************************************************************************/
3700 const struct player *known_for)
3701{
3702 if (pcity->original == nullptr) {
3703 /* Nobody knows */
3704 return MAX_NUM_PLAYER_SLOTS;
3705 }
3706
3707 if (pcity->original != known_for
3708 || known_for == nullptr) {
3709 /* Players know what they have built themselves,
3710 * global observer knows everything. */
3711 return player_number(pcity->original);
3712 }
3713
3714 return MAX_NUM_PLAYER_SLOTS;
3715}
#define ACTION_NONE
Definition actions.h:55
const struct action * action_auto_perf_unit_do(const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit, const struct extra_type *target_extra)
void advisor_choose_build(struct player *pplayer, struct city *pcity)
int adv_could_unit_move_to_tile(struct unit *punit, struct tile *dest_tile)
Definition advgoto.c:359
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
#define n
Definition astring.c:77
bool is_land_barbarian(struct player *pplayer)
Definition barbarian.c:75
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:142
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:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:121
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
#define BV_ISSET_ANY(vec)
Definition bitvector.h:117
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:3626
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:3396
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:3455
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:3382
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:3342
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:3597
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:3651
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:700
#define cities_iterate_end
Definition city.h:514
@ CNA_BROADCAST_PENDING
Definition city.h:305
@ CNA_NOT
Definition city.h:303
@ CNA_NORMAL
Definition city.h:304
#define city_list_iterate(citylist, pcity)
Definition city.h:505
#define city_tile(_pcity_)
Definition city.h:561
#define cities_iterate(pcity)
Definition city.h:509
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:83
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:211
@ CITIZEN_ANGRY
Definition city.h:268
@ CITIZEN_HAPPY
Definition city.h:265
@ CITIZEN_CONTENT
Definition city.h:266
@ CITIZEN_UNHAPPY
Definition city.h:267
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:81
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
Definition city.h:185
#define output_type_iterate(output)
Definition city.h:842
#define city_owner(_pcity_)
Definition city.h:560
#define city_tile_iterate_skip_free_worked_end
Definition city.h:219
#define city_list_iterate_end
Definition city.h:507
#define city_map_iterate_radius_sq_end
Definition city.h:190
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:227
@ FEELING_LAST
Definition city.h:282
#define city_tile_iterate_end
Definition city.h:235
#define city_built_iterate(_pcity, _p)
Definition city.h:831
#define city_map_iterate_without_index_end
Definition city.h:181
#define city_built_iterate_end
Definition city.h:837
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:177
#define output_type_iterate_end
Definition city.h:848
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3277
void city_freeze_workers_queue(struct city *pcity)
Definition citytools.c:160
void package_city(struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct trade_route_packet_list *routes, bool dipl_invest)
Definition citytools.c:2531
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3342
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1681
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:2160
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3303
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3624
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3648
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2368
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2776
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:3027
static void raze_city(struct city *pcity)
Definition citytools.c:928
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1435
static bool city_workers_queue_remove(struct city *pcity)
Definition citytools.c:184
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:2220
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2181
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1520
bool send_city_suppression(bool now)
Definition citytools.c:2170
static bool send_city_suppressed
Definition citytools.c:101
void sync_cities(void)
Definition citytools.c:3351
static const char * search_for_city_name(struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
Definition citytools.c:338
static void announce_trade_route_removal(struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
Definition citytools.c:2886
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:136
void update_unit_upkeep(struct unit *punit, int free_uk[O_LAST])
Definition citytools.c:3114
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3466
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3699
static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders)
Definition citytools.c:1019
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3476
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:3188
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3060
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3385
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2979
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3334
void city_thaw_workers(struct city *pcity)
Definition citytools.c:146
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2868
static bool is_default_city_name(const char *name, struct player *pplayer)
Definition citytools.c:320
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3077
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1992
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3589
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:962
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3165
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3614
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:3404
void remove_city(struct city *pcity)
Definition citytools.c:1713
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:3005
static struct city_list * arrange_workers_queue
Definition citytools.c:98
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2943
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2420
static int evaluate_city_name_priority(struct tile *ptile, const struct nation_city *pncity, int default_priority)
Definition citytools.c:219
void city_thaw_workers_queue(void)
Definition citytools.c:197
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2249
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:1077
void city_add_improvement_with_gov_notice(struct city *pcity, const struct impr_type *pimprove, const char *format)
Definition citytools.c:3670
void send_player_cities(struct player *pplayer)
Definition citytools.c:2348
void city_map_update_all(struct city *pcity)
Definition citytools.c:3370
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:3291
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2847
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2324
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3451
#define trade_route_packet_list_iterate_end
Definition citytools.h:28
#define LOG_BUILD_TARGET
Definition citytools.h:21
#define trade_route_packet_list_iterate(ptrlist, ptr)
Definition citytools.h:26
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:366
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:197
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3567
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4620
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:762
bool city_refresh(struct city *pcity)
Definition cityturn.c:158
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:182
void city_refresh_queue_processing(void)
Definition cityturn.c:213
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:235
enum announce_type announce
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2174
char * incite_cost
Definition comments.c:76
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:2426
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 const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1066
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:980
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
enum event_type event
Definition events.c:81
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:641
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
#define MAX_NUM_BUILDING_LIST
Definition fc_types.h:46
unsigned char citizens
Definition fc_types.h:247
int Impr_type_id
Definition fc_types.h:235
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
@ RPT_CERTAIN
Definition fc_types.h:533
#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:231
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:92
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
void fc_mutex_allocate(fc_mutex *mutex)
void fc_mutex_release(fc_mutex *mutex)
const char * city_tile_link(const struct city *pcity)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
const char * unit_link(const struct unit *punit)
const char * unit_tile_link(const struct unit *punit)
#define MAX_LEN_LINK
struct civ_game game
Definition game.c:61
struct city * game_city_by_name(const char *name)
Definition game.c:87
struct world wld
Definition game.c:62
struct unit * game_unit_by_number(int id)
Definition game.c:115
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:184
struct city * game_city_by_number(int id)
Definition game.c:106
#define any_web_conns()
Definition game.h:324
@ CNM_PLAYER_UNIQUE
Definition game.h:46
@ CNM_GLOBAL_UNIQUE
Definition game.h:47
@ CNM_NO_STEALING
Definition game.h:48
void send_game_info(struct conn_list *dest)
Definition gamehand.c:910
struct city * owner
Definition citydlg.c:226
static GtkWidget * source
Definition gotodlg.c:58
GType type
Definition repodlgs.c:1313
static const int bufsz
Definition helpdlg.c:70
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
@ H_PRODCHGPEN
Definition handicaps.h:35
void idex_register_city(struct world *iworld, struct city *pcity)
Definition idex.c:67
struct impr_type * improvement_by_number(const Impr_type_id id)
int impr_sell_gold(const struct impr_type *pimprove)
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
bool is_improvement_visible(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
struct city * city_from_great_wonder(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
void adv_city_free(struct city *pcity)
Definition infracache.c:502
void adv_city_update(struct city *pcity)
Definition infracache.c:463
void adv_city_alloc(struct city *pcity)
Definition infracache.c:489
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:206
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_base(level, message,...)
Definition log.h:95
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:209
int map_num_tiles(void)
Definition map.c:1152
bool is_safe_ocean(const struct civ_map *nmap, const struct tile *ptile)
Definition map.c:712
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
#define adjc_iterate_end
Definition map.h:430
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:425
#define whole_map_iterate(_map, _tile)
Definition map.h:573
#define whole_map_iterate_end
Definition map.h:582
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2489
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2171
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:899
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2577
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:489
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1372
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:773
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:416
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2680
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:925
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1164
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2250
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1444
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:239
void map_clear_border(struct tile *ptile)
Definition maphand.c:2201
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1387
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2477
#define map_get_player_site(_ptile_, _pplayer_)
Definition maphand.h:93
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
bool can_exist_at_tile(const struct civ_map *nmap, const struct unit_type *utype, const struct tile *ptile)
Definition movement.c:289
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:318
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:330
bool is_city_channel_tile(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
Definition movement.c:242
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:490
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:464
const char * nation_city_name(const struct nation_city *pncity)
Definition nation.c:412
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Definition nation.c:331
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
enum nation_city_preference nation_city_preference_revert(enum nation_city_preference prefer)
Definition nation.c:371
Nation_type_id nation_count(void)
Definition nation.c:507
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
enum nation_city_preference nation_city_terrain_preference(const struct nation_city *pncity, const struct terrain *pterrain)
Definition nation.c:422
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Definition nation.c:434
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:84
nation_city_preference
Definition nation.h:39
@ NCP_NONE
Definition nation.h:41
@ NCP_DISLIKE
Definition nation.h:40
@ NCP_LIKE
Definition nation.h:42
#define nation_city_list_iterate(citylist, pncity)
Definition nation.h:48
#define nation_list_iterate_end
Definition nation.h:86
#define nation_city_list_iterate_end
Definition nation.h:50
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c: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:1996
int player_index(const struct player *pplayer)
Definition player.c:829
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1133
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1149
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#define player_slots_iterate(_pslot)
Definition player.h:528
#define is_ai(plr)
Definition player.h:232
#define players_iterate_alive_end
Definition player.h:552
#define player_slots_iterate_end
Definition player.h:532
#define players_iterate_alive(_pplayer)
Definition player.h:547
int normal_player_count(void)
Definition plrhand.c:3209
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2963
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2364
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1148
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3008
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2915
void update_capital(struct player *pplayer)
Definition plrhand.c:731
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
#define allowed_nations_iterate_end
Definition plrhand.h:73
#define fc_rand(_size)
Definition rand.h:56
bool is_req_active(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type)
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
int universal_number(const struct universal *source)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
struct research * research_get(const struct player *pplayer)
Definition research.c:128
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:416
#define sanity_check_city(x)
Definition sanitycheck.h:41
void script_server_signal_emit(const char *signal_name,...)
void script_server_remove_exported_object(void *object)
static struct connection connections[MAX_NUM_CONNECTIONS]
Definition sernet.c:94
void flush_packets(void)
Definition sernet.c:376
static struct setting settings[]
Definition settings.c:1474
bool is_ascii_name(const char *name)
Definition shared.c:286
#define CLIP(lower, current, upper)
Definition shared.h:57
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
void spaceship_lost(struct player *pplayer)
Definition spacerace.c:431
@ SSHIP_STARTED
Definition spaceship.h:84
@ SSHIP_LAUNCHED
Definition spaceship.h:85
Specialist_type_id specialist_count(void)
Definition specialist.c:71
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
#define DEFAULT_SPECIALIST
Definition specialist.h:43
SPECPQ_PRIORITY_TYPE priority
Definition specpq.h:86
size_t size
Definition specvec.h:72
static int recursion[AIT_LAST]
Definition srv_log.c:45
int identity_number(void)
Definition srv_main.c:2061
enum server_states server_state(void)
Definition srv_main.c:338
Definition city.h:317
struct trade_route_list * routes
Definition city.h:341
citizens * nationality
Definition city.h:338
struct tile * tile
Definition city.h:319
enum city_names_mode allowed_city_names
Definition game.h:134
struct civ_game::@32::@36::@41 mutexes
bool vision_reveal_tiles
Definition game.h:207
struct conn_list * glob_observers
Definition game.h:98
fc_mutex city_list
Definition game.h:278
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:174
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:111
bool savepalace
Definition game.h:194
struct civ_game::@31 rgame
struct civ_game::@32::@36 server
int razechance
Definition game.h:183
int init_buildings[MAX_NUM_BUILDING_LIST]
Definition nation.h:123
struct nation_list * parent_nations
Definition nation.h:136
struct nation_type::@54::@56 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:281
bv_plr_flags flags
Definition player.h:292
char username[MAX_LEN_NAME]
Definition player.h:252
struct team * team
Definition player.h:261
struct conn_list * connections
Definition player.h:298
bool is_alive
Definition player.h:268
struct player_economic economic
Definition player.h:284
const struct player * player
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
Definition unit.h:140
int length
Definition unit.h:198
int upkeep[O_LAST]
Definition unit.h:150
int id
Definition unit.h:147
struct unit::@83 orders
bool moved
Definition unit.h:176
struct vision * vision
Definition unit.h:247
bool vigilant
Definition unit.h:200
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
enum unit_activity changed_from
Definition unit.h:171
struct unit_adv * adv
Definition unit.h:239
int homecity
Definition unit.h:148
struct unit * transporter
Definition unit.h:186
const struct unit_type * utype
Definition unit.h:141
struct player * owner
Definition unit.h:145
bool dying
Definition unit.h:253
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:960
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#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:266
#define terrain_type_iterate_end
Definition terrain.h:272
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
#define tile_claimer(_tile)
Definition tile.h:101
#define tile_index(_pt_)
Definition tile.h:89
#define tile_worked(_tile)
Definition tile.h:115
#define tile_terrain(_tile)
Definition tile.h:111
#define TILE_XY(ptile)
Definition tile.h:43
#define tile_continent(_tile)
Definition tile.h:93
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
#define tile_owner(_tile)
Definition tile.h:97
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
Goods_type_id goods_number(const struct goods_type *pgood)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2, int priority)
#define trade_routes_iterate_safe_end
@ TRI_CANCEL
Definition traderoutes.h:32
#define trade_routes_iterate_end
#define trade_routes_iterate_safe(c, proute)
#define trade_routes_iterate(c, proute)
trade_route_type
Definition traderoutes.h:37
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1959
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:865
#define unit_tile(_pu)
Definition unit.h:404
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:427
#define unit_owner(_pu)
Definition unit.h:403
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6663
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:4072
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void unit_make_contact(const struct unit *punit, struct tile *ptile, struct player *pplayer)
Definition unittools.c:5180
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1401
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2864
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2877
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:800
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2139
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:5021
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1225
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Definition unittype.c:1498
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:1593
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1933
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:393
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:270
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:862
#define unit_type_iterate_end
Definition unittype.h:869
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