Freeciv-3.4
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 /* Clear pointer to old owner's access areas */
1136 if (pcity->aarea != nullptr) {
1137 city_list_remove(pcity->aarea->cities, pcity);
1138 pcity->aarea = nullptr;
1139 }
1140
1141 /* Activate AI control of the new owner. */
1142 CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
1143
1145
1146 unit_list_iterate(pcity->units_supported, punit) {
1148 /* Mark unit to have no homecity at all.
1149 * 1. We remove unit from units_supported list here,
1150 * real_change_unit_homecity() should not attempt it.
1151 * 2. Otherwise we might delete the homecity from under the unit
1152 * in the client */
1153 punit->homecity = 0;
1154 send_unit_info(nullptr, punit);
1156 unit_list_clear(pcity->units_supported);
1157
1158 /* Remove all global improvement effects that this city confers (but
1159 then restore the local improvement list - we need this to restore
1160 the global effects for the new city owner) */
1162 city_built_iterate(pcity, pimprove) {
1163 if (is_small_wonder(pimprove)) {
1164 /* Small wonders are really removed (not restored later). */
1165 building_removed(pcity, pimprove, "conquered", nullptr);
1167 } else {
1168 city_remove_improvement(pcity, pimprove);
1169 if (is_great_wonder(pimprove)) {
1171 }
1172 /* Note: internal turn here, next city_built_iterate(). */
1173 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
1174 }
1176
1178 old_vision = pcity->server.vision;
1183
1185
1189
1192 _("You already had a city called %s."
1193 " The city was renamed to %s."),
1195 city_link(pcity));
1196
1198 }
1199
1200 /* Has to follow the unfog call above. */
1201 city_list_remove(pgiver->cities, pcity);
1203 /* city_thaw_workers_queue() later */
1204
1205 pcity->owner = ptaker;
1206 pcity->capital = CAPITAL_NOT;
1207 pcity->acquire_t = CACQ_CONQUEST;
1209 city_list_prepend(ptaker->cities, pcity);
1210
1211 if (could_see_unit != nullptr) {
1212 /* Hide/reveal units. Do it after vision have been given to taker, city
1213 * owner has been changed, and before any script could be spawned. */
1214 for (i = 0; i < units_num; i++) {
1216
1220 && !aunit->server.dying) {
1221 /* Reveal 'aunit'. */
1222 send_unit_info(aplayer->connections, aunit);
1223 }
1224 } else {
1226 /* Hide 'aunit'. */
1228 }
1229 }
1231 }
1232
1233 fc_assert(i == units_num);
1234
1236 could_see_unit = nullptr;
1237 }
1238
1240 pcity, nullptr,
1242 /* The units themselves are already freed by transfer_city_units(). */
1244
1245 if (resolve_stack) {
1247 }
1248
1249 if (!city_exist(saved_id)) {
1251 }
1252
1253 /* Reset turns owner counters */
1254 if (city_remains) {
1256 if (pcount->type == CB_CITY_OWNED_TURNS) {
1257 pcity->counter_values[pcount->index] = 0;
1258 }
1260 }
1261
1262 if (city_remains) {
1263 /* Update the city's trade routes. */
1265
1266 /* Clear CMA. */
1267 if (pcity->cm_parameter) {
1268 free(pcity->cm_parameter);
1269 pcity->cm_parameter = nullptr;
1270 }
1271
1273 }
1274
1275 /*
1276 * maybe_make_contact() MUST be called before city_map_update_all(),
1277 * since the diplomacy status can influence whether a tile is available.
1278 */
1280
1281 if (city_remains) {
1282 struct extra_type *upgradet;
1283
1284 if (raze) {
1286 }
1287
1288 if (taker_had_no_cities) {
1289 /* If conqueror previously had no cities, we might need to give
1290 * them a palace etc */
1291 if (build_free) {
1293 } /* Else caller should probably ensure palace is built */
1294
1295 BV_SET(ptaker->flags, PLRF_FIRST_CITY);
1296 }
1297
1299
1300 /* Restore any global improvement effects that this city confers */
1301 city_built_iterate(pcity, pimprove) {
1303 _("Transfer of %s"));
1305
1306 /* Set production to something valid for pplayer, if not.
1307 * (previously allowed building obsolete units.) */
1308 if (!can_city_build_now(nmap, pcity, &pcity->production, RPT_CERTAIN)) {
1310 }
1311
1312 /* What wasn't obsolete for the old owner may be so now. */
1314
1316
1317 if (new_extras) {
1318 const char *clink = city_link(pcity);
1319
1321 _("The people in %s are stunned by your "
1322 "technological insight!"),
1323 clink);
1324
1325 if (upgradet != nullptr) {
1327 _("Workers spontaneously gather and upgrade "
1328 "%s with %s."),
1330 } else {
1332 _("Workers spontaneously gather and upgrade "
1333 "%s infrastructure."),
1334 clink);
1335 }
1337 }
1338
1339 /* Build a new palace for free if the player lost their capital and
1340 savepalace is on. */
1342
1343 /* Refresh the city's vision range, since it might be different
1344 * under the new owner. */
1346
1347 /* Update the national borders, within the current vision and culture.
1348 * This could leave a border ring around the city, updated later by
1349 * map_calculate_borders() at the next turn.
1350 */
1352 /* city_thaw_workers_queue() later */
1353
1354 auto_arrange_workers(pcity); /* Does city_map_update_all() */
1356 city_thaw_workers_queue(); /* After old city has a chance to work! */
1358 /* No sanity check here as the city is not refreshed! */
1359 }
1360
1361 if (city_remains) {
1362 /* Send city with updated owner information to giver and to everyone
1363 * having shared vision pact with them before they may
1364 * lose vision to it. When we later send info to everybody seeing the city,
1365 * they may not be included. */
1366 send_city_info(nullptr, pcity);
1367 }
1368
1369 /* Remove the sight points from the giver. */
1370 vision_clear_sight(old_vision);
1371 vision_free(old_vision);
1372
1373 /* Send wonder infos. */
1374 if (had_great_wonders) {
1375 send_game_info(nullptr);
1376 if (city_remains) {
1377 send_player_info_c(ptaker, nullptr);
1378
1379 /* Refresh all cities of the taker to account for possible changes due
1380 * to player wide effects. */
1381 city_list_iterate(ptaker->cities, acity) {
1384 } else {
1385 /* Refresh all cities to account for possible global effects. */
1389 }
1390 }
1392 /* No need to send to detached connections. */
1393 send_player_info_c(pgiver, nullptr);
1394
1395 /* Refresh all cities of the giver to account for possible changes due
1396 * to player wide effects. */
1397 city_list_iterate(pgiver->cities, acity) {
1400 }
1401
1402 /* Refresh all cities in the queue. */
1404 /* After the refresh the sanity check can be done. */
1406
1407 if (city_remains) {
1408 /* Send information about conquered city to all players. */
1409 send_city_info(nullptr, pcity);
1410 }
1411
1412 /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to
1413 * refresh all cities for the player. */
1417 }
1421 }
1422
1423 if (pgiver->primary_capital_id == saved_id) {
1425 }
1426
1427 sync_cities();
1428
1429 CALL_FUNC_EACH_AI(city_info, pcity);
1430
1431 return city_remains;
1432}
1433
1434/************************************************************************/
1442{
1443 struct player *pplayer;
1444 struct nation_type *nation;
1445 int i;
1447 bool first_city;
1448
1449 fc_assert_ret(pcity != nullptr);
1450 pplayer = city_owner(pcity);
1451 fc_assert_ret(pplayer != nullptr);
1452 nation = nation_of_player(pplayer);
1453 fc_assert_ret(nation != nullptr);
1454
1455 /* If this isn't the first city a player has ever had, they only get
1456 * any initial buildings with the SaveSmallWonder flag, and then only
1457 * if savepalace is enabled. */
1459
1462
1463 /* Global free buildings. */
1464 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1466 struct impr_type *pimprove;
1467
1468 if (n == B_LAST) {
1469 break;
1470 }
1471
1472 pimprove = improvement_by_number(n);
1473 fc_assert_action(!is_great_wonder(pimprove), continue);
1474 if (first_city
1478 /* TRANS: Reason that a building was added to the city.
1479 * Building is given for free to player's first city. */
1480 Q_("?initbldg:Free %s"));
1481 if (is_small_wonder(pimprove)) {
1483 }
1484 }
1485 }
1486
1487 /* Nation specific free buildings. */
1488 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1489 Impr_type_id n = nation->init_buildings[i];
1490 struct impr_type *pimprove;
1491
1492 if (n == B_LAST) {
1493 break;
1494 }
1495
1496 pimprove = improvement_by_number(n);
1497 if (first_city
1501 /* TRANS: Reason that a building was added to the city.
1502 * Building is given for free to player's first city. */
1503 Q_("?initbldg:Free %s"));
1504 if (is_small_wonder(pimprove)) {
1506 } else if (is_great_wonder(pimprove)) {
1508 }
1509 }
1510 }
1511
1512 /* Update wonder infos. */
1513 if (has_great_wonders) {
1514 send_game_info(nullptr);
1515 /* No need to send to detached connections. */
1516 send_player_info_c(pplayer, nullptr);
1517 } else if (has_small_wonders) {
1518 /* No need to send to detached connections. */
1519 send_player_info_c(pplayer, nullptr);
1520 }
1521}
1522
1523/************************************************************************/
1526void create_city(struct player *pplayer, struct tile *ptile,
1527 const char *name, struct player *nationality)
1528{
1529 struct player *saved_owner = tile_owner(ptile);
1530 struct tile *saved_claimer = tile_claimer(ptile);
1531 struct city *pwork = tile_worked(ptile);
1532 struct city *pcity;
1535 const struct civ_map *nmap = &(wld.map);
1536
1537 log_debug("create_city() %s", name);
1538
1539 pcity = create_city_virtual(pplayer, ptile, name);
1540
1541 /* Remove units no more seen. Do it before city is really put into
1542 * the game. */
1543 players_iterate(other_player) {
1544 if (can_player_see_units_in_city(other_player, pcity)
1545 || !map_is_known_and_seen(ptile, other_player, V_MAIN)) {
1546 continue;
1547 }
1548 unit_list_iterate(ptile->units, punit) {
1549 if (can_player_see_unit(other_player, punit)) {
1550 unit_goes_out_of_sight(other_player, punit);
1551 }
1554
1556
1557 tile_set_owner(ptile, pplayer, ptile); /* Temporarily */
1560
1564
1565 if (city_list_size(pplayer->cities) == 0) {
1566 /* Free initial buildings, or at least a palace if they were
1567 * previously careless enough to lose all their cities */
1569 BV_SET(pplayer->flags, PLRF_FIRST_CITY);
1570 }
1571
1572 /* Set up citizens nationality. */
1574
1575 /* Place a worker at the is_city_center() is_free_worked().
1576 * It is possible to build a city on a tile that is already worked;
1577 * this will displace the worker on the newly-built city's tile -- Syela */
1578 tile_set_worked(ptile, pcity); /* Instead of city_map_update_worker() */
1579
1580 if (pwork != nullptr) {
1581 /* Was previously worked by another city */
1582 /* Turn citizen into specialist. */
1583 pwork->specialists[DEFAULT_SPECIALIST]++;
1584 /* One less citizen. Citizen sanity will be handled later in
1585 * city_thaw_workers_queue() */
1586 pwork->server.synced = FALSE;
1588 }
1589
1590 /* Update citizens. */
1591 citizens_update(pcity, nationality);
1592
1593 /* Restore the old-owner information so removal
1594 * of territory claiming bases can work relative to it. */
1596
1597 /* Destroy any extras that don't belong in the city. */
1598 extra_type_iterate(pextra) {
1599 if (tile_has_extra(ptile, pextra)
1600 && !is_native_tile_to_extra(pextra, ptile)) {
1601 destroy_extra(ptile, pextra);
1602 }
1604
1605 /* Build any extras that the city should have. */
1606 upgrade_city_extras(pcity, nullptr);
1607
1608 /* Claim the ground we stand on */
1609 map_claim_ownership(ptile, pplayer, ptile, TRUE);
1610
1611 /* Before arranging workers to show unknown land */
1612 pcity->server.vision = vision_new(pplayer, ptile);
1615 city_list_prepend(pplayer->cities, pcity);
1616
1617 /* This is dependent on the current vision, so must be done after
1618 * vision is prepared and before arranging workers. */
1619 map_claim_border(ptile, pplayer, -1);
1620 /* city_thaw_workers_queue() later */
1621
1622 /* Refresh the city. First a city refresh is done (this shouldn't
1623 * send any packets to the client because the city has no supported units)
1624 * then rearrange the workers. Note that auto_arrange_workers() does its
1625 * own refresh call; it is safest to do our own controlled city_refresh()
1626 * first. */
1629 city_thaw_workers_queue(); /* After new city has a chance to work! */
1631
1632 /* Bases destroyed earlier may have had watchtower effect. Refresh
1633 * unit vision. */
1635
1636 update_tile_knowledge(ptile);
1637
1640 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1641 * cities for the player. */
1642 city_refresh_for_player(pplayer);
1643 }
1644
1645 pcity->server.synced = FALSE;
1646 send_city_info(nullptr, pcity);
1647 sync_cities(); /* Will also send pwork. */
1648
1649 notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server,
1650 _("You have founded %s."),
1651 city_link(pcity));
1653
1654 unit_list_iterate((ptile)->units, punit) {
1656
1657 /* Catch fortress building, transforming into ocean, etc. */
1660 }
1661
1662 /* Update happiness (the unit may no longer cause unrest). */
1663 if (home) {
1664 if (city_refresh(home)) {
1665 /* Shouldn't happen, but better be safe than sorry. */
1667 }
1670 }
1672
1674
1675 script_server_signal_emit("city_built", pcity);
1676
1677 CALL_FUNC_EACH_AI(city_created, pcity);
1678 CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
1679}
1680
1681/************************************************************************/
1687bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1688 const char *name, struct player *nationality)
1689{
1690 const struct civ_map *nmap = &(wld.map);
1691
1692 if (is_enemy_unit_tile(ptile, pplayer)
1693 || !city_can_be_built_here(nmap, ptile, nullptr, FALSE)) {
1694 return FALSE;
1695 }
1696
1697 if (!pplayer->is_alive) {
1698 pplayer->is_alive = TRUE;
1699 send_player_info_c(pplayer, nullptr);
1700 }
1701
1702 if (name == nullptr || name[0] == '\0') {
1703 name = city_name_suggestion(pplayer, ptile);
1704 }
1705
1706 if (nationality == nullptr) {
1707 nationality = pplayer;
1708 }
1709
1710 map_show_tile(pplayer, ptile);
1711 create_city(pplayer, ptile, name, nationality);
1712
1713 return TRUE;
1714}
1715
1716/************************************************************************/
1720{
1721 struct player *powner = city_owner(pcity);
1722 struct tile *pcenter = city_tile(pcity);
1724 struct vision *old_vision;
1725 int id = pcity->id; /* We need this even after memory has been freed */
1726 bool had_great_wonders = FALSE;
1729 struct dbv tile_processed;
1730 struct tile_list *process_queue;
1731 const char *ctl = city_tile_link(pcity);
1732 const struct civ_map *nmap = &(wld.map);
1733
1734 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1735 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1736
1738 city_built_iterate(pcity, pimprove) {
1739 building_removed(pcity, pimprove, "city_destroyed", nullptr);
1740
1741 if (is_small_wonder(pimprove)) {
1743 } else if (is_great_wonder(pimprove)) {
1745 }
1747
1748 /* Rehome units in other cities */
1749 unit_list_iterate_safe(pcity->units_supported, punit) {
1751
1752 if (new_home_city
1753 && new_home_city != pcity
1754 && city_owner(new_home_city) == powner
1755 && !punit->server.dying) {
1757 }
1759
1760 /* Make sure ships are not left on land when city is removed. */
1762 bool moved;
1763 const struct unit_type *punittype = unit_type_get(punit);
1764
1765 /* can_exist_at_tile() would give wrong results, as
1766 * the city is still on map. */
1769 || is_safe_ocean(nmap, pcenter))) {
1770 continue;
1771 }
1772
1774 moved = FALSE;
1776 struct unit *ptrans;
1777
1780 /* Move */
1782 /* It may be impossible to survive at the tile even if it is
1783 * native. See UTYF_COAST_STRICT */
1785 } else {
1786 ptrans = nullptr;
1787 }
1790 nullptr, nullptr,
1792 nullptr) != nullptr) {
1793 moved = TRUE;
1794 }
1795 if (moved) {
1798 _("Moved %s out of disbanded city %s "
1799 "since it cannot stay on %s."),
1802 break;
1803 }
1804 }
1805 }
1807 if (!moved) {
1810 _("When %s was disbanded your %s could not "
1811 "get out, and it was therefore lost."),
1812 ctl,
1814 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1815 }
1817
1821 struct tile *ptile = tile_list_front(process_queue);
1822
1825 adjc_iterate(nmap, ptile, piter) {
1826 struct city *other_city;
1827
1829 continue;
1830 }
1832 if (other_city != nullptr) {
1833 /* Adjacent tile has a city that may have been part of same channel */
1838
1844 _("When %s was disbanded your %s in %s was trapped, "
1845 "and it was therefore lost."),
1846 ctl,
1849 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1850 }
1852 } else {
1854 }
1856 }
1857
1860
1861 if (!city_exist(id)) {
1862 /* Wiping trapped units caused city to disappear. */
1863 return;
1864 }
1865
1866 /* Any remaining supported units are destroyed */
1867 unit_list_iterate_safe(pcity->units_supported, punit) {
1868 wipe_unit(punit, ULR_CITY_LOST, nullptr);
1870
1871 if (!city_exist(id)) {
1872 /* Wiping supported units caused city to disappear. */
1873 return;
1874 }
1875
1878 TRUE, TRUE);
1879
1880 FC_FREE(proute);
1881 FC_FREE(pback);
1883
1888
1889 /* idex_unregister_city() is called in game_remove_city() below */
1890
1891 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1892 * still be alive in the client, or in the player map. The number of
1893 * removed cities is small, so the loss is acceptable. */
1894
1895 old_vision = pcity->server.vision;
1896 pcity->server.vision = nullptr;
1899
1900 /* Remove city from the map. */
1901 tile_set_worked(pcenter, nullptr);
1902
1903 /* Reveal units. */
1904 players_iterate(other_player) {
1905 if (can_player_see_units_in_city(other_player, pcity)
1906 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1907 continue;
1908 }
1910 if (can_player_see_unit(other_player, punit)) {
1911 send_unit_info(other_player->connections, punit);
1912 }
1915
1919
1920 /* Remove any extras that were only there because the city was there. */
1921 extra_type_iterate(pextra) {
1922 if (tile_has_extra(pcenter, pextra)
1923 && !is_native_tile_to_extra(pextra, pcenter)) {
1925 }
1927
1928 players_iterate(other_player) {
1929 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1930 reality_check_city(other_player, pcenter);
1931 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1932 map_show_tile(other_player, pcenter);
1933 }
1935
1937 if (pconn->playing == nullptr && pconn->observer) {
1938 /* For detached observers we have to send a specific packet. This is
1939 * a hack necessitated by the private map that exists for players but
1940 * not observers. */
1942 }
1944
1945 if (old_vision != NULL) {
1946 vision_clear_sight(old_vision);
1947 vision_free(old_vision);
1948 }
1949
1950 /* Infrastructures may have changed. */
1951 send_tile_info(nullptr, pcenter, FALSE);
1952
1953 /* Build a new palace for free if the player lost their capital and
1954 * savepalace is on. */
1956
1957 /* Update wonder infos. */
1958 if (had_great_wonders) {
1959 send_game_info(nullptr);
1960 /* No need to send to detached connections. */
1961 send_player_info_c(powner, nullptr);
1962 } else if (BV_ISSET_ANY(had_small_wonders)) {
1963 /* No need to send to detached connections. */
1964 send_player_info_c(powner, nullptr);
1965 }
1966
1969 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1970 * cities for the player. */
1972 }
1973
1974 sync_cities();
1975
1976 /* At least sentried helicopters need to go idle, maybe others.
1977 * In alien ruleset, city center might have provided water source
1978 * for adjacent tile. */
1980}
1981
1982/************************************************************************/
1998bool unit_conquer_city(struct unit *punit, struct city *pcity)
1999{
2000 bool try_civil_war = FALSE;
2001 bool city_remains;
2002 int coins;
2003 struct player *pplayer = unit_owner(punit);
2004 struct player *cplayer = city_owner(pcity);
2005#ifndef FREECIV_NDEBUG
2006 const struct unit_type *utype = unit_type_get(punit);
2007#endif
2008
2009 /* If not at war, may peacefully enter city. */
2011 "Can't conquer city during peace.");
2012
2013 /* If we cannot occupy the city, this unit entering will not trigger
2014 * effects below. */
2018 FALSE, "Bad unit for city occupation.");
2019
2020 /* A transported unit trying to conquer a city should already have been
2021 * unloaded. */
2023 "Can't conquer city while transported.");
2024
2025 /* Okay, we're at war - invader captures/destroys city... */
2026
2027 /* If a capital is captured, then spark off a civil war
2028 * - Kris Bubendorfer
2029 * Also check spaceships --dwp */
2030
2031 if (is_capital(pcity)
2032 && (cplayer->spaceship.state == SSHIP_STARTED
2033 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
2035 }
2036
2037 if (is_capital(pcity)
2042 }
2043
2044 /*
2045 * We later remove a citizen. Lets check if we can save this since
2046 * the city will be destroyed.
2047 */
2048 if (city_size_get(pcity) <= 1) {
2049 int saved_id = pcity->id;
2050
2052 _("You destroy %s completely."),
2055 _("%s has been destroyed by %s."),
2056 city_tile_link(pcity), player_name(pplayer));
2057 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2058
2059 /* We can't be sure of city existence after running some script */
2060 if (city_exist(saved_id)) {
2062 }
2063
2064 if (try_civil_war) {
2066 }
2067 return TRUE;
2068 }
2069
2071 coins = MIN(coins,
2072 fc_rand((coins / 20) + 1)
2073 + (coins * (city_size_get(pcity))) / 200);
2074 pplayer->economic.gold += coins;
2075 cplayer->economic.gold -= coins;
2076 send_player_info_c(pplayer, pplayer->connections);
2077 send_player_info_c(cplayer, cplayer->connections);
2078 if (pcity->original != pplayer) {
2079 if (coins > 0) {
2081 PL_("You conquer %s; your lootings accumulate"
2082 " to %d gold!",
2083 "You conquer %s; your lootings accumulate"
2084 " to %d gold!", coins),
2086 coins);
2088 PL_("%s conquered %s and looted %d gold"
2089 " from the city.",
2090 "%s conquered %s and looted %d gold"
2091 " from the city.", coins),
2092 player_name(pplayer),
2094 coins);
2095 } else {
2097 _("You conquer %s."),
2098 city_link(pcity));
2100 _("%s conquered %s."),
2101 player_name(pplayer),
2102 city_link(pcity));
2103 }
2104 } else {
2105 if (coins > 0) {
2107 PL_("You have liberated %s!"
2108 " Lootings accumulate to %d gold.",
2109 "You have liberated %s!"
2110 " Lootings accumulate to %d gold.", coins),
2112 coins);
2114 PL_("%s liberated %s and looted %d gold"
2115 " from the city.",
2116 "%s liberated %s and looted %d gold"
2117 " from the city.", coins),
2118 player_name(pplayer),
2120 coins);
2121 } else {
2123 _("You have liberated %s!"),
2124 city_link(pcity));
2126 _("%s liberated %s."),
2127 player_name(pplayer),
2128 city_link(pcity));
2129 }
2130 }
2131
2133 /* Just try to steal. Ignore failures to get tech */
2134 steal_a_tech(pplayer, cplayer, A_UNSET);
2135 }
2136
2137 /* We transfer the city first so that it is in a consistent state when
2138 * the size is reduced. */
2139 /* FIXME: maybe it should be a ruleset option whether barbarians get
2140 * free buildings such as palaces? */
2141 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2142 !is_barbarian(pplayer));
2143
2144 if (city_remains) {
2145 /* Reduce size should not destroy this city */
2147 city_reduce_size(pcity, 1, pplayer, "conquest");
2148 }
2149
2150 if (try_civil_war) {
2152 }
2153
2154 if (city_remains) {
2155 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2156 "conquest");
2157 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2158 }
2159
2160 return TRUE;
2161}
2162
2163/************************************************************************/
2166static int city_citywalls_gfx(const struct city *pcity)
2167{
2169
2170 return walls > 0 ? walls : 0;
2171}
2172
2173/************************************************************************/
2177{
2179
2181 return formerly;
2182}
2183
2184/************************************************************************/
2187static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2188 struct packet_city_short_info *packet)
2189{
2190 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2191
2192 packet->id = pdcity->identity;
2194
2195 if (pdcity->original != NULL) {
2196 packet->original = player_number(pdcity->original);
2197 } else {
2199 }
2200
2201 packet->tile = tile_index(ptile);
2202 if (pdcity->name == nullptr) {
2203 packet->name[0] = '\0';
2204 } else {
2205 sz_strlcpy(packet->name, pdcity->name);
2206 }
2207
2208 packet->size = vision_site_size_get(pdcity);
2209
2210 packet->occupied = pdcity->occupied;
2211 packet->walls = pdcity->walls;
2212 packet->style = pdcity->style;
2213 packet->city_image = pdcity->city_image;
2214 packet->capital = pdcity->capital;
2215
2216 packet->happy = pdcity->happy;
2217 packet->unhappy = pdcity->unhappy;
2218
2219 packet->improvements = pdcity->improvements;
2220}
2221
2222/************************************************************************/
2227{
2228 players_iterate(pplayer) {
2229 if (player_can_see_city_externals(pplayer, pcity)) {
2230 if (update_dumb_city(pplayer, pcity)) {
2231 struct packet_city_short_info packet;
2232
2233 if (city_owner(pcity) != pplayer) {
2234 /* Don't send the short_city information to someone who can see
2235 * city's internals. Doing so would really confuse the client. */
2236 package_dumb_city(pplayer, pcity->tile, &packet);
2237 lsend_packet_city_short_info(pplayer->connections, &packet);
2238 }
2239 }
2240 }
2242
2243 /* Don't send to non-player observers since they don't have 'dumb city'
2244 * information. */
2245}
2246
2247/************************************************************************/
2256{
2257 struct packet_city_info packet;
2262 struct player *powner = city_owner(pcity);
2263 struct trade_route_packet_list *routes;
2265
2266 /* Send to everyone who can see the city. */
2267
2268 if (pcity->server.needs_arrange != CNA_NOT) {
2269 /* Send city only when it's in sane state.
2270 * If it's not, it will be sent to everyone once
2271 * rearrangement has been finished. */
2272 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2273
2274 return;
2275 }
2276
2277 if (any_web_conns()) {
2279 } else {
2280 webp_ptr = nullptr;
2281 }
2282
2283 routes = trade_route_packet_list_new();
2285 webp_ptr, routes, FALSE);
2286
2287 players_iterate(pplayer) {
2288 if (!send_city_suppressed || pplayer != powner) {
2289 if (can_player_see_city_internals(pplayer, pcity)) {
2290 update_dumb_city(pplayer, pcity);
2291 packet.original = city_original_owner(pcity, pplayer);
2292 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2293 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2294 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2295 web_lsend_packet(city_info_addition, pplayer->connections,
2296 webp_ptr, FALSE);
2298 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2300 } else if (player_can_see_city_externals(pplayer, pcity)) {
2301 reality_check_city(pplayer, pcity->tile);
2302 update_dumb_city(pplayer, pcity);
2303 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2304 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2305 }
2306 }
2308
2309 /* Send to global observers. */
2310 packet.original = city_original_owner(pcity, nullptr);
2317 }
2319
2324}
2325
2326/************************************************************************/
2331{
2332 conn_list_do_buffer(dest);
2333 conn_list_iterate(dest, pconn) {
2334 struct player *pplayer = pconn->playing;
2335
2336 if (!pplayer && !pconn->observer) {
2337 continue;
2338 }
2339 whole_map_iterate(&(wld.map), ptile) {
2340 if (pplayer == nullptr
2341 || map_get_player_site(ptile, pplayer) != nullptr) {
2342 send_city_info_at_tile(pplayer, pconn->self, nullptr, ptile);
2343 }
2345 }
2348 flush_packets();
2349}
2350
2351/************************************************************************/
2354void send_player_cities(struct player *pplayer)
2355{
2356 city_list_iterate(pplayer->cities, pcity) {
2357 if (city_refresh(pcity)) {
2358 log_error("%s radius changed while sending to player.",
2360
2361 /* Make sure that no workers in illegal position outside radius. */
2363 }
2364 send_city_info(pplayer, pcity);
2365 }
2367}
2368
2369/************************************************************************/
2374void send_city_info(struct player *dest, struct city *pcity)
2375{
2376 struct player *powner = city_owner(pcity);
2377
2378 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2379 return;
2380 }
2381
2382 if (dest == powner && send_city_suppressed) {
2383 return;
2384 }
2385
2386 if (!dest || dest == powner) {
2387 pcity->server.synced = TRUE;
2388 }
2389
2390 if (!dest) {
2392 } else {
2394 }
2395
2396 /* Sending counters */
2398
2400 && player_list_size(team_members(powner->team)) > 1) {
2401 /* We want to send the new total bulbs production of the team. */
2402 send_research_info(research_get(powner), nullptr);
2403 }
2404}
2405
2406/************************************************************************/
2427 struct city *pcity, struct tile *ptile)
2428{
2429 struct packet_city_info packet;
2434 struct player *powner = nullptr;
2435 struct trade_route_packet_list *routes = nullptr;
2437
2438 if (!pcity) {
2439 pcity = tile_city(ptile);
2440 }
2441 if (pcity != nullptr && pcity->server.needs_arrange != CNA_NOT) {
2442 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2443
2444 return;
2445 }
2446 if (pcity) {
2447 powner = city_owner(pcity);
2448 }
2449
2450 if (any_web_conns()) {
2452 } else {
2453 webp_ptr = nullptr;
2454 }
2455
2456 if (powner != nullptr && powner == pviewer) {
2457 /* Send info to owner */
2458 /* This case implies powner non-nullptr which means pcity non-nullptr */
2459 if (!send_city_suppressed) {
2460 /* Wait that city has been rearranged, if it's currently
2461 * not in a sane state. */
2462
2463 routes = trade_route_packet_list_new();
2464
2465 /* Send all info to the owner */
2466 update_dumb_city(powner, pcity);
2468 webp_ptr, routes, FALSE);
2470 lsend_packet_city_info(dest, &packet, FALSE);
2477 if (dest == powner->connections) {
2478 /* HACK: send also a copy to global observers. */
2479 packet.original = city_original_owner(pcity, nullptr);
2486 }
2488 }
2489 }
2490 } else {
2491 /* Send info to non-owner */
2492 if (!pviewer) { /* Observer */
2493 if (pcity) {
2494 routes = trade_route_packet_list_new();
2495
2496 /* Should be dumb_city info? */
2498 webp_ptr, routes, FALSE);
2499 lsend_packet_city_info(dest, &packet, FALSE);
2506 }
2507 } else {
2508 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2509 if (pcity) { /* It's there and we see it; update and send */
2513 }
2514 } else { /* Not seen; send old info */
2515 if (map_is_known(ptile, pviewer)
2516 && map_get_player_site(ptile, pviewer) != nullptr) {
2519 }
2520 }
2521 }
2522 }
2523
2524 if (routes != nullptr) {
2529 }
2530}
2531
2532/************************************************************************/
2537void package_city(struct city *pcity, struct packet_city_info *packet,
2541 struct trade_route_packet_list *routes,
2542 bool dipl_invest)
2543{
2544 int i;
2545 int ppl = 0; /* Counter of citizens for sanity check */
2546
2547 fc_assert(!pcity->server.needs_arrange);
2548
2549 packet->id = pcity->id;
2550 packet->owner = player_number(city_owner(pcity));
2551
2552 packet->tile = tile_index(city_tile(pcity));
2554
2555 packet->size = city_size_get(pcity);
2556 for (i = 0; i < FEELING_LAST; i++) {
2557 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2558 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2559 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2560 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2561 if (i == 0) {
2562 ppl += packet->ppl_happy[i];
2563 ppl += packet->ppl_content[i];
2564 ppl += packet->ppl_unhappy[i];
2565 ppl += packet->ppl_angry[i];
2566 }
2567 }
2568 /* The number of data in specialists[] array */
2571 packet->specialists[sp] = pcity->specialists[sp];
2573 ppl += packet->specialists[sp];
2574 }
2576
2577 /* The nationality of the citizens. */
2578 nat_packet->id = pcity->id;
2579 nat_packet->nationalities_count = 0;
2581 int cit = 0;
2582
2583 player_slots_iterate(pslot) {
2584 citizens nationality = citizens_nation_get(pcity, pslot);
2585
2586 if (nationality != 0) {
2587 /* This player should exist! */
2588 fc_assert(player_slot_get_player(pslot) != nullptr);
2589
2590 nat_packet->nation_id[nat_packet->nationalities_count]
2591 = player_slot_index(pslot);
2592 nat_packet->nation_citizens[nat_packet->nationalities_count]
2593 = nationality;
2594 nat_packet->nationalities_count++;
2595
2596 cit += nationality;
2597 }
2599
2600 fc_assert(cit == packet->size);
2601 }
2602
2603 packet->history = pcity->history;
2604 packet->culture = city_culture(pcity);
2606
2607 if (packet->size != ppl) {
2608 static bool recursion = FALSE;
2609
2610 if (recursion) {
2611 /* Recursion didn't help. Do not enter infinite recursive loop.
2612 * Package city as it is. */
2613 log_error("Failed to fix inconsistent city size.");
2614 recursion = FALSE;
2615 } else {
2616 /* Note: If you get this error and try to debug the cause, you may find
2617 * using check_city_feelings() in some key points useful. */
2618 /* Have this as an fc_assert() first, so one can use '-F' to caught
2619 * these in debugger. */
2620 fc_assert(packet->size == ppl);
2621
2622 /* In all builds have an error message shown. */
2623 log_error("City size %d, citizen count %d for %s",
2624 packet->size, ppl, city_name_get(pcity));
2625
2626 /* Try to fix */
2629
2630 /* And repackage */
2631 recursion = TRUE;
2633 web_packet, routes, dipl_invest);
2634 recursion = FALSE;
2635
2636 return;
2637 }
2638 }
2639
2640 packet->city_radius_sq = pcity->city_radius_sq;
2641
2642 i = 0;
2645 = fc_malloc(sizeof(struct packet_trade_route_info));
2646
2647 tri_packet->city = pcity->id;
2648 tri_packet->index = i;
2649 tri_packet->partner = proute->partner;
2650 tri_packet->value = proute->value;
2651 tri_packet->direction = proute->dir;
2652 tri_packet->goods = goods_number(proute->goods);
2653
2655
2656 i++;
2658
2659 packet->trade_route_count = i;
2660
2662 packet->surplus[o] = pcity->surplus[o];
2663 packet->waste[o] = pcity->waste[o];
2664 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2665 packet->prod[o] = pcity->prod[o];
2666 packet->citizen_base[o] = pcity->citizen_base[o];
2667 packet->usage[o] = pcity->usage[o];
2669
2670 packet->food_stock = pcity->food_stock;
2671 packet->shield_stock = pcity->shield_stock;
2672 packet->pollution = pcity->pollution;
2673 packet->illness_trade = pcity->illness_trade;
2674 packet->city_options = pcity->city_options;
2675 packet->wl_cb = pcity->wlcb;
2676
2677 if (!dipl_invest) {
2678 packet->acquire_type = pcity->acquire_t;
2679 } else {
2680 /* Dummy value */
2681 packet->acquire_type = CACQ_CONQUEST;
2682 }
2683
2684 packet->production_kind = pcity->production.kind;
2685 packet->production_value = universal_number(&pcity->production);
2686
2687 packet->turn_last_built = pcity->turn_last_built;
2688 packet->turn_founded = pcity->turn_founded;
2689
2690 packet->changed_from_kind = pcity->changed_from.kind;
2692
2693 packet->before_change_shields = pcity->before_change_shields;
2694 packet->disbanded_shields = pcity->disbanded_shields;
2695 packet->caravan_shields = pcity->caravan_shields;
2696 packet->last_turns_shield_surplus = pcity->last_turns_shield_surplus;
2697
2698 worklist_copy(&packet->worklist, &pcity->worklist);
2700
2701 packet->airlift = pcity->airlift;
2702 packet->did_buy = pcity->did_buy;
2703 packet->did_sell = pcity->did_sell;
2704 packet->was_happy = pcity->was_happy;
2705 packet->had_famine = pcity->had_famine;
2706
2707 packet->anarchy = pcity->anarchy;
2708 packet->rapture = pcity->rapture;
2709
2710 packet->walls = city_citywalls_gfx(pcity);
2711 packet->style = pcity->style;
2713 packet->capital = pcity->capital;
2714 packet->steal = pcity->steal;
2715
2716 rally_packet->id = pcity->id;
2717 rally_packet->length = pcity->rally_point.length;
2718 rally_packet->persistent = pcity->rally_point.persistent;
2719 rally_packet->vigilant = pcity->rally_point.vigilant;
2720 if (pcity->rally_point.length) {
2721 memcpy(rally_packet->orders, pcity->rally_point.orders,
2722 pcity->rally_point.length * sizeof(struct unit_order));
2723 }
2724
2725 BV_CLR_ALL(packet->improvements);
2726 improvement_iterate(pimprove) {
2727 if (city_has_building(pcity, pimprove)) {
2728 BV_SET(packet->improvements, improvement_index(pimprove));
2729 }
2731
2732#ifdef FREECIV_WEB
2733 if (web_packet != nullptr) {
2734 struct tile *pcenter = city_tile(pcity);
2735 const struct civ_map *nmap = &(wld.map);
2736
2737 BV_CLR_ALL(web_packet->can_build_unit);
2738 BV_CLR_ALL(web_packet->can_build_improvement);
2739
2740 web_packet->id = pcity->id;
2741
2742 if (pcity->cm_parameter != nullptr) {
2743 web_packet->cma_enabled = TRUE;
2744 cm_copy_parameter(&web_packet->cm_parameter, pcity->cm_parameter);
2745 } else {
2746 web_packet->cma_enabled = FALSE;
2747 memset(&web_packet->cm_parameter, 0, sizeof(web_packet->cm_parameter));
2748 }
2749
2751 web_packet->granary_turns = city_turns_to_grow(pcity);
2752
2753 improvement_iterate(pimprove) {
2755 BV_SET(web_packet->can_build_improvement, improvement_index(pimprove));
2756 }
2758
2761 BV_SET(web_packet->can_build_unit, utype_index(punittype));
2762 }
2764
2765 i = 0;
2767 web_packet->output_food[i] = city_tile_output_now(pcity, ptile, O_FOOD);
2768 web_packet->output_shield[i] = city_tile_output_now(pcity, ptile, O_SHIELD);
2769 web_packet->output_trade[i] = city_tile_output_now(pcity, ptile, O_TRADE);
2770
2771 i++;
2773 }
2774#endif /* FREECIV_WEB */
2775}
2776
2777/************************************************************************/
2787bool update_dumb_city(struct player *pplayer, struct city *pcity)
2788{
2789 bv_imprs improvements;
2790 struct tile *pcenter = city_tile(pcity);
2791 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2792 /* pcity->client.occupied isn't used at the server, so we go straight to
2793 * the unit list to check the occupied status. */
2794 bool occupied = (unit_list_size(pcenter->units) > 0);
2796 bool happy = city_happy(pcity);
2797 bool unhappy = city_unhappy(pcity);
2798 int style = pcity->style;
2800 enum capital_type capital = pcity->capital;
2801
2802 /* Only someone knowing the tile should ever know a city on it. */
2803 fc_assert(map_is_known(pcenter, pplayer));
2804
2806 improvement_iterate(pimprove) {
2807 if (is_improvement_visible(pimprove)
2808 && city_has_building(pcity, pimprove)) {
2810 }
2812
2813 if (pdcity == nullptr) {
2816 } else if (pdcity->location != pcenter) {
2817 log_error("Trying to update bad city (wrong location) "
2818 "at %i,%i for player %s",
2819 TILE_XY(pcity->tile), player_name(pplayer));
2820 fc_assert(pdcity->location == pcenter);
2821 pdcity->location = pcenter; /* ?? */
2822 } else if (pdcity->identity != pcity->id) {
2823 log_error("Trying to update old city (wrong identity) "
2824 "at %i,%i for player %s",
2825 TILE_XY(city_tile(pcity)), player_name(pplayer));
2826 fc_assert(pdcity->identity == pcity->id);
2827 pdcity->identity = pcity->id; /* ?? */
2828 } else if (pdcity->occupied == occupied
2829 && pdcity->walls == walls
2830 && pdcity->happy == happy
2831 && pdcity->unhappy == unhappy
2832 && pdcity->style == style
2833 && pdcity->city_image == city_image
2834 && pdcity->capital == capital
2835 && BV_ARE_EQUAL(pdcity->improvements, improvements)
2838 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2839 return FALSE;
2840 }
2841
2843 pdcity->occupied = occupied;
2844 pdcity->walls = walls;
2845 pdcity->style = style;
2846 pdcity->city_image = city_image;
2847 pdcity->capital = capital;
2848 pdcity->happy = happy;
2849 pdcity->unhappy = unhappy;
2850 pdcity->improvements = improvements;
2851
2852 return TRUE;
2853}
2854
2855/************************************************************************/
2858void reality_check_city(struct player *pplayer, struct tile *ptile)
2859{
2860 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2861
2862 if (pdcity) {
2863 struct city *pcity = tile_city(ptile);
2864
2865 if (!pcity || pcity->id != pdcity->identity) {
2866 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2867
2868 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2869 fc_assert_ret(playtile->site == pdcity);
2870 playtile->site = nullptr;
2872 }
2873 }
2874}
2875
2876/************************************************************************/
2879void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2880{
2881 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2882
2883 if (pdcity) {
2884 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2885
2886 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2887 fc_assert_ret(playtile->site == pdcity);
2888 playtile->site = nullptr;
2890 }
2891}
2892
2893/************************************************************************/
2897static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2898 bool source_gone)
2899{
2900 struct player *plr1 = city_owner(pc1);
2901 struct player *plr2 = city_owner(pc2);
2904
2907
2908 if (plr1 == plr2) {
2909 if (source_gone) {
2912 _("Trade between %s and %s lost along with city."),
2914 } else {
2917 _("Trade route between %s and %s canceled."),
2919 }
2920 } else {
2921 if (source_gone) {
2924 /* TRANS: "...between Spanish city Madrid and Paris..." */
2925 _("Trade between %s city %s and %s lost along with "
2926 "their city."),
2928 /* It's implicit to removed city's owner that that city no longer
2929 * has trade routes, so say nothing in that case */
2930 } else {
2933 _("Sorry, the %s canceled the trade route "
2934 "from %s to your city %s."),
2938 /* TRANS: "...from Paris to Spanish city Madrid." */
2939 _("We canceled the trade route "
2940 "from %s to %s city %s."),
2942 }
2943 }
2944}
2945
2946/************************************************************************/
2955 struct trade_route *proute,
2956 bool announce, bool source_gone)
2957{
2958 struct city *pc2 = game_city_by_number(proute->partner);
2959 struct trade_route *back_route = nullptr;
2960
2961 fc_assert_ret_val(pc1 && proute, nullptr);
2962
2964
2965 if (pc2 != nullptr) {
2967 if (pc1->id == pback->partner) {
2968 back_route = pback;
2969 }
2971
2972 if (back_route != nullptr) {
2974 }
2975
2976 if (announce) {
2978
2981 }
2982 }
2983
2984 return back_route;
2985}
2986
2987/**********************************************************************/
2991{
2993 ftc_server,
2994 _("%s has been struck by a plague! Population lost!"),
2995 city_link(pcity));
2996 if (city_reduce_size(pcity, 1, nullptr, "plague")) {
2997 pcity->turn_plague = game.info.turn;
2998
2999 /* Recalculate illness */
3000 pcity->server.illness = city_illness_calc(pcity, nullptr, nullptr,
3001 &(pcity->illness_trade),
3002 nullptr);
3003
3004 return TRUE;
3005 }
3006
3007 return FALSE;
3008}
3009
3010/************************************************************************/
3016void do_sell_building(struct player *pplayer, struct city *pcity,
3017 struct impr_type *pimprove, const char *reason)
3018{
3019 if (can_city_sell_building(pcity, pimprove)) {
3020 pplayer->economic.gold += impr_sell_gold(pimprove);
3021 building_lost(pcity, pimprove, reason, nullptr);
3022 }
3023}
3024
3025/************************************************************************/
3037struct city
3038*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
3039 struct player **oldcity_owner)
3040{
3041 struct city *oldcity = nullptr;
3042
3043 fc_assert_ret_val(!city_has_building(pcity, pimprove), nullptr);
3044
3045 if (is_great_wonder(pimprove)) {
3046 if (!(oldcity = city_from_great_wonder(pimprove))) {
3047 oldcity = pcity;
3048 }
3050 } else if (is_small_wonder(pimprove)) {
3051 if (!(oldcity
3052 = city_from_small_wonder(city_owner(pcity), pimprove))) {
3053 oldcity = pcity;
3054 }
3055 }
3056 if (oldcity && oldcity != pcity) {
3059 _("Moving %s"));
3060 } else {
3062 _("Acquiring %s"));
3063 }
3064
3065 return oldcity;
3066}
3067
3068/************************************************************************/
3071bool building_removed(struct city *pcity, const struct impr_type *pimprove,
3072 const char *reason, struct unit *destroyer)
3073{
3074 int backup = pcity->id;
3075
3076 city_remove_improvement(pcity, pimprove);
3077
3078 script_server_signal_emit("building_lost", pcity, pimprove, reason,
3079 destroyer);
3080
3081 return city_exist(backup);
3082}
3083
3084/************************************************************************/
3088void building_lost(struct city *pcity, const struct impr_type *pimprove,
3089 const char *reason, struct unit *destroyer)
3090{
3091 struct player *owner = city_owner(pcity);
3093 bool city_remains;
3094
3096
3097 if ((was_capital && (!city_remains || !is_capital(pcity)))
3098 && (owner->spaceship.state == SSHIP_STARTED
3099 || owner->spaceship.state == SSHIP_LAUNCHED)) {
3100 /* If the capital was lost (by destruction of the palace) production on
3101 * the spaceship is lost. */
3103 }
3104
3105 if (city_remains) {
3106 /* Update city; influence of effects (buildings, ...) on unit upkeep */
3107 if (city_refresh(pcity)) {
3109 }
3110
3111 /* Re-update the city's visible area. This updates fog if the vision
3112 * range increases or decreases. */
3114 }
3115}
3116
3117/************************************************************************/
3126{
3127 bool update = FALSE;
3128 int cost;
3129
3132 if (cost > 0) {
3133 if (free_uk[o] > cost) {
3134 free_uk[o] -= cost;
3135 cost = 0;
3136 } else {
3137 cost -= free_uk[o];
3138 free_uk[o] = 0;
3139 }
3140 }
3141
3142 if (cost != punit->upkeep[o]) {
3143 update = TRUE;
3144 punit->upkeep[o] = cost;
3145 }
3147
3148 if (update) {
3149 /* Update unit information to the player and global observers. */
3150 send_unit_info(nullptr, punit);
3151 }
3152}
3153
3154/************************************************************************/
3174void city_units_upkeep(const struct city *pcity)
3175{
3176 int free_uk[O_LAST];
3177
3178 if (!pcity || !pcity->units_supported
3179 || unit_list_size(pcity->units_supported) < 1) {
3180 return;
3181 }
3182
3187
3188 /* Save the upkeep for all units in the corresponding punit struct */
3189 unit_list_iterate(pcity->units_supported, punit) {
3192}
3193
3194/************************************************************************/
3197void change_build_target(struct player *pplayer, struct city *pcity,
3198 struct universal *target,
3199 enum event_type event)
3200{
3201 const char *name;
3202 const char *source;
3203
3204 /* If the city is already building this thing, don't do anything */
3205 if (are_universals_equal(&pcity->production, target)) {
3206 return;
3207 }
3208
3209 /* Is the city no longer building a wonder? */
3210 if (VUT_IMPROVEMENT == pcity->production.kind
3211 && is_great_wonder(pcity->production.value.building)
3212 && event != E_IMP_AUTO
3213 && event != E_WORKLIST) {
3214 /* If the build target is changed because of an advisor's suggestion or
3215 * because the worklist advances, then the wonder was completed --
3216 * don't announce that the player has *stopped* building that wonder.
3217 */
3219 _("The %s have stopped building The %s in %s."),
3220 nation_plural_for_player(pplayer),
3222 city_link(pcity));
3223 }
3224
3225 /* Manage the city change-production penalty.
3226 (May penalize, restore or do nothing to the shield_stock.) */
3227 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3228 pcity->shield_stock = city_change_production_penalty(pcity, target);
3229 }
3230
3231 /* Change build target. */
3232 pcity->production = *target;
3233
3234 /* What's the name of the target? */
3236
3237 switch (event) {
3238 case E_WORKLIST:
3239 /* TRANS: Possible 'source' of the production change
3240 * (in "<city> is building ..." sentence). Preserve leading space. */
3241 source = _(" from the worklist");
3242 break;
3243 case E_IMP_AUTO:
3244 /* TRANS: Possible 'source' of the production change
3245 * (in "<city> is building ..." sentence). Preserve leading space. */
3246 source = _(" as suggested by the advisor");
3247 break;
3248 default:
3249 source = "";
3250 break;
3251 }
3252
3253 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3255
3256 /* Tell the player what's up. */
3257 /* FIXME: this may give bad grammar when translated if the 'source'
3258 * string can have multiple values. */
3260 /* TRANS: "<city> is building <production><source>."
3261 * 'source' might be an empty string, or a clause like
3262 * " from the worklist". */
3263 _("%s is building %s%s."),
3265 name, source);
3266
3267 /* If the city is building a wonder, tell the rest of the world
3268 about it. */
3269 if (VUT_IMPROVEMENT == pcity->production.kind
3270 && is_great_wonder(pcity->production.value.building)) {
3272 _("The %s have started building The %s in %s."),
3273 nation_plural_for_player(pplayer),
3274 name,
3275 city_link(pcity));
3276 }
3277}
3278
3279/************************************************************************/
3286void city_map_update_empty(struct city *pcity, struct tile *ptile)
3287{
3288 tile_set_worked(ptile, nullptr);
3289 send_tile_info(nullptr, ptile, FALSE);
3290 pcity->server.synced = FALSE;
3291}
3292
3293/************************************************************************/
3300void city_map_update_worker(struct city *pcity, struct tile *ptile)
3301{
3302 tile_set_worked(ptile, pcity);
3303 send_tile_info(nullptr, ptile, FALSE);
3304 pcity->server.synced = FALSE;
3305}
3306
3307/************************************************************************/
3312static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3313{
3314 struct city *pwork = tile_worked(ptile);
3315
3316 if (pwork != nullptr
3317 && !is_free_worked(pwork, ptile)
3318 && !city_can_work_tile(pwork, ptile)) {
3319 tile_set_worked(ptile, nullptr);
3320 send_tile_info(nullptr, ptile, FALSE);
3321
3322 pwork->specialists[DEFAULT_SPECIALIST]++; /* Keep city sanity */
3323 pwork->server.synced = FALSE;
3324
3325 if (queued) {
3326 city_freeze_workers_queue(pwork); /* Place the displaced later */
3327 } else {
3328 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3330 send_city_info(nullptr, pwork);
3331 }
3332 return TRUE;
3333 }
3334
3335 return FALSE;
3336}
3337
3338/************************************************************************/
3344{
3345 return city_map_update_tile_direct(ptile, TRUE);
3346}
3347
3348/************************************************************************/
3352{
3353 return city_map_update_tile_direct(ptile, FALSE);
3354}
3355
3356/************************************************************************/
3360void sync_cities(void)
3361{
3363 return;
3364 }
3365
3366 players_iterate(pplayer) {
3367 city_list_iterate(pplayer->cities, pcity) {
3368 if (!pcity->server.synced) {
3369 /* Sending will set to TRUE. */
3370 send_city_info(pplayer, pcity);
3371 }
3374}
3375
3376/************************************************************************/
3380{
3381 struct tile *pcenter = city_tile(pcity);
3382 const struct civ_map *nmap = &(wld.map);
3383
3385 ptile, _index, _x, _y) {
3386 /* Bypass city_map_update_tile_now() for efficiency */
3389}
3390
3391/************************************************************************/
3402
3403/************************************************************************/
3414{
3415 adjc_iterate(&(wld.map), ptile, tile1) {
3416 struct city *pcity = tile_city(tile1);
3417
3418 if (pcity) {
3419 struct player *pplayer = city_owner(pcity);
3420 const struct req_context city_ctxt = {
3421 .player = pplayer,
3422 .city = pcity,
3423 .tile = pcity->tile,
3424 };
3425
3426 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3427 city_built_iterate(pcity, pimprove) {
3428 if (!can_city_sell_building(pcity, pimprove)) {
3429 continue;
3430 }
3431
3432 requirement_vector_iterate(&pimprove->reqs, preq) {
3433 if ((VUT_TERRAIN == preq->source.kind
3434 || VUT_TERRAINCLASS == preq->source.kind
3435 || VUT_TERRFLAG == preq->source.kind)
3436 && !is_req_active(&city_ctxt, nullptr, preq, RPT_CERTAIN)) {
3437 int price = impr_sell_gold(pimprove);
3438
3439 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3441 PL_("You sell %s in %s (now landlocked)"
3442 " for %d gold.",
3443 "You sell %s in %s (now landlocked)"
3444 " for %d gold.", price),
3447 }
3450 }
3452}
3453
3454/************************************************************************/
3461{
3462 if (pcity->server.vision != nullptr) {
3463 v_radius_t vision_radius_sq
3465
3466 vision_change_sight(pcity->server.vision, vision_radius_sq);
3468 }
3469}
3470
3471/************************************************************************/
3476{
3477 city_list_iterate(pplayer->cities, pcity) {
3480}
3481
3482/************************************************************************/
3486{
3487 fc_assert_ret_val(pcity != nullptr, FALSE);
3488
3493 const struct civ_map *nmap = &(wld.map);
3494
3495 /* Check minimum / maximum allowed city radii */
3498
3500 /* No change */
3501 return FALSE;
3502 }
3503
3504 /* Get number of city tiles for each radii */
3507
3509 /* A change of the squared city radius but no change of the number of
3510 * city tiles */
3511 return FALSE;
3512 }
3513
3514 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3516
3517 /* Workers map before */
3518 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3522
3524
3526 /* Increased number of city tiles */
3528 } else {
3529 /* Reduced number of city tiles */
3530 int workers = 0;
3531
3532 /* Remove workers from the tiles removed rom the city map */
3534 city_x, city_y) {
3535 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3537 city_y);
3538
3539 if (ptile && pcity == tile_worked(ptile)) {
3541 workers++;
3542 }
3544
3545 /* Add workers to free city tiles */
3546 if (workers > 0) {
3547 int radius_sq = city_map_radius_sq_get(pcity);
3548
3550 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3551 city_x, city_y);
3552
3553 if (ptile && !is_free_worked(pcity, ptile)
3554 && tile_worked(ptile) != pcity
3555 && city_can_work_tile(pcity, ptile)) {
3557 workers--;
3558 }
3559
3560 if (workers <= 0) {
3561 break;
3562 }
3564 }
3565
3566 /* If there still are workers they will be updated to specialists */
3567 if (workers > 0) {
3568 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3569 }
3570
3572 }
3573
3574 /* City removal might be ongoing, and advisor data already deleted */
3575 if (pcity->server.adv != nullptr) {
3576 /* If city is under AI control, update it */
3578 }
3579
3581 ftc_server, _("The size of the city map of %s is %s."),
3583 city_tiles_old < city_tiles_new ? _("increased")
3584 : _("reduced"));
3585
3586 /* Workers map after */
3587 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3591
3592 return TRUE;
3593}
3594
3595/************************************************************************/
3599{
3600 struct packet_worker_task packet;
3601
3602 if (ptask == nullptr) {
3603 return;
3604 }
3605
3606 worker_task_list_remove(pcity->task_reqs, ptask);
3607
3608 packet.city_id = pcity->id;
3609 packet.tile_id = tile_index(ptask->ptile);
3610 packet.activity = ACTIVITY_LAST;
3611 packet.tgt = 0;
3612 packet.want = 0;
3613
3614 free(ptask);
3615
3618}
3619
3620/************************************************************************/
3624{
3625 while (worker_task_list_size(pcity->task_reqs) > 0) {
3627 }
3628}
3629
3630/************************************************************************/
3634{
3635 struct packet_worker_task packet;
3636
3637 packet.city_id = pcity->id;
3638
3639 worker_task_list_iterate(pcity->task_reqs, ptask) {
3640 packet.tile_id = tile_index(ptask->ptile);
3641 packet.activity = ptask->act;
3642 if (ptask->tgt == nullptr) {
3643 packet.tgt = -1;
3644 } else {
3645 packet.tgt = extra_number(ptask->tgt);
3646 }
3647 packet.want = ptask->want;
3648
3652}
3653
3654/************************************************************************/
3658{
3659 int build = pcity->shield_stock;
3660
3661 switch (pcity->production.kind) {
3662 case VUT_IMPROVEMENT:
3663 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3664 build);
3665 case VUT_UTYPE:
3666 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3667 build);
3668 default:
3669 break;
3670 };
3671
3672 return FC_INFINITY;
3673}
3674
3675/************************************************************************/
3680 const struct impr_type *pimprove,
3681 const char *format)
3682{
3683 if (is_wonder(pimprove)) {
3684 /* Only wonders may grant governments */
3685 struct cur_govs_data *govs_data;
3686 char buf[250];
3687
3689 city_add_improvement(pcity, pimprove);
3690
3691 fc_snprintf(buf, sizeof(buf), format,
3693
3694 players_iterate_alive(pplayer) {
3697
3699 } else {
3700 city_add_improvement(pcity, pimprove);
3701 }
3702}
3703
3704/************************************************************************/
3709 const struct player *known_for)
3710{
3711 if (pcity->original == nullptr) {
3712 /* Nobody knows */
3713 return MAX_NUM_PLAYER_SLOTS;
3714 }
3715
3716 if (pcity->original != known_for
3717 || known_for == nullptr) {
3718 /* Players know what they have built themselves,
3719 * global observer knows everything. */
3720 return player_number(pcity->original);
3721 }
3722
3723 return MAX_NUM_PLAYER_SLOTS;
3724}
#define ACTION_NONE
Definition actions.h:59
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:361
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:390
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:380
#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:3722
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:740
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1201
int city_granary_size(int city_size)
Definition city.c:2203
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2267
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1105
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:1296
bool is_capital(const struct city *pcity)
Definition city.c:1636
const char * city_name_get(const struct city *pcity)
Definition city.c:1157
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3483
struct output_type * get_output_type(Output_type_id output)
Definition city.c:640
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2257
bool city_unhappy(const struct city *pcity)
Definition city.c:1683
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3542
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:860
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1736
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2942
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1943
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:1544
bool city_happy(const struct city *pcity)
Definition city.c:1671
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3469
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1441
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
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target, const enum req_problem_type prob_type)
Definition city.c:1028
citizens city_specialists(const struct city *pcity)
Definition city.c:3415
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:957
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1752
int city_map_tiles(int city_radius_sq)
Definition city.c:171
bool city_exist(int id)
Definition city.c:3693
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1513
int city_turns_to_grow(const struct city *pcity)
Definition city.c:2053
void city_rally_point_clear(struct city *pcity)
Definition city.c:3747
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:703
#define cities_iterate_end
Definition city.h:517
@ CNA_BROADCAST_PENDING
Definition city.h:306
@ CNA_NOT
Definition city.h:304
@ CNA_NORMAL
Definition city.h:305
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:565
#define cities_iterate(pcity)
Definition city.h:512
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:84
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:212
@ CITIZEN_ANGRY
Definition city.h:269
@ CITIZEN_HAPPY
Definition city.h:266
@ CITIZEN_CONTENT
Definition city.h:267
@ CITIZEN_UNHAPPY
Definition city.h:268
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:82
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
Definition city.h:186
#define output_type_iterate(output)
Definition city.h:853
#define city_owner(_pcity_)
Definition city.h:564
#define city_tile_iterate_skip_free_worked_end
Definition city.h:220
#define city_list_iterate_end
Definition city.h:510
#define city_map_iterate_radius_sq_end
Definition city.h:191
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:228
@ FEELING_LAST
Definition city.h:283
#define city_tile_iterate_end
Definition city.h:236
#define city_built_iterate(_pcity, _p)
Definition city.h:842
#define city_map_iterate_without_index_end
Definition city.h:182
#define city_built_iterate_end
Definition city.h:848
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:178
#define output_type_iterate_end
Definition city.h:859
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3286
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:2537
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3351
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1687
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:2166
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3312
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3633
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3657
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2374
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2787
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:3038
static void raze_city(struct city *pcity)
Definition citytools.c:928
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1441
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:2226
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2187
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1526
bool send_city_suppression(bool now)
Definition citytools.c:2176
static bool send_city_suppressed
Definition citytools.c:101
void sync_cities(void)
Definition citytools.c:3360
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:2897
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:3125
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3475
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3708
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:3485
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:3197
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3071
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3394
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2990
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3343
void city_thaw_workers(struct city *pcity)
Definition citytools.c:146
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2879
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:3088
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1998
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3598
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:962
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3174
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3623
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:3413
void remove_city(struct city *pcity)
Definition citytools.c:1719
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:3016
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:2954
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2426
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:2255
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:3679
void send_player_cities(struct player *pplayer)
Definition citytools.c:2354
void city_map_update_all(struct city *pcity)
Definition citytools.c:3379
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:3300
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2858
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2330
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3460
#define trade_route_packet_list_iterate_end
Definition citytools.h:28
#define LOG_BUILD_TARGET
Definition citytools.h:21
#define trade_route_packet_list_iterate(ptrlist, ptr)
Definition citytools.h:26
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:367
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:198
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3743
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4797
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:764
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:183
void city_refresh_queue_processing(void)
Definition cityturn.c:214
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:236
enum announce_type announce
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2176
char * incite_cost
Definition comments.c:77
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:368
struct connection * conn_by_user(const char *user_name)
Definition connection.c:379
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:358
bool conn_is_global_observer(const struct connection *pconn)
Definition connection.c:755
#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:2435
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:77
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:73
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1071
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:983
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
enum event_type event
Definition events.c:82
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:249
int Impr_type_id
Definition fc_types.h:237
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
@ RPT_CERTAIN
Definition fc_types.h:516
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
@ O_LAST
Definition fc_types.h:103
#define MAX_LEN_CITYNAME
Definition fc_types.h:69
signed short Continent_id
Definition fc_types.h:233
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:94
#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)
Definition fcthread.c:144
void fc_mutex_release(fc_mutex *mutex)
Definition fcthread.c:152
const char * city_tile_link(const struct city *pcity)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
const char * unit_link(const struct unit *punit)
const char * unit_tile_link(const struct unit *punit)
#define MAX_LEN_LINK
struct civ_game game
Definition game.c:62
struct city * game_city_by_name(const char *name)
Definition game.c:88
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c: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 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 map_num_tiles(void)
Definition map.c:1161
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:439
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:434
#define whole_map_iterate(_map, _tile)
Definition map.h:582
#define whole_map_iterate_end
Definition map.h:591
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:278
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:350
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:362
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:522
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:496
const char * nation_city_name(const struct nation_city *pncity)
Definition nation.c:416
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Definition nation.c:335
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:378
Nation_type_id nation_count(void)
Definition nation.c:503
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:461
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:425
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Definition nation.c:435
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:495
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 player_number(const struct player *pplayer)
Definition player.c:826
const char * player_name(const struct player *pplayer)
Definition player.c:885
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1095
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1376
int player_slot_index(const struct player_slot *pslot)
Definition player.c:423
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1979
int player_index(const struct player *pplayer)
Definition player.c:818
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1155
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1397
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1124
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:432
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1140
#define players_iterate_end
Definition player.h:552
#define players_iterate(_pplayer)
Definition player.h:547
static bool is_barbarian(const struct player *pplayer)
Definition player.h:499
#define player_slots_iterate(_pslot)
Definition player.h:538
#define is_ai(plr)
Definition player.h:232
#define players_iterate_alive_end
Definition player.h:562
#define player_slots_iterate_end
Definition player.h:542
#define players_iterate_alive(_pplayer)
Definition player.h:557
int normal_player_count(void)
Definition plrhand.c:3217
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2971
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2371
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:3016
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2923
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:130
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:417
#define sanity_check_city(x)
Definition sanitycheck.h:42
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:1494
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
bool is_normal_specialist_id(Specialist_type_id sp)
Definition specialist.c:196
#define specialist_type_iterate_end
Definition specialist.h:85
#define specialist_type_iterate(sp)
Definition specialist.h:79
#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:2109
enum server_states server_state(void)
Definition srv_main.c:341
Definition city.h:318
struct trade_route_list * routes
Definition city.h:342
citizens * nationality
Definition city.h:339
struct tile * tile
Definition city.h:320
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:138
struct nation_type::@54::@56 server
struct nation_list * civilwar_nations
Definition nation.h:137
int last_turns_shield_surplus
int prod[O_LAST]
int ppl_content[FEELING_LAST]
bv_city_options city_options
int waste[O_LAST]
enum capital_type capital
enum city_acquire_type acquire_type
int unhappy_penalty[O_LAST]
enum city_wl_cancel_behavior wl_cb
bv_imprs improvements
struct worklist worklist
int citizen_base[O_LAST]
int specialists[SP_MAX]
int ppl_unhappy[FEELING_LAST]
int usage[O_LAST]
int surplus[O_LAST]
char name[MAX_LEN_CITYNAME]
int ppl_angry[FEELING_LAST]
int ppl_happy[FEELING_LAST]
char name[MAX_LEN_CITYNAME]
enum capital_type capital
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:139
int length
Definition unit.h:197
int upkeep[O_LAST]
Definition unit.h:149
int id
Definition unit.h:146
struct unit::@83 orders
bool moved
Definition unit.h:175
struct vision * vision
Definition unit.h:246
bool vigilant
Definition unit.h:199
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:141
enum unit_activity changed_from
Definition unit.h:170
struct unit_adv * adv
Definition unit.h:238
int homecity
Definition unit.h:147
struct unit * transporter
Definition unit.h:185
const struct unit_type * utype
Definition unit.h:140
struct player * owner
Definition unit.h:144
bool dying
Definition unit.h:252
bool happy
Definition vision.h:119
bv_imprs improvements
Definition vision.h:125
int walls
Definition vision.h:118
int style
Definition vision.h:121
bool unhappy
Definition vision.h:120
int city_image
Definition vision.h:122
bool occupied
Definition vision.h:117
enum capital_type capital
Definition vision.h:123
v_radius_t radius_sq
Definition vision.h:91
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:443
#define A_UNSET
Definition tech.h:48
void free_current_governments_data(struct cur_govs_data *data)
Definition techtools.c:1537
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1233
void notify_new_government_options(struct player *pplayer, struct cur_govs_data *data, const char *reason)
Definition techtools.c:1551
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
struct cur_govs_data * create_current_governments_data_all(void)
Definition techtools.c:1517
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:615
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:240
bool is_terrain_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:351
#define terrain_type_iterate(_p)
Definition terrain.h:267
#define terrain_type_iterate_end
Definition terrain.h:273
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:602
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:107
#define tile_claimer(_tile)
Definition tile.h:101
#define tile_index(_pt_)
Definition tile.h:89
#define tile_worked(_tile)
Definition tile.h:119
#define tile_terrain(_tile)
Definition tile.h:115
#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:152
#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
int unit_upkeep_cost(const struct unit *punit, Output_type_id otype)
Definition unit.c:2972
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1977
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:882
#define unit_tile(_pu)
Definition unit.h:407
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:432
#define unit_owner(_pu)
Definition unit.h:406
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity, enum gen_action trigger_action)
Definition unithand.c:6706
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:4093
#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:5192
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1407
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2870
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2883
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:802
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2145
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:5034
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1231
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Definition unittype.c:1517
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1613
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1954
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:412
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:289
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
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:865
#define unit_type_iterate_end
Definition unittype.h:872
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:97
#define V_RADIUS(main_sq, invis_sq, subs_sq)
Definition vision.h:95
#define vision_site_owner(v)
Definition vision.h:128
short int v_radius_t[V_COUNT]
Definition vision.h:82
#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