Freeciv-3.1: /fast/freeciv/nightly/S3_1/server/citytools.c Source File

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() */
97 static struct city_list *arrange_workers_queue = NULL;
98
99/* Suppress sending cities during game_load() and end_phase() */
100 static bool send_city_suppressed = FALSE;
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/************************************************************************/
135 void city_freeze_workers(struct city *pcity)
136{
137 pcity->server.workers_frozen++;
138}
139
140/************************************************************************/
145 void 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 */
152 auto_arrange_workers(pcity);
153 }
154}
155
156/************************************************************************/
159 void city_freeze_workers_queue(struct city *pcity)
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) {
170 pcity->server.needs_arrange = CNA_NORMAL;
171 }
172}
173
174/************************************************************************/
178 static 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/************************************************************************/
191 void city_thaw_workers_queue(void)
192{
193 if (NULL == arrange_workers_queue) {
194 return;
195 }
196
197 city_list_iterate(arrange_workers_queue, pcity) {
198 city_thaw_workers(pcity);
199 } city_list_iterate_end;
200
201 city_list_destroy(arrange_workers_queue);
202 arrange_workers_queue = NULL;
203}
204
205/************************************************************************/
213 static 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 */
235 if (!game.server.natural_city_names) {
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 }
274 } extra_type_by_cause_iterate_end;
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 }
305 } terrain_type_iterate_end;
306
307 return (int) priority;
308}
309
310/************************************************************************/
314 static bool is_default_city_name(const char *name, struct player *pplayer)
315{
316 nation_city_list_iterate(nation_cities(nation_of_player(pplayer)),
317 pncity) {
318 if (0 == fc_strcasecmp(name, nation_city_name(pncity))) {
319 return TRUE;
320 }
321 } nation_city_list_iterate_end;
322 return FALSE;
323}
324
325/************************************************************************/
332 static 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 }
350 } nation_city_list_iterate_end;
351
352 return best_name;
353}
354
355/************************************************************************/
367 bool 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. */
373 if (CNM_PLAYER_UNIQUE == game.server.allowed_city_names
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. */
383 if ((CNM_GLOBAL_UNIQUE == game.server.allowed_city_names
384 || CNM_NO_STEALING == game.server.allowed_city_names)
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 */
403 if (CNM_NO_STEALING == game.server.allowed_city_names) {
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 }
411 } players_iterate_end;
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/************************************************************************/
451 const 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. */
512 nation_list_iterate(pnation->server.civilwar_nations, n) {
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 }
520 } nation_list_iterate_end;
521
522 /* Append the nation's parent nations into the search tree. */
523 nation_list_iterate(pnation->server.parent_nations, n) {
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 }
531 } nation_list_iterate_end;
532 }
533
534 /* Still not found; append all remaining nations. */
535 allowed_nations_iterate(n) {
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 }
543 } allowed_nations_iterate_end;
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/************************************************************************/
569 int build_points_left(struct city *pcity)
570{
571 int cost = city_production_build_shield_cost(pcity);
572
573 return cost - pcity->shield_stock;
574}
575
576/************************************************************************/
583 static 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. */
591 fc_assert_ret_msg(!punit->server.dying,
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",
598 nation_rule_name(nation_of_player(from_player)),
599 unit_rule_name(punit),
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."),
605 unit_link(punit),
606 city_link(tocity));
607 }
608 } else {
609 struct tile *utile = unit_tile(punit);
610 struct city *in_city = tile_city(utile);
611
612 if (utype_player_already_has_this_unique(to_player,
613 unit_type_get(punit))) {
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",
619 nation_rule_name(nation_of_player(to_player)),
620 unit_rule_name(punit),
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),
635 unit_tile_link(punit));
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",
646 unit_rule_name(punit), city_name_get(in_city),
647 nation_rule_name(nation_of_player(from_player)),
648 nation_rule_name(nation_of_player(to_player)));
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."),
653 unit_link(punit),
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",
660 unit_rule_name(punit),
661 nation_rule_name(nation_of_player(from_player)),
662 nation_rule_name(nation_of_player(to_player)));
663 if (verbose) {
664 notify_player(from_player, unit_tile(punit),
665 E_UNIT_RELOCATED, ftc_server,
666 _("Transferred %s from %s to %s."),
667 unit_link(punit),
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",
673 unit_rule_name(punit),
674 nation_rule_name(nation_of_player(from_player)),
675 nation_rule_name(nation_of_player(to_player)));
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),
682 unit_tile_link(punit),
683 nation_adjective_for_player(to_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/************************************************************************/
714 void 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 }
765 } unit_list_iterate_safe_end;
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 */
774 unit_list_iterate_safe(units, vunit) {
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.",
805 nation_rule_name(nation_of_unit(vunit)),
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 }
815 } unit_list_iterate_safe_end;
816
817#ifdef FREECIV_DEBUG
818 unit_list_iterate(pcity->units_supported, punit) {
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);
826 } unit_list_iterate_end;
827#endif /* FREECIV_DEBUG */
828}
829
830/************************************************************************/
849 struct 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
904 > IDENTITY_NUMBER_ZERO))
905 && (pclass == NULL
906 || is_native_near_tile(&(wld.map), pclass, city_tile(pcity)))) {
907 best_dist = city_dist;
908 best_city = pcity;
909 }
910 } city_list_iterate_end;
911 } players_iterate_end;
912
913 return best_city;
914}
915
916/************************************************************************/
921 static 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 }
942 } city_built_iterate_end;
943
944 if (city_remains) {
945 nullify_prechange_production(pcity);
946 pcity->shield_stock = 0;
947 }
948}
949
950/************************************************************************/
954 static 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);
970 struct trade_route_settings *settings = trade_route_settings_by_type(type);
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);
999 } trade_routes_iterate_safe_end;
1000}
1001
1002/************************************************************************/
1007 static 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."),
1045 improvement_name_translation(pimprove),
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 }
1053 } improvement_iterate_end;
1054}
1055
1056/************************************************************************/
1065 bool 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;
1093 } unit_list_iterate_end;
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 }
1107 } players_iterate_end;
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 */
1120 city_rally_point_clear(pcity);
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
1127 unit_list_iterate(pcity->units_supported, punit) {
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);
1136 } unit_list_iterate_end;
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 }
1156 } city_built_iterate_end;
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;
1162 vision_reveal_tiles(new_vision, game.server.vision_reveal_tiles);
1163 vision_change_sight(new_vision, old_vision->radius_sq);
1164
1165 ASSERT_VISION(new_vision);
1166
1167 if (CNM_PLAYER_UNIQUE == game.server.allowed_city_names
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 }
1210 } players_iterate_end;
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. */
1235 reestablish_city_trade_routes(pcity);
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) {
1263 city_build_free_buildings(pcity);
1264 } /* else caller should probably ensure palace is built */
1265 ptaker->server.got_first_city = TRUE;
1266 }
1267
1268 citizens_convert_conquest(pcity);
1269
1270 /* Restore any global improvement effects that this city confers */
1271 city_built_iterate(pcity, pimprove) {
1272 city_add_improvement(pcity, pimprove);
1273 } city_built_iterate_end;
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. */
1282 remove_obsolete_buildings_city(pcity, TRUE);
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! */
1326 city_refresh_queue_add(pcity);
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) {
1351 city_refresh_queue_add(acity);
1352 } city_list_iterate_end;
1353 } else {
1354 /* Refresh all cities to account for possible global effects. */
1355 cities_iterate(acity) {
1356 city_refresh_queue_add(acity);
1357 } cities_iterate_end;
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) {
1367 city_refresh_queue_add(acity);
1368 } city_list_iterate_end;
1369 }
1370
1371 /* Refresh all cities in the queue. */
1372 city_refresh_queue_processing();
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)) {
1385 city_refresh_for_player(ptaker);
1386 }
1387 if (old_giver_content_citizens != player_content_citizens(pgiver)
1388 || old_giver_angry_citizens != player_angry_citizens(pgiver)) {
1389 city_refresh_for_player(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/************************************************************************/
1410 void city_build_free_buildings(struct city *pcity)
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++) {
1434 Impr_type_id n = game.rgame.global_init_buildings[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
1444 || (game.server.savepalace
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
1464 || (game.server.savepalace
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/************************************************************************/
1489 void 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 }
1514 } unit_list_iterate_end;
1515 } players_iterate_end;
1516
1517 adv_city_alloc(pcity);
1518
1519 tile_set_owner(ptile, pplayer, ptile); /* temporarily */
1520 city_choose_build_default(pcity);
1521 pcity->id = identity_number();
1522
1523 fc_allocate_mutex(&game.server.mutexes.city_list);
1524 idex_register_city(&wld, pcity);
1525 fc_release_mutex(&game.server.mutexes.city_list);
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 */
1530 city_build_free_buildings(pcity);
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. */
1545 pwork->specialists[DEFAULT_SPECIALIST]++;
1546 /* One less citizen. Citizen sanity will be handled later in
1547 * city_thaw_workers_queue() */
1548 pwork->server.synced = FALSE;
1549 city_freeze_workers_queue(pwork);
1550 }
1551
1552 /* Update citizens. */
1553 citizens_update(pcity, nationality);
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 }
1565 } extra_type_iterate_end;
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);
1575 vision_reveal_tiles(pcity->server.vision, game.server.vision_reveal_tiles);
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! */
1592 city_refresh_queue_processing();
1593
1594 /* Bases destroyed earlier may have had watchtower effect. Refresh
1595 * unit vision. */
1596 unit_list_refresh_vision(ptile->units);
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. */
1620 if (!can_unit_continue_current_activity(&(wld.map), punit)) {
1621 unit_activities_cancel(punit);
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. */
1628 auto_arrange_workers(home);
1629 }
1630 sanity_check_city(home);
1631 send_city_info(city_owner(home), home);
1632 }
1633 } unit_list_iterate_end;
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/************************************************************************/
1649 bool create_city_for_player(struct player *pplayer, struct tile *ptile,
1650 const char *name)
1651{
1652 if (is_enemy_unit_tile(ptile, pplayer)
1653 || !city_can_be_built_here(ptile, NULL, FALSE)) {
1654 return FALSE;
1655 }
1656
1657 if (!pplayer->is_alive) {
1658 pplayer->is_alive = TRUE;
1659 send_player_info_c(pplayer, NULL);
1660 }
1661
1662 if (name == NULL || name[0] == '\0') {
1663 name = city_name_suggestion(pplayer, ptile);
1664 }
1665
1666 map_show_tile(pplayer, ptile);
1667 create_city(pplayer, ptile, name, pplayer);
1668
1669 return TRUE;
1670}
1671
1672/************************************************************************/
1675 void remove_city(struct city *pcity)
1676{
1677 struct player *powner = city_owner(pcity);
1678 struct tile *pcenter = city_tile(pcity);
1679 bv_imprs had_small_wonders;
1680 struct vision *old_vision;
1681 int id = pcity->id; /* We need this even after memory has been freed */
1682 bool had_great_wonders = FALSE;
1683 const citizens old_content_citizens = player_content_citizens(powner);
1684 const citizens old_angry_citizens = player_angry_citizens(powner);
1685 struct dbv tile_processed;
1686 struct tile_list *process_queue;
1687 const char *ctl = city_tile_link(pcity);
1688
1689 CALL_PLR_AI_FUNC(city_lost, powner, powner, pcity);
1690 CALL_FUNC_EACH_AI(city_destroyed, pcity);
1691
1692 BV_CLR_ALL(had_small_wonders);
1693 city_built_iterate(pcity, pimprove) {
1694 building_removed(pcity, pimprove, "city_destroyed", NULL);
1695
1696 if (is_small_wonder(pimprove)) {
1697 BV_SET(had_small_wonders, improvement_index(pimprove));
1698 } else if (is_great_wonder(pimprove)) {
1699 had_great_wonders = TRUE;
1700 }
1701 } city_built_iterate_end;
1702
1703 /* Rehome units in other cities */
1704 unit_list_iterate_safe(pcity->units_supported, punit) {
1705 struct city *new_home_city = tile_city(unit_tile(punit));
1706
1707 if (new_home_city
1708 && new_home_city != pcity
1709 && city_owner(new_home_city) == powner
1710 && !punit->server.dying) {
1711 transfer_unit(punit, new_home_city, TRUE, TRUE);
1712 }
1713 } unit_list_iterate_safe_end;
1714
1715 /* Make sure ships are not left on land when city is removed. */
1716 unit_list_iterate_safe(pcenter->units, punit) {
1717 bool moved;
1718 const struct unit_type *punittype = unit_type_get(punit);
1719
1720 if (is_native_tile(punittype, pcenter)) {
1721 continue;
1722 }
1723
1724 unit_activity_handling(punit, ACTIVITY_IDLE);
1725 moved = FALSE;
1726 adjc_iterate(&(wld.map), pcenter, tile1) {
1727 struct unit *ptrans;
1728
1729 if (!moved && is_native_tile(punittype, tile1)) {
1730 if (adv_could_unit_move_to_tile(punit, tile1) == 1) {
1731 /* Move */
1732 if (!can_unit_survive_at_tile(&(wld.map), punit, tile1)) {
1733 /* It may be impossible to survive at the tile even if it is
1734 * native. See UTYF_COAST_STRICT */
1735 ptrans = transporter_for_unit_at(punit, tile1);
1736 } else {
1737 ptrans = NULL;
1738 }
1739 if (action_auto_perf_unit_do(AAPC_CITY_GONE, punit,
1740 tile_owner(tile1), NULL, NULL,
1741 tile1, tile_city(tile1), ptrans,
1742 NULL) != NULL) {
1743 moved = TRUE;
1744 }
1745 if (moved) {
1746 notify_player(unit_owner(punit), tile1,
1747 E_UNIT_RELOCATED, ftc_server,
1748 _("Moved %s out of disbanded city %s "
1749 "since it cannot stay on %s."),
1750 unit_link(punit), ctl,
1751 terrain_name_translation(tile_terrain(pcenter)));
1752 break;
1753 }
1754 }
1755 }
1756 } adjc_iterate_end;
1757 if (!moved) {
1758 notify_player(unit_owner(punit), unit_tile(punit),
1759 E_UNIT_LOST_MISC, ftc_server,
1760 _("When %s was disbanded your %s could not "
1761 "get out, and it was therefore lost."),
1762 ctl,
1763 unit_tile_link(punit));
1764 wipe_unit(punit, ULR_CITY_LOST, NULL);
1765 }
1766 } unit_list_iterate_safe_end;
1767
1768 process_queue = tile_list_new();
1769 dbv_init(&tile_processed, map_num_tiles());
1770 for (tile_list_append(process_queue, pcenter); tile_list_size(process_queue) > 0;) {
1771 struct tile *ptile = tile_list_front(process_queue);
1772
1773 tile_list_pop_front(process_queue);
1774 dbv_set(&tile_processed, tile_index(ptile));
1775 adjc_iterate(&(wld.map), ptile, piter) {
1776 struct city *other_city;
1777
1778 if (dbv_isset(&tile_processed, tile_index(piter))) {
1779 continue;
1780 }
1781 other_city = tile_city(piter);
1782 if (other_city != NULL) {
1783 /* Adjacent tile has a city that may have been part of same channel */
1784 dbv_set(&tile_processed, tile_index(piter));
1785 tile_list_append(process_queue, piter);
1786 unit_list_iterate_safe(piter->units, punit) {
1787 struct unit_class *pclass = utype_class(punit->utype);
1788
1789 if (!uclass_has_flag(pclass, UCF_BUILD_ANYWHERE)
1790 && !is_native_tile(punit->utype, piter)
1791 && !is_city_channel_tile(&(wld.map), pclass, piter, pcenter)) {
1792 notify_player(unit_owner(punit), unit_tile(punit),
1793 E_UNIT_LOST_MISC, ftc_server,
1794 _("When %s was disbanded your %s in %s was trapped, "
1795 "and it was therefore lost."),
1796 ctl,
1797 unit_tile_link(punit),
1798 city_link(other_city));
1799 wipe_unit(punit, ULR_CITY_LOST, NULL);
1800 }
1801 } unit_list_iterate_safe_end;
1802 } else {
1803 dbv_set(&tile_processed, tile_index(piter));
1804 }
1805 } adjc_iterate_end;
1806 }
1807
1808 dbv_free(&tile_processed);
1809 tile_list_destroy(process_queue);
1810
1811 if (!city_exist(id)) {
1812 /* Wiping trapped units caused city to disappear. */
1813 return;
1814 }
1815
1816 /* Any remaining supported units are destroyed */
1817 unit_list_iterate_safe(pcity->units_supported, punit) {
1818 wipe_unit(punit, ULR_CITY_LOST, NULL);
1819 } unit_list_iterate_safe_end;
1820
1821 if (!city_exist(id)) {
1822 /* Wiping supported units caused city to disappear. */
1823 return;
1824 }
1825
1826 trade_routes_iterate_safe(pcity, proute) {
1827 struct trade_route *pback = remove_trade_route(pcity, proute,
1828 TRUE, TRUE);
1829
1830 FC_FREE(proute);
1831 FC_FREE(pback);
1832 } trade_routes_iterate_safe_end;
1833
1834 map_clear_border(pcenter);
1835 city_workers_queue_remove(pcity);
1836 city_thaw_workers_queue();
1837 city_refresh_queue_processing();
1838
1839 /* idex_unregister_city() is called in game_remove_city() below */
1840
1841 /* identity_number_release(pcity->id) is *NOT* done! The cities may
1842 still be alive in the client, or in the player map. The number of
1843 removed cities is small, so the loss is acceptable.
1844 */
1845
1846 old_vision = pcity->server.vision;
1847 pcity->server.vision = NULL;
1848 script_server_remove_exported_object(pcity);
1849 adv_city_free(pcity);
1850
1851 /* Remove city from the map. */
1852 tile_set_worked(pcenter, NULL);
1853
1854 /* Reveal units. */
1855 players_iterate(other_player) {
1856 if (can_player_see_units_in_city(other_player, pcity)
1857 || !map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1858 continue;
1859 }
1860 unit_list_iterate(pcenter->units, punit) {
1861 if (can_player_see_unit(other_player, punit)) {
1862 send_unit_info(other_player->connections, punit);
1863 }
1864 } unit_list_iterate_end;
1865 } players_iterate_end;
1866
1867 fc_allocate_mutex(&game.server.mutexes.city_list);
1868 game_remove_city(&wld, pcity);
1869 fc_release_mutex(&game.server.mutexes.city_list);
1870
1871 /* Remove any extras that were only there because the city was there. */
1872 extra_type_iterate(pextra) {
1873 if (tile_has_extra(pcenter, pextra)
1874 && !is_native_tile_to_extra(pextra, pcenter)) {
1875 tile_extra_rm_apply(pcenter, pextra);
1876 }
1877 } extra_type_iterate_end;
1878
1879 players_iterate(other_player) {
1880 if (map_is_known_and_seen(pcenter, other_player, V_MAIN)) {
1881 reality_check_city(other_player, pcenter);
1882 } else if (get_player_bonus(other_player, EFT_REVEAL_CITIES) > 0) {
1883 map_show_tile(other_player, pcenter);
1884 }
1885 } players_iterate_end;
1886
1887 conn_list_iterate(game.est_connections, pconn) {
1888 if (NULL == pconn->playing && pconn->observer) {
1889 /* For detached observers we have to send a specific packet. This is
1890 * a hack necessitated by the private map that exists for players but
1891 * not observers. */
1892 dsend_packet_city_remove(pconn, id, id);
1893 }
1894 } conn_list_iterate_end;
1895
1896 if (old_vision != NULL) {
1897 vision_clear_sight(old_vision);
1898 vision_free(old_vision);
1899 }
1900
1901 /* Infrastructures may have changed. */
1902 send_tile_info(NULL, pcenter, FALSE);
1903
1904 /* Build a new palace for free if the player lost their capital and
1905 savepalace is on. */
1906 build_free_small_wonders(powner, &had_small_wonders);
1907
1908 /* Update wonder infos. */
1909 if (had_great_wonders) {
1910 send_game_info(NULL);
1911 /* No need to send to detached connections. */
1912 send_player_info_c(powner, NULL);
1913 } else if (BV_ISSET_ANY(had_small_wonders)) {
1914 /* No need to send to detached connections. */
1915 send_player_info_c(powner, NULL);
1916 }
1917
1918 if (old_content_citizens != player_content_citizens(powner)
1919 || old_angry_citizens != player_angry_citizens(powner)) {
1920 /* We crossed the EFT_EMPIRE_SIZE_* effects, we have to refresh all
1921 * cities for the player. */
1922 city_refresh_for_player(powner);
1923 }
1924
1925 sync_cities();
1926
1927 /* At least sentried helicopters need to go idle, maybe others.
1928 * In alien ruleset, city center might have provided water source
1929 * for adjacent tile. */
1930 tile_change_side_effects(pcenter, FALSE);
1931}
1932
1933/************************************************************************/
1949 bool unit_conquer_city(struct unit *punit, struct city *pcity)
1950{
1951 bool try_civil_war = FALSE;
1952 bool city_remains;
1953 int coins;
1954 struct player *pplayer = unit_owner(punit);
1955 struct player *cplayer = city_owner(pcity);
1956
1957 /* If not at war, may peacefully enter city. */
1958 fc_assert_ret_val_msg(pplayers_at_war(pplayer, cplayer), FALSE,
1959 "Can't conquer city during peace.");
1960
1961 /* If we cannot occupy the city, this unit entering will not trigger the
1962 * effects below. */
1963 fc_assert_ret_val_msg(unit_can_take_over(punit)
1964 || utype_can_do_action(unit_type_get(punit),
1965 ACTION_PARADROP_CONQUER)
1966 || utype_can_do_action(unit_type_get(punit),
1967 ACTION_PARADROP_FRIGHTEN_CONQUER)
1968 || utype_can_do_action(unit_type_get(punit),
1969 ACTION_PARADROP_ENTER_CONQUER),
1970 FALSE, "Bad unit for city occupation.");
1971
1972 /* A transported unit trying to conquer a city should already have been
1973 * unloaded. */
1974 fc_assert_ret_val_msg(punit->transporter == NULL, FALSE,
1975 "Can't conquer city while transported.");
1976
1977 /* Okay, we're at war - invader captures/destroys city... */
1978
1979 /* If a capital is captured, then spark off a civil war
1980 - Kris Bubendorfer
1981 Also check spaceships --dwp
1982 */
1983
1984 if (is_capital(pcity)
1985 && (cplayer->spaceship.state == SSHIP_STARTED
1986 || cplayer->spaceship.state == SSHIP_LAUNCHED)) {
1987 spaceship_lost(cplayer);
1988 }
1989
1990 if (is_capital(pcity)
1991 && civil_war_possible(cplayer, TRUE, TRUE)
1992 && normal_player_count() < MAX_NUM_PLAYERS
1993 && civil_war_triggered(cplayer)) {
1994 try_civil_war = TRUE;
1995 }
1996
1997 /*
1998 * We later remove a citizen. Lets check if we can save this since
1999 * the city will be destroyed.
2000 */
2001 if (city_size_get(pcity) <= 1) {
2002 int saved_id = pcity->id;
2003
2004 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2005 _("You destroy %s completely."),
2006 city_tile_link(pcity));
2007 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2008 _("%s has been destroyed by %s."),
2009 city_tile_link(pcity), player_name(pplayer));
2010 script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
2011
2012 /* We cant't be sure of city existence after running some script */
2013 if (city_exist(saved_id)) {
2014 remove_city(pcity);
2015 }
2016
2017 if (try_civil_war) {
2018 (void) civil_war(cplayer);
2019 }
2020 return TRUE;
2021 }
2022
2023 coins = cplayer->economic.gold;
2024 coins = MIN(coins,
2025 fc_rand((coins / 20) + 1)
2026 + (coins * (city_size_get(pcity))) / 200);
2027 pplayer->economic.gold += coins;
2028 cplayer->economic.gold -= coins;
2029 send_player_info_c(pplayer, pplayer->connections);
2030 send_player_info_c(cplayer, cplayer->connections);
2031 if (pcity->original != pplayer) {
2032 if (coins > 0) {
2033 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2034 PL_("You conquer %s; your lootings accumulate"
2035 " to %d gold!",
2036 "You conquer %s; your lootings accumulate"
2037 " to %d gold!", coins),
2038 city_link(pcity),
2039 coins);
2040 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2041 PL_("%s conquered %s and looted %d gold"
2042 " from the city.",
2043 "%s conquered %s and looted %d gold"
2044 " from the city.", coins),
2045 player_name(pplayer),
2046 city_link(pcity),
2047 coins);
2048 } else {
2049 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2050 _("You conquer %s."),
2051 city_link(pcity));
2052 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2053 _("%s conquered %s."),
2054 player_name(pplayer),
2055 city_link(pcity));
2056 }
2057 } else {
2058 if (coins > 0) {
2059 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2060 PL_("You have liberated %s!"
2061 " Lootings accumulate to %d gold.",
2062 "You have liberated %s!"
2063 " Lootings accumulate to %d gold.", coins),
2064 city_link(pcity),
2065 coins);
2066 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2067 PL_("%s liberated %s and looted %d gold"
2068 " from the city.",
2069 "%s liberated %s and looted %d gold"
2070 " from the city.", coins),
2071 player_name(pplayer),
2072 city_link(pcity),
2073 coins);
2074 } else {
2075 notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2076 _("You have liberated %s!"),
2077 city_link(pcity));
2078 notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2079 _("%s liberated %s."),
2080 player_name(pplayer),
2081 city_link(pcity));
2082 }
2083 }
2084
2085 if (fc_rand(100) < get_unit_bonus(punit, EFT_CONQUEST_TECH_PCT)) {
2086 /* Just try to steal. Ignore failures to get tech */
2087 steal_a_tech(pplayer, cplayer, A_UNSET);
2088 }
2089
2090 /* We transfer the city first so that it is in a consistent state when
2091 * the size is reduced. */
2092 /* FIXME: maybe it should be a ruleset option whether barbarians get
2093 * free buildings such as palaces? */
2094 city_remains = transfer_city(pplayer, pcity, 0, TRUE, TRUE, TRUE,
2095 !is_barbarian(pplayer));
2096
2097 if (city_remains) {
2098 /* reduce size should not destroy this city */
2099 fc_assert(city_size_get(pcity) > 1);
2100 city_reduce_size(pcity, 1, pplayer, "conquest");
2101 }
2102
2103 if (try_civil_war) {
2104 (void) civil_war(cplayer);
2105 }
2106
2107 if (city_remains) {
2108 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
2109 "conquest");
2110 script_server_signal_emit("city_lost", pcity, cplayer, pplayer);
2111 }
2112
2113 return TRUE;
2114}
2115
2116/************************************************************************/
2119 static int city_citywalls_gfx(const struct city *pcity)
2120{
2121 int walls = get_city_bonus(pcity, EFT_VISIBLE_WALLS);
2122
2123 return walls > 0 ? walls : 0;
2124}
2125
2126/************************************************************************/
2129 bool send_city_suppression(bool now)
2130{
2131 bool formerly = send_city_suppressed;
2132
2133 send_city_suppressed = now;
2134 return formerly;
2135}
2136
2137/************************************************************************/
2140 static void package_dumb_city(struct player *pplayer, struct tile *ptile,
2141 struct packet_city_short_info *packet)
2142{
2143 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2144
2145 packet->id32 = pdcity->identity;
2146 packet->id16 = packet->id32;
2147 packet->owner = player_number(vision_site_owner(pdcity));
2148
2149 packet->tile = tile_index(ptile);
2150 if (pdcity->name == NULL) {
2151 packet->name[0] = '\0';
2152 } else {
2153 sz_strlcpy(packet->name, pdcity->name);
2154 }
2155
2156 packet->size = vision_site_size_get(pdcity);
2157
2158 packet->occupied = pdcity->occupied;
2159 packet->walls = pdcity->walls;
2160 packet->style = pdcity->style;
2161 packet->city_image = pdcity->city_image;
2162 packet->capital = pdcity->capital;
2163
2164 packet->happy = pdcity->happy;
2165 packet->unhappy = pdcity->unhappy;
2166
2167 packet->improvements = pdcity->improvements;
2168}
2169
2170/************************************************************************/
2174 void refresh_dumb_city(struct city *pcity)
2175{
2176 players_iterate(pplayer) {
2177 if (player_can_see_city_externals(pplayer, pcity)) {
2178 if (update_dumb_city(pplayer, pcity)) {
2179 struct packet_city_short_info packet;
2180
2181 if (city_owner(pcity) != pplayer) {
2182 /* Don't send the short_city information to someone who can see the
2183 * city's internals. Doing so would really confuse the client. */
2184 package_dumb_city(pplayer, pcity->tile, &packet);
2185 lsend_packet_city_short_info(pplayer->connections, &packet);
2186 }
2187 }
2188 }
2189 } players_iterate_end;
2190
2191 /* Don't send to non-player observers since they don't have 'dumb city'
2192 * information. */
2193}
2194
2195/************************************************************************/
2203 void broadcast_city_info(struct city *pcity)
2204{
2205 struct packet_city_info packet;
2206 struct packet_city_nationalities nat_packet;
2207 struct packet_city_rally_point rally_packet;
2208 struct packet_web_city_info_addition web_packet;
2209 struct packet_city_short_info sc_pack;
2210 struct player *powner = city_owner(pcity);
2211 struct trade_route_packet_list *routes;
2212
2213 /* Send to everyone who can see the city. */
2214
2215 if (pcity->server.needs_arrange != CNA_NOT) {
2216 /* Send city only when it's in sane state.
2217 * If it's not, it will be sent to everyone once
2218 * rearrangement has been finished. */
2219 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2220
2221 return;
2222 }
2223
2224 routes = trade_route_packet_list_new();
2225 package_city(pcity, &packet, &nat_packet, &rally_packet,
2226 &web_packet, routes, FALSE);
2227
2228 players_iterate(pplayer) {
2229 if (!send_city_suppressed || pplayer != powner) {
2230 if (can_player_see_city_internals(pplayer, pcity)) {
2231 update_dumb_city(pplayer, pcity);
2232 packet.original = city_original_owner(pcity, pplayer);
2233 lsend_packet_city_info(pplayer->connections, &packet, FALSE);
2234 lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE);
2235 lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE);
2236 web_lsend_packet(city_info_addition, pplayer->connections, &web_packet, FALSE);
2237 trade_route_packet_list_iterate(routes, route_packet) {
2238 lsend_packet_trade_route_info(pplayer->connections, route_packet);
2239 } trade_route_packet_list_iterate_end;
2240 } else if (player_can_see_city_externals(pplayer, pcity)) {
2241 reality_check_city(pplayer, pcity->tile);
2242 update_dumb_city(pplayer, pcity);
2243 package_dumb_city(pplayer, pcity->tile, &sc_pack);
2244 lsend_packet_city_short_info(pplayer->connections, &sc_pack);
2245 }
2246 }
2247 } players_iterate_end;
2248
2249 /* Send to global observers. */
2250 packet.original = city_original_owner(pcity, NULL);
2251 conn_list_iterate(game.est_connections, pconn) {
2252 if (conn_is_global_observer(pconn)) {
2253 send_packet_city_info(pconn, &packet, FALSE);
2254 send_packet_city_nationalities(pconn, &nat_packet, FALSE);
2255 send_packet_city_rally_point(pconn, &rally_packet, FALSE);
2256 web_send_packet(city_info_addition, pconn, &web_packet, FALSE);
2257 }
2258 } conn_list_iterate_end;
2259
2260 trade_route_packet_list_iterate(routes, route_packet) {
2261 FC_FREE(route_packet);
2262 } trade_route_packet_list_iterate_end;
2263 trade_route_packet_list_destroy(routes);
2264}
2265
2266/************************************************************************/
2270 void send_all_known_cities(struct conn_list *dest)
2271{
2272 conn_list_do_buffer(dest);
2273 conn_list_iterate(dest, pconn) {
2274 struct player *pplayer = pconn->playing;
2275
2276 if (!pplayer && !pconn->observer) {
2277 continue;
2278 }
2279 whole_map_iterate(&(wld.map), ptile) {
2280 if (!pplayer || NULL != map_get_player_site(ptile, pplayer)) {
2281 send_city_info_at_tile(pplayer, pconn->self, NULL, ptile);
2282 }
2283 } whole_map_iterate_end;
2284 }
2285 conn_list_iterate_end;
2286 conn_list_do_unbuffer(dest);
2287 flush_packets();
2288}
2289
2290/************************************************************************/
2293 void send_player_cities(struct player *pplayer)
2294{
2295 city_list_iterate(pplayer->cities, pcity) {
2296 if (city_refresh(pcity)) {
2297 log_error("%s radius changed while sending to player.",
2298 city_name_get(pcity));
2299
2300 /* Make sure that no workers in illegal position outside radius. */
2301 auto_arrange_workers(pcity);
2302 }
2303 send_city_info(pplayer, pcity);
2304 }
2305 city_list_iterate_end;
2306}
2307
2308/************************************************************************/
2313 void send_city_info(struct player *dest, struct city *pcity)
2314{
2315 struct player *powner = city_owner(pcity);
2316
2317 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
2318 return;
2319 }
2320
2321 if (dest == powner && send_city_suppressed) {
2322 return;
2323 }
2324
2325 if (!dest || dest == powner) {
2326 pcity->server.synced = TRUE;
2327 }
2328
2329 if (!dest) {
2330 broadcast_city_info(pcity);
2331 } else {
2332 send_city_info_at_tile(dest, dest->connections, pcity, pcity->tile);
2333 }
2334
2335 if (game.info.team_pooled_research
2336 && player_list_size(team_members(powner->team)) > 1) {
2337 /* We want to send the new total bulbs production of the team. */
2338 send_research_info(research_get(powner), NULL);
2339 }
2340}
2341
2342/************************************************************************/
2362 void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest,
2363 struct city *pcity, struct tile *ptile)
2364{
2365 struct packet_city_info packet;
2366 struct packet_city_nationalities nat_packet;
2367 struct packet_city_rally_point rally_packet;
2368 struct packet_web_city_info_addition web_packet;
2369 struct packet_city_short_info sc_pack;
2370 struct player *powner = NULL;
2371 struct trade_route_packet_list *routes = NULL;
2372
2373 if (!pcity) {
2374 pcity = tile_city(ptile);
2375 }
2376 if (pcity != NULL && pcity->server.needs_arrange != CNA_NOT) {
2377 pcity->server.needs_arrange = CNA_BROADCAST_PENDING;
2378
2379 return;
2380 }
2381 if (pcity) {
2382 powner = city_owner(pcity);
2383 }
2384
2385 if (powner != NULL && powner == pviewer) {
2386 /* Send info to owner */
2387 /* This case implies powner non-NULL which means pcity non-NULL */
2388 if (!send_city_suppressed) {
2389 /* Wait that city has been rearranged, if it's currently
2390 * not in sane state. */
2391
2392 routes = trade_route_packet_list_new();
2393
2394 /* Send all info to the owner */
2395 update_dumb_city(powner, pcity);
2396 package_city(pcity, &packet, &nat_packet, &rally_packet,
2397 &web_packet, routes, FALSE);
2398 packet.original = city_original_owner(pcity, pviewer);
2399 lsend_packet_city_info(dest, &packet, FALSE);
2400 lsend_packet_city_nationalities(dest, &nat_packet, FALSE);
2401 lsend_packet_city_rally_point(dest, &rally_packet, FALSE);
2402 web_lsend_packet(city_info_addition, dest, &web_packet, FALSE);
2403 trade_route_packet_list_iterate(routes, route_packet) {
2404 lsend_packet_trade_route_info(dest, route_packet);
2405 } trade_route_packet_list_iterate_end;
2406 if (dest == powner->connections) {
2407 /* HACK: send also a copy to global observers. */
2408 packet.original = city_original_owner(pcity, NULL);
2409 conn_list_iterate(game.est_connections, pconn) {
2410 if (conn_is_global_observer(pconn)) {
2411 send_packet_city_info(pconn, &packet, FALSE);
2412 trade_route_packet_list_iterate(routes, route_packet) {
2413 send_packet_trade_route_info(pconn, route_packet);
2414 } trade_route_packet_list_iterate_end;
2415 }
2416 } conn_list_iterate_end;
2417 }
2418 }
2419 } else {
2420 /* send info to non-owner */
2421 if (!pviewer) { /* observer */
2422 if (pcity) {
2423 routes = trade_route_packet_list_new();
2424
2425 /* Should be dumb_city info? */
2426 package_city(pcity, &packet, &nat_packet, &rally_packet,
2427 &web_packet, routes, FALSE);
2428 lsend_packet_city_info(dest, &packet, FALSE);
2429 lsend_packet_city_nationalities(dest, &nat_packet, FALSE);
2430 lsend_packet_city_rally_point(dest, &rally_packet, FALSE);
2431 web_lsend_packet(city_info_addition, dest, &web_packet, FALSE);
2432 trade_route_packet_list_iterate(routes, route_packet) {
2433 lsend_packet_trade_route_info(dest, route_packet);
2434 } trade_route_packet_list_iterate_end;
2435 }
2436 } else {
2437 if (map_is_known_and_seen(ptile, pviewer, V_MAIN)) {
2438 if (pcity) { /* it's there and we see it; update and send */
2439 update_dumb_city(pviewer, pcity);
2440 package_dumb_city(pviewer, ptile, &sc_pack);
2441 lsend_packet_city_short_info(dest, &sc_pack);
2442 }
2443 } else { /* not seen; send old info */
2444 if (map_is_known(ptile, pviewer)
2445 && map_get_player_site(ptile, pviewer) != NULL) {
2446 package_dumb_city(pviewer, ptile, &sc_pack);
2447 lsend_packet_city_short_info(dest, &sc_pack);
2448 }
2449 }
2450 }
2451 }
2452
2453 if (routes != NULL) {
2454 trade_route_packet_list_iterate(routes, route_packet) {
2455 FC_FREE(route_packet);
2456 } trade_route_packet_list_iterate_end;
2457 trade_route_packet_list_destroy(routes);
2458 }
2459}
2460
2461/************************************************************************/
2466 void package_city(struct city *pcity, struct packet_city_info *packet,
2467 struct packet_city_nationalities *nat_packet,
2468 struct packet_city_rally_point *rally_packet,
2469 struct packet_web_city_info_addition *web_packet,
2470 struct trade_route_packet_list *routes,
2471 bool dipl_invest)
2472{
2473 int i;
2474 int ppl = 0;
2475
2476 fc_assert(!pcity->server.needs_arrange);
2477
2478 packet->id32 = pcity->id;
2479 packet->id16 = packet->id32;
2480 packet->owner = player_number(city_owner(pcity));
2481
2482 packet->tile = tile_index(city_tile(pcity));
2483 sz_strlcpy(packet->name, city_name_get(pcity));
2484
2485 packet->size = city_size_get(pcity);
2486 for (i = 0; i < FEELING_LAST; i++) {
2487 packet->ppl_happy[i] = pcity->feel[CITIZEN_HAPPY][i];
2488 packet->ppl_content[i] = pcity->feel[CITIZEN_CONTENT][i];
2489 packet->ppl_unhappy[i] = pcity->feel[CITIZEN_UNHAPPY][i];
2490 packet->ppl_angry[i] = pcity->feel[CITIZEN_ANGRY][i];
2491 if (i == 0) {
2492 ppl += packet->ppl_happy[i];
2493 ppl += packet->ppl_content[i];
2494 ppl += packet->ppl_unhappy[i];
2495 ppl += packet->ppl_angry[i];
2496 }
2497 }
2498 /* The number of data in specialists[] array */
2499 packet->specialists_size = specialist_count();
2500 specialist_type_iterate(sp) {
2501 packet->specialists[sp] = pcity->specialists[sp];
2502 ppl += packet->specialists[sp];
2503 } specialist_type_iterate_end;
2504
2505 /* The nationality of the citizens. */
2506 nat_packet->id32 = pcity->id;
2507 nat_packet->id16 = nat_packet->id32;
2508 nat_packet->nationalities_count = 0;
2509 if (game.info.citizen_nationality) {
2510 int cit = 0;
2511
2512 player_slots_iterate(pslot) {
2513 citizens nationality = citizens_nation_get(pcity, pslot);
2514 if (nationality != 0) {
2515 /* This player should exist! */
2516 fc_assert(player_slot_get_player(pslot) != NULL);
2517
2518 nat_packet->nation_id[nat_packet->nationalities_count]
2519 = player_slot_index(pslot);
2520 nat_packet->nation_citizens[nat_packet->nationalities_count]
2521 = nationality;
2522 nat_packet->nationalities_count++;
2523
2524 cit += nationality;
2525 }
2526 } player_slots_iterate_end;
2527
2528 fc_assert(cit == packet->size);
2529 }
2530
2531 packet->history = pcity->history;
2532 packet->culture = city_culture(pcity);
2533 packet->buy_cost = city_production_buy_gold_cost(pcity);
2534
2535 if (packet->size != ppl) {
2536 static bool recursion = FALSE;
2537
2538 if (recursion) {
2539 /* Recursion didn't help. Do not enter infinite recursive loop.
2540 * Package city as it is. */
2541 log_error("Failed to fix inconsistent city size.");
2542 recursion = FALSE;
2543 } else {
2544 /* Note: If you get this error and try to debug the cause, you may find
2545 * using check_city_feelings() in some key points useful. */
2546 /* Have this as an fc_assert() first, so one can use '-F' to caught these in
2547 * debugger. */
2548 fc_assert(packet->size == ppl);
2549
2550 /* In all builds have an error message shown. */
2551 log_error("City size %d, citizen count %d for %s",
2552 packet->size, ppl, city_name_get(pcity));
2553
2554 /* Try to fix */
2555 city_refresh(pcity);
2556 auto_arrange_workers(pcity);
2557
2558 /* And repackage */
2559 recursion = TRUE;
2560 package_city(pcity, packet, nat_packet, rally_packet,
2561 web_packet, routes, dipl_invest);
2562 recursion = FALSE;
2563
2564 return;
2565 }
2566 }
2567
2568 packet->city_radius_sq = pcity->city_radius_sq;
2569
2570 i = 0;
2571 trade_routes_iterate(pcity, proute) {
2572 struct packet_trade_route_info *tri_packet = fc_malloc(sizeof(struct packet_trade_route_info));
2573
2574 tri_packet->city32 = pcity->id;
2575 tri_packet->city16 = tri_packet->city32;
2576 tri_packet->index = i;
2577 tri_packet->partner32 = proute->partner;
2578 tri_packet->partner16 = tri_packet->partner32;
2579 tri_packet->value = proute->value;
2580 tri_packet->direction = proute->dir;
2581 tri_packet->goods = goods_number(proute->goods);
2582
2583 trade_route_packet_list_append(routes, tri_packet);
2584
2585 i++;
2586 } trade_routes_iterate_end;
2587
2588 packet->trade_route_count = i;
2589
2590 output_type_iterate(o) {
2591 packet->surplus[o] = pcity->surplus[o];
2592 packet->waste[o] = pcity->waste[o];
2593 packet->unhappy_penalty[o] = pcity->unhappy_penalty[o];
2594 packet->prod[o] = pcity->prod[o];
2595 packet->citizen_base[o] = pcity->citizen_base[o];
2596 packet->usage[o] = pcity->usage[o];
2597 } output_type_iterate_end;
2598
2599 packet->food_stock = pcity->food_stock;
2600 packet->shield_stock = pcity->shield_stock;
2601 packet->pollution = pcity->pollution;
2602 packet->illness_trade = pcity->illness_trade;
2603 packet->city_options = pcity->city_options;
2604
2605 packet->production_kind = pcity->production.kind;
2606 packet->production_value = universal_number(&pcity->production);
2607
2608 packet->turn_last_built=pcity->turn_last_built;
2609 packet->turn_founded = pcity->turn_founded;
2610
2611 packet->changed_from_kind = pcity->changed_from.kind;
2612 packet->changed_from_value = universal_number(&pcity->changed_from);
2613
2614 packet->before_change_shields=pcity->before_change_shields;
2615 packet->disbanded_shields=pcity->disbanded_shields;
2616 packet->caravan_shields=pcity->caravan_shields;
2617 packet->last_turns_shield_surplus = pcity->last_turns_shield_surplus;
2618
2619 worklist_copy(&packet->worklist, &pcity->worklist);
2620 packet->diplomat_investigate=dipl_invest;
2621
2622 packet->airlift = pcity->airlift;
2623 packet->did_buy = pcity->did_buy;
2624 packet->did_sell = pcity->did_sell;
2625 packet->was_happy = pcity->was_happy;
2626
2627 packet->walls = city_citywalls_gfx(pcity);
2628 packet->style = pcity->style;
2629 packet->city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2630 packet->capital = pcity->capital;
2631 packet->steal = pcity->steal;
2632
2633 rally_packet->city_id32 = pcity->id;
2634 rally_packet->city_id16 = rally_packet->city_id32;
2635 rally_packet->length = pcity->rally_point.length;
2636 rally_packet->persistent = pcity->rally_point.persistent;
2637 rally_packet->vigilant = pcity->rally_point.vigilant;
2638 if (pcity->rally_point.length) {
2639 memcpy(rally_packet->orders, pcity->rally_point.orders,
2640 pcity->rally_point.length * sizeof(struct unit_order));
2641 }
2642
2643 BV_CLR_ALL(packet->improvements);
2644 improvement_iterate(pimprove) {
2645 if (city_has_building(pcity, pimprove)) {
2646 BV_SET(packet->improvements, improvement_index(pimprove));
2647 }
2648 } improvement_iterate_end;
2649
2650#ifdef FREECIV_WEB
2651 web_packet->id32 = pcity->id;
2652 web_packet->id16 = web_packet->id32;
2653
2654 web_packet->granary_size = city_granary_size(city_size_get(pcity));
2655 web_packet->granary_turns = city_turns_to_grow(pcity);
2656#endif /* FREECIV_WEB */
2657}
2658
2659/************************************************************************/
2669 bool update_dumb_city(struct player *pplayer, struct city *pcity)
2670{
2671 bv_imprs improvements;
2672 struct tile *pcenter = city_tile(pcity);
2673 struct vision_site *pdcity = map_get_player_city(pcenter, pplayer);
2674 /* pcity->client.occupied isn't used at the server, so we go straight to the
2675 * unit list to check the occupied status. */
2676 bool occupied = (unit_list_size(pcenter->units) > 0);
2677 int walls = city_citywalls_gfx(pcity);
2678 bool happy = city_happy(pcity);
2679 bool unhappy = city_unhappy(pcity);
2680 int style = pcity->style;
2681 int city_image = get_city_bonus(pcity, EFT_CITY_IMAGE);
2682 enum capital_type capital = pcity->capital;
2683
2684 BV_CLR_ALL(improvements);
2685 improvement_iterate(pimprove) {
2686 if (is_improvement_visible(pimprove)
2687 && city_has_building(pcity, pimprove)) {
2688 BV_SET(improvements, improvement_index(pimprove));
2689 }
2690 } improvement_iterate_end;
2691
2692 if (NULL == pdcity) {
2693 pdcity = vision_site_new_from_city(pcity);
2694 change_playertile_site(map_get_player_tile(pcenter, pplayer), pdcity);
2695 } else if (pdcity->location != pcenter) {
2696 log_error("Trying to update bad city (wrong location) "
2697 "at %i,%i for player %s",
2698 TILE_XY(pcity->tile), player_name(pplayer));
2699 fc_assert(pdcity->location == pcenter);
2700 pdcity->location = pcenter; /* ?? */
2701 } else if (pdcity->identity != pcity->id) {
2702 log_error("Trying to update old city (wrong identity) "
2703 "at %i,%i for player %s",
2704 TILE_XY(city_tile(pcity)), player_name(pplayer));
2705 fc_assert(pdcity->identity == pcity->id);
2706 pdcity->identity = pcity->id; /* ?? */
2707 } else if (pdcity->occupied == occupied
2708 && pdcity->walls == walls
2709 && pdcity->happy == happy
2710 && pdcity->unhappy == unhappy
2711 && pdcity->style == style
2712 && pdcity->city_image == city_image
2713 && pdcity->capital == capital
2714 && BV_ARE_EQUAL(pdcity->improvements, improvements)
2715 && vision_site_size_get(pdcity) == city_size_get(pcity)
2716 && vision_site_owner(pdcity) == city_owner(pcity)
2717 && (pdcity->name && !strcmp(pdcity->name, city_name_get(pcity)))) {
2718 return FALSE;
2719 }
2720
2721 vision_site_update_from_city(pdcity, pcity);
2722 pdcity->occupied = occupied;
2723 pdcity->walls = walls;
2724 pdcity->style = style;
2725 pdcity->city_image = city_image;
2726 pdcity->capital = capital;
2727 pdcity->happy = happy;
2728 pdcity->unhappy = unhappy;
2729 pdcity->improvements = improvements;
2730
2731 return TRUE;
2732}
2733
2734/************************************************************************/
2737 void reality_check_city(struct player *pplayer, struct tile *ptile)
2738{
2739 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2740
2741 if (pdcity) {
2742 struct city *pcity = tile_city(ptile);
2743
2744 if (!pcity || pcity->id != pdcity->identity) {
2745 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2746
2747 dlsend_packet_city_remove(pplayer->connections,
2748 pdcity->identity, pdcity->identity);
2749 fc_assert_ret(playtile->site == pdcity);
2750 playtile->site = NULL;
2751 vision_site_destroy(pdcity);
2752 }
2753 }
2754}
2755
2756/************************************************************************/
2759 void remove_dumb_city(struct player *pplayer, struct tile *ptile)
2760{
2761 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
2762
2763 if (pdcity) {
2764 struct player_tile *playtile = map_get_player_tile(ptile, pplayer);
2765
2766 dlsend_packet_city_remove(pplayer->connections,
2767 pdcity->identity, pdcity->identity);
2768 fc_assert_ret(playtile->site == pdcity);
2769 playtile->site = NULL;
2770 vision_site_destroy(pdcity);
2771 }
2772}
2773
2774/************************************************************************/
2778 static void announce_trade_route_removal(struct city *pc1, struct city *pc2,
2779 bool source_gone)
2780{
2781 struct player *plr1 = city_owner(pc1);
2782 struct player *plr2 = city_owner(pc2);
2783 char city1_link[MAX_LEN_LINK];
2784 char city2_link[MAX_LEN_LINK];
2785
2786 sz_strlcpy(city1_link, city_link(pc1));
2787 sz_strlcpy(city2_link, city_link(pc2));
2788
2789 if (plr1 == plr2) {
2790 if (source_gone) {
2791 notify_player(plr2, city_tile(pc2),
2792 E_CARAVAN_ACTION, ftc_server,
2793 _("Trade between %s and %s lost along with city."),
2794 city1_link, city2_link);
2795 } else {
2796 notify_player(plr1, city_tile(pc1),
2797 E_CARAVAN_ACTION, ftc_server,
2798 _("Trade route between %s and %s canceled."),
2799 city1_link, city2_link);
2800 }
2801 } else {
2802 if (source_gone) {
2803 notify_player(plr2, city_tile(pc2),
2804 E_CARAVAN_ACTION, ftc_server,
2805 /* TRANS: "...between Spanish city Madrid and Paris..." */
2806 _("Trade between %s city %s and %s lost along with "
2807 "their city."),
2808 nation_adjective_for_player(plr1), city1_link, city2_link);
2809 /* It's implicit to removed city's owner that that city no longer
2810 * has trade routes, so say nothing in that case */
2811 } else {
2812 notify_player(plr2, city_tile(pc2),
2813 E_CARAVAN_ACTION, ftc_server,
2814 _("Sorry, the %s canceled the trade route "
2815 "from %s to your city %s."),
2816 nation_plural_for_player(plr1), city1_link, city2_link);
2817 notify_player(plr1, city_tile(pc1),
2818 E_CARAVAN_ACTION, ftc_server,
2819 /* TRANS: "...from Paris to Spanish city Madrid." */
2820 _("We canceled the trade route "
2821 "from %s to %s city %s."),
2822 city1_link, nation_adjective_for_player(plr2), city2_link);
2823 }
2824 }
2825}
2826
2827/************************************************************************/
2835 struct trade_route *remove_trade_route(struct city *pc1, struct trade_route *proute,
2836 bool announce, bool source_gone)
2837{
2838 struct city *pc2 = game_city_by_number(proute->partner);
2839 struct trade_route *back_route = NULL;
2840
2841 fc_assert_ret_val(pc1 && proute, NULL);
2842
2843 trade_route_list_remove(pc1->routes, proute);
2844
2845 if (pc2 != NULL) {
2846 trade_routes_iterate(pc2, pback) {
2847 if (pc1->id == pback->partner) {
2848 back_route = pback;
2849 }
2850 } trade_routes_iterate_end;
2851
2852 if (back_route != NULL) {
2853 trade_route_list_remove(pc2->routes, back_route);
2854 }
2855
2856 if (announce) {
2857 announce_trade_route_removal(pc1, pc2, source_gone);
2858
2859 city_refresh(pc2);
2860 send_city_info(city_owner(pc2), pc2);
2861 }
2862 }
2863
2864 return back_route;
2865}
2866
2867/**********************************************************************/
2870 bool city_illness_strike(struct city *pcity)
2871{
2872 notify_player(city_owner(pcity), city_tile(pcity), E_CITY_PLAGUE,
2873 ftc_server,
2874 _("%s has been struck by a plague! Population lost!"),
2875 city_link(pcity));
2876 if (city_reduce_size(pcity, 1, NULL, "plague")) {
2877 pcity->turn_plague = game.info.turn;
2878
2879 /* recalculate illness */
2880 pcity->server.illness
2881 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade),
2882 NULL);
2883
2884 return TRUE;
2885 }
2886
2887 return FALSE;
2888}
2889
2890/************************************************************************/
2896 void do_sell_building(struct player *pplayer, struct city *pcity,
2897 struct impr_type *pimprove, const char *reason)
2898{
2899 if (can_city_sell_building(pcity, pimprove)) {
2900 pplayer->economic.gold += impr_sell_gold(pimprove);
2901 building_lost(pcity, pimprove, reason, NULL);
2902 }
2903}
2904
2905/************************************************************************/
2917struct city
2918*build_or_move_building(struct city *pcity, struct impr_type *pimprove,
2919 struct player **oldcity_owner)
2920{
2921 struct city *oldcity = NULL;
2922
2923 fc_assert_ret_val(!city_has_building(pcity, pimprove), NULL);
2924 if (is_great_wonder(pimprove)) {
2925 if (!(oldcity = city_from_great_wonder(pimprove))) {
2926 oldcity = pcity;
2927 }
2928 *oldcity_owner = city_owner(oldcity);
2929 } else if (is_small_wonder(pimprove)) {
2930 if (!(oldcity
2931 = city_from_small_wonder(city_owner(pcity), pimprove))) {
2932 oldcity = pcity;
2933 }
2934 }
2935 if (oldcity && oldcity != pcity) {
2936 city_remove_improvement(oldcity, pimprove);
2937 }
2938
2939 city_add_improvement(pcity, pimprove);
2940 return oldcity;
2941}
2942
2943/************************************************************************/
2946 bool building_removed(struct city *pcity, const struct impr_type *pimprove,
2947 const char *reason, struct unit *destroyer)
2948{
2949 int backup = pcity->id;
2950
2951 city_remove_improvement(pcity, pimprove);
2952
2953 script_server_signal_emit("building_lost", pcity, pimprove, reason,
2954 destroyer);
2955
2956 return city_exist(backup);
2957}
2958
2959/************************************************************************/
2963 void building_lost(struct city *pcity, const struct impr_type *pimprove,
2964 const char *reason, struct unit *destroyer)
2965{
2966 struct player *owner = city_owner(pcity);
2967 bool was_capital = is_capital(pcity);
2968 bool city_remains;
2969
2970 city_remains = building_removed(pcity, pimprove, reason, destroyer);
2971
2972 if ((was_capital && (!city_remains || !is_capital(pcity)))
2973 && (owner->spaceship.state == SSHIP_STARTED
2974 || owner->spaceship.state == SSHIP_LAUNCHED)) {
2975 /* If the capital was lost (by destruction of the palace) production on
2976 * the spaceship is lost. */
2977 spaceship_lost(owner);
2978 }
2979
2980 if (city_remains) {
2981 /* update city; influence of effects (buildings, ...) on unit upkeep */
2982 if (city_refresh(pcity)) {
2983 auto_arrange_workers(pcity);
2984 }
2985
2986 /* Re-update the city's visible area. This updates fog if the vision
2987 * range increases or decreases. */
2988 city_refresh_vision(pcity);
2989 }
2990}
2991
2992/************************************************************************/
3012 void city_units_upkeep(const struct city *pcity)
3013{
3014 int free_uk[O_LAST];
3015
3016 if (!pcity || !pcity->units_supported
3017 || unit_list_size(pcity->units_supported) < 1) {
3018 return;
3019 }
3020
3021 output_type_iterate(o) {
3022 free_uk[o] = get_city_output_bonus(pcity, get_output_type(o),
3023 EFT_UNIT_UPKEEP_FREE_PER_CITY);
3024 } output_type_iterate_end;
3025
3026 /* Save the upkeep for all units in the corresponding punit struct */
3027 unit_list_iterate(pcity->units_supported, punit) {
3028 const struct unit_type *ut = unit_type_get(punit);
3029 struct player *plr = unit_owner(punit);
3030 bool update = FALSE;
3031 int cost;
3032
3033 output_type_iterate(o) {
3034 cost = utype_upkeep_cost(ut, plr, o);
3035 if (cost > 0) {
3036 if (free_uk[o] > cost) {
3037 free_uk[o] -= cost;
3038 cost = 0;
3039 } else {
3040 cost -= free_uk[o];
3041 free_uk[o] = 0;
3042 }
3043 }
3044
3045 if (cost != punit->upkeep[o]) {
3046 update = TRUE;
3047 punit->upkeep[o] = cost;
3048 }
3049 } output_type_iterate_end;
3050
3051 if (update) {
3052 /* Update unit information to the player and global observers. */
3053 send_unit_info(NULL, punit);
3054 }
3055 } unit_list_iterate_end;
3056}
3057
3058/************************************************************************/
3061 void change_build_target(struct player *pplayer, struct city *pcity,
3062 struct universal *target,
3063 enum event_type event)
3064{
3065 const char *name;
3066 const char *source;
3067
3068 /* If the city is already building this thing, don't do anything */
3069 if (are_universals_equal(&pcity->production, target)) {
3070 return;
3071 }
3072
3073 /* Is the city no longer building a wonder? */
3074 if (VUT_IMPROVEMENT == pcity->production.kind
3075 && is_great_wonder(pcity->production.value.building)
3076 && event != E_IMP_AUTO
3077 && event != E_WORKLIST) {
3078 /* If the build target is changed because of an advisor's suggestion or
3079 because the worklist advances, then the wonder was completed --
3080 don't announce that the player has *stopped* building that wonder.
3081 */
3082 notify_player(NULL, city_tile(pcity), E_WONDER_STOPPED, ftc_server,
3083 _("The %s have stopped building The %s in %s."),
3084 nation_plural_for_player(pplayer),
3085 city_production_name_translation(pcity),
3086 city_link(pcity));
3087 }
3088
3089 /* Manage the city change-production penalty.
3090 (May penalize, restore or do nothing to the shield_stock.) */
3091 if (!is_ai(pplayer) || has_handicap(pplayer, H_PRODCHGPEN)) {
3092 pcity->shield_stock = city_change_production_penalty(pcity, target);
3093 }
3094
3095 /* Change build target. */
3096 pcity->production = *target;
3097
3098 /* What's the name of the target? */
3099 name = city_production_name_translation(pcity);
3100
3101 switch (event) {
3102 case E_WORKLIST:
3103 /* TRANS: Possible 'source' of the production change
3104 * (in "<city> is building ..." sentence). Preserve leading space. */
3105 source = _(" from the worklist");
3106 break;
3107 case E_IMP_AUTO:
3108 /* TRANS: Possible 'source' of the production change
3109 * (in "<city> is building ..." sentence). Preserve leading space. */
3110 source = _(" as suggested by the advisor");
3111 break;
3112 default:
3113 source = "";
3114 break;
3115 }
3116
3117 log_base(LOG_BUILD_TARGET, "%s started building %s%s.",
3118 city_name_get(pcity), name, source);
3119
3120 /* Tell the player what's up. */
3121 /* FIXME: this may give bad grammar when translated if the 'source'
3122 * string can have multiple values. */
3123 notify_player(pplayer, city_tile(pcity), event, ftc_server,
3124 /* TRANS: "<city> is building <production><source>."
3125 * 'source' might be an empty string, or a clause like
3126 * " from the worklist". */
3127 _("%s is building %s%s."),
3128 city_link(pcity),
3129 name, source);
3130
3131 /* If the city is building a wonder, tell the rest of the world
3132 about it. */
3133 if (VUT_IMPROVEMENT == pcity->production.kind
3134 && is_great_wonder(pcity->production.value.building)) {
3135 notify_player(NULL, city_tile(pcity), E_WONDER_STARTED, ftc_server,
3136 _("The %s have started building The %s in %s."),
3137 nation_plural_for_player(pplayer),
3138 name,
3139 city_link(pcity));
3140 }
3141}
3142
3143/************************************************************************/
3150 void city_map_update_empty(struct city *pcity, struct tile *ptile)
3151{
3152 tile_set_worked(ptile, NULL);
3153 send_tile_info(NULL, ptile, FALSE);
3154 pcity->server.synced = FALSE;
3155}
3156
3157/************************************************************************/
3164 void city_map_update_worker(struct city *pcity, struct tile *ptile)
3165{
3166 tile_set_worked(ptile, pcity);
3167 send_tile_info(NULL, ptile, FALSE);
3168 pcity->server.synced = FALSE;
3169}
3170
3171/************************************************************************/
3176 static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
3177{
3178 struct city *pwork = tile_worked(ptile);
3179
3180 if (NULL != pwork
3181 && !is_free_worked(pwork, ptile)
3182 && !city_can_work_tile(pwork, ptile)) {
3183 tile_set_worked(ptile, NULL);
3184 send_tile_info(NULL, ptile, FALSE);
3185
3186 pwork->specialists[DEFAULT_SPECIALIST]++; /* keep city sanity */
3187 pwork->server.synced = FALSE;
3188
3189 if (queued) {
3190 city_freeze_workers_queue(pwork); /* place the displaced later */
3191 } else {
3192 city_refresh(pwork); /* Specialist added, keep citizen count sanity */
3193 auto_arrange_workers(pwork);
3194 send_city_info(NULL, pwork);
3195 }
3196 return TRUE;
3197 }
3198
3199 return FALSE;
3200}
3201
3202/************************************************************************/
3207 bool city_map_update_tile_frozen(struct tile *ptile)
3208{
3209 return city_map_update_tile_direct(ptile, TRUE);
3210}
3211
3212/************************************************************************/
3215 bool city_map_update_tile_now(struct tile *ptile)
3216{
3217 return city_map_update_tile_direct(ptile, FALSE);
3218}
3219
3220/************************************************************************/
3224 void sync_cities(void)
3225{
3226 if (send_city_suppressed) {
3227 return;
3228 }
3229
3230 players_iterate(pplayer) {
3231 city_list_iterate(pplayer->cities, pcity) {
3232 if (!pcity->server.synced) {
3233 /* sending will set to TRUE. */
3234 send_city_info(pplayer, pcity);
3235 }
3236 } city_list_iterate_end;
3237 } players_iterate_end;
3238}
3239
3240/************************************************************************/
3243 void city_map_update_all(struct city *pcity)
3244{
3245 struct tile *pcenter = city_tile(pcity);
3246 const struct civ_map *nmap = &(wld.map);
3247
3248 city_tile_iterate_skip_free_worked(nmap, city_map_radius_sq_get(pcity), pcenter,
3249 ptile, _index, _x, _y) {
3250 /* bypass city_map_update_tile_now() for efficiency */
3251 city_map_update_tile_direct(ptile, FALSE);
3252 } city_tile_iterate_skip_free_worked_end;
3253}
3254
3255/************************************************************************/
3258 void city_map_update_all_cities_for_player(struct player *pplayer)
3259{
3260 city_list_iterate(pplayer->cities, pcity) {
3261 city_freeze_workers(pcity);
3262 city_map_update_all(pcity);
3263 city_thaw_workers(pcity);
3264 } city_list_iterate_end;
3265}
3266
3267/************************************************************************/
3277 void city_landlocked_sell_coastal_improvements(struct tile *ptile)
3278{
3279 adjc_iterate(&(wld.map), ptile, tile1) {
3280 struct city *pcity = tile_city(tile1);
3281
3282 if (pcity) {
3283 struct player *pplayer = city_owner(pcity);
3284 const struct req_context city_ctxt = {
3285 .player = pplayer,
3286 .city = pcity,
3287 .tile = pcity->tile,
3288 };
3289
3290 /* Sell all buildings (but not Wonders) that must be next to the ocean */
3291 city_built_iterate(pcity, pimprove) {
3292 if (!can_city_sell_building(pcity, pimprove)) {
3293 continue;
3294 }
3295
3296 requirement_vector_iterate(&pimprove->reqs, preq) {
3297 if ((VUT_TERRAIN == preq->source.kind
3298 || VUT_TERRAINCLASS == preq->source.kind
3299 || VUT_TERRFLAG == preq->source.kind)
3300 && !is_req_active(&city_ctxt, NULL, preq, RPT_CERTAIN)) {
3301 int price = impr_sell_gold(pimprove);
3302
3303 do_sell_building(pplayer, pcity, pimprove, "landlocked");
3304 notify_player(pplayer, tile1, E_IMP_SOLD, ftc_server,
3305 PL_("You sell %s in %s (now landlocked)"
3306 " for %d gold.",
3307 "You sell %s in %s (now landlocked)"
3308 " for %d gold.", price),
3309 improvement_name_translation(pimprove),
3310 city_link(pcity), price);
3311 }
3312 } requirement_vector_iterate_end;
3313 } city_built_iterate_end;
3314 }
3315 } adjc_iterate_end;
3316}
3317
3318/************************************************************************/
3324 void city_refresh_vision(struct city *pcity)
3325{
3326 if (pcity->server.vision != NULL) {
3327 v_radius_t vision_radius_sq
3328 = V_RADIUS(get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ), 2, 2);
3329
3330 vision_change_sight(pcity->server.vision, vision_radius_sq);
3331 ASSERT_VISION(pcity->server.vision);
3332 }
3333}
3334
3335/************************************************************************/
3339 void refresh_player_cities_vision(struct player *pplayer)
3340{
3341 city_list_iterate(pplayer->cities, pcity) {
3342 city_refresh_vision(pcity);
3343 } city_list_iterate_end;
3344}
3345
3346/************************************************************************/
3349 bool city_map_update_radius_sq(struct city *pcity)
3350{
3351 fc_assert_ret_val(pcity != NULL, FALSE);
3352
3353 int city_tiles_old, city_tiles_new;
3354 int city_radius_sq_old = city_map_radius_sq_get(pcity);
3355 int city_radius_sq_new = game.info.init_city_radius_sq
3356 + get_city_bonus(pcity, EFT_CITY_RADIUS_SQ);
3357 const struct civ_map *nmap = &(wld.map);
3358
3359 /* Check minimum / maximum allowed city radii */
3360 city_radius_sq_new = CLIP(CITY_MAP_MIN_RADIUS_SQ, city_radius_sq_new,
3361 CITY_MAP_MAX_RADIUS_SQ);
3362
3363 if (city_radius_sq_new == city_radius_sq_old) {
3364 /* No change */
3365 return FALSE;
3366 }
3367
3368 /* Get number of city tiles for each radii */
3369 city_tiles_old = city_map_tiles(city_radius_sq_old);
3370 city_tiles_new = city_map_tiles(city_radius_sq_new);
3371
3372 if (city_tiles_old == city_tiles_new) {
3373 /* A change of the squared city radius but no change of the number of
3374 * city tiles */
3375 return FALSE;;
3376 }
3377
3378 log_debug("[%s (%d)] city_map_radius_sq: %d => %d", city_name_get(pcity),
3379 pcity->id, city_radius_sq_old, city_radius_sq_new);
3380
3381 /* Workers map before */
3382 log_debug("[%s (%d)] city size: %d; specialists: %d (before change)",
3383 city_name_get(pcity), pcity->id, city_size_get(pcity),
3384 city_specialists(pcity));
3385 citylog_map_workers(LOG_DEBUG, pcity);
3386
3387 city_map_radius_sq_set(pcity, city_radius_sq_new);
3388
3389 if (city_tiles_old < city_tiles_new) {
3390 /* Increased number of city tiles */
3391 city_refresh_vision(pcity);
3392 } else {
3393 /* Reduced number of city tiles */
3394 int workers = 0;
3395
3396 /* Remove workers from the tiles removed rom the city map */
3397 city_map_iterate_radius_sq(city_radius_sq_new, city_radius_sq_old,
3398 city_x, city_y) {
3399 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity),
3400 city_radius_sq_old, city_x,
3401 city_y);
3402
3403 if (ptile && pcity == tile_worked(ptile)) {
3404 city_map_update_empty(pcity, ptile);
3405 workers++;
3406 }
3407 } city_map_iterate_radius_sq_end;
3408
3409 /* add workers to free city tiles */
3410 if (workers > 0) {
3411 int radius_sq = city_map_radius_sq_get(pcity);
3412
3413 city_map_iterate_without_index(radius_sq, city_x, city_y) {
3414 struct tile *ptile = city_map_to_tile(nmap, city_tile(pcity), radius_sq,
3415 city_x, city_y);
3416
3417 if (ptile && !is_free_worked(pcity, ptile)
3418 && tile_worked(ptile) != pcity
3419 && city_can_work_tile(pcity, ptile)) {
3420 city_map_update_worker(pcity, ptile);
3421 workers--;
3422 }
3423
3424 if (workers <= 0) {
3425 break;
3426 }
3427 } city_map_iterate_without_index_end;
3428 }
3429
3430 /* If there are still workers they will be updated to specialists */
3431 if (workers > 0) {
3432 pcity->specialists[DEFAULT_SPECIALIST] += workers;
3433 }
3434
3435 city_refresh_vision(pcity);
3436 }
3437
3438 /* City removal might be ongoing, and advisor data already deleted */
3439 if (pcity->server.adv != NULL) {
3440 /* If city is under AI control, update it */
3441 adv_city_update(pcity);
3442 }
3443
3444 notify_player(city_owner(pcity), city_tile(pcity), E_CITY_RADIUS_SQ,
3445 ftc_server, _("The size of the city map of %s is %s."),
3446 city_name_get(pcity),
3447 city_tiles_old < city_tiles_new ? _("increased")
3448 : _("reduced"));
3449
3450 /* Workers map after */
3451 log_debug("[%s (%d)] city size: %d; specialists: %d (after change)",
3452 city_name_get(pcity), pcity->id, city_size_get(pcity),
3453 city_specialists(pcity));
3454 citylog_map_workers(LOG_DEBUG, pcity);
3455
3456 return TRUE;
3457}
3458
3459/************************************************************************/
3462 void clear_worker_task(struct city *pcity, struct worker_task *ptask)
3463{
3464 struct packet_worker_task packet;
3465
3466 if (ptask == NULL) {
3467 return;
3468 }
3469
3470 worker_task_list_remove(pcity->task_reqs, ptask);
3471
3472 packet.city_id32 = pcity->id;
3473 packet.city_id16 = packet.city_id32;
3474 packet.tile_id = tile_index(ptask->ptile);
3475 packet.activity = ACTIVITY_LAST;
3476 packet.tgt = 0;
3477 packet.want = 0;
3478
3479 free(ptask);
3480
3481 lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
3482 lsend_packet_worker_task(game.glob_observers, &packet);
3483}
3484
3485/************************************************************************/
3488 void clear_worker_tasks(struct city *pcity)
3489{
3490 while (worker_task_list_size(pcity->task_reqs) > 0) {
3491 clear_worker_task(pcity, worker_task_list_get(pcity->task_reqs, 0));
3492 }
3493}
3494
3495/************************************************************************/
3498 void package_and_send_worker_tasks(struct city *pcity)
3499{
3500 struct packet_worker_task packet;
3501
3502 packet.city_id32 = pcity->id;
3503 packet.city_id16 = packet.city_id32;
3504
3505 worker_task_list_iterate(pcity->task_reqs, ptask) {
3506 packet.tile_id = tile_index(ptask->ptile);
3507 packet.activity = ptask->act;
3508 if (ptask->tgt == NULL) {
3509 packet.tgt = -1;
3510 } else {
3511 packet.tgt = extra_number(ptask->tgt);
3512 }
3513 packet.want = ptask->want;
3514
3515 lsend_packet_worker_task(city_owner(pcity)->connections, &packet);
3516 lsend_packet_worker_task(game.glob_observers, &packet);
3517 } worker_task_list_iterate_end;
3518}
3519
3520/************************************************************************/
3523 int city_production_buy_gold_cost(const struct city *pcity)
3524{
3525 int build = pcity->shield_stock;
3526
3527 switch (pcity->production.kind) {
3528 case VUT_IMPROVEMENT:
3529 return impr_buy_gold_cost(pcity, pcity->production.value.building,
3530 build);
3531 case VUT_UTYPE:
3532 return utype_buy_gold_cost(pcity, pcity->production.value.utype,
3533 build);
3534 default:
3535 break;
3536 };
3537
3538 return FC_INFINITY;
3539}
3540
3541/************************************************************************/
3545 int city_original_owner(const struct city *pcity,
3546 const struct player *known_for)
3547{
3548 if (pcity->original == NULL) {
3549 /* Nobody knows */
3550 return MAX_NUM_PLAYER_SLOTS;
3551 }
3552
3553 if (pcity->original != known_for
3554 || known_for == NULL) {
3555 /* Players know what they have built themselves,
3556 * global observer knows everything. */
3557 return player_number(pcity->original);
3558 }
3559
3560 return MAX_NUM_PLAYER_SLOTS;
3561}
action_auto_perf_unit_do
const struct action * action_auto_perf_unit_do(const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit, const struct extra_type *target_extra)
Definition actiontools.c:989
actiontools.h
advisor_choose_build
void advisor_choose_build(struct player *pplayer, struct city *pcity)
Definition advbuilding.c:320
advbuilding.h
adv_could_unit_move_to_tile
int adv_could_unit_move_to_tile(struct unit *punit, struct tile *dest_tile)
Definition advgoto.c:348
advgoto.h
ai.h
CALL_FUNC_EACH_AI
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
CALL_PLR_AI_FUNC
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
n
#define n
Definition astring.c:77
autosettlers.h
is_land_barbarian
bool is_land_barbarian(struct player *pplayer)
Definition barbarian.c:75
barbarian.h
base.h
dbv_init
void dbv_init(struct dbv *pdbv, int bits)
Definition bitvector.c:50
dbv_set
void dbv_set(struct dbv *pdbv, int bit)
Definition bitvector.c:144
dbv_isset
bool dbv_isset(const struct dbv *pdbv, int bit)
Definition bitvector.c:120
dbv_free
void dbv_free(struct dbv *pdbv)
Definition bitvector.c:95
bitvector.h
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ARE_EQUAL
#define BV_ARE_EQUAL(vec1, vec2)
Definition bitvector.h:113
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
BV_ISSET_ANY
#define BV_ISSET_ANY(vec)
Definition bitvector.h:109
citizens_nation_get
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
citizens_init
void citizens_init(struct city *pcity)
Definition citizens.c:32
citizens.h
citizens_convert_conquest
void citizens_convert_conquest(struct city *pcity)
Definition citizenshand.c:386
citizens_update
void citizens_update(struct city *pcity, struct player *plr)
Definition citizenshand.c:202
citizenshand.h
is_free_worked
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3488
city_map_radius_sq_set
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:142
city_production_build_shield_cost
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:721
city_name_set
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1114
city_granary_size
int city_granary_size(int city_size)
Definition city.c:2095
player_angry_citizens
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2159
can_city_build_now
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Definition city.c:984
city_map_to_tile
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:299
city_has_building
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1207
is_capital
bool is_capital(const struct city *pcity)
Definition city.c:1544
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1106
city_remove_improvement
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3272
city_can_be_built_here
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1451
get_output_type
struct output_type * get_output_type(Output_type_id output)
Definition city.c:632
player_content_citizens
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2149
city_unhappy
bool city_unhappy(const struct city *pcity)
Definition city.c:1591
create_city_virtual
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3331
city_list_find_number
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1644
city_illness_calc
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2763
city_change_production_penalty
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1851
city_happy
bool city_happy(const struct city *pcity)
Definition city.c:1579
city_add_improvement
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3258
city_map_radius_sq_get
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:131
citylog_map_workers
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:440
city_specialists
citizens city_specialists(const struct city *pcity)
Definition city.c:3218
city_choose_build_default
void city_choose_build_default(struct city *pcity)
Definition city.c:1056
city_list_find_name
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1660
city_map_tiles
int city_map_tiles(int city_radius_sq)
Definition city.c:165
city_exist
bool city_exist(int id)
Definition city.c:3459
city_can_work_tile
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1420
city_turns_to_grow
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1961
city_rally_point_clear
void city_rally_point_clear(struct city *pcity)
Definition city.c:3513
city_production_name_translation
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:694
city.h
cities_iterate_end
#define cities_iterate_end
Definition city.h:497
CNA_BROADCAST_PENDING
@ CNA_BROADCAST_PENDING
Definition city.h:300
CNA_NOT
@ CNA_NOT
Definition city.h:298
CNA_NORMAL
@ CNA_NORMAL
Definition city.h:299
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:488
city_tile
#define city_tile(_pcity_)
Definition city.h:544
cities_iterate
#define cities_iterate(pcity)
Definition city.h:492
CITY_MAP_MAX_RADIUS_SQ
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:78
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
city_tile_iterate_skip_free_worked
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:206
CITIZEN_ANGRY
@ CITIZEN_ANGRY
Definition city.h:263
CITIZEN_HAPPY
@ CITIZEN_HAPPY
Definition city.h:260
CITIZEN_CONTENT
@ CITIZEN_CONTENT
Definition city.h:261
CITIZEN_UNHAPPY
@ CITIZEN_UNHAPPY
Definition city.h:262
CITY_MAP_MIN_RADIUS_SQ
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:76
city_map_iterate_radius_sq
#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, _x, _y)
Definition city.h:180
output_type_iterate
#define output_type_iterate(output)
Definition city.h:809
city_owner
#define city_owner(_pcity_)
Definition city.h:543
city_tile_iterate_skip_free_worked_end
#define city_tile_iterate_skip_free_worked_end
Definition city.h:214
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:490
city_map_iterate_radius_sq_end
#define city_map_iterate_radius_sq_end
Definition city.h:185
FEELING_LAST
@ FEELING_LAST
Definition city.h:277
city_built_iterate
#define city_built_iterate(_pcity, _p)
Definition city.h:798
city_map_iterate_without_index_end
#define city_map_iterate_without_index_end
Definition city.h:176
city_built_iterate_end
#define city_built_iterate_end
Definition city.h:804
city_map_iterate_without_index
#define city_map_iterate_without_index(_radius_sq, _x, _y)
Definition city.h:172
output_type_iterate_end
#define output_type_iterate_end
Definition city.h:815
city_map_update_empty
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3150
city_freeze_workers_queue
void city_freeze_workers_queue(struct city *pcity)
Definition citytools.c:159
package_city
void package_city(struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct trade_route_packet_list *routes, bool dipl_invest)
Definition citytools.c:2466
city_map_update_tile_now
bool city_map_update_tile_now(struct tile *ptile)
Definition citytools.c:3215
city_name_suggestion
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Definition citytools.c:451
city_citywalls_gfx
static int city_citywalls_gfx(const struct city *pcity)
Definition citytools.c:2119
city_map_update_tile_direct
static bool city_map_update_tile_direct(struct tile *ptile, bool queued)
Definition citytools.c:3176
package_and_send_worker_tasks
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3498
city_production_buy_gold_cost
int city_production_buy_gold_cost(const struct city *pcity)
Definition citytools.c:3523
send_city_info
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2313
update_dumb_city
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2669
build_or_move_building
struct city * build_or_move_building(struct city *pcity, struct impr_type *pimprove, struct player **oldcity_owner)
Definition citytools.c:2918
raze_city
static void raze_city(struct city *pcity)
Definition citytools.c:921
city_build_free_buildings
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1410
city_workers_queue_remove
static bool city_workers_queue_remove(struct city *pcity)
Definition citytools.c:178
find_closest_city
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:849
refresh_dumb_city
void refresh_dumb_city(struct city *pcity)
Definition citytools.c:2174
package_dumb_city
static void package_dumb_city(struct player *pplayer, struct tile *ptile, struct packet_city_short_info *packet)
Definition citytools.c:2140
create_city
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Definition citytools.c:1489
send_city_suppression
bool send_city_suppression(bool now)
Definition citytools.c:2129
send_city_suppressed
static bool send_city_suppressed
Definition citytools.c:100
sync_cities
void sync_cities(void)
Definition citytools.c:3224
search_for_city_name
static const char * search_for_city_name(struct tile *ptile, const struct nation_city_list *default_cities, struct player *pplayer)
Definition citytools.c:332
announce_trade_route_removal
static void announce_trade_route_removal(struct city *pc1, struct city *pc2, bool source_gone) fc__attribute((nonnull(1
Definition citytools.c:2778
city_freeze_workers
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:135
refresh_player_cities_vision
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3339
city_original_owner
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3545
build_free_small_wonders
static void build_free_small_wonders(struct player *pplayer, bv_imprs *had_small_wonders)
Definition citytools.c:1007
city_map_update_radius_sq
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3349
build_points_left
int build_points_left(struct city *pcity)
Definition citytools.c:569
change_build_target
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3061
building_removed
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:2946
city_map_update_all_cities_for_player
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3258
city_illness_strike
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2870
city_map_update_tile_frozen
bool city_map_update_tile_frozen(struct tile *ptile)
Definition citytools.c:3207
city_thaw_workers
void city_thaw_workers(struct city *pcity)
Definition citytools.c:145
remove_dumb_city
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2759
is_default_city_name
static bool is_default_city_name(const char *name, struct player *pplayer)
Definition citytools.c:314
building_lost
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:2963
unit_conquer_city
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Definition citytools.c:1949
clear_worker_task
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Definition citytools.c:3462
reestablish_city_trade_routes
static void reestablish_city_trade_routes(struct city *pcity)
Definition citytools.c:954
city_units_upkeep
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3012
clear_worker_tasks
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3488
is_allowed_city_name
bool is_allowed_city_name(struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
Definition citytools.c:367
transfer_unit
static void transfer_unit(struct unit *punit, struct city *tocity, bool rehome, bool verbose)
Definition citytools.c:583
city_landlocked_sell_coastal_improvements
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
Definition citytools.c:3277
remove_city
void remove_city(struct city *pcity)
Definition citytools.c:1675
do_sell_building
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:2896
arrange_workers_queue
static struct city_list * arrange_workers_queue
Definition citytools.c:97
remove_trade_route
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2835
create_city_for_player
bool create_city_for_player(struct player *pplayer, struct tile *ptile, const char *name)
Definition citytools.c:1649
send_city_info_at_tile
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Definition citytools.c:2362
evaluate_city_name_priority
static int evaluate_city_name_priority(struct tile *ptile, const struct nation_city *pncity, int default_priority)
Definition citytools.c:213
city_thaw_workers_queue
void city_thaw_workers_queue(void)
Definition citytools.c:191
broadcast_city_info
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2203
transfer_city
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Definition citytools.c:1065
send_player_cities
void send_player_cities(struct player *pplayer)
Definition citytools.c:2293
city_map_update_all
void city_map_update_all(struct city *pcity)
Definition citytools.c:3243
transfer_city_units
void transfer_city_units(struct player *pplayer, struct player *pvictim, struct unit_list *units, struct city *pcity, struct city *exclude_city, int kill_outside, bool verbose)
Definition citytools.c:714
city_map_update_worker
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Definition citytools.c:3164
reality_check_city
void reality_check_city(struct player *pplayer, struct tile *ptile)
Definition citytools.c:2737
send_all_known_cities
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2270
city_refresh_vision
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3324
citytools.h
trade_route_packet_list_iterate_end
#define trade_route_packet_list_iterate_end
Definition citytools.h:28
LOG_BUILD_TARGET
#define LOG_BUILD_TARGET
Definition citytools.h:21
trade_route_packet_list_iterate
#define trade_route_packet_list_iterate(ptrlist, ptr)
Definition citytools.h:26
auto_arrange_workers
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:368
city_refresh_queue_add
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:199
nullify_prechange_production
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3372
city_reduce_size
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:807
city_refresh
bool city_refresh(struct city *pcity)
Definition cityturn.c:161
city_refresh_for_player
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:184
city_refresh_queue_processing
void city_refresh_queue_processing(void)
Definition cityturn.c:215
remove_obsolete_buildings_city
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:237
cityturn.h
announce
enum announce_type announce
Definition client_main.c:147
cm.h
conn_list_do_unbuffer
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:365
conn_by_user
struct connection * conn_by_user(const char *user_name)
Definition connection.c:376
conn_list_do_buffer
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:355
conn_is_global_observer
bool conn_is_global_observer(const struct connection *pconn)
Definition connection.c:750
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:115
city_culture
int city_culture(const struct city *pcity)
Definition culture.c:29
culture.h
homeless
static void homeless(QVariant data1, QVariant data2)
Definition dialogs.cpp:2396
punit
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
cost
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:73
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
get_unit_bonus
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:992
get_city_output_bonus
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:906
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
event
enum event_type event
Definition events.c:81
events.h
extra_number
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
is_native_tile_to_extra
bool is_native_tile_to_extra(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:608
extra_name_translation
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
extra_type_iterate
#define extra_type_iterate(_p)
Definition extras.h:291
extra_type_iterate_end
#define extra_type_iterate_end
Definition extras.h:297
extra_road_get
#define extra_road_get(_e_)
Definition extras.h:185
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:315
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
MAX_NUM_BUILDING_LIST
#define MAX_NUM_BUILDING_LIST
Definition fc_types.h:46
citizens
unsigned char citizens
Definition fc_types.h:358
Impr_type_id
int Impr_type_id
Definition fc_types.h:346
MAX_NUM_PLAYERS
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
RPT_CERTAIN
@ RPT_CERTAIN
Definition fc_types.h:586
MAX_NUM_PLAYER_SLOTS
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
O_LAST
@ O_LAST
Definition fc_types.h:91
MAX_LEN_CITYNAME
#define MAX_LEN_CITYNAME
Definition fc_types.h:67
Continent_id
signed short Continent_id
Definition fc_types.h:342
IDENTITY_NUMBER_ZERO
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
fcintl.h
PL_
#define PL_(String1, String2, n)
Definition fcintl.h:71
_
#define _(String)
Definition fcintl.h:67
fc_allocate_mutex
void fc_allocate_mutex(fc_mutex *mutex)
fc_release_mutex
void fc_release_mutex(fc_mutex *mutex)
city_tile_link
const char * city_tile_link(const struct city *pcity)
Definition featured_text.c:1089
ftc_server
const struct ft_color ftc_server
Definition featured_text.c:77
city_link
const char * city_link(const struct city *pcity)
Definition featured_text.c:1072
unit_link
const char * unit_link(const struct unit *punit)
Definition featured_text.c:1200
unit_tile_link
const char * unit_tile_link(const struct unit *punit)
Definition featured_text.c:1217
MAX_LEN_LINK
#define MAX_LEN_LINK
Definition featured_text.h:138
game
struct civ_game game
Definition game.c:57
game_city_by_name
struct city * game_city_by_name(const char *name)
Definition game.c:83
wld
struct world wld
Definition game.c:58
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:111
game_remove_city
void game_remove_city(struct world *gworld, struct city *pcity)
Definition game.c:173
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
game.h
CNM_PLAYER_UNIQUE
@ CNM_PLAYER_UNIQUE
Definition game.h:46
CNM_GLOBAL_UNIQUE
@ CNM_GLOBAL_UNIQUE
Definition game.h:47
CNM_NO_STEALING
@ CNM_NO_STEALING
Definition game.h:48
send_game_info
void send_game_info(struct conn_list *dest)
Definition gamehand.c:905
gamehand.h
government.h
owner
struct city * owner
Definition citydlg.c:219
source
static GtkWidget * source
Definition gotodlg.c:58
type
GType type
Definition repodlgs.c:1312
bufsz
static const int bufsz
Definition helpdlg.c:70
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps.h
H_PRODCHGPEN
@ H_PRODCHGPEN
Definition handicaps.h:35
idex_register_city
void idex_register_city(struct world *iworld, struct city *pcity)
Definition idex.c:66
idex.h
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:192
impr_sell_gold
int impr_sell_gold(const struct impr_type *pimprove)
Definition improvement.c:332
can_city_sell_building
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:1072
is_improvement
bool is_improvement(const struct impr_type *pimprove)
Definition improvement.c:783
is_improvement_visible
bool is_improvement_visible(const struct impr_type *pimprove)
Definition improvement.c:391
improvement_index
Impr_type_id improvement_index(const struct impr_type *pimprove)
Definition improvement.c:173
impr_buy_gold_cost
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
Definition improvement.c:304
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:767
improvement_has_flag
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Definition improvement.c:381
city_from_small_wonder
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:1049
improvement_name_translation
const char * improvement_name_translation(const struct impr_type *pimprove)
Definition improvement.c:241
city_from_great_wonder
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:989
is_small_wonder
bool is_small_wonder(const struct impr_type *pimprove)
Definition improvement.c:775
improvement.h
improvement_iterate_end
#define improvement_iterate_end
Definition improvement.h:211
improvement_iterate
#define improvement_iterate(_p)
Definition improvement.h:205
B_LAST
#define B_LAST
Definition improvement.h:42
adv_city_free
void adv_city_free(struct city *pcity)
Definition infracache.c:501
adv_city_update
void adv_city_update(struct city *pcity)
Definition infracache.c:462
adv_city_alloc
void adv_city_alloc(struct city *pcity)
Definition infracache.c:488
infracache.h
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
log_verbose
#define log_verbose(message,...)
Definition log.h:109
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_assert_ret_msg
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:205
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187
log_debug
#define log_debug(message,...)
Definition log.h:115
log_base
#define log_base(level, message,...)
Definition log.h:94
LOG_DEBUG
@ LOG_DEBUG
Definition log.h:34
log_error
#define log_error(message,...)
Definition log.h:103
fc_assert_ret_val_msg
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
luascript_types.h
map_num_tiles
int map_num_tiles(void)
Definition map.c:1012
real_map_distance
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:628
map.h
adjc_iterate_end
#define adjc_iterate_end
Definition map.h:427
adjc_iterate
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:422
whole_map_iterate
#define whole_map_iterate(_map, _tile)
Definition map.h:539
whole_map_iterate_end
#define whole_map_iterate_end
Definition map.h:548
vision_clear_sight
void vision_clear_sight(struct vision *vision)
Definition maphand.c:2499
map_claim_ownership
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2173
map_is_known
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:886
destroy_extra
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2574
send_tile_info
void send_tile_info(struct conn_list *dest, struct tile *ptile, bool send_unknown)
Definition maphand.c:488
map_get_player_city
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1343
map_show_tile
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:760
give_citymap_from_player_to_player
void give_citymap_from_player_to_player(struct city *pcity, struct player *pfrom, struct player *pdest)
Definition maphand.c:415
tile_change_side_effects
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2677
map_is_known_and_seen
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:900
change_playertile_site
void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site)
Definition maphand.c:1137
map_claim_border
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2252
update_tile_knowledge
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1424
map_get_player_site
struct vision_site * map_get_player_site(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1356
upgrade_city_extras
bool upgrade_city_extras(struct city *pcity, struct extra_type **gained)
Definition maphand.c:238
map_clear_border
void map_clear_border(struct tile *ptile)
Definition maphand.c:2203
map_get_player_tile
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1367
vision_change_sight
void vision_change_sight(struct vision *vision, const v_radius_t radius_sq)
Definition maphand.c:2487
maphand.h
mem.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
can_unit_exist_at_tile
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
is_native_tile
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:316
is_city_channel_tile
bool is_city_channel_tile(const struct civ_map *nmap, const struct unit_class *punitclass, const struct tile *ptile, const struct tile *pexclude)
Definition movement.c:228
can_unit_survive_at_tile
bool can_unit_survive_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:476
is_native_near_tile
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:450
movement.h
nation_city_name
const char * nation_city_name(const struct nation_city *pncity)
Definition nation.c:411
nation_cities
const struct nation_city_list * nation_cities(const struct nation_type *pnation)
Definition nation.c:330
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
nation_city_preference_revert
enum nation_city_preference nation_city_preference_revert(enum nation_city_preference prefer)
Definition nation.c:370
nation_count
Nation_type_id nation_count(void)
Definition nation.c:506
nation_of_unit
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:462
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
nation_city_terrain_preference
enum nation_city_preference nation_city_terrain_preference(const struct nation_city *pncity, const struct terrain *pterrain)
Definition nation.c:421
nation_of_player
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
nation_city_river_preference
enum nation_city_preference nation_city_river_preference(const struct nation_city *pncity)
Definition nation.c:433
nation_index
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:497
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
nation_list_iterate
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:83
nation_city_preference
nation_city_preference
Definition nation.h:38
NCP_NONE
@ NCP_NONE
Definition nation.h:40
NCP_DISLIKE
@ NCP_DISLIKE
Definition nation.h:39
NCP_LIKE
@ NCP_LIKE
Definition nation.h:41
nation_city_list_iterate
#define nation_city_list_iterate(citylist, pncity)
Definition nation.h:47
nation_list_iterate_end
#define nation_list_iterate_end
Definition nation.h:85
nation_city_list_iterate_end
#define nation_city_list_iterate_end
Definition nation.h:49
notify_player
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:292
notify.h
web_send_packet
#define web_send_packet(packetname,...)
Definition packets.h:52
web_lsend_packet
#define web_lsend_packet(packetname,...)
Definition packets.h:53
send_packet_city_rally_point
int send_packet_city_rally_point(struct connection *pc, const struct packet_city_rally_point *packet, bool force_to_send)
Definition packets_gen.c:31982
lsend_packet_city_nationalities
void lsend_packet_city_nationalities(struct conn_list *dest, const struct packet_city_nationalities *packet, bool force_to_send)
Definition packets_gen.c:24479
dlsend_packet_city_remove
void dlsend_packet_city_remove(struct conn_list *dest, int city_id16, int city_id32)
Definition packets_gen.c:12150
dsend_packet_city_remove
int dsend_packet_city_remove(struct connection *pc, int city_id16, int city_id32)
Definition packets_gen.c:12140
send_packet_city_info
int send_packet_city_info(struct connection *pc, const struct packet_city_info *packet, bool force_to_send)
Definition packets_gen.c:23508
lsend_packet_trade_route_info
void lsend_packet_trade_route_info(struct conn_list *dest, const struct packet_trade_route_info *packet)
Definition packets_gen.c:26251
send_packet_trade_route_info
int send_packet_trade_route_info(struct connection *pc, const struct packet_trade_route_info *packet)
Definition packets_gen.c:26239
lsend_packet_city_info
void lsend_packet_city_info(struct conn_list *dest, const struct packet_city_info *packet, bool force_to_send)
Definition packets_gen.c:23520
send_packet_city_nationalities
int send_packet_city_nationalities(struct connection *pc, const struct packet_city_nationalities *packet, bool force_to_send)
Definition packets_gen.c:24467
lsend_packet_city_short_info
void lsend_packet_city_short_info(struct conn_list *dest, const struct packet_city_short_info *packet)
Definition packets_gen.c:25598
lsend_packet_worker_task
void lsend_packet_worker_task(struct conn_list *dest, const struct packet_worker_task *packet)
Definition packets_gen.c:32565
lsend_packet_city_rally_point
void lsend_packet_city_rally_point(struct conn_list *dest, const struct packet_city_rally_point *packet, bool force_to_send)
Definition packets_gen.c:31994
player_number
int player_number(const struct player *pplayer)
Definition player.c:828
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:886
can_player_see_unit
bool can_player_see_unit(const struct player *pplayer, const struct unit *punit)
Definition player.c:1084
pplayers_at_war
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1364
player_slot_index
int player_slot_index(const struct player_slot *pslot)
Definition player.c:419
player_index
int player_index(const struct player *pplayer)
Definition player.c:820
player_can_see_city_externals
bool player_can_see_city_externals(const struct player *pow_player, const struct city *target_city)
Definition player.c:1143
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
can_player_see_units_in_city
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1113
player_slot_get_player
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:430
can_player_see_city_internals
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1129
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:535
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
player_slots_iterate
#define player_slots_iterate(_pslot)
Definition player.h:521
is_ai
#define is_ai(plr)
Definition player.h:234
player_slots_iterate_end
#define player_slots_iterate_end
Definition player.h:525
normal_player_count
int normal_player_count(void)
Definition plrhand.c:3034
civil_war_triggered
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2785
maybe_make_contact
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2191
send_player_info_c
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
civil_war
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:2835
civil_war_possible
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2738
update_capital
void update_capital(struct player *pplayer)
Definition plrhand.c:612
plrhand.h
allowed_nations_iterate
#define allowed_nations_iterate(pnation)
Definition plrhand.h:67
allowed_nations_iterate_end
#define allowed_nations_iterate_end
Definition plrhand.h:71
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:34
is_req_active
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
Definition requirements.c:4268
are_universals_equal
bool are_universals_equal(const struct universal *psource1, const struct universal *psource2)
Definition requirements.c:5278
universal_number
int universal_number(const struct universal *source)
Definition requirements.c:790
requirements.h
requirement_vector_iterate_end
#define requirement_vector_iterate_end
Definition requirements.h:93
requirement_vector_iterate
#define requirement_vector_iterate(req_vec, preq)
Definition requirements.h:91
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
research.h
road_has_flag
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
road.h
sanitycheck.h
sanity_check_city
#define sanity_check_city(x)
Definition sanitycheck.h:41
script_server_signal_emit
void script_server_signal_emit(const char *signal_name,...)
Definition script_server.c:408
script_server_remove_exported_object
void script_server_remove_exported_object(void *object)
Definition script_server.c:207
script_server.h
connections
static struct connection connections[MAX_NUM_CONNECTIONS]
Definition sernet.c:94
flush_packets
void flush_packets(void)
Definition sernet.c:379
sernet.h
settings
static struct setting settings[]
Definition settings.c:1378
is_ascii_name
bool is_ascii_name(const char *name)
Definition shared.c:282
shared.h
CLIP
#define CLIP(lower, current, upper)
Definition shared.h:57
MIN
#define MIN(x, y)
Definition shared.h:55
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
spaceship_lost
void spaceship_lost(struct player *pplayer)
Definition spacerace.c:430
spacerace.h
SSHIP_STARTED
@ SSHIP_STARTED
Definition spaceship.h:84
SSHIP_LAUNCHED
@ SSHIP_LAUNCHED
Definition spaceship.h:85
specialist_count
Specialist_type_id specialist_count(void)
Definition specialist.c:71
specialist.h
specialist_type_iterate_end
#define specialist_type_iterate_end
Definition specialist.h:79
specialist_type_iterate
#define specialist_type_iterate(sp)
Definition specialist.h:73
DEFAULT_SPECIALIST
#define DEFAULT_SPECIALIST
Definition specialist.h:43
priority
SPECPQ_PRIORITY_TYPE priority
Definition specpq.h:86
size
size_t size
Definition specvec.h:72
recursion
static int recursion[AIT_LAST]
Definition srv_log.c:44
identity_number
int identity_number(void)
Definition srv_main.c:1952
server_state
enum server_states server_state(void)
Definition srv_main.c:323
srv_main.h
built_status::turn
int turn
Definition city.h:238
city
Definition city.h:309
city::task_reqs
struct worker_task_list * task_reqs
Definition city.h:395
city::turn_last_built
int turn_last_built
Definition city.h:373
city::surplus
int surplus[O_LAST]
Definition city.h:343
city::food_stock
int food_stock
Definition city.h:354
city::built
struct built_status built[B_LAST]
Definition city.h:380
city::original
struct player * original
Definition city.h:313
city::history
int history
Definition city.h:393
city::pollution
int pollution
Definition city.h:356
city::did_sell
bool did_sell
Definition city.h:367
city::id
int id
Definition city.h:315
city::last_turns_shield_surplus
int last_turns_shield_surplus
Definition city.h:378
city::capital
enum capital_type capital
Definition city.h:317
city::disbanded_shields
int disbanded_shields
Definition city.h:377
city::waste
int waste[O_LAST]
Definition city.h:344
city::workers_frozen
int workers_frozen
Definition city.h:420
city::turn_plague
int turn_plague
Definition city.h:361
city::city_options
bv_city_options city_options
Definition city.h:389
city::city_radius_sq
int city_radius_sq
Definition city.h:362
city::was_happy
bool was_happy
Definition city.h:368
city::owner
struct player * owner
Definition city.h:312
city::turn_founded
int turn_founded
Definition city.h:372
city::airlift
int airlift
Definition city.h:365
city::citizen_base
int citizen_base[O_LAST]
Definition city.h:347
city::caravan_shields
int caravan_shields
Definition city.h:376
city::did_buy
bool did_buy
Definition city.h:366
city::routes
struct trade_route_list * routes
Definition city.h:332
city::needs_arrange
enum city_needs_arrange needs_arrange
Definition city.h:424
city::usage
int usage[O_LAST]
Definition city.h:348
city::worklist
struct worklist worklist
Definition city.h:387
city::production
struct universal production
Definition city.h:382
city::orders
struct unit_order * orders
Definition city.h:405
city::rally_point
struct city::@16 rally_point
city::adv
struct adv_city * adv
Definition city.h:435
city::nationality
citizens * nationality
Definition city.h:329
city::vigilant
bool vigilant
Definition city.h:404
city::steal
int steal
Definition city.h:397
city::unhappy_penalty
int unhappy_penalty[O_LAST]
Definition city.h:345
city::illness
int illness
Definition city.h:417
city::before_change_shields
int before_change_shields
Definition city.h:375
city::style
int style
Definition city.h:316
city::length
size_t length
Definition city.h:400
city::synced
bool synced
Definition city.h:431
city::feel
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:321
city::specialists
citizens specialists[SP_MAX]
Definition city.h:324
city::tile
struct tile * tile
Definition city.h:311
city::shield_stock
int shield_stock
Definition city.h:355
city::prod
int prod[O_LAST]
Definition city.h:346
city::vision
struct vision * vision
Definition city.h:438
city::server
struct city::@17::@19 server
city::cm_parameter
struct cm_parameter * cm_parameter
Definition city.h:408
city::changed_from
struct universal changed_from
Definition city.h:385
city::units_supported
struct unit_list * units_supported
Definition city.h:391
city::illness_trade
int illness_trade
Definition city.h:357
city::persistent
bool persistent
Definition city.h:402
civ_game::allowed_city_names
enum city_names_mode allowed_city_names
Definition game.h:126
civ_game::rgame
struct civ_game::@29 rgame
civ_game::server
struct civ_game::@30::@34 server
civ_game::vision_reveal_tiles
bool vision_reveal_tiles
Definition game.h:199
civ_game::glob_observers
struct conn_list * glob_observers
Definition game.h:98
civ_game::city_list
fc_mutex city_list
Definition game.h:267
civ_game::est_connections
struct conn_list * est_connections
Definition game.h:97
civ_game::info
struct packet_game_info info
Definition game.h:89
civ_game::natural_city_names
bool natural_city_names
Definition game.h:166
civ_game::global_init_buildings
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:108
civ_game::mutexes
struct civ_game::@30::@34::@38 mutexes
civ_game::savepalace
bool savepalace
Definition game.h:186
civ_game::razechance
int razechance
Definition game.h:175
civ_map
Definition map_types.h:71
connection
Definition connection.h:141
connection::access_level
enum cmdlevel access_level
Definition connection.h:182
dbv
Definition bitvector.h:32
extra_type
Definition extras.h:85
impr_type
Definition improvement.h:68
nation_city
Definition nation.c:320
nation_type
Definition nation.h:97
nation_type::init_buildings
int init_buildings[MAX_NUM_BUILDING_LIST]
Definition nation.h:122
nation_type::parent_nations
struct nation_list * parent_nations
Definition nation.h:135
nation_type::server
struct nation_type::@50::@52 server
nation_type::civilwar_nations
struct nation_list * civilwar_nations
Definition nation.h:134
packet_city_info
Definition packets_gen.h:326
packet_city_info::style
int style
Definition packets_gen.h:334
packet_city_info::last_turns_shield_surplus
int last_turns_shield_surplus
Definition packets_gen.h:365
packet_city_info::usage
int usage[O_LAST]
Definition packets_gen.h:350
packet_city_info::before_change_shields
int before_change_shields
Definition packets_gen.h:362
packet_city_info::ppl_content
int ppl_content[FEELING_LAST]
Definition packets_gen.h:337
packet_city_info::city_options
bv_city_options city_options
Definition packets_gen.h:376
packet_city_info::id32
int id32
Definition packets_gen.h:328
packet_city_info::capital
enum capital_type capital
Definition packets_gen.h:335
packet_city_info::surplus
int surplus[O_LAST]
Definition packets_gen.h:345
packet_city_info::ppl_unhappy
int ppl_unhappy[FEELING_LAST]
Definition packets_gen.h:338
packet_city_info::original
int original
Definition packets_gen.h:331
packet_city_info::citizen_base
int citizen_base[O_LAST]
Definition packets_gen.h:349
packet_city_info::changed_from_kind
int changed_from_kind
Definition packets_gen.h:360
packet_city_info::specialists
int specialists[SP_MAX]
Definition packets_gen.h:341
packet_city_info::changed_from_value
int changed_from_value
Definition packets_gen.h:361
packet_city_info::ppl_angry
int ppl_angry[FEELING_LAST]
Definition packets_gen.h:339
packet_city_info::food_stock
int food_stock
Definition packets_gen.h:351
packet_city_info::specialists_size
int specialists_size
Definition packets_gen.h:340
packet_city_info::owner
int owner
Definition packets_gen.h:330
packet_city_info::walls
int walls
Definition packets_gen.h:371
packet_city_info::improvements
bv_imprs improvements
Definition packets_gen.h:375
packet_city_info::shield_stock
int shield_stock
Definition packets_gen.h:352
packet_city_info::was_happy
bool was_happy
Definition packets_gen.h:369
packet_city_info::worklist
struct worklist worklist
Definition packets_gen.h:374
packet_city_info::steal
int steal
Definition packets_gen.h:373
packet_city_info::airlift
int airlift
Definition packets_gen.h:366
packet_city_info::did_buy
bool did_buy
Definition packets_gen.h:367
packet_city_info::turn_founded
int turn_founded
Definition packets_gen.h:358
packet_city_info::buy_cost
int buy_cost
Definition packets_gen.h:344
packet_city_info::name
char name[MAX_LEN_CITYNAME]
Definition packets_gen.h:377
packet_city_info::pollution
int pollution
Definition packets_gen.h:354
packet_city_info::trade_route_count
int trade_route_count
Definition packets_gen.h:353
packet_city_info::ppl_happy
int ppl_happy[FEELING_LAST]
Definition packets_gen.h:336
packet_city_info::did_sell
bool did_sell
Definition packets_gen.h:368
packet_city_info::production_value
int production_value
Definition packets_gen.h:357
packet_city_info::prod
int prod[O_LAST]
Definition packets_gen.h:348
packet_city_info::caravan_shields
int caravan_shields
Definition packets_gen.h:364
packet_city_info::illness_trade
int illness_trade
Definition packets_gen.h:355
packet_city_info::culture
int culture
Definition packets_gen.h:343
packet_city_info::diplomat_investigate
bool diplomat_investigate
Definition packets_gen.h:370
packet_city_info::unhappy_penalty
int unhappy_penalty[O_LAST]
Definition packets_gen.h:347
packet_city_info::history
int history
Definition packets_gen.h:342
packet_city_info::turn_last_built
int turn_last_built
Definition packets_gen.h:359
packet_city_info::city_image
int city_image
Definition packets_gen.h:372
packet_city_info::disbanded_shields
int disbanded_shields
Definition packets_gen.h:363
packet_city_info::id16
int id16
Definition packets_gen.h:327
packet_city_info::production_kind
int production_kind
Definition packets_gen.h:356
packet_city_info::tile
int tile
Definition packets_gen.h:329
packet_city_info::size
int size
Definition packets_gen.h:332
packet_city_info::city_radius_sq
int city_radius_sq
Definition packets_gen.h:333
packet_city_info::waste
int waste[O_LAST]
Definition packets_gen.h:346
packet_city_nationalities
Definition packets_gen.h:380
packet_city_nationalities::nation_id
int nation_id[MAX_CITY_NATIONALITIES]
Definition packets_gen.h:384
packet_city_nationalities::id16
int id16
Definition packets_gen.h:381
packet_city_nationalities::id32
int id32
Definition packets_gen.h:382
packet_city_nationalities::nation_citizens
int nation_citizens[MAX_CITY_NATIONALITIES]
Definition packets_gen.h:385
packet_city_nationalities::nationalities_count
int nationalities_count
Definition packets_gen.h:383
packet_city_rally_point
Definition packets_gen.h:497
packet_city_rally_point::city_id32
int city_id32
Definition packets_gen.h:499
packet_city_rally_point::persistent
bool persistent
Definition packets_gen.h:501
packet_city_rally_point::orders
struct unit_order orders[MAX_LEN_ROUTE]
Definition packets_gen.h:503
packet_city_rally_point::city_id16
int city_id16
Definition packets_gen.h:498
packet_city_rally_point::vigilant
bool vigilant
Definition packets_gen.h:502
packet_city_rally_point::length
int length
Definition packets_gen.h:500
packet_city_short_info
Definition packets_gen.h:388
packet_city_short_info::walls
int walls
Definition packets_gen.h:397
packet_city_short_info::style
int style
Definition packets_gen.h:394
packet_city_short_info::size
int size
Definition packets_gen.h:393
packet_city_short_info::improvements
bv_imprs improvements
Definition packets_gen.h:401
packet_city_short_info::capital
enum capital_type capital
Definition packets_gen.h:395
packet_city_short_info::owner
int owner
Definition packets_gen.h:392
packet_city_short_info::city_image
int city_image
Definition packets_gen.h:400
packet_city_short_info::happy
bool happy
Definition packets_gen.h:398
packet_city_short_info::unhappy
bool unhappy
Definition packets_gen.h:399
packet_city_short_info::tile
int tile
Definition packets_gen.h:391
packet_city_short_info::occupied
bool occupied
Definition packets_gen.h:396
packet_city_short_info::name
char name[MAX_LEN_CITYNAME]
Definition packets_gen.h:402
packet_city_short_info::id32
int id32
Definition packets_gen.h:390
packet_city_short_info::id16
int id16
Definition packets_gen.h:389
packet_game_info::team_pooled_research
bool team_pooled_research
Definition packets_gen.h:224
packet_game_info::citizen_nationality
bool citizen_nationality
Definition packets_gen.h:143
packet_game_info::init_city_radius_sq
int init_city_radius_sq
Definition packets_gen.h:184
packet_game_info::turn
int turn
Definition packets_gen.h:241
packet_trade_route_info
Definition packets_gen.h:405
packet_trade_route_info::city16
int city16
Definition packets_gen.h:406
packet_trade_route_info::value
int value
Definition packets_gen.h:411
packet_trade_route_info::partner16
int partner16
Definition packets_gen.h:409
packet_trade_route_info::city32
int city32
Definition packets_gen.h:407
packet_trade_route_info::partner32
int partner32
Definition packets_gen.h:410
packet_trade_route_info::goods
Goods_type_id goods
Definition packets_gen.h:413
packet_trade_route_info::direction
enum route_direction direction
Definition packets_gen.h:412
packet_trade_route_info::index
int index
Definition packets_gen.h:408
packet_web_city_info_addition
Definition packets_gen.h:1866
packet_web_city_info_addition::id32
int id32
Definition packets_gen.h:1868
packet_web_city_info_addition::id16
int id16
Definition packets_gen.h:1867
packet_web_city_info_addition::granary_size
int granary_size
Definition packets_gen.h:1869
packet_web_city_info_addition::granary_turns
int granary_turns
Definition packets_gen.h:1870
packet_worker_task
Definition packets_gen.h:506
packet_worker_task::tile_id
int tile_id
Definition packets_gen.h:509
packet_worker_task::city_id16
int city_id16
Definition packets_gen.h:507
packet_worker_task::city_id32
int city_id32
Definition packets_gen.h:508
packet_worker_task::activity
enum unit_activity activity
Definition packets_gen.h:510
packet_worker_task::want
int want
Definition packets_gen.h:512
packet_worker_task::tgt
int tgt
Definition packets_gen.h:511
player_economic::gold
int gold
Definition player.h:70
player_spaceship::state
enum spaceship_state state
Definition spaceship.h:108
player_tile
Definition maphand.h:30
player_tile::site
struct vision_site * site
Definition maphand.h:31
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::primary_capital_id
int primary_capital_id
Definition player.h:275
player::got_first_city
bool got_first_city
Definition player.h:320
player::username
char username[MAX_LEN_NAME]
Definition player.h:252
player::team
struct team * team
Definition player.h:261
player::connections
struct conn_list * connections
Definition player.h:298
player::is_alive
bool is_alive
Definition player.h:268
player::economic
struct player_economic economic
Definition player.h:284
player::spaceship
struct player_spaceship spaceship
Definition player.h:286
player::server
struct player::@69::@71 server
req_context
Definition requirements.h:99
req_context::player
const struct player * player
Definition requirements.h:100
tile
Definition tile.h:49
tile::units
struct unit_list * units
Definition tile.h:57
trade_route_settings
Definition traderoutes.h:75
trade_route
Definition traderoutes.h:83
trade_route::partner
int partner
Definition traderoutes.h:84
unit_class
Definition unittype.h:136
unit_order
Definition unit.h:92
unit_type
Definition unittype.h:481
unit
Definition unit.h:138
unit::upkeep
int upkeep[O_LAST]
Definition unit.h:148
unit::id
int id
Definition unit.h:145
unit::moved
bool moved
Definition unit.h:173
unit::server
struct unit::@80::@83 server
unit::homecity
int homecity
Definition unit.h:146
unit::transporter
struct unit * transporter
Definition unit.h:183
unit::utype
const struct unit_type * utype
Definition unit.h:139
unit::dying
bool dying
Definition unit.h:248
universal
Definition fc_types.h:756
universal::kind
enum universals_n kind
Definition fc_types.h:758
universal::value
universals_u value
Definition fc_types.h:757
vision_site
Definition vision.h:109
vision_site::name
char * name
Definition vision.h:110
vision_site::happy
bool happy
Definition vision.h:119
vision_site::improvements
bv_imprs improvements
Definition vision.h:125
vision_site::location
struct tile * location
Definition vision.h:111
vision_site::identity
int identity
Definition vision.h:114
vision_site::walls
int walls
Definition vision.h:118
vision_site::style
int style
Definition vision.h:121
vision_site::unhappy
bool unhappy
Definition vision.h:120
vision_site::city_image
int city_image
Definition vision.h:122
vision_site::occupied
bool occupied
Definition vision.h:117
vision_site::capital
enum capital_type capital
Definition vision.h:123
vision
Definition vision.h:85
vision::radius_sq
v_radius_t radius_sq
Definition vision.h:92
worker_task
Definition workertask.h:21
worker_task::ptile
struct tile * ptile
Definition workertask.h:22
world::map
struct civ_map map
Definition world_object.h:38
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
fc__attribute
#define fc__attribute(x)
Definition support.h:89
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
team_members
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
tech.h
A_UNSET
#define A_UNSET
Definition tech.h:48
steal_a_tech
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1207
send_research_info
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
techtools.h
is_terrain_class_near_tile
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:600
terrain_name_translation
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
is_terrain_near_tile
bool is_terrain_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct terrain *pterrain, bool check_self)
Definition terrain.c:336
terrain_type_iterate
#define terrain_type_iterate(_p)
Definition terrain.h:358
terrain_type_iterate_end
#define terrain_type_iterate_end
Definition terrain.h:364
tile_set_owner
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
tile_extra_rm_apply
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_set_worked
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
tile_claimer
#define tile_claimer(_tile)
Definition tile.h:99
tile_index
#define tile_index(_pt_)
Definition tile.h:87
tile_worked
#define tile_worked(_tile)
Definition tile.h:113
tile_terrain
#define tile_terrain(_tile)
Definition tile.h:109
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:42
tile_continent
#define tile_continent(_tile)
Definition tile.h:91
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
tile_owner
#define tile_owner(_tile)
Definition tile.h:95
can_cities_trade
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:214
cities_trade_route_type
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
goods_number
Goods_type_id goods_number(const struct goods_type *pgood)
Definition traderoutes.c:579
trade_route_settings_by_type
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
Definition traderoutes.c:201
can_establish_trade_route
bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
Definition traderoutes.c:275
traderoutes.h
trade_routes_iterate_safe_end
#define trade_routes_iterate_safe_end
Definition traderoutes.h:155
TRI_CANCEL
@ TRI_CANCEL
Definition traderoutes.h:32
trade_routes_iterate_end
#define trade_routes_iterate_end
Definition traderoutes.h:133
trade_routes_iterate_safe
#define trade_routes_iterate_safe(c, proute)
Definition traderoutes.h:137
trade_routes_iterate
#define trade_routes_iterate(c, proute)
Definition traderoutes.h:129
trade_route_type
trade_route_type
Definition traderoutes.h:37
universals_u::utype
const struct unit_type * utype
Definition fc_types.h:604
universals_u::building
const struct impr_type * building
Definition fc_types.h:598
transporter_for_unit_at
struct unit * transporter_for_unit_at(const struct unit *pcargo, const struct tile *ptile)
Definition unit.c:1902
can_unit_continue_current_activity
bool can_unit_continue_current_activity(const struct civ_map *nmap, struct unit *punit)
Definition unit.c:842
unit.h
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
is_enemy_unit_tile
static bool is_enemy_unit_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.h:411
unit_owner
#define unit_owner(_pu)
Definition unit.h:387
unit_activity_handling
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Definition unithand.c:6176
unit_change_homecity_handling
void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool rehome)
Definition unithand.c:3853
unithand.h
unitlist.h
unit_list_iterate
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
unit_list_iterate_safe
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
unit_list_iterate_end
#define unit_list_iterate_end
Definition unitlist.h:33
unit_list_iterate_safe_end
#define unit_list_iterate_safe_end
Definition unitlist.h:61
resolve_unit_stacks
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1418
unit_goes_out_of_sight
void unit_goes_out_of_sight(struct player *pplayer, struct unit *punit)
Definition unittools.c:2784
send_unit_info
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2797
unit_activities_cancel
void unit_activities_cancel(struct unit *punit)
Definition unittools.c:792
wipe_unit
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2251
unit_list_refresh_vision
void unit_list_refresh_vision(struct unit_list *punitlist)
Definition unittools.c:4867
bounce_unit
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1245
unittools.h
utype_buy_gold_cost
int utype_buy_gold_cost(const struct city *pcity, const struct unit_type *punittype, int shields_in_stock)
Definition unittype.c:1544
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_upkeep_cost
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1639
utype_player_already_has_this_unique
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1979
unit_can_take_over
bool unit_can_take_over(const struct unit *punit)
Definition unittype.c:258
utype_can_do_action
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
uclass_has_flag
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753
utype_class
#define utype_class(_t_)
Definition unittype.h:736
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604
vision_site_update_from_city
void vision_site_update_from_city(struct vision_site *psite, const struct city *pcity)
Definition vision.c:115
vision_site_size_get
citizens vision_site_size_get(const struct vision_site *psite)
Definition vision.c:155
vision_new
struct vision * vision_new(struct player *pplayer, struct tile *ptile)
Definition vision.c:33
vision_reveal_tiles
bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles)
Definition vision.c:62
vision_free
void vision_free(struct vision *vision)
Definition vision.c:50
vision_site_new_from_city
struct vision_site * vision_site_new_from_city(const struct city *pcity)
Definition vision.c:101
vision_site_destroy
void vision_site_destroy(struct vision_site *psite)
Definition vision.c:74
vision.h
ASSERT_VISION
#define ASSERT_VISION(v)
Definition vision.h:98
V_RADIUS
#define V_RADIUS(main_sq, invis_sq, subs_sq)
Definition vision.h:96
vision_site_owner
#define vision_site_owner(v)
Definition vision.h:128
v_radius_t
short int v_radius_t[V_COUNT]
Definition vision.h:83
worker_task_list_iterate
#define worker_task_list_iterate(tasklist, ptask)
Definition workertask.h:33
worker_task_list_iterate_end
#define worker_task_list_iterate_end
Definition workertask.h:35
worklist_copy
void worklist_copy(struct worklist *dst, const struct worklist *src)
Definition worklist.c:112