Freeciv-3.1
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 "culture.h"
45#include "events.h"
46#include "disaster.h"
47#include "game.h"
48#include "government.h"
49#include "map.h"
50#include "player.h"
51#include "research.h"
52#include "road.h"
53#include "server_settings.h"
54#include "specialist.h"
55#include "tech.h"
56#include "traderoutes.h"
57#include "unit.h"
58#include "unitlist.h"
59
60/* common/scriptcore */
61#include "luascript_types.h"
62
63/* server */
64#include "citizenshand.h"
65#include "citytools.h"
66#include "cityturn.h"
67#include "maphand.h"
68#include "notify.h"
69#include "plrhand.h"
70#include "sanitycheck.h"
71#include "spacerace.h"
72#include "srv_log.h"
73#include "srv_main.h"
74#include "techtools.h"
75#include "unittools.h"
76#include "unithand.h"
77
78/* server/advisors */
79#include "advbuilding.h"
80#include "advdata.h"
81#include "autosettlers.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);
142 (struct player *pplayer);
143static bool player_balance_treasury_units(struct player *pplayer);
144
145static bool disband_city(struct city *pcity);
146
147static void define_orig_production_values(struct city *pcity);
148static void update_city_activity(struct city *pcity);
149static void nullify_caravan_and_disband_plus(struct city *pcity);
150static bool city_illness_check(const struct city * pcity);
151
152static float city_migration_score(struct city *pcity);
153static bool do_city_migration(struct city *pcity_from,
154 struct city *pcity_to);
155static bool check_city_migrations_player(const struct player *pplayer);
156
157/**********************************************************************/
161bool city_refresh(struct city *pcity)
162{
163 bool retval;
164 const struct civ_map *nmap = &(wld.map);
165
166 pcity->server.needs_refresh = FALSE;
167
168 retval = city_map_update_radius_sq(pcity);
169 city_units_upkeep(pcity); /* Update unit upkeep */
170 city_refresh_from_main_map(nmap, pcity, NULL);
171 city_style_refresh(pcity);
172
173 if (retval) {
174 /* Force a sync of the city after the change. */
175 send_city_info(city_owner(pcity), pcity);
176 }
177
178 return retval;
179}
180
181/**********************************************************************/
185void city_refresh_for_player(struct player *pplayer)
186{
188 city_list_iterate(pplayer->cities, pcity) {
189 if (city_refresh(pcity)) {
191 }
192 send_city_info(pplayer, pcity);
195}
196
197/**********************************************************************/
200void city_refresh_queue_add(struct city *pcity)
201{
202 if (NULL == city_refresh_queue) {
203 city_refresh_queue = city_list_new();
204 } else if (city_list_find_number(city_refresh_queue, pcity->id)) {
205 return;
206 }
207
208 city_list_prepend(city_refresh_queue, pcity);
209 pcity->server.needs_refresh = TRUE;
210}
211
212/**********************************************************************/
217{
218 if (NULL == city_refresh_queue) {
219 return;
220 }
221
223 if (pcity->server.needs_refresh) {
224 if (city_refresh(pcity)) {
226 }
227 send_city_info(city_owner(pcity), pcity);
228 }
230
231 city_list_destroy(city_refresh_queue);
232 city_refresh_queue = NULL;
233}
234
235/**********************************************************************/
238void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
239{
240 struct player *pplayer = city_owner(pcity);
241 bool sold = FALSE;
242
243 city_built_iterate(pcity, pimprove) {
244 if (improvement_obsolete(pplayer, pimprove, pcity)
245 && can_city_sell_building(pcity, pimprove)) {
246 int sgold;
247
248 do_sell_building(pplayer, pcity, pimprove, "obsolete");
249 sgold = impr_sell_gold(pimprove);
250 notify_player(pplayer, city_tile(pcity), E_IMP_SOLD, ftc_server,
251 PL_("%s is selling %s (obsolete) for %d.",
252 "%s is selling %s (obsolete) for %d.",
253 sgold),
254 city_link(pcity),
256 sgold);
257 sold = TRUE;
258 }
260
261 if (sold && refresh) {
262 if (city_refresh(pcity)) {
264 }
265 send_city_info(pplayer, pcity);
266 send_player_info_c(pplayer, NULL); /* Send updated gold to all */
267 }
268}
269
270/**********************************************************************/
274{
275 city_list_iterate(pplayer->cities, pcity) {
278}
279
280/**********************************************************************/
284void apply_cmresult_to_city(struct city *pcity,
285 const struct cm_result *cmr)
286{
287 struct tile *pcenter = city_tile(pcity);
288 const struct civ_map *nmap = &(wld.map);
289
290 /* Now apply results */
292 ptile, idx, x, y) {
293 struct city *pwork = tile_worked(ptile);
294
295 if (cmr->worker_positions[idx]) {
296 if (NULL == pwork) {
297 city_map_update_worker(pcity, ptile);
298 } else {
299 fc_assert(pwork == pcity);
300 }
301 } else {
302 if (pwork == pcity) {
303 city_map_update_empty(pcity, ptile);
304 }
305 }
307
309 pcity->specialists[sp] = cmr->specialists[sp];
311}
312
313/**********************************************************************/
317 struct city *pcity)
318{
319 int csize = city_size_get(pcity);
320 int gsize = city_granary_size(csize);
321
322 cmp->require_happy = FALSE;
323 cmp->allow_disorder = FALSE;
324 cmp->allow_specialists = TRUE;
325
326 /* We used to look at pplayer->ai.xxx_priority to determine the values
327 * to be used here. However that doesn't work at all because those values
328 * are on a different scale. Later the AI may wish to adjust its
329 * priorities - this should be done via a separate set of variables. */
330 if (csize > 1) {
331 if (csize <= game.info.notradesize) {
332 cmp->factor[O_FOOD] = 15;
333 } else {
334 if (gsize == pcity->food_stock) {
335 /* We don't need more food if the granary is full. */
336 cmp->factor[O_FOOD] = 0;
337 } else {
338 cmp->factor[O_FOOD] = 10;
339 }
340 }
341 } else {
342 /* Growing to size 2 is the highest priority. */
343 cmp->factor[O_FOOD] = 20;
344 }
345
346 cmp->factor[O_SHIELD] = 5;
347 cmp->factor[O_TRADE] = 0; /* Trade only provides gold/science. */
348 cmp->factor[O_GOLD] = 2;
349 cmp->factor[O_LUXURY] = 0; /* Luxury only influences happiness. */
350 cmp->factor[O_SCIENCE] = 2;
351 cmp->happy_factor = 0;
352
353 if (gsize == pcity->food_stock) {
354 cmp->minimal_surplus[O_FOOD] = 0;
355 } else {
356 cmp->minimal_surplus[O_FOOD] = 1;
357 }
358
359 cmp->minimal_surplus[O_SHIELD] = 1;
360 cmp->minimal_surplus[O_TRADE] = 0;
361 cmp->minimal_surplus[O_GOLD] = -FC_INFINITY;
362 cmp->minimal_surplus[O_LUXURY] = 0;
363 cmp->minimal_surplus[O_SCIENCE] = 0;
364}
365
366/**********************************************************************/
369void auto_arrange_workers(struct city *pcity)
370{
371 struct cm_parameter cmp;
372 struct cm_parameter *pcmp;
373 struct cm_result *cmr;
374 bool broadcast_needed;
375
376 /* See comment in freeze_workers(): we can't rearrange while
377 * workers are frozen (i.e. multiple updates need to be done). */
378 if (pcity->server.workers_frozen > 0) {
379 if (pcity->server.needs_arrange == CNA_NOT) {
381 }
382 return;
383 }
385
386 broadcast_needed = (pcity->server.needs_arrange == CNA_BROADCAST_PENDING);
387
388 /* Freeze the workers and make sure all the tiles around the city
389 * are up to date. Then thaw, but hackishly make sure that thaw
390 * doesn't call us recursively, which would waste time. */
391 city_freeze_workers(pcity);
393
394 city_map_update_all(pcity);
395
397 city_thaw_workers(pcity);
398
399 /* Now start actually rearranging. */
400 city_refresh(pcity);
401
402 sanity_check_city(pcity);
403 cm_clear_cache(pcity);
404
405 if (pcity->cm_parameter) {
406 pcmp = pcity->cm_parameter;
407 } else {
408 pcmp = &cmp;
409 cm_init_parameter(pcmp);
410 set_default_city_manager(pcmp, pcity);
411 }
412
413 /* This must be after city_refresh() so that the result gets created for the right
414 * city radius */
415 cmr = cm_result_new(pcity);
416 cm_query_result(pcity, pcmp, cmr, FALSE);
417
418 if (!cmr->found_a_valid) {
419 if (pcity->cm_parameter) {
420 /* If player-defined parameters fail, cancel and notify player. */
421 free(pcity->cm_parameter);
422 pcity->cm_parameter = NULL;
423
424 notify_player(city_owner(pcity), city_tile(pcity),
425 E_CITY_CMA_RELEASE, ftc_server,
426 _("The citizen governor can't fulfill the requirements "
427 "for %s. Passing back control."),
428 city_link(pcity));
429
430 /* Switch to default parameters, and try with them */
431 pcmp = &cmp;
432 cm_init_parameter(pcmp);
433 set_default_city_manager(pcmp, pcity);
434 cm_query_result(pcity, pcmp, cmr, FALSE);
435 }
436
437 if (!cmr->found_a_valid) {
438 /* Drop surpluses and try again. */
440 cmp.minimal_surplus[o] = 0;
442 cmp.minimal_surplus[O_GOLD] = -FC_INFINITY;
443 cm_query_result(pcity, pcmp, cmr, FALSE);
444 }
445 }
446 if (!cmr->found_a_valid) {
447 /* Emergency management. Get _some_ result. This doesn't use
448 * cm_init_emergency_parameter() so we can keep the factors from
449 * above. */
451 cmp.minimal_surplus[o] = MIN(cmp.minimal_surplus[o],
452 MIN(pcity->surplus[o], 0));
454 cmp.require_happy = FALSE;
455 cmp.allow_disorder = is_ai(city_owner(pcity)) ? FALSE : TRUE;
456 cm_query_result(pcity, pcmp, cmr, FALSE);
457 }
458 if (!cmr->found_a_valid) {
459 CITY_LOG(LOG_DEBUG, pcity, "emergency management");
460 pcmp = &cmp;
462 cm_query_result(pcity, pcmp, cmr, TRUE);
463 }
465
466 apply_cmresult_to_city(pcity, cmr);
467
468 if (pcity->server.debug) {
469 /* Print debug output if requested. */
470 cm_print_city(pcity);
471 cm_print_result(cmr);
472 }
473
474 if (city_refresh(pcity)) {
475 log_error("%s radius changed when already arranged workers.",
476 city_name_get(pcity));
477 /* Can't do anything - don't want to enter infinite recursive loop
478 * by trying to arrange workers more. */
479 }
480 sanity_check_city(pcity);
481
482 if (broadcast_needed) {
483 broadcast_city_info(pcity);
484 }
485
488}
489
490/**********************************************************************/
493static void city_global_turn_notify(struct conn_list *dest)
494{
495 cities_iterate(pcity) {
496 const struct impr_type *pimprove = pcity->production.value.building;
497
498 if (VUT_IMPROVEMENT == pcity->production.kind
499 && is_great_wonder(pimprove)
500 && (1 >= city_production_turns_to_build(pcity, TRUE)
501 && can_city_build_improvement_now(pcity, pimprove))) {
502 notify_conn(dest, city_tile(pcity),
503 E_WONDER_WILL_BE_BUILT, ftc_server,
504 _("Notice: Wonder %s in %s will be finished next turn."),
505 improvement_name_translation(pimprove), city_link(pcity));
506 }
508}
509
510/**********************************************************************/
514static void city_turn_notify(const struct city *pcity,
515 struct conn_list *dest,
516 const struct player *cache_for_player)
517{
518 const struct impr_type *pimprove = pcity->production.value.building;
519 struct packet_chat_msg packet;
520 int turns_growth, turns_granary;
521
522 if (0 < pcity->surplus[O_FOOD]) {
523 turns_growth = (city_granary_size(city_size_get(pcity))
524 - pcity->food_stock - 1) / pcity->surplus[O_FOOD];
525
526 if (get_city_bonus(pcity, EFT_GROWTH_FOOD) <= 0
527 && 0 < get_current_construction_bonus(pcity, EFT_GROWTH_FOOD,
529 && 0 < pcity->surplus[O_SHIELD]) {
530 /* From the check above, the surplus must always be positive. */
531 turns_granary = (impr_build_shield_cost(pcity, pimprove)
532 - pcity->shield_stock) / pcity->surplus[O_SHIELD];
533 /* If growth and granary completion occur simultaneously, granary
534 * preserves food. -AJS. */
535 if (5 > turns_growth && 5 > turns_granary
536 && turns_growth < turns_granary) {
537 package_event(&packet, city_tile(pcity),
538 E_CITY_GRAN_THROTTLE, ftc_server,
539 _("Suggest throttling growth in %s to use %s "
540 "(being built) more effectively."),
541 city_link(pcity),
543 lsend_packet_chat_msg(dest, &packet);
544 if (NULL != cache_for_player) {
545 event_cache_add_for_player(&packet, cache_for_player);
546 }
547 }
548 }
549
550 if (0 >= turns_growth && !city_celebrating(pcity)
551 && city_can_grow_to(pcity, city_size_get(pcity) + 1)) {
552 package_event(&packet, city_tile(pcity),
553 E_CITY_MAY_SOON_GROW, ftc_server,
554 _("%s may soon grow to size %i."),
555 city_link(pcity), city_size_get(pcity) + 1);
556 lsend_packet_chat_msg(dest, &packet);
557 if (NULL != cache_for_player) {
558 event_cache_add_for_player(&packet, cache_for_player);
559 }
560 }
561 } else {
562 if (0 >= pcity->food_stock + pcity->surplus[O_FOOD]
563 && 0 > pcity->surplus[O_FOOD]) {
564 package_event(&packet, city_tile(pcity),
565 E_CITY_FAMINE_FEARED, ftc_server,
566 _("Warning: Famine feared in %s."), city_link(pcity));
567 lsend_packet_chat_msg(dest, &packet);
568 if (NULL != cache_for_player) {
569 event_cache_add_for_player(&packet, cache_for_player);
570 }
571 }
572 }
573}
574
575/**********************************************************************/
580{
581 if (NULL != pconn) {
582 struct player *pplayer = conn_get_player(pconn);
583
584 if (NULL != pplayer) {
585 city_list_iterate(pplayer->cities, pcity) {
586 city_turn_notify(pcity, pconn->self, NULL);
588 }
590 } else {
591 players_iterate(pplayer) {
592 city_list_iterate(pplayer->cities, pcity) {
593 city_turn_notify(pcity, pplayer->connections, pplayer);
596 /* NB: notifications to 'game.est_connections' are automatically
597 * cached. */
599 }
600}
601
602/**********************************************************************/
605void update_city_activities(struct player *pplayer)
606{
607 char buf[4 * MAX_LEN_NAME];
608 int n, gold;
609
610 fc_assert(NULL != pplayer->cities);
611
612 n = city_list_size(pplayer->cities);
613 gold = pplayer->economic.gold;
614 pplayer->server.bulbs_last_turn = 0;
615
616 if (n > 0) {
617 struct city *cities[n];
618 int i = 0, r;
619
620 city_list_iterate(pplayer->cities, pcity) {
621
622 citizens_convert(pcity);
623
624 /* Cancel trade routes that cannot exist any more */
625 trade_routes_iterate_safe(pcity, proute) {
626 struct city *tcity = game_city_by_number(proute->partner);
627
628 if (tcity != NULL) {
629 bool cancel = FALSE;
630
631 if (proute->dir != RDIR_FROM && goods_has_flag(proute->goods, GF_DEPLETES)
632 && !goods_can_be_provided(tcity, proute->goods, NULL)) {
633 cancel = TRUE;
634 }
635 if (!cancel && !can_cities_trade(pcity, tcity)) {
636 enum trade_route_type type = cities_trade_route_type(pcity, tcity);
638
639 if (settings->cancelling == TRI_CANCEL) {
640 cancel = TRUE;
641 }
642 }
643
644 if (cancel) {
645 struct trade_route *back;
646
647 back = remove_trade_route(pcity, proute, TRUE, FALSE);
648 free(proute);
649 free(back);
650 }
651 }
653
654 /* Add cities to array for later random order handling */
655 cities[i++] = pcity;
657
658 /* How gold upkeep is handled depends on the setting
659 * 'game.info.gold_upkeep_style':
660 * GOLD_UPKEEP_CITY: Each city tries to balance its upkeep individually
661 * (this is done in update_city_activity()).
662 * GOLD_UPKEEP_MIXED: Each city tries to balance its upkeep for
663 * buildings individually; the upkeep for units is
664 * paid by the nation.
665 * GOLD_UPKEEP_NATION: The nation as a whole balances the treasury. If
666 * the treasury is not balance units and buildings
667 * are sold. */
668
669 /* Iterate over cities in a random order. */
670 while (i > 0) {
671 r = fc_rand(i);
672 /* update unit upkeep */
675 cities[r] = cities[--i];
676 }
677
678 if (pplayer->economic.infra_points < 0) {
679 pplayer->economic.infra_points = 0;
680 }
681
682 if (pplayer->economic.gold < 0) {
683 switch (game.info.gold_upkeep_style) {
684 case GOLD_UPKEEP_CITY:
685 break;
686 case GOLD_UPKEEP_MIXED:
687 /* Nation pays for units. */
689 break;
690 case GOLD_UPKEEP_NATION:
691 /* Nation pays for units and buildings. */
693 break;
694 }
695 }
696
697 /* Should not happen. */
698 fc_assert(pplayer->economic.gold >= 0);
699 }
700
701 /* This test includes the cost of the units because
702 * units are paid for in update_city_activity() or
703 * player_balance_treasury_units(). */
704 if (gold - (gold - pplayer->economic.gold) * 3 < 0) {
705 notify_player(pplayer, NULL, E_LOW_ON_FUNDS, ftc_server,
706 _("WARNING, we're LOW on FUNDS %s."),
707 ruler_title_for_player(pplayer, buf, sizeof(buf)));
708 }
709
710#if 0
711 /* Uncomment to unbalance the game, like in civ1 (CLG). */
712 if (pplayer->got_tech && pplayer->research->researched > 0) {
713 pplayer->research->researched = 0;
714 }
715#endif
716
718}
719
720/**********************************************************************/
732static bool upkeep_kill_unit(struct unit *punit, Output_type_id outp,
733 enum unit_loss_reason wipe_reason,
734 bool wipe_in_the_end)
735{
736 int punit_id;
737
738 if (!action_auto_perf_unit_sel(AAPC_UNIT_UPKEEP, punit,
739 NULL, get_output_type(outp), NULL)) {
740 /* Can't get rid of this unit. It is undisbandable for the current
741 * situation. */
742 return FALSE;
743 }
744
745 punit_id = punit->id;
746
747 /* Try to perform this unit's can't upkeep actions. */
748 action_auto_perf_unit_do(AAPC_UNIT_UPKEEP, punit,
749 NULL, get_output_type(outp), NULL,
750 NULL, NULL, NULL, NULL);
751
752 if (wipe_in_the_end && unit_is_alive(punit_id)) {
753 /* No forced action was able to kill the unit. Finish the job. */
754 wipe_unit(punit, wipe_reason, NULL);
755 }
756
757 return !unit_is_alive(punit_id);
758}
759
760/**********************************************************************/
764static citizens city_reduce_specialists(struct city *pcity, citizens change)
765{
766 citizens want = change;
767
768 fc_assert_ret_val(0 < change, 0);
769
771 citizens fix = MIN(want, pcity->specialists[sp]);
772
773 pcity->specialists[sp] -= fix;
774 want -= fix;
776
777 return change - want;
778}
779
780/**********************************************************************/
784static citizens city_reduce_workers(struct city *pcity, citizens change)
785{
786 struct tile *pcenter = city_tile(pcity);
787 int want = change;
788 const struct civ_map *nmap = &(wld.map);
789
790 fc_assert_ret_val(0 < change, 0);
791
793 ptile, _index, _x, _y) {
794 if (0 < want && tile_worked(ptile) == pcity) {
795 city_map_update_empty(pcity, ptile);
796 want--;
797 }
799
800 return change - want;
801}
802
803/**********************************************************************/
808bool city_reduce_size(struct city *pcity, citizens pop_loss,
809 struct player *destroyer, const char *reason)
810{
811 citizens loss_remain;
812 int old_radius_sq;
813
814 if (pop_loss == 0) {
815 return TRUE;
816 }
817
818 if (city_size_get(pcity) <= pop_loss) {
819 int id = pcity->id;
820
821 citizens_update(pcity, NULL); /* To avoid warnings during the script */
822 /* Won't refresh a doomed city, or should we? */
823 script_server_signal_emit("city_destroyed", pcity, pcity->owner,
824 destroyer);
825
826 if (city_exist(id)) {
827 remove_city(pcity);
828 }
829 return FALSE;
830 }
831 old_radius_sq = tile_border_source_radius_sq(pcity->tile);
832 city_size_add(pcity, -pop_loss);
833 map_update_border(pcity->tile, pcity->owner, old_radius_sq,
835
836 /* Cap the food stock at the new granary size. */
837 if (pcity->food_stock > city_granary_size(city_size_get(pcity))) {
839 }
840
841 /* First try to kill off the specialists */
842 loss_remain = pop_loss - city_reduce_specialists(pcity, pop_loss);
843
844 if (loss_remain > 0) {
845 /* Take it out on workers */
846#ifndef FREECIV_NDEBUG
847 loss_remain -=
848#endif /* FREECIV_NDEBUG */
849 city_reduce_workers(pcity, loss_remain);
850 }
851
852 /* Update citizens. */
853 citizens_update(pcity, NULL);
854
855 /* Update number of people in each feelings category.
856 * This also updates the city radius if needed. */
857 city_refresh(pcity);
858
860
861 /* Send city data. */
862 sync_cities();
863
864 fc_assert_ret_val_msg(0 == loss_remain, TRUE,
865 "city_reduce_size() has remaining"
866 "%d of %d for \"%s\"[%d]",
867 loss_remain, pop_loss,
868 city_name_get(pcity), city_size_get(pcity));
869
870 /* Update cities that have trade routes with us */
871 trade_partners_iterate(pcity, pcity2) {
872 if (city_refresh(pcity2)) {
873 /* This should never happen, but if it does, make sure not to
874 * leave workers outside city radius. */
875 auto_arrange_workers(pcity2);
876 }
878
879 sanity_check_city(pcity);
880
881 if (reason != NULL) {
882 int id = pcity->id;
883
884 script_server_signal_emit("city_size_change", pcity,
885 (lua_Integer)(-pop_loss), reason);
886
887 return city_exist(id);
888 }
889
890 return TRUE;
891}
892
893/**********************************************************************/
897void city_repair_size(struct city *pcity, int change)
898{
899 if (change > 0) {
900 pcity->specialists[DEFAULT_SPECIALIST] += change;
901 } else if (change < 0) {
902 int need = change + city_reduce_specialists(pcity, -change);
903
904 if (0 > need) {
905#ifndef FREECIV_NDEBUG
906 need +=
907#endif /* FREECIV_NDEBUG */
908 city_reduce_workers(pcity, -need);
909 }
910
911 fc_assert_msg(0 == need,
912 "city_repair_size() has remaining %d of %d for \"%s\"[%d]",
913 need, change, city_name_get(pcity), city_size_get(pcity));
914 }
915}
916
917/**********************************************************************/
924int city_granary_savings(const struct city *pcity)
925{
926 int savings = get_city_bonus(pcity, EFT_GROWTH_FOOD);
927
928 return CLIP(0, savings, 100);
929}
930
931/**********************************************************************/
937static void city_reset_foodbox(struct city *pcity, int new_size)
938{
939 fc_assert_ret(pcity != NULL);
940
941 pcity->food_stock = (city_granary_size(new_size)
942 * city_granary_savings(pcity)) / 100;
943}
944
945/**********************************************************************/
950static bool city_increase_size(struct city *pcity)
951{
952 int new_food;
953 int savings_pct = city_granary_savings(pcity);
954 bool have_square = FALSE;
955 bool rapture_grow = city_rapture_grow(pcity); /* Check before size increase! */
956 struct tile *pcenter = city_tile(pcity);
957 struct player *powner = city_owner(pcity);
958 const struct impr_type *pimprove = pcity->production.value.building;
959 const struct civ_map *nmap = &(wld.map);
960
961 if (!city_can_grow_to(pcity, city_size_get(pcity) + 1)) {
962 /* Need improvement */
963 if (get_current_construction_bonus(pcity, EFT_SIZE_ADJ, RPT_CERTAIN) > 0
964 || get_current_construction_bonus(pcity, EFT_SIZE_UNLIMIT, RPT_CERTAIN) > 0) {
965 notify_player(powner, city_tile(pcity), E_CITY_AQ_BUILDING, ftc_server,
966 _("%s needs %s (being built) to grow beyond size %d."),
967 city_link(pcity),
969 city_size_get(pcity));
970 } else {
971 notify_player(powner, city_tile(pcity), E_CITY_AQUEDUCT, ftc_server,
972 _("%s needs an improvement to grow beyond size %d."),
973 city_link(pcity), city_size_get(pcity));
974 }
975 /* Granary can only hold so much */
976 new_food = (city_granary_size(city_size_get(pcity))
977 * (100 * 100 - game.server.aqueductloss * (100 - savings_pct))
978 / (100 * 100));
979 pcity->food_stock = MIN(pcity->food_stock, new_food);
980
981 return FALSE;
982 }
983
984 city_size_add(pcity, 1);
985
986 /* Do not empty food stock if city is growing by celebrating */
987 if (rapture_grow) {
988 new_food = city_granary_size(city_size_get(pcity));
989 } else {
990 new_food = city_granary_size(city_size_get(pcity)) * savings_pct / 100;
991 }
992 pcity->food_stock = MIN(pcity->food_stock, new_food);
993
994 /* If there is enough food, and the city is big enough,
995 * make new citizens into scientists or taxmen -- Massimo */
996
997 /* Ignore food if no square can be worked */
999 ptile, _index, _x, _y) {
1000 if (tile_worked(ptile) != pcity /* Quick test */
1001 && city_can_work_tile(pcity, ptile)) {
1002 have_square = TRUE;
1003 }
1005
1006 if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1007 && is_city_option_set(pcity, CITYO_SCIENCE_SPECIALISTS)) {
1008 pcity->specialists[best_specialist(O_SCIENCE, pcity)]++;
1009 } else if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
1010 && is_city_option_set(pcity, CITYO_GOLD_SPECIALISTS)) {
1011 pcity->specialists[best_specialist(O_GOLD, pcity)]++;
1012 } else {
1013 pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
1014 }
1015
1016 /* Deprecated signal. Connect your lua functions to "city_size_change" that's
1017 * emitted from calling functions which know the 'reason' of the increase. */
1018 script_server_signal_emit("city_growth", pcity,
1019 (lua_Integer)city_size_get(pcity));
1020
1021 return TRUE;
1022}
1023
1024/**********************************************************************/
1028 struct player *nationality)
1029{
1030 struct player *powner = city_owner(pcity);
1031
1032 /* Update citizens. */
1033 citizens_update(pcity, nationality);
1034
1035 /* Refresh the city data; this also checks the squared city radius. */
1036 city_refresh(pcity);
1037
1038 auto_arrange_workers(pcity);
1039
1040 /* Update cities that have trade routes with us */
1041 trade_partners_iterate(pcity, pcity2) {
1042 if (city_refresh(pcity2)) {
1043 /* This should never happen, but if it does, make sure not to
1044 * leave workers outside city radius. */
1045 auto_arrange_workers(pcity2);
1046 }
1048
1049 notify_player(powner, city_tile(pcity), E_CITY_GROWTH, ftc_server,
1050 _("%s grows to size %d."),
1051 city_link(pcity), city_size_get(pcity));
1052
1053 sanity_check_city(pcity);
1054
1055 sync_cities();
1056}
1057
1058/**********************************************************************/
1062 struct player *nationality, const char *reason)
1063{
1064 int change = size - city_size_get(pcity);
1065
1066 if (change > 0) {
1067 int old_size = city_size_get(pcity);
1068 int real_change;
1069 int current_size = city_size_get(pcity);
1070 int id = pcity->id;
1071
1072 /* Increase city size until size reached, or increase fails */
1073 while (size > current_size && city_increase_size(pcity)) {
1074 /* TODO: This is currently needed only because there's
1075 * deprecated script signal "city_growth" emitted.
1076 * Check the need after signal has been dropped completely. */
1077 if (!city_exist(id)) {
1078 return FALSE;
1079 }
1080
1081 current_size++;
1082 }
1083
1084 city_refresh_after_city_size_increase(pcity, nationality);
1085
1086 real_change = current_size - old_size;
1087
1088 if (real_change != 0 && reason != NULL) {
1089 script_server_signal_emit("city_size_change", pcity,
1090 (lua_Integer)real_change, reason);
1091
1092 if (!city_exist(id)) {
1093 return FALSE;
1094 }
1095 }
1096 } else if (change < 0) {
1097 /* We assume that city_change_size() is never called because
1098 * of enemy actions. If that changes, enemy must be passed
1099 * to city_reduce_size() */
1100 return city_reduce_size(pcity, -change, NULL, reason);
1101 }
1102
1103 map_claim_border(pcity->tile, pcity->owner, -1);
1104
1105 return TRUE;
1106}
1107
1108/**********************************************************************/
1112static void city_populate(struct city *pcity, struct player *nationality)
1113{
1114 int saved_id = pcity->id;
1115 int granary_size = city_granary_size(city_size_get(pcity));
1116
1117 pcity->food_stock += pcity->surplus[O_FOOD];
1118 if (pcity->food_stock >= granary_size || city_rapture_grow(pcity)) {
1119 if (city_had_recent_plague(pcity)) {
1120 notify_player(city_owner(pcity), city_tile(pcity),
1121 E_CITY_PLAGUE, ftc_server,
1122 _("A recent plague outbreak prevents growth in %s."),
1123 city_link(pcity));
1124 /* Lose excess food */
1125 pcity->food_stock = MIN(pcity->food_stock, granary_size);
1126 } else {
1127 bool success;
1128
1129 success = city_increase_size(pcity);
1130 map_claim_border(pcity->tile, pcity->owner, -1);
1131
1132 if (success) {
1133 city_refresh_after_city_size_increase(pcity, nationality);
1134 script_server_signal_emit("city_size_change", pcity,
1135 (lua_Integer)1, "growth");
1136 }
1137 }
1138 } else if (pcity->food_stock < 0) {
1139 /* FIXME: should this depend on units with ability to build
1140 * cities or on units that require food in upkeep?
1141 * I'll assume citybuilders (units that 'contain' 1 pop) -- sjolie
1142 * The above may make more logical sense, but in game terms
1143 * you want to disband a unit that is draining your food
1144 * reserves. Hence, I'll assume food upkeep > 0 units. -- jjm
1145 */
1147 if (punit->upkeep[O_FOOD] > 0) {
1148 const char *punit_link = unit_tile_link(punit);
1149
1150 if (upkeep_kill_unit(punit, O_FOOD, ULR_STARVED,
1152 notify_player(city_owner(pcity), city_tile(pcity),
1153 E_UNIT_LOST_MISC, ftc_server,
1154 _("Famine feared in %s, %s lost!"),
1155 city_link(pcity), punit_link);
1156 }
1157
1158 if (city_exist(saved_id)) {
1159 city_reset_foodbox(pcity, city_size_get(pcity));
1160 }
1161
1162 return;
1163 }
1165 if (city_size_get(pcity) > 1) {
1166 notify_player(city_owner(pcity), city_tile(pcity),
1167 E_CITY_FAMINE, ftc_server,
1168 _("Famine causes population loss in %s."),
1169 city_link(pcity));
1170 } else {
1171 notify_player(city_owner(pcity), city_tile(pcity),
1172 E_CITY_FAMINE, ftc_server,
1173 _("Famine destroys %s entirely."),
1174 city_link(pcity));
1175 }
1176 city_reset_foodbox(pcity, city_size_get(pcity) - 1);
1177 city_reduce_size(pcity, 1, NULL, "famine");
1178 }
1179}
1180
1181/**********************************************************************/
1188 struct city *pcity,
1189 struct player *pplayer,
1190 int saved_id)
1191{
1192 const void *ptarget;
1193 const char *tgt_name;
1194 const struct requirement_vector *build_reqs;
1195 const char *signal_name;
1196 const struct req_context city_ctxt = {
1197 .player = pplayer,
1198 .city = pcity,
1199 .tile = city_tile(pcity)
1200 /* FIXME: Setting .unittype is currently redundant,
1201 * but can_city_build_unit_direct() does it */
1202 };
1203 bool purge = FALSE;
1204 bool known = FALSE;
1205
1206 switch (target->kind) {
1207 case VUT_UTYPE:
1208 ptarget = target->value.utype;
1209 build_reqs = &target->value.utype->build_reqs;
1210 tgt_name = utype_name_translation(ptarget);
1211 signal_name = "unit_cant_be_built";
1212 break;
1213 case VUT_IMPROVEMENT:
1214 ptarget = target->value.building;
1215 build_reqs = &target->value.building->reqs;
1216 tgt_name = city_improvement_name_translation(pcity, ptarget);
1217 signal_name = "building_cant_be_built";
1218 break;
1219 default:
1220 fc_assert_ret_val((target->kind == VUT_IMPROVEMENT
1221 || target->kind == VUT_UTYPE), FALSE);
1222 return FALSE;
1223 break;
1224 }
1225
1226 requirement_vector_iterate(build_reqs, preq) {
1227 if (!is_req_active(&city_ctxt, NULL, preq, RPT_POSSIBLE)) {
1228 known = TRUE;
1229 switch (preq->source.kind) {
1230 case VUT_ADVANCE:
1231 if (preq->present) {
1232 notify_player(pplayer, city_tile(pcity),
1233 E_CITY_CANTBUILD, ftc_server,
1234 _("%s can't build %s from the worklist; "
1235 "tech %s not yet available. Postponing..."),
1236 city_link(pcity),
1237 tgt_name,
1239 (preq->source.value.advance));
1240 script_server_signal_emit(signal_name, ptarget,
1241 pcity, "need_tech");
1242 } else {
1243 /* While techs can be unlearned, this isn't useful feedback */
1244 purge = TRUE;
1245 }
1246 break;
1247 case VUT_TECHFLAG:
1248 if (preq->present) {
1249 notify_player(pplayer, city_tile(pcity),
1250 E_CITY_CANTBUILD, ftc_server,
1251 _("%s can't build %s from the worklist; "
1252 "no tech with flag \"%s\" yet available. "
1253 "Postponing..."),
1254 city_link(pcity),
1255 tgt_name,
1256 tech_flag_id_name(preq->source.value.techflag));
1257 script_server_signal_emit(signal_name, ptarget,
1258 pcity, "need_techflag");
1259 } else {
1260 /* While techs can be unlearned, this isn't useful feedback */
1261 purge = TRUE;
1262 }
1263 break;
1264 case VUT_IMPROVEMENT:
1265 if (preq->range == REQ_RANGE_LOCAL) {
1266 /* Building itself is never going to change */
1267 purge = TRUE;
1268 } else {
1269 if (preq->present) {
1270 notify_player(pplayer, city_tile(pcity),
1271 E_CITY_CANTBUILD, ftc_server,
1272 _("%s can't build %s from the worklist; "
1273 "need to have %s first. Postponing..."),
1274 city_link(pcity),
1275 tgt_name,
1277 preq->source.value.building));
1278 script_server_signal_emit(signal_name, ptarget,
1279 pcity, "need_building");
1280 } else {
1281 notify_player(pplayer, city_tile(pcity),
1282 E_CITY_CANTBUILD, ftc_server,
1283 _("%s can't build %s from the worklist; "
1284 "need to not have %s. Postponing..."),
1285 city_link(pcity),
1286 tgt_name,
1288 preq->source.value.building));
1289 script_server_signal_emit(signal_name, ptarget,
1290 pcity, "have_building");
1291 }
1292 }
1293 break;
1294 case VUT_IMPR_GENUS:
1295 if (preq->range == REQ_RANGE_LOCAL) {
1296 /* Building's own genus is never going to change */
1297 purge = TRUE;
1298 } else {
1299 if (preq->present) {
1300 notify_player(pplayer, city_tile(pcity),
1301 E_CITY_CANTBUILD, ftc_server,
1302 _("%s can't build %s from the worklist; "
1303 "need to have %s first. Postponing..."),
1304 city_link(pcity),
1305 tgt_name,
1306 impr_genus_id_translated_name(
1307 preq->source.value.impr_genus));
1308 script_server_signal_emit(signal_name, ptarget,
1309 pcity, "need_building_genus");
1310 } else {
1311 notify_player(pplayer, city_tile(pcity),
1312 E_CITY_CANTBUILD, ftc_server,
1313 _("%s can't build %s from the worklist; "
1314 "need to not have %s. Postponing..."),
1315 city_link(pcity),
1316 tgt_name,
1317 impr_genus_id_translated_name(
1318 preq->source.value.impr_genus));
1319 script_server_signal_emit(signal_name, ptarget,
1320 pcity, "have_building_genus");
1321 }
1322 }
1323 break;
1324 case VUT_GOVERNMENT:
1325 if (preq->present) {
1326 notify_player(pplayer, city_tile(pcity),
1327 E_CITY_CANTBUILD, ftc_server,
1328 _("%s can't build %s from the worklist; "
1329 "it needs %s government. Postponing..."),
1330 city_link(pcity),
1331 tgt_name,
1332 government_name_translation(preq->source.value.govern));
1333 script_server_signal_emit(signal_name, ptarget,
1334 pcity, "need_government");
1335 } else {
1336 notify_player(pplayer, city_tile(pcity),
1337 E_CITY_CANTBUILD, ftc_server,
1338 _("%s can't build %s from the worklist; "
1339 "it cannot have %s government. Postponing..."),
1340 city_link(pcity),
1341 tgt_name,
1342 government_name_translation(preq->source.value.govern));
1343 script_server_signal_emit(signal_name, ptarget,
1344 pcity, "have_government");
1345 }
1346 break;
1347 case VUT_ACHIEVEMENT:
1348 if (preq->present) {
1349 notify_player(pplayer, city_tile(pcity),
1350 E_CITY_CANTBUILD, ftc_server,
1351 _("%s can't build %s from the worklist; "
1352 "it needs \"%s\" achievement. Postponing..."),
1353 city_link(pcity),
1354 tgt_name,
1355 achievement_name_translation(preq->source.value.achievement));
1356 script_server_signal_emit(signal_name, ptarget,
1357 pcity, "need_achievement");
1358 } else {
1359 /* Can't unachieve things. */
1360 purge = TRUE;
1361 }
1362 break;
1363 case VUT_EXTRA:
1364 if (preq->present) {
1365 notify_player(pplayer, city_tile(pcity),
1366 E_CITY_CANTBUILD, ftc_server,
1367 Q_("?extra:%s can't build %s from the worklist; "
1368 "%s is required. Postponing..."),
1369 city_link(pcity),
1370 tgt_name,
1371 extra_name_translation(preq->source.value.extra));
1372 script_server_signal_emit(signal_name, ptarget,
1373 pcity, "need_extra");
1374 } else {
1375 notify_player(pplayer, city_tile(pcity),
1376 E_CITY_CANTBUILD, ftc_server,
1377 Q_("?extra:%s can't build %s from the worklist; "
1378 "%s is prohibited. Postponing..."),
1379 city_link(pcity),
1380 tgt_name,
1381 extra_name_translation(preq->source.value.extra));
1382 script_server_signal_emit(signal_name, ptarget,
1383 pcity, "have_extra");
1384 }
1385 break;
1386 case VUT_GOOD:
1387 if (preq->present) {
1388 notify_player(pplayer, city_tile(pcity),
1389 E_CITY_CANTBUILD, ftc_server,
1390 Q_("?extra:%s can't build %s from the worklist; "
1391 "%s is required. Postponing..."),
1392 city_link(pcity),
1393 tgt_name,
1394 goods_name_translation(preq->source.value.good));
1395 script_server_signal_emit(signal_name, ptarget,
1396 pcity, "need_good");
1397 } else {
1398 notify_player(pplayer, city_tile(pcity),
1399 E_CITY_CANTBUILD, ftc_server,
1400 Q_("?extra:%s can't build %s from the worklist; "
1401 "%s is prohibited. Postponing..."),
1402 city_link(pcity),
1403 tgt_name,
1404 goods_name_translation(preq->source.value.good));
1405 script_server_signal_emit(signal_name, ptarget,
1406 pcity, "have_good");
1407 }
1408 break;
1409 case VUT_TERRAIN:
1410 if (preq->present) {
1411 notify_player(pplayer, city_tile(pcity),
1412 E_CITY_CANTBUILD, ftc_server,
1413 Q_("?terrain:%s can't build %s from the worklist; "
1414 "%s terrain is required. Postponing..."),
1415 city_link(pcity),
1416 tgt_name,
1417 terrain_name_translation(preq->source.value.terrain));
1418 script_server_signal_emit(signal_name, ptarget,
1419 pcity, "need_terrain");
1420 } else {
1421 notify_player(pplayer, city_tile(pcity),
1422 E_CITY_CANTBUILD, ftc_server,
1423 Q_("?terrain:%s can't build %s from the worklist; "
1424 "%s terrain is prohibited. Postponing..."),
1425 city_link(pcity),
1426 tgt_name,
1427 terrain_name_translation(preq->source.value.terrain));
1428 script_server_signal_emit(signal_name, ptarget,
1429 pcity, "have_terrain");
1430 }
1431 break;
1432 case VUT_NATION:
1433 if (preq->range < REQ_RANGE_TRADE_ROUTE
1434 || preq->range == REQ_RANGE_PLAYER) {
1435 /* At higher ranges, new players with their nations may arrive */
1436 purge = TRUE;
1437 } else {
1438 if (preq->present) {
1439 notify_player(pplayer, city_tile(pcity),
1440 E_CITY_CANTBUILD, ftc_server,
1441 /* TRANS: "%s nation" is adjective */
1442 Q_("?nation:%s can't build %s from the worklist; "
1443 "%s nation is required. Postponing..."),
1444 city_link(pcity),
1445 tgt_name,
1446 nation_adjective_translation(preq->source.value.nation));
1447 script_server_signal_emit(signal_name, ptarget,
1448 pcity, "need_nation");
1449 } else {
1450 notify_player(pplayer, city_tile(pcity),
1451 E_CITY_CANTBUILD, ftc_server,
1452 Q_("?nation:%s can't build %s from the worklist; "
1453 "%s nation is prohibited. Postponing..."),
1454 city_link(pcity),
1455 tgt_name,
1456 nation_adjective_translation(preq->source.value.nation));
1457 script_server_signal_emit(signal_name, ptarget,
1458 pcity, "have_nation");
1459 }
1460 }
1461 break;
1462 case VUT_NATIONGROUP:
1463 if (preq->range < REQ_RANGE_TRADE_ROUTE
1464 || preq->range == REQ_RANGE_PLAYER) {
1465 /* At higher ranges, new players with their nations may arrive */
1466 purge = TRUE;
1467 } else {
1468 if (preq->present) {
1469 notify_player(pplayer, city_tile(pcity),
1470 E_CITY_CANTBUILD, ftc_server,
1471 /* TRANS: "%s nation" is adjective */
1472 Q_("?ngroup:%s can't build %s from the worklist; "
1473 "%s nation is required. Postponing..."),
1474 city_link(pcity),
1475 tgt_name,
1476 nation_group_name_translation(preq->source.value.nationgroup));
1477 script_server_signal_emit(signal_name, ptarget,
1478 pcity, "need_nationgroup");
1479 } else {
1480 notify_player(pplayer, city_tile(pcity),
1481 E_CITY_CANTBUILD, ftc_server,
1482 Q_("?ngroup:%s can't build %s from the worklist; "
1483 "%s nation is prohibited. Postponing..."),
1484 city_link(pcity),
1485 tgt_name,
1486 nation_group_name_translation(preq->source.value.nationgroup));
1487 script_server_signal_emit(signal_name, ptarget,
1488 pcity, "have_nationgroup");
1489 }
1490 }
1491 break;
1492 case VUT_STYLE:
1493 /* FIXME: City styles sometimes change over time, but it isn't
1494 * entirely under player control. Probably better to purge
1495 * with useful explanation. */
1496 if (preq->present) {
1497 notify_player(pplayer, city_tile(pcity),
1498 E_CITY_CANTBUILD, ftc_server,
1499 _("%s can't build %s from the worklist; "
1500 "only %s style cities may build this. Postponing..."),
1501 city_link(pcity),
1502 tgt_name,
1503 style_name_translation(preq->source.value.style));
1504 script_server_signal_emit(signal_name, ptarget,
1505 pcity, "need_style");
1506 } else {
1507 notify_player(pplayer, city_tile(pcity),
1508 E_CITY_CANTBUILD, ftc_server,
1509 _("%s can't build %s from the worklist; "
1510 "%s style cities may not build this. Postponing..."),
1511 city_link(pcity),
1512 tgt_name,
1513 style_name_translation(preq->source.value.style));
1514 script_server_signal_emit(signal_name, ptarget,
1515 pcity, "have_style");
1516 }
1517 break;
1518 case VUT_NATIONALITY:
1519 /* FIXME: Changing citizen nationality is hard: purging might be
1520 * more useful in this case. */
1521 if (preq->present) {
1522 notify_player(pplayer, city_tile(pcity),
1523 E_CITY_CANTBUILD, ftc_server,
1524 /* TRANS: Latter %s is citizen nationality */
1525 _("%s can't build %s from the worklist; "
1526 "only city with %s may build this. Postponing..."),
1527 city_link(pcity),
1528 tgt_name,
1529 nation_plural_translation(preq->source.value.nationality));
1530 script_server_signal_emit(signal_name, ptarget,
1531 pcity, "need_nationality");
1532 } else {
1533 notify_player(pplayer, city_tile(pcity),
1534 E_CITY_CANTBUILD, ftc_server,
1535 /* TRANS: Latter %s is citizen nationality */
1536 _("%s can't build %s from the worklist; "
1537 "only city without %s may build this. Postponing..."),
1538 city_link(pcity),
1539 tgt_name,
1540 nation_plural_translation(preq->source.value.nationality));
1541 script_server_signal_emit(signal_name, ptarget,
1542 pcity, "have_nationality");
1543 }
1544 break;
1545 case VUT_DIPLREL:
1546 case VUT_DIPLREL_TILE: /* The tile owner is the city owner */
1547 case VUT_DIPLREL_TILE_O: /* The tile owner is the city owner */
1548 if (preq->present) {
1549 const char *reason;
1550
1551 notify_player(pplayer, city_tile(pcity),
1552 E_CITY_CANTBUILD, ftc_server,
1553 /* TRANS: '%s' is a wide range of relationships;
1554 * e.g., 'Peace', 'Never met', 'Foreign',
1555 * 'Hosts embassy', 'Provided Casus Belli' */
1556 _("%s can't build %s from the worklist; "
1557 "the relationship '%s' is required."
1558 " Postponing..."),
1559 city_link(pcity),
1560 tgt_name,
1562 preq->source.value.diplrel));
1563
1564 if (preq->source.kind == VUT_DIPLREL_TILE) {
1565 reason = "need_diplrel_tile";
1566 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1567 reason = "need_diplrel_tile_o";
1568 } else {
1569 fc_assert(preq->source.kind == VUT_DIPLREL);
1570 reason = "need_diplrel";
1571 }
1572
1573 script_server_signal_emit(signal_name, ptarget,
1574 pcity, reason);
1575 } else {
1576 const char *reason;
1577
1578 notify_player(pplayer, city_tile(pcity),
1579 E_CITY_CANTBUILD, ftc_server,
1580 _("%s can't build %s from the worklist; "
1581 "the relationship '%s' is prohibited."
1582 " Postponing..."),
1583 city_link(pcity),
1584 tgt_name,
1586 preq->source.value.diplrel));
1587
1588 if (preq->source.kind == VUT_DIPLREL_TILE) {
1589 reason = "have_diplrel_tile";
1590 } else if (preq->source.kind == VUT_DIPLREL_TILE_O) {
1591 reason = "have_diplrel_tile_o";
1592 } else {
1593 fc_assert(preq->source.kind == VUT_DIPLREL);
1594 reason = "have_diplrel";
1595 }
1596
1597 script_server_signal_emit(signal_name, ptarget,
1598 pcity, reason);
1599 }
1600 break;
1601 case VUT_DIPLREL_UNITANY:
1602 case VUT_DIPLREL_UNITANY_O:
1603 if (preq->present) {
1604 const char *reason;
1605
1606 notify_player(pplayer, city_tile(pcity),
1607 E_CITY_CANTBUILD, ftc_server,
1608 /* TRANS: '%s' is a wide range of relationships;
1609 * e.g., 'Peace', 'Never met', 'Foreign',
1610 * 'Hosts embassy', 'Provided Casus Belli' */
1611 _("%s can't build %s from the worklist; "
1612 "unit with the relationship '%s' is required."
1613 " Postponing..."),
1614 city_link(pcity),
1615 tgt_name,
1617 preq->source.value.diplrel));
1618
1619 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1620 reason = "need_diplrel_unitany";
1621 } else {
1622 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1623 reason = "need_diplrel_unitany_o";
1624 }
1625
1626 script_server_signal_emit(signal_name, ptarget,
1627 pcity, reason);
1628 } else {
1629 const char *reason;
1630
1631 notify_player(pplayer, city_tile(pcity),
1632 E_CITY_CANTBUILD, ftc_server,
1633 _("%s can't build %s from the worklist; "
1634 "unit with the relationship '%s' is prohibited."
1635 " Postponing..."),
1636 city_link(pcity),
1637 tgt_name,
1639 preq->source.value.diplrel));
1640
1641 if (preq->source.kind == VUT_DIPLREL_UNITANY) {
1642 reason = "have_diplrel_unitany";
1643 } else {
1644 fc_assert(preq->source.kind == VUT_DIPLREL_UNITANY_O);
1645 reason = "have_diplrel_unitany_o";
1646 }
1647
1648 script_server_signal_emit(signal_name, ptarget,
1649 pcity, reason);
1650 }
1651 break;
1652 case VUT_MINSIZE:
1653 if (preq->present) {
1654 notify_player(pplayer, city_tile(pcity),
1655 E_CITY_CANTBUILD, ftc_server,
1656 _("%s can't build %s from the worklist; "
1657 "city must be of size %d or larger. "
1658 "Postponing..."),
1659 city_link(pcity),
1660 tgt_name,
1661 preq->source.value.minsize);
1662 script_server_signal_emit(signal_name, ptarget,
1663 pcity, "need_minsize");
1664 } else {
1665 notify_player(pplayer, city_tile(pcity),
1666 E_CITY_CANTBUILD, ftc_server,
1667 _("%s can't build %s from the worklist; "
1668 "city must be of size %d or smaller."
1669 "Postponing..."),
1670 city_link(pcity),
1671 tgt_name,
1672 (preq->source.value.minsize - 1));
1673 script_server_signal_emit(signal_name, ptarget,
1674 pcity, "need_minsize");
1675 }
1676 break;
1677 case VUT_MINCULTURE:
1678 if (preq->present) {
1679 notify_player(pplayer, city_tile(pcity),
1680 E_CITY_CANTBUILD, ftc_server,
1681 _("%s can't build %s from the worklist; "
1682 "city must have culture of %d. Postponing..."),
1683 city_link(pcity),
1684 tgt_name,
1685 preq->source.value.minculture);
1686 script_server_signal_emit(signal_name, ptarget,
1687 pcity, "need_minculture");
1688 } else {
1689 /* What has been written may not be unwritten. */
1690 purge = TRUE;
1691 }
1692 break;
1693 case VUT_MINFOREIGNPCT:
1694 if (preq->present) {
1695 notify_player(pplayer, city_tile(pcity),
1696 E_CITY_CANTBUILD, ftc_server,
1697 _("%s can't build %s from the worklist; "
1698 "city must have %d%% foreign population. Postponing..."),
1699 city_link(pcity),
1700 tgt_name,
1701 preq->source.value.minforeignpct);
1702 script_server_signal_emit(signal_name, ptarget,
1703 pcity, "need_minforeignpct");
1704 } else {
1705 notify_player(pplayer, city_tile(pcity),
1706 E_CITY_CANTBUILD, ftc_server,
1707 _("%s can't build %s from the worklist; "
1708 "city must have %d%% native population. Postponing..."),
1709 city_link(pcity),
1710 tgt_name,
1711 100 - preq->source.value.minforeignpct);
1712 script_server_signal_emit(signal_name, ptarget,
1713 pcity, "need_minforeignpct");
1714 }
1715 break;
1716 case VUT_MINTECHS:
1717 if (preq->present) {
1718 notify_player(pplayer, city_tile(pcity),
1719 E_CITY_CANTBUILD, ftc_server,
1720 _("%s can't build %s from the worklist; "
1721 "%d techs must be known. Postponing..."),
1722 city_link(pcity),
1723 tgt_name,
1724 preq->source.value.min_techs);
1725 script_server_signal_emit(signal_name, ptarget,
1726 pcity, "need_mintechs");
1727 } else {
1728 purge = TRUE;
1729 }
1730 break;
1731 case VUT_MAXTILEUNITS:
1732 if (preq->present) {
1733 notify_player(pplayer, city_tile(pcity),
1734 E_CITY_CANTBUILD, ftc_server,
1735 PL_("%s can't build %s from the worklist; "
1736 "more than %d unit on tile."
1737 " Postponing...",
1738 "%s can't build %s from the worklist; "
1739 "more than %d units on tile."
1740 " Postponing...",
1741 preq->source.value.max_tile_units),
1742 city_link(pcity),
1743 tgt_name,
1744 preq->source.value.max_tile_units);
1745 script_server_signal_emit(signal_name, ptarget,
1746 pcity, "need_tileunits");
1747 } else {
1748 notify_player(pplayer, city_tile(pcity),
1749 E_CITY_CANTBUILD, ftc_server,
1750 PL_("%s can't build %s from the worklist; "
1751 "fewer than %d unit on tile."
1752 " Postponing...",
1753 "%s can't build %s from the worklist; "
1754 "fewer than %d units on tile."
1755 " Postponing...",
1756 preq->source.value.max_tile_units + 1),
1757 city_link(pcity),
1758 tgt_name,
1759 preq->source.value.max_tile_units + 1);
1760 script_server_signal_emit(signal_name, ptarget,
1761 pcity, "need_tileunits");
1762 }
1763 break;
1764 case VUT_AI_LEVEL:
1765 /* Can't change AI level. */
1766 purge = TRUE;
1767 break;
1768 case VUT_TERRAINCLASS:
1769 /* Change of terrain class is expected to be very unlikely. Purge!
1770 * TODO: Analyze ruleset to see how unlikely terrain class change actually is. */
1771 purge = TRUE;
1772 break;
1773 case VUT_TERRFLAG:
1774 if (preq->present) {
1775 notify_player(pplayer, city_tile(pcity),
1776 E_CITY_CANTBUILD, ftc_server,
1777 _("%s can't build %s from the worklist; "
1778 "terrain with \"%s\" flag is required. "
1779 "Postponing..."),
1780 city_link(pcity),
1781 tgt_name,
1782 terrain_flag_id_name(preq->source.value.terrainflag));
1783 script_server_signal_emit(signal_name, ptarget,
1784 pcity, "need_terrainflag");
1785 } else {
1786 notify_player(pplayer, city_tile(pcity),
1787 E_CITY_CANTBUILD, ftc_server,
1788 _("%s can't build %s from the worklist; "
1789 "terrain with \"%s\" flag is prohibited. "
1790 "Postponing..."),
1791 city_link(pcity),
1792 tgt_name,
1793 terrain_flag_id_name(preq->source.value.terrainflag));
1794 script_server_signal_emit(signal_name, ptarget,
1795 pcity, "have_terrainflag");
1796 }
1797 break;
1798 case VUT_ROADFLAG:
1799 if (preq->present) {
1800 notify_player(pplayer, city_tile(pcity),
1801 E_CITY_CANTBUILD, ftc_server,
1802 _("%s can't build %s from the worklist; "
1803 "road with \"%s\" flag is required. "
1804 "Postponing..."),
1805 city_link(pcity),
1806 tgt_name,
1807 road_flag_id_name(preq->source.value.roadflag));
1808 script_server_signal_emit(signal_name, ptarget,
1809 pcity, "need_roadflag");
1810 } else {
1811 notify_player(pplayer, city_tile(pcity),
1812 E_CITY_CANTBUILD, ftc_server,
1813 _("%s can't build %s from the worklist; "
1814 "road with \"%s\" flag is prohibited. "
1815 "Postponing..."),
1816 city_link(pcity),
1817 tgt_name,
1818 road_flag_id_name(preq->source.value.roadflag));
1819 script_server_signal_emit(signal_name, ptarget,
1820 pcity, "have_roadflag");
1821 }
1822 break;
1823 case VUT_EXTRAFLAG:
1824 if (preq->present) {
1825 notify_player(pplayer, city_tile(pcity),
1826 E_CITY_CANTBUILD, ftc_server,
1827 _("%s can't build %s from the worklist; "
1828 "extra with \"%s\" flag is required. "
1829 "Postponing..."),
1830 city_link(pcity),
1831 tgt_name,
1832 extra_flag_id_translated_name(preq->source.value.extraflag));
1833 script_server_signal_emit(signal_name, ptarget,
1834 pcity, "need_extraflag");
1835 } else {
1836 notify_player(pplayer, city_tile(pcity),
1837 E_CITY_CANTBUILD, ftc_server,
1838 _("%s can't build %s from the worklist; "
1839 "extra with \"%s\" flag is prohibited. "
1840 "Postponing..."),
1841 city_link(pcity),
1842 tgt_name,
1843 extra_flag_id_translated_name(preq->source.value.extraflag));
1844 script_server_signal_emit(signal_name, ptarget,
1845 pcity, "have_extraflag");
1846 }
1847 break;
1848 case VUT_UTYPE:
1849 case VUT_UTFLAG:
1850 case VUT_UCLASS:
1851 case VUT_UCFLAG:
1852 case VUT_MINVETERAN:
1853 case VUT_UNITSTATE:
1854 case VUT_ACTIVITY:
1855 case VUT_MINMOVES:
1856 case VUT_MINHP:
1857 case VUT_ACTION:
1858 case VUT_OTYPE:
1859 case VUT_SPECIALIST:
1860 case VUT_TERRAINALTER: /* XXX could do this in principle */
1861 case VUT_CITYTILE:
1862 /* Will only happen with a bogus ruleset. */
1863 log_error("worklist_change_build_target() has bogus preq");
1864 break;
1865 case VUT_CITYSTATUS:
1866 if (preq->source.value.citystatus == CITYS_OWNED_BY_ORIGINAL) {
1867 if (preq->range == REQ_RANGE_CITY) {
1868 /* Can't change at this range */
1869 purge = TRUE;
1870 } else {
1871 if (preq->present) {
1872 notify_player(pplayer, city_tile(pcity),
1873 E_CITY_CANTBUILD, ftc_server,
1874 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
1875 _("%s can't build %s from the worklist; "
1876 "only available when city in range %s \"%s\". "
1877 "Postponing..."),
1878 city_link(pcity),
1879 tgt_name, req_range_name(preq->range),
1880 citystatus_type_name(preq->source.value.citystatus));
1881 script_server_signal_emit(signal_name, ptarget,
1882 pcity, "need_citystatus");
1883 } else {
1884 notify_player(pplayer, city_tile(pcity),
1885 E_CITY_CANTBUILD, ftc_server,
1886 /* TRANS: last %s is a CityStatus ("OwnedByOriginal") */
1887 _("%s can't build %s from the worklist; "
1888 "not available when city in range %s is \"%s\". "
1889 "Postponing..."),
1890 city_link(pcity),
1891 tgt_name, req_range_name(preq->range),
1892 citystatus_type_name(preq->source.value.citystatus));
1893 script_server_signal_emit(signal_name, ptarget,
1894 pcity, "have_citystatus");
1895 }
1896 }
1897 } else {
1898 /* Other status types will only happen with a bogus ruleset. */
1899 log_error("worklist_change_build_target() has bogus citystatus preq");
1900 }
1901 break;
1902 case VUT_MINYEAR:
1903 if (preq->present) {
1904 notify_player(pplayer, city_tile(pcity),
1905 E_CITY_CANTBUILD, ftc_server,
1906 /* TRANS: last %s is a date */
1907 _("%s can't build %s from the worklist; "
1908 "only available from %s. Postponing..."),
1909 city_link(pcity),
1910 tgt_name,
1911 textyear(preq->source.value.minyear));
1912 script_server_signal_emit(signal_name, ptarget,
1913 pcity, "need_minyear");
1914 } else {
1915 /* Can't go back in time. */
1916 purge = TRUE;
1917 }
1918 break;
1919 case VUT_MINCALFRAG:
1920 /* Unlike VUT_MINYEAR, a requirement in either direction is
1921 * likely to be fulfilled sooner or later. */
1922 if (preq->present) {
1923 notify_player(pplayer, city_tile(pcity),
1924 E_CITY_CANTBUILD, ftc_server,
1925 /* TRANS: last %s is a calendar fragment from
1926 * the ruleset; may be a bare number */
1927 _("%s can't build %s from the worklist; "
1928 "only available from %s. Postponing..."),
1929 city_link(pcity),
1930 tgt_name,
1931 textcalfrag(preq->source.value.mincalfrag));
1932 script_server_signal_emit(signal_name, ptarget,
1933 pcity, "need_mincalfrag");
1934 } else {
1935 fc_assert_action(preq->source.value.mincalfrag > 0, break);
1936 notify_player(pplayer, city_tile(pcity),
1937 E_CITY_CANTBUILD, ftc_server,
1938 /* TRANS: last %s is a calendar fragment from
1939 * the ruleset; may be a bare number */
1940 _("%s can't build %s from the worklist; "
1941 "not available after %s. Postponing..."),
1942 city_link(pcity),
1943 tgt_name,
1944 textcalfrag(preq->source.value.mincalfrag - 1));
1945 script_server_signal_emit(signal_name, ptarget,
1946 pcity, "have_mincalfrag");
1947 }
1948 break;
1949 case VUT_TOPO:
1950 if (preq->present) {
1951 notify_player(pplayer, city_tile(pcity),
1952 E_CITY_CANTBUILD, ftc_server,
1953 /* TRANS: third %s is topology flag name
1954 * ("WrapX", "ISO", etc) */
1955 _("%s can't build %s from the worklist; "
1956 "only available in worlds with %s map."),
1957 city_link(pcity),
1958 tgt_name,
1959 _(topo_flag_name(preq->source.value.topo_property)));
1960 script_server_signal_emit(signal_name, ptarget,
1961 pcity, "need_topo");
1962 }
1963 purge = TRUE;
1964 break;
1965 case VUT_SERVERSETTING:
1966 notify_player(pplayer, city_tile(pcity),
1967 E_CITY_CANTBUILD, ftc_server,
1968 /* TRANS: %s is a server setting, its value and
1969 * if it is required to be present or absent.
1970 * The string's format is specified in
1971 * ssetv_human_readable().
1972 * Example: "killstack is enabled". */
1973 _("%s can't build %s from the worklist; "
1974 "only available when the server setting "
1975 "%s."),
1976 city_link(pcity),
1977 tgt_name,
1978 ssetv_human_readable(preq->source.value.ssetval,
1979 preq->present));
1980 script_server_signal_emit(signal_name, ptarget,
1981 pcity, "need_setting");
1982 /* Don't assume that the server setting will be changed. */
1983 purge = TRUE;
1984 break;
1985 case VUT_AGE:
1986 if (preq->present) {
1987 notify_player(pplayer, city_tile(pcity),
1988 E_CITY_CANTBUILD, ftc_server,
1989 _("%s can't build %s from the worklist; "
1990 "only available once %d turns old. Postponing..."),
1991 city_link(pcity),
1992 tgt_name,
1993 preq->source.value.age);
1994 script_server_signal_emit(signal_name, ptarget,
1995 pcity, "need_age");
1996 } else {
1997 /* Can't go back in time. */
1998 purge = TRUE;
1999 }
2000 break;
2001 case VUT_NONE:
2002 case VUT_COUNT:
2004 "worklist_change_build_target() "
2005 "called with invalid preq");
2006 break;
2007 /* No default handling here, as we want compiler warning
2008 * if new requirement type is added to enum and it's not handled
2009 * here. */
2010 };
2011 break;
2012 }
2013
2014 /* Almost all cases emit signal in the end, so city check needed. */
2015 if (!city_exist(saved_id)) {
2016 /* Some script has removed city */
2017 return TRUE;
2018 }
2019
2021
2022 if (!known) {
2023 /* FIXME: make can_city_build_improvement_now() return a reason enum,
2024 * so we can notify user with it.
2025 * Likely the building already exist. */
2026 purge = TRUE;
2027 }
2028
2029 return purge;
2030}
2031
2032/**********************************************************************/
2038static bool worklist_change_build_target(struct player *pplayer,
2039 struct city *pcity)
2040{
2041 struct universal target;
2042 bool success = FALSE;
2043 int i;
2044 int saved_id = pcity->id;
2045 bool city_checked = TRUE; /* This is used to avoid spurious city_exist() calls */
2046 struct worklist *pwl = &pcity->worklist;
2047 const struct civ_map *nmap = &(wld.map);
2048
2049 if (worklist_is_empty(pwl)) {
2050 /* Nothing in the worklist; bail now. */
2051 return FALSE;
2052 }
2053
2054 i = 0;
2055 while (!success && i < worklist_length(pwl)) {
2056
2057 if (!city_checked) {
2058 if (!city_exist(saved_id)) {
2059 /* Some script has removed useless city that cannot build
2060 * what it is told to! */
2061 return FALSE;
2062 }
2063 city_checked = TRUE;
2064 }
2065
2066 if (worklist_peek_ith(pwl, &target, i)) {
2067 success = can_city_build_now(nmap, pcity, &target);
2068 } else {
2069 success = FALSE;
2070 }
2071 i++;
2072
2073 if (success) {
2074 break; /* while */
2075 }
2076
2077 switch (target.kind) {
2078 case VUT_UTYPE:
2079 {
2080 const struct unit_type *ptarget = target.value.utype;
2081 const struct unit_type *pupdate = unit_upgrades_to(pcity, ptarget);
2082 bool purge;
2083
2084 /* Maybe we can just upgrade the target to what the city /can/ build. */
2085 if (U_NOT_OBSOLETED == pupdate) {
2086 purge = FALSE;
2087
2088 /* Nope, we're stuck. Skip this item from the worklist. */
2089 if (ptarget->require_advance != NULL
2090 && TECH_KNOWN != research_invention_state
2091 (research_get(pplayer),
2092 advance_number(ptarget->require_advance))) {
2093 notify_player(pplayer, city_tile(pcity),
2094 E_CITY_CANTBUILD, ftc_server,
2095 _("%s can't build %s from the worklist; "
2096 "tech %s not yet available. Postponing..."),
2097 city_link(pcity), utype_name_translation(ptarget),
2099 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2100 "need_tech");
2101 } else {
2102 /* Unknown or requirement from vector. */
2103 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2104 saved_id);
2105 }
2106 city_checked = FALSE;
2107 if (!purge) {
2108 break;
2109 }
2110 } else {
2111 purge = !can_city_build_unit_later(nmap, pcity, pupdate);
2112 }
2113 if (purge) {
2114 /* If the city can never build this unit or its descendants,
2115 * drop it. */
2116 notify_player(pplayer, city_tile(pcity),
2117 E_CITY_CANTBUILD, ftc_server,
2118 _("%s can't build %s from the worklist. Purging..."),
2119 city_link(pcity),
2120 /* Yes, warn about the targets that's actually
2121 in the worklist, not its obsolete-closure
2122 pupdate. */
2123 utype_name_translation(ptarget));
2124 script_server_signal_emit("unit_cant_be_built", ptarget, pcity,
2125 "never");
2126 if (city_exist(saved_id)) {
2127 city_checked = TRUE;
2128 /* Purge this worklist item. */
2129 i--;
2130 worklist_remove(pwl, i);
2131 } else {
2132 city_checked = FALSE;
2133 }
2134 } else {
2135 /* Yep, we can go after pupdate instead. Joy! */
2136 notify_player(pplayer, city_tile(pcity), E_WORKLIST, ftc_server,
2137 _("Production of %s is upgraded to %s in %s."),
2138 utype_name_translation(ptarget),
2139 utype_name_translation(pupdate),
2140 city_link(pcity));
2141 target.value.utype = pupdate;
2142 }
2143 break;
2144 }
2145 case VUT_IMPROVEMENT:
2146 {
2147 const struct impr_type *ptarget = target.value.building;
2148 const struct impr_type *pupdate = building_upgrades_to(pcity, ptarget);
2149 bool purge;
2150
2151 /* If the city can never build this improvement, drop it. */
2152 success = can_city_build_improvement_later(pcity, pupdate);
2153 purge = !success;
2154
2155 /* Maybe this improvement has been obsoleted by something that
2156 we can build. */
2157 if (purge) {
2158 /* Nope, no use. *sigh* */
2159
2160 /* Can it be postponed? */
2161 if (can_city_build_improvement_later(pcity, ptarget)) {
2162 purge = worklist_item_postpone_req_vec(&target, pcity, pplayer,
2163 saved_id);
2164
2165 /* Almost all cases emit signal in the end, so city check needed. */
2166 if (!city_exist(saved_id)) {
2167 /* Some script has removed city */
2168 return FALSE;
2169 }
2170 city_checked = TRUE;
2171 }
2172 } else if (success) {
2173 /* Hey, we can upgrade the improvement! */
2174 notify_player(pplayer, city_tile(pcity), E_WORKLIST, ftc_server,
2175 _("Production of %s is upgraded to %s in %s."),
2176 city_improvement_name_translation(pcity, ptarget),
2177 city_improvement_name_translation(pcity, pupdate),
2178 city_link(pcity));
2179 target.value.building = pupdate;
2180 }
2181
2182 if (purge) {
2183 /* Never in a million years. */
2184 notify_player(pplayer, city_tile(pcity),
2185 E_CITY_CANTBUILD, ftc_server,
2186 _("%s can't build %s from the worklist. Purging..."),
2187 city_link(pcity),
2188 city_improvement_name_translation(pcity, ptarget));
2189 script_server_signal_emit("building_cant_be_built", ptarget, pcity,
2190 "never");
2191 if (city_exist(saved_id)) {
2192 city_checked = TRUE;
2193 /* Purge this worklist item. */
2194 i--;
2195 worklist_remove(pwl, i);
2196 } else {
2197 city_checked = FALSE;
2198 }
2199 }
2200 break;
2201 }
2202 default:
2203 /* skip useless target */
2204 log_error("worklist_change_build_target() has unrecognized "
2205 "target kind (%d)", target.kind);
2206 break;
2207 };
2208 } /* while */
2209
2210 if (success) {
2211 /* All okay. Switch targets. */
2212 change_build_target(pplayer, pcity, &target, E_WORKLIST);
2213
2214 /* i is the index immediately _after_ the item we're changing to.
2215 Remove the (i-1)th item from the worklist. */
2216 worklist_remove(pwl, i - 1);
2217 }
2218
2219 if (worklist_is_empty(pwl)) {
2220 /* There *was* something in the worklist, but it's empty now. Bug the
2221 player about it. */
2222 notify_player(pplayer, city_tile(pcity), E_WORKLIST, ftc_server,
2223 /* TRANS: The <city> worklist .... */
2224 _("The %s worklist is now empty."),
2225 city_link(pcity));
2226 }
2227
2228 return success;
2229}
2230
2231/**********************************************************************/
2236void choose_build_target(struct player *pplayer, struct city *pcity)
2237{
2238 const struct civ_map *nmap = &(wld.map);
2239
2240 /* Pick the next thing off the worklist. */
2241 if (worklist_change_build_target(pplayer, pcity)) {
2242 return;
2243 }
2244
2245 /* Try building the same thing again. Repeat building doesn't require a
2246 * call to change_build_target, so just return. */
2247 switch (pcity->production.kind) {
2248 case VUT_UTYPE:
2249 /* We can build a unit again unless it's unique or we have lost the tech. */
2250 if (!utype_has_flag(pcity->production.value.utype, UTYF_UNIQUE)
2251 && can_city_build_unit_now(nmap, pcity, pcity->production.value.utype)) {
2252 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2254 return;
2255 }
2256 break;
2257 case VUT_IMPROVEMENT:
2259 /* We can build space and coinage again, and possibly others. */
2260 log_base(LOG_BUILD_TARGET, "%s repeats building %s", city_name_get(pcity),
2262 return;
2263 }
2264 break;
2265 default:
2266 /* fallthru */
2267 break;
2268 };
2269
2270 /* Find *something* to do! */
2271 log_debug("Trying advisor_choose_build.");
2272 advisor_choose_build(pplayer, pcity);
2273 log_debug("Advisor_choose_build didn't kill us.");
2274}
2275
2276/**********************************************************************/
2281static const struct impr_type *building_upgrades_to(struct city *pcity,
2282 const struct impr_type *pimprove)
2283{
2284 const struct impr_type *check = pimprove;
2285 const struct impr_type *best_upgrade = NULL;
2286
2287 if (!can_city_build_improvement_direct(pcity, check)) {
2288 return NULL;
2289 }
2290 while (valid_improvement(check = improvement_replacement(check))) {
2291 if (can_city_build_improvement_direct(pcity, check)) {
2292 best_upgrade = check;
2293 }
2294 }
2295
2296 return best_upgrade;
2297}
2298
2299/**********************************************************************/
2302static void upgrade_building_prod(struct city *pcity)
2303{
2304 const struct impr_type *producing = pcity->production.value.building;
2305 const struct impr_type *upgrading = building_upgrades_to(pcity, producing);
2306
2307 if (upgrading && can_city_build_improvement_now(pcity, upgrading)) {
2308 notify_player(city_owner(pcity), city_tile(pcity),
2309 E_UNIT_UPGRADED, ftc_server,
2310 _("Production of %s is upgraded to %s in %s."),
2313 city_link(pcity));
2314 pcity->production.kind = VUT_IMPROVEMENT;
2315 pcity->production.value.building = upgrading;
2316 }
2317}
2318
2319/**********************************************************************/
2327static const struct unit_type *unit_upgrades_to(struct city *pcity,
2328 const struct unit_type *punittype)
2329{
2330 const struct unit_type *check = punittype;
2331 const struct unit_type *best_upgrade = U_NOT_OBSOLETED;
2332 const struct civ_map *nmap = &(wld.map);
2333
2334 if (!can_city_build_unit_direct(nmap, pcity, punittype)) {
2335 return U_NOT_OBSOLETED;
2336 }
2337 while ((check = check->obsoleted_by) != U_NOT_OBSOLETED) {
2338 if (can_city_build_unit_direct(nmap, pcity, check)) {
2339 best_upgrade = check;
2340 }
2341 }
2342
2343 return best_upgrade;
2344}
2345
2346/**********************************************************************/
2349static void upgrade_unit_prod(struct city *pcity)
2350{
2351 const struct unit_type *producing = pcity->production.value.utype;
2352 const struct unit_type *upgrading = unit_upgrades_to(pcity, producing);
2353 const struct civ_map *nmap = &(wld.map);
2354
2355 if (upgrading && can_city_build_unit_direct(nmap, pcity, upgrading)) {
2356 notify_player(city_owner(pcity), city_tile(pcity),
2357 E_UNIT_UPGRADED, ftc_server,
2358 _("Production of %s is upgraded to %s in %s."),
2359 utype_name_translation(producing),
2360 utype_name_translation(upgrading),
2361 city_link(pcity));
2362 pcity->production.value.utype = upgrading;
2363 }
2364}
2365
2366/**********************************************************************/
2373static bool city_distribute_surplus_shields(struct player *pplayer,
2374 struct city *pcity)
2375{
2376 int size_reduction = 0;
2377 struct unit *sacrifizer;
2378
2379 if (pcity->surplus[O_SHIELD] < 0) {
2381 if (utype_upkeep_cost(unit_type_get(punit), pplayer, O_SHIELD) > 0
2382 && pcity->surplus[O_SHIELD] < 0) {
2383 const char *punit_link = unit_link(punit);
2384
2385 /* TODO: Should the unit try to help cities on adjacent tiles? That
2386 * would be a rules change. (This action is performed by the game
2387 * it self) */
2388 if (upkeep_kill_unit(punit, O_SHIELD, ULR_UPKEEP,
2390 notify_player(pplayer, city_tile(pcity),
2391 E_UNIT_LOST_MISC, ftc_server,
2392 _("%s can't upkeep %s, unit disbanded."),
2393 city_link(pcity), punit_link);
2394 }
2395
2396 /* pcity->surplus[O_SHIELD] is automatically updated. */
2397 }
2399 }
2400
2401 if (pcity->surplus[O_SHIELD] < 0) {
2402 /* Special case: MissingXProtected. This nasty unit won't go so easily.
2403 * It'd rather make the citizens pay in blood for their failure to upkeep
2404 * it! If we make it here all normal units are already disbanded, so only
2405 * undisbandable ones remain. */
2408
2409 if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
2410
2411 size_reduction++;
2412 sacrifizer = punit;
2413
2414 /* No upkeep for the unit this turn. */
2415 pcity->surplus[O_SHIELD] += upkeep;
2416 }
2418 }
2419
2420 /* Now we confirm changes made last turn. */
2421 pcity->shield_stock += pcity->surplus[O_SHIELD];
2422 pcity->before_change_shields = pcity->shield_stock;
2424
2425 /* Previous turn values stored, and they are consistent with
2426 * other previous turn data.
2427 * Now reduce city size, likely messing all the values. */
2428 if (size_reduction > 0) {
2429 if (size_reduction == 1) {
2430 notify_player(pplayer, city_tile(pcity),
2431 E_UNIT_LOST_MISC, ftc_server,
2432 _("Citizens in %s perish for their failure to "
2433 "upkeep %s!"),
2434 city_link(pcity), unit_link(sacrifizer));
2435 } else {
2436 notify_player(pplayer, city_tile(pcity),
2437 E_UNIT_LOST_MISC, ftc_server,
2438 _("Citizens in %s perish for their failure to "
2439 "upkeep units!"),
2440 city_link(pcity));
2441 }
2442
2443 if (!city_reduce_size(pcity, size_reduction, NULL, "upkeep_failure")) {
2444 return FALSE;
2445 }
2446 }
2447
2448 return TRUE;
2449}
2450
2451/**********************************************************************/
2454static bool city_build_building(struct player *pplayer, struct city *pcity)
2455{
2456 bool space_part;
2457 int mod;
2458 const struct impr_type *pimprove;
2459 int saved_id = pcity->id;
2460
2461 if (city_production_has_flag(pcity, IF_GOLD)) {
2462 fc_assert(pcity->before_change_shields >= 0);
2463
2464 /* pcity->before_change_shields already contains the surplus from
2465 * this turn. */
2466 pplayer->economic.gold += pcity->before_change_shields;
2467 pcity->before_change_shields = 0;
2468 pcity->shield_stock = 0;
2469 choose_build_target(pplayer, pcity);
2470
2471 return TRUE;
2472 }
2473
2474 upgrade_building_prod(pcity);
2475
2476 /* The final (after upgrade) build target */
2477 pimprove = pcity->production.value.building;
2478
2479 if (!can_city_build_improvement_now(pcity, pimprove)) {
2480 notify_player(pplayer, city_tile(pcity), E_CITY_CANTBUILD, ftc_server,
2481 _("%s is building %s, which is no longer available."),
2482 city_link(pcity),
2483 city_improvement_name_translation(pcity, pimprove));
2484 script_server_signal_emit("building_cant_be_built", pimprove, pcity,
2485 "unavailable");
2486 return TRUE;
2487 }
2488 if (pcity->shield_stock >= impr_build_shield_cost(pcity, pimprove)) {
2489 int cost;
2490
2491 if (is_small_wonder(pimprove)) {
2492 city_list_iterate(pplayer->cities, wcity) {
2493 if (city_has_building(wcity, pimprove)) {
2494 city_remove_improvement(wcity, pimprove);
2495 break;
2496 }
2498 }
2499
2500 space_part = TRUE;
2501 if (get_current_construction_bonus(pcity, EFT_SS_STRUCTURAL,
2502 RPT_CERTAIN) > 0) {
2503 pplayer->spaceship.structurals++;
2504 } else if (get_current_construction_bonus(pcity, EFT_SS_COMPONENT,
2505 RPT_CERTAIN) > 0) {
2506 pplayer->spaceship.components++;
2507 } else if (get_current_construction_bonus(pcity, EFT_SS_MODULE,
2508 RPT_CERTAIN) > 0) {
2509 pplayer->spaceship.modules++;
2510 } else {
2511 space_part = FALSE;
2512 city_add_improvement(pcity, pimprove);
2513 }
2514 cost = impr_build_shield_cost(pcity, pimprove);
2515 pcity->before_change_shields -= cost;
2516 pcity->shield_stock -= cost;
2517 pcity->turn_last_built = game.info.turn;
2518 /* to eliminate micromanagement */
2519 if (is_great_wonder(pimprove)) {
2520 notify_player(NULL, city_tile(pcity), E_WONDER_BUILD, ftc_server,
2521 _("The %s have finished building %s in %s."),
2522 nation_plural_for_player(pplayer),
2523 city_improvement_name_translation(pcity, pimprove),
2524 city_link(pcity));
2525 }
2526
2527 notify_player(pplayer, city_tile(pcity), E_IMP_BUILD, ftc_server,
2528 _("%s has finished building %s."),
2529 city_link(pcity), improvement_name_translation(pimprove));
2530 script_server_signal_emit("building_built", pimprove, pcity);
2531
2532 if (!city_exist(saved_id)) {
2533 /* Script removed city */
2534 return FALSE;
2535 }
2536
2537 /* Call this function since some buildings may change the
2538 * the vision range of a city */
2539 city_refresh_vision(pcity);
2540
2541 if ((mod = get_current_construction_bonus(pcity, EFT_GIVE_IMM_TECH,
2542 RPT_CERTAIN))) {
2543 struct research *presearch = research_get(pplayer);
2544 char research_name[MAX_LEN_NAME * 2];
2545 int i;
2546 const char *provider = improvement_name_translation(pimprove);
2547
2548 notify_research(presearch, NULL, E_TECH_GAIN, ftc_server,
2549 PL_("%s boosts research; you gain %d immediate "
2550 "advance.",
2551 "%s boosts research; you gain %d immediate "
2552 "advances.",
2553 mod), provider, mod);
2554
2555 research_pretty_name(presearch, research_name, sizeof(research_name));
2556 for (i = 0; i < mod; i++) {
2557 Tech_type_id tech = pick_free_tech(presearch);
2558 const char *adv_name = research_advance_name_translation(presearch, tech);
2559
2560 give_immediate_free_tech(presearch, tech);
2561 notify_research(presearch, NULL, E_TECH_GAIN, ftc_server,
2562 /* TRANS: Tech from building (Darwin's Voyage) */
2563 Q_("?frombldg:Acquired %s from %s."), adv_name,
2564 provider);
2565
2566 notify_research_embassies(presearch, NULL, E_TECH_EMBASSY, ftc_server,
2567 /* TRANS: Tech from building (Darwin's
2568 * Voyage) */
2569 Q_("?frombldg:The %s have acquired %s "
2570 "from %s."),
2571 research_name, adv_name, provider);
2572 }
2573 }
2574 if (space_part && pplayer->spaceship.state == SSHIP_NONE) {
2575 notify_player(NULL, city_tile(pcity), E_SPACESHIP, ftc_server,
2576 _("The %s have started building a spaceship!"),
2577 nation_plural_for_player(pplayer));
2578 pplayer->spaceship.state = SSHIP_STARTED;
2579 }
2580 if (space_part) {
2581 /* space ship part build */
2582 send_spaceship_info(pplayer, NULL);
2583 } else {
2584 /* Update city data. */
2585 if (city_refresh(pcity)) {
2586 auto_arrange_workers(pcity);
2587 }
2588 }
2589
2590 /* Move to the next thing in the worklist */
2591 choose_build_target(pplayer, pcity);
2592 }
2593
2594 return TRUE;
2595}
2596
2597/**********************************************************************/
2606static struct unit *city_create_unit(struct city *pcity,
2607 const struct unit_type *utype,
2608 struct citizens_reduction *red)
2609{
2610 struct player *pplayer = city_owner(pcity);
2611 struct unit *punit;
2612 int saved_unit_id;
2613 int pop_cost = utype_pop_value(utype, pcity);
2614
2615 punit = unit_virtual_prepare(pplayer, pcity->tile, utype,
2617 pcity->id, -1, -1);
2618 pplayer->score.units_built++;
2619 if (pop_cost > 0 && pcity->nationality) {
2620 /* We don't reduce city size in-place to keep it correct and
2621 * existing at all while we call the following callback */
2622 citizens_unit_nationality(pcity, pop_cost, red);
2623 } else if (red) {
2624 red->change = 0;
2625 }
2626 (void) place_unit(punit, pplayer, pcity, NULL, FALSE);
2627 saved_unit_id = punit->id;
2628
2629 /* If city has a rally point set, give the unit a move order. */
2630 if (pcity->rally_point.length) {
2635 * sizeof(struct unit_order));
2636 memcpy(punit->orders.list, pcity->rally_point.orders,
2637 pcity->rally_point.length * sizeof(struct unit_order));
2638 }
2639
2640 /* This might destroy pcity and/or punit: */
2641 script_server_signal_emit("unit_built", punit, pcity);
2642
2643 if (unit_is_alive(saved_unit_id)) {
2644 return punit;
2645 } else {
2646 return NULL;
2647 }
2648}
2649
2650/**********************************************************************/
2659static bool city_build_unit(struct player *pplayer, struct city *pcity)
2660{
2661 const struct unit_type *utype;
2662 struct worklist *pwl = &pcity->worklist;
2663 int unit_shield_cost, num_units, i;
2664 int saved_city_id = pcity->id;
2665 const struct civ_map *nmap = &(wld.map);
2666
2667 fc_assert_ret_val(pcity->production.kind == VUT_UTYPE, FALSE);
2668
2669 /* If the city has already bought a unit which is now obsolete, don't try
2670 * to upgrade the production. The new unit might require more shields, which
2671 * would be bad if it was bought to urgently defend a city. (Equally it
2672 * might be the same cost or cheaper, but tough; you hurried the unit so
2673 * you miss out on technological advances.) */
2674 if (city_can_change_build(pcity)) {
2675 upgrade_unit_prod(pcity);
2676 }
2677
2678 utype = pcity->production.value.utype;
2679 unit_shield_cost = utype_build_shield_cost(pcity, NULL, utype);
2680
2681 /* We must make a special case for barbarians here, because they are
2682 so dumb. Really. They don't know the prerequisite techs for units
2683 they build!! - Per */
2684 if (!can_city_build_unit_direct(nmap, pcity, utype)
2685 && !is_barbarian(pplayer)) {
2686 notify_player(pplayer, city_tile(pcity), E_CITY_CANTBUILD, ftc_server,
2687 _("%s is building %s, which is no longer available."),
2688 city_link(pcity), utype_name_translation(utype));
2689
2690 /* Log before signal emitting, so pointers are certainly valid */
2691 log_verbose("%s %s tried to build %s, which is not available.",
2693 city_name_get(pcity), utype_rule_name(utype));
2694 script_server_signal_emit("unit_cant_be_built", utype, pcity,
2695 "unavailable");
2696 return city_exist(saved_city_id);
2697 }
2698
2699 if (pcity->shield_stock >= unit_shield_cost) {
2700 int pop_cost = utype_pop_value(utype, pcity);
2701 struct unit *punit;
2702
2703 /* Should we disband the city? -- Massimo */
2704 if (city_size_get(pcity) == pop_cost
2705 && is_city_option_set(pcity, CITYO_DISBAND)) {
2706 return !disband_city(pcity);
2707 }
2708
2709 if (city_size_get(pcity) <= pop_cost) {
2710 notify_player(pplayer, city_tile(pcity), E_CITY_CANTBUILD, ftc_server,
2711 /* TRANS: city ... utype ... size ... pop_cost */
2712 _("%s can't build %s yet. "
2713 "(city size: %d, unit population cost: %d)"),
2715 city_size_get(pcity), pop_cost);
2716 script_server_signal_emit("unit_cant_be_built", utype, pcity,
2717 "pop_cost");
2718 return city_exist(saved_city_id);
2719 }
2720
2721 fc_assert(pop_cost == 0 || city_size_get(pcity) >= pop_cost);
2722
2723 /* don't update turn_last_built if we returned above */
2724 pcity->turn_last_built = game.info.turn;
2725
2726 /* check if we can build more than one unit (effect City_Build_Slots) */
2727 (void) city_production_build_units(pcity, FALSE, &num_units);
2728
2729 /* We should be able to build at least one (by checks above) */
2730 fc_assert(num_units >= 1);
2731
2732 for (i = 0; i < num_units; i++) {
2733 struct citizens_reduction natred[MAX_CITY_NATIONALITIES + 1];
2734
2735 punit = city_create_unit(pcity, utype, natred);
2736
2737 /* Check if the city still exists (script might have removed it).
2738 * If not, we assume any effects / announcements done below were
2739 * already replaced by the script if necessary. */
2740 if (!city_exist(saved_city_id)) {
2741 break;
2742 }
2743
2744 if (punit) {
2745 notify_player(pplayer, city_tile(pcity), E_UNIT_BUILT, ftc_server,
2746 /* TRANS: <city> is finished building <unit/building>. */
2747 _("%s is finished building %s."),
2748 city_link(pcity), utype_name_translation(utype));
2749 }
2750
2751 /* After we created the unit remove the citizen. This will also
2752 * rearrange the worker to take into account the extra resources
2753 * (food) needed. */
2754 if (pop_cost > 0) {
2755 /* This won't disband city due to pop_cost, but script might
2756 * still destroy city. */
2757 citizens_reduction_apply(pcity, natred);
2758 /* If the city has changed its nationalities during
2759 * "unit_built" signal, we take some other citizens instead */
2760 if (!city_reduce_size(pcity, pop_cost, NULL, "unit_built")) {
2761 break;
2762 }
2763 }
2764
2765 /* to eliminate micromanagement, we only subtract the unit's cost */
2766 /* signals could change the prod stock! */
2767 if ((pcity->before_change_shields -= unit_shield_cost) < 0) {
2768 pcity->before_change_shields = 0;
2769 }
2770 if ((pcity->shield_stock -= unit_shield_cost) < 0) {
2771 log_normal("City %s (%s) has built %s but has no %d shields "
2772 "for it, nullifying shield stock", city_name_get(pcity),
2773 player_name(pplayer), utype_rule_name(utype),
2774 unit_shield_cost);
2775 pcity->shield_stock = 0;
2776 }
2777
2778 if (pop_cost > 0) {
2779 /* Additional message if the unit has population cost. */
2780 notify_player(pplayer, city_tile(pcity), E_UNIT_BUILT_POP_COST,
2781 ftc_server,
2782 /* TRANS: "<unit> cost... <city> shrinks..."
2783 * Plural in "%d population", not "size %d". */
2784 PL_("%s cost %d population. %s shrinks to size %d.",
2785 "%s cost %d population. %s shrinks to size %d.",
2786 pop_cost),
2787 utype_name_translation(utype), pop_cost,
2788 city_link(pcity), city_size_get(pcity));
2789 }
2790
2791 if (i != 0 && worklist_length(pwl) > 0) {
2792 /* remove the build unit from the worklist; it has to be one less
2793 * than units build to preserve the next build target from the
2794 * worklist */
2795 worklist_remove(pwl, 0);
2796 }
2797 } /* for */
2798
2799 if (city_exist(saved_city_id)) {
2800 if (pcity->rally_point.length && !pcity->rally_point.persistent) {
2802 }
2803
2804 /* Done building this unit; time to move on to the next. */
2805 choose_build_target(pplayer, pcity);
2806 }
2807 } /* if */
2808
2809 return city_exist(saved_city_id);
2810}
2811
2812/**********************************************************************/
2815static bool city_build_stuff(struct player *pplayer, struct city *pcity)
2816{
2817 if (!city_distribute_surplus_shields(pplayer, pcity)) {
2818 return FALSE;
2819 }
2820
2823
2824 switch (pcity->production.kind) {
2825 case VUT_IMPROVEMENT:
2826 return city_build_building(pplayer, pcity);
2827 case VUT_UTYPE:
2828 return city_build_unit(pplayer, pcity);
2829 default:
2830 /* must never happen! */
2832 break;
2833 };
2834 return FALSE;
2835}
2836
2837/**********************************************************************/
2847static bool sell_random_building(struct player *pplayer,
2848 struct cityimpr_list *imprs)
2849{
2850 struct cityimpr *pcityimpr;
2851 int r;
2852
2853 fc_assert_ret_val(pplayer != NULL, FALSE);
2854
2855 if (!imprs || cityimpr_list_size(imprs) == 0) {
2856 return FALSE;
2857 }
2858
2859 r = fc_rand(cityimpr_list_size(imprs));
2860 pcityimpr = cityimpr_list_get(imprs, r);
2861
2862 notify_player(pplayer, city_tile(pcityimpr->pcity), E_IMP_AUCTIONED,
2863 ftc_server,
2864 _("Can't afford to maintain %s in %s, building sold!"),
2866 city_link(pcityimpr->pcity));
2867 log_debug("%s: sold building (%s)", player_name(pplayer),
2869
2870 do_sell_building(pplayer, pcityimpr->pcity, pcityimpr->pimprove, "cant_maintain");
2871
2872 cityimpr_list_remove(imprs, pcityimpr);
2873
2874 /* Get back the gold upkeep that was already paid this turn. */
2875 pplayer->economic.gold += city_improvement_upkeep(pcityimpr->pcity,
2876 pcityimpr->pimprove);
2877
2878 city_refresh_queue_add(pcityimpr->pcity);
2879
2880 FC_FREE(pcityimpr);
2881
2882 return TRUE;
2883}
2884
2885/**********************************************************************/
2893static void uk_rem_gold_callback(struct unit *punit)
2894{
2895 int gold_upkeep;
2896
2897 /* Remove the unit from uk_rem_gold. */
2898 unit_list_remove(uk_rem_gold, punit);
2899
2900 gold_upkeep = punit->server.upkeep_paid[O_GOLD];
2901
2902 /* All units in uk_rem_gold should have gold upkeep! */
2903 fc_assert_ret_msg(gold_upkeep > 0, "%s has %d gold upkeep",
2904 unit_rule_name(punit), gold_upkeep);
2905
2906 /* Get the upkeep gold back. */
2907 unit_owner(punit)->economic.gold += gold_upkeep;
2908}
2909
2910/**********************************************************************/
2914static void uk_rem_gold_append(struct unit *punit)
2915{
2916 /* Make the unit aware that it is on the uk_rem_gold list. */
2918
2919 /* Add the unit to the list. */
2920 unit_list_append(uk_rem_gold, punit);
2921}
2922
2923/**********************************************************************/
2927static void unit_list_referred_destroy(struct unit_list *punitlist)
2928{
2929 unit_list_iterate(punitlist, punit) {
2930 /* Clear the unit's knowledge of the list. */
2933
2934 /* Destroy the list it self. */
2935 unit_list_destroy(punitlist);
2936}
2937
2938/**********************************************************************/
2950static struct unit *sell_random_unit(struct player *pplayer,
2951 struct unit_list *punitlist)
2952{
2953 struct unit *punit;
2954 int r;
2955 struct unit_list *cargo;
2956
2957 fc_assert_ret_val(pplayer != NULL, NULL);
2958
2959 if (!punitlist || unit_list_size(punitlist) == 0) {
2960 return NULL;
2961 }
2962
2963 r = fc_rand(unit_list_size(punitlist));
2964 punit = unit_list_get(punitlist, r);
2965
2966 cargo = unit_list_new();
2967
2968 /* Check if unit is transporting other units from punitlist,
2969 * and sell one of those (recursively) instead.
2970 * Note that in case of recursive transports we have to iterate
2971 * also through those middle transports that themselves are not in
2972 * punitlist. */
2973 unit_cargo_iterate(punit, pcargo) {
2974 /* Optimization, do not iterate over punitlist
2975 * if we are sure that pcargo is not in it. */
2976 if (pcargo->server.upkeep_paid[O_GOLD] > 0) {
2977 unit_list_iterate(punitlist, p2) {
2978 if (pcargo == p2) {
2979 unit_list_append(cargo, pcargo);
2980 }
2982 }
2984
2985 if (unit_list_size(cargo) > 0) {
2986 /* Recursively sell. Note that cargo list has both
2987 * leaf units and middle transports in case of
2988 * recursive transports. */
2989 struct unit *ret = sell_random_unit(pplayer, cargo);
2990
2991 unit_list_destroy(cargo);
2992
2993 unit_list_remove(punitlist, ret);
2994
2995 return ret;
2996 }
2997
2998 unit_list_destroy(cargo);
2999
3000 {
3001 const char *punit_link = unit_tile_link(punit);
3002#ifdef FREECIV_DEBUG
3003 const char *punit_logname = unit_rule_name(punit);
3004#endif /* FREECIV_DEBUG */
3005 struct tile *utile = unit_tile(punit);
3006
3007 if (upkeep_kill_unit(punit, O_GOLD, ULR_SOLD,
3009 unit_list_remove(punitlist, punit);
3010
3011 /* The gold was paid back when the unit removal made
3012 * uk_rem_gold_callback() run as the unit's removal call back. */
3013
3014 notify_player(pplayer, utile, E_UNIT_LOST_MISC, ftc_server,
3015 _("Not enough gold. %s disbanded."),
3016 punit_link);
3017 log_debug("%s: unit sold (%s)", player_name(pplayer),
3018 punit_logname);
3019 } else {
3020 /* Not able to get rid of punit */
3021 return NULL;
3022 }
3023 }
3024
3025 unit_list_remove(punitlist, punit);
3026
3027 return punit;
3028}
3029
3030/**********************************************************************/
3034 (struct player *pplayer)
3035{
3036 struct cityimpr_list *pimprlist;
3037 bool sell_unit = TRUE;
3038
3039 if (!pplayer) {
3040 return FALSE;
3041 }
3042
3043 pimprlist = cityimpr_list_new();
3044 uk_rem_gold = unit_list_new();
3045
3046 city_list_iterate(pplayer->cities, pcity) {
3047 city_built_iterate(pcity, pimprove) {
3048 if (can_city_sell_building(pcity, pimprove)) {
3049 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3050
3051 ci->pcity = pcity;
3052 ci->pimprove = pimprove;
3053 cityimpr_list_append(pimprlist, ci);
3054 }
3056
3058 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3060 }
3063
3064 while (pplayer->economic.gold < 0
3065 && (cityimpr_list_size(pimprlist) > 0
3066 || unit_list_size(uk_rem_gold) > 0)) {
3067 if ((!sell_unit && cityimpr_list_size(pimprlist) > 0)
3068 || unit_list_size(uk_rem_gold) == 0) {
3069 sell_random_building(pplayer, pimprlist);
3070 } else {
3071 sell_random_unit(pplayer, uk_rem_gold);
3072 }
3073 sell_unit = !sell_unit;
3074 }
3075
3076 /* Free remaining entries from list */
3077 cityimpr_list_iterate(pimprlist, pimpr) {
3078 FC_FREE(pimpr);
3080
3081 if (pplayer->economic.gold < 0) {
3082 /* If we get here it means the player has
3083 * negative gold. This should never happen. */
3084 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3085 player_name(pplayer), player_number(pplayer));
3086 }
3087
3088 cityimpr_list_destroy(pimprlist);
3090
3091 return pplayer->economic.gold >= 0;
3092}
3093
3094/**********************************************************************/
3097static bool player_balance_treasury_units(struct player *pplayer)
3098{
3099 if (!pplayer) {
3100 return FALSE;
3101 }
3102
3103 uk_rem_gold = unit_list_new();
3104
3105 city_list_iterate(pplayer->cities, pcity) {
3107 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3109 }
3112
3113 while (pplayer->economic.gold < 0
3114 && sell_random_unit(pplayer, uk_rem_gold)) {
3115 /* all done in sell_random_unit() */
3116 }
3117
3118 if (pplayer->economic.gold < 0) {
3119 /* If we get here it means the player has
3120 * negative gold. This should never happen. */
3121 fc_assert_msg(FALSE, "Player %s (nb %d) cannot have negative gold!",
3122 player_name(pplayer), player_number(pplayer));
3123 }
3124
3126
3127 return pplayer->economic.gold >= 0;
3128}
3129
3130/**********************************************************************/
3134{
3135 struct player *pplayer;
3136 struct cityimpr_list *pimprlist;
3137
3138 if (!pcity) {
3139 return TRUE;
3140 }
3141
3142 pplayer = city_owner(pcity);
3143 pimprlist = cityimpr_list_new();
3144
3145 /* Create a vector of all buildings that can be sold. */
3146 city_built_iterate(pcity, pimprove) {
3147 if (can_city_sell_building(pcity, pimprove)) {
3148 struct cityimpr *ci = fc_malloc(sizeof(*ci));
3149
3150 ci->pcity = pcity;
3151 ci->pimprove = pimprove;
3152 cityimpr_list_append(pimprlist, ci);
3153 }
3155
3156 /* Try to sell some buildings. */
3157 while (pplayer->economic.gold < 0
3158 && sell_random_building(pplayer, pimprlist)) {
3159 /* all done in sell_random_building */
3160 }
3161
3162 /* Free remaining entries from list */
3163 cityimpr_list_iterate(pimprlist, pimpr) {
3164 FC_FREE(pimpr);
3166
3167 cityimpr_list_destroy(pimprlist);
3168
3169 return pplayer->economic.gold >= 0;
3170}
3171
3172/**********************************************************************/
3181{
3182 struct player *pplayer;
3183
3184 if (!pcity) {
3185 return TRUE;
3186 }
3187
3188 pplayer = city_owner(pcity);
3189 uk_rem_gold = unit_list_new();
3190
3191 /* Create a vector of all supported units with gold upkeep. */
3193 if (punit->server.upkeep_paid[O_GOLD] > 0) {
3195 }
3197
3198 /* Still not enough gold, so try "selling" some units. */
3199 while (pplayer->economic.gold < 0
3200 && sell_random_unit(pplayer, uk_rem_gold)) {
3201 /* all done in sell_random_unit() */
3202 }
3203
3204 /* If we get here the player has negative gold, but hopefully
3205 * another city will be able to pay the deficit, so continue. */
3206
3208
3209 return pplayer->economic.gold >= 0;
3210}
3211
3212/**********************************************************************/
3215static bool place_pollution(struct city *pcity, enum extra_cause cause)
3216{
3217 struct tile *ptile;
3218 struct tile *pcenter = city_tile(pcity);
3219 int city_radius_sq = city_map_radius_sq_get(pcity);
3220 int k = 100;
3221 const struct civ_map *nmap = &(wld.map);
3222
3223 while (k > 0) {
3224 /* Place pollution on a random city tile */
3225 int cx, cy;
3226 int tile_id = fc_rand(city_map_tiles(city_radius_sq));
3227 struct extra_type *pextra;
3228
3229 city_tile_index_to_xy(&cx, &cy, tile_id, city_radius_sq);
3230
3231 /* Check for a real map position */
3232 if (!(ptile = city_map_to_tile(nmap, pcenter, city_radius_sq, cx, cy))) {
3233 continue;
3234 }
3235
3236 pextra = rand_extra_for_tile(ptile, cause, FALSE);
3237
3238 if (pextra != NULL && !tile_has_extra(ptile, pextra)) {
3239 tile_add_extra(ptile, pextra);
3240 update_tile_knowledge(ptile);
3241
3242 return TRUE;
3243 }
3244 k--;
3245 }
3246 log_debug("pollution not placed: city: %s", city_name_get(pcity));
3247
3248 return FALSE;
3249}
3250
3251/**********************************************************************/
3254static void check_pollution(struct city *pcity)
3255{
3256 if (fc_rand(100) < pcity->pollution) {
3257 if (place_pollution(pcity, EC_POLLUTION)) {
3258 notify_player(city_owner(pcity), city_tile(pcity), E_POLLUTION, ftc_server,
3259 _("Pollution near %s."), city_link(pcity));
3260 }
3261 }
3262}
3263
3264/**********************************************************************/
3271int city_incite_cost(struct player *pplayer, struct city *pcity)
3272{
3273 int dist, size;
3274 double cost; /* Intermediate values can get very large */
3275
3276 /* Gold factor */
3277 cost = city_owner(pcity)->economic.gold + game.server.base_incite_cost;
3278
3279 unit_list_iterate(pcity->tile->units, punit) {
3283
3284 /* Buildings */
3285 city_built_iterate(pcity, pimprove) {
3286 cost += impr_build_shield_cost(pcity, pimprove)
3289
3290 /* Stability bonuses */
3291 if (!city_unhappy(pcity)) {
3292 cost *= 2;
3293 }
3294 if (city_celebrating(pcity)) {
3295 cost *= 2;
3296 }
3297
3298 /* Buy back is cheap, conquered cities are also cheap */
3300 if (city_owner(pcity) != pcity->original) {
3301 if (pplayer == pcity->original) {
3302 cost /= 2; /* Buy back: 50% price reduction */
3303 } else {
3304 cost = cost * 2 / 3; /* Buy conquered: 33% price reduction */
3305 }
3306 }
3307 }
3308
3309 /* Distance from capital */
3310 /* Max penalty. Applied if there is no capital, or it's even further away. */
3311 dist = 32;
3312 city_list_iterate(city_owner(pcity)->cities, capital) {
3313 if (is_capital(capital)) {
3314 int tmp = map_distance(capital->tile, pcity->tile);
3315
3316 if (tmp < dist) {
3317 dist = tmp;
3318 }
3319 }
3321
3322 size = MAX(1, city_size_get(pcity)
3325 - pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] * 3);
3326 cost *= size;
3328 cost = cost / (dist + 3);
3329
3331 int cost_per_citizen = cost / pcity->size;
3332 int natives = citizens_nation_get(pcity, city_owner(pcity)->slot);
3333 int tgt_cit = citizens_nation_get(pcity, pplayer->slot);
3334 int third_party = pcity->size - natives - tgt_cit;
3335
3336 cost = cost_per_citizen * (natives + 0.7 * third_party + 0.5 * tgt_cit);
3337 }
3338
3339 cost += (cost * get_city_bonus(pcity, EFT_INCITE_COST_PCT)) / 100;
3340 cost /= 100;
3341
3344 } else {
3345 return cost;
3346 }
3347}
3348
3349/**********************************************************************/
3352static void define_orig_production_values(struct city *pcity)
3353{
3354 /* Remember what this city is building last turn, so that on the next turn
3355 * the player can switch production to something else and then change it
3356 * back without penalty. This has to be updated _before_ production for
3357 * this turn is calculated, so that the penalty will apply if the player
3358 * changes production away from what has just been completed. This makes
3359 * sense if you consider what this value means: all the shields in the
3360 * city have been dedicated toward the project that was chosen last turn,
3361 * so the player shouldn't be penalized if the governor has to pick
3362 * something different. See city_change_production_penalty(). */
3363 pcity->changed_from = pcity->production;
3364
3365 log_debug("In %s, building %s. Beg of Turn shields = %d",
3367 pcity->before_change_shields);
3368}
3369
3370/**********************************************************************/
3373static void nullify_caravan_and_disband_plus(struct city *pcity)
3374{
3375 pcity->disbanded_shields=0;
3376 pcity->caravan_shields=0;
3377}
3378
3379/**********************************************************************/
3384{
3386 pcity->before_change_shields=0;
3387}
3388
3389/**********************************************************************/
3392static void update_city_activity(struct city *pcity)
3393{
3394 struct player *pplayer;
3395 struct government *gov;
3396 bool is_happy;
3397 bool is_celebrating;
3398
3399 if (!pcity) {
3400 return;
3401 }
3402
3403 pplayer = city_owner(pcity);
3404 gov = government_of_city(pcity);
3405 is_happy = city_happy(pcity);
3406 is_celebrating = city_celebrating(pcity);
3407
3408 if (city_refresh(pcity)) {
3409 auto_arrange_workers(pcity);
3410 }
3411
3412 /* Reporting of celebrations rewritten, copying the treatment of disorder below,
3413 with the added rapture rounds count. 991219 -- Jing */
3414 if (city_build_stuff(pplayer, pcity)) {
3415 int saved_id;
3416 int revolution_turns;
3417
3418 pcity->history += city_history_gain(pcity);
3419
3420 /* History can decrease, but never go below zero */
3421 pcity->history = MAX(pcity->history, 0);
3422
3423 /* Keep old behaviour when building new improvement could keep
3424 city celebrating */
3425 if (!is_happy) {
3426 is_happy = city_happy(pcity);
3427 }
3428
3429 if (city_celebrating(pcity) || is_celebrating) {
3430 pcity->rapture++;
3431 if (pcity->rapture == 1) {
3432 notify_player(pplayer, city_tile(pcity), E_CITY_LOVE, ftc_server,
3433 _("Celebrations in your honor in %s."),
3434 city_link(pcity));
3435 }
3436 } else {
3437 if (pcity->rapture != 0) {
3438 notify_player(pplayer, city_tile(pcity), E_CITY_NORMAL, ftc_server,
3439 _("Celebrations canceled in %s."),
3440 city_link(pcity));
3441 }
3442 pcity->rapture = 0;
3443 }
3444 pcity->was_happy = is_happy;
3445
3446 /* Handle the illness. */
3447 if (game.info.illness_on) {
3448 /* Recalculate city illness; illness due to trade has to be saved
3449 * within the city struct, as the client does not have all
3450 * the data to calculate it */
3451 pcity->server.illness
3452 = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), NULL);
3453
3454 if (city_illness_check(pcity)) {
3455 if (!city_illness_strike(pcity)) {
3456 /* Illness destroyed the city */
3457 return;
3458 }
3459 }
3460 }
3461
3462 /* City population updated here, after the rapture stuff above. --Jing */
3463 saved_id = pcity->id;
3464 city_populate(pcity, pplayer);
3465 if (NULL == player_city_by_number(pplayer, saved_id)) {
3466 return;
3467 }
3468
3469 pcity->did_sell = FALSE;
3470 pcity->did_buy = FALSE;
3471 pcity->airlift = city_airlift_max(pcity);
3472 update_bulbs(pplayer, pcity->prod[O_SCIENCE], FALSE);
3473
3474 pplayer->economic.infra_points += get_city_bonus(pcity, EFT_INFRA_POINTS);
3475
3476 /* Update the treasury. */
3477 pplayer->economic.gold += pcity->surplus[O_GOLD];
3478
3479 /* FIXME: Nation level upkeep should be paid after ALL cities
3480 * have been processed, not after each individual city. */
3481 if (game.info.gold_upkeep_style != GOLD_UPKEEP_CITY) {
3482 /* Unit upkeep was not included in city balance ->
3483 * not reduced from the city surplus. */
3484 pplayer->economic.gold -= city_total_unit_gold_upkeep(pcity);
3485
3486 if (game.info.gold_upkeep_style == GOLD_UPKEEP_NATION) {
3487 /* Building upkeep was not included in city balance ->
3488 * not reduced from the city surplus. */
3489 pplayer->economic.gold -= city_total_impr_gold_upkeep(pcity);
3490 }
3491 }
3492
3493 /* Remember how much gold upkeep each unit was paid. */
3497
3498 if (pplayer->economic.gold < 0) {
3499 /* Not enough gold - we have to sell some buildings, and if that
3500 * is not enough, disband units with gold upkeep, taking into
3501 * account the setting of 'game.info.gold_upkeep_style':
3502 * GOLD_UPKEEP_CITY: Cities pay for buildings and units.
3503 * GOLD_UPKEEP_MIXED: Cities pay only for buildings; the nation pays
3504 * for units.
3505 * GOLD_UPKEEP_NATION: The nation pays for buildings and units. */
3506 switch (game.info.gold_upkeep_style) {
3507 case GOLD_UPKEEP_CITY:
3508 case GOLD_UPKEEP_MIXED:
3510 && game.info.gold_upkeep_style == GOLD_UPKEEP_CITY) {
3512 }
3513 break;
3514 case GOLD_UPKEEP_NATION:
3515 break;
3516 }
3517 }
3518
3519 revolution_turns = get_city_bonus(pcity, EFT_REVOLUTION_UNHAPPINESS);
3520 if (city_unhappy(pcity)) {
3521 const char *revomsg;
3522
3523 pcity->anarchy++;
3524 if (pcity->anarchy == revolution_turns) {
3525 /* Revolution next turn if not dealt with */
3526 /* TRANS: preserve leading space; this string will be appended to
3527 * another sentence */
3528 revomsg = _(" Unrest threatens to spread beyond the city.");
3529 } else {
3530 revomsg = "";
3531 }
3532 if (pcity->anarchy == 1) {
3533 notify_player(pplayer, city_tile(pcity), E_CITY_DISORDER, ftc_server,
3534 /* TRANS: second %s is an optional extra sentence */
3535 _("Civil disorder in %s.%s"),
3536 city_link(pcity), revomsg);
3537 } else {
3538 notify_player(pplayer, city_tile(pcity), E_CITY_DISORDER, ftc_server,
3539 /* TRANS: second %s is an optional extra sentence */
3540 _("CIVIL DISORDER CONTINUES in %s.%s"),
3541 city_link(pcity), revomsg);
3542 }
3543 } else {
3544 if (pcity->anarchy != 0) {
3545 notify_player(pplayer, city_tile(pcity), E_CITY_NORMAL, ftc_server,
3546 _("Order restored in %s."),
3547 city_link(pcity));
3548 }
3549 pcity->anarchy = 0;
3550 }
3551 check_pollution(pcity);
3552
3553 send_city_info(NULL, pcity);
3554
3555 if (revolution_turns > 0 && pcity->anarchy > revolution_turns) {
3556 notify_player(pplayer, city_tile(pcity), E_ANARCHY, ftc_server,
3557 /* TRANS: %s - government form, e.g., Democracy */
3558 _("The people have overthrown your %s, "
3559 "your country is in turmoil."),
3562 }
3563 if (city_refresh(pcity)) {
3564 auto_arrange_workers(pcity);
3565 }
3566 sanity_check_city(pcity);
3567 }
3568}
3569
3570/**********************************************************************/
3573static bool city_illness_check(const struct city * pcity)
3574{
3575 if (fc_rand(1000) < pcity->server.illness) {
3576 return TRUE;
3577 }
3578
3579 return FALSE;
3580}
3581
3582/**********************************************************************/
3586static bool disband_city(struct city *pcity)
3587{
3588 struct player *pplayer = city_owner(pcity);
3589 struct tile *ptile = pcity->tile;
3590 struct city *rcity=NULL;
3591 const struct unit_type *utype = pcity->production.value.utype;
3592 struct unit *punit;
3593 int saved_id = pcity->id;
3594
3595 /* find closest city other than pcity */
3596 rcity = find_closest_city(ptile, pcity, pplayer, FALSE, FALSE, FALSE, TRUE,
3597 FALSE, NULL);
3598
3599 if (!rcity) {
3600 /* What should we do when we try to disband our only city? */
3601 notify_player(pplayer, ptile, E_CITY_CANTBUILD, ftc_server,
3602 _("%s can't build %s yet, "
3603 "as we can't disband our only city."),
3605 script_server_signal_emit("unit_cant_be_built", utype, pcity,
3606 "pop_cost");
3607 if (!city_exist(saved_id)) {
3608 /* Script decided to remove even the last city */
3609 return TRUE;
3610 } else {
3611 return FALSE;
3612 }
3613 }
3614
3615 punit = city_create_unit(pcity, utype, NULL);
3616
3617 /* "unit_built" script handler may have destroyed city. If so, we
3618 * assume something sensible happened to its units, and that the
3619 * script took care of announcing unit creation if required. */
3620 if (city_exist(saved_id)) {
3621 /* Shift all the units supported by pcity (including the new unit)
3622 * to rcity. transfer_city_units does not make sure no units are
3623 * left floating without a transport, but since all units are
3624 * transferred this is not a problem. */
3625 transfer_city_units(pplayer, pplayer, pcity->units_supported, rcity,
3626 pcity, -1, TRUE);
3627
3628 if (punit) {
3629 notify_player(pplayer, ptile, E_UNIT_BUILT, ftc_server,
3630 /* TRANS: "<city> is disbanded into Settler." */
3631 _("%s is disbanded into %s."),
3633 }
3634
3635 script_server_signal_emit("city_destroyed", pcity, pcity->owner, NULL);
3636
3637 if (!city_exist(saved_id)) {
3638 /* Already removed during the script */
3639 return TRUE;
3640 }
3641 remove_city(pcity);
3642
3643 /* Since we've removed the city, we don't need to worry about
3644 * charging for production, disabling rally points, etc. */
3645 }
3646
3647 return TRUE;
3648}
3649
3650/**********************************************************************/
3698static float city_migration_score(struct city *pcity)
3699{
3700 float score = 0.0;
3701 int build_shield_cost = 0;
3702 bool has_wonder = FALSE;
3703
3704 if (!pcity) {
3705 return score;
3706 }
3707
3708 if (pcity->server.mgr_score_calc_turn == game.info.turn) {
3709 /* up-to-date migration score */
3710 return pcity->server.migration_score;
3711 }
3712
3713 /* feeling of the citizens */
3714 score = (city_size_get(pcity)
3715 + 1.00 * pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
3716 + 0.00 * pcity->feel[CITIZEN_CONTENT][FEELING_FINAL]
3717 - 0.25 * pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL]
3718 - 0.50 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
3719
3720 /* calculate shield build cost for all buildings */
3721 city_built_iterate(pcity, pimprove) {
3722 build_shield_cost += impr_build_shield_cost(pcity, pimprove);
3723 if (is_wonder(pimprove)) {
3724 /* this city has a wonder */
3725 has_wonder = TRUE;
3726 }
3728
3729 /* take shield costs of all buidings into account; normalized by 1000 */
3730 score *= (1 + (1 - exp(- (float) MAX(0, build_shield_cost) / 1000)) / 5);
3731 /* take trade into account; normalized by 100 */
3732 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_TRADE]) / 100))
3733 / 5);
3734 /* take luxury into account; normalized by 100 */
3735 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_LUXURY]) / 100))
3736 / 5);
3737 /* take science into account; normalized by 100 */
3738 score *= (1 + (1 - exp(- (float) MAX(0, pcity->surplus[O_SCIENCE]) / 100))
3739 / 5);
3740
3741 score += city_culture(pcity) * game.info.culture_migration_pml / 1000;
3742
3743 /* Take food into account; the food surplus is clipped to values between
3744 * -10..20 and normalize by 10. Thus, the factor is between 0.9 and 1.2. */
3745 score *= (1 + (float) CLIP(-10, pcity->surplus[O_FOOD], 20) / 10 );
3746
3747 /* Reduce the score due to city illness (plague). The illness is given in
3748 * tenth of percent (0..1000) and normalized by 25. Thus, this factor is
3749 * between 0.6 (ill city) and 1.0 (health city). */
3750 score *= (100 - (float)city_illness_calc(pcity, NULL, NULL, NULL, NULL)
3751 / 25);
3752
3753 if (has_wonder) {
3754 /* people like wonders */
3755 score *= 1.25;
3756 }
3757
3758 if (is_capital(pcity)) {
3759 /* the capital is a magnet for the citizens */
3760 score *= 1.25;
3761 }
3762
3763 /* take into account effects */
3764 score *= (1.0 + get_city_bonus(pcity, EFT_MIGRATION_PCT) / 100.0);
3765
3766 log_debug("[M] %s score: %.3f", city_name_get(pcity), score);
3767
3768 /* set migration score for the city */
3769 pcity->server.migration_score = score;
3770 /* set the turn, when the score was calculated */
3772
3773 return score;
3774}
3775
3776/**********************************************************************/
3782static bool do_city_migration(struct city *pcity_from,
3783 struct city *pcity_to)
3784{
3785 struct player *pplayer_from, *pplayer_to, *pplayer_citizen;
3786 struct tile *ptile_from, *ptile_to;
3787 char name_from[MAX_LEN_LINK], name_to[MAX_LEN_LINK];
3788 const char *nation_from, *nation_to;
3789 struct city *rcity = NULL;
3790 int to_id = pcity_to->id;
3791 const struct civ_map *nmap = &(wld.map);
3792
3793 if (!pcity_from || !pcity_to) {
3794 return FALSE;
3795 }
3796
3797 pplayer_from = city_owner(pcity_from);
3798 pplayer_citizen = pplayer_from;
3799 pplayer_to = city_owner(pcity_to);
3800 /* We copy that, because city_link always returns the same pointer. */
3801 sz_strlcpy(name_from, city_link(pcity_from));
3802 sz_strlcpy(name_to, city_link(pcity_to));
3803 nation_from = nation_adjective_for_player(pplayer_from);
3804 nation_to = nation_adjective_for_player(pplayer_to);
3805 ptile_from = city_tile(pcity_from);
3806 ptile_to = city_tile(pcity_to);
3807
3808 /* Check food supply in the receiver city */
3810 bool migration = FALSE;
3811
3812 if (pcity_to->surplus[O_FOOD] >= game.info.food_cost) {
3813 migration = TRUE;
3814 } else {
3815 /* Check if there is a free tile for the new citizen which, when worked,
3816 * leads to zero or positive food surplus for the enlarged city */
3817 int max_food_tile = -1; /* no free tile */
3818
3820 city_tile(pcity_to), ptile) {
3821 if (city_can_work_tile(pcity_to, ptile)
3822 && tile_worked(ptile) != pcity_to) {
3823 /* Safest assumption is that city won't be celebrating once an
3824 * additional citizen is added */
3825 max_food_tile = MAX(max_food_tile,
3826 city_tile_output(pcity_to, ptile, FALSE, O_FOOD));
3827 }
3829 if (max_food_tile >= 0
3830 && pcity_to->surplus[O_FOOD] + max_food_tile >= game.info.food_cost) {
3831 migration = TRUE;
3832 }
3833 }
3834
3835 if (!migration) {
3836 /* insufficiency food in receiver city; no additional citizens */
3837 if (pplayer_from == pplayer_to) {
3838 /* migration between one nation */
3839 notify_player(pplayer_to, ptile_to, E_CITY_TRANSFER, ftc_server,
3840 /* TRANS: From <city1> to <city2>. */
3841 _("Migrants from %s can't go to %s because there is "
3842 "not enough food available!"),
3843 name_from, name_to);
3844 } else {
3845 /* migration between different nations */
3846 notify_player(pplayer_from, ptile_to, E_CITY_TRANSFER, ftc_server,
3847 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
3848 _("Migrants from %s can't go to %s (%s) because there "
3849 "is not enough food available!"),
3850 name_from, name_to, nation_to);
3851 notify_player(pplayer_to, ptile_to, E_CITY_TRANSFER, ftc_server,
3852 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
3853 _("Migrants from %s (%s) can't go to %s because there "
3854 "is not enough food available!"),
3855 name_from, nation_from, name_to);
3856 }
3857
3858 return FALSE;
3859 }
3860 }
3861
3862 if (!city_can_grow_to(pcity_to, city_size_get(pcity_to) + 1)) {
3863 /* receiver city can't grow */
3864 if (pplayer_from == pplayer_to) {
3865 /* migration between one nation */
3866 notify_player(pplayer_to, ptile_to, E_CITY_TRANSFER, ftc_server,
3867 /* TRANS: From <city1> to <city2>. */
3868 _("Migrants from %s can't go to %s because it needs "
3869 "an improvement to grow!"),
3870 name_from, name_to);
3871 } else {
3872 /* migration between different nations */
3873 notify_player(pplayer_from, ptile_to, E_CITY_TRANSFER, ftc_server,
3874 /* TRANS: From <city1> to <city2> of <city2 nation adjective>. */
3875 _("Migrants from %s can't go to %s (%s) because it "
3876 "needs an improvement to grow!"),
3877 name_from, name_to, nation_to);
3878 notify_player(pplayer_to, ptile_to, E_CITY_TRANSFER, ftc_server,
3879 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
3880 _("Migrants from %s (%s) can't go to %s because it "
3881 "needs an improvement to grow!"),
3882 name_from, nation_from, name_to);
3883 }
3884
3885 return FALSE;
3886 }
3887
3888 /* reduce size of giver */
3889 if (city_size_get(pcity_from) == 1) {
3890
3892 /* Preserve nationality of city's only citizen */
3893 pplayer_citizen = player_slot_get_player(citizens_random(pcity_from));
3894 }
3895
3896 /* do not destroy wonders */
3897 city_built_iterate(pcity_from, pimprove) {
3898 if (is_wonder(pimprove)) {
3899 return FALSE;
3900 }
3902
3903 /* find closest city other of the same player than pcity_from */
3904 rcity = find_closest_city(ptile_from, pcity_from, pplayer_from, FALSE,
3905 FALSE, FALSE, TRUE, FALSE, NULL);
3906
3907 if (rcity) {
3908 int id = pcity_from->id;
3909
3910 /* transfer all units to the closest city */
3911 transfer_city_units(pplayer_from, pplayer_from,
3912 pcity_from->units_supported, rcity, pcity_from,
3913 -1, TRUE);
3914 sz_strlcpy(name_from, city_tile_link(pcity_from));
3915
3916 script_server_signal_emit("city_size_change", pcity_from,
3917 (lua_Integer)(-1), "migration_from");
3918
3919 if (city_exist(id)) {
3920 script_server_signal_emit("city_destroyed", pcity_from,
3921 pcity_from->owner, NULL);
3922
3923 if (city_exist(id)) {
3924 remove_city(pcity_from);
3925 }
3926 }
3927
3928 notify_player(pplayer_from, ptile_from, E_CITY_LOST, ftc_server,
3929 _("%s was disbanded by its citizens."),
3930 name_from);
3931 } else {
3932 /* it's the only city of the nation */
3933 return FALSE;
3934 }
3935 } else {
3936 /* the migrants take half of the food box with them (this prevents
3937 * migration -> grow -> migration -> ... cycles) */
3938 pcity_from->food_stock /= 2;
3939
3941 /* Those citizens that are from the target nation are most
3942 * ones migrating. */
3943 if (citizens_nation_get(pcity_from, pplayer_to->slot) > 0) {
3944 pplayer_citizen = pplayer_to;
3945 } else if (!citizens_nation_get(pcity_from, pplayer_citizen->slot)) {
3946 /* No native citizens at all in the city, choose random foreigner */
3947 struct player_slot *cit_slot = citizens_random(pcity_from);
3948
3949 pplayer_citizen = player_slot_get_player(cit_slot);
3950 }
3951 /* This should be followed by city_reduce_size(). */
3952 citizens_nation_add(pcity_from, pplayer_citizen->slot, -1);
3953 }
3954 city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
3955 city_refresh_vision(pcity_from);
3956 if (city_refresh(pcity_from)) {
3957 auto_arrange_workers(pcity_from);
3958 }
3959 }
3960
3961 /* This should be _before_ the size of the city is increased. Thus, the
3962 * order of the messages is correct (1: migration; 2: increased size). */
3963 if (pplayer_from == pplayer_to) {
3964 /* migration between one nation */
3965 notify_player(pplayer_from, ptile_to, E_CITY_TRANSFER, ftc_server,
3966 /* TRANS: From <city1> to <city2>. */
3967 _("Migrants from %s moved to %s in search of a better "
3968 "life."), name_from, name_to);
3969 } else {
3970 /* migration between different nations */
3971 notify_player(pplayer_from, ptile_to, E_CITY_TRANSFER, ftc_server,
3972 /* TRANS: From <city1> to <city2> (<city2 nation adjective>). */
3973 _("Migrants from %s moved to %s (%s) in search of a "
3974 "better life."),
3975 name_from, name_to, nation_to);
3976 notify_player(pplayer_to, ptile_to, E_CITY_TRANSFER, ftc_server,
3977 /* TRANS: From <city1> (<city1 nation adjective>) to <city2>. */
3978 _("Migrants from %s (%s) moved to %s in search of a "
3979 "better life."),
3980 name_from, nation_from, name_to);
3981 }
3982
3983 /* Increase size of receiver city */
3984 if (city_exist(to_id)) {
3985 bool incr_success = city_increase_size(pcity_to);
3986
3987 if (city_exist(to_id)) {
3988 city_refresh_after_city_size_increase(pcity_to, pplayer_citizen);
3989 city_refresh_vision(pcity_to);
3990 if (city_refresh(pcity_to)) {
3991 auto_arrange_workers(pcity_to);
3992 }
3993 if (incr_success) {
3994 script_server_signal_emit("city_size_change", pcity_to,
3995 (lua_Integer)1, "migration_to");
3996 }
3997 }
3998 }
3999
4000 log_debug("[M] T%d migration successful (%s -> %s)",
4001 game.info.turn, name_from, name_to);
4002
4003 return TRUE;
4004}
4005
4006/**********************************************************************/
4028{
4029 bool internat = FALSE;
4030
4031 if (!game.server.migration) {
4032 return FALSE;
4033 }
4034
4036 || (game.server.mgr_worldchance <= 0
4037 && game.server.mgr_nationchance <= 0)) {
4038 return FALSE;
4039 }
4040
4041 /* check for migration */
4042 players_iterate(pplayer) {
4043 if (!pplayer->cities) {
4044 continue;
4045 }
4046
4047 if (check_city_migrations_player(pplayer)) {
4048 internat = TRUE;
4049 }
4051
4052 return internat;
4053}
4054
4055/**********************************************************************/
4059bool city_empty_food_stock(struct city *pcity) {
4060 struct player *pplayer = city_owner(pcity);
4061 struct tile *ptile = city_tile(pcity);
4062
4063 fc_assert_ret_val(pcity != NULL, FALSE);
4064
4065 if (pcity->food_stock > 0) {
4066 pcity->food_stock = 0;
4067
4068 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4069 /* TRANS: %s is a city name */
4070 _("All stored food destroyed in %s."), city_link(pcity));
4071
4072 return TRUE;
4073 }
4074
4075 return FALSE;
4076}
4077
4078/**********************************************************************/
4081static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
4082{
4083 struct player *pplayer = city_owner(pcity);
4084 struct tile *ptile = city_tile(pcity);
4085 bool had_internal_effect = FALSE;
4086
4087 log_debug("%s at %s", disaster_rule_name(pdis), city_name_get(pcity));
4088
4089 notify_player(pplayer, ptile, E_DISASTER,
4090 ftc_server,
4091 /* TRANS: Disasters such as Earthquake */
4092 _("%s was hit by %s."), city_name_get(pcity),
4094
4095 if (disaster_has_effect(pdis, DE_POLLUTION)) {
4096 if (place_pollution(pcity, EC_POLLUTION)) {
4097 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4098 _("Pollution near %s."), city_link(pcity));
4099 had_internal_effect = TRUE;
4100 }
4101 }
4102
4103 if (disaster_has_effect(pdis, DE_FALLOUT)) {
4104 if (place_pollution(pcity, EC_FALLOUT)) {
4105 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4106 _("Fallout near %s."), city_link(pcity));
4107 had_internal_effect = TRUE;
4108 }
4109 }
4110
4111 if (disaster_has_effect(pdis, DE_REDUCE_DESTROY)
4112 || (disaster_has_effect(pdis, DE_REDUCE_POP)
4113 && pcity->size > 1)) {
4114 if (!city_reduce_size(pcity, 1, NULL, "disaster")) {
4115 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4116 /* TRANS: "Industrial Accident destroys Bogota entirely." */
4117 _("%s destroys %s entirely."),
4118 disaster_name_translation(pdis), city_link(pcity));
4119 pcity = NULL;
4120 } else {
4121 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4122 /* TRANS: "Nuclear Accident ... Montreal." */
4123 _("%s causes population loss in %s."),
4124 disaster_name_translation(pdis), city_link(pcity));
4125 }
4126
4127 had_internal_effect = TRUE;
4128 }
4129
4130 if (pcity && disaster_has_effect(pdis, DE_DESTROY_BUILDING)) {
4131 int total = 0;
4132 struct impr_type *imprs[B_LAST];
4133
4134 city_built_iterate(pcity, pimprove) {
4135 if (is_improvement(pimprove)
4136 && !improvement_has_flag(pimprove, IF_DISASTER_PROOF)) {
4137 imprs[total++] = pimprove;
4138 }
4140
4141 if (total > 0) {
4142 int num = fc_rand(total);
4143
4144 building_lost(pcity, imprs[num], "disaster", NULL);
4145
4146 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4147 /* TRANS: second %s is the name of a city improvement */
4148 _("%s destroys %s in %s."),
4150 improvement_name_translation(imprs[num]),
4151 city_link(pcity));
4152
4153 had_internal_effect = TRUE;
4154 }
4155 }
4156
4157 if (pcity && disaster_has_effect(pdis, DE_EMPTY_FOODSTOCK)) {
4158 if (city_empty_food_stock(pcity)) {
4159 had_internal_effect = TRUE;
4160 }
4161 }
4162
4163 if (pcity && disaster_has_effect(pdis, DE_EMPTY_PRODSTOCK)) {
4164 if (pcity->shield_stock > 0) {
4165 char prod[256];
4166
4167 pcity->shield_stock = 0;
4168 nullify_prechange_production(pcity); /* Make it impossible to recover */
4169
4170 universal_name_translation(&pcity->production, prod, sizeof(prod));
4171 notify_player(pplayer, ptile, E_DISASTER, ftc_server,
4172 /* TRANS: "Production of Colossus in Rhodes destroyed." */
4173 _("Production of %s in %s destroyed."),
4174 prod, city_link(pcity));
4175
4176 had_internal_effect = TRUE;
4177 }
4178 }
4179
4180 script_server_signal_emit("disaster_occurred", pdis, pcity,
4181 had_internal_effect);
4182 script_server_signal_emit("disaster", pdis, pcity);
4183}
4184
4185/**********************************************************************/
4189{
4190 if (game.info.disasters == 0) {
4191 /* Shortcut out as no disaster is possible. */
4192 return;
4193 }
4194
4195 players_iterate(pplayer) {
4196 /* Safe city iterator needed as disaster may destroy city */
4197 city_list_iterate_safe(pplayer->cities, pcity) {
4198 int id = pcity->id;
4199
4200 disaster_type_iterate(pdis) {
4201 if (city_exist(id)) {
4202 /* City survived earlier disasters. */
4203 int probability = game.info.disasters * pdis->frequency;
4204 int result = fc_rand(DISASTER_BASE_RARITY);
4205
4206 if (result < probability) {
4207 if (can_disaster_happen(pdis, pcity)) {
4208 apply_disaster(pcity, pdis);
4209 }
4210 }
4211 }
4215}
4216
4217/**********************************************************************/
4225static bool check_city_migrations_player(const struct player *pplayer)
4226{
4227 char city_link_text[MAX_LEN_LINK];
4228 float best_city_player_score, best_city_world_score;
4229 struct city *best_city_player, *best_city_world, *acity;
4230 float score_from, score_tmp, weight;
4231 int dist, mgr_dist;
4232 bool internat = FALSE;
4233
4234 /* check for each city
4235 * city_list_iterate_safe_end must be used because we could
4236 * remove one city from the list */
4237 city_list_iterate_safe(pplayer->cities, pcity) {
4238 /* no migration out of the capital */
4239 if (is_capital(pcity)) {
4240 continue;
4241 }
4242
4243 /* check only each (game.server.mgr_turninterval) turn
4244 * (counted from the funding turn) and do not migrate
4245 * the same turn a city is founded */
4246 if (game.info.turn == pcity->turn_founded
4247 || ((game.info.turn - pcity->turn_founded)
4248 % game.server.mgr_turninterval) != 0) {
4249 continue;
4250 }
4251
4252 best_city_player_score = 0.0;
4253 best_city_world_score = 0.0;
4254 best_city_player = NULL;
4255 best_city_world = NULL;
4256
4257 /* score of the actual city
4258 * taking into account a persistence factor of 3 */
4259 score_from = city_migration_score(pcity) * 3;
4260
4261 log_debug("[M] T%d check city: %s score: %6.3f (%s)",
4262 game.info.turn, city_name_get(pcity), score_from,
4263 player_name(pplayer));
4264
4265 /* consider all cities within the maximal possible distance
4266 * (= CITY_MAP_MAX_RADIUS + GAME_MAX_MGR_DISTANCE) */
4267 iterate_outward(&(wld.map), city_tile(pcity),
4269 acity = tile_city(ptile);
4270
4271 if (!acity || acity == pcity) {
4272 /* no city or the city in the center */
4273 continue;
4274 }
4275
4276 /* Calculate the migration distance. The value of
4277 * game.server.mgr_distance is added to the current city radius. If the
4278 * distance between both cities is lower or equal than this value,
4279 * migration is possible. */
4280 mgr_dist = (int)sqrt((double)MAX(city_map_radius_sq_get(acity),0))
4282
4283 /* distance between the two cities */
4284 dist = real_map_distance(city_tile(pcity), city_tile(acity));
4285
4286 if (dist > mgr_dist) {
4287 /* to far away */
4288 continue;
4289 }
4290
4291 /* score of the second city, weighted by the distance */
4292 weight = ((float) (mgr_dist + 1 - dist) / (float) (mgr_dist + 1));
4293 score_tmp = city_migration_score(acity) * weight;
4294
4295 log_debug("[M] T%d - compare city: %s (%s) dist: %d mgr_dist: %d "
4296 "score: %6.3f", game.info.turn, city_name_get(acity),
4297 player_name(city_owner(acity)), dist, mgr_dist, score_tmp);
4298
4299 if (game.server.mgr_nationchance > 0 && city_owner(acity) == pplayer) {
4300 /* migration between cities of the same owner */
4301 if (score_tmp > score_from && score_tmp > best_city_player_score) {
4302 /* select the best! */
4303 best_city_player_score = score_tmp;
4304 best_city_player = acity;
4305
4306 log_debug("[M] T%d - best city (player): %s (%s) score: "
4307 "%6.3f (> %6.3f)", game.info.turn,
4308 city_name_get(best_city_player), player_name(pplayer),
4309 best_city_player_score, score_from);
4310 }
4311 } else if (game.server.mgr_worldchance > 0
4312 && city_owner(acity) != pplayer) {
4313 /* migration between cities of different owners */
4315 /* Modify the score if citizens could migrate to a city of their
4316 * original nation. */
4317 if (citizens_nation_get(pcity, city_owner(acity)->slot) > 0) {
4318 score_tmp *= 2;
4319 }
4320 }
4321
4322 if (score_tmp > score_from && score_tmp > best_city_world_score) {
4323 /* select the best! */
4324 best_city_world_score = score_tmp;
4325 best_city_world = acity;
4326
4327 log_debug("[M] T%d - best city (world): %s (%s) score: "
4328 "%6.3f (> %6.3f)", game.info.turn,
4329 city_name_get(best_city_world),
4330 player_name(city_owner(best_city_world)),
4331 best_city_world_score, score_from);
4332 }
4333 }
4335
4336 if (best_city_player != NULL) {
4337 /* First, do the migration within one nation */
4338 if (fc_rand(100) >= game.server.mgr_nationchance) {
4339 /* No migration */
4340 /* N.B.: city_link always returns the same pointer. */
4341 sz_strlcpy(city_link_text, city_link(pcity));
4342 notify_player(pplayer, city_tile(pcity), E_CITY_TRANSFER, ftc_server,
4343 _("Citizens of %s are thinking about migrating to %s "
4344 "for a better life."),
4345 city_link_text, city_link(best_city_player));
4346 } else {
4347 do_city_migration(pcity, best_city_player);
4348 }
4349
4350 /* Stop here */
4351 continue;
4352 }
4353
4354 if (best_city_world != NULL) {
4355 /* Second, do the migration between all nations */
4356 if (fc_rand(100) >= game.server.mgr_worldchance) {
4357 const char *nname;
4358
4359 nname = nation_adjective_for_player(city_owner(best_city_world));
4360 /* No migration */
4361 /* N.B.: city_link always returns the same pointer. */
4362 sz_strlcpy(city_link_text, city_link(pcity));
4363 notify_player(pplayer, city_tile(pcity), E_CITY_TRANSFER, ftc_server,
4364 /* TRANS: <city1> to <city2> (<city2 nation adjective>). */
4365 _("Citizens of %s are thinking about migrating to %s "
4366 "(%s) for a better life."),
4367 city_link_text, city_link(best_city_world), nname);
4368 } else {
4369 do_city_migration(pcity, best_city_world);
4370 internat = TRUE;
4371 }
4372
4373 /* Stop here */
4374 continue;
4375 }
4377
4378 return internat;
4379}
4380
4381/**********************************************************************/
4384void city_style_refresh(struct city *pcity)
4385{
4386 pcity->style = city_style(pcity);
4387}
4388
4389/**********************************************************************/
4392void city_tc_effect_refresh(struct player *pplayer)
4393{
4394 const struct civ_map *nmap = &(wld.map);
4395
4396 city_list_iterate(pplayer->cities, pcity) {
4397 bool changed = FALSE;
4398
4400 city_tile(pcity), ptile, idx, x, y) {
4401 if (ptile->worked == pcity
4402 && get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) {
4403 city_map_update_empty(pcity, ptile);
4404 pcity->specialists[DEFAULT_SPECIALIST]++;
4405 changed = TRUE;
4406 }
4408
4409 if (changed) {
4410 auto_arrange_workers(pcity);
4411 send_city_info(NULL, pcity);
4412 }
4414}
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:120
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:658
int city_granary_size(int city_size)
Definition city.c:2104
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:300
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1216
bool is_capital(const struct city *pcity)
Definition city.c:1552
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3284
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1231
int city_airlift_max(const struct city *pcity)
Definition city.c:2844
struct output_type * get_output_type(Output_type_id output)
Definition city.c:633
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3301
void city_size_add(struct city *pcity, int add)
Definition city.c:1142
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:712
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:789
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:839
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:96
bool city_rapture_grow(const struct city *pcity)
Definition city.c:1626
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:805
bool city_unhappy(const struct city *pcity)
Definition city.c:1599
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3247
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1652
bool city_celebrating(const struct city *pcity)
Definition city.c:1618
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:815
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2772
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:1985
void city_refresh_from_main_map(const struct civ_map *nmap, struct city *pcity, bool *workers_map)
Definition city.c:3070
bool city_happy(const struct city *pcity)
Definition city.c:1587
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3270
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
static int cmp(int v1, int v2)
Definition city.c:320
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1259
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:888
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:991
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:927
int city_map_tiles(int city_radius_sq)
Definition city.c:166
bool city_exist(int id)
Definition city.c:3471
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1429
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:732
void city_rally_point_clear(struct city *pcity)
Definition city.c:3525
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:856
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2825
bool city_can_change_build(const struct city *pcity)
Definition city.c:1057
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:948
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1198
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1179
#define cities_iterate_end
Definition city.h:497
#define city_list_iterate_safe(citylist, _city)
Definition city.h:502
@ CNA_BROADCAST_PENDING
Definition city.h:300
@ CNA_NOT
Definition city.h:298
@ CNA_NORMAL
Definition city.h:299
#define city_list_iterate(citylist, pcity)
Definition city.h:488
#define city_tile(_pcity_)
Definition city.h:544
#define cities_iterate(pcity)
Definition city.h:492
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, _tile, _index, _x, _y)
Definition city.h:206
@ CITIZEN_ANGRY
Definition city.h:263
@ CITIZEN_HAPPY
Definition city.h:260
@ CITIZEN_CONTENT
Definition city.h:261
@ CITIZEN_UNHAPPY
Definition city.h:262
#define output_type_iterate(output)
Definition city.h:821
#define INCITE_IMPOSSIBLE_COST
Definition city.h:88
#define city_owner(_pcity_)
Definition city.h:543
#define city_tile_iterate_skip_free_worked_end
Definition city.h:214
#define city_list_iterate_end
Definition city.h:490
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:222
#define city_list_iterate_safe_end
Definition city.h:524
@ FEELING_FINAL
Definition city.h:276
#define city_tile_iterate_end
Definition city.h:230
#define CITY_MAP_MAX_RADIUS
Definition city.h:71
#define city_built_iterate(_pcity, _p)
Definition city.h:810
#define city_built_iterate_end
Definition city.h:816
#define output_type_iterate_end
Definition city.h:827
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3164
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2327
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:854
void sync_cities(void)
Definition citytools.c:3238
static void void city_freeze_workers(struct city *pcity)
Definition citytools.c:135
bool city_map_update_radius_sq(struct city *pcity)
Definition citytools.c:3363
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Definition citytools.c:3075
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2884
void city_thaw_workers(struct city *pcity)
Definition citytools.c:145
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:2977
void city_units_upkeep(const struct city *pcity)
Definition citytools.c:3026
void remove_city(struct city *pcity)
Definition citytools.c:1684
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Definition citytools.c:2910
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2849
void broadcast_city_info(struct city *pcity)
Definition citytools.c:2217
void city_map_update_all(struct city *pcity)
Definition citytools.c:3257
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:719
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Definition citytools.c:3178
void city_refresh_vision(struct city *pcity)
Definition citytools.c:3338
#define LOG_BUILD_TARGET
Definition citytools.h:21
static bool city_illness_check(const struct city *pcity)
Definition cityturn.c:3573
static void uk_rem_gold_append(struct unit *punit)
Definition cityturn.c:2914
static bool worklist_change_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2038
void remove_obsolete_buildings(struct player *pplayer)
Definition cityturn.c:273
static bool city_build_stuff(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2815
static void city_reset_foodbox(struct city *pcity, int new_size)
Definition cityturn.c:937
static void apply_disaster(struct city *pcity, struct disaster_type *pdis)
Definition cityturn.c:4081
static bool city_distribute_surplus_shields(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2373
int city_granary_savings(const struct city *pcity)
Definition cityturn.c:924
static void unit_list_referred_destroy(struct unit_list *punitlist)
Definition cityturn.c:2927
static bool place_pollution(struct city *pcity, enum extra_cause cause)
Definition cityturn.c:3215
void choose_build_target(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2236
static void uk_rem_gold_callback(struct unit *punit)
Definition cityturn.c:2893
void auto_arrange_workers(struct city *pcity)
Definition cityturn.c:369
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:200
static struct unit_list * uk_rem_gold
Definition cityturn.c:93
static bool city_balance_treasury_buildings(struct city *pcity)
Definition cityturn.c:3133
static void update_city_activity(struct city *pcity)
Definition cityturn.c:3392
static void upgrade_unit_prod(struct city *pcity)
Definition cityturn.c:2349
static float city_migration_score(struct city *pcity)
Definition cityturn.c:3698
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3383
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4059
bool check_city_migrations(void)
Definition cityturn.c:4027
static void upgrade_building_prod(struct city *pcity)
Definition cityturn.c:2302
bool city_change_size(struct city *pcity, citizens size, struct player *nationality, const char *reason)
Definition cityturn.c:1061
static citizens city_reduce_specialists(struct city *pcity, citizens change)
Definition cityturn.c:764
static void city_global_turn_notify(struct conn_list *dest)
Definition cityturn.c:493
static void city_populate(struct city *pcity, struct player *nationality)
Definition cityturn.c:1112
static void city_refresh_after_city_size_increase(struct city *pcity, struct player *nationality)
Definition cityturn.c:1027
static void define_orig_production_values(struct city *pcity)
Definition cityturn.c:3352
void city_repair_size(struct city *pcity, int change)
Definition cityturn.c:897
#define cityimpr_list_iterate(cityimprlist, pcityimpr)
Definition cityturn.c:127
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:732
static bool city_build_building(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2454
static struct unit static const struct impr_type * building_upgrades_to(struct city *pcity, const struct impr_type *pimprove)
Definition cityturn.c:2281
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:579
static struct unit * sell_random_unit(struct player *pplayer, struct unit_list *punitlist)
Definition cityturn.c:2950
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3271
static void nullify_caravan_and_disband_plus(struct city *pcity)
Definition cityturn.c:3373
static bool sell_random_building(struct player *pplayer, struct cityimpr_list *imprs)
Definition cityturn.c:2847
static bool disband_city(struct city *pcity)
Definition cityturn.c:3586
void update_city_activities(struct player *pplayer)
Definition cityturn.c:605
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:808
#define cityimpr_list_iterate_end
Definition cityturn.c:129
bool city_refresh(struct city *pcity)
Definition cityturn.c:161
static void city_turn_notify(const struct city *pcity, struct conn_list *dest, const struct player *cache_for_player)
Definition cityturn.c:514
static bool city_increase_size(struct city *pcity)
Definition cityturn.c:950
void apply_cmresult_to_city(struct city *pcity, const struct cm_result *cmr)
Definition cityturn.c:284
void city_style_refresh(struct city *pcity)
Definition cityturn.c:4384
static bool city_balance_treasury_units(struct city *pcity)
Definition cityturn.c:3180
static const struct unit_type * unit_upgrades_to(struct city *pcity, const struct unit_type *id)
Definition cityturn.c:2327
static bool do_city_migration(struct city *pcity_from, struct city *pcity_to)
Definition cityturn.c:3782
static struct city_list * city_refresh_queue
Definition cityturn.c:87
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:185
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4392
static void check_pollution(struct city *pcity)
Definition cityturn.c:3254
void check_disasters(void)
Definition cityturn.c:4188
static void set_default_city_manager(struct cm_parameter *cmp, struct city *pcity)
Definition cityturn.c:316
static citizens city_reduce_workers(struct city *pcity, citizens change)
Definition cityturn.c:784
static bool worklist_item_postpone_req_vec(struct universal *target, struct city *pcity, struct player *pplayer, int saved_id)
Definition cityturn.c:1187
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:2606
static bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3034
void city_refresh_queue_processing(void)
Definition cityturn.c:216
void remove_obsolete_buildings_city(struct city *pcity, bool refresh)
Definition cityturn.c:238
static bool check_city_migrations_player(const struct player *pplayer)
Definition cityturn.c:4225
static bool city_build_unit(struct player *pplayer, struct city *pcity)
Definition cityturn.c:2659
static bool player_balance_treasury_units(struct player *pplayer)
Definition cityturn.c:3097
void cm_clear_cache(struct city *pcity)
Definition cm.c:320
void cm_init_parameter(struct cm_parameter *dest)
Definition cm.c:2181
struct cm_result * cm_result_new(struct city *pcity)
Definition cm.c:343
void cm_result_destroy(struct cm_result *result)
Definition cm.c:366
void cm_print_result(const struct cm_result *result)
Definition cm.c:2467
void cm_query_result(struct city *pcity, const struct cm_parameter *param, struct cm_result *result, bool negative_ok)
Definition cm.c:2120
void cm_init_emergency_parameter(struct cm_parameter *dest)
Definition cm.c:2199
void cm_print_city(const struct city *pcity)
Definition cm.c:2429
struct player * conn_get_player(const struct connection *pconn)
Definition connection.c:760
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:365
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:355
int city_culture(const struct city *pcity)
Definition culture.c:29
int city_history_gain(const struct city *pcity)
Definition culture.c:37
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:73
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:73
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:80
#define DISASTER_BASE_RARITY
Definition disaster.h:44
#define disaster_type_iterate_end
Definition disaster.h:86
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
int get_current_construction_bonus(const struct city *pcity, enum effect_type effect_type, const enum req_problem_type prob_type)
Definition effects.c:1104
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:838
struct extra_type * rand_extra_for_tile(struct tile *ptile, enum extra_cause cause, bool generated)
Definition extras.c:267
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
#define MAX_CITY_NATIONALITIES
Definition fc_types.h:79
int Tech_type_id
Definition fc_types.h:347
unsigned char citizens
Definition fc_types.h:358
@ RPT_CERTAIN
Definition fc_types.h:586
@ RPT_POSSIBLE
Definition fc_types.h:585
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_SHIELD
Definition fc_types.h:91
@ O_FOOD
Definition fc_types.h:91
@ O_TRADE
Definition fc_types.h:91
@ O_SCIENCE
Definition fc_types.h:91
@ O_LUXURY
Definition fc_types.h:91
@ O_GOLD
Definition fc_types.h:91
enum output_type_id Output_type_id
Definition fc_types.h:348
#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:57
struct world wld
Definition game.c:58
struct city * game_city_by_number(int id)
Definition game.c:102
#define GAME_MAX_MGR_DISTANCE
Definition game.h:511
const char * government_name_translation(const struct government *pgovern)
Definition government.c:142
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:390
struct government * government_of_city(const struct city *pcity)
Definition government.c:122
Government_type_id government_number(const struct government *pgovern)
Definition government.c:90
GType type
Definition repodlgs.c:1312
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:454
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)
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:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_msg(condition, message,...)
Definition log.h:205
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
#define log_base(level, message,...)
Definition log.h:94
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:628
int map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:652
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
Definition map.h:361
#define iterate_outward_end
Definition map.h:365
void map_update_border(struct tile *ptile, struct player *owner, int old_radius_sq, int new_radius_sq)
Definition maphand.c:2238
void map_claim_border(struct tile *ptile, struct player *owner, int radius_sq)
Definition maphand.c:2270
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1427
#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:137
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:148
struct nation_type * nation_of_city(const struct city *pcity)
Definition nation.c:453
const char * nation_group_name_translation(const struct nation_group *pgroup)
Definition nation.c:1089
const char * nation_plural_translation(const struct nation_type *pnation)
Definition nation.c:158
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
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_chat_msg(struct conn_list *dest, const struct packet_chat_msg *packet)
struct city_list * cities
Definition packhand.c:117
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1179
const char * diplrel_name_translation(int value)
Definition player.c:1591
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:430
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
#define is_ai(plr)
Definition player.h:234
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
#define fc_rand(_size)
Definition rand.h:34
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
const char * universal_rule_name(const struct universal *psource)
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:271
struct research * research_get(const struct player *pplayer)
Definition research.c:126
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
int research_pretty_name(const struct research *presearch, char *buf, size_t buf_len)
Definition research.c:167
#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:1378
#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:128
@ 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
#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:309
int turn_last_built
Definition city.h:373
int surplus[O_LAST]
Definition city.h:343
int food_stock
Definition city.h:354
struct player * original
Definition city.h:313
int history
Definition city.h:393
int pollution
Definition city.h:356
bool did_sell
Definition city.h:367
int id
Definition city.h:315
int last_turns_shield_surplus
Definition city.h:378
int disbanded_shields
Definition city.h:377
int workers_frozen
Definition city.h:420
bool was_happy
Definition city.h:368
struct player * owner
Definition city.h:312
int airlift
Definition city.h:365
int caravan_shields
Definition city.h:376
bool did_buy
Definition city.h:366
int anarchy
Definition city.h:370
enum city_needs_arrange needs_arrange
Definition city.h:424
struct worklist worklist
Definition city.h:387
struct universal production
Definition city.h:382
struct unit_order * orders
Definition city.h:405
struct city::@16 rally_point
citizens * nationality
Definition city.h:329
bool vigilant
Definition city.h:404
citizens size
Definition city.h:320
int illness
Definition city.h:417
int before_change_shields
Definition city.h:375
int style
Definition city.h:316
size_t length
Definition city.h:400
float migration_score
Definition city.h:414
bool needs_refresh
Definition city.h:428
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:321
citizens specialists[SP_MAX]
Definition city.h:324
struct tile * tile
Definition city.h:311
int shield_stock
Definition city.h:355
int prod[O_LAST]
Definition city.h:346
struct city::@17::@19 server
struct cm_parameter * cm_parameter
Definition city.h:408
bool debug
Definition city.h:433
struct universal changed_from
Definition city.h:385
struct unit_list * units_supported
Definition city.h:391
int mgr_score_calc_turn
Definition city.h:415
int illness_trade
Definition city.h:357
bool persistent
Definition city.h:402
int rapture
Definition city.h:371
struct city * pcity
Definition cityturn.c:119
struct impr_type * pimprove
Definition cityturn.c:120
int mgr_worldchance
Definition game.h:161
int incite_total_factor
Definition game.h:149
struct civ_game::@30::@34 server
int mgr_nationchance
Definition game.h:159
bool mgr_foodneeded
Definition game.h:158
int base_incite_cost
Definition game.h:133
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
int mgr_turninterval
Definition game.h:160
bool migration
Definition game.h:163
int incite_improvement_factor
Definition game.h:148
int aqueductloss
Definition game.h:128
int incite_unit_factor
Definition game.h:150
int mgr_distance
Definition game.h:157
Definition cm.h:52
bool found_a_valid
Definition cm.h:54
bool * worker_positions
Definition cm.h:59
citizens specialists[SP_MAX]
Definition cm.h:60
struct conn_list * self
Definition connection.h:168
struct requirement_vector reqs
Definition improvement.h:75
enum gold_upkeep_style gold_upkeep_style
int infra_points
Definition player.h:74
int units_built
Definition player.h:111
enum spaceship_state state
Definition spaceship.h:108
struct city_list * cities
Definition player.h:281
int bulbs_last_turn
Definition player.h:351
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
struct player::@69::@71 server
const struct player * player
Definition tile.h:49
struct unit_list * units
Definition tile.h:57
struct requirement_vector build_reqs
Definition unittype.h:501
const struct unit_type * obsoleted_by
Definition unittype.h:510
struct advance * require_advance
Definition unittype.h:500
Definition unit.h:138
int length
Definition unit.h:195
int upkeep[O_LAST]
Definition unit.h:148
bool has_orders
Definition unit.h:193
int id
Definition unit.h:145
bool vigilant
Definition unit.h:197
struct unit::@79 orders
struct unit_order * list
Definition unit.h:198
struct unit::@80::@83 server
int upkeep_paid[O_LAST]
Definition unit.h:254
const struct unit_type * utype
Definition unit.h:139
enum universals_n kind
Definition fc_types.h:758
universals_u value
Definition fc_types.h:757
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:167
#define fc__attribute(x)
Definition support.h:89
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
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:1361
void give_immediate_free_tech(struct research *presearch, Tech_type_id tech)
Definition techtools.c:1380
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech)
Definition techtools.c:643
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:940
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_worked(_tile)
Definition tile.h:117
#define tile_has_extra(ptile, pextra)
Definition tile.h:150
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_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)
bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood, struct unit *punit)
#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:604
const struct impr_type * building
Definition fc_types.h:598
bool unit_is_alive(int id)
Definition unit.c:2245
#define unit_tile(_pu)
Definition unit.h:395
#define unit_cargo_iterate_end
Definition unit.h:570
#define unit_cargo_iterate(_ptrans, _pcargo)
Definition unit.h:567
#define unit_owner(_pu)
Definition unit.h:394
#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:1782
bool place_unit(struct unit *punit, struct player *pplayer, struct city *pcity, struct unit *ptrans, bool force)
Definition unittools.c:1724
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:1676
void unit_unset_removal_callback(struct unit *punit)
Definition unittools.c:1796
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2248
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:1528
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:1639
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1580
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1490
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604
#define U_NOT_OBSOLETED
Definition unittype.h:509
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