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