Freeciv-3.2: /fast/freeciv/nightly/S3_2/server/citytools.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
citytools.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22/* utility */
23#include "bitvector.h"
24#include "fcintl.h"
25#include "log.h"
26#include "mem.h"
27#include "rand.h"
28#include "shared.h"
29#include "support.h"
30
31/* common */
32#include "ai.h"
33#include "base.h"
34#include "citizens.h"
35#include "city.h"
36#include "counters.h"
37#include "culture.h"
38#include "events.h"
39#include "game.h"
40#include "government.h"
41#include "improvement.h"
42#include "idex.h"
43#include "map.h"
44#include "movement.h"
45#include "packets.h"
46#include "player.h"
47#include "requirements.h"
48#include "research.h"
49#include "road.h"
50#include "specialist.h"
51#include "tech.h"
52#include "traderoutes.h"
53#include "unit.h"
54#include "unitlist.h"
55#include "vision.h"
56
57/* common/aicore */
58#include "cm.h"
59
60/* common/scriptcore */
61#include "luascript_types.h"
62
63/* server */
64#include "actiontools.h"
65#include "barbarian.h"
66#include "citizenshand.h"
67#include "cityturn.h"
68#include "gamehand.h" /* send_game_info() */
69#include "maphand.h"
70#include "notify.h"
71#include "plrhand.h"
72#include "sanitycheck.h"
73#include "sernet.h"
74#include "spacerace.h"
75#include "srv_main.h"
76#include "techtools.h"
77#include "unithand.h"
78#include "unittools.h"
79
80/* server/advisors */
81#include "advbuilding.h"
82#include "advgoto.h"
83#include "autosettlers.h"
84#include "infracache.h"
85
86/* server/scripting */
87#include "script_server.h"
88
89/* ai */
90#include "handicaps.h"
91
92/* ai */
93#include "handicaps.h"
94
95#include "citytools.h"
96
97
98/* Queue for pending auto_arrange_workers() */
99 static struct city_list *arrange_workers_queue = NULL;
100
101/* Suppress sending cities during game_load() and end_phase() */
102 static bool send_city_suppressed = FALSE;
103
104static bool city_workers_queue_remove(struct city *pcity);
105
106static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
107 bool source_gone)
108 fc__attribute((nonnull (1, 2)));
109
110/************************************************************************/
137 void city_freeze_workers(struct city *pcity)
138{
139 pcity->server.workers_frozen++;
140}
141
142/************************************************************************/
147 void city_thaw_workers(struct city *pcity)
148{
149 pcity->server.workers_frozen--;
150 fc_assert(pcity->server.workers_frozen >= 0);
151 if (pcity->server.workers_frozen == 0
152 && pcity->server.needs_arrange != CNA_NOT) {
153 city_refresh(pcity); /* Citizen count sanity */
154 auto_arrange_workers(pcity);
155 }
156}
157
158/************************************************************************/
161 void city_freeze_workers_queue(struct city *pcity)
162{
163 if (NULL == arrange_workers_queue) {
164 arrange_workers_queue = city_list_new();
165 } else if (city_list_find_number(arrange_workers_queue, pcity->id)) {
166 return;
167 }
168
169 city_list_prepend(arrange_workers_queue, pcity);
170 city_freeze_workers(pcity);
171 if (pcity->server.needs_arrange == CNA_NOT) {
172 pcity->server.needs_arrange = CNA_NORMAL;
173 }
174}
175
176/************************************************************************/
180 static bool city_workers_queue_remove(struct city *pcity)
181{
182 if (arrange_workers_queue == NULL) {
183 return FALSE;
184 }
185
186 return city_list_remove(arrange_workers_queue, pcity);
187}
188
189/************************************************************************/
193 void city_thaw_workers_queue(void)
194{
195 if (NULL == arrange_workers_queue) {
196 return;
197 }
198
199 city_list_iterate(arrange_workers_queue, pcity) {
200 city_thaw_workers(pcity);
201 } city_list_iterate_end;
202
203 city_list_destroy(arrange_workers_queue);
204 arrange_workers_queue = NULL;
205}
206
207/************************************************************************/
215 static int evaluate_city_name_priority(struct tile *ptile,
216 const struct nation_city *pncity,
217 int default_priority)
218{
219 /* Lower values mean higher priority. */
220 float priority = (float)default_priority;
221 enum nation_city_preference goodness;
222
223 /* Increasing this value will increase the difference caused by
224 (non-)matching terrain. A matching terrain is mult_factor
225 "better" than an unlisted terrain, which is mult_factor
226 "better" than a non-matching terrain. */
227 const float mult_factor = 1.4;
228 bool river = FALSE;
229
230 /*
231 * If natural city names aren't being used, we just return the
232 * base value. This will have the effect of the first-listed
233 * city being used. We do this here rather than special-casing
234 * it elsewhere because this localizes everything to this
235 * function, even though it's a bit inefficient.
236 */
237 if (!game.server.natural_city_names) {
238 return default_priority;
239 }
240
241 /*
242 * Assuming we're using the natural city naming system, we use
243 * an internal alorithm to calculate the priority of each name.
244 * It's a pretty fuzzy algorithm; we basically do the following:
245 * - Change the priority scale from 0..n to 10..n+10. This means
246 * each successive city is 10% lower priority than the first.
247 * - Multiply by a semi-random number. This has the effect of
248 * decreasing rounding errors in the successive calculations,
249 * as well as introducing a smallish random effect.
250 * - Check over all the applicable terrains, and
251 * multiply or divide the priority based on whether or not
252 * the terrain matches. See comment below.
253 */
254
255 priority += 10.0;
256 priority *= 10.0 + fc_rand(5);
257
258 /*
259 * The terrain priority in the struct nation_city will be either
260 * -1, 0, or 1. We therefore take this as-is if the terrain is
261 * present, or negate it if not.
262 *
263 * The reason we multiply as well as divide the value is so
264 * that cities that don't care what terrain they are on (which
265 * is the default) will be left in the middle of the pack. If
266 * we _only_ multiplied (or divided), then cities that had more
267 * terrain labels would have their priorities hurt (or helped).
268 */
269 goodness = nation_city_river_preference(pncity);
270 extra_type_by_cause_iterate(EC_ROAD, priver) {
271 if (tile_has_extra(ptile, priver)
272 && road_has_flag(extra_road_get(priver), RF_RIVER)) {
273 river = TRUE;
274 break;
275 }
276 } extra_type_by_cause_iterate_end;
277 if (!river) {
278 goodness = nation_city_preference_revert(goodness);
279 }
280
281 switch (goodness) {
282 case NCP_DISLIKE:
283 priority *= mult_factor;
284 break;
285 case NCP_NONE:
286 break;
287 case NCP_LIKE:
288 priority /= mult_factor;
289 break;
290 }
291
292 terrain_type_iterate(pterrain) {
293 /* Now we do the same for every available terrain. */
294 goodness = nation_city_terrain_preference(pncity, pterrain);
295 if (!is_terrain_near_tile(&(wld.map), ptile, pterrain, TRUE)) {
296 goodness = nation_city_preference_revert(goodness);
297 }
298 switch (goodness) {
299 case NCP_DISLIKE:
300 priority *= mult_factor;
301 break;
302 case NCP_NONE:
303 break;
304 case NCP_LIKE:
305 priority /= mult_factor;
306 }
307 } terrain_type_iterate_end;
308
309 return (int) priority;
310}
311
312/************************************************************************/
316 static bool is_default_city_name(const char *name, struct player *pplayer)
317{
318 nation_city_list_iterate(nation_cities(nation_of_player(pplayer)),
319 pncity) {
320 if (0 == fc_strcasecmp(name, nation_city_name(pncity))) {
321 return TRUE;
322 }
323 } nation_city_list_iterate_end;
324 return FALSE;
325}
326
327/************************************************************************/
334 static const char *search_for_city_name(struct tile *ptile,
335 const struct nation_city_list *
336 default_cities,
337 struct player *pplayer)
338{
339 int choice = 0, priority, best_priority = -1;
340 const char *name, *best_name = NULL;
341
342 nation_city_list_iterate(default_cities, pncity) {
343 name = nation_city_name(pncity);
344 if (NULL == game_city_by_name(name)
345 && is_allowed_city_name(pplayer, name, NULL, 0)) {
346 priority = evaluate_city_name_priority(ptile, pncity, choice++);
347 if (-1 == best_priority || priority < best_priority) {
348 best_priority = priority;
349 best_name = name;
350 }
351 }
352 } nation_city_list_iterate_end;
353
354 return best_name;
355}
356
357/************************************************************************/
369 bool is_allowed_city_name(struct player *pplayer, const char *cityname,
370 char *error_buf, size_t bufsz)
371{
372 struct connection *pconn = conn_by_user(pplayer->username);
373
374 /* Mode 1: A city name has to be unique for each player. */
375 if (CNM_PLAYER_UNIQUE == game.server.allowed_city_names
376 && city_list_find_name(pplayer->cities, cityname)) {
377 if (error_buf) {
378 fc_snprintf(error_buf, bufsz, _("You already have a city called %s."),
379 cityname);
380 }
381 return FALSE;
382 }
383
384 /* Modes 2,3: A city name has to be globally unique. */
385 if ((CNM_GLOBAL_UNIQUE == game.server.allowed_city_names
386 || CNM_NO_STEALING == game.server.allowed_city_names)
387 && game_city_by_name(cityname)) {
388 if (error_buf) {
389 fc_snprintf(error_buf, bufsz,
390 _("A city called %s already exists."), cityname);
391 }
392 return FALSE;
393 }
394
395 /* General rule: any name in our ruleset is allowed. */
396 if (is_default_city_name(cityname, pplayer)) {
397 return TRUE;
398 }
399
400 /*
401 * Mode 3: Check that the proposed city name is not in another
402 * player's default city names. Note the name will already have been
403 * allowed if it is in this player's default city names list.
404 */
405 if (CNM_NO_STEALING == game.server.allowed_city_names) {
406 struct player *pother = NULL;
407
408 players_iterate(player2) {
409 if (player2 != pplayer && is_default_city_name(cityname, player2)) {
410 pother = player2;
411 break;
412 }
413 } players_iterate_end;
414
415 if (pother != NULL) {
416 if (error_buf) {
417 fc_snprintf(error_buf, bufsz,
418 _("Can't use %s as a city name. It is reserved for %s."),
419 cityname, nation_plural_for_player(pother));
420 }
421 return FALSE;
422 }
423 }
424
425 /* To prevent abuse, only players with HACK access (usually local
426 * connections) can use non-ascii names. Otherwise players could use
427 * confusing garbage names in multi-player games.
428 *
429 * We can even reach here for an AI player, if all the cities of the
430 * original nation are exhausted and the backup nations have non-ascii
431 * names in them. */
432 if (!is_ascii_name(cityname)
433 && (!pconn || pconn->access_level != ALLOW_HACK)) {
434 if (error_buf) {
435 fc_snprintf(error_buf, bufsz,
436 _("%s is not a valid name. Only ASCII or "
437 "ruleset names are allowed for cities."),
438 cityname);
439 }
440 return FALSE;
441 }
442
443
444 return TRUE;
445}
446
447/************************************************************************/
453 const char *city_name_suggestion(struct player *pplayer, struct tile *ptile)
454{
455 struct nation_type *pnation = nation_of_player(pplayer);
456 const char *name;
457
458 log_verbose("Suggesting city name for %s at (%d,%d)",
459 player_name(pplayer), TILE_XY(ptile));
460
461 /* First try default city names. */
462 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
463 if (NULL != name) {
464 log_debug("Default city name found: %s.", name);
465 return name;
466 }
467
468 /* Not found... Let's try a straightforward algorithm to look through
469 * nations to find a city name.
470 *
471 * We start by adding the player's nation to the queue. Then we proceed:
472 * - Pick a random nation from the queue.
473 * - If it has a valid city name, use that.
474 * - Otherwise, add all parent and child nations to the queue.
475 * - If the queue is empty, add all remaining nations to it and continue.
476 *
477 * Variables used:
478 * - nation_list is a queue of nations to look through.
479 * - nations_selected tells whether each nation is in the queue already
480 * - queue_size gives the size of the queue (number of nations in it).
481 * - i is the current position in the queue.
482 * Note that nations aren't removed from the queue after they're processed.
483 * New nations are just added onto the end. */
484 {
485 struct nation_type *nation_list[nation_count()];
486 bool nations_selected[nation_count()];
487 int queue_size = 1, i = 0, idx;
488
489 memset(nations_selected, 0, sizeof(nations_selected));
490 nation_list[0] = pnation;
491 nations_selected[nation_index(pnation)] = TRUE;
492
493 while (i < nation_count()) {
494 for (; i < queue_size; i++) {
495
496 if (0 < i) {
497 /* Pick a random nation from the queue. */
498 const int which = i + fc_rand(queue_size - i);
499 struct nation_type *tmp = nation_list[i];
500
501 nation_list[i] = nation_list[which];
502 nation_list[which] = tmp;
503
504 pnation = nation_list[i];
505 log_debug("Looking through %s.", nation_rule_name(pnation));
506 name = search_for_city_name(ptile, nation_cities(pnation), pplayer);
507
508 if (NULL != name) {
509 return name;
510 }
511 }
512
513 /* Append the nation's civil war nations into the search tree. */
514 nation_list_iterate(pnation->server.civilwar_nations, n) {
515 idx = nation_index(n);
516 if (!nations_selected[idx]) {
517 nation_list[queue_size] = n;
518 nations_selected[idx] = TRUE;
519 queue_size++;
520 log_debug("Child %s.", nation_rule_name(n));
521 }
522 } nation_list_iterate_end;
523
524 /* Append the nation's parent nations into the search tree. */
525 nation_list_iterate(pnation->server.parent_nations, n) {
526 idx = nation_index(n);
527 if (!nations_selected[idx]) {
528 nation_list[queue_size] = n;
529 nations_selected[idx] = TRUE;
530 queue_size++;
531 log_debug("Parent %s.", nation_rule_name(n));
532 }
533 } nation_list_iterate_end;
534 }
535
536 /* Still not found; append all remaining nations. */
537 allowed_nations_iterate(n) {
538 idx = nation_index(n);
539 if (!nations_selected[idx]) {
540 nation_list[queue_size] = n;
541 nations_selected[nation_index(n)] = TRUE;
542 queue_size++;
543 log_debug("Misc nation %s.", nation_rule_name(n));
544 }
545 } allowed_nations_iterate_end;
546 }
547 }
548
549 /* Not found in rulesets, make a default name. */
550 {
551 static char tempname[MAX_LEN_CITYNAME];
552 int i;
553
554 log_debug("City name not found in rulesets.");
555 for (i = 1; i <= map_num_tiles(); i++ ) {
556 fc_snprintf(tempname, MAX_LEN_CITYNAME, _("City no. %d"), i);
557 if (NULL == game_city_by_name(tempname)) {
558 return tempname;
559 }
560 }
561
562 fc_assert_msg(FALSE, "Failed to generate a city name.");
563 sz_strlcpy(tempname, _("A poorly-named city"));
564 return tempname;
565 }
566}
567
568/************************************************************************/
571 int build_points_left(struct city *pcity)
572{
573 int cost = city_production_build_shield_cost(pcity);
574
575 return cost - pcity->shield_stock;
576}
577
578/************************************************************************/
585 static void transfer_unit(struct unit *punit, struct city *tocity,
586 bool rehome, bool verbose)
587{
588 struct player *from_player = unit_owner(punit);
589 struct player *to_player = city_owner(tocity);
590
591 /* Transferring a dying GameLoss unit as part of the loot for
592 * killing it caused gna bug #23676. */
593 fc_assert_ret_msg(!punit->server.dying,
594 "Tried to transfer the dying unit %d.",
595 punit->id);
596
597 if (from_player == to_player) {
598 fc_assert_ret(rehome);
599 log_verbose("Changed homecity of %s %s to %s",
600 nation_rule_name(nation_of_player(from_player)),
601 unit_rule_name(punit),
602 city_name_get(tocity));
603 if (verbose) {
604 notify_player(from_player, unit_tile(punit),
605 E_UNIT_RELOCATED, ftc_server,
606 _("Changed homecity of %s to %s."),
607 unit_link(punit),
608 city_link(tocity));
609 }
610 } else {
611 struct tile *utile = unit_tile(punit);
612 struct city *in_city = tile_city(utile);
613
614 if (utype_player_already_has_this_unique(to_player,
615 unit_type_get(punit))) {
616 /* This is a unique unit that to_player already has. A transfer would
617 * break the rule that a player only may have one unit of each unique
618 * unit type. */
619
620 log_debug("%s already have a %s. Can't transfer from %s",
621 nation_rule_name(nation_of_player(to_player)),
622 unit_rule_name(punit),
623 nation_rule_name(nation_of_player(from_player)));
624
625 if (utype_has_flag(unit_type_get(punit), UTYF_GAMELOSS)) {
626 /* Try to save game loss units. */
627 bounce_unit(punit, verbose);
628 } else {
629 /* Kill the unique unit. */
630
631 if (verbose) {
632 notify_player(from_player, unit_tile(punit),
633 E_UNIT_LOST_MISC, ftc_server,
634 /* TRANS: Americans ... Leader */
635 _("The %s already have a %s. Can't transfer yours."),
636 nation_plural_for_player(to_player),
637 unit_tile_link(punit));
638 }
639
640 wipe_unit(punit, ULR_CITY_LOST, NULL);
641 }
642
643 return;
644 }
645
646 if (in_city) {
647 log_verbose("Transferred %s in %s from %s to %s",
648 unit_rule_name(punit), city_name_get(in_city),
649 nation_rule_name(nation_of_player(from_player)),
650 nation_rule_name(nation_of_player(to_player)));
651 if (verbose) {
652 notify_player(from_player, unit_tile(punit),
653 E_UNIT_RELOCATED, ftc_server,
654 _("Transferred %s in %s from %s to %s."),
655 unit_link(punit),
656 city_link(in_city),
657 nation_plural_for_player(from_player),
658 nation_plural_for_player(to_player));
659 }
660 } else if (can_unit_exist_at_tile(&(wld.map), punit, tocity->tile)) {
661 log_verbose("Transferred %s from %s to %s",
662 unit_rule_name(punit),
663 nation_rule_name(nation_of_player(from_player)),
664 nation_rule_name(nation_of_player(to_player)));
665 if (verbose) {
666 notify_player(from_player, unit_tile(punit),
667 E_UNIT_RELOCATED, ftc_server,
668 _("Transferred %s from %s to %s."),
669 unit_link(punit),
670 nation_plural_for_player(from_player),
671 nation_plural_for_player(to_player));
672 }
673 } else {
674 log_verbose("Could not transfer %s from %s to %s",
675 unit_rule_name(punit),
676 nation_rule_name(nation_of_player(from_player)),
677 nation_rule_name(nation_of_player(to_player)));
678 if (verbose) {
679 notify_player(from_player, unit_tile(punit),
680 E_UNIT_LOST_MISC, ftc_server,
681 /* TRANS: Polish Destroyer ... German <city> */
682 _("%s %s lost in transfer to %s %s"),
683 nation_adjective_for_player(from_player),
684 unit_tile_link(punit),
685 nation_adjective_for_player(to_player),
686 city_link(tocity));
687 }
688 wipe_unit(punit, ULR_CITY_LOST, NULL);
689 return;
690 }
691
692 maybe_make_contact(utile, to_player);
693 }
694 unit_change_homecity_handling(punit, tocity, rehome);
695}
696
697/************************************************************************/
716 void transfer_city_units(struct player *pplayer, struct player *pvictim,
717 struct unit_list *units, struct city *pcity,
718 struct city *exclude_city,
719 int kill_outside, bool verbose)
720{
721 struct tile *ptile = pcity->tile;
722 int saved_id = pcity->id;
723 const char *name = city_name_get(pcity);
724
725 /* Transfer enemy units in the city to the new owner.
726 * Only relevant if we are transferring to another player. */
727 if (pplayer != pvictim) {
728 unit_list_iterate_safe((ptile)->units, vunit) {
729 if (vunit->server.dying) {
730 /* Don't transfer or bounce a dying unit. It will soon be gone
731 * anyway.
732 *
733 * Bouncing a dying unit isn't a good idea.
734 * Remaining death handling may do things meant for its current
735 * location to the new location. (Example: Stack death)
736 * bounce_unit() will wipe the unit if it can't be bounced. Wiping
737 * the dying unit isn't a good idea. The remaining death handling
738 * code will try to read from it.
739 *
740 * Transferring a dying GameLoss unit as part of the loot for
741 * killing it caused gna bug #23676. */
742 continue;
743 }
744
745 /* Don't transfer units already owned by new city-owner --wegge */
746 if (unit_owner(vunit) == pvictim) {
747 /* Determine whether unit was homeless. If it was, we don't give
748 * it a homecity, only change ownership.
749 * We have to search the transferred city's former units because
750 * the unit may have been made only temporarily homeless during
751 * city transfer. */
752 bool homeless = (vunit->homecity == 0)
753 && !unit_list_search(units, vunit);
754
755 /* vunit may die during transfer_unit().
756 * unit_list_remove() is still safe using vunit pointer, as
757 * pointer is not used for dereferencing, only as value.
758 * Not sure if it would be safe to unlink first and transfer only
759 * after that. Not sure if it is correct to unlink at all in
760 * some cases, depending which list 'units' points to. */
761 transfer_unit(vunit, pcity, !homeless, verbose);
762 unit_list_remove(units, vunit);
763 } else if (!pplayers_allied(pplayer, unit_owner(vunit))) {
764 /* the owner of vunit is allied to pvictim but not to pplayer */
765 bounce_unit(vunit, verbose);
766 }
767 } unit_list_iterate_safe_end;
768 }
769
770 if (!city_exist(saved_id)) {
771 saved_id = 0;
772 }
773
774 /* Any remaining units supported by the city are either given new home
775 cities or maybe destroyed */
776 unit_list_iterate_safe(units, vunit) {
777 struct city *new_home_city = tile_city(unit_tile(vunit));
778
779 if (vunit->server.dying) {
780 /* Don't transfer or destroy a dying unit. It will soon be gone
781 * anyway.
782 *
783 * Transferring a dying GameLoss unit as part of the loot for
784 * killing it caused gna bug #23676. */
785 continue;
786 }
787
788 if (new_home_city && new_home_city != exclude_city
789 && city_owner(new_home_city) == unit_owner(vunit)) {
790 /* unit is in another city: make that the new homecity,
791 * unless that city is actually the same city (happens if disbanding)
792 * Unit had a homecity since it was supported, so rehome. */
793 transfer_unit(vunit, new_home_city, TRUE, verbose);
794 } else if ((kill_outside == -1
795 || real_map_distance(unit_tile(vunit), ptile) <= kill_outside)
796 && saved_id) {
797 /* else transfer to specified city. */
798 transfer_unit(vunit, pcity, TRUE, verbose);
799 if (unit_tile(vunit) == ptile && !pplayers_allied(pplayer, pvictim)) {
800 /* Unit is inside city being transferred, bounce it */
801 bounce_unit(vunit, TRUE);
802 }
803 } else {
804 /* The unit is lost. Call notify_player (in all other cases it is
805 * called automatically). */
806 log_verbose("Lost %s %s at (%d,%d) when %s was lost.",
807 nation_rule_name(nation_of_unit(vunit)),
808 unit_rule_name(vunit), TILE_XY(unit_tile(vunit)), name);
809 if (verbose) {
810 notify_player(unit_owner(vunit), unit_tile(vunit),
811 E_UNIT_LOST_MISC, ftc_server,
812 _("%s lost along with control of %s."),
813 unit_tile_link(vunit), name);
814 }
815 wipe_unit(vunit, ULR_CITY_LOST, NULL);
816 }
817 } unit_list_iterate_safe_end;
818
819#ifdef FREECIV_DEBUG
820 unit_list_iterate(pcity->units_supported, punit) {
821 if (punit->server.dying) {
822 /* Leave the dying alone. */
823 continue;
824 }
825
826 fc_assert(punit->homecity == pcity->id);
827 fc_assert(unit_owner(punit) == pplayer);
828 } unit_list_iterate_end;
829#endif /* FREECIV_DEBUG */
830}
831
832/************************************************************************/
851 struct city *find_closest_city(const struct tile *ptile,
852 const struct city *pexclcity,
853 const struct player *pplayer,
854 bool only_ocean, bool only_continent,
855 bool only_known, bool only_player,
856 bool only_enemy, const struct unit_class *pclass)
857{
858 Continent_id con;
859 struct city *best_city = NULL;
860 int best_dist = -1;
861
862 fc_assert_ret_val(ptile != NULL, NULL);
863
864 if (pplayer != NULL && only_player && only_enemy) {
865 log_error("Non of my own cities will be at war with me!");
866 return NULL;
867 }
868
869 con = tile_continent(ptile);
870
871 players_iterate(aplayer) {
872 if (pplayer != NULL && only_player && pplayer != aplayer) {
873 /* only cities of player 'pplayer' */
874 continue;
875 }
876
877 if (pplayer != NULL && only_enemy
878 && !pplayers_at_war(pplayer, aplayer)) {
879 /* only cities of players at war with player 'pplayer' */
880 continue;
881 }
882
883 city_list_iterate(aplayer->cities, pcity) {
884 int city_dist;
885
886 if (pexclcity && pexclcity == pcity) {
887 /* not this city */
888 continue;
889 }
890
891 city_dist = real_map_distance(ptile, city_tile(pcity));
892
893 /* Find the closest city matching the requirements.
894 * - closer than the current best city
895 * - (if required) on the same continent
896 * - (if required) adjacent to ocean
897 * - (if required) only cities known by the player
898 * - (if required) only cities native to the class */
899 if ((best_dist == -1 || city_dist < best_dist)
900 && (!only_continent || con == tile_continent(pcity->tile))
901 && (!only_ocean || is_terrain_class_near_tile(&(wld.map),
902 city_tile(pcity), TC_OCEAN))
903 && (!only_known
904 || (map_is_known(city_tile(pcity), pplayer)
905 && map_get_player_site(city_tile(pcity), pplayer)->identity
906 > IDENTITY_NUMBER_ZERO))
907 && (pclass == NULL
908 || is_native_near_tile(&(wld.map), pclass, city_tile(pcity)))) {
909 best_dist = city_dist;
910 best_city = pcity;
911 }
912 } city_list_iterate_end;
913 } players_iterate_end;
914
915 return best_city;
916}
917
918/************************************************************************/
923 static void raze_city(struct city *pcity)
924{
925 int razechance = game.server.razechance;
926 bool city_remains = TRUE;
927
928 /* land barbarians are more likely to destroy city improvements */
929 if (is_land_barbarian(city_owner(pcity))) {
930 razechance += 30;
931 }
932
933 city_built_iterate(pcity, pimprove) {
934 /* Small wonders should have already been removed by
935 * transfer_city() (with 100% probability). */
936 fc_assert(!is_small_wonder(pimprove));
937 if (is_improvement(pimprove) && (fc_rand(100) < razechance)) {
938 /* FIXME: Should maybe have conquering unit instead of NULL as destroyer */
939 city_remains = building_removed(pcity, pimprove, "razed", NULL);
940 if (!city_remains) {
941 break;
942 }
943 }
944 } city_built_iterate_end;
945
946 if (city_remains) {
947 nullify_prechange_production(pcity);
948 pcity->shield_stock = 0;
949 }
950}
951
952/************************************************************************/
956 static void reestablish_city_trade_routes(struct city *pcity)
957{
958 trade_routes_iterate_safe(pcity, proute) {
959 bool keep_route;
960 struct trade_route *back;
961 struct city *partner = game_city_by_number(proute->partner);
962
963 /* Remove the city's trade routes (old owner).
964 * Do not announce removal as we might restore the route immediately below */
965 back = remove_trade_route(pcity, proute, FALSE, FALSE);
966
967 keep_route = can_cities_trade(pcity, partner)
968 && can_establish_trade_route(pcity, partner);
969
970 if (!keep_route) {
971 enum trade_route_type type = cities_trade_route_type(pcity, partner);
972 struct trade_route_settings *settings = trade_route_settings_by_type(type);
973
974 if (settings->cancelling != TRI_CANCEL) {
975 keep_route = TRUE;
976 }
977 }
978
979 /* Readd the city's trade route (new owner) */
980 if (keep_route) {
981 trade_route_list_append(pcity->routes, proute);
982 trade_route_list_append(partner->routes, back);
983 } else {
984 free(proute);
985 free(back);
986
987 /* Now announce the trade route removal */
988 announce_trade_route_removal(pcity, partner, FALSE);
989 }
990
991 /* Refresh regardless; either it lost a trade route or the trade
992 * route revenue changed. */
993 city_refresh(partner);
994 send_city_info(city_owner(partner), partner);
995
996 /* Give the new owner infos about the city which has a trade route
997 * with the transferred city. */
998 if (game.info.reveal_trade_partner) {
999 struct player *owner = city_owner(pcity);
1000
1001 map_show_tile(owner, partner->tile);
1002 update_dumb_city(owner, partner);
1003 send_city_info(owner, partner);
1004 }
1005 } trade_routes_iterate_safe_end;
1006}
1007
1008/************************************************************************/
1013 static void build_free_small_wonders(struct player *pplayer,
1014 bv_imprs *had_small_wonders)
1015{
1016 int size = city_list_size(pplayer->cities);
1017
1018 if (!game.server.savepalace) {
1019 /* Nothing to do */
1020 return;
1021 }
1022
1023 if (size == 0) {
1024 /* The last city was removed or transferred to the enemy.
1025 * If the victim survives to found or acquire another city, they'll
1026 * get any savepalace initial buildings then. */
1027 return;
1028 }
1029
1030 improvement_iterate(pimprove) {
1031 if (improvement_has_flag(pimprove, IF_SAVE_SMALL_WONDER)
1032 && BV_ISSET(*had_small_wonders, improvement_index(pimprove))) {
1033 /* FIXME: instead, find central city */
1034 struct city *pnew_city = city_list_get(pplayer->cities, fc_rand(size));
1035
1036 fc_assert_action(NULL == city_from_small_wonder(pplayer, pimprove),
1037 continue);
1038
1039 city_add_improvement(pnew_city, pimprove);
1040
1041 /*
1042 * send_player_cities will recalculate all cities and send them to
1043 * the client.
1044 */
1045 send_player_cities(pplayer);
1046
1047 notify_player(pplayer, city_tile(pnew_city), E_IMP_BUILD, ftc_server,
1048 /* FIXME: should already be notified about city loss? */
1049 /* TRANS: <building> ... <city> */
1050 _("A replacement %s was built in %s."),
1051 improvement_name_translation(pimprove),
1052 city_link(pnew_city));
1053 /*
1054 * The enemies want to see the new capital in their intelligence
1055 * report.
1056 */
1057 send_city_info(NULL, pnew_city);
1058 }
1059 } improvement_iterate_end;
1060}
1061
1062/************************************************************************/
1071 bool transfer_city(struct player *ptaker, struct city *pcity,
1072 int kill_outside, bool transfer_unit_verbose,
1073 bool resolve_stack, bool raze, bool build_free)
1074{
1075 bv_imprs had_small_wonders;
1076 struct vision *old_vision, *new_vision;
1077 struct unit_list *old_city_units = unit_list_new();
1078 struct player *pgiver = city_owner(pcity);
1079 struct tile *pcenter = city_tile(pcity);
1080 int saved_id = pcity->id;
1081 bool city_remains = TRUE;
1082 bool had_great_wonders = FALSE;
1083 const citizens old_taker_content_citizens = player_content_citizens(ptaker);
1084 const citizens old_giver_content_citizens = player_content_citizens(pgiver);
1085 const citizens old_taker_angry_citizens = player_angry_citizens(ptaker);
1086 const citizens old_giver_angry_citizens = player_angry_citizens(pgiver);
1087 bool taker_had_no_cities = (city_list_size(ptaker->cities) == 0);
1088 bool new_extras;
1089 int units_num = 0;
1090 const int ul_size = unit_list_size(pcenter->units);
1091 int central_units[ul_size + 1];
1092 bv_player *could_see_unit = NULL;
1093 int i;
1094
1095 fc_assert_ret_val(pgiver != ptaker, TRUE);
1096
1097 unit_list_iterate(pcenter->units, punit) {
1098 central_units[units_num++] = punit->id;
1099 } unit_list_iterate_end;
1100
1101 if (units_num > 0) {
1102 could_see_unit = fc_calloc(sizeof(*could_see_unit), units_num);
1103
1104 /* Remember what player see what unit. */
1105 for (i = 0; i < units_num; i++) {
1106 struct unit *aunit = game_unit_by_number(central_units[i]);
1107
1108 BV_CLR_ALL(could_see_unit[i]);
1109 players_iterate(aplayer) {
1110 if (can_player_see_unit(aplayer, aunit)) {
1111 BV_SET(could_see_unit[i], player_index(aplayer));
1112 }
1113 } players_iterate_end;
1114 }
1115
1116 fc_assert(i == units_num);
1117 }
1118
1119 /* Remove AI control of the old owner. */
1120 CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity);
1121
1122 /* Forget old tasks */
1123 clear_worker_tasks(pcity);
1124
1125 /* Forget old rally point */
1126 city_rally_point_clear(pcity);
1127
1128 /* Activate AI control of the new owner. */
1129 CALL_PLR_AI_FUNC(city_got, ptaker, ptaker, pcity);
1130
1131 city_freeze_workers(pcity);
1132
1133 unit_list_iterate(pcity->units_supported, punit) {
1134 unit_list_prepend(old_city_units, punit);
1135 /* Mark unit to have no homecity at all.
1136 * 1. We remove unit from units_supported list here,
1137 * real_change_unit_homecity() should not attempt it.
1138 * 2. Otherwise we might delete the homecity from under the unit
1139 * in the client */
1140 punit->homecity = 0;
1141 send_unit_info(NULL, punit);
1142 } unit_list_iterate_end;
1143 unit_list_clear(pcity->units_supported);
1144
1145 /* Remove all global improvement effects that this city confers (but
1146 then restore the local improvement list - we need this to restore the
1147 global effects for the new city owner) */
1148 BV_CLR_ALL(had_small_wonders);
1149 city_built_iterate(pcity, pimprove) {
1150 if (is_small_wonder(pimprove)) {
1151 /* Small wonders are really removed (not restored later). */
1152 building_removed(pcity, pimprove, "conquered", NULL);
1153 BV_SET(had_small_wonders, improvement_index(pimprove));
1154 } else {
1155 city_remove_improvement(pcity, pimprove);
1156 if (is_great_wonder(pimprove)) {
1157 had_great_wonders = TRUE;
1158 }
1159 /* Note: internal turn here, next city_built_iterate(). */
1160 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
1161 }
1162 } city_built_iterate_end;
1163
1164 give_citymap_from_player_to_player(pcity, pgiver, ptaker);
1165 old_vision = pcity->server.vision;
1166 new_vision = vision_new(ptaker, pcenter);
1167 pcity->server.vision = new_vision;
1168 vision_reveal_tiles(new_vision, game.server.vision_reveal_tiles);
1169 vision_change_sight(new_vision, old_vision->radius_sq);
1170
1171 ASSERT_VISION(new_vision);
1172
1173 if (CNM_PLAYER_UNIQUE == game.server.allowed_city_names
1174 && city_list_find_name(ptaker->cities, city_name_get(pcity))) {
1175 char *old_city_name = fc_strdup(city_name_get(pcity));
1176
1177 city_name_set(pcity, city_name_suggestion(ptaker, pcenter));
1178 notify_player(ptaker, pcenter, E_BAD_COMMAND, ftc_server,
1179 _("You already had a city called %s."
1180 " The city was renamed to %s."),
1181 old_city_name,
1182 city_link(pcity));
1183
1184 free(old_city_name);
1185 }
1186
1187 /* Has to follow the unfog call above. */
1188 city_list_remove(pgiver->cities, pcity);
1189 map_clear_border(pcenter);
1190 /* city_thaw_workers_queue() later */
1191
1192 pcity->owner = ptaker;
1193 pcity->capital = CAPITAL_NOT;
1194 pcity->acquire_t = CACQ_CONQUEST;
1195 map_claim_ownership(pcenter, ptaker, pcenter, TRUE);
1196 city_list_prepend(ptaker->cities, pcity);
1197
1198 if (could_see_unit != NULL) {
1199 /* Hide/reveal units. Do it after vision have been given to taker, city
1200 * owner has been changed, and before any script could be spawned. */
1201 for (i = 0; i < units_num; i++) {
1202 struct unit *aunit = game_unit_by_number(central_units[i]);
1203
1204 players_iterate(aplayer) {
1205 if (can_player_see_unit(aplayer, aunit)) {
1206 if (!BV_ISSET(could_see_unit[i], player_index(aplayer))
1207 && !aunit->server.dying) {
1208 /* Reveal 'aunit'. */
1209 send_unit_info(aplayer->connections, aunit);
1210 }
1211 } else {
1212 if (BV_ISSET(could_see_unit[i], player_index(aplayer))) {
1213 /* Hide 'aunit'. */
1214 unit_goes_out_of_sight(aplayer, aunit);
1215 }
1216 }
1217 } players_iterate_end;
1218 }
1219
1220 fc_assert(i == units_num);
1221
1222 free(could_see_unit);
1223 could_see_unit = NULL;
1224 }
1225
1226 transfer_city_units(ptaker, pgiver, old_city_units,
1227 pcity, NULL,
1228 kill_outside, transfer_unit_verbose);
1229 /* The units themselves are already freed by transfer_city_units(). */
1230 unit_list_destroy(old_city_units);
1231
1232 if (resolve_stack) {
1233 resolve_unit_stacks(pgiver, ptaker, transfer_unit_verbose);
1234 }
1235
1236 if (!city_exist(saved_id)) {
1237 city_remains = FALSE;
1238 }
1239
1240 /* Reset turns owner counters */
1241 if (city_remains) {
1242 city_counters_iterate(pcount) {
1243 if (pcount->type == CB_CITY_OWNED_TURNS) {
1244 pcity->counter_values[pcount->index] = 0;
1245 }
1246 } city_counters_iterate_end;
1247 }
1248
1249 if (city_remains) {
1250 /* Update the city's trade routes. */
1251 reestablish_city_trade_routes(pcity);
1252
1253 /* Clear CMA. */
1254 if (pcity->cm_parameter) {
1255 free(pcity->cm_parameter);
1256 pcity->cm_parameter = NULL;
1257 }
1258
1259 city_refresh(pcity);
1260 }
1261
1262 /*
1263 * maybe_make_contact() MUST be called before city_map_update_all(),
1264 * since the diplomacy status can influence whether a tile is available.
1265 */
1266 maybe_make_contact(pcenter, ptaker);
1267
1268 if (city_remains) {
1269 struct extra_type *upgradet;
1270
1271 if (raze) {
1272 raze_city(pcity);
1273 }
1274
1275 if (taker_had_no_cities) {
1276 /* If conqueror previously had no cities, we might need to give
1277 * them a palace etc */
1278 if (build_free) {
1279 city_build_free_buildings(pcity);
1280 } /* Else caller should probably ensure palace is built */
1281
1282 BV_SET(ptaker->flags, PLRF_FIRST_CITY);
1283 }
1284
1285 citizens_convert_conquest(pcity);
1286
1287 /* Restore any global improvement effects that this city confers */
1288 city_built_iterate(pcity, pimprove) {
1289 city_add_improvement_with_gov_notice(pcity, pimprove,
1290 _("Transfer of %s"));
1291 } city_built_iterate_end;
1292
1293 /* Set production to something valid for pplayer, if not.
1294 * (previously allowed building obsolete units.) */
1295 if (!can_city_build_now(pcity, &pcity->production)) {
1296 advisor_choose_build(ptaker, pcity);
1297 }
1298
1299 /* What wasn't obsolete for the old owner may be so now. */
1300 remove_obsolete_buildings_city(pcity, TRUE);
1301
1302 new_extras = upgrade_city_extras(pcity, &upgradet);
1303
1304 if (new_extras) {
1305 const char *clink = city_link(pcity);
1306
1307 notify_player(ptaker, pcenter, E_CITY_TRANSFER, ftc_server,
1308 _("The people in %s are stunned by your "
1309 "technological insight!"),
1310 clink);
1311
1312 if (upgradet != NULL) {
1313 notify_player(ptaker, pcenter, E_CITY_TRANSFER, ftc_server,
1314 _("Workers spontaneously gather and upgrade "
1315 "%s with %s."),
1316 clink, extra_name_translation(upgradet));
1317 } else {
1318 notify_player(ptaker, pcenter, E_CITY_TRANSFER, ftc_server,
1319 _("Workers spontaneously gather and upgrade "
1320 "%s infrastructure."),
1321 clink);
1322 }
1323 update_tile_knowledge(pcenter);
1324 }
1325
1326 /* Build a new palace for free if the player lost their capital and
1327 savepalace is on. */
1328 build_free_small_wonders(pgiver, &had_small_wonders);
1329
1330 /* Refresh the city's vision range, since it might be different
1331 * under the new owner. */
1332 city_refresh_vision(pcity);
1333
1334 /* Update the national borders, within the current vision and culture.
1335 * This could leave a border ring around the city, updated later by
1336 * map_calculate_borders() at the next turn.
1337 */
1338 map_claim_border(pcenter, ptaker, -1);
1339 /* city_thaw_workers_queue() later */
1340
1341 auto_arrange_workers(pcity); /* does city_map_update_all() */
1342 city_thaw_workers(pcity);
1343 city_thaw_workers_queue(); /* after old city has a chance to work! */
1344 city_refresh_queue_add(pcity);
1345 /* no sanity check here as the city is not refreshed! */
1346 }
1347
1348 if (city_remains) {
1349 /* Send city with updated owner information to giver and to everyone
1350 * having shared vision pact with them before they may
1351 * lose vision to it. When we later send info to everybody seeing the city,
1352 * they may not be included. */
1353 send_city_info(NULL, pcity);
1354 }
1355
1356 /* Remove the sight points from the giver. */
1357 vision_clear_sight(old_vision);
1358 vision_free(old_vision);
1359
1360 /* Send wonder infos. */
1361 if (had_great_wonders) {
1362 send_game_info(NULL);
1363 if (city_remains) {
1364 send_player_info_c(ptaker, NULL);
1365
1366 /* Refresh all cities of the taker to account for possible changes due
1367 * to player wide effects. */
1368 city_list_iterate(ptaker->cities, acity) {
1369 city_refresh_queue_add(acity);
1370 } city_list_iterate_end;
1371 } else {
1372 /* Refresh all cities to account for possible global effects. */
1373 cities_iterate(acity) {
1374 city_refresh_queue_add(acity);
1375 } cities_iterate_end;
1376 }
1377 }
1378 if (BV_ISSET_ANY(had_small_wonders) || had_great_wonders) {
1379 /* No need to send to detached connections. */
1380 send_player_info_c(pgiver, NULL);
1381
1382 /* Refresh all cities of the giver to account for possible changes due
1383 * to player wide effects. */
1384 city_list_iterate(pgiver->cities, acity) {
1385 city_refresh_queue_add(acity);
1386 } city_list_iterate_end;
1387 }
1388
1389 /* Refresh all cities in the queue. */
1390 city_refresh_queue_processing();
1391 /* After the refresh the sanity check can be done. */
1392 sanity_check_city(pcity);
1393
1394 if (city_remains) {
1395 /* Send information about conquered city to all players. */
1396 send_city_info(NULL, pcity);
1397 }
1398
1399 /* We may cross the EFT_EMPIRE_SIZE_* effects, then we will have to
1400 * refresh all cities for the player. */
1401 if (old_taker_content_citizens != player_content_citizens(ptaker)
1402 || old_taker_angry_citizens != player_angry_citizens(ptaker)) {
1403 city_refresh_for_player(ptaker);
1404 }
1405 if (old_giver_content_citizens != player_content_citizens(pgiver)
1406 || old_giver_angry_citizens != player_angry_citizens(pgiver)) {
1407 city_refresh_for_player(pgiver);
1408 }
1409
1410 if (pgiver->primary_capital_id == saved_id) {
1411 update_capital(pgiver);
1412 }
1413
1414 sync_cities();
1415
1416 CALL_FUNC_EACH_AI(city_info, pcity);
1417
1418 return city_remains;
1419}
1420
1421/************************************************************************/
1428 void city_build_free_buildings(struct city *pcity)
1429{
1430 struct player *pplayer;
1431 struct nation_type *nation;
1432 int i;
1433 bool has_small_wonders, has_great_wonders;
1434 bool first_city;
1435
1436 fc_assert_ret(NULL != pcity);
1437 pplayer = city_owner(pcity);
1438 fc_assert_ret(NULL != pplayer);
1439 nation = nation_of_player(pplayer);
1440 fc_assert_ret(NULL != nation);
1441
1442 /* If this isn't the first city a player has ever had, they only get
1443 * any initial buildings with the SaveSmallWonder flag, and then only
1444 * if savepalace is enabled. */
1445 first_city = !player_has_flag(pplayer, PLRF_FIRST_CITY);
1446
1447 has_small_wonders = FALSE;
1448 has_great_wonders = FALSE;
1449
1450 /* Global free buildings. */
1451 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1452 Impr_type_id n = game.rgame.global_init_buildings[i];
1453 struct impr_type *pimprove;
1454
1455 if (n == B_LAST) {
1456 break;
1457 }
1458
1459 pimprove = improvement_by_number(n);
1460 fc_assert_action(!is_great_wonder(pimprove), continue);
1461 if (first_city
1462 || (game.server.savepalace
1463 && improvement_has_flag(pimprove, IF_SAVE_SMALL_WONDER))) {
1464 city_add_improvement_with_gov_notice(pcity, pimprove,
1465 /* TRANS: Reason that a building was added to the city.
1466 * Building is given for free to player's first city. */
1467 Q_("?initbldg:Free %s"));
1468 if (is_small_wonder(pimprove)) {
1469 has_small_wonders = TRUE;
1470 }
1471 }
1472 }
1473
1474 /* Nation specific free buildings. */
1475 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1476 Impr_type_id n = nation->init_buildings[i];
1477 struct impr_type *pimprove;
1478
1479 if (n == B_LAST) {
1480 break;
1481 }
1482
1483 pimprove = improvement_by_number(n);
1484 if (first_city
1485 || (game.server.savepalace
1486 && improvement_has_flag(pimprove, IF_SAVE_SMALL_WONDER))) {
1487 city_add_improvement_with_gov_notice(pcity, pimprove,
1488 /* TRANS: Reason that a building was added to the city.
1489 * Building is given for free to player's first city. */
1490 Q_("?initbldg:Free %s"));
1491 if (is_small_wonder(pimprove)) {
1492 has_small_wonders = TRUE;
1493 } else if (is_great_wonder(pimprove)) {
1494 has_great_wonders = TRUE;
1495 }
1496 }
1497 }
1498
1499 /* Update wonder infos. */
1500 if (has_great_wonders) {
1501 send_game_info(NULL);
1502 /* No need to send to detached connections. */
1503 send_player_info_c(pplayer, NULL);
1504 } else if (has_small_wonders) {
1505 /* No need to send to detached connections. */
1506 send_player_info_c(pplayer, NULL);
1507 }
1508}
1509
1510/************************************************************************/
1513 void create_city(struct player *pplayer, struct tile *ptile,
1514 const char *name, struct player *nationality)
1515{
1516 struct player *saved_owner = tile_owner(ptile);
1517 struct tile *saved_claimer = tile_claimer(ptile);
1518 struct city *pwork = tile_worked(ptile);
1519 struct city *pcity;
1520 const citizens old_content_citizens = player_content_citizens(pplayer);
1521 const citizens old_angry_citizens = player_angry_citizens(pplayer);
1522
1523 log_debug("create_city() %s", name);
1524
1525 pcity = create_city_virtual(pplayer, ptile, name);
1526
1527 /* Remove units no more seen. Do it before city is really put into the
1528 * game. */
1529 players_iterate(other_player) {
1530 if (can_player_see_units_in_city(other_player, pcity)
1531 || !map_is_known_and_seen(ptile, other_player, V_MAIN)) {
1532 continue;
1533 }
1534 unit_list_iterate(ptile->units, punit) {
1535 if (can_player_see_unit(other_player, punit)) {
1536 unit_goes_out_of_sight(other_player, punit);
1537 }
1538 } unit_list_iterate_end;
1539 } players_iterate_end;
1540
1541 adv_city_alloc(pcity);
1542
1543 tile_set_owner(ptile, pplayer, ptile); /* Temporarily */
1544 city_choose_build_default(pcity);
1545 pcity->id = identity_number();
1546
1547 fc_mutex_allocate(&game.server.mutexes.city_list);
1548 idex_register_city(&wld, pcity);
1549 fc_mutex_release(&game.server.mutexes.city_list);
1550
1551 if (city_list_size(pplayer->cities) == 0) {
1552 /* Free initial buildings, or at least a palace if they were
1553 * previously careless enough to lose all their cities */
1554 city_build_free_buildings(pcity);
1555 BV_SET(pplayer->flags, PLRF_FIRST_CITY);
1556 }
1557
1558 /* Set up citizens nationality. */
1559 citizens_init(pcity);
1560
1561 /* Place a worker at the is_city_center() is_free_worked().
1562 * It is possible to build a city on a tile that is already worked;
1563 * this will displace the worker on the newly-built city's tile -- Syela */
1564 tile_set_worked(ptile, pcity); /* instead of city_map_update_worker() */
1565
1566 if (NULL != pwork) {
1567 /* was previously worked by another city */
1568 /* Turn citizen into specialist. */
1569 pwork->specialists[DEFAULT_SPECIALIST]++;
1570 /* One less citizen. Citizen sanity will be handled later in
1571 * city_thaw_workers_queue() */
1572 pwork->server.synced = FALSE;
1573 city_freeze_workers_queue(pwork);
1574 }
1575
1576 /* Update citizens. */
1577 citizens_update(pcity, nationality);
1578
1579 /* Restore the old-owner information so removal
1580 * of territory claiming bases can work relative to it. */
1581 tile_set_owner(ptile, saved_owner, saved_claimer);
1582
1583 /* Destroy any extras that don't belong in the city. */
1584 extra_type_iterate(pextra) {
1585 if (tile_has_extra(ptile, pextra)
1586 && !is_native_tile_to_extra(pextra, ptile)) {
1587 destroy_extra(ptile, pextra);
1588 }
1589 } extra_type_iterate_end;
1590
1591 /* Build any extras that the city should have. */
1592 upgrade_city_extras(pcity, NULL);
1593
1594 /* Claim the ground we stand on */
1595 map_claim_ownership(ptile, pplayer, ptile, TRUE);
1596
1597 /* Before arranging workers to show unknown land */
1598 pcity->server.vision = vision_new(pplayer, ptile);
1599 vision_reveal_tiles(pcity->server.vision, game.server.vision_reveal_tiles);
1600 city_refresh_vision(pcity);
1601 city_list_prepend(pplayer->cities, pcity);
1602
1603 /* This is dependent on the current vision, so must be done after
1604 * vision is prepared and before arranging workers. */
1605 map_claim_border(ptile, pplayer, -1);
1606 /* city_thaw_workers_queue() later */
1607
1608 /* Refresh the city. First a city refresh is done (this shouldn't
1609 * send any packets to the client because the city has no supported units)
1610 * then rearrange the workers. Note that auto_arrange_workers does its
1611 * own refresh call; it is safest to do our own controlled city_refresh
1612 * first. */
1613 city_refresh(pcity);
1614 auto_arrange_workers(pcity);
1615 city_thaw_workers_queue(); /* after new city has a chance to work! */
1616 city_refresh_queue_processing();
1617
1618 /* Bases destroyed earlier may have had watchtower effect. Refresh
1619 * unit vision. */
1620 unit_list_refresh_vision(ptile->units);
1621
1622 update_tile_knowledge(ptile);
1623
1624 if (old_content_citizens != player_content_citizens(pplayer)
1625 || old_angry_citizens != player_angry_citizens(pplayer)) {
1626 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1627 * cities for the player. */
1628 city_refresh_for_player(pplayer);
1629 }
1630
1631 pcity->server.synced = FALSE;
1632 send_city_info(NULL, pcity);
1633 sync_cities(); /* Will also send pwork. */
1634
1635 notify_player(pplayer, ptile, E_CITY_BUILD, ftc_server,
1636 _("You have founded %s."),
1637 city_link(pcity));
1638 maybe_make_contact(ptile, city_owner(pcity));
1639
1640 unit_list_iterate((ptile)->units, punit) {
1641 struct city *home = game_city_by_number(punit->homecity);
1642
1643 /* Catch fortress building, transforming into ocean, etc. */
1644 if (!can_unit_continue_current_activity(&(wld.map), punit)) {
1645 unit_activities_cancel(punit);
1646 }
1647
1648 /* Update happiness (the unit may no longer cause unrest). */
1649 if (home) {
1650 if (city_refresh(home)) {
1651 /* Shouldn't happen, but better be safe than sorry. */
1652 auto_arrange_workers(home);
1653 }
1654 sanity_check_city(home);
1655 send_city_info(city_owner(home), home);
1656 }
1657 } unit_list_iterate_end;
1658
1659 sanity_check_city(pcity);
1660
1661 script_server_signal_emit("city_built", pcity);
1662
1663 CALL_FUNC_EACH_AI(city_created, pcity);
1664 CALL_PLR_AI_FUNC(city_got, pplayer, pplayer, pcity);
1665}
1666
1667/************************************************************************/
1673 bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1674 const char *name)
1675{
1676 if (is_enemy_unit_tile(ptile, pplayer)
1677 || !city_can_be_built_here(ptile, NULL, FALSE)) {
1678 return FALSE;
1679 }
1680
1681 if (!pplayer->is_alive) {
1682 pplayer->is_alive = TRUE;
1683 send_player_info_c(pplayer, NULL);
1684 }
1685
1686 if (name == NULL || name[0] == '\0') {
1687 name = city_name_suggestion(pplayer, ptile);
1688 }
1689
1690 map_show_tile(pplayer, ptile);
1691 create_city(pplayer, ptile, name, pplayer);
1692
1693 return TRUE;
1694}
1695
1696/************************************************************************/
1699 void remove_city(struct city *pcity)
1700{
1701 struct player *powner = city_owner(pcity);
1702 struct tile *pcenter = city_tile(pcity);
1703 bv_imprs had_small_wonders;
1704 struct vision *old_vision;
1705 int id = pcity->id; /* We need this even after memory has been freed */
1706 bool had_great_wonders = FALSE;
1707 const citizens old_content_citizens = player_content_citizens(powner);
1708 const citizens old_angry_citizens = player_angry_citizens(powner);
1709 struct dbv tile_processed;
1710 struct tile_list *process_queue;
1711 const char *ctl = city_tile_link(pcity);
1712
1713 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1714 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1715
1716 BV_CLR_ALL(had_small_wonders);
1717 city_built_iterate(pcity, pimprove) {
1718 building_removed(pcity, pimprove, "city_destroyed", NULL);
1719
1720 if (is_small_wonder(pimprove)) {
1721 BV_SET(had_small_wonders, improvement_index(pimprove));
1722 } else if (is_great_wonder(pimprove)) {
1723 had_great_wonders = TRUE;
1724 }
1725 } city_built_iterate_end;
1726
1727 /* Rehome units in other cities */
1728 unit_list_iterate_safe(pcity->units_supported, punit) {
1729 struct city *new_home_city = tile_city(unit_tile(punit));
1730
1731 if (new_home_city
1732 && new_home_city != pcity
1733 && city_owner(new_home_city) == powner
1734 && !punit->server.dying) {
1735 transfer_unit(punit, new_home_city, TRUE, TRUE);
1736 }
1737 } unit_list_iterate_safe_end;
1738
1739 /* Make sure ships are not left on land when city is removed. */
1740 unit_list_iterate_safe(pcenter->units, punit) {
1741 bool moved;
1742 const struct unit_type *punittype = unit_type_get(punit);
1743
1744 if (is_native_tile(punittype, pcenter)) {
1745 continue;
1746 }
1747
1748 unit_activity_handling(punit, ACTIVITY_IDLE);
1749 moved = FALSE;
1750 adjc_iterate(&(wld.map), pcenter, tile1) {
1751 struct unit *ptrans;
1752
1753 if (!moved && is_native_tile(punittype, tile1)) {
1754 if (adv_could_unit_move_to_tile(punit, tile1) == 1) {
1755 /* Move */
1756 if (!can_unit_survive_at_tile(&(wld.map), punit, tile1)) {
1757 /* It may be impossible to survive at the tile even if it is
1758 * native. See UTYF_COAST_STRICT */
1759 ptrans = transporter_for_unit_at(punit, tile1);
1760 } else {
1761 ptrans = NULL;
1762 }
1763 if (action_auto_perf_unit_do(AAPC_CITY_GONE, punit,
1764 tile_owner(tile1), NULL, NULL,
1765 tile1, tile_city(tile1), ptrans,
1766 NULL) != NULL) {
1767 moved = TRUE;
1768 }
1769 if (moved) {
1770 notify_player(unit_owner(punit), tile1,
1771 E_UNIT_RELOCATED, ftc_server,
1772 _("Moved %s out of disbanded city %s "
1773 "since it cannot stay on %s."),
1774 unit_link(punit), ctl,
1775 terrain_name_translation(tile_terrain(pcenter)));
1776 break;
1777 }
1778 }
1779 }
1780 } adjc_iterate_end;
1781 if (!moved) {
1782 notify_player(unit_owner(punit), unit_tile(punit),
1783 E_UNIT_LOST_MISC, ftc_server,
1784 _("When %s was disbanded your %s could not "
1785 "get out, and it was therefore lost."),
1786 ctl,
1787 unit_tile_link(punit));
1788 wipe_unit(punit, ULR_CITY_LOST, NULL);
1789 }
1790 } unit_list_iterate_safe_end;
1791
1792 process_queue = tile_list_new();
1793 dbv_init(&tile_processed, map_num_tiles());
1794 for (tile_list_append(process_queue, pcenter); tile_list_size(process_queue) > 0;) {
1795 struct tile *ptile = tile_list_front(process_queue);
1796
1797 tile_list_pop_front(process_queue);
1798 dbv_set(&tile_processed, tile_index(ptile));
1799 adjc_iterate(&(wld.map), ptile, piter) {
1800 struct city *other_city;
1801
1802 if (dbv_isset(&tile_processed, tile_index(piter))) {
1803 continue;
1804 }
1805 other_city = tile_city(piter);
1806 if (other_city != NULL) {
1807 /* Adjacent tile has a city that may have been part of same channel */
1808 dbv_set(&tile_processed, tile_index(piter));
1809 tile_list_append(process_queue, piter);
1810 unit_list_iterate_safe(piter->units, punit) {
1811 struct unit_class *pclass = utype_class(punit->utype);
1812
1813 if (!uclass_has_flag(pclass, UCF_BUILD_ANYWHERE)
1814 && !is_native_tile(punit->utype, piter)
1815 && !is_city_channel_tile(&(wld.map), pclass, piter, pcenter)) {
1816 notify_player(unit_owner(punit), unit_tile(punit),
1817 E_UNIT_LOST_MISC, ftc_server,
1818 _("When %s was disbanded your %s in %s was trapped, "
1819 "and it was therefore lost."),
1820 ctl,
1821 unit_tile_link(punit),
1822 city_link(other_city));
1823 wipe_unit(punit, ULR_CITY_LOST, NULL);
1824 }
1825 } unit_list_iterate_safe_end;
1826 } else {
1827 dbv_set(&tile_processed, tile_index(piter));
1828 }
1829 } adjc_iterate_end;
1830 }
1831
1832 dbv_free(&tile_processed);
1833 tile_list_destroy(process_queue);
1834
1835 if (!city_exist(id)) {
1836 /* Wiping trapped units caused city to disappear. */
1837 return;
1838 }
1839
1840 /* Any remaining supported units are destroyed */
1841 unit_list_iterate_safe(pcity->units_supported, punit) {
1842 wipe_unit(punit, ULR_CITY_LOST, NULL);
1843 } unit_list_iterate_safe_end;
1844
1845 if (!city_exist(id)) {
1846 /* Wiping supported units caused city to disappear. */
1847 return;
1848 }
1849
1850 trade_routes_iterate_safe(pcity, proute) {
1851 struct trade_route *pback = remove_trade_route(pcity, proute,
1852 TRUE, TRUE);
1853
1854 FC_FREE(proute);
1855 FC_FREE(pback);
1856 } trade_routes_iterate_safe_end;
1857
1858 map_clear_border(pcenter);
1859 city_workers_queue_remove(pcity);
1860 city_thaw_workers_queue();
1861 city_refresh_queue_processing();
1862
1863 /* idex_unregister_city() is called in game_remove_city() below */
1864
1865 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1866 still be alive in the client, or in the player map. The number of
1867 removed cities is small, so the loss is acceptable.
1868 */
1869
1870 old_vision = pcity->server.vision;
1871 pcity->server.vision = NULL;
1872 script_server_remove_exported_object(pcity);
1873 adv_city_free(pcity);
1874
1875 /* Remove city from the map. */
1876 tile_set_worked(pcenter, NULL);
1877
1878 /* Reveal units. */
1879 players_iterate(other_player) {
1880 if (can_player_see_units_in_city(other_player, pcity)
1881 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1882 continue;
1883 }
1884 unit_list_iterate(pcenter->units, punit) {
1885 if (can_player_see_unit(other_player, punit)) {
1886 send_unit_info(other_player->connections, punit);
1887 }
1888 } unit_list_iterate_end;
1889 } players_iterate_end;
1890
1891 fc_mutex_allocate(&game.server.mutexes.city_list);
1892 game_remove_city(&wld, pcity);
1893 fc_mutex_release(&game.server.mutexes.city_list);
1894
1895 /* Remove any extras that were only there because the city was there. */
1896 extra_type_iterate(pextra) {
1897 if (tile_has_extra(pcenter, pextra)
1898 && !is_native_tile_to_extra(pextra, pcenter)) {
1899 tile_extra_rm_apply(pcenter, pextra);
1900 }
1901 } extra_type_iterate_end;
1902
1903 players_iterate(other_player) {
1904 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1905 reality_check_city(other_player, pcenter);
1906 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1907 map_show_tile(other_player, pcenter);
1908 }
1909 } players_iterate_end;
1910
1911 conn_list_iterate(game.est_connections, pconn) {
1912 if (NULL == pconn->playing && pconn->observer) {
1913 /* For detached observers we have to send a specific packet. This is
1914 * a hack necessitated by the private map that exists for players but
1915 * not observers. */
1916 dsend_packet_city_remove(pconn, id);
1917 }
1918 } conn_list_iterate_end;
1919
1920 if (old_vision != NULL) {
1921 vision_clear_sight(old_vision);
1922 vision_free(old_vision);
1923 }
1924
1925 /* Infrastructures may have changed. */
1926 send_tile_info(NULL, pcenter, FALSE);
1927
1928 /* Build a new palace for free if the player lost their capital and
1929 savepalace is on. */
1930 build_free_small_wonders(powner, &had_small_wonders);
1931
1932 /* Update wonder infos. */
1933 if (had_great_wonders) {
1934 send_game_info(NULL);
1935 /* No need to send to detached connections. */
1936 send_player_info_c(powner, NULL);
1937 } else if (BV_ISSET_ANY(had_small_wonders)) {
1938 /* No need to send to detached connections. */
1939 send_player_info_c(powner, NULL);
1940 }
1941
1942 if (old_content_citizens != player_content_citizens(powner)
1943 || old_angry_citizens != player_angry_citizens(powner)) {
1944 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1945 * cities for the player. */
1946 city_refresh_for_player(powner);
1947 }
1948
1949 sync_cities();
1950
1951 /* At least sentried helicopters need to go idle, maybe others.
1952 * In alien ruleset, city center might have provided water source
1953 * for adjacent tile. */
1954 tile_change_side_effects(pcenter, FALSE);
1955}
1956
1957/************************************************************************/
1973 bool unit_conquer_city(struct unit *punit, struct city *pcity)
1974{
1975 bool try_civil_war = FALSE;
1976 bool city_remains;
1977 int coins;
1978 struct player *pplayer = unit_owner(punit);
1979 struct player *cplayer = city_owner(pcity);
1980#ifndef FREECIV_NDEBUG
1981 const struct unit_type *utype = unit_type_get(punit);
1982#endif
1983
1984 /* If not at war, may peacefully enter city. */
1985 fc_assert_ret_val_msg(pplayers_at_war(pplayer, cplayer), FALSE,
1986 "Can't conquer city during peace.");
1987
1988 /* If we cannot occupy the city, this unit entering will not trigger the
1989 * effects below. */
1990 fc_assert_ret_val_msg(unit_can_take_over(punit)
1991 || utype_can_do_action_result(utype, ACTRES_PARADROP_CONQUER)
1992 || utype_can_do_action_result(utype, ACTRES_TELEPORT_CONQUER),
1993 FALSE, "Bad unit for city occupation.");
1994
1995 /* A transported unit trying to conquer a city should already have been
1996 * unloaded. */
1997 fc_assert_ret_val_msg(punit->transporter == NULL, FALSE,
1998 "Can't conquer city while transported.");
1999
2000 /* Okay, we're at war - invader captures/destroys city... */
2001
2002 /* If a capital is captured, then spark off a civil war
2003 - Kris Bubendorfer
2004 Also check spaceships --dwp
2005 */
2006
2007 if (is_capital(pcity)
2008 && (cplayer->spaceship.state == SSHIP_STARTED
2009 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
2010 spaceship_lost(cplayer);
2011 }
2012
2013 if (is_capital(pcity)
2014 && civil_war_possible(cplayer, TRUE, TRUE)
2015 && normal_player_count() < MAX_NUM_PLAYERS
2016 && civil_war_triggered(cplayer)) {
2017 try_civil_war = TRUE;
2018 }
2019
2020 /*
2021 * We later remove a citizen. Lets check if we can save this since
2022 * the city will be destroyed.
2023 */
2024 if (city_size_get(pcity) <= 1) {
2025 int saved_id = pcity->id;
2026
2027 notify_player(pplayer, city_tile(pcity), E_CITY_CONQUERED, ftc_server,
2028 _("You destroy %s completely."),
2029 city_tile_link(pcity));
2030 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2031 _("%s has been destroyed by %s."),
2032 city_tile_link(pcity), player_name(pplayer));
2033 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2034
2035 /* We cant't be sure of city existence after running some script */
2036 if (city_exist(saved_id)) {
2037 remove_city(pcity);
2038 }
2039
2040 if (try_civil_war) {
2041 (void) civil_war(cplayer);
2042 }
2043 return TRUE;
2044 }
2045
2046 coins = cplayer->economic.gold;
2047 coins = MIN(coins,
2048 fc_rand((coins / 20) + 1)
2049 + (coins * (city_size_get(pcity))) / 200);
2050 pplayer->economic.gold += coins;
2051 cplayer->economic.gold -= coins;
2052 send_player_info_c(pplayer, pplayer->connections);
2053 send_player_info_c(cplayer, cplayer->connections);
2054 if (pcity->original != pplayer) {
2055 if (coins > 0) {
2056 notify_player(pplayer, city_tile(pcity), E_CITY_CONQUERED, ftc_server,
2057 PL_("You conquer %s; your lootings accumulate"
2058 " to %d gold!",
2059 "You conquer %s; your lootings accumulate"
2060 " to %d gold!", coins),
2061 city_link(pcity),
2062 coins);
2063 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2064 PL_("%s conquered %s and looted %d gold"
2065 " from the city.",
2066 "%s conquered %s and looted %d gold"
2067 " from the city.", coins),
2068 player_name(pplayer),
2069 city_link(pcity),
2070 coins);
2071 } else {
2072 notify_player(pplayer, city_tile(pcity), E_CITY_CONQUERED, ftc_server,
2073 _("You conquer %s."),
2074 city_link(pcity));
2075 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2076 _("%s conquered %s."),
2077 player_name(pplayer),
2078 city_link(pcity));
2079 }
2080 } else {
2081 if (coins > 0) {
2082 notify_player(pplayer, city_tile(pcity), E_CITY_CONQUERED, ftc_server,
2083 PL_("You have liberated %s!"
2084 " Lootings accumulate to %d gold.",
2085 "You have liberated %s!"
2086 " Lootings accumulate to %d gold.", coins),
2087 city_link(pcity),
2088 coins);
2089 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2090 PL_("%s liberated %s and looted %d gold"
2091 " from the city.",
2092 "%s liberated %s and looted %d gold"
2093 " from the city.", coins),
2094 player_name(pplayer),
2095 city_link(pcity),
2096 coins);
2097 } else {
2098 notify_player(pplayer, city_tile(pcity), E_CITY_CONQUERED, ftc_server,
2099 _("You have liberated %s!"),
2100 city_link(pcity));
2101 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2102 _("%s liberated %s."),
2103 player_name(pplayer),
2104 city_link(pcity));
2105 }
2106 }
2107
2108 if (fc_rand(100) < get_unit_bonus(punit, EFT_CONQUEST_TECH_PCT)) {
2109 /* Just try to steal. Ignore failures to get tech */
2110 steal_a_tech(pplayer, cplayer, A_UNSET);
2111 }
2112
2113 /* We transfer the city first so that it is in a consistent state when
2114 * the size is reduced. */
2115 /* FIXME: maybe it should be a ruleset option whether barbarians get
2116 * free buildings such as palaces? */
2117 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2118 !is_barbarian(pplayer));
2119
2120 if (city_remains) {
2121 /* reduce size should not destroy this city */
2122 fc_assert(city_size_get(pcity) > 1);
2123 city_reduce_size(pcity, 1, pplayer, "conquest");
2124 }
2125
2126 if (try_civil_war) {
2127 (void) civil_war(cplayer);
2128 }
2129
2130 if (city_remains) {
2131 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2132 "conquest");
2133 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2134 }
2135
2136 return TRUE;
2137}
2138
2139/************************************************************************/
2142 static int city_citywalls_gfx(const struct city *pcity)
2143{
2144 int walls = get_city_bonus(pcity, EFT_VISIBLE_WALLS);
2145
2146 return walls > 0 ? walls : 0;
2147}
2148
2149/************************************************************************/
2152 bool send_city_suppression(bool now)
2153{
2154 bool formerly = send_city_suppressed;
2155
2156 send_city_suppressed = now;
2157 return formerly;
2158}
2159
2160/************************************************************************/
2163 static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2164 struct packet_city_short_info *packet)
2165{
2166 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2167
2168 packet->id = pdcity->identity;
2169 packet->owner = player_number(vision_site_owner(pdcity));
2170
2171 packet->tile = tile_index(ptile);
2172 if (pdcity->name == NULL) {
2173 packet->name[0] = '\0';
2174 } else {
2175 sz_strlcpy(packet->name, pdcity->name);
2176 }
2177
2178 packet->size = vision_site_size_get(pdcity);
2179
2180 packet->occupied = pdcity->occupied;
2181 packet->walls = pdcity->walls;
2182 packet->style = pdcity->style;
2183 packet->city_image = pdcity->city_image;
2184 packet->capital = pdcity->capital;
2185
2186 packet->happy = pdcity->happy;
2187 packet->unhappy = pdcity->unhappy;
2188
2189 packet->improvements = pdcity->improvements;
2190}
2191
2192/************************************************************************/
2196 void refresh_dumb_city(struct city *pcity)
2197{
2198 players_iterate(pplayer) {
2199 if (player_can_see_city_externals(pplayer, pcity)) {
2200 if (update_dumb_city(pplayer, pcity)) {
2201 struct packet_city_short_info packet;
2202
2203 if (city_owner(pcity) != pplayer) {
2204 /* Don't send the short_city information to someone who can see the
2205 * city's internals. Doing so would really confuse the client. */
2206 package_dumb_city(pplayer, pcity->tile, &packet);
2207 lsend_packet_city_short_info(pplayer->connections, &packet);
2208 }
2209 }
2210 }
2211 } players_iterate_end;
2212
2213 /* Don't send to non-player observers since they don't have 'dumb city'
2214 * information. */
2215}
2216
2217/************************************************************************/
2225 void broadcast_city_info(struct city *pcity)
2226{
2227 struct packet_city_info packet;
2228 struct packet_city_nationalities nat_packet;
2229 struct packet_city_rally_point rally_packet;
2230 struct packet_web_city_info_addition web_packet;
2231 struct packet_city_short_info sc_pack;
2232 struct player *powner = city_owner(pcity);
2233 struct trade_route_packet_list *routes;
2234 struct packet_web_city_info_addition *webp_ptr;
2235
2236 /* Send to everyone who can see the city. */
2237
2238 if (pcity->server.needs_arrange != CNA_NOT) {
2239 /* Send city only when it's in sane state.
2240 * If it's not, it will be sent to everyone once
2241 * rearrangement has been finished. */
2242 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2243
2244 return;
2245 }
2246
2247 if (any_web_conns()) {
2248 webp_ptr = &web_packet;
2249 } else {
2250 webp_ptr = NULL;
2251 }
2252
2253 routes = trade_route_packet_list_new();
2254 package_city(pcity, &packet, &nat_packet, &rally_packet,
2255 webp_ptr, routes, FALSE);
2256
2257 players_iterate(pplayer) {
2258 if (!send_city_suppressed || pplayer != powner) {
2259 if (can_player_see_city_internals(pplayer, pcity)) {
2260 update_dumb_city(pplayer, pcity);
2261 packet.original = city_original_owner(pcity, pplayer);
2262 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2263 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2264 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2265 web_lsend_packet(city_info_addition, pplayer->connections,
2266 webp_ptr, FALSE);
2267 trade_route_packet_list_iterate(routes, route_packet) {
2268 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2269 } trade_route_packet_list_iterate_end;
2270 } else if (player_can_see_city_externals(pplayer, pcity)) {
2271 reality_check_city(pplayer, pcity->tile);
2272 update_dumb_city(pplayer, pcity);
2273 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2274 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2275 }
2276 }
2277 } players_iterate_end;
2278
2279 /* Send to global observers. */
2280 packet.original = city_original_owner(pcity, NULL);
2281 conn_list_iterate(game.est_connections, pconn) {
2282 if (conn_is_global_observer(pconn)) {
2283 send_packet_city_info(pconn, &packet, FALSE);
2284 send_packet_city_nationalities(pconn, &nat_packet, FALSE);
2285 send_packet_city_rally_point(pconn, &rally_packet, FALSE);
2286 web_send_packet(city_info_addition, pconn, webp_ptr, FALSE);
2287 }
2288 } conn_list_iterate_end;
2289
2290 trade_route_packet_list_iterate(routes, route_packet) {
2291 FC_FREE(route_packet);
2292 } trade_route_packet_list_iterate_end;
2293 trade_route_packet_list_destroy(routes);
2294}
2295
2296/************************************************************************/
2300 void send_all_known_cities(struct conn_list *dest)
2301{
2302 conn_list_do_buffer(dest);
2303 conn_list_iterate(dest, pconn) {
2304 struct player *pplayer = pconn->playing;
2305
2306 if (!pplayer && !pconn->observer) {
2307 continue;
2308 }
2309 whole_map_iterate(&(wld.map), ptile) {
2310 if (!pplayer || NULL != map_get_player_site(ptile, pplayer)) {
2311 send_city_info_at_tile(pplayer, pconn->self, NULL, ptile);
2312 }
2313 } whole_map_iterate_end;
2314 }
2315 conn_list_iterate_end;
2316 conn_list_do_unbuffer(dest);
2317 flush_packets();
2318}
2319
2320/************************************************************************/
2323 void send_player_cities(struct player *pplayer)
2324{
2325 city_list_iterate(pplayer->cities, pcity) {
2326 if (city_refresh(pcity)) {
2327 log_error("%s radius changed while sending to player.",
2328 city_name_get(pcity));
2329
2330 /* Make sure that no workers in illegal position outside radius. */
2331 auto_arrange_workers(pcity);
2332 }
2333 send_city_info(pplayer, pcity);
2334 }
2335 city_list_iterate_end;
2336}
2337
2338/************************************************************************/
2343 void send_city_info(struct player *dest, struct city *pcity)
2344{
2345 struct player *powner = city_owner(pcity);
2346
2347 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2348 return;
2349 }
2350
2351 if (dest == powner && send_city_suppressed) {
2352 return;
2353 }
2354
2355 if (!dest || dest == powner) {
2356 pcity->server.synced = TRUE;
2357 }
2358
2359 if (!dest) {
2360 broadcast_city_info(pcity);
2361 } else {
2362 send_city_info_at_tile(dest, dest->connections, pcity, pcity->tile);
2363 }
2364
2365 /* Sending counters */
2366 city_counters_refresh(pcity);
2367
2368 if (game.info.team_pooled_research
2369 && player_list_size(team_members(powner->team)) > 1) {
2370 /* We want to send the new total bulbs production of the team. */
2371 send_research_info(research_get(powner), NULL);
2372 }
2373}
2374
2375/************************************************************************/
2395 void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest,
2396 struct city *pcity, struct tile *ptile)
2397{
2398 struct packet_city_info packet;
2399 struct packet_city_nationalities nat_packet;
2400 struct packet_city_rally_point rally_packet;
2401 struct packet_web_city_info_addition web_packet;
2402 struct packet_city_short_info sc_pack;
2403 struct player *powner = NULL;
2404 struct trade_route_packet_list *routes = NULL;
2405 struct packet_web_city_info_addition *webp_ptr;
2406
2407 if (!pcity) {
2408 pcity = tile_city(ptile);
2409 }
2410 if (pcity != NULL && pcity->server.needs_arrange != CNA_NOT) {
2411 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2412
2413 return;
2414 }
2415 if (pcity) {
2416 powner = city_owner(pcity);
2417 }
2418
2419 if (any_web_conns()) {
2420 webp_ptr = &web_packet;
2421 } else {
2422 webp_ptr = NULL;
2423 }
2424
2425 if (powner != NULL && powner == pviewer) {
2426 /* Send info to owner */
2427 /* This case implies powner non-NULL which means pcity non-NULL */
2428 if (!send_city_suppressed) {
2429 /* Wait that city has been rearranged, if it's currently
2430 * not in sane state. */
2431
2432 routes = trade_route_packet_list_new();
2433
2434 /* Send all info to the owner */
2435 update_dumb_city(powner, pcity);
2436 package_city(pcity, &packet, &nat_packet, &rally_packet,
2437 webp_ptr, routes, FALSE);
2438 packet.original = city_original_owner(pcity, pviewer);
2439 lsend_packet_city_info(dest, &packet, FALSE);
2440 lsend_packet_city_nationalities(dest, &nat_packet, FALSE);
2441 lsend_packet_city_rally_point(dest, &rally_packet, FALSE);
2442 web_lsend_packet(city_info_addition, dest, webp_ptr, FALSE);
2443 trade_route_packet_list_iterate(routes, route_packet) {
2444 lsend_packet_trade_route_info(dest, route_packet);
2445 } trade_route_packet_list_iterate_end;
2446 if (dest == powner->connections) {
2447 /* HACK: send also a copy to global observers. */
2448 packet.original = city_original_owner(pcity, NULL);
2449 conn_list_iterate(game.est_connections, pconn) {
2450 if (conn_is_global_observer(pconn)) {
2451 send_packet_city_info(pconn, &packet, FALSE);
2452 trade_route_packet_list_iterate(routes, route_packet) {
2453 send_packet_trade_route_info(pconn, route_packet);
2454 } trade_route_packet_list_iterate_end;
2455 }
2456 } conn_list_iterate_end;
2457 }
2458 }
2459 } else {
2460 /* send info to non-owner */
2461 if (!pviewer) { /* observer */
2462 if (pcity) {
2463 routes = trade_route_packet_list_new();
2464
2465 /* Should be dumb_city info? */
2466 package_city(pcity, &packet, &nat_packet, &rally_packet,
2467 webp_ptr, routes, FALSE);
2468 lsend_packet_city_info(dest, &packet, FALSE);
2469 lsend_packet_city_nationalities(dest, &nat_packet, FALSE);
2470 lsend_packet_city_rally_point(dest, &rally_packet, FALSE);
2471 web_lsend_packet(city_info_addition, dest, webp_ptr, FALSE);
2472 trade_route_packet_list_iterate(routes, route_packet) {
2473 lsend_packet_trade_route_info(dest, route_packet);
2474 } trade_route_packet_list_iterate_end;
2475 }
2476 } else {
2477 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2478 if (pcity) { /* it's there and we see it; update and send */
2479 update_dumb_city(pviewer, pcity);
2480 package_dumb_city(pviewer, ptile, &sc_pack);
2481 lsend_packet_city_short_info(dest, &sc_pack);
2482 }
2483 } else { /* not seen; send old info */
2484 if (map_is_known(ptile, pviewer)
2485 && map_get_player_site(ptile, pviewer) != NULL) {
2486 package_dumb_city(pviewer, ptile, &sc_pack);
2487 lsend_packet_city_short_info(dest, &sc_pack);
2488 }
2489 }
2490 }
2491 }
2492
2493 if (routes != NULL) {
2494 trade_route_packet_list_iterate(routes, route_packet) {
2495 FC_FREE(route_packet);
2496 } trade_route_packet_list_iterate_end;
2497 trade_route_packet_list_destroy(routes);
2498 }
2499}
2500
2501/************************************************************************/
2506 void package_city(struct city *pcity, struct packet_city_info *packet,
2507 struct packet_city_nationalities *nat_packet,
2508 struct packet_city_rally_point *rally_packet,
2509 struct packet_web_city_info_addition *web_packet,
2510 struct trade_route_packet_list *routes,
2511 bool dipl_invest)
2512{
2513 int i;
2514 int ppl = 0;
2515
2516 fc_assert(!pcity->server.needs_arrange);
2517
2518 packet->id = pcity->id;
2519 packet->owner = player_number(city_owner(pcity));
2520
2521 packet->tile = tile_index(city_tile(pcity));
2522 sz_strlcpy(packet->name, city_name_get(pcity));
2523
2524 packet->size = city_size_get(pcity);
2525 for (i = 0; i < FEELING_LAST; i++) {
2526 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2527 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2528 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2529 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2530 if (i == 0) {
2531 ppl += packet->ppl_happy[i];
2532 ppl += packet->ppl_content[i];
2533 ppl += packet->ppl_unhappy[i];
2534 ppl += packet->ppl_angry[i];
2535 }
2536 }
2537 /* The number of data in specialists[] array */
2538 packet->specialists_size = specialist_count();
2539 specialist_type_iterate(sp) {
2540 packet->specialists[sp] = pcity->specialists[sp];
2541 ppl += packet->specialists[sp];
2542 } specialist_type_iterate_end;
2543
2544 /* The nationality of the citizens. */
2545 nat_packet->id = pcity->id;
2546 nat_packet->nationalities_count = 0;
2547 if (game.info.citizen_nationality) {
2548 int cit = 0;
2549
2550 player_slots_iterate(pslot) {
2551 citizens nationality = citizens_nation_get(pcity, pslot);
2552 if (nationality != 0) {
2553 /* This player should exist! */
2554 fc_assert(player_slot_get_player(pslot) != NULL);
2555
2556 nat_packet->nation_id[nat_packet->nationalities_count]
2557 = player_slot_index(pslot);
2558 nat_packet->nation_citizens[nat_packet->nationalities_count]
2559 = nationality;
2560 nat_packet->nationalities_count++;
2561
2562 cit += nationality;
2563 }
2564 } player_slots_iterate_end;
2565
2566 fc_assert(cit == packet->size);
2567 }
2568
2569 packet->history = pcity->history;
2570 packet->culture = city_culture(pcity);
2571 packet->buy_cost = city_production_buy_gold_cost(pcity);
2572
2573 if (packet->size != ppl) {
2574 static bool recursion = FALSE;
2575
2576 if (recursion) {
2577 /* Recursion didn't help. Do not enter infinite recursive loop.
2578 * Package city as it is. */
2579 log_error("Failed to fix inconsistent city size.");
2580 recursion = FALSE;
2581 } else {
2582 /* Note: If you get this error and try to debug the cause, you may find
2583 * using check_city_feelings() in some key points useful. */
2584 /* Have this as an fc_assert() first, so one can use '-F' to caught these in
2585 * debugger. */
2586 fc_assert(packet->size == ppl);
2587
2588 /* In all builds have an error message shown. */
2589 log_error("City size %d, citizen count %d for %s",
2590 packet->size, ppl, city_name_get(pcity));
2591
2592 /* Try to fix */
2593 city_refresh(pcity);
2594 auto_arrange_workers(pcity);
2595
2596 /* And repackage */
2597 recursion = TRUE;
2598 package_city(pcity, packet, nat_packet, rally_packet,
2599 web_packet, routes, dipl_invest);
2600 recursion = FALSE;
2601
2602 return;
2603 }
2604 }
2605
2606 packet->city_radius_sq = pcity->city_radius_sq;
2607
2608 i = 0;
2609 trade_routes_iterate(pcity, proute) {
2610 struct packet_trade_route_info *tri_packet = fc_malloc(sizeof(struct packet_trade_route_info));
2611
2612 tri_packet->city = pcity->id;
2613 tri_packet->index = i;
2614 tri_packet->partner = proute->partner;
2615 tri_packet->value = proute->value;
2616 tri_packet->direction = proute->dir;
2617 tri_packet->goods = goods_number(proute->goods);
2618
2619 trade_route_packet_list_append(routes, tri_packet);
2620
2621 i++;
2622 } trade_routes_iterate_end;
2623
2624 packet->trade_route_count = i;
2625
2626 output_type_iterate(o) {
2627 packet->surplus[o] = pcity->surplus[o];
2628 packet->waste[o] = pcity->waste[o];
2629 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2630 packet->prod[o] = pcity->prod[o];
2631 packet->citizen_base[o] = pcity->citizen_base[o];
2632 packet->usage[o] = pcity->usage[o];
2633 } output_type_iterate_end;
2634
2635 packet->food_stock = pcity->food_stock;
2636 packet->shield_stock = pcity->shield_stock;
2637 packet->pollution = pcity->pollution;
2638 packet->illness_trade = pcity->illness_trade;
2639 packet->city_options = pcity->city_options;
2640
2641 packet->production_kind = pcity->production.kind;
2642 packet->production_value = universal_number(&pcity->production);
2643
2644 packet->turn_last_built = pcity->turn_last_built;
2645 packet->turn_founded = pcity->turn_founded;
2646
2647 packet->changed_from_kind = pcity->changed_from.kind;
2648 packet->changed_from_value = universal_number(&pcity->changed_from);
2649
2650 packet->before_change_shields = pcity->before_change_shields;
2651 packet->disbanded_shields = pcity->disbanded_shields;
2652 packet->caravan_shields = pcity->caravan_shields;
2653 packet->last_turns_shield_surplus = pcity->last_turns_shield_surplus;
2654
2655 worklist_copy(&packet->worklist, &pcity->worklist);
2656 packet->diplomat_investigate = dipl_invest;
2657
2658 packet->airlift = pcity->airlift;
2659 packet->did_buy = pcity->did_buy;
2660 packet->did_sell = pcity->did_sell;
2661 packet->was_happy = pcity->was_happy;
2662 packet->had_famine = pcity->had_famine;
2663
2664 packet->walls = city_citywalls_gfx(pcity);
2665 packet->style = pcity->style;
2666 packet->city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2667 packet->capital = pcity->capital;
2668 packet->steal = pcity->steal;
2669
2670 rally_packet->id = pcity->id;
2671 rally_packet->length = pcity->rally_point.length;
2672 rally_packet->persistent = pcity->rally_point.persistent;
2673 rally_packet->vigilant = pcity->rally_point.vigilant;
2674 if (pcity->rally_point.length) {
2675 memcpy(rally_packet->orders, pcity->rally_point.orders,
2676 pcity->rally_point.length * sizeof(struct unit_order));
2677 }
2678
2679 BV_CLR_ALL(packet->improvements);
2680 improvement_iterate(pimprove) {
2681 if (city_has_building(pcity, pimprove)) {
2682 BV_SET(packet->improvements, improvement_index(pimprove));
2683 }
2684 } improvement_iterate_end;
2685
2686#ifdef FREECIV_WEB
2687 if (web_packet != NULL) {
2688 struct tile *pcenter = city_tile(pcity);
2689
2690 BV_CLR_ALL(web_packet->can_build_unit);
2691 BV_CLR_ALL(web_packet->can_build_improvement);
2692
2693 web_packet->id = pcity->id;
2694
2695 if (pcity->cm_parameter != NULL) {
2696 web_packet->cma_enabled = TRUE;
2697 cm_copy_parameter(&web_packet->cm_parameter, pcity->cm_parameter);
2698 } else {
2699 web_packet->cma_enabled = FALSE;
2700 memset(&web_packet->cm_parameter, 0, sizeof(web_packet->cm_parameter));
2701 }
2702
2703 web_packet->granary_size = city_granary_size(city_size_get(pcity));
2704 web_packet->granary_turns = city_turns_to_grow(pcity);
2705
2706 improvement_iterate(pimprove) {
2707 if (can_city_build_improvement_now(pcity, pimprove)) {
2708 BV_SET(web_packet->can_build_improvement, improvement_index(pimprove));
2709 }
2710 } improvement_iterate_end;
2711
2712 unit_type_iterate(punittype) {
2713 if (can_city_build_unit_now(pcity, punittype)) {
2714 BV_SET(web_packet->can_build_unit, utype_index(punittype));
2715 }
2716 } unit_type_iterate_end;
2717
2718 i = 0;
2719 city_tile_iterate(city_map_radius_sq_get(pcity), pcenter, ptile) {
2720 web_packet->output_food[i] = city_tile_output_now(pcity, ptile, O_FOOD);
2721 web_packet->output_shield[i] = city_tile_output_now(pcity, ptile, O_SHIELD);
2722 web_packet->output_trade[i] = city_tile_output_now(pcity, ptile, O_TRADE);
2723
2724 i++;
2725 } city_tile_iterate_end;
2726 }
2727#endif /* FREECIV_WEB */
2728}
2729
2730/************************************************************************/
2740 bool update_dumb_city(struct player *pplayer, struct city *pcity)
2741{
2742 bv_imprs improvements;
2743 struct tile *pcenter = city_tile(pcity);
2744 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2745 /* pcity->client.occupied isn't used at the server, so we go straight to the
2746 * unit list to check the occupied status. */
2747 bool occupied = (unit_list_size(pcenter->units) > 0);
2748 int walls = city_citywalls_gfx(pcity);
2749 bool happy = city_happy(pcity);
2750 bool unhappy = city_unhappy(pcity);
2751 int style = pcity->style;
2752 int city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2753 enum capital_type capital = pcity->capital;
2754
2755 /* Only someone knowing the tile should ever know a city on it. */
2756 fc_assert(map_is_known(pcenter, pplayer));
2757
2758 BV_CLR_ALL(improvements);
2759 improvement_iterate(pimprove) {
2760 if (is_improvement_visible(pimprove)
2761 && city_has_building(pcity, pimprove)) {
2762 BV_SET(improvements, improvement_index(pimprove));
2763 }
2764 } improvement_iterate_end;
2765
2766 if (NULL == pdcity) {
2767 pdcity = vision_site_new_from_city(pcity);
2768 change_playertile_site(map_get_player_tile(pcenter, pplayer), pdcity);
2769 } else if (pdcity->location != pcenter) {
2770 log_error("Trying to update bad city (wrong location) "
2771 "at %i,%i for player %s",
2772 TILE_XY(pcity->tile), player_name(pplayer));
2773 fc_assert(pdcity->location == pcenter);
2774 pdcity->location = pcenter; /* ?? */
2775 } else if (pdcity->identity != pcity->id) {
2776 log_error("Trying to update old city (wrong identity) "
2777 "at %i,%i for player %s",
2778 TILE_XY(city_tile(pcity)), player_name(pplayer));
2779 fc_assert(pdcity->identity == pcity->id);
2780 pdcity->identity = pcity->id; /* ?? */
2781 } else if (pdcity->occupied == occupied
2782 && pdcity->walls == walls
2783 && pdcity->happy == happy
2784 && pdcity->unhappy == unhappy
2785 && pdcity->style == style
2786 && pdcity->city_image == city_image
2787 && pdcity->capital == capital
2788 && BV_ARE_EQUAL(pdcity->improvements, improvements)
2789 && vision_site_size_get(pdcity) == city_size_get(pcity)
2790 && vision_site_owner(pdcity) == city_owner(pcity)
2791 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2792 return FALSE;
2793 }
2794
2795 vision_site_update_from_city(pdcity, pcity);
2796 pdcity->occupied = occupied;
2797 pdcity->walls = walls;
2798 pdcity->style = style;
2799 pdcity->city_image = city_image;
2800 pdcity->capital = capital;
2801 pdcity->happy = happy;
2802 pdcity->unhappy = unhappy;
2803 pdcity->improvements = improvements;
2804
2805 return TRUE;
2806}
2807
2808/************************************************************************/
2811 void reality_check_city(struct player *pplayer, struct tile *ptile)
2812{
2813 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2814
2815 if (pdcity) {
2816 struct city *pcity = tile_city(ptile);
2817
2818 if (!pcity || pcity->id != pdcity->identity) {
2819 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2820
2821 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2822 fc_assert_ret(playtile->site == pdcity);
2823 playtile->site = NULL;
2824 vision_site_destroy(pdcity);
2825 }
2826 }
2827}
2828
2829/************************************************************************/
2832 void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2833{
2834 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2835
2836 if (pdcity) {
2837 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2838
2839 dlsend_packet_city_remove(pplayer->connections, pdcity->identity);
2840 fc_assert_ret(playtile->site == pdcity);
2841 playtile->site = NULL;
2842 vision_site_destroy(pdcity);
2843 }
2844}
2845
2846/************************************************************************/
2850 static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2851 bool source_gone)
2852{
2853 struct player *plr1 = city_owner(pc1);
2854 struct player *plr2 = city_owner(pc2);
2855 char city1_link[MAX_LEN_LINK];
2856 char city2_link[MAX_LEN_LINK];
2857
2858 sz_strlcpy(city1_link, city_link(pc1));
2859 sz_strlcpy(city2_link, city_link(pc2));
2860
2861 if (plr1 == plr2) {
2862 if (source_gone) {
2863 notify_player(plr2, city_tile(pc2),
2864 E_CARAVAN_ACTION, ftc_server,
2865 _("Trade between %s and %s lost along with city."),
2866 city1_link, city2_link);
2867 } else {
2868 notify_player(plr1, city_tile(pc1),
2869 E_CARAVAN_ACTION, ftc_server,
2870 _("Trade route between %s and %s canceled."),
2871 city1_link, city2_link);
2872 }
2873 } else {
2874 if (source_gone) {
2875 notify_player(plr2, city_tile(pc2),
2876 E_CARAVAN_ACTION, ftc_server,
2877 /* TRANS: "...between Spanish city Madrid and Paris..." */
2878 _("Trade between %s city %s and %s lost along with "
2879 "their city."),
2880 nation_adjective_for_player(plr1), city1_link, city2_link);
2881 /* It's implicit to removed city's owner that that city no longer
2882 * has trade routes, so say nothing in that case */
2883 } else {
2884 notify_player(plr2, city_tile(pc2),
2885 E_CARAVAN_ACTION, ftc_server,
2886 _("Sorry, the %s canceled the trade route "
2887 "from %s to your city %s."),
2888 nation_plural_for_player(plr1), city1_link, city2_link);
2889 notify_player(plr1, city_tile(pc1),
2890 E_CARAVAN_ACTION, ftc_server,
2891 /* TRANS: "...from Paris to Spanish city Madrid." */
2892 _("We canceled the trade route "
2893 "from %s to %s city %s."),
2894 city1_link, nation_adjective_for_player(plr2), city2_link);
2895 }
2896 }
2897}
2898
2899/************************************************************************/
2907 struct trade_route *remove_trade_route(struct city *pc1, struct trade_route *proute,
2908 bool announce, bool source_gone)
2909{
2910 struct city *pc2 = game_city_by_number(proute->partner);
2911 struct trade_route *back_route = NULL;
2912
2913 fc_assert_ret_val(pc1 && proute, NULL);
2914
2915 trade_route_list_remove(pc1->routes, proute);
2916
2917 if (pc2 != NULL) {
2918 trade_routes_iterate(pc2, pback) {
2919 if (pc1->id == pback->partner) {
2920 back_route = pback;
2921 }
2922 } trade_routes_iterate_end;
2923
2924 if (back_route != NULL) {
2925 trade_route_list_remove(pc2->routes, back_route);
2926 }
2927
2928 if (announce) {
2929 announce_trade_route_removal(pc1, pc2, source_gone);
2930
2931 city_refresh(pc2);
2932 send_city_info(city_owner(pc2), pc2);
2933 }
2934 }
2935
2936 return back_route;
2937}
2938
2939/**********************************************************************/
2942 bool city_illness_strike(struct city *pcity)
2943{
2944 notify_player(city_owner(pcity), city_tile(pcity), E_CITY_PLAGUE,
2945 ftc_server,
2946 _("%s has been struck by a plague! Population lost!"),
2947 city_link(pcity));
2948 if (city_reduce_size(pcity, 1, NULL, "plague")) {
2949 pcity->turn_plague = game.info.turn;
2950
2951 /* recalculate illness */
2952 pcity->server.illness
2953 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade),
2954 NULL);
2955
2956 return TRUE;
2957 }
2958
2959 return FALSE;
2960}
2961
2962/************************************************************************/
2968 void do_sell_building(struct player *pplayer, struct city *pcity,
2969 struct impr_type *pimprove, const char *reason)
2970{
2971 if (can_city_sell_building(pcity, pimprove)) {
2972 pplayer->economic.gold += impr_sell_gold(pimprove);
2973 building_lost(pcity, pimprove, reason, NULL);
2974 }
2975}
2976
2977/************************************************************************/
2989struct city
2990*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
2991 struct player **oldcity_owner)
2992{
2993 struct city *oldcity = NULL;
2994
2995 fc_assert_ret_val(!city_has_building(pcity, pimprove), NULL);
2996 if (is_great_wonder(pimprove)) {
2997 if (!(oldcity = city_from_great_wonder(pimprove))) {
2998 oldcity = pcity;
2999 }
3000 *oldcity_owner = city_owner(oldcity);
3001 } else if (is_small_wonder(pimprove)) {
3002 if (!(oldcity
3003 = city_from_small_wonder(city_owner(pcity), pimprove))) {
3004 oldcity = pcity;
3005 }
3006 }
3007 if (oldcity && oldcity != pcity) {
3008 city_remove_improvement(oldcity, pimprove);
3009 city_add_improvement_with_gov_notice(pcity, pimprove,
3010 _("Moving %s"));
3011 } else {
3012 city_add_improvement_with_gov_notice(pcity, pimprove,
3013 _("Acquiring %s"));
3014 }
3015
3016 return oldcity;
3017}
3018
3019/************************************************************************/
3022 bool building_removed(struct city *pcity, const struct impr_type *pimprove,
3023 const char *reason, struct unit *destroyer)
3024{
3025 int backup = pcity->id;
3026
3027 city_remove_improvement(pcity, pimprove);
3028
3029 script_server_signal_emit("building_lost", pcity, pimprove, reason,
3030 destroyer);
3031
3032 return city_exist(backup);
3033}
3034
3035/************************************************************************/
3039 void building_lost(struct city *pcity, const struct impr_type *pimprove,
3040 const char *reason, struct unit *destroyer)
3041{
3042 struct player *owner = city_owner(pcity);
3043 bool was_capital = is_capital(pcity);
3044 bool city_remains;
3045
3046 city_remains = building_removed(pcity, pimprove, reason, destroyer);
3047
3048 if ((was_capital && (!city_remains || !is_capital(pcity)))
3049 && (owner->spaceship.state == SSHIP_STARTED
3050 || owner->spaceship.state == SSHIP_LAUNCHED)) {
3051 /* If the capital was lost (by destruction of the palace) production on
3052 * the spaceship is lost. */
3053 spaceship_lost(owner);
3054 }
3055
3056 if (city_remains) {
3057 /* update city; influence of effects (buildings, ...) on unit upkeep */
3058 if (city_refresh(pcity)) {
3059 auto_arrange_workers(pcity);
3060 }
3061
3062 /* Re-update the city's visible area. This updates fog if the vision
3063 * range increases or decreases. */
3064 city_refresh_vision(pcity);
3065 }
3066}
3067
3068/************************************************************************/
3076 void update_unit_upkeep(struct unit *punit, int free_uk[O_LAST])
3077{
3078 const struct unit_type *ut = unit_type_get(punit);
3079 struct player *plr = unit_owner(punit);
3080 bool update = FALSE;
3081 int cost;
3082
3083 output_type_iterate(o) {
3084 cost = utype_upkeep_cost(ut, plr, o);
3085 if (cost > 0) {
3086 if (free_uk[o] > cost) {
3087 free_uk[o] -= cost;
3088 cost = 0;
3089 } else {
3090 cost -= free_uk[o];
3091 free_uk[o] = 0;
3092 }
3093 }
3094
3095 if (cost != punit->upkeep[o]) {
3096 update = TRUE;
3097 punit->upkeep[o] = cost;
3098 }
3099 } output_type_iterate_end;
3100
3101 if (update) {
3102 /* Update unit information to the player and global observers. */
3103 send_unit_info(NULL, punit);
3104 }
3105}
3106
3107/************************************************************************/
3127 void city_units_upkeep(const struct city *pcity)
3128{
3129 int free_uk[O_LAST];
3130
3131 if (!pcity || !pcity->units_supported
3132 || unit_list_size(pcity->units_supported) < 1) {
3133 return;
3134 }
3135
3136 output_type_iterate(o) {
3137 free_uk[o] = get_city_output_bonus(pcity, get_output_type(o),
3138 EFT_UNIT_UPKEEP_FREE_PER_CITY);
3139 } output_type_iterate_end;
3140
3141 /* Save the upkeep for all units in the corresponding punit struct */
3142 unit_list_iterate(pcity->units_supported, punit) {
3143 update_unit_upkeep(punit, free_uk);
3144 } unit_list_iterate_end;
3145}
3146
3147/************************************************************************/
3150 void change_build_target(struct player *pplayer, struct city *pcity,
3151 struct universal *target,
3152 enum event_type event)
3153{
3154 const char *name;
3155 const char *source;
3156
3157 /* If the city is already building this thing, don't do anything */
3158 if (are_universals_equal(&pcity->production, target)) {
3159 return;
3160 }
3161
3162 /* Is the city no longer building a wonder? */
3163 if (VUT_IMPROVEMENT == pcity->production.kind
3164 && is_great_wonder(pcity->production.value.building)
3165 && event != E_IMP_AUTO
3166 && event != E_WORKLIST) {
3167 /* If the build target is changed because of an advisor's suggestion or
3168 because the worklist advances, then the wonder was completed --
3169 don't announce that the player has *stopped* building that wonder.
3170 */
3171 notify_player(NULL, city_tile(pcity), E_WONDER_STOPPED, ftc_server,
3172 _("The %s have stopped building The %s in %s."),
3173 nation_plural_for_player(pplayer),
3174 city_production_name_translation(pcity),
3175 city_link(pcity));
3176 }
3177
3178 /* Manage the city change-production penalty.
3179 (May penalize, restore or do nothing to the shield_stock.) */
3180 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3181 pcity->shield_stock = city_change_production_penalty(pcity, target);
3182 }
3183
3184 /* Change build target. */
3185 pcity->production = *target;
3186
3187 /* What's the name of the target? */
3188 name = city_production_name_translation(pcity);
3189
3190 switch (event) {
3191 case E_WORKLIST:
3192 /* TRANS: Possible 'source' of the production change
3193 * (in "<city> is building ..." sentence). Preserve leading space. */
3194 source = _(" from the worklist");
3195 break;
3196 case E_IMP_AUTO:
3197 /* TRANS: Possible 'source' of the production change
3198 * (in "<city> is building ..." sentence). Preserve leading space. */
3199 source = _(" as suggested by the advisor");
3200 break;
3201 default:
3202 source = "";
3203 break;
3204 }
3205
3206 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3207 city_name_get(pcity), name, source);
3208
3209 /* Tell the player what's up. */
3210 /* FIXME: this may give bad grammar when translated if the 'source'
3211 * string can have multiple values. */
3212 notify_player(pplayer, city_tile(pcity), event, ftc_server,
3213 /* TRANS: "<city> is building <production><source>."
3214 * 'source' might be an empty string, or a clause like
3215 * " from the worklist". */
3216 _("%s is building %s%s."),
3217 city_link(pcity),
3218 name, source);
3219
3220 /* If the city is building a wonder, tell the rest of the world
3221 about it. */
3222 if (VUT_IMPROVEMENT == pcity->production.kind
3223 && is_great_wonder(pcity->production.value.building)) {
3224 notify_player(NULL, city_tile(pcity), E_WONDER_STARTED, ftc_server,
3225 _("The %s have started building The %s in %s."),
3226 nation_plural_for_player(pplayer),
3227 name,
3228 city_link(pcity));
3229 }
3230}
3231
3232/************************************************************************/
3239 void city_map_update_empty(struct city *pcity, struct tile *ptile)
3240{
3241 tile_set_worked(ptile, NULL);
3242 send_tile_info(NULL, ptile, FALSE);
3243 pcity->server.synced = FALSE;
3244}
3245
3246/************************************************************************/
3253 void city_map_update_worker(struct city *pcity, struct tile *ptile)
3254{
3255 tile_set_worked(ptile, pcity);
3256 send_tile_info(NULL, ptile, FALSE);
3257 pcity->server.synced = FALSE;
3258}
3259
3260/************************************************************************/
3265 static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3266{
3267 struct city *pwork = tile_worked(ptile);
3268
3269 if (NULL != pwork
3270 && !is_free_worked(pwork, ptile)
3271 && !city_can_work_tile(pwork, ptile)) {
3272 tile_set_worked(ptile, NULL);
3273 send_tile_info(NULL, ptile, FALSE);
3274
3275 pwork->specialists[DEFAULT_SPECIALIST]++; /* keep city sanity */
3276 pwork->server.synced = FALSE;
3277
3278 if (queued) {
3279 city_freeze_workers_queue(pwork); /* place the displaced later */
3280 } else {
3281 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3282 auto_arrange_workers(pwork);
3283 send_city_info(NULL, pwork);
3284 }
3285 return TRUE;
3286 }
3287
3288 return FALSE;
3289}
3290
3291/************************************************************************/
3296 bool city_map_update_tile_frozen(struct tile *ptile)
3297{
3298 return city_map_update_tile_direct(ptile, TRUE);
3299}
3300
3301/************************************************************************/
3304 bool city_map_update_tile_now(struct tile *ptile)
3305{
3306 return city_map_update_tile_direct(ptile, FALSE);
3307}
3308
3309/************************************************************************/
3313 void sync_cities(void)
3314{
3315 if (send_city_suppressed) {
3316 return;
3317 }
3318
3319 players_iterate(pplayer) {
3320 city_list_iterate(pplayer->cities, pcity) {
3321 if (!pcity->server.synced) {
3322 /* sending will set to TRUE. */
3323 send_city_info(pplayer, pcity);
3324 }
3325 } city_list_iterate_end;
3326 } players_iterate_end;
3327}
3328
3329/************************************************************************/
3332 void city_map_update_all(struct city *pcity)
3333{
3334 struct tile *pcenter = city_tile(pcity);
3335 const struct civ_map *nmap = &(wld.map);
3336
3337 city_tile_iterate_skip_free_worked(nmap, city_map_radius_sq_get(pcity), pcenter,
3338 ptile, _index, _x, _y) {
3339 /* bypass city_map_update_tile_now() for efficiency */
3340 city_map_update_tile_direct(ptile, FALSE);
3341 } city_tile_iterate_skip_free_worked_end;
3342}
3343
3344/************************************************************************/
3347 void city_map_update_all_cities_for_player(struct player *pplayer)
3348{
3349 city_list_iterate(pplayer->cities, pcity) {
3350 city_freeze_workers(pcity);
3351 city_map_update_all(pcity);
3352 city_thaw_workers(pcity);
3353 } city_list_iterate_end;
3354}
3355
3356/************************************************************************/
3366 void city_landlocked_sell_coastal_improvements(struct tile *ptile)
3367{
3368 adjc_iterate(&(wld.map), ptile, tile1) {
3369 struct city *pcity = tile_city(tile1);
3370
3371 if (pcity) {
3372 struct player *pplayer = city_owner(pcity);
3373 const struct req_context city_ctxt = {
3374 .player = pplayer,
3375 .city = pcity,
3376 .tile = pcity->tile,
3377 };
3378
3379 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3380 city_built_iterate(pcity, pimprove) {
3381 if (!can_city_sell_building(pcity, pimprove)) {
3382 continue;
3383 }
3384
3385 requirement_vector_iterate(&pimprove->reqs, preq) {
3386 if ((VUT_TERRAIN == preq->source.kind
3387 || VUT_TERRAINCLASS == preq->source.kind
3388 || VUT_TERRFLAG == preq->source.kind)
3389 && !is_req_active(&city_ctxt, NULL, preq, RPT_CERTAIN)) {
3390 int price = impr_sell_gold(pimprove);
3391
3392 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3393 notify_player(pplayer, tile1, E_IMP_SOLD, ftc_server,
3394 PL_("You sell %s in %s (now landlocked)"
3395 " for %d gold.",
3396 "You sell %s in %s (now landlocked)"
3397 " for %d gold.", price),
3398 improvement_name_translation(pimprove),
3399 city_link(pcity), price);
3400 }
3401 } requirement_vector_iterate_end;
3402 } city_built_iterate_end;
3403 }
3404 } adjc_iterate_end;
3405}
3406
3407/************************************************************************/
3413 void city_refresh_vision(struct city *pcity)
3414{
3415 if (pcity->server.vision != NULL) {
3416 v_radius_t vision_radius_sq
3417 = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2);
3418
3419 vision_change_sight(pcity->server.vision, vision_radius_sq);
3420 ASSERT_VISION(pcity->server.vision);
3421 }
3422}
3423
3424/************************************************************************/
3428 void refresh_player_cities_vision(struct player *pplayer)
3429{
3430 city_list_iterate(pplayer->cities, pcity) {
3431 city_refresh_vision(pcity);
3432 } city_list_iterate_end;
3433}
3434
3435/************************************************************************/
3438 bool city_map_update_radius_sq(struct city *pcity)
3439{
3440 fc_assert_ret_val(pcity != NULL, FALSE);
3441
3442 int city_tiles_old, city_tiles_new;
3443 int city_radius_sq_old = city_map_radius_sq_get(pcity);
3444 int city_radius_sq_new = game.info.init_city_radius_sq
3445 + get_city_bonus(pcity, EFT_CITY_RADIUS_SQ);
3446 const struct civ_map *nmap = &(wld.map);
3447
3448 /* Check minimum / maximum allowed city radii */
3449 city_radius_sq_new = CLIP(CITY_MAP_MIN_RADIUS_SQ, city_radius_sq_new,
3450 CITY_MAP_MAX_RADIUS_SQ);
3451
3452 if (city_radius_sq_new == city_radius_sq_old) {
3453 /* No change */
3454 return FALSE;
3455 }
3456
3457 /* Get number of city tiles for each radii */
3458 city_tiles_old = city_map_tiles(city_radius_sq_old);
3459 city_tiles_new = city_map_tiles(city_radius_sq_new);
3460
3461 if (city_tiles_old == city_tiles_new) {
3462 /* A change of the squared city radius but no change of the number of
3463 * city tiles */
3464 return FALSE;;
3465 }
3466
3467 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3468 pcity->id, city_radius_sq_old, city_radius_sq_new);
3469
3470 /* Workers map before */
3471 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3472 city_name_get(pcity), pcity->id, city_size_get(pcity),
3473 city_specialists(pcity));
3474 citylog_map_workers(LOG_DEBUG, pcity);
3475
3476 city_map_radius_sq_set(pcity, city_radius_sq_new);
3477
3478 if (city_tiles_old < city_tiles_new) {
3479 /* Increased number of city tiles */
3480 city_refresh_vision(pcity);
3481 } else {
3482 /* Reduced number of city tiles */
3483 int workers = 0;
3484
3485 /* Remove workers from the tiles removed rom the city map */
3486 city_map_iterate_radius_sq(city_radius_sq_new, city_radius_sq_old,
3487 city_x, city_y) {
3488 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3489 city_radius_sq_old, city_x,
3490 city_y);
3491
3492 if (ptile && pcity == tile_worked(ptile)) {
3493 city_map_update_empty(pcity, ptile);
3494 workers++;
3495 }
3496 } city_map_iterate_radius_sq_end;
3497
3498 /* add workers to free city tiles */
3499 if (workers > 0) {
3500 int radius_sq = city_map_radius_sq_get(pcity);
3501
3502 city_map_iterate_without_index(radius_sq, city_x, city_y) {
3503 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3504 city_x, city_y);
3505
3506 if (ptile && !is_free_worked(pcity, ptile)
3507 && tile_worked(ptile) != pcity
3508 && city_can_work_tile(pcity, ptile)) {
3509 city_map_update_worker(pcity, ptile);
3510 workers--;
3511 }
3512
3513 if (workers <= 0) {
3514 break;
3515 }
3516 } city_map_iterate_without_index_end;
3517 }
3518
3519 /* If there are still workers they will be updated to specialists */
3520 if (workers > 0) {
3521 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3522 }
3523
3524 city_refresh_vision(pcity);
3525 }
3526
3527 /* City removal might be ongoing, and advisor data already deleted */
3528 if (pcity->server.adv != NULL) {
3529 /* If city is under AI control, update it */
3530 adv_city_update(pcity);
3531 }
3532
3533 notify_player(city_owner(pcity), city_tile(pcity), E_CITY_RADIUS_SQ,
3534 ftc_server, _("The size of the city map of %s is %s."),
3535 city_name_get(pcity),
3536 city_tiles_old < city_tiles_new ? _("increased")
3537 : _("reduced"));
3538
3539 /* Workers map after */
3540 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3541 city_name_get(pcity), pcity->id, city_size_get(pcity),
3542 city_specialists(pcity));
3543 citylog_map_workers(LOG_DEBUG, pcity);
3544
3545 return TRUE;
3546}
3547
3548/************************************************************************/
3551 void clear_worker_task(struct city *pcity, struct worker_task *ptask)
3552{
3553 struct packet_worker_task packet;
3554
3555 if (ptask == NULL) {
3556 return;
3557 }
3558
3559 worker_task_list_remove(pcity->task_reqs, ptask);
3560
3561 packet.city_id = pcity->id;
3562 packet.tile_id = tile_index(ptask->ptile);
3563 packet.activity = ACTIVITY_LAST;
3564 packet.tgt = 0;
3565 packet.want = 0;
3566
3567 free(ptask);
3568
3569 lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
3570 lsend_packet_worker_task(game.glob_observers, &packet);
3571}
3572
3573/************************************************************************/
3576 void clear_worker_tasks(struct city *pcity)
3577{
3578 while (worker_task_list_size(pcity->task_reqs) > 0) {
3579 clear_worker_task(pcity, worker_task_list_get(pcity->task_reqs, 0));
3580 }
3581}
3582
3583/************************************************************************/
3586 void package_and_send_worker_tasks(struct city *pcity)
3587{
3588 struct packet_worker_task packet;
3589
3590 packet.city_id = pcity->id;
3591
3592 worker_task_list_iterate(pcity->task_reqs, ptask) {
3593 packet.tile_id = tile_index(ptask->ptile);
3594 packet.activity = ptask->act;
3595 if (ptask->tgt == NULL) {
3596 packet.tgt = -1;
3597 } else {
3598 packet.tgt = extra_number(ptask->tgt);
3599 }
3600 packet.want = ptask->want;
3601
3602 lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
3603 lsend_packet_worker_task(game.glob_observers, &packet);
3604 } worker_task_list_iterate_end;
3605}
3606
3607/************************************************************************/
3610 int city_production_buy_gold_cost(const struct city *pcity)
3611{
3612 int build = pcity->shield_stock;
3613
3614 switch (pcity->production.kind) {
3615 case VUT_IMPROVEMENT:
3616 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3617 build);
3618 case VUT_UTYPE:
3619 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3620 build);
3621 default:
3622 break;
3623 };
3624
3625 return FC_INFINITY;
3626}
3627
3628/************************************************************************/
3632 void city_add_improvement_with_gov_notice(struct city *pcity,
3633 const struct impr_type *pimprove,
3634 const char *format)
3635{
3636 if (is_wonder(pimprove)) {
3637 /* Only wonders may grant governments */
3638 struct cur_govs_data *govs_data;
3639 char buf[250];
3640
3641 govs_data = create_current_governments_data_all();
3642 city_add_improvement(pcity, pimprove);
3643
3644 fc_snprintf(buf, sizeof(buf), format, improvement_name_translation(pimprove));
3645
3646 players_iterate_alive(pplayer) {
3647 notify_new_government_options(pplayer, govs_data, buf);
3648 } players_iterate_alive_end;
3649
3650 free_current_governments_data(govs_data);
3651 } else {
3652 city_add_improvement(pcity, pimprove);
3653 }
3654}
3655
3656/************************************************************************/
3660 int city_original_owner(const struct city *pcity,
3661 const struct player *known_for)
3662{
3663 if (pcity->original == NULL) {
3664 /* Nobody knows */
3665 return MAX_NUM_PLAYER_SLOTS;
3666 }
3667
3668 if (pcity->original != known_for
3669 || known_for == NULL) {
3670 /* Players know what they have built themselves,
3671 * global observer knows everything. */
3672 return player_number(pcity->original);
3673 }
3674
3675 return MAX_NUM_PLAYER_SLOTS;
3676}
action_auto_perf_unit_do
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)
Definition actiontools.c:991
actiontools.h
advisor_choose_build
void advisor_choose_build(struct player *pplayer, struct city *pcity)
Definition advbuilding.c:315
advbuilding.h
adv_could_unit_move_to_tile
int adv_could_unit_move_to_tile(struct unit *punit, struct tile *dest_tile)
Definition advgoto.c:354
advgoto.h
ai.h
CALL_FUNC_EACH_AI
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
CALL_PLR_AI_FUNC
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
n
#define n
Definition astring.c:77
autosettlers.h
is_land_barbarian
bool is_land_barbarian(struct player *pplayer)
Definition barbarian.c:75
barbarian.h
base.h
dbv_init
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
dbv_set
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:144
dbv_isset
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
dbv_free
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
bitvector.h
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ARE_EQUAL
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:113
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
BV_ISSET_ANY
#define BV_ISSET_ANY(vec)
Definition bitvector.h:109
citizens_nation_get
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
citizens_init
void citizens_init(struct city *pcity)
Definition citizens.c:32
citizens.h
citizens_convert_conquest
void citizens_convert_conquest(struct city *pcity)
Definition citizenshand.c:386
citizens_update
void citizens_update(struct city *pcity, struct player *plr)
Definition citizenshand.c:202
citizenshand.h
is_free_worked
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3589
city_map_radius_sq_set
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:147
city_production_build_shield_cost
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:736
city_name_set
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1136
city_granary_size
int city_granary_size(int city_size)
Definition city.c:2123
player_angry_citizens
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2187
can_city_build_now
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Definition city.c:1006
city_map_to_tile
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:304
city_has_building
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
is_capital
bool is_capital(const struct city *pcity)
Definition city.c:1571
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
city_remove_improvement
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3359
city_can_be_built_here
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1478
get_output_type
struct output_type * get_output_type(Output_type_id output)
Definition city.c:637
can_city_build_improvement_now
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:853
player_content_citizens
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2177
city_unhappy
bool city_unhappy(const struct city *pcity)
Definition city.c:1618
create_city_virtual
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3418
city_list_find_number
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1671
city_illness_calc
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2861
city_change_production_penalty
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1878
city_happy
bool city_happy(const struct city *pcity)
Definition city.c:1606
city_add_improvement
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3345
city_tile_output_now
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1375
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:136
citylog_map_workers
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:445
city_specialists
citizens city_specialists(const struct city *pcity)
Definition city.c:3305
city_choose_build_default
void city_choose_build_default(struct city *pcity)
Definition city.c:1078
city_list_find_name
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1687
city_map_tiles
int city_map_tiles(int city_radius_sq)
Definition city.c:170
city_exist
bool city_exist(int id)
Definition city.c:3560
city_can_work_tile
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1447
city_turns_to_grow
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1988
city_rally_point_clear
void city_rally_point_clear(struct city *pcity)
Definition city.c:3614
can_city_build_unit_now
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:945
city_production_name_translation
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:699
city.h
cities_iterate_end
#define cities_iterate_end
Definition city.h:517
CNA_BROADCAST_PENDING
@ CNA_BROADCAST_PENDING
Definition city.h:308
CNA_NOT
@ CNA_NOT
Definition city.h:306
CNA_NORMAL
@ CNA_NORMAL
Definition city.h:307
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_tile
#define city_tile(_pcity_)
Definition city.h:564
cities_iterate
#define cities_iterate(pcity)
Definition city.h:512
CITY_MAP_MAX_RADIUS_SQ
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
city_tile_iterate_skip_free_worked
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:214
CITIZEN_ANGRY
@ CITIZEN_ANGRY
Definition city.h:271
CITIZEN_HAPPY
@ CITIZEN_HAPPY
Definition city.h:268
CITIZEN_CONTENT
@ CITIZEN_CONTENT
Definition city.h:269
CITIZEN_UNHAPPY
@ CITIZEN_UNHAPPY
Definition city.h:270
CITY_MAP_MIN_RADIUS_SQ
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:84
city_map_iterate_radius_sq
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
Definition city.h:188
output_type_iterate
#define output_type_iterate(output)
Definition city.h:833
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_tile_iterate_skip_free_worked_end
#define city_tile_iterate_skip_free_worked_end
Definition city.h:222
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
city_map_iterate_radius_sq_end
#define city_map_iterate_radius_sq_end
Definition city.h:193
city_tile_iterate
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
FEELING_LAST
@ FEELING_LAST
Definition city.h:285
city_tile_iterate_end
#define city_tile_iterate_end
Definition city.h:238
city_built_iterate
#define city_built_iterate(_pcity, _p)
Definition city.h:822
city_map_iterate_without_index_end
#define city_map_iterate_without_index_end
Definition city.h:184
city_built_iterate_end
#define city_built_iterate_end
Definition city.h:828
city_map_iterate_without_index
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:180
output_type_iterate_end
#define output_type_iterate_end
Definition city.h:839
city_map_update_empty
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3239
city_freeze_workers_queue
void city_freeze_workers_queue(struct city *pcity)
Definition citytools.c:161
package_city
void package_city(struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct trade_route_packet_list *routes, bool dipl_invest)
Definition citytools.c:2506
city_map_update_tile_now
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3304
city_name_suggestion
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:453
city_citywalls_gfx
static int city_citywalls_gfx(const struct city *pcity)
Definition citytools.c:2142
city_map_update_tile_direct
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3265
package_and_send_worker_tasks
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3586
city_production_buy_gold_cost
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3610
send_city_info
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2343
update_dumb_city
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2740
build_or_move_building
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:2990
raze_city
static void raze_city(struct city *pcity)
Definition citytools.c:923
city_build_free_buildings
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1428
city_workers_queue_remove
static bool city_workers_queue_remove(struct city *pcity)
Definition citytools.c:180
find_closest_city
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:851
refresh_dumb_city
void refresh_dumb_city(struct city *pcity)
Definition citytools.c:2196
package_dumb_city
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2163
create_city
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1513
send_city_suppression
bool send_city_suppression(bool now)
Definition citytools.c:2152
send_city_suppressed
static bool send_city_suppressed
Definition citytools.c:102
sync_cities
void sync_cities(void)
Definition citytools.c:3313
search_for_city_name
static const char * search_for_city_name(struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
Definition citytools.c:334
announce_trade_route_removal
static void announce_trade_route_removal(struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
Definition citytools.c:2850
city_freeze_workers
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:137
update_unit_upkeep
void update_unit_upkeep(struct unit *punit, int free_uk[O_LAST])
Definition citytools.c:3076
refresh_player_cities_vision
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3428
city_original_owner
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3660
build_free_small_wonders
static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders)
Definition citytools.c:1013
city_map_update_radius_sq
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3438
build_points_left
int build_points_left(struct city *pcity)
Definition citytools.c:571
change_build_target
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3150
building_removed
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3022
city_map_update_all_cities_for_player
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3347
city_illness_strike
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2942
city_map_update_tile_frozen
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3296
city_thaw_workers
void city_thaw_workers(struct city *pcity)
Definition citytools.c:147
remove_dumb_city
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2832
is_default_city_name
static bool is_default_city_name(const char *name, struct player *pplayer)
Definition citytools.c:316
building_lost
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3039
unit_conquer_city
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1973
clear_worker_task
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3551
reestablish_city_trade_routes
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:956
city_units_upkeep
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3127
clear_worker_tasks
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3576
is_allowed_city_name
bool is_allowed_city_name(struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
Definition citytools.c:369
transfer_unit
static void transfer_unit(struct unit *punit, struct city *tocity, bool rehome, bool verbose)
Definition citytools.c:585
city_landlocked_sell_coastal_improvements
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
Definition citytools.c:3366
remove_city
void remove_city(struct city *pcity)
Definition citytools.c:1699
do_sell_building
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:2968
arrange_workers_queue
static struct city_list * arrange_workers_queue
Definition citytools.c:99
remove_trade_route
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2907
create_city_for_player
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1673
send_city_info_at_tile
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2395
evaluate_city_name_priority
static int evaluate_city_name_priority(struct tile *ptile, const struct nation_city *pncity, int default_priority)
Definition citytools.c:215
city_thaw_workers_queue
void city_thaw_workers_queue(void)
Definition citytools.c:193
broadcast_city_info
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2225
transfer_city
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Definition citytools.c:1071
city_add_improvement_with_gov_notice
void city_add_improvement_with_gov_notice(struct city *pcity, const struct impr_type *pimprove, const char *format)
Definition citytools.c:3632
send_player_cities
void send_player_cities(struct player *pplayer)
Definition citytools.c:2323
city_map_update_all
void city_map_update_all(struct city *pcity)
Definition citytools.c:3332
transfer_city_units
void transfer_city_units(struct player *pplayer, struct player *pvictim, struct unit_list *units, struct city *pcity, struct city *exclude_city, int kill_outside, bool verbose)
Definition citytools.c:716
city_map_update_worker
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Definition citytools.c:3253
reality_check_city
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2811
send_all_known_cities
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2300
city_refresh_vision
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3413
citytools.h
trade_route_packet_list_iterate_end
#define trade_route_packet_list_iterate_end
Definition citytools.h:28
LOG_BUILD_TARGET
#define LOG_BUILD_TARGET
Definition citytools.h:21
trade_route_packet_list_iterate
#define trade_route_packet_list_iterate(ptrlist, ptr)
Definition citytools.h:26
auto_arrange_workers
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:366
city_refresh_queue_add
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:197
nullify_prechange_production
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3536
city_counters_refresh
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4575
city_reduce_size
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:762
city_refresh
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
city_refresh_for_player
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:182
city_refresh_queue_processing
void city_refresh_queue_processing(void)
Definition cityturn.c:213
remove_obsolete_buildings_city
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:235
cityturn.h
announce
enum announce_type announce
Definition client_main.c:148
cm_copy_parameter
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2171
cm.h
incite_cost
char * incite_cost
Definition comments.c:74
conn_list_do_unbuffer
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:366
conn_by_user
struct connection * conn_by_user(const char *user_name)
Definition connection.c:377
conn_list_do_buffer
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:356
conn_is_global_observer
bool conn_is_global_observer(const struct connection *pconn)
Definition connection.c:753
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:110
counters.h
city_counters_iterate_end
#define city_counters_iterate_end
Definition counters.h:64
city_counters_iterate
#define city_counters_iterate(pcount)
Definition counters.h:57
city_culture
int city_culture(const struct city *pcity)
Definition culture.c:29
culture.h
homeless
static void homeless(QVariant data1, QVariant data2)
Definition dialogs.cpp:2418
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
cost
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
get_unit_bonus
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1070
get_city_output_bonus
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:984
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
event
enum event_type event
Definition events.c:81
events.h
extra_number
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
is_native_tile_to_extra
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:633
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:315
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:321
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:191
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:339
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
MAX_NUM_BUILDING_LIST
#define MAX_NUM_BUILDING_LIST
Definition fc_types.h:46
citizens
unsigned char citizens
Definition fc_types.h:391
Impr_type_id
int Impr_type_id
Definition fc_types.h:379
MAX_NUM_PLAYERS
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
RPT_CERTAIN
@ RPT_CERTAIN
Definition fc_types.h:704
MAX_NUM_PLAYER_SLOTS
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
O_SHIELD
@ O_SHIELD
Definition fc_types.h:101
O_FOOD
@ O_FOOD
Definition fc_types.h:101
O_TRADE
@ O_TRADE
Definition fc_types.h:101
O_LAST
@ O_LAST
Definition fc_types.h:101
MAX_LEN_CITYNAME
#define MAX_LEN_CITYNAME
Definition fc_types.h:67
Continent_id
signed short Continent_id
Definition fc_types.h:375
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:92
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
fc_mutex_allocate
void fc_mutex_allocate(fc_mutex *mutex)
fc_mutex_release
void fc_mutex_release(fc_mutex *mutex)
city_tile_link
const char * city_tile_link(const struct city *pcity)
Definition featured_text.c:1089
ftc_server
const struct ft_color ftc_server
Definition featured_text.c:77
city_link
const char * city_link(const struct city *pcity)
Definition featured_text.c:1072
unit_link
const char * unit_link(const struct unit *punit)
Definition featured_text.c:1122
unit_tile_link
const char * unit_tile_link(const struct unit *punit)
Definition featured_text.c:1139
MAX_LEN_LINK
#define MAX_LEN_LINK
Definition featured_text.h:138
game
struct civ_game game
Definition game.c:62
game_city_by_name
struct city * game_city_by_name(const char *name)
Definition game.c:88
wld
struct world wld
Definition game.c:63
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:116
game_remove_city
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:178
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:107
game.h
any_web_conns
#define any_web_conns()
Definition game.h:315
CNM_PLAYER_UNIQUE
@ CNM_PLAYER_UNIQUE
Definition game.h:46
CNM_GLOBAL_UNIQUE
@ CNM_GLOBAL_UNIQUE
Definition game.h:47
CNM_NO_STEALING
@ CNM_NO_STEALING
Definition game.h:48
send_game_info
void send_game_info(struct conn_list *dest)
Definition gamehand.c:907
gamehand.h
government.h
owner
struct city * owner
Definition citydlg.c:220
source
static GtkWidget * source
Definition gotodlg.c:58
type
GType type
Definition repodlgs.c:1313
bufsz
static const int bufsz
Definition helpdlg.c:70
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_PRODCHGPEN
@ H_PRODCHGPEN
Definition handicaps.h:35
idex_register_city
void idex_register_city(struct world *iworld, struct city *pcity)
Definition idex.c:67
idex.h
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:194
impr_sell_gold
int impr_sell_gold(const struct impr_type *pimprove)
Definition improvement.c:334
can_city_sell_building
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:1100
is_improvement
bool is_improvement(const struct impr_type *pimprove)
Definition improvement.c:788
is_improvement_visible
bool is_improvement_visible(const struct impr_type *pimprove)
Definition improvement.c:393
improvement_index
Impr_type_id improvement_index(const struct impr_type *pimprove)
Definition improvement.c:175
impr_buy_gold_cost
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
Definition improvement.c:306
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:343
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:772
improvement_has_flag
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Definition improvement.c:383
city_from_small_wonder
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:1076
improvement_name_translation
const char * improvement_name_translation(const struct impr_type *pimprove)
Definition improvement.c:243
city_from_great_wonder
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:1016
is_small_wonder
bool is_small_wonder(const struct impr_type *pimprove)
Definition improvement.c:780
improvement.h
improvement_iterate_end
#define improvement_iterate_end
Definition improvement.h:205
improvement_iterate
#define improvement_iterate(_p)
Definition improvement.h:199
B_LAST
#define B_LAST
Definition improvement.h:42
adv_city_free
void adv_city_free(struct city *pcity)
Definition infracache.c:501
adv_city_update
void adv_city_update(struct city *pcity)
Definition infracache.c:462
adv_city_alloc
void adv_city_alloc(struct city *pcity)
Definition infracache.c:488
infracache.h
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
log_verbose
#define log_verbose(message,...)
Definition log.h:109
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_msg
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:205
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187
log_debug
#define log_debug(message,...)
Definition log.h:115
log_base
#define log_base(level, message,...)
Definition log.h:94
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
log_error
#define log_error(message,...)
Definition log.h:103
fc_assert_ret_val_msg
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
luascript_types.h
map_num_tiles
int map_num_tiles(void)
Definition map.c:1014
real_map_distance
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
map.h
adjc_iterate_end
#define adjc_iterate_end
Definition map.h:433
adjc_iterate
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:428
whole_map_iterate
#define whole_map_iterate(_map, _tile)
Definition map.h:545
whole_map_iterate_end
#define whole_map_iterate_end
Definition map.h:554
vision_clear_sight
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2511
map_claim_ownership
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2185
map_is_known
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:894
destroy_extra
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2586
send_tile_info
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:491
map_get_player_city
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1364
map_show_tile
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:768
give_citymap_from_player_to_player
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:418
tile_change_side_effects
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2689
map_is_known_and_seen
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:920
change_playertile_site
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1156
map_claim_border
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2264
update_tile_knowledge
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1436
upgrade_city_extras
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:241
map_clear_border
void map_clear_border(struct tile *ptile)
Definition maphand.c:2215
map_get_player_tile
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1379
vision_change_sight
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2499
maphand.h
map_get_player_site
#define map_get_player_site(_ptile_, _pplayer_)
Definition maphand.h:93
mem.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
can_unit_exist_at_tile
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
is_native_tile
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:331
is_city_channel_tile
bool is_city_channel_tile(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
Definition movement.c:243
can_unit_survive_at_tile
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:491
is_native_near_tile
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:465
movement.h
nation_city_name
const char * nation_city_name(const struct nation_city *pncity)
Definition nation.c:412
nation_cities
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Definition nation.c:331
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
nation_city_preference_revert
enum nation_city_preference nation_city_preference_revert(enum nation_city_preference prefer)
Definition nation.c:371
nation_count
Nation_type_id nation_count(void)
Definition nation.c:507
nation_of_unit
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
nation_city_terrain_preference
enum nation_city_preference nation_city_terrain_preference(const struct nation_city *pncity, const struct terrain *pterrain)
Definition nation.c:422
nation_of_player
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
nation_city_river_preference
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Definition nation.c:434
nation_index
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
nation_list_iterate
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:84
nation_city_preference
nation_city_preference
Definition nation.h:39
NCP_NONE
@ NCP_NONE
Definition nation.h:41
NCP_DISLIKE
@ NCP_DISLIKE
Definition nation.h:40
NCP_LIKE
@ NCP_LIKE
Definition nation.h:42
nation_city_list_iterate
#define nation_city_list_iterate(citylist, pncity)
Definition nation.h:48
nation_list_iterate_end
#define nation_list_iterate_end
Definition nation.h:86
nation_city_list_iterate_end
#define nation_city_list_iterate_end
Definition nation.h:50
notify_player
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:292
notify.h
packets.h
web_send_packet
#define web_send_packet(packetname, pconn,...)
Definition packets.h:56
web_lsend_packet
#define web_lsend_packet(packetname,...)
Definition packets.h:57
send_packet_city_rally_point
int send_packet_city_rally_point(struct connection *pc, const struct packet_city_rally_point *packet, bool force_to_send)
Definition packets_gen.c:21281
dlsend_packet_city_remove
void dlsend_packet_city_remove(struct conn_list *dest, int city_id)
Definition packets_gen.c:12845
lsend_packet_city_nationalities
void lsend_packet_city_nationalities(struct conn_list *dest, const struct packet_city_nationalities *packet, bool force_to_send)
Definition packets_gen.c:16533
send_packet_city_info
int send_packet_city_info(struct connection *pc, const struct packet_city_info *packet, bool force_to_send)
Definition packets_gen.c:16008
lsend_packet_trade_route_info
void lsend_packet_trade_route_info(struct conn_list *dest, const struct packet_trade_route_info *packet)
Definition packets_gen.c:17969
send_packet_trade_route_info
int send_packet_trade_route_info(struct connection *pc, const struct packet_trade_route_info *packet)
Definition packets_gen.c:17957
lsend_packet_city_info
void lsend_packet_city_info(struct conn_list *dest, const struct packet_city_info *packet, bool force_to_send)
Definition packets_gen.c:16020
send_packet_city_nationalities
int send_packet_city_nationalities(struct connection *pc, const struct packet_city_nationalities *packet, bool force_to_send)
Definition packets_gen.c:16521
lsend_packet_city_short_info
void lsend_packet_city_short_info(struct conn_list *dest, const struct packet_city_short_info *packet)
Definition packets_gen.c:17581
lsend_packet_worker_task
void lsend_packet_worker_task(struct conn_list *dest, const struct packet_worker_task *packet)
Definition packets_gen.c:21632
dsend_packet_city_remove
int dsend_packet_city_remove(struct connection *pc, int city_id)
Definition packets_gen.c:12836
lsend_packet_city_rally_point
void lsend_packet_city_rally_point(struct conn_list *dest, const struct packet_city_rally_point *packet, bool force_to_send)
Definition packets_gen.c:21293
player_number
int player_number(const struct player *pplayer)
Definition player.c:837
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
can_player_see_unit
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1104
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
player_slot_index
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
player_has_flag
bool player_has_flag(const struct player *pplayer, enum plr_flag_id flag)
Definition player.c:1990
player_index
int player_index(const struct player *pplayer)
Definition player.c:829
player_can_see_city_externals
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1164
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
can_player_see_units_in_city
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1133
player_slot_get_player
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
can_player_see_city_internals
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1149
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:537
players_iterate
#define players_iterate(_pplayer)
Definition player.h:532
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
player_slots_iterate
#define player_slots_iterate(_pslot)
Definition player.h:523
is_ai
#define is_ai(plr)
Definition player.h:230
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:547
player_slots_iterate_end
#define player_slots_iterate_end
Definition player.h:527
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:542
normal_player_count
int normal_player_count(void)
Definition plrhand.c:3200
civil_war_triggered
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2951
maybe_make_contact
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2357
send_player_info_c
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1142
civil_war
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3001
civil_war_possible
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2904
update_capital
void update_capital(struct player *pplayer)
Definition plrhand.c:729
plrhand.h
allowed_nations_iterate
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
allowed_nations_iterate_end
#define allowed_nations_iterate_end
Definition plrhand.h:73
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:56
is_req_active
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
Definition requirements.c:5416
are_universals_equal
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
Definition requirements.c:6466
universal_number
int universal_number(const struct universal *source)
Definition requirements.c:872
requirements.h
requirement_vector_iterate_end
#define requirement_vector_iterate_end
Definition requirements.h:94
requirement_vector_iterate
#define requirement_vector_iterate(req_vec, preq)
Definition requirements.h:92
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research.h
road_has_flag
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
road.h
sanitycheck.h
sanity_check_city
#define sanity_check_city(x)
Definition sanitycheck.h:41
script_server_signal_emit
void script_server_signal_emit(const char *signal_name,...)
Definition script_server.c:408
script_server_remove_exported_object
void script_server_remove_exported_object(void *object)
Definition script_server.c:207
script_server.h
connections
static struct connection connections[MAX_NUM_CONNECTIONS]
Definition sernet.c:94
flush_packets
void flush_packets(void)
Definition sernet.c:381
sernet.h
settings
static struct setting settings[]
Definition settings.c:1473
is_ascii_name
bool is_ascii_name(const char *name)
Definition shared.c:283
shared.h
CLIP
#define CLIP(lower, current, upper)
Definition shared.h:57
MIN
#define MIN(x, y)
Definition shared.h:55
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
spaceship_lost
void spaceship_lost(struct player *pplayer)
Definition spacerace.c:431
spacerace.h
SSHIP_STARTED
@ SSHIP_STARTED
Definition spaceship.h:84
SSHIP_LAUNCHED
@ SSHIP_LAUNCHED
Definition spaceship.h:85
specialist_count
Specialist_type_id specialist_count(void)
Definition specialist.c:71
specialist.h
specialist_type_iterate_end
#define specialist_type_iterate_end
Definition specialist.h:79
specialist_type_iterate
#define specialist_type_iterate(sp)
Definition specialist.h:73
DEFAULT_SPECIALIST
#define DEFAULT_SPECIALIST
Definition specialist.h:43
priority
SPECPQ_PRIORITY_TYPE priority
Definition specpq.h:86
size
size_t size
Definition specvec.h:72
recursion
static int recursion[AIT_LAST]
Definition srv_log.c:45
identity_number
int identity_number(void)
Definition srv_main.c:2020
server_state
enum server_states server_state(void)
Definition srv_main.c:333
srv_main.h
built_status::turn
int turn
Definition city.h:246
city
Definition city.h:320
city::task_reqs
struct worker_task_list * task_reqs
Definition city.h:412
city::turn_last_built
int turn_last_built
Definition city.h:387
city::surplus
int surplus[O_LAST]
Definition city.h:355
city::food_stock
int food_stock
Definition city.h:367
city::built
struct built_status built[B_LAST]
Definition city.h:394
city::original
struct player * original
Definition city.h:324
city::history
int history
Definition city.h:410
city::counter_values
int * counter_values
Definition city.h:408
city::pollution
int pollution
Definition city.h:369
city::did_sell
bool did_sell
Definition city.h:380
city::id
int id
Definition city.h:326
city::last_turns_shield_surplus
int last_turns_shield_surplus
Definition city.h:392
city::capital
enum capital_type capital
Definition city.h:328
city::disbanded_shields
int disbanded_shields
Definition city.h:391
city::waste
int waste[O_LAST]
Definition city.h:356
city::workers_frozen
int workers_frozen
Definition city.h:437
city::turn_plague
int turn_plague
Definition city.h:374
city::city_options
bv_city_options city_options
Definition city.h:403
city::city_radius_sq
int city_radius_sq
Definition city.h:375
city::was_happy
bool was_happy
Definition city.h:381
city::owner
struct player * owner
Definition city.h:323
city::acquire_t
enum city_acquire_type acquire_t
Definition city.h:329
city::turn_founded
int turn_founded
Definition city.h:386
city::airlift
int airlift
Definition city.h:378
city::citizen_base
int citizen_base[O_LAST]
Definition city.h:359
city::caravan_shields
int caravan_shields
Definition city.h:390
city::did_buy
bool did_buy
Definition city.h:379
city::routes
struct trade_route_list * routes
Definition city.h:344
city::needs_arrange
enum city_needs_arrange needs_arrange
Definition city.h:441
city::usage
int usage[O_LAST]
Definition city.h:360
city::worklist
struct worklist worklist
Definition city.h:401
city::production
struct universal production
Definition city.h:396
city::orders
struct unit_order * orders
Definition city.h:422
city::rally_point
struct city::@16 rally_point
city::adv
struct adv_city * adv
Definition city.h:452
city::nationality
citizens * nationality
Definition city.h:341
city::vigilant
bool vigilant
Definition city.h:421
city::steal
int steal
Definition city.h:414
city::unhappy_penalty
int unhappy_penalty[O_LAST]
Definition city.h:357
city::illness
int illness
Definition city.h:434
city::before_change_shields
int before_change_shields
Definition city.h:389
city::style
int style
Definition city.h:327
city::had_famine
bool had_famine
Definition city.h:382
city::length
size_t length
Definition city.h:417
city::synced
bool synced
Definition city.h:448
city::feel
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:333
city::specialists
citizens specialists[SP_MAX]
Definition city.h:336
city::tile
struct tile * tile
Definition city.h:322
city::shield_stock
int shield_stock
Definition city.h:368
city::prod
int prod[O_LAST]
Definition city.h:358
city::vision
struct vision * vision
Definition city.h:455
city::server
struct city::@17::@19 server
city::cm_parameter
struct cm_parameter * cm_parameter
Definition city.h:425
city::changed_from
struct universal changed_from
Definition city.h:399
city::units_supported
struct unit_list * units_supported
Definition city.h:406
city::illness_trade
int illness_trade
Definition city.h:370
city::persistent
bool persistent
Definition city.h:419
civ_game::allowed_city_names
enum city_names_mode allowed_city_names
Definition game.h:127
civ_game::mutexes
struct civ_game::@31::@35::@39 mutexes
civ_game::vision_reveal_tiles
bool vision_reveal_tiles
Definition game.h:200
civ_game::glob_observers
struct conn_list * glob_observers
Definition game.h:98
civ_game::city_list
fc_mutex city_list
Definition game.h:270
civ_game::est_connections
struct conn_list * est_connections
Definition game.h:97
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::natural_city_names
bool natural_city_names
Definition game.h:167
civ_game::global_init_buildings
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:109
civ_game::savepalace
bool savepalace
Definition game.h:187
civ_game::server
struct civ_game::@31::@35 server
civ_game::rgame
struct civ_game::@30 rgame
civ_game::razechance
int razechance
Definition game.h:176
civ_map
Definition map_types.h:71
connection
Definition connection.h:136
cur_govs_data
Definition techtools.h:23
dbv
Definition bitvector.h:32
extra_type
Definition extras.h:88
impr_type
Definition improvement.h:50
nation_city
Definition nation.c:321
nation_type
Definition nation.h:98
nation_type::init_buildings
int init_buildings[MAX_NUM_BUILDING_LIST]
Definition nation.h:123
nation_type::parent_nations
struct nation_list * parent_nations
Definition nation.h:136
nation_type::server
struct nation_type::@51::@53 server
nation_type::civilwar_nations
struct nation_list * civilwar_nations
Definition nation.h:135
packet_city_info
Definition packets_gen.h:329
packet_city_info::style
int style
Definition packets_gen.h:336
packet_city_info::last_turns_shield_surplus
int last_turns_shield_surplus
Definition packets_gen.h:367
packet_city_info::usage
int usage[O_LAST]
Definition packets_gen.h:352
packet_city_info::before_change_shields
int before_change_shields
Definition packets_gen.h:364
packet_city_info::ppl_content
int ppl_content[FEELING_LAST]
Definition packets_gen.h:339
packet_city_info::city_options
bv_city_options city_options
Definition packets_gen.h:379
packet_city_info::capital
enum capital_type capital
Definition packets_gen.h:337
packet_city_info::surplus
int surplus[O_LAST]
Definition packets_gen.h:347
packet_city_info::had_famine
bool had_famine
Definition packets_gen.h:372
packet_city_info::ppl_unhappy
int ppl_unhappy[FEELING_LAST]
Definition packets_gen.h:340
packet_city_info::original
int original
Definition packets_gen.h:333
packet_city_info::citizen_base
int citizen_base[O_LAST]
Definition packets_gen.h:351
packet_city_info::changed_from_kind
int changed_from_kind
Definition packets_gen.h:362
packet_city_info::specialists
int specialists[SP_MAX]
Definition packets_gen.h:343
packet_city_info::changed_from_value
int changed_from_value
Definition packets_gen.h:363
packet_city_info::ppl_angry
int ppl_angry[FEELING_LAST]
Definition packets_gen.h:341
packet_city_info::food_stock
int food_stock
Definition packets_gen.h:353
packet_city_info::id
int id
Definition packets_gen.h:330
packet_city_info::specialists_size
int specialists_size
Definition packets_gen.h:342
packet_city_info::owner
int owner
Definition packets_gen.h:332
packet_city_info::walls
int walls
Definition packets_gen.h:374
packet_city_info::improvements
bv_imprs improvements
Definition packets_gen.h:378
packet_city_info::shield_stock
int shield_stock
Definition packets_gen.h:354
packet_city_info::was_happy
bool was_happy
Definition packets_gen.h:371
packet_city_info::worklist
struct worklist worklist
Definition packets_gen.h:377
packet_city_info::steal
int steal
Definition packets_gen.h:376
packet_city_info::airlift
int airlift
Definition packets_gen.h:368
packet_city_info::did_buy
bool did_buy
Definition packets_gen.h:369
packet_city_info::turn_founded
int turn_founded
Definition packets_gen.h:360
packet_city_info::buy_cost
int buy_cost
Definition packets_gen.h:346
packet_city_info::name
char name[MAX_LEN_CITYNAME]
Definition packets_gen.h:380
packet_city_info::pollution
int pollution
Definition packets_gen.h:356
packet_city_info::trade_route_count
int trade_route_count
Definition packets_gen.h:355
packet_city_info::ppl_happy
int ppl_happy[FEELING_LAST]
Definition packets_gen.h:338
packet_city_info::did_sell
bool did_sell
Definition packets_gen.h:370
packet_city_info::production_value
int production_value
Definition packets_gen.h:359
packet_city_info::prod
int prod[O_LAST]
Definition packets_gen.h:350
packet_city_info::caravan_shields
int caravan_shields
Definition packets_gen.h:366
packet_city_info::illness_trade
int illness_trade
Definition packets_gen.h:357
packet_city_info::culture
int culture
Definition packets_gen.h:345
packet_city_info::diplomat_investigate
bool diplomat_investigate
Definition packets_gen.h:373
packet_city_info::unhappy_penalty
int unhappy_penalty[O_LAST]
Definition packets_gen.h:349
packet_city_info::history
int history
Definition packets_gen.h:344
packet_city_info::turn_last_built
int turn_last_built
Definition packets_gen.h:361
packet_city_info::city_image
int city_image
Definition packets_gen.h:375
packet_city_info::disbanded_shields
int disbanded_shields
Definition packets_gen.h:365
packet_city_info::production_kind
int production_kind
Definition packets_gen.h:358
packet_city_info::tile
int tile
Definition packets_gen.h:331
packet_city_info::size
int size
Definition packets_gen.h:334
packet_city_info::city_radius_sq
int city_radius_sq
Definition packets_gen.h:335
packet_city_info::waste
int waste[O_LAST]
Definition packets_gen.h:348
packet_city_nationalities
Definition packets_gen.h:383
packet_city_rally_point
Definition packets_gen.h:488
packet_city_short_info
Definition packets_gen.h:396
packet_city_short_info::walls
int walls
Definition packets_gen.h:404
packet_city_short_info::style
int style
Definition packets_gen.h:401
packet_city_short_info::size
int size
Definition packets_gen.h:400
packet_city_short_info::improvements
bv_imprs improvements
Definition packets_gen.h:408
packet_city_short_info::capital
enum capital_type capital
Definition packets_gen.h:402
packet_city_short_info::owner
int owner
Definition packets_gen.h:399
packet_city_short_info::id
int id
Definition packets_gen.h:397
packet_city_short_info::city_image
int city_image
Definition packets_gen.h:407
packet_city_short_info::happy
bool happy
Definition packets_gen.h:405
packet_city_short_info::unhappy
bool unhappy
Definition packets_gen.h:406
packet_city_short_info::tile
int tile
Definition packets_gen.h:398
packet_city_short_info::occupied
bool occupied
Definition packets_gen.h:403
packet_city_short_info::name
char name[MAX_LEN_CITYNAME]
Definition packets_gen.h:409
packet_game_info::team_pooled_research
bool team_pooled_research
Definition packets_gen.h:224
packet_game_info::citizen_nationality
bool citizen_nationality
Definition packets_gen.h:140
packet_game_info::init_city_radius_sq
int init_city_radius_sq
Definition packets_gen.h:184
packet_game_info::reveal_trade_partner
bool reveal_trade_partner
Definition packets_gen.h:159
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_trade_route_info
Definition packets_gen.h:412
packet_web_city_info_addition
Definition packets_gen.h:1861
packet_worker_task
Definition packets_gen.h:496
packet_worker_task::city_id
int city_id
Definition packets_gen.h:497
packet_worker_task::tile_id
int tile_id
Definition packets_gen.h:498
packet_worker_task::activity
enum unit_activity activity
Definition packets_gen.h:499
packet_worker_task::want
int want
Definition packets_gen.h:501
packet_worker_task::tgt
int tgt
Definition packets_gen.h:500
player_economic::gold
int gold
Definition player.h:61
player_tile
Definition maphand.h:30
player
Definition player.h:247
player::cities
struct city_list * cities
Definition player.h:279
player::flags
bv_plr_flags flags
Definition player.h:290
player::username
char username[MAX_LEN_NAME]
Definition player.h:250
player::team
struct team * team
Definition player.h:259
player::connections
struct conn_list * connections
Definition player.h:296
player::is_alive
bool is_alive
Definition player.h:266
player::economic
struct player_economic economic
Definition player.h:282
req_context
Definition requirements.h:100
req_context::player
const struct player * player
Definition requirements.h:101
tile
Definition tile.h:50
tile::units
struct unit_list * units
Definition tile.h:58
trade_route_settings
Definition traderoutes.h:75
trade_route
Definition traderoutes.h:83
unit_class
Definition unittype.h:149
unit_order
Definition unit.h:92
unit_type
Definition unittype.h:500
unit
Definition unit.h:138
unit::upkeep
int upkeep[O_LAST]
Definition unit.h:148
unit::id
int id
Definition unit.h:145
unit::moved
bool moved
Definition unit.h:173
unit::server
struct unit::@81::@84 server
unit::tile
struct tile * tile
Definition unit.h:140
unit::homecity
int homecity
Definition unit.h:146
unit::transporter
struct unit * transporter
Definition unit.h:183
unit::utype
const struct unit_type * utype
Definition unit.h:139
unit::dying
bool dying
Definition unit.h:250
universal
Definition fc_types.h:901
universal::kind
enum universals_n kind
Definition fc_types.h:903
universal::value
universals_u value
Definition fc_types.h:902
vision_site
Definition vision.h:109
vision_site::happy
bool happy
Definition vision.h:119
vision_site::improvements
bv_imprs improvements
Definition vision.h:125
vision_site::walls
int walls
Definition vision.h:118
vision_site::style
int style
Definition vision.h:121
vision_site::unhappy
bool unhappy
Definition vision.h:120
vision_site::city_image
int city_image
Definition vision.h:122
vision_site::occupied
bool occupied
Definition vision.h:117
vision_site::capital
enum capital_type capital
Definition vision.h:123
vision
Definition vision.h:85
vision::radius_sq
v_radius_t radius_sq
Definition vision.h:92
worker_task
Definition workertask.h:21
world::map
struct civ_map map
Definition world_object.h:38
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
fc__attribute
#define fc__attribute(x)
Definition support.h:99
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
team_members
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
tech.h
A_UNSET
#define A_UNSET
Definition tech.h:48
free_current_governments_data
void free_current_governments_data(struct cur_govs_data *data)
Definition techtools.c:1537
steal_a_tech
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1233
notify_new_government_options
void notify_new_government_options(struct player *pplayer, struct cur_govs_data *data, const char *reason)
Definition techtools.c:1551
send_research_info
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
create_current_governments_data_all
struct cur_govs_data * create_current_governments_data_all(void)
Definition techtools.c:1517
techtools.h
is_terrain_class_near_tile
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:612
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:238
is_terrain_near_tile
bool is_terrain_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:348
terrain_type_iterate
#define terrain_type_iterate(_p)
Definition terrain.h:373
terrain_type_iterate_end
#define terrain_type_iterate_end
Definition terrain.h:379
tile_set_owner
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
tile_extra_rm_apply
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_set_worked
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
tile_claimer
#define tile_claimer(_tile)
Definition tile.h:100
tile_index
#define tile_index(_pt_)
Definition tile.h:88
tile_worked
#define tile_worked(_tile)
Definition tile.h:114
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:110
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:43
tile_continent
#define tile_continent(_tile)
Definition tile.h:92
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
tile_owner
#define tile_owner(_tile)
Definition tile.h:96
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
cities_trade_route_type
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
goods_number
Goods_type_id goods_number(const struct goods_type *pgood)
Definition traderoutes.c:581
trade_route_settings_by_type
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
Definition traderoutes.c:201
can_establish_trade_route
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:275
traderoutes.h
trade_routes_iterate_safe_end
#define trade_routes_iterate_safe_end
Definition traderoutes.h:156
TRI_CANCEL
@ TRI_CANCEL
Definition traderoutes.h:32
trade_routes_iterate_end
#define trade_routes_iterate_end
Definition traderoutes.h:134
trade_routes_iterate_safe
#define trade_routes_iterate_safe(c, proute)
Definition traderoutes.h:138
trade_routes_iterate
#define trade_routes_iterate(c, proute)
Definition traderoutes.h:130
trade_route_type
trade_route_type
Definition traderoutes.h:37
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:724
universals_u::building
const struct impr_type * building
Definition fc_types.h:717
transporter_for_unit_at
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1918
can_unit_continue_current_activity
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:838
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:390
is_enemy_unit_tile
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:413
unit_owner
#define unit_owner(_pu)
Definition unit.h:389
unit_activity_handling
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6468
unit_change_homecity_handling
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:4014
unithand.h
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_safe
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_list_iterate_safe_end
#define unit_list_iterate_safe_end
Definition unitlist.h:61
resolve_unit_stacks
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1398
unit_goes_out_of_sight
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2712
send_unit_info
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2725
unit_activities_cancel
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:800
wipe_unit
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2135
unit_list_refresh_vision
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4855
bounce_unit
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1225
unittools.h
utype_buy_gold_cost
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Definition unittype.c:1492
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_upkeep_cost
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
utype_player_already_has_this_unique
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1927
utype_can_do_action_result
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:387
unit_can_take_over
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:264
utype_index
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
uclass_has_flag
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:766
utype_class
#define utype_class(_t_)
Definition unittype.h:749
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:852
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:859
vision_site_update_from_city
void vision_site_update_from_city(struct vision_site *psite, const struct city *pcity)
Definition vision.c:115
vision_site_size_get
citizens vision_site_size_get(const struct vision_site *psite)
Definition vision.c:155
vision_new
struct vision * vision_new(struct player *pplayer, struct tile *ptile)
Definition vision.c:33
vision_reveal_tiles
bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
Definition vision.c:62
vision_free
void vision_free(struct vision *vision)
Definition vision.c:50
vision_site_new_from_city
struct vision_site * vision_site_new_from_city(const struct city *pcity)
Definition vision.c:101
vision_site_destroy
void vision_site_destroy(struct vision_site *psite)
Definition vision.c:74
vision.h
ASSERT_VISION
#define ASSERT_VISION(v)
Definition vision.h:98
V_RADIUS
#define V_RADIUS(main_sq, invis_sq, subs_sq)
Definition vision.h:96
vision_site_owner
#define vision_site_owner(v)
Definition vision.h:128
v_radius_t
short int v_radius_t[V_COUNT]
Definition vision.h:83
worker_task_list_iterate
#define worker_task_list_iterate(tasklist, ptask)
Definition workertask.h:33
worker_task_list_iterate_end
#define worker_task_list_iterate_end
Definition workertask.h:35
worklist_copy
void worklist_copy(struct worklist *dst, const struct worklist *src)
Definition worklist.c:112