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 "traderoutes.h"
58#include "unit.h"
59#include "unitlist.h"
60
61/* common/scriptcore */
62#include "luascript_types.h"
63
64/* server */
65#include "citizenshand.h"
66#include "citytools.h"
67#include "cityturn.h"
68#include "maphand.h"
69#include "notify.h"
70#include "plrhand.h"
71#include "sanitycheck.h"
72#include "spacerace.h"
73#include "srv_log.h"
74#include "srv_main.h"
75#include "techtools.h"
76#include "unittools.h"
77#include "unithand.h"
78
79/* server/advisors */
80#include "advbuilding.h"
81#include "advdata.h"
82
83/* server/scripting */
84#include "script_server.h"
85
86/* Queue for pending city_refresh() */
87static struct city_list *city_refresh_queue = nullptr;
88
89/* The game is currently considering to remove the listed units because of
90 * missing gold upkeep. A unit ends up here if it has gold upkeep that
91 * can't be paid. A random unit in the list will be removed until the
92 * problem is solved. */
93static struct unit_list *uk_rem_gold = nullptr;
94
95static void check_pollution(struct city *pcity);
96static void city_populate(struct city *pcity, struct player *nationality);
97
98static bool worklist_change_build_target(struct player *pplayer,
99 struct city *pcity);
100
101static bool city_distribute_surplus_shields(struct player *pplayer,
102 struct city *pcity);
103static bool city_build_building(struct player *pplayer, struct city *pcity);
104static bool city_build_unit(struct player *pplayer, struct city *pcity);
105static bool city_build_stuff(struct player *pplayer, struct city *pcity);
106static struct unit *city_create_unit(struct city *pcity,
107 const struct unit_type *utype,
108 struct citizens_reduction *red)
109 fc__attribute((nonnull (1, 2)));
110static const struct impr_type *building_upgrades_to(struct city *pcity,
111 const struct impr_type *pimprove);
112static void upgrade_building_prod(struct city *pcity);
113static const struct unit_type *unit_upgrades_to(struct city *pcity,
114 const struct unit_type *id);
115static void upgrade_unit_prod(struct city *pcity);
116
117/* Helper struct for associating a building to a city. */
118struct cityimpr {
119 struct city *pcity;
121};
122
123#define SPECLIST_TAG cityimpr
124#define SPECLIST_TYPE struct cityimpr
125#include "speclist.h"
126
127#define cityimpr_list_iterate(cityimprlist, pcityimpr) \
128 TYPED_LIST_ITERATE(struct cityimpr, cityimprlist, pcityimpr)
129#define cityimpr_list_iterate_end LIST_ITERATE_END
130
131static bool sell_random_building(struct player *pplayer,
132 struct cityimpr_list *imprs);
133static struct unit *sell_random_unit(struct player *pplayer,
134 struct unit_list *punitlist);
135
136static citizens city_reduce_specialists(struct city *pcity, citizens change);
137static citizens city_reduce_workers(struct city *pcity, citizens change);
138
139static bool city_balance_treasury_buildings(struct city *pcity);
140static bool city_balance_treasury_units(struct city *pcity);
141
142static bool disband_city(struct city *pcity);
143
144static void define_orig_production_values(struct city *pcity);
145static void update_city_activity(struct city *pcity);
146static void nullify_caravan_and_disband_plus(struct city *pcity);
147static bool city_illness_check(const struct city * pcity);
148
149static float city_migration_score(struct city *pcity);
150static bool do_city_migration(struct city *pcity_from,
151 struct city *pcity_to);
152static bool check_city_migrations_player(const struct player *pplayer);
153
154/**********************************************************************/
159{
160 bool retval;
161 const struct civ_map *nmap = &(wld.map);
162
163 pcity->server.needs_refresh = FALSE;
164
166 city_units_upkeep(pcity); /* Update unit upkeep */
169
170 if (retval) {
171 /* Force a sync of the city after the change. */
173 }
174
175 return retval;
176}
177
178/**********************************************************************/
182void city_refresh_for_player(struct player *pplayer)
183{
185 city_list_iterate(pplayer->cities, pcity) {
186 if (city_refresh(pcity)) {
188 }
189 send_city_info(pplayer, pcity);
192}
193
194/**********************************************************************/
198{
199 if (city_refresh_queue == nullptr) {
202 return;
203 }
204
206 pcity->server.needs_refresh = TRUE;
207}
208
209/**********************************************************************/
214{
215 if (city_refresh_queue == nullptr) {
216 return;
217 }
218
220 if (pcity->server.needs_refresh) {
221 if (city_refresh(pcity)) {
223 }
225 }
227
229 city_refresh_queue = nullptr;
230}
231
232/**********************************************************************/
235void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
236{
237 struct player *pplayer = city_owner(pcity);
238 bool sold = FALSE;
239
240 city_built_iterate(pcity, pimprove) {
241 if (improvement_obsolete(pplayer, pimprove, pcity)
242 && can_city_sell_building(pcity, pimprove)) {
243 int sgold;
244
245 do_sell_building(pplayer, pcity, pimprove, "obsolete");
246 sgold = impr_sell_gold(pimprove);
248 PL_("%s is selling %s (obsolete) for %d.",
249 "%s is selling %s (obsolete) for %d.",
250 sgold),
253 sgold);
254 sold = TRUE;
255 }
257
258 if (sold && refresh) {
259 if (city_refresh(pcity)) {
261 }
262 send_city_info(pplayer, pcity);
263 send_player_info_c(pplayer, nullptr); /* Send updated gold to all */
264 }
265}
266
267/**********************************************************************/
276
277/**********************************************************************/
282 const struct cm_result *cmr)
283{
284 struct tile *pcenter = city_tile(pcity);
285 const struct civ_map *nmap = &(wld.map);
286
287 /* Now apply results */
289 ptile, idx, x, y) {
290 struct city *pwork = tile_worked(ptile);
291
292 if (cmr->worker_positions[idx]) {
293 if (pwork == nullptr) {
295 } else {
297 }
298 } else {
299 if (pwork == pcity) {
301 }
302 }
304
306 pcity->specialists[sp] = cmr->specialists[sp];
308}
309
310/**********************************************************************/
314 struct city *pcity)
315{
318
319 cmp->require_happy = FALSE;
320 cmp->allow_disorder = FALSE;
321 cmp->allow_specialists = TRUE;
322
323 /* We used to look at pplayer->ai.xxx_priority to determine the values
324 * to be used here. However that doesn't work at all because those values
325 * are on a different scale. Later the AI may wish to adjust its
326 * priorities - this should be done via a separate set of variables. */
327 if (csize > 1) {
328 if (csize <= game.info.notradesize) {
329 cmp->factor[O_FOOD] = 15;
330 } else {
331 if (gsize == pcity->food_stock) {
332 /* We don't need more food if the granary is full. */
333 cmp->factor[O_FOOD] = 0;
334 } else {
335 cmp->factor[O_FOOD] = 10;
336 }
337 }
338 } else {
339 /* Growing to size 2 is the highest priority. */
340 cmp->factor[O_FOOD] = 20;
341 }
342
343 cmp->factor[O_SHIELD] = 5;
344 cmp->factor[O_TRADE] = 0; /* Trade only provides gold/science. */
345 cmp->factor[O_GOLD] = 2;
346 cmp->factor[O_LUXURY] = 0; /* Luxury only influences happiness. */
347 cmp->factor[O_SCIENCE] = 2;
348 cmp->happy_factor = 0;
349
350 if (gsize == pcity->food_stock) {
351 cmp->minimal_surplus[O_FOOD] = 0;
352 } else {
353 cmp->minimal_surplus[O_FOOD] = 1;
354 }
355
356 cmp->minimal_surplus[O_SHIELD] = 1;
357 cmp->minimal_surplus[O_TRADE] = 0;
358 cmp->minimal_surplus[O_GOLD] = -FC_INFINITY;
359 cmp->minimal_surplus[O_LUXURY] = 0;
360 cmp->minimal_surplus[O_SCIENCE] = 0;
361}
362
363/**********************************************************************/
367{
368 struct cm_parameter cmp;
369 struct cm_parameter *pcmp;
370 struct cm_result *cmr;
371 bool broadcast_needed;
372
373 /* See comment in freeze_workers(): we can't rearrange while
374 * workers are frozen (i.e. multiple updates need to be done). */
375 if (pcity->server.workers_frozen > 0) {
376 if (pcity->server.needs_arrange == CNA_NOT) {
377 pcity->server.needs_arrange = CNA_NORMAL;
378 }
379 return;
380 }
382
384
385 /* Freeze the workers and make sure all the tiles around the city
386 * are up to date. Then thaw, but hackishly make sure that thaw
387 * doesn't call us recursively, which would waste time. */
389 pcity->server.needs_arrange = CNA_NOT;
390
392
393 pcity->server.needs_arrange = CNA_NOT;
395
396 /* Now start actually rearranging. */
398
401
402 if (pcity->cm_parameter) {
403 pcmp = pcity->cm_parameter;
404 } else {
405 pcmp = &cmp;
408 }
409
410 /* This must be after city_refresh() so that the result gets created for the right
411 * city radius */
414
415 if (!cmr->found_a_valid) {
416 if (pcity->cm_parameter) {
417 /* If player-defined parameters fail, cancel and notify player. */
418 free(pcity->cm_parameter);
419 pcity->cm_parameter = nullptr;
420
423 _("The citizen governor can't fulfill the requirements "
424 "for %s. Passing back control."),
426
427 /* Switch to default parameters, and try with them */
428 pcmp = &cmp;
432 }
433
434 if (!cmr->found_a_valid) {
435 /* Drop surpluses and try again. */
437 cmp.minimal_surplus[o] = 0;
439 cmp.minimal_surplus[O_GOLD] = -FC_INFINITY;
441 }
442 }
443 if (!cmr->found_a_valid) {
444 /* Emergency management. Get _some_ result. This doesn't use
445 * cm_init_emergency_parameter() so we can keep the factors from
446 * above. */
448 cmp.minimal_surplus[o] = MIN(cmp.minimal_surplus[o],
449 MIN(pcity->surplus[o], 0));
451 cmp.require_happy = FALSE;
452 cmp.allow_disorder = is_ai(city_owner(pcity)) ? FALSE : TRUE;
454 }
455 if (!cmr->found_a_valid) {
456 CITY_LOG(LOG_DEBUG, pcity, "emergency management");
457 pcmp = &cmp;
460 }
461 fc_assert_ret(cmr->found_a_valid);
462
464
465 if (pcity->server.debug) {
466 /* Print debug output if requested. */
469 }
470
471 if (city_refresh(pcity)) {
472 log_error("%s radius changed when already arranged workers.",
474 /* Can't do anything - don't want to enter infinite recursive loop
475 * by trying to arrange workers more. */
476 }
478
479 if (broadcast_needed) {
481 }
482
485}
486
487/**********************************************************************/
490static void city_global_turn_notify(struct conn_list *dest)
491{
493 const struct impr_type *pimprove = pcity->production.value.building;
494
495 if (VUT_IMPROVEMENT == pcity->production.kind
496 && is_great_wonder(pimprove)
498 && can_city_build_improvement_now(pcity, pimprove))) {
501 _("Notice: Wonder %s in %s will be finished next turn."),
503 }
505}
506
507/**********************************************************************/
511static void city_turn_notify(const struct city *pcity,
512 struct conn_list *dest,
513 const struct player *cache_for_player)
514{
515 const struct impr_type *pimprove = pcity->production.value.building;
516 struct packet_chat_msg packet;
518
519 if (0 < pcity->surplus[O_FOOD]) {
521 - pcity->food_stock - 1) / pcity->surplus[O_FOOD];
522
526 && 0 < pcity->surplus[O_SHIELD]) {
527 /* From the check above, the surplus must always be positive. */
529 - pcity->shield_stock) / pcity->surplus[O_SHIELD];
530 /* If growth and granary completion occur simultaneously, granary
531 * preserves food. -AJS. */
532 if (5 > turns_growth && 5 > turns_granary
534 package_event(&packet, city_tile(pcity),
536 _("Suggest throttling growth in %s to use %s "
537 "(being built) more effectively."),
540 lsend_packet_chat_msg(dest, &packet);
541 if (cache_for_player != nullptr) {
543 }
544 }
545 }
546
549 package_event(&packet, city_tile(pcity),
551 _("%s may soon grow to size %i."),
553 lsend_packet_chat_msg(dest, &packet);
554 if (cache_for_player != nullptr) {
556 }
557 }
558 } else {
559 if (0 >= pcity->food_stock + pcity->surplus[O_FOOD]
560 && 0 > pcity->surplus[O_FOOD]) {
561 package_event(&packet, city_tile(pcity),
563 _("Warning: Famine feared in %s."), city_link(pcity));
564 lsend_packet_chat_msg(dest, &packet);
565 if (cache_for_player != nullptr) {
567 }
568 }
569 }
570}
571
572/**********************************************************************/
577{
578 if (pconn != nullptr) {
579 struct player *pplayer = conn_get_player(pconn);
580
581 if (pplayer != nullptr) {
582 city_list_iterate(pplayer->cities, pcity) {
583 city_turn_notify(pcity, pconn->self, nullptr);
585 }
587 } else {
588 players_iterate(pplayer) {
589 city_list_iterate(pplayer->cities, pcity) {
590 city_turn_notify(pcity, pplayer->connections, pplayer);
593 /* NB: notifications to 'game.est_connections' are automatically
594 * cached. */
596 }
597}
598
599/**********************************************************************/
602void update_city_activities(struct player *pplayer)
603{
604 int n;
605
606 fc_assert(pplayer->cities != nullptr);
607
608 n = city_list_size(pplayer->cities);
609
610 if (n > 0) {
611 struct city *cities[n];
612 int i = 0, r;
613
614 city_list_iterate(pplayer->cities, pcity) {
615
617
618 /* Cancel trade routes that cannot exist any more */
620 struct city *tcity = game_city_by_number(proute->partner);
621
622 if (tcity != nullptr) {
623 bool cancel = FALSE;
624
625 if (proute->dir != RDIR_FROM && goods_has_flag(proute->goods, GF_DEPLETES)
626 && !goods_can_be_provided(tcity, proute->goods, nullptr)) {
627 cancel = TRUE;
628 }
629 if (!cancel && !can_cities_trade(pcity, tcity)) {
632
633 if (settings->cancelling == TRI_CANCEL) {
634 cancel = TRUE;
635 }
636 }
637
638 if (cancel) {
639 struct trade_route *back;
640
642 free(proute);
643 free(back);
644 }
645 }
647
648 /* Add cities to array for later random order handling */
649 cities[i++] = pcity;
651
652 /* How gold upkeep is handled depends on the setting
653 * 'game.info.gold_upkeep_style':
654 * GOLD_UPKEEP_CITY: Each city tries to balance its upkeep individually
655 * (this is done in update_city_activity()).
656 * GOLD_UPKEEP_MIXED: Each city tries to balance its upkeep for
657 * buildings individually; the upkeep for units is
658 * paid by the nation.
659 * GOLD_UPKEEP_NATION: The nation as a whole balances the treasury. If
660 * the treasury is not balance units and buildings
661 * are sold. */
662
663 /* Iterate over cities in a random order. */
664 while (i > 0) {
665 r = fc_rand(i);
666 /* update unit upkeep */
669 cities[r] = cities[--i];
670 }
671 }
672}
673
674/**********************************************************************/
688 bool wipe_in_the_end)
689{
690 int punit_id;
691
693 nullptr, get_output_type(outp), nullptr)) {
694 /* Can't get rid of this unit. It is undisbandable for the current
695 * situation. */
696 return FALSE;
697 }
698
699 punit_id = punit->id;
700
701 /* Try to perform this unit's can't upkeep actions. */
703 nullptr, get_output_type(outp), nullptr,
704 nullptr, nullptr, nullptr, nullptr);
705
707 /* No forced action was able to kill the unit. Finish the job. */
708 wipe_unit(punit, wipe_reason, nullptr);
709 }
710
711 return !unit_is_alive(punit_id);
712}
713
714/**********************************************************************/
719{
720 citizens want = change;
721
722 fc_assert_ret_val(0 < change, 0);
723
725 citizens fix = MIN(want, pcity->specialists[sp]);
726
727 pcity->specialists[sp] -= fix;
728 want -= fix;
730
731 return change - want;
732}
733
734/**********************************************************************/
739{
740 struct tile *pcenter = city_tile(pcity);
741 int want = change;
742 const struct civ_map *nmap = &(wld.map);
743
744 fc_assert_ret_val(0 < change, 0);
745
747 ptile, _index, _x, _y) {
748 if (0 < want && tile_worked(ptile) == pcity) {
750 want--;
751 }
753
754 return change - want;
755}
756
757/**********************************************************************/
763 struct player *destroyer, const char *reason)
764{
766 int old_radius_sq;
767
768 if (pop_loss == 0) {
769 return TRUE;
770 }
771
772 if (city_size_get(pcity) <= pop_loss) {
773 int id = pcity->id;
774
775 citizens_update(pcity, nullptr); /* To avoid warnings during the script */
776 /* Won't refresh a doomed city, or should we? */
777 script_server_signal_emit("city_destroyed", pcity, pcity->owner,
778 destroyer);
779
780 if (city_exist(id)) {
782 }
783 return FALSE;
784 }
789
790 /* Cap the food stock at the new granary size. */
791 if (pcity->food_stock > city_granary_size(city_size_get(pcity))) {
793 }
794
795 /* First try to kill off the specialists */
797
798 if (loss_remain > 0) {
799 /* Take it out on workers */
800#ifndef FREECIV_NDEBUG
801 loss_remain -=
802#endif /* FREECIV_NDEBUG */
804 }
805
806 /* Update citizens. */
807 citizens_update(pcity, nullptr);
808
809 /* Update number of people in each feelings category.
810 * This also updates the city radius if needed. */
812
814
815 /* Send city data. */
816 sync_cities();
817
819 "city_reduce_size() has remaining"
820 "%d of %d for \"%s\"[%d]",
823
824 /* Update cities that have trade routes with us */
826 if (city_refresh(pcity2)) {
827 /* This should never happen, but if it does, make sure not to
828 * leave workers outside city radius. */
830 }
832
834
835 if (reason != nullptr) {
836 int id = pcity->id;
837
838 script_server_signal_emit("city_size_change", pcity,
840
841 return city_exist(id);
842 }
843
844 return TRUE;
845}
846
847/**********************************************************************/
851void city_repair_size(struct city *pcity, int change)
852{
853 if (change > 0) {
854 pcity->specialists[DEFAULT_SPECIALIST] += change;
855 } else if (change < 0) {
856 int need = change + city_reduce_specialists(pcity, -change);
857
858 if (0 > need) {
859#ifndef FREECIV_NDEBUG
860 need +=
861#endif /* FREECIV_NDEBUG */
863 }
864
865 fc_assert_msg(0 == need,
866 "city_repair_size() has remaining %d of %d for \"%s\"[%d]",
868 }
869}
870
871/**********************************************************************/
879{
881
882 return CLIP(0, savings, 100);
883}
884
885/**********************************************************************/
893{
895
896 return CLIP(0, savings, 100);
897}
898
899/**********************************************************************/
906{
908
909 pcity->food_stock = (city_granary_size(new_size) * savings_pct) / 100;
910}
911
912/**********************************************************************/
918static bool city_increase_size(struct city *pcity, bool natural_growth,
920{
921 int new_food;
923 bool have_square = FALSE;
924 bool rapture_grow = city_rapture_grow(pcity); /* Check before size increase! */
925 struct tile *pcenter = city_tile(pcity);
926 struct player *powner = city_owner(pcity);
927 const struct impr_type *pimprove = pcity->production.value.building;
928 const struct civ_map *nmap = &(wld.map);
929
931 /* Need improvement */
935 _("%s needs %s (being built) to grow beyond size %d."),
939 } else {
941 _("%s needs an improvement to grow beyond size %d."),
943 }
944 /* Granary can only hold so much */
946 * (100 * 100 - game.server.aqueductloss * (100 - savings_pct))
947 / (100 * 100));
948 pcity->food_stock = MIN(pcity->food_stock, new_food);
949
950 return FALSE;
951 }
952
953 if (natural_growth) {
954 /* Growth by filled foodbox */
955 int stock;
956 int granary;
957
959 if (pcity->food_stock <= granary) {
960 stock = 0;
961 } else {
962 stock = pcity->food_stock - granary;
963 }
964
966
967 /* Do not empty food stock if city is growing by celebrating */
968 if (rapture_grow) {
970 } else {
972 }
973
974 /* Never increase amount of food in the foodbox */
975 pcity->food_stock = MIN(pcity->food_stock, new_food);
976 } else {
977 /* Growth by means like add-to-city or population migration */
979
981
982 /* Preserve old food stock, unless granary effect gives us more. */
983 pcity->food_stock = MAX(pcity->food_stock, new_food);
984 }
985
986 if (sid >= 0) {
988 pcity->specialists[sid]++;
989 } else {
990 /* If there is enough food, and the city is big enough,
991 * make new citizens into scientists or taxmen -- Massimo */
992
993 /* Ignore food if no square can be worked */
995 ptile, _index, _x, _y) {
996 if (tile_worked(ptile) != pcity /* Quick test */
997 && city_can_work_tile(pcity, ptile)) {
999 }
1001
1002 if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1004 pcity->specialists[best_specialist(O_SCIENCE, pcity)]++;
1005 } else if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1007 pcity->specialists[best_specialist(O_GOLD, pcity)]++;
1008 } else {
1009 pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
1010 }
1011 }
1012
1013 /* Deprecated signal. Connect your lua functions to "city_size_change" that's
1014 * emitted from calling functions which know the 'reason' of the increase. */
1015 script_server_signal_emit("city_growth", pcity,
1017
1018 return TRUE;
1019}
1020
1021/**********************************************************************/
1027 struct player *nationality,
1028 bool aaw)
1029{
1030 struct player *powner = city_owner(pcity);
1031
1032 /* Update citizens. */
1033 citizens_update(pcity, nationality);
1034
1035 /* Refresh the city data; this also checks the squared city radius. */
1037
1038 if (aaw) {
1040 }
1041
1042 /* Update cities that have trade routes with us */
1044 if (city_refresh(pcity2)) {
1045 /* This should never happen, but if it does, make sure not to
1046 * leave workers outside city radius. */
1048 }
1050
1052 _("%s grows to size %d."),
1054
1056
1057 sync_cities();
1058}
1059
1060/**********************************************************************/
1068 struct player *nationality,
1069 Specialist_type_id sid, const char *reason)
1070{
1071 int change = size - city_size_get(pcity);
1072
1073 if (change > 0) {
1075 int real_change;
1077 int id = pcity->id;
1078
1079 /* Increase city size until size reached, or increase fails */
1081 /* TODO: This is currently needed only because there's
1082 * deprecated script signal "city_growth" emitted.
1083 * Check the need after signal has been dropped completely. */
1084 if (!city_exist(id)) {
1085 return FALSE;
1086 }
1087
1088 current_size++;
1089 }
1090
1092
1094
1095 if (real_change != 0 && reason != nullptr) {
1096 script_server_signal_emit("city_size_change", pcity,
1098
1099 if (!city_exist(id)) {
1100 return FALSE;
1101 }
1102 }
1103 } else if (change < 0) {
1104 /* We assume that city_change_size() is never called because
1105 * of enemy actions. If that changes, enemy must be passed
1106 * to city_reduce_size() */
1107 return city_reduce_size(pcity, -change, nullptr, reason);
1108 }
1109
1111
1112 return TRUE;
1113}
1114
1115/**********************************************************************/
1119static void city_populate(struct city *pcity, struct player *nationality)
1120{
1121 int saved_id = pcity->id;
1122 int granary_size = city_granary_size(city_size_get(pcity));
1123
1124 pcity->food_stock += pcity->surplus[O_FOOD];
1125 if (pcity->food_stock >= granary_size || city_rapture_grow(pcity)) {
1129 _("A recent plague outbreak prevents growth in %s."),
1130 city_link(pcity));
1131 /* Lose excess food */
1132 pcity->food_stock = MIN(pcity->food_stock, granary_size);
1133 } else {
1134 bool success;
1135
1138
1139 if (success) {
1141 script_server_signal_emit("city_size_change", pcity,
1142 (lua_Integer)1, "growth");
1143 }
1144 }
1145 } else if (pcity->food_stock < 0) {
1146 /* FIXME: should this depend on units with ability to build
1147 * cities or on units that require food in upkeep?
1148 * I'll assume citybuilders (units that 'contain' 1 pop) -- sjolie
1149 * The above may make more logical sense, but in game terms
1150 * you want to disband a unit that is draining your food
1151 * reserves. Hence, I'll assume food upkeep > 0 units. -- jjm
1152 */
1153 unit_list_iterate_safe(pcity->units_supported, punit) {
1154 if (punit->upkeep[O_FOOD] > 0) {
1155 const char *punit_link = unit_tile_link(punit);
1156
1161 _("Famine feared in %s, %s lost!"),
1163 }
1164
1165 if (city_exist(saved_id)) {
1167 }
1168
1169 return;
1170 }
1172 if (city_size_get(pcity) > 1) {
1175 _("Famine causes population loss in %s."),
1176 city_link(pcity));
1177 } else {
1180 _("Famine destroys %s entirely."),
1181 city_link(pcity));
1182 }
1184 if (city_reduce_size(pcity, 1, nullptr, "famine")) {
1185 pcity->had_famine = TRUE;
1186 }
1187 }
1188}
1189
1190/**********************************************************************/
1197 struct city *pcity,
1198 struct player *pplayer,
1199 int saved_id)
1200{
1201 const void *ptarget;
1202 const char *tgt_name;
1203 const struct requirement_vector *build_reqs;
1204 const char *signal_name;
1205 const struct req_context city_ctxt = {
1206 .player = pplayer,
1207 .city = pcity,
1208 .tile = city_tile(pcity)
1209 /* FIXME: Setting .unittype is currently redundant,
1210 * but can_city_build_unit_direct() does it */
1211 };
1212 bool purge = FALSE;
1213 bool known = FALSE;
1214
1215 if (pcity->wlcb == WLCB_ALWAYS_PURGE) {
1216 return TRUE;
1217 }
1218
1219 switch (target->kind) {
1220 case VUT_UTYPE:
1221 ptarget = target->value.utype;
1222 build_reqs = &target->value.utype->build_reqs;
1224 signal_name = "unit_cant_be_built";
1225 break;
1226 case VUT_IMPROVEMENT:
1227 ptarget = target->value.building;
1228 build_reqs = &target->value.building->reqs;
1230 signal_name = "building_cant_be_built";
1231 break;
1232 default:
1234 || target->kind == VUT_UTYPE), FALSE);
1235 return FALSE;
1236 }
1237
1238 if (pcity->wlcb == WLCB_ALWAYS_POSTPONE) {
1239 notify_player(pplayer, city_tile(pcity),
1241 _("%s can't build %s from the worklist. "
1242 "Postponing..."),
1244 tgt_name);
1245 return FALSE;
1246 }
1247
1248 requirement_vector_iterate(build_reqs, preq) {
1249 if (!is_req_active(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
1250 known = TRUE;
1251 switch (preq->source.kind) {
1252 case VUT_COUNTER:
1253 if (preq->present) {
1254 notify_player(pplayer, city_tile(pcity),
1256 _("%s can't build %s from the worklist; "
1257 "counter %s value's checkpoint do not met "
1258 "Postponing..."),
1260 tgt_name,
1262 (preq->source.value.counter));
1263 } else {
1264 purge = TRUE;
1265 }
1266 break;
1267 case VUT_ADVANCE:
1268 if (preq->present) {
1269 notify_player(pplayer, city_tile(pcity),
1271 _("%s can't build %s from the worklist; "
1272 "tech %s not yet available. Postponing..."),
1274 tgt_name,
1276 (preq->source.value.advance));
1278 pcity, "need_tech");
1279 } else {
1280 /* While techs can be unlearned, this isn't useful feedback */
1281 purge = TRUE;
1282 }
1283 break;
1284 case VUT_TECHFLAG:
1285 if (preq->present) {
1286 notify_player(pplayer, city_tile(pcity),
1288 _("%s can't build %s from the worklist; "
1289 "no tech with flag \"%s\" yet available. "
1290 "Postponing..."),
1292 tgt_name,
1293 tech_flag_id_name(preq->source.value.techflag));
1295 pcity, "need_techflag");
1296 } else {
1297 /* While techs can be unlearned, this isn't useful feedback */
1298 purge = TRUE;
1299 }
1300 break;
1301 case VUT_IMPROVEMENT:
1302 case VUT_SITE:
1303 if (preq->range == REQ_RANGE_LOCAL) {
1304 /* Building itself is never going to change */
1305 purge = TRUE;
1306 } else {
1307 if (preq->present) {
1308 notify_player(pplayer, city_tile(pcity),
1310 _("%s can't build %s from the worklist; "
1311 "need to have %s first. Postponing..."),
1313 tgt_name,
1315 preq->source.value.building));
1317 pcity, "need_building");
1318 } else {
1319 notify_player(pplayer, city_tile(pcity),
1321 _("%s can't build %s from the worklist; "
1322 "need to not have %s. Postponing..."),
1324 tgt_name,
1326 preq->source.value.building));
1328 pcity, "have_building");
1329 }
1330 }
1331 break;
1332 case VUT_IMPR_GENUS:
1333 if (preq->range == REQ_RANGE_LOCAL) {
1334 /* Building's own genus is never going to change */
1335 purge = TRUE;
1336 } else {
1337 if (preq->present) {
1338 notify_player(pplayer, city_tile(pcity),
1340 _("%s can't build %s from the worklist; "
1341 "need to have %s first. Postponing..."),
1343 tgt_name,
1345 preq->source.value.impr_genus));
1347 pcity, "need_building_genus");
1348 } else {
1349 notify_player(pplayer, city_tile(pcity),
1351 _("%s can't build %s from the worklist; "
1352 "need to not have %s. Postponing..."),
1354 tgt_name,
1356 preq->source.value.impr_genus));
1358 pcity, "have_building_genus");
1359 }
1360 }
1361 break;
1362 case VUT_IMPR_FLAG:
1363 if (preq->range == REQ_RANGE_LOCAL) {
1364 /* Building's own flags are never going to change */
1365 purge = TRUE;
1366 } else {
1367 if (preq->present) {
1368 notify_player(pplayer, city_tile(pcity),
1370 _("%s can't build %s from the worklist; "
1371 "need to have %s first. Postponing..."),
1373 tgt_name,
1375 preq->source.value.impr_flag));
1377 pcity, "need_building_flag");
1378 } else {
1379 notify_player(pplayer, city_tile(pcity),
1381 _("%s can't build %s from the worklist; "
1382 "need to not have %s. Postponing..."),
1384 tgt_name,
1386 preq->source.value.impr_flag));
1388 pcity, "have_building_flag");
1389 }
1390 }
1391 break;
1392 case VUT_PLAYER_FLAG:
1393 if (preq->present) {
1394 notify_player(pplayer, city_tile(pcity),
1396 _("%s can't build %s from the worklist; "
1397 "need to have %s first. Postponing..."),
1399 tgt_name,
1401 preq->source.value.plr_flag));
1403 pcity, "need_player_flag");
1404 } else {
1405 notify_player(pplayer, city_tile(pcity),
1407 _("%s can't build %s from the worklist; "
1408 "need to not have %s. Postponing..."),
1410 tgt_name,
1412 preq->source.value.plr_flag));
1414 pcity, "have_player_flag");
1415 }
1416 break;
1417 case VUT_PLAYER_STATE:
1418 purge = TRUE;
1419 break;
1420 case VUT_GOVERNMENT:
1421 if (preq->present) {
1422 notify_player(pplayer, city_tile(pcity),
1424 _("%s can't build %s from the worklist; "
1425 "it needs %s government. Postponing..."),
1427 tgt_name,
1428 government_name_translation(preq->source.value.govern));
1430 pcity, "need_government");
1431 } else {
1432 notify_player(pplayer, city_tile(pcity),
1434 _("%s can't build %s from the worklist; "
1435 "it cannot have %s government. Postponing..."),
1437 tgt_name,
1438 government_name_translation(preq->source.value.govern));
1440 pcity, "have_government");
1441 }
1442 break;
1443 case VUT_GOVFLAG:
1444 if (preq->present) {
1445 notify_player(pplayer, city_tile(pcity),
1447 _("%s can't build %s from the worklist; "
1448 "it needs %s government. Postponing..."),
1450 tgt_name,
1451 gov_flag_id_translated_name(preq->source.value.govflag));
1453 pcity, "need_govflag");
1454 } else {
1455 notify_player(pplayer, city_tile(pcity),
1457 _("%s can't build %s from the worklist; "
1458 "it cannot have %s government. Postponing..."),
1460 tgt_name,
1461 gov_flag_id_translated_name(preq->source.value.govflag));
1463 pcity, "have_govflag");
1464 }
1465 break;
1466 case VUT_ACHIEVEMENT:
1467 if (preq->present) {
1468 notify_player(pplayer, city_tile(pcity),
1470 _("%s can't build %s from the worklist; "
1471 "it needs \"%s\" achievement. Postponing..."),
1473 tgt_name,
1474 achievement_name_translation(preq->source.value.achievement));
1476 pcity, "need_achievement");
1477 } else {
1478 /* Can't unachieve things. */
1479 purge = TRUE;
1480 }
1481 break;
1482 case VUT_EXTRA:
1483 if (preq->present) {
1484 notify_player(pplayer, city_tile(pcity),
1486 Q_("?extra:%s can't build %s from the worklist; "
1487 "%s is required. Postponing..."),
1489 tgt_name,
1490 extra_name_translation(preq->source.value.extra));
1492 pcity, "need_extra");
1493 } else {
1494 notify_player(pplayer, city_tile(pcity),
1496 Q_("?extra:%s can't build %s from the worklist; "
1497 "%s is prohibited. Postponing..."),
1499 tgt_name,
1500 extra_name_translation(preq->source.value.extra));
1502 pcity, "have_extra");
1503 }
1504 break;
1505 case VUT_GOOD:
1506 if (preq->present) {
1507 notify_player(pplayer, city_tile(pcity),
1509 Q_("?extra:%s can't build %s from the worklist; "
1510 "%s is required. Postponing..."),
1512 tgt_name,
1513 goods_name_translation(preq->source.value.good));
1515 pcity, "need_good");
1516 } else {
1517 notify_player(pplayer, city_tile(pcity),
1519 Q_("?extra:%s can't build %s from the worklist; "
1520 "%s is prohibited. Postponing..."),
1522 tgt_name,
1523 goods_name_translation(preq->source.value.good));
1525 pcity, "have_good");
1526 }
1527 break;
1528 case VUT_TERRAIN:
1529 if (preq->present) {
1530 notify_player(pplayer, city_tile(pcity),
1532 Q_("?terrain:%s can't build %s from the worklist; "
1533 "%s terrain is required. Postponing..."),
1535 tgt_name,
1536 terrain_name_translation(preq->source.value.terrain));
1538 pcity, "need_terrain");
1539 } else {
1540 notify_player(pplayer, city_tile(pcity),
1542 Q_("?terrain:%s can't build %s from the worklist; "
1543 "%s terrain is prohibited. Postponing..."),
1545 tgt_name,
1546 terrain_name_translation(preq->source.value.terrain));
1548 pcity, "have_terrain");
1549 }
1550 break;
1551 case VUT_NATION:
1552 if (preq->range < REQ_RANGE_TRADE_ROUTE
1553 || preq->range == REQ_RANGE_PLAYER) {
1554 /* At higher ranges, new players with their nations may arrive */
1555 purge = TRUE;
1556 } else {
1557 if (preq->present) {
1558 notify_player(pplayer, city_tile(pcity),
1560 /* TRANS: "%s nation" is adjective */
1561 Q_("?nation:%s can't build %s from the worklist; "
1562 "%s nation is required. Postponing..."),
1564 tgt_name,
1565 nation_adjective_translation(preq->source.value.nation));
1567 pcity, "need_nation");
1568 } else {
1569 notify_player(pplayer, city_tile(pcity),
1571 Q_("?nation:%s can't build %s from the worklist; "
1572 "%s nation is prohibited. Postponing..."),
1574 tgt_name,
1575 nation_adjective_translation(preq->source.value.nation));
1577 pcity, "have_nation");
1578 }
1579 }
1580 break;
1581 case VUT_NATIONGROUP:
1582 if (preq->range < REQ_RANGE_TRADE_ROUTE
1583 || preq->range == REQ_RANGE_PLAYER) {
1584 /* At higher ranges, new players with their nations may arrive */
1585 purge = TRUE;
1586 } else {
1587 if (preq->present) {
1588 notify_player(pplayer, city_tile(pcity),
1590 /* TRANS: "%s nation" is adjective */
1591 Q_("?ngroup:%s can't build %s from the worklist; "
1592 "%s nation is required. Postponing..."),
1594 tgt_name,
1595 nation_group_name_translation(preq->source.value.nationgroup));
1597 pcity, "need_nationgroup");
1598 } else {
1599 notify_player(pplayer, city_tile(pcity),
1601 Q_("?ngroup:%s can't build %s from the worklist; "
1602 "%s nation is prohibited. Postponing..."),
1604 tgt_name,
1605 nation_group_name_translation(preq->source.value.nationgroup));
1607 pcity, "have_nationgroup");
1608 }
1609 }
1610 break;
1611 case VUT_STYLE:
1612 /* FIXME: City styles sometimes change over time, but it isn't
1613 * entirely under player control. Probably better to purge
1614 * with useful explanation. */
1615 if (preq->present) {
1616 notify_player(pplayer, city_tile(pcity),
1618 _("%s can't build %s from the worklist; "
1619 "only %s style cities may build this. Postponing..."),
1621 tgt_name,
1622 style_name_translation(preq->source.value.style));
1624 pcity, "need_style");
1625 } else {
1626 notify_player(pplayer, city_tile(pcity),
1628 _("%s can't build %s from the worklist; "
1629 "%s style cities may not build this. Postponing..."),
1631 tgt_name,
1632 style_name_translation(preq->source.value.style));
1634 pcity, "have_style");
1635 }
1636 break;
1637 case VUT_NATIONALITY:
1638 /* FIXME: Changing citizen nationality is hard: purging might be
1639 * more useful in this case. */
1640 if (preq->present) {
1641 notify_player(pplayer, city_tile(pcity),
1643 /* TRANS: Latter %s is citizen nationality */
1644 _("%s can't build %s from the worklist; "
1645 "only city with %s may build this. Postponing..."),
1647 tgt_name,
1648 nation_plural_translation(preq->source.value.nationality));
1650 pcity, "need_nationality");
1651 } else {
1652 notify_player(pplayer, city_tile(pcity),
1654 /* TRANS: Latter %s is citizen nationality */
1655 _("%s can't build %s from the worklist; "
1656 "only city without %s may build this. Postponing..."),
1658 tgt_name,
1659 nation_plural_translation(preq->source.value.nationality));
1661 pcity, "have_nationality");
1662 }
1663 break;
1664 case VUT_ORIGINAL_OWNER:
1665 /* Original owner of this specific city won't change.
1666 * Update this when supporting ranges other than REQ_RANGE_CITY. */
1667 purge = TRUE;
1668 break;
1669 case VUT_DIPLREL:
1670 case VUT_DIPLREL_TILE: /* The tile owner is the city owner */
1671 case VUT_DIPLREL_TILE_O: /* The tile owner is the city owner */
1672 if (preq->present) {
1673 const char *reason;
1674
1675 notify_player(pplayer, city_tile(pcity),
1677 /* TRANS: '%s' is a wide range of relationships;
1678 * e.g., 'Peace', 'Never met', 'Foreign',
1679 * 'Hosts embassy', 'Provided Casus Belli' */
1680 _("%s can't build %s from the worklist; "
1681 "the relationship '%s' is required."
1682 " Postponing..."),
1684 tgt_name,
1686 preq->source.value.diplrel));
1687
1688 if (preq->source.kind == VUT_DIPLREL_TILE) {
1689 reason = "need_diplrel_tile";
1690 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1691 reason = "need_diplrel_tile_o";
1692 } else {
1693 fc_assert(preq->source.kind == VUT_DIPLREL);
1694 reason = "need_diplrel";
1695 }
1696
1698 pcity, reason);
1699 } else {
1700 const char *reason;
1701
1702 notify_player(pplayer, city_tile(pcity),
1704 _("%s can't build %s from the worklist; "
1705 "the relationship '%s' is prohibited."
1706 " Postponing..."),
1708 tgt_name,
1710 preq->source.value.diplrel));
1711
1712 if (preq->source.kind == VUT_DIPLREL_TILE) {
1713 reason = "have_diplrel_tile";
1714 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1715 reason = "have_diplrel_tile_o";
1716 } else {
1717 fc_assert(preq->source.kind == VUT_DIPLREL);
1718 reason = "have_diplrel";
1719 }
1720
1722 pcity, reason);
1723 }
1724 break;
1727 if (preq->present) {
1728 const char *reason;
1729
1730 notify_player(pplayer, city_tile(pcity),
1732 /* TRANS: '%s' is a wide range of relationships;
1733 * e.g., 'Peace', 'Never met', 'Foreign',
1734 * 'Hosts embassy', 'Provided Casus Belli' */
1735 _("%s can't build %s from the worklist; "
1736 "unit with the relationship '%s' is required."
1737 " Postponing..."),
1739 tgt_name,
1741 preq->source.value.diplrel));
1742
1743 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1744 reason = "need_diplrel_unitany";
1745 } else {
1746 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1747 reason = "need_diplrel_unitany_o";
1748 }
1749
1751 pcity, reason);
1752 } else {
1753 const char *reason;
1754
1755 notify_player(pplayer, city_tile(pcity),
1757 _("%s can't build %s from the worklist; "
1758 "unit with the relationship '%s' is prohibited."
1759 " Postponing..."),
1761 tgt_name,
1763 preq->source.value.diplrel));
1764
1765 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1766 reason = "have_diplrel_unitany";
1767 } else {
1768 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1769 reason = "have_diplrel_unitany_o";
1770 }
1771
1773 pcity, reason);
1774 }
1775 break;
1776 case VUT_MINSIZE:
1777 if (preq->present) {
1778 notify_player(pplayer, city_tile(pcity),
1780 _("%s can't build %s from the worklist; "
1781 "city must be of size %d or larger. "
1782 "Postponing..."),
1784 tgt_name,
1785 preq->source.value.minsize);
1787 pcity, "need_minsize");
1788 } else {
1789 notify_player(pplayer, city_tile(pcity),
1791 _("%s can't build %s from the worklist; "
1792 "city must be of size %d or smaller."
1793 "Postponing..."),
1795 tgt_name,
1796 (preq->source.value.minsize - 1));
1798 pcity, "need_minsize");
1799 }
1800 break;
1801 case VUT_MINCULTURE:
1802 if (preq->present) {
1803 notify_player(pplayer, city_tile(pcity),
1805 _("%s can't build %s from the worklist; "
1806 "city must have culture of %d. Postponing..."),
1808 tgt_name,
1809 preq->source.value.minculture);
1811 pcity, "need_minculture");
1812 } else {
1813 /* What has been written may not be unwritten. */
1814 purge = TRUE;
1815 }
1816 break;
1817 case VUT_MINFOREIGNPCT:
1818 if (preq->present) {
1819 notify_player(pplayer, city_tile(pcity),
1821 _("%s can't build %s from the worklist; "
1822 "city must have %d%% foreign population. Postponing..."),
1824 tgt_name,
1825 preq->source.value.minforeignpct);
1827 pcity, "need_minforeignpct");
1828 } else {
1829 notify_player(pplayer, city_tile(pcity),
1831 _("%s can't build %s from the worklist; "
1832 "city must have %d%% native population. Postponing..."),
1834 tgt_name,
1835 100 - preq->source.value.minforeignpct);
1837 pcity, "need_minforeignpct");
1838 }
1839 break;
1840 case VUT_MINTECHS:
1841 if (preq->present) {
1842 notify_player(pplayer, city_tile(pcity),
1844 _("%s can't build %s from the worklist; "
1845 "%d techs must be known. Postponing..."),
1847 tgt_name,
1848 preq->source.value.min_techs);
1850 pcity, "need_mintechs");
1851 } else {
1852 purge = TRUE;
1853 }
1854 break;
1855 case VUT_FUTURETECHS:
1856 if (preq->present) {
1857 notify_player(pplayer, city_tile(pcity),
1859 _("%s can't build %s from the worklist; "
1860 "%d future techs must be known. Postponing..."),
1862 tgt_name,
1863 preq->source.value.future_techs);
1865 pcity, "need_futuretechs");
1866 } else {
1867 purge = TRUE;
1868 }
1869 break;
1870 case VUT_MINCITIES:
1871 if (preq->present) {
1872 notify_player(pplayer, city_tile(pcity),
1874 _("%s can't build %s from the worklist; "
1875 "Must own %d cities. Postponing..."),
1877 tgt_name,
1878 preq->source.value.min_cities);
1880 pcity, "need_mincities");
1881 } else {
1882 purge = TRUE;
1883 }
1884 break;
1886 if (preq->present) {
1887 notify_player(pplayer, city_tile(pcity),
1889 PL_("%s can't build %s from the worklist; "
1890 "more than %d total unit on tile."
1891 " Postponing...",
1892 "%s can't build %s from the worklist; "
1893 "more than %d total units on tile."
1894 " Postponing...",
1895 preq->source.value.max_tile_total_units),
1897 tgt_name,
1898 preq->source.value.max_tile_total_units);
1900 pcity, "need_tileunits");
1901 } else {
1902 notify_player(pplayer, city_tile(pcity),
1904 PL_("%s can't build %s from the worklist; "
1905 "fewer than %d total unit on tile."
1906 " Postponing...",
1907 "%s can't build %s from the worklist; "
1908 "fewer than %d total units on tile."
1909 " Postponing...",
1910 preq->source.value.max_tile_total_units + 1),
1912 tgt_name,
1913 preq->source.value.max_tile_total_units + 1);
1915 pcity, "need_tileunits");
1916 }
1917 break;
1919 if (preq->present) {
1920 notify_player(pplayer, city_tile(pcity),
1922 PL_("%s can't build %s from the worklist; "
1923 "more than %d unit on tile."
1924 " Postponing...",
1925 "%s can't build %s from the worklist; "
1926 "more than %d units on tile."
1927 " Postponing...",
1928 preq->source.value.max_tile_top_units),
1930 tgt_name,
1931 preq->source.value.max_tile_top_units);
1933 pcity, "need_tiletopunits");
1934 } else {
1935 notify_player(pplayer, city_tile(pcity),
1937 PL_("%s can't build %s from the worklist; "
1938 "fewer than %d unit on tile."
1939 " Postponing...",
1940 "%s can't build %s from the worklist; "
1941 "fewer than %d units on tile."
1942 " Postponing...",
1943 preq->source.value.max_tile_top_units + 1),
1945 tgt_name,
1946 preq->source.value.max_tile_top_units + 1);
1948 pcity, "need_tiletopunits");
1949 }
1950 break;
1951 case VUT_AI_LEVEL:
1952 /* Can't change AI level. */
1953 purge = TRUE;
1954 break;
1955 case VUT_TERRAINCLASS:
1956 /* Change of terrain class is expected to be very unlikely. Purge!
1957 * TODO: Analyze ruleset to see how unlikely terrain class change actually is. */
1958 purge = TRUE;
1959 break;
1960 case VUT_TERRFLAG:
1961 if (preq->present) {
1962 notify_player(pplayer, city_tile(pcity),
1964 _("%s can't build %s from the worklist; "
1965 "terrain with \"%s\" flag is required. "
1966 "Postponing..."),
1968 tgt_name,
1969 terrain_flag_id_name(preq->source.value.terrainflag));
1971 pcity, "need_terrainflag");
1972 } else {
1973 notify_player(pplayer, city_tile(pcity),
1975 _("%s can't build %s from the worklist; "
1976 "terrain with \"%s\" flag is prohibited. "
1977 "Postponing..."),
1979 tgt_name,
1980 terrain_flag_id_name(preq->source.value.terrainflag));
1982 pcity, "have_terrainflag");
1983 }
1984 break;
1986 /* Changing the continent size is hard; cf. VUT_TERRAINCLASS above.
1987 * Change this when we support less fixed ranges (e.g. city?). */
1988 purge = TRUE;
1989 break;
1990 case VUT_ROADFLAG:
1991 if (preq->present) {
1992 notify_player(pplayer, city_tile(pcity),
1994 _("%s can't build %s from the worklist; "
1995 "road with \"%s\" flag is required. "
1996 "Postponing..."),
1998 tgt_name,
1999 road_flag_id_name(preq->source.value.roadflag));
2001 pcity, "need_roadflag");
2002 } else {
2003 notify_player(pplayer, city_tile(pcity),
2005 _("%s can't build %s from the worklist; "
2006 "road with \"%s\" flag is prohibited. "
2007 "Postponing..."),
2009 tgt_name,
2010 road_flag_id_name(preq->source.value.roadflag));
2012 pcity, "have_roadflag");
2013 }
2014 break;
2015 case VUT_EXTRAFLAG:
2016 if (preq->present) {
2017 notify_player(pplayer, city_tile(pcity),
2019 _("%s can't build %s from the worklist; "
2020 "extra with \"%s\" flag is required. "
2021 "Postponing..."),
2023 tgt_name,
2024 extra_flag_id_translated_name(preq->source.value.extraflag));
2026 pcity, "need_extraflag");
2027 } else {
2028 notify_player(pplayer, city_tile(pcity),
2030 _("%s can't build %s from the worklist; "
2031 "extra with \"%s\" flag is prohibited. "
2032 "Postponing..."),
2034 tgt_name,
2035 extra_flag_id_translated_name(preq->source.value.extraflag));
2037 pcity, "have_extraflag");
2038 }
2039 break;
2040 case VUT_MINLATITUDE:
2041 case VUT_MAXLATITUDE:
2042 /* Can't change where the city is located. */
2043 purge = TRUE;
2044 break;
2045 case VUT_CITYTILE:
2046 if (CITYT_BORDERING_TCLASS_REGION == preq->source.value.citytile
2047 && (preq->range == REQ_RANGE_CADJACENT
2048 || preq->range == REQ_RANGE_ADJACENT)) {
2049 if (preq->present) {
2050 notify_player(pplayer, city_tile(pcity),
2052 _("%s can't build %s from the worklist; "
2053 "different terrain class nearby is required. "
2054 "Postponing..."),
2056 tgt_name);
2058 pcity, "need_different_terrainclass");
2059 } else {
2060 notify_player(pplayer, city_tile(pcity),
2062 _("%s can't build %s from the worklist; "
2063 "different terrain class nearby is prohibited. "
2064 "Postponing..."),
2066 tgt_name);
2068 pcity, "have_different_terrainclass");
2069 }
2070 break;
2071 }
2072 /* Other values should not present in build reqs */
2074
2075 case VUT_UTYPE:
2076 case VUT_UTFLAG:
2077 case VUT_UCLASS:
2078 case VUT_UCFLAG:
2079 case VUT_MINVETERAN:
2080 case VUT_UNITSTATE:
2081 case VUT_ACTIVITY:
2082 case VUT_MINMOVES:
2083 case VUT_MINHP:
2084 case VUT_ACTION:
2085 case VUT_OTYPE:
2086 case VUT_SPECIALIST:
2088 case VUT_TILE_REL:
2089 case VUT_TERRAINALTER: /* XXX could do this in principle */
2090 /* Will only happen with a bogus ruleset. */
2091 log_error("worklist_change_build_target() has bogus preq");
2092 break;
2093 case VUT_CITYSTATUS:
2094 if (preq->source.value.citystatus == CITYS_TRANSFERRED) {
2095 /* If there's a change, it will invalidate worklist anyway. */
2096 purge = TRUE;
2097 } else if (preq->source.value.citystatus == CITYS_OWNED_BY_ORIGINAL) {
2098 if (preq->range == REQ_RANGE_CITY || preq->range == REQ_RANGE_TILE) {
2099 /* Can't change at these ranges */
2100 purge = TRUE;
2101 } else {
2102 if (preq->present) {
2103 notify_player(pplayer, city_tile(pcity),
2105 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2106 _("%s can't build %s from the worklist; "
2107 "only available when city in range %s \"%s\". "
2108 "Postponing..."),
2110 tgt_name, req_range_name(preq->range),
2111 citystatus_type_name(preq->source.value.citystatus));
2113 pcity, "need_citystatus");
2114 } else {
2115 notify_player(pplayer, city_tile(pcity),
2117 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2118 _("%s can't build %s from the worklist; "
2119 "not available when city in range %s is \"%s\". "
2120 "Postponing..."),
2122 tgt_name, req_range_name(preq->range),
2123 citystatus_type_name(preq->source.value.citystatus));
2125 pcity, "have_citystatus");
2126 }
2127 }
2128 } else {
2129 /* Other status types will only happen with a bogus ruleset. */
2130 log_error("worklist_change_build_target() has bogus citystatus preq");
2131 }
2132 break;
2133 case VUT_MINYEAR:
2134 if (preq->present) {
2135 notify_player(pplayer, city_tile(pcity),
2137 /* TRANS: last %s is a date */
2138 _("%s can't build %s from the worklist; "
2139 "only available from %s. Postponing..."),
2141 tgt_name,
2142 textyear(preq->source.value.minyear));
2144 pcity, "need_minyear");
2145 } else {
2146 /* Can't go back in time. */
2147 purge = TRUE;
2148 }
2149 break;
2150 case VUT_MINCALFRAG:
2151 /* Unlike VUT_MINYEAR, a requirement in either direction is
2152 * likely to be fulfilled sooner or later. */
2153 if (preq->present) {
2154 notify_player(pplayer, city_tile(pcity),
2156 /* TRANS: last %s is a calendar fragment from
2157 * the ruleset; may be a bare number */
2158 _("%s can't build %s from the worklist; "
2159 "only available from %s. Postponing..."),
2161 tgt_name,
2162 textcalfrag(preq->source.value.mincalfrag));
2164 pcity, "need_mincalfrag");
2165 } else {
2166 fc_assert_action(preq->source.value.mincalfrag > 0, break);
2167 notify_player(pplayer, city_tile(pcity),
2169 /* TRANS: last %s is a calendar fragment from
2170 * the ruleset; may be a bare number */
2171 _("%s can't build %s from the worklist; "
2172 "not available after %s. Postponing..."),
2174 tgt_name,
2175 textcalfrag(preq->source.value.mincalfrag - 1));
2177 pcity, "have_mincalfrag");
2178 }
2179 break;
2180 case VUT_TOPO:
2181 if (preq->present) {
2182 notify_player(pplayer, city_tile(pcity),
2184 /* TRANS: third %s is topology flag name
2185 * ("Hex", "ISO" */
2186 _("%s can't build %s from the worklist; "
2187 "only available in worlds with %s map."),
2189 tgt_name,
2190 _(topo_flag_name(preq->source.value.topo_property)));
2192 pcity, "need_topo");
2193 }
2194 purge = TRUE;
2195 break;
2196 case VUT_WRAP:
2197 if (preq->present) {
2198 notify_player(pplayer, city_tile(pcity),
2200 /* TRANS: third %s is wrap flag name
2201 * ("WrapX", "Wrapy") */
2202 _("%s can't build %s from the worklist; "
2203 "only available in worlds with %s map."),
2205 tgt_name,
2206 _(wrap_flag_name(preq->source.value.wrap_property)));
2208 pcity, "need_wrap");
2209 }
2210 purge = TRUE;
2211 break;
2212 case VUT_SERVERSETTING:
2213 notify_player(pplayer, city_tile(pcity),
2215 /* TRANS: %s is a server setting, its value and
2216 * if it is required to be present or absent.
2217 * The string's format is specified in
2218 * ssetv_human_readable().
2219 * Example: "killstack is enabled". */
2220 _("%s can't build %s from the worklist; "
2221 "only available when the server setting "
2222 "%s."),
2224 tgt_name,
2225 ssetv_human_readable(preq->source.value.ssetval,
2226 preq->present));
2228 pcity, "need_setting");
2229 /* Don't assume that the server setting will be changed. */
2230 purge = TRUE;
2231 break;
2232 case VUT_AGE:
2233 if (preq->present) {
2234 notify_player(pplayer, city_tile(pcity),
2236 _("%s can't build %s from the worklist; "
2237 "only available once %d turns old. Postponing..."),
2239 tgt_name,
2240 preq->source.value.age);
2242 pcity, "need_age");
2243 } else {
2244 /* Can't go back in time. */
2245 purge = TRUE;
2246 }
2247 break;
2248 case VUT_FORM_AGE:
2249 if (preq->present) {
2250 notify_player(pplayer, city_tile(pcity),
2252 _("%s can't build %s from the worklist; "
2253 "only available once %d turns old form. Postponing..."),
2255 tgt_name,
2256 preq->source.value.age);
2258 pcity, "need_form_age");
2259 } else {
2260 /* Can't go back in time. */
2261 purge = TRUE;
2262 }
2263 break;
2264 case VUT_NONE:
2265 case VUT_COUNT:
2267 "worklist_change_build_target() "
2268 "called with invalid preq");
2269 break;
2270 /* No default handling here, as we want compiler warning
2271 * if new requirement type is added to enum and it's not handled
2272 * here. */
2273 };
2274 break;
2275 }
2276
2277 /* Almost all cases emit signal in the end, so city check needed. */
2278 if (!city_exist(saved_id)) {
2279 /* Some script has removed city */
2280 return TRUE;
2281 }
2282
2284
2285 if (!known) {
2286 /* FIXME: make can_city_build_improvement_now() return a reason enum,
2287 * so we can notify user with it.
2288 * Likely the building already exist. */
2289 purge = TRUE;
2290 }
2291
2292 return purge;
2293}
2294
2295/**********************************************************************/
2301static bool worklist_change_build_target(struct player *pplayer,
2302 struct city *pcity)
2303{
2304 struct universal target;
2305 bool success = FALSE;
2306 int i;
2307 int saved_id = pcity->id;
2308 bool city_checked = TRUE; /* This is used to avoid spurious city_exist() calls */
2309 struct worklist *pwl = &pcity->worklist;
2310 const struct civ_map *nmap = &(wld.map);
2311
2312 if (worklist_is_empty(pwl)) {
2313 /* Nothing in the worklist; bail now. */
2314 return FALSE;
2315 }
2316
2317 i = 0;
2318 while (!success && i < worklist_length(pwl)) {
2319
2320 if (!city_checked) {
2321 if (!city_exist(saved_id)) {
2322 /* Some script has removed useless city that cannot build
2323 * what it is told to! */
2324 return FALSE;
2325 }
2327 }
2328
2329 if (worklist_peek_ith(pwl, &target, i)) {
2330 success = can_city_build_now(nmap, pcity, &target);
2331 } else {
2332 success = FALSE;
2333 }
2334 i++;
2335
2336 if (success) {
2337 break; /* while */
2338 }
2339
2340 switch (target.kind) {
2341 case VUT_UTYPE:
2342 {
2343 const struct unit_type *ptarget = target.value.utype;
2345 bool purge;
2346
2347 /* Maybe we can just upgrade the target to what the city /can/ build. */
2348 if (U_NOT_OBSOLETED == pupdate) {
2349 /* Nope, we're stuck. Skip this item from the worklist. */
2350 struct research *presearch = research_get(pplayer);
2351 struct advance *missing = nullptr;
2352 bool multiple = FALSE;
2353
2356 if (missing != nullptr) {
2357 multiple = TRUE;
2358 } else {
2359 missing = padv;
2360 }
2361 }
2363
2364
2365 purge = FALSE;
2366 if (missing != nullptr) {
2367 if (!multiple) {
2368 notify_player(pplayer, city_tile(pcity),
2370 _("%s can't build %s from the worklist; "
2371 "tech %s not yet available. Postponing..."),
2374 } else {
2375 notify_player(pplayer, city_tile(pcity),
2377 _("%s can't build %s from the worklist; "
2378 "multiple techs still needed. Postponing..."),
2380 }
2381
2382 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2383 "need_tech");
2384 } else {
2385 /* Unknown or requirement from vector. */
2386 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2387 saved_id);
2388 }
2390 if (!purge) {
2391 break;
2392 }
2393 } else {
2395 }
2396 if (purge) {
2397 /* If the city can never build this unit or its descendants,
2398 * drop it. */
2399 notify_player(pplayer, city_tile(pcity),
2401 _("%s can't build %s from the worklist. Purging..."),
2403 /* Yes, warn about the targets that's actually
2404 in the worklist, not its obsolete-closure
2405 pupdate. */
2407 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2408 "never");
2409 if (city_exist(saved_id)) {
2411 /* Purge this worklist item. */
2412 i--;
2414 } else {
2416 }
2417 } else {
2418 /* Yep, we can go after pupdate instead. Joy! */
2420 _("Production of %s is upgraded to %s in %s."),
2423 city_link(pcity));
2424 target.value.utype = pupdate;
2425 }
2426 break;
2427 }
2428 case VUT_IMPROVEMENT:
2429 {
2430 const struct impr_type *ptarget = target.value.building;
2432 bool purge;
2433
2434 /* If the city can never build this improvement, drop it. */
2436 purge = !success;
2437
2438 /* Maybe this improvement has been obsoleted by something that
2439 we can build. */
2440 if (purge) {
2441 /* Nope, no use. *sigh* */
2442
2443 /* Can it be postponed? */
2445 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2446 saved_id);
2447
2448 /* Almost all cases emit signal in the end, so city check needed. */
2449 if (!city_exist(saved_id)) {
2450 /* Some script has removed city */
2451 return FALSE;
2452 }
2454 }
2455 } else if (success) {
2456 /* Hey, we can upgrade the improvement! */
2458 _("Production of %s is upgraded to %s in %s."),
2461 city_link(pcity));
2462 target.value.building = pupdate;
2463 }
2464
2465 if (purge) {
2466 /* Never in a million years. */
2467 notify_player(pplayer, city_tile(pcity),
2469 _("%s can't build %s from the worklist. Purging..."),
2472 script_server_signal_emit("building_cant_be_built", ptarget, pcity,
2473 "never");
2474 if (city_exist(saved_id)) {
2476 /* Purge this worklist item. */
2477 i--;
2479 } else {
2481 }
2482 }
2483 break;
2484 }
2485 default:
2486 /* skip useless target */
2487 log_error("worklist_change_build_target() has unrecognized "
2488 "target kind (%d)", target.kind);
2489 break;
2490 };
2491 } /* while */
2492
2493 if (success) {
2494 /* All okay. Switch targets. */
2495 change_build_target(pplayer, pcity, &target, E_WORKLIST);
2496
2497 /* i is the index immediately _after_ the item we're changing to.
2498 Remove the (i-1)th item from the worklist. */
2499 worklist_remove(pwl, i - 1);
2500 }
2501
2502 if (worklist_is_empty(pwl)) {
2503 /* There *was* something in the worklist, but it's empty now. Bug the
2504 player about it. */
2506 /* TRANS: The <city> worklist .... */
2507 _("The %s worklist is now empty."),
2508 city_link(pcity));
2509 }
2510
2511 return success;
2512}
2513
2514/**********************************************************************/
2519void choose_build_target(struct player *pplayer, struct city *pcity)
2520{
2521 const struct civ_map *nmap = &(wld.map);
2522
2523 /* Pick the next thing off the worklist. */
2524 if (worklist_change_build_target(pplayer, pcity)) {
2525 return;
2526 }
2527
2528 /* Try building the same thing again. Repeat building doesn't require a
2529 * call to change_build_target, so just return. */
2530 switch (pcity->production.kind) {
2531 case VUT_UTYPE:
2532 /* We can build a unit again unless it's unique or we have lost the tech. */
2533 if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
2534 && can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
2535 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2536 utype_rule_name(pcity->production.value.utype));
2537 return;
2538 }
2539 break;
2540 case VUT_IMPROVEMENT:
2541 if (can_city_build_improvement_now(pcity, pcity->production.value.building)) {
2542 /* We can build space and coinage again, and possibly others. */
2543 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2544 improvement_rule_name(pcity->production.value.building));
2545 return;
2546 }
2547 break;
2548 default:
2549 /* fallthru */
2550 break;
2551 };
2552
2553 /* Find *something* to do! */
2554 log_debug("Trying advisor_choose_build.");
2555 advisor_choose_build(pplayer, pcity);
2556 log_debug("Advisor_choose_build didn't kill us.");
2557}
2558
2559/**********************************************************************/
2564static const struct impr_type *building_upgrades_to(struct city *pcity,
2565 const struct impr_type *pimprove)
2566{
2567 const struct impr_type *check = pimprove;
2568 const struct impr_type *best_upgrade = nullptr;
2569
2571 return nullptr;
2572 }
2576 }
2577 }
2578
2579 return best_upgrade;
2580}
2581
2582/**********************************************************************/
2586{
2587 const struct impr_type *producing = pcity->production.value.building;
2589
2593 _("Production of %s is upgraded to %s in %s."),
2596 city_link(pcity));
2597 pcity->production.kind = VUT_IMPROVEMENT;
2598 pcity->production.value.building = upgrading;
2599 }
2600}
2601
2602/**********************************************************************/
2610static const struct unit_type *unit_upgrades_to(struct city *pcity,
2611 const struct unit_type *punittype)
2612{
2613 const struct unit_type *check = punittype;
2614 const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
2615 const struct civ_map *nmap = &(wld.map);
2616
2618 return U_NOT_OBSOLETED;
2619 }
2620 while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
2623 }
2624 }
2625
2626 return best_upgrade;
2627}
2628
2629/**********************************************************************/
2632static void upgrade_unit_prod(struct city *pcity)
2633{
2634 const struct unit_type *producing = pcity->production.value.utype;
2636 const struct civ_map *nmap = &(wld.map);
2637
2641 _("Production of %s is upgraded to %s in %s."),
2644 city_link(pcity));
2645 pcity->production.value.utype = upgrading;
2646 }
2647}
2648
2649/**********************************************************************/
2656static bool city_distribute_surplus_shields(struct player *pplayer,
2657 struct city *pcity)
2658{
2659 int size_reduction = 0;
2660 struct unit *sacrifizer;
2661
2662 if (pcity->surplus[O_SHIELD] < 0) {
2663 unit_list_iterate_safe(pcity->units_supported, punit) {
2665 && pcity->surplus[O_SHIELD] < 0) {
2666 const char *punit_link = unit_link(punit);
2667
2668 /* TODO: Should the unit try to help cities on adjacent tiles? That
2669 * would be a rules change. (This action is performed by the game
2670 * it self) */
2673 notify_player(pplayer, city_tile(pcity),
2675 _("%s can't upkeep %s, unit disbanded."),
2677 }
2678
2679 /* pcity->surplus[O_SHIELD] is automatically updated. */
2680 }
2682 }
2683
2684 if (pcity->surplus[O_SHIELD] < 0) {
2685 /* Special case: MissingXProtected. This nasty unit won't go so easily.
2686 * It'd rather make the citizens pay in blood for their failure to upkeep
2687 * it! If we make it here all normal units are already disbanded, so only
2688 * undisbandable ones remain. */
2689 unit_list_iterate_safe(pcity->units_supported, punit) {
2691
2692 if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
2693
2695 sacrifizer = punit;
2696
2697 /* No upkeep for the unit this turn. */
2698 pcity->surplus[O_SHIELD] += upkeep;
2699 }
2701 }
2702
2703 /* Now we confirm changes made last turn. */
2704 pcity->shield_stock += pcity->surplus[O_SHIELD];
2705 pcity->before_change_shields = pcity->shield_stock;
2706 pcity->last_turns_shield_surplus = pcity->surplus[O_SHIELD];
2707
2708 /* Previous turn values stored, and they are consistent with
2709 * other previous turn data.
2710 * Now reduce city size, likely messing all the values. */
2711 if (size_reduction > 0) {
2712 if (size_reduction == 1) {
2713 notify_player(pplayer, city_tile(pcity),
2715 _("Citizens in %s perish for their failure to "
2716 "upkeep %s!"),
2718 } else {
2719 notify_player(pplayer, city_tile(pcity),
2721 _("Citizens in %s perish for their failure to "
2722 "upkeep units!"),
2723 city_link(pcity));
2724 }
2725
2726 if (!city_reduce_size(pcity, size_reduction, nullptr, "upkeep_failure")) {
2727 return FALSE;
2728 }
2729 }
2730
2731 return TRUE;
2732}
2733
2734/**********************************************************************/
2737static bool city_build_building(struct player *pplayer, struct city *pcity)
2738{
2739 bool space_part;
2740 int mod;
2741 const struct impr_type *pimprove;
2742 int saved_id = pcity->id;
2743 const struct civ_map *nmap = &(wld.map);
2744
2745 if (is_convert_improvement(pcity->production.value.building)) {
2746 /* Coinage-like improvements that convert production */
2747 fc_assert(pcity->before_change_shields >= 0);
2748
2749 /* pcity->before_change_shields already contains the surplus from
2750 * this turn. */
2752 pplayer->economic.gold += pcity->before_change_shields;
2754 pplayer->economic.infra_points += pcity->before_change_shields;
2755 }
2756
2757 pcity->before_change_shields = 0;
2758 pcity->shield_stock = 0;
2759 choose_build_target(pplayer, pcity);
2760
2761 return TRUE;
2762 }
2763
2765
2766 /* The final (after upgrade) build target */
2767 pimprove = pcity->production.value.building;
2768
2769 if (!can_city_build_improvement_now(pcity, pimprove)) {
2771 _("%s is building %s, which is no longer available."),
2774 script_server_signal_emit("building_cant_be_built", pimprove, pcity,
2775 "unavailable");
2776 return TRUE;
2777 }
2778 if (pcity->shield_stock >= impr_build_shield_cost(pcity, pimprove)
2780 int cost;
2781
2782 if (is_small_wonder(pimprove)) {
2783 city_list_iterate(pplayer->cities, wcity) {
2784 if (city_has_building(wcity, pimprove)) {
2785 city_remove_improvement(wcity, pimprove);
2786 break;
2787 }
2789 }
2790
2791 space_part = TRUE;
2793 RPT_CERTAIN) > 0) {
2794 pplayer->spaceship.structurals++;
2796 RPT_CERTAIN) > 0) {
2797 pplayer->spaceship.components++;
2799 RPT_CERTAIN) > 0) {
2800 pplayer->spaceship.modules++;
2801 } else {
2802 space_part = FALSE;
2804 _("Completion of %s"));
2805 }
2806 cost = impr_build_shield_cost(pcity, pimprove);
2807 pcity->before_change_shields -= cost;
2808 pcity->shield_stock -= cost;
2809 pcity->turn_last_built = game.info.turn;
2810 /* To eliminate micromanagement */
2811 if (is_great_wonder(pimprove)) {
2813 _("The %s have finished building %s in %s."),
2814 nation_plural_for_player(pplayer),
2816 city_link(pcity));
2817 }
2818
2820 _("%s has finished building %s."),
2822 script_server_signal_emit("building_built", pimprove, pcity);
2823
2824 if (!city_exist(saved_id)) {
2825 /* Script removed city */
2826 return FALSE;
2827 }
2828
2829 /* Call this function since some buildings may change the
2830 * the vision range of a city */
2832
2834 RPT_CERTAIN))) {
2835 struct research *presearch = research_get(pplayer);
2836 char research_name[MAX_LEN_NAME * 2];
2837 int i;
2838 const char *provider = improvement_name_translation(pimprove);
2839
2841 PL_("%s boosts research; you gain %d immediate "
2842 "advance.",
2843 "%s boosts research; you gain %d immediate "
2844 "advances.",
2845 mod), provider, mod);
2846
2848 for (i = 0; i < mod; i++) {
2851
2854 /* TRANS: Tech from building (Darwin's Voyage) */
2855 Q_("?frombldg:Acquired %s from %s."), adv_name,
2856 provider);
2857
2859 /* TRANS: Tech from building (Darwin's
2860 * Voyage) */
2861 Q_("?frombldg:The %s have acquired %s "
2862 "from %s."),
2864 }
2865 }
2866 if (space_part && pplayer->spaceship.state == SSHIP_NONE) {
2868 _("The %s have started building a spaceship!"),
2869 nation_plural_for_player(pplayer));
2870 pplayer->spaceship.state = SSHIP_STARTED;
2871 }
2872 if (space_part) {
2873 /* Space ship part build */
2874 send_spaceship_info(pplayer, nullptr);
2875 } else {
2876 /* Update city data. */
2877 if (city_refresh(pcity)) {
2879 }
2880 }
2881
2882 /* Move to the next thing in the worklist */
2883 choose_build_target(pplayer, pcity);
2884 }
2885
2886 return TRUE;
2887}
2888
2889/**********************************************************************/
2898static struct unit *city_create_unit(struct city *pcity,
2899 const struct unit_type *utype,
2900 struct citizens_reduction *red)
2901{
2902 struct player *pplayer = city_owner(pcity);
2903 struct unit *punit;
2904 int saved_unit_id;
2905 int pop_cost = utype_pop_value(utype, pcity);
2906
2909 pcity->id, -1, -1);
2910 pplayer->score.units_built++;
2911
2912 if (pop_cost > 0 && pcity->nationality != nullptr) {
2913 /* We don't reduce city size in-place to keep it correct and
2914 * existing at all while we call the following callback.
2915 * We want citizens_unit_nationality() to adjust 'red' even when
2916 * we are not setting unit nationality based on the return */
2917 struct player *nat = citizens_unit_nationality(pcity, pop_cost, red);
2918
2921 }
2922 } else if (red) {
2923 red->change = 0;
2924 }
2925
2926 (void) place_unit(punit, pplayer, pcity, nullptr, FALSE);
2928
2929 /* If city has a rally point set, give the unit a move order. */
2930 if (pcity->rally_point.length) {
2932 punit->orders.length = pcity->rally_point.length;
2933 punit->orders.vigilant = pcity->rally_point.vigilant;
2934 punit->orders.list = fc_malloc(pcity->rally_point.length
2935 * sizeof(struct unit_order));
2936 memcpy(punit->orders.list, pcity->rally_point.orders,
2937 pcity->rally_point.length * sizeof(struct unit_order));
2938 }
2939
2940 /* This might destroy pcity and/or punit: */
2941 script_server_signal_emit("unit_built", punit, pcity);
2942
2944 return punit;
2945 } else {
2946 return nullptr;
2947 }
2948}
2949
2950/**********************************************************************/
2959static bool city_build_unit(struct player *pplayer, struct city *pcity)
2960{
2961 const struct unit_type *utype;
2962 struct worklist *pwl = &pcity->worklist;
2964 int saved_city_id = pcity->id;
2965 const struct civ_map *nmap = &(wld.map);
2966
2967 fc_assert_ret_val(pcity->production.kind == VUT_UTYPE, FALSE);
2968
2969 /* If the city has already bought a unit which is now obsolete, don't try
2970 * to upgrade the production. The new unit might require more shields, which
2971 * would be bad if it was bought to urgently defend a city. (Equally it
2972 * might be the same cost or cheaper, but tough; you hurried the unit so
2973 * you miss out on technological advances.) */
2976 }
2977
2978 utype = pcity->production.value.utype;
2980
2981 /* We must make a special case for barbarians here, because they are
2982 so dumb. Really. They don't know the prerequisite techs for units
2983 they build!! - Per */
2985 && !is_barbarian(pplayer)) {
2987 _("%s is building %s, which is no longer available."),
2989
2990 /* Log before signal emitting, so pointers are certainly valid */
2991 log_verbose("%s %s tried to build %s, which is not available.",
2994 script_server_signal_emit("unit_cant_be_built", utype, pcity,
2995 "unavailable");
2996 return city_exist(saved_city_id);
2997 }
2998
2999 if (pcity->shield_stock >= unit_shield_cost
3001 int pop_cost = utype_pop_value(utype, pcity);
3002 struct unit *punit;
3003
3004 /* Should we disband the city? -- Massimo */
3005 if (city_size_get(pcity) == pop_cost
3007 return !disband_city(pcity);
3008 }
3009
3010 if (city_size_get(pcity) <= pop_cost) {
3012 /* TRANS: city ... utype ... size ... pop_cost */
3013 _("%s can't build %s yet. "
3014 "(city size: %d, unit population cost: %d)"),
3016 city_size_get(pcity), pop_cost);
3017 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3018 "pop_cost");
3019 return city_exist(saved_city_id);
3020 }
3021
3022 fc_assert(pop_cost == 0 || city_size_get(pcity) >= pop_cost);
3023
3024 /* don't update turn_last_built if we returned above */
3025 pcity->turn_last_built = game.info.turn;
3026
3027 /* check if we can build more than one unit (effect City_Build_Slots) */
3029
3030 /* We should be able to build at least one (by checks above) */
3031 fc_assert(num_units >= 1);
3032
3033 for (i = 0; i < num_units; i++) {
3035
3037
3038 /* Check if the city still exists (script might have removed it).
3039 * If not, we assume any effects / announcements done below were
3040 * already replaced by the script if necessary. */
3041 if (!city_exist(saved_city_id)) {
3042 break;
3043 }
3044
3045 if (punit) {
3046 if (punit->carrying
3049 /* TRANS: <city> is finished building <unit>, carrying <goods>. */
3050 _("%s is finished building %s, carrying %s."),
3053 } else {
3055 /* TRANS: <city> is finished building <unit/building>. */
3056 _("%s is finished building %s."),
3058 }
3059 }
3060
3061 /* After we created the unit remove the citizen. This will also
3062 * rearrange the worker to take into account the extra resources
3063 * (food) needed. */
3064 if (pop_cost > 0) {
3065 /* This won't disband city due to pop_cost, but script might
3066 * still destroy city. */
3068 /* If the city has changed its nationalities during
3069 * "unit_built" signal, we take some other citizens instead */
3070 if (!city_reduce_size(pcity, pop_cost, nullptr, "unit_built")) {
3071 break;
3072 }
3073 }
3074
3075 /* to eliminate micromanagement, we only subtract the unit's cost */
3076 /* signals could change the prod stock! */
3077 if ((pcity->before_change_shields -= unit_shield_cost) < 0) {
3078 pcity->before_change_shields = 0;
3079 }
3080 if ((pcity->shield_stock -= unit_shield_cost) < 0) {
3081 log_normal("City %s (%s) has built %s but has no %d shields "
3082 "for it, nullifying shield stock", city_name_get(pcity),
3083 player_name(pplayer), utype_rule_name(utype),
3085 pcity->shield_stock = 0;
3086 }
3087
3088 if (pop_cost > 0) {
3089 /* Additional message if the unit has population cost. */
3091 ftc_server,
3092 /* TRANS: "<unit> cost... <city> shrinks..."
3093 * Plural in "%d population", not "size %d". */
3094 PL_("%s cost %d population. %s shrinks to size %d.",
3095 "%s cost %d population. %s shrinks to size %d.",
3096 pop_cost),
3097 utype_name_translation(utype), pop_cost,
3099 }
3100
3101 if (i != 0 && worklist_length(pwl) > 0) {
3102 /* remove the build unit from the worklist; it has to be one less
3103 * than units build to preserve the next build target from the
3104 * worklist */
3105 worklist_remove(pwl, 0);
3106 }
3107 } /* for */
3108
3110 if (pcity->rally_point.length && !pcity->rally_point.persistent) {
3112 }
3113
3114 /* Done building this unit; time to move on to the next. */
3115 choose_build_target(pplayer, pcity);
3116 }
3117 } /* if */
3118
3119 return city_exist(saved_city_id);
3120}
3121
3122/**********************************************************************/
3125static bool city_build_stuff(struct player *pplayer, struct city *pcity)
3126{
3127 if (!city_distribute_surplus_shields(pplayer, pcity)) {
3128 return FALSE;
3129 }
3130
3133
3134 switch (pcity->production.kind) {
3135 case VUT_IMPROVEMENT:
3136 return city_build_building(pplayer, pcity);
3137 case VUT_UTYPE:
3138 return city_build_unit(pplayer, pcity);
3139 default:
3140 /* Must never happen! */
3142 break;
3143 };
3144
3145 return FALSE;
3146}
3147
3148/**********************************************************************/
3158static bool sell_random_building(struct player *pplayer,
3159 struct cityimpr_list *imprs)
3160{
3161 struct cityimpr *pcityimpr;
3162 int r;
3163
3164 fc_assert_ret_val(pplayer != nullptr, FALSE);
3165
3166 if (!imprs || cityimpr_list_size(imprs) == 0) {
3167 return FALSE;
3168 }
3169
3172
3174 ftc_server,
3175 _("Can't afford to maintain %s in %s, building sold!"),
3177 city_link(pcityimpr->pcity));
3178 log_debug("%s: sold building (%s)", player_name(pplayer),
3180
3181 do_sell_building(pplayer, pcityimpr->pcity, pcityimpr->pimprove, "cant_maintain");
3182
3184
3185 /* Get back the gold upkeep that was already paid this turn. */
3187 pcityimpr->pimprove);
3188
3190
3192
3193 return TRUE;
3194}
3195
3196/**********************************************************************/
3204static void uk_rem_gold_callback(struct unit *punit)
3205{
3206 int gold_upkeep;
3207
3208 /* Remove the unit from uk_rem_gold. */
3210
3211 gold_upkeep = punit->server.upkeep_paid[O_GOLD];
3212
3213 /* All units in uk_rem_gold should have gold upkeep! */
3214 fc_assert_ret_msg(gold_upkeep > 0, "%s has %d gold upkeep",
3215 unit_rule_name(punit), gold_upkeep);
3216
3217 /* Get the upkeep gold back. */
3218 unit_owner(punit)->economic.gold += gold_upkeep;
3219}
3220
3221/**********************************************************************/
3225static void uk_rem_gold_append(struct unit *punit)
3226{
3227 /* Make the unit aware that it is on the uk_rem_gold list. */
3229
3230 /* Add the unit to the list. */
3232}
3233
3234/**********************************************************************/
3238static void unit_list_referred_destroy(struct unit_list *punitlist)
3239{
3241 /* Clear the unit's knowledge of the list. */
3244
3245 /* Destroy the list it self. */
3247}
3248
3249/**********************************************************************/
3261static struct unit *sell_random_unit(struct player *pplayer,
3262 struct unit_list *punitlist)
3263{
3264 struct unit *punit;
3265 int r;
3266 struct unit_list *cargo;
3267
3268 fc_assert_ret_val(pplayer != nullptr, nullptr);
3269
3270 if (!punitlist || unit_list_size(punitlist) == 0) {
3271 return nullptr;
3272 }
3273
3276
3277 cargo = unit_list_new();
3278
3279 /* Check if unit is transporting other units from punitlist,
3280 * and sell one of those (recursively) instead.
3281 * Note that in case of recursive transports we have to iterate
3282 * also through those middle transports that themselves are not in
3283 * punitlist. */
3285 /* Optimization, do not iterate over punitlist
3286 * if we are sure that pcargo is not in it. */
3287 if (pcargo->server.upkeep_paid[O_GOLD] > 0) {
3289 if (pcargo == p2) {
3290 unit_list_append(cargo, pcargo);
3291 }
3293 }
3295
3296 if (unit_list_size(cargo) > 0) {
3297 /* Recursively sell. Note that cargo list has both
3298 * leaf units and middle transports in case of
3299 * recursive transports. */
3300 struct unit *ret = sell_random_unit(pplayer, cargo);
3301
3302 unit_list_destroy(cargo);
3303
3305
3306 return ret;
3307 }
3308
3309 unit_list_destroy(cargo);
3310
3311 {
3312 const char *punit_link = unit_tile_link(punit);
3313#ifdef FREECIV_DEBUG
3314 const char *punit_logname = unit_rule_name(punit);
3315#endif /* FREECIV_DEBUG */
3316 struct tile *utile = unit_tile(punit);
3317
3321
3322 /* The gold was paid back when the unit removal made
3323 * uk_rem_gold_callback() run as the unit's removal call back. */
3324
3325 notify_player(pplayer, utile, E_UNIT_LOST_MISC, ftc_server,
3326 _("Not enough gold. %s disbanded."),
3327 punit_link);
3328 log_debug("%s: unit sold (%s)", player_name(pplayer),
3330 } else {
3331 /* Not able to get rid of punit */
3332 return nullptr;
3333 }
3334 }
3335
3337
3338 return punit;
3339}
3340
3341/**********************************************************************/
3345{
3346 struct cityimpr_list *pimprlist;
3347 bool sell_unit = TRUE;
3348
3349 if (!pplayer) {
3350 return FALSE;
3351 }
3352
3355
3356 city_list_iterate(pplayer->cities, pcity) {
3357 city_built_iterate(pcity, pimprove) {
3358 if (can_city_sell_building(pcity, pimprove)) {
3359 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3360
3361 ci->pcity = pcity;
3362 ci->pimprove = pimprove;
3364 }
3367
3368 unit_list_iterate(pplayer->units, punit) {
3369 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3371 }
3373
3374 while (pplayer->economic.gold < 0
3376 || unit_list_size(uk_rem_gold) > 0)) {
3378 || unit_list_size(uk_rem_gold) == 0) {
3380 } else {
3381 sell_random_unit(pplayer, uk_rem_gold);
3382 }
3384 }
3385
3386 /* Free remaining entries from list */
3388 FC_FREE(pimpr);
3390
3391 if (pplayer->economic.gold < 0) {
3392 /* If we get here it means the player has
3393 * negative gold. This should never happen. */
3394 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3395 player_name(pplayer), player_number(pplayer));
3396 }
3397
3400
3401 return pplayer->economic.gold >= 0;
3402}
3403
3404/**********************************************************************/
3408{
3409 if (!pplayer) {
3410 return FALSE;
3411 }
3412
3414
3415 unit_list_iterate(pplayer->units, punit) {
3416 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3418 }
3420
3421 while (pplayer->economic.gold < 0
3422 && sell_random_unit(pplayer, uk_rem_gold)) {
3423 /* All done in sell_random_unit() */
3424 }
3425
3426 if (pplayer->economic.gold < 0) {
3427 /* If we get here it means the player has
3428 * negative gold. This should never happen. */
3429 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3430 player_name(pplayer), player_number(pplayer));
3431 }
3432
3434
3435 return pplayer->economic.gold >= 0;
3436}
3437
3438/**********************************************************************/
3442{
3443 struct player *pplayer;
3444 struct cityimpr_list *pimprlist;
3445
3446 if (!pcity) {
3447 return TRUE;
3448 }
3449
3450 pplayer = city_owner(pcity);
3452
3453 /* Create a vector of all buildings that can be sold. */
3454 city_built_iterate(pcity, pimprove) {
3455 if (can_city_sell_building(pcity, pimprove)) {
3456 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3457
3458 ci->pcity = pcity;
3459 ci->pimprove = pimprove;
3461 }
3463
3464 /* Try to sell some buildings. */
3465 while (pplayer->economic.gold < 0
3466 && sell_random_building(pplayer, pimprlist)) {
3467 /* all done in sell_random_building */
3468 }
3469
3470 /* Free remaining entries from list */
3472 FC_FREE(pimpr);
3474
3476
3477 return pplayer->economic.gold >= 0;
3478}
3479
3480/**********************************************************************/
3489{
3490 struct player *pplayer;
3491
3492 if (!pcity) {
3493 return TRUE;
3494 }
3495
3496 pplayer = city_owner(pcity);
3498
3499 /* Create a vector of all supported units with gold upkeep. */
3500 unit_list_iterate(pcity->units_supported, punit) {
3501 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3503 }
3505
3506 /* Still not enough gold, so try "selling" some units. */
3507 while (pplayer->economic.gold < 0
3508 && sell_random_unit(pplayer, uk_rem_gold)) {
3509 /* All done in sell_random_unit() */
3510 }
3511
3512 /* If we get here the player has negative gold, but hopefully
3513 * another city will be able to pay the deficit, so continue. */
3514
3516
3517 return pplayer->economic.gold >= 0;
3518}
3519
3520/**********************************************************************/
3523static bool place_pollution(struct city *pcity, enum extra_cause cause)
3524{
3525 struct tile *ptile;
3526 struct tile *pcenter = city_tile(pcity);
3527 int city_radius_sq = city_map_radius_sq_get(pcity);
3528 int k = 100;
3529 const struct civ_map *nmap = &(wld.map);
3530
3531 while (k > 0) {
3532 /* Place pollution on a random city tile */
3533 int cx, cy;
3534 int tile_id = fc_rand(city_map_tiles(city_radius_sq));
3535 struct extra_type *pextra;
3536
3537 city_tile_index_to_xy(&cx, &cy, tile_id, city_radius_sq);
3538
3539 /* Check for a real map position */
3540 if (!(ptile = city_map_to_tile(nmap, pcenter, city_radius_sq, cx, cy))) {
3541 continue;
3542 }
3543
3544 pextra = rand_extra_for_tile(ptile, cause, FALSE);
3545
3546 if (pextra != nullptr && !tile_has_extra(ptile, pextra)) {
3547 tile_add_extra(ptile, pextra);
3548 update_tile_knowledge(ptile);
3549
3550 return TRUE;
3551 }
3552 k--;
3553 }
3554 log_debug("pollution not placed: city: %s", city_name_get(pcity));
3555
3556 return FALSE;
3557}
3558
3559/**********************************************************************/
3562static void check_pollution(struct city *pcity)
3563{
3564 if (fc_rand(100) < pcity->pollution) {
3567 _("Pollution near %s."), city_link(pcity));
3568 }
3569 }
3570}
3571
3572/**********************************************************************/
3579int city_incite_cost(struct player *pplayer, struct city *pcity)
3580{
3581 int dist, size;
3582 double cost; /* Intermediate values can get very large */
3583
3584 /* Gold factor */
3585 cost = city_owner(pcity)->economic.gold + game.server.base_incite_cost;
3586
3591
3592 /* Buildings */
3593 city_built_iterate(pcity, pimprove) {
3594 cost += impr_build_shield_cost(pcity, pimprove)
3597
3598 /* Stability bonuses */
3599 if (!city_unhappy(pcity)) {
3600 cost *= 2;
3601 }
3602 if (city_celebrating(pcity)) {
3603 cost *= 2;
3604 }
3605
3606 /* Buy back is cheap, conquered cities are also cheap */
3608 if (city_owner(pcity) != pcity->original) {
3609 if (pplayer == pcity->original) {
3610 cost /= 2; /* Buy back: 50% price reduction */
3611 } else {
3612 cost = cost * 2 / 3; /* Buy conquered: 33% price reduction */
3613 }
3614 }
3615 }
3616
3617 /* Distance from capital */
3618 /* Max penalty. Applied if there is no capital, or it's even further away. */
3619 dist = 32;
3621 if (is_capital(capital)) {
3622 int tmp = map_distance(capital->tile, pcity->tile);
3623
3624 if (tmp < dist) {
3625 dist = tmp;
3626 }
3627 }
3629
3633 - pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] * 3);
3634 cost *= size;
3636 cost = cost / (dist + 3);
3637
3639 int cost_per_citizen = cost / pcity->size;
3641 int tgt_cit = citizens_nation_get(pcity, pplayer->slot);
3642 int third_party = pcity->size - natives - tgt_cit;
3643
3644 cost = cost_per_citizen * (natives + 0.7 * third_party + 0.5 * tgt_cit);
3645 }
3646
3648 cost /= 100;
3649
3652 } else {
3653 return cost;
3654 }
3655}
3656
3657/**********************************************************************/
3661{
3662 /* Remember what this city is building last turn, so that on the next turn
3663 * the player can switch production to something else and then change it
3664 * back without penalty. This has to be updated _before_ production for
3665 * this turn is calculated, so that the penalty will apply if the player
3666 * changes production away from what has just been completed. This makes
3667 * sense if you consider what this value means: all the shields in the
3668 * city have been dedicated toward the project that was chosen last turn,
3669 * so the player shouldn't be penalized if the governor has to pick
3670 * something different. See city_change_production_penalty(). */
3671 pcity->changed_from = pcity->production;
3672
3673 log_debug("In %s, building %s. Beg of Turn shields = %d",
3675 pcity->before_change_shields);
3676}
3677
3678/**********************************************************************/
3682{
3683 pcity->disbanded_shields = 0;
3684 pcity->caravan_shields = 0;
3685}
3686
3687/**********************************************************************/
3692{
3694 pcity->before_change_shields = 0;
3695}
3696
3697/**********************************************************************/
3700static void update_city_activity(struct city *pcity)
3701{
3702 struct player *pplayer;
3703 struct government *gov;
3704 bool is_happy;
3705 bool is_celebrating;
3706
3707 if (!pcity) {
3708 return;
3709 }
3710
3711 pplayer = city_owner(pcity);
3715
3716 if (city_refresh(pcity)) {
3718 }
3719
3720 /* Reporting of celebrations rewritten, copying the treatment of disorder below,
3721 with the added rapture rounds count. 991219 -- Jing */
3722 if (city_build_stuff(pplayer, pcity)) {
3723 int saved_id;
3724 int revolution_turns;
3725
3726 pcity->history += city_history_gain(pcity);
3727
3728 /* History can decrease, but never go below zero */
3729 pcity->history = MAX(pcity->history, 0);
3730
3731 /* Keep old behavior when building new improvement could keep
3732 city celebrating */
3733 if (!is_happy) {
3735 }
3736
3738 pcity->rapture++;
3739
3740 /* Update city's celebrating counters */
3742 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3743 pcity->counter_values[pcount->index]++;
3744 }
3746
3747 if (pcity->rapture == 1) {
3749 _("Celebrations in your honor in %s."),
3750 city_link(pcity));
3751 }
3752 } else {
3753 if (pcity->rapture != 0) {
3755 _("Celebrations canceled in %s."),
3756 city_link(pcity));
3757 }
3758
3759 /* Update city's celebrating counters */
3761 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3762 pcity->counter_values[pcount->index] = 0;
3763 }
3765 pcity->rapture = 0;
3766 }
3767 pcity->was_happy = is_happy;
3768
3769 /* Handle the illness. */
3770 if (game.info.illness_on) {
3771 /* Recalculate city illness; illness due to trade has to be saved
3772 * within the city struct, as the client does not have all
3773 * the data to calculate it */
3774 pcity->server.illness
3775 = city_illness_calc(pcity, nullptr, nullptr,
3776 &(pcity->illness_trade), nullptr);
3777
3779 if (!city_illness_strike(pcity)) {
3780 /* Illness destroyed the city */
3781 return;
3782 }
3783 }
3784 }
3785
3786 /* City population updated here, after the rapture stuff above. --Jing */
3787 saved_id = pcity->id;
3788 pcity->had_famine = FALSE;
3789 city_populate(pcity, pplayer);
3790 if (player_city_by_number(pplayer, saved_id) == nullptr) {
3791 return;
3792 }
3793
3794 pcity->did_sell = FALSE;
3795 pcity->did_buy = FALSE;
3796 pcity->airlift = city_airlift_max(pcity);
3797 update_bulbs(pplayer, pcity->prod[O_SCIENCE], FALSE, FALSE);
3798
3800
3801 /* Update the treasury. */
3802 pplayer->economic.gold += pcity->surplus[O_GOLD];
3803
3804 /* FIXME: Nation level upkeep should be paid after ALL cities
3805 * have been processed, not after each individual city. */
3807 /* Unit upkeep was not included in city balance ->
3808 * not reduced from the city surplus. */
3810
3812 /* Building upkeep was not included in city balance ->
3813 * not reduced from the city surplus. */
3815 }
3816 }
3817
3818 /* Remember how much gold upkeep each unit was paid. */
3819 unit_list_iterate(pcity->units_supported, punit) {
3822
3823 if (pplayer->economic.gold < 0) {
3824 /* Not enough gold - we have to sell some buildings, and if that
3825 * is not enough, disband units with gold upkeep, taking into
3826 * account the setting of 'game.info.gold_upkeep_style':
3827 * GOLD_UPKEEP_CITY: Cities pay for buildings and units.
3828 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
3829 * for units.
3830 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
3831 switch (game.info.gold_upkeep_style) {
3832 case GOLD_UPKEEP_CITY:
3833 case GOLD_UPKEEP_MIXED:
3837 }
3838 break;
3839 case GOLD_UPKEEP_NATION:
3840 break;
3841 }
3842 }
3843
3845 if (city_unhappy(pcity)) {
3846 const char *revomsg;
3847
3848 pcity->anarchy++;
3849
3851 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3852 pcity->counter_values[pcount->index]++;
3853 }
3855
3856 if (pcity->anarchy == revolution_turns) {
3857 /* Revolution next turn if not dealt with */
3858 /* TRANS: preserve leading space; this string will be appended to
3859 * another sentence */
3860 revomsg = _(" Unrest threatens to spread beyond the city.");
3861 } else {
3862 revomsg = "";
3863 }
3864 if (pcity->anarchy == 1) {
3866 /* TRANS: second %s is an optional extra sentence */
3867 _("Civil disorder in %s.%s"),
3869 } else {
3871 /* TRANS: second %s is an optional extra sentence */
3872 _("CIVIL DISORDER CONTINUES in %s.%s"),
3874 }
3875 } else {
3876 if (pcity->anarchy != 0) {
3878 _("Order restored in %s."),
3879 city_link(pcity));
3880 }
3881 pcity->anarchy = 0;
3882
3884 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3885 pcity->counter_values[pcount->index] = 0;
3886 }
3888 }
3890
3891 send_city_info(nullptr, pcity);
3892
3893 if (revolution_turns > 0 && pcity->anarchy > revolution_turns) {
3895 /* TRANS: %s - government form, e.g., Democracy */
3896 _("The people have overthrown your %s, "
3897 "your country is in turmoil."),
3900 }
3901 if (city_refresh(pcity)) {
3903 }
3905 }
3906}
3907
3908/**********************************************************************/
3911static bool city_illness_check(const struct city * pcity)
3912{
3913 if (fc_rand(1000) < pcity->server.illness) {
3914 return TRUE;
3915 }
3916
3917 return FALSE;
3918}
3919
3920/**********************************************************************/
3924static bool disband_city(struct city *pcity)
3925{
3926 struct player *pplayer = city_owner(pcity);
3927 struct tile *ptile = pcity->tile;
3928 struct city *rcity = nullptr;
3929 const struct unit_type *utype = pcity->production.value.utype;
3930 struct unit *punit;
3931 int saved_id = pcity->id;
3932
3933 /* Find closest city other than pcity */
3934 rcity = find_closest_city(ptile, pcity, pplayer, FALSE, FALSE, FALSE, TRUE,
3935 FALSE, nullptr);
3936
3937 if (!rcity) {
3938 /* What should we do when we try to disband our only city? */
3939 notify_player(pplayer, ptile, E_CITY_CANTBUILD, ftc_server,
3940 _("%s can't build %s yet, "
3941 "as we can't disband our only city."),
3943 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3944 "pop_cost");
3945 if (!city_exist(saved_id)) {
3946 /* Script decided to remove even the last city */
3947 return TRUE;
3948 } else {
3949 return FALSE;
3950 }
3951 }
3952
3954
3955 /* "unit_built" script handler may have destroyed city. If so, we
3956 * assume something sensible happened to its units, and that the
3957 * script took care of announcing unit creation if required. */
3958 if (city_exist(saved_id)) {
3959 /* Shift all the units supported by pcity (including the new unit)
3960 * to rcity. transfer_city_units() does not make sure no units are
3961 * left floating without a transport, but since all units are
3962 * transferred this is not a problem. */
3963 transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity,
3964 pcity, -1, TRUE);
3965
3966 if (punit) {
3967 notify_player(pplayer, ptile, E_UNIT_BUILT, ftc_server,
3968 /* TRANS: "<city> is disbanded into Settler." */
3969 _("%s is disbanded into %s."),
3971 }
3972
3973 script_server_signal_emit("city_destroyed", pcity, pcity->owner, NULL);
3974
3975 if (!city_exist(saved_id)) {
3976 /* Already removed during the script */
3977 return TRUE;
3978 }
3980
3981 /* Since we've removed the city, we don't need to worry about
3982 * charging for production, disabling rally points, etc. */
3983 }
3984
3985 return TRUE;
3986}
3987
3988/**********************************************************************/
4036static float city_migration_score(struct city *pcity)
4037{
4038 float score = 0.0;
4039 int build_shield_cost = 0;
4040 bool has_wonder = FALSE;
4041
4042 if (!pcity) {
4043 return score;
4044 }
4045
4046 if (pcity->server.mgr_score_calc_turn == game.info.turn) {
4047 /* up-to-date migration score */
4048 return pcity->server.migration_score;
4049 }
4050
4051 /* feeling of the citizens */
4052 score = (city_size_get(pcity)
4053 + 1.00 * pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
4054 + 0.00 * pcity->feel[CITIZEN_CONTENT][FEELING_FINAL]
4055 - 0.25 * pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
4056 - 0.50 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
4057
4058 /* calculate shield build cost for all buildings */
4059 city_built_iterate(pcity, pimprove) {
4061 if (is_wonder(pimprove)) {
4062 /* this city has a wonder */
4063 has_wonder = TRUE;
4064 }
4066
4067 /* take shield costs of all buidings into account; normalized by 1000 */
4068 score *= (1 + (1 - exp(- (float) MAX(0, build_shield_cost) / 1000)) / 5);
4069 /* take trade into account; normalized by 100 */
4070 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_TRADE]) / 100))
4071 / 5);
4072 /* take luxury into account; normalized by 100 */
4073 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_LUXURY]) / 100))
4074 / 5);
4075 /* take science into account; normalized by 100 */
4076 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_SCIENCE]) / 100))
4077 / 5);
4078
4080
4081 /* Take food into account; the food surplus is clipped to values between
4082 * -10..20 and normalize by 10. Thus, the factor is between 0.9 and 1.2. */
4083 score *= (1 + (float) CLIP(-10, pcity->surplus[O_FOOD], 20) / 10 );
4084
4085 /* Reduce the score due to city illness (plague). The illness is given in
4086 * tenth of percent (0..1000) and normalized by 25. Thus, this factor is
4087 * between 0.6 (ill city) and 1.0 (health city). */
4088 score *= (100 - (float)city_illness_calc(pcity, nullptr, nullptr,
4089 nullptr, nullptr) / 25);
4090
4091 if (has_wonder) {
4092 /* People like wonders */
4093 score *= 1.25;
4094 }
4095
4096 if (is_capital(pcity)) {
4097 /* The capital is a magnet for the citizens */
4098 score *= 1.25;
4099 }
4100
4101 /* Take into account effects */
4102 score *= (1.0 + get_city_bonus(pcity, EFT_MIGRATION_PCT) / 100.0);
4103
4104 log_debug("[M] %s score: %.3f", city_name_get(pcity), score);
4105
4106 /* Set migration score for the city */
4107 pcity->server.migration_score = score;
4108 /* Set the turn, when the score was calculated */
4109 pcity->server.mgr_score_calc_turn = game.info.turn;
4110
4111 return score;
4112}
4113
4114/**********************************************************************/
4121 struct city *pcity_to)
4122{
4124 struct tile *ptile_from, *ptile_to;
4126 const char *nation_from, *nation_to;
4127 struct city *rcity = nullptr;
4128 int to_id = pcity_to->id;
4129 const struct civ_map *nmap = &(wld.map);
4130
4131 if (!pcity_from || !pcity_to) {
4132 return FALSE;
4133 }
4134
4138 /* We copy that, because city_link always returns the same pointer. */
4145
4146 /* Check food supply in the receiver city */
4148 bool migration = FALSE;
4149
4150 if (pcity_to->surplus[O_FOOD] >= game.info.food_cost) {
4151 migration = TRUE;
4152 } else {
4153 /* Check if there is a free tile for the new citizen which, when worked,
4154 * leads to zero or positive food surplus for the enlarged city */
4155 int max_food_tile = -1; /* no free tile */
4156
4158 city_tile(pcity_to), ptile) {
4159 if (city_can_work_tile(pcity_to, ptile)
4160 && tile_worked(ptile) != pcity_to) {
4161 /* Safest assumption is that city won't be celebrating once an
4162 * additional citizen is added */
4165 }
4167 if (max_food_tile >= 0
4168 && pcity_to->surplus[O_FOOD] + max_food_tile >= game.info.food_cost) {
4169 migration = TRUE;
4170 }
4171 }
4172
4173 if (!migration) {
4174 /* Insufficiency food in receiver city; no additional citizens */
4175 if (pplayer_from == pplayer_to) {
4176 /* Migration between one nation */
4178 /* TRANS: From <city1> to <city2>. */
4179 _("Migrants from %s can't go to %s because there is "
4180 "not enough food available!"),
4182 } else {
4183 /* Migration between different nations */
4185 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4186 _("Migrants from %s can't go to %s (%s) because there "
4187 "is not enough food available!"),
4190 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4191 _("Migrants from %s (%s) can't go to %s because there "
4192 "is not enough food available!"),
4194 }
4195
4196 return FALSE;
4197 }
4198 }
4199
4201 /* Receiver city can't grow */
4202 if (pplayer_from == pplayer_to) {
4203 /* Migration between one nation */
4205 /* TRANS: From <city1> to <city2>. */
4206 _("Migrants from %s can't go to %s because it needs "
4207 "an improvement to grow!"),
4209 } else {
4210 /* Migration between different nations */
4212 /* TRANS: From <city1> to <city2> of <city2 nation adjective>. */
4213 _("Migrants from %s can't go to %s (%s) because it "
4214 "needs an improvement to grow!"),
4217 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4218 _("Migrants from %s (%s) can't go to %s because it "
4219 "needs an improvement to grow!"),
4221 }
4222
4223 return FALSE;
4224 }
4225
4226 /* Reduce size of giver */
4227 if (city_size_get(pcity_from) == 1) {
4228
4230 /* Preserve nationality of city's only citizen */
4232 }
4233
4234 /* Do not destroy wonders */
4235 city_built_iterate(pcity_from, pimprove) {
4236 if (is_wonder(pimprove)) {
4237 return FALSE;
4238 }
4240
4241 /* Find closest city other of the same player than pcity_from */
4243 FALSE, FALSE, TRUE, FALSE, nullptr);
4244
4245 if (rcity) {
4246 int id = pcity_from->id;
4247
4248 /* Transfer all units to the closest city */
4250 pcity_from->units_supported, rcity, pcity_from,
4251 -1, TRUE);
4253
4254 script_server_signal_emit("city_size_change", pcity_from,
4255 (lua_Integer)(-1), "migration_from");
4256
4257 if (city_exist(id)) {
4258 script_server_signal_emit("city_destroyed", pcity_from,
4259 pcity_from->owner, nullptr);
4260
4261 if (city_exist(id)) {
4263 }
4264 }
4265
4267 _("%s was disbanded by its citizens."),
4268 name_from);
4269 } else {
4270 /* It's the only city of the nation */
4271 return FALSE;
4272 }
4273 } else {
4274 /* The migrants take half of the food box with them (this prevents
4275 * migration -> grow -> migration -> ... cycles) */
4276 pcity_from->food_stock /= 2;
4277
4279 /* Those citizens that are from the target nation are most
4280 * ones migrating. */
4281 if (citizens_nation_get(pcity_from, pplayer_to->slot) > 0) {
4283 } else if (!citizens_nation_get(pcity_from, pplayer_citizen->slot)) {
4284 /* No native citizens at all in the city, choose random foreigner */
4286
4288 }
4289 /* This should be followed by city_reduce_size(). */
4291 }
4292 city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
4294 if (city_refresh(pcity_from)) {
4296 }
4297 }
4298
4299 /* This should be _before_ the size of the city is increased. Thus, the
4300 * order of the messages is correct (1: migration; 2: increased size). */
4301 if (pplayer_from == pplayer_to) {
4302 /* Migration between one nation */
4304 /* TRANS: From <city1> to <city2>. */
4305 _("Migrants from %s moved to %s in search of a better "
4306 "life."), name_from, name_to);
4307 } else {
4308 /* Migration between different nations */
4310 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4311 _("Migrants from %s moved to %s (%s) in search of a "
4312 "better life."),
4315 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4316 _("Migrants from %s (%s) moved to %s in search of a "
4317 "better life."),
4319 }
4320
4321 /* Increase size of receiver city */
4322 if (city_exist(to_id)) {
4324
4325 if (city_exist(to_id)) {
4328 if (city_refresh(pcity_to)) {
4330 }
4331 if (incr_success) {
4332 script_server_signal_emit("city_size_change", pcity_to,
4333 (lua_Integer)1, "migration_to");
4334 }
4335 }
4336 }
4337
4338 log_debug("[M] T%d migration successful (%s -> %s)",
4340
4341 return TRUE;
4342}
4343
4344/**********************************************************************/
4366{
4367 bool internat = FALSE;
4368
4369 if (!game.server.migration) {
4370 return FALSE;
4371 }
4372
4374 || (game.server.mgr_worldchance <= 0
4375 && game.server.mgr_nationchance <= 0)) {
4376 return FALSE;
4377 }
4378
4379 /* check for migration */
4380 players_iterate(pplayer) {
4381 if (!pplayer->cities) {
4382 continue;
4383 }
4384
4385 if (check_city_migrations_player(pplayer)) {
4386 internat = TRUE;
4387 }
4389
4390 return internat;
4391}
4392
4393/**********************************************************************/
4398 struct player *pplayer = city_owner(pcity);
4399 struct tile *ptile = city_tile(pcity);
4400
4401 fc_assert_ret_val(pcity != nullptr, FALSE);
4402
4403 if (pcity->food_stock > 0) {
4404 pcity->food_stock = 0;
4405
4406 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4407 /* TRANS: %s is a city name */
4408 _("All stored food destroyed in %s."), city_link(pcity));
4409
4410 return TRUE;
4411 }
4412
4413 return FALSE;
4414}
4415
4416/**********************************************************************/
4419static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
4420{
4421 struct player *pplayer = city_owner(pcity);
4422 struct tile *ptile = city_tile(pcity);
4424
4426
4427 notify_player(pplayer, ptile, E_DISASTER,
4428 ftc_server,
4429 /* TRANS: Disasters such as Earthquake */
4430 _("%s was hit by %s."), city_name_get(pcity),
4432
4434 if (pplayer->economic.gold > 0 && pcity->prod[O_TRADE] > 0) {
4435 int amount = pcity->prod[O_TRADE] * 5;
4436
4437 amount = MIN(pplayer->economic.gold, amount);
4438 pplayer->economic.gold -= amount;
4439 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4440 PL_("Robbery in %s. %d gold stolen.",
4441 "Robbery in %s. %d gold stolen.", amount),
4444 }
4445 }
4446
4449 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4450 _("Pollution near %s."), city_link(pcity));
4452 }
4453 }
4454
4457 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4458 _("Fallout near %s."), city_link(pcity));
4460 }
4461 }
4462
4465 && pcity->size > 1)) {
4466 if (!city_reduce_size(pcity, 1, nullptr, "disaster")) {
4467 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4468 /* TRANS: "Industrial Accident destroys Bogota entirely." */
4469 _("%s destroys %s entirely."),
4471 pcity = nullptr;
4472 } else {
4473 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4474 /* TRANS: "Nuclear Accident ... Montreal." */
4475 _("%s causes population loss in %s."),
4477 }
4478
4480 }
4481
4483 int total = 0;
4484 struct impr_type *imprs[B_LAST];
4485
4486 city_built_iterate(pcity, pimprove) {
4487 if (is_improvement(pimprove)
4488 && !improvement_has_flag(pimprove, IF_DISASTER_PROOF)) {
4489 imprs[total++] = pimprove;
4490 }
4492
4493 if (total > 0) {
4494 int num = fc_rand(total);
4495
4496 building_lost(pcity, imprs[num], "disaster", nullptr);
4497
4498 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4499 /* TRANS: second %s is the name of a city improvement */
4500 _("%s destroys %s in %s."),
4503 city_link(pcity));
4504
4506 }
4507 }
4508
4512 }
4513 }
4514
4516 if (pcity->shield_stock > 0) {
4517 char prod[256];
4518
4519 pcity->shield_stock = 0;
4520 nullify_prechange_production(pcity); /* Make it impossible to recover */
4521
4522 universal_name_translation(&pcity->production, prod, sizeof(prod));
4523 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4524 /* TRANS: "Production of Colossus in Rhodes destroyed." */
4525 _("Production of %s in %s destroyed."),
4526 prod, city_link(pcity));
4527
4529 }
4530 }
4531
4532 script_server_signal_emit("disaster_occurred", pdis, pcity,
4534 script_server_signal_emit("disaster", pdis, pcity);
4535}
4536
4537/**********************************************************************/
4541{
4542 if (game.info.disasters == 0) {
4543 /* Shortcut out as no disaster is possible. */
4544 return;
4545 }
4546
4547 players_iterate(pplayer) {
4548 /* Safe city iterator needed as disaster may destroy city */
4549 city_list_iterate_safe(pplayer->cities, pcity) {
4550 int id = pcity->id;
4551
4553 if (city_exist(id)) {
4554 /* City survived earlier disasters. */
4555 int probability = game.info.disasters * pdis->frequency;
4556 int result = fc_rand(DISASTER_BASE_RARITY);
4557
4558 if (result < probability) {
4561 }
4562 }
4563 }
4567}
4568
4569/**********************************************************************/
4577static bool check_city_migrations_player(const struct player *pplayer)
4578{
4582 float score_from, score_tmp, weight;
4583 int dist, mgr_dist;
4584 bool internat = FALSE;
4585
4586 /* Check for each city
4587 * city_list_iterate_safe() must be used because we could
4588 * remove one city from the list */
4590 /* No migration out of the capital */
4591 if (is_capital(pcity)) {
4592 continue;
4593 }
4594
4595 /* Check only each (game.server.mgr_turninterval) turn
4596 * (counted from the funding turn) and do not migrate
4597 * the same turn a city is founded */
4598 if (game.info.turn == pcity->turn_founded
4599 || ((game.info.turn - pcity->turn_founded)
4600 % game.server.mgr_turninterval) != 0) {
4601 continue;
4602 }
4603
4606 best_city_player = nullptr;
4607 best_city_world = nullptr;
4608
4609 /* Score of the actual city
4610 * taking into account a persistence factor of 3 */
4612
4613 log_debug("[M] T%d check city: %s score: %6.3f (%s)",
4615 player_name(pplayer));
4616
4617 /* Consider all cities within the maximal possible distance
4618 * (= CITY_MAP_MAX_RADIUS + GAME_MAX_MGR_DISTANCE) */
4621 acity = tile_city(ptile);
4622
4623 if (!acity || acity == pcity) {
4624 /* No city or the city in the center */
4625 continue;
4626 }
4627
4628 /* Calculate the migration distance. The value of
4629 * game.server.mgr_distance is added to the current city radius. If the
4630 * distance between both cities is lower or equal than this value,
4631 * migration is possible. */
4634
4635 /* distance between the two cities */
4637
4638 if (dist > mgr_dist) {
4639 /* Too far away */
4640 continue;
4641 }
4642
4643 /* Score of the second city, weighted by the distance */
4644 weight = ((float) (mgr_dist + 1 - dist) / (float) (mgr_dist + 1));
4646
4647 log_debug("[M] T%d - compare city: %s (%s) dist: %d mgr_dist: %d "
4648 "score: %6.3f", game.info.turn, city_name_get(acity),
4650
4651 if (game.server.mgr_nationchance > 0 && city_owner(acity) == pplayer) {
4652 /* Migration between cities of the same owner */
4654 /* Select the best! */
4657
4658 log_debug("[M] T%d - best city (player): %s (%s) score: "
4659 "%6.3f (> %6.3f)", game.info.turn,
4662 }
4663 } else if (game.server.mgr_worldchance > 0
4664 && city_owner(acity) != pplayer) {
4665 /* Migration between cities of different owners */
4667 /* Modify the score if citizens could migrate to a city of their
4668 * original nation. */
4669 if (citizens_nation_get(pcity, city_owner(acity)->slot) > 0) {
4670 score_tmp *= 2;
4671 }
4672 }
4673
4675 /* Select the best! */
4678
4679 log_debug("[M] T%d - best city (world): %s (%s) score: "
4680 "%6.3f (> %6.3f)", game.info.turn,
4684 }
4685 }
4687
4688 if (best_city_player != nullptr) {
4689 /* First, do the migration within one nation */
4690 if (fc_rand(100) >= game.server.mgr_nationchance) {
4691 /* No migration */
4692 /* N.B.: city_link() always returns the same pointer. */
4695 _("Citizens of %s are thinking about migrating to %s "
4696 "for a better life."),
4698 } else {
4700 }
4701
4702 /* Stop here */
4703 continue;
4704 }
4705
4706 if (best_city_world != nullptr) {
4707 /* Second, do the migration between all nations */
4708 if (fc_rand(100) >= game.server.mgr_worldchance) {
4709 const char *nname;
4710
4712 /* No migration */
4713 /* N.B.: city_link() always returns the same pointer. */
4716 /* TRANS: <city1> to <city2> (<city2 nation adjective>). */
4717 _("Citizens of %s are thinking about migrating to %s "
4718 "(%s) for a better life."),
4720 } else {
4722 internat = TRUE;
4723 }
4724
4725 /* Stop here */
4726 continue;
4727 }
4729
4730 return internat;
4731}
4732
4733/**********************************************************************/
4737{
4738 pcity->style = city_style(pcity);
4739}
4740
4741/**********************************************************************/
4746{
4748 struct packet_city_update_counters packet;
4749
4750 packet.city = pcity->id;
4751
4753
4754 packet.count = counter_count;
4755 for (i = 0; i < counter_count; i++) {
4756 packet.counters[i] = pcity->counter_values[i];
4757 }
4758
4761}
4762
4763/**********************************************************************/
4766void city_tc_effect_refresh(struct player *pplayer)
4767{
4768 const struct civ_map *nmap = &(wld.map);
4769
4770 city_list_iterate(pplayer->cities, pcity) {
4771 bool changed = FALSE;
4772
4774 city_tile(pcity), ptile, idx, x, y) {
4775 if (ptile->worked == pcity
4776 && get_city_tile_output_bonus(pcity, ptile, nullptr,
4777 EFT_TILE_WORKABLE) <= 0) {
4779 pcity->specialists[DEFAULT_SPECIALIST]++;
4780 changed = TRUE;
4781 }
4783
4784 if (changed) {
4786 send_city_info(nullptr, pcity);
4787 }
4789}
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:3707
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:3911
static void uk_rem_gold_append(struct unit *punit)
Definition cityturn.c:3225
static void city_refresh_after_city_size_increase(struct city *pcity, struct player *nationality, bool aaw)
Definition cityturn.c:1026
static bool worklist_change_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2301
void remove_obsolete_buildings(struct player *pplayer)
Definition cityturn.c:270
static bool city_build_stuff(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3125
int city_shrink_granary_savings(const struct city *pcity)
Definition cityturn.c:892
static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
Definition cityturn.c:4419
static bool city_distribute_surplus_shields(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2656
static void unit_list_referred_destroy(struct unit_list *punitlist)
Definition cityturn.c:3238
static bool place_pollution(struct city *pcity, enum extra_cause cause)
Definition cityturn.c:3523
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2519
static void uk_rem_gold_callback(struct unit *punit)
Definition cityturn.c:3204
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:366
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:197
static struct unit_list * uk_rem_gold
Definition cityturn.c:93
static bool city_balance_treasury_buildings(struct city *pcity)
Definition cityturn.c:3441
static void update_city_activity(struct city *pcity)
Definition cityturn.c:3700
static void upgrade_unit_prod(struct city *pcity)
Definition cityturn.c:2632
static float city_migration_score(struct city *pcity)
Definition cityturn.c:4036
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3691
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4397
static bool city_increase_size(struct city *pcity, bool natural_growth, Specialist_type_id sid)
Definition cityturn.c:918
bool check_city_migrations(void)
Definition cityturn.c:4365
static void upgrade_building_prod(struct city *pcity)
Definition cityturn.c:2585
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3344
static citizens city_reduce_specialists(struct city *pcity, citizens change)
Definition cityturn.c:718
static void city_global_turn_notify(struct conn_list *dest)
Definition cityturn.c:490
static void city_populate(struct city *pcity, struct player *nationality)
Definition cityturn.c:1119
static void define_orig_production_values(struct city *pcity)
Definition cityturn.c:3660
void city_repair_size(struct city *pcity, int change)
Definition cityturn.c:851
#define cityimpr_list_iterate(cityimprlist, pcityimpr)
Definition cityturn.c:127
void city_counters_refresh(struct city *pcity)
Definition cityturn.c:4745
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:686
static bool city_build_building(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2737
static struct unit static const struct impr_type * building_upgrades_to(struct city *pcity, const struct impr_type *pimprove)
Definition cityturn.c:2564
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:576
static struct unit * sell_random_unit(struct player *pplayer, struct unit_list *punitlist)
Definition cityturn.c:3261
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3579
static void nullify_caravan_and_disband_plus(struct city *pcity)
Definition cityturn.c:3681
static bool sell_random_building(struct player *pplayer, struct cityimpr_list *imprs)
Definition cityturn.c:3158
static bool disband_city(struct city *pcity)
Definition cityturn.c:3924
void update_city_activities(struct player *pplayer)
Definition cityturn.c:602
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:762
#define cityimpr_list_iterate_end
Definition cityturn.c:129
bool city_refresh(struct city *pcity)
Definition cityturn.c:158
static void city_turn_notify(const struct city *pcity, struct conn_list *dest, const struct player *cache_for_player)
Definition cityturn.c:511
static void city_shrink_reset_foodbox(struct city *pcity, int new_size)
Definition cityturn.c:905
void apply_cmresult_to_city(struct city *pcity, const struct cm_result *cmr)
Definition cityturn.c:281
bool player_balance_treasury_units(struct player *pplayer)
Definition cityturn.c:3407
void city_style_refresh(struct city *pcity)
Definition cityturn.c:4736
static bool city_balance_treasury_units(struct city *pcity)
Definition cityturn.c:3488
static const struct unit_type * unit_upgrades_to(struct city *pcity, const struct unit_type *id)
Definition cityturn.c:2610
static bool do_city_migration(struct city *pcity_from, struct city *pcity_to)
Definition cityturn.c:4120
static struct city_list * city_refresh_queue
Definition cityturn.c:87
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:182
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4766
static void check_pollution(struct city *pcity)
Definition cityturn.c:3562
void check_disasters(void)
Definition cityturn.c:4540
static void set_default_city_manager(struct cm_parameter *cmp, struct city *pcity)
Definition cityturn.c:313
static citizens city_reduce_workers(struct city *pcity, citizens change)
Definition cityturn.c:738
static bool worklist_item_postpone_req_vec(struct universal *target, struct city *pcity, struct player *pplayer, int saved_id)
Definition cityturn.c:1196
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:2898
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, Specialist_type_id sid, const char *reason)
Definition cityturn.c:1067
void city_refresh_queue_processing(void)
Definition cityturn.c:213
int city_growth_granary_savings(const struct city *pcity)
Definition cityturn.c:878
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:235
static bool check_city_migrations_player(const struct player *pplayer)
Definition cityturn.c:4577
static bool city_build_unit(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2959
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:76
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:90
int Tech_type_id
Definition fc_types.h:237
unsigned char citizens
Definition fc_types.h:248
@ RPT_CERTAIN
Definition fc_types.h:515
@ RPT_POSSIBLE
Definition fc_types.h:514
int Specialist_type_id
Definition fc_types.h:235
#define MAX_LEN_NAME
Definition fc_types.h:67
#define CITY_MAP_MAX_RADIUS
Definition fc_types.h:84
@ O_SHIELD
Definition fc_types.h:102
@ O_FOOD
Definition fc_types.h:102
@ O_TRADE
Definition fc_types.h:102
@ O_SCIENCE
Definition fc_types.h:102
@ O_LUXURY
Definition fc_types.h:102
@ O_GOLD
Definition fc_types.h:102
enum output_type_id Output_type_id
Definition fc_types.h:238
#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:470
const char * nation_group_name_translation(const struct nation_group *pgroup)
Definition nation.c:1128
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:839
const char * player_name(const struct player *pplayer)
Definition player.c:900
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1211
const char * diplrel_name_translation(int value)
Definition player.c:1639
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:439
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
#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:119
struct impr_type * pimprove
Definition cityturn.c:120
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:593
universals_u value
Definition fc_types.h:592
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:241
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
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:535
const struct impr_type * building
Definition fc_types.h:528
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