Freeciv-3.2: /fast/freeciv/nightly/S3_2/server/cityturn.c Source File

Freeciv-3.2

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