Freeciv-3.4
Loading...
Searching...
No Matches
cityturn.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#include <math.h> /* exp, sqrt */
22
23/* dependencies/lua */
24#include "lua.h" /* lua_Integer */
25
26/* utility */
27#include "fcintl.h"
28#include "log.h"
29#include "mem.h"
30#include "rand.h"
31#include "shared.h"
32#include "support.h"
33
34/* common/aicore */
35#include "cm.h"
36
37/* common */
38#include "achievements.h"
39#include "actiontools.h"
40#include "borders.h"
41#include "calendar.h"
42#include "citizens.h"
43#include "city.h"
44#include "counters.h"
45#include "culture.h"
46#include "events.h"
47#include "disaster.h"
48#include "game.h"
49#include "government.h"
50#include "map.h"
51#include "player.h"
52#include "research.h"
53#include "road.h"
54#include "server_settings.h"
55#include "specialist.h"
56#include "tech.h"
57#include "tiledef.h"
58#include "traderoutes.h"
59#include "unit.h"
60#include "unitlist.h"
61
62/* common/scriptcore */
63#include "luascript_types.h"
64
65/* server */
66#include "citizenshand.h"
67#include "citytools.h"
68#include "cityturn.h"
69#include "maphand.h"
70#include "notify.h"
71#include "plrhand.h"
72#include "sanitycheck.h"
73#include "spacerace.h"
74#include "srv_log.h"
75#include "srv_main.h"
76#include "techtools.h"
77#include "unittools.h"
78#include "unithand.h"
79
80/* server/advisors */
81#include "advbuilding.h"
82#include "advdata.h"
83
84/* server/scripting */
85#include "script_server.h"
86
87/* Queue for pending city_refresh() */
88static struct city_list *city_refresh_queue = nullptr;
89
90/* The game is currently considering to remove the listed units because of
91 * missing gold upkeep. A unit ends up here if it has gold upkeep that
92 * can't be paid. A random unit in the list will be removed until the
93 * problem is solved. */
94static struct unit_list *uk_rem_gold = nullptr;
95
96static void check_pollution(struct city *pcity);
97static void city_populate(struct city *pcity, struct player *nationality);
98
99static bool worklist_change_build_target(struct player *pplayer,
100 struct city *pcity);
101
102static bool city_distribute_surplus_shields(struct player *pplayer,
103 struct city *pcity);
104static bool city_build_building(struct player *pplayer, struct city *pcity);
105static bool city_build_unit(struct player *pplayer, struct city *pcity);
106static bool city_build_stuff(struct player *pplayer, struct city *pcity);
107static struct unit *city_create_unit(struct city *pcity,
108 const struct unit_type *utype,
109 struct citizens_reduction *red)
110 fc__attribute((nonnull (1, 2)));
111static const struct impr_type *building_upgrades_to(struct city *pcity,
112 const struct impr_type *pimprove);
113static void upgrade_building_prod(struct city *pcity);
114static const struct unit_type *unit_upgrades_to(struct city *pcity,
115 const struct unit_type *id);
116static void upgrade_unit_prod(struct city *pcity);
117
118/* Helper struct for associating a building to a city. */
119struct cityimpr {
120 struct city *pcity;
122};
123
124#define SPECLIST_TAG cityimpr
125#define SPECLIST_TYPE struct cityimpr
126#include "speclist.h"
127
128#define cityimpr_list_iterate(cityimprlist, pcityimpr) \
129 TYPED_LIST_ITERATE(struct cityimpr, cityimprlist, pcityimpr)
130#define cityimpr_list_iterate_end LIST_ITERATE_END
131
132static bool sell_random_building(struct player *pplayer,
133 struct cityimpr_list *imprs);
134static struct unit *sell_random_unit(struct player *pplayer,
135 struct unit_list *punitlist);
136
137static citizens city_reduce_specialists(struct city *pcity, citizens change);
138static citizens city_reduce_workers(struct city *pcity, citizens change);
139
140static bool city_balance_treasury_buildings(struct city *pcity);
141static bool city_balance_treasury_units(struct city *pcity);
142
143static bool disband_city(struct city *pcity);
144
145static void define_orig_production_values(struct city *pcity);
146static void update_city_activity(struct city *pcity);
147static void nullify_caravan_and_disband_plus(struct city *pcity);
148static bool city_illness_check(const struct city * pcity);
149
150static float city_migration_score(struct city *pcity);
151static bool do_city_migration(struct city *pcity_from,
152 struct city *pcity_to);
153static bool check_city_migrations_player(const struct player *pplayer);
154
155/**********************************************************************/
160{
161 bool retval;
162 const struct civ_map *nmap = &(wld.map);
163
164 pcity->server.needs_refresh = FALSE;
165
167 city_units_upkeep(pcity); /* Update unit upkeep */
170
171 if (retval) {
172 /* Force a sync of the city after the change. */
174 }
175
176 return retval;
177}
178
179/**********************************************************************/
183void city_refresh_for_player(struct player *pplayer)
184{
186 city_list_iterate(pplayer->cities, pcity) {
187 if (city_refresh(pcity)) {
189 }
190 send_city_info(pplayer, pcity);
193}
194
195/**********************************************************************/
199{
200 if (city_refresh_queue == nullptr) {
203 return;
204 }
205
207 pcity->server.needs_refresh = TRUE;
208}
209
210/**********************************************************************/
215{
216 if (city_refresh_queue == nullptr) {
217 return;
218 }
219
221 if (pcity->server.needs_refresh) {
222 if (city_refresh(pcity)) {
224 }
226 }
228
230 city_refresh_queue = nullptr;
231}
232
233/**********************************************************************/
236void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
237{
238 struct player *pplayer = city_owner(pcity);
239 bool sold = FALSE;
240
241 city_built_iterate(pcity, pimprove) {
242 if (improvement_obsolete(pplayer, pimprove, pcity)
243 && can_city_sell_building(pcity, pimprove)) {
244 int sgold;
245
246 do_sell_building(pplayer, pcity, pimprove, "obsolete");
247 sgold = impr_sell_gold(pimprove);
249 PL_("%s is selling %s (obsolete) for %d.",
250 "%s is selling %s (obsolete) for %d.",
251 sgold),
254 sgold);
255 sold = TRUE;
256 }
258
259 if (sold && refresh) {
260 if (city_refresh(pcity)) {
262 }
263 send_city_info(pplayer, pcity);
264 send_player_info_c(pplayer, nullptr); /* Send updated gold to all */
265 }
266}
267
268/**********************************************************************/
277
278/**********************************************************************/
283 const struct cm_result *cmr)
284{
285 struct tile *pcenter = city_tile(pcity);
286 const struct civ_map *nmap = &(wld.map);
287
288 /* Now apply results */
290 ptile, idx, x, y) {
291 struct city *pwork = tile_worked(ptile);
292
293 if (cmr->worker_positions[idx]) {
294 if (pwork == nullptr) {
296 } else {
298 }
299 } else {
300 if (pwork == pcity) {
302 }
303 }
305
307 pcity->specialists[sp] = cmr->specialists[sp];
309}
310
311/**********************************************************************/
315 struct city *pcity)
316{
319
320 cmp->require_happy = FALSE;
321 cmp->allow_disorder = FALSE;
322 cmp->allow_specialists = TRUE;
323
324 /* We used to look at pplayer->ai.xxx_priority to determine the values
325 * to be used here. However that doesn't work at all because those values
326 * are on a different scale. Later the AI may wish to adjust its
327 * priorities - this should be done via a separate set of variables. */
328 if (csize > 1) {
329 if (csize <= game.info.notradesize) {
330 cmp->factor[O_FOOD] = 15;
331 } else {
332 if (gsize == pcity->food_stock) {
333 /* We don't need more food if the granary is full. */
334 cmp->factor[O_FOOD] = 0;
335 } else {
336 cmp->factor[O_FOOD] = 10;
337 }
338 }
339 } else {
340 /* Growing to size 2 is the highest priority. */
341 cmp->factor[O_FOOD] = 20;
342 }
343
344 cmp->factor[O_SHIELD] = 5;
345 cmp->factor[O_TRADE] = 0; /* Trade only provides gold/science. */
346 cmp->factor[O_GOLD] = 2;
347 cmp->factor[O_LUXURY] = 0; /* Luxury only influences happiness. */
348 cmp->factor[O_SCIENCE] = 2;
349 cmp->happy_factor = 0;
350
351 if (gsize == pcity->food_stock) {
352 cmp->minimal_surplus[O_FOOD] = 0;
353 } else {
354 cmp->minimal_surplus[O_FOOD] = 1;
355 }
356
357 cmp->minimal_surplus[O_SHIELD] = 1;
358 cmp->minimal_surplus[O_TRADE] = 0;
359 cmp->minimal_surplus[O_GOLD] = -FC_INFINITY;
360 cmp->minimal_surplus[O_LUXURY] = 0;
361 cmp->minimal_surplus[O_SCIENCE] = 0;
362}
363
364/**********************************************************************/
368{
369 struct cm_parameter cmp;
370 struct cm_parameter *pcmp;
371 struct cm_result *cmr;
372 bool broadcast_needed;
373
374 /* See comment in freeze_workers(): we can't rearrange while
375 * workers are frozen (i.e. multiple updates need to be done). */
376 if (pcity->server.workers_frozen > 0) {
377 if (pcity->server.needs_arrange == CNA_NOT) {
378 pcity->server.needs_arrange = CNA_NORMAL;
379 }
380 return;
381 }
383
385
386 /* Freeze the workers and make sure all the tiles around the city
387 * are up to date. Then thaw, but hackishly make sure that thaw
388 * doesn't call us recursively, which would waste time. */
390 pcity->server.needs_arrange = CNA_NOT;
391
393
394 pcity->server.needs_arrange = CNA_NOT;
396
397 /* Now start actually rearranging. */
399
402
403 if (pcity->cm_parameter) {
404 pcmp = pcity->cm_parameter;
405 } else {
406 pcmp = &cmp;
409 }
410
411 /* This must be after city_refresh() so that the result gets created for the right
412 * city radius */
415
416 if (!cmr->found_a_valid) {
417 if (pcity->cm_parameter) {
418 /* If player-defined parameters fail, cancel and notify player. */
419 free(pcity->cm_parameter);
420 pcity->cm_parameter = nullptr;
421
424 _("The citizen governor can't fulfill the requirements "
425 "for %s. Passing back control."),
427
428 /* Switch to default parameters, and try with them */
429 pcmp = &cmp;
433 }
434
435 if (!cmr->found_a_valid) {
436 /* Drop surpluses and try again. */
438 cmp.minimal_surplus[o] = 0;
440 cmp.minimal_surplus[O_GOLD] = -FC_INFINITY;
442 }
443 }
444 if (!cmr->found_a_valid) {
445 /* Emergency management. Get _some_ result. This doesn't use
446 * cm_init_emergency_parameter() so we can keep the factors from
447 * above. */
449 cmp.minimal_surplus[o] = MIN(cmp.minimal_surplus[o],
450 MIN(pcity->surplus[o], 0));
452 cmp.require_happy = FALSE;
453 cmp.allow_disorder = is_ai(city_owner(pcity)) ? FALSE : TRUE;
455 }
456 if (!cmr->found_a_valid) {
457 CITY_LOG(LOG_DEBUG, pcity, "emergency management");
458 pcmp = &cmp;
461 }
462 fc_assert_ret(cmr->found_a_valid);
463
465
466 if (pcity->server.debug) {
467 /* Print debug output if requested. */
470 }
471
472 if (city_refresh(pcity)) {
473 log_error("%s radius changed when already arranged workers.",
475 /* Can't do anything - don't want to enter infinite recursive loop
476 * by trying to arrange workers more. */
477 }
479
480 if (broadcast_needed) {
482 }
483
486}
487
488/**********************************************************************/
491static void city_global_turn_notify(struct conn_list *dest)
492{
494 const struct impr_type *pimprove = pcity->production.value.building;
495
496 if (VUT_IMPROVEMENT == pcity->production.kind
497 && is_great_wonder(pimprove)
500 RPT_CERTAIN))) {
503 _("Notice: Wonder %s in %s will be finished next turn."),
505 }
507}
508
509/**********************************************************************/
513static void city_turn_notify(const struct city *pcity,
514 struct conn_list *dest,
515 const struct player *cache_for_player)
516{
517 const struct impr_type *pimprove = pcity->production.value.building;
518 struct packet_chat_msg packet;
520
521 if (0 < pcity->surplus[O_FOOD]) {
523 - pcity->food_stock - 1) / pcity->surplus[O_FOOD];
524
528 && 0 < pcity->surplus[O_SHIELD]) {
529 /* From the check above, the surplus must always be positive. */
531 - pcity->shield_stock) / pcity->surplus[O_SHIELD];
532 /* If growth and granary completion occur simultaneously, granary
533 * preserves food. -AJS. */
534 if (5 > turns_growth && 5 > turns_granary
536 package_event(&packet, city_tile(pcity),
538 _("Suggest throttling growth in %s to use %s "
539 "(being built) more effectively."),
542 lsend_packet_chat_msg(dest, &packet);
543 if (cache_for_player != nullptr) {
545 }
546 }
547 }
548
551 package_event(&packet, city_tile(pcity),
553 _("%s may soon grow to size %i."),
555 lsend_packet_chat_msg(dest, &packet);
556 if (cache_for_player != nullptr) {
558 }
559 }
560 } else {
561 if (0 >= pcity->food_stock + pcity->surplus[O_FOOD]
562 && 0 > pcity->surplus[O_FOOD]) {
563 package_event(&packet, city_tile(pcity),
565 _("Warning: Famine feared in %s."), city_link(pcity));
566 lsend_packet_chat_msg(dest, &packet);
567 if (cache_for_player != nullptr) {
569 }
570 }
571 }
572}
573
574/**********************************************************************/
579{
580 if (pconn != nullptr) {
581 struct player *pplayer = conn_get_player(pconn);
582
583 if (pplayer != nullptr) {
584 city_list_iterate(pplayer->cities, pcity) {
585 city_turn_notify(pcity, pconn->self, nullptr);
587 }
589 } else {
590 players_iterate(pplayer) {
591 city_list_iterate(pplayer->cities, pcity) {
592 city_turn_notify(pcity, pplayer->connections, pplayer);
595 /* NB: notifications to 'game.est_connections' are automatically
596 * cached. */
598 }
599}
600
601/**********************************************************************/
604void update_city_activities(struct player *pplayer)
605{
606 int n;
607
608 fc_assert(pplayer->cities != nullptr);
609
610 n = city_list_size(pplayer->cities);
611
612 if (n > 0) {
613 struct city *cities[n];
614 int i = 0, r;
615
616 city_list_iterate(pplayer->cities, pcity) {
617
619
620 /* Cancel trade routes that cannot exist any more */
622 struct city *tcity = game_city_by_number(proute->partner);
623
624 if (tcity != nullptr) {
625 bool cancel = FALSE;
626
627 if (proute->dir != RDIR_FROM && goods_has_flag(proute->goods, GF_DEPLETES)
628 && !goods_can_be_provided(tcity, proute->goods, nullptr)) {
629 cancel = TRUE;
630 }
631 if (!cancel && !can_cities_trade(pcity, tcity)) {
634
635 if (settings->cancelling == TRI_CANCEL) {
636 cancel = TRUE;
637 }
638 }
639
640 if (cancel) {
641 struct trade_route *back;
642
644 free(proute);
645 free(back);
646 }
647 }
649
650 /* Add cities to array for later random order handling */
651 cities[i++] = pcity;
653
654 /* How gold upkeep is handled depends on the setting
655 * 'game.info.gold_upkeep_style':
656 * GOLD_UPKEEP_CITY: Each city tries to balance its upkeep individually
657 * (this is done in update_city_activity()).
658 * GOLD_UPKEEP_MIXED: Each city tries to balance its upkeep for
659 * buildings individually; the upkeep for units is
660 * paid by the nation.
661 * GOLD_UPKEEP_NATION: The nation as a whole balances the treasury. If
662 * the treasury is not balance units and buildings
663 * are sold. */
664
665 /* Iterate over cities in a random order. */
666 while (i > 0) {
667 r = fc_rand(i);
668 /* update unit upkeep */
671 cities[r] = cities[--i];
672 }
673 }
674}
675
676/**********************************************************************/
690 bool wipe_in_the_end)
691{
692 int punit_id;
693
695 nullptr, get_output_type(outp), nullptr)) {
696 /* Can't get rid of this unit. It is undisbandable for the current
697 * situation. */
698 return FALSE;
699 }
700
701 punit_id = punit->id;
702
703 /* Try to perform this unit's can't upkeep actions. */
705 nullptr, get_output_type(outp), nullptr,
706 nullptr, nullptr, nullptr, nullptr);
707
709 /* No forced action was able to kill the unit. Finish the job. */
710 wipe_unit(punit, wipe_reason, nullptr);
711 }
712
713 return !unit_is_alive(punit_id);
714}
715
716/**********************************************************************/
721{
722 citizens want = change;
723
724 fc_assert_ret_val(0 < change, 0);
725
727 citizens fix = MIN(want, pcity->specialists[sp]);
728
729 pcity->specialists[sp] -= fix;
730 want -= fix;
732
733 return change - want;
734}
735
736/**********************************************************************/
741{
742 struct tile *pcenter = city_tile(pcity);
743 int want = change;
744 const struct civ_map *nmap = &(wld.map);
745
746 fc_assert_ret_val(0 < change, 0);
747
749 ptile, _index, _x, _y) {
750 if (0 < want && tile_worked(ptile) == pcity) {
752 want--;
753 }
755
756 return change - want;
757}
758
759/**********************************************************************/
765 struct player *destroyer, const char *reason)
766{
768 int old_radius_sq;
769
770 if (pop_loss == 0) {
771 return TRUE;
772 }
773
774 if (city_size_get(pcity) <= pop_loss) {
775 int id = pcity->id;
776
777 citizens_update(pcity, nullptr); /* To avoid warnings during the script */
778 /* Won't refresh a doomed city, or should we? */
779 script_server_signal_emit("city_destroyed", pcity, pcity->owner,
780 destroyer);
781
782 if (city_exist(id)) {
784 }
785 return FALSE;
786 }
791
792 /* Cap the food stock at the new granary size. */
793 if (pcity->food_stock > city_granary_size(city_size_get(pcity))) {
795 }
796
797 /* First try to kill off the specialists */
799
800 if (loss_remain > 0) {
801 /* Take it out on workers */
802#ifndef FREECIV_NDEBUG
803 loss_remain -=
804#endif /* FREECIV_NDEBUG */
806 }
807
808 /* Update citizens. */
809 citizens_update(pcity, nullptr);
810
811 /* Update number of people in each feelings category.
812 * This also updates the city radius if needed. */
814
816
817 /* Send city data. */
818 sync_cities();
819
821 "city_reduce_size() has remaining"
822 "%d of %d for \"%s\"[%d]",
825
826 /* Update cities that have trade routes with us */
828 if (city_refresh(pcity2)) {
829 /* This should never happen, but if it does, make sure not to
830 * leave workers outside city radius. */
832 }
834
836
837 if (reason != nullptr) {
838 int id = pcity->id;
839
840 script_server_signal_emit("city_size_change", pcity,
842
843 return city_exist(id);
844 }
845
846 return TRUE;
847}
848
849/**********************************************************************/
853void city_repair_size(struct city *pcity, int change)
854{
855 if (change > 0) {
856 pcity->specialists[DEFAULT_SPECIALIST] += change;
857 } else if (change < 0) {
858 int need = change + city_reduce_specialists(pcity, -change);
859
860 if (0 > need) {
861#ifndef FREECIV_NDEBUG
862 need +=
863#endif /* FREECIV_NDEBUG */
865 }
866
867 fc_assert_msg(0 == need,
868 "city_repair_size() has remaining %d of %d for \"%s\"[%d]",
870 }
871}
872
873/**********************************************************************/
881{
883
884 return CLIP(0, savings, 100);
885}
886
887/**********************************************************************/
895{
897
898 return CLIP(0, savings, 100);
899}
900
901/**********************************************************************/
908{
910
911 pcity->food_stock = (city_granary_size(new_size) * savings_pct) / 100;
912}
913
914/**********************************************************************/
920static bool city_increase_size(struct city *pcity, bool natural_growth,
922{
923 int new_food;
925 bool have_square = FALSE;
926 bool rapture_grow = city_rapture_grow(pcity); /* Check before size increase! */
927 struct tile *pcenter = city_tile(pcity);
928 struct player *powner = city_owner(pcity);
929 const struct impr_type *pimprove = pcity->production.value.building;
930 const struct civ_map *nmap = &(wld.map);
931
933 /* Need improvement */
937 _("%s needs %s (being built) to grow beyond size %d."),
941 } else {
943 _("%s needs an improvement to grow beyond size %d."),
945 }
946 /* Granary can only hold so much */
948 * (100 * 100 - game.server.aqueductloss * (100 - savings_pct))
949 / (100 * 100));
950 pcity->food_stock = MIN(pcity->food_stock, new_food);
951
952 return FALSE;
953 }
954
955 if (natural_growth) {
956 /* Growth by filled foodbox */
957 int stock;
958 int granary;
959
961 if (pcity->food_stock <= granary) {
962 stock = 0;
963 } else {
964 stock = pcity->food_stock - granary;
965 }
966
968
969 /* Do not empty food stock if city is growing by celebrating */
970 if (rapture_grow) {
972 } else {
974 }
975
976 /* Never increase amount of food in the foodbox */
977 pcity->food_stock = MIN(pcity->food_stock, new_food);
978 } else {
979 /* Growth by means like add-to-city or population migration */
981
983
984 /* Preserve old food stock, unless granary effect gives us more. */
985 pcity->food_stock = MAX(pcity->food_stock, new_food);
986 }
987
988 if (sid >= 0) {
990 pcity->specialists[sid]++;
991 } else {
992 /* If there is enough food, and the city is big enough,
993 * make new citizens into scientists or taxmen -- Massimo */
994
995 /* Ignore food if no square can be worked */
997 ptile, _index, _x, _y) {
998 if (tile_worked(ptile) != pcity /* Quick test */
999 && city_can_work_tile(pcity, ptile)) {
1000 have_square = TRUE;
1001 }
1003
1004 if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1006 pcity->specialists[best_specialist(O_SCIENCE, pcity)]++;
1007 } else if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1009 pcity->specialists[best_specialist(O_GOLD, pcity)]++;
1010 } else {
1011 pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
1012 }
1013 }
1014
1015 /* Deprecated signal. Connect your lua functions to "city_size_change" that's
1016 * emitted from calling functions which know the 'reason' of the increase. */
1017 script_server_signal_emit("city_growth", pcity,
1019
1020 return TRUE;
1021}
1022
1023/**********************************************************************/
1029 struct player *nationality,
1030 bool aaw)
1031{
1032 struct player *powner = city_owner(pcity);
1033
1034 /* Update citizens. */
1035 citizens_update(pcity, nationality);
1036
1037 /* Refresh the city data; this also checks the squared city radius. */
1039
1040 if (aaw) {
1042 }
1043
1044 /* Update cities that have trade routes with us */
1046 if (city_refresh(pcity2)) {
1047 /* This should never happen, but if it does, make sure not to
1048 * leave workers outside city radius. */
1050 }
1052
1054 _("%s grows to size %d."),
1056
1058
1059 sync_cities();
1060}
1061
1062/**********************************************************************/
1070 struct player *nationality,
1071 Specialist_type_id sid, const char *reason)
1072{
1073 int change = size - city_size_get(pcity);
1074
1075 if (change > 0) {
1077 int real_change;
1079 int id = pcity->id;
1080
1081 /* Increase city size until size reached, or increase fails */
1083 /* TODO: This is currently needed only because there's
1084 * deprecated script signal "city_growth" emitted.
1085 * Check the need after signal has been dropped completely. */
1086 if (!city_exist(id)) {
1087 return FALSE;
1088 }
1089
1090 current_size++;
1091 }
1092
1094
1096
1097 if (real_change != 0 && reason != nullptr) {
1098 script_server_signal_emit("city_size_change", pcity,
1100
1101 if (!city_exist(id)) {
1102 return FALSE;
1103 }
1104 }
1105 } else if (change < 0) {
1106 /* We assume that city_change_size() is never called because
1107 * of enemy actions. If that changes, enemy must be passed
1108 * to city_reduce_size() */
1109 return city_reduce_size(pcity, -change, nullptr, reason);
1110 }
1111
1113
1114 return TRUE;
1115}
1116
1117/**********************************************************************/
1121static void city_populate(struct city *pcity, struct player *nationality)
1122{
1123 int saved_id = pcity->id;
1124 int granary_size = city_granary_size(city_size_get(pcity));
1125
1126 pcity->food_stock += pcity->surplus[O_FOOD];
1127 if (pcity->food_stock >= granary_size || city_rapture_grow(pcity)) {
1131 _("A recent plague outbreak prevents growth in %s."),
1132 city_link(pcity));
1133 /* Lose excess food */
1134 pcity->food_stock = MIN(pcity->food_stock, granary_size);
1135 } else {
1136 bool success;
1137
1140
1141 if (success) {
1143 script_server_signal_emit("city_size_change", pcity,
1144 (lua_Integer)1, "growth");
1145 }
1146 }
1147 } else if (pcity->food_stock < 0) {
1148 /* FIXME: should this depend on units with ability to build
1149 * cities or on units that require food in upkeep?
1150 * I'll assume citybuilders (units that 'contain' 1 pop) -- sjolie
1151 * The above may make more logical sense, but in game terms
1152 * you want to disband a unit that is draining your food
1153 * reserves. Hence, I'll assume food upkeep > 0 units. -- jjm
1154 */
1155 unit_list_iterate_safe(pcity->units_supported, punit) {
1156 if (punit->upkeep[O_FOOD] > 0) {
1157 const char *punit_link = unit_tile_link(punit);
1158
1163 _("Famine feared in %s, %s lost!"),
1165 }
1166
1167 if (city_exist(saved_id)) {
1169 }
1170
1171 return;
1172 }
1174 if (city_size_get(pcity) > 1) {
1177 _("Famine causes population loss in %s."),
1178 city_link(pcity));
1179 } else {
1182 _("Famine destroys %s entirely."),
1183 city_link(pcity));
1184 }
1186 if (city_reduce_size(pcity, 1, nullptr, "famine")) {
1187 pcity->had_famine = TRUE;
1188 }
1189 }
1190}
1191
1192/**********************************************************************/
1199 struct city *pcity,
1200 struct player *pplayer,
1201 int saved_id)
1202{
1203 const void *ptarget;
1204 const char *tgt_name;
1205 const struct requirement_vector *build_reqs;
1206 const char *signal_name;
1207 const struct req_context city_ctxt = {
1208 .player = pplayer,
1209 .city = pcity,
1210 .tile = city_tile(pcity)
1211 /* FIXME: Setting .unittype is currently redundant,
1212 * but can_city_build_unit_direct() does it */
1213 };
1214 bool purge = FALSE;
1215 bool known = FALSE;
1216
1217 if (pcity->wlcb == WLCB_ALWAYS_PURGE) {
1218 return TRUE;
1219 }
1220
1221 switch (target->kind) {
1222 case VUT_UTYPE:
1223 ptarget = target->value.utype;
1224 build_reqs = &target->value.utype->build_reqs;
1226 signal_name = "unit_cant_be_built";
1227 break;
1228 case VUT_IMPROVEMENT:
1229 ptarget = target->value.building;
1230 build_reqs = &target->value.building->reqs;
1232 signal_name = "building_cant_be_built";
1233 break;
1234 default:
1236 || target->kind == VUT_UTYPE), FALSE);
1237 return FALSE;
1238 }
1239
1240 if (pcity->wlcb == WLCB_ALWAYS_POSTPONE) {
1241 notify_player(pplayer, city_tile(pcity),
1243 _("%s can't build %s from the worklist. "
1244 "Postponing..."),
1246 tgt_name);
1247 return FALSE;
1248 }
1249
1250 requirement_vector_iterate(build_reqs, preq) {
1251 if (!is_req_active(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
1252 known = TRUE;
1253 switch (preq->source.kind) {
1254 case VUT_COUNTER:
1255 if (preq->present) {
1256 notify_player(pplayer, city_tile(pcity),
1258 _("%s can't build %s from the worklist; "
1259 "counter %s value's checkpoint do not met "
1260 "Postponing..."),
1262 tgt_name,
1264 (preq->source.value.counter));
1265 } else {
1266 purge = TRUE;
1267 }
1268 break;
1269 case VUT_ADVANCE:
1270 if (preq->present) {
1271 notify_player(pplayer, city_tile(pcity),
1273 _("%s can't build %s from the worklist; "
1274 "tech %s not yet available. Postponing..."),
1276 tgt_name,
1278 (preq->source.value.advance));
1280 pcity, "need_tech");
1281 } else {
1282 /* While techs can be unlearned, this isn't useful feedback */
1283 purge = TRUE;
1284 }
1285 break;
1286 case VUT_TECHFLAG:
1287 if (preq->present) {
1288 notify_player(pplayer, city_tile(pcity),
1290 _("%s can't build %s from the worklist; "
1291 "no tech with flag \"%s\" yet available. "
1292 "Postponing..."),
1294 tgt_name,
1295 tech_flag_id_name(preq->source.value.techflag));
1297 pcity, "need_techflag");
1298 } else {
1299 /* While techs can be unlearned, this isn't useful feedback */
1300 purge = TRUE;
1301 }
1302 break;
1303 case VUT_IMPROVEMENT:
1304 case VUT_SITE:
1305 if (preq->range == REQ_RANGE_LOCAL) {
1306 /* Building itself is never going to change */
1307 purge = TRUE;
1308 } else {
1309 if (preq->present) {
1310 notify_player(pplayer, city_tile(pcity),
1312 _("%s can't build %s from the worklist; "
1313 "need to have %s first. Postponing..."),
1315 tgt_name,
1317 preq->source.value.building));
1319 pcity, "need_building");
1320 } else {
1321 notify_player(pplayer, city_tile(pcity),
1323 _("%s can't build %s from the worklist; "
1324 "need to not have %s. Postponing..."),
1326 tgt_name,
1328 preq->source.value.building));
1330 pcity, "have_building");
1331 }
1332 }
1333 break;
1334 case VUT_IMPR_GENUS:
1335 if (preq->range == REQ_RANGE_LOCAL) {
1336 /* Building's own genus is never going to change */
1337 purge = TRUE;
1338 } else {
1339 if (preq->present) {
1340 notify_player(pplayer, city_tile(pcity),
1342 _("%s can't build %s from the worklist; "
1343 "need to have %s first. Postponing..."),
1345 tgt_name,
1347 preq->source.value.impr_genus));
1349 pcity, "need_building_genus");
1350 } else {
1351 notify_player(pplayer, city_tile(pcity),
1353 _("%s can't build %s from the worklist; "
1354 "need to not have %s. Postponing..."),
1356 tgt_name,
1358 preq->source.value.impr_genus));
1360 pcity, "have_building_genus");
1361 }
1362 }
1363 break;
1364 case VUT_IMPR_FLAG:
1365 if (preq->range == REQ_RANGE_LOCAL) {
1366 /* Building's own flags are never going to change */
1367 purge = TRUE;
1368 } else {
1369 if (preq->present) {
1370 notify_player(pplayer, city_tile(pcity),
1372 _("%s can't build %s from the worklist; "
1373 "need to have %s first. Postponing..."),
1375 tgt_name,
1377 preq->source.value.impr_flag));
1379 pcity, "need_building_flag");
1380 } else {
1381 notify_player(pplayer, city_tile(pcity),
1383 _("%s can't build %s from the worklist; "
1384 "need to not have %s. Postponing..."),
1386 tgt_name,
1388 preq->source.value.impr_flag));
1390 pcity, "have_building_flag");
1391 }
1392 }
1393 break;
1394 case VUT_PLAYER_FLAG:
1395 if (preq->present) {
1396 notify_player(pplayer, city_tile(pcity),
1398 _("%s can't build %s from the worklist; "
1399 "need to have %s first. Postponing..."),
1401 tgt_name,
1403 preq->source.value.plr_flag));
1405 pcity, "need_player_flag");
1406 } else {
1407 notify_player(pplayer, city_tile(pcity),
1409 _("%s can't build %s from the worklist; "
1410 "need to not have %s. Postponing..."),
1412 tgt_name,
1414 preq->source.value.plr_flag));
1416 pcity, "have_player_flag");
1417 }
1418 break;
1419 case VUT_PLAYER_STATE:
1420 purge = TRUE;
1421 break;
1422 case VUT_GOVERNMENT:
1423 if (preq->present) {
1424 notify_player(pplayer, city_tile(pcity),
1426 _("%s can't build %s from the worklist; "
1427 "it needs %s government. Postponing..."),
1429 tgt_name,
1430 government_name_translation(preq->source.value.govern));
1432 pcity, "need_government");
1433 } else {
1434 notify_player(pplayer, city_tile(pcity),
1436 _("%s can't build %s from the worklist; "
1437 "it cannot have %s government. Postponing..."),
1439 tgt_name,
1440 government_name_translation(preq->source.value.govern));
1442 pcity, "have_government");
1443 }
1444 break;
1445 case VUT_GOVFLAG:
1446 if (preq->present) {
1447 notify_player(pplayer, city_tile(pcity),
1449 _("%s can't build %s from the worklist; "
1450 "it needs %s government. Postponing..."),
1452 tgt_name,
1453 gov_flag_id_translated_name(preq->source.value.govflag));
1455 pcity, "need_govflag");
1456 } else {
1457 notify_player(pplayer, city_tile(pcity),
1459 _("%s can't build %s from the worklist; "
1460 "it cannot have %s government. Postponing..."),
1462 tgt_name,
1463 gov_flag_id_translated_name(preq->source.value.govflag));
1465 pcity, "have_govflag");
1466 }
1467 break;
1468 case VUT_ACHIEVEMENT:
1469 if (preq->present) {
1470 notify_player(pplayer, city_tile(pcity),
1472 _("%s can't build %s from the worklist; "
1473 "it needs \"%s\" achievement. Postponing..."),
1475 tgt_name,
1476 achievement_name_translation(preq->source.value.achievement));
1478 pcity, "need_achievement");
1479 } else {
1480 /* Can't unachieve things. */
1481 purge = TRUE;
1482 }
1483 break;
1484 case VUT_EXTRA:
1485 if (preq->present) {
1486 notify_player(pplayer, city_tile(pcity),
1488 Q_("?extra:%s can't build %s from the worklist; "
1489 "%s is required. Postponing..."),
1491 tgt_name,
1492 extra_name_translation(preq->source.value.extra));
1494 pcity, "need_extra");
1495 } else {
1496 notify_player(pplayer, city_tile(pcity),
1498 Q_("?extra:%s can't build %s from the worklist; "
1499 "%s is prohibited. Postponing..."),
1501 tgt_name,
1502 extra_name_translation(preq->source.value.extra));
1504 pcity, "have_extra");
1505 }
1506 break;
1507 case VUT_TILEDEF:
1508 if (preq->present) {
1509 notify_player(pplayer, city_tile(pcity),
1511 Q_("?tiledef:%s can't build %s from the worklist; "
1512 "%s is required. Postponing..."),
1514 tgt_name,
1515 tiledef_name_translation(preq->source.value.tiledef));
1517 pcity, "need_tiledef");
1518 } else {
1519 notify_player(pplayer, city_tile(pcity),
1521 Q_("?tiledef:%s can't build %s from the worklist; "
1522 "%s is prohibited. Postponing..."),
1524 tgt_name,
1525 tiledef_name_translation(preq->source.value.tiledef));
1527 pcity, "have_tiledef");
1528 }
1529 break;
1531 if (preq->present) {
1532 notify_player(pplayer, city_tile(pcity),
1534 Q_("?tdconn:%s can't build %s from the worklist; "
1535 "access to %s is required. Postponing..."),
1537 tgt_name,
1538 tiledef_name_translation(preq->source.value.tiledef));
1540 pcity, "need_tiledef_conn");
1541 } else {
1542 notify_player(pplayer, city_tile(pcity),
1544 Q_("?tdconn:%s can't build %s from the worklist; "
1545 "access to %s is prohibited. Postponing..."),
1547 tgt_name,
1548 tiledef_name_translation(preq->source.value.tiledef));
1550 pcity, "have_tiledef_conn");
1551 }
1552 break;
1553 case VUT_GOOD:
1554 if (preq->present) {
1555 notify_player(pplayer, city_tile(pcity),
1557 Q_("?extra:%s can't build %s from the worklist; "
1558 "%s is required. Postponing..."),
1560 tgt_name,
1561 goods_name_translation(preq->source.value.good));
1563 pcity, "need_good");
1564 } else {
1565 notify_player(pplayer, city_tile(pcity),
1567 Q_("?extra:%s can't build %s from the worklist; "
1568 "%s is prohibited. Postponing..."),
1570 tgt_name,
1571 goods_name_translation(preq->source.value.good));
1573 pcity, "have_good");
1574 }
1575 break;
1576 case VUT_TERRAIN:
1577 if (preq->present) {
1578 notify_player(pplayer, city_tile(pcity),
1580 Q_("?terrain:%s can't build %s from the worklist; "
1581 "%s terrain is required. Postponing..."),
1583 tgt_name,
1584 terrain_name_translation(preq->source.value.terrain));
1586 pcity, "need_terrain");
1587 } else {
1588 notify_player(pplayer, city_tile(pcity),
1590 Q_("?terrain:%s can't build %s from the worklist; "
1591 "%s terrain is prohibited. Postponing..."),
1593 tgt_name,
1594 terrain_name_translation(preq->source.value.terrain));
1596 pcity, "have_terrain");
1597 }
1598 break;
1599 case VUT_NATION:
1600 if (preq->range < REQ_RANGE_TRADE_ROUTE
1601 || preq->range == REQ_RANGE_PLAYER) {
1602 /* At higher ranges, new players with their nations may arrive */
1603 purge = TRUE;
1604 } else {
1605 if (preq->present) {
1606 notify_player(pplayer, city_tile(pcity),
1608 /* TRANS: "%s nation" is adjective */
1609 Q_("?nation:%s can't build %s from the worklist; "
1610 "%s nation is required. Postponing..."),
1612 tgt_name,
1613 nation_adjective_translation(preq->source.value.nation));
1615 pcity, "need_nation");
1616 } else {
1617 notify_player(pplayer, city_tile(pcity),
1619 Q_("?nation:%s can't build %s from the worklist; "
1620 "%s nation is prohibited. Postponing..."),
1622 tgt_name,
1623 nation_adjective_translation(preq->source.value.nation));
1625 pcity, "have_nation");
1626 }
1627 }
1628 break;
1629 case VUT_NATIONGROUP:
1630 if (preq->range < REQ_RANGE_TRADE_ROUTE
1631 || preq->range == REQ_RANGE_PLAYER) {
1632 /* At higher ranges, new players with their nations may arrive */
1633 purge = TRUE;
1634 } else {
1635 if (preq->present) {
1636 notify_player(pplayer, city_tile(pcity),
1638 /* TRANS: "%s nation" is adjective */
1639 Q_("?ngroup:%s can't build %s from the worklist; "
1640 "%s nation is required. Postponing..."),
1642 tgt_name,
1643 nation_group_name_translation(preq->source.value.nationgroup));
1645 pcity, "need_nationgroup");
1646 } else {
1647 notify_player(pplayer, city_tile(pcity),
1649 Q_("?ngroup:%s can't build %s from the worklist; "
1650 "%s nation is prohibited. Postponing..."),
1652 tgt_name,
1653 nation_group_name_translation(preq->source.value.nationgroup));
1655 pcity, "have_nationgroup");
1656 }
1657 }
1658 break;
1659 case VUT_STYLE:
1660 /* FIXME: City styles sometimes change over time, but it isn't
1661 * entirely under player control. Probably better to purge
1662 * with useful explanation. */
1663 if (preq->present) {
1664 notify_player(pplayer, city_tile(pcity),
1666 _("%s can't build %s from the worklist; "
1667 "only %s style cities may build this. Postponing..."),
1669 tgt_name,
1670 style_name_translation(preq->source.value.style));
1672 pcity, "need_style");
1673 } else {
1674 notify_player(pplayer, city_tile(pcity),
1676 _("%s can't build %s from the worklist; "
1677 "%s style cities may not build this. Postponing..."),
1679 tgt_name,
1680 style_name_translation(preq->source.value.style));
1682 pcity, "have_style");
1683 }
1684 break;
1685 case VUT_NATIONALITY:
1686 /* FIXME: Changing citizen nationality is hard: purging might be
1687 * more useful in this case. */
1688 if (preq->present) {
1689 notify_player(pplayer, city_tile(pcity),
1691 /* TRANS: Latter %s is citizen nationality */
1692 _("%s can't build %s from the worklist; "
1693 "only city with %s may build this. Postponing..."),
1695 tgt_name,
1696 nation_plural_translation(preq->source.value.nationality));
1698 pcity, "need_nationality");
1699 } else {
1700 notify_player(pplayer, city_tile(pcity),
1702 /* TRANS: Latter %s is citizen nationality */
1703 _("%s can't build %s from the worklist; "
1704 "only city without %s may build this. Postponing..."),
1706 tgt_name,
1707 nation_plural_translation(preq->source.value.nationality));
1709 pcity, "have_nationality");
1710 }
1711 break;
1712 case VUT_ORIGINAL_OWNER:
1713 /* Original owner of this specific city won't change.
1714 * Update this when supporting ranges other than REQ_RANGE_CITY. */
1715 purge = TRUE;
1716 break;
1717 case VUT_DIPLREL:
1718 case VUT_DIPLREL_TILE: /* The tile owner is the city owner */
1719 case VUT_DIPLREL_TILE_O: /* The tile owner is the city owner */
1720 if (preq->present) {
1721 const char *reason;
1722
1723 notify_player(pplayer, city_tile(pcity),
1725 /* TRANS: '%s' is a wide range of relationships;
1726 * e.g., 'Peace', 'Never met', 'Foreign',
1727 * 'Hosts embassy', 'Provided Casus Belli' */
1728 _("%s can't build %s from the worklist; "
1729 "the relationship '%s' is required."
1730 " Postponing..."),
1732 tgt_name,
1734 preq->source.value.diplrel));
1735
1736 if (preq->source.kind == VUT_DIPLREL_TILE) {
1737 reason = "need_diplrel_tile";
1738 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1739 reason = "need_diplrel_tile_o";
1740 } else {
1741 fc_assert(preq->source.kind == VUT_DIPLREL);
1742 reason = "need_diplrel";
1743 }
1744
1746 pcity, reason);
1747 } else {
1748 const char *reason;
1749
1750 notify_player(pplayer, city_tile(pcity),
1752 _("%s can't build %s from the worklist; "
1753 "the relationship '%s' is prohibited."
1754 " Postponing..."),
1756 tgt_name,
1758 preq->source.value.diplrel));
1759
1760 if (preq->source.kind == VUT_DIPLREL_TILE) {
1761 reason = "have_diplrel_tile";
1762 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1763 reason = "have_diplrel_tile_o";
1764 } else {
1765 fc_assert(preq->source.kind == VUT_DIPLREL);
1766 reason = "have_diplrel";
1767 }
1768
1770 pcity, reason);
1771 }
1772 break;
1775 if (preq->present) {
1776 const char *reason;
1777
1778 notify_player(pplayer, city_tile(pcity),
1780 /* TRANS: '%s' is a wide range of relationships;
1781 * e.g., 'Peace', 'Never met', 'Foreign',
1782 * 'Hosts embassy', 'Provided Casus Belli' */
1783 _("%s can't build %s from the worklist; "
1784 "unit with the relationship '%s' is required."
1785 " Postponing..."),
1787 tgt_name,
1789 preq->source.value.diplrel));
1790
1791 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1792 reason = "need_diplrel_unitany";
1793 } else {
1794 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1795 reason = "need_diplrel_unitany_o";
1796 }
1797
1799 pcity, reason);
1800 } else {
1801 const char *reason;
1802
1803 notify_player(pplayer, city_tile(pcity),
1805 _("%s can't build %s from the worklist; "
1806 "unit with the relationship '%s' is prohibited."
1807 " Postponing..."),
1809 tgt_name,
1811 preq->source.value.diplrel));
1812
1813 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1814 reason = "have_diplrel_unitany";
1815 } else {
1816 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1817 reason = "have_diplrel_unitany_o";
1818 }
1819
1821 pcity, reason);
1822 }
1823 break;
1824 case VUT_MINSIZE:
1825 if (preq->present) {
1826 notify_player(pplayer, city_tile(pcity),
1828 _("%s can't build %s from the worklist; "
1829 "city must be of size %d or larger. "
1830 "Postponing..."),
1832 tgt_name,
1833 preq->source.value.minsize);
1835 pcity, "need_minsize");
1836 } else {
1837 notify_player(pplayer, city_tile(pcity),
1839 _("%s can't build %s from the worklist; "
1840 "city must be of size %d or smaller."
1841 "Postponing..."),
1843 tgt_name,
1844 (preq->source.value.minsize - 1));
1846 pcity, "need_minsize");
1847 }
1848 break;
1849 case VUT_MINCULTURE:
1850 if (preq->present) {
1851 notify_player(pplayer, city_tile(pcity),
1853 _("%s can't build %s from the worklist; "
1854 "city must have culture of %d. Postponing..."),
1856 tgt_name,
1857 preq->source.value.minculture);
1859 pcity, "need_minculture");
1860 } else {
1861 /* What has been written may not be unwritten. */
1862 purge = TRUE;
1863 }
1864 break;
1865 case VUT_MINFOREIGNPCT:
1866 if (preq->present) {
1867 notify_player(pplayer, city_tile(pcity),
1869 _("%s can't build %s from the worklist; "
1870 "city must have %d%% foreign population. Postponing..."),
1872 tgt_name,
1873 preq->source.value.minforeignpct);
1875 pcity, "need_minforeignpct");
1876 } else {
1877 notify_player(pplayer, city_tile(pcity),
1879 _("%s can't build %s from the worklist; "
1880 "city must have %d%% native population. Postponing..."),
1882 tgt_name,
1883 100 - preq->source.value.minforeignpct);
1885 pcity, "need_minforeignpct");
1886 }
1887 break;
1888 case VUT_MINTECHS:
1889 if (preq->present) {
1890 notify_player(pplayer, city_tile(pcity),
1892 _("%s can't build %s from the worklist; "
1893 "%d techs must be known. Postponing..."),
1895 tgt_name,
1896 preq->source.value.min_techs);
1898 pcity, "need_mintechs");
1899 } else {
1900 purge = TRUE;
1901 }
1902 break;
1903 case VUT_FUTURETECHS:
1904 if (preq->present) {
1905 notify_player(pplayer, city_tile(pcity),
1907 _("%s can't build %s from the worklist; "
1908 "%d future techs must be known. Postponing..."),
1910 tgt_name,
1911 preq->source.value.future_techs);
1913 pcity, "need_futuretechs");
1914 } else {
1915 purge = TRUE;
1916 }
1917 break;
1918 case VUT_MINCITIES:
1919 if (preq->present) {
1920 notify_player(pplayer, city_tile(pcity),
1922 _("%s can't build %s from the worklist; "
1923 "Must own %d cities. Postponing..."),
1925 tgt_name,
1926 preq->source.value.min_cities);
1928 pcity, "need_mincities");
1929 } else {
1930 purge = TRUE;
1931 }
1932 break;
1934 if (preq->present) {
1935 notify_player(pplayer, city_tile(pcity),
1937 PL_("%s can't build %s from the worklist; "
1938 "more than %d total unit on tile."
1939 " Postponing...",
1940 "%s can't build %s from the worklist; "
1941 "more than %d total units on tile."
1942 " Postponing...",
1943 preq->source.value.max_tile_total_units),
1945 tgt_name,
1946 preq->source.value.max_tile_total_units);
1948 pcity, "need_tileunits");
1949 } else {
1950 notify_player(pplayer, city_tile(pcity),
1952 PL_("%s can't build %s from the worklist; "
1953 "fewer than %d total unit on tile."
1954 " Postponing...",
1955 "%s can't build %s from the worklist; "
1956 "fewer than %d total units on tile."
1957 " Postponing...",
1958 preq->source.value.max_tile_total_units + 1),
1960 tgt_name,
1961 preq->source.value.max_tile_total_units + 1);
1963 pcity, "need_tileunits");
1964 }
1965 break;
1967 if (preq->present) {
1968 notify_player(pplayer, city_tile(pcity),
1970 PL_("%s can't build %s from the worklist; "
1971 "more than %d unit on tile."
1972 " Postponing...",
1973 "%s can't build %s from the worklist; "
1974 "more than %d units on tile."
1975 " Postponing...",
1976 preq->source.value.max_tile_top_units),
1978 tgt_name,
1979 preq->source.value.max_tile_top_units);
1981 pcity, "need_tiletopunits");
1982 } else {
1983 notify_player(pplayer, city_tile(pcity),
1985 PL_("%s can't build %s from the worklist; "
1986 "fewer than %d unit on tile."
1987 " Postponing...",
1988 "%s can't build %s from the worklist; "
1989 "fewer than %d units on tile."
1990 " Postponing...",
1991 preq->source.value.max_tile_top_units + 1),
1993 tgt_name,
1994 preq->source.value.max_tile_top_units + 1);
1996 pcity, "need_tiletopunits");
1997 }
1998 break;
1999 case VUT_AI_LEVEL:
2000 /* Can't change AI level. */
2001 purge = TRUE;
2002 break;
2003 case VUT_TERRAINCLASS:
2004 /* Change of terrain class is expected to be very unlikely. Purge!
2005 * TODO: Analyze ruleset to see how unlikely terrain class change actually is. */
2006 purge = TRUE;
2007 break;
2008 case VUT_TERRFLAG:
2009 if (preq->present) {
2010 notify_player(pplayer, city_tile(pcity),
2012 _("%s can't build %s from the worklist; "
2013 "terrain with \"%s\" flag is required. "
2014 "Postponing..."),
2016 tgt_name,
2017 terrain_flag_id_name(preq->source.value.terrainflag));
2019 pcity, "need_terrainflag");
2020 } else {
2021 notify_player(pplayer, city_tile(pcity),
2023 _("%s can't build %s from the worklist; "
2024 "terrain with \"%s\" flag is prohibited. "
2025 "Postponing..."),
2027 tgt_name,
2028 terrain_flag_id_name(preq->source.value.terrainflag));
2030 pcity, "have_terrainflag");
2031 }
2032 break;
2034 /* Changing the continent size is hard; cf. VUT_TERRAINCLASS above.
2035 * Change this when we support less fixed ranges (e.g. city?). */
2036 purge = TRUE;
2037 break;
2038 case VUT_ROADFLAG:
2039 if (preq->present) {
2040 notify_player(pplayer, city_tile(pcity),
2042 _("%s can't build %s from the worklist; "
2043 "road with \"%s\" flag is required. "
2044 "Postponing..."),
2046 tgt_name,
2047 road_flag_id_name(preq->source.value.roadflag));
2049 pcity, "need_roadflag");
2050 } else {
2051 notify_player(pplayer, city_tile(pcity),
2053 _("%s can't build %s from the worklist; "
2054 "road with \"%s\" flag is prohibited. "
2055 "Postponing..."),
2057 tgt_name,
2058 road_flag_id_name(preq->source.value.roadflag));
2060 pcity, "have_roadflag");
2061 }
2062 break;
2063 case VUT_EXTRAFLAG:
2064 if (preq->present) {
2065 notify_player(pplayer, city_tile(pcity),
2067 _("%s can't build %s from the worklist; "
2068 "extra with \"%s\" flag is required. "
2069 "Postponing..."),
2071 tgt_name,
2072 extra_flag_id_translated_name(preq->source.value.extraflag));
2074 pcity, "need_extraflag");
2075 } else {
2076 notify_player(pplayer, city_tile(pcity),
2078 _("%s can't build %s from the worklist; "
2079 "extra with \"%s\" flag is prohibited. "
2080 "Postponing..."),
2082 tgt_name,
2083 extra_flag_id_translated_name(preq->source.value.extraflag));
2085 pcity, "have_extraflag");
2086 }
2087 break;
2088 case VUT_MINLATITUDE:
2089 case VUT_MAXLATITUDE:
2090 /* Can't change where the city is located. */
2091 purge = TRUE;
2092 break;
2093 case VUT_CITYTILE:
2094 if (CITYT_BORDERING_TCLASS_REGION == preq->source.value.citytile
2095 && (preq->range == REQ_RANGE_CADJACENT
2096 || preq->range == REQ_RANGE_ADJACENT)) {
2097 if (preq->present) {
2098 notify_player(pplayer, city_tile(pcity),
2100 _("%s can't build %s from the worklist; "
2101 "different terrain class nearby is required. "
2102 "Postponing..."),
2104 tgt_name);
2106 pcity, "need_different_terrainclass");
2107 } else {
2108 notify_player(pplayer, city_tile(pcity),
2110 _("%s can't build %s from the worklist; "
2111 "different terrain class nearby is prohibited. "
2112 "Postponing..."),
2114 tgt_name);
2116 pcity, "have_different_terrainclass");
2117 }
2118 break;
2119 }
2120 /* Other values should not present in build reqs */
2122
2123 case VUT_UTYPE:
2124 case VUT_UTFLAG:
2125 case VUT_UCLASS:
2126 case VUT_UCFLAG:
2127 case VUT_MINVETERAN:
2128 case VUT_UNITSTATE:
2129 case VUT_ACTIVITY:
2130 case VUT_MINMOVES:
2131 case VUT_MINHP:
2132 case VUT_ACTION:
2133 case VUT_OTYPE:
2134 case VUT_SPECIALIST:
2136 case VUT_TILE_REL:
2137 case VUT_TERRAINALTER: /* XXX could do this in principle */
2138 /* Will only happen with a bogus ruleset. */
2139 log_error("worklist_change_build_target() has bogus preq");
2140 break;
2141 case VUT_CITYSTATUS:
2142 if (preq->source.value.citystatus == CITYS_TRANSFERRED) {
2143 /* If there's a change, it will invalidate worklist anyway. */
2144 purge = TRUE;
2145 } else if (preq->source.value.citystatus == CITYS_OWNED_BY_ORIGINAL) {
2146 if (preq->range == REQ_RANGE_CITY || preq->range == REQ_RANGE_TILE) {
2147 /* Can't change at these ranges */
2148 purge = TRUE;
2149 } else {
2150 if (preq->present) {
2151 notify_player(pplayer, city_tile(pcity),
2153 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2154 _("%s can't build %s from the worklist; "
2155 "only available when city in range %s \"%s\". "
2156 "Postponing..."),
2158 tgt_name, req_range_name(preq->range),
2159 citystatus_type_name(preq->source.value.citystatus));
2161 pcity, "need_citystatus");
2162 } else {
2163 notify_player(pplayer, city_tile(pcity),
2165 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2166 _("%s can't build %s from the worklist; "
2167 "not available when city in range %s is \"%s\". "
2168 "Postponing..."),
2170 tgt_name, req_range_name(preq->range),
2171 citystatus_type_name(preq->source.value.citystatus));
2173 pcity, "have_citystatus");
2174 }
2175 }
2176 } else {
2177 /* Other status types will only happen with a bogus ruleset. */
2178 log_error("worklist_change_build_target() has bogus citystatus preq");
2179 }
2180 break;
2181 case VUT_MINYEAR:
2182 if (preq->present) {
2183 notify_player(pplayer, city_tile(pcity),
2185 /* TRANS: last %s is a date */
2186 _("%s can't build %s from the worklist; "
2187 "only available from %s. Postponing..."),
2189 tgt_name,
2190 textyear(preq->source.value.minyear));
2192 pcity, "need_minyear");
2193 } else {
2194 /* Can't go back in time. */
2195 purge = TRUE;
2196 }
2197 break;
2198 case VUT_MINCALFRAG:
2199 /* Unlike VUT_MINYEAR, a requirement in either direction is
2200 * likely to be fulfilled sooner or later. */
2201 if (preq->present) {
2202 notify_player(pplayer, city_tile(pcity),
2204 /* TRANS: last %s is a calendar fragment from
2205 * the ruleset; may be a bare number */
2206 _("%s can't build %s from the worklist; "
2207 "only available from %s. Postponing..."),
2209 tgt_name,
2210 textcalfrag(preq->source.value.mincalfrag));
2212 pcity, "need_mincalfrag");
2213 } else {
2214 fc_assert_action(preq->source.value.mincalfrag > 0, break);
2215 notify_player(pplayer, city_tile(pcity),
2217 /* TRANS: last %s is a calendar fragment from
2218 * the ruleset; may be a bare number */
2219 _("%s can't build %s from the worklist; "
2220 "not available after %s. Postponing..."),
2222 tgt_name,
2223 textcalfrag(preq->source.value.mincalfrag - 1));
2225 pcity, "have_mincalfrag");
2226 }
2227 break;
2228 case VUT_TOPO:
2229 if (preq->present) {
2230 notify_player(pplayer, city_tile(pcity),
2232 /* TRANS: third %s is topology flag name
2233 * ("Hex", "ISO" */
2234 _("%s can't build %s from the worklist; "
2235 "only available in worlds with %s map."),
2237 tgt_name,
2238 _(topo_flag_name(preq->source.value.topo_property)));
2240 pcity, "need_topo");
2241 }
2242 purge = TRUE;
2243 break;
2244 case VUT_WRAP:
2245 if (preq->present) {
2246 notify_player(pplayer, city_tile(pcity),
2248 /* TRANS: third %s is wrap flag name
2249 * ("WrapX", "Wrapy") */
2250 _("%s can't build %s from the worklist; "
2251 "only available in worlds with %s map."),
2253 tgt_name,
2254 _(wrap_flag_name(preq->source.value.wrap_property)));
2256 pcity, "need_wrap");
2257 }
2258 purge = TRUE;
2259 break;
2260 case VUT_SERVERSETTING:
2261 notify_player(pplayer, city_tile(pcity),
2263 /* TRANS: %s is a server setting, its value and
2264 * if it is required to be present or absent.
2265 * The string's format is specified in
2266 * ssetv_human_readable().
2267 * Example: "killstack is enabled". */
2268 _("%s can't build %s from the worklist; "
2269 "only available when the server setting "
2270 "%s."),
2272 tgt_name,
2273 ssetv_human_readable(preq->source.value.ssetval,
2274 preq->present));
2276 pcity, "need_setting");
2277 /* Don't assume that the server setting will be changed. */
2278 purge = TRUE;
2279 break;
2280 case VUT_AGE:
2281 if (preq->present) {
2282 notify_player(pplayer, city_tile(pcity),
2284 _("%s can't build %s from the worklist; "
2285 "only available once %d turns old. Postponing..."),
2287 tgt_name,
2288 preq->source.value.age);
2290 pcity, "need_age");
2291 } else {
2292 /* Can't go back in time. */
2293 purge = TRUE;
2294 }
2295 break;
2296 case VUT_FORM_AGE:
2297 if (preq->present) {
2298 notify_player(pplayer, city_tile(pcity),
2300 _("%s can't build %s from the worklist; "
2301 "only available once %d turns old form. Postponing..."),
2303 tgt_name,
2304 preq->source.value.age);
2306 pcity, "need_form_age");
2307 } else {
2308 /* Can't go back in time. */
2309 purge = TRUE;
2310 }
2311 break;
2312 case VUT_NONE:
2313 case VUT_COUNT:
2315 "worklist_change_build_target() "
2316 "called with invalid preq");
2317 break;
2318 /* No default handling here, as we want compiler warning
2319 * if new requirement type is added to enum and it's not handled
2320 * here. */
2321 };
2322 break;
2323 }
2324
2325 /* Almost all cases emit signal in the end, so city check needed. */
2326 if (!city_exist(saved_id)) {
2327 /* Some script has removed city */
2328 return TRUE;
2329 }
2330
2332
2333 if (!known) {
2334 /* FIXME: make can_city_build_improvement_now() return a reason enum,
2335 * so we can notify user with it.
2336 * Likely the building already exist. */
2337 purge = TRUE;
2338 }
2339
2340 return purge;
2341}
2342
2343/**********************************************************************/
2349static bool worklist_change_build_target(struct player *pplayer,
2350 struct city *pcity)
2351{
2352 struct universal target;
2353 bool success = FALSE;
2354 int i;
2355 int saved_id = pcity->id;
2356 bool city_checked = TRUE; /* This is used to avoid spurious city_exist() calls */
2357 struct worklist *pwl = &pcity->worklist;
2358 const struct civ_map *nmap = &(wld.map);
2359
2360 if (worklist_is_empty(pwl)) {
2361 /* Nothing in the worklist; bail now. */
2362 return FALSE;
2363 }
2364
2365 i = 0;
2366 while (!success && i < worklist_length(pwl)) {
2367
2368 if (!city_checked) {
2369 if (!city_exist(saved_id)) {
2370 /* Some script has removed useless city that cannot build
2371 * what it is told to! */
2372 return FALSE;
2373 }
2375 }
2376
2377 if (worklist_peek_ith(pwl, &target, i)) {
2378 success = can_city_build_now(nmap, pcity, &target);
2379 } else {
2380 success = FALSE;
2381 }
2382 i++;
2383
2384 if (success) {
2385 break; /* while */
2386 }
2387
2388 switch (target.kind) {
2389 case VUT_UTYPE:
2390 {
2391 const struct unit_type *ptarget = target.value.utype;
2393 bool purge;
2394
2395 /* Maybe we can just upgrade the target to what the city /can/ build. */
2396 if (U_NOT_OBSOLETED == pupdate) {
2397 /* Nope, we're stuck. Skip this item from the worklist. */
2398 struct research *presearch = research_get(pplayer);
2399 struct advance *missing = nullptr;
2400 bool multiple = FALSE;
2401
2404 if (missing != nullptr) {
2405 multiple = TRUE;
2406 } else {
2407 missing = padv;
2408 }
2409 }
2411
2412
2413 purge = FALSE;
2414 if (missing != nullptr) {
2415 if (!multiple) {
2416 notify_player(pplayer, city_tile(pcity),
2418 _("%s can't build %s from the worklist; "
2419 "tech %s not yet available. Postponing..."),
2422 } else {
2423 notify_player(pplayer, city_tile(pcity),
2425 _("%s can't build %s from the worklist; "
2426 "multiple techs still needed. Postponing..."),
2428 }
2429
2430 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2431 "need_tech");
2432 } else {
2433 /* Unknown or requirement from vector. */
2434 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2435 saved_id);
2436 }
2438 if (!purge) {
2439 break;
2440 }
2441 } else {
2443 }
2444 if (purge) {
2445 /* If the city can never build this unit or its descendants,
2446 * drop it. */
2447 notify_player(pplayer, city_tile(pcity),
2449 _("%s can't build %s from the worklist. Purging..."),
2451 /* Yes, warn about the targets that's actually
2452 in the worklist, not its obsolete-closure
2453 pupdate. */
2455 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2456 "never");
2457 if (city_exist(saved_id)) {
2459 /* Purge this worklist item. */
2460 i--;
2462 } else {
2464 }
2465 } else {
2466 /* Yep, we can go after pupdate instead. Joy! */
2468 _("Production of %s is upgraded to %s in %s."),
2471 city_link(pcity));
2472 target.value.utype = pupdate;
2473 }
2474 break;
2475 }
2476 case VUT_IMPROVEMENT:
2477 {
2478 const struct impr_type *ptarget = target.value.building;
2480 bool purge;
2481
2482 /* If the city can never build this improvement, drop it. */
2484 purge = !success;
2485
2486 /* Maybe this improvement has been obsoleted by something that
2487 we can build. */
2488 if (purge) {
2489 /* Nope, no use. *sigh* */
2490
2491 /* Can it be postponed? */
2493 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2494 saved_id);
2495
2496 /* Almost all cases emit signal in the end, so city check needed. */
2497 if (!city_exist(saved_id)) {
2498 /* Some script has removed city */
2499 return FALSE;
2500 }
2502 }
2503 } else if (success) {
2504 /* Hey, we can upgrade the improvement! */
2506 _("Production of %s is upgraded to %s in %s."),
2509 city_link(pcity));
2510 target.value.building = pupdate;
2511 }
2512
2513 if (purge) {
2514 /* Never in a million years. */
2515 notify_player(pplayer, city_tile(pcity),
2517 _("%s can't build %s from the worklist. Purging..."),
2520 script_server_signal_emit("building_cant_be_built", ptarget, pcity,
2521 "never");
2522 if (city_exist(saved_id)) {
2524 /* Purge this worklist item. */
2525 i--;
2527 } else {
2529 }
2530 }
2531 break;
2532 }
2533 default:
2534 /* skip useless target */
2535 log_error("worklist_change_build_target() has unrecognized "
2536 "target kind (%d)", target.kind);
2537 break;
2538 };
2539 } /* while */
2540
2541 if (success) {
2542 /* All okay. Switch targets. */
2543 change_build_target(pplayer, pcity, &target, E_WORKLIST);
2544
2545 /* i is the index immediately _after_ the item we're changing to.
2546 Remove the (i-1)th item from the worklist. */
2547 worklist_remove(pwl, i - 1);
2548 }
2549
2550 if (worklist_is_empty(pwl)) {
2551 /* There *was* something in the worklist, but it's empty now. Bug the
2552 player about it. */
2554 /* TRANS: The <city> worklist .... */
2555 _("The %s worklist is now empty."),
2556 city_link(pcity));
2557 }
2558
2559 return success;
2560}
2561
2562/**********************************************************************/
2567void choose_build_target(struct player *pplayer, struct city *pcity)
2568{
2569 const struct civ_map *nmap = &(wld.map);
2570
2571 /* Pick the next thing off the worklist. */
2572 if (worklist_change_build_target(pplayer, pcity)) {
2573 return;
2574 }
2575
2576 /* Try building the same thing again. Repeat building doesn't require a
2577 * call to change_build_target, so just return. */
2578 switch (pcity->production.kind) {
2579 case VUT_UTYPE:
2580 /* We can build a unit again unless it's unique or we have lost the tech. */
2581 if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
2582 && can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
2583 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2584 utype_rule_name(pcity->production.value.utype));
2585 return;
2586 }
2587 break;
2588 case VUT_IMPROVEMENT:
2589 if (can_city_build_improvement_now(pcity, pcity->production.value.building,
2590 RPT_CERTAIN)) {
2591 /* We can build space and coinage again, and possibly others. */
2592 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2593 improvement_rule_name(pcity->production.value.building));
2594 return;
2595 }
2596 break;
2597 default:
2598 /* fallthru */
2599 break;
2600 };
2601
2602 /* Find *something* to do! */
2603 log_debug("Trying advisor_choose_build.");
2604 advisor_choose_build(pplayer, pcity);
2605 log_debug("Advisor_choose_build didn't kill us.");
2606}
2607
2608/**********************************************************************/
2613static const struct impr_type *building_upgrades_to(struct city *pcity,
2614 const struct impr_type *pimprove)
2615{
2616 const struct impr_type *check = pimprove;
2617 const struct impr_type *best_upgrade = nullptr;
2618
2620 return nullptr;
2621 }
2625 }
2626 }
2627
2628 return best_upgrade;
2629}
2630
2631/**********************************************************************/
2635{
2636 const struct impr_type *producing = pcity->production.value.building;
2638
2639 if (upgrading
2643 _("Production of %s is upgraded to %s in %s."),
2646 city_link(pcity));
2647 pcity->production.kind = VUT_IMPROVEMENT;
2648 pcity->production.value.building = upgrading;
2649 }
2650}
2651
2652/**********************************************************************/
2660static const struct unit_type *unit_upgrades_to(struct city *pcity,
2661 const struct unit_type *punittype)
2662{
2663 const struct unit_type *check = punittype;
2664 const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
2665 const struct civ_map *nmap = &(wld.map);
2666
2668 return U_NOT_OBSOLETED;
2669 }
2670 while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
2673 }
2674 }
2675
2676 return best_upgrade;
2677}
2678
2679/**********************************************************************/
2682static void upgrade_unit_prod(struct city *pcity)
2683{
2684 const struct unit_type *producing = pcity->production.value.utype;
2686 const struct civ_map *nmap = &(wld.map);
2687
2691 _("Production of %s is upgraded to %s in %s."),
2694 city_link(pcity));
2695 pcity->production.value.utype = upgrading;
2696 }
2697}
2698
2699/**********************************************************************/
2706static bool city_distribute_surplus_shields(struct player *pplayer,
2707 struct city *pcity)
2708{
2709 int size_reduction = 0;
2710 struct unit *sacrifizer;
2711
2712 if (pcity->surplus[O_SHIELD] < 0) {
2713 unit_list_iterate_safe(pcity->units_supported, punit) {
2715 && pcity->surplus[O_SHIELD] < 0) {
2716 const char *punit_link = unit_link(punit);
2717
2718 /* TODO: Should the unit try to help cities on adjacent tiles? That
2719 * would be a rules change. (This action is performed by the game
2720 * it self) */
2723 notify_player(pplayer, city_tile(pcity),
2725 _("%s can't upkeep %s, unit disbanded."),
2727 }
2728
2729 /* pcity->surplus[O_SHIELD] is automatically updated. */
2730 }
2732 }
2733
2734 if (pcity->surplus[O_SHIELD] < 0) {
2735 /* Special case: MissingXProtected. This nasty unit won't go so easily.
2736 * It'd rather make the citizens pay in blood for their failure to upkeep
2737 * it! If we make it here all normal units are already disbanded, so only
2738 * undisbandable ones remain. */
2739 unit_list_iterate_safe(pcity->units_supported, punit) {
2741
2742 if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
2743
2745 sacrifizer = punit;
2746
2747 /* No upkeep for the unit this turn. */
2748 pcity->surplus[O_SHIELD] += upkeep;
2749 }
2751 }
2752
2753 /* Now we confirm changes made last turn. */
2754 pcity->shield_stock += pcity->surplus[O_SHIELD];
2755 pcity->before_change_shields = pcity->shield_stock;
2756 pcity->last_turns_shield_surplus = pcity->surplus[O_SHIELD];
2757
2758 /* Previous turn values stored, and they are consistent with
2759 * other previous turn data.
2760 * Now reduce city size, likely messing all the values. */
2761 if (size_reduction > 0) {
2762 if (size_reduction == 1) {
2763 notify_player(pplayer, city_tile(pcity),
2765 _("Citizens in %s perish for their failure to "
2766 "upkeep %s!"),
2768 } else {
2769 notify_player(pplayer, city_tile(pcity),
2771 _("Citizens in %s perish for their failure to "
2772 "upkeep units!"),
2773 city_link(pcity));
2774 }
2775
2776 if (!city_reduce_size(pcity, size_reduction, nullptr, "upkeep_failure")) {
2777 return FALSE;
2778 }
2779 }
2780
2781 return TRUE;
2782}
2783
2784/**********************************************************************/
2787static bool city_build_building(struct player *pplayer, struct city *pcity)
2788{
2789 bool space_part;
2790 int mod;
2791 const struct impr_type *pimprove;
2792 int saved_id = pcity->id;
2793 const struct civ_map *nmap = &(wld.map);
2794
2795 if (is_convert_improvement(pcity->production.value.building)) {
2796 /* Coinage-like improvements that convert production */
2797 fc_assert(pcity->before_change_shields >= 0);
2798
2799 /* pcity->before_change_shields already contains the surplus from
2800 * this turn. */
2802 pplayer->economic.gold += pcity->before_change_shields;
2804 pplayer->economic.infra_points += pcity->before_change_shields;
2805 }
2806
2807 pcity->before_change_shields = 0;
2808 pcity->shield_stock = 0;
2809 choose_build_target(pplayer, pcity);
2810
2811 return TRUE;
2812 }
2813
2815
2816 /* The final (after upgrade) build target */
2817 pimprove = pcity->production.value.building;
2818
2821 _("%s is building %s, which is no longer available."),
2824 script_server_signal_emit("building_cant_be_built", pimprove, pcity,
2825 "unavailable");
2826 return TRUE;
2827 }
2828 if (pcity->shield_stock >= impr_build_shield_cost(pcity, pimprove)
2830 int cost;
2831
2832 if (is_small_wonder(pimprove)) {
2833 city_list_iterate(pplayer->cities, wcity) {
2834 if (city_has_building(wcity, pimprove)) {
2835 city_remove_improvement(wcity, pimprove);
2836 break;
2837 }
2839 }
2840
2841 space_part = TRUE;
2843 RPT_CERTAIN) > 0) {
2844 pplayer->spaceship.structurals++;
2846 RPT_CERTAIN) > 0) {
2847 pplayer->spaceship.components++;
2849 RPT_CERTAIN) > 0) {
2850 pplayer->spaceship.modules++;
2851 } else {
2852 space_part = FALSE;
2854 _("Completion of %s"));
2855 }
2856 cost = impr_build_shield_cost(pcity, pimprove);
2857 pcity->before_change_shields -= cost;
2858 pcity->shield_stock -= cost;
2859 pcity->turn_last_built = game.info.turn;
2860 /* To eliminate micromanagement */
2861 if (is_great_wonder(pimprove)) {
2863 _("The %s have finished building %s in %s."),
2864 nation_plural_for_player(pplayer),
2866 city_link(pcity));
2867 }
2868
2870 _("%s has finished building %s."),
2872 script_server_signal_emit("building_built", pimprove, pcity);
2873
2874 if (!city_exist(saved_id)) {
2875 /* Script removed city */
2876 return FALSE;
2877 }
2878
2879 /* Call this function since some buildings may change the
2880 * the vision range of a city */
2882
2884 RPT_CERTAIN))) {
2885 struct research *presearch = research_get(pplayer);
2886 char research_name[MAX_LEN_NAME * 2];
2887 int i;
2888 const char *provider = improvement_name_translation(pimprove);
2889
2891 PL_("%s boosts research; you gain %d immediate "
2892 "advance.",
2893 "%s boosts research; you gain %d immediate "
2894 "advances.",
2895 mod), provider, mod);
2896
2898 for (i = 0; i < mod; i++) {
2901
2904 /* TRANS: Tech from building (Darwin's Voyage) */
2905 Q_("?frombldg:Acquired %s from %s."), adv_name,
2906 provider);
2907
2909 /* TRANS: Tech from building (Darwin's
2910 * Voyage) */
2911 Q_("?frombldg:The %s have acquired %s "
2912 "from %s."),
2914 }
2915 }
2916 if (space_part && pplayer->spaceship.state == SSHIP_NONE) {
2918 _("The %s have started building a spaceship!"),
2919 nation_plural_for_player(pplayer));
2920 pplayer->spaceship.state = SSHIP_STARTED;
2921 }
2922 if (space_part) {
2923 /* Space ship part build */
2924 send_spaceship_info(pplayer, nullptr);
2925 } else {
2926 /* Update city data. */
2927 if (city_refresh(pcity)) {
2929 }
2930 }
2931
2932 /* Move to the next thing in the worklist */
2933 choose_build_target(pplayer, pcity);
2934 }
2935
2936 return TRUE;
2937}
2938
2939/**********************************************************************/
2948static struct unit *city_create_unit(struct city *pcity,
2949 const struct unit_type *utype,
2950 struct citizens_reduction *red)
2951{
2952 struct player *pplayer = city_owner(pcity);
2953 struct unit *punit;
2954 int saved_unit_id;
2955 int pop_cost = utype_pop_value(utype, pcity);
2956
2959 pcity->id, -1, -1);
2960 pplayer->score.units_built++;
2961
2962 if (pop_cost > 0 && pcity->nationality != nullptr) {
2963 /* We don't reduce city size in-place to keep it correct and
2964 * existing at all while we call the following callback.
2965 * We want citizens_unit_nationality() to adjust 'red' even when
2966 * we are not setting unit nationality based on the return */
2967 struct player *nat = citizens_unit_nationality(pcity, pop_cost, red);
2968
2971 }
2972 } else if (red) {
2973 red->change = 0;
2974 }
2975
2976 (void) place_unit(punit, pplayer, pcity, nullptr, FALSE);
2978
2979 /* If city has a rally point set, give the unit a move order. */
2980 if (pcity->rally_point.length) {
2982 punit->orders.length = pcity->rally_point.length;
2983 punit->orders.vigilant = pcity->rally_point.vigilant;
2984 punit->orders.list = fc_malloc(pcity->rally_point.length
2985 * sizeof(struct unit_order));
2986 memcpy(punit->orders.list, pcity->rally_point.orders,
2987 pcity->rally_point.length * sizeof(struct unit_order));
2988 }
2989
2990 /* This might destroy pcity and/or punit: */
2991 script_server_signal_emit("unit_built", punit, pcity);
2992
2994 return punit;
2995 } else {
2996 return nullptr;
2997 }
2998}
2999
3000/**********************************************************************/
3009static bool city_build_unit(struct player *pplayer, struct city *pcity)
3010{
3011 const struct unit_type *utype;
3012 struct worklist *pwl = &pcity->worklist;
3014 int saved_city_id = pcity->id;
3015 const struct civ_map *nmap = &(wld.map);
3016
3017 fc_assert_ret_val(pcity->production.kind == VUT_UTYPE, FALSE);
3018
3019 /* If the city has already bought a unit which is now obsolete, don't try
3020 * to upgrade the production. The new unit might require more shields, which
3021 * would be bad if it was bought to urgently defend a city. (Equally it
3022 * might be the same cost or cheaper, but tough; you hurried the unit so
3023 * you miss out on technological advances.) */
3026 }
3027
3028 utype = pcity->production.value.utype;
3030
3031 /* We must make a special case for barbarians here, because they are
3032 so dumb. Really. They don't know the prerequisite techs for units
3033 they build!! - Per */
3035 && !is_barbarian(pplayer)) {
3037 _("%s is building %s, which is no longer available."),
3039
3040 /* Log before signal emitting, so pointers are certainly valid */
3041 log_verbose("%s %s tried to build %s, which is not available.",
3044 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3045 "unavailable");
3046 return city_exist(saved_city_id);
3047 }
3048
3049 if (pcity->shield_stock >= unit_shield_cost
3051 int pop_cost = utype_pop_value(utype, pcity);
3052 struct unit *punit;
3053
3054 /* Should we disband the city? -- Massimo */
3055 if (city_size_get(pcity) == pop_cost
3057 return !disband_city(pcity);
3058 }
3059
3060 if (city_size_get(pcity) <= pop_cost) {
3062 /* TRANS: city ... utype ... size ... pop_cost */
3063 _("%s can't build %s yet. "
3064 "(city size: %d, unit population cost: %d)"),
3066 city_size_get(pcity), pop_cost);
3067 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3068 "pop_cost");
3069 return city_exist(saved_city_id);
3070 }
3071
3072 fc_assert(pop_cost == 0 || city_size_get(pcity) >= pop_cost);
3073
3074 /* don't update turn_last_built if we returned above */
3075 pcity->turn_last_built = game.info.turn;
3076
3077 /* check if we can build more than one unit (effect City_Build_Slots) */
3079
3080 /* We should be able to build at least one (by checks above) */
3081 fc_assert(num_units >= 1);
3082
3083 for (i = 0; i < num_units; i++) {
3085
3087
3088 /* Check if the city still exists (script might have removed it).
3089 * If not, we assume any effects / announcements done below were
3090 * already replaced by the script if necessary. */
3091 if (!city_exist(saved_city_id)) {
3092 break;
3093 }
3094
3095 if (punit) {
3096 if (punit->carrying
3099 /* TRANS: <city> is finished building <unit>, carrying <goods>. */
3100 _("%s is finished building %s, carrying %s."),
3103 } else {
3105 /* TRANS: <city> is finished building <unit/building>. */
3106 _("%s is finished building %s."),
3108 }
3109 }
3110
3111 /* After we created the unit remove the citizen. This will also
3112 * rearrange the worker to take into account the extra resources
3113 * (food) needed. */
3114 if (pop_cost > 0) {
3115 /* This won't disband city due to pop_cost, but script might
3116 * still destroy city. */
3118 /* If the city has changed its nationalities during
3119 * "unit_built" signal, we take some other citizens instead */
3120 if (!city_reduce_size(pcity, pop_cost, nullptr, "unit_built")) {
3121 break;
3122 }
3123 }
3124
3125 /* to eliminate micromanagement, we only subtract the unit's cost */
3126 /* signals could change the prod stock! */
3127 if ((pcity->before_change_shields -= unit_shield_cost) < 0) {
3128 pcity->before_change_shields = 0;
3129 }
3130 if ((pcity->shield_stock -= unit_shield_cost) < 0) {
3131 log_normal("City %s (%s) has built %s but has no %d shields "
3132 "for it, nullifying shield stock", city_name_get(pcity),
3133 player_name(pplayer), utype_rule_name(utype),
3135 pcity->shield_stock = 0;
3136 }
3137
3138 if (pop_cost > 0) {
3139 /* Additional message if the unit has population cost. */
3141 ftc_server,
3142 /* TRANS: "<unit> cost... <city> shrinks..."
3143 * Plural in "%d population", not "size %d". */
3144 PL_("%s cost %d population. %s shrinks to size %d.",
3145 "%s cost %d population. %s shrinks to size %d.",
3146 pop_cost),
3147 utype_name_translation(utype), pop_cost,
3149 }
3150
3151 if (i != 0 && worklist_length(pwl) > 0) {
3152 /* remove the build unit from the worklist; it has to be one less
3153 * than units build to preserve the next build target from the
3154 * worklist */
3155 worklist_remove(pwl, 0);
3156 }
3157 } /* for */
3158
3160 if (pcity->rally_point.length && !pcity->rally_point.persistent) {
3162 }
3163
3164 /* Done building this unit; time to move on to the next. */
3165 choose_build_target(pplayer, pcity);
3166 }
3167 } /* if */
3168
3169 return city_exist(saved_city_id);
3170}
3171
3172/**********************************************************************/
3175static bool city_build_stuff(struct player *pplayer, struct city *pcity)
3176{
3177 if (!city_distribute_surplus_shields(pplayer, pcity)) {
3178 return FALSE;
3179 }
3180
3183
3184 switch (pcity->production.kind) {
3185 case VUT_IMPROVEMENT:
3186 return city_build_building(pplayer, pcity);
3187 case VUT_UTYPE:
3188 return city_build_unit(pplayer, pcity);
3189 default:
3190 /* Must never happen! */
3192 break;
3193 };
3194
3195 return FALSE;
3196}
3197
3198/**********************************************************************/
3208static bool sell_random_building(struct player *pplayer,
3209 struct cityimpr_list *imprs)
3210{
3211 struct cityimpr *pcityimpr;
3212 int r;
3213
3214 fc_assert_ret_val(pplayer != nullptr, FALSE);
3215
3216 if (!imprs || cityimpr_list_size(imprs) == 0) {
3217 return FALSE;
3218 }
3219
3222
3224 ftc_server,
3225 _("Can't afford to maintain %s in %s, building sold!"),
3227 city_link(pcityimpr->pcity));
3228 log_debug("%s: sold building (%s)", player_name(pplayer),
3230
3231 do_sell_building(pplayer, pcityimpr->pcity, pcityimpr->pimprove, "cant_maintain");
3232
3234
3235 /* Get back the gold upkeep that was already paid this turn. */
3237 pcityimpr->pimprove);
3238
3240
3242
3243 return TRUE;
3244}
3245
3246/**********************************************************************/
3254static void uk_rem_gold_callback(struct unit *punit)
3255{
3256 int gold_upkeep;
3257
3258 /* Remove the unit from uk_rem_gold. */
3260
3261 gold_upkeep = punit->server.upkeep_paid[O_GOLD];
3262
3263 /* All units in uk_rem_gold should have gold upkeep! */
3264 fc_assert_ret_msg(gold_upkeep > 0, "%s has %d gold upkeep",
3265 unit_rule_name(punit), gold_upkeep);
3266
3267 /* Get the upkeep gold back. */
3268 unit_owner(punit)->economic.gold += gold_upkeep;
3269}
3270
3271/**********************************************************************/
3275static void uk_rem_gold_append(struct unit *punit)
3276{
3277 /* Make the unit aware that it is on the uk_rem_gold list. */
3279
3280 /* Add the unit to the list. */
3282}
3283
3284/**********************************************************************/
3288static void unit_list_referred_destroy(struct unit_list *punitlist)
3289{
3291 /* Clear the unit's knowledge of the list. */
3294
3295 /* Destroy the list it self. */
3297}
3298
3299/**********************************************************************/
3311static struct unit *sell_random_unit(struct player *pplayer,
3312 struct unit_list *punitlist)
3313{
3314 struct unit *punit;
3315 int r;
3316 struct unit_list *cargo;
3317
3318 fc_assert_ret_val(pplayer != nullptr, nullptr);
3319
3320 if (!punitlist || unit_list_size(punitlist) == 0) {
3321 return nullptr;
3322 }
3323
3326
3327 cargo = unit_list_new();
3328
3329 /* Check if unit is transporting other units from punitlist,
3330 * and sell one of those (recursively) instead.
3331 * Note that in case of recursive transports we have to iterate
3332 * also through those middle transports that themselves are not in
3333 * punitlist. */
3335 /* Optimization, do not iterate over punitlist
3336 * if we are sure that pcargo is not in it. */
3337 if (pcargo->server.upkeep_paid[O_GOLD] > 0) {
3339 if (pcargo == p2) {
3340 unit_list_append(cargo, pcargo);
3341 }
3343 }
3345
3346 if (unit_list_size(cargo) > 0) {
3347 /* Recursively sell. Note that cargo list has both
3348 * leaf units and middle transports in case of
3349 * recursive transports. */
3350 struct unit *ret = sell_random_unit(pplayer, cargo);
3351
3352 unit_list_destroy(cargo);
3353
3355
3356 return ret;
3357 }
3358
3359 unit_list_destroy(cargo);
3360
3361 {
3362 const char *punit_link = unit_tile_link(punit);
3363#ifdef FREECIV_DEBUG
3364 const char *punit_logname = unit_rule_name(punit);
3365#endif /* FREECIV_DEBUG */
3366 struct tile *utile = unit_tile(punit);
3367
3371
3372 /* The gold was paid back when the unit removal made
3373 * uk_rem_gold_callback() run as the unit's removal call back. */
3374
3375 notify_player(pplayer, utile, E_UNIT_LOST_MISC, ftc_server,
3376 _("Not enough gold. %s disbanded."),
3377 punit_link);
3378 log_debug("%s: unit sold (%s)", player_name(pplayer),
3380 } else {
3381 /* Not able to get rid of punit */
3382 return nullptr;
3383 }
3384 }
3385
3387
3388 return punit;
3389}
3390
3391/**********************************************************************/
3395{
3396 struct cityimpr_list *pimprlist;
3397 bool sell_unit = TRUE;
3398
3399 if (!pplayer) {
3400 return FALSE;
3401 }
3402
3405
3406 city_list_iterate(pplayer->cities, pcity) {
3407 city_built_iterate(pcity, pimprove) {
3408 if (can_city_sell_building(pcity, pimprove)) {
3409 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3410
3411 ci->pcity = pcity;
3412 ci->pimprove = pimprove;
3414 }
3417
3418 unit_list_iterate(pplayer->units, punit) {
3419 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3421 }
3423
3424 while (pplayer->economic.gold < 0
3426 || unit_list_size(uk_rem_gold) > 0)) {
3428 || unit_list_size(uk_rem_gold) == 0) {
3430 } else {
3431 sell_random_unit(pplayer, uk_rem_gold);
3432 }
3434 }
3435
3436 /* Free remaining entries from list */
3438 FC_FREE(pimpr);
3440
3441 if (pplayer->economic.gold < 0) {
3442 /* If we get here it means the player has
3443 * negative gold. This should never happen. */
3444 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3445 player_name(pplayer), player_number(pplayer));
3446 }
3447
3450
3451 return pplayer->economic.gold >= 0;
3452}
3453
3454/**********************************************************************/
3458{
3459 if (!pplayer) {
3460 return FALSE;
3461 }
3462
3464
3465 unit_list_iterate(pplayer->units, punit) {
3466 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3468 }
3470
3471 while (pplayer->economic.gold < 0
3472 && sell_random_unit(pplayer, uk_rem_gold)) {
3473 /* All done in sell_random_unit() */
3474 }
3475
3476 if (pplayer->economic.gold < 0) {
3477 /* If we get here it means the player has
3478 * negative gold. This should never happen. */
3479 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3480 player_name(pplayer), player_number(pplayer));
3481 }
3482
3484
3485 return pplayer->economic.gold >= 0;
3486}
3487
3488/**********************************************************************/
3492{
3493 struct player *pplayer;
3494 struct cityimpr_list *pimprlist;
3495
3496 if (!pcity) {
3497 return TRUE;
3498 }
3499
3500 pplayer = city_owner(pcity);
3502
3503 /* Create a vector of all buildings that can be sold. */
3504 city_built_iterate(pcity, pimprove) {
3505 if (can_city_sell_building(pcity, pimprove)) {
3506 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3507
3508 ci->pcity = pcity;
3509 ci->pimprove = pimprove;
3511 }
3513
3514 /* Try to sell some buildings. */
3515 while (pplayer->economic.gold < 0
3516 && sell_random_building(pplayer, pimprlist)) {
3517 /* all done in sell_random_building */
3518 }
3519
3520 /* Free remaining entries from list */
3522 FC_FREE(pimpr);
3524
3526
3527 return pplayer->economic.gold >= 0;
3528}
3529
3530/**********************************************************************/
3539{
3540 struct player *pplayer;
3541
3542 if (!pcity) {
3543 return TRUE;
3544 }
3545
3546 pplayer = city_owner(pcity);
3548
3549 /* Create a vector of all supported units with gold upkeep. */
3550 unit_list_iterate(pcity->units_supported, punit) {
3551 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3553 }
3555
3556 /* Still not enough gold, so try "selling" some units. */
3557 while (pplayer->economic.gold < 0
3558 && sell_random_unit(pplayer, uk_rem_gold)) {
3559 /* All done in sell_random_unit() */
3560 }
3561
3562 /* If we get here the player has negative gold, but hopefully
3563 * another city will be able to pay the deficit, so continue. */
3564
3566
3567 return pplayer->economic.gold >= 0;
3568}
3569
3570/**********************************************************************/
3573static bool place_pollution(struct city *pcity, enum extra_cause cause)
3574{
3575 struct tile *ptile;
3576 struct tile *pcenter = city_tile(pcity);
3577 int city_radius_sq = city_map_radius_sq_get(pcity);
3578 int k = 100;
3579 const struct civ_map *nmap = &(wld.map);
3580
3581 while (k > 0) {
3582 /* Place pollution on a random city tile */
3583 int cx, cy;
3584 int tile_id = fc_rand(city_map_tiles(city_radius_sq));
3585 struct extra_type *pextra;
3586
3587 city_tile_index_to_xy(&cx, &cy, tile_id, city_radius_sq);
3588
3589 /* Check for a real map position */
3590 if (!(ptile = city_map_to_tile(nmap, pcenter, city_radius_sq, cx, cy))) {
3591 continue;
3592 }
3593
3594 pextra = rand_extra_for_tile(ptile, cause, FALSE);
3595
3596 if (pextra != nullptr && !tile_has_extra(ptile, pextra)) {
3597 tile_add_extra(ptile, pextra);
3598 update_tile_knowledge(ptile);
3599
3600 return TRUE;
3601 }
3602 k--;
3603 }
3604 log_debug("pollution not placed: city: %s", city_name_get(pcity));
3605
3606 return FALSE;
3607}
3608
3609/**********************************************************************/
3612static void check_pollution(struct city *pcity)
3613{
3614 if (fc_rand(100) < pcity->pollution) {
3617 _("Pollution near %s."), city_link(pcity));
3618 }
3619 }
3620}
3621
3622/**********************************************************************/
3629int city_incite_cost(struct player *pplayer, struct city *pcity)
3630{
3631 int dist, size;
3632 double cost; /* Intermediate values can get very large */
3633
3634 /* Gold factor */
3635 cost = city_owner(pcity)->economic.gold + game.server.base_incite_cost;
3636
3641
3642 /* Buildings */
3643 city_built_iterate(pcity, pimprove) {
3644 cost += impr_build_shield_cost(pcity, pimprove)
3647
3648 /* Stability bonuses */
3649 if (!city_unhappy(pcity)) {
3650 cost *= 2;
3651 }
3652 if (city_celebrating(pcity)) {
3653 cost *= 2;
3654 }
3655
3656 /* Buy back is cheap, conquered cities are also cheap */
3658 if (city_owner(pcity) != pcity->original) {
3659 if (pplayer == pcity->original) {
3660 cost /= 2; /* Buy back: 50% price reduction */
3661 } else {
3662 cost = cost * 2 / 3; /* Buy conquered: 33% price reduction */
3663 }
3664 }
3665 }
3666
3667 /* Distance from capital */
3668 /* Max penalty. Applied if there is no capital, or it's even further away. */
3669 dist = 32;
3671 if (is_capital(capital)) {
3672 int tmp = map_distance(capital->tile, pcity->tile);
3673
3674 if (tmp < dist) {
3675 dist = tmp;
3676 }
3677 }
3679
3683 - pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] * 3);
3684 cost *= size;
3686 cost = cost / (dist + 3);
3687
3689 int cost_per_citizen = cost / pcity->size;
3691 int tgt_cit = citizens_nation_get(pcity, pplayer->slot);
3692 int third_party = pcity->size - natives - tgt_cit;
3693
3694 cost = cost_per_citizen * (natives + 0.7 * third_party + 0.5 * tgt_cit);
3695 }
3696
3698 cost /= 100;
3699
3702 } else {
3703 return cost;
3704 }
3705}
3706
3707/**********************************************************************/
3711{
3712 /* Remember what this city is building last turn, so that on the next turn
3713 * the player can switch production to something else and then change it
3714 * back without penalty. This has to be updated _before_ production for
3715 * this turn is calculated, so that the penalty will apply if the player
3716 * changes production away from what has just been completed. This makes
3717 * sense if you consider what this value means: all the shields in the
3718 * city have been dedicated toward the project that was chosen last turn,
3719 * so the player shouldn't be penalized if the governor has to pick
3720 * something different. See city_change_production_penalty(). */
3721 pcity->changed_from = pcity->production;
3722
3723 log_debug("In %s, building %s. Beg of Turn shields = %d",
3725 pcity->before_change_shields);
3726}
3727
3728/**********************************************************************/
3732{
3733 pcity->disbanded_shields = 0;
3734 pcity->caravan_shields = 0;
3735}
3736
3737/**********************************************************************/
3742{
3744 pcity->before_change_shields = 0;
3745}
3746
3747/**********************************************************************/
3750static void update_city_activity(struct city *pcity)
3751{
3752 struct player *pplayer;
3753 struct government *gov;
3754 bool is_happy;
3755 bool is_celebrating;
3756
3757 if (!pcity) {
3758 return;
3759 }
3760
3761 pplayer = city_owner(pcity);
3765
3766 if (city_refresh(pcity)) {
3768 }
3769
3770 /* Reporting of celebrations rewritten, copying the treatment of disorder below,
3771 with the added rapture rounds count. 991219 -- Jing */
3772 if (city_build_stuff(pplayer, pcity)) {
3773 int saved_id;
3774 int revolution_turns;
3775
3776 pcity->history += city_history_gain(pcity);
3777
3778 /* History can decrease, but never go below zero */
3779 pcity->history = MAX(pcity->history, 0);
3780
3781 /* Keep old behavior when building new improvement could keep
3782 city celebrating */
3783 if (!is_happy) {
3785 }
3786
3788 pcity->rapture++;
3789
3790 /* Update city's celebrating counters */
3792 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3793 pcity->counter_values[pcount->index]++;
3794 }
3796
3797 if (pcity->rapture == 1) {
3799 _("Celebrations in your honor in %s."),
3800 city_link(pcity));
3801 }
3802 } else {
3803 if (pcity->rapture != 0) {
3805 _("Celebrations canceled in %s."),
3806 city_link(pcity));
3807 }
3808
3809 /* Update city's celebrating counters */
3811 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3812 pcity->counter_values[pcount->index] = 0;
3813 }
3815 pcity->rapture = 0;
3816 }
3817 pcity->was_happy = is_happy;
3818
3819 /* Handle the illness. */
3820 if (game.info.illness_on) {
3821 /* Recalculate city illness; illness due to trade has to be saved
3822 * within the city struct, as the client does not have all
3823 * the data to calculate it */
3824 pcity->server.illness
3825 = city_illness_calc(pcity, nullptr, nullptr,
3826 &(pcity->illness_trade), nullptr);
3827
3829 if (!city_illness_strike(pcity)) {
3830 /* Illness destroyed the city */
3831 return;
3832 }
3833 }
3834 }
3835
3836 /* City population updated here, after the rapture stuff above. --Jing */
3837 saved_id = pcity->id;
3838 pcity->had_famine = FALSE;
3839 city_populate(pcity, pplayer);
3840 if (player_city_by_number(pplayer, saved_id) == nullptr) {
3841 return;
3842 }
3843
3844 pcity->did_sell = FALSE;
3845 pcity->did_buy = FALSE;
3846 pcity->airlift = city_airlift_max(pcity);
3847 update_bulbs(pplayer, pcity->prod[O_SCIENCE], FALSE, FALSE);
3848
3850
3851 /* Update the treasury. */
3852 pplayer->economic.gold += pcity->surplus[O_GOLD];
3853
3854 /* FIXME: Nation level upkeep should be paid after ALL cities
3855 * have been processed, not after each individual city. */
3857 /* Unit upkeep was not included in city balance ->
3858 * not reduced from the city surplus. */
3860
3862 /* Building upkeep was not included in city balance ->
3863 * not reduced from the city surplus. */
3865 }
3866 }
3867
3868 /* Remember how much gold upkeep each unit was paid. */
3869 unit_list_iterate(pcity->units_supported, punit) {
3872
3873 if (pplayer->economic.gold < 0) {
3874 /* Not enough gold - we have to sell some buildings, and if that
3875 * is not enough, disband units with gold upkeep, taking into
3876 * account the setting of 'game.info.gold_upkeep_style':
3877 * GOLD_UPKEEP_CITY: Cities pay for buildings and units.
3878 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
3879 * for units.
3880 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
3881 switch (game.info.gold_upkeep_style) {
3882 case GOLD_UPKEEP_CITY:
3883 case GOLD_UPKEEP_MIXED:
3887 }
3888 break;
3889 case GOLD_UPKEEP_NATION:
3890 break;
3891 }
3892 }
3893
3895 if (city_unhappy(pcity)) {
3896 const char *revomsg;
3897
3898 pcity->anarchy++;
3899
3901 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3902 pcity->counter_values[pcount->index]++;
3903 }
3905
3906 if (pcity->anarchy == revolution_turns) {
3907 /* Revolution next turn if not dealt with */
3908 /* TRANS: preserve leading space; this string will be appended to
3909 * another sentence */
3910 revomsg = _(" Unrest threatens to spread beyond the city.");
3911 } else {
3912 revomsg = "";
3913 }
3914 if (pcity->anarchy == 1) {
3916 /* TRANS: second %s is an optional extra sentence */
3917 _("Civil disorder in %s.%s"),
3919 } else {
3921 /* TRANS: second %s is an optional extra sentence */
3922 _("CIVIL DISORDER CONTINUES in %s.%s"),
3924 }
3925 } else {
3926 if (pcity->anarchy != 0) {
3928 _("Order restored in %s."),
3929 city_link(pcity));
3930 }
3931 pcity->anarchy = 0;
3932
3934 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3935 pcity->counter_values[pcount->index] = 0;
3936 }
3938 }
3940
3941 send_city_info(nullptr, pcity);
3942
3943 if (revolution_turns > 0 && pcity->anarchy > revolution_turns) {
3945 /* TRANS: %s - government form, e.g., Democracy */
3946 _("The people have overthrown your %s, "
3947 "your country is in turmoil."),
3950 }
3951 if (city_refresh(pcity)) {
3953 }
3955 }
3956}
3957
3958/**********************************************************************/
3961static bool city_illness_check(const struct city * pcity)
3962{
3963 if (fc_rand(1000) < pcity->server.illness) {
3964 return TRUE;
3965 }
3966
3967 return FALSE;
3968}
3969
3970/**********************************************************************/
3974static bool disband_city(struct city *pcity)
3975{
3976 struct player *pplayer = city_owner(pcity);
3977 struct tile *ptile = pcity->tile;
3978 struct city *rcity = nullptr;
3979 const struct unit_type *utype = pcity->production.value.utype;
3980 struct unit *punit;
3981 int saved_id = pcity->id;
3982
3983 /* Find closest city other than pcity */
3984 rcity = find_closest_city(ptile, pcity, pplayer, FALSE, FALSE, FALSE, TRUE,
3985 FALSE, nullptr);
3986
3987 if (!rcity) {
3988 /* What should we do when we try to disband our only city? */
3989 notify_player(pplayer, ptile, E_CITY_CANTBUILD, ftc_server,
3990 _("%s can't build %s yet, "
3991 "as we can't disband our only city."),
3993 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3994 "pop_cost");
3995 if (!city_exist(saved_id)) {
3996 /* Script decided to remove even the last city */
3997 return TRUE;
3998 } else {
3999 return FALSE;
4000 }
4001 }
4002
4004
4005 /* "unit_built" script handler may have destroyed city. If so, we
4006 * assume something sensible happened to its units, and that the
4007 * script took care of announcing unit creation if required. */
4008 if (city_exist(saved_id)) {
4009 /* Shift all the units supported by pcity (including the new unit)
4010 * to rcity. transfer_city_units() does not make sure no units are
4011 * left floating without a transport, but since all units are
4012 * transferred this is not a problem. */
4013 transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity,
4014 pcity, -1, TRUE);
4015
4016 if (punit) {
4017 notify_player(pplayer, ptile, E_UNIT_BUILT, ftc_server,
4018 /* TRANS: "<city> is disbanded into Settler." */
4019 _("%s is disbanded into %s."),
4021 }
4022
4023 script_server_signal_emit("city_destroyed", pcity, pcity->owner, NULL);
4024
4025 if (!city_exist(saved_id)) {
4026 /* Already removed during the script */
4027 return TRUE;
4028 }
4030
4031 /* Since we've removed the city, we don't need to worry about
4032 * charging for production, disabling rally points, etc. */
4033 }
4034
4035 return TRUE;
4036}
4037
4038/**********************************************************************/
4086static float city_migration_score(struct city *pcity)
4087{
4088 float score = 0.0;
4089 int build_shield_cost = 0;
4090 bool has_wonder = FALSE;
4091
4092 if (!pcity) {
4093 return score;
4094 }
4095
4096 if (pcity->server.mgr_score_calc_turn == game.info.turn) {
4097 /* up-to-date migration score */
4098 return pcity->server.migration_score;
4099 }
4100
4101 /* feeling of the citizens */
4102 score = (city_size_get(pcity)
4103 + 1.00 * pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
4104 + 0.00 * pcity->feel[CITIZEN_CONTENT][FEELING_FINAL]
4105 - 0.25 * pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
4106 - 0.50 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
4107
4108 /* calculate shield build cost for all buildings */
4109 city_built_iterate(pcity, pimprove) {
4111 if (is_wonder(pimprove)) {
4112 /* this city has a wonder */
4113 has_wonder = TRUE;
4114 }
4116
4117 /* take shield costs of all buidings into account; normalized by 1000 */
4118 score *= (1 + (1 - exp(- (float) MAX(0, build_shield_cost) / 1000)) / 5);
4119 /* take trade into account; normalized by 100 */
4120 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_TRADE]) / 100))
4121 / 5);
4122 /* take luxury into account; normalized by 100 */
4123 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_LUXURY]) / 100))
4124 / 5);
4125 /* take science into account; normalized by 100 */
4126 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_SCIENCE]) / 100))
4127 / 5);
4128
4130
4131 /* Take food into account; the food surplus is clipped to values between
4132 * -10..20 and normalize by 10. Thus, the factor is between 0.9 and 1.2. */
4133 score *= (1 + (float) CLIP(-10, pcity->surplus[O_FOOD], 20) / 10 );
4134
4135 /* Reduce the score due to city illness (plague). The illness is given in
4136 * tenth of percent (0..1000) and normalized by 25. Thus, this factor is
4137 * between 0.6 (ill city) and 1.0 (health city). */
4138 score *= (100 - (float)city_illness_calc(pcity, nullptr, nullptr,
4139 nullptr, nullptr) / 25);
4140
4141 if (has_wonder) {
4142 /* People like wonders */
4143 score *= 1.25;
4144 }
4145
4146 if (is_capital(pcity)) {
4147 /* The capital is a magnet for the citizens */
4148 score *= 1.25;
4149 }
4150
4151 /* Take into account effects */
4152 score *= (1.0 + get_city_bonus(pcity, EFT_MIGRATION_PCT) / 100.0);
4153
4154 log_debug("[M] %s score: %.3f", city_name_get(pcity), score);
4155
4156 /* Set migration score for the city */
4157 pcity->server.migration_score = score;
4158 /* Set the turn, when the score was calculated */
4159 pcity->server.mgr_score_calc_turn = game.info.turn;
4160
4161 return score;
4162}
4163
4164/**********************************************************************/
4171 struct city *pcity_to)
4172{
4174 struct tile *ptile_from, *ptile_to;
4176 const char *nation_from, *nation_to;
4177 struct city *rcity = nullptr;
4178 int to_id = pcity_to->id;
4179 const struct civ_map *nmap = &(wld.map);
4180
4181 if (!pcity_from || !pcity_to) {
4182 return FALSE;
4183 }
4184
4188 /* We copy that, because city_link always returns the same pointer. */
4195
4196 /* Check food supply in the receiver city */
4198 bool migration = FALSE;
4199
4200 if (pcity_to->surplus[O_FOOD] >= game.info.food_cost) {
4201 migration = TRUE;
4202 } else {
4203 /* Check if there is a free tile for the new citizen which, when worked,
4204 * leads to zero or positive food surplus for the enlarged city */
4205 int max_food_tile = -1; /* no free tile */
4206
4208 city_tile(pcity_to), ptile) {
4209 if (city_can_work_tile(pcity_to, ptile)
4210 && tile_worked(ptile) != pcity_to) {
4211 /* Safest assumption is that city won't be celebrating once an
4212 * additional citizen is added */
4215 }
4217 if (max_food_tile >= 0
4218 && pcity_to->surplus[O_FOOD] + max_food_tile >= game.info.food_cost) {
4219 migration = TRUE;
4220 }
4221 }
4222
4223 if (!migration) {
4224 /* Insufficiency food in receiver city; no additional citizens */
4225 if (pplayer_from == pplayer_to) {
4226 /* Migration between one nation */
4228 /* TRANS: From <city1> to <city2>. */
4229 _("Migrants from %s can't go to %s because there is "
4230 "not enough food available!"),
4232 } else {
4233 /* Migration between different nations */
4235 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4236 _("Migrants from %s can't go to %s (%s) because there "
4237 "is not enough food available!"),
4240 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4241 _("Migrants from %s (%s) can't go to %s because there "
4242 "is not enough food available!"),
4244 }
4245
4246 return FALSE;
4247 }
4248 }
4249
4251 /* Receiver city can't grow */
4252 if (pplayer_from == pplayer_to) {
4253 /* Migration between one nation */
4255 /* TRANS: From <city1> to <city2>. */
4256 _("Migrants from %s can't go to %s because it needs "
4257 "an improvement to grow!"),
4259 } else {
4260 /* Migration between different nations */
4262 /* TRANS: From <city1> to <city2> of <city2 nation adjective>. */
4263 _("Migrants from %s can't go to %s (%s) because it "
4264 "needs an improvement to grow!"),
4267 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4268 _("Migrants from %s (%s) can't go to %s because it "
4269 "needs an improvement to grow!"),
4271 }
4272
4273 return FALSE;
4274 }
4275
4276 /* Reduce size of giver */
4277 if (city_size_get(pcity_from) == 1) {
4278
4280 /* Preserve nationality of city's only citizen */
4282 }
4283
4284 /* Do not destroy wonders */
4285 city_built_iterate(pcity_from, pimprove) {
4286 if (is_wonder(pimprove)) {
4287 return FALSE;
4288 }
4290
4291 /* Find closest city other of the same player than pcity_from */
4293 FALSE, FALSE, TRUE, FALSE, nullptr);
4294
4295 if (rcity) {
4296 int id = pcity_from->id;
4297
4298 /* Transfer all units to the closest city */
4300 pcity_from->units_supported, rcity, pcity_from,
4301 -1, TRUE);
4303
4304 script_server_signal_emit("city_size_change", pcity_from,
4305 (lua_Integer)(-1), "migration_from");
4306
4307 if (city_exist(id)) {
4308 script_server_signal_emit("city_destroyed", pcity_from,
4309 pcity_from->owner, nullptr);
4310
4311 if (city_exist(id)) {
4313 }
4314 }
4315
4317 _("%s was disbanded by its citizens."),
4318 name_from);
4319 } else {
4320 /* It's the only city of the nation */
4321 return FALSE;
4322 }
4323 } else {
4324 /* The migrants take half of the food box with them (this prevents
4325 * migration -> grow -> migration -> ... cycles) */
4326 pcity_from->food_stock /= 2;
4327
4329 /* Those citizens that are from the target nation are most
4330 * ones migrating. */
4331 if (citizens_nation_get(pcity_from, pplayer_to->slot) > 0) {
4333 } else if (!citizens_nation_get(pcity_from, pplayer_citizen->slot)) {
4334 /* No native citizens at all in the city, choose random foreigner */
4336
4338 }
4339 /* This should be followed by city_reduce_size(). */
4341 }
4342 city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
4344 if (city_refresh(pcity_from)) {
4346 }
4347 }
4348
4349 /* This should be _before_ the size of the city is increased. Thus, the
4350 * order of the messages is correct (1: migration; 2: increased size). */
4351 if (pplayer_from == pplayer_to) {
4352 /* Migration between one nation */
4354 /* TRANS: From <city1> to <city2>. */
4355 _("Migrants from %s moved to %s in search of a better "
4356 "life."), name_from, name_to);
4357 } else {
4358 /* Migration between different nations */
4360 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4361 _("Migrants from %s moved to %s (%s) in search of a "
4362 "better life."),
4365 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4366 _("Migrants from %s (%s) moved to %s in search of a "
4367 "better life."),
4369 }
4370
4371 /* Increase size of receiver city */
4372 if (city_exist(to_id)) {
4374
4375 if (city_exist(to_id)) {
4378 if (city_refresh(pcity_to)) {
4380 }
4381 if (incr_success) {
4382 script_server_signal_emit("city_size_change", pcity_to,
4383 (lua_Integer)1, "migration_to");
4384 }
4385 }
4386 }
4387
4388 log_debug("[M] T%d migration successful (%s -> %s)",
4390
4391 return TRUE;
4392}
4393
4394/**********************************************************************/
4416{
4417 bool internat = FALSE;
4418
4419 if (!game.server.migration) {
4420 return FALSE;
4421 }
4422
4424 || (game.server.mgr_worldchance <= 0
4425 && game.server.mgr_nationchance <= 0)) {
4426 return FALSE;
4427 }
4428
4429 /* check for migration */
4430 players_iterate(pplayer) {
4431 if (!pplayer->cities) {
4432 continue;
4433 }
4434
4435 if (check_city_migrations_player(pplayer)) {
4436 internat = TRUE;
4437 }
4439
4440 return internat;
4441}
4442
4443/**********************************************************************/
4448 struct player *pplayer = city_owner(pcity);
4449 struct tile *ptile = city_tile(pcity);
4450
4451 fc_assert_ret_val(pcity != nullptr, FALSE);
4452
4453 if (pcity->food_stock > 0) {
4454 pcity->food_stock = 0;
4455
4456 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4457 /* TRANS: %s is a city name */
4458 _("All stored food destroyed in %s."), city_link(pcity));
4459
4460 return TRUE;
4461 }
4462
4463 return FALSE;
4464}
4465
4466/**********************************************************************/
4469static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
4470{
4471 struct player *pplayer = city_owner(pcity);
4472 struct tile *ptile = city_tile(pcity);
4474
4476
4477 notify_player(pplayer, ptile, E_DISASTER,
4478 ftc_server,
4479 /* TRANS: Disasters such as Earthquake */
4480 _("%s was hit by %s."), city_name_get(pcity),
4482
4484 if (pplayer->economic.gold > 0 && pcity->prod[O_TRADE] > 0) {
4485 int amount = pcity->prod[O_TRADE] * 5;
4486
4487 amount = MIN(pplayer->economic.gold, amount);
4488 pplayer->economic.gold -= amount;
4489 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4490 PL_("Robbery in %s. %d gold stolen.",
4491 "Robbery in %s. %d gold stolen.", amount),
4494 }
4495 }
4496
4499 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4500 _("Pollution near %s."), city_link(pcity));
4502 }
4503 }
4504
4507 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4508 _("Fallout near %s."), city_link(pcity));
4510 }
4511 }
4512
4515 && pcity->size > 1)) {
4516 if (!city_reduce_size(pcity, 1, nullptr, "disaster")) {
4517 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4518 /* TRANS: "Industrial Accident destroys Bogota entirely." */
4519 _("%s destroys %s entirely."),
4521 pcity = nullptr;
4522 } else {
4523 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4524 /* TRANS: "Nuclear Accident ... Montreal." */
4525 _("%s causes population loss in %s."),
4527 }
4528
4530 }
4531
4533 int total = 0;
4534 struct impr_type *imprs[B_LAST];
4535
4536 city_built_iterate(pcity, pimprove) {
4537 if (is_improvement(pimprove)
4538 && !improvement_has_flag(pimprove, IF_DISASTER_PROOF)) {
4539 imprs[total++] = pimprove;
4540 }
4542
4543 if (total > 0) {
4544 int num = fc_rand(total);
4545
4546 building_lost(pcity, imprs[num], "disaster", nullptr);
4547
4548 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4549 /* TRANS: second %s is the name of a city improvement */
4550 _("%s destroys %s in %s."),
4553 city_link(pcity));
4554
4556 }
4557 }
4558
4562 }
4563 }
4564
4566 if (pcity->shield_stock > 0) {
4567 char prod[256];
4568
4569 pcity->shield_stock = 0;
4570 nullify_prechange_production(pcity); /* Make it impossible to recover */
4571
4572 universal_name_translation(&pcity->production, prod, sizeof(prod));
4573 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4574 /* TRANS: "Production of Colossus in Rhodes destroyed." */
4575 _("Production of %s in %s destroyed."),
4576 prod, city_link(pcity));
4577
4579 }
4580 }
4581
4582 script_server_signal_emit("disaster_occurred", pdis, pcity,
4584 script_server_signal_emit("disaster", pdis, pcity);
4585}
4586
4587/**********************************************************************/
4591{
4592 if (game.info.disasters == 0) {
4593 /* Shortcut out as no disaster is possible. */
4594 return;
4595 }
4596
4597 players_iterate(pplayer) {
4598 /* Safe city iterator needed as disaster may destroy city */
4599 city_list_iterate_safe(pplayer->cities, pcity) {
4600 int id = pcity->id;
4601
4603 if (city_exist(id)) {
4604 /* City survived earlier disasters. */
4605 int probability = game.info.disasters * pdis->frequency;
4606 int result = fc_rand(DISASTER_BASE_RARITY);
4607
4608 if (result < probability) {
4611 }
4612 }
4613 }
4617}
4618
4619/**********************************************************************/
4627static bool check_city_migrations_player(const struct player *pplayer)
4628{
4632 float score_from, score_tmp, weight;
4633 int dist, mgr_dist;
4634 bool internat = FALSE;
4635
4636 /* Check for each city
4637 * city_list_iterate_safe() must be used because we could
4638 * remove one city from the list */
4640 /* No migration out of the capital */
4641 if (is_capital(pcity)) {
4642 continue;
4643 }
4644
4645 /* Check only each (game.server.mgr_turninterval) turn
4646 * (counted from the funding turn) and do not migrate
4647 * the same turn a city is founded */
4648 if (game.info.turn == pcity->turn_founded
4649 || ((game.info.turn - pcity->turn_founded)
4650 % game.server.mgr_turninterval) != 0) {
4651 continue;
4652 }
4653
4656 best_city_player = nullptr;
4657 best_city_world = nullptr;
4658
4659 /* Score of the actual city
4660 * taking into account a persistence factor of 3 */
4662
4663 log_debug("[M] T%d check city: %s score: %6.3f (%s)",
4665 player_name(pplayer));
4666
4667 /* Consider all cities within the maximal possible distance
4668 * (= CITY_MAP_MAX_RADIUS + GAME_MAX_MGR_DISTANCE) */
4671 acity = tile_city(ptile);
4672
4673 if (!acity || acity == pcity) {
4674 /* No city or the city in the center */
4675 continue;
4676 }
4677
4678 /* Calculate the migration distance. The value of
4679 * game.server.mgr_distance is added to the current city radius. If the
4680 * distance between both cities is lower or equal than this value,
4681 * migration is possible. */
4684
4685 /* distance between the two cities */
4687
4688 if (dist > mgr_dist) {
4689 /* Too far away */
4690 continue;
4691 }
4692
4693 /* Score of the second city, weighted by the distance */
4694 weight = ((float) (mgr_dist + 1 - dist) / (float) (mgr_dist + 1));
4696
4697 log_debug("[M] T%d - compare city: %s (%s) dist: %d mgr_dist: %d "
4698 "score: %6.3f", game.info.turn, city_name_get(acity),
4700
4701 if (game.server.mgr_nationchance > 0 && city_owner(acity) == pplayer) {
4702 /* Migration between cities of the same owner */
4704 /* Select the best! */
4707
4708 log_debug("[M] T%d - best city (player): %s (%s) score: "
4709 "%6.3f (> %6.3f)", game.info.turn,
4712 }
4713 } else if (game.server.mgr_worldchance > 0
4714 && city_owner(acity) != pplayer) {
4715 /* Migration between cities of different owners */
4717 /* Modify the score if citizens could migrate to a city of their
4718 * original nation. */
4719 if (citizens_nation_get(pcity, city_owner(acity)->slot) > 0) {
4720 score_tmp *= 2;
4721 }
4722 }
4723
4725 /* Select the best! */
4728
4729 log_debug("[M] T%d - best city (world): %s (%s) score: "
4730 "%6.3f (> %6.3f)", game.info.turn,
4734 }
4735 }
4737
4738 if (best_city_player != nullptr) {
4739 /* First, do the migration within one nation */
4740 if (fc_rand(100) >= game.server.mgr_nationchance) {
4741 /* No migration */
4742 /* N.B.: city_link() always returns the same pointer. */
4745 _("Citizens of %s are thinking about migrating to %s "
4746 "for a better life."),
4748 } else {
4750 }
4751
4752 /* Stop here */
4753 continue;
4754 }
4755
4756 if (best_city_world != nullptr) {
4757 /* Second, do the migration between all nations */
4758 if (fc_rand(100) >= game.server.mgr_worldchance) {
4759 const char *nname;
4760
4762 /* No migration */
4763 /* N.B.: city_link() always returns the same pointer. */
4766 /* TRANS: <city1> to <city2> (<city2 nation adjective>). */
4767 _("Citizens of %s are thinking about migrating to %s "
4768 "(%s) for a better life."),
4770 } else {
4772 internat = TRUE;
4773 }
4774
4775 /* Stop here */
4776 continue;
4777 }
4779
4780 return internat;
4781}
4782
4783/**********************************************************************/
4787{
4788 pcity->style = city_style(pcity);
4789}
4790
4791/**********************************************************************/
4796{
4798 struct packet_city_update_counters packet;
4799
4800 packet.city = pcity->id;
4801
4803
4804 packet.count = counter_count;
4805 for (i = 0; i < counter_count; i++) {
4806 packet.counters[i] = pcity->counter_values[i];
4807 }
4808
4811}
4812
4813/**********************************************************************/
4816void city_tc_effect_refresh(struct player *pplayer)
4817{
4818 const struct civ_map *nmap = &(wld.map);
4819
4820 city_list_iterate(pplayer->cities, pcity) {
4821 bool changed = FALSE;
4822
4824 city_tile(pcity), ptile, idx, x, y) {
4825 if (ptile->worked == pcity
4826 && get_city_tile_output_bonus(pcity, ptile, nullptr,
4827 EFT_TILE_WORKABLE) <= 0) {
4829 pcity->specialists[DEFAULT_SPECIALIST]++;
4830 changed = TRUE;
4831 }
4833
4834 if (changed) {
4836 send_city_info(nullptr, pcity);
4837 }
4839}
const char * achievement_name_translation(struct achievement *pach)
bool is_action_enabled_city(const struct civ_map *nmap, const action_id wanted_action, const struct city *actor_city)
Definition actions.c:3718
const struct action_auto_perf * action_auto_perf_unit_sel(const enum action_auto_perf_cause cause, const struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action)
const struct action * action_auto_perf_unit_do(const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit, const struct extra_type *target_extra)
void advisor_choose_build(struct player *pplayer, struct city *pcity)
#define n
Definition astring.c:77
int tile_border_source_radius_sq(struct tile *ptile)
Definition borders.c:33
const char * textcalfrag(int frag)
Definition calendar.c:101
const char * textyear(int year)
Definition calendar.c:121
struct player_slot * citizens_random(const struct city *pcity)
Definition citizens.c:190
void citizens_nation_add(struct city *pcity, const struct player_slot *pslot, int add)
Definition citizens.c:104
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
void citizens_reduction_apply(struct city *pcity, const struct citizens_reduction *pchange)
struct player * citizens_unit_nationality(const struct city *pcity, unsigned pop_cost, struct citizens_reduction *pchange)
void citizens_convert(struct city *pcity)
void citizens_update(struct city *pcity, struct player *plr)
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:666
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:834
int city_granary_size(int city_size)
Definition city.c:2180
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:305
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1287
bool is_capital(const struct city *pcity)
Definition city.c:1627
const char * city_name_get(const struct city *pcity)
Definition city.c:1148
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3460
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1303
int city_airlift_max(const struct city *pcity)
Definition city.c:2991
struct output_type * get_output_type(Output_type_id output)
Definition city.c:640
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3477
void city_size_add(struct city *pcity, int add)
Definition city.c:1211
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:730
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:808
bool city_tile_index_to_xy(int *city_map_x, int *city_map_y, int city_tile_index, int city_radius_sq)
Definition city.c:101
bool city_rapture_grow(const struct city *pcity)
Definition city.c:1701
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:824
bool city_unhappy(const struct city *pcity)
Definition city.c:1674
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3423
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:860
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1727
bool city_celebrating(const struct city *pcity)
Definition city.c:1693
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2919
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2060
void city_refresh_from_main_map(const struct civ_map *nmap, struct city *pcity, bool *workers_map)
Definition city.c:3250
bool city_happy(const struct city *pcity)
Definition city.c:1662
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
static int cmp(int v1, int v2)
Definition city.c:325
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1331
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:911
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1022
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:955
int city_map_tiles(int city_radius_sq)
Definition city.c:171
bool city_exist(int id)
Definition city.c:3663
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1504
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:750
void city_rally_point_clear(struct city *pcity)
Definition city.c:3717
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:879
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2972
bool city_can_change_build(const struct city *pcity)
Definition city.c:1089
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:978
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1269
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1248
#define cities_iterate_end
Definition city.h:517
#define city_list_iterate_safe(citylist, _city)
Definition city.h:522
@ CNA_BROADCAST_PENDING
Definition city.h:306
@ CNA_NOT
Definition city.h:304
@ CNA_NORMAL
Definition city.h:305
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:565
#define cities_iterate(pcity)
Definition city.h:512
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:212
@ CITIZEN_ANGRY
Definition city.h:269
@ CITIZEN_HAPPY
Definition city.h:266
@ CITIZEN_CONTENT
Definition city.h:267
@ CITIZEN_UNHAPPY
Definition city.h:268
#define output_type_iterate(output)
Definition city.h:849
#define INCITE_IMPOSSIBLE_COST
Definition city.h:94
#define city_owner(_pcity_)
Definition city.h:564
#define city_tile_iterate_skip_free_worked_end
Definition city.h:220
#define city_list_iterate_end
Definition city.h:510
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:228
#define city_list_iterate_safe_end
Definition city.h:544
@ FEELING_FINAL
Definition city.h:282
#define city_tile_iterate_end
Definition city.h:236
#define city_built_iterate(_pcity, _p)
Definition city.h:838
#define city_built_iterate_end
Definition city.h:844
#define output_type_iterate_end
Definition city.h:855
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3280
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2368
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:856
void sync_cities(void)
Definition citytools.c:3354
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:136
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3479
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3191
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2984
void city_thaw_workers(struct city *pcity)
Definition citytools.c:146
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3082
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3168
void remove_city(struct city *pcity)
Definition citytools.c:1713
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:3010
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2948
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2249
void city_add_improvement_with_gov_notice(struct city *pcity, const struct impr_type *pimprove, const char *format)
Definition citytools.c:3673
void city_map_update_all(struct city *pcity)
Definition citytools.c:3373
void transfer_city_units(struct player *pplayer, struct player *pvictim, struct unit_list *units, struct city *pcity, struct city *exclude_city, int kill_outside, bool verbose)
Definition citytools.c:721
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Definition citytools.c:3294
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3454
#define LOG_BUILD_TARGET
Definition citytools.h:21
static bool city_illness_check(const struct city *pcity)
Definition cityturn.c:3961
static void uk_rem_gold_append(struct unit *punit)
Definition cityturn.c:3275
static void city_refresh_after_city_size_increase(struct city *pcity, struct player *nationality, bool aaw)
Definition cityturn.c:1028
static bool worklist_change_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2349
void remove_obsolete_buildings(struct player *pplayer)
Definition cityturn.c:271
static bool city_build_stuff(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3175
int city_shrink_granary_savings(const struct city *pcity)
Definition cityturn.c:894
static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
Definition cityturn.c:4469
static bool city_distribute_surplus_shields(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2706
static void unit_list_referred_destroy(struct unit_list *punitlist)
Definition cityturn.c:3288
static bool place_pollution(struct city *pcity, enum extra_cause cause)
Definition cityturn.c:3573
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2567
static void uk_rem_gold_callback(struct unit *punit)
Definition cityturn.c:3254
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:367
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:198
static struct unit_list * uk_rem_gold
Definition cityturn.c:94
static bool city_balance_treasury_buildings(struct city *pcity)
Definition cityturn.c:3491
static void update_city_activity(struct city *pcity)
Definition cityturn.c:3750
static void upgrade_unit_prod(struct city *pcity)
Definition cityturn.c:2682
static float city_migration_score(struct city *pcity)
Definition cityturn.c:4086
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3741
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4447
static bool city_increase_size(struct city *pcity, bool natural_growth, Specialist_type_id sid)
Definition cityturn.c:920
bool check_city_migrations(void)
Definition cityturn.c:4415
static void upgrade_building_prod(struct city *pcity)
Definition cityturn.c:2634
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3394
static citizens city_reduce_specialists(struct city *pcity, citizens change)
Definition cityturn.c:720
static void city_global_turn_notify(struct conn_list *dest)
Definition cityturn.c:491
static void city_populate(struct city *pcity, struct player *nationality)
Definition cityturn.c:1121
static void define_orig_production_values(struct city *pcity)
Definition cityturn.c:3710
void city_repair_size(struct city *pcity, int change)
Definition cityturn.c:853
#define cityimpr_list_iterate(cityimprlist, pcityimpr)
Definition cityturn.c:128
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4795
static bool upkeep_kill_unit(struct unit *punit, Output_type_id outp, enum unit_loss_reason wipe_reason, bool wipe_in_the_end)
Definition cityturn.c:688
static bool city_build_building(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2787
static struct unit static const struct impr_type * building_upgrades_to(struct city *pcity, const struct impr_type *pimprove)
Definition cityturn.c:2613
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:578
static struct unit * sell_random_unit(struct player *pplayer, struct unit_list *punitlist)
Definition cityturn.c:3311
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3629
static void nullify_caravan_and_disband_plus(struct city *pcity)
Definition cityturn.c:3731
static bool sell_random_building(struct player *pplayer, struct cityimpr_list *imprs)
Definition cityturn.c:3208
static bool disband_city(struct city *pcity)
Definition cityturn.c:3974
void update_city_activities(struct player *pplayer)
Definition cityturn.c:604
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:764
#define cityimpr_list_iterate_end
Definition cityturn.c:130
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
static void city_turn_notify(const struct city *pcity, struct conn_list *dest, const struct player *cache_for_player)
Definition cityturn.c:513
static void city_shrink_reset_foodbox(struct city *pcity, int new_size)
Definition cityturn.c:907
void apply_cmresult_to_city(struct city *pcity, const struct cm_result *cmr)
Definition cityturn.c:282
bool player_balance_treasury_units(struct player *pplayer)
Definition cityturn.c:3457
void city_style_refresh(struct city *pcity)
Definition cityturn.c:4786
static bool city_balance_treasury_units(struct city *pcity)
Definition cityturn.c:3538
static const struct unit_type * unit_upgrades_to(struct city *pcity, const struct unit_type *id)
Definition cityturn.c:2660
static bool do_city_migration(struct city *pcity_from, struct city *pcity_to)
Definition cityturn.c:4170
static struct city_list * city_refresh_queue
Definition cityturn.c:88
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:183
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4816
static void check_pollution(struct city *pcity)
Definition cityturn.c:3612
void check_disasters(void)
Definition cityturn.c:4590
static void set_default_city_manager(struct cm_parameter *cmp, struct city *pcity)
Definition cityturn.c:314
static citizens city_reduce_workers(struct city *pcity, citizens change)
Definition cityturn.c:740
static bool worklist_item_postpone_req_vec(struct universal *target, struct city *pcity, struct player *pplayer, int saved_id)
Definition cityturn.c:1198
static struct unit * city_create_unit(struct city *pcity, const struct unit_type *utype, struct citizens_reduction *red) fc__attribute((nonnull(1
Definition cityturn.c:2948
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, Specialist_type_id sid, const char *reason)
Definition cityturn.c:1069
void city_refresh_queue_processing(void)
Definition cityturn.c:214
int city_growth_granary_savings(const struct city *pcity)
Definition cityturn.c:880
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:236
static bool check_city_migrations_player(const struct player *pplayer)
Definition cityturn.c:4627
static bool city_build_unit(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3009
void cm_clear_cache(struct city *pcity)
Definition cm.c:322
void cm_init_parameter(struct cm_parameter *dest)
Definition cm.c:2185
struct cm_result * cm_result_new(struct city *pcity)
Definition cm.c:345
void cm_result_destroy(struct cm_result *result)
Definition cm.c:368
void cm_print_result(const struct cm_result *result)
Definition cm.c:2471
void cm_query_result(struct city *pcity, const struct cm_parameter *param, struct cm_result *result, bool negative_ok)
Definition cm.c:2124
void cm_init_emergency_parameter(struct cm_parameter *dest)
Definition cm.c:2203
void cm_print_city(const struct city *pcity)
Definition cm.c:2433
char * incite_cost
Definition comments.c:77
struct player * conn_get_player(const struct connection *pconn)
Definition connection.c:765
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:368
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:358
const char * counter_name_translation(const struct counter *counter)
Definition counters.c:158
int counters_get_city_counters_count(void)
Definition counters.c:74
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
int city_culture(const struct city *pcity)
Definition culture.c:29
int city_history_gain(const struct city *pcity)
Definition culture.c:39
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
const char * disaster_rule_name(struct disaster_type *pdis)
Definition disaster.c:105
bool can_disaster_happen(const struct disaster_type *pdis, const struct city *pcity)
Definition disaster.c:139
const char * disaster_name_translation(struct disaster_type *pdis)
Definition disaster.c:97
bool disaster_has_effect(const struct disaster_type *pdis, enum disaster_effect_id effect)
Definition disaster.c:130
#define disaster_type_iterate(_p)
Definition disaster.h:82
#define DISASTER_BASE_RARITY
Definition disaster.h:46
#define disaster_type_iterate_end
Definition disaster.h:88
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_current_construction_bonus(const struct city *pcity, enum effect_type effect_type, const enum req_problem_type prob_type)
Definition effects.c:1188
int get_city_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:913
struct extra_type * rand_extra_for_tile(struct tile *ptile, enum extra_cause cause, bool generated)
Definition extras.c:283
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define MAX_CITY_NATIONALITIES
Definition fc_types.h:91
int Tech_type_id
Definition fc_types.h:238
unsigned char citizens
Definition fc_types.h:249
@ RPT_CERTAIN
Definition fc_types.h:516
@ RPT_POSSIBLE
Definition fc_types.h:515
int Specialist_type_id
Definition fc_types.h:236
#define MAX_LEN_NAME
Definition fc_types.h:68
#define CITY_MAP_MAX_RADIUS
Definition fc_types.h:85
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
@ O_SCIENCE
Definition fc_types.h:103
@ O_LUXURY
Definition fc_types.h:103
@ O_GOLD
Definition fc_types.h:103
enum output_type_id Output_type_id
Definition fc_types.h:239
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * city_tile_link(const struct city *pcity)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
const char * unit_link(const struct unit *punit)
const char * unit_tile_link(const struct unit *punit)
#define MAX_LEN_LINK
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:106
#define GAME_MAX_MGR_DISTANCE
Definition game.h:538
const char * government_name_translation(const struct government *pgovern)
Definition government.c:145
struct government * government_of_city(const struct city *pcity)
Definition government.c:125
Government_type_id government_number(const struct government *pgovern)
Definition government.c:93
GType type
Definition repodlgs.c:1313
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
int impr_sell_gold(const struct impr_type *pimprove)
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
bool is_convert_improvement(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
const struct impr_type * improvement_replacement(const struct impr_type *pimprove)
#define B_LAST
Definition improvement.h:42
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:206
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_normal(message,...)
Definition log.h:108
#define log_base(level, message,...)
Definition log.h:95
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:209
void lsend_packet_city_update_counters(struct conn_list *dest, const struct packet_city_update_counters *packet)
void lsend_packet_chat_msg(struct conn_list *dest, const struct packet_chat_msg *packet)
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:565
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
int map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:699
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
Definition map.h:373
#define iterate_outward_end
Definition map.h:377
void map_update_border(struct tile *ptile, struct player *owner, int old_radius_sq, int new_radius_sq)
Definition maphand.c:2218
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2250
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1444
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_malloc(sz)
Definition mem.h:34
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:149
struct nation_type * nation_of_city(const struct city *pcity)
Definition nation.c:453
const char * nation_group_name_translation(const struct nation_group *pgroup)
Definition nation.c:1080
const char * nation_plural_translation(const struct nation_type *pnation)
Definition nation.c:159
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
void notify_research(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:393
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void notify_research_embassies(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:433
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
void package_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:168
void event_cache_add_for_player(const struct packet_chat_msg *packet, const struct player *pplayer)
Definition notify.c:645
struct city_list * cities
Definition packhand.c:120
int player_number(const struct player *pplayer)
Definition player.c:826
const char * player_name(const struct player *pplayer)
Definition player.c:885
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1191
const char * diplrel_name_translation(int value)
Definition player.c:1614
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:432
#define players_iterate_end
Definition player.h:552
#define players_iterate(_pplayer)
Definition player.h:547
static bool is_barbarian(const struct player *pplayer)
Definition player.h:499
#define is_ai(plr)
Definition player.h:232
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1148
#define fc_rand(_size)
Definition rand.h:56
const char * universal_rule_name(const struct universal *psource)
bool is_req_active(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, const enum req_problem_type prob_type)
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:276
struct research * research_get(const struct player *pplayer)
Definition research.c:130
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:622
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:171
#define sanity_check_city(x)
Definition sanitycheck.h:42
void script_server_signal_emit(const char *signal_name,...)
const char * ssetv_human_readable(ssetv val, bool present)
static struct setting settings[]
Definition settings.c:1494
#define CLIP(lower, current, upper)
Definition shared.h:57
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
void send_spaceship_info(struct player *src, struct conn_list *dest)
Definition spacerace.c:129
@ SSHIP_STARTED
Definition spaceship.h:84
@ SSHIP_NONE
Definition spaceship.h:84
bool is_normal_specialist_id(Specialist_type_id sp)
Definition specialist.c:196
#define normal_specialist_type_iterate(sp)
Definition specialist.h:89
#define DEFAULT_SPECIALIST
Definition specialist.h:43
#define normal_specialist_type_iterate_end
Definition specialist.h:95
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
#define CITY_LOG(loglevel, pcity, msg,...)
Definition srv_log.h:83
@ AIT_CITIZEN_ARRANGE
Definition srv_log.h:50
@ TIMER_STOP
Definition srv_log.h:76
@ TIMER_START
Definition srv_log.h:76
#define TIMING_LOG(timer, activity)
Definition srv_log.h:125
Definition city.h:318
int id
Definition city.h:324
struct city * pcity
Definition cityturn.c:120
struct impr_type * pimprove
Definition cityturn.c:121
int mgr_worldchance
Definition game.h:169
int incite_total_factor
Definition game.h:157
int mgr_nationchance
Definition game.h:167
struct conn_list * glob_observers
Definition game.h:98
bool mgr_foodneeded
Definition game.h:166
int base_incite_cost
Definition game.h:141
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
int mgr_turninterval
Definition game.h:168
bool migration
Definition game.h:171
int incite_improvement_factor
Definition game.h:156
int aqueductloss
Definition game.h:136
int incite_unit_factor
Definition game.h:158
struct civ_game::@32::@36 server
int mgr_distance
Definition game.h:165
Definition cm.h:52
struct requirement_vector reqs
Definition improvement.h:58
int counters[MAX_COUNTERS]
enum gold_upkeep_style gold_upkeep_style
bool unit_builders_nationality
int infra_points
Definition player.h:67
int units_built
Definition player.h:104
enum spaceship_state state
Definition spaceship.h:108
struct city_list * cities
Definition player.h:281
struct unit_list * units
Definition player.h:282
struct conn_list * connections
Definition player.h:298
struct player_economic economic
Definition player.h:284
struct player_spaceship spaceship
Definition player.h:286
struct player_score score
Definition player.h:283
struct player_slot * slot
Definition player.h:250
const struct player * player
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
struct requirement_vector build_reqs
Definition unittype.h:527
Definition unit.h:140
int length
Definition unit.h:198
int upkeep[O_LAST]
Definition unit.h:150
bool has_orders
Definition unit.h:196
int id
Definition unit.h:147
struct unit::@83 orders
bool debug
Definition unit.h:237
bool vigilant
Definition unit.h:200
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
struct unit_order * list
Definition unit.h:201
enum unit_activity changed_from
Definition unit.h:171
struct player * nationality
Definition unit.h:146
int upkeep_paid[O_LAST]
Definition unit.h:259
struct goods_type * carrying
Definition unit.h:189
const struct unit_type * utype
Definition unit.h:141
struct player * owner
Definition unit.h:145
enum universals_n kind
Definition fc_types.h:595
universals_u value
Definition fc_types.h:594
struct civ_map map
int city_style(struct city *pcity)
Definition style.c:235
const char * style_name_translation(const struct nation_style *pstyle)
Definition style.c:95
#define sz_strlcpy(dest, src)
Definition support.h:195
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define fc__fallthrough
Definition support.h:119
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:305
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:100
Tech_type_id pick_free_tech(struct research *presearch)
Definition techtools.c:1389
void give_immediate_free_tech(struct research *presearch, Tech_type_id tech)
Definition techtools.c:1408
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech, bool free_bulbs)
Definition techtools.c:654
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:240
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:956
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_worked(_tile)
Definition tile.h:119
#define tile_has_extra(ptile, pextra)
Definition tile.h:152
const char * tiledef_name_translation(const struct tiledef *td)
Definition tiledef.c:95
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
bool goods_can_be_provided(const struct city *pcity, const struct goods_type *pgood, const struct unit *punit)
bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
const char * goods_name_translation(struct goods_type *pgood)
#define trade_routes_iterate_safe_end
@ TRI_CANCEL
Definition traderoutes.h:32
#define trade_routes_iterate_safe(c, proute)
#define trade_partners_iterate_end
#define trade_partners_iterate(c, p)
trade_route_type
Definition traderoutes.h:37
const struct unit_type * utype
Definition fc_types.h:536
const struct impr_type * building
Definition fc_types.h:529
bool unit_is_alive(int id)
Definition unit.c:2306
int unit_upkeep_cost(const struct unit *punit, Output_type_id otype)
Definition unit.c:2972
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:402
#define unit_tile(_pu)
Definition unit.h:408
#define unit_cargo_iterate_end
Definition unit.h:602
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:599
#define unit_owner(_pu)
Definition unit.h:407
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void unit_set_removal_callback(struct unit *punit, void(*callback)(struct unit *punit))
Definition unittools.c:1776
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1718
struct unit * unit_virtual_prepare(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left)
Definition unittools.c:1670
void unit_unset_removal_callback(struct unit *punit)
Definition unittools.c:1790
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2144
int unit_build_shield_cost(const struct city *pcity, const struct unit *punit)
Definition unittype.c:1501
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1613
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1554
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1586
#define unit_tech_reqs_iterate_end
Definition unittype.h:889
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:883
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define U_NOT_OBSOLETED
Definition unittype.h:535
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
bool worklist_is_empty(const struct worklist *pwl)
Definition worklist.c:66
void worklist_remove(struct worklist *pwl, int idx)
Definition worklist.c:122
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57