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)
499 && can_city_build_improvement_now(pcity, pimprove))) {
502 _("Notice: Wonder %s in %s will be finished next turn."),
504 }
506}
507
508/**********************************************************************/
512static void city_turn_notify(const struct city *pcity,
513 struct conn_list *dest,
514 const struct player *cache_for_player)
515{
516 const struct impr_type *pimprove = pcity->production.value.building;
517 struct packet_chat_msg packet;
519
520 if (0 < pcity->surplus[O_FOOD]) {
522 - pcity->food_stock - 1) / pcity->surplus[O_FOOD];
523
527 && 0 < pcity->surplus[O_SHIELD]) {
528 /* From the check above, the surplus must always be positive. */
530 - pcity->shield_stock) / pcity->surplus[O_SHIELD];
531 /* If growth and granary completion occur simultaneously, granary
532 * preserves food. -AJS. */
533 if (5 > turns_growth && 5 > turns_granary
535 package_event(&packet, city_tile(pcity),
537 _("Suggest throttling growth in %s to use %s "
538 "(being built) more effectively."),
541 lsend_packet_chat_msg(dest, &packet);
542 if (cache_for_player != nullptr) {
544 }
545 }
546 }
547
550 package_event(&packet, city_tile(pcity),
552 _("%s may soon grow to size %i."),
554 lsend_packet_chat_msg(dest, &packet);
555 if (cache_for_player != nullptr) {
557 }
558 }
559 } else {
560 if (0 >= pcity->food_stock + pcity->surplus[O_FOOD]
561 && 0 > pcity->surplus[O_FOOD]) {
562 package_event(&packet, city_tile(pcity),
564 _("Warning: Famine feared in %s."), city_link(pcity));
565 lsend_packet_chat_msg(dest, &packet);
566 if (cache_for_player != nullptr) {
568 }
569 }
570 }
571}
572
573/**********************************************************************/
578{
579 if (pconn != nullptr) {
580 struct player *pplayer = conn_get_player(pconn);
581
582 if (pplayer != nullptr) {
583 city_list_iterate(pplayer->cities, pcity) {
584 city_turn_notify(pcity, pconn->self, nullptr);
586 }
588 } else {
589 players_iterate(pplayer) {
590 city_list_iterate(pplayer->cities, pcity) {
591 city_turn_notify(pcity, pplayer->connections, pplayer);
594 /* NB: notifications to 'game.est_connections' are automatically
595 * cached. */
597 }
598}
599
600/**********************************************************************/
603void update_city_activities(struct player *pplayer)
604{
605 int n;
606
607 fc_assert(pplayer->cities != nullptr);
608
609 n = city_list_size(pplayer->cities);
610
611 if (n > 0) {
612 struct city *cities[n];
613 int i = 0, r;
614
615 city_list_iterate(pplayer->cities, pcity) {
616
618
619 /* Cancel trade routes that cannot exist any more */
621 struct city *tcity = game_city_by_number(proute->partner);
622
623 if (tcity != nullptr) {
624 bool cancel = FALSE;
625
626 if (proute->dir != RDIR_FROM && goods_has_flag(proute->goods, GF_DEPLETES)
627 && !goods_can_be_provided(tcity, proute->goods, nullptr)) {
628 cancel = TRUE;
629 }
630 if (!cancel && !can_cities_trade(pcity, tcity)) {
633
634 if (settings->cancelling == TRI_CANCEL) {
635 cancel = TRUE;
636 }
637 }
638
639 if (cancel) {
640 struct trade_route *back;
641
643 free(proute);
644 free(back);
645 }
646 }
648
649 /* Add cities to array for later random order handling */
650 cities[i++] = pcity;
652
653 /* How gold upkeep is handled depends on the setting
654 * 'game.info.gold_upkeep_style':
655 * GOLD_UPKEEP_CITY: Each city tries to balance its upkeep individually
656 * (this is done in update_city_activity()).
657 * GOLD_UPKEEP_MIXED: Each city tries to balance its upkeep for
658 * buildings individually; the upkeep for units is
659 * paid by the nation.
660 * GOLD_UPKEEP_NATION: The nation as a whole balances the treasury. If
661 * the treasury is not balance units and buildings
662 * are sold. */
663
664 /* Iterate over cities in a random order. */
665 while (i > 0) {
666 r = fc_rand(i);
667 /* update unit upkeep */
670 cities[r] = cities[--i];
671 }
672 }
673}
674
675/**********************************************************************/
689 bool wipe_in_the_end)
690{
691 int punit_id;
692
694 nullptr, get_output_type(outp), nullptr)) {
695 /* Can't get rid of this unit. It is undisbandable for the current
696 * situation. */
697 return FALSE;
698 }
699
700 punit_id = punit->id;
701
702 /* Try to perform this unit's can't upkeep actions. */
704 nullptr, get_output_type(outp), nullptr,
705 nullptr, nullptr, nullptr, nullptr);
706
708 /* No forced action was able to kill the unit. Finish the job. */
709 wipe_unit(punit, wipe_reason, nullptr);
710 }
711
712 return !unit_is_alive(punit_id);
713}
714
715/**********************************************************************/
720{
721 citizens want = change;
722
723 fc_assert_ret_val(0 < change, 0);
724
726 citizens fix = MIN(want, pcity->specialists[sp]);
727
728 pcity->specialists[sp] -= fix;
729 want -= fix;
731
732 return change - want;
733}
734
735/**********************************************************************/
740{
741 struct tile *pcenter = city_tile(pcity);
742 int want = change;
743 const struct civ_map *nmap = &(wld.map);
744
745 fc_assert_ret_val(0 < change, 0);
746
748 ptile, _index, _x, _y) {
749 if (0 < want && tile_worked(ptile) == pcity) {
751 want--;
752 }
754
755 return change - want;
756}
757
758/**********************************************************************/
764 struct player *destroyer, const char *reason)
765{
767 int old_radius_sq;
768
769 if (pop_loss == 0) {
770 return TRUE;
771 }
772
773 if (city_size_get(pcity) <= pop_loss) {
774 int id = pcity->id;
775
776 citizens_update(pcity, nullptr); /* To avoid warnings during the script */
777 /* Won't refresh a doomed city, or should we? */
778 script_server_signal_emit("city_destroyed", pcity, pcity->owner,
779 destroyer);
780
781 if (city_exist(id)) {
783 }
784 return FALSE;
785 }
790
791 /* Cap the food stock at the new granary size. */
792 if (pcity->food_stock > city_granary_size(city_size_get(pcity))) {
794 }
795
796 /* First try to kill off the specialists */
798
799 if (loss_remain > 0) {
800 /* Take it out on workers */
801#ifndef FREECIV_NDEBUG
802 loss_remain -=
803#endif /* FREECIV_NDEBUG */
805 }
806
807 /* Update citizens. */
808 citizens_update(pcity, nullptr);
809
810 /* Update number of people in each feelings category.
811 * This also updates the city radius if needed. */
813
815
816 /* Send city data. */
817 sync_cities();
818
820 "city_reduce_size() has remaining"
821 "%d of %d for \"%s\"[%d]",
824
825 /* Update cities that have trade routes with us */
827 if (city_refresh(pcity2)) {
828 /* This should never happen, but if it does, make sure not to
829 * leave workers outside city radius. */
831 }
833
835
836 if (reason != nullptr) {
837 int id = pcity->id;
838
839 script_server_signal_emit("city_size_change", pcity,
841
842 return city_exist(id);
843 }
844
845 return TRUE;
846}
847
848/**********************************************************************/
852void city_repair_size(struct city *pcity, int change)
853{
854 if (change > 0) {
855 pcity->specialists[DEFAULT_SPECIALIST] += change;
856 } else if (change < 0) {
857 int need = change + city_reduce_specialists(pcity, -change);
858
859 if (0 > need) {
860#ifndef FREECIV_NDEBUG
861 need +=
862#endif /* FREECIV_NDEBUG */
864 }
865
866 fc_assert_msg(0 == need,
867 "city_repair_size() has remaining %d of %d for \"%s\"[%d]",
869 }
870}
871
872/**********************************************************************/
880{
882
883 return CLIP(0, savings, 100);
884}
885
886/**********************************************************************/
894{
896
897 return CLIP(0, savings, 100);
898}
899
900/**********************************************************************/
907{
909
910 pcity->food_stock = (city_granary_size(new_size) * savings_pct) / 100;
911}
912
913/**********************************************************************/
919static bool city_increase_size(struct city *pcity, bool natural_growth,
921{
922 int new_food;
924 bool have_square = FALSE;
925 bool rapture_grow = city_rapture_grow(pcity); /* Check before size increase! */
926 struct tile *pcenter = city_tile(pcity);
927 struct player *powner = city_owner(pcity);
928 const struct impr_type *pimprove = pcity->production.value.building;
929 const struct civ_map *nmap = &(wld.map);
930
932 /* Need improvement */
936 _("%s needs %s (being built) to grow beyond size %d."),
940 } else {
942 _("%s needs an improvement to grow beyond size %d."),
944 }
945 /* Granary can only hold so much */
947 * (100 * 100 - game.server.aqueductloss * (100 - savings_pct))
948 / (100 * 100));
949 pcity->food_stock = MIN(pcity->food_stock, new_food);
950
951 return FALSE;
952 }
953
954 if (natural_growth) {
955 /* Growth by filled foodbox */
956 int stock;
957 int granary;
958
960 if (pcity->food_stock <= granary) {
961 stock = 0;
962 } else {
963 stock = pcity->food_stock - granary;
964 }
965
967
968 /* Do not empty food stock if city is growing by celebrating */
969 if (rapture_grow) {
971 } else {
973 }
974
975 /* Never increase amount of food in the foodbox */
976 pcity->food_stock = MIN(pcity->food_stock, new_food);
977 } else {
978 /* Growth by means like add-to-city or population migration */
980
982
983 /* Preserve old food stock, unless granary effect gives us more. */
984 pcity->food_stock = MAX(pcity->food_stock, new_food);
985 }
986
987 if (sid >= 0) {
989 pcity->specialists[sid]++;
990 } else {
991 /* If there is enough food, and the city is big enough,
992 * make new citizens into scientists or taxmen -- Massimo */
993
994 /* Ignore food if no square can be worked */
996 ptile, _index, _x, _y) {
997 if (tile_worked(ptile) != pcity /* Quick test */
998 && city_can_work_tile(pcity, ptile)) {
1000 }
1002
1003 if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1005 pcity->specialists[best_specialist(O_SCIENCE, pcity)]++;
1006 } else if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1008 pcity->specialists[best_specialist(O_GOLD, pcity)]++;
1009 } else {
1010 pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
1011 }
1012 }
1013
1014 /* Deprecated signal. Connect your lua functions to "city_size_change" that's
1015 * emitted from calling functions which know the 'reason' of the increase. */
1016 script_server_signal_emit("city_growth", pcity,
1018
1019 return TRUE;
1020}
1021
1022/**********************************************************************/
1028 struct player *nationality,
1029 bool aaw)
1030{
1031 struct player *powner = city_owner(pcity);
1032
1033 /* Update citizens. */
1034 citizens_update(pcity, nationality);
1035
1036 /* Refresh the city data; this also checks the squared city radius. */
1038
1039 if (aaw) {
1041 }
1042
1043 /* Update cities that have trade routes with us */
1045 if (city_refresh(pcity2)) {
1046 /* This should never happen, but if it does, make sure not to
1047 * leave workers outside city radius. */
1049 }
1051
1053 _("%s grows to size %d."),
1055
1057
1058 sync_cities();
1059}
1060
1061/**********************************************************************/
1069 struct player *nationality,
1070 Specialist_type_id sid, const char *reason)
1071{
1072 int change = size - city_size_get(pcity);
1073
1074 if (change > 0) {
1076 int real_change;
1078 int id = pcity->id;
1079
1080 /* Increase city size until size reached, or increase fails */
1082 /* TODO: This is currently needed only because there's
1083 * deprecated script signal "city_growth" emitted.
1084 * Check the need after signal has been dropped completely. */
1085 if (!city_exist(id)) {
1086 return FALSE;
1087 }
1088
1089 current_size++;
1090 }
1091
1093
1095
1096 if (real_change != 0 && reason != nullptr) {
1097 script_server_signal_emit("city_size_change", pcity,
1099
1100 if (!city_exist(id)) {
1101 return FALSE;
1102 }
1103 }
1104 } else if (change < 0) {
1105 /* We assume that city_change_size() is never called because
1106 * of enemy actions. If that changes, enemy must be passed
1107 * to city_reduce_size() */
1108 return city_reduce_size(pcity, -change, nullptr, reason);
1109 }
1110
1112
1113 return TRUE;
1114}
1115
1116/**********************************************************************/
1120static void city_populate(struct city *pcity, struct player *nationality)
1121{
1122 int saved_id = pcity->id;
1123 int granary_size = city_granary_size(city_size_get(pcity));
1124
1125 pcity->food_stock += pcity->surplus[O_FOOD];
1126 if (pcity->food_stock >= granary_size || city_rapture_grow(pcity)) {
1130 _("A recent plague outbreak prevents growth in %s."),
1131 city_link(pcity));
1132 /* Lose excess food */
1133 pcity->food_stock = MIN(pcity->food_stock, granary_size);
1134 } else {
1135 bool success;
1136
1139
1140 if (success) {
1142 script_server_signal_emit("city_size_change", pcity,
1143 (lua_Integer)1, "growth");
1144 }
1145 }
1146 } else if (pcity->food_stock < 0) {
1147 /* FIXME: should this depend on units with ability to build
1148 * cities or on units that require food in upkeep?
1149 * I'll assume citybuilders (units that 'contain' 1 pop) -- sjolie
1150 * The above may make more logical sense, but in game terms
1151 * you want to disband a unit that is draining your food
1152 * reserves. Hence, I'll assume food upkeep > 0 units. -- jjm
1153 */
1154 unit_list_iterate_safe(pcity->units_supported, punit) {
1155 if (punit->upkeep[O_FOOD] > 0) {
1156 const char *punit_link = unit_tile_link(punit);
1157
1162 _("Famine feared in %s, %s lost!"),
1164 }
1165
1166 if (city_exist(saved_id)) {
1168 }
1169
1170 return;
1171 }
1173 if (city_size_get(pcity) > 1) {
1176 _("Famine causes population loss in %s."),
1177 city_link(pcity));
1178 } else {
1181 _("Famine destroys %s entirely."),
1182 city_link(pcity));
1183 }
1185 if (city_reduce_size(pcity, 1, nullptr, "famine")) {
1186 pcity->had_famine = TRUE;
1187 }
1188 }
1189}
1190
1191/**********************************************************************/
1198 struct city *pcity,
1199 struct player *pplayer,
1200 int saved_id)
1201{
1202 const void *ptarget;
1203 const char *tgt_name;
1204 const struct requirement_vector *build_reqs;
1205 const char *signal_name;
1206 const struct req_context city_ctxt = {
1207 .player = pplayer,
1208 .city = pcity,
1209 .tile = city_tile(pcity)
1210 /* FIXME: Setting .unittype is currently redundant,
1211 * but can_city_build_unit_direct() does it */
1212 };
1213 bool purge = FALSE;
1214 bool known = FALSE;
1215
1216 if (pcity->wlcb == WLCB_ALWAYS_PURGE) {
1217 return TRUE;
1218 }
1219
1220 switch (target->kind) {
1221 case VUT_UTYPE:
1222 ptarget = target->value.utype;
1223 build_reqs = &target->value.utype->build_reqs;
1225 signal_name = "unit_cant_be_built";
1226 break;
1227 case VUT_IMPROVEMENT:
1228 ptarget = target->value.building;
1229 build_reqs = &target->value.building->reqs;
1231 signal_name = "building_cant_be_built";
1232 break;
1233 default:
1235 || target->kind == VUT_UTYPE), FALSE);
1236 return FALSE;
1237 }
1238
1239 if (pcity->wlcb == WLCB_ALWAYS_POSTPONE) {
1240 notify_player(pplayer, city_tile(pcity),
1242 _("%s can't build %s from the worklist. "
1243 "Postponing..."),
1245 tgt_name);
1246 return FALSE;
1247 }
1248
1249 requirement_vector_iterate(build_reqs, preq) {
1250 if (!is_req_active(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
1251 known = TRUE;
1252 switch (preq->source.kind) {
1253 case VUT_COUNTER:
1254 if (preq->present) {
1255 notify_player(pplayer, city_tile(pcity),
1257 _("%s can't build %s from the worklist; "
1258 "counter %s value's checkpoint do not met "
1259 "Postponing..."),
1261 tgt_name,
1263 (preq->source.value.counter));
1264 } else {
1265 purge = TRUE;
1266 }
1267 break;
1268 case VUT_ADVANCE:
1269 if (preq->present) {
1270 notify_player(pplayer, city_tile(pcity),
1272 _("%s can't build %s from the worklist; "
1273 "tech %s not yet available. Postponing..."),
1275 tgt_name,
1277 (preq->source.value.advance));
1279 pcity, "need_tech");
1280 } else {
1281 /* While techs can be unlearned, this isn't useful feedback */
1282 purge = TRUE;
1283 }
1284 break;
1285 case VUT_TECHFLAG:
1286 if (preq->present) {
1287 notify_player(pplayer, city_tile(pcity),
1289 _("%s can't build %s from the worklist; "
1290 "no tech with flag \"%s\" yet available. "
1291 "Postponing..."),
1293 tgt_name,
1294 tech_flag_id_name(preq->source.value.techflag));
1296 pcity, "need_techflag");
1297 } else {
1298 /* While techs can be unlearned, this isn't useful feedback */
1299 purge = TRUE;
1300 }
1301 break;
1302 case VUT_IMPROVEMENT:
1303 case VUT_SITE:
1304 if (preq->range == REQ_RANGE_LOCAL) {
1305 /* Building itself is never going to change */
1306 purge = TRUE;
1307 } else {
1308 if (preq->present) {
1309 notify_player(pplayer, city_tile(pcity),
1311 _("%s can't build %s from the worklist; "
1312 "need to have %s first. Postponing..."),
1314 tgt_name,
1316 preq->source.value.building));
1318 pcity, "need_building");
1319 } else {
1320 notify_player(pplayer, city_tile(pcity),
1322 _("%s can't build %s from the worklist; "
1323 "need to not have %s. Postponing..."),
1325 tgt_name,
1327 preq->source.value.building));
1329 pcity, "have_building");
1330 }
1331 }
1332 break;
1333 case VUT_IMPR_GENUS:
1334 if (preq->range == REQ_RANGE_LOCAL) {
1335 /* Building's own genus is never going to change */
1336 purge = TRUE;
1337 } else {
1338 if (preq->present) {
1339 notify_player(pplayer, city_tile(pcity),
1341 _("%s can't build %s from the worklist; "
1342 "need to have %s first. Postponing..."),
1344 tgt_name,
1346 preq->source.value.impr_genus));
1348 pcity, "need_building_genus");
1349 } else {
1350 notify_player(pplayer, city_tile(pcity),
1352 _("%s can't build %s from the worklist; "
1353 "need to not have %s. Postponing..."),
1355 tgt_name,
1357 preq->source.value.impr_genus));
1359 pcity, "have_building_genus");
1360 }
1361 }
1362 break;
1363 case VUT_IMPR_FLAG:
1364 if (preq->range == REQ_RANGE_LOCAL) {
1365 /* Building's own flags are never going to change */
1366 purge = TRUE;
1367 } else {
1368 if (preq->present) {
1369 notify_player(pplayer, city_tile(pcity),
1371 _("%s can't build %s from the worklist; "
1372 "need to have %s first. Postponing..."),
1374 tgt_name,
1376 preq->source.value.impr_flag));
1378 pcity, "need_building_flag");
1379 } else {
1380 notify_player(pplayer, city_tile(pcity),
1382 _("%s can't build %s from the worklist; "
1383 "need to not have %s. Postponing..."),
1385 tgt_name,
1387 preq->source.value.impr_flag));
1389 pcity, "have_building_flag");
1390 }
1391 }
1392 break;
1393 case VUT_PLAYER_FLAG:
1394 if (preq->present) {
1395 notify_player(pplayer, city_tile(pcity),
1397 _("%s can't build %s from the worklist; "
1398 "need to have %s first. Postponing..."),
1400 tgt_name,
1402 preq->source.value.plr_flag));
1404 pcity, "need_player_flag");
1405 } else {
1406 notify_player(pplayer, city_tile(pcity),
1408 _("%s can't build %s from the worklist; "
1409 "need to not have %s. Postponing..."),
1411 tgt_name,
1413 preq->source.value.plr_flag));
1415 pcity, "have_player_flag");
1416 }
1417 break;
1418 case VUT_PLAYER_STATE:
1419 purge = TRUE;
1420 break;
1421 case VUT_GOVERNMENT:
1422 if (preq->present) {
1423 notify_player(pplayer, city_tile(pcity),
1425 _("%s can't build %s from the worklist; "
1426 "it needs %s government. Postponing..."),
1428 tgt_name,
1429 government_name_translation(preq->source.value.govern));
1431 pcity, "need_government");
1432 } else {
1433 notify_player(pplayer, city_tile(pcity),
1435 _("%s can't build %s from the worklist; "
1436 "it cannot have %s government. Postponing..."),
1438 tgt_name,
1439 government_name_translation(preq->source.value.govern));
1441 pcity, "have_government");
1442 }
1443 break;
1444 case VUT_GOVFLAG:
1445 if (preq->present) {
1446 notify_player(pplayer, city_tile(pcity),
1448 _("%s can't build %s from the worklist; "
1449 "it needs %s government. Postponing..."),
1451 tgt_name,
1452 gov_flag_id_translated_name(preq->source.value.govflag));
1454 pcity, "need_govflag");
1455 } else {
1456 notify_player(pplayer, city_tile(pcity),
1458 _("%s can't build %s from the worklist; "
1459 "it cannot have %s government. Postponing..."),
1461 tgt_name,
1462 gov_flag_id_translated_name(preq->source.value.govflag));
1464 pcity, "have_govflag");
1465 }
1466 break;
1467 case VUT_ACHIEVEMENT:
1468 if (preq->present) {
1469 notify_player(pplayer, city_tile(pcity),
1471 _("%s can't build %s from the worklist; "
1472 "it needs \"%s\" achievement. Postponing..."),
1474 tgt_name,
1475 achievement_name_translation(preq->source.value.achievement));
1477 pcity, "need_achievement");
1478 } else {
1479 /* Can't unachieve things. */
1480 purge = TRUE;
1481 }
1482 break;
1483 case VUT_EXTRA:
1484 if (preq->present) {
1485 notify_player(pplayer, city_tile(pcity),
1487 Q_("?extra:%s can't build %s from the worklist; "
1488 "%s is required. Postponing..."),
1490 tgt_name,
1491 extra_name_translation(preq->source.value.extra));
1493 pcity, "need_extra");
1494 } else {
1495 notify_player(pplayer, city_tile(pcity),
1497 Q_("?extra:%s can't build %s from the worklist; "
1498 "%s is prohibited. Postponing..."),
1500 tgt_name,
1501 extra_name_translation(preq->source.value.extra));
1503 pcity, "have_extra");
1504 }
1505 break;
1506 case VUT_TILEDEF:
1507 if (preq->present) {
1508 notify_player(pplayer, city_tile(pcity),
1510 Q_("?tiledef:%s can't build %s from the worklist; "
1511 "%s is required. Postponing..."),
1513 tgt_name,
1514 tiledef_name_translation(preq->source.value.tiledef));
1516 pcity, "need_tiledef");
1517 } else {
1518 notify_player(pplayer, city_tile(pcity),
1520 Q_("?tiledef:%s can't build %s from the worklist; "
1521 "%s is prohibited. Postponing..."),
1523 tgt_name,
1524 tiledef_name_translation(preq->source.value.tiledef));
1526 pcity, "have_tiledef");
1527 }
1528 break;
1530 if (preq->present) {
1531 notify_player(pplayer, city_tile(pcity),
1533 Q_("?tdconn:%s can't build %s from the worklist; "
1534 "access to %s is required. Postponing..."),
1536 tgt_name,
1537 tiledef_name_translation(preq->source.value.tiledef));
1539 pcity, "need_tiledef_conn");
1540 } else {
1541 notify_player(pplayer, city_tile(pcity),
1543 Q_("?tdconn:%s can't build %s from the worklist; "
1544 "access to %s is prohibited. Postponing..."),
1546 tgt_name,
1547 tiledef_name_translation(preq->source.value.tiledef));
1549 pcity, "have_tiledef_conn");
1550 }
1551 break;
1552 case VUT_GOOD:
1553 if (preq->present) {
1554 notify_player(pplayer, city_tile(pcity),
1556 Q_("?extra:%s can't build %s from the worklist; "
1557 "%s is required. Postponing..."),
1559 tgt_name,
1560 goods_name_translation(preq->source.value.good));
1562 pcity, "need_good");
1563 } else {
1564 notify_player(pplayer, city_tile(pcity),
1566 Q_("?extra:%s can't build %s from the worklist; "
1567 "%s is prohibited. Postponing..."),
1569 tgt_name,
1570 goods_name_translation(preq->source.value.good));
1572 pcity, "have_good");
1573 }
1574 break;
1575 case VUT_TERRAIN:
1576 if (preq->present) {
1577 notify_player(pplayer, city_tile(pcity),
1579 Q_("?terrain:%s can't build %s from the worklist; "
1580 "%s terrain is required. Postponing..."),
1582 tgt_name,
1583 terrain_name_translation(preq->source.value.terrain));
1585 pcity, "need_terrain");
1586 } else {
1587 notify_player(pplayer, city_tile(pcity),
1589 Q_("?terrain:%s can't build %s from the worklist; "
1590 "%s terrain is prohibited. Postponing..."),
1592 tgt_name,
1593 terrain_name_translation(preq->source.value.terrain));
1595 pcity, "have_terrain");
1596 }
1597 break;
1598 case VUT_NATION:
1599 if (preq->range < REQ_RANGE_TRADE_ROUTE
1600 || preq->range == REQ_RANGE_PLAYER) {
1601 /* At higher ranges, new players with their nations may arrive */
1602 purge = TRUE;
1603 } else {
1604 if (preq->present) {
1605 notify_player(pplayer, city_tile(pcity),
1607 /* TRANS: "%s nation" is adjective */
1608 Q_("?nation:%s can't build %s from the worklist; "
1609 "%s nation is required. Postponing..."),
1611 tgt_name,
1612 nation_adjective_translation(preq->source.value.nation));
1614 pcity, "need_nation");
1615 } else {
1616 notify_player(pplayer, city_tile(pcity),
1618 Q_("?nation:%s can't build %s from the worklist; "
1619 "%s nation is prohibited. Postponing..."),
1621 tgt_name,
1622 nation_adjective_translation(preq->source.value.nation));
1624 pcity, "have_nation");
1625 }
1626 }
1627 break;
1628 case VUT_NATIONGROUP:
1629 if (preq->range < REQ_RANGE_TRADE_ROUTE
1630 || preq->range == REQ_RANGE_PLAYER) {
1631 /* At higher ranges, new players with their nations may arrive */
1632 purge = TRUE;
1633 } else {
1634 if (preq->present) {
1635 notify_player(pplayer, city_tile(pcity),
1637 /* TRANS: "%s nation" is adjective */
1638 Q_("?ngroup:%s can't build %s from the worklist; "
1639 "%s nation is required. Postponing..."),
1641 tgt_name,
1642 nation_group_name_translation(preq->source.value.nationgroup));
1644 pcity, "need_nationgroup");
1645 } else {
1646 notify_player(pplayer, city_tile(pcity),
1648 Q_("?ngroup:%s can't build %s from the worklist; "
1649 "%s nation is prohibited. Postponing..."),
1651 tgt_name,
1652 nation_group_name_translation(preq->source.value.nationgroup));
1654 pcity, "have_nationgroup");
1655 }
1656 }
1657 break;
1658 case VUT_STYLE:
1659 /* FIXME: City styles sometimes change over time, but it isn't
1660 * entirely under player control. Probably better to purge
1661 * with useful explanation. */
1662 if (preq->present) {
1663 notify_player(pplayer, city_tile(pcity),
1665 _("%s can't build %s from the worklist; "
1666 "only %s style cities may build this. Postponing..."),
1668 tgt_name,
1669 style_name_translation(preq->source.value.style));
1671 pcity, "need_style");
1672 } else {
1673 notify_player(pplayer, city_tile(pcity),
1675 _("%s can't build %s from the worklist; "
1676 "%s style cities may not build this. Postponing..."),
1678 tgt_name,
1679 style_name_translation(preq->source.value.style));
1681 pcity, "have_style");
1682 }
1683 break;
1684 case VUT_NATIONALITY:
1685 /* FIXME: Changing citizen nationality is hard: purging might be
1686 * more useful in this case. */
1687 if (preq->present) {
1688 notify_player(pplayer, city_tile(pcity),
1690 /* TRANS: Latter %s is citizen nationality */
1691 _("%s can't build %s from the worklist; "
1692 "only city with %s may build this. Postponing..."),
1694 tgt_name,
1695 nation_plural_translation(preq->source.value.nationality));
1697 pcity, "need_nationality");
1698 } else {
1699 notify_player(pplayer, city_tile(pcity),
1701 /* TRANS: Latter %s is citizen nationality */
1702 _("%s can't build %s from the worklist; "
1703 "only city without %s may build this. Postponing..."),
1705 tgt_name,
1706 nation_plural_translation(preq->source.value.nationality));
1708 pcity, "have_nationality");
1709 }
1710 break;
1711 case VUT_ORIGINAL_OWNER:
1712 /* Original owner of this specific city won't change.
1713 * Update this when supporting ranges other than REQ_RANGE_CITY. */
1714 purge = TRUE;
1715 break;
1716 case VUT_DIPLREL:
1717 case VUT_DIPLREL_TILE: /* The tile owner is the city owner */
1718 case VUT_DIPLREL_TILE_O: /* The tile owner is the city owner */
1719 if (preq->present) {
1720 const char *reason;
1721
1722 notify_player(pplayer, city_tile(pcity),
1724 /* TRANS: '%s' is a wide range of relationships;
1725 * e.g., 'Peace', 'Never met', 'Foreign',
1726 * 'Hosts embassy', 'Provided Casus Belli' */
1727 _("%s can't build %s from the worklist; "
1728 "the relationship '%s' is required."
1729 " Postponing..."),
1731 tgt_name,
1733 preq->source.value.diplrel));
1734
1735 if (preq->source.kind == VUT_DIPLREL_TILE) {
1736 reason = "need_diplrel_tile";
1737 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1738 reason = "need_diplrel_tile_o";
1739 } else {
1740 fc_assert(preq->source.kind == VUT_DIPLREL);
1741 reason = "need_diplrel";
1742 }
1743
1745 pcity, reason);
1746 } else {
1747 const char *reason;
1748
1749 notify_player(pplayer, city_tile(pcity),
1751 _("%s can't build %s from the worklist; "
1752 "the relationship '%s' is prohibited."
1753 " Postponing..."),
1755 tgt_name,
1757 preq->source.value.diplrel));
1758
1759 if (preq->source.kind == VUT_DIPLREL_TILE) {
1760 reason = "have_diplrel_tile";
1761 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1762 reason = "have_diplrel_tile_o";
1763 } else {
1764 fc_assert(preq->source.kind == VUT_DIPLREL);
1765 reason = "have_diplrel";
1766 }
1767
1769 pcity, reason);
1770 }
1771 break;
1774 if (preq->present) {
1775 const char *reason;
1776
1777 notify_player(pplayer, city_tile(pcity),
1779 /* TRANS: '%s' is a wide range of relationships;
1780 * e.g., 'Peace', 'Never met', 'Foreign',
1781 * 'Hosts embassy', 'Provided Casus Belli' */
1782 _("%s can't build %s from the worklist; "
1783 "unit with the relationship '%s' is required."
1784 " Postponing..."),
1786 tgt_name,
1788 preq->source.value.diplrel));
1789
1790 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1791 reason = "need_diplrel_unitany";
1792 } else {
1793 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1794 reason = "need_diplrel_unitany_o";
1795 }
1796
1798 pcity, reason);
1799 } else {
1800 const char *reason;
1801
1802 notify_player(pplayer, city_tile(pcity),
1804 _("%s can't build %s from the worklist; "
1805 "unit with the relationship '%s' is prohibited."
1806 " Postponing..."),
1808 tgt_name,
1810 preq->source.value.diplrel));
1811
1812 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1813 reason = "have_diplrel_unitany";
1814 } else {
1815 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1816 reason = "have_diplrel_unitany_o";
1817 }
1818
1820 pcity, reason);
1821 }
1822 break;
1823 case VUT_MINSIZE:
1824 if (preq->present) {
1825 notify_player(pplayer, city_tile(pcity),
1827 _("%s can't build %s from the worklist; "
1828 "city must be of size %d or larger. "
1829 "Postponing..."),
1831 tgt_name,
1832 preq->source.value.minsize);
1834 pcity, "need_minsize");
1835 } else {
1836 notify_player(pplayer, city_tile(pcity),
1838 _("%s can't build %s from the worklist; "
1839 "city must be of size %d or smaller."
1840 "Postponing..."),
1842 tgt_name,
1843 (preq->source.value.minsize - 1));
1845 pcity, "need_minsize");
1846 }
1847 break;
1848 case VUT_MINCULTURE:
1849 if (preq->present) {
1850 notify_player(pplayer, city_tile(pcity),
1852 _("%s can't build %s from the worklist; "
1853 "city must have culture of %d. Postponing..."),
1855 tgt_name,
1856 preq->source.value.minculture);
1858 pcity, "need_minculture");
1859 } else {
1860 /* What has been written may not be unwritten. */
1861 purge = TRUE;
1862 }
1863 break;
1864 case VUT_MINFOREIGNPCT:
1865 if (preq->present) {
1866 notify_player(pplayer, city_tile(pcity),
1868 _("%s can't build %s from the worklist; "
1869 "city must have %d%% foreign population. Postponing..."),
1871 tgt_name,
1872 preq->source.value.minforeignpct);
1874 pcity, "need_minforeignpct");
1875 } else {
1876 notify_player(pplayer, city_tile(pcity),
1878 _("%s can't build %s from the worklist; "
1879 "city must have %d%% native population. Postponing..."),
1881 tgt_name,
1882 100 - preq->source.value.minforeignpct);
1884 pcity, "need_minforeignpct");
1885 }
1886 break;
1887 case VUT_MINTECHS:
1888 if (preq->present) {
1889 notify_player(pplayer, city_tile(pcity),
1891 _("%s can't build %s from the worklist; "
1892 "%d techs must be known. Postponing..."),
1894 tgt_name,
1895 preq->source.value.min_techs);
1897 pcity, "need_mintechs");
1898 } else {
1899 purge = TRUE;
1900 }
1901 break;
1902 case VUT_FUTURETECHS:
1903 if (preq->present) {
1904 notify_player(pplayer, city_tile(pcity),
1906 _("%s can't build %s from the worklist; "
1907 "%d future techs must be known. Postponing..."),
1909 tgt_name,
1910 preq->source.value.future_techs);
1912 pcity, "need_futuretechs");
1913 } else {
1914 purge = TRUE;
1915 }
1916 break;
1917 case VUT_MINCITIES:
1918 if (preq->present) {
1919 notify_player(pplayer, city_tile(pcity),
1921 _("%s can't build %s from the worklist; "
1922 "Must own %d cities. Postponing..."),
1924 tgt_name,
1925 preq->source.value.min_cities);
1927 pcity, "need_mincities");
1928 } else {
1929 purge = TRUE;
1930 }
1931 break;
1933 if (preq->present) {
1934 notify_player(pplayer, city_tile(pcity),
1936 PL_("%s can't build %s from the worklist; "
1937 "more than %d total unit on tile."
1938 " Postponing...",
1939 "%s can't build %s from the worklist; "
1940 "more than %d total units on tile."
1941 " Postponing...",
1942 preq->source.value.max_tile_total_units),
1944 tgt_name,
1945 preq->source.value.max_tile_total_units);
1947 pcity, "need_tileunits");
1948 } else {
1949 notify_player(pplayer, city_tile(pcity),
1951 PL_("%s can't build %s from the worklist; "
1952 "fewer than %d total unit on tile."
1953 " Postponing...",
1954 "%s can't build %s from the worklist; "
1955 "fewer than %d total units on tile."
1956 " Postponing...",
1957 preq->source.value.max_tile_total_units + 1),
1959 tgt_name,
1960 preq->source.value.max_tile_total_units + 1);
1962 pcity, "need_tileunits");
1963 }
1964 break;
1966 if (preq->present) {
1967 notify_player(pplayer, city_tile(pcity),
1969 PL_("%s can't build %s from the worklist; "
1970 "more than %d unit on tile."
1971 " Postponing...",
1972 "%s can't build %s from the worklist; "
1973 "more than %d units on tile."
1974 " Postponing...",
1975 preq->source.value.max_tile_top_units),
1977 tgt_name,
1978 preq->source.value.max_tile_top_units);
1980 pcity, "need_tiletopunits");
1981 } else {
1982 notify_player(pplayer, city_tile(pcity),
1984 PL_("%s can't build %s from the worklist; "
1985 "fewer than %d unit on tile."
1986 " Postponing...",
1987 "%s can't build %s from the worklist; "
1988 "fewer than %d units on tile."
1989 " Postponing...",
1990 preq->source.value.max_tile_top_units + 1),
1992 tgt_name,
1993 preq->source.value.max_tile_top_units + 1);
1995 pcity, "need_tiletopunits");
1996 }
1997 break;
1998 case VUT_AI_LEVEL:
1999 /* Can't change AI level. */
2000 purge = TRUE;
2001 break;
2002 case VUT_TERRAINCLASS:
2003 /* Change of terrain class is expected to be very unlikely. Purge!
2004 * TODO: Analyze ruleset to see how unlikely terrain class change actually is. */
2005 purge = TRUE;
2006 break;
2007 case VUT_TERRFLAG:
2008 if (preq->present) {
2009 notify_player(pplayer, city_tile(pcity),
2011 _("%s can't build %s from the worklist; "
2012 "terrain with \"%s\" flag is required. "
2013 "Postponing..."),
2015 tgt_name,
2016 terrain_flag_id_name(preq->source.value.terrainflag));
2018 pcity, "need_terrainflag");
2019 } else {
2020 notify_player(pplayer, city_tile(pcity),
2022 _("%s can't build %s from the worklist; "
2023 "terrain with \"%s\" flag is prohibited. "
2024 "Postponing..."),
2026 tgt_name,
2027 terrain_flag_id_name(preq->source.value.terrainflag));
2029 pcity, "have_terrainflag");
2030 }
2031 break;
2033 /* Changing the continent size is hard; cf. VUT_TERRAINCLASS above.
2034 * Change this when we support less fixed ranges (e.g. city?). */
2035 purge = TRUE;
2036 break;
2037 case VUT_ROADFLAG:
2038 if (preq->present) {
2039 notify_player(pplayer, city_tile(pcity),
2041 _("%s can't build %s from the worklist; "
2042 "road with \"%s\" flag is required. "
2043 "Postponing..."),
2045 tgt_name,
2046 road_flag_id_name(preq->source.value.roadflag));
2048 pcity, "need_roadflag");
2049 } else {
2050 notify_player(pplayer, city_tile(pcity),
2052 _("%s can't build %s from the worklist; "
2053 "road with \"%s\" flag is prohibited. "
2054 "Postponing..."),
2056 tgt_name,
2057 road_flag_id_name(preq->source.value.roadflag));
2059 pcity, "have_roadflag");
2060 }
2061 break;
2062 case VUT_EXTRAFLAG:
2063 if (preq->present) {
2064 notify_player(pplayer, city_tile(pcity),
2066 _("%s can't build %s from the worklist; "
2067 "extra with \"%s\" flag is required. "
2068 "Postponing..."),
2070 tgt_name,
2071 extra_flag_id_translated_name(preq->source.value.extraflag));
2073 pcity, "need_extraflag");
2074 } else {
2075 notify_player(pplayer, city_tile(pcity),
2077 _("%s can't build %s from the worklist; "
2078 "extra with \"%s\" flag is prohibited. "
2079 "Postponing..."),
2081 tgt_name,
2082 extra_flag_id_translated_name(preq->source.value.extraflag));
2084 pcity, "have_extraflag");
2085 }
2086 break;
2087 case VUT_MINLATITUDE:
2088 case VUT_MAXLATITUDE:
2089 /* Can't change where the city is located. */
2090 purge = TRUE;
2091 break;
2092 case VUT_CITYTILE:
2093 if (CITYT_BORDERING_TCLASS_REGION == preq->source.value.citytile
2094 && (preq->range == REQ_RANGE_CADJACENT
2095 || preq->range == REQ_RANGE_ADJACENT)) {
2096 if (preq->present) {
2097 notify_player(pplayer, city_tile(pcity),
2099 _("%s can't build %s from the worklist; "
2100 "different terrain class nearby is required. "
2101 "Postponing..."),
2103 tgt_name);
2105 pcity, "need_different_terrainclass");
2106 } else {
2107 notify_player(pplayer, city_tile(pcity),
2109 _("%s can't build %s from the worklist; "
2110 "different terrain class nearby is prohibited. "
2111 "Postponing..."),
2113 tgt_name);
2115 pcity, "have_different_terrainclass");
2116 }
2117 break;
2118 }
2119 /* Other values should not present in build reqs */
2121
2122 case VUT_UTYPE:
2123 case VUT_UTFLAG:
2124 case VUT_UCLASS:
2125 case VUT_UCFLAG:
2126 case VUT_MINVETERAN:
2127 case VUT_UNITSTATE:
2128 case VUT_ACTIVITY:
2129 case VUT_MINMOVES:
2130 case VUT_MINHP:
2131 case VUT_ACTION:
2132 case VUT_OTYPE:
2133 case VUT_SPECIALIST:
2135 case VUT_TILE_REL:
2136 case VUT_TERRAINALTER: /* XXX could do this in principle */
2137 /* Will only happen with a bogus ruleset. */
2138 log_error("worklist_change_build_target() has bogus preq");
2139 break;
2140 case VUT_CITYSTATUS:
2141 if (preq->source.value.citystatus == CITYS_TRANSFERRED) {
2142 /* If there's a change, it will invalidate worklist anyway. */
2143 purge = TRUE;
2144 } else if (preq->source.value.citystatus == CITYS_OWNED_BY_ORIGINAL) {
2145 if (preq->range == REQ_RANGE_CITY || preq->range == REQ_RANGE_TILE) {
2146 /* Can't change at these ranges */
2147 purge = TRUE;
2148 } else {
2149 if (preq->present) {
2150 notify_player(pplayer, city_tile(pcity),
2152 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2153 _("%s can't build %s from the worklist; "
2154 "only available when city in range %s \"%s\". "
2155 "Postponing..."),
2157 tgt_name, req_range_name(preq->range),
2158 citystatus_type_name(preq->source.value.citystatus));
2160 pcity, "need_citystatus");
2161 } else {
2162 notify_player(pplayer, city_tile(pcity),
2164 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2165 _("%s can't build %s from the worklist; "
2166 "not available when city in range %s is \"%s\". "
2167 "Postponing..."),
2169 tgt_name, req_range_name(preq->range),
2170 citystatus_type_name(preq->source.value.citystatus));
2172 pcity, "have_citystatus");
2173 }
2174 }
2175 } else {
2176 /* Other status types will only happen with a bogus ruleset. */
2177 log_error("worklist_change_build_target() has bogus citystatus preq");
2178 }
2179 break;
2180 case VUT_MINYEAR:
2181 if (preq->present) {
2182 notify_player(pplayer, city_tile(pcity),
2184 /* TRANS: last %s is a date */
2185 _("%s can't build %s from the worklist; "
2186 "only available from %s. Postponing..."),
2188 tgt_name,
2189 textyear(preq->source.value.minyear));
2191 pcity, "need_minyear");
2192 } else {
2193 /* Can't go back in time. */
2194 purge = TRUE;
2195 }
2196 break;
2197 case VUT_MINCALFRAG:
2198 /* Unlike VUT_MINYEAR, a requirement in either direction is
2199 * likely to be fulfilled sooner or later. */
2200 if (preq->present) {
2201 notify_player(pplayer, city_tile(pcity),
2203 /* TRANS: last %s is a calendar fragment from
2204 * the ruleset; may be a bare number */
2205 _("%s can't build %s from the worklist; "
2206 "only available from %s. Postponing..."),
2208 tgt_name,
2209 textcalfrag(preq->source.value.mincalfrag));
2211 pcity, "need_mincalfrag");
2212 } else {
2213 fc_assert_action(preq->source.value.mincalfrag > 0, break);
2214 notify_player(pplayer, city_tile(pcity),
2216 /* TRANS: last %s is a calendar fragment from
2217 * the ruleset; may be a bare number */
2218 _("%s can't build %s from the worklist; "
2219 "not available after %s. Postponing..."),
2221 tgt_name,
2222 textcalfrag(preq->source.value.mincalfrag - 1));
2224 pcity, "have_mincalfrag");
2225 }
2226 break;
2227 case VUT_TOPO:
2228 if (preq->present) {
2229 notify_player(pplayer, city_tile(pcity),
2231 /* TRANS: third %s is topology flag name
2232 * ("Hex", "ISO" */
2233 _("%s can't build %s from the worklist; "
2234 "only available in worlds with %s map."),
2236 tgt_name,
2237 _(topo_flag_name(preq->source.value.topo_property)));
2239 pcity, "need_topo");
2240 }
2241 purge = TRUE;
2242 break;
2243 case VUT_WRAP:
2244 if (preq->present) {
2245 notify_player(pplayer, city_tile(pcity),
2247 /* TRANS: third %s is wrap flag name
2248 * ("WrapX", "Wrapy") */
2249 _("%s can't build %s from the worklist; "
2250 "only available in worlds with %s map."),
2252 tgt_name,
2253 _(wrap_flag_name(preq->source.value.wrap_property)));
2255 pcity, "need_wrap");
2256 }
2257 purge = TRUE;
2258 break;
2259 case VUT_SERVERSETTING:
2260 notify_player(pplayer, city_tile(pcity),
2262 /* TRANS: %s is a server setting, its value and
2263 * if it is required to be present or absent.
2264 * The string's format is specified in
2265 * ssetv_human_readable().
2266 * Example: "killstack is enabled". */
2267 _("%s can't build %s from the worklist; "
2268 "only available when the server setting "
2269 "%s."),
2271 tgt_name,
2272 ssetv_human_readable(preq->source.value.ssetval,
2273 preq->present));
2275 pcity, "need_setting");
2276 /* Don't assume that the server setting will be changed. */
2277 purge = TRUE;
2278 break;
2279 case VUT_AGE:
2280 if (preq->present) {
2281 notify_player(pplayer, city_tile(pcity),
2283 _("%s can't build %s from the worklist; "
2284 "only available once %d turns old. Postponing..."),
2286 tgt_name,
2287 preq->source.value.age);
2289 pcity, "need_age");
2290 } else {
2291 /* Can't go back in time. */
2292 purge = TRUE;
2293 }
2294 break;
2295 case VUT_FORM_AGE:
2296 if (preq->present) {
2297 notify_player(pplayer, city_tile(pcity),
2299 _("%s can't build %s from the worklist; "
2300 "only available once %d turns old form. Postponing..."),
2302 tgt_name,
2303 preq->source.value.age);
2305 pcity, "need_form_age");
2306 } else {
2307 /* Can't go back in time. */
2308 purge = TRUE;
2309 }
2310 break;
2311 case VUT_NONE:
2312 case VUT_COUNT:
2314 "worklist_change_build_target() "
2315 "called with invalid preq");
2316 break;
2317 /* No default handling here, as we want compiler warning
2318 * if new requirement type is added to enum and it's not handled
2319 * here. */
2320 };
2321 break;
2322 }
2323
2324 /* Almost all cases emit signal in the end, so city check needed. */
2325 if (!city_exist(saved_id)) {
2326 /* Some script has removed city */
2327 return TRUE;
2328 }
2329
2331
2332 if (!known) {
2333 /* FIXME: make can_city_build_improvement_now() return a reason enum,
2334 * so we can notify user with it.
2335 * Likely the building already exist. */
2336 purge = TRUE;
2337 }
2338
2339 return purge;
2340}
2341
2342/**********************************************************************/
2348static bool worklist_change_build_target(struct player *pplayer,
2349 struct city *pcity)
2350{
2351 struct universal target;
2352 bool success = FALSE;
2353 int i;
2354 int saved_id = pcity->id;
2355 bool city_checked = TRUE; /* This is used to avoid spurious city_exist() calls */
2356 struct worklist *pwl = &pcity->worklist;
2357 const struct civ_map *nmap = &(wld.map);
2358
2359 if (worklist_is_empty(pwl)) {
2360 /* Nothing in the worklist; bail now. */
2361 return FALSE;
2362 }
2363
2364 i = 0;
2365 while (!success && i < worklist_length(pwl)) {
2366
2367 if (!city_checked) {
2368 if (!city_exist(saved_id)) {
2369 /* Some script has removed useless city that cannot build
2370 * what it is told to! */
2371 return FALSE;
2372 }
2374 }
2375
2376 if (worklist_peek_ith(pwl, &target, i)) {
2377 success = can_city_build_now(nmap, pcity, &target);
2378 } else {
2379 success = FALSE;
2380 }
2381 i++;
2382
2383 if (success) {
2384 break; /* while */
2385 }
2386
2387 switch (target.kind) {
2388 case VUT_UTYPE:
2389 {
2390 const struct unit_type *ptarget = target.value.utype;
2392 bool purge;
2393
2394 /* Maybe we can just upgrade the target to what the city /can/ build. */
2395 if (U_NOT_OBSOLETED == pupdate) {
2396 /* Nope, we're stuck. Skip this item from the worklist. */
2397 struct research *presearch = research_get(pplayer);
2398 struct advance *missing = nullptr;
2399 bool multiple = FALSE;
2400
2403 if (missing != nullptr) {
2404 multiple = TRUE;
2405 } else {
2406 missing = padv;
2407 }
2408 }
2410
2411
2412 purge = FALSE;
2413 if (missing != nullptr) {
2414 if (!multiple) {
2415 notify_player(pplayer, city_tile(pcity),
2417 _("%s can't build %s from the worklist; "
2418 "tech %s not yet available. Postponing..."),
2421 } else {
2422 notify_player(pplayer, city_tile(pcity),
2424 _("%s can't build %s from the worklist; "
2425 "multiple techs still needed. Postponing..."),
2427 }
2428
2429 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2430 "need_tech");
2431 } else {
2432 /* Unknown or requirement from vector. */
2433 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2434 saved_id);
2435 }
2437 if (!purge) {
2438 break;
2439 }
2440 } else {
2442 }
2443 if (purge) {
2444 /* If the city can never build this unit or its descendants,
2445 * drop it. */
2446 notify_player(pplayer, city_tile(pcity),
2448 _("%s can't build %s from the worklist. Purging..."),
2450 /* Yes, warn about the targets that's actually
2451 in the worklist, not its obsolete-closure
2452 pupdate. */
2454 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2455 "never");
2456 if (city_exist(saved_id)) {
2458 /* Purge this worklist item. */
2459 i--;
2461 } else {
2463 }
2464 } else {
2465 /* Yep, we can go after pupdate instead. Joy! */
2467 _("Production of %s is upgraded to %s in %s."),
2470 city_link(pcity));
2471 target.value.utype = pupdate;
2472 }
2473 break;
2474 }
2475 case VUT_IMPROVEMENT:
2476 {
2477 const struct impr_type *ptarget = target.value.building;
2479 bool purge;
2480
2481 /* If the city can never build this improvement, drop it. */
2483 purge = !success;
2484
2485 /* Maybe this improvement has been obsoleted by something that
2486 we can build. */
2487 if (purge) {
2488 /* Nope, no use. *sigh* */
2489
2490 /* Can it be postponed? */
2492 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2493 saved_id);
2494
2495 /* Almost all cases emit signal in the end, so city check needed. */
2496 if (!city_exist(saved_id)) {
2497 /* Some script has removed city */
2498 return FALSE;
2499 }
2501 }
2502 } else if (success) {
2503 /* Hey, we can upgrade the improvement! */
2505 _("Production of %s is upgraded to %s in %s."),
2508 city_link(pcity));
2509 target.value.building = pupdate;
2510 }
2511
2512 if (purge) {
2513 /* Never in a million years. */
2514 notify_player(pplayer, city_tile(pcity),
2516 _("%s can't build %s from the worklist. Purging..."),
2519 script_server_signal_emit("building_cant_be_built", ptarget, pcity,
2520 "never");
2521 if (city_exist(saved_id)) {
2523 /* Purge this worklist item. */
2524 i--;
2526 } else {
2528 }
2529 }
2530 break;
2531 }
2532 default:
2533 /* skip useless target */
2534 log_error("worklist_change_build_target() has unrecognized "
2535 "target kind (%d)", target.kind);
2536 break;
2537 };
2538 } /* while */
2539
2540 if (success) {
2541 /* All okay. Switch targets. */
2542 change_build_target(pplayer, pcity, &target, E_WORKLIST);
2543
2544 /* i is the index immediately _after_ the item we're changing to.
2545 Remove the (i-1)th item from the worklist. */
2546 worklist_remove(pwl, i - 1);
2547 }
2548
2549 if (worklist_is_empty(pwl)) {
2550 /* There *was* something in the worklist, but it's empty now. Bug the
2551 player about it. */
2553 /* TRANS: The <city> worklist .... */
2554 _("The %s worklist is now empty."),
2555 city_link(pcity));
2556 }
2557
2558 return success;
2559}
2560
2561/**********************************************************************/
2566void choose_build_target(struct player *pplayer, struct city *pcity)
2567{
2568 const struct civ_map *nmap = &(wld.map);
2569
2570 /* Pick the next thing off the worklist. */
2571 if (worklist_change_build_target(pplayer, pcity)) {
2572 return;
2573 }
2574
2575 /* Try building the same thing again. Repeat building doesn't require a
2576 * call to change_build_target, so just return. */
2577 switch (pcity->production.kind) {
2578 case VUT_UTYPE:
2579 /* We can build a unit again unless it's unique or we have lost the tech. */
2580 if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
2581 && can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
2582 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2583 utype_rule_name(pcity->production.value.utype));
2584 return;
2585 }
2586 break;
2587 case VUT_IMPROVEMENT:
2588 if (can_city_build_improvement_now(pcity, pcity->production.value.building)) {
2589 /* We can build space and coinage again, and possibly others. */
2590 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2591 improvement_rule_name(pcity->production.value.building));
2592 return;
2593 }
2594 break;
2595 default:
2596 /* fallthru */
2597 break;
2598 };
2599
2600 /* Find *something* to do! */
2601 log_debug("Trying advisor_choose_build.");
2602 advisor_choose_build(pplayer, pcity);
2603 log_debug("Advisor_choose_build didn't kill us.");
2604}
2605
2606/**********************************************************************/
2611static const struct impr_type *building_upgrades_to(struct city *pcity,
2612 const struct impr_type *pimprove)
2613{
2614 const struct impr_type *check = pimprove;
2615 const struct impr_type *best_upgrade = nullptr;
2616
2618 return nullptr;
2619 }
2623 }
2624 }
2625
2626 return best_upgrade;
2627}
2628
2629/**********************************************************************/
2633{
2634 const struct impr_type *producing = pcity->production.value.building;
2636
2640 _("Production of %s is upgraded to %s in %s."),
2643 city_link(pcity));
2644 pcity->production.kind = VUT_IMPROVEMENT;
2645 pcity->production.value.building = upgrading;
2646 }
2647}
2648
2649/**********************************************************************/
2657static const struct unit_type *unit_upgrades_to(struct city *pcity,
2658 const struct unit_type *punittype)
2659{
2660 const struct unit_type *check = punittype;
2661 const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
2662 const struct civ_map *nmap = &(wld.map);
2663
2665 return U_NOT_OBSOLETED;
2666 }
2667 while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
2670 }
2671 }
2672
2673 return best_upgrade;
2674}
2675
2676/**********************************************************************/
2679static void upgrade_unit_prod(struct city *pcity)
2680{
2681 const struct unit_type *producing = pcity->production.value.utype;
2683 const struct civ_map *nmap = &(wld.map);
2684
2688 _("Production of %s is upgraded to %s in %s."),
2691 city_link(pcity));
2692 pcity->production.value.utype = upgrading;
2693 }
2694}
2695
2696/**********************************************************************/
2703static bool city_distribute_surplus_shields(struct player *pplayer,
2704 struct city *pcity)
2705{
2706 int size_reduction = 0;
2707 struct unit *sacrifizer;
2708
2709 if (pcity->surplus[O_SHIELD] < 0) {
2710 unit_list_iterate_safe(pcity->units_supported, punit) {
2712 && pcity->surplus[O_SHIELD] < 0) {
2713 const char *punit_link = unit_link(punit);
2714
2715 /* TODO: Should the unit try to help cities on adjacent tiles? That
2716 * would be a rules change. (This action is performed by the game
2717 * it self) */
2720 notify_player(pplayer, city_tile(pcity),
2722 _("%s can't upkeep %s, unit disbanded."),
2724 }
2725
2726 /* pcity->surplus[O_SHIELD] is automatically updated. */
2727 }
2729 }
2730
2731 if (pcity->surplus[O_SHIELD] < 0) {
2732 /* Special case: MissingXProtected. This nasty unit won't go so easily.
2733 * It'd rather make the citizens pay in blood for their failure to upkeep
2734 * it! If we make it here all normal units are already disbanded, so only
2735 * undisbandable ones remain. */
2736 unit_list_iterate_safe(pcity->units_supported, punit) {
2738
2739 if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
2740
2742 sacrifizer = punit;
2743
2744 /* No upkeep for the unit this turn. */
2745 pcity->surplus[O_SHIELD] += upkeep;
2746 }
2748 }
2749
2750 /* Now we confirm changes made last turn. */
2751 pcity->shield_stock += pcity->surplus[O_SHIELD];
2752 pcity->before_change_shields = pcity->shield_stock;
2753 pcity->last_turns_shield_surplus = pcity->surplus[O_SHIELD];
2754
2755 /* Previous turn values stored, and they are consistent with
2756 * other previous turn data.
2757 * Now reduce city size, likely messing all the values. */
2758 if (size_reduction > 0) {
2759 if (size_reduction == 1) {
2760 notify_player(pplayer, city_tile(pcity),
2762 _("Citizens in %s perish for their failure to "
2763 "upkeep %s!"),
2765 } else {
2766 notify_player(pplayer, city_tile(pcity),
2768 _("Citizens in %s perish for their failure to "
2769 "upkeep units!"),
2770 city_link(pcity));
2771 }
2772
2773 if (!city_reduce_size(pcity, size_reduction, nullptr, "upkeep_failure")) {
2774 return FALSE;
2775 }
2776 }
2777
2778 return TRUE;
2779}
2780
2781/**********************************************************************/
2784static bool city_build_building(struct player *pplayer, struct city *pcity)
2785{
2786 bool space_part;
2787 int mod;
2788 const struct impr_type *pimprove;
2789 int saved_id = pcity->id;
2790 const struct civ_map *nmap = &(wld.map);
2791
2792 if (is_convert_improvement(pcity->production.value.building)) {
2793 /* Coinage-like improvements that convert production */
2794 fc_assert(pcity->before_change_shields >= 0);
2795
2796 /* pcity->before_change_shields already contains the surplus from
2797 * this turn. */
2799 pplayer->economic.gold += pcity->before_change_shields;
2801 pplayer->economic.infra_points += pcity->before_change_shields;
2802 }
2803
2804 pcity->before_change_shields = 0;
2805 pcity->shield_stock = 0;
2806 choose_build_target(pplayer, pcity);
2807
2808 return TRUE;
2809 }
2810
2812
2813 /* The final (after upgrade) build target */
2814 pimprove = pcity->production.value.building;
2815
2816 if (!can_city_build_improvement_now(pcity, pimprove)) {
2818 _("%s is building %s, which is no longer available."),
2821 script_server_signal_emit("building_cant_be_built", pimprove, pcity,
2822 "unavailable");
2823 return TRUE;
2824 }
2825 if (pcity->shield_stock >= impr_build_shield_cost(pcity, pimprove)
2827 int cost;
2828
2829 if (is_small_wonder(pimprove)) {
2830 city_list_iterate(pplayer->cities, wcity) {
2831 if (city_has_building(wcity, pimprove)) {
2832 city_remove_improvement(wcity, pimprove);
2833 break;
2834 }
2836 }
2837
2838 space_part = TRUE;
2840 RPT_CERTAIN) > 0) {
2841 pplayer->spaceship.structurals++;
2843 RPT_CERTAIN) > 0) {
2844 pplayer->spaceship.components++;
2846 RPT_CERTAIN) > 0) {
2847 pplayer->spaceship.modules++;
2848 } else {
2849 space_part = FALSE;
2851 _("Completion of %s"));
2852 }
2853 cost = impr_build_shield_cost(pcity, pimprove);
2854 pcity->before_change_shields -= cost;
2855 pcity->shield_stock -= cost;
2856 pcity->turn_last_built = game.info.turn;
2857 /* To eliminate micromanagement */
2858 if (is_great_wonder(pimprove)) {
2860 _("The %s have finished building %s in %s."),
2861 nation_plural_for_player(pplayer),
2863 city_link(pcity));
2864 }
2865
2867 _("%s has finished building %s."),
2869 script_server_signal_emit("building_built", pimprove, pcity);
2870
2871 if (!city_exist(saved_id)) {
2872 /* Script removed city */
2873 return FALSE;
2874 }
2875
2876 /* Call this function since some buildings may change the
2877 * the vision range of a city */
2879
2881 RPT_CERTAIN))) {
2882 struct research *presearch = research_get(pplayer);
2883 char research_name[MAX_LEN_NAME * 2];
2884 int i;
2885 const char *provider = improvement_name_translation(pimprove);
2886
2888 PL_("%s boosts research; you gain %d immediate "
2889 "advance.",
2890 "%s boosts research; you gain %d immediate "
2891 "advances.",
2892 mod), provider, mod);
2893
2895 for (i = 0; i < mod; i++) {
2898
2901 /* TRANS: Tech from building (Darwin's Voyage) */
2902 Q_("?frombldg:Acquired %s from %s."), adv_name,
2903 provider);
2904
2906 /* TRANS: Tech from building (Darwin's
2907 * Voyage) */
2908 Q_("?frombldg:The %s have acquired %s "
2909 "from %s."),
2911 }
2912 }
2913 if (space_part && pplayer->spaceship.state == SSHIP_NONE) {
2915 _("The %s have started building a spaceship!"),
2916 nation_plural_for_player(pplayer));
2917 pplayer->spaceship.state = SSHIP_STARTED;
2918 }
2919 if (space_part) {
2920 /* Space ship part build */
2921 send_spaceship_info(pplayer, nullptr);
2922 } else {
2923 /* Update city data. */
2924 if (city_refresh(pcity)) {
2926 }
2927 }
2928
2929 /* Move to the next thing in the worklist */
2930 choose_build_target(pplayer, pcity);
2931 }
2932
2933 return TRUE;
2934}
2935
2936/**********************************************************************/
2945static struct unit *city_create_unit(struct city *pcity,
2946 const struct unit_type *utype,
2947 struct citizens_reduction *red)
2948{
2949 struct player *pplayer = city_owner(pcity);
2950 struct unit *punit;
2951 int saved_unit_id;
2952 int pop_cost = utype_pop_value(utype, pcity);
2953
2956 pcity->id, -1, -1);
2957 pplayer->score.units_built++;
2958
2959 if (pop_cost > 0 && pcity->nationality != nullptr) {
2960 /* We don't reduce city size in-place to keep it correct and
2961 * existing at all while we call the following callback.
2962 * We want citizens_unit_nationality() to adjust 'red' even when
2963 * we are not setting unit nationality based on the return */
2964 struct player *nat = citizens_unit_nationality(pcity, pop_cost, red);
2965
2968 }
2969 } else if (red) {
2970 red->change = 0;
2971 }
2972
2973 (void) place_unit(punit, pplayer, pcity, nullptr, FALSE);
2975
2976 /* If city has a rally point set, give the unit a move order. */
2977 if (pcity->rally_point.length) {
2979 punit->orders.length = pcity->rally_point.length;
2980 punit->orders.vigilant = pcity->rally_point.vigilant;
2981 punit->orders.list = fc_malloc(pcity->rally_point.length
2982 * sizeof(struct unit_order));
2983 memcpy(punit->orders.list, pcity->rally_point.orders,
2984 pcity->rally_point.length * sizeof(struct unit_order));
2985 }
2986
2987 /* This might destroy pcity and/or punit: */
2988 script_server_signal_emit("unit_built", punit, pcity);
2989
2991 return punit;
2992 } else {
2993 return nullptr;
2994 }
2995}
2996
2997/**********************************************************************/
3006static bool city_build_unit(struct player *pplayer, struct city *pcity)
3007{
3008 const struct unit_type *utype;
3009 struct worklist *pwl = &pcity->worklist;
3011 int saved_city_id = pcity->id;
3012 const struct civ_map *nmap = &(wld.map);
3013
3014 fc_assert_ret_val(pcity->production.kind == VUT_UTYPE, FALSE);
3015
3016 /* If the city has already bought a unit which is now obsolete, don't try
3017 * to upgrade the production. The new unit might require more shields, which
3018 * would be bad if it was bought to urgently defend a city. (Equally it
3019 * might be the same cost or cheaper, but tough; you hurried the unit so
3020 * you miss out on technological advances.) */
3023 }
3024
3025 utype = pcity->production.value.utype;
3027
3028 /* We must make a special case for barbarians here, because they are
3029 so dumb. Really. They don't know the prerequisite techs for units
3030 they build!! - Per */
3032 && !is_barbarian(pplayer)) {
3034 _("%s is building %s, which is no longer available."),
3036
3037 /* Log before signal emitting, so pointers are certainly valid */
3038 log_verbose("%s %s tried to build %s, which is not available.",
3041 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3042 "unavailable");
3043 return city_exist(saved_city_id);
3044 }
3045
3046 if (pcity->shield_stock >= unit_shield_cost
3048 int pop_cost = utype_pop_value(utype, pcity);
3049 struct unit *punit;
3050
3051 /* Should we disband the city? -- Massimo */
3052 if (city_size_get(pcity) == pop_cost
3054 return !disband_city(pcity);
3055 }
3056
3057 if (city_size_get(pcity) <= pop_cost) {
3059 /* TRANS: city ... utype ... size ... pop_cost */
3060 _("%s can't build %s yet. "
3061 "(city size: %d, unit population cost: %d)"),
3063 city_size_get(pcity), pop_cost);
3064 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3065 "pop_cost");
3066 return city_exist(saved_city_id);
3067 }
3068
3069 fc_assert(pop_cost == 0 || city_size_get(pcity) >= pop_cost);
3070
3071 /* don't update turn_last_built if we returned above */
3072 pcity->turn_last_built = game.info.turn;
3073
3074 /* check if we can build more than one unit (effect City_Build_Slots) */
3076
3077 /* We should be able to build at least one (by checks above) */
3078 fc_assert(num_units >= 1);
3079
3080 for (i = 0; i < num_units; i++) {
3082
3084
3085 /* Check if the city still exists (script might have removed it).
3086 * If not, we assume any effects / announcements done below were
3087 * already replaced by the script if necessary. */
3088 if (!city_exist(saved_city_id)) {
3089 break;
3090 }
3091
3092 if (punit) {
3093 if (punit->carrying
3096 /* TRANS: <city> is finished building <unit>, carrying <goods>. */
3097 _("%s is finished building %s, carrying %s."),
3100 } else {
3102 /* TRANS: <city> is finished building <unit/building>. */
3103 _("%s is finished building %s."),
3105 }
3106 }
3107
3108 /* After we created the unit remove the citizen. This will also
3109 * rearrange the worker to take into account the extra resources
3110 * (food) needed. */
3111 if (pop_cost > 0) {
3112 /* This won't disband city due to pop_cost, but script might
3113 * still destroy city. */
3115 /* If the city has changed its nationalities during
3116 * "unit_built" signal, we take some other citizens instead */
3117 if (!city_reduce_size(pcity, pop_cost, nullptr, "unit_built")) {
3118 break;
3119 }
3120 }
3121
3122 /* to eliminate micromanagement, we only subtract the unit's cost */
3123 /* signals could change the prod stock! */
3124 if ((pcity->before_change_shields -= unit_shield_cost) < 0) {
3125 pcity->before_change_shields = 0;
3126 }
3127 if ((pcity->shield_stock -= unit_shield_cost) < 0) {
3128 log_normal("City %s (%s) has built %s but has no %d shields "
3129 "for it, nullifying shield stock", city_name_get(pcity),
3130 player_name(pplayer), utype_rule_name(utype),
3132 pcity->shield_stock = 0;
3133 }
3134
3135 if (pop_cost > 0) {
3136 /* Additional message if the unit has population cost. */
3138 ftc_server,
3139 /* TRANS: "<unit> cost... <city> shrinks..."
3140 * Plural in "%d population", not "size %d". */
3141 PL_("%s cost %d population. %s shrinks to size %d.",
3142 "%s cost %d population. %s shrinks to size %d.",
3143 pop_cost),
3144 utype_name_translation(utype), pop_cost,
3146 }
3147
3148 if (i != 0 && worklist_length(pwl) > 0) {
3149 /* remove the build unit from the worklist; it has to be one less
3150 * than units build to preserve the next build target from the
3151 * worklist */
3152 worklist_remove(pwl, 0);
3153 }
3154 } /* for */
3155
3157 if (pcity->rally_point.length && !pcity->rally_point.persistent) {
3159 }
3160
3161 /* Done building this unit; time to move on to the next. */
3162 choose_build_target(pplayer, pcity);
3163 }
3164 } /* if */
3165
3166 return city_exist(saved_city_id);
3167}
3168
3169/**********************************************************************/
3172static bool city_build_stuff(struct player *pplayer, struct city *pcity)
3173{
3174 if (!city_distribute_surplus_shields(pplayer, pcity)) {
3175 return FALSE;
3176 }
3177
3180
3181 switch (pcity->production.kind) {
3182 case VUT_IMPROVEMENT:
3183 return city_build_building(pplayer, pcity);
3184 case VUT_UTYPE:
3185 return city_build_unit(pplayer, pcity);
3186 default:
3187 /* Must never happen! */
3189 break;
3190 };
3191
3192 return FALSE;
3193}
3194
3195/**********************************************************************/
3205static bool sell_random_building(struct player *pplayer,
3206 struct cityimpr_list *imprs)
3207{
3208 struct cityimpr *pcityimpr;
3209 int r;
3210
3211 fc_assert_ret_val(pplayer != nullptr, FALSE);
3212
3213 if (!imprs || cityimpr_list_size(imprs) == 0) {
3214 return FALSE;
3215 }
3216
3219
3221 ftc_server,
3222 _("Can't afford to maintain %s in %s, building sold!"),
3224 city_link(pcityimpr->pcity));
3225 log_debug("%s: sold building (%s)", player_name(pplayer),
3227
3228 do_sell_building(pplayer, pcityimpr->pcity, pcityimpr->pimprove, "cant_maintain");
3229
3231
3232 /* Get back the gold upkeep that was already paid this turn. */
3234 pcityimpr->pimprove);
3235
3237
3239
3240 return TRUE;
3241}
3242
3243/**********************************************************************/
3251static void uk_rem_gold_callback(struct unit *punit)
3252{
3253 int gold_upkeep;
3254
3255 /* Remove the unit from uk_rem_gold. */
3257
3258 gold_upkeep = punit->server.upkeep_paid[O_GOLD];
3259
3260 /* All units in uk_rem_gold should have gold upkeep! */
3261 fc_assert_ret_msg(gold_upkeep > 0, "%s has %d gold upkeep",
3262 unit_rule_name(punit), gold_upkeep);
3263
3264 /* Get the upkeep gold back. */
3265 unit_owner(punit)->economic.gold += gold_upkeep;
3266}
3267
3268/**********************************************************************/
3272static void uk_rem_gold_append(struct unit *punit)
3273{
3274 /* Make the unit aware that it is on the uk_rem_gold list. */
3276
3277 /* Add the unit to the list. */
3279}
3280
3281/**********************************************************************/
3285static void unit_list_referred_destroy(struct unit_list *punitlist)
3286{
3288 /* Clear the unit's knowledge of the list. */
3291
3292 /* Destroy the list it self. */
3294}
3295
3296/**********************************************************************/
3308static struct unit *sell_random_unit(struct player *pplayer,
3309 struct unit_list *punitlist)
3310{
3311 struct unit *punit;
3312 int r;
3313 struct unit_list *cargo;
3314
3315 fc_assert_ret_val(pplayer != nullptr, nullptr);
3316
3317 if (!punitlist || unit_list_size(punitlist) == 0) {
3318 return nullptr;
3319 }
3320
3323
3324 cargo = unit_list_new();
3325
3326 /* Check if unit is transporting other units from punitlist,
3327 * and sell one of those (recursively) instead.
3328 * Note that in case of recursive transports we have to iterate
3329 * also through those middle transports that themselves are not in
3330 * punitlist. */
3332 /* Optimization, do not iterate over punitlist
3333 * if we are sure that pcargo is not in it. */
3334 if (pcargo->server.upkeep_paid[O_GOLD] > 0) {
3336 if (pcargo == p2) {
3337 unit_list_append(cargo, pcargo);
3338 }
3340 }
3342
3343 if (unit_list_size(cargo) > 0) {
3344 /* Recursively sell. Note that cargo list has both
3345 * leaf units and middle transports in case of
3346 * recursive transports. */
3347 struct unit *ret = sell_random_unit(pplayer, cargo);
3348
3349 unit_list_destroy(cargo);
3350
3352
3353 return ret;
3354 }
3355
3356 unit_list_destroy(cargo);
3357
3358 {
3359 const char *punit_link = unit_tile_link(punit);
3360#ifdef FREECIV_DEBUG
3361 const char *punit_logname = unit_rule_name(punit);
3362#endif /* FREECIV_DEBUG */
3363 struct tile *utile = unit_tile(punit);
3364
3368
3369 /* The gold was paid back when the unit removal made
3370 * uk_rem_gold_callback() run as the unit's removal call back. */
3371
3372 notify_player(pplayer, utile, E_UNIT_LOST_MISC, ftc_server,
3373 _("Not enough gold. %s disbanded."),
3374 punit_link);
3375 log_debug("%s: unit sold (%s)", player_name(pplayer),
3377 } else {
3378 /* Not able to get rid of punit */
3379 return nullptr;
3380 }
3381 }
3382
3384
3385 return punit;
3386}
3387
3388/**********************************************************************/
3392{
3393 struct cityimpr_list *pimprlist;
3394 bool sell_unit = TRUE;
3395
3396 if (!pplayer) {
3397 return FALSE;
3398 }
3399
3402
3403 city_list_iterate(pplayer->cities, pcity) {
3404 city_built_iterate(pcity, pimprove) {
3405 if (can_city_sell_building(pcity, pimprove)) {
3406 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3407
3408 ci->pcity = pcity;
3409 ci->pimprove = pimprove;
3411 }
3414
3415 unit_list_iterate(pplayer->units, punit) {
3416 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3418 }
3420
3421 while (pplayer->economic.gold < 0
3423 || unit_list_size(uk_rem_gold) > 0)) {
3425 || unit_list_size(uk_rem_gold) == 0) {
3427 } else {
3428 sell_random_unit(pplayer, uk_rem_gold);
3429 }
3431 }
3432
3433 /* Free remaining entries from list */
3435 FC_FREE(pimpr);
3437
3438 if (pplayer->economic.gold < 0) {
3439 /* If we get here it means the player has
3440 * negative gold. This should never happen. */
3441 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3442 player_name(pplayer), player_number(pplayer));
3443 }
3444
3447
3448 return pplayer->economic.gold >= 0;
3449}
3450
3451/**********************************************************************/
3455{
3456 if (!pplayer) {
3457 return FALSE;
3458 }
3459
3461
3462 unit_list_iterate(pplayer->units, punit) {
3463 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3465 }
3467
3468 while (pplayer->economic.gold < 0
3469 && sell_random_unit(pplayer, uk_rem_gold)) {
3470 /* All done in sell_random_unit() */
3471 }
3472
3473 if (pplayer->economic.gold < 0) {
3474 /* If we get here it means the player has
3475 * negative gold. This should never happen. */
3476 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3477 player_name(pplayer), player_number(pplayer));
3478 }
3479
3481
3482 return pplayer->economic.gold >= 0;
3483}
3484
3485/**********************************************************************/
3489{
3490 struct player *pplayer;
3491 struct cityimpr_list *pimprlist;
3492
3493 if (!pcity) {
3494 return TRUE;
3495 }
3496
3497 pplayer = city_owner(pcity);
3499
3500 /* Create a vector of all buildings that can be sold. */
3501 city_built_iterate(pcity, pimprove) {
3502 if (can_city_sell_building(pcity, pimprove)) {
3503 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3504
3505 ci->pcity = pcity;
3506 ci->pimprove = pimprove;
3508 }
3510
3511 /* Try to sell some buildings. */
3512 while (pplayer->economic.gold < 0
3513 && sell_random_building(pplayer, pimprlist)) {
3514 /* all done in sell_random_building */
3515 }
3516
3517 /* Free remaining entries from list */
3519 FC_FREE(pimpr);
3521
3523
3524 return pplayer->economic.gold >= 0;
3525}
3526
3527/**********************************************************************/
3536{
3537 struct player *pplayer;
3538
3539 if (!pcity) {
3540 return TRUE;
3541 }
3542
3543 pplayer = city_owner(pcity);
3545
3546 /* Create a vector of all supported units with gold upkeep. */
3547 unit_list_iterate(pcity->units_supported, punit) {
3548 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3550 }
3552
3553 /* Still not enough gold, so try "selling" some units. */
3554 while (pplayer->economic.gold < 0
3555 && sell_random_unit(pplayer, uk_rem_gold)) {
3556 /* All done in sell_random_unit() */
3557 }
3558
3559 /* If we get here the player has negative gold, but hopefully
3560 * another city will be able to pay the deficit, so continue. */
3561
3563
3564 return pplayer->economic.gold >= 0;
3565}
3566
3567/**********************************************************************/
3570static bool place_pollution(struct city *pcity, enum extra_cause cause)
3571{
3572 struct tile *ptile;
3573 struct tile *pcenter = city_tile(pcity);
3574 int city_radius_sq = city_map_radius_sq_get(pcity);
3575 int k = 100;
3576 const struct civ_map *nmap = &(wld.map);
3577
3578 while (k > 0) {
3579 /* Place pollution on a random city tile */
3580 int cx, cy;
3581 int tile_id = fc_rand(city_map_tiles(city_radius_sq));
3582 struct extra_type *pextra;
3583
3584 city_tile_index_to_xy(&cx, &cy, tile_id, city_radius_sq);
3585
3586 /* Check for a real map position */
3587 if (!(ptile = city_map_to_tile(nmap, pcenter, city_radius_sq, cx, cy))) {
3588 continue;
3589 }
3590
3591 pextra = rand_extra_for_tile(ptile, cause, FALSE);
3592
3593 if (pextra != nullptr && !tile_has_extra(ptile, pextra)) {
3594 tile_add_extra(ptile, pextra);
3595 update_tile_knowledge(ptile);
3596
3597 return TRUE;
3598 }
3599 k--;
3600 }
3601 log_debug("pollution not placed: city: %s", city_name_get(pcity));
3602
3603 return FALSE;
3604}
3605
3606/**********************************************************************/
3609static void check_pollution(struct city *pcity)
3610{
3611 if (fc_rand(100) < pcity->pollution) {
3614 _("Pollution near %s."), city_link(pcity));
3615 }
3616 }
3617}
3618
3619/**********************************************************************/
3626int city_incite_cost(struct player *pplayer, struct city *pcity)
3627{
3628 int dist, size;
3629 double cost; /* Intermediate values can get very large */
3630
3631 /* Gold factor */
3632 cost = city_owner(pcity)->economic.gold + game.server.base_incite_cost;
3633
3638
3639 /* Buildings */
3640 city_built_iterate(pcity, pimprove) {
3641 cost += impr_build_shield_cost(pcity, pimprove)
3644
3645 /* Stability bonuses */
3646 if (!city_unhappy(pcity)) {
3647 cost *= 2;
3648 }
3649 if (city_celebrating(pcity)) {
3650 cost *= 2;
3651 }
3652
3653 /* Buy back is cheap, conquered cities are also cheap */
3655 if (city_owner(pcity) != pcity->original) {
3656 if (pplayer == pcity->original) {
3657 cost /= 2; /* Buy back: 50% price reduction */
3658 } else {
3659 cost = cost * 2 / 3; /* Buy conquered: 33% price reduction */
3660 }
3661 }
3662 }
3663
3664 /* Distance from capital */
3665 /* Max penalty. Applied if there is no capital, or it's even further away. */
3666 dist = 32;
3668 if (is_capital(capital)) {
3669 int tmp = map_distance(capital->tile, pcity->tile);
3670
3671 if (tmp < dist) {
3672 dist = tmp;
3673 }
3674 }
3676
3680 - pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] * 3);
3681 cost *= size;
3683 cost = cost / (dist + 3);
3684
3686 int cost_per_citizen = cost / pcity->size;
3688 int tgt_cit = citizens_nation_get(pcity, pplayer->slot);
3689 int third_party = pcity->size - natives - tgt_cit;
3690
3691 cost = cost_per_citizen * (natives + 0.7 * third_party + 0.5 * tgt_cit);
3692 }
3693
3695 cost /= 100;
3696
3699 } else {
3700 return cost;
3701 }
3702}
3703
3704/**********************************************************************/
3708{
3709 /* Remember what this city is building last turn, so that on the next turn
3710 * the player can switch production to something else and then change it
3711 * back without penalty. This has to be updated _before_ production for
3712 * this turn is calculated, so that the penalty will apply if the player
3713 * changes production away from what has just been completed. This makes
3714 * sense if you consider what this value means: all the shields in the
3715 * city have been dedicated toward the project that was chosen last turn,
3716 * so the player shouldn't be penalized if the governor has to pick
3717 * something different. See city_change_production_penalty(). */
3718 pcity->changed_from = pcity->production;
3719
3720 log_debug("In %s, building %s. Beg of Turn shields = %d",
3722 pcity->before_change_shields);
3723}
3724
3725/**********************************************************************/
3729{
3730 pcity->disbanded_shields = 0;
3731 pcity->caravan_shields = 0;
3732}
3733
3734/**********************************************************************/
3739{
3741 pcity->before_change_shields = 0;
3742}
3743
3744/**********************************************************************/
3747static void update_city_activity(struct city *pcity)
3748{
3749 struct player *pplayer;
3750 struct government *gov;
3751 bool is_happy;
3752 bool is_celebrating;
3753
3754 if (!pcity) {
3755 return;
3756 }
3757
3758 pplayer = city_owner(pcity);
3762
3763 if (city_refresh(pcity)) {
3765 }
3766
3767 /* Reporting of celebrations rewritten, copying the treatment of disorder below,
3768 with the added rapture rounds count. 991219 -- Jing */
3769 if (city_build_stuff(pplayer, pcity)) {
3770 int saved_id;
3771 int revolution_turns;
3772
3773 pcity->history += city_history_gain(pcity);
3774
3775 /* History can decrease, but never go below zero */
3776 pcity->history = MAX(pcity->history, 0);
3777
3778 /* Keep old behavior when building new improvement could keep
3779 city celebrating */
3780 if (!is_happy) {
3782 }
3783
3785 pcity->rapture++;
3786
3787 /* Update city's celebrating counters */
3789 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3790 pcity->counter_values[pcount->index]++;
3791 }
3793
3794 if (pcity->rapture == 1) {
3796 _("Celebrations in your honor in %s."),
3797 city_link(pcity));
3798 }
3799 } else {
3800 if (pcity->rapture != 0) {
3802 _("Celebrations canceled in %s."),
3803 city_link(pcity));
3804 }
3805
3806 /* Update city's celebrating counters */
3808 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3809 pcity->counter_values[pcount->index] = 0;
3810 }
3812 pcity->rapture = 0;
3813 }
3814 pcity->was_happy = is_happy;
3815
3816 /* Handle the illness. */
3817 if (game.info.illness_on) {
3818 /* Recalculate city illness; illness due to trade has to be saved
3819 * within the city struct, as the client does not have all
3820 * the data to calculate it */
3821 pcity->server.illness
3822 = city_illness_calc(pcity, nullptr, nullptr,
3823 &(pcity->illness_trade), nullptr);
3824
3826 if (!city_illness_strike(pcity)) {
3827 /* Illness destroyed the city */
3828 return;
3829 }
3830 }
3831 }
3832
3833 /* City population updated here, after the rapture stuff above. --Jing */
3834 saved_id = pcity->id;
3835 pcity->had_famine = FALSE;
3836 city_populate(pcity, pplayer);
3837 if (player_city_by_number(pplayer, saved_id) == nullptr) {
3838 return;
3839 }
3840
3841 pcity->did_sell = FALSE;
3842 pcity->did_buy = FALSE;
3843 pcity->airlift = city_airlift_max(pcity);
3844 update_bulbs(pplayer, pcity->prod[O_SCIENCE], FALSE, FALSE);
3845
3847
3848 /* Update the treasury. */
3849 pplayer->economic.gold += pcity->surplus[O_GOLD];
3850
3851 /* FIXME: Nation level upkeep should be paid after ALL cities
3852 * have been processed, not after each individual city. */
3854 /* Unit upkeep was not included in city balance ->
3855 * not reduced from the city surplus. */
3857
3859 /* Building upkeep was not included in city balance ->
3860 * not reduced from the city surplus. */
3862 }
3863 }
3864
3865 /* Remember how much gold upkeep each unit was paid. */
3866 unit_list_iterate(pcity->units_supported, punit) {
3869
3870 if (pplayer->economic.gold < 0) {
3871 /* Not enough gold - we have to sell some buildings, and if that
3872 * is not enough, disband units with gold upkeep, taking into
3873 * account the setting of 'game.info.gold_upkeep_style':
3874 * GOLD_UPKEEP_CITY: Cities pay for buildings and units.
3875 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
3876 * for units.
3877 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
3878 switch (game.info.gold_upkeep_style) {
3879 case GOLD_UPKEEP_CITY:
3880 case GOLD_UPKEEP_MIXED:
3884 }
3885 break;
3886 case GOLD_UPKEEP_NATION:
3887 break;
3888 }
3889 }
3890
3892 if (city_unhappy(pcity)) {
3893 const char *revomsg;
3894
3895 pcity->anarchy++;
3896
3898 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3899 pcity->counter_values[pcount->index]++;
3900 }
3902
3903 if (pcity->anarchy == revolution_turns) {
3904 /* Revolution next turn if not dealt with */
3905 /* TRANS: preserve leading space; this string will be appended to
3906 * another sentence */
3907 revomsg = _(" Unrest threatens to spread beyond the city.");
3908 } else {
3909 revomsg = "";
3910 }
3911 if (pcity->anarchy == 1) {
3913 /* TRANS: second %s is an optional extra sentence */
3914 _("Civil disorder in %s.%s"),
3916 } else {
3918 /* TRANS: second %s is an optional extra sentence */
3919 _("CIVIL DISORDER CONTINUES in %s.%s"),
3921 }
3922 } else {
3923 if (pcity->anarchy != 0) {
3925 _("Order restored in %s."),
3926 city_link(pcity));
3927 }
3928 pcity->anarchy = 0;
3929
3931 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3932 pcity->counter_values[pcount->index] = 0;
3933 }
3935 }
3937
3938 send_city_info(nullptr, pcity);
3939
3940 if (revolution_turns > 0 && pcity->anarchy > revolution_turns) {
3942 /* TRANS: %s - government form, e.g., Democracy */
3943 _("The people have overthrown your %s, "
3944 "your country is in turmoil."),
3947 }
3948 if (city_refresh(pcity)) {
3950 }
3952 }
3953}
3954
3955/**********************************************************************/
3958static bool city_illness_check(const struct city * pcity)
3959{
3960 if (fc_rand(1000) < pcity->server.illness) {
3961 return TRUE;
3962 }
3963
3964 return FALSE;
3965}
3966
3967/**********************************************************************/
3971static bool disband_city(struct city *pcity)
3972{
3973 struct player *pplayer = city_owner(pcity);
3974 struct tile *ptile = pcity->tile;
3975 struct city *rcity = nullptr;
3976 const struct unit_type *utype = pcity->production.value.utype;
3977 struct unit *punit;
3978 int saved_id = pcity->id;
3979
3980 /* Find closest city other than pcity */
3981 rcity = find_closest_city(ptile, pcity, pplayer, FALSE, FALSE, FALSE, TRUE,
3982 FALSE, nullptr);
3983
3984 if (!rcity) {
3985 /* What should we do when we try to disband our only city? */
3986 notify_player(pplayer, ptile, E_CITY_CANTBUILD, ftc_server,
3987 _("%s can't build %s yet, "
3988 "as we can't disband our only city."),
3990 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3991 "pop_cost");
3992 if (!city_exist(saved_id)) {
3993 /* Script decided to remove even the last city */
3994 return TRUE;
3995 } else {
3996 return FALSE;
3997 }
3998 }
3999
4001
4002 /* "unit_built" script handler may have destroyed city. If so, we
4003 * assume something sensible happened to its units, and that the
4004 * script took care of announcing unit creation if required. */
4005 if (city_exist(saved_id)) {
4006 /* Shift all the units supported by pcity (including the new unit)
4007 * to rcity. transfer_city_units() does not make sure no units are
4008 * left floating without a transport, but since all units are
4009 * transferred this is not a problem. */
4010 transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity,
4011 pcity, -1, TRUE);
4012
4013 if (punit) {
4014 notify_player(pplayer, ptile, E_UNIT_BUILT, ftc_server,
4015 /* TRANS: "<city> is disbanded into Settler." */
4016 _("%s is disbanded into %s."),
4018 }
4019
4020 script_server_signal_emit("city_destroyed", pcity, pcity->owner, NULL);
4021
4022 if (!city_exist(saved_id)) {
4023 /* Already removed during the script */
4024 return TRUE;
4025 }
4027
4028 /* Since we've removed the city, we don't need to worry about
4029 * charging for production, disabling rally points, etc. */
4030 }
4031
4032 return TRUE;
4033}
4034
4035/**********************************************************************/
4083static float city_migration_score(struct city *pcity)
4084{
4085 float score = 0.0;
4086 int build_shield_cost = 0;
4087 bool has_wonder = FALSE;
4088
4089 if (!pcity) {
4090 return score;
4091 }
4092
4093 if (pcity->server.mgr_score_calc_turn == game.info.turn) {
4094 /* up-to-date migration score */
4095 return pcity->server.migration_score;
4096 }
4097
4098 /* feeling of the citizens */
4099 score = (city_size_get(pcity)
4100 + 1.00 * pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
4101 + 0.00 * pcity->feel[CITIZEN_CONTENT][FEELING_FINAL]
4102 - 0.25 * pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
4103 - 0.50 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
4104
4105 /* calculate shield build cost for all buildings */
4106 city_built_iterate(pcity, pimprove) {
4108 if (is_wonder(pimprove)) {
4109 /* this city has a wonder */
4110 has_wonder = TRUE;
4111 }
4113
4114 /* take shield costs of all buidings into account; normalized by 1000 */
4115 score *= (1 + (1 - exp(- (float) MAX(0, build_shield_cost) / 1000)) / 5);
4116 /* take trade into account; normalized by 100 */
4117 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_TRADE]) / 100))
4118 / 5);
4119 /* take luxury into account; normalized by 100 */
4120 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_LUXURY]) / 100))
4121 / 5);
4122 /* take science into account; normalized by 100 */
4123 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_SCIENCE]) / 100))
4124 / 5);
4125
4127
4128 /* Take food into account; the food surplus is clipped to values between
4129 * -10..20 and normalize by 10. Thus, the factor is between 0.9 and 1.2. */
4130 score *= (1 + (float) CLIP(-10, pcity->surplus[O_FOOD], 20) / 10 );
4131
4132 /* Reduce the score due to city illness (plague). The illness is given in
4133 * tenth of percent (0..1000) and normalized by 25. Thus, this factor is
4134 * between 0.6 (ill city) and 1.0 (health city). */
4135 score *= (100 - (float)city_illness_calc(pcity, nullptr, nullptr,
4136 nullptr, nullptr) / 25);
4137
4138 if (has_wonder) {
4139 /* People like wonders */
4140 score *= 1.25;
4141 }
4142
4143 if (is_capital(pcity)) {
4144 /* The capital is a magnet for the citizens */
4145 score *= 1.25;
4146 }
4147
4148 /* Take into account effects */
4149 score *= (1.0 + get_city_bonus(pcity, EFT_MIGRATION_PCT) / 100.0);
4150
4151 log_debug("[M] %s score: %.3f", city_name_get(pcity), score);
4152
4153 /* Set migration score for the city */
4154 pcity->server.migration_score = score;
4155 /* Set the turn, when the score was calculated */
4156 pcity->server.mgr_score_calc_turn = game.info.turn;
4157
4158 return score;
4159}
4160
4161/**********************************************************************/
4168 struct city *pcity_to)
4169{
4171 struct tile *ptile_from, *ptile_to;
4173 const char *nation_from, *nation_to;
4174 struct city *rcity = nullptr;
4175 int to_id = pcity_to->id;
4176 const struct civ_map *nmap = &(wld.map);
4177
4178 if (!pcity_from || !pcity_to) {
4179 return FALSE;
4180 }
4181
4185 /* We copy that, because city_link always returns the same pointer. */
4192
4193 /* Check food supply in the receiver city */
4195 bool migration = FALSE;
4196
4197 if (pcity_to->surplus[O_FOOD] >= game.info.food_cost) {
4198 migration = TRUE;
4199 } else {
4200 /* Check if there is a free tile for the new citizen which, when worked,
4201 * leads to zero or positive food surplus for the enlarged city */
4202 int max_food_tile = -1; /* no free tile */
4203
4205 city_tile(pcity_to), ptile) {
4206 if (city_can_work_tile(pcity_to, ptile)
4207 && tile_worked(ptile) != pcity_to) {
4208 /* Safest assumption is that city won't be celebrating once an
4209 * additional citizen is added */
4212 }
4214 if (max_food_tile >= 0
4215 && pcity_to->surplus[O_FOOD] + max_food_tile >= game.info.food_cost) {
4216 migration = TRUE;
4217 }
4218 }
4219
4220 if (!migration) {
4221 /* Insufficiency food in receiver city; no additional citizens */
4222 if (pplayer_from == pplayer_to) {
4223 /* Migration between one nation */
4225 /* TRANS: From <city1> to <city2>. */
4226 _("Migrants from %s can't go to %s because there is "
4227 "not enough food available!"),
4229 } else {
4230 /* Migration between different nations */
4232 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4233 _("Migrants from %s can't go to %s (%s) because there "
4234 "is not enough food available!"),
4237 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4238 _("Migrants from %s (%s) can't go to %s because there "
4239 "is not enough food available!"),
4241 }
4242
4243 return FALSE;
4244 }
4245 }
4246
4248 /* Receiver city can't grow */
4249 if (pplayer_from == pplayer_to) {
4250 /* Migration between one nation */
4252 /* TRANS: From <city1> to <city2>. */
4253 _("Migrants from %s can't go to %s because it needs "
4254 "an improvement to grow!"),
4256 } else {
4257 /* Migration between different nations */
4259 /* TRANS: From <city1> to <city2> of <city2 nation adjective>. */
4260 _("Migrants from %s can't go to %s (%s) because it "
4261 "needs an improvement to grow!"),
4264 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4265 _("Migrants from %s (%s) can't go to %s because it "
4266 "needs an improvement to grow!"),
4268 }
4269
4270 return FALSE;
4271 }
4272
4273 /* Reduce size of giver */
4274 if (city_size_get(pcity_from) == 1) {
4275
4277 /* Preserve nationality of city's only citizen */
4279 }
4280
4281 /* Do not destroy wonders */
4282 city_built_iterate(pcity_from, pimprove) {
4283 if (is_wonder(pimprove)) {
4284 return FALSE;
4285 }
4287
4288 /* Find closest city other of the same player than pcity_from */
4290 FALSE, FALSE, TRUE, FALSE, nullptr);
4291
4292 if (rcity) {
4293 int id = pcity_from->id;
4294
4295 /* Transfer all units to the closest city */
4297 pcity_from->units_supported, rcity, pcity_from,
4298 -1, TRUE);
4300
4301 script_server_signal_emit("city_size_change", pcity_from,
4302 (lua_Integer)(-1), "migration_from");
4303
4304 if (city_exist(id)) {
4305 script_server_signal_emit("city_destroyed", pcity_from,
4306 pcity_from->owner, nullptr);
4307
4308 if (city_exist(id)) {
4310 }
4311 }
4312
4314 _("%s was disbanded by its citizens."),
4315 name_from);
4316 } else {
4317 /* It's the only city of the nation */
4318 return FALSE;
4319 }
4320 } else {
4321 /* The migrants take half of the food box with them (this prevents
4322 * migration -> grow -> migration -> ... cycles) */
4323 pcity_from->food_stock /= 2;
4324
4326 /* Those citizens that are from the target nation are most
4327 * ones migrating. */
4328 if (citizens_nation_get(pcity_from, pplayer_to->slot) > 0) {
4330 } else if (!citizens_nation_get(pcity_from, pplayer_citizen->slot)) {
4331 /* No native citizens at all in the city, choose random foreigner */
4333
4335 }
4336 /* This should be followed by city_reduce_size(). */
4338 }
4339 city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
4341 if (city_refresh(pcity_from)) {
4343 }
4344 }
4345
4346 /* This should be _before_ the size of the city is increased. Thus, the
4347 * order of the messages is correct (1: migration; 2: increased size). */
4348 if (pplayer_from == pplayer_to) {
4349 /* Migration between one nation */
4351 /* TRANS: From <city1> to <city2>. */
4352 _("Migrants from %s moved to %s in search of a better "
4353 "life."), name_from, name_to);
4354 } else {
4355 /* Migration between different nations */
4357 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4358 _("Migrants from %s moved to %s (%s) in search of a "
4359 "better life."),
4362 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4363 _("Migrants from %s (%s) moved to %s in search of a "
4364 "better life."),
4366 }
4367
4368 /* Increase size of receiver city */
4369 if (city_exist(to_id)) {
4371
4372 if (city_exist(to_id)) {
4375 if (city_refresh(pcity_to)) {
4377 }
4378 if (incr_success) {
4379 script_server_signal_emit("city_size_change", pcity_to,
4380 (lua_Integer)1, "migration_to");
4381 }
4382 }
4383 }
4384
4385 log_debug("[M] T%d migration successful (%s -> %s)",
4387
4388 return TRUE;
4389}
4390
4391/**********************************************************************/
4413{
4414 bool internat = FALSE;
4415
4416 if (!game.server.migration) {
4417 return FALSE;
4418 }
4419
4421 || (game.server.mgr_worldchance <= 0
4422 && game.server.mgr_nationchance <= 0)) {
4423 return FALSE;
4424 }
4425
4426 /* check for migration */
4427 players_iterate(pplayer) {
4428 if (!pplayer->cities) {
4429 continue;
4430 }
4431
4432 if (check_city_migrations_player(pplayer)) {
4433 internat = TRUE;
4434 }
4436
4437 return internat;
4438}
4439
4440/**********************************************************************/
4445 struct player *pplayer = city_owner(pcity);
4446 struct tile *ptile = city_tile(pcity);
4447
4448 fc_assert_ret_val(pcity != nullptr, FALSE);
4449
4450 if (pcity->food_stock > 0) {
4451 pcity->food_stock = 0;
4452
4453 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4454 /* TRANS: %s is a city name */
4455 _("All stored food destroyed in %s."), city_link(pcity));
4456
4457 return TRUE;
4458 }
4459
4460 return FALSE;
4461}
4462
4463/**********************************************************************/
4466static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
4467{
4468 struct player *pplayer = city_owner(pcity);
4469 struct tile *ptile = city_tile(pcity);
4471
4473
4474 notify_player(pplayer, ptile, E_DISASTER,
4475 ftc_server,
4476 /* TRANS: Disasters such as Earthquake */
4477 _("%s was hit by %s."), city_name_get(pcity),
4479
4481 if (pplayer->economic.gold > 0 && pcity->prod[O_TRADE] > 0) {
4482 int amount = pcity->prod[O_TRADE] * 5;
4483
4484 amount = MIN(pplayer->economic.gold, amount);
4485 pplayer->economic.gold -= amount;
4486 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4487 PL_("Robbery in %s. %d gold stolen.",
4488 "Robbery in %s. %d gold stolen.", amount),
4491 }
4492 }
4493
4496 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4497 _("Pollution near %s."), city_link(pcity));
4499 }
4500 }
4501
4504 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4505 _("Fallout near %s."), city_link(pcity));
4507 }
4508 }
4509
4512 && pcity->size > 1)) {
4513 if (!city_reduce_size(pcity, 1, nullptr, "disaster")) {
4514 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4515 /* TRANS: "Industrial Accident destroys Bogota entirely." */
4516 _("%s destroys %s entirely."),
4518 pcity = nullptr;
4519 } else {
4520 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4521 /* TRANS: "Nuclear Accident ... Montreal." */
4522 _("%s causes population loss in %s."),
4524 }
4525
4527 }
4528
4530 int total = 0;
4531 struct impr_type *imprs[B_LAST];
4532
4533 city_built_iterate(pcity, pimprove) {
4534 if (is_improvement(pimprove)
4535 && !improvement_has_flag(pimprove, IF_DISASTER_PROOF)) {
4536 imprs[total++] = pimprove;
4537 }
4539
4540 if (total > 0) {
4541 int num = fc_rand(total);
4542
4543 building_lost(pcity, imprs[num], "disaster", nullptr);
4544
4545 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4546 /* TRANS: second %s is the name of a city improvement */
4547 _("%s destroys %s in %s."),
4550 city_link(pcity));
4551
4553 }
4554 }
4555
4559 }
4560 }
4561
4563 if (pcity->shield_stock > 0) {
4564 char prod[256];
4565
4566 pcity->shield_stock = 0;
4567 nullify_prechange_production(pcity); /* Make it impossible to recover */
4568
4569 universal_name_translation(&pcity->production, prod, sizeof(prod));
4570 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4571 /* TRANS: "Production of Colossus in Rhodes destroyed." */
4572 _("Production of %s in %s destroyed."),
4573 prod, city_link(pcity));
4574
4576 }
4577 }
4578
4579 script_server_signal_emit("disaster_occurred", pdis, pcity,
4581 script_server_signal_emit("disaster", pdis, pcity);
4582}
4583
4584/**********************************************************************/
4588{
4589 if (game.info.disasters == 0) {
4590 /* Shortcut out as no disaster is possible. */
4591 return;
4592 }
4593
4594 players_iterate(pplayer) {
4595 /* Safe city iterator needed as disaster may destroy city */
4596 city_list_iterate_safe(pplayer->cities, pcity) {
4597 int id = pcity->id;
4598
4600 if (city_exist(id)) {
4601 /* City survived earlier disasters. */
4602 int probability = game.info.disasters * pdis->frequency;
4603 int result = fc_rand(DISASTER_BASE_RARITY);
4604
4605 if (result < probability) {
4608 }
4609 }
4610 }
4614}
4615
4616/**********************************************************************/
4624static bool check_city_migrations_player(const struct player *pplayer)
4625{
4629 float score_from, score_tmp, weight;
4630 int dist, mgr_dist;
4631 bool internat = FALSE;
4632
4633 /* Check for each city
4634 * city_list_iterate_safe() must be used because we could
4635 * remove one city from the list */
4637 /* No migration out of the capital */
4638 if (is_capital(pcity)) {
4639 continue;
4640 }
4641
4642 /* Check only each (game.server.mgr_turninterval) turn
4643 * (counted from the funding turn) and do not migrate
4644 * the same turn a city is founded */
4645 if (game.info.turn == pcity->turn_founded
4646 || ((game.info.turn - pcity->turn_founded)
4647 % game.server.mgr_turninterval) != 0) {
4648 continue;
4649 }
4650
4653 best_city_player = nullptr;
4654 best_city_world = nullptr;
4655
4656 /* Score of the actual city
4657 * taking into account a persistence factor of 3 */
4659
4660 log_debug("[M] T%d check city: %s score: %6.3f (%s)",
4662 player_name(pplayer));
4663
4664 /* Consider all cities within the maximal possible distance
4665 * (= CITY_MAP_MAX_RADIUS + GAME_MAX_MGR_DISTANCE) */
4668 acity = tile_city(ptile);
4669
4670 if (!acity || acity == pcity) {
4671 /* No city or the city in the center */
4672 continue;
4673 }
4674
4675 /* Calculate the migration distance. The value of
4676 * game.server.mgr_distance is added to the current city radius. If the
4677 * distance between both cities is lower or equal than this value,
4678 * migration is possible. */
4681
4682 /* distance between the two cities */
4684
4685 if (dist > mgr_dist) {
4686 /* Too far away */
4687 continue;
4688 }
4689
4690 /* Score of the second city, weighted by the distance */
4691 weight = ((float) (mgr_dist + 1 - dist) / (float) (mgr_dist + 1));
4693
4694 log_debug("[M] T%d - compare city: %s (%s) dist: %d mgr_dist: %d "
4695 "score: %6.3f", game.info.turn, city_name_get(acity),
4697
4698 if (game.server.mgr_nationchance > 0 && city_owner(acity) == pplayer) {
4699 /* Migration between cities of the same owner */
4701 /* Select the best! */
4704
4705 log_debug("[M] T%d - best city (player): %s (%s) score: "
4706 "%6.3f (> %6.3f)", game.info.turn,
4709 }
4710 } else if (game.server.mgr_worldchance > 0
4711 && city_owner(acity) != pplayer) {
4712 /* Migration between cities of different owners */
4714 /* Modify the score if citizens could migrate to a city of their
4715 * original nation. */
4716 if (citizens_nation_get(pcity, city_owner(acity)->slot) > 0) {
4717 score_tmp *= 2;
4718 }
4719 }
4720
4722 /* Select the best! */
4725
4726 log_debug("[M] T%d - best city (world): %s (%s) score: "
4727 "%6.3f (> %6.3f)", game.info.turn,
4731 }
4732 }
4734
4735 if (best_city_player != nullptr) {
4736 /* First, do the migration within one nation */
4737 if (fc_rand(100) >= game.server.mgr_nationchance) {
4738 /* No migration */
4739 /* N.B.: city_link() always returns the same pointer. */
4742 _("Citizens of %s are thinking about migrating to %s "
4743 "for a better life."),
4745 } else {
4747 }
4748
4749 /* Stop here */
4750 continue;
4751 }
4752
4753 if (best_city_world != nullptr) {
4754 /* Second, do the migration between all nations */
4755 if (fc_rand(100) >= game.server.mgr_worldchance) {
4756 const char *nname;
4757
4759 /* No migration */
4760 /* N.B.: city_link() always returns the same pointer. */
4763 /* TRANS: <city1> to <city2> (<city2 nation adjective>). */
4764 _("Citizens of %s are thinking about migrating to %s "
4765 "(%s) for a better life."),
4767 } else {
4769 internat = TRUE;
4770 }
4771
4772 /* Stop here */
4773 continue;
4774 }
4776
4777 return internat;
4778}
4779
4780/**********************************************************************/
4784{
4785 pcity->style = city_style(pcity);
4786}
4787
4788/**********************************************************************/
4793{
4795 struct packet_city_update_counters packet;
4796
4797 packet.city = pcity->id;
4798
4800
4801 packet.count = counter_count;
4802 for (i = 0; i < counter_count; i++) {
4803 packet.counters[i] = pcity->counter_values[i];
4804 }
4805
4808}
4809
4810/**********************************************************************/
4813void city_tc_effect_refresh(struct player *pplayer)
4814{
4815 const struct civ_map *nmap = &(wld.map);
4816
4817 city_list_iterate(pplayer->cities, pcity) {
4818 bool changed = FALSE;
4819
4821 city_tile(pcity), ptile, idx, x, y) {
4822 if (ptile->worked == pcity
4823 && get_city_tile_output_bonus(pcity, ptile, nullptr,
4824 EFT_TILE_WORKABLE) <= 0) {
4826 pcity->specialists[DEFAULT_SPECIALIST]++;
4827 changed = TRUE;
4828 }
4830
4831 if (changed) {
4833 send_city_info(nullptr, pcity);
4834 }
4836}
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
int city_granary_size(int city_size)
Definition city.c:2173
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:1280
bool is_capital(const struct city *pcity)
Definition city.c:1620
const char * city_name_get(const struct city *pcity)
Definition city.c:1141
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3453
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1296
int city_airlift_max(const struct city *pcity)
Definition city.c:2984
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:3470
void city_size_add(struct city *pcity, int add)
Definition city.c:1204
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 can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:858
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:1694
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:1667
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3416
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1720
bool city_celebrating(const struct city *pcity)
Definition city.c:1686
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:834
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2912
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2053
void city_refresh_from_main_map(const struct civ_map *nmap, struct city *pcity, bool *workers_map)
Definition city.c:3243
bool city_happy(const struct city *pcity)
Definition city.c:1655
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:1324
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:907
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1017
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:951
int city_map_tiles(int city_radius_sq)
Definition city.c:171
bool city_exist(int id)
Definition city.c:3656
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1497
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:3710
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:875
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2965
bool city_can_change_build(const struct city *pcity)
Definition city.c:1083
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:974
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1262
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1241
#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:847
#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:836
#define city_built_iterate_end
Definition city.h:842
#define output_type_iterate_end
Definition city.h:853
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:3958
static void uk_rem_gold_append(struct unit *punit)
Definition cityturn.c:3272
static void city_refresh_after_city_size_increase(struct city *pcity, struct player *nationality, bool aaw)
Definition cityturn.c:1027
static bool worklist_change_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2348
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:3172
int city_shrink_granary_savings(const struct city *pcity)
Definition cityturn.c:893
static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
Definition cityturn.c:4466
static bool city_distribute_surplus_shields(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2703
static void unit_list_referred_destroy(struct unit_list *punitlist)
Definition cityturn.c:3285
static bool place_pollution(struct city *pcity, enum extra_cause cause)
Definition cityturn.c:3570
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2566
static void uk_rem_gold_callback(struct unit *punit)
Definition cityturn.c:3251
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:3488
static void update_city_activity(struct city *pcity)
Definition cityturn.c:3747
static void upgrade_unit_prod(struct city *pcity)
Definition cityturn.c:2679
static float city_migration_score(struct city *pcity)
Definition cityturn.c:4083
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3738
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4444
static bool city_increase_size(struct city *pcity, bool natural_growth, Specialist_type_id sid)
Definition cityturn.c:919
bool check_city_migrations(void)
Definition cityturn.c:4412
static void upgrade_building_prod(struct city *pcity)
Definition cityturn.c:2632
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3391
static citizens city_reduce_specialists(struct city *pcity, citizens change)
Definition cityturn.c:719
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:1120
static void define_orig_production_values(struct city *pcity)
Definition cityturn.c:3707
void city_repair_size(struct city *pcity, int change)
Definition cityturn.c:852
#define cityimpr_list_iterate(cityimprlist, pcityimpr)
Definition cityturn.c:128
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4792
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:687
static bool city_build_building(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2784
static struct unit static const struct impr_type * building_upgrades_to(struct city *pcity, const struct impr_type *pimprove)
Definition cityturn.c:2611
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:577
static struct unit * sell_random_unit(struct player *pplayer, struct unit_list *punitlist)
Definition cityturn.c:3308
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3626
static void nullify_caravan_and_disband_plus(struct city *pcity)
Definition cityturn.c:3728
static bool sell_random_building(struct player *pplayer, struct cityimpr_list *imprs)
Definition cityturn.c:3205
static bool disband_city(struct city *pcity)
Definition cityturn.c:3971
void update_city_activities(struct player *pplayer)
Definition cityturn.c:603
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:763
#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:512
static void city_shrink_reset_foodbox(struct city *pcity, int new_size)
Definition cityturn.c:906
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:3454
void city_style_refresh(struct city *pcity)
Definition cityturn.c:4783
static bool city_balance_treasury_units(struct city *pcity)
Definition cityturn.c:3535
static const struct unit_type * unit_upgrades_to(struct city *pcity, const struct unit_type *id)
Definition cityturn.c:2657
static bool do_city_migration(struct city *pcity_from, struct city *pcity_to)
Definition cityturn.c:4167
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:4813
static void check_pollution(struct city *pcity)
Definition cityturn.c:3609
void check_disasters(void)
Definition cityturn.c:4587
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:739
static bool worklist_item_postpone_req_vec(struct universal *target, struct city *pcity, struct player *pplayer, int saved_id)
Definition cityturn.c:1197
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:2945
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, Specialist_type_id sid, const char *reason)
Definition cityturn.c:1068
void city_refresh_queue_processing(void)
Definition cityturn.c:214
int city_growth_granary_savings(const struct city *pcity)
Definition cityturn.c:879
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:4624
static bool city_build_unit(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3006
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:107
#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:1388
void give_immediate_free_tech(struct research *presearch, Tech_type_id tech)
Definition techtools.c:1407
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:2317
int unit_upkeep_cost(const struct unit *punit, Output_type_id otype)
Definition unit.c:2994
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:407
#define unit_cargo_iterate_end
Definition unit.h:590
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:587
#define unit_owner(_pu)
Definition unit.h:406
#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