Freeciv-3.3
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 = NULL;
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 = NULL;
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 (NULL == city_refresh_queue) {
202 return;
203 }
204
206 pcity->server.needs_refresh = TRUE;
207}
208
209/**********************************************************************/
214{
215 if (NULL == city_refresh_queue) {
216 return;
217 }
218
220 if (pcity->server.needs_refresh) {
221 if (city_refresh(pcity)) {
223 }
225 }
227
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, NULL); /* 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 (NULL == pwork) {
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 = NULL;
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 (NULL != cache_for_player) {
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 (NULL != cache_for_player) {
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 (NULL != cache_for_player) {
567 }
568 }
569 }
570}
571
572/**********************************************************************/
577{
578 if (NULL != pconn) {
579 struct player *pplayer = conn_get_player(pconn);
580
581 if (NULL != pplayer) {
582 city_list_iterate(pplayer->cities, pcity) {
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(NULL != pplayer->cities);
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 != NULL) {
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, NULL)) {
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
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. */
704 NULL, NULL, NULL, NULL);
705
707 /* No forced action was able to kill the unit. Finish the job. */
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, NULL); /* 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. */
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 != NULL) {
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/**********************************************************************/
905static void city_reset_foodbox(struct city *pcity, int new_size,
906 bool shrink)
907{
908 int savings_pct = ( shrink
911
912 pcity->food_stock = (city_granary_size(new_size) * savings_pct) / 100;
913}
914
915/**********************************************************************/
920static bool city_increase_size(struct city *pcity)
921{
922 int new_food;
924 bool have_square = FALSE;
925 bool rapture_grow = city_rapture_grow(pcity); /* Check before size increase! */
926 struct tile *pcenter = city_tile(pcity);
927 struct player *powner = city_owner(pcity);
928 const struct impr_type *pimprove = pcity->production.value.building;
929 const struct civ_map *nmap = &(wld.map);
930
932 /* Need improvement */
936 _("%s needs %s (being built) to grow beyond size %d."),
940 } else {
942 _("%s needs an improvement to grow beyond size %d."),
944 }
945 /* Granary can only hold so much */
947 * (100 * 100 - game.server.aqueductloss * (100 - savings_pct))
948 / (100 * 100));
949 pcity->food_stock = MIN(pcity->food_stock, new_food);
950
951 return FALSE;
952 }
953
955
956 /* Do not empty food stock if city is growing by celebrating */
957 if (rapture_grow) {
959 } else {
961 }
962 pcity->food_stock = MIN(pcity->food_stock, new_food);
963
964 /* If there is enough food, and the city is big enough,
965 * make new citizens into scientists or taxmen -- Massimo */
966
967 /* Ignore food if no square can be worked */
969 ptile, _index, _x, _y) {
970 if (tile_worked(ptile) != pcity /* Quick test */
971 && city_can_work_tile(pcity, ptile)) {
973 }
975
976 if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
978 pcity->specialists[best_specialist(O_SCIENCE, pcity)]++;
979 } else if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
981 pcity->specialists[best_specialist(O_GOLD, pcity)]++;
982 } else {
983 pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
984 }
985
986 /* Deprecated signal. Connect your lua functions to "city_size_change" that's
987 * emitted from calling functions which know the 'reason' of the increase. */
988 script_server_signal_emit("city_growth", pcity,
990
991 return TRUE;
992}
993
994/**********************************************************************/
998 struct player *nationality)
999{
1000 struct player *powner = city_owner(pcity);
1001
1002 /* Update citizens. */
1003 citizens_update(pcity, nationality);
1004
1005 /* Refresh the city data; this also checks the squared city radius. */
1007
1009
1010 /* Update cities that have trade routes with us */
1012 if (city_refresh(pcity2)) {
1013 /* This should never happen, but if it does, make sure not to
1014 * leave workers outside city radius. */
1016 }
1018
1020 _("%s grows to size %d."),
1022
1024
1025 sync_cities();
1026}
1027
1028/**********************************************************************/
1032 struct player *nationality, const char *reason)
1033{
1034 int change = size - city_size_get(pcity);
1035
1036 if (change > 0) {
1038 int real_change;
1040 int id = pcity->id;
1041
1042 /* Increase city size until size reached, or increase fails */
1044 /* TODO: This is currently needed only because there's
1045 * deprecated script signal "city_growth" emitted.
1046 * Check the need after signal has been dropped completely. */
1047 if (!city_exist(id)) {
1048 return FALSE;
1049 }
1050
1051 current_size++;
1052 }
1053
1055
1057
1058 if (real_change != 0 && reason != NULL) {
1059 script_server_signal_emit("city_size_change", pcity,
1061
1062 if (!city_exist(id)) {
1063 return FALSE;
1064 }
1065 }
1066 } else if (change < 0) {
1067 /* We assume that city_change_size() is never called because
1068 * of enemy actions. If that changes, enemy must be passed
1069 * to city_reduce_size() */
1070 return city_reduce_size(pcity, -change, NULL, reason);
1071 }
1072
1074
1075 return TRUE;
1076}
1077
1078/**********************************************************************/
1082static void city_populate(struct city *pcity, struct player *nationality)
1083{
1084 int saved_id = pcity->id;
1085 int granary_size = city_granary_size(city_size_get(pcity));
1086
1087 pcity->food_stock += pcity->surplus[O_FOOD];
1088 if (pcity->food_stock >= granary_size || city_rapture_grow(pcity)) {
1092 _("A recent plague outbreak prevents growth in %s."),
1093 city_link(pcity));
1094 /* Lose excess food */
1095 pcity->food_stock = MIN(pcity->food_stock, granary_size);
1096 } else {
1097 bool success;
1098
1101
1102 if (success) {
1104 script_server_signal_emit("city_size_change", pcity,
1105 (lua_Integer)1, "growth");
1106 }
1107 }
1108 } else if (pcity->food_stock < 0) {
1109 /* FIXME: should this depend on units with ability to build
1110 * cities or on units that require food in upkeep?
1111 * I'll assume citybuilders (units that 'contain' 1 pop) -- sjolie
1112 * The above may make more logical sense, but in game terms
1113 * you want to disband a unit that is draining your food
1114 * reserves. Hence, I'll assume food upkeep > 0 units. -- jjm
1115 */
1116 unit_list_iterate_safe(pcity->units_supported, punit) {
1117 if (punit->upkeep[O_FOOD] > 0) {
1118 const char *punit_link = unit_tile_link(punit);
1119
1124 _("Famine feared in %s, %s lost!"),
1126 }
1127
1128 if (city_exist(saved_id)) {
1130 }
1131
1132 return;
1133 }
1135 if (city_size_get(pcity) > 1) {
1138 _("Famine causes population loss in %s."),
1139 city_link(pcity));
1140 } else {
1143 _("Famine destroys %s entirely."),
1144 city_link(pcity));
1145 }
1147 if (city_reduce_size(pcity, 1, NULL, "famine")) {
1148 pcity->had_famine = TRUE;
1149 }
1150 }
1151}
1152
1153/**********************************************************************/
1160 struct city *pcity,
1161 struct player *pplayer,
1162 int saved_id)
1163{
1164 const void *ptarget;
1165 const char *tgt_name;
1166 const struct requirement_vector *build_reqs;
1167 const char *signal_name;
1168 const struct req_context city_ctxt = {
1169 .player = pplayer,
1170 .city = pcity,
1171 .tile = city_tile(pcity)
1172 /* FIXME: Setting .unittype is currently redundant,
1173 * but can_city_build_unit_direct() does it */
1174 };
1175 bool purge = FALSE;
1176 bool known = FALSE;
1177
1178 if (pcity->wlcb == WLCB_ALWAYS_PURGE) {
1179 return TRUE;
1180 }
1181
1182 switch (target->kind) {
1183 case VUT_UTYPE:
1184 ptarget = target->value.utype;
1185 build_reqs = &target->value.utype->build_reqs;
1187 signal_name = "unit_cant_be_built";
1188 break;
1189 case VUT_IMPROVEMENT:
1190 ptarget = target->value.building;
1191 build_reqs = &target->value.building->reqs;
1193 signal_name = "building_cant_be_built";
1194 break;
1195 default:
1197 || target->kind == VUT_UTYPE), FALSE);
1198 return FALSE;
1199 }
1200
1201 if (pcity->wlcb == WLCB_ALWAYS_POSTPONE) {
1202 notify_player(pplayer, city_tile(pcity),
1204 _("%s can't build %s from the worklist. "
1205 "Postponing..."),
1207 tgt_name);
1208 return FALSE;
1209 }
1210
1211 requirement_vector_iterate(build_reqs, preq) {
1213 known = TRUE;
1214 switch (preq->source.kind) {
1215 case VUT_COUNTER:
1216 if (preq->present) {
1217 notify_player(pplayer, city_tile(pcity),
1219 _("%s can't build %s from the worklist; "
1220 "counter %s value's checkpoint do not met "
1221 "Postponing..."),
1223 tgt_name,
1225 (preq->source.value.counter));
1226 } else {
1227 purge = TRUE;
1228 }
1229 break;
1230 case VUT_ADVANCE:
1231 if (preq->present) {
1232 notify_player(pplayer, city_tile(pcity),
1234 _("%s can't build %s from the worklist; "
1235 "tech %s not yet available. Postponing..."),
1237 tgt_name,
1239 (preq->source.value.advance));
1241 pcity, "need_tech");
1242 } else {
1243 /* While techs can be unlearned, this isn't useful feedback */
1244 purge = TRUE;
1245 }
1246 break;
1247 case VUT_TECHFLAG:
1248 if (preq->present) {
1249 notify_player(pplayer, city_tile(pcity),
1251 _("%s can't build %s from the worklist; "
1252 "no tech with flag \"%s\" yet available. "
1253 "Postponing..."),
1255 tgt_name,
1256 tech_flag_id_name(preq->source.value.techflag));
1258 pcity, "need_techflag");
1259 } else {
1260 /* While techs can be unlearned, this isn't useful feedback */
1261 purge = TRUE;
1262 }
1263 break;
1264 case VUT_IMPROVEMENT:
1265 case VUT_SITE:
1266 if (preq->range == REQ_RANGE_LOCAL) {
1267 /* Building itself is never going to change */
1268 purge = TRUE;
1269 } else {
1270 if (preq->present) {
1271 notify_player(pplayer, city_tile(pcity),
1273 _("%s can't build %s from the worklist; "
1274 "need to have %s first. Postponing..."),
1276 tgt_name,
1278 preq->source.value.building));
1280 pcity, "need_building");
1281 } else {
1282 notify_player(pplayer, city_tile(pcity),
1284 _("%s can't build %s from the worklist; "
1285 "need to not have %s. Postponing..."),
1287 tgt_name,
1289 preq->source.value.building));
1291 pcity, "have_building");
1292 }
1293 }
1294 break;
1295 case VUT_IMPR_GENUS:
1296 if (preq->range == REQ_RANGE_LOCAL) {
1297 /* Building's own genus is never going to change */
1298 purge = TRUE;
1299 } else {
1300 if (preq->present) {
1301 notify_player(pplayer, city_tile(pcity),
1303 _("%s can't build %s from the worklist; "
1304 "need to have %s first. Postponing..."),
1306 tgt_name,
1308 preq->source.value.impr_genus));
1310 pcity, "need_building_genus");
1311 } else {
1312 notify_player(pplayer, city_tile(pcity),
1314 _("%s can't build %s from the worklist; "
1315 "need to not have %s. Postponing..."),
1317 tgt_name,
1319 preq->source.value.impr_genus));
1321 pcity, "have_building_genus");
1322 }
1323 }
1324 break;
1325 case VUT_IMPR_FLAG:
1326 if (preq->range == REQ_RANGE_LOCAL) {
1327 /* Building's own flags are never going to change */
1328 purge = TRUE;
1329 } else {
1330 if (preq->present) {
1331 notify_player(pplayer, city_tile(pcity),
1333 _("%s can't build %s from the worklist; "
1334 "need to have %s first. Postponing..."),
1336 tgt_name,
1338 preq->source.value.impr_flag));
1340 pcity, "need_building_flag");
1341 } else {
1342 notify_player(pplayer, city_tile(pcity),
1344 _("%s can't build %s from the worklist; "
1345 "need to not have %s. Postponing..."),
1347 tgt_name,
1349 preq->source.value.impr_flag));
1351 pcity, "have_building_flag");
1352 }
1353 }
1354 break;
1355 case VUT_PLAYER_FLAG:
1356 if (preq->present) {
1357 notify_player(pplayer, city_tile(pcity),
1359 _("%s can't build %s from the worklist; "
1360 "need to have %s first. Postponing..."),
1362 tgt_name,
1364 preq->source.value.plr_flag));
1366 pcity, "need_player_flag");
1367 } else {
1368 notify_player(pplayer, city_tile(pcity),
1370 _("%s can't build %s from the worklist; "
1371 "need to not have %s. Postponing..."),
1373 tgt_name,
1375 preq->source.value.plr_flag));
1377 pcity, "have_player_flag");
1378 }
1379 break;
1380 case VUT_PLAYER_STATE:
1381 purge = TRUE;
1382 break;
1383 case VUT_GOVERNMENT:
1384 if (preq->present) {
1385 notify_player(pplayer, city_tile(pcity),
1387 _("%s can't build %s from the worklist; "
1388 "it needs %s government. Postponing..."),
1390 tgt_name,
1391 government_name_translation(preq->source.value.govern));
1393 pcity, "need_government");
1394 } else {
1395 notify_player(pplayer, city_tile(pcity),
1397 _("%s can't build %s from the worklist; "
1398 "it cannot have %s government. Postponing..."),
1400 tgt_name,
1401 government_name_translation(preq->source.value.govern));
1403 pcity, "have_government");
1404 }
1405 break;
1406 case VUT_ACHIEVEMENT:
1407 if (preq->present) {
1408 notify_player(pplayer, city_tile(pcity),
1410 _("%s can't build %s from the worklist; "
1411 "it needs \"%s\" achievement. Postponing..."),
1413 tgt_name,
1414 achievement_name_translation(preq->source.value.achievement));
1416 pcity, "need_achievement");
1417 } else {
1418 /* Can't unachieve things. */
1419 purge = TRUE;
1420 }
1421 break;
1422 case VUT_EXTRA:
1423 if (preq->present) {
1424 notify_player(pplayer, city_tile(pcity),
1426 Q_("?extra:%s can't build %s from the worklist; "
1427 "%s is required. Postponing..."),
1429 tgt_name,
1430 extra_name_translation(preq->source.value.extra));
1432 pcity, "need_extra");
1433 } else {
1434 notify_player(pplayer, city_tile(pcity),
1436 Q_("?extra:%s can't build %s from the worklist; "
1437 "%s is prohibited. Postponing..."),
1439 tgt_name,
1440 extra_name_translation(preq->source.value.extra));
1442 pcity, "have_extra");
1443 }
1444 break;
1445 case VUT_GOOD:
1446 if (preq->present) {
1447 notify_player(pplayer, city_tile(pcity),
1449 Q_("?extra:%s can't build %s from the worklist; "
1450 "%s is required. Postponing..."),
1452 tgt_name,
1453 goods_name_translation(preq->source.value.good));
1455 pcity, "need_good");
1456 } else {
1457 notify_player(pplayer, city_tile(pcity),
1459 Q_("?extra:%s can't build %s from the worklist; "
1460 "%s is prohibited. Postponing..."),
1462 tgt_name,
1463 goods_name_translation(preq->source.value.good));
1465 pcity, "have_good");
1466 }
1467 break;
1468 case VUT_TERRAIN:
1469 if (preq->present) {
1470 notify_player(pplayer, city_tile(pcity),
1472 Q_("?terrain:%s can't build %s from the worklist; "
1473 "%s terrain is required. Postponing..."),
1475 tgt_name,
1476 terrain_name_translation(preq->source.value.terrain));
1478 pcity, "need_terrain");
1479 } else {
1480 notify_player(pplayer, city_tile(pcity),
1482 Q_("?terrain:%s can't build %s from the worklist; "
1483 "%s terrain is prohibited. Postponing..."),
1485 tgt_name,
1486 terrain_name_translation(preq->source.value.terrain));
1488 pcity, "have_terrain");
1489 }
1490 break;
1491 case VUT_NATION:
1492 if (preq->range < REQ_RANGE_TRADE_ROUTE
1493 || preq->range == REQ_RANGE_PLAYER) {
1494 /* At higher ranges, new players with their nations may arrive */
1495 purge = TRUE;
1496 } else {
1497 if (preq->present) {
1498 notify_player(pplayer, city_tile(pcity),
1500 /* TRANS: "%s nation" is adjective */
1501 Q_("?nation:%s can't build %s from the worklist; "
1502 "%s nation is required. Postponing..."),
1504 tgt_name,
1505 nation_adjective_translation(preq->source.value.nation));
1507 pcity, "need_nation");
1508 } else {
1509 notify_player(pplayer, city_tile(pcity),
1511 Q_("?nation:%s can't build %s from the worklist; "
1512 "%s nation is prohibited. Postponing..."),
1514 tgt_name,
1515 nation_adjective_translation(preq->source.value.nation));
1517 pcity, "have_nation");
1518 }
1519 }
1520 break;
1521 case VUT_NATIONGROUP:
1522 if (preq->range < REQ_RANGE_TRADE_ROUTE
1523 || preq->range == REQ_RANGE_PLAYER) {
1524 /* At higher ranges, new players with their nations may arrive */
1525 purge = TRUE;
1526 } else {
1527 if (preq->present) {
1528 notify_player(pplayer, city_tile(pcity),
1530 /* TRANS: "%s nation" is adjective */
1531 Q_("?ngroup:%s can't build %s from the worklist; "
1532 "%s nation is required. Postponing..."),
1534 tgt_name,
1535 nation_group_name_translation(preq->source.value.nationgroup));
1537 pcity, "need_nationgroup");
1538 } else {
1539 notify_player(pplayer, city_tile(pcity),
1541 Q_("?ngroup:%s can't build %s from the worklist; "
1542 "%s nation is prohibited. Postponing..."),
1544 tgt_name,
1545 nation_group_name_translation(preq->source.value.nationgroup));
1547 pcity, "have_nationgroup");
1548 }
1549 }
1550 break;
1551 case VUT_STYLE:
1552 /* FIXME: City styles sometimes change over time, but it isn't
1553 * entirely under player control. Probably better to purge
1554 * with useful explanation. */
1555 if (preq->present) {
1556 notify_player(pplayer, city_tile(pcity),
1558 _("%s can't build %s from the worklist; "
1559 "only %s style cities may build this. Postponing..."),
1561 tgt_name,
1562 style_name_translation(preq->source.value.style));
1564 pcity, "need_style");
1565 } else {
1566 notify_player(pplayer, city_tile(pcity),
1568 _("%s can't build %s from the worklist; "
1569 "%s style cities may not build this. Postponing..."),
1571 tgt_name,
1572 style_name_translation(preq->source.value.style));
1574 pcity, "have_style");
1575 }
1576 break;
1577 case VUT_NATIONALITY:
1578 /* FIXME: Changing citizen nationality is hard: purging might be
1579 * more useful in this case. */
1580 if (preq->present) {
1581 notify_player(pplayer, city_tile(pcity),
1583 /* TRANS: Latter %s is citizen nationality */
1584 _("%s can't build %s from the worklist; "
1585 "only city with %s may build this. Postponing..."),
1587 tgt_name,
1588 nation_plural_translation(preq->source.value.nationality));
1590 pcity, "need_nationality");
1591 } else {
1592 notify_player(pplayer, city_tile(pcity),
1594 /* TRANS: Latter %s is citizen nationality */
1595 _("%s can't build %s from the worklist; "
1596 "only city without %s may build this. Postponing..."),
1598 tgt_name,
1599 nation_plural_translation(preq->source.value.nationality));
1601 pcity, "have_nationality");
1602 }
1603 break;
1604 case VUT_ORIGINAL_OWNER:
1605 /* Original owner of this specific city won't change.
1606 * Update this when supporting ranges other than REQ_RANGE_CITY. */
1607 purge = TRUE;
1608 break;
1609 case VUT_DIPLREL:
1610 case VUT_DIPLREL_TILE: /* The tile owner is the city owner */
1611 case VUT_DIPLREL_TILE_O: /* The tile owner is the city owner */
1612 if (preq->present) {
1613 const char *reason;
1614
1615 notify_player(pplayer, city_tile(pcity),
1617 /* TRANS: '%s' is a wide range of relationships;
1618 * e.g., 'Peace', 'Never met', 'Foreign',
1619 * 'Hosts embassy', 'Provided Casus Belli' */
1620 _("%s can't build %s from the worklist; "
1621 "the relationship '%s' is required."
1622 " Postponing..."),
1624 tgt_name,
1626 preq->source.value.diplrel));
1627
1628 if (preq->source.kind == VUT_DIPLREL_TILE) {
1629 reason = "need_diplrel_tile";
1630 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1631 reason = "need_diplrel_tile_o";
1632 } else {
1633 fc_assert(preq->source.kind == VUT_DIPLREL);
1634 reason = "need_diplrel";
1635 }
1636
1638 pcity, reason);
1639 } else {
1640 const char *reason;
1641
1642 notify_player(pplayer, city_tile(pcity),
1644 _("%s can't build %s from the worklist; "
1645 "the relationship '%s' is prohibited."
1646 " Postponing..."),
1648 tgt_name,
1650 preq->source.value.diplrel));
1651
1652 if (preq->source.kind == VUT_DIPLREL_TILE) {
1653 reason = "have_diplrel_tile";
1654 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1655 reason = "have_diplrel_tile_o";
1656 } else {
1657 fc_assert(preq->source.kind == VUT_DIPLREL);
1658 reason = "have_diplrel";
1659 }
1660
1662 pcity, reason);
1663 }
1664 break;
1667 if (preq->present) {
1668 const char *reason;
1669
1670 notify_player(pplayer, city_tile(pcity),
1672 /* TRANS: '%s' is a wide range of relationships;
1673 * e.g., 'Peace', 'Never met', 'Foreign',
1674 * 'Hosts embassy', 'Provided Casus Belli' */
1675 _("%s can't build %s from the worklist; "
1676 "unit with the relationship '%s' is required."
1677 " Postponing..."),
1679 tgt_name,
1681 preq->source.value.diplrel));
1682
1683 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1684 reason = "need_diplrel_unitany";
1685 } else {
1686 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1687 reason = "need_diplrel_unitany_o";
1688 }
1689
1691 pcity, reason);
1692 } else {
1693 const char *reason;
1694
1695 notify_player(pplayer, city_tile(pcity),
1697 _("%s can't build %s from the worklist; "
1698 "unit with the relationship '%s' is prohibited."
1699 " Postponing..."),
1701 tgt_name,
1703 preq->source.value.diplrel));
1704
1705 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1706 reason = "have_diplrel_unitany";
1707 } else {
1708 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1709 reason = "have_diplrel_unitany_o";
1710 }
1711
1713 pcity, reason);
1714 }
1715 break;
1716 case VUT_MINSIZE:
1717 if (preq->present) {
1718 notify_player(pplayer, city_tile(pcity),
1720 _("%s can't build %s from the worklist; "
1721 "city must be of size %d or larger. "
1722 "Postponing..."),
1724 tgt_name,
1725 preq->source.value.minsize);
1727 pcity, "need_minsize");
1728 } else {
1729 notify_player(pplayer, city_tile(pcity),
1731 _("%s can't build %s from the worklist; "
1732 "city must be of size %d or smaller."
1733 "Postponing..."),
1735 tgt_name,
1736 (preq->source.value.minsize - 1));
1738 pcity, "need_minsize");
1739 }
1740 break;
1741 case VUT_MINCULTURE:
1742 if (preq->present) {
1743 notify_player(pplayer, city_tile(pcity),
1745 _("%s can't build %s from the worklist; "
1746 "city must have culture of %d. Postponing..."),
1748 tgt_name,
1749 preq->source.value.minculture);
1751 pcity, "need_minculture");
1752 } else {
1753 /* What has been written may not be unwritten. */
1754 purge = TRUE;
1755 }
1756 break;
1757 case VUT_MINFOREIGNPCT:
1758 if (preq->present) {
1759 notify_player(pplayer, city_tile(pcity),
1761 _("%s can't build %s from the worklist; "
1762 "city must have %d%% foreign population. Postponing..."),
1764 tgt_name,
1765 preq->source.value.minforeignpct);
1767 pcity, "need_minforeignpct");
1768 } else {
1769 notify_player(pplayer, city_tile(pcity),
1771 _("%s can't build %s from the worklist; "
1772 "city must have %d%% native population. Postponing..."),
1774 tgt_name,
1775 100 - preq->source.value.minforeignpct);
1777 pcity, "need_minforeignpct");
1778 }
1779 break;
1780 case VUT_MINTECHS:
1781 if (preq->present) {
1782 notify_player(pplayer, city_tile(pcity),
1784 _("%s can't build %s from the worklist; "
1785 "%d techs must be known. Postponing..."),
1787 tgt_name,
1788 preq->source.value.min_techs);
1790 pcity, "need_mintechs");
1791 } else {
1792 purge = TRUE;
1793 }
1794 break;
1795 case VUT_MINCITIES:
1796 if (preq->present) {
1797 notify_player(pplayer, city_tile(pcity),
1799 _("%s can't build %s from the worklist; "
1800 "Must own %d cities. Postponing..."),
1802 tgt_name,
1803 preq->source.value.min_cities);
1805 pcity, "need_mincities");
1806 } else {
1807 purge = TRUE;
1808 }
1809 break;
1810 case VUT_MAXTILEUNITS:
1811 if (preq->present) {
1812 notify_player(pplayer, city_tile(pcity),
1814 PL_("%s can't build %s from the worklist; "
1815 "more than %d unit on tile."
1816 " Postponing...",
1817 "%s can't build %s from the worklist; "
1818 "more than %d units on tile."
1819 " Postponing...",
1820 preq->source.value.max_tile_units),
1822 tgt_name,
1823 preq->source.value.max_tile_units);
1825 pcity, "need_tileunits");
1826 } else {
1827 notify_player(pplayer, city_tile(pcity),
1829 PL_("%s can't build %s from the worklist; "
1830 "fewer than %d unit on tile."
1831 " Postponing...",
1832 "%s can't build %s from the worklist; "
1833 "fewer than %d units on tile."
1834 " Postponing...",
1835 preq->source.value.max_tile_units + 1),
1837 tgt_name,
1838 preq->source.value.max_tile_units + 1);
1840 pcity, "need_tileunits");
1841 }
1842 break;
1843 case VUT_AI_LEVEL:
1844 /* Can't change AI level. */
1845 purge = TRUE;
1846 break;
1847 case VUT_TERRAINCLASS:
1848 /* Change of terrain class is expected to be very unlikely. Purge!
1849 * TODO: Analyze ruleset to see how unlikely terrain class change actually is. */
1850 purge = TRUE;
1851 break;
1852 case VUT_TERRFLAG:
1853 if (preq->present) {
1854 notify_player(pplayer, city_tile(pcity),
1856 _("%s can't build %s from the worklist; "
1857 "terrain with \"%s\" flag is required. "
1858 "Postponing..."),
1860 tgt_name,
1861 terrain_flag_id_name(preq->source.value.terrainflag));
1863 pcity, "need_terrainflag");
1864 } else {
1865 notify_player(pplayer, city_tile(pcity),
1867 _("%s can't build %s from the worklist; "
1868 "terrain with \"%s\" flag is prohibited. "
1869 "Postponing..."),
1871 tgt_name,
1872 terrain_flag_id_name(preq->source.value.terrainflag));
1874 pcity, "have_terrainflag");
1875 }
1876 break;
1878 /* Changing the continent size is hard; cf. VUT_TERRAINCLASS above.
1879 * Change this when we support less fixed ranges (e.g. city?). */
1880 purge = TRUE;
1881 break;
1882 case VUT_ROADFLAG:
1883 if (preq->present) {
1884 notify_player(pplayer, city_tile(pcity),
1886 _("%s can't build %s from the worklist; "
1887 "road with \"%s\" flag is required. "
1888 "Postponing..."),
1890 tgt_name,
1891 road_flag_id_name(preq->source.value.roadflag));
1893 pcity, "need_roadflag");
1894 } else {
1895 notify_player(pplayer, city_tile(pcity),
1897 _("%s can't build %s from the worklist; "
1898 "road with \"%s\" flag is prohibited. "
1899 "Postponing..."),
1901 tgt_name,
1902 road_flag_id_name(preq->source.value.roadflag));
1904 pcity, "have_roadflag");
1905 }
1906 break;
1907 case VUT_EXTRAFLAG:
1908 if (preq->present) {
1909 notify_player(pplayer, city_tile(pcity),
1911 _("%s can't build %s from the worklist; "
1912 "extra with \"%s\" flag is required. "
1913 "Postponing..."),
1915 tgt_name,
1916 extra_flag_id_translated_name(preq->source.value.extraflag));
1918 pcity, "need_extraflag");
1919 } else {
1920 notify_player(pplayer, city_tile(pcity),
1922 _("%s can't build %s from the worklist; "
1923 "extra with \"%s\" flag is prohibited. "
1924 "Postponing..."),
1926 tgt_name,
1927 extra_flag_id_translated_name(preq->source.value.extraflag));
1929 pcity, "have_extraflag");
1930 }
1931 break;
1932 case VUT_MINLATITUDE:
1933 case VUT_MAXLATITUDE:
1934 /* Can't change where the city is located. */
1935 purge = TRUE;
1936 break;
1937 case VUT_CITYTILE:
1938 if (CITYT_BORDERING_TCLASS_REGION == preq->source.value.citytile
1939 && (preq->range == REQ_RANGE_CADJACENT
1940 || preq->range == REQ_RANGE_ADJACENT)) {
1941 if (preq->present) {
1942 notify_player(pplayer, city_tile(pcity),
1944 _("%s can't build %s from the worklist; "
1945 "different terrain class nearby is required. "
1946 "Postponing..."),
1948 tgt_name);
1950 pcity, "need_different_terrainclass");
1951 } else {
1952 notify_player(pplayer, city_tile(pcity),
1954 _("%s can't build %s from the worklist; "
1955 "different terrain class nearby is prohibited. "
1956 "Postponing..."),
1958 tgt_name);
1960 pcity, "have_different_terrainclass");
1961 }
1962 break;
1963 }
1964 /* Other values should not present in build reqs */
1966
1967 case VUT_UTYPE:
1968 case VUT_UTFLAG:
1969 case VUT_UCLASS:
1970 case VUT_UCFLAG:
1971 case VUT_MINVETERAN:
1972 case VUT_UNITSTATE:
1973 case VUT_ACTIVITY:
1974 case VUT_MINMOVES:
1975 case VUT_MINHP:
1976 case VUT_ACTION:
1977 case VUT_OTYPE:
1978 case VUT_SPECIALIST:
1980 case VUT_TILE_REL:
1981 case VUT_TERRAINALTER: /* XXX could do this in principle */
1982 /* Will only happen with a bogus ruleset. */
1983 log_error("worklist_change_build_target() has bogus preq");
1984 break;
1985 case VUT_CITYSTATUS:
1986 if (preq->source.value.citystatus == CITYS_TRANSFERRED) {
1987 /* If there's a change, it will invalidate worklist anyway. */
1988 purge = TRUE;
1989 } else if (preq->source.value.citystatus == CITYS_OWNED_BY_ORIGINAL) {
1990 if (preq->range == REQ_RANGE_CITY || preq->range == REQ_RANGE_TILE) {
1991 /* Can't change at these ranges */
1992 purge = TRUE;
1993 } else {
1994 if (preq->present) {
1995 notify_player(pplayer, city_tile(pcity),
1997 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
1998 _("%s can't build %s from the worklist; "
1999 "only available when city in range %s \"%s\". "
2000 "Postponing..."),
2002 tgt_name, req_range_name(preq->range),
2003 citystatus_type_name(preq->source.value.citystatus));
2005 pcity, "need_citystatus");
2006 } else {
2007 notify_player(pplayer, city_tile(pcity),
2009 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2010 _("%s can't build %s from the worklist; "
2011 "not available when city in range %s is \"%s\". "
2012 "Postponing..."),
2014 tgt_name, req_range_name(preq->range),
2015 citystatus_type_name(preq->source.value.citystatus));
2017 pcity, "have_citystatus");
2018 }
2019 }
2020 } else {
2021 /* Other status types will only happen with a bogus ruleset. */
2022 log_error("worklist_change_build_target() has bogus citystatus preq");
2023 }
2024 break;
2025 case VUT_MINYEAR:
2026 if (preq->present) {
2027 notify_player(pplayer, city_tile(pcity),
2029 /* TRANS: last %s is a date */
2030 _("%s can't build %s from the worklist; "
2031 "only available from %s. Postponing..."),
2033 tgt_name,
2034 textyear(preq->source.value.minyear));
2036 pcity, "need_minyear");
2037 } else {
2038 /* Can't go back in time. */
2039 purge = TRUE;
2040 }
2041 break;
2042 case VUT_MINCALFRAG:
2043 /* Unlike VUT_MINYEAR, a requirement in either direction is
2044 * likely to be fulfilled sooner or later. */
2045 if (preq->present) {
2046 notify_player(pplayer, city_tile(pcity),
2048 /* TRANS: last %s is a calendar fragment from
2049 * the ruleset; may be a bare number */
2050 _("%s can't build %s from the worklist; "
2051 "only available from %s. Postponing..."),
2053 tgt_name,
2054 textcalfrag(preq->source.value.mincalfrag));
2056 pcity, "need_mincalfrag");
2057 } else {
2058 fc_assert_action(preq->source.value.mincalfrag > 0, break);
2059 notify_player(pplayer, city_tile(pcity),
2061 /* TRANS: last %s is a calendar fragment from
2062 * the ruleset; may be a bare number */
2063 _("%s can't build %s from the worklist; "
2064 "not available after %s. Postponing..."),
2066 tgt_name,
2067 textcalfrag(preq->source.value.mincalfrag - 1));
2069 pcity, "have_mincalfrag");
2070 }
2071 break;
2072 case VUT_TOPO:
2073 if (preq->present) {
2074 notify_player(pplayer, city_tile(pcity),
2076 /* TRANS: third %s is topology flag name
2077 * ("Hex", "ISO" */
2078 _("%s can't build %s from the worklist; "
2079 "only available in worlds with %s map."),
2081 tgt_name,
2082 _(topo_flag_name(preq->source.value.topo_property)));
2084 pcity, "need_topo");
2085 }
2086 purge = TRUE;
2087 break;
2088 case VUT_WRAP:
2089 if (preq->present) {
2090 notify_player(pplayer, city_tile(pcity),
2092 /* TRANS: third %s is wrap flag name
2093 * ("WrapX", "Wrapy") */
2094 _("%s can't build %s from the worklist; "
2095 "only available in worlds with %s map."),
2097 tgt_name,
2098 _(wrap_flag_name(preq->source.value.wrap_property)));
2100 pcity, "need_wrap");
2101 }
2102 purge = TRUE;
2103 break;
2104 case VUT_SERVERSETTING:
2105 notify_player(pplayer, city_tile(pcity),
2107 /* TRANS: %s is a server setting, its value and
2108 * if it is required to be present or absent.
2109 * The string's format is specified in
2110 * ssetv_human_readable().
2111 * Example: "killstack is enabled". */
2112 _("%s can't build %s from the worklist; "
2113 "only available when the server setting "
2114 "%s."),
2116 tgt_name,
2117 ssetv_human_readable(preq->source.value.ssetval,
2118 preq->present));
2120 pcity, "need_setting");
2121 /* Don't assume that the server setting will be changed. */
2122 purge = TRUE;
2123 break;
2124 case VUT_AGE:
2125 if (preq->present) {
2126 notify_player(pplayer, city_tile(pcity),
2128 _("%s can't build %s from the worklist; "
2129 "only available once %d turns old. Postponing..."),
2131 tgt_name,
2132 preq->source.value.age);
2134 pcity, "need_age");
2135 } else {
2136 /* Can't go back in time. */
2137 purge = TRUE;
2138 }
2139 break;
2140 case VUT_FORM_AGE:
2141 if (preq->present) {
2142 notify_player(pplayer, city_tile(pcity),
2144 _("%s can't build %s from the worklist; "
2145 "only available once %d turns old form. Postponing..."),
2147 tgt_name,
2148 preq->source.value.age);
2150 pcity, "need_form_age");
2151 } else {
2152 /* Can't go back in time. */
2153 purge = TRUE;
2154 }
2155 break;
2156 case VUT_NONE:
2157 case VUT_COUNT:
2159 "worklist_change_build_target() "
2160 "called with invalid preq");
2161 break;
2162 /* No default handling here, as we want compiler warning
2163 * if new requirement type is added to enum and it's not handled
2164 * here. */
2165 };
2166 break;
2167 }
2168
2169 /* Almost all cases emit signal in the end, so city check needed. */
2170 if (!city_exist(saved_id)) {
2171 /* Some script has removed city */
2172 return TRUE;
2173 }
2174
2176
2177 if (!known) {
2178 /* FIXME: make can_city_build_improvement_now() return a reason enum,
2179 * so we can notify user with it.
2180 * Likely the building already exist. */
2181 purge = TRUE;
2182 }
2183
2184 return purge;
2185}
2186
2187/**********************************************************************/
2193static bool worklist_change_build_target(struct player *pplayer,
2194 struct city *pcity)
2195{
2196 struct universal target;
2197 bool success = FALSE;
2198 int i;
2199 int saved_id = pcity->id;
2200 bool city_checked = TRUE; /* This is used to avoid spurious city_exist() calls */
2201 struct worklist *pwl = &pcity->worklist;
2202 const struct civ_map *nmap = &(wld.map);
2203
2204 if (worklist_is_empty(pwl)) {
2205 /* Nothing in the worklist; bail now. */
2206 return FALSE;
2207 }
2208
2209 i = 0;
2210 while (!success && i < worklist_length(pwl)) {
2211
2212 if (!city_checked) {
2213 if (!city_exist(saved_id)) {
2214 /* Some script has removed useless city that cannot build
2215 * what it is told to! */
2216 return FALSE;
2217 }
2219 }
2220
2221 if (worklist_peek_ith(pwl, &target, i)) {
2222 success = can_city_build_now(nmap, pcity, &target);
2223 } else {
2224 success = FALSE;
2225 }
2226 i++;
2227
2228 if (success) {
2229 break; /* while */
2230 }
2231
2232 switch (target.kind) {
2233 case VUT_UTYPE:
2234 {
2235 const struct unit_type *ptarget = target.value.utype;
2237 bool purge;
2238
2239 /* Maybe we can just upgrade the target to what the city /can/ build. */
2240 if (U_NOT_OBSOLETED == pupdate) {
2241 /* Nope, we're stuck. Skip this item from the worklist. */
2242 struct research *presearch = research_get(pplayer);
2243 struct advance *missing = NULL;
2244 bool multiple = FALSE;
2245
2248 if (missing != NULL) {
2249 multiple = TRUE;
2250 } else {
2251 missing = padv;
2252 }
2253 }
2255
2256
2257 if (missing != NULL) {
2258 if (!multiple) {
2259 notify_player(pplayer, city_tile(pcity),
2261 _("%s can't build %s from the worklist; "
2262 "tech %s not yet available. Postponing..."),
2265 } else {
2266 notify_player(pplayer, city_tile(pcity),
2268 _("%s can't build %s from the worklist; "
2269 "multiple techs still needed. Postponing..."),
2271 }
2272
2273 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2274 "need_tech");
2275 } else {
2276 /* Unknown or requirement from vector. */
2277 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2278 saved_id);
2279 }
2281 break;
2282 } else {
2284 }
2285 if (purge) {
2286 /* If the city can never build this unit or its descendants,
2287 * drop it. */
2288 notify_player(pplayer, city_tile(pcity),
2290 _("%s can't build %s from the worklist. Purging..."),
2292 /* Yes, warn about the targets that's actually
2293 in the worklist, not its obsolete-closure
2294 pupdate. */
2296 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2297 "never");
2298 if (city_exist(saved_id)) {
2300 /* Purge this worklist item. */
2301 i--;
2303 } else {
2305 }
2306 } else {
2307 /* Yep, we can go after pupdate instead. Joy! */
2309 _("Production of %s is upgraded to %s in %s."),
2312 city_link(pcity));
2313 target.value.utype = pupdate;
2314 }
2315 break;
2316 }
2317 case VUT_IMPROVEMENT:
2318 {
2319 const struct impr_type *ptarget = target.value.building;
2321 bool purge;
2322
2323 /* If the city can never build this improvement, drop it. */
2325 purge = !success;
2326
2327 /* Maybe this improvement has been obsoleted by something that
2328 we can build. */
2329 if (purge) {
2330 /* Nope, no use. *sigh* */
2331
2332 /* Can it be postponed? */
2334 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2335 saved_id);
2336
2337 /* Almost all cases emit signal in the end, so city check needed. */
2338 if (!city_exist(saved_id)) {
2339 /* Some script has removed city */
2340 return FALSE;
2341 }
2343 }
2344 } else if (success) {
2345 /* Hey, we can upgrade the improvement! */
2347 _("Production of %s is upgraded to %s in %s."),
2350 city_link(pcity));
2351 target.value.building = pupdate;
2352 }
2353
2354 if (purge) {
2355 /* Never in a million years. */
2356 notify_player(pplayer, city_tile(pcity),
2358 _("%s can't build %s from the worklist. Purging..."),
2361 script_server_signal_emit("building_cant_be_built", ptarget, pcity,
2362 "never");
2363 if (city_exist(saved_id)) {
2365 /* Purge this worklist item. */
2366 i--;
2368 } else {
2370 }
2371 }
2372 break;
2373 }
2374 default:
2375 /* skip useless target */
2376 log_error("worklist_change_build_target() has unrecognized "
2377 "target kind (%d)", target.kind);
2378 break;
2379 };
2380 } /* while */
2381
2382 if (success) {
2383 /* All okay. Switch targets. */
2384 change_build_target(pplayer, pcity, &target, E_WORKLIST);
2385
2386 /* i is the index immediately _after_ the item we're changing to.
2387 Remove the (i-1)th item from the worklist. */
2388 worklist_remove(pwl, i - 1);
2389 }
2390
2391 if (worklist_is_empty(pwl)) {
2392 /* There *was* something in the worklist, but it's empty now. Bug the
2393 player about it. */
2395 /* TRANS: The <city> worklist .... */
2396 _("The %s worklist is now empty."),
2397 city_link(pcity));
2398 }
2399
2400 return success;
2401}
2402
2403/**********************************************************************/
2408void choose_build_target(struct player *pplayer, struct city *pcity)
2409{
2410 const struct civ_map *nmap = &(wld.map);
2411
2412 /* Pick the next thing off the worklist. */
2413 if (worklist_change_build_target(pplayer, pcity)) {
2414 return;
2415 }
2416
2417 /* Try building the same thing again. Repeat building doesn't require a
2418 * call to change_build_target, so just return. */
2419 switch (pcity->production.kind) {
2420 case VUT_UTYPE:
2421 /* We can build a unit again unless it's unique or we have lost the tech. */
2422 if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
2423 && can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
2424 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2425 utype_rule_name(pcity->production.value.utype));
2426 return;
2427 }
2428 break;
2429 case VUT_IMPROVEMENT:
2430 if (can_city_build_improvement_now(pcity, pcity->production.value.building)) {
2431 /* We can build space and coinage again, and possibly others. */
2432 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2433 improvement_rule_name(pcity->production.value.building));
2434 return;
2435 }
2436 break;
2437 default:
2438 /* fallthru */
2439 break;
2440 };
2441
2442 /* Find *something* to do! */
2443 log_debug("Trying advisor_choose_build.");
2444 advisor_choose_build(pplayer, pcity);
2445 log_debug("Advisor_choose_build didn't kill us.");
2446}
2447
2448/**********************************************************************/
2453static const struct impr_type *building_upgrades_to(struct city *pcity,
2454 const struct impr_type *pimprove)
2455{
2456 const struct impr_type *check = pimprove;
2457 const struct impr_type *best_upgrade = NULL;
2458
2460 return NULL;
2461 }
2465 }
2466 }
2467
2468 return best_upgrade;
2469}
2470
2471/**********************************************************************/
2475{
2476 const struct impr_type *producing = pcity->production.value.building;
2478
2482 _("Production of %s is upgraded to %s in %s."),
2485 city_link(pcity));
2486 pcity->production.kind = VUT_IMPROVEMENT;
2487 pcity->production.value.building = upgrading;
2488 }
2489}
2490
2491/**********************************************************************/
2499static const struct unit_type *unit_upgrades_to(struct city *pcity,
2500 const struct unit_type *punittype)
2501{
2502 const struct unit_type *check = punittype;
2503 const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
2504 const struct civ_map *nmap = &(wld.map);
2505
2507 return U_NOT_OBSOLETED;
2508 }
2509 while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
2512 }
2513 }
2514
2515 return best_upgrade;
2516}
2517
2518/**********************************************************************/
2521static void upgrade_unit_prod(struct city *pcity)
2522{
2523 const struct unit_type *producing = pcity->production.value.utype;
2525 const struct civ_map *nmap = &(wld.map);
2526
2530 _("Production of %s is upgraded to %s in %s."),
2533 city_link(pcity));
2534 pcity->production.value.utype = upgrading;
2535 }
2536}
2537
2538/**********************************************************************/
2545static bool city_distribute_surplus_shields(struct player *pplayer,
2546 struct city *pcity)
2547{
2548 int size_reduction = 0;
2549 struct unit *sacrifizer;
2550
2551 if (pcity->surplus[O_SHIELD] < 0) {
2552 unit_list_iterate_safe(pcity->units_supported, punit) {
2553 if (utype_upkeep_cost(unit_type_get(punit), pplayer, O_SHIELD) > 0
2554 && pcity->surplus[O_SHIELD] < 0) {
2555 const char *punit_link = unit_link(punit);
2556
2557 /* TODO: Should the unit try to help cities on adjacent tiles? That
2558 * would be a rules change. (This action is performed by the game
2559 * it self) */
2562 notify_player(pplayer, city_tile(pcity),
2564 _("%s can't upkeep %s, unit disbanded."),
2566 }
2567
2568 /* pcity->surplus[O_SHIELD] is automatically updated. */
2569 }
2571 }
2572
2573 if (pcity->surplus[O_SHIELD] < 0) {
2574 /* Special case: MissingXProtected. This nasty unit won't go so easily.
2575 * It'd rather make the citizens pay in blood for their failure to upkeep
2576 * it! If we make it here all normal units are already disbanded, so only
2577 * undisbandable ones remain. */
2578 unit_list_iterate_safe(pcity->units_supported, punit) {
2580
2581 if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
2582
2584 sacrifizer = punit;
2585
2586 /* No upkeep for the unit this turn. */
2587 pcity->surplus[O_SHIELD] += upkeep;
2588 }
2590 }
2591
2592 /* Now we confirm changes made last turn. */
2593 pcity->shield_stock += pcity->surplus[O_SHIELD];
2594 pcity->before_change_shields = pcity->shield_stock;
2595 pcity->last_turns_shield_surplus = pcity->surplus[O_SHIELD];
2596
2597 /* Previous turn values stored, and they are consistent with
2598 * other previous turn data.
2599 * Now reduce city size, likely messing all the values. */
2600 if (size_reduction > 0) {
2601 if (size_reduction == 1) {
2602 notify_player(pplayer, city_tile(pcity),
2604 _("Citizens in %s perish for their failure to "
2605 "upkeep %s!"),
2607 } else {
2608 notify_player(pplayer, city_tile(pcity),
2610 _("Citizens in %s perish for their failure to "
2611 "upkeep units!"),
2612 city_link(pcity));
2613 }
2614
2615 if (!city_reduce_size(pcity, size_reduction, NULL, "upkeep_failure")) {
2616 return FALSE;
2617 }
2618 }
2619
2620 return TRUE;
2621}
2622
2623/**********************************************************************/
2626static bool city_build_building(struct player *pplayer, struct city *pcity)
2627{
2628 bool space_part;
2629 int mod;
2630 const struct impr_type *pimprove;
2631 int saved_id = pcity->id;
2632
2633 if (is_convert_improvement(pcity->production.value.building)) {
2634 /* Coinage-like improvements that convert production */
2635 fc_assert(pcity->before_change_shields >= 0);
2636
2637 /* pcity->before_change_shields already contains the surplus from
2638 * this turn. */
2640 pplayer->economic.gold += pcity->before_change_shields;
2642 pplayer->economic.infra_points += pcity->before_change_shields;
2643 }
2644
2645 pcity->before_change_shields = 0;
2646 pcity->shield_stock = 0;
2647 choose_build_target(pplayer, pcity);
2648
2649 return TRUE;
2650 }
2651
2653
2654 /* The final (after upgrade) build target */
2655 pimprove = pcity->production.value.building;
2656
2657 if (!can_city_build_improvement_now(pcity, pimprove)) {
2659 _("%s is building %s, which is no longer available."),
2662 script_server_signal_emit("building_cant_be_built", pimprove, pcity,
2663 "unavailable");
2664 return TRUE;
2665 }
2666 if (pcity->shield_stock >= impr_build_shield_cost(pcity, pimprove)) {
2667 int cost;
2668
2669 if (is_small_wonder(pimprove)) {
2670 city_list_iterate(pplayer->cities, wcity) {
2671 if (city_has_building(wcity, pimprove)) {
2672 city_remove_improvement(wcity, pimprove);
2673 break;
2674 }
2676 }
2677
2678 space_part = TRUE;
2680 RPT_CERTAIN) > 0) {
2681 pplayer->spaceship.structurals++;
2683 RPT_CERTAIN) > 0) {
2684 pplayer->spaceship.components++;
2686 RPT_CERTAIN) > 0) {
2687 pplayer->spaceship.modules++;
2688 } else {
2689 space_part = FALSE;
2691 _("Completion of %s"));
2692 }
2693 cost = impr_build_shield_cost(pcity, pimprove);
2694 pcity->before_change_shields -= cost;
2695 pcity->shield_stock -= cost;
2696 pcity->turn_last_built = game.info.turn;
2697 /* to eliminate micromanagement */
2698 if (is_great_wonder(pimprove)) {
2700 _("The %s have finished building %s in %s."),
2701 nation_plural_for_player(pplayer),
2703 city_link(pcity));
2704 }
2705
2707 _("%s has finished building %s."),
2709 script_server_signal_emit("building_built", pimprove, pcity);
2710
2711 if (!city_exist(saved_id)) {
2712 /* Script removed city */
2713 return FALSE;
2714 }
2715
2716 /* Call this function since some buildings may change the
2717 * the vision range of a city */
2719
2721 RPT_CERTAIN))) {
2722 struct research *presearch = research_get(pplayer);
2723 char research_name[MAX_LEN_NAME * 2];
2724 int i;
2725 const char *provider = improvement_name_translation(pimprove);
2726
2728 PL_("%s boosts research; you gain %d immediate "
2729 "advance.",
2730 "%s boosts research; you gain %d immediate "
2731 "advances.",
2732 mod), provider, mod);
2733
2735 for (i = 0; i < mod; i++) {
2738
2741 /* TRANS: Tech from building (Darwin's Voyage) */
2742 Q_("?frombldg:Acquired %s from %s."), adv_name,
2743 provider);
2744
2746 /* TRANS: Tech from building (Darwin's
2747 * Voyage) */
2748 Q_("?frombldg:The %s have acquired %s "
2749 "from %s."),
2751 }
2752 }
2753 if (space_part && pplayer->spaceship.state == SSHIP_NONE) {
2755 _("The %s have started building a spaceship!"),
2756 nation_plural_for_player(pplayer));
2757 pplayer->spaceship.state = SSHIP_STARTED;
2758 }
2759 if (space_part) {
2760 /* space ship part build */
2761 send_spaceship_info(pplayer, NULL);
2762 } else {
2763 /* Update city data. */
2764 if (city_refresh(pcity)) {
2766 }
2767 }
2768
2769 /* Move to the next thing in the worklist */
2770 choose_build_target(pplayer, pcity);
2771 }
2772
2773 return TRUE;
2774}
2775
2776/**********************************************************************/
2785static struct unit *city_create_unit(struct city *pcity,
2786 const struct unit_type *utype,
2787 struct citizens_reduction *red)
2788{
2789 struct player *pplayer = city_owner(pcity);
2790 struct unit *punit;
2791 int saved_unit_id;
2792 int pop_cost = utype_pop_value(utype, pcity);
2793
2796 pcity->id, -1, -1);
2797 pplayer->score.units_built++;
2798
2799 if (pop_cost > 0 && pcity->nationality != NULL) {
2800 /* We don't reduce city size in-place to keep it correct and
2801 * existing at all while we call the following callback.
2802 * We want citizens_unit_nationality() to adjust 'red' even when
2803 * we are not setting unit nationality based on the return */
2804 struct player *nat = citizens_unit_nationality(pcity, pop_cost, red);
2805
2808 }
2809 } else if (red) {
2810 red->change = 0;
2811 }
2812
2813 (void) place_unit(punit, pplayer, pcity, NULL, FALSE);
2815
2816 /* If city has a rally point set, give the unit a move order. */
2817 if (pcity->rally_point.length) {
2819 punit->orders.length = pcity->rally_point.length;
2820 punit->orders.vigilant = pcity->rally_point.vigilant;
2821 punit->orders.list = fc_malloc(pcity->rally_point.length
2822 * sizeof(struct unit_order));
2823 memcpy(punit->orders.list, pcity->rally_point.orders,
2824 pcity->rally_point.length * sizeof(struct unit_order));
2825 }
2826
2827 /* This might destroy pcity and/or punit: */
2828 script_server_signal_emit("unit_built", punit, pcity);
2829
2831 return punit;
2832 } else {
2833 return NULL;
2834 }
2835}
2836
2837/**********************************************************************/
2846static bool city_build_unit(struct player *pplayer, struct city *pcity)
2847{
2848 const struct unit_type *utype;
2849 struct worklist *pwl = &pcity->worklist;
2851 int saved_city_id = pcity->id;
2852 const struct civ_map *nmap = &(wld.map);
2853
2854 fc_assert_ret_val(pcity->production.kind == VUT_UTYPE, FALSE);
2855
2856 /* If the city has already bought a unit which is now obsolete, don't try
2857 * to upgrade the production. The new unit might require more shields, which
2858 * would be bad if it was bought to urgently defend a city. (Equally it
2859 * might be the same cost or cheaper, but tough; you hurried the unit so
2860 * you miss out on technological advances.) */
2863 }
2864
2865 utype = pcity->production.value.utype;
2867
2868 /* We must make a special case for barbarians here, because they are
2869 so dumb. Really. They don't know the prerequisite techs for units
2870 they build!! - Per */
2872 && !is_barbarian(pplayer)) {
2874 _("%s is building %s, which is no longer available."),
2876
2877 /* Log before signal emitting, so pointers are certainly valid */
2878 log_verbose("%s %s tried to build %s, which is not available.",
2881 script_server_signal_emit("unit_cant_be_built", utype, pcity,
2882 "unavailable");
2883 return city_exist(saved_city_id);
2884 }
2885
2886 if (pcity->shield_stock >= unit_shield_cost) {
2887 int pop_cost = utype_pop_value(utype, pcity);
2888 struct unit *punit;
2889
2890 /* Should we disband the city? -- Massimo */
2891 if (city_size_get(pcity) == pop_cost
2893 return !disband_city(pcity);
2894 }
2895
2896 if (city_size_get(pcity) <= pop_cost) {
2898 /* TRANS: city ... utype ... size ... pop_cost */
2899 _("%s can't build %s yet. "
2900 "(city size: %d, unit population cost: %d)"),
2902 city_size_get(pcity), pop_cost);
2903 script_server_signal_emit("unit_cant_be_built", utype, pcity,
2904 "pop_cost");
2905 return city_exist(saved_city_id);
2906 }
2907
2908 fc_assert(pop_cost == 0 || city_size_get(pcity) >= pop_cost);
2909
2910 /* don't update turn_last_built if we returned above */
2911 pcity->turn_last_built = game.info.turn;
2912
2913 /* check if we can build more than one unit (effect City_Build_Slots) */
2915
2916 /* We should be able to build at least one (by checks above) */
2917 fc_assert(num_units >= 1);
2918
2919 for (i = 0; i < num_units; i++) {
2921
2923
2924 /* Check if the city still exists (script might have removed it).
2925 * If not, we assume any effects / announcements done below were
2926 * already replaced by the script if necessary. */
2927 if (!city_exist(saved_city_id)) {
2928 break;
2929 }
2930
2931 if (punit) {
2933 /* TRANS: <city> is finished building <unit/building>. */
2934 _("%s is finished building %s."),
2936 }
2937
2938 /* After we created the unit remove the citizen. This will also
2939 * rearrange the worker to take into account the extra resources
2940 * (food) needed. */
2941 if (pop_cost > 0) {
2942 /* This won't disband city due to pop_cost, but script might
2943 * still destroy city. */
2945 /* If the city has changed its nationalities during
2946 * "unit_built" signal, we take some other citizens instead */
2947 if (!city_reduce_size(pcity, pop_cost, NULL, "unit_built")) {
2948 break;
2949 }
2950 }
2951
2952 /* to eliminate micromanagement, we only subtract the unit's cost */
2953 /* signals could change the prod stock! */
2954 if ((pcity->before_change_shields -= unit_shield_cost) < 0) {
2955 pcity->before_change_shields = 0;
2956 }
2957 if ((pcity->shield_stock -= unit_shield_cost) < 0) {
2958 log_normal("City %s (%s) has built %s but has no %d shields "
2959 "for it, nullifying shield stock", city_name_get(pcity),
2960 player_name(pplayer), utype_rule_name(utype),
2962 pcity->shield_stock = 0;
2963 }
2964
2965 if (pop_cost > 0) {
2966 /* Additional message if the unit has population cost. */
2968 ftc_server,
2969 /* TRANS: "<unit> cost... <city> shrinks..."
2970 * Plural in "%d population", not "size %d". */
2971 PL_("%s cost %d population. %s shrinks to size %d.",
2972 "%s cost %d population. %s shrinks to size %d.",
2973 pop_cost),
2974 utype_name_translation(utype), pop_cost,
2976 }
2977
2978 if (i != 0 && worklist_length(pwl) > 0) {
2979 /* remove the build unit from the worklist; it has to be one less
2980 * than units build to preserve the next build target from the
2981 * worklist */
2982 worklist_remove(pwl, 0);
2983 }
2984 } /* for */
2985
2987 if (pcity->rally_point.length && !pcity->rally_point.persistent) {
2989 }
2990
2991 /* Done building this unit; time to move on to the next. */
2992 choose_build_target(pplayer, pcity);
2993 }
2994 } /* if */
2995
2996 return city_exist(saved_city_id);
2997}
2998
2999/**********************************************************************/
3002static bool city_build_stuff(struct player *pplayer, struct city *pcity)
3003{
3004 if (!city_distribute_surplus_shields(pplayer, pcity)) {
3005 return FALSE;
3006 }
3007
3010
3011 switch (pcity->production.kind) {
3012 case VUT_IMPROVEMENT:
3013 return city_build_building(pplayer, pcity);
3014 case VUT_UTYPE:
3015 return city_build_unit(pplayer, pcity);
3016 default:
3017 /* must never happen! */
3019 break;
3020 };
3021 return FALSE;
3022}
3023
3024/**********************************************************************/
3034static bool sell_random_building(struct player *pplayer,
3035 struct cityimpr_list *imprs)
3036{
3037 struct cityimpr *pcityimpr;
3038 int r;
3039
3040 fc_assert_ret_val(pplayer != NULL, FALSE);
3041
3042 if (!imprs || cityimpr_list_size(imprs) == 0) {
3043 return FALSE;
3044 }
3045
3048
3050 ftc_server,
3051 _("Can't afford to maintain %s in %s, building sold!"),
3053 city_link(pcityimpr->pcity));
3054 log_debug("%s: sold building (%s)", player_name(pplayer),
3056
3057 do_sell_building(pplayer, pcityimpr->pcity, pcityimpr->pimprove, "cant_maintain");
3058
3060
3061 /* Get back the gold upkeep that was already paid this turn. */
3063 pcityimpr->pimprove);
3064
3066
3068
3069 return TRUE;
3070}
3071
3072/**********************************************************************/
3080static void uk_rem_gold_callback(struct unit *punit)
3081{
3082 int gold_upkeep;
3083
3084 /* Remove the unit from uk_rem_gold. */
3086
3087 gold_upkeep = punit->server.upkeep_paid[O_GOLD];
3088
3089 /* All units in uk_rem_gold should have gold upkeep! */
3090 fc_assert_ret_msg(gold_upkeep > 0, "%s has %d gold upkeep",
3091 unit_rule_name(punit), gold_upkeep);
3092
3093 /* Get the upkeep gold back. */
3094 unit_owner(punit)->economic.gold += gold_upkeep;
3095}
3096
3097/**********************************************************************/
3101static void uk_rem_gold_append(struct unit *punit)
3102{
3103 /* Make the unit aware that it is on the uk_rem_gold list. */
3105
3106 /* Add the unit to the list. */
3108}
3109
3110/**********************************************************************/
3114static void unit_list_referred_destroy(struct unit_list *punitlist)
3115{
3117 /* Clear the unit's knowledge of the list. */
3120
3121 /* Destroy the list it self. */
3123}
3124
3125/**********************************************************************/
3137static struct unit *sell_random_unit(struct player *pplayer,
3138 struct unit_list *punitlist)
3139{
3140 struct unit *punit;
3141 int r;
3142 struct unit_list *cargo;
3143
3144 fc_assert_ret_val(pplayer != NULL, NULL);
3145
3146 if (!punitlist || unit_list_size(punitlist) == 0) {
3147 return NULL;
3148 }
3149
3152
3153 cargo = unit_list_new();
3154
3155 /* Check if unit is transporting other units from punitlist,
3156 * and sell one of those (recursively) instead.
3157 * Note that in case of recursive transports we have to iterate
3158 * also through those middle transports that themselves are not in
3159 * punitlist. */
3161 /* Optimization, do not iterate over punitlist
3162 * if we are sure that pcargo is not in it. */
3163 if (pcargo->server.upkeep_paid[O_GOLD] > 0) {
3165 if (pcargo == p2) {
3166 unit_list_append(cargo, pcargo);
3167 }
3169 }
3171
3172 if (unit_list_size(cargo) > 0) {
3173 /* Recursively sell. Note that cargo list has both
3174 * leaf units and middle transports in case of
3175 * recursive transports. */
3176 struct unit *ret = sell_random_unit(pplayer, cargo);
3177
3178 unit_list_destroy(cargo);
3179
3181
3182 return ret;
3183 }
3184
3185 unit_list_destroy(cargo);
3186
3187 {
3188 const char *punit_link = unit_tile_link(punit);
3189#ifdef FREECIV_DEBUG
3190 const char *punit_logname = unit_rule_name(punit);
3191#endif /* FREECIV_DEBUG */
3192 struct tile *utile = unit_tile(punit);
3193
3197
3198 /* The gold was paid back when the unit removal made
3199 * uk_rem_gold_callback() run as the unit's removal call back. */
3200
3201 notify_player(pplayer, utile, E_UNIT_LOST_MISC, ftc_server,
3202 _("Not enough gold. %s disbanded."),
3203 punit_link);
3204 log_debug("%s: unit sold (%s)", player_name(pplayer),
3206 } else {
3207 /* Not able to get rid of punit */
3208 return NULL;
3209 }
3210 }
3211
3213
3214 return punit;
3215}
3216
3217/**********************************************************************/
3221{
3222 struct cityimpr_list *pimprlist;
3223 bool sell_unit = TRUE;
3224
3225 if (!pplayer) {
3226 return FALSE;
3227 }
3228
3231
3232 city_list_iterate(pplayer->cities, pcity) {
3233 city_built_iterate(pcity, pimprove) {
3234 if (can_city_sell_building(pcity, pimprove)) {
3235 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3236
3237 ci->pcity = pcity;
3238 ci->pimprove = pimprove;
3240 }
3243
3244 unit_list_iterate(pplayer->units, punit) {
3245 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3247 }
3249
3250 while (pplayer->economic.gold < 0
3252 || unit_list_size(uk_rem_gold) > 0)) {
3254 || unit_list_size(uk_rem_gold) == 0) {
3256 } else {
3257 sell_random_unit(pplayer, uk_rem_gold);
3258 }
3260 }
3261
3262 /* Free remaining entries from list */
3264 FC_FREE(pimpr);
3266
3267 if (pplayer->economic.gold < 0) {
3268 /* If we get here it means the player has
3269 * negative gold. This should never happen. */
3270 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3271 player_name(pplayer), player_number(pplayer));
3272 }
3273
3276
3277 return pplayer->economic.gold >= 0;
3278}
3279
3280/**********************************************************************/
3284{
3285 if (!pplayer) {
3286 return FALSE;
3287 }
3288
3290
3291 unit_list_iterate(pplayer->units, punit) {
3292 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3294 }
3296
3297 while (pplayer->economic.gold < 0
3298 && sell_random_unit(pplayer, uk_rem_gold)) {
3299 /* All done in sell_random_unit() */
3300 }
3301
3302 if (pplayer->economic.gold < 0) {
3303 /* If we get here it means the player has
3304 * negative gold. This should never happen. */
3305 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3306 player_name(pplayer), player_number(pplayer));
3307 }
3308
3310
3311 return pplayer->economic.gold >= 0;
3312}
3313
3314/**********************************************************************/
3318{
3319 struct player *pplayer;
3320 struct cityimpr_list *pimprlist;
3321
3322 if (!pcity) {
3323 return TRUE;
3324 }
3325
3326 pplayer = city_owner(pcity);
3328
3329 /* Create a vector of all buildings that can be sold. */
3330 city_built_iterate(pcity, pimprove) {
3331 if (can_city_sell_building(pcity, pimprove)) {
3332 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3333
3334 ci->pcity = pcity;
3335 ci->pimprove = pimprove;
3337 }
3339
3340 /* Try to sell some buildings. */
3341 while (pplayer->economic.gold < 0
3342 && sell_random_building(pplayer, pimprlist)) {
3343 /* all done in sell_random_building */
3344 }
3345
3346 /* Free remaining entries from list */
3348 FC_FREE(pimpr);
3350
3352
3353 return pplayer->economic.gold >= 0;
3354}
3355
3356/**********************************************************************/
3365{
3366 struct player *pplayer;
3367
3368 if (!pcity) {
3369 return TRUE;
3370 }
3371
3372 pplayer = city_owner(pcity);
3374
3375 /* Create a vector of all supported units with gold upkeep. */
3376 unit_list_iterate(pcity->units_supported, punit) {
3377 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3379 }
3381
3382 /* Still not enough gold, so try "selling" some units. */
3383 while (pplayer->economic.gold < 0
3384 && sell_random_unit(pplayer, uk_rem_gold)) {
3385 /* All done in sell_random_unit() */
3386 }
3387
3388 /* If we get here the player has negative gold, but hopefully
3389 * another city will be able to pay the deficit, so continue. */
3390
3392
3393 return pplayer->economic.gold >= 0;
3394}
3395
3396/**********************************************************************/
3399static bool place_pollution(struct city *pcity, enum extra_cause cause)
3400{
3401 struct tile *ptile;
3402 struct tile *pcenter = city_tile(pcity);
3403 int city_radius_sq = city_map_radius_sq_get(pcity);
3404 int k = 100;
3405 const struct civ_map *nmap = &(wld.map);
3406
3407 while (k > 0) {
3408 /* Place pollution on a random city tile */
3409 int cx, cy;
3410 int tile_id = fc_rand(city_map_tiles(city_radius_sq));
3411 struct extra_type *pextra;
3412
3413 city_tile_index_to_xy(&cx, &cy, tile_id, city_radius_sq);
3414
3415 /* Check for a real map position */
3416 if (!(ptile = city_map_to_tile(nmap, pcenter, city_radius_sq, cx, cy))) {
3417 continue;
3418 }
3419
3420 pextra = rand_extra_for_tile(ptile, cause, FALSE);
3421
3422 if (pextra != NULL && !tile_has_extra(ptile, pextra)) {
3423 tile_add_extra(ptile, pextra);
3424 update_tile_knowledge(ptile);
3425
3426 return TRUE;
3427 }
3428 k--;
3429 }
3430 log_debug("pollution not placed: city: %s", city_name_get(pcity));
3431
3432 return FALSE;
3433}
3434
3435/**********************************************************************/
3438static void check_pollution(struct city *pcity)
3439{
3440 if (fc_rand(100) < pcity->pollution) {
3443 _("Pollution near %s."), city_link(pcity));
3444 }
3445 }
3446}
3447
3448/**********************************************************************/
3455int city_incite_cost(struct player *pplayer, struct city *pcity)
3456{
3457 int dist, size;
3458 double cost; /* Intermediate values can get very large */
3459
3460 /* Gold factor */
3461 cost = city_owner(pcity)->economic.gold + game.server.base_incite_cost;
3462
3467
3468 /* Buildings */
3469 city_built_iterate(pcity, pimprove) {
3470 cost += impr_build_shield_cost(pcity, pimprove)
3473
3474 /* Stability bonuses */
3475 if (!city_unhappy(pcity)) {
3476 cost *= 2;
3477 }
3478 if (city_celebrating(pcity)) {
3479 cost *= 2;
3480 }
3481
3482 /* Buy back is cheap, conquered cities are also cheap */
3484 if (city_owner(pcity) != pcity->original) {
3485 if (pplayer == pcity->original) {
3486 cost /= 2; /* Buy back: 50% price reduction */
3487 } else {
3488 cost = cost * 2 / 3; /* Buy conquered: 33% price reduction */
3489 }
3490 }
3491 }
3492
3493 /* Distance from capital */
3494 /* Max penalty. Applied if there is no capital, or it's even further away. */
3495 dist = 32;
3497 if (is_capital(capital)) {
3498 int tmp = map_distance(capital->tile, pcity->tile);
3499
3500 if (tmp < dist) {
3501 dist = tmp;
3502 }
3503 }
3505
3509 - pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] * 3);
3510 cost *= size;
3512 cost = cost / (dist + 3);
3513
3515 int cost_per_citizen = cost / pcity->size;
3517 int tgt_cit = citizens_nation_get(pcity, pplayer->slot);
3518 int third_party = pcity->size - natives - tgt_cit;
3519
3520 cost = cost_per_citizen * (natives + 0.7 * third_party + 0.5 * tgt_cit);
3521 }
3522
3524 cost /= 100;
3525
3528 } else {
3529 return cost;
3530 }
3531}
3532
3533/**********************************************************************/
3537{
3538 /* Remember what this city is building last turn, so that on the next turn
3539 * the player can switch production to something else and then change it
3540 * back without penalty. This has to be updated _before_ production for
3541 * this turn is calculated, so that the penalty will apply if the player
3542 * changes production away from what has just been completed. This makes
3543 * sense if you consider what this value means: all the shields in the
3544 * city have been dedicated toward the project that was chosen last turn,
3545 * so the player shouldn't be penalized if the governor has to pick
3546 * something different. See city_change_production_penalty(). */
3547 pcity->changed_from = pcity->production;
3548
3549 log_debug("In %s, building %s. Beg of Turn shields = %d",
3551 pcity->before_change_shields);
3552}
3553
3554/**********************************************************************/
3558{
3559 pcity->disbanded_shields = 0;
3560 pcity->caravan_shields = 0;
3561}
3562
3563/**********************************************************************/
3568{
3570 pcity->before_change_shields = 0;
3571}
3572
3573/**********************************************************************/
3576static void update_city_activity(struct city *pcity)
3577{
3578 struct player *pplayer;
3579 struct government *gov;
3580 bool is_happy;
3581 bool is_celebrating;
3582
3583 if (!pcity) {
3584 return;
3585 }
3586
3587 pplayer = city_owner(pcity);
3591
3592 if (city_refresh(pcity)) {
3594 }
3595
3596 /* Reporting of celebrations rewritten, copying the treatment of disorder below,
3597 with the added rapture rounds count. 991219 -- Jing */
3598 if (city_build_stuff(pplayer, pcity)) {
3599 int saved_id;
3600 int revolution_turns;
3601
3602 pcity->history += city_history_gain(pcity);
3603
3604 /* History can decrease, but never go below zero */
3605 pcity->history = MAX(pcity->history, 0);
3606
3607 /* Keep old behaviour when building new improvement could keep
3608 city celebrating */
3609 if (!is_happy) {
3611 }
3612
3614 pcity->rapture++;
3615
3616 /* Update city's celebrating counters */
3618 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3619 pcity->counter_values[pcount->index]++;
3620 }
3622
3623 if (pcity->rapture == 1) {
3625 _("Celebrations in your honor in %s."),
3626 city_link(pcity));
3627 }
3628 } else {
3629 if (pcity->rapture != 0) {
3631 _("Celebrations canceled in %s."),
3632 city_link(pcity));
3633 }
3634
3635 /* Update city's celebrating counters */
3637 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3638 pcity->counter_values[pcount->index] = 0;
3639 }
3641 pcity->rapture = 0;
3642 }
3643 pcity->was_happy = is_happy;
3644
3645 /* Handle the illness. */
3646 if (game.info.illness_on) {
3647 /* Recalculate city illness; illness due to trade has to be saved
3648 * within the city struct, as the client does not have all
3649 * the data to calculate it */
3650 pcity->server.illness
3651 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), NULL);
3652
3654 if (!city_illness_strike(pcity)) {
3655 /* Illness destroyed the city */
3656 return;
3657 }
3658 }
3659 }
3660
3661 /* City population updated here, after the rapture stuff above. --Jing */
3662 saved_id = pcity->id;
3663 pcity->had_famine = FALSE;
3664 city_populate(pcity, pplayer);
3665 if (NULL == player_city_by_number(pplayer, saved_id)) {
3666 return;
3667 }
3668
3669 pcity->did_sell = FALSE;
3670 pcity->did_buy = FALSE;
3671 pcity->airlift = city_airlift_max(pcity);
3672 update_bulbs(pplayer, pcity->prod[O_SCIENCE], FALSE, FALSE);
3673
3675
3676 /* Update the treasury. */
3677 pplayer->economic.gold += pcity->surplus[O_GOLD];
3678
3679 /* FIXME: Nation level upkeep should be paid after ALL cities
3680 * have been processed, not after each individual city. */
3682 /* Unit upkeep was not included in city balance ->
3683 * not reduced from the city surplus. */
3685
3687 /* Building upkeep was not included in city balance ->
3688 * not reduced from the city surplus. */
3690 }
3691 }
3692
3693 /* Remember how much gold upkeep each unit was paid. */
3694 unit_list_iterate(pcity->units_supported, punit) {
3697
3698 if (pplayer->economic.gold < 0) {
3699 /* Not enough gold - we have to sell some buildings, and if that
3700 * is not enough, disband units with gold upkeep, taking into
3701 * account the setting of 'game.info.gold_upkeep_style':
3702 * GOLD_UPKEEP_CITY: Cities pay for buildings and units.
3703 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
3704 * for units.
3705 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
3706 switch (game.info.gold_upkeep_style) {
3707 case GOLD_UPKEEP_CITY:
3708 case GOLD_UPKEEP_MIXED:
3712 }
3713 break;
3714 case GOLD_UPKEEP_NATION:
3715 break;
3716 }
3717 }
3718
3720 if (city_unhappy(pcity)) {
3721 const char *revomsg;
3722
3723 pcity->anarchy++;
3724
3726 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3727 pcity->counter_values[pcount->index]++;
3728 }
3730
3731 if (pcity->anarchy == revolution_turns) {
3732 /* Revolution next turn if not dealt with */
3733 /* TRANS: preserve leading space; this string will be appended to
3734 * another sentence */
3735 revomsg = _(" Unrest threatens to spread beyond the city.");
3736 } else {
3737 revomsg = "";
3738 }
3739 if (pcity->anarchy == 1) {
3741 /* TRANS: second %s is an optional extra sentence */
3742 _("Civil disorder in %s.%s"),
3744 } else {
3746 /* TRANS: second %s is an optional extra sentence */
3747 _("CIVIL DISORDER CONTINUES in %s.%s"),
3749 }
3750 } else {
3751 if (pcity->anarchy != 0) {
3753 _("Order restored in %s."),
3754 city_link(pcity));
3755 }
3756 pcity->anarchy = 0;
3757
3759 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3760 pcity->counter_values[pcount->index] = 0;
3761 }
3763 }
3765
3767
3768 if (revolution_turns > 0 && pcity->anarchy > revolution_turns) {
3770 /* TRANS: %s - government form, e.g., Democracy */
3771 _("The people have overthrown your %s, "
3772 "your country is in turmoil."),
3775 }
3776 if (city_refresh(pcity)) {
3778 }
3780 }
3781}
3782
3783/**********************************************************************/
3786static bool city_illness_check(const struct city * pcity)
3787{
3788 if (fc_rand(1000) < pcity->server.illness) {
3789 return TRUE;
3790 }
3791
3792 return FALSE;
3793}
3794
3795/**********************************************************************/
3799static bool disband_city(struct city *pcity)
3800{
3801 struct player *pplayer = city_owner(pcity);
3802 struct tile *ptile = pcity->tile;
3803 struct city *rcity = NULL;
3804 const struct unit_type *utype = pcity->production.value.utype;
3805 struct unit *punit;
3806 int saved_id = pcity->id;
3807
3808 /* find closest city other than pcity */
3809 rcity = find_closest_city(ptile, pcity, pplayer, FALSE, FALSE, FALSE, TRUE,
3810 FALSE, NULL);
3811
3812 if (!rcity) {
3813 /* What should we do when we try to disband our only city? */
3814 notify_player(pplayer, ptile, E_CITY_CANTBUILD, ftc_server,
3815 _("%s can't build %s yet, "
3816 "as we can't disband our only city."),
3818 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3819 "pop_cost");
3820 if (!city_exist(saved_id)) {
3821 /* Script decided to remove even the last city */
3822 return TRUE;
3823 } else {
3824 return FALSE;
3825 }
3826 }
3827
3829
3830 /* "unit_built" script handler may have destroyed city. If so, we
3831 * assume something sensible happened to its units, and that the
3832 * script took care of announcing unit creation if required. */
3833 if (city_exist(saved_id)) {
3834 /* Shift all the units supported by pcity (including the new unit)
3835 * to rcity. transfer_city_units does not make sure no units are
3836 * left floating without a transport, but since all units are
3837 * transferred this is not a problem. */
3838 transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity,
3839 pcity, -1, TRUE);
3840
3841 if (punit) {
3842 notify_player(pplayer, ptile, E_UNIT_BUILT, ftc_server,
3843 /* TRANS: "<city> is disbanded into Settler." */
3844 _("%s is disbanded into %s."),
3846 }
3847
3848 script_server_signal_emit("city_destroyed", pcity, pcity->owner, NULL);
3849
3850 if (!city_exist(saved_id)) {
3851 /* Already removed during the script */
3852 return TRUE;
3853 }
3855
3856 /* Since we've removed the city, we don't need to worry about
3857 * charging for production, disabling rally points, etc. */
3858 }
3859
3860 return TRUE;
3861}
3862
3863/**********************************************************************/
3911static float city_migration_score(struct city *pcity)
3912{
3913 float score = 0.0;
3914 int build_shield_cost = 0;
3915 bool has_wonder = FALSE;
3916
3917 if (!pcity) {
3918 return score;
3919 }
3920
3921 if (pcity->server.mgr_score_calc_turn == game.info.turn) {
3922 /* up-to-date migration score */
3923 return pcity->server.migration_score;
3924 }
3925
3926 /* feeling of the citizens */
3927 score = (city_size_get(pcity)
3928 + 1.00 * pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
3929 + 0.00 * pcity->feel[CITIZEN_CONTENT][FEELING_FINAL]
3930 - 0.25 * pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
3931 - 0.50 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
3932
3933 /* calculate shield build cost for all buildings */
3934 city_built_iterate(pcity, pimprove) {
3936 if (is_wonder(pimprove)) {
3937 /* this city has a wonder */
3938 has_wonder = TRUE;
3939 }
3941
3942 /* take shield costs of all buidings into account; normalized by 1000 */
3943 score *= (1 + (1 - exp(- (float) MAX(0, build_shield_cost) / 1000)) / 5);
3944 /* take trade into account; normalized by 100 */
3945 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_TRADE]) / 100))
3946 / 5);
3947 /* take luxury into account; normalized by 100 */
3948 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_LUXURY]) / 100))
3949 / 5);
3950 /* take science into account; normalized by 100 */
3951 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_SCIENCE]) / 100))
3952 / 5);
3953
3955
3956 /* Take food into account; the food surplus is clipped to values between
3957 * -10..20 and normalize by 10. Thus, the factor is between 0.9 and 1.2. */
3958 score *= (1 + (float) CLIP(-10, pcity->surplus[O_FOOD], 20) / 10 );
3959
3960 /* Reduce the score due to city illness (plague). The illness is given in
3961 * tenth of percent (0..1000) and normalized by 25. Thus, this factor is
3962 * between 0.6 (ill city) and 1.0 (health city). */
3963 score *= (100 - (float)city_illness_calc(pcity, NULL, NULL, NULL, NULL)
3964 / 25);
3965
3966 if (has_wonder) {
3967 /* people like wonders */
3968 score *= 1.25;
3969 }
3970
3971 if (is_capital(pcity)) {
3972 /* the capital is a magnet for the citizens */
3973 score *= 1.25;
3974 }
3975
3976 /* take into account effects */
3977 score *= (1.0 + get_city_bonus(pcity, EFT_MIGRATION_PCT) / 100.0);
3978
3979 log_debug("[M] %s score: %.3f", city_name_get(pcity), score);
3980
3981 /* set migration score for the city */
3982 pcity->server.migration_score = score;
3983 /* set the turn, when the score was calculated */
3984 pcity->server.mgr_score_calc_turn = game.info.turn;
3985
3986 return score;
3987}
3988
3989/**********************************************************************/
3996 struct city *pcity_to)
3997{
3999 struct tile *ptile_from, *ptile_to;
4001 const char *nation_from, *nation_to;
4002 struct city *rcity = NULL;
4003 int to_id = pcity_to->id;
4004 const struct civ_map *nmap = &(wld.map);
4005
4006 if (!pcity_from || !pcity_to) {
4007 return FALSE;
4008 }
4009
4013 /* We copy that, because city_link always returns the same pointer. */
4020
4021 /* Check food supply in the receiver city */
4023 bool migration = FALSE;
4024
4025 if (pcity_to->surplus[O_FOOD] >= game.info.food_cost) {
4026 migration = TRUE;
4027 } else {
4028 /* Check if there is a free tile for the new citizen which, when worked,
4029 * leads to zero or positive food surplus for the enlarged city */
4030 int max_food_tile = -1; /* no free tile */
4031
4033 city_tile(pcity_to), ptile) {
4034 if (city_can_work_tile(pcity_to, ptile)
4035 && tile_worked(ptile) != pcity_to) {
4036 /* Safest assumption is that city won't be celebrating once an
4037 * additional citizen is added */
4040 }
4042 if (max_food_tile >= 0
4043 && pcity_to->surplus[O_FOOD] + max_food_tile >= game.info.food_cost) {
4044 migration = TRUE;
4045 }
4046 }
4047
4048 if (!migration) {
4049 /* insufficiency food in receiver city; no additional citizens */
4050 if (pplayer_from == pplayer_to) {
4051 /* migration between one nation */
4053 /* TRANS: From <city1> to <city2>. */
4054 _("Migrants from %s can't go to %s because there is "
4055 "not enough food available!"),
4057 } else {
4058 /* migration between different nations */
4060 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4061 _("Migrants from %s can't go to %s (%s) because there "
4062 "is not enough food available!"),
4065 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4066 _("Migrants from %s (%s) can't go to %s because there "
4067 "is not enough food available!"),
4069 }
4070
4071 return FALSE;
4072 }
4073 }
4074
4076 /* receiver city can't grow */
4077 if (pplayer_from == pplayer_to) {
4078 /* migration between one nation */
4080 /* TRANS: From <city1> to <city2>. */
4081 _("Migrants from %s can't go to %s because it needs "
4082 "an improvement to grow!"),
4084 } else {
4085 /* migration between different nations */
4087 /* TRANS: From <city1> to <city2> of <city2 nation adjective>. */
4088 _("Migrants from %s can't go to %s (%s) because it "
4089 "needs an improvement to grow!"),
4092 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4093 _("Migrants from %s (%s) can't go to %s because it "
4094 "needs an improvement to grow!"),
4096 }
4097
4098 return FALSE;
4099 }
4100
4101 /* reduce size of giver */
4102 if (city_size_get(pcity_from) == 1) {
4103
4105 /* Preserve nationality of city's only citizen */
4107 }
4108
4109 /* do not destroy wonders */
4110 city_built_iterate(pcity_from, pimprove) {
4111 if (is_wonder(pimprove)) {
4112 return FALSE;
4113 }
4115
4116 /* find closest city other of the same player than pcity_from */
4118 FALSE, FALSE, TRUE, FALSE, NULL);
4119
4120 if (rcity) {
4121 int id = pcity_from->id;
4122
4123 /* transfer all units to the closest city */
4125 pcity_from->units_supported, rcity, pcity_from,
4126 -1, TRUE);
4128
4129 script_server_signal_emit("city_size_change", pcity_from,
4130 (lua_Integer)(-1), "migration_from");
4131
4132 if (city_exist(id)) {
4133 script_server_signal_emit("city_destroyed", pcity_from,
4134 pcity_from->owner, NULL);
4135
4136 if (city_exist(id)) {
4138 }
4139 }
4140
4142 _("%s was disbanded by its citizens."),
4143 name_from);
4144 } else {
4145 /* it's the only city of the nation */
4146 return FALSE;
4147 }
4148 } else {
4149 /* the migrants take half of the food box with them (this prevents
4150 * migration -> grow -> migration -> ... cycles) */
4151 pcity_from->food_stock /= 2;
4152
4154 /* Those citizens that are from the target nation are most
4155 * ones migrating. */
4156 if (citizens_nation_get(pcity_from, pplayer_to->slot) > 0) {
4158 } else if (!citizens_nation_get(pcity_from, pplayer_citizen->slot)) {
4159 /* No native citizens at all in the city, choose random foreigner */
4161
4163 }
4164 /* This should be followed by city_reduce_size(). */
4166 }
4167 city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
4169 if (city_refresh(pcity_from)) {
4171 }
4172 }
4173
4174 /* This should be _before_ the size of the city is increased. Thus, the
4175 * order of the messages is correct (1: migration; 2: increased size). */
4176 if (pplayer_from == pplayer_to) {
4177 /* migration between one nation */
4179 /* TRANS: From <city1> to <city2>. */
4180 _("Migrants from %s moved to %s in search of a better "
4181 "life."), name_from, name_to);
4182 } else {
4183 /* migration between different nations */
4185 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4186 _("Migrants from %s moved to %s (%s) in search of a "
4187 "better life."),
4190 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4191 _("Migrants from %s (%s) moved to %s in search of a "
4192 "better life."),
4194 }
4195
4196 /* Increase size of receiver city */
4197 if (city_exist(to_id)) {
4199
4200 if (city_exist(to_id)) {
4203 if (city_refresh(pcity_to)) {
4205 }
4206 if (incr_success) {
4207 script_server_signal_emit("city_size_change", pcity_to,
4208 (lua_Integer)1, "migration_to");
4209 }
4210 }
4211 }
4212
4213 log_debug("[M] T%d migration successful (%s -> %s)",
4215
4216 return TRUE;
4217}
4218
4219/**********************************************************************/
4241{
4242 bool internat = FALSE;
4243
4244 if (!game.server.migration) {
4245 return FALSE;
4246 }
4247
4249 || (game.server.mgr_worldchance <= 0
4250 && game.server.mgr_nationchance <= 0)) {
4251 return FALSE;
4252 }
4253
4254 /* check for migration */
4255 players_iterate(pplayer) {
4256 if (!pplayer->cities) {
4257 continue;
4258 }
4259
4260 if (check_city_migrations_player(pplayer)) {
4261 internat = TRUE;
4262 }
4264
4265 return internat;
4266}
4267
4268/**********************************************************************/
4273 struct player *pplayer = city_owner(pcity);
4274 struct tile *ptile = city_tile(pcity);
4275
4277
4278 if (pcity->food_stock > 0) {
4279 pcity->food_stock = 0;
4280
4281 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4282 /* TRANS: %s is a city name */
4283 _("All stored food destroyed in %s."), city_link(pcity));
4284
4285 return TRUE;
4286 }
4287
4288 return FALSE;
4289}
4290
4291/**********************************************************************/
4294static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
4295{
4296 struct player *pplayer = city_owner(pcity);
4297 struct tile *ptile = city_tile(pcity);
4299
4301
4302 notify_player(pplayer, ptile, E_DISASTER,
4303 ftc_server,
4304 /* TRANS: Disasters such as Earthquake */
4305 _("%s was hit by %s."), city_name_get(pcity),
4307
4309 if (pplayer->economic.gold > 0 && pcity->prod[O_TRADE] > 0) {
4310 int amount = pcity->prod[O_TRADE] * 5;
4311
4312 amount = MIN(pplayer->economic.gold, amount);
4313 pplayer->economic.gold -= amount;
4314 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4315 PL_("Robbery in %s. %d gold stolen.",
4316 "Robbery in %s. %d gold stolen.", amount),
4319 }
4320 }
4321
4324 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4325 _("Pollution near %s."), city_link(pcity));
4327 }
4328 }
4329
4332 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4333 _("Fallout near %s."), city_link(pcity));
4335 }
4336 }
4337
4340 && pcity->size > 1)) {
4341 if (!city_reduce_size(pcity, 1, NULL, "disaster")) {
4342 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4343 /* TRANS: "Industrial Accident destroys Bogota entirely." */
4344 _("%s destroys %s entirely."),
4346 pcity = NULL;
4347 } else {
4348 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4349 /* TRANS: "Nuclear Accident ... Montreal." */
4350 _("%s causes population loss in %s."),
4352 }
4353
4355 }
4356
4358 int total = 0;
4359 struct impr_type *imprs[B_LAST];
4360
4361 city_built_iterate(pcity, pimprove) {
4362 if (is_improvement(pimprove)
4363 && !improvement_has_flag(pimprove, IF_DISASTER_PROOF)) {
4364 imprs[total++] = pimprove;
4365 }
4367
4368 if (total > 0) {
4369 int num = fc_rand(total);
4370
4371 building_lost(pcity, imprs[num], "disaster", NULL);
4372
4373 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4374 /* TRANS: second %s is the name of a city improvement */
4375 _("%s destroys %s in %s."),
4378 city_link(pcity));
4379
4381 }
4382 }
4383
4387 }
4388 }
4389
4391 if (pcity->shield_stock > 0) {
4392 char prod[256];
4393
4394 pcity->shield_stock = 0;
4395 nullify_prechange_production(pcity); /* Make it impossible to recover */
4396
4397 universal_name_translation(&pcity->production, prod, sizeof(prod));
4398 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4399 /* TRANS: "Production of Colossus in Rhodes destroyed." */
4400 _("Production of %s in %s destroyed."),
4401 prod, city_link(pcity));
4402
4404 }
4405 }
4406
4407 script_server_signal_emit("disaster_occurred", pdis, pcity,
4409 script_server_signal_emit("disaster", pdis, pcity);
4410}
4411
4412/**********************************************************************/
4416{
4417 if (game.info.disasters == 0) {
4418 /* Shortcut out as no disaster is possible. */
4419 return;
4420 }
4421
4422 players_iterate(pplayer) {
4423 /* Safe city iterator needed as disaster may destroy city */
4424 city_list_iterate_safe(pplayer->cities, pcity) {
4425 int id = pcity->id;
4426
4428 if (city_exist(id)) {
4429 /* City survived earlier disasters. */
4430 int probability = game.info.disasters * pdis->frequency;
4431 int result = fc_rand(DISASTER_BASE_RARITY);
4432
4433 if (result < probability) {
4436 }
4437 }
4438 }
4442}
4443
4444/**********************************************************************/
4452static bool check_city_migrations_player(const struct player *pplayer)
4453{
4457 float score_from, score_tmp, weight;
4458 int dist, mgr_dist;
4459 bool internat = FALSE;
4460
4461 /* check for each city
4462 * city_list_iterate_safe_end must be used because we could
4463 * remove one city from the list */
4465 /* no migration out of the capital */
4466 if (is_capital(pcity)) {
4467 continue;
4468 }
4469
4470 /* check only each (game.server.mgr_turninterval) turn
4471 * (counted from the funding turn) and do not migrate
4472 * the same turn a city is founded */
4473 if (game.info.turn == pcity->turn_founded
4474 || ((game.info.turn - pcity->turn_founded)
4475 % game.server.mgr_turninterval) != 0) {
4476 continue;
4477 }
4478
4483
4484 /* score of the actual city
4485 * taking into account a persistence factor of 3 */
4487
4488 log_debug("[M] T%d check city: %s score: %6.3f (%s)",
4490 player_name(pplayer));
4491
4492 /* consider all cities within the maximal possible distance
4493 * (= CITY_MAP_MAX_RADIUS + GAME_MAX_MGR_DISTANCE) */
4496 acity = tile_city(ptile);
4497
4498 if (!acity || acity == pcity) {
4499 /* no city or the city in the center */
4500 continue;
4501 }
4502
4503 /* Calculate the migration distance. The value of
4504 * game.server.mgr_distance is added to the current city radius. If the
4505 * distance between both cities is lower or equal than this value,
4506 * migration is possible. */
4509
4510 /* distance between the two cities */
4512
4513 if (dist > mgr_dist) {
4514 /* to far away */
4515 continue;
4516 }
4517
4518 /* score of the second city, weighted by the distance */
4519 weight = ((float) (mgr_dist + 1 - dist) / (float) (mgr_dist + 1));
4521
4522 log_debug("[M] T%d - compare city: %s (%s) dist: %d mgr_dist: %d "
4523 "score: %6.3f", game.info.turn, city_name_get(acity),
4525
4526 if (game.server.mgr_nationchance > 0 && city_owner(acity) == pplayer) {
4527 /* migration between cities of the same owner */
4529 /* select the best! */
4532
4533 log_debug("[M] T%d - best city (player): %s (%s) score: "
4534 "%6.3f (> %6.3f)", game.info.turn,
4537 }
4538 } else if (game.server.mgr_worldchance > 0
4539 && city_owner(acity) != pplayer) {
4540 /* migration between cities of different owners */
4542 /* Modify the score if citizens could migrate to a city of their
4543 * original nation. */
4544 if (citizens_nation_get(pcity, city_owner(acity)->slot) > 0) {
4545 score_tmp *= 2;
4546 }
4547 }
4548
4550 /* select the best! */
4553
4554 log_debug("[M] T%d - best city (world): %s (%s) score: "
4555 "%6.3f (> %6.3f)", game.info.turn,
4559 }
4560 }
4562
4563 if (best_city_player != NULL) {
4564 /* First, do the migration within one nation */
4565 if (fc_rand(100) >= game.server.mgr_nationchance) {
4566 /* No migration */
4567 /* N.B.: city_link always returns the same pointer. */
4570 _("Citizens of %s are thinking about migrating to %s "
4571 "for a better life."),
4573 } else {
4575 }
4576
4577 /* Stop here */
4578 continue;
4579 }
4580
4581 if (best_city_world != NULL) {
4582 /* Second, do the migration between all nations */
4583 if (fc_rand(100) >= game.server.mgr_worldchance) {
4584 const char *nname;
4585
4587 /* No migration */
4588 /* N.B.: city_link always returns the same pointer. */
4591 /* TRANS: <city1> to <city2> (<city2 nation adjective>). */
4592 _("Citizens of %s are thinking about migrating to %s "
4593 "(%s) for a better life."),
4595 } else {
4597 internat = TRUE;
4598 }
4599
4600 /* Stop here */
4601 continue;
4602 }
4604
4605 return internat;
4606}
4607
4608/**********************************************************************/
4612{
4613 pcity->style = city_style(pcity);
4614}
4615
4616/**********************************************************************/
4621{
4623 struct packet_city_update_counters packet;
4624
4625 packet.city = pcity->id;
4626
4628
4629 packet.count = counter_count;
4630 for (i = 0; i < counter_count; i++) {
4631 packet.counters[i] = pcity->counter_values[i];
4632 }
4633
4636}
4637
4638/**********************************************************************/
4641void city_tc_effect_refresh(struct player *pplayer)
4642{
4643 const struct civ_map *nmap = &(wld.map);
4644
4645 city_list_iterate(pplayer->cities, pcity) {
4646 bool changed = FALSE;
4647
4649 city_tile(pcity), ptile, idx, x, y) {
4650 if (ptile->worked == pcity
4653 pcity->specialists[DEFAULT_SPECIALIST]++;
4654 changed = TRUE;
4655 }
4657
4658 if (changed) {
4661 }
4663}
const char * achievement_name_translation(struct achievement *pach)
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:3396
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:3413
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:3359
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:3597
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:3651
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:514
#define city_list_iterate_safe(citylist, _city)
Definition city.h:519
@ CNA_BROADCAST_PENDING
Definition city.h:305
@ CNA_NOT
Definition city.h:303
@ CNA_NORMAL
Definition city.h:304
#define city_list_iterate(citylist, pcity)
Definition city.h:505
#define city_tile(_pcity_)
Definition city.h:561
#define cities_iterate(pcity)
Definition city.h:509
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:211
@ CITIZEN_ANGRY
Definition city.h:268
@ CITIZEN_HAPPY
Definition city.h:265
@ CITIZEN_CONTENT
Definition city.h:266
@ CITIZEN_UNHAPPY
Definition city.h:267
#define output_type_iterate(output)
Definition city.h:842
#define INCITE_IMPOSSIBLE_COST
Definition city.h:93
#define city_owner(_pcity_)
Definition city.h:560
#define city_tile_iterate_skip_free_worked_end
Definition city.h:219
#define city_list_iterate_end
Definition city.h:507
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:227
#define city_list_iterate_safe_end
Definition city.h:541
@ FEELING_FINAL
Definition city.h:281
#define city_tile_iterate_end
Definition city.h:235
#define city_built_iterate(_pcity, _p)
Definition city.h:831
#define city_built_iterate_end
Definition city.h:837
#define output_type_iterate_end
Definition city.h:848
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3277
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:3351
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:3476
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3188
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2979
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:3077
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3165
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:3005
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2943
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:3670
void city_map_update_all(struct city *pcity)
Definition citytools.c:3370
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:3291
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3451
#define LOG_BUILD_TARGET
Definition citytools.h:21
static bool city_illness_check(const struct city *pcity)
Definition cityturn.c:3786
static void uk_rem_gold_append(struct unit *punit)
Definition cityturn.c:3101
static bool worklist_change_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2193
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:3002
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:4294
static bool city_distribute_surplus_shields(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2545
static void unit_list_referred_destroy(struct unit_list *punitlist)
Definition cityturn.c:3114
static bool place_pollution(struct city *pcity, enum extra_cause cause)
Definition cityturn.c:3399
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2408
static void uk_rem_gold_callback(struct unit *punit)
Definition cityturn.c:3080
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:3317
static void update_city_activity(struct city *pcity)
Definition cityturn.c:3576
static void upgrade_unit_prod(struct city *pcity)
Definition cityturn.c:2521
static float city_migration_score(struct city *pcity)
Definition cityturn.c:3911
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3567
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4272
bool check_city_migrations(void)
Definition cityturn.c:4240
static void upgrade_building_prod(struct city *pcity)
Definition cityturn.c:2474
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3220
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, const char *reason)
Definition cityturn.c:1031
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:1082
static void city_refresh_after_city_size_increase(struct city *pcity, struct player *nationality)
Definition cityturn.c:997
static void define_orig_production_values(struct city *pcity)
Definition cityturn.c:3536
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:4620
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:2626
static struct unit static const struct impr_type * building_upgrades_to(struct city *pcity, const struct impr_type *pimprove)
Definition cityturn.c:2453
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:3137
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3455
static void nullify_caravan_and_disband_plus(struct city *pcity)
Definition cityturn.c:3557
static bool sell_random_building(struct player *pplayer, struct cityimpr_list *imprs)
Definition cityturn.c:3034
static bool disband_city(struct city *pcity)
Definition cityturn.c:3799
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 bool city_increase_size(struct city *pcity)
Definition cityturn.c:920
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:3283
void city_style_refresh(struct city *pcity)
Definition cityturn.c:4611
static bool city_balance_treasury_units(struct city *pcity)
Definition cityturn.c:3364
static const struct unit_type * unit_upgrades_to(struct city *pcity, const struct unit_type *id)
Definition cityturn.c:2499
static bool do_city_migration(struct city *pcity_from, struct city *pcity_to)
Definition cityturn.c:3995
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:4641
static void check_pollution(struct city *pcity)
Definition cityturn.c:3438
static void city_reset_foodbox(struct city *pcity, int new_size, bool shrink)
Definition cityturn.c:905
void check_disasters(void)
Definition cityturn.c:4415
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:1159
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:2785
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:4452
static bool city_build_unit(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2846
void cm_clear_cache(struct city *pcity)
Definition cm.c:322
void cm_init_parameter(struct cm_parameter *dest)
Definition cm.c:2183
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:2469
void cm_query_result(struct city *pcity, const struct cm_parameter *param, struct cm_result *result, bool negative_ok)
Definition cm.c:2122
void cm_init_emergency_parameter(struct cm_parameter *dest)
Definition cm.c:2201
void cm_print_city(const struct city *pcity)
Definition cm.c:2431
char * incite_cost
Definition comments.c:76
struct player * conn_get_player(const struct connection *pconn)
Definition connection.c:763
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:366
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:356
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:89
int Tech_type_id
Definition fc_types.h:236
unsigned char citizens
Definition fc_types.h:247
@ RPT_CERTAIN
Definition fc_types.h:533
@ RPT_POSSIBLE
Definition fc_types.h:532
#define MAX_LEN_NAME
Definition fc_types.h:66
#define CITY_MAP_MAX_RADIUS
Definition fc_types.h:83
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
enum output_type_id Output_type_id
Definition fc_types.h:237
#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:61
struct world wld
Definition game.c:62
struct city * game_city_by_number(int id)
Definition game.c:106
#define GAME_MAX_MGR_DISTANCE
Definition game.h:538
const char * government_name_translation(const struct government *pgovern)
Definition government.c:143
struct government * government_of_city(const struct city *pcity)
Definition government.c:123
Government_type_id government_number(const struct government *pgovern)
Definition government.c:91
GType type
Definition repodlgs.c:1313
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:565
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
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:454
const char * nation_group_name_translation(const struct nation_group *pgroup)
Definition nation.c:1090
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
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)
struct city_list * cities
Definition packhand.c:119
int player_number(const struct player *pplayer)
Definition player.c:837
const char * player_name(const struct player *pplayer)
Definition player.c:895
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1203
const char * diplrel_name_translation(int value)
Definition player.c:1631
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
#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:273
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:169
#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:1474
#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
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
#define DEFAULT_SPECIALIST
Definition specialist.h:43
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:317
int id
Definition city.h:323
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
const struct unit_type * utype
Definition unit.h:141
struct player * owner
Definition unit.h:145
enum universals_n kind
Definition fc_types.h:608
universals_u value
Definition fc_types.h:607
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:238
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:955
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_worked(_tile)
Definition tile.h:115
#define tile_has_extra(ptile, pextra)
Definition tile.h:148
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:553
const struct impr_type * building
Definition fc_types.h:546
bool unit_is_alive(int id)
Definition unit.c:2290
#define unit_tile(_pu)
Definition unit.h:404
#define unit_cargo_iterate_end
Definition unit.h:585
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:582
#define unit_owner(_pu)
Definition unit.h:403
#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:1771
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1713
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:1665
void unit_unset_removal_callback(struct unit *punit)
Definition unittools.c:1785
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2139
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
int unit_build_shield_cost(const struct city *pcity, const struct unit *punit)
Definition unittype.c:1482
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1593
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1584
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1534
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1444
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1566
#define unit_tech_reqs_iterate_end
Definition unittype.h:888
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:882
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