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/**********************************************************************/
906{
908
909 pcity->food_stock = (city_granary_size(new_size) * savings_pct) / 100;
910}
911
912/**********************************************************************/
917static bool city_increase_size(struct city *pcity)
918{
919 int new_food;
921 bool have_square = FALSE;
922 bool rapture_grow = city_rapture_grow(pcity); /* Check before size increase! */
923 struct tile *pcenter = city_tile(pcity);
924 struct player *powner = city_owner(pcity);
925 const struct impr_type *pimprove = pcity->production.value.building;
926 const struct civ_map *nmap = &(wld.map);
927 int stock;
928 int granary;
929
931 /* Need improvement */
935 _("%s needs %s (being built) to grow beyond size %d."),
939 } else {
941 _("%s needs an improvement to grow beyond size %d."),
943 }
944 /* Granary can only hold so much */
946 * (100 * 100 - game.server.aqueductloss * (100 - savings_pct))
947 / (100 * 100));
948 pcity->food_stock = MIN(pcity->food_stock, new_food);
949
950 return FALSE;
951 }
952
954 if (pcity->food_stock <= granary) {
955 stock = 0;
956 } else {
957 stock = pcity->food_stock - granary;
958 }
959
961
962 /* Do not empty food stock if city is growing by celebrating */
963 if (rapture_grow) {
965 } else {
967 }
968 pcity->food_stock = MIN(pcity->food_stock, new_food);
969
970 /* If there is enough food, and the city is big enough,
971 * make new citizens into scientists or taxmen -- Massimo */
972
973 /* Ignore food if no square can be worked */
975 ptile, _index, _x, _y) {
976 if (tile_worked(ptile) != pcity /* Quick test */
977 && city_can_work_tile(pcity, ptile)) {
979 }
981
982 if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
984 pcity->specialists[best_specialist(O_SCIENCE, pcity)]++;
985 } else if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
987 pcity->specialists[best_specialist(O_GOLD, pcity)]++;
988 } else {
989 pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
990 }
991
992 /* Deprecated signal. Connect your lua functions to "city_size_change" that's
993 * emitted from calling functions which know the 'reason' of the increase. */
994 script_server_signal_emit("city_growth", pcity,
996
997 return TRUE;
998}
999
1000/**********************************************************************/
1004 struct player *nationality)
1005{
1006 struct player *powner = city_owner(pcity);
1007
1008 /* Update citizens. */
1009 citizens_update(pcity, nationality);
1010
1011 /* Refresh the city data; this also checks the squared city radius. */
1013
1015
1016 /* Update cities that have trade routes with us */
1018 if (city_refresh(pcity2)) {
1019 /* This should never happen, but if it does, make sure not to
1020 * leave workers outside city radius. */
1022 }
1024
1026 _("%s grows to size %d."),
1028
1030
1031 sync_cities();
1032}
1033
1034/**********************************************************************/
1038 struct player *nationality, const char *reason)
1039{
1040 int change = size - city_size_get(pcity);
1041
1042 if (change > 0) {
1044 int real_change;
1046 int id = pcity->id;
1047
1048 /* Increase city size until size reached, or increase fails */
1050 /* TODO: This is currently needed only because there's
1051 * deprecated script signal "city_growth" emitted.
1052 * Check the need after signal has been dropped completely. */
1053 if (!city_exist(id)) {
1054 return FALSE;
1055 }
1056
1057 current_size++;
1058 }
1059
1061
1063
1064 if (real_change != 0 && reason != NULL) {
1065 script_server_signal_emit("city_size_change", pcity,
1067
1068 if (!city_exist(id)) {
1069 return FALSE;
1070 }
1071 }
1072 } else if (change < 0) {
1073 /* We assume that city_change_size() is never called because
1074 * of enemy actions. If that changes, enemy must be passed
1075 * to city_reduce_size() */
1076 return city_reduce_size(pcity, -change, NULL, reason);
1077 }
1078
1080
1081 return TRUE;
1082}
1083
1084/**********************************************************************/
1088static void city_populate(struct city *pcity, struct player *nationality)
1089{
1090 int saved_id = pcity->id;
1091 int granary_size = city_granary_size(city_size_get(pcity));
1092
1093 pcity->food_stock += pcity->surplus[O_FOOD];
1094 if (pcity->food_stock >= granary_size || city_rapture_grow(pcity)) {
1098 _("A recent plague outbreak prevents growth in %s."),
1099 city_link(pcity));
1100 /* Lose excess food */
1101 pcity->food_stock = MIN(pcity->food_stock, granary_size);
1102 } else {
1103 bool success;
1104
1107
1108 if (success) {
1110 script_server_signal_emit("city_size_change", pcity,
1111 (lua_Integer)1, "growth");
1112 }
1113 }
1114 } else if (pcity->food_stock < 0) {
1115 /* FIXME: should this depend on units with ability to build
1116 * cities or on units that require food in upkeep?
1117 * I'll assume citybuilders (units that 'contain' 1 pop) -- sjolie
1118 * The above may make more logical sense, but in game terms
1119 * you want to disband a unit that is draining your food
1120 * reserves. Hence, I'll assume food upkeep > 0 units. -- jjm
1121 */
1122 unit_list_iterate_safe(pcity->units_supported, punit) {
1123 if (punit->upkeep[O_FOOD] > 0) {
1124 const char *punit_link = unit_tile_link(punit);
1125
1130 _("Famine feared in %s, %s lost!"),
1132 }
1133
1134 if (city_exist(saved_id)) {
1136 }
1137
1138 return;
1139 }
1141 if (city_size_get(pcity) > 1) {
1144 _("Famine causes population loss in %s."),
1145 city_link(pcity));
1146 } else {
1149 _("Famine destroys %s entirely."),
1150 city_link(pcity));
1151 }
1153 if (city_reduce_size(pcity, 1, NULL, "famine")) {
1154 pcity->had_famine = TRUE;
1155 }
1156 }
1157}
1158
1159/**********************************************************************/
1166 struct city *pcity,
1167 struct player *pplayer,
1168 int saved_id)
1169{
1170 const void *ptarget;
1171 const char *tgt_name;
1172 const struct requirement_vector *build_reqs;
1173 const char *signal_name;
1174 const struct req_context city_ctxt = {
1175 .player = pplayer,
1176 .city = pcity,
1177 .tile = city_tile(pcity)
1178 /* FIXME: Setting .unittype is currently redundant,
1179 * but can_city_build_unit_direct() does it */
1180 };
1181 bool purge = FALSE;
1182 bool known = FALSE;
1183
1184 if (pcity->wlcb == WLCB_ALWAYS_PURGE) {
1185 return TRUE;
1186 }
1187
1188 switch (target->kind) {
1189 case VUT_UTYPE:
1190 ptarget = target->value.utype;
1191 build_reqs = &target->value.utype->build_reqs;
1193 signal_name = "unit_cant_be_built";
1194 break;
1195 case VUT_IMPROVEMENT:
1196 ptarget = target->value.building;
1197 build_reqs = &target->value.building->reqs;
1199 signal_name = "building_cant_be_built";
1200 break;
1201 default:
1203 || target->kind == VUT_UTYPE), FALSE);
1204 return FALSE;
1205 }
1206
1207 if (pcity->wlcb == WLCB_ALWAYS_POSTPONE) {
1208 notify_player(pplayer, city_tile(pcity),
1210 _("%s can't build %s from the worklist. "
1211 "Postponing..."),
1213 tgt_name);
1214 return FALSE;
1215 }
1216
1217 requirement_vector_iterate(build_reqs, preq) {
1219 known = TRUE;
1220 switch (preq->source.kind) {
1221 case VUT_COUNTER:
1222 if (preq->present) {
1223 notify_player(pplayer, city_tile(pcity),
1225 _("%s can't build %s from the worklist; "
1226 "counter %s value's checkpoint do not met "
1227 "Postponing..."),
1229 tgt_name,
1231 (preq->source.value.counter));
1232 } else {
1233 purge = TRUE;
1234 }
1235 break;
1236 case VUT_ADVANCE:
1237 if (preq->present) {
1238 notify_player(pplayer, city_tile(pcity),
1240 _("%s can't build %s from the worklist; "
1241 "tech %s not yet available. Postponing..."),
1243 tgt_name,
1245 (preq->source.value.advance));
1247 pcity, "need_tech");
1248 } else {
1249 /* While techs can be unlearned, this isn't useful feedback */
1250 purge = TRUE;
1251 }
1252 break;
1253 case VUT_TECHFLAG:
1254 if (preq->present) {
1255 notify_player(pplayer, city_tile(pcity),
1257 _("%s can't build %s from the worklist; "
1258 "no tech with flag \"%s\" yet available. "
1259 "Postponing..."),
1261 tgt_name,
1262 tech_flag_id_name(preq->source.value.techflag));
1264 pcity, "need_techflag");
1265 } else {
1266 /* While techs can be unlearned, this isn't useful feedback */
1267 purge = TRUE;
1268 }
1269 break;
1270 case VUT_IMPROVEMENT:
1271 case VUT_SITE:
1272 if (preq->range == REQ_RANGE_LOCAL) {
1273 /* Building itself is never going to change */
1274 purge = TRUE;
1275 } else {
1276 if (preq->present) {
1277 notify_player(pplayer, city_tile(pcity),
1279 _("%s can't build %s from the worklist; "
1280 "need to have %s first. Postponing..."),
1282 tgt_name,
1284 preq->source.value.building));
1286 pcity, "need_building");
1287 } else {
1288 notify_player(pplayer, city_tile(pcity),
1290 _("%s can't build %s from the worklist; "
1291 "need to not have %s. Postponing..."),
1293 tgt_name,
1295 preq->source.value.building));
1297 pcity, "have_building");
1298 }
1299 }
1300 break;
1301 case VUT_IMPR_GENUS:
1302 if (preq->range == REQ_RANGE_LOCAL) {
1303 /* Building's own genus is never going to change */
1304 purge = TRUE;
1305 } else {
1306 if (preq->present) {
1307 notify_player(pplayer, city_tile(pcity),
1309 _("%s can't build %s from the worklist; "
1310 "need to have %s first. Postponing..."),
1312 tgt_name,
1314 preq->source.value.impr_genus));
1316 pcity, "need_building_genus");
1317 } else {
1318 notify_player(pplayer, city_tile(pcity),
1320 _("%s can't build %s from the worklist; "
1321 "need to not have %s. Postponing..."),
1323 tgt_name,
1325 preq->source.value.impr_genus));
1327 pcity, "have_building_genus");
1328 }
1329 }
1330 break;
1331 case VUT_IMPR_FLAG:
1332 if (preq->range == REQ_RANGE_LOCAL) {
1333 /* Building's own flags are never going to change */
1334 purge = TRUE;
1335 } else {
1336 if (preq->present) {
1337 notify_player(pplayer, city_tile(pcity),
1339 _("%s can't build %s from the worklist; "
1340 "need to have %s first. Postponing..."),
1342 tgt_name,
1344 preq->source.value.impr_flag));
1346 pcity, "need_building_flag");
1347 } else {
1348 notify_player(pplayer, city_tile(pcity),
1350 _("%s can't build %s from the worklist; "
1351 "need to not have %s. Postponing..."),
1353 tgt_name,
1355 preq->source.value.impr_flag));
1357 pcity, "have_building_flag");
1358 }
1359 }
1360 break;
1361 case VUT_PLAYER_FLAG:
1362 if (preq->present) {
1363 notify_player(pplayer, city_tile(pcity),
1365 _("%s can't build %s from the worklist; "
1366 "need to have %s first. Postponing..."),
1368 tgt_name,
1370 preq->source.value.plr_flag));
1372 pcity, "need_player_flag");
1373 } else {
1374 notify_player(pplayer, city_tile(pcity),
1376 _("%s can't build %s from the worklist; "
1377 "need to not have %s. Postponing..."),
1379 tgt_name,
1381 preq->source.value.plr_flag));
1383 pcity, "have_player_flag");
1384 }
1385 break;
1386 case VUT_PLAYER_STATE:
1387 purge = TRUE;
1388 break;
1389 case VUT_GOVERNMENT:
1390 if (preq->present) {
1391 notify_player(pplayer, city_tile(pcity),
1393 _("%s can't build %s from the worklist; "
1394 "it needs %s government. Postponing..."),
1396 tgt_name,
1397 government_name_translation(preq->source.value.govern));
1399 pcity, "need_government");
1400 } else {
1401 notify_player(pplayer, city_tile(pcity),
1403 _("%s can't build %s from the worklist; "
1404 "it cannot have %s government. Postponing..."),
1406 tgt_name,
1407 government_name_translation(preq->source.value.govern));
1409 pcity, "have_government");
1410 }
1411 break;
1412 case VUT_ACHIEVEMENT:
1413 if (preq->present) {
1414 notify_player(pplayer, city_tile(pcity),
1416 _("%s can't build %s from the worklist; "
1417 "it needs \"%s\" achievement. Postponing..."),
1419 tgt_name,
1420 achievement_name_translation(preq->source.value.achievement));
1422 pcity, "need_achievement");
1423 } else {
1424 /* Can't unachieve things. */
1425 purge = TRUE;
1426 }
1427 break;
1428 case VUT_EXTRA:
1429 if (preq->present) {
1430 notify_player(pplayer, city_tile(pcity),
1432 Q_("?extra:%s can't build %s from the worklist; "
1433 "%s is required. Postponing..."),
1435 tgt_name,
1436 extra_name_translation(preq->source.value.extra));
1438 pcity, "need_extra");
1439 } else {
1440 notify_player(pplayer, city_tile(pcity),
1442 Q_("?extra:%s can't build %s from the worklist; "
1443 "%s is prohibited. Postponing..."),
1445 tgt_name,
1446 extra_name_translation(preq->source.value.extra));
1448 pcity, "have_extra");
1449 }
1450 break;
1451 case VUT_GOOD:
1452 if (preq->present) {
1453 notify_player(pplayer, city_tile(pcity),
1455 Q_("?extra:%s can't build %s from the worklist; "
1456 "%s is required. Postponing..."),
1458 tgt_name,
1459 goods_name_translation(preq->source.value.good));
1461 pcity, "need_good");
1462 } else {
1463 notify_player(pplayer, city_tile(pcity),
1465 Q_("?extra:%s can't build %s from the worklist; "
1466 "%s is prohibited. Postponing..."),
1468 tgt_name,
1469 goods_name_translation(preq->source.value.good));
1471 pcity, "have_good");
1472 }
1473 break;
1474 case VUT_TERRAIN:
1475 if (preq->present) {
1476 notify_player(pplayer, city_tile(pcity),
1478 Q_("?terrain:%s can't build %s from the worklist; "
1479 "%s terrain is required. Postponing..."),
1481 tgt_name,
1482 terrain_name_translation(preq->source.value.terrain));
1484 pcity, "need_terrain");
1485 } else {
1486 notify_player(pplayer, city_tile(pcity),
1488 Q_("?terrain:%s can't build %s from the worklist; "
1489 "%s terrain is prohibited. Postponing..."),
1491 tgt_name,
1492 terrain_name_translation(preq->source.value.terrain));
1494 pcity, "have_terrain");
1495 }
1496 break;
1497 case VUT_NATION:
1498 if (preq->range < REQ_RANGE_TRADE_ROUTE
1499 || preq->range == REQ_RANGE_PLAYER) {
1500 /* At higher ranges, new players with their nations may arrive */
1501 purge = TRUE;
1502 } else {
1503 if (preq->present) {
1504 notify_player(pplayer, city_tile(pcity),
1506 /* TRANS: "%s nation" is adjective */
1507 Q_("?nation:%s can't build %s from the worklist; "
1508 "%s nation is required. Postponing..."),
1510 tgt_name,
1511 nation_adjective_translation(preq->source.value.nation));
1513 pcity, "need_nation");
1514 } else {
1515 notify_player(pplayer, city_tile(pcity),
1517 Q_("?nation:%s can't build %s from the worklist; "
1518 "%s nation is prohibited. Postponing..."),
1520 tgt_name,
1521 nation_adjective_translation(preq->source.value.nation));
1523 pcity, "have_nation");
1524 }
1525 }
1526 break;
1527 case VUT_NATIONGROUP:
1528 if (preq->range < REQ_RANGE_TRADE_ROUTE
1529 || preq->range == REQ_RANGE_PLAYER) {
1530 /* At higher ranges, new players with their nations may arrive */
1531 purge = TRUE;
1532 } else {
1533 if (preq->present) {
1534 notify_player(pplayer, city_tile(pcity),
1536 /* TRANS: "%s nation" is adjective */
1537 Q_("?ngroup:%s can't build %s from the worklist; "
1538 "%s nation is required. Postponing..."),
1540 tgt_name,
1541 nation_group_name_translation(preq->source.value.nationgroup));
1543 pcity, "need_nationgroup");
1544 } else {
1545 notify_player(pplayer, city_tile(pcity),
1547 Q_("?ngroup:%s can't build %s from the worklist; "
1548 "%s nation is prohibited. Postponing..."),
1550 tgt_name,
1551 nation_group_name_translation(preq->source.value.nationgroup));
1553 pcity, "have_nationgroup");
1554 }
1555 }
1556 break;
1557 case VUT_STYLE:
1558 /* FIXME: City styles sometimes change over time, but it isn't
1559 * entirely under player control. Probably better to purge
1560 * with useful explanation. */
1561 if (preq->present) {
1562 notify_player(pplayer, city_tile(pcity),
1564 _("%s can't build %s from the worklist; "
1565 "only %s style cities may build this. Postponing..."),
1567 tgt_name,
1568 style_name_translation(preq->source.value.style));
1570 pcity, "need_style");
1571 } else {
1572 notify_player(pplayer, city_tile(pcity),
1574 _("%s can't build %s from the worklist; "
1575 "%s style cities may not build this. Postponing..."),
1577 tgt_name,
1578 style_name_translation(preq->source.value.style));
1580 pcity, "have_style");
1581 }
1582 break;
1583 case VUT_NATIONALITY:
1584 /* FIXME: Changing citizen nationality is hard: purging might be
1585 * more useful in this case. */
1586 if (preq->present) {
1587 notify_player(pplayer, city_tile(pcity),
1589 /* TRANS: Latter %s is citizen nationality */
1590 _("%s can't build %s from the worklist; "
1591 "only city with %s may build this. Postponing..."),
1593 tgt_name,
1594 nation_plural_translation(preq->source.value.nationality));
1596 pcity, "need_nationality");
1597 } else {
1598 notify_player(pplayer, city_tile(pcity),
1600 /* TRANS: Latter %s is citizen nationality */
1601 _("%s can't build %s from the worklist; "
1602 "only city without %s may build this. Postponing..."),
1604 tgt_name,
1605 nation_plural_translation(preq->source.value.nationality));
1607 pcity, "have_nationality");
1608 }
1609 break;
1610 case VUT_ORIGINAL_OWNER:
1611 /* Original owner of this specific city won't change.
1612 * Update this when supporting ranges other than REQ_RANGE_CITY. */
1613 purge = TRUE;
1614 break;
1615 case VUT_DIPLREL:
1616 case VUT_DIPLREL_TILE: /* The tile owner is the city owner */
1617 case VUT_DIPLREL_TILE_O: /* The tile owner is the city owner */
1618 if (preq->present) {
1619 const char *reason;
1620
1621 notify_player(pplayer, city_tile(pcity),
1623 /* TRANS: '%s' is a wide range of relationships;
1624 * e.g., 'Peace', 'Never met', 'Foreign',
1625 * 'Hosts embassy', 'Provided Casus Belli' */
1626 _("%s can't build %s from the worklist; "
1627 "the relationship '%s' is required."
1628 " Postponing..."),
1630 tgt_name,
1632 preq->source.value.diplrel));
1633
1634 if (preq->source.kind == VUT_DIPLREL_TILE) {
1635 reason = "need_diplrel_tile";
1636 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1637 reason = "need_diplrel_tile_o";
1638 } else {
1639 fc_assert(preq->source.kind == VUT_DIPLREL);
1640 reason = "need_diplrel";
1641 }
1642
1644 pcity, reason);
1645 } else {
1646 const char *reason;
1647
1648 notify_player(pplayer, city_tile(pcity),
1650 _("%s can't build %s from the worklist; "
1651 "the relationship '%s' is prohibited."
1652 " Postponing..."),
1654 tgt_name,
1656 preq->source.value.diplrel));
1657
1658 if (preq->source.kind == VUT_DIPLREL_TILE) {
1659 reason = "have_diplrel_tile";
1660 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1661 reason = "have_diplrel_tile_o";
1662 } else {
1663 fc_assert(preq->source.kind == VUT_DIPLREL);
1664 reason = "have_diplrel";
1665 }
1666
1668 pcity, reason);
1669 }
1670 break;
1673 if (preq->present) {
1674 const char *reason;
1675
1676 notify_player(pplayer, city_tile(pcity),
1678 /* TRANS: '%s' is a wide range of relationships;
1679 * e.g., 'Peace', 'Never met', 'Foreign',
1680 * 'Hosts embassy', 'Provided Casus Belli' */
1681 _("%s can't build %s from the worklist; "
1682 "unit with the relationship '%s' is required."
1683 " Postponing..."),
1685 tgt_name,
1687 preq->source.value.diplrel));
1688
1689 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1690 reason = "need_diplrel_unitany";
1691 } else {
1692 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1693 reason = "need_diplrel_unitany_o";
1694 }
1695
1697 pcity, reason);
1698 } else {
1699 const char *reason;
1700
1701 notify_player(pplayer, city_tile(pcity),
1703 _("%s can't build %s from the worklist; "
1704 "unit with the relationship '%s' is prohibited."
1705 " Postponing..."),
1707 tgt_name,
1709 preq->source.value.diplrel));
1710
1711 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1712 reason = "have_diplrel_unitany";
1713 } else {
1714 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1715 reason = "have_diplrel_unitany_o";
1716 }
1717
1719 pcity, reason);
1720 }
1721 break;
1722 case VUT_MINSIZE:
1723 if (preq->present) {
1724 notify_player(pplayer, city_tile(pcity),
1726 _("%s can't build %s from the worklist; "
1727 "city must be of size %d or larger. "
1728 "Postponing..."),
1730 tgt_name,
1731 preq->source.value.minsize);
1733 pcity, "need_minsize");
1734 } else {
1735 notify_player(pplayer, city_tile(pcity),
1737 _("%s can't build %s from the worklist; "
1738 "city must be of size %d or smaller."
1739 "Postponing..."),
1741 tgt_name,
1742 (preq->source.value.minsize - 1));
1744 pcity, "need_minsize");
1745 }
1746 break;
1747 case VUT_MINCULTURE:
1748 if (preq->present) {
1749 notify_player(pplayer, city_tile(pcity),
1751 _("%s can't build %s from the worklist; "
1752 "city must have culture of %d. Postponing..."),
1754 tgt_name,
1755 preq->source.value.minculture);
1757 pcity, "need_minculture");
1758 } else {
1759 /* What has been written may not be unwritten. */
1760 purge = TRUE;
1761 }
1762 break;
1763 case VUT_MINFOREIGNPCT:
1764 if (preq->present) {
1765 notify_player(pplayer, city_tile(pcity),
1767 _("%s can't build %s from the worklist; "
1768 "city must have %d%% foreign population. Postponing..."),
1770 tgt_name,
1771 preq->source.value.minforeignpct);
1773 pcity, "need_minforeignpct");
1774 } else {
1775 notify_player(pplayer, city_tile(pcity),
1777 _("%s can't build %s from the worklist; "
1778 "city must have %d%% native population. Postponing..."),
1780 tgt_name,
1781 100 - preq->source.value.minforeignpct);
1783 pcity, "need_minforeignpct");
1784 }
1785 break;
1786 case VUT_MINTECHS:
1787 if (preq->present) {
1788 notify_player(pplayer, city_tile(pcity),
1790 _("%s can't build %s from the worklist; "
1791 "%d techs must be known. Postponing..."),
1793 tgt_name,
1794 preq->source.value.min_techs);
1796 pcity, "need_mintechs");
1797 } else {
1798 purge = TRUE;
1799 }
1800 break;
1801 case VUT_MINCITIES:
1802 if (preq->present) {
1803 notify_player(pplayer, city_tile(pcity),
1805 _("%s can't build %s from the worklist; "
1806 "Must own %d cities. Postponing..."),
1808 tgt_name,
1809 preq->source.value.min_cities);
1811 pcity, "need_mincities");
1812 } else {
1813 purge = TRUE;
1814 }
1815 break;
1816 case VUT_MAXTILEUNITS:
1817 if (preq->present) {
1818 notify_player(pplayer, city_tile(pcity),
1820 PL_("%s can't build %s from the worklist; "
1821 "more than %d unit on tile."
1822 " Postponing...",
1823 "%s can't build %s from the worklist; "
1824 "more than %d units on tile."
1825 " Postponing...",
1826 preq->source.value.max_tile_units),
1828 tgt_name,
1829 preq->source.value.max_tile_units);
1831 pcity, "need_tileunits");
1832 } else {
1833 notify_player(pplayer, city_tile(pcity),
1835 PL_("%s can't build %s from the worklist; "
1836 "fewer than %d unit on tile."
1837 " Postponing...",
1838 "%s can't build %s from the worklist; "
1839 "fewer than %d units on tile."
1840 " Postponing...",
1841 preq->source.value.max_tile_units + 1),
1843 tgt_name,
1844 preq->source.value.max_tile_units + 1);
1846 pcity, "need_tileunits");
1847 }
1848 break;
1849 case VUT_AI_LEVEL:
1850 /* Can't change AI level. */
1851 purge = TRUE;
1852 break;
1853 case VUT_TERRAINCLASS:
1854 /* Change of terrain class is expected to be very unlikely. Purge!
1855 * TODO: Analyze ruleset to see how unlikely terrain class change actually is. */
1856 purge = TRUE;
1857 break;
1858 case VUT_TERRFLAG:
1859 if (preq->present) {
1860 notify_player(pplayer, city_tile(pcity),
1862 _("%s can't build %s from the worklist; "
1863 "terrain with \"%s\" flag is required. "
1864 "Postponing..."),
1866 tgt_name,
1867 terrain_flag_id_name(preq->source.value.terrainflag));
1869 pcity, "need_terrainflag");
1870 } else {
1871 notify_player(pplayer, city_tile(pcity),
1873 _("%s can't build %s from the worklist; "
1874 "terrain with \"%s\" flag is prohibited. "
1875 "Postponing..."),
1877 tgt_name,
1878 terrain_flag_id_name(preq->source.value.terrainflag));
1880 pcity, "have_terrainflag");
1881 }
1882 break;
1884 /* Changing the continent size is hard; cf. VUT_TERRAINCLASS above.
1885 * Change this when we support less fixed ranges (e.g. city?). */
1886 purge = TRUE;
1887 break;
1888 case VUT_ROADFLAG:
1889 if (preq->present) {
1890 notify_player(pplayer, city_tile(pcity),
1892 _("%s can't build %s from the worklist; "
1893 "road with \"%s\" flag is required. "
1894 "Postponing..."),
1896 tgt_name,
1897 road_flag_id_name(preq->source.value.roadflag));
1899 pcity, "need_roadflag");
1900 } else {
1901 notify_player(pplayer, city_tile(pcity),
1903 _("%s can't build %s from the worklist; "
1904 "road with \"%s\" flag is prohibited. "
1905 "Postponing..."),
1907 tgt_name,
1908 road_flag_id_name(preq->source.value.roadflag));
1910 pcity, "have_roadflag");
1911 }
1912 break;
1913 case VUT_EXTRAFLAG:
1914 if (preq->present) {
1915 notify_player(pplayer, city_tile(pcity),
1917 _("%s can't build %s from the worklist; "
1918 "extra with \"%s\" flag is required. "
1919 "Postponing..."),
1921 tgt_name,
1922 extra_flag_id_translated_name(preq->source.value.extraflag));
1924 pcity, "need_extraflag");
1925 } else {
1926 notify_player(pplayer, city_tile(pcity),
1928 _("%s can't build %s from the worklist; "
1929 "extra with \"%s\" flag is prohibited. "
1930 "Postponing..."),
1932 tgt_name,
1933 extra_flag_id_translated_name(preq->source.value.extraflag));
1935 pcity, "have_extraflag");
1936 }
1937 break;
1938 case VUT_MINLATITUDE:
1939 case VUT_MAXLATITUDE:
1940 /* Can't change where the city is located. */
1941 purge = TRUE;
1942 break;
1943 case VUT_CITYTILE:
1944 if (CITYT_BORDERING_TCLASS_REGION == preq->source.value.citytile
1945 && (preq->range == REQ_RANGE_CADJACENT
1946 || preq->range == REQ_RANGE_ADJACENT)) {
1947 if (preq->present) {
1948 notify_player(pplayer, city_tile(pcity),
1950 _("%s can't build %s from the worklist; "
1951 "different terrain class nearby is required. "
1952 "Postponing..."),
1954 tgt_name);
1956 pcity, "need_different_terrainclass");
1957 } else {
1958 notify_player(pplayer, city_tile(pcity),
1960 _("%s can't build %s from the worklist; "
1961 "different terrain class nearby is prohibited. "
1962 "Postponing..."),
1964 tgt_name);
1966 pcity, "have_different_terrainclass");
1967 }
1968 break;
1969 }
1970 /* Other values should not present in build reqs */
1972
1973 case VUT_UTYPE:
1974 case VUT_UTFLAG:
1975 case VUT_UCLASS:
1976 case VUT_UCFLAG:
1977 case VUT_MINVETERAN:
1978 case VUT_UNITSTATE:
1979 case VUT_ACTIVITY:
1980 case VUT_MINMOVES:
1981 case VUT_MINHP:
1982 case VUT_ACTION:
1983 case VUT_OTYPE:
1984 case VUT_SPECIALIST:
1986 case VUT_TILE_REL:
1987 case VUT_TERRAINALTER: /* XXX could do this in principle */
1988 /* Will only happen with a bogus ruleset. */
1989 log_error("worklist_change_build_target() has bogus preq");
1990 break;
1991 case VUT_CITYSTATUS:
1992 if (preq->source.value.citystatus == CITYS_TRANSFERRED) {
1993 /* If there's a change, it will invalidate worklist anyway. */
1994 purge = TRUE;
1995 } else if (preq->source.value.citystatus == CITYS_OWNED_BY_ORIGINAL) {
1996 if (preq->range == REQ_RANGE_CITY || preq->range == REQ_RANGE_TILE) {
1997 /* Can't change at these ranges */
1998 purge = TRUE;
1999 } else {
2000 if (preq->present) {
2001 notify_player(pplayer, city_tile(pcity),
2003 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2004 _("%s can't build %s from the worklist; "
2005 "only available when city in range %s \"%s\". "
2006 "Postponing..."),
2008 tgt_name, req_range_name(preq->range),
2009 citystatus_type_name(preq->source.value.citystatus));
2011 pcity, "need_citystatus");
2012 } else {
2013 notify_player(pplayer, city_tile(pcity),
2015 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
2016 _("%s can't build %s from the worklist; "
2017 "not available when city in range %s is \"%s\". "
2018 "Postponing..."),
2020 tgt_name, req_range_name(preq->range),
2021 citystatus_type_name(preq->source.value.citystatus));
2023 pcity, "have_citystatus");
2024 }
2025 }
2026 } else {
2027 /* Other status types will only happen with a bogus ruleset. */
2028 log_error("worklist_change_build_target() has bogus citystatus preq");
2029 }
2030 break;
2031 case VUT_MINYEAR:
2032 if (preq->present) {
2033 notify_player(pplayer, city_tile(pcity),
2035 /* TRANS: last %s is a date */
2036 _("%s can't build %s from the worklist; "
2037 "only available from %s. Postponing..."),
2039 tgt_name,
2040 textyear(preq->source.value.minyear));
2042 pcity, "need_minyear");
2043 } else {
2044 /* Can't go back in time. */
2045 purge = TRUE;
2046 }
2047 break;
2048 case VUT_MINCALFRAG:
2049 /* Unlike VUT_MINYEAR, a requirement in either direction is
2050 * likely to be fulfilled sooner or later. */
2051 if (preq->present) {
2052 notify_player(pplayer, city_tile(pcity),
2054 /* TRANS: last %s is a calendar fragment from
2055 * the ruleset; may be a bare number */
2056 _("%s can't build %s from the worklist; "
2057 "only available from %s. Postponing..."),
2059 tgt_name,
2060 textcalfrag(preq->source.value.mincalfrag));
2062 pcity, "need_mincalfrag");
2063 } else {
2064 fc_assert_action(preq->source.value.mincalfrag > 0, break);
2065 notify_player(pplayer, city_tile(pcity),
2067 /* TRANS: last %s is a calendar fragment from
2068 * the ruleset; may be a bare number */
2069 _("%s can't build %s from the worklist; "
2070 "not available after %s. Postponing..."),
2072 tgt_name,
2073 textcalfrag(preq->source.value.mincalfrag - 1));
2075 pcity, "have_mincalfrag");
2076 }
2077 break;
2078 case VUT_TOPO:
2079 if (preq->present) {
2080 notify_player(pplayer, city_tile(pcity),
2082 /* TRANS: third %s is topology flag name
2083 * ("Hex", "ISO" */
2084 _("%s can't build %s from the worklist; "
2085 "only available in worlds with %s map."),
2087 tgt_name,
2088 _(topo_flag_name(preq->source.value.topo_property)));
2090 pcity, "need_topo");
2091 }
2092 purge = TRUE;
2093 break;
2094 case VUT_WRAP:
2095 if (preq->present) {
2096 notify_player(pplayer, city_tile(pcity),
2098 /* TRANS: third %s is wrap flag name
2099 * ("WrapX", "Wrapy") */
2100 _("%s can't build %s from the worklist; "
2101 "only available in worlds with %s map."),
2103 tgt_name,
2104 _(wrap_flag_name(preq->source.value.wrap_property)));
2106 pcity, "need_wrap");
2107 }
2108 purge = TRUE;
2109 break;
2110 case VUT_SERVERSETTING:
2111 notify_player(pplayer, city_tile(pcity),
2113 /* TRANS: %s is a server setting, its value and
2114 * if it is required to be present or absent.
2115 * The string's format is specified in
2116 * ssetv_human_readable().
2117 * Example: "killstack is enabled". */
2118 _("%s can't build %s from the worklist; "
2119 "only available when the server setting "
2120 "%s."),
2122 tgt_name,
2123 ssetv_human_readable(preq->source.value.ssetval,
2124 preq->present));
2126 pcity, "need_setting");
2127 /* Don't assume that the server setting will be changed. */
2128 purge = TRUE;
2129 break;
2130 case VUT_AGE:
2131 if (preq->present) {
2132 notify_player(pplayer, city_tile(pcity),
2134 _("%s can't build %s from the worklist; "
2135 "only available once %d turns old. Postponing..."),
2137 tgt_name,
2138 preq->source.value.age);
2140 pcity, "need_age");
2141 } else {
2142 /* Can't go back in time. */
2143 purge = TRUE;
2144 }
2145 break;
2146 case VUT_FORM_AGE:
2147 if (preq->present) {
2148 notify_player(pplayer, city_tile(pcity),
2150 _("%s can't build %s from the worklist; "
2151 "only available once %d turns old form. Postponing..."),
2153 tgt_name,
2154 preq->source.value.age);
2156 pcity, "need_form_age");
2157 } else {
2158 /* Can't go back in time. */
2159 purge = TRUE;
2160 }
2161 break;
2162 case VUT_NONE:
2163 case VUT_COUNT:
2165 "worklist_change_build_target() "
2166 "called with invalid preq");
2167 break;
2168 /* No default handling here, as we want compiler warning
2169 * if new requirement type is added to enum and it's not handled
2170 * here. */
2171 };
2172 break;
2173 }
2174
2175 /* Almost all cases emit signal in the end, so city check needed. */
2176 if (!city_exist(saved_id)) {
2177 /* Some script has removed city */
2178 return TRUE;
2179 }
2180
2182
2183 if (!known) {
2184 /* FIXME: make can_city_build_improvement_now() return a reason enum,
2185 * so we can notify user with it.
2186 * Likely the building already exist. */
2187 purge = TRUE;
2188 }
2189
2190 return purge;
2191}
2192
2193/**********************************************************************/
2199static bool worklist_change_build_target(struct player *pplayer,
2200 struct city *pcity)
2201{
2202 struct universal target;
2203 bool success = FALSE;
2204 int i;
2205 int saved_id = pcity->id;
2206 bool city_checked = TRUE; /* This is used to avoid spurious city_exist() calls */
2207 struct worklist *pwl = &pcity->worklist;
2208 const struct civ_map *nmap = &(wld.map);
2209
2210 if (worklist_is_empty(pwl)) {
2211 /* Nothing in the worklist; bail now. */
2212 return FALSE;
2213 }
2214
2215 i = 0;
2216 while (!success && i < worklist_length(pwl)) {
2217
2218 if (!city_checked) {
2219 if (!city_exist(saved_id)) {
2220 /* Some script has removed useless city that cannot build
2221 * what it is told to! */
2222 return FALSE;
2223 }
2225 }
2226
2227 if (worklist_peek_ith(pwl, &target, i)) {
2228 success = can_city_build_now(nmap, pcity, &target);
2229 } else {
2230 success = FALSE;
2231 }
2232 i++;
2233
2234 if (success) {
2235 break; /* while */
2236 }
2237
2238 switch (target.kind) {
2239 case VUT_UTYPE:
2240 {
2241 const struct unit_type *ptarget = target.value.utype;
2243 bool purge;
2244
2245 /* Maybe we can just upgrade the target to what the city /can/ build. */
2246 if (U_NOT_OBSOLETED == pupdate) {
2247 /* Nope, we're stuck. Skip this item from the worklist. */
2248 struct research *presearch = research_get(pplayer);
2249 struct advance *missing = NULL;
2250 bool multiple = FALSE;
2251
2254 if (missing != NULL) {
2255 multiple = TRUE;
2256 } else {
2257 missing = padv;
2258 }
2259 }
2261
2262
2263 purge = FALSE;
2264 if (missing != NULL) {
2265 if (!multiple) {
2266 notify_player(pplayer, city_tile(pcity),
2268 _("%s can't build %s from the worklist; "
2269 "tech %s not yet available. Postponing..."),
2272 } else {
2273 notify_player(pplayer, city_tile(pcity),
2275 _("%s can't build %s from the worklist; "
2276 "multiple techs still needed. Postponing..."),
2278 }
2279
2280 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2281 "need_tech");
2282 } else {
2283 /* Unknown or requirement from vector. */
2284 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2285 saved_id);
2286 }
2288 if (!purge) {
2289 break;
2290 }
2291 } else {
2293 }
2294 if (purge) {
2295 /* If the city can never build this unit or its descendants,
2296 * drop it. */
2297 notify_player(pplayer, city_tile(pcity),
2299 _("%s can't build %s from the worklist. Purging..."),
2301 /* Yes, warn about the targets that's actually
2302 in the worklist, not its obsolete-closure
2303 pupdate. */
2305 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2306 "never");
2307 if (city_exist(saved_id)) {
2309 /* Purge this worklist item. */
2310 i--;
2312 } else {
2314 }
2315 } else {
2316 /* Yep, we can go after pupdate instead. Joy! */
2318 _("Production of %s is upgraded to %s in %s."),
2321 city_link(pcity));
2322 target.value.utype = pupdate;
2323 }
2324 break;
2325 }
2326 case VUT_IMPROVEMENT:
2327 {
2328 const struct impr_type *ptarget = target.value.building;
2330 bool purge;
2331
2332 /* If the city can never build this improvement, drop it. */
2334 purge = !success;
2335
2336 /* Maybe this improvement has been obsoleted by something that
2337 we can build. */
2338 if (purge) {
2339 /* Nope, no use. *sigh* */
2340
2341 /* Can it be postponed? */
2343 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2344 saved_id);
2345
2346 /* Almost all cases emit signal in the end, so city check needed. */
2347 if (!city_exist(saved_id)) {
2348 /* Some script has removed city */
2349 return FALSE;
2350 }
2352 }
2353 } else if (success) {
2354 /* Hey, we can upgrade the improvement! */
2356 _("Production of %s is upgraded to %s in %s."),
2359 city_link(pcity));
2360 target.value.building = pupdate;
2361 }
2362
2363 if (purge) {
2364 /* Never in a million years. */
2365 notify_player(pplayer, city_tile(pcity),
2367 _("%s can't build %s from the worklist. Purging..."),
2370 script_server_signal_emit("building_cant_be_built", ptarget, pcity,
2371 "never");
2372 if (city_exist(saved_id)) {
2374 /* Purge this worklist item. */
2375 i--;
2377 } else {
2379 }
2380 }
2381 break;
2382 }
2383 default:
2384 /* skip useless target */
2385 log_error("worklist_change_build_target() has unrecognized "
2386 "target kind (%d)", target.kind);
2387 break;
2388 };
2389 } /* while */
2390
2391 if (success) {
2392 /* All okay. Switch targets. */
2393 change_build_target(pplayer, pcity, &target, E_WORKLIST);
2394
2395 /* i is the index immediately _after_ the item we're changing to.
2396 Remove the (i-1)th item from the worklist. */
2397 worklist_remove(pwl, i - 1);
2398 }
2399
2400 if (worklist_is_empty(pwl)) {
2401 /* There *was* something in the worklist, but it's empty now. Bug the
2402 player about it. */
2404 /* TRANS: The <city> worklist .... */
2405 _("The %s worklist is now empty."),
2406 city_link(pcity));
2407 }
2408
2409 return success;
2410}
2411
2412/**********************************************************************/
2417void choose_build_target(struct player *pplayer, struct city *pcity)
2418{
2419 const struct civ_map *nmap = &(wld.map);
2420
2421 /* Pick the next thing off the worklist. */
2422 if (worklist_change_build_target(pplayer, pcity)) {
2423 return;
2424 }
2425
2426 /* Try building the same thing again. Repeat building doesn't require a
2427 * call to change_build_target, so just return. */
2428 switch (pcity->production.kind) {
2429 case VUT_UTYPE:
2430 /* We can build a unit again unless it's unique or we have lost the tech. */
2431 if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
2432 && can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
2433 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2434 utype_rule_name(pcity->production.value.utype));
2435 return;
2436 }
2437 break;
2438 case VUT_IMPROVEMENT:
2439 if (can_city_build_improvement_now(pcity, pcity->production.value.building)) {
2440 /* We can build space and coinage again, and possibly others. */
2441 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2442 improvement_rule_name(pcity->production.value.building));
2443 return;
2444 }
2445 break;
2446 default:
2447 /* fallthru */
2448 break;
2449 };
2450
2451 /* Find *something* to do! */
2452 log_debug("Trying advisor_choose_build.");
2453 advisor_choose_build(pplayer, pcity);
2454 log_debug("Advisor_choose_build didn't kill us.");
2455}
2456
2457/**********************************************************************/
2462static const struct impr_type *building_upgrades_to(struct city *pcity,
2463 const struct impr_type *pimprove)
2464{
2465 const struct impr_type *check = pimprove;
2466 const struct impr_type *best_upgrade = NULL;
2467
2469 return NULL;
2470 }
2474 }
2475 }
2476
2477 return best_upgrade;
2478}
2479
2480/**********************************************************************/
2484{
2485 const struct impr_type *producing = pcity->production.value.building;
2487
2491 _("Production of %s is upgraded to %s in %s."),
2494 city_link(pcity));
2495 pcity->production.kind = VUT_IMPROVEMENT;
2496 pcity->production.value.building = upgrading;
2497 }
2498}
2499
2500/**********************************************************************/
2508static const struct unit_type *unit_upgrades_to(struct city *pcity,
2509 const struct unit_type *punittype)
2510{
2511 const struct unit_type *check = punittype;
2512 const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
2513 const struct civ_map *nmap = &(wld.map);
2514
2516 return U_NOT_OBSOLETED;
2517 }
2518 while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
2521 }
2522 }
2523
2524 return best_upgrade;
2525}
2526
2527/**********************************************************************/
2530static void upgrade_unit_prod(struct city *pcity)
2531{
2532 const struct unit_type *producing = pcity->production.value.utype;
2534 const struct civ_map *nmap = &(wld.map);
2535
2539 _("Production of %s is upgraded to %s in %s."),
2542 city_link(pcity));
2543 pcity->production.value.utype = upgrading;
2544 }
2545}
2546
2547/**********************************************************************/
2554static bool city_distribute_surplus_shields(struct player *pplayer,
2555 struct city *pcity)
2556{
2557 int size_reduction = 0;
2558 struct unit *sacrifizer;
2559
2560 if (pcity->surplus[O_SHIELD] < 0) {
2561 unit_list_iterate_safe(pcity->units_supported, punit) {
2562 if (utype_upkeep_cost(unit_type_get(punit), pplayer, O_SHIELD) > 0
2563 && pcity->surplus[O_SHIELD] < 0) {
2564 const char *punit_link = unit_link(punit);
2565
2566 /* TODO: Should the unit try to help cities on adjacent tiles? That
2567 * would be a rules change. (This action is performed by the game
2568 * it self) */
2571 notify_player(pplayer, city_tile(pcity),
2573 _("%s can't upkeep %s, unit disbanded."),
2575 }
2576
2577 /* pcity->surplus[O_SHIELD] is automatically updated. */
2578 }
2580 }
2581
2582 if (pcity->surplus[O_SHIELD] < 0) {
2583 /* Special case: MissingXProtected. This nasty unit won't go so easily.
2584 * It'd rather make the citizens pay in blood for their failure to upkeep
2585 * it! If we make it here all normal units are already disbanded, so only
2586 * undisbandable ones remain. */
2587 unit_list_iterate_safe(pcity->units_supported, punit) {
2589
2590 if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
2591
2593 sacrifizer = punit;
2594
2595 /* No upkeep for the unit this turn. */
2596 pcity->surplus[O_SHIELD] += upkeep;
2597 }
2599 }
2600
2601 /* Now we confirm changes made last turn. */
2602 pcity->shield_stock += pcity->surplus[O_SHIELD];
2603 pcity->before_change_shields = pcity->shield_stock;
2604 pcity->last_turns_shield_surplus = pcity->surplus[O_SHIELD];
2605
2606 /* Previous turn values stored, and they are consistent with
2607 * other previous turn data.
2608 * Now reduce city size, likely messing all the values. */
2609 if (size_reduction > 0) {
2610 if (size_reduction == 1) {
2611 notify_player(pplayer, city_tile(pcity),
2613 _("Citizens in %s perish for their failure to "
2614 "upkeep %s!"),
2616 } else {
2617 notify_player(pplayer, city_tile(pcity),
2619 _("Citizens in %s perish for their failure to "
2620 "upkeep units!"),
2621 city_link(pcity));
2622 }
2623
2624 if (!city_reduce_size(pcity, size_reduction, NULL, "upkeep_failure")) {
2625 return FALSE;
2626 }
2627 }
2628
2629 return TRUE;
2630}
2631
2632/**********************************************************************/
2635static bool city_build_building(struct player *pplayer, struct city *pcity)
2636{
2637 bool space_part;
2638 int mod;
2639 const struct impr_type *pimprove;
2640 int saved_id = pcity->id;
2641
2642 if (is_convert_improvement(pcity->production.value.building)) {
2643 /* Coinage-like improvements that convert production */
2644 fc_assert(pcity->before_change_shields >= 0);
2645
2646 /* pcity->before_change_shields already contains the surplus from
2647 * this turn. */
2649 pplayer->economic.gold += pcity->before_change_shields;
2651 pplayer->economic.infra_points += pcity->before_change_shields;
2652 }
2653
2654 pcity->before_change_shields = 0;
2655 pcity->shield_stock = 0;
2656 choose_build_target(pplayer, pcity);
2657
2658 return TRUE;
2659 }
2660
2662
2663 /* The final (after upgrade) build target */
2664 pimprove = pcity->production.value.building;
2665
2666 if (!can_city_build_improvement_now(pcity, pimprove)) {
2668 _("%s is building %s, which is no longer available."),
2671 script_server_signal_emit("building_cant_be_built", pimprove, pcity,
2672 "unavailable");
2673 return TRUE;
2674 }
2675 if (pcity->shield_stock >= impr_build_shield_cost(pcity, pimprove)) {
2676 int cost;
2677
2678 if (is_small_wonder(pimprove)) {
2679 city_list_iterate(pplayer->cities, wcity) {
2680 if (city_has_building(wcity, pimprove)) {
2681 city_remove_improvement(wcity, pimprove);
2682 break;
2683 }
2685 }
2686
2687 space_part = TRUE;
2689 RPT_CERTAIN) > 0) {
2690 pplayer->spaceship.structurals++;
2692 RPT_CERTAIN) > 0) {
2693 pplayer->spaceship.components++;
2695 RPT_CERTAIN) > 0) {
2696 pplayer->spaceship.modules++;
2697 } else {
2698 space_part = FALSE;
2700 _("Completion of %s"));
2701 }
2702 cost = impr_build_shield_cost(pcity, pimprove);
2703 pcity->before_change_shields -= cost;
2704 pcity->shield_stock -= cost;
2705 pcity->turn_last_built = game.info.turn;
2706 /* to eliminate micromanagement */
2707 if (is_great_wonder(pimprove)) {
2709 _("The %s have finished building %s in %s."),
2710 nation_plural_for_player(pplayer),
2712 city_link(pcity));
2713 }
2714
2716 _("%s has finished building %s."),
2718 script_server_signal_emit("building_built", pimprove, pcity);
2719
2720 if (!city_exist(saved_id)) {
2721 /* Script removed city */
2722 return FALSE;
2723 }
2724
2725 /* Call this function since some buildings may change the
2726 * the vision range of a city */
2728
2730 RPT_CERTAIN))) {
2731 struct research *presearch = research_get(pplayer);
2732 char research_name[MAX_LEN_NAME * 2];
2733 int i;
2734 const char *provider = improvement_name_translation(pimprove);
2735
2737 PL_("%s boosts research; you gain %d immediate "
2738 "advance.",
2739 "%s boosts research; you gain %d immediate "
2740 "advances.",
2741 mod), provider, mod);
2742
2744 for (i = 0; i < mod; i++) {
2747
2750 /* TRANS: Tech from building (Darwin's Voyage) */
2751 Q_("?frombldg:Acquired %s from %s."), adv_name,
2752 provider);
2753
2755 /* TRANS: Tech from building (Darwin's
2756 * Voyage) */
2757 Q_("?frombldg:The %s have acquired %s "
2758 "from %s."),
2760 }
2761 }
2762 if (space_part && pplayer->spaceship.state == SSHIP_NONE) {
2764 _("The %s have started building a spaceship!"),
2765 nation_plural_for_player(pplayer));
2766 pplayer->spaceship.state = SSHIP_STARTED;
2767 }
2768 if (space_part) {
2769 /* space ship part build */
2770 send_spaceship_info(pplayer, NULL);
2771 } else {
2772 /* Update city data. */
2773 if (city_refresh(pcity)) {
2775 }
2776 }
2777
2778 /* Move to the next thing in the worklist */
2779 choose_build_target(pplayer, pcity);
2780 }
2781
2782 return TRUE;
2783}
2784
2785/**********************************************************************/
2794static struct unit *city_create_unit(struct city *pcity,
2795 const struct unit_type *utype,
2796 struct citizens_reduction *red)
2797{
2798 struct player *pplayer = city_owner(pcity);
2799 struct unit *punit;
2800 int saved_unit_id;
2801 int pop_cost = utype_pop_value(utype, pcity);
2802
2805 pcity->id, -1, -1);
2806 pplayer->score.units_built++;
2807
2808 if (pop_cost > 0 && pcity->nationality != NULL) {
2809 /* We don't reduce city size in-place to keep it correct and
2810 * existing at all while we call the following callback.
2811 * We want citizens_unit_nationality() to adjust 'red' even when
2812 * we are not setting unit nationality based on the return */
2813 struct player *nat = citizens_unit_nationality(pcity, pop_cost, red);
2814
2817 }
2818 } else if (red) {
2819 red->change = 0;
2820 }
2821
2822 (void) place_unit(punit, pplayer, pcity, NULL, FALSE);
2824
2825 /* If city has a rally point set, give the unit a move order. */
2826 if (pcity->rally_point.length) {
2828 punit->orders.length = pcity->rally_point.length;
2829 punit->orders.vigilant = pcity->rally_point.vigilant;
2830 punit->orders.list = fc_malloc(pcity->rally_point.length
2831 * sizeof(struct unit_order));
2832 memcpy(punit->orders.list, pcity->rally_point.orders,
2833 pcity->rally_point.length * sizeof(struct unit_order));
2834 }
2835
2836 /* This might destroy pcity and/or punit: */
2837 script_server_signal_emit("unit_built", punit, pcity);
2838
2840 return punit;
2841 } else {
2842 return NULL;
2843 }
2844}
2845
2846/**********************************************************************/
2855static bool city_build_unit(struct player *pplayer, struct city *pcity)
2856{
2857 const struct unit_type *utype;
2858 struct worklist *pwl = &pcity->worklist;
2860 int saved_city_id = pcity->id;
2861 const struct civ_map *nmap = &(wld.map);
2862
2863 fc_assert_ret_val(pcity->production.kind == VUT_UTYPE, FALSE);
2864
2865 /* If the city has already bought a unit which is now obsolete, don't try
2866 * to upgrade the production. The new unit might require more shields, which
2867 * would be bad if it was bought to urgently defend a city. (Equally it
2868 * might be the same cost or cheaper, but tough; you hurried the unit so
2869 * you miss out on technological advances.) */
2872 }
2873
2874 utype = pcity->production.value.utype;
2876
2877 /* We must make a special case for barbarians here, because they are
2878 so dumb. Really. They don't know the prerequisite techs for units
2879 they build!! - Per */
2881 && !is_barbarian(pplayer)) {
2883 _("%s is building %s, which is no longer available."),
2885
2886 /* Log before signal emitting, so pointers are certainly valid */
2887 log_verbose("%s %s tried to build %s, which is not available.",
2890 script_server_signal_emit("unit_cant_be_built", utype, pcity,
2891 "unavailable");
2892 return city_exist(saved_city_id);
2893 }
2894
2895 if (pcity->shield_stock >= unit_shield_cost) {
2896 int pop_cost = utype_pop_value(utype, pcity);
2897 struct unit *punit;
2898
2899 /* Should we disband the city? -- Massimo */
2900 if (city_size_get(pcity) == pop_cost
2902 return !disband_city(pcity);
2903 }
2904
2905 if (city_size_get(pcity) <= pop_cost) {
2907 /* TRANS: city ... utype ... size ... pop_cost */
2908 _("%s can't build %s yet. "
2909 "(city size: %d, unit population cost: %d)"),
2911 city_size_get(pcity), pop_cost);
2912 script_server_signal_emit("unit_cant_be_built", utype, pcity,
2913 "pop_cost");
2914 return city_exist(saved_city_id);
2915 }
2916
2917 fc_assert(pop_cost == 0 || city_size_get(pcity) >= pop_cost);
2918
2919 /* don't update turn_last_built if we returned above */
2920 pcity->turn_last_built = game.info.turn;
2921
2922 /* check if we can build more than one unit (effect City_Build_Slots) */
2924
2925 /* We should be able to build at least one (by checks above) */
2926 fc_assert(num_units >= 1);
2927
2928 for (i = 0; i < num_units; i++) {
2930
2932
2933 /* Check if the city still exists (script might have removed it).
2934 * If not, we assume any effects / announcements done below were
2935 * already replaced by the script if necessary. */
2936 if (!city_exist(saved_city_id)) {
2937 break;
2938 }
2939
2940 if (punit) {
2941 if (punit->carrying
2944 /* TRANS: <city> is finished building <unit>, carrying <goods>. */
2945 _("%s is finished building %s, carrying %s."),
2948 } else {
2950 /* TRANS: <city> is finished building <unit/building>. */
2951 _("%s is finished building %s."),
2953 }
2954 }
2955
2956 /* After we created the unit remove the citizen. This will also
2957 * rearrange the worker to take into account the extra resources
2958 * (food) needed. */
2959 if (pop_cost > 0) {
2960 /* This won't disband city due to pop_cost, but script might
2961 * still destroy city. */
2963 /* If the city has changed its nationalities during
2964 * "unit_built" signal, we take some other citizens instead */
2965 if (!city_reduce_size(pcity, pop_cost, NULL, "unit_built")) {
2966 break;
2967 }
2968 }
2969
2970 /* to eliminate micromanagement, we only subtract the unit's cost */
2971 /* signals could change the prod stock! */
2972 if ((pcity->before_change_shields -= unit_shield_cost) < 0) {
2973 pcity->before_change_shields = 0;
2974 }
2975 if ((pcity->shield_stock -= unit_shield_cost) < 0) {
2976 log_normal("City %s (%s) has built %s but has no %d shields "
2977 "for it, nullifying shield stock", city_name_get(pcity),
2978 player_name(pplayer), utype_rule_name(utype),
2980 pcity->shield_stock = 0;
2981 }
2982
2983 if (pop_cost > 0) {
2984 /* Additional message if the unit has population cost. */
2986 ftc_server,
2987 /* TRANS: "<unit> cost... <city> shrinks..."
2988 * Plural in "%d population", not "size %d". */
2989 PL_("%s cost %d population. %s shrinks to size %d.",
2990 "%s cost %d population. %s shrinks to size %d.",
2991 pop_cost),
2992 utype_name_translation(utype), pop_cost,
2994 }
2995
2996 if (i != 0 && worklist_length(pwl) > 0) {
2997 /* remove the build unit from the worklist; it has to be one less
2998 * than units build to preserve the next build target from the
2999 * worklist */
3000 worklist_remove(pwl, 0);
3001 }
3002 } /* for */
3003
3005 if (pcity->rally_point.length && !pcity->rally_point.persistent) {
3007 }
3008
3009 /* Done building this unit; time to move on to the next. */
3010 choose_build_target(pplayer, pcity);
3011 }
3012 } /* if */
3013
3014 return city_exist(saved_city_id);
3015}
3016
3017/**********************************************************************/
3020static bool city_build_stuff(struct player *pplayer, struct city *pcity)
3021{
3022 if (!city_distribute_surplus_shields(pplayer, pcity)) {
3023 return FALSE;
3024 }
3025
3028
3029 switch (pcity->production.kind) {
3030 case VUT_IMPROVEMENT:
3031 return city_build_building(pplayer, pcity);
3032 case VUT_UTYPE:
3033 return city_build_unit(pplayer, pcity);
3034 default:
3035 /* must never happen! */
3037 break;
3038 };
3039 return FALSE;
3040}
3041
3042/**********************************************************************/
3052static bool sell_random_building(struct player *pplayer,
3053 struct cityimpr_list *imprs)
3054{
3055 struct cityimpr *pcityimpr;
3056 int r;
3057
3058 fc_assert_ret_val(pplayer != NULL, FALSE);
3059
3060 if (!imprs || cityimpr_list_size(imprs) == 0) {
3061 return FALSE;
3062 }
3063
3066
3068 ftc_server,
3069 _("Can't afford to maintain %s in %s, building sold!"),
3071 city_link(pcityimpr->pcity));
3072 log_debug("%s: sold building (%s)", player_name(pplayer),
3074
3075 do_sell_building(pplayer, pcityimpr->pcity, pcityimpr->pimprove, "cant_maintain");
3076
3078
3079 /* Get back the gold upkeep that was already paid this turn. */
3081 pcityimpr->pimprove);
3082
3084
3086
3087 return TRUE;
3088}
3089
3090/**********************************************************************/
3098static void uk_rem_gold_callback(struct unit *punit)
3099{
3100 int gold_upkeep;
3101
3102 /* Remove the unit from uk_rem_gold. */
3104
3105 gold_upkeep = punit->server.upkeep_paid[O_GOLD];
3106
3107 /* All units in uk_rem_gold should have gold upkeep! */
3108 fc_assert_ret_msg(gold_upkeep > 0, "%s has %d gold upkeep",
3109 unit_rule_name(punit), gold_upkeep);
3110
3111 /* Get the upkeep gold back. */
3112 unit_owner(punit)->economic.gold += gold_upkeep;
3113}
3114
3115/**********************************************************************/
3119static void uk_rem_gold_append(struct unit *punit)
3120{
3121 /* Make the unit aware that it is on the uk_rem_gold list. */
3123
3124 /* Add the unit to the list. */
3126}
3127
3128/**********************************************************************/
3132static void unit_list_referred_destroy(struct unit_list *punitlist)
3133{
3135 /* Clear the unit's knowledge of the list. */
3138
3139 /* Destroy the list it self. */
3141}
3142
3143/**********************************************************************/
3155static struct unit *sell_random_unit(struct player *pplayer,
3156 struct unit_list *punitlist)
3157{
3158 struct unit *punit;
3159 int r;
3160 struct unit_list *cargo;
3161
3162 fc_assert_ret_val(pplayer != NULL, NULL);
3163
3164 if (!punitlist || unit_list_size(punitlist) == 0) {
3165 return NULL;
3166 }
3167
3170
3171 cargo = unit_list_new();
3172
3173 /* Check if unit is transporting other units from punitlist,
3174 * and sell one of those (recursively) instead.
3175 * Note that in case of recursive transports we have to iterate
3176 * also through those middle transports that themselves are not in
3177 * punitlist. */
3179 /* Optimization, do not iterate over punitlist
3180 * if we are sure that pcargo is not in it. */
3181 if (pcargo->server.upkeep_paid[O_GOLD] > 0) {
3183 if (pcargo == p2) {
3184 unit_list_append(cargo, pcargo);
3185 }
3187 }
3189
3190 if (unit_list_size(cargo) > 0) {
3191 /* Recursively sell. Note that cargo list has both
3192 * leaf units and middle transports in case of
3193 * recursive transports. */
3194 struct unit *ret = sell_random_unit(pplayer, cargo);
3195
3196 unit_list_destroy(cargo);
3197
3199
3200 return ret;
3201 }
3202
3203 unit_list_destroy(cargo);
3204
3205 {
3206 const char *punit_link = unit_tile_link(punit);
3207#ifdef FREECIV_DEBUG
3208 const char *punit_logname = unit_rule_name(punit);
3209#endif /* FREECIV_DEBUG */
3210 struct tile *utile = unit_tile(punit);
3211
3215
3216 /* The gold was paid back when the unit removal made
3217 * uk_rem_gold_callback() run as the unit's removal call back. */
3218
3219 notify_player(pplayer, utile, E_UNIT_LOST_MISC, ftc_server,
3220 _("Not enough gold. %s disbanded."),
3221 punit_link);
3222 log_debug("%s: unit sold (%s)", player_name(pplayer),
3224 } else {
3225 /* Not able to get rid of punit */
3226 return NULL;
3227 }
3228 }
3229
3231
3232 return punit;
3233}
3234
3235/**********************************************************************/
3239{
3240 struct cityimpr_list *pimprlist;
3241 bool sell_unit = TRUE;
3242
3243 if (!pplayer) {
3244 return FALSE;
3245 }
3246
3249
3250 city_list_iterate(pplayer->cities, pcity) {
3251 city_built_iterate(pcity, pimprove) {
3252 if (can_city_sell_building(pcity, pimprove)) {
3253 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3254
3255 ci->pcity = pcity;
3256 ci->pimprove = pimprove;
3258 }
3261
3262 unit_list_iterate(pplayer->units, punit) {
3263 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3265 }
3267
3268 while (pplayer->economic.gold < 0
3270 || unit_list_size(uk_rem_gold) > 0)) {
3272 || unit_list_size(uk_rem_gold) == 0) {
3274 } else {
3275 sell_random_unit(pplayer, uk_rem_gold);
3276 }
3278 }
3279
3280 /* Free remaining entries from list */
3282 FC_FREE(pimpr);
3284
3285 if (pplayer->economic.gold < 0) {
3286 /* If we get here it means the player has
3287 * negative gold. This should never happen. */
3288 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3289 player_name(pplayer), player_number(pplayer));
3290 }
3291
3294
3295 return pplayer->economic.gold >= 0;
3296}
3297
3298/**********************************************************************/
3302{
3303 if (!pplayer) {
3304 return FALSE;
3305 }
3306
3308
3309 unit_list_iterate(pplayer->units, punit) {
3310 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3312 }
3314
3315 while (pplayer->economic.gold < 0
3316 && sell_random_unit(pplayer, uk_rem_gold)) {
3317 /* All done in sell_random_unit() */
3318 }
3319
3320 if (pplayer->economic.gold < 0) {
3321 /* If we get here it means the player has
3322 * negative gold. This should never happen. */
3323 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3324 player_name(pplayer), player_number(pplayer));
3325 }
3326
3328
3329 return pplayer->economic.gold >= 0;
3330}
3331
3332/**********************************************************************/
3336{
3337 struct player *pplayer;
3338 struct cityimpr_list *pimprlist;
3339
3340 if (!pcity) {
3341 return TRUE;
3342 }
3343
3344 pplayer = city_owner(pcity);
3346
3347 /* Create a vector of all buildings that can be sold. */
3348 city_built_iterate(pcity, pimprove) {
3349 if (can_city_sell_building(pcity, pimprove)) {
3350 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3351
3352 ci->pcity = pcity;
3353 ci->pimprove = pimprove;
3355 }
3357
3358 /* Try to sell some buildings. */
3359 while (pplayer->economic.gold < 0
3360 && sell_random_building(pplayer, pimprlist)) {
3361 /* all done in sell_random_building */
3362 }
3363
3364 /* Free remaining entries from list */
3366 FC_FREE(pimpr);
3368
3370
3371 return pplayer->economic.gold >= 0;
3372}
3373
3374/**********************************************************************/
3383{
3384 struct player *pplayer;
3385
3386 if (!pcity) {
3387 return TRUE;
3388 }
3389
3390 pplayer = city_owner(pcity);
3392
3393 /* Create a vector of all supported units with gold upkeep. */
3394 unit_list_iterate(pcity->units_supported, punit) {
3395 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3397 }
3399
3400 /* Still not enough gold, so try "selling" some units. */
3401 while (pplayer->economic.gold < 0
3402 && sell_random_unit(pplayer, uk_rem_gold)) {
3403 /* All done in sell_random_unit() */
3404 }
3405
3406 /* If we get here the player has negative gold, but hopefully
3407 * another city will be able to pay the deficit, so continue. */
3408
3410
3411 return pplayer->economic.gold >= 0;
3412}
3413
3414/**********************************************************************/
3417static bool place_pollution(struct city *pcity, enum extra_cause cause)
3418{
3419 struct tile *ptile;
3420 struct tile *pcenter = city_tile(pcity);
3421 int city_radius_sq = city_map_radius_sq_get(pcity);
3422 int k = 100;
3423 const struct civ_map *nmap = &(wld.map);
3424
3425 while (k > 0) {
3426 /* Place pollution on a random city tile */
3427 int cx, cy;
3428 int tile_id = fc_rand(city_map_tiles(city_radius_sq));
3429 struct extra_type *pextra;
3430
3431 city_tile_index_to_xy(&cx, &cy, tile_id, city_radius_sq);
3432
3433 /* Check for a real map position */
3434 if (!(ptile = city_map_to_tile(nmap, pcenter, city_radius_sq, cx, cy))) {
3435 continue;
3436 }
3437
3438 pextra = rand_extra_for_tile(ptile, cause, FALSE);
3439
3440 if (pextra != NULL && !tile_has_extra(ptile, pextra)) {
3441 tile_add_extra(ptile, pextra);
3442 update_tile_knowledge(ptile);
3443
3444 return TRUE;
3445 }
3446 k--;
3447 }
3448 log_debug("pollution not placed: city: %s", city_name_get(pcity));
3449
3450 return FALSE;
3451}
3452
3453/**********************************************************************/
3456static void check_pollution(struct city *pcity)
3457{
3458 if (fc_rand(100) < pcity->pollution) {
3461 _("Pollution near %s."), city_link(pcity));
3462 }
3463 }
3464}
3465
3466/**********************************************************************/
3473int city_incite_cost(struct player *pplayer, struct city *pcity)
3474{
3475 int dist, size;
3476 double cost; /* Intermediate values can get very large */
3477
3478 /* Gold factor */
3479 cost = city_owner(pcity)->economic.gold + game.server.base_incite_cost;
3480
3485
3486 /* Buildings */
3487 city_built_iterate(pcity, pimprove) {
3488 cost += impr_build_shield_cost(pcity, pimprove)
3491
3492 /* Stability bonuses */
3493 if (!city_unhappy(pcity)) {
3494 cost *= 2;
3495 }
3496 if (city_celebrating(pcity)) {
3497 cost *= 2;
3498 }
3499
3500 /* Buy back is cheap, conquered cities are also cheap */
3502 if (city_owner(pcity) != pcity->original) {
3503 if (pplayer == pcity->original) {
3504 cost /= 2; /* Buy back: 50% price reduction */
3505 } else {
3506 cost = cost * 2 / 3; /* Buy conquered: 33% price reduction */
3507 }
3508 }
3509 }
3510
3511 /* Distance from capital */
3512 /* Max penalty. Applied if there is no capital, or it's even further away. */
3513 dist = 32;
3515 if (is_capital(capital)) {
3516 int tmp = map_distance(capital->tile, pcity->tile);
3517
3518 if (tmp < dist) {
3519 dist = tmp;
3520 }
3521 }
3523
3527 - pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] * 3);
3528 cost *= size;
3530 cost = cost / (dist + 3);
3531
3533 int cost_per_citizen = cost / pcity->size;
3535 int tgt_cit = citizens_nation_get(pcity, pplayer->slot);
3536 int third_party = pcity->size - natives - tgt_cit;
3537
3538 cost = cost_per_citizen * (natives + 0.7 * third_party + 0.5 * tgt_cit);
3539 }
3540
3542 cost /= 100;
3543
3546 } else {
3547 return cost;
3548 }
3549}
3550
3551/**********************************************************************/
3555{
3556 /* Remember what this city is building last turn, so that on the next turn
3557 * the player can switch production to something else and then change it
3558 * back without penalty. This has to be updated _before_ production for
3559 * this turn is calculated, so that the penalty will apply if the player
3560 * changes production away from what has just been completed. This makes
3561 * sense if you consider what this value means: all the shields in the
3562 * city have been dedicated toward the project that was chosen last turn,
3563 * so the player shouldn't be penalized if the governor has to pick
3564 * something different. See city_change_production_penalty(). */
3565 pcity->changed_from = pcity->production;
3566
3567 log_debug("In %s, building %s. Beg of Turn shields = %d",
3569 pcity->before_change_shields);
3570}
3571
3572/**********************************************************************/
3576{
3577 pcity->disbanded_shields = 0;
3578 pcity->caravan_shields = 0;
3579}
3580
3581/**********************************************************************/
3586{
3588 pcity->before_change_shields = 0;
3589}
3590
3591/**********************************************************************/
3594static void update_city_activity(struct city *pcity)
3595{
3596 struct player *pplayer;
3597 struct government *gov;
3598 bool is_happy;
3599 bool is_celebrating;
3600
3601 if (!pcity) {
3602 return;
3603 }
3604
3605 pplayer = city_owner(pcity);
3609
3610 if (city_refresh(pcity)) {
3612 }
3613
3614 /* Reporting of celebrations rewritten, copying the treatment of disorder below,
3615 with the added rapture rounds count. 991219 -- Jing */
3616 if (city_build_stuff(pplayer, pcity)) {
3617 int saved_id;
3618 int revolution_turns;
3619
3620 pcity->history += city_history_gain(pcity);
3621
3622 /* History can decrease, but never go below zero */
3623 pcity->history = MAX(pcity->history, 0);
3624
3625 /* Keep old behavior when building new improvement could keep
3626 city celebrating */
3627 if (!is_happy) {
3629 }
3630
3632 pcity->rapture++;
3633
3634 /* Update city's celebrating counters */
3636 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3637 pcity->counter_values[pcount->index]++;
3638 }
3640
3641 if (pcity->rapture == 1) {
3643 _("Celebrations in your honor in %s."),
3644 city_link(pcity));
3645 }
3646 } else {
3647 if (pcity->rapture != 0) {
3649 _("Celebrations canceled in %s."),
3650 city_link(pcity));
3651 }
3652
3653 /* Update city's celebrating counters */
3655 if (pcount->type == CB_CITY_CELEBRATION_TURNS) {
3656 pcity->counter_values[pcount->index] = 0;
3657 }
3659 pcity->rapture = 0;
3660 }
3661 pcity->was_happy = is_happy;
3662
3663 /* Handle the illness. */
3664 if (game.info.illness_on) {
3665 /* Recalculate city illness; illness due to trade has to be saved
3666 * within the city struct, as the client does not have all
3667 * the data to calculate it */
3668 pcity->server.illness
3669 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), NULL);
3670
3672 if (!city_illness_strike(pcity)) {
3673 /* Illness destroyed the city */
3674 return;
3675 }
3676 }
3677 }
3678
3679 /* City population updated here, after the rapture stuff above. --Jing */
3680 saved_id = pcity->id;
3681 pcity->had_famine = FALSE;
3682 city_populate(pcity, pplayer);
3683 if (NULL == player_city_by_number(pplayer, saved_id)) {
3684 return;
3685 }
3686
3687 pcity->did_sell = FALSE;
3688 pcity->did_buy = FALSE;
3689 pcity->airlift = city_airlift_max(pcity);
3690 update_bulbs(pplayer, pcity->prod[O_SCIENCE], FALSE, FALSE);
3691
3693
3694 /* Update the treasury. */
3695 pplayer->economic.gold += pcity->surplus[O_GOLD];
3696
3697 /* FIXME: Nation level upkeep should be paid after ALL cities
3698 * have been processed, not after each individual city. */
3700 /* Unit upkeep was not included in city balance ->
3701 * not reduced from the city surplus. */
3703
3705 /* Building upkeep was not included in city balance ->
3706 * not reduced from the city surplus. */
3708 }
3709 }
3710
3711 /* Remember how much gold upkeep each unit was paid. */
3712 unit_list_iterate(pcity->units_supported, punit) {
3715
3716 if (pplayer->economic.gold < 0) {
3717 /* Not enough gold - we have to sell some buildings, and if that
3718 * is not enough, disband units with gold upkeep, taking into
3719 * account the setting of 'game.info.gold_upkeep_style':
3720 * GOLD_UPKEEP_CITY: Cities pay for buildings and units.
3721 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
3722 * for units.
3723 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
3724 switch (game.info.gold_upkeep_style) {
3725 case GOLD_UPKEEP_CITY:
3726 case GOLD_UPKEEP_MIXED:
3730 }
3731 break;
3732 case GOLD_UPKEEP_NATION:
3733 break;
3734 }
3735 }
3736
3738 if (city_unhappy(pcity)) {
3739 const char *revomsg;
3740
3741 pcity->anarchy++;
3742
3744 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3745 pcity->counter_values[pcount->index]++;
3746 }
3748
3749 if (pcity->anarchy == revolution_turns) {
3750 /* Revolution next turn if not dealt with */
3751 /* TRANS: preserve leading space; this string will be appended to
3752 * another sentence */
3753 revomsg = _(" Unrest threatens to spread beyond the city.");
3754 } else {
3755 revomsg = "";
3756 }
3757 if (pcity->anarchy == 1) {
3759 /* TRANS: second %s is an optional extra sentence */
3760 _("Civil disorder in %s.%s"),
3762 } else {
3764 /* TRANS: second %s is an optional extra sentence */
3765 _("CIVIL DISORDER CONTINUES in %s.%s"),
3767 }
3768 } else {
3769 if (pcity->anarchy != 0) {
3771 _("Order restored in %s."),
3772 city_link(pcity));
3773 }
3774 pcity->anarchy = 0;
3775
3777 if (pcount->type == CB_CITY_DISORDER_TURNS) {
3778 pcity->counter_values[pcount->index] = 0;
3779 }
3781 }
3783
3785
3786 if (revolution_turns > 0 && pcity->anarchy > revolution_turns) {
3788 /* TRANS: %s - government form, e.g., Democracy */
3789 _("The people have overthrown your %s, "
3790 "your country is in turmoil."),
3793 }
3794 if (city_refresh(pcity)) {
3796 }
3798 }
3799}
3800
3801/**********************************************************************/
3804static bool city_illness_check(const struct city * pcity)
3805{
3806 if (fc_rand(1000) < pcity->server.illness) {
3807 return TRUE;
3808 }
3809
3810 return FALSE;
3811}
3812
3813/**********************************************************************/
3817static bool disband_city(struct city *pcity)
3818{
3819 struct player *pplayer = city_owner(pcity);
3820 struct tile *ptile = pcity->tile;
3821 struct city *rcity = NULL;
3822 const struct unit_type *utype = pcity->production.value.utype;
3823 struct unit *punit;
3824 int saved_id = pcity->id;
3825
3826 /* find closest city other than pcity */
3827 rcity = find_closest_city(ptile, pcity, pplayer, FALSE, FALSE, FALSE, TRUE,
3828 FALSE, NULL);
3829
3830 if (!rcity) {
3831 /* What should we do when we try to disband our only city? */
3832 notify_player(pplayer, ptile, E_CITY_CANTBUILD, ftc_server,
3833 _("%s can't build %s yet, "
3834 "as we can't disband our only city."),
3836 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3837 "pop_cost");
3838 if (!city_exist(saved_id)) {
3839 /* Script decided to remove even the last city */
3840 return TRUE;
3841 } else {
3842 return FALSE;
3843 }
3844 }
3845
3847
3848 /* "unit_built" script handler may have destroyed city. If so, we
3849 * assume something sensible happened to its units, and that the
3850 * script took care of announcing unit creation if required. */
3851 if (city_exist(saved_id)) {
3852 /* Shift all the units supported by pcity (including the new unit)
3853 * to rcity. transfer_city_units does not make sure no units are
3854 * left floating without a transport, but since all units are
3855 * transferred this is not a problem. */
3856 transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity,
3857 pcity, -1, TRUE);
3858
3859 if (punit) {
3860 notify_player(pplayer, ptile, E_UNIT_BUILT, ftc_server,
3861 /* TRANS: "<city> is disbanded into Settler." */
3862 _("%s is disbanded into %s."),
3864 }
3865
3866 script_server_signal_emit("city_destroyed", pcity, pcity->owner, NULL);
3867
3868 if (!city_exist(saved_id)) {
3869 /* Already removed during the script */
3870 return TRUE;
3871 }
3873
3874 /* Since we've removed the city, we don't need to worry about
3875 * charging for production, disabling rally points, etc. */
3876 }
3877
3878 return TRUE;
3879}
3880
3881/**********************************************************************/
3929static float city_migration_score(struct city *pcity)
3930{
3931 float score = 0.0;
3932 int build_shield_cost = 0;
3933 bool has_wonder = FALSE;
3934
3935 if (!pcity) {
3936 return score;
3937 }
3938
3939 if (pcity->server.mgr_score_calc_turn == game.info.turn) {
3940 /* up-to-date migration score */
3941 return pcity->server.migration_score;
3942 }
3943
3944 /* feeling of the citizens */
3945 score = (city_size_get(pcity)
3946 + 1.00 * pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
3947 + 0.00 * pcity->feel[CITIZEN_CONTENT][FEELING_FINAL]
3948 - 0.25 * pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
3949 - 0.50 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
3950
3951 /* calculate shield build cost for all buildings */
3952 city_built_iterate(pcity, pimprove) {
3954 if (is_wonder(pimprove)) {
3955 /* this city has a wonder */
3956 has_wonder = TRUE;
3957 }
3959
3960 /* take shield costs of all buidings into account; normalized by 1000 */
3961 score *= (1 + (1 - exp(- (float) MAX(0, build_shield_cost) / 1000)) / 5);
3962 /* take trade into account; normalized by 100 */
3963 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_TRADE]) / 100))
3964 / 5);
3965 /* take luxury into account; normalized by 100 */
3966 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_LUXURY]) / 100))
3967 / 5);
3968 /* take science into account; normalized by 100 */
3969 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_SCIENCE]) / 100))
3970 / 5);
3971
3973
3974 /* Take food into account; the food surplus is clipped to values between
3975 * -10..20 and normalize by 10. Thus, the factor is between 0.9 and 1.2. */
3976 score *= (1 + (float) CLIP(-10, pcity->surplus[O_FOOD], 20) / 10 );
3977
3978 /* Reduce the score due to city illness (plague). The illness is given in
3979 * tenth of percent (0..1000) and normalized by 25. Thus, this factor is
3980 * between 0.6 (ill city) and 1.0 (health city). */
3981 score *= (100 - (float)city_illness_calc(pcity, NULL, NULL, NULL, NULL)
3982 / 25);
3983
3984 if (has_wonder) {
3985 /* people like wonders */
3986 score *= 1.25;
3987 }
3988
3989 if (is_capital(pcity)) {
3990 /* the capital is a magnet for the citizens */
3991 score *= 1.25;
3992 }
3993
3994 /* take into account effects */
3995 score *= (1.0 + get_city_bonus(pcity, EFT_MIGRATION_PCT) / 100.0);
3996
3997 log_debug("[M] %s score: %.3f", city_name_get(pcity), score);
3998
3999 /* set migration score for the city */
4000 pcity->server.migration_score = score;
4001 /* set the turn, when the score was calculated */
4002 pcity->server.mgr_score_calc_turn = game.info.turn;
4003
4004 return score;
4005}
4006
4007/**********************************************************************/
4014 struct city *pcity_to)
4015{
4017 struct tile *ptile_from, *ptile_to;
4019 const char *nation_from, *nation_to;
4020 struct city *rcity = NULL;
4021 int to_id = pcity_to->id;
4022 const struct civ_map *nmap = &(wld.map);
4023
4024 if (!pcity_from || !pcity_to) {
4025 return FALSE;
4026 }
4027
4031 /* We copy that, because city_link always returns the same pointer. */
4038
4039 /* Check food supply in the receiver city */
4041 bool migration = FALSE;
4042
4043 if (pcity_to->surplus[O_FOOD] >= game.info.food_cost) {
4044 migration = TRUE;
4045 } else {
4046 /* Check if there is a free tile for the new citizen which, when worked,
4047 * leads to zero or positive food surplus for the enlarged city */
4048 int max_food_tile = -1; /* no free tile */
4049
4051 city_tile(pcity_to), ptile) {
4052 if (city_can_work_tile(pcity_to, ptile)
4053 && tile_worked(ptile) != pcity_to) {
4054 /* Safest assumption is that city won't be celebrating once an
4055 * additional citizen is added */
4058 }
4060 if (max_food_tile >= 0
4061 && pcity_to->surplus[O_FOOD] + max_food_tile >= game.info.food_cost) {
4062 migration = TRUE;
4063 }
4064 }
4065
4066 if (!migration) {
4067 /* insufficiency food in receiver city; no additional citizens */
4068 if (pplayer_from == pplayer_to) {
4069 /* migration between one nation */
4071 /* TRANS: From <city1> to <city2>. */
4072 _("Migrants from %s can't go to %s because there is "
4073 "not enough food available!"),
4075 } else {
4076 /* migration between different nations */
4078 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4079 _("Migrants from %s can't go to %s (%s) because there "
4080 "is not enough food available!"),
4083 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4084 _("Migrants from %s (%s) can't go to %s because there "
4085 "is not enough food available!"),
4087 }
4088
4089 return FALSE;
4090 }
4091 }
4092
4094 /* receiver city can't grow */
4095 if (pplayer_from == pplayer_to) {
4096 /* migration between one nation */
4098 /* TRANS: From <city1> to <city2>. */
4099 _("Migrants from %s can't go to %s because it needs "
4100 "an improvement to grow!"),
4102 } else {
4103 /* migration between different nations */
4105 /* TRANS: From <city1> to <city2> of <city2 nation adjective>. */
4106 _("Migrants from %s can't go to %s (%s) because it "
4107 "needs an improvement to grow!"),
4110 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4111 _("Migrants from %s (%s) can't go to %s because it "
4112 "needs an improvement to grow!"),
4114 }
4115
4116 return FALSE;
4117 }
4118
4119 /* reduce size of giver */
4120 if (city_size_get(pcity_from) == 1) {
4121
4123 /* Preserve nationality of city's only citizen */
4125 }
4126
4127 /* do not destroy wonders */
4128 city_built_iterate(pcity_from, pimprove) {
4129 if (is_wonder(pimprove)) {
4130 return FALSE;
4131 }
4133
4134 /* find closest city other of the same player than pcity_from */
4136 FALSE, FALSE, TRUE, FALSE, NULL);
4137
4138 if (rcity) {
4139 int id = pcity_from->id;
4140
4141 /* transfer all units to the closest city */
4143 pcity_from->units_supported, rcity, pcity_from,
4144 -1, TRUE);
4146
4147 script_server_signal_emit("city_size_change", pcity_from,
4148 (lua_Integer)(-1), "migration_from");
4149
4150 if (city_exist(id)) {
4151 script_server_signal_emit("city_destroyed", pcity_from,
4152 pcity_from->owner, NULL);
4153
4154 if (city_exist(id)) {
4156 }
4157 }
4158
4160 _("%s was disbanded by its citizens."),
4161 name_from);
4162 } else {
4163 /* it's the only city of the nation */
4164 return FALSE;
4165 }
4166 } else {
4167 /* the migrants take half of the food box with them (this prevents
4168 * migration -> grow -> migration -> ... cycles) */
4169 pcity_from->food_stock /= 2;
4170
4172 /* Those citizens that are from the target nation are most
4173 * ones migrating. */
4174 if (citizens_nation_get(pcity_from, pplayer_to->slot) > 0) {
4176 } else if (!citizens_nation_get(pcity_from, pplayer_citizen->slot)) {
4177 /* No native citizens at all in the city, choose random foreigner */
4179
4181 }
4182 /* This should be followed by city_reduce_size(). */
4184 }
4185 city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
4187 if (city_refresh(pcity_from)) {
4189 }
4190 }
4191
4192 /* This should be _before_ the size of the city is increased. Thus, the
4193 * order of the messages is correct (1: migration; 2: increased size). */
4194 if (pplayer_from == pplayer_to) {
4195 /* migration between one nation */
4197 /* TRANS: From <city1> to <city2>. */
4198 _("Migrants from %s moved to %s in search of a better "
4199 "life."), name_from, name_to);
4200 } else {
4201 /* migration between different nations */
4203 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
4204 _("Migrants from %s moved to %s (%s) in search of a "
4205 "better life."),
4208 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
4209 _("Migrants from %s (%s) moved to %s in search of a "
4210 "better life."),
4212 }
4213
4214 /* Increase size of receiver city */
4215 if (city_exist(to_id)) {
4217
4218 if (city_exist(to_id)) {
4221 if (city_refresh(pcity_to)) {
4223 }
4224 if (incr_success) {
4225 script_server_signal_emit("city_size_change", pcity_to,
4226 (lua_Integer)1, "migration_to");
4227 }
4228 }
4229 }
4230
4231 log_debug("[M] T%d migration successful (%s -> %s)",
4233
4234 return TRUE;
4235}
4236
4237/**********************************************************************/
4259{
4260 bool internat = FALSE;
4261
4262 if (!game.server.migration) {
4263 return FALSE;
4264 }
4265
4267 || (game.server.mgr_worldchance <= 0
4268 && game.server.mgr_nationchance <= 0)) {
4269 return FALSE;
4270 }
4271
4272 /* check for migration */
4273 players_iterate(pplayer) {
4274 if (!pplayer->cities) {
4275 continue;
4276 }
4277
4278 if (check_city_migrations_player(pplayer)) {
4279 internat = TRUE;
4280 }
4282
4283 return internat;
4284}
4285
4286/**********************************************************************/
4291 struct player *pplayer = city_owner(pcity);
4292 struct tile *ptile = city_tile(pcity);
4293
4295
4296 if (pcity->food_stock > 0) {
4297 pcity->food_stock = 0;
4298
4299 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4300 /* TRANS: %s is a city name */
4301 _("All stored food destroyed in %s."), city_link(pcity));
4302
4303 return TRUE;
4304 }
4305
4306 return FALSE;
4307}
4308
4309/**********************************************************************/
4312static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
4313{
4314 struct player *pplayer = city_owner(pcity);
4315 struct tile *ptile = city_tile(pcity);
4317
4319
4320 notify_player(pplayer, ptile, E_DISASTER,
4321 ftc_server,
4322 /* TRANS: Disasters such as Earthquake */
4323 _("%s was hit by %s."), city_name_get(pcity),
4325
4327 if (pplayer->economic.gold > 0 && pcity->prod[O_TRADE] > 0) {
4328 int amount = pcity->prod[O_TRADE] * 5;
4329
4330 amount = MIN(pplayer->economic.gold, amount);
4331 pplayer->economic.gold -= amount;
4332 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4333 PL_("Robbery in %s. %d gold stolen.",
4334 "Robbery in %s. %d gold stolen.", amount),
4337 }
4338 }
4339
4342 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4343 _("Pollution near %s."), city_link(pcity));
4345 }
4346 }
4347
4350 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4351 _("Fallout near %s."), city_link(pcity));
4353 }
4354 }
4355
4358 && pcity->size > 1)) {
4359 if (!city_reduce_size(pcity, 1, NULL, "disaster")) {
4360 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4361 /* TRANS: "Industrial Accident destroys Bogota entirely." */
4362 _("%s destroys %s entirely."),
4364 pcity = NULL;
4365 } else {
4366 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4367 /* TRANS: "Nuclear Accident ... Montreal." */
4368 _("%s causes population loss in %s."),
4370 }
4371
4373 }
4374
4376 int total = 0;
4377 struct impr_type *imprs[B_LAST];
4378
4379 city_built_iterate(pcity, pimprove) {
4380 if (is_improvement(pimprove)
4381 && !improvement_has_flag(pimprove, IF_DISASTER_PROOF)) {
4382 imprs[total++] = pimprove;
4383 }
4385
4386 if (total > 0) {
4387 int num = fc_rand(total);
4388
4389 building_lost(pcity, imprs[num], "disaster", NULL);
4390
4391 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4392 /* TRANS: second %s is the name of a city improvement */
4393 _("%s destroys %s in %s."),
4396 city_link(pcity));
4397
4399 }
4400 }
4401
4405 }
4406 }
4407
4409 if (pcity->shield_stock > 0) {
4410 char prod[256];
4411
4412 pcity->shield_stock = 0;
4413 nullify_prechange_production(pcity); /* Make it impossible to recover */
4414
4415 universal_name_translation(&pcity->production, prod, sizeof(prod));
4416 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4417 /* TRANS: "Production of Colossus in Rhodes destroyed." */
4418 _("Production of %s in %s destroyed."),
4419 prod, city_link(pcity));
4420
4422 }
4423 }
4424
4425 script_server_signal_emit("disaster_occurred", pdis, pcity,
4427 script_server_signal_emit("disaster", pdis, pcity);
4428}
4429
4430/**********************************************************************/
4434{
4435 if (game.info.disasters == 0) {
4436 /* Shortcut out as no disaster is possible. */
4437 return;
4438 }
4439
4440 players_iterate(pplayer) {
4441 /* Safe city iterator needed as disaster may destroy city */
4442 city_list_iterate_safe(pplayer->cities, pcity) {
4443 int id = pcity->id;
4444
4446 if (city_exist(id)) {
4447 /* City survived earlier disasters. */
4448 int probability = game.info.disasters * pdis->frequency;
4449 int result = fc_rand(DISASTER_BASE_RARITY);
4450
4451 if (result < probability) {
4454 }
4455 }
4456 }
4460}
4461
4462/**********************************************************************/
4470static bool check_city_migrations_player(const struct player *pplayer)
4471{
4475 float score_from, score_tmp, weight;
4476 int dist, mgr_dist;
4477 bool internat = FALSE;
4478
4479 /* check for each city
4480 * city_list_iterate_safe_end must be used because we could
4481 * remove one city from the list */
4483 /* no migration out of the capital */
4484 if (is_capital(pcity)) {
4485 continue;
4486 }
4487
4488 /* check only each (game.server.mgr_turninterval) turn
4489 * (counted from the funding turn) and do not migrate
4490 * the same turn a city is founded */
4491 if (game.info.turn == pcity->turn_founded
4492 || ((game.info.turn - pcity->turn_founded)
4493 % game.server.mgr_turninterval) != 0) {
4494 continue;
4495 }
4496
4501
4502 /* score of the actual city
4503 * taking into account a persistence factor of 3 */
4505
4506 log_debug("[M] T%d check city: %s score: %6.3f (%s)",
4508 player_name(pplayer));
4509
4510 /* consider all cities within the maximal possible distance
4511 * (= CITY_MAP_MAX_RADIUS + GAME_MAX_MGR_DISTANCE) */
4514 acity = tile_city(ptile);
4515
4516 if (!acity || acity == pcity) {
4517 /* no city or the city in the center */
4518 continue;
4519 }
4520
4521 /* Calculate the migration distance. The value of
4522 * game.server.mgr_distance is added to the current city radius. If the
4523 * distance between both cities is lower or equal than this value,
4524 * migration is possible. */
4527
4528 /* distance between the two cities */
4530
4531 if (dist > mgr_dist) {
4532 /* to far away */
4533 continue;
4534 }
4535
4536 /* score of the second city, weighted by the distance */
4537 weight = ((float) (mgr_dist + 1 - dist) / (float) (mgr_dist + 1));
4539
4540 log_debug("[M] T%d - compare city: %s (%s) dist: %d mgr_dist: %d "
4541 "score: %6.3f", game.info.turn, city_name_get(acity),
4543
4544 if (game.server.mgr_nationchance > 0 && city_owner(acity) == pplayer) {
4545 /* migration between cities of the same owner */
4547 /* select the best! */
4550
4551 log_debug("[M] T%d - best city (player): %s (%s) score: "
4552 "%6.3f (> %6.3f)", game.info.turn,
4555 }
4556 } else if (game.server.mgr_worldchance > 0
4557 && city_owner(acity) != pplayer) {
4558 /* migration between cities of different owners */
4560 /* Modify the score if citizens could migrate to a city of their
4561 * original nation. */
4562 if (citizens_nation_get(pcity, city_owner(acity)->slot) > 0) {
4563 score_tmp *= 2;
4564 }
4565 }
4566
4568 /* select the best! */
4571
4572 log_debug("[M] T%d - best city (world): %s (%s) score: "
4573 "%6.3f (> %6.3f)", game.info.turn,
4577 }
4578 }
4580
4581 if (best_city_player != NULL) {
4582 /* First, do the migration within one nation */
4583 if (fc_rand(100) >= game.server.mgr_nationchance) {
4584 /* No migration */
4585 /* N.B.: city_link always returns the same pointer. */
4588 _("Citizens of %s are thinking about migrating to %s "
4589 "for a better life."),
4591 } else {
4593 }
4594
4595 /* Stop here */
4596 continue;
4597 }
4598
4599 if (best_city_world != NULL) {
4600 /* Second, do the migration between all nations */
4601 if (fc_rand(100) >= game.server.mgr_worldchance) {
4602 const char *nname;
4603
4605 /* No migration */
4606 /* N.B.: city_link always returns the same pointer. */
4609 /* TRANS: <city1> to <city2> (<city2 nation adjective>). */
4610 _("Citizens of %s are thinking about migrating to %s "
4611 "(%s) for a better life."),
4613 } else {
4615 internat = TRUE;
4616 }
4617
4618 /* Stop here */
4619 continue;
4620 }
4622
4623 return internat;
4624}
4625
4626/**********************************************************************/
4630{
4631 pcity->style = city_style(pcity);
4632}
4633
4634/**********************************************************************/
4639{
4641 struct packet_city_update_counters packet;
4642
4643 packet.city = pcity->id;
4644
4646
4647 packet.count = counter_count;
4648 for (i = 0; i < counter_count; i++) {
4649 packet.counters[i] = pcity->counter_values[i];
4650 }
4651
4654}
4655
4656/**********************************************************************/
4659void city_tc_effect_refresh(struct player *pplayer)
4660{
4661 const struct civ_map *nmap = &(wld.map);
4662
4663 city_list_iterate(pplayer->cities, pcity) {
4664 bool changed = FALSE;
4665
4667 city_tile(pcity), ptile, idx, x, y) {
4668 if (ptile->worked == pcity
4671 pcity->specialists[DEFAULT_SPECIALIST]++;
4672 changed = TRUE;
4673 }
4675
4676 if (changed) {
4679 }
4681}
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:3804
static void uk_rem_gold_append(struct unit *punit)
Definition cityturn.c:3119
static bool worklist_change_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2199
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:3020
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:4312
static bool city_distribute_surplus_shields(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2554
static void unit_list_referred_destroy(struct unit_list *punitlist)
Definition cityturn.c:3132
static bool place_pollution(struct city *pcity, enum extra_cause cause)
Definition cityturn.c:3417
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2417
static void uk_rem_gold_callback(struct unit *punit)
Definition cityturn.c:3098
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:3335
static void update_city_activity(struct city *pcity)
Definition cityturn.c:3594
static void upgrade_unit_prod(struct city *pcity)
Definition cityturn.c:2530
static float city_migration_score(struct city *pcity)
Definition cityturn.c:3929
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3585
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4290
bool check_city_migrations(void)
Definition cityturn.c:4258
static void upgrade_building_prod(struct city *pcity)
Definition cityturn.c:2483
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3238
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, const char *reason)
Definition cityturn.c:1037
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:1088
static void city_refresh_after_city_size_increase(struct city *pcity, struct player *nationality)
Definition cityturn.c:1003
static void define_orig_production_values(struct city *pcity)
Definition cityturn.c:3554
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:4638
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:2635
static struct unit static const struct impr_type * building_upgrades_to(struct city *pcity, const struct impr_type *pimprove)
Definition cityturn.c:2462
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:3155
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3473
static void nullify_caravan_and_disband_plus(struct city *pcity)
Definition cityturn.c:3575
static bool sell_random_building(struct player *pplayer, struct cityimpr_list *imprs)
Definition cityturn.c:3052
static bool disband_city(struct city *pcity)
Definition cityturn.c:3817
void update_city_activities(struct player *pplayer)
Definition cityturn.c:602
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:762
#define cityimpr_list_iterate_end
Definition cityturn.c:129
bool city_refresh(struct city *pcity)
Definition cityturn.c:158
static void city_turn_notify(const struct city *pcity, struct conn_list *dest, const struct player *cache_for_player)
Definition cityturn.c:511
static void city_shrink_reset_foodbox(struct city *pcity, int new_size)
Definition cityturn.c:905
static bool city_increase_size(struct city *pcity)
Definition cityturn.c:917
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:3301
void city_style_refresh(struct city *pcity)
Definition cityturn.c:4629
static bool city_balance_treasury_units(struct city *pcity)
Definition cityturn.c:3382
static const struct unit_type * unit_upgrades_to(struct city *pcity, const struct unit_type *id)
Definition cityturn.c:2508
static bool do_city_migration(struct city *pcity_from, struct city *pcity_to)
Definition cityturn.c:4013
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:4659
static void check_pollution(struct city *pcity)
Definition cityturn.c:3456
void check_disasters(void)
Definition cityturn.c:4433
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:1165
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:2794
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:4470
static bool city_build_unit(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2855
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:525
Definition unit.h:140
int length
Definition unit.h:198
int upkeep[O_LAST]
Definition unit.h:150
bool has_orders
Definition unit.h:196
int id
Definition unit.h:147
struct unit::@83 orders
bool debug
Definition unit.h:237
bool vigilant
Definition unit.h:200
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
struct unit_order * list
Definition unit.h:201
enum unit_activity changed_from
Definition unit.h:171
struct player * nationality
Definition unit.h:146
int upkeep_paid[O_LAST]
Definition unit.h:259
struct goods_type * carrying
Definition unit.h:189
const struct unit_type * utype
Definition unit.h:141
struct player * owner
Definition unit.h:145
enum universals_n kind
Definition fc_types.h: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:119
#define tile_has_extra(ptile, pextra)
Definition tile.h:152
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
bool goods_can_be_provided(const struct city *pcity, const struct goods_type *pgood, const struct unit *punit)
bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
const char * goods_name_translation(struct goods_type *pgood)
#define trade_routes_iterate_safe_end
@ TRI_CANCEL
Definition traderoutes.h:32
#define trade_routes_iterate_safe(c, proute)
#define trade_partners_iterate_end
#define trade_partners_iterate(c, p)
trade_route_type
Definition traderoutes.h:37
const struct unit_type * utype
Definition fc_types.h:553
const struct impr_type * building
Definition fc_types.h:546
bool unit_is_alive(int id)
Definition unit.c:2316
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:401
#define unit_tile(_pu)
Definition unit.h:407
#define unit_cargo_iterate_end
Definition unit.h:588
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:585
#define unit_owner(_pu)
Definition unit.h:406
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void unit_set_removal_callback(struct unit *punit, void(*callback)(struct unit *punit))
Definition unittools.c:1776
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1718
struct unit * unit_virtual_prepare(struct player *pplayer, struct tile *ptile, const struct unit_type *type, int veteran_level, int homecity_id, int moves_left, int hp_left)
Definition unittools.c:1670
void unit_unset_removal_callback(struct unit *punit)
Definition unittools.c:1790
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2144
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:1480
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:1591
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1582
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1532
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1442
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1564
#define unit_tech_reqs_iterate_end
Definition unittype.h:886
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:880
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:622
#define U_NOT_OBSOLETED
Definition unittype.h:533
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