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;
1529 case VUT_GOOD:
1530 if (preq->present) {
1531 notify_player(pplayer, city_tile(pcity),
1533 Q_("?extra:%s can't build %s from the worklist; "
1534 "%s is required. Postponing..."),
1536 tgt_name,
1537 goods_name_translation(preq->source.value.good));
1539 pcity, "need_good");
1540 } else {
1541 notify_player(pplayer, city_tile(pcity),
1543 Q_("?extra:%s can't build %s from the worklist; "
1544 "%s is prohibited. Postponing..."),
1546 tgt_name,
1547 goods_name_translation(preq->source.value.good));
1549 pcity, "have_good");
1550 }
1551 break;
1552 case VUT_TERRAIN:
1553 if (preq->present) {
1554 notify_player(pplayer, city_tile(pcity),
1556 Q_("?terrain:%s can't build %s from the worklist; "
1557 "%s terrain is required. Postponing..."),
1559 tgt_name,
1560 terrain_name_translation(preq->source.value.terrain));
1562 pcity, "need_terrain");
1563 } else {
1564 notify_player(pplayer, city_tile(pcity),
1566 Q_("?terrain:%s can't build %s from the worklist; "
1567 "%s terrain is prohibited. Postponing..."),
1569 tgt_name,
1570 terrain_name_translation(preq->source.value.terrain));
1572 pcity, "have_terrain");
1573 }
1574 break;
1575 case VUT_NATION:
1576 if (preq->range < REQ_RANGE_TRADE_ROUTE
1577 || preq->range == REQ_RANGE_PLAYER) {
1578 /* At higher ranges, new players with their nations may arrive */
1579 purge = TRUE;
1580 } else {
1581 if (preq->present) {
1582 notify_player(pplayer, city_tile(pcity),
1584 /* TRANS: "%s nation" is adjective */
1585 Q_("?nation:%s can't build %s from the worklist; "
1586 "%s nation is required. Postponing..."),
1588 tgt_name,
1589 nation_adjective_translation(preq->source.value.nation));
1591 pcity, "need_nation");
1592 } else {
1593 notify_player(pplayer, city_tile(pcity),
1595 Q_("?nation:%s can't build %s from the worklist; "
1596 "%s nation is prohibited. Postponing..."),
1598 tgt_name,
1599 nation_adjective_translation(preq->source.value.nation));
1601 pcity, "have_nation");
1602 }
1603 }
1604 break;
1605 case VUT_NATIONGROUP:
1606 if (preq->range < REQ_RANGE_TRADE_ROUTE
1607 || preq->range == REQ_RANGE_PLAYER) {
1608 /* At higher ranges, new players with their nations may arrive */
1609 purge = TRUE;
1610 } else {
1611 if (preq->present) {
1612 notify_player(pplayer, city_tile(pcity),
1614 /* TRANS: "%s nation" is adjective */
1615 Q_("?ngroup:%s can't build %s from the worklist; "
1616 "%s nation is required. Postponing..."),
1618 tgt_name,
1619 nation_group_name_translation(preq->source.value.nationgroup));
1621 pcity, "need_nationgroup");
1622 } else {
1623 notify_player(pplayer, city_tile(pcity),
1625 Q_("?ngroup:%s can't build %s from the worklist; "
1626 "%s nation is prohibited. Postponing..."),
1628 tgt_name,
1629 nation_group_name_translation(preq->source.value.nationgroup));
1631 pcity, "have_nationgroup");
1632 }
1633 }
1634 break;
1635 case VUT_STYLE:
1636 /* FIXME: City styles sometimes change over time, but it isn't
1637 * entirely under player control. Probably better to purge
1638 * with useful explanation. */
1639 if (preq->present) {
1640 notify_player(pplayer, city_tile(pcity),
1642 _("%s can't build %s from the worklist; "
1643 "only %s style cities may build this. Postponing..."),
1645 tgt_name,
1646 style_name_translation(preq->source.value.style));
1648 pcity, "need_style");
1649 } else {
1650 notify_player(pplayer, city_tile(pcity),
1652 _("%s can't build %s from the worklist; "
1653 "%s style cities may not build this. Postponing..."),
1655 tgt_name,
1656 style_name_translation(preq->source.value.style));
1658 pcity, "have_style");
1659 }
1660 break;
1661 case VUT_NATIONALITY:
1662 /* FIXME: Changing citizen nationality is hard: purging might be
1663 * more useful in this case. */
1664 if (preq->present) {
1665 notify_player(pplayer, city_tile(pcity),
1667 /* TRANS: Latter %s is citizen nationality */
1668 _("%s can't build %s from the worklist; "
1669 "only city with %s may build this. Postponing..."),
1671 tgt_name,
1672 nation_plural_translation(preq->source.value.nationality));
1674 pcity, "need_nationality");
1675 } else {
1676 notify_player(pplayer, city_tile(pcity),
1678 /* TRANS: Latter %s is citizen nationality */
1679 _("%s can't build %s from the worklist; "
1680 "only city without %s may build this. Postponing..."),
1682 tgt_name,
1683 nation_plural_translation(preq->source.value.nationality));
1685 pcity, "have_nationality");
1686 }
1687 break;
1688 case VUT_ORIGINAL_OWNER:
1689 /* Original owner of this specific city won't change.
1690 * Update this when supporting ranges other than REQ_RANGE_CITY. */
1691 purge = TRUE;
1692 break;
1693 case VUT_DIPLREL:
1694 case VUT_DIPLREL_TILE: /* The tile owner is the city owner */
1695 case VUT_DIPLREL_TILE_O: /* The tile owner is the city owner */
1696 if (preq->present) {
1697 const char *reason;
1698
1699 notify_player(pplayer, city_tile(pcity),
1701 /* TRANS: '%s' is a wide range of relationships;
1702 * e.g., 'Peace', 'Never met', 'Foreign',
1703 * 'Hosts embassy', 'Provided Casus Belli' */
1704 _("%s can't build %s from the worklist; "
1705 "the relationship '%s' is required."
1706 " Postponing..."),
1708 tgt_name,
1710 preq->source.value.diplrel));
1711
1712 if (preq->source.kind == VUT_DIPLREL_TILE) {
1713 reason = "need_diplrel_tile";
1714 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1715 reason = "need_diplrel_tile_o";
1716 } else {
1717 fc_assert(preq->source.kind == VUT_DIPLREL);
1718 reason = "need_diplrel";
1719 }
1720
1722 pcity, reason);
1723 } else {
1724 const char *reason;
1725
1726 notify_player(pplayer, city_tile(pcity),
1728 _("%s can't build %s from the worklist; "
1729 "the relationship '%s' is prohibited."
1730 " Postponing..."),
1732 tgt_name,
1734 preq->source.value.diplrel));
1735
1736 if (preq->source.kind == VUT_DIPLREL_TILE) {
1737 reason = "have_diplrel_tile";
1738 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1739 reason = "have_diplrel_tile_o";
1740 } else {
1741 fc_assert(preq->source.kind == VUT_DIPLREL);
1742 reason = "have_diplrel";
1743 }
1744
1746 pcity, reason);
1747 }
1748 break;
1751 if (preq->present) {
1752 const char *reason;
1753
1754 notify_player(pplayer, city_tile(pcity),
1756 /* TRANS: '%s' is a wide range of relationships;
1757 * e.g., 'Peace', 'Never met', 'Foreign',
1758 * 'Hosts embassy', 'Provided Casus Belli' */
1759 _("%s can't build %s from the worklist; "
1760 "unit with the relationship '%s' is required."
1761 " Postponing..."),
1763 tgt_name,
1765 preq->source.value.diplrel));
1766
1767 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1768 reason = "need_diplrel_unitany";
1769 } else {
1770 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1771 reason = "need_diplrel_unitany_o";
1772 }
1773
1775 pcity, reason);
1776 } else {
1777 const char *reason;
1778
1779 notify_player(pplayer, city_tile(pcity),
1781 _("%s can't build %s from the worklist; "
1782 "unit with the relationship '%s' is prohibited."
1783 " Postponing..."),
1785 tgt_name,
1787 preq->source.value.diplrel));
1788
1789 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1790 reason = "have_diplrel_unitany";
1791 } else {
1792 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1793 reason = "have_diplrel_unitany_o";
1794 }
1795
1797 pcity, reason);
1798 }
1799 break;
1800 case VUT_MINSIZE:
1801 if (preq->present) {
1802 notify_player(pplayer, city_tile(pcity),
1804 _("%s can't build %s from the worklist; "
1805 "city must be of size %d or larger. "
1806 "Postponing..."),
1808 tgt_name,
1809 preq->source.value.minsize);
1811 pcity, "need_minsize");
1812 } else {
1813 notify_player(pplayer, city_tile(pcity),
1815 _("%s can't build %s from the worklist; "
1816 "city must be of size %d or smaller."
1817 "Postponing..."),
1819 tgt_name,
1820 (preq->source.value.minsize - 1));
1822 pcity, "need_minsize");
1823 }
1824 break;
1825 case VUT_MINCULTURE:
1826 if (preq->present) {
1827 notify_player(pplayer, city_tile(pcity),
1829 _("%s can't build %s from the worklist; "
1830 "city must have culture of %d. Postponing..."),
1832 tgt_name,
1833 preq->source.value.minculture);
1835 pcity, "need_minculture");
1836 } else {
1837 /* What has been written may not be unwritten. */
1838 purge = TRUE;
1839 }
1840 break;
1841 case VUT_MINFOREIGNPCT:
1842 if (preq->present) {
1843 notify_player(pplayer, city_tile(pcity),
1845 _("%s can't build %s from the worklist; "
1846 "city must have %d%% foreign population. Postponing..."),
1848 tgt_name,
1849 preq->source.value.minforeignpct);
1851 pcity, "need_minforeignpct");
1852 } else {
1853 notify_player(pplayer, city_tile(pcity),
1855 _("%s can't build %s from the worklist; "
1856 "city must have %d%% native population. Postponing..."),
1858 tgt_name,
1859 100 - preq->source.value.minforeignpct);
1861 pcity, "need_minforeignpct");
1862 }
1863 break;
1864 case VUT_MINTECHS:
1865 if (preq->present) {
1866 notify_player(pplayer, city_tile(pcity),
1868 _("%s can't build %s from the worklist; "
1869 "%d techs must be known. Postponing..."),
1871 tgt_name,
1872 preq->source.value.min_techs);
1874 pcity, "need_mintechs");
1875 } else {
1876 purge = TRUE;
1877 }
1878 break;
1879 case VUT_FUTURETECHS:
1880 if (preq->present) {
1881 notify_player(pplayer, city_tile(pcity),
1883 _("%s can't build %s from the worklist; "
1884 "%d future techs must be known. Postponing..."),
1886 tgt_name,
1887 preq->source.value.future_techs);
1889 pcity, "need_futuretechs");
1890 } else {
1891 purge = TRUE;
1892 }
1893 break;
1894 case VUT_MINCITIES:
1895 if (preq->present) {
1896 notify_player(pplayer, city_tile(pcity),
1898 _("%s can't build %s from the worklist; "
1899 "Must own %d cities. Postponing..."),
1901 tgt_name,
1902 preq->source.value.min_cities);
1904 pcity, "need_mincities");
1905 } else {
1906 purge = TRUE;
1907 }
1908 break;
1910 if (preq->present) {
1911 notify_player(pplayer, city_tile(pcity),
1913 PL_("%s can't build %s from the worklist; "
1914 "more than %d total unit on tile."
1915 " Postponing...",
1916 "%s can't build %s from the worklist; "
1917 "more than %d total units on tile."
1918 " Postponing...",
1919 preq->source.value.max_tile_total_units),
1921 tgt_name,
1922 preq->source.value.max_tile_total_units);
1924 pcity, "need_tileunits");
1925 } else {
1926 notify_player(pplayer, city_tile(pcity),
1928 PL_("%s can't build %s from the worklist; "
1929 "fewer than %d total unit on tile."
1930 " Postponing...",
1931 "%s can't build %s from the worklist; "
1932 "fewer than %d total units on tile."
1933 " Postponing...",
1934 preq->source.value.max_tile_total_units + 1),
1936 tgt_name,
1937 preq->source.value.max_tile_total_units + 1);
1939 pcity, "need_tileunits");
1940 }
1941 break;
1943 if (preq->present) {
1944 notify_player(pplayer, city_tile(pcity),
1946 PL_("%s can't build %s from the worklist; "
1947 "more than %d unit on tile."
1948 " Postponing...",
1949 "%s can't build %s from the worklist; "
1950 "more than %d units on tile."
1951 " Postponing...",
1952 preq->source.value.max_tile_top_units),
1954 tgt_name,
1955 preq->source.value.max_tile_top_units);
1957 pcity, "need_tiletopunits");
1958 } else {
1959 notify_player(pplayer, city_tile(pcity),
1961 PL_("%s can't build %s from the worklist; "
1962 "fewer than %d unit on tile."
1963 " Postponing...",
1964 "%s can't build %s from the worklist; "
1965 "fewer than %d units on tile."
1966 " Postponing...",
1967 preq->source.value.max_tile_top_units + 1),
1969 tgt_name,
1970 preq->source.value.max_tile_top_units + 1);
1972 pcity, "need_tiletopunits");
1973 }
1974 break;
1975 case VUT_AI_LEVEL:
1976 /* Can't change AI level. */
1977 purge = TRUE;
1978 break;
1979 case VUT_TERRAINCLASS:
1980 /* Change of terrain class is expected to be very unlikely. Purge!
1981 * TODO: Analyze ruleset to see how unlikely terrain class change actually is. */
1982 purge = TRUE;
1983 break;
1984 case VUT_TERRFLAG:
1985 if (preq->present) {
1986 notify_player(pplayer, city_tile(pcity),
1988 _("%s can't build %s from the worklist; "
1989 "terrain with \"%s\" flag is required. "
1990 "Postponing..."),
1992 tgt_name,
1993 terrain_flag_id_name(preq->source.value.terrainflag));
1995 pcity, "need_terrainflag");
1996 } else {
1997 notify_player(pplayer, city_tile(pcity),
1999 _("%s can't build %s from the worklist; "
2000 "terrain with \"%s\" flag is prohibited. "
2001 "Postponing..."),
2003 tgt_name,
2004 terrain_flag_id_name(preq->source.value.terrainflag));
2006 pcity, "have_terrainflag");
2007 }
2008 break;
2010 /* Changing the continent size is hard; cf. VUT_TERRAINCLASS above.
2011 * Change this when we support less fixed ranges (e.g. city?). */
2012 purge = TRUE;
2013 break;
2014 case VUT_ROADFLAG:
2015 if (preq->present) {
2016 notify_player(pplayer, city_tile(pcity),
2018 _("%s can't build %s from the worklist; "
2019 "road with \"%s\" flag is required. "
2020 "Postponing..."),
2022 tgt_name,
2023 road_flag_id_name(preq->source.value.roadflag));
2025 pcity, "need_roadflag");
2026 } else {
2027 notify_player(pplayer, city_tile(pcity),
2029 _("%s can't build %s from the worklist; "
2030 "road with \"%s\" flag is prohibited. "
2031 "Postponing..."),
2033 tgt_name,
2034 road_flag_id_name(preq->source.value.roadflag));
2036 pcity, "have_roadflag");
2037 }
2038 break;
2039 case VUT_EXTRAFLAG:
2040 if (preq->present) {
2041 notify_player(pplayer, city_tile(pcity),
2043 _("%s can't build %s from the worklist; "
2044 "extra with \"%s\" flag is required. "
2045 "Postponing..."),
2047 tgt_name,
2048 extra_flag_id_translated_name(preq->source.value.extraflag));
2050 pcity, "need_extraflag");
2051 } else {
2052 notify_player(pplayer, city_tile(pcity),
2054 _("%s can't build %s from the worklist; "
2055 "extra with \"%s\" flag is prohibited. "
2056 "Postponing..."),
2058 tgt_name,
2059 extra_flag_id_translated_name(preq->source.value.extraflag));
2061 pcity, "have_extraflag");
2062 }
2063 break;
2064 case VUT_MINLATITUDE:
2065 case VUT_MAXLATITUDE:
2066 /* Can't change where the city is located. */
2067 purge = TRUE;
2068 break;
2069 case VUT_CITYTILE:
2070 if (CITYT_BORDERING_TCLASS_REGION == preq->source.value.citytile
2071 && (preq->range == REQ_RANGE_CADJACENT
2072 || preq->range == REQ_RANGE_ADJACENT)) {
2073 if (preq->present) {
2074 notify_player(pplayer, city_tile(pcity),
2076 _("%s can't build %s from the worklist; "
2077 "different terrain class nearby is required. "
2078 "Postponing..."),
2080 tgt_name);
2082 pcity, "need_different_terrainclass");
2083 } else {
2084 notify_player(pplayer, city_tile(pcity),
2086 _("%s can't build %s from the worklist; "
2087 "different terrain class nearby is prohibited. "
2088 "Postponing..."),
2090 tgt_name);
2092 pcity, "have_different_terrainclass");
2093 }
2094 break;
2095 }
2096 /* Other values should not present in build reqs */
2098
2099 case VUT_UTYPE:
2100 case VUT_UTFLAG:
2101 case VUT_UCLASS:
2102 case VUT_UCFLAG:
2103 case VUT_MINVETERAN:
2104 case VUT_UNITSTATE:
2105 case VUT_ACTIVITY:
2106 case VUT_MINMOVES:
2107 case VUT_MINHP:
2108 case VUT_ACTION:
2109 case VUT_OTYPE:
2110 case VUT_SPECIALIST:
2112 case VUT_TILE_REL:
2113 case VUT_TERRAINALTER: /* XXX could do this in principle */
2114 /* Will only happen with a bogus ruleset. */
2115 log_error("worklist_change_build_target() has bogus preq");
2116 break;
2117 case VUT_CITYSTATUS:
2118 if (preq->source.value.citystatus == CITYS_TRANSFERRED) {
2119 /* If there's a change, it will invalidate worklist anyway. */
2120 purge = TRUE;
2121 } else if (preq->source.value.citystatus == CITYS_OWNED_BY_ORIGINAL) {
2122 if (preq->range == REQ_RANGE_CITY || preq->range == REQ_RANGE_TILE) {
2123 /* Can't change at these ranges */
2124 purge = TRUE;
2125 } else {
2126 if (preq->present) {
2127 notify_player(pplayer, city_tile(pcity),
2129 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2130 _("%s can't build %s from the worklist; "
2131 "only available when city in range %s \"%s\". "
2132 "Postponing..."),
2134 tgt_name, req_range_name(preq->range),
2135 citystatus_type_name(preq->source.value.citystatus));
2137 pcity, "need_citystatus");
2138 } else {
2139 notify_player(pplayer, city_tile(pcity),
2141 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2142 _("%s can't build %s from the worklist; "
2143 "not available when city in range %s is \"%s\". "
2144 "Postponing..."),
2146 tgt_name, req_range_name(preq->range),
2147 citystatus_type_name(preq->source.value.citystatus));
2149 pcity, "have_citystatus");
2150 }
2151 }
2152 } else {
2153 /* Other status types will only happen with a bogus ruleset. */
2154 log_error("worklist_change_build_target() has bogus citystatus preq");
2155 }
2156 break;
2157 case VUT_MINYEAR:
2158 if (preq->present) {
2159 notify_player(pplayer, city_tile(pcity),
2161 /* TRANS: last %s is a date */
2162 _("%s can't build %s from the worklist; "
2163 "only available from %s. Postponing..."),
2165 tgt_name,
2166 textyear(preq->source.value.minyear));
2168 pcity, "need_minyear");
2169 } else {
2170 /* Can't go back in time. */
2171 purge = TRUE;
2172 }
2173 break;
2174 case VUT_MINCALFRAG:
2175 /* Unlike VUT_MINYEAR, a requirement in either direction is
2176 * likely to be fulfilled sooner or later. */
2177 if (preq->present) {
2178 notify_player(pplayer, city_tile(pcity),
2180 /* TRANS: last %s is a calendar fragment from
2181 * the ruleset; may be a bare number */
2182 _("%s can't build %s from the worklist; "
2183 "only available from %s. Postponing..."),
2185 tgt_name,
2186 textcalfrag(preq->source.value.mincalfrag));
2188 pcity, "need_mincalfrag");
2189 } else {
2190 fc_assert_action(preq->source.value.mincalfrag > 0, break);
2191 notify_player(pplayer, city_tile(pcity),
2193 /* TRANS: last %s is a calendar fragment from
2194 * the ruleset; may be a bare number */
2195 _("%s can't build %s from the worklist; "
2196 "not available after %s. Postponing..."),
2198 tgt_name,
2199 textcalfrag(preq->source.value.mincalfrag - 1));
2201 pcity, "have_mincalfrag");
2202 }
2203 break;
2204 case VUT_TOPO:
2205 if (preq->present) {
2206 notify_player(pplayer, city_tile(pcity),
2208 /* TRANS: third %s is topology flag name
2209 * ("Hex", "ISO" */
2210 _("%s can't build %s from the worklist; "
2211 "only available in worlds with %s map."),
2213 tgt_name,
2214 _(topo_flag_name(preq->source.value.topo_property)));
2216 pcity, "need_topo");
2217 }
2218 purge = TRUE;
2219 break;
2220 case VUT_WRAP:
2221 if (preq->present) {
2222 notify_player(pplayer, city_tile(pcity),
2224 /* TRANS: third %s is wrap flag name
2225 * ("WrapX", "Wrapy") */
2226 _("%s can't build %s from the worklist; "
2227 "only available in worlds with %s map."),
2229 tgt_name,
2230 _(wrap_flag_name(preq->source.value.wrap_property)));
2232 pcity, "need_wrap");
2233 }
2234 purge = TRUE;
2235 break;
2236 case VUT_SERVERSETTING:
2237 notify_player(pplayer, city_tile(pcity),
2239 /* TRANS: %s is a server setting, its value and
2240 * if it is required to be present or absent.
2241 * The string's format is specified in
2242 * ssetv_human_readable().
2243 * Example: "killstack is enabled". */
2244 _("%s can't build %s from the worklist; "
2245 "only available when the server setting "
2246 "%s."),
2248 tgt_name,
2249 ssetv_human_readable(preq->source.value.ssetval,
2250 preq->present));
2252 pcity, "need_setting");
2253 /* Don't assume that the server setting will be changed. */
2254 purge = TRUE;
2255 break;
2256 case VUT_AGE:
2257 if (preq->present) {
2258 notify_player(pplayer, city_tile(pcity),
2260 _("%s can't build %s from the worklist; "
2261 "only available once %d turns old. Postponing..."),
2263 tgt_name,
2264 preq->source.value.age);
2266 pcity, "need_age");
2267 } else {
2268 /* Can't go back in time. */
2269 purge = TRUE;
2270 }
2271 break;
2272 case VUT_FORM_AGE:
2273 if (preq->present) {
2274 notify_player(pplayer, city_tile(pcity),
2276 _("%s can't build %s from the worklist; "
2277 "only available once %d turns old form. Postponing..."),
2279 tgt_name,
2280 preq->source.value.age);
2282 pcity, "need_form_age");
2283 } else {
2284 /* Can't go back in time. */
2285 purge = TRUE;
2286 }
2287 break;
2288 case VUT_NONE:
2289 case VUT_COUNT:
2291 "worklist_change_build_target() "
2292 "called with invalid preq");
2293 break;
2294 /* No default handling here, as we want compiler warning
2295 * if new requirement type is added to enum and it's not handled
2296 * here. */
2297 };
2298 break;
2299 }
2300
2301 /* Almost all cases emit signal in the end, so city check needed. */
2302 if (!city_exist(saved_id)) {
2303 /* Some script has removed city */
2304 return TRUE;
2305 }
2306
2308
2309 if (!known) {
2310 /* FIXME: make can_city_build_improvement_now() return a reason enum,
2311 * so we can notify user with it.
2312 * Likely the building already exist. */
2313 purge = TRUE;
2314 }
2315
2316 return purge;
2317}
2318
2319/**********************************************************************/
2325static bool worklist_change_build_target(struct player *pplayer,
2326 struct city *pcity)
2327{
2328 struct universal target;
2329 bool success = FALSE;
2330 int i;
2331 int saved_id = pcity->id;
2332 bool city_checked = TRUE; /* This is used to avoid spurious city_exist() calls */
2333 struct worklist *pwl = &pcity->worklist;
2334 const struct civ_map *nmap = &(wld.map);
2335
2336 if (worklist_is_empty(pwl)) {
2337 /* Nothing in the worklist; bail now. */
2338 return FALSE;
2339 }
2340
2341 i = 0;
2342 while (!success && i < worklist_length(pwl)) {
2343
2344 if (!city_checked) {
2345 if (!city_exist(saved_id)) {
2346 /* Some script has removed useless city that cannot build
2347 * what it is told to! */
2348 return FALSE;
2349 }
2351 }
2352
2353 if (worklist_peek_ith(pwl, &target, i)) {
2354 success = can_city_build_now(nmap, pcity, &target);
2355 } else {
2356 success = FALSE;
2357 }
2358 i++;
2359
2360 if (success) {
2361 break; /* while */
2362 }
2363
2364 switch (target.kind) {
2365 case VUT_UTYPE:
2366 {
2367 const struct unit_type *ptarget = target.value.utype;
2369 bool purge;
2370
2371 /* Maybe we can just upgrade the target to what the city /can/ build. */
2372 if (U_NOT_OBSOLETED == pupdate) {
2373 /* Nope, we're stuck. Skip this item from the worklist. */
2374 struct research *presearch = research_get(pplayer);
2375 struct advance *missing = nullptr;
2376 bool multiple = FALSE;
2377
2380 if (missing != nullptr) {
2381 multiple = TRUE;
2382 } else {
2383 missing = padv;
2384 }
2385 }
2387
2388
2389 purge = FALSE;
2390 if (missing != nullptr) {
2391 if (!multiple) {
2392 notify_player(pplayer, city_tile(pcity),
2394 _("%s can't build %s from the worklist; "
2395 "tech %s not yet available. Postponing..."),
2398 } else {
2399 notify_player(pplayer, city_tile(pcity),
2401 _("%s can't build %s from the worklist; "
2402 "multiple techs still needed. Postponing..."),
2404 }
2405
2406 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2407 "need_tech");
2408 } else {
2409 /* Unknown or requirement from vector. */
2410 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2411 saved_id);
2412 }
2414 if (!purge) {
2415 break;
2416 }
2417 } else {
2419 }
2420 if (purge) {
2421 /* If the city can never build this unit or its descendants,
2422 * drop it. */
2423 notify_player(pplayer, city_tile(pcity),
2425 _("%s can't build %s from the worklist. Purging..."),
2427 /* Yes, warn about the targets that's actually
2428 in the worklist, not its obsolete-closure
2429 pupdate. */
2431 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2432 "never");
2433 if (city_exist(saved_id)) {
2435 /* Purge this worklist item. */
2436 i--;
2438 } else {
2440 }
2441 } else {
2442 /* Yep, we can go after pupdate instead. Joy! */
2444 _("Production of %s is upgraded to %s in %s."),
2447 city_link(pcity));
2448 target.value.utype = pupdate;
2449 }
2450 break;
2451 }
2452 case VUT_IMPROVEMENT:
2453 {
2454 const struct impr_type *ptarget = target.value.building;
2456 bool purge;
2457
2458 /* If the city can never build this improvement, drop it. */
2460 purge = !success;
2461
2462 /* Maybe this improvement has been obsoleted by something that
2463 we can build. */
2464 if (purge) {
2465 /* Nope, no use. *sigh* */
2466
2467 /* Can it be postponed? */
2469 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2470 saved_id);
2471
2472 /* Almost all cases emit signal in the end, so city check needed. */
2473 if (!city_exist(saved_id)) {
2474 /* Some script has removed city */
2475 return FALSE;
2476 }
2478 }
2479 } else if (success) {
2480 /* Hey, we can upgrade the improvement! */
2482 _("Production of %s is upgraded to %s in %s."),
2485 city_link(pcity));
2486 target.value.building = pupdate;
2487 }
2488
2489 if (purge) {
2490 /* Never in a million years. */
2491 notify_player(pplayer, city_tile(pcity),
2493 _("%s can't build %s from the worklist. Purging..."),
2496 script_server_signal_emit("building_cant_be_built", ptarget, pcity,
2497 "never");
2498 if (city_exist(saved_id)) {
2500 /* Purge this worklist item. */
2501 i--;
2503 } else {
2505 }
2506 }
2507 break;
2508 }
2509 default:
2510 /* skip useless target */
2511 log_error("worklist_change_build_target() has unrecognized "
2512 "target kind (%d)", target.kind);
2513 break;
2514 };
2515 } /* while */
2516
2517 if (success) {
2518 /* All okay. Switch targets. */
2519 change_build_target(pplayer, pcity, &target, E_WORKLIST);
2520
2521 /* i is the index immediately _after_ the item we're changing to.
2522 Remove the (i-1)th item from the worklist. */
2523 worklist_remove(pwl, i - 1);
2524 }
2525
2526 if (worklist_is_empty(pwl)) {
2527 /* There *was* something in the worklist, but it's empty now. Bug the
2528 player about it. */
2530 /* TRANS: The <city> worklist .... */
2531 _("The %s worklist is now empty."),
2532 city_link(pcity));
2533 }
2534
2535 return success;
2536}
2537
2538/**********************************************************************/
2543void choose_build_target(struct player *pplayer, struct city *pcity)
2544{
2545 const struct civ_map *nmap = &(wld.map);
2546
2547 /* Pick the next thing off the worklist. */
2548 if (worklist_change_build_target(pplayer, pcity)) {
2549 return;
2550 }
2551
2552 /* Try building the same thing again. Repeat building doesn't require a
2553 * call to change_build_target, so just return. */
2554 switch (pcity->production.kind) {
2555 case VUT_UTYPE:
2556 /* We can build a unit again unless it's unique or we have lost the tech. */
2557 if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
2558 && can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
2559 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2560 utype_rule_name(pcity->production.value.utype));
2561 return;
2562 }
2563 break;
2564 case VUT_IMPROVEMENT:
2565 if (can_city_build_improvement_now(pcity, pcity->production.value.building)) {
2566 /* We can build space and coinage again, and possibly others. */
2567 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2568 improvement_rule_name(pcity->production.value.building));
2569 return;
2570 }
2571 break;
2572 default:
2573 /* fallthru */
2574 break;
2575 };
2576
2577 /* Find *something* to do! */
2578 log_debug("Trying advisor_choose_build.");
2579 advisor_choose_build(pplayer, pcity);
2580 log_debug("Advisor_choose_build didn't kill us.");
2581}
2582
2583/**********************************************************************/
2588static const struct impr_type *building_upgrades_to(struct city *pcity,
2589 const struct impr_type *pimprove)
2590{
2591 const struct impr_type *check = pimprove;
2592 const struct impr_type *best_upgrade = nullptr;
2593
2595 return nullptr;
2596 }
2600 }
2601 }
2602
2603 return best_upgrade;
2604}
2605
2606/**********************************************************************/
2610{
2611 const struct impr_type *producing = pcity->production.value.building;
2613
2617 _("Production of %s is upgraded to %s in %s."),
2620 city_link(pcity));
2621 pcity->production.kind = VUT_IMPROVEMENT;
2622 pcity->production.value.building = upgrading;
2623 }
2624}
2625
2626/**********************************************************************/
2634static const struct unit_type *unit_upgrades_to(struct city *pcity,
2635 const struct unit_type *punittype)
2636{
2637 const struct unit_type *check = punittype;
2638 const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
2639 const struct civ_map *nmap = &(wld.map);
2640
2642 return U_NOT_OBSOLETED;
2643 }
2644 while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
2647 }
2648 }
2649
2650 return best_upgrade;
2651}
2652
2653/**********************************************************************/
2656static void upgrade_unit_prod(struct city *pcity)
2657{
2658 const struct unit_type *producing = pcity->production.value.utype;
2660 const struct civ_map *nmap = &(wld.map);
2661
2665 _("Production of %s is upgraded to %s in %s."),
2668 city_link(pcity));
2669 pcity->production.value.utype = upgrading;
2670 }
2671}
2672
2673/**********************************************************************/
2680static bool city_distribute_surplus_shields(struct player *pplayer,
2681 struct city *pcity)
2682{
2683 int size_reduction = 0;
2684 struct unit *sacrifizer;
2685
2686 if (pcity->surplus[O_SHIELD] < 0) {
2687 unit_list_iterate_safe(pcity->units_supported, punit) {
2689 && pcity->surplus[O_SHIELD] < 0) {
2690 const char *punit_link = unit_link(punit);
2691
2692 /* TODO: Should the unit try to help cities on adjacent tiles? That
2693 * would be a rules change. (This action is performed by the game
2694 * it self) */
2697 notify_player(pplayer, city_tile(pcity),
2699 _("%s can't upkeep %s, unit disbanded."),
2701 }
2702
2703 /* pcity->surplus[O_SHIELD] is automatically updated. */
2704 }
2706 }
2707
2708 if (pcity->surplus[O_SHIELD] < 0) {
2709 /* Special case: MissingXProtected. This nasty unit won't go so easily.
2710 * It'd rather make the citizens pay in blood for their failure to upkeep
2711 * it! If we make it here all normal units are already disbanded, so only
2712 * undisbandable ones remain. */
2713 unit_list_iterate_safe(pcity->units_supported, punit) {
2715
2716 if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
2717
2719 sacrifizer = punit;
2720
2721 /* No upkeep for the unit this turn. */
2722 pcity->surplus[O_SHIELD] += upkeep;
2723 }
2725 }
2726
2727 /* Now we confirm changes made last turn. */
2728 pcity->shield_stock += pcity->surplus[O_SHIELD];
2729 pcity->before_change_shields = pcity->shield_stock;
2730 pcity->last_turns_shield_surplus = pcity->surplus[O_SHIELD];
2731
2732 /* Previous turn values stored, and they are consistent with
2733 * other previous turn data.
2734 * Now reduce city size, likely messing all the values. */
2735 if (size_reduction > 0) {
2736 if (size_reduction == 1) {
2737 notify_player(pplayer, city_tile(pcity),
2739 _("Citizens in %s perish for their failure to "
2740 "upkeep %s!"),
2742 } else {
2743 notify_player(pplayer, city_tile(pcity),
2745 _("Citizens in %s perish for their failure to "
2746 "upkeep units!"),
2747 city_link(pcity));
2748 }
2749
2750 if (!city_reduce_size(pcity, size_reduction, nullptr, "upkeep_failure")) {
2751 return FALSE;
2752 }
2753 }
2754
2755 return TRUE;
2756}
2757
2758/**********************************************************************/
2761static bool city_build_building(struct player *pplayer, struct city *pcity)
2762{
2763 bool space_part;
2764 int mod;
2765 const struct impr_type *pimprove;
2766 int saved_id = pcity->id;
2767 const struct civ_map *nmap = &(wld.map);
2768
2769 if (is_convert_improvement(pcity->production.value.building)) {
2770 /* Coinage-like improvements that convert production */
2771 fc_assert(pcity->before_change_shields >= 0);
2772
2773 /* pcity->before_change_shields already contains the surplus from
2774 * this turn. */
2776 pplayer->economic.gold += pcity->before_change_shields;
2778 pplayer->economic.infra_points += pcity->before_change_shields;
2779 }
2780
2781 pcity->before_change_shields = 0;
2782 pcity->shield_stock = 0;
2783 choose_build_target(pplayer, pcity);
2784
2785 return TRUE;
2786 }
2787
2789
2790 /* The final (after upgrade) build target */
2791 pimprove = pcity->production.value.building;
2792
2793 if (!can_city_build_improvement_now(pcity, pimprove)) {
2795 _("%s is building %s, which is no longer available."),
2798 script_server_signal_emit("building_cant_be_built", pimprove, pcity,
2799 "unavailable");
2800 return TRUE;
2801 }
2802 if (pcity->shield_stock >= impr_build_shield_cost(pcity, pimprove)
2804 int cost;
2805
2806 if (is_small_wonder(pimprove)) {
2807 city_list_iterate(pplayer->cities, wcity) {
2808 if (city_has_building(wcity, pimprove)) {
2809 city_remove_improvement(wcity, pimprove);
2810 break;
2811 }
2813 }
2814
2815 space_part = TRUE;
2817 RPT_CERTAIN) > 0) {
2818 pplayer->spaceship.structurals++;
2820 RPT_CERTAIN) > 0) {
2821 pplayer->spaceship.components++;
2823 RPT_CERTAIN) > 0) {
2824 pplayer->spaceship.modules++;
2825 } else {
2826 space_part = FALSE;
2828 _("Completion of %s"));
2829 }
2830 cost = impr_build_shield_cost(pcity, pimprove);
2831 pcity->before_change_shields -= cost;
2832 pcity->shield_stock -= cost;
2833 pcity->turn_last_built = game.info.turn;
2834 /* To eliminate micromanagement */
2835 if (is_great_wonder(pimprove)) {
2837 _("The %s have finished building %s in %s."),
2838 nation_plural_for_player(pplayer),
2840 city_link(pcity));
2841 }
2842
2844 _("%s has finished building %s."),
2846 script_server_signal_emit("building_built", pimprove, pcity);
2847
2848 if (!city_exist(saved_id)) {
2849 /* Script removed city */
2850 return FALSE;
2851 }
2852
2853 /* Call this function since some buildings may change the
2854 * the vision range of a city */
2856
2858 RPT_CERTAIN))) {
2859 struct research *presearch = research_get(pplayer);
2860 char research_name[MAX_LEN_NAME * 2];
2861 int i;
2862 const char *provider = improvement_name_translation(pimprove);
2863
2865 PL_("%s boosts research; you gain %d immediate "
2866 "advance.",
2867 "%s boosts research; you gain %d immediate "
2868 "advances.",
2869 mod), provider, mod);
2870
2872 for (i = 0; i < mod; i++) {
2875
2878 /* TRANS: Tech from building (Darwin's Voyage) */
2879 Q_("?frombldg:Acquired %s from %s."), adv_name,
2880 provider);
2881
2883 /* TRANS: Tech from building (Darwin's
2884 * Voyage) */
2885 Q_("?frombldg:The %s have acquired %s "
2886 "from %s."),
2888 }
2889 }
2890 if (space_part && pplayer->spaceship.state == SSHIP_NONE) {
2892 _("The %s have started building a spaceship!"),
2893 nation_plural_for_player(pplayer));
2894 pplayer->spaceship.state = SSHIP_STARTED;
2895 }
2896 if (space_part) {
2897 /* Space ship part build */
2898 send_spaceship_info(pplayer, nullptr);
2899 } else {
2900 /* Update city data. */
2901 if (city_refresh(pcity)) {
2903 }
2904 }
2905
2906 /* Move to the next thing in the worklist */
2907 choose_build_target(pplayer, pcity);
2908 }
2909
2910 return TRUE;
2911}
2912
2913/**********************************************************************/
2922static struct unit *city_create_unit(struct city *pcity,
2923 const struct unit_type *utype,
2924 struct citizens_reduction *red)
2925{
2926 struct player *pplayer = city_owner(pcity);
2927 struct unit *punit;
2928 int saved_unit_id;
2929 int pop_cost = utype_pop_value(utype, pcity);
2930
2933 pcity->id, -1, -1);
2934 pplayer->score.units_built++;
2935
2936 if (pop_cost > 0 && pcity->nationality != nullptr) {
2937 /* We don't reduce city size in-place to keep it correct and
2938 * existing at all while we call the following callback.
2939 * We want citizens_unit_nationality() to adjust 'red' even when
2940 * we are not setting unit nationality based on the return */
2941 struct player *nat = citizens_unit_nationality(pcity, pop_cost, red);
2942
2945 }
2946 } else if (red) {
2947 red->change = 0;
2948 }
2949
2950 (void) place_unit(punit, pplayer, pcity, nullptr, FALSE);
2952
2953 /* If city has a rally point set, give the unit a move order. */
2954 if (pcity->rally_point.length) {
2956 punit->orders.length = pcity->rally_point.length;
2957 punit->orders.vigilant = pcity->rally_point.vigilant;
2958 punit->orders.list = fc_malloc(pcity->rally_point.length
2959 * sizeof(struct unit_order));
2960 memcpy(punit->orders.list, pcity->rally_point.orders,
2961 pcity->rally_point.length * sizeof(struct unit_order));
2962 }
2963
2964 /* This might destroy pcity and/or punit: */
2965 script_server_signal_emit("unit_built", punit, pcity);
2966
2968 return punit;
2969 } else {
2970 return nullptr;
2971 }
2972}
2973
2974/**********************************************************************/
2983static bool city_build_unit(struct player *pplayer, struct city *pcity)
2984{
2985 const struct unit_type *utype;
2986 struct worklist *pwl = &pcity->worklist;
2988 int saved_city_id = pcity->id;
2989 const struct civ_map *nmap = &(wld.map);
2990
2991 fc_assert_ret_val(pcity->production.kind == VUT_UTYPE, FALSE);
2992
2993 /* If the city has already bought a unit which is now obsolete, don't try
2994 * to upgrade the production. The new unit might require more shields, which
2995 * would be bad if it was bought to urgently defend a city. (Equally it
2996 * might be the same cost or cheaper, but tough; you hurried the unit so
2997 * you miss out on technological advances.) */
3000 }
3001
3002 utype = pcity->production.value.utype;
3004
3005 /* We must make a special case for barbarians here, because they are
3006 so dumb. Really. They don't know the prerequisite techs for units
3007 they build!! - Per */
3009 && !is_barbarian(pplayer)) {
3011 _("%s is building %s, which is no longer available."),
3013
3014 /* Log before signal emitting, so pointers are certainly valid */
3015 log_verbose("%s %s tried to build %s, which is not available.",
3018 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3019 "unavailable");
3020 return city_exist(saved_city_id);
3021 }
3022
3023 if (pcity->shield_stock >= unit_shield_cost
3025 int pop_cost = utype_pop_value(utype, pcity);
3026 struct unit *punit;
3027
3028 /* Should we disband the city? -- Massimo */
3029 if (city_size_get(pcity) == pop_cost
3031 return !disband_city(pcity);
3032 }
3033
3034 if (city_size_get(pcity) <= pop_cost) {
3036 /* TRANS: city ... utype ... size ... pop_cost */
3037 _("%s can't build %s yet. "
3038 "(city size: %d, unit population cost: %d)"),
3040 city_size_get(pcity), pop_cost);
3041 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3042 "pop_cost");
3043 return city_exist(saved_city_id);
3044 }
3045
3046 fc_assert(pop_cost == 0 || city_size_get(pcity) >= pop_cost);
3047
3048 /* don't update turn_last_built if we returned above */
3049 pcity->turn_last_built = game.info.turn;
3050
3051 /* check if we can build more than one unit (effect City_Build_Slots) */
3053
3054 /* We should be able to build at least one (by checks above) */
3055 fc_assert(num_units >= 1);
3056
3057 for (i = 0; i < num_units; i++) {
3059
3061
3062 /* Check if the city still exists (script might have removed it).
3063 * If not, we assume any effects / announcements done below were
3064 * already replaced by the script if necessary. */
3065 if (!city_exist(saved_city_id)) {
3066 break;
3067 }
3068
3069 if (punit) {
3070 if (punit->carrying
3073 /* TRANS: <city> is finished building <unit>, carrying <goods>. */
3074 _("%s is finished building %s, carrying %s."),
3077 } else {
3079 /* TRANS: <city> is finished building <unit/building>. */
3080 _("%s is finished building %s."),
3082 }
3083 }
3084
3085 /* After we created the unit remove the citizen. This will also
3086 * rearrange the worker to take into account the extra resources
3087 * (food) needed. */
3088 if (pop_cost > 0) {
3089 /* This won't disband city due to pop_cost, but script might
3090 * still destroy city. */
3092 /* If the city has changed its nationalities during
3093 * "unit_built" signal, we take some other citizens instead */
3094 if (!city_reduce_size(pcity, pop_cost, nullptr, "unit_built")) {
3095 break;
3096 }
3097 }
3098
3099 /* to eliminate micromanagement, we only subtract the unit's cost */
3100 /* signals could change the prod stock! */
3101 if ((pcity->before_change_shields -= unit_shield_cost) < 0) {
3102 pcity->before_change_shields = 0;
3103 }
3104 if ((pcity->shield_stock -= unit_shield_cost) < 0) {
3105 log_normal("City %s (%s) has built %s but has no %d shields "
3106 "for it, nullifying shield stock", city_name_get(pcity),
3107 player_name(pplayer), utype_rule_name(utype),
3109 pcity->shield_stock = 0;
3110 }
3111
3112 if (pop_cost > 0) {
3113 /* Additional message if the unit has population cost. */
3115 ftc_server,
3116 /* TRANS: "<unit> cost... <city> shrinks..."
3117 * Plural in "%d population", not "size %d". */
3118 PL_("%s cost %d population. %s shrinks to size %d.",
3119 "%s cost %d population. %s shrinks to size %d.",
3120 pop_cost),
3121 utype_name_translation(utype), pop_cost,
3123 }
3124
3125 if (i != 0 && worklist_length(pwl) > 0) {
3126 /* remove the build unit from the worklist; it has to be one less
3127 * than units build to preserve the next build target from the
3128 * worklist */
3129 worklist_remove(pwl, 0);
3130 }
3131 } /* for */
3132
3134 if (pcity->rally_point.length && !pcity->rally_point.persistent) {
3136 }
3137
3138 /* Done building this unit; time to move on to the next. */
3139 choose_build_target(pplayer, pcity);
3140 }
3141 } /* if */
3142
3143 return city_exist(saved_city_id);
3144}
3145
3146/**********************************************************************/
3149static bool city_build_stuff(struct player *pplayer, struct city *pcity)
3150{
3151 if (!city_distribute_surplus_shields(pplayer, pcity)) {
3152 return FALSE;
3153 }
3154
3157
3158 switch (pcity->production.kind) {
3159 case VUT_IMPROVEMENT:
3160 return city_build_building(pplayer, pcity);
3161 case VUT_UTYPE:
3162 return city_build_unit(pplayer, pcity);
3163 default:
3164 /* Must never happen! */
3166 break;
3167 };
3168
3169 return FALSE;
3170}
3171
3172/**********************************************************************/
3182static bool sell_random_building(struct player *pplayer,
3183 struct cityimpr_list *imprs)
3184{
3185 struct cityimpr *pcityimpr;
3186 int r;
3187
3188 fc_assert_ret_val(pplayer != nullptr, FALSE);
3189
3190 if (!imprs || cityimpr_list_size(imprs) == 0) {
3191 return FALSE;
3192 }
3193
3196
3198 ftc_server,
3199 _("Can't afford to maintain %s in %s, building sold!"),
3201 city_link(pcityimpr->pcity));
3202 log_debug("%s: sold building (%s)", player_name(pplayer),
3204
3205 do_sell_building(pplayer, pcityimpr->pcity, pcityimpr->pimprove, "cant_maintain");
3206
3208
3209 /* Get back the gold upkeep that was already paid this turn. */
3211 pcityimpr->pimprove);
3212
3214
3216
3217 return TRUE;
3218}
3219
3220/**********************************************************************/
3228static void uk_rem_gold_callback(struct unit *punit)
3229{
3230 int gold_upkeep;
3231
3232 /* Remove the unit from uk_rem_gold. */
3234
3235 gold_upkeep = punit->server.upkeep_paid[O_GOLD];
3236
3237 /* All units in uk_rem_gold should have gold upkeep! */
3238 fc_assert_ret_msg(gold_upkeep > 0, "%s has %d gold upkeep",
3239 unit_rule_name(punit), gold_upkeep);
3240
3241 /* Get the upkeep gold back. */
3242 unit_owner(punit)->economic.gold += gold_upkeep;
3243}
3244
3245/**********************************************************************/
3249static void uk_rem_gold_append(struct unit *punit)
3250{
3251 /* Make the unit aware that it is on the uk_rem_gold list. */
3253
3254 /* Add the unit to the list. */
3256}
3257
3258/**********************************************************************/
3262static void unit_list_referred_destroy(struct unit_list *punitlist)
3263{
3265 /* Clear the unit's knowledge of the list. */
3268
3269 /* Destroy the list it self. */
3271}
3272
3273/**********************************************************************/
3285static struct unit *sell_random_unit(struct player *pplayer,
3286 struct unit_list *punitlist)
3287{
3288 struct unit *punit;
3289 int r;
3290 struct unit_list *cargo;
3291
3292 fc_assert_ret_val(pplayer != nullptr, nullptr);
3293
3294 if (!punitlist || unit_list_size(punitlist) == 0) {
3295 return nullptr;
3296 }
3297
3300
3301 cargo = unit_list_new();
3302
3303 /* Check if unit is transporting other units from punitlist,
3304 * and sell one of those (recursively) instead.
3305 * Note that in case of recursive transports we have to iterate
3306 * also through those middle transports that themselves are not in
3307 * punitlist. */
3309 /* Optimization, do not iterate over punitlist
3310 * if we are sure that pcargo is not in it. */
3311 if (pcargo->server.upkeep_paid[O_GOLD] > 0) {
3313 if (pcargo == p2) {
3314 unit_list_append(cargo, pcargo);
3315 }
3317 }
3319
3320 if (unit_list_size(cargo) > 0) {
3321 /* Recursively sell. Note that cargo list has both
3322 * leaf units and middle transports in case of
3323 * recursive transports. */
3324 struct unit *ret = sell_random_unit(pplayer, cargo);
3325
3326 unit_list_destroy(cargo);
3327
3329
3330 return ret;
3331 }
3332
3333 unit_list_destroy(cargo);
3334
3335 {
3336 const char *punit_link = unit_tile_link(punit);
3337#ifdef FREECIV_DEBUG
3338 const char *punit_logname = unit_rule_name(punit);
3339#endif /* FREECIV_DEBUG */
3340 struct tile *utile = unit_tile(punit);
3341
3345
3346 /* The gold was paid back when the unit removal made
3347 * uk_rem_gold_callback() run as the unit's removal call back. */
3348
3349 notify_player(pplayer, utile, E_UNIT_LOST_MISC, ftc_server,
3350 _("Not enough gold. %s disbanded."),
3351 punit_link);
3352 log_debug("%s: unit sold (%s)", player_name(pplayer),
3354 } else {
3355 /* Not able to get rid of punit */
3356 return nullptr;
3357 }
3358 }
3359
3361
3362 return punit;
3363}
3364
3365/**********************************************************************/
3369{
3370 struct cityimpr_list *pimprlist;
3371 bool sell_unit = TRUE;
3372
3373 if (!pplayer) {
3374 return FALSE;
3375 }
3376
3379
3380 city_list_iterate(pplayer->cities, pcity) {
3381 city_built_iterate(pcity, pimprove) {
3382 if (can_city_sell_building(pcity, pimprove)) {
3383 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3384
3385 ci->pcity = pcity;
3386 ci->pimprove = pimprove;
3388 }
3391
3392 unit_list_iterate(pplayer->units, punit) {
3393 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3395 }
3397
3398 while (pplayer->economic.gold < 0
3400 || unit_list_size(uk_rem_gold) > 0)) {
3402 || unit_list_size(uk_rem_gold) == 0) {
3404 } else {
3405 sell_random_unit(pplayer, uk_rem_gold);
3406 }
3408 }
3409
3410 /* Free remaining entries from list */
3412 FC_FREE(pimpr);
3414
3415 if (pplayer->economic.gold < 0) {
3416 /* If we get here it means the player has
3417 * negative gold. This should never happen. */
3418 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3419 player_name(pplayer), player_number(pplayer));
3420 }
3421
3424
3425 return pplayer->economic.gold >= 0;
3426}
3427
3428/**********************************************************************/
3432{
3433 if (!pplayer) {
3434 return FALSE;
3435 }
3436
3438
3439 unit_list_iterate(pplayer->units, punit) {
3440 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3442 }
3444
3445 while (pplayer->economic.gold < 0
3446 && sell_random_unit(pplayer, uk_rem_gold)) {
3447 /* All done in sell_random_unit() */
3448 }
3449
3450 if (pplayer->economic.gold < 0) {
3451 /* If we get here it means the player has
3452 * negative gold. This should never happen. */
3453 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3454 player_name(pplayer), player_number(pplayer));
3455 }
3456
3458
3459 return pplayer->economic.gold >= 0;
3460}
3461
3462/**********************************************************************/
3466{
3467 struct player *pplayer;
3468 struct cityimpr_list *pimprlist;
3469
3470 if (!pcity) {
3471 return TRUE;
3472 }
3473
3474 pplayer = city_owner(pcity);
3476
3477 /* Create a vector of all buildings that can be sold. */
3478 city_built_iterate(pcity, pimprove) {
3479 if (can_city_sell_building(pcity, pimprove)) {
3480 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3481
3482 ci->pcity = pcity;
3483 ci->pimprove = pimprove;
3485 }
3487
3488 /* Try to sell some buildings. */
3489 while (pplayer->economic.gold < 0
3490 && sell_random_building(pplayer, pimprlist)) {
3491 /* all done in sell_random_building */
3492 }
3493
3494 /* Free remaining entries from list */
3496 FC_FREE(pimpr);
3498
3500
3501 return pplayer->economic.gold >= 0;
3502}
3503
3504/**********************************************************************/
3513{
3514 struct player *pplayer;
3515
3516 if (!pcity) {
3517 return TRUE;
3518 }
3519
3520 pplayer = city_owner(pcity);
3522
3523 /* Create a vector of all supported units with gold upkeep. */
3524 unit_list_iterate(pcity->units_supported, punit) {
3525 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3527 }
3529
3530 /* Still not enough gold, so try "selling" some units. */
3531 while (pplayer->economic.gold < 0
3532 && sell_random_unit(pplayer, uk_rem_gold)) {
3533 /* All done in sell_random_unit() */
3534 }
3535
3536 /* If we get here the player has negative gold, but hopefully
3537 * another city will be able to pay the deficit, so continue. */
3538
3540
3541 return pplayer->economic.gold >= 0;
3542}
3543
3544/**********************************************************************/
3547static bool place_pollution(struct city *pcity, enum extra_cause cause)
3548{
3549 struct tile *ptile;
3550 struct tile *pcenter = city_tile(pcity);
3551 int city_radius_sq = city_map_radius_sq_get(pcity);
3552 int k = 100;
3553 const struct civ_map *nmap = &(wld.map);
3554
3555 while (k > 0) {
3556 /* Place pollution on a random city tile */
3557 int cx, cy;
3558 int tile_id = fc_rand(city_map_tiles(city_radius_sq));
3559 struct extra_type *pextra;
3560
3561 city_tile_index_to_xy(&cx, &cy, tile_id, city_radius_sq);
3562
3563 /* Check for a real map position */
3564 if (!(ptile = city_map_to_tile(nmap, pcenter, city_radius_sq, cx, cy))) {
3565 continue;
3566 }
3567
3568 pextra = rand_extra_for_tile(ptile, cause, FALSE);
3569
3570 if (pextra != nullptr && !tile_has_extra(ptile, pextra)) {
3571 tile_add_extra(ptile, pextra);
3572 update_tile_knowledge(ptile);
3573
3574 return TRUE;
3575 }
3576 k--;
3577 }
3578 log_debug("pollution not placed: city: %s", city_name_get(pcity));
3579
3580 return FALSE;
3581}
3582
3583/**********************************************************************/
3586static void check_pollution(struct city *pcity)
3587{
3588 if (fc_rand(100) < pcity->pollution) {
3591 _("Pollution near %s."), city_link(pcity));
3592 }
3593 }
3594}
3595
3596/**********************************************************************/
3603int city_incite_cost(struct player *pplayer, struct city *pcity)
3604{
3605 int dist, size;
3606 double cost; /* Intermediate values can get very large */
3607
3608 /* Gold factor */
3609 cost = city_owner(pcity)->economic.gold + game.server.base_incite_cost;
3610
3615
3616 /* Buildings */
3617 city_built_iterate(pcity, pimprove) {
3618 cost += impr_build_shield_cost(pcity, pimprove)
3621
3622 /* Stability bonuses */
3623 if (!city_unhappy(pcity)) {
3624 cost *= 2;
3625 }
3626 if (city_celebrating(pcity)) {
3627 cost *= 2;
3628 }
3629
3630 /* Buy back is cheap, conquered cities are also cheap */
3632 if (city_owner(pcity) != pcity->original) {
3633 if (pplayer == pcity->original) {
3634 cost /= 2; /* Buy back: 50% price reduction */
3635 } else {
3636 cost = cost * 2 / 3; /* Buy conquered: 33% price reduction */
3637 }
3638 }
3639 }
3640
3641 /* Distance from capital */
3642 /* Max penalty. Applied if there is no capital, or it's even further away. */
3643 dist = 32;
3645 if (is_capital(capital)) {
3646 int tmp = map_distance(capital->tile, pcity->tile);
3647
3648 if (tmp < dist) {
3649 dist = tmp;
3650 }
3651 }
3653
3657 - pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] * 3);
3658 cost *= size;
3660 cost = cost / (dist + 3);
3661
3663 int cost_per_citizen = cost / pcity->size;
3665 int tgt_cit = citizens_nation_get(pcity, pplayer->slot);
3666 int third_party = pcity->size - natives - tgt_cit;
3667
3668 cost = cost_per_citizen * (natives + 0.7 * third_party + 0.5 * tgt_cit);
3669 }
3670
3672 cost /= 100;
3673
3676 } else {
3677 return cost;
3678 }
3679}
3680
3681/**********************************************************************/
3685{
3686 /* Remember what this city is building last turn, so that on the next turn
3687 * the player can switch production to something else and then change it
3688 * back without penalty. This has to be updated _before_ production for
3689 * this turn is calculated, so that the penalty will apply if the player
3690 * changes production away from what has just been completed. This makes
3691 * sense if you consider what this value means: all the shields in the
3692 * city have been dedicated toward the project that was chosen last turn,
3693 * so the player shouldn't be penalized if the governor has to pick
3694 * something different. See city_change_production_penalty(). */
3695 pcity->changed_from = pcity->production;
3696
3697 log_debug("In %s, building %s. Beg of Turn shields = %d",
3699 pcity->before_change_shields);
3700}
3701
3702/**********************************************************************/
3706{
3707 pcity->disbanded_shields = 0;
3708 pcity->caravan_shields = 0;
3709}
3710
3711/**********************************************************************/
3716{
3718 pcity->before_change_shields = 0;
3719}
3720
3721/**********************************************************************/
3724static void update_city_activity(struct city *pcity)
3725{
3726 struct player *pplayer;
3727 struct government *gov;
3728 bool is_happy;
3729 bool is_celebrating;
3730
3731 if (!pcity) {
3732 return;
3733 }
3734
3735 pplayer = city_owner(pcity);
3739
3740 if (city_refresh(pcity)) {
3742 }
3743
3744 /* Reporting of celebrations rewritten, copying the treatment of disorder below,
3745 with the added rapture rounds count. 991219 -- Jing */
3746 if (city_build_stuff(pplayer, pcity)) {
3747 int saved_id;
3748 int revolution_turns;
3749
3750 pcity->history += city_history_gain(pcity);
3751
3752 /* History can decrease, but never go below zero */
3753 pcity->history = MAX(pcity->history, 0);
3754
3755 /* Keep old behavior when building new improvement could keep
3756 city celebrating */
3757 if (!is_happy) {
3759 }
3760
3762 pcity->rapture++;
3763
3764 /* Update city's celebrating counters */
3766 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3767 pcity->counter_values[pcount->index]++;
3768 }
3770
3771 if (pcity->rapture == 1) {
3773 _("Celebrations in your honor in %s."),
3774 city_link(pcity));
3775 }
3776 } else {
3777 if (pcity->rapture != 0) {
3779 _("Celebrations canceled in %s."),
3780 city_link(pcity));
3781 }
3782
3783 /* Update city's celebrating counters */
3785 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3786 pcity->counter_values[pcount->index] = 0;
3787 }
3789 pcity->rapture = 0;
3790 }
3791 pcity->was_happy = is_happy;
3792
3793 /* Handle the illness. */
3794 if (game.info.illness_on) {
3795 /* Recalculate city illness; illness due to trade has to be saved
3796 * within the city struct, as the client does not have all
3797 * the data to calculate it */
3798 pcity->server.illness
3799 = city_illness_calc(pcity, nullptr, nullptr,
3800 &(pcity->illness_trade), nullptr);
3801
3803 if (!city_illness_strike(pcity)) {
3804 /* Illness destroyed the city */
3805 return;
3806 }
3807 }
3808 }
3809
3810 /* City population updated here, after the rapture stuff above. --Jing */
3811 saved_id = pcity->id;
3812 pcity->had_famine = FALSE;
3813 city_populate(pcity, pplayer);
3814 if (player_city_by_number(pplayer, saved_id) == nullptr) {
3815 return;
3816 }
3817
3818 pcity->did_sell = FALSE;
3819 pcity->did_buy = FALSE;
3820 pcity->airlift = city_airlift_max(pcity);
3821 update_bulbs(pplayer, pcity->prod[O_SCIENCE], FALSE, FALSE);
3822
3824
3825 /* Update the treasury. */
3826 pplayer->economic.gold += pcity->surplus[O_GOLD];
3827
3828 /* FIXME: Nation level upkeep should be paid after ALL cities
3829 * have been processed, not after each individual city. */
3831 /* Unit upkeep was not included in city balance ->
3832 * not reduced from the city surplus. */
3834
3836 /* Building upkeep was not included in city balance ->
3837 * not reduced from the city surplus. */
3839 }
3840 }
3841
3842 /* Remember how much gold upkeep each unit was paid. */
3843 unit_list_iterate(pcity->units_supported, punit) {
3846
3847 if (pplayer->economic.gold < 0) {
3848 /* Not enough gold - we have to sell some buildings, and if that
3849 * is not enough, disband units with gold upkeep, taking into
3850 * account the setting of 'game.info.gold_upkeep_style':
3851 * GOLD_UPKEEP_CITY: Cities pay for buildings and units.
3852 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
3853 * for units.
3854 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
3855 switch (game.info.gold_upkeep_style) {
3856 case GOLD_UPKEEP_CITY:
3857 case GOLD_UPKEEP_MIXED:
3861 }
3862 break;
3863 case GOLD_UPKEEP_NATION:
3864 break;
3865 }
3866 }
3867
3869 if (city_unhappy(pcity)) {
3870 const char *revomsg;
3871
3872 pcity->anarchy++;
3873
3875 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3876 pcity->counter_values[pcount->index]++;
3877 }
3879
3880 if (pcity->anarchy == revolution_turns) {
3881 /* Revolution next turn if not dealt with */
3882 /* TRANS: preserve leading space; this string will be appended to
3883 * another sentence */
3884 revomsg = _(" Unrest threatens to spread beyond the city.");
3885 } else {
3886 revomsg = "";
3887 }
3888 if (pcity->anarchy == 1) {
3890 /* TRANS: second %s is an optional extra sentence */
3891 _("Civil disorder in %s.%s"),
3893 } else {
3895 /* TRANS: second %s is an optional extra sentence */
3896 _("CIVIL DISORDER CONTINUES in %s.%s"),
3898 }
3899 } else {
3900 if (pcity->anarchy != 0) {
3902 _("Order restored in %s."),
3903 city_link(pcity));
3904 }
3905 pcity->anarchy = 0;
3906
3908 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3909 pcity->counter_values[pcount->index] = 0;
3910 }
3912 }
3914
3915 send_city_info(nullptr, pcity);
3916
3917 if (revolution_turns > 0 && pcity->anarchy > revolution_turns) {
3919 /* TRANS: %s - government form, e.g., Democracy */
3920 _("The people have overthrown your %s, "
3921 "your country is in turmoil."),
3924 }
3925 if (city_refresh(pcity)) {
3927 }
3929 }
3930}
3931
3932/**********************************************************************/
3935static bool city_illness_check(const struct city * pcity)
3936{
3937 if (fc_rand(1000) < pcity->server.illness) {
3938 return TRUE;
3939 }
3940
3941 return FALSE;
3942}
3943
3944/**********************************************************************/
3948static bool disband_city(struct city *pcity)
3949{
3950 struct player *pplayer = city_owner(pcity);
3951 struct tile *ptile = pcity->tile;
3952 struct city *rcity = nullptr;
3953 const struct unit_type *utype = pcity->production.value.utype;
3954 struct unit *punit;
3955 int saved_id = pcity->id;
3956
3957 /* Find closest city other than pcity */
3958 rcity = find_closest_city(ptile, pcity, pplayer, FALSE, FALSE, FALSE, TRUE,
3959 FALSE, nullptr);
3960
3961 if (!rcity) {
3962 /* What should we do when we try to disband our only city? */
3963 notify_player(pplayer, ptile, E_CITY_CANTBUILD, ftc_server,
3964 _("%s can't build %s yet, "
3965 "as we can't disband our only city."),
3967 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3968 "pop_cost");
3969 if (!city_exist(saved_id)) {
3970 /* Script decided to remove even the last city */
3971 return TRUE;
3972 } else {
3973 return FALSE;
3974 }
3975 }
3976
3978
3979 /* "unit_built" script handler may have destroyed city. If so, we
3980 * assume something sensible happened to its units, and that the
3981 * script took care of announcing unit creation if required. */
3982 if (city_exist(saved_id)) {
3983 /* Shift all the units supported by pcity (including the new unit)
3984 * to rcity. transfer_city_units() does not make sure no units are
3985 * left floating without a transport, but since all units are
3986 * transferred this is not a problem. */
3987 transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity,
3988 pcity, -1, TRUE);
3989
3990 if (punit) {
3991 notify_player(pplayer, ptile, E_UNIT_BUILT, ftc_server,
3992 /* TRANS: "<city> is disbanded into Settler." */
3993 _("%s is disbanded into %s."),
3995 }
3996
3997 script_server_signal_emit("city_destroyed", pcity, pcity->owner, NULL);
3998
3999 if (!city_exist(saved_id)) {
4000 /* Already removed during the script */
4001 return TRUE;
4002 }
4004
4005 /* Since we've removed the city, we don't need to worry about
4006 * charging for production, disabling rally points, etc. */
4007 }
4008
4009 return TRUE;
4010}
4011
4012/**********************************************************************/
4060static float city_migration_score(struct city *pcity)
4061{
4062 float score = 0.0;
4063 int build_shield_cost = 0;
4064 bool has_wonder = FALSE;
4065
4066 if (!pcity) {
4067 return score;
4068 }
4069
4070 if (pcity->server.mgr_score_calc_turn == game.info.turn) {
4071 /* up-to-date migration score */
4072 return pcity->server.migration_score;
4073 }
4074
4075 /* feeling of the citizens */
4076 score = (city_size_get(pcity)
4077 + 1.00 * pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
4078 + 0.00 * pcity->feel[CITIZEN_CONTENT][FEELING_FINAL]
4079 - 0.25 * pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
4080 - 0.50 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
4081
4082 /* calculate shield build cost for all buildings */
4083 city_built_iterate(pcity, pimprove) {
4085 if (is_wonder(pimprove)) {
4086 /* this city has a wonder */
4087 has_wonder = TRUE;
4088 }
4090
4091 /* take shield costs of all buidings into account; normalized by 1000 */
4092 score *= (1 + (1 - exp(- (float) MAX(0, build_shield_cost) / 1000)) / 5);
4093 /* take trade into account; normalized by 100 */
4094 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_TRADE]) / 100))
4095 / 5);
4096 /* take luxury into account; normalized by 100 */
4097 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_LUXURY]) / 100))
4098 / 5);
4099 /* take science into account; normalized by 100 */
4100 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_SCIENCE]) / 100))
4101 / 5);
4102
4104
4105 /* Take food into account; the food surplus is clipped to values between
4106 * -10..20 and normalize by 10. Thus, the factor is between 0.9 and 1.2. */
4107 score *= (1 + (float) CLIP(-10, pcity->surplus[O_FOOD], 20) / 10 );
4108
4109 /* Reduce the score due to city illness (plague). The illness is given in
4110 * tenth of percent (0..1000) and normalized by 25. Thus, this factor is
4111 * between 0.6 (ill city) and 1.0 (health city). */
4112 score *= (100 - (float)city_illness_calc(pcity, nullptr, nullptr,
4113 nullptr, nullptr) / 25);
4114
4115 if (has_wonder) {
4116 /* People like wonders */
4117 score *= 1.25;
4118 }
4119
4120 if (is_capital(pcity)) {
4121 /* The capital is a magnet for the citizens */
4122 score *= 1.25;
4123 }
4124
4125 /* Take into account effects */
4126 score *= (1.0 + get_city_bonus(pcity, EFT_MIGRATION_PCT) / 100.0);
4127
4128 log_debug("[M] %s score: %.3f", city_name_get(pcity), score);
4129
4130 /* Set migration score for the city */
4131 pcity->server.migration_score = score;
4132 /* Set the turn, when the score was calculated */
4133 pcity->server.mgr_score_calc_turn = game.info.turn;
4134
4135 return score;
4136}
4137
4138/**********************************************************************/
4145 struct city *pcity_to)
4146{
4148 struct tile *ptile_from, *ptile_to;
4150 const char *nation_from, *nation_to;
4151 struct city *rcity = nullptr;
4152 int to_id = pcity_to->id;
4153 const struct civ_map *nmap = &(wld.map);
4154
4155 if (!pcity_from || !pcity_to) {
4156 return FALSE;
4157 }
4158
4162 /* We copy that, because city_link always returns the same pointer. */
4169
4170 /* Check food supply in the receiver city */
4172 bool migration = FALSE;
4173
4174 if (pcity_to->surplus[O_FOOD] >= game.info.food_cost) {
4175 migration = TRUE;
4176 } else {
4177 /* Check if there is a free tile for the new citizen which, when worked,
4178 * leads to zero or positive food surplus for the enlarged city */
4179 int max_food_tile = -1; /* no free tile */
4180
4182 city_tile(pcity_to), ptile) {
4183 if (city_can_work_tile(pcity_to, ptile)
4184 && tile_worked(ptile) != pcity_to) {
4185 /* Safest assumption is that city won't be celebrating once an
4186 * additional citizen is added */
4189 }
4191 if (max_food_tile >= 0
4192 && pcity_to->surplus[O_FOOD] + max_food_tile >= game.info.food_cost) {
4193 migration = TRUE;
4194 }
4195 }
4196
4197 if (!migration) {
4198 /* Insufficiency food in receiver city; no additional citizens */
4199 if (pplayer_from == pplayer_to) {
4200 /* Migration between one nation */
4202 /* TRANS: From <city1> to <city2>. */
4203 _("Migrants from %s can't go to %s because there is "
4204 "not enough food available!"),
4206 } else {
4207 /* Migration between different nations */
4209 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4210 _("Migrants from %s can't go to %s (%s) because there "
4211 "is not enough food available!"),
4214 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4215 _("Migrants from %s (%s) can't go to %s because there "
4216 "is not enough food available!"),
4218 }
4219
4220 return FALSE;
4221 }
4222 }
4223
4225 /* Receiver city can't grow */
4226 if (pplayer_from == pplayer_to) {
4227 /* Migration between one nation */
4229 /* TRANS: From <city1> to <city2>. */
4230 _("Migrants from %s can't go to %s because it needs "
4231 "an improvement to grow!"),
4233 } else {
4234 /* Migration between different nations */
4236 /* TRANS: From <city1> to <city2> of <city2 nation adjective>. */
4237 _("Migrants from %s can't go to %s (%s) because it "
4238 "needs an improvement to grow!"),
4241 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4242 _("Migrants from %s (%s) can't go to %s because it "
4243 "needs an improvement to grow!"),
4245 }
4246
4247 return FALSE;
4248 }
4249
4250 /* Reduce size of giver */
4251 if (city_size_get(pcity_from) == 1) {
4252
4254 /* Preserve nationality of city's only citizen */
4256 }
4257
4258 /* Do not destroy wonders */
4259 city_built_iterate(pcity_from, pimprove) {
4260 if (is_wonder(pimprove)) {
4261 return FALSE;
4262 }
4264
4265 /* Find closest city other of the same player than pcity_from */
4267 FALSE, FALSE, TRUE, FALSE, nullptr);
4268
4269 if (rcity) {
4270 int id = pcity_from->id;
4271
4272 /* Transfer all units to the closest city */
4274 pcity_from->units_supported, rcity, pcity_from,
4275 -1, TRUE);
4277
4278 script_server_signal_emit("city_size_change", pcity_from,
4279 (lua_Integer)(-1), "migration_from");
4280
4281 if (city_exist(id)) {
4282 script_server_signal_emit("city_destroyed", pcity_from,
4283 pcity_from->owner, nullptr);
4284
4285 if (city_exist(id)) {
4287 }
4288 }
4289
4291 _("%s was disbanded by its citizens."),
4292 name_from);
4293 } else {
4294 /* It's the only city of the nation */
4295 return FALSE;
4296 }
4297 } else {
4298 /* The migrants take half of the food box with them (this prevents
4299 * migration -> grow -> migration -> ... cycles) */
4300 pcity_from->food_stock /= 2;
4301
4303 /* Those citizens that are from the target nation are most
4304 * ones migrating. */
4305 if (citizens_nation_get(pcity_from, pplayer_to->slot) > 0) {
4307 } else if (!citizens_nation_get(pcity_from, pplayer_citizen->slot)) {
4308 /* No native citizens at all in the city, choose random foreigner */
4310
4312 }
4313 /* This should be followed by city_reduce_size(). */
4315 }
4316 city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
4318 if (city_refresh(pcity_from)) {
4320 }
4321 }
4322
4323 /* This should be _before_ the size of the city is increased. Thus, the
4324 * order of the messages is correct (1: migration; 2: increased size). */
4325 if (pplayer_from == pplayer_to) {
4326 /* Migration between one nation */
4328 /* TRANS: From <city1> to <city2>. */
4329 _("Migrants from %s moved to %s in search of a better "
4330 "life."), name_from, name_to);
4331 } else {
4332 /* Migration between different nations */
4334 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4335 _("Migrants from %s moved to %s (%s) in search of a "
4336 "better life."),
4339 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4340 _("Migrants from %s (%s) moved to %s in search of a "
4341 "better life."),
4343 }
4344
4345 /* Increase size of receiver city */
4346 if (city_exist(to_id)) {
4348
4349 if (city_exist(to_id)) {
4352 if (city_refresh(pcity_to)) {
4354 }
4355 if (incr_success) {
4356 script_server_signal_emit("city_size_change", pcity_to,
4357 (lua_Integer)1, "migration_to");
4358 }
4359 }
4360 }
4361
4362 log_debug("[M] T%d migration successful (%s -> %s)",
4364
4365 return TRUE;
4366}
4367
4368/**********************************************************************/
4390{
4391 bool internat = FALSE;
4392
4393 if (!game.server.migration) {
4394 return FALSE;
4395 }
4396
4398 || (game.server.mgr_worldchance <= 0
4399 && game.server.mgr_nationchance <= 0)) {
4400 return FALSE;
4401 }
4402
4403 /* check for migration */
4404 players_iterate(pplayer) {
4405 if (!pplayer->cities) {
4406 continue;
4407 }
4408
4409 if (check_city_migrations_player(pplayer)) {
4410 internat = TRUE;
4411 }
4413
4414 return internat;
4415}
4416
4417/**********************************************************************/
4422 struct player *pplayer = city_owner(pcity);
4423 struct tile *ptile = city_tile(pcity);
4424
4425 fc_assert_ret_val(pcity != nullptr, FALSE);
4426
4427 if (pcity->food_stock > 0) {
4428 pcity->food_stock = 0;
4429
4430 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4431 /* TRANS: %s is a city name */
4432 _("All stored food destroyed in %s."), city_link(pcity));
4433
4434 return TRUE;
4435 }
4436
4437 return FALSE;
4438}
4439
4440/**********************************************************************/
4443static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
4444{
4445 struct player *pplayer = city_owner(pcity);
4446 struct tile *ptile = city_tile(pcity);
4448
4450
4451 notify_player(pplayer, ptile, E_DISASTER,
4452 ftc_server,
4453 /* TRANS: Disasters such as Earthquake */
4454 _("%s was hit by %s."), city_name_get(pcity),
4456
4458 if (pplayer->economic.gold > 0 && pcity->prod[O_TRADE] > 0) {
4459 int amount = pcity->prod[O_TRADE] * 5;
4460
4461 amount = MIN(pplayer->economic.gold, amount);
4462 pplayer->economic.gold -= amount;
4463 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4464 PL_("Robbery in %s. %d gold stolen.",
4465 "Robbery in %s. %d gold stolen.", amount),
4468 }
4469 }
4470
4473 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4474 _("Pollution near %s."), city_link(pcity));
4476 }
4477 }
4478
4481 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4482 _("Fallout near %s."), city_link(pcity));
4484 }
4485 }
4486
4489 && pcity->size > 1)) {
4490 if (!city_reduce_size(pcity, 1, nullptr, "disaster")) {
4491 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4492 /* TRANS: "Industrial Accident destroys Bogota entirely." */
4493 _("%s destroys %s entirely."),
4495 pcity = nullptr;
4496 } else {
4497 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4498 /* TRANS: "Nuclear Accident ... Montreal." */
4499 _("%s causes population loss in %s."),
4501 }
4502
4504 }
4505
4507 int total = 0;
4508 struct impr_type *imprs[B_LAST];
4509
4510 city_built_iterate(pcity, pimprove) {
4511 if (is_improvement(pimprove)
4512 && !improvement_has_flag(pimprove, IF_DISASTER_PROOF)) {
4513 imprs[total++] = pimprove;
4514 }
4516
4517 if (total > 0) {
4518 int num = fc_rand(total);
4519
4520 building_lost(pcity, imprs[num], "disaster", nullptr);
4521
4522 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4523 /* TRANS: second %s is the name of a city improvement */
4524 _("%s destroys %s in %s."),
4527 city_link(pcity));
4528
4530 }
4531 }
4532
4536 }
4537 }
4538
4540 if (pcity->shield_stock > 0) {
4541 char prod[256];
4542
4543 pcity->shield_stock = 0;
4544 nullify_prechange_production(pcity); /* Make it impossible to recover */
4545
4546 universal_name_translation(&pcity->production, prod, sizeof(prod));
4547 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4548 /* TRANS: "Production of Colossus in Rhodes destroyed." */
4549 _("Production of %s in %s destroyed."),
4550 prod, city_link(pcity));
4551
4553 }
4554 }
4555
4556 script_server_signal_emit("disaster_occurred", pdis, pcity,
4558 script_server_signal_emit("disaster", pdis, pcity);
4559}
4560
4561/**********************************************************************/
4565{
4566 if (game.info.disasters == 0) {
4567 /* Shortcut out as no disaster is possible. */
4568 return;
4569 }
4570
4571 players_iterate(pplayer) {
4572 /* Safe city iterator needed as disaster may destroy city */
4573 city_list_iterate_safe(pplayer->cities, pcity) {
4574 int id = pcity->id;
4575
4577 if (city_exist(id)) {
4578 /* City survived earlier disasters. */
4579 int probability = game.info.disasters * pdis->frequency;
4580 int result = fc_rand(DISASTER_BASE_RARITY);
4581
4582 if (result < probability) {
4585 }
4586 }
4587 }
4591}
4592
4593/**********************************************************************/
4601static bool check_city_migrations_player(const struct player *pplayer)
4602{
4606 float score_from, score_tmp, weight;
4607 int dist, mgr_dist;
4608 bool internat = FALSE;
4609
4610 /* Check for each city
4611 * city_list_iterate_safe() must be used because we could
4612 * remove one city from the list */
4614 /* No migration out of the capital */
4615 if (is_capital(pcity)) {
4616 continue;
4617 }
4618
4619 /* Check only each (game.server.mgr_turninterval) turn
4620 * (counted from the funding turn) and do not migrate
4621 * the same turn a city is founded */
4622 if (game.info.turn == pcity->turn_founded
4623 || ((game.info.turn - pcity->turn_founded)
4624 % game.server.mgr_turninterval) != 0) {
4625 continue;
4626 }
4627
4630 best_city_player = nullptr;
4631 best_city_world = nullptr;
4632
4633 /* Score of the actual city
4634 * taking into account a persistence factor of 3 */
4636
4637 log_debug("[M] T%d check city: %s score: %6.3f (%s)",
4639 player_name(pplayer));
4640
4641 /* Consider all cities within the maximal possible distance
4642 * (= CITY_MAP_MAX_RADIUS + GAME_MAX_MGR_DISTANCE) */
4645 acity = tile_city(ptile);
4646
4647 if (!acity || acity == pcity) {
4648 /* No city or the city in the center */
4649 continue;
4650 }
4651
4652 /* Calculate the migration distance. The value of
4653 * game.server.mgr_distance is added to the current city radius. If the
4654 * distance between both cities is lower or equal than this value,
4655 * migration is possible. */
4658
4659 /* distance between the two cities */
4661
4662 if (dist > mgr_dist) {
4663 /* Too far away */
4664 continue;
4665 }
4666
4667 /* Score of the second city, weighted by the distance */
4668 weight = ((float) (mgr_dist + 1 - dist) / (float) (mgr_dist + 1));
4670
4671 log_debug("[M] T%d - compare city: %s (%s) dist: %d mgr_dist: %d "
4672 "score: %6.3f", game.info.turn, city_name_get(acity),
4674
4675 if (game.server.mgr_nationchance > 0 && city_owner(acity) == pplayer) {
4676 /* Migration between cities of the same owner */
4678 /* Select the best! */
4681
4682 log_debug("[M] T%d - best city (player): %s (%s) score: "
4683 "%6.3f (> %6.3f)", game.info.turn,
4686 }
4687 } else if (game.server.mgr_worldchance > 0
4688 && city_owner(acity) != pplayer) {
4689 /* Migration between cities of different owners */
4691 /* Modify the score if citizens could migrate to a city of their
4692 * original nation. */
4693 if (citizens_nation_get(pcity, city_owner(acity)->slot) > 0) {
4694 score_tmp *= 2;
4695 }
4696 }
4697
4699 /* Select the best! */
4702
4703 log_debug("[M] T%d - best city (world): %s (%s) score: "
4704 "%6.3f (> %6.3f)", game.info.turn,
4708 }
4709 }
4711
4712 if (best_city_player != nullptr) {
4713 /* First, do the migration within one nation */
4714 if (fc_rand(100) >= game.server.mgr_nationchance) {
4715 /* No migration */
4716 /* N.B.: city_link() always returns the same pointer. */
4719 _("Citizens of %s are thinking about migrating to %s "
4720 "for a better life."),
4722 } else {
4724 }
4725
4726 /* Stop here */
4727 continue;
4728 }
4729
4730 if (best_city_world != nullptr) {
4731 /* Second, do the migration between all nations */
4732 if (fc_rand(100) >= game.server.mgr_worldchance) {
4733 const char *nname;
4734
4736 /* No migration */
4737 /* N.B.: city_link() always returns the same pointer. */
4740 /* TRANS: <city1> to <city2> (<city2 nation adjective>). */
4741 _("Citizens of %s are thinking about migrating to %s "
4742 "(%s) for a better life."),
4744 } else {
4746 internat = TRUE;
4747 }
4748
4749 /* Stop here */
4750 continue;
4751 }
4753
4754 return internat;
4755}
4756
4757/**********************************************************************/
4761{
4762 pcity->style = city_style(pcity);
4763}
4764
4765/**********************************************************************/
4770{
4772 struct packet_city_update_counters packet;
4773
4774 packet.city = pcity->id;
4775
4777
4778 packet.count = counter_count;
4779 for (i = 0; i < counter_count; i++) {
4780 packet.counters[i] = pcity->counter_values[i];
4781 }
4782
4785}
4786
4787/**********************************************************************/
4790void city_tc_effect_refresh(struct player *pplayer)
4791{
4792 const struct civ_map *nmap = &(wld.map);
4793
4794 city_list_iterate(pplayer->cities, pcity) {
4795 bool changed = FALSE;
4796
4798 city_tile(pcity), ptile, idx, x, y) {
4799 if (ptile->worked == pcity
4800 && get_city_tile_output_bonus(pcity, ptile, nullptr,
4801 EFT_TILE_WORKABLE) <= 0) {
4803 pcity->specialists[DEFAULT_SPECIALIST]++;
4804 changed = TRUE;
4805 }
4807
4808 if (changed) {
4810 send_city_info(nullptr, pcity);
4811 }
4813}
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
struct player * citizens_unit_nationality(const struct city *pcity, int pop_cost, struct citizens_reduction *pchange)
void citizens_reduction_apply(struct city *pcity, const 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:663
int city_granary_size(int city_size)
Definition city.c:2132
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:1240
bool is_capital(const struct city *pcity)
Definition city.c:1579
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3411
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1255
int city_airlift_max(const struct city *pcity)
Definition city.c:2942
struct output_type * get_output_type(Output_type_id output)
Definition city.c:638
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3428
void city_size_add(struct city *pcity, int add)
Definition city.c:1164
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:727
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:804
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
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:1653
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:820
bool city_unhappy(const struct city *pcity)
Definition city.c:1626
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3374
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1679
bool city_celebrating(const struct city *pcity)
Definition city.c:1645
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:830
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2870
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2012
void city_refresh_from_main_map(const struct civ_map *nmap, struct city *pcity, bool *workers_map)
Definition city.c:3201
bool city_happy(const struct city *pcity)
Definition city.c:1614
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:1283
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:903
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1013
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:947
int city_map_tiles(int city_radius_sq)
Definition city.c:171
bool city_exist(int id)
Definition city.c:3612
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:747
void city_rally_point_clear(struct city *pcity)
Definition city.c:3666
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:871
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2923
bool city_can_change_build(const struct city *pcity)
Definition city.c:1079
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:970
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1222
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1201
#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:564
#define cities_iterate(pcity)
Definition city.h:512
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#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:846
#define INCITE_IMPOSSIBLE_COST
Definition city.h:94
#define city_owner(_pcity_)
Definition city.h:563
#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:835
#define city_built_iterate_end
Definition city.h:841
#define output_type_iterate_end
Definition city.h:852
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:3935
static void uk_rem_gold_append(struct unit *punit)
Definition cityturn.c:3249
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:2325
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:3149
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:4443
static bool city_distribute_surplus_shields(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2680
static void unit_list_referred_destroy(struct unit_list *punitlist)
Definition cityturn.c:3262
static bool place_pollution(struct city *pcity, enum extra_cause cause)
Definition cityturn.c:3547
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2543
static void uk_rem_gold_callback(struct unit *punit)
Definition cityturn.c:3228
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:3465
static void update_city_activity(struct city *pcity)
Definition cityturn.c:3724
static void upgrade_unit_prod(struct city *pcity)
Definition cityturn.c:2656
static float city_migration_score(struct city *pcity)
Definition cityturn.c:4060
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3715
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4421
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:4389
static void upgrade_building_prod(struct city *pcity)
Definition cityturn.c:2609
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3368
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:3684
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:4769
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:2761
static struct unit static const struct impr_type * building_upgrades_to(struct city *pcity, const struct impr_type *pimprove)
Definition cityturn.c:2588
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:3285
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3603
static void nullify_caravan_and_disband_plus(struct city *pcity)
Definition cityturn.c:3705
static bool sell_random_building(struct player *pplayer, struct cityimpr_list *imprs)
Definition cityturn.c:3182
static bool disband_city(struct city *pcity)
Definition cityturn.c:3948
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:3431
void city_style_refresh(struct city *pcity)
Definition cityturn.c:4760
static bool city_balance_treasury_units(struct city *pcity)
Definition cityturn.c:3512
static const struct unit_type * unit_upgrades_to(struct city *pcity, const struct unit_type *id)
Definition cityturn.c:2634
static bool do_city_migration(struct city *pcity_from, struct city *pcity_to)
Definition cityturn.c:4144
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:4790
static void check_pollution(struct city *pcity)
Definition cityturn.c:3586
void check_disasters(void)
Definition cityturn.c:4564
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:2922
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:4601
static bool city_build_unit(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2983
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:157
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:1180
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:912
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:364
#define iterate_outward_end
Definition map.h:368
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:41
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:241
const char * style_name_translation(const struct nation_style *pstyle)
Definition style.c:99
#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:300
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
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