Freeciv-3.1: /fast/freeciv/nightly/S3_1/server/cityturn.c Source File

Freeciv-3.1

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