Freeciv-3.2
Loading...
Searching...
No Matches
city.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 <stdlib.h>
19#include <string.h>
20#include <math.h> /* pow, sqrt, exp */
21
22/* utility */
23#include "distribute.h"
24#include "fcintl.h"
25#include "log.h"
26#include "mem.h"
27#include "support.h"
28
29/* common */
30#include "ai.h"
31#include "citizens.h"
32#include "counters.h"
33#include "effects.h"
34#include "game.h"
35#include "government.h"
36#include "improvement.h"
37#include "map.h"
38#include "movement.h"
39#include "packets.h"
40#include "specialist.h"
41#include "traderoutes.h"
42#include "unit.h"
43
44/* aicore */
45#include "cm.h"
46
47#include "city.h"
48
49/* Define this to add in extra (very slow) assertions for the city code. */
50#undef CITY_DEBUGGING
51
52static char *citylog_map_line(int y, int city_radius_sq, int *city_map_data);
53#ifdef FREECIV_DEBUG
54/* Only used for debugging */
55static void citylog_map_index(enum log_level level);
56static void citylog_map_radius_sq(enum log_level level);
57#endif /* FREECIV_DEBUG */
58
59/* Get city tile informations using the city tile index. */
61/* Get city tile informations using the city tile coordinates. This is an
62 * [x][y] array of integer values corresponding to city_map_index. The
63 * coordinates x and y are in the range [0, CITY_MAP_MAX_SIZE] */
65
66/* Number of tiles of a city; depends on the squared city radius */
68
69/* Definitions and functions for the tile_cache */
70struct tile_cache {
72};
73
74static inline void city_tile_cache_update(struct city *pcity);
75static inline int city_tile_cache_get_output(const struct city *pcity,
77 enum output_type_id o);
78
79static const struct city *nearest_gov_center(const struct city *pcity,
80 int *min_dist)
81 fc__attribute((nonnull (1, 2)));
82
84
85/* One day these values may be read in from the ruleset. In the meantime
86 * they're just an easy way to access information about each output type. */
88 {O_FOOD, N_("Food"), "food", TRUE, UNHAPPY_PENALTY_SURPLUS},
89 {O_SHIELD, N_("Shield"), "shield", TRUE, UNHAPPY_PENALTY_SURPLUS},
90 {O_TRADE, N_("Trade"), "trade", TRUE, UNHAPPY_PENALTY_NONE},
91 {O_GOLD, N_("Gold"), "gold", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION},
92 {O_LUXURY, N_("Luxury"), "luxury", FALSE, UNHAPPY_PENALTY_NONE},
93 {O_SCIENCE, N_("Science"), "science", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION}
94};
95
96/**********************************************************************/
101 int city_tile_index, int city_radius_sq)
102{
105
106 /* tile indices are sorted from smallest to largest city radius */
107 if (city_tile_index < 0
108 || city_tile_index >= city_map_tiles(city_radius_sq)) {
109 return FALSE;
110 }
111
114
115 return TRUE;
116}
117
118/**********************************************************************/
123 int city_radius_sq)
124{
125 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, 0);
126 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, 0);
128 city_map_y), 0);
129
131}
132
133/**********************************************************************/
136int city_map_radius_sq_get(const struct city *pcity)
137{
138 /* a save return value is only the minimal squared radius */
140
141 return pcity->city_radius_sq;
142}
143
144/**********************************************************************/
147void city_map_radius_sq_set(struct city *pcity, int radius_sq)
148{
151
152 pcity->city_radius_sq = radius_sq;
153}
154
155/**********************************************************************/
165
166/**********************************************************************/
170int city_map_tiles(int city_radius_sq)
171{
172 if (city_radius_sq == CITY_MAP_CENTER_RADIUS_SQ) {
173 /* special case: city center; first tile of the city map */
174 return 0;
175 }
176
177 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, -1);
178 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, -1);
179
180 return city_map_numtiles[city_radius_sq];
181}
182
183/**********************************************************************/
187bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
188 const int city_map_y)
189{
190 /* The city's valid positions are in a circle around the city center.
191 * Depending on the value for the squared city radius the circle will be:
192 *
193 * - rectangular (max radius = 5; max squared radius = 26)
194 *
195 * 0 1 2 3 4 5 6 7 8 9 10
196 *
197 * 0 26 25 26 -5
198 * 1 25 20 17 16 17 20 25 -4
199 * 2 25 18 13 10 9 10 13 18 25 -3
200 * 3 20 13 8 5 4 5 8 13 20 -2
201 * 4 26 17 10 5 2 1 2 5 10 17 26 -1
202 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
203 * 6 26 17 10 5 2 1 2 5 10 17 26 +1
204 * 7 20 13 8 5 4 5 8 13 20 +2
205 * 8 25 18 13 10 9 10 13 18 25 +3
206 * 9 25 20 17 16 17 20 25 +4
207 * 10 26 25 26 +5
208 *
209 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
210 *
211 * - hexagonal (max radius = 5; max squared radius = 26)
212 *
213 * 0 1 2 3 4 5 6 7 8 9 10
214 *
215 * 0 25 25 25 25 25 25 -5
216 * 1 25 16 16 16 16 16 25 -4
217 * 2 25 16 9 9 9 9 16 25 -3
218 * 3 25 16 9 4 4 4 9 16 25 -2
219 * 4 25 16 9 4 1 1 4 9 16 25 -1
220 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
221 * 6 25 16 9 4 1 1 4 9 16 25 +1
222 * 7 25 16 9 4 4 4 9 16 25 +2
223 * 8 25 16 9 9 9 9 16 25 +3
224 * 9 25 16 16 16 16 16 25 +4
225 * 10 25 25 25 25 25 25 +5
226 *
227 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
228 *
229 * The following tables show the tiles per city radii / squared city radii.
230 * '-' indicates no change compared to the previous value
231 *
232 * radius | 0 | 1 | | | 2 | | | | | 3
233 * radius_sq | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
234 * ------------------+----+----+----+----+----+----+----+----+----+----
235 * tiles rectangular | 5 | 9 | - | 13 | 21 | - | - | 25 | 29 | 37
236 * tiles hexagonal | 7 | - | - | 19 | - | - | - | - | 37 | -
237 *
238 * radius | | | | | | | 4 | | |
239 * radius_sq | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
240 * ------------------+----+----+----+----+----+----+----+----+----+----
241 * tiles rectangular | - | - | 45 | - | - | 49 | 57 | 61 | - | 69
242 * tiles hexagonal | - | - | - | - | - | 61 | - | - | - | -
243 *
244 * radius | | | | | | 5
245 * radius_sq | 21 | 22 | 23 | 24 | 25 | 26
246 * ------------------+----+----+----+----+----+----
247 * tiles rectangular | - | - | - | - | 81 | 89
248 * tiles hexagonal | - | - | - | - | 91 | -
249 *
250 * So radius_sq == 5 (radius == 2) corresponds to the "traditional"
251 * used city map.
252 */
255
256 return dist <= city_radius_sq;
257}
258
259/**********************************************************************/
264 const int city_radius_sq,
265 const struct tile *city_center,
266 const struct tile *map_tile)
267{
269
272
273 return is_valid_city_coords(city_radius_sq, *city_map_x, *city_map_y);
274}
275
276/**********************************************************************/
281 const struct city *const pcity,
282 const struct tile *map_tile)
283{
285 city_map_radius_sq_get(pcity), pcity->tile,
286 map_tile);
287}
288
289/**********************************************************************/
292bool city_map_includes_tile(const struct city *const pcity,
293 const struct tile *map_tile)
294{
295 int tmp_x, tmp_y;
296
297 return city_base_to_city_map(&tmp_x, &tmp_y, pcity, map_tile);
298}
299
300/**********************************************************************/
304struct tile *city_map_to_tile(const struct civ_map *nmap,
305 const struct tile *city_center,
306 int city_radius_sq, int city_map_x,
307 int city_map_y)
308{
309 int tile_x, tile_y;
310
312 city_map_y), NULL);
313
314 index_to_map_pos(&tile_x, &tile_y, tile_index(city_center));
317
319}
320
321/**********************************************************************/
324static int cmp(int v1, int v2)
325{
326 if (v1 == v2) {
327 return 0;
328 } else if (v1 > v2) {
329 return 1;
330 } else {
331 return -1;
332 }
333}
334
335/**********************************************************************/
342int compare_iter_index(const void *a, const void *b)
343{
344 const struct iter_index *index1 = a, *index2 = b;
345 int value;
346
347 value = cmp(index1->dist, index2->dist);
348 if (value != 0) {
349 return value;
350 }
351
352 value = cmp(index1->dx, index2->dx);
353 if (value != 0) {
354 return value;
355 }
356
357 value = cmp(index1->dy, index2->dy);
358 fc_assert(0 != value);
359 return value;
360}
361
362/**********************************************************************/
367#define CITYLOG_MAX_VAL 9999 /* maximal value displayed in the citylog */
368static char *citylog_map_line(int y, int city_radius_sq, int *city_map_data)
369{
370 int x, mindex;
371 static char citylog[128], tmp[8];
372
374
375 /* print y coordinates (absolut) */
376 fc_snprintf(citylog, sizeof(citylog), "%2d ", y);
377
378 /* print values */
379 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
380 if (is_valid_city_coords(city_radius_sq, x, y)) {
381 mindex = city_tile_xy_to_index(x, y, city_radius_sq);
382 /* show values between -10000 and +10000 */
385 fc_snprintf(tmp, sizeof(tmp), "%5d", city_map_data[mindex]);
387 } else {
388 fc_snprintf(tmp, sizeof(tmp), " ####");
390 }
391 } else {
392 fc_snprintf(tmp, sizeof(tmp), " ");
394 }
395 }
396
397 /* print y coordinates (relativ) */
398 fc_snprintf(tmp, sizeof(tmp), " %+4d", CITY_ABS2REL(y));
400
401 return citylog;
402}
403#undef CITYLOG_MAX_VAL
404
405/**********************************************************************/
410void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
411{
412 int x, y;
413 char line[128], tmp[8];
414
416 return;
417 }
418
419 log_base(level, "(max squared city radius = %d)", CITY_MAP_MAX_RADIUS_SQ);
420
421 /* print x coordinates (absolut) */
422 fc_snprintf(line, sizeof(line), " ");
423 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
424 fc_snprintf(tmp, sizeof(tmp), "%+5d", x);
426 }
427 log_base(level, "%s", line);
428
429 for (y = 0; y < CITY_MAP_MAX_SIZE; y++) {
430 log_base(level, "%s", citylog_map_line(y, radius_sq, map_data));
431 }
432
433 /* print x coordinates (relativ) */
434 fc_snprintf(line, sizeof(line), " ");
435 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
436 fc_snprintf(tmp, sizeof(tmp), "%+5d", CITY_ABS2REL(x));
438 }
439 log_base(level, "%s", line);
440}
441
442/**********************************************************************/
445void citylog_map_workers(enum log_level level, struct city *pcity)
446{
447 int *city_map_data = NULL;
448 const struct civ_map *nmap = &(wld.map);
449
450 fc_assert_ret(pcity != NULL);
451
453 return;
454 }
455
457 sizeof(*city_map_data));
458
459 city_map_iterate(city_map_radius_sq_get(pcity), cindex, x, y) {
460 struct tile *ptile = city_map_to_tile(nmap,
461 city_tile(pcity),
463 x, y);
464 city_map_data[cindex] = (ptile && tile_worked(ptile) == pcity)
465 ? (is_free_worked_index(cindex) ? 2 : 1) : 0;
467
468 log_base(level, "[%s (%d)] workers map:", city_name_get(pcity), pcity->id);
471}
472
473#ifdef FREECIV_DEBUG
474/**********************************************************************/
477static void citylog_map_index(enum log_level level)
478{
479 int *city_map_data = NULL;
480
482 return;
483 }
484
486 sizeof(*city_map_data));
487
489 city_map_data[cindex] = cindex;
491
492 log_debug("city map index:");
495}
496
497/**********************************************************************/
500static void citylog_map_radius_sq(enum log_level level)
501{
502 int *city_map_data = NULL;
503
505 return;
506 }
507
509 sizeof(*city_map_data));
510
513 CITY_ABS2REL(y));
515
516 log_debug("city map squared radius:");
519}
520#endif /* FREECIV_DEBUG */
521
522/**********************************************************************/
527{
528 int i, dx, dy, city_x, city_y, dist, city_count_tiles = 0;
531
532 /* initialise map information for each city radii */
533 for (i = 0; i <= CITY_MAP_MAX_RADIUS_SQ; i++) {
534 city_map_numtiles[i] = 0; /* will be set below */
535 }
536
537 /* We don't use city-map iterators in this function because they may
538 * rely on the indices that have not yet been generated. Furthermore,
539 * we don't know the number of tiles within the city radius, so we need
540 * an temporary city_map_index array. Its content will be copied into
541 * the real array below. */
545
550
551 for (i = CITY_MAP_MAX_RADIUS_SQ; i >= 0; i--) {
552 if (dist <= i) {
553 /* increase number of tiles within this squared city radius */
555 }
556 }
557
559 }
560
561 /* Initialise city_map_xy. -1 defines a invalid city map positions. */
563 }
564 }
565
568
569 /* copy the index numbers from city_map_index_tmp into city_map_index */
570 for (i = 0; i < city_count_tiles; i++) {
572 }
573
576
577 /* set the static variable city_map_xy */
578 for (i = 0; i < city_count_tiles; i++) {
582 }
583
584#ifdef FREECIV_DEBUG
587
589 log_debug("radius_sq = %2d, tiles = %2d", i, city_map_tiles(i));
590 }
591
592 for (i = 0; i < city_count_tiles; i++) {
595 log_debug("[%2d]: (dx,dy) = (%+2d,%+2d), (x,y) = (%2d,%2d), "
596 "dist = %2d, check = %2d", i,
599 }
600#endif /* FREECIV_DEBUG */
601
603}
604
605/**********************************************************************/
609{
611}
612
613/**********************************************************************/
619{
620 fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
621 return output_types[output].id;
622}
623
624/**********************************************************************/
629{
630 fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
631 return _(output_types[output].name);
632}
633
634/**********************************************************************/
638{
639 fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
640 return &output_types[output];
641}
642
643/**********************************************************************/
647{
649
650 for (o = 0; o < O_LAST; o++) {
651 if (fc_strcasecmp(output_types[o].id, id) == 0) {
652 return o;
653 }
654 }
655
656 return O_LAST;
657}
658
659/**********************************************************************/
662const char *city_improvement_name_translation(const struct city *pcity,
663 const struct impr_type *pimprove)
664{
665 static char buffer[256];
666 const char *state = NULL;
667
668 if (is_great_wonder(pimprove)) {
669 if (great_wonder_is_available(pimprove)) {
670 state = Q_("?wonder:W");
671 } else if (great_wonder_is_destroyed(pimprove)) {
672 state = Q_("?destroyed:D");
673 } else {
674 state = Q_("?built:B");
675 }
676 }
677 if (pcity) {
678 struct player *pplayer = city_owner(pcity);
679
680 if (improvement_obsolete(pplayer, pimprove, pcity)) {
681 state = Q_("?obsolete:O");
682 } else if (is_improvement_redundant(pcity, pimprove)) {
683 state = Q_("?redundant:*");
684 }
685 }
686
687 if (state) {
688 fc_snprintf(buffer, sizeof(buffer), "%s(%s)",
689 improvement_name_translation(pimprove), state);
690 return buffer;
691 } else {
692 return improvement_name_translation(pimprove);
693 }
694}
695
696/**********************************************************************/
699const char *city_production_name_translation(const struct city *pcity)
700{
701 static char buffer[256];
702
703 switch (pcity->production.kind) {
704 case VUT_IMPROVEMENT:
706 default:
707 /* fallthru */
708 break;
709 };
710 return universal_name_translation(&pcity->production, buffer, sizeof(buffer));
711}
712
713/**********************************************************************/
716bool city_production_is_genus(const struct city *pcity,
717 enum impr_genus_id genus)
718{
719 return VUT_IMPROVEMENT == pcity->production.kind
720 && (pcity->production.value.building->genus == genus);
721}
722
723/**********************************************************************/
726bool city_production_has_flag(const struct city *pcity,
727 enum impr_flag_id flag)
728{
729 return VUT_IMPROVEMENT == pcity->production.kind
731}
732
733/**********************************************************************/
737{
738 return universal_build_shield_cost(pcity, &pcity->production);
739}
740
741/**********************************************************************/
746bool city_production_build_units(const struct city *pcity,
747 bool add_production, int *num_units)
748{
749 const struct unit_type *utype;
750 struct universal target;
751 int build_slots = city_build_slots(pcity);
752 int shields_left = pcity->shield_stock;
753 int unit_shield_cost, i;
754
756 (*num_units) = 0;
757
758 if (pcity->production.kind != VUT_UTYPE) {
759 /* not a unit as the current production */
760 return FALSE;
761 }
762
763 utype = pcity->production.value.utype;
764 if (utype_pop_value(utype, pcity) != 0 || utype_has_flag(utype, UTYF_UNIQUE)) {
765 /* unit with population cost or unique unit means that only one unit can
766 * be build */
767 (*num_units)++;
768 return FALSE;
769 }
770
771 if (add_production) {
772 shields_left += pcity->prod[O_SHIELD];
773 }
774
776
777 for (i = 0; i < build_slots; i++) {
779 /* not enough shields */
780 break;
781 }
782
783 (*num_units)++;
785
786 if (worklist_length(&pcity->worklist) > i) {
787 (void) worklist_peek_ith(&pcity->worklist, &target, i);
788 if (target.kind != VUT_UTYPE
789 || utype_index(target.value.utype) != utype_index(utype)) {
790 /* stop if there is a build target in the worklist not equal to the
791 * unit we build */
792 break;
793 }
794 }
795 }
796
797 return TRUE;
798}
799
800/************************************************************************/
804 const struct unit_type *punittype)
805{
806 int levels = get_unittype_bonus(city_owner(pcity), pcity->tile, punittype,
809
810 levels = CLIP(0, levels, max_levels);
811
812 return levels;
813}
814
815/**********************************************************************/
819int city_production_turns_to_build(const struct city *pcity,
821{
823}
824
825/**********************************************************************/
830 const struct impr_type *pimprove)
831{
832 if (!can_player_build_improvement_direct(city_owner(pcity), pimprove)) {
833 return FALSE;
834 }
835
836 if (city_has_building(pcity, pimprove)) {
837 return FALSE;
838 }
839
840 return are_reqs_active(&(const struct req_context) {
841 .player = city_owner(pcity),
842 .city = pcity,
843 .tile = pcity->tile,
844 },
845 NULL,
846 &(pimprove->reqs), RPT_CERTAIN);
847}
848
849/**********************************************************************/
853bool can_city_build_improvement_now(const struct city *pcity,
854 const struct impr_type *pimprove)
855{
856 if (!can_city_build_improvement_direct(pcity, pimprove)) {
857 return FALSE;
858 }
859 if (improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
860 return FALSE;
861 }
862
863 return TRUE;
864}
865
866/**********************************************************************/
870bool can_city_build_improvement_later(const struct city *pcity,
871 const struct impr_type *pimprove)
872{
873 const struct req_context city_ctxt = {
874 .player = city_owner(pcity),
875 .city = pcity,
876 .tile = city_tile(pcity),
877 };
878
879 /* Can the _player_ ever build this improvement? */
880 /* NOTE: It checks for obsoletion player-level. What aboult checking
881 * for it city-level? That may unlist from a worklist some things
882 * we'll be able to switch to after e.g. selling something else */
883 if (!can_player_build_improvement_later(city_owner(pcity), pimprove)) {
884 return FALSE;
885 }
886
887 /* Check for requirements that aren't met and that are unchanging (so
888 * they can never be met). */
891 return FALSE;
892 }
894
895 return TRUE;
896}
897
898/**********************************************************************/
902bool can_city_build_unit_direct(const struct city *pcity,
903 const struct unit_type *punittype)
904{
906 return FALSE;
907 }
908
909 /* Check unit build requirements.
910 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
911 * Don't recheck those. Not only for optimization, but also not to override the
912 * special handling of tech requirements for barbarians */
913 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
915 &(const struct req_context) {
916 .player = city_owner(pcity),
917 .city = pcity,
918 .tile = city_tile(pcity),
919 .unittype = punittype,
920 },
921 NULL,
922 &punittype->build_reqs, RPT_CERTAIN)) {
923 return FALSE;
924 }
925
926 /* You can't build naval units inland. */
929 pcity->tile)) {
930 return FALSE;
931 }
932
933 if (punittype->city_slots > 0
934 && city_unit_slots_available(pcity) < punittype->city_slots) {
935 return FALSE;
936 }
937
938 return TRUE;
939}
940
941/**********************************************************************/
945bool can_city_build_unit_now(const struct city *pcity,
946 const struct unit_type *punittype)
947{
949 return FALSE;
950 }
951 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
952 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
953 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
955 return FALSE;
956 }
957 }
958 return TRUE;
959}
960
961/**********************************************************************/
965bool can_city_build_unit_later(const struct city *pcity,
966 const struct unit_type *punittype)
967{
968 /* Can the _player_ ever build this unit? */
970 return FALSE;
971 }
972
973 /* Some units can be built only in certain cities -- for instance,
974 ships may be built only in cities adjacent to ocean. */
977 pcity->tile)) {
978 return FALSE;
979 }
980
981 return TRUE;
982}
983
984/**********************************************************************/
988bool can_city_build_direct(const struct city *pcity,
989 const struct universal *target)
990{
991 switch (target->kind) {
992 case VUT_UTYPE:
993 return can_city_build_unit_direct(pcity, target->value.utype);
994 case VUT_IMPROVEMENT:
995 return can_city_build_improvement_direct(pcity, target->value.building);
996 default:
997 break;
998 };
999 return FALSE;
1000}
1001
1002/**********************************************************************/
1006bool can_city_build_now(const struct city *pcity,
1007 const struct universal *target)
1008{
1009 switch (target->kind) {
1010 case VUT_UTYPE:
1011 return can_city_build_unit_now(pcity, target->value.utype);
1012 case VUT_IMPROVEMENT:
1013 return can_city_build_improvement_now(pcity, target->value.building);
1014 default:
1015 break;
1016 };
1017 return FALSE;
1018}
1019
1020/**********************************************************************/
1023bool can_city_build_later(const struct city *pcity,
1024 const struct universal *target)
1025{
1026 switch (target->kind) {
1027 case VUT_UTYPE:
1028 return can_city_build_unit_later(pcity, target->value.utype);
1029 case VUT_IMPROVEMENT:
1030 return can_city_build_improvement_later(pcity, target->value.building);
1031 default:
1032 break;
1033 };
1034 return FALSE;
1035}
1036
1037/**********************************************************************/
1040int city_unit_slots_available(const struct city *pcity)
1041{
1042 int max = get_city_bonus(pcity, EFT_UNIT_SLOTS);
1043 int current;
1044
1045 current = 0;
1047 current += unit_type_get(punit)->city_slots;
1049
1050 return max - current;
1051}
1052
1053/**********************************************************************/
1056bool city_can_use_specialist(const struct city *pcity,
1058{
1059 return are_reqs_active(&(const struct req_context) {
1060 .player = city_owner(pcity),
1061 .city = pcity,
1062 },
1063 NULL,
1065}
1066
1067/**********************************************************************/
1070bool city_can_change_build(const struct city *pcity)
1071{
1072 return !pcity->did_buy || pcity->shield_stock <= 0;
1073}
1074
1075/**********************************************************************/
1079{
1080 if (NULL == city_tile(pcity)) {
1081 /* When a "dummy" city is created with no tile, then choosing a build
1082 * target could fail. This currently might happen during map editing.
1083 * FIXME: assumes the first unit is always "valid", so check for
1084 * obsolete units elsewhere. */
1085 pcity->production.kind = VUT_UTYPE;
1087 } else {
1088 struct unit_type *u = best_role_unit(pcity, L_FIRSTBUILD);
1089
1090 if (u) {
1091 pcity->production.kind = VUT_UTYPE;
1092 pcity->production.value.utype = u;
1093 } else {
1094 bool found = FALSE;
1095
1096 /* Just pick the first available item. */
1097 improvement_iterate(pimprove) {
1098 if (can_city_build_improvement_direct(pcity, pimprove)) {
1099 found = TRUE;
1101 pcity->production.value.building = pimprove;
1102 break;
1103 }
1105
1106 if (!found) {
1109#ifndef FREECIV_NDEBUG
1110 /* Later than this, 'found' is only needed in an fc_assert() */
1111 found = TRUE;
1112#endif /* FREECIV_NDEBUG */
1113 pcity->production.kind = VUT_UTYPE;
1115 }
1117 }
1118
1119 fc_assert_msg(found, "No production found for city %s!",
1120 city_name_get(pcity));
1121 }
1122 }
1123}
1124
1125/**********************************************************************/
1128const char *city_name_get(const struct city *pcity)
1129{
1130 return (pcity->name != NULL) ? pcity->name : "City missing a name";
1131}
1132
1133/**********************************************************************/
1136void city_name_set(struct city *pcity, const char *new_name)
1137{
1138 if (pcity->name != NULL) {
1139 free(pcity->name);
1140 }
1141
1142 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1143 pcity->name = fc_strdup(new_name);
1144 } else {
1145 log_warn(_("City name \"%s\" too long"), new_name);
1147 sz_strlcpy(pcity->name, new_name);
1148 }
1149}
1150
1151/**********************************************************************/
1155void city_size_add(struct city *pcity, int add)
1156{
1157 citizens size = city_size_get(pcity);
1158
1159 fc_assert_ret(pcity != NULL);
1161
1162 /* Client sets size to zero to start stacking citizens in */
1163 fc_assert_ret(size > -add || (!is_server() && size == add));
1164
1165 city_size_set(pcity, size + add);
1166}
1167
1168/**********************************************************************/
1171void city_size_set(struct city *pcity, citizens size)
1172{
1173 fc_assert_ret(pcity != NULL);
1174
1175 /* Set city size. */
1176 pcity->size = size;
1177}
1178
1179/**********************************************************************/
1182int city_population(const struct city *pcity)
1183{
1184 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1185 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1186}
1187
1188/**********************************************************************/
1192int city_total_impr_gold_upkeep(const struct city *pcity)
1193{
1194 int gold_needed = 0;
1195
1196 if (pcity == NULL) {
1197 return 0;
1198 }
1199
1200 city_built_iterate(pcity, pimprove) {
1201 gold_needed += city_improvement_upkeep(pcity, pimprove);
1203
1204 gold_needed -= get_city_bonus(pcity, EFT_IMPR_UPKEEP_REDUCTION);
1205
1206 return MAX(gold_needed, 0);
1207}
1208
1209/**********************************************************************/
1213int city_total_unit_gold_upkeep(const struct city *pcity)
1214{
1215 int gold_needed = 0;
1216
1217 if (pcity == NULL || pcity->units_supported == NULL) {
1218 return 0;
1219 }
1220
1222 gold_needed += punit->upkeep[O_GOLD];
1224
1225 return gold_needed;
1226}
1227
1228/**********************************************************************/
1231bool city_has_building(const struct city *pcity,
1232 const struct impr_type *pimprove)
1233{
1234 if (NULL == pimprove) {
1235 /* Callers should ensure that any external data is tested with
1236 * valid_improvement_by_number() */
1237 return FALSE;
1238 }
1239 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1240}
1241
1242/**********************************************************************/
1246int city_improvement_upkeep(const struct city *pcity,
1247 const struct impr_type *b)
1248{
1249 int upkeep;
1250
1251 if (NULL == b) {
1252 return 0;
1253 }
1254 if (!is_building_sellable(b)) {
1255 return 0;
1256 }
1257
1258 upkeep = b->upkeep;
1259 if (upkeep <= get_building_bonus(pcity, b, EFT_UPKEEP_FREE)) {
1260 return 0;
1261 }
1262
1263 return upkeep;
1264}
1265
1266/**********************************************************************/
1274int city_tile_output(const struct city *pcity, const struct tile *ptile,
1276{
1277 int prod;
1278 const struct req_context city_ctxt = {
1279 .player = pcity ? city_owner(pcity) : NULL,
1280 .city = pcity,
1281 .tile = ptile,
1282 };
1283 struct terrain *pterrain = tile_terrain(ptile);
1284 const struct output_type *output = &output_types[otype];
1285
1286 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1287
1288 if (T_UNKNOWN == pterrain) {
1289 /* Special case for the client. The server doesn't allow unknown tiles
1290 * to be worked but we don't necessarily know what player is involved. */
1291 return 0;
1292 }
1293
1294 prod = pterrain->output[otype];
1295 if (tile_resource_is_valid(ptile)) {
1296 prod += tile_resource(ptile)->data.resource->output[otype];
1297 }
1298
1299 switch (otype) {
1300 case O_SHIELD:
1301 if (pterrain->mining_shield_incr != 0) {
1302 prod += pterrain->mining_shield_incr
1304 / 100;
1305 }
1306 break;
1307 case O_FOOD:
1308 if (pterrain->irrigation_food_incr != 0) {
1309 prod += pterrain->irrigation_food_incr
1311 EFT_IRRIGATION_PCT) / 100;
1312 }
1313 break;
1314 case O_TRADE:
1315 case O_GOLD:
1316 case O_SCIENCE:
1317 case O_LUXURY:
1318 case O_LAST:
1319 break;
1320 }
1321
1322 prod += tile_roads_output_incr(ptile, otype);
1323 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1324
1325 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1326 if (prod > 0) {
1327 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1329
1330 if (prod >= game.info.granularity) {
1331 prod += get_tile_output_bonus(pcity, ptile, output,
1333
1334 if (is_celebrating) {
1335 prod += get_tile_output_bonus(pcity, ptile, output,
1337 }
1338 }
1339
1340 prod += (prod
1341 * get_tile_output_bonus(pcity, ptile, output,
1343 / 100;
1344 if (!is_celebrating && penalty_limit > 0 && prod > penalty_limit) {
1345 if (prod <= game.info.granularity) {
1346 prod = 0;
1347 } else {
1348 prod -= game.info.granularity;
1349 }
1350 }
1351 }
1352
1353 prod -= (prod
1354 * get_tile_output_bonus(pcity, ptile, output,
1356 / 100;
1357
1358 if (NULL != pcity && is_city_center(pcity, ptile)) {
1359 prod = MAX(prod, game.info.min_city_center_output[otype]);
1360 }
1361
1362 return prod;
1363}
1364
1365/**********************************************************************/
1375int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1377{
1378 return city_tile_output(pcity, ptile, city_celebrating(pcity), otype);
1379}
1380
1381/**********************************************************************/
1393 const struct city *pcity,
1394 const struct tile *ptile)
1395{
1396 struct player *powner = city_owner(pcity);
1398 struct player *towner;
1399
1400 if (NULL == ptile) {
1401 return FALSE;
1402 }
1403
1404 if (!city_base_to_city_map(&city_map_x, &city_map_y, pcity, ptile)) {
1405 return FALSE;
1406 }
1407
1408 if (NULL != restriction
1409 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1410 return FALSE;
1411 }
1412
1413 towner = tile_owner(ptile);
1414 if (NULL != towner && towner != powner
1415 && !gives_shared_tiles(towner, powner)) {
1416 return FALSE;
1417 }
1418 /* TODO: civ3-like option for borders */
1419
1420 if (NULL != tile_worked(ptile) && tile_worked(ptile) != pcity) {
1421 return FALSE;
1422 }
1423
1424 if (powner == restriction
1425 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1426 return FALSE;
1427 }
1428
1429 if (!is_free_worked(pcity, ptile)
1430 && NULL != unit_occupies_tile(ptile, powner)) {
1431 return FALSE;
1432 }
1433
1434 if (get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) {
1435 return FALSE;
1436 }
1437
1438 return TRUE;
1439}
1440
1441/**********************************************************************/
1447bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1448{
1449 return base_city_can_work_tile(city_owner(pcity), pcity, ptile);
1450}
1451
1452/**********************************************************************/
1457 const struct tile *ptile)
1458{
1459 /* citymindist minimum is 1, meaning adjacent is okay */
1460 int citymindist = game.info.citymindist;
1461
1462 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1463 if (tile_city(ptile1)) {
1464 return TRUE;
1465 }
1467
1468 return FALSE;
1469}
1470
1471/**********************************************************************/
1478bool city_can_be_built_here(const struct tile *ptile,
1479 const struct unit *punit,
1480 bool hut_test)
1481{
1482 struct civ_map *nmap = &(wld.map);
1483
1484 if (!city_can_be_built_tile_only(nmap, ptile)) {
1485 return FALSE;
1486 }
1487
1488 if (punit == NULL) {
1489 /* The remaining checks tests if punit can found a city here */
1490 return TRUE;
1491 }
1492
1493 if (hut_test) {
1494 struct player *towner;
1495
1496 /* Huts can be found only from native tiles, owned by the unit owner.
1497 * Unlike actual city building, this behavior is not affected
1498 * by the ruleset. */
1499 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1500 return FALSE;
1501 }
1502
1503 towner = tile_owner(ptile);
1504
1505 if (towner == NULL || towner == unit_owner(punit)) {
1506 return TRUE;
1507 }
1508
1509 return FALSE;
1510 }
1511
1514 /* This action can't be done by this unit type at all. */
1515 continue;
1516 }
1517
1518 /* Non native tile detection */
1519 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1520 /* The ruleset may allow founding cities on non native terrain. */
1523 /* Many rulesets allow land units to build land cities and sea units
1524 * to build ocean cities. Air units can build cities anywhere. */
1525 continue;
1526 }
1527
1528 /* Foreign tile detection. */
1529 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1530 /* The ruleset may allow founding cities on foreign terrain. */
1532 paction->id,
1533 DRO_FOREIGN, TRUE)) {
1534 /* Cannot steal borders by settling. This has to be settled by
1535 * force of arms. */
1536 continue;
1537 }
1538
1539 return TRUE;
1541
1542 return FALSE;
1543}
1544
1545/**********************************************************************/
1553 const struct tile *ptile)
1554{
1556 /* No cities on this terrain. */
1557 return FALSE;
1558 }
1559
1561 return FALSE;
1562 }
1563
1564 return TRUE;
1565}
1566
1567/**********************************************************************/
1571bool is_capital(const struct city *pcity)
1572{
1573 return pcity->capital != CAPITAL_NOT;
1574}
1575
1576/**********************************************************************/
1579bool is_gov_center(const struct city *pcity)
1580{
1581 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1582}
1583
1584/**********************************************************************/
1588bool city_got_defense_effect(const struct city *pcity,
1589 const struct unit_type *attacker)
1590{
1591 if (!attacker) {
1592 /* Any defense building will do */
1593 return get_city_bonus(pcity, EFT_DEFEND_BONUS) > 0;
1594 }
1595
1596 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1597 NULL, EFT_DEFEND_BONUS) > 0;
1598}
1599
1600/**********************************************************************/
1606bool city_happy(const struct city *pcity)
1607{
1608 return (city_size_get(pcity) >= game.info.celebratesize
1609 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1610 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1611 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1612}
1613
1614/**********************************************************************/
1618bool city_unhappy(const struct city *pcity)
1619{
1620 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1622 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1623}
1624
1625/**********************************************************************/
1629bool base_city_celebrating(const struct city *pcity)
1630{
1631 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1632}
1633
1634/**********************************************************************/
1637bool city_celebrating(const struct city *pcity)
1638{
1639 return base_city_celebrating(pcity) && city_happy(pcity);
1640}
1641
1642/**********************************************************************/
1645bool city_rapture_grow(const struct city *pcity)
1646{
1647 /* .rapture is checked instead of city_celebrating() because this
1648 function is called after .was_happy was updated. */
1649 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1650 && (pcity->rapture % game.info.rapturedelay) == 0
1651 && get_city_bonus(pcity, EFT_RAPTURE_GROW) > 0);
1652}
1653
1654/**********************************************************************/
1657bool city_is_occupied(const struct city *pcity)
1658{
1659 if (is_server()) {
1660 /* The server sees the units inside the city. */
1661 return (unit_list_size(city_tile(pcity)->units) > 0);
1662 } else {
1663 /* The client gets the occupied property from the server. */
1664 return pcity->client.occupied;
1665 }
1666}
1667
1668/**********************************************************************/
1671struct city *city_list_find_number(struct city_list *This, int id)
1672{
1673 if (id != 0) {
1674 city_list_iterate(This, pcity) {
1675 if (pcity->id == id) {
1676 return pcity;
1677 }
1679 }
1680
1681 return NULL;
1682}
1683
1684/**********************************************************************/
1687struct city *city_list_find_name(struct city_list *This, const char *name)
1688{
1689 city_list_iterate(This, pcity) {
1690 if (fc_strcasecmp(name, pcity->name) == 0) {
1691 return pcity;
1692 }
1694
1695 return NULL;
1696}
1697
1698/**********************************************************************/
1703int city_name_compare(const void *p1, const void *p2)
1704{
1705 return fc_strcasecmp((*(const struct city **) p1)->name,
1706 (*(const struct city **) p2)->name);
1707}
1708
1709/**********************************************************************/
1714{
1715 int i;
1716
1717 for (i = 0; i < game.control.num_city_styles; i++) {
1718 if (0 == strcmp(city_style_name_translation(i), s)) {
1719 return i;
1720 }
1721 }
1722
1723 return -1;
1724}
1725
1726/**********************************************************************/
1730int city_style_by_rule_name(const char *s)
1731{
1732 const char *qs = Qn_(s);
1733 int i;
1734
1735 for (i = 0; i < game.control.num_city_styles; i++) {
1736 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1737 return i;
1738 }
1739 }
1740
1741 return -1;
1742}
1743
1744/**********************************************************************/
1749{
1751}
1752
1753/**********************************************************************/
1757const char *city_style_rule_name(const int style)
1758{
1760}
1761
1762/* Cache of what city production caravan shields are allowed to help. */
1765
1766/**********************************************************************/
1771{
1772 struct requirement prod_as_req;
1773
1774#define log_ca_s_init log_debug
1775
1776 /* Remove old data. */
1779
1780 /* Common for all production kinds. */
1782 prod_as_req.survives = FALSE;
1783 prod_as_req.present = TRUE;
1784
1785 /* Check improvements */
1786 prod_as_req.source.kind = VUT_IMPROVEMENT;
1787
1789 /* Check this improvement. */
1790 prod_as_req.source.value.building = itype;
1791
1794 enabler) {
1796 &(enabler->target_reqs))
1797 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1798 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1799 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1800 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1801 /* This improvement kind can receive caravan shields. */
1802
1804
1805 /* Move on to the next improvement */
1806 break;
1807 }
1809
1810 log_ca_s_init("Help Wonder: %s for %s",
1812 ? "possible" : "impossible"),
1815
1816 /* Check units. */
1817 prod_as_req.source.kind = VUT_UTYPE;
1818
1820 /* Check this utype. */
1821 prod_as_req.source.value.utype = putype;
1822
1825 enabler) {
1827 &(enabler->target_reqs))
1828 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1829 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1830 /* This unit type kind can receive caravan shields. */
1831
1833
1834 /* Move on to the next unit type */
1835 break;
1836 }
1838
1839 log_ca_s_init("Help Wonder: %s for %s",
1841 ? "possible" : "impossible"),
1844
1845#undef log_ca_s_init
1846}
1847
1848/**********************************************************************/
1853{
1854 switch (tgt->kind) {
1855 case VUT_IMPROVEMENT:
1858 case VUT_UTYPE:
1860 utype_index(tgt->value.utype));
1861 default:
1863 return FALSE;
1864 };
1865}
1866
1867/**********************************************************************/
1878int city_change_production_penalty(const struct city *pcity,
1879 const struct universal *target)
1880{
1885
1886 switch (pcity->changed_from.kind) {
1887 case VUT_IMPROVEMENT:
1888 if (is_wonder(pcity->changed_from.value.building)) {
1890 } else {
1892 }
1893 break;
1894 case VUT_UTYPE:
1896 break;
1897 default:
1899 break;
1900 };
1901
1902 switch (target->kind) {
1903 case VUT_IMPROVEMENT:
1904 if (is_wonder(target->value.building)) {
1906 } else {
1908 }
1909 break;
1910 case VUT_UTYPE:
1912 break;
1913 default:
1915 break;
1916 };
1917
1918 /* Changing production is penalized under certain circumstances. */
1919 if (orig_class == new_class
1920 || orig_class == PCT_LAST) {
1921 /* There's never a penalty for building something of the same class. */
1923 } else if (city_built_last_turn(pcity)) {
1924 /* Surplus shields from the previous production won't be penalized if
1925 * you change production on the very next turn. But you can only use
1926 * up to the city's surplus amount of shields in this way. */
1928 pcity->before_change_shields);
1930 } else {
1931 /* Penalize 50% of the production. */
1933 }
1934
1935 /* Do not put penalty on these. It shouldn't matter whether you disband unit
1936 before or after changing production...*/
1938
1939 /* Caravan shields are penalized (just as if you disbanded the caravan)
1940 * if you're not building a wonder. */
1943 } else {
1945 }
1946
1949
1951}
1952
1953/**********************************************************************/
1957int city_turns_to_build(const struct city *pcity,
1958 const struct universal *target,
1960{
1961 int city_shield_surplus = pcity->surplus[O_SHIELD];
1963 city_change_production_penalty(pcity, target) : 0;
1964 int cost = universal_build_shield_cost(pcity, target);
1965
1966 if (target->kind == VUT_IMPROVEMENT
1967 && is_great_wonder(target->value.building)
1969 return FC_INFINITY;
1970 }
1971
1973 return 1;
1974 } else if (city_shield_surplus > 0) {
1975 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
1976 } else {
1977 return FC_INFINITY;
1978 }
1979}
1980
1981/**********************************************************************/
1988int city_turns_to_grow(const struct city *pcity)
1989{
1990 if (pcity->surplus[O_FOOD] > 0) {
1991 return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
1992 pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
1993 } else if (pcity->surplus[O_FOOD] < 0) {
1994 /* Turns before famine loss */
1995 return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
1996 } else {
1997 return FC_INFINITY;
1998 }
1999}
2000
2001/**********************************************************************/
2004bool city_can_grow_to(const struct city *pcity, int pop_size)
2005{
2006 return (get_city_bonus(pcity, EFT_SIZE_UNLIMIT) > 0
2007 || pop_size <= get_city_bonus(pcity, EFT_SIZE_ADJ));
2008}
2009
2010/**********************************************************************/
2013struct city *tile_enemy_city(const struct tile *ptile,
2014 const struct player *pplayer)
2015{
2016 struct city *pcity = tile_city(ptile);
2017
2018 if (pcity != NULL && pplayers_at_war(pplayer, city_owner(pcity))) {
2019 return pcity;
2020 }
2021
2022 return NULL;
2023}
2024
2025/**********************************************************************/
2028struct city *tile_allied_city(const struct tile *ptile,
2029 const struct player *pplayer)
2030{
2031 struct city *pcity = tile_city(ptile);
2032
2033 if (pcity != NULL && pplayers_allied(pplayer, city_owner(pcity))) {
2034 return pcity;
2035 }
2036
2037 return NULL;
2038}
2039
2040/**********************************************************************/
2043struct city *tile_non_attack_city(const struct tile *ptile,
2044 const struct player *pplayer)
2045{
2046 struct city *pcity = tile_city(ptile);
2047
2048 if (pcity != NULL && pplayers_non_attack(pplayer, city_owner(pcity))) {
2049 return pcity;
2050 }
2051
2052 return NULL;
2053}
2054
2055/**********************************************************************/
2058struct city *tile_non_allied_city(const struct tile *ptile,
2059 const struct player *pplayer)
2060{
2061 struct city *pcity = tile_city(ptile);
2062
2063 if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) {
2064 return pcity;
2065 }
2066
2067 return NULL;
2068}
2069
2070/**********************************************************************/
2074 int distance)
2075{
2077 distance);
2078}
2079
2080/**********************************************************************/
2084 const struct tile *ptile,
2085 int distance)
2086{
2087 square_iterate(&(wld.map), ptile, distance, ptile1) {
2088 struct city *pcity = tile_city(ptile1);
2089
2090 if (pcity && pplayers_allied(owner, city_owner(pcity))) {
2091 return TRUE;
2092 }
2094
2095 return FALSE;
2096}
2097
2098/**********************************************************************/
2102bool city_exists_within_max_city_map(const struct tile *ptile,
2103 bool may_be_on_center)
2104{
2105 const struct civ_map *nmap = &(wld.map);
2106
2108 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2109 if (tile_city(ptile1)) {
2110 return TRUE;
2111 }
2112 }
2114
2115 return FALSE;
2116}
2117
2118/**********************************************************************/
2123int city_granary_size(int city_size)
2124{
2127 int base_value;
2128
2129 /* If the city has no citizens, there is no granary. */
2130 if (city_size == 0) {
2131 return 0;
2132 }
2133
2134 /* Granary sizes for the first food_inis citizens are given directly.
2135 * After that we increase the granary size by food_inc per citizen. */
2136 if (city_size > food_inis) {
2137 base_value = game.info.granary_food_ini[food_inis - 1];
2138 base_value += food_inc * (city_size - food_inis);
2139 } else {
2140 base_value = game.info.granary_food_ini[city_size - 1];
2141 }
2142
2143 return MAX(base_value * game.info.foodbox / 100, 1);
2144}
2145
2146/**********************************************************************/
2151static int player_base_citizen_happiness(const struct player *pplayer)
2152{
2153 int cities = city_list_size(pplayer->cities);
2154 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2157
2158 if (basis + step <= 0) {
2159 /* Value of zero means effect is inactive */
2160 return content;
2161 }
2162
2163 if (cities > basis) {
2164 content--;
2165 if (step != 0) {
2166 /* the first penalty is at (basis + 1) cities;
2167 the next is at (basis + step + 1), _not_ (basis + step) */
2168 content -= (cities - basis - 1) / step;
2169 }
2170 }
2171 return content;
2172}
2173
2174/**********************************************************************/
2178{
2179 int content = player_base_citizen_happiness(pplayer);
2180
2181 return CLIP(0, content, MAX_CITY_SIZE);
2182}
2183
2184/**********************************************************************/
2188{
2189 if (!game.info.angrycitizen) {
2190 return 0;
2191 } else {
2192 /* Create angry citizens only if we have a negative number of possible
2193 * content citizens. This can happen when empires grow really big. */
2194 int content = player_base_citizen_happiness(pplayer);
2195
2196 return CLIP(0, -content, MAX_CITY_SIZE);
2197 }
2198}
2199
2200/**********************************************************************/
2204{
2205 struct output_type *output = &output_types[otype];
2206 int bonus1 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
2208 int bonus2 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
2210
2211 return MAX(bonus1 * bonus2 / 100, 0);
2212}
2213
2214/**********************************************************************/
2218int get_city_tithes_bonus(const struct city *pcity)
2219{
2220 int tithes_bonus = 0;
2221
2222 if (get_city_bonus(pcity, EFT_HAPPINESS_TO_GOLD) <= 0) {
2223 return 0;
2224 }
2225
2228
2229 return tithes_bonus;
2230}
2231
2232/**********************************************************************/
2236void add_tax_income(const struct player *pplayer, int trade, int *output)
2237{
2238 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2239 unsigned rates[3];
2240 int result[3];
2241
2242 if (game.info.changable_tax) {
2243 rates[SCIENCE] = pplayer->economic.science;
2244 rates[LUXURY] = pplayer->economic.luxury;
2245 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2246 } else {
2250 }
2251
2252 /* ANARCHY */
2254 rates[SCIENCE] = 0;
2255 rates[LUXURY] = 100;
2256 rates[TAX] = 0;
2257 }
2258
2259 distribute(trade, 3, rates, result);
2260
2261 output[O_SCIENCE] += result[SCIENCE];
2262 output[O_GOLD] += result[TAX];
2263 output[O_LUXURY] += result[LUXURY];
2264}
2265
2266/**********************************************************************/
2270bool city_built_last_turn(const struct city *pcity)
2271{
2272 return pcity->turn_last_built + 1 >= game.info.turn;
2273}
2274
2275/**********************************************************************/
2278static const struct city *nearest_gov_center(const struct city *pcity,
2279 int *min_dist)
2280{
2281 const struct city *gov_center = NULL;
2282
2284
2285 /* Check the special case that city itself is gov center
2286 * before expensive iteration through all cities. */
2287 if (is_gov_center(pcity)) {
2288 *min_dist = 0;
2289 return pcity;
2290 } else {
2292 /* Do not recheck current city */
2293 if (gc != pcity && is_gov_center(gc)) {
2294 int dist = real_map_distance(gc->tile, pcity->tile);
2295
2296 if (dist < *min_dist) {
2297 gov_center = gc;
2298 *min_dist = dist;
2299 }
2300 }
2302 }
2303
2304 return gov_center;
2305}
2306
2307/**********************************************************************/
2315static inline void get_worked_tile_output(const struct city *pcity,
2316 int *output, bool *workers_map)
2317{
2318 bool is_worked;
2319#ifdef CITY_DEBUGGING
2321#endif
2322 struct tile *pcenter = city_tile(pcity);
2323 const struct civ_map *nmap = &(wld.map);
2324
2325 memset(output, 0, O_LAST * sizeof(*output));
2326
2329 if (workers_map == NULL) {
2330 struct city *pwork = tile_worked(ptile);
2331
2332 is_worked = (NULL != pwork && pwork == pcity);
2333 } else {
2334 is_worked = workers_map[city_tile_index];
2335 }
2336
2337 if (is_worked) {
2339#ifdef CITY_DEBUGGING
2340 /* This assertion never fails, but it's so slow that we disable
2341 * it by default. */
2343 == city_tile_output(pcity, ptile, is_celebrating, o));
2344#endif /* CITY_DEBUGGING */
2345 output[o] += city_tile_cache_get_output(pcity, city_tile_index, o);
2347 }
2349}
2350
2351/**********************************************************************/
2355void add_specialist_output(const struct city *pcity, int *output)
2356{
2358 int count = pcity->specialists[sp];
2359
2362
2363 output[stat_index] += count * amount;
2366}
2367
2368/**********************************************************************/
2377static inline void set_city_bonuses(struct city *pcity)
2378{
2380 pcity->bonus[o] = get_final_city_output_bonus(pcity, o);
2381 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2382 &output_types[o],
2384 /* Total bonus cannot be negative, as that could lead to unresolvable
2385 * negative balance. */
2386 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2388}
2389
2390/**********************************************************************/
2400static inline void city_tile_cache_update(struct city *pcity)
2401{
2403 int radius_sq = city_map_radius_sq_get(pcity);
2404 const struct civ_map *nmap = &(wld.map);
2405
2406 /* Initialize tile_cache if needed */
2407 if (pcity->tile_cache == NULL || pcity->tile_cache_radius_sq == -1
2408 || pcity->tile_cache_radius_sq != radius_sq) {
2409 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2410 city_map_tiles(radius_sq)
2411 * sizeof(*(pcity->tile_cache)));
2412 pcity->tile_cache_radius_sq = radius_sq;
2413 }
2414
2415 /* Any unreal tiles are skipped - these values should have been memset
2416 * to 0 when the city was created. */
2417 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2419 (pcity->tile_cache[city_tile_index]).output[o]
2420 = city_tile_output(pcity, ptile, is_celebrating, o);
2423}
2424
2425/**********************************************************************/
2429static inline int city_tile_cache_get_output(const struct city *pcity,
2430 int city_tile_index,
2431 enum output_type_id o)
2432{
2434 == city_map_radius_sq_get(pcity), 0);
2436
2437 return (pcity->tile_cache[city_tile_index]).output[o];
2438}
2439
2440/**********************************************************************/
2443static void set_surpluses(struct city *pcity)
2444{
2446 int surplus = pcity->prod[o] - pcity->usage[o];
2447
2448 /* Add 'surplus' waste to 'usage'. */
2449 if (surplus > 0) {
2450 struct output_type *output = get_output_type(o);
2454
2455 if (waste_by_rel_dist > 0) {
2456 int min_dist;
2457 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2458
2459 if (gov_center == NULL) {
2460 /* No gov center - no income */
2461 waste_level = 100;
2462 } else {
2463 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2465 }
2466 }
2467
2468 if (waste_level > 0) {
2469 if (waste_level < 100) {
2470 pcity->usage[o] += (surplus * waste_level / 100);
2471 } else {
2472 pcity->usage[o] = pcity->prod[o];
2473 }
2474 }
2475 }
2476
2477 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2479}
2480
2481/**********************************************************************/
2484static void happy_copy(struct city *pcity, enum citizen_feeling i)
2485{
2486 int c = 0;
2487
2488 for (; c < CITIZEN_LAST; c++) {
2489 pcity->feel[c][i] = pcity->feel[c][i - 1];
2490 }
2491}
2492
2493/**********************************************************************/
2496static void citizen_base_mood(struct city *pcity)
2497{
2498 struct player *pplayer = city_owner(pcity);
2499 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2500 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2501 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2502 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2503 citizens size = city_size_get(pcity);
2505
2506 /* This is the number of citizens that may start out content, depending
2507 * on empire size and game's city unhappysize. This may be bigger than
2508 * the size of the city, since this is a potential. */
2510 /* Similarly, this is the potential number of angry citizens. */
2512
2513 /* Create content citizens. Take specialists from their ranks. */
2514 *content = MAX(0, MIN(size, base_content) - spes);
2515
2516 /* Create angry citizens. Specialists never become angry. */
2517 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2518 *angry = MIN(base_angry, size - spes);
2519
2520 /* Create unhappy citizens. In the beginning, all who are not content,
2521 * specialists or angry are unhappy. This is changed by luxuries and
2522 * buildings later. */
2523 *unhappy = (size - spes - *content - *angry);
2524
2525 /* No one is born happy. */
2526 *happy = 0;
2527}
2528
2529/**********************************************************************/
2535static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2536{
2537 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2538 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2539 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2540 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2541
2542 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2543 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2544 (*angry)--;
2545 (*unhappy)++;
2547 }
2548 while (*luxuries >= game.info.happy_cost && *content > 0) {
2549 /* Upgrade content to happy: costs HAPPY_COST each. */
2550 (*content)--;
2551 (*happy)++;
2553 }
2554 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2555 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2556 * double the cost. */
2557 (*unhappy)--;
2558 (*happy)++;
2559 *luxuries -= 2 * game.info.happy_cost;
2560 }
2561 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2562 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2563 (*unhappy)--;
2564 (*content)++;
2566 }
2567}
2568
2569/**********************************************************************/
2572static inline void citizen_happy_luxury(struct city *pcity)
2573{
2574 int x = pcity->prod[O_LUXURY];
2575
2576 citizen_luxury_happy(pcity, &x);
2577}
2578
2579/**********************************************************************/
2582static inline void citizen_content_buildings(struct city *pcity)
2583{
2584 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2585 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2586 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2588
2589 /* make people content (but not happy):
2590 get rid of angry first, then make unhappy content. */
2591 while (faces > 0 && *angry > 0) {
2592 (*angry)--;
2593 (*unhappy)++;
2594 faces--;
2595 }
2596 while (faces > 0 && *unhappy > 0) {
2597 (*unhappy)--;
2598 (*content)++;
2599 faces--;
2600 }
2601}
2602
2603/**********************************************************************/
2606static inline void citizen_happiness_nationality(struct city *pcity)
2607{
2609 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_NATIONALITY];
2610 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_NATIONALITY];
2611
2614
2615 if (pct > 0) {
2616 int enemies = 0;
2617 int unhappy_inc;
2618 struct player *owner = city_owner(pcity);
2619
2620 citizens_foreign_iterate(pcity, pslot, nationality) {
2622 enemies += nationality;
2623 }
2625
2626 unhappy_inc = enemies * pct / 100;
2627
2628 /* First make content => unhappy, then happy => unhappy,
2629 * then happy => content. No-one becomes angry. */
2630 while (unhappy_inc > 0 && *content > 0) {
2631 (*content)--;
2632 (*unhappy)++;
2633 unhappy_inc--;
2634 }
2635 while (unhappy_inc > 1 && *happy > 0) {
2636 (*happy)--;
2637 (*unhappy)++;
2638 unhappy_inc -= 2;
2639 }
2640 while (unhappy_inc > 0 && *happy > 0) {
2641 (*happy)--;
2642 (*content)++;
2643 unhappy_inc--;
2644 }
2645 }
2646 }
2647}
2648
2649/**********************************************************************/
2655static inline void citizen_happy_units(struct city *pcity)
2656{
2657 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2658 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2659 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2660 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2661 citizens amt = pcity->martial_law;
2662
2663 /* Pacify discontent citizens through martial law. First convert
2664 * angry => unhappy, then unhappy => content. */
2665 while (amt > 0 && *angry > 0) {
2666 (*angry)--;
2667 (*unhappy)++;
2668 amt--;
2669 }
2670 while (amt > 0 && *unhappy > 0) {
2671 (*unhappy)--;
2672 (*content)++;
2673 amt--;
2674 }
2675
2676 /* Now make citizens unhappier because of military units away from home.
2677 * First make content => unhappy, then happy => unhappy,
2678 * then happy => content. */
2679 amt = pcity->unit_happy_upkeep;
2680 while (amt > 0 && *content > 0) {
2681 (*content)--;
2682 (*unhappy)++;
2683 amt--;
2684 }
2685 while (amt > 1 && *happy > 0) {
2686 (*happy)--;
2687 (*unhappy)++;
2688 amt -= 2;
2689 }
2690 while (amt > 0 && *happy > 0) {
2691 (*happy)--;
2692 (*content)++;
2693 amt--;
2694 }
2695 /* Any remaining unhappiness is lost since angry citizens aren't created
2696 * here. */
2697 /* FIXME: Why not? - Per */
2698}
2699
2700/**********************************************************************/
2703static inline void citizen_happy_wonders(struct city *pcity)
2704{
2705 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2706 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2707 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2708 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2709 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2710
2711 /* First create happy citizens from content, then from unhappy
2712 * citizens; we cannot help angry citizens here. */
2713 while (bonus > 0 && *content > 0) {
2714 (*content)--;
2715 (*happy)++;
2716 bonus--;
2717 }
2718 while (bonus > 1 && *unhappy > 0) {
2719 (*unhappy)--;
2720 (*happy)++;
2721 bonus -= 2;
2722 }
2723 /* The rest falls through and lets unhappy people become content. */
2724
2725 if (get_city_bonus(pcity, EFT_NO_UNHAPPY) > 0) {
2726 *content += *unhappy + *angry;
2727 *unhappy = 0;
2728 *angry = 0;
2729 return;
2730 }
2731
2732 bonus += get_city_bonus(pcity, EFT_FORCE_CONTENT);
2733
2734 /* get rid of angry first, then make unhappy content */
2735 while (bonus > 0 && *angry > 0) {
2736 (*angry)--;
2737 (*unhappy)++;
2738 bonus--;
2739 }
2740 while (bonus > 0 && *unhappy > 0) {
2741 (*unhappy)--;
2742 (*content)++;
2743 bonus--;
2744 }
2745}
2746
2747/**********************************************************************/
2751static inline void unhappy_city_check(struct city *pcity)
2752{
2753 if (city_unhappy(pcity)) {
2755 switch (output_types[o].unhappy_penalty) {
2757 pcity->unhappy_penalty[o] = 0;
2758 break;
2760 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2761 break;
2763 pcity->unhappy_penalty[o] = pcity->prod[o];
2764 break;
2765 }
2766
2767 pcity->prod[o] -= pcity->unhappy_penalty[o];
2769 } else {
2770 memset(pcity->unhappy_penalty, 0,
2771 O_LAST * sizeof(*pcity->unhappy_penalty));
2772 }
2773}
2774
2775/**********************************************************************/
2778int city_pollution_types(const struct city *pcity, int shield_total,
2779 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2780{
2781 int prod, pop, mod;
2782
2783 /* Add one one pollution per shield, multipled by the bonus. */
2784 prod = 100 + get_city_bonus(pcity, EFT_POLLU_PROD_PCT);
2785 prod = shield_total * MAX(prod, 0) / 100;
2786
2787 /* Add one pollution per citizen for baseline combined bonus (100%). */
2788 pop = (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT))
2789 * (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT_2))
2790 / 100;
2791 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2792
2793 /* Then there is base pollution (usually a negative number). */
2794 mod = game.info.base_pollution;
2795
2796 if (pollu_prod) {
2797 *pollu_prod = prod;
2798 }
2799 if (pollu_pop) {
2800 *pollu_pop = pop;
2801 }
2802 if (pollu_mod) {
2803 *pollu_mod = mod;
2804 }
2805 return MAX(prod + pop + mod, 0);
2806}
2807
2808/**********************************************************************/
2812int city_pollution(const struct city *pcity, int shield_total)
2813{
2815}
2816
2817/**********************************************************************/
2824static int get_trade_illness(const struct city *pcity)
2825{
2826 float illness_trade = 0.0;
2827
2829 if (trade_city->turn_plague != -1
2830 && game.info.turn - trade_city->turn_plague < 5) {
2831 illness_trade += (float)game.info.illness_trade_infection
2832 * sqrt(1.0 * city_size_get(pcity)
2833 * city_size_get(trade_city)) / 100.0;
2834 }
2836
2837 return (int)illness_trade;
2838}
2839
2840/**********************************************************************/
2844static int get_city_health(const struct city *pcity)
2845{
2846 return get_city_bonus(pcity, EFT_HEALTH_PCT);
2847}
2848
2849/**********************************************************************/
2861int city_illness_calc(const struct city *pcity, int *ill_base,
2862 int *ill_size, int *ill_trade, int *ill_pollution)
2863{
2864 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2866
2867 if (game.info.illness_on
2869 /* offset the city size by game.info.illness_min_size */
2871
2872 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2873 * 10.0 * game.info.illness_base_factor);
2874 if (is_server()) {
2875 /* on the server we recalculate the illness due to trade as we have
2876 * all informations */
2877 illness_trade = get_trade_illness(pcity);
2878 } else {
2879 /* on the client we have to rely on the value saved within the city
2880 * struct */
2881 illness_trade = pcity->illness_trade;
2882 }
2883
2886 }
2887
2888 illness_base = illness_size + illness_trade + illness_pollution;
2889 illness_percent = 100 - get_city_health(pcity);
2890
2891 /* returning other data */
2892 if (ill_size) {
2894 }
2895
2896 if (ill_trade) {
2897 *ill_trade = illness_trade;
2898 }
2899
2900 if (ill_pollution) {
2902 }
2903
2904 if (ill_base) {
2906 }
2907
2908 return CLIP(0, illness_base * illness_percent / 100 , 999);
2909}
2910
2911/**********************************************************************/
2914bool city_had_recent_plague(const struct city *pcity)
2915{
2916 /* Correctly handles special case turn_plague == -1 (never) */
2917 return (pcity->turn_plague == game.info.turn);
2918}
2919
2920/**********************************************************************/
2923int city_build_slots(const struct city *pcity)
2924{
2925 return get_city_bonus(pcity, EFT_CITY_BUILD_SLOTS);
2926}
2927
2928/**********************************************************************/
2933int city_airlift_max(const struct city *pcity)
2934{
2935 return get_city_bonus(pcity, EFT_AIRLIFT);
2936}
2937
2938/**********************************************************************/
2944inline void set_city_production(struct city *pcity)
2945{
2946 int trade;
2947
2948 /* Calculate city production!
2949 *
2950 * This is a rather complicated process if we allow rules to become
2951 * more generalized. We can assume that there are no recursive dependency
2952 * loops, but there are some dependencies that do not follow strict
2953 * ordering. For instance corruption must be calculated before
2954 * trade taxes can be counted up, which must occur before the science bonus
2955 * is added on. But the calculation of corruption must include the
2956 * trade bonus. To do this without excessive special casing means that in
2957 * this case the bonuses are multiplied on twice (but only saved the second
2958 * time).
2959 */
2960
2962 pcity->prod[o] = pcity->citizen_base[o];
2964
2965 /* Add on special extra incomes: trade routes and tithes. */
2967 struct city *tcity = game_city_by_number(proute->partner);
2968 bool can_trade;
2969
2970 /* Partner city may have not yet been sent to the client, or
2971 * there's just a placeholder city with a placeholder owner
2972 * created for some tile->worked. */
2973 if (!is_server()
2974 && (tcity == NULL
2975 || city_owner(tcity)->slot == NULL)) {
2976 continue;
2977 }
2978
2979 fc_assert_action(tcity != NULL, continue);
2980
2982
2983 if (!can_trade) {
2986
2987 if (settings->cancelling == TRI_ACTIVE) {
2988 can_trade = TRUE;
2989 }
2990 }
2991
2992 if (can_trade) {
2993 int value;
2994
2995 value =
2997 proute->value = trade_from_route(pcity, proute, value);
2998 pcity->prod[O_TRADE] += proute->value
2999 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3000 } else {
3001 proute->value = 0;
3002 }
3004 pcity->prod[O_GOLD] += get_city_tithes_bonus(pcity);
3005
3006 /* Account for waste. Note that waste is calculated before tax income is
3007 * calculated, so if you had "science waste" it would not include taxed
3008 * science. However waste is calculated after the bonuses are multiplied
3009 * on, so shield waste will include shield bonuses. */
3011 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3012
3013 prod = MAX(prod, 0);
3014 pcity->waste[o] = city_waste(pcity, o, prod, NULL);
3016
3017 /* Convert trade into science/luxury/gold, and add this on to whatever
3018 * science/luxury/gold is already there. */
3019 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3020 + pcity->abs_bonus[O_TRADE];
3021 trade = MAX(trade, 0);
3023 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3024 pcity->prod);
3025
3026 /* Add on effect bonuses and waste. Note that the waste calculation
3027 * (above) already includes the bonuses. */
3029 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3030
3031 prod = MAX(prod, 0);
3032 pcity->prod[o] = prod;
3033 pcity->prod[o] -= pcity->waste[o];
3035}
3036
3037/**********************************************************************/
3041{
3042 struct city *pcity;
3043 const struct unit_type *ut;
3044 struct player *plr;
3045 int happy_cost;
3046
3047 if (!punit || !free_unhappy) {
3048 return 0;
3049 }
3050
3052 if (pcity == NULL) {
3053 return 0;
3054 }
3055
3057 plr = unit_owner(punit);
3058 happy_cost = utype_happy_cost(ut, plr);
3059
3060 if (happy_cost <= 0) {
3061 return 0;
3062 }
3063
3065
3067 return 0;
3068 }
3069
3070 happy_cost -= get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL_PER);
3071 if (happy_cost <= 0) {
3072 return 0;
3073 }
3074
3075 if (*free_unhappy >= happy_cost) {
3076 *free_unhappy -= happy_cost;
3077 return 0;
3078 } else {
3079 happy_cost -= *free_unhappy;
3080 *free_unhappy = 0;
3081 }
3082
3083 return happy_cost;
3084}
3085
3086/**********************************************************************/
3090static inline void city_support(struct city *pcity)
3091{
3093
3094 /* Clear all usage values. */
3095 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3096 pcity->martial_law = 0;
3097 pcity->unit_happy_upkeep = 0;
3098
3099 /* Building and unit gold upkeep depends on the setting
3100 * 'game.info.gold_upkeep_style':
3101 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3102 * city.
3103 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3104 * The upkeep for units is paid by the nation.
3105 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3106 * nation. */
3108 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3109 switch (game.info.gold_upkeep_style) {
3110 case GOLD_UPKEEP_CITY:
3111 pcity->usage[O_GOLD] += city_total_unit_gold_upkeep(pcity);
3112 fc__fallthrough; /* No break */
3113 case GOLD_UPKEEP_MIXED:
3114 pcity->usage[O_GOLD] += city_total_impr_gold_upkeep(pcity);
3115 break;
3116 case GOLD_UPKEEP_NATION:
3117 /* nothing */
3118 break;
3119 }
3120 /* Food consumption by citizens. */
3121 pcity->usage[O_FOOD] += game.info.food_cost * city_size_get(pcity);
3122
3123 /* Military units in this city (need _not_ be home city) can make
3124 * unhappy citizens content */
3126 if (martial_law_each > 0) {
3127 int count = 0;
3129
3130 unit_list_iterate(pcity->tile->units, punit) {
3131 if ((count < martial_law_max || martial_law_max == 0)
3133 && unit_owner(punit) == city_owner(pcity)) {
3134 count++;
3135 }
3137
3138 pcity->martial_law = CLIP(0, count * martial_law_each, MAX_CITY_SIZE);
3139 }
3140
3145 if (O_GOLD != o) {
3146 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3147 pcity->usage[o] += punit->upkeep[o];
3148 }
3151}
3152
3153/**********************************************************************/
3165void city_refresh_from_main_map(struct city *pcity, bool *workers_map)
3166{
3167 if (workers_map == NULL) {
3168 /* do a full refresh */
3169
3170 /* Calculate the bonus[] array values. */
3171 set_city_bonuses(pcity);
3172 /* Calculate the tile_cache[] values. */
3174 /* manage settlers, and units */
3175 city_support(pcity);
3176 }
3177
3178 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3179 get_worked_tile_output(pcity, pcity->citizen_base, workers_map);
3180 add_specialist_output(pcity, pcity->citizen_base);
3181
3182 set_city_production(pcity);
3183 citizen_base_mood(pcity);
3184 /* Note that pollution is calculated before unhappy_city_check() makes
3185 * deductions for disorder; so a city in disorder still causes pollution */
3186 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3187
3188 happy_copy(pcity, FEELING_LUXURY);
3189 citizen_happy_luxury(pcity); /* with our new found luxuries */
3190
3191 happy_copy(pcity, FEELING_EFFECT);
3193
3196
3197 /* Martial law & unrest from units */
3199 citizen_happy_units(pcity);
3200
3201 /* Building (including wonder) happiness effects */
3202 happy_copy(pcity, FEELING_FINAL);
3203 citizen_happy_wonders(pcity);
3204
3205 unhappy_city_check(pcity);
3206 set_surpluses(pcity);
3207}
3208
3209/**********************************************************************/
3216int city_waste(const struct city *pcity, Output_type_id otype, int total,
3217 int *breakdown)
3218{
3219 int penalty_waste = 0;
3220 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3221 * corruption */
3222 int total_eft = total; /* Normal corruption calculated on total reduced by
3223 * possible size penalty */
3224 const struct output_type *output = get_output_type(otype);
3226 bool waste_all = FALSE;
3227
3228 if (otype == O_TRADE) {
3229 /* FIXME: special case for trade: it is affected by notradesize and
3230 * fulltradesize server settings.
3231 *
3232 * If notradesize and fulltradesize are equal then the city gets no
3233 * trade at that size. */
3234 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3235 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3236
3237 if (city_size_get(pcity) <= notradesize) {
3238 penalty_size = total_eft; /* Then no trade income. */
3239 } else if (city_size_get(pcity) >= fulltradesize) {
3240 penalty_size = 0;
3241 } else {
3242 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3243 / (fulltradesize - notradesize);
3244 }
3245 }
3246
3247 /* Apply corruption only to anything left after tradesize */
3249
3250 /* Distance-based waste.
3251 * Don't bother calculating if there's nothing left to lose. */
3252 if (total_eft > 0) {
3253 int waste_by_dist = get_city_output_bonus(pcity, output,
3255 int waste_by_rel_dist = get_city_output_bonus(pcity, output,
3257 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3258 int min_dist;
3259 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3260
3261 if (gov_center == NULL) {
3262 waste_all = TRUE; /* No gov center - no income */
3263 } else {
3265 if (waste_by_rel_dist > 0) {
3266 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3267 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3268 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3270 }
3271 }
3272 }
3273 }
3274
3275 if (waste_all) {
3277 } else {
3278 int waste_pct = get_city_output_bonus(pcity, output,
3280
3281 /* Corruption/waste calculated only for the actually produced amount */
3282 if (waste_level > 0) {
3284 }
3285
3286 /* Bonus calculated only for the actually produced amount */
3288
3289 /* Clip */
3291 }
3292
3293 if (breakdown) {
3296 }
3297
3298 /* Add up total penalty */
3299 return penalty_waste + penalty_size;
3300}
3301
3302/**********************************************************************/
3305citizens city_specialists(const struct city *pcity)
3306{
3307 citizens count = 0;
3308
3310 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3311 count += pcity->specialists[sp];
3313
3314 return count;
3315}
3316
3317/**********************************************************************/
3323 const struct city *pcity)
3324{
3325 int best = DEFAULT_SPECIALIST;
3326 int val = get_specialist_output(pcity, best, otype);
3327
3329 if (!pcity || city_can_use_specialist(pcity, i)) {
3330 int val2 = get_specialist_output(pcity, i, otype);
3331
3332 if (val2 > val) {
3333 best = i;
3334 val = val2;
3335 }
3336 }
3338
3339 return best;
3340}
3341
3342/**********************************************************************/
3345void city_add_improvement(struct city *pcity,
3346 const struct impr_type *pimprove)
3347{
3348 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3349
3350 if (is_server() && is_wonder(pimprove)) {
3351 /* Client just read the info from the packets. */
3352 wonder_built(pcity, pimprove);
3353 }
3354}
3355
3356/**********************************************************************/
3360 const struct impr_type *pimprove)
3361{
3362 log_debug("Improvement %s removed from city %s",
3363 improvement_rule_name(pimprove), pcity->name);
3364
3365 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3366
3367 if (is_server() && is_wonder(pimprove)) {
3368 /* Client just read the info from the packets. */
3369 wonder_destroyed(pcity, pimprove);
3370 }
3371}
3372
3373/**********************************************************************/
3376bool is_city_option_set(const struct city *pcity, enum city_options option)
3377{
3378 return BV_ISSET(pcity->city_options, option);
3379}
3380
3381/**********************************************************************/
3385{
3386 int i;
3387
3388 city_styles = fc_calloc(num, sizeof(*city_styles));
3390
3391 for (i = 0; i < game.control.num_city_styles; i++) {
3393 }
3394}
3395
3396/**********************************************************************/
3400{
3401 int i;
3402
3403 for (i = 0; i < game.control.num_city_styles; i++) {
3405 }
3406
3408 city_styles = NULL;
3410}
3411
3412/**********************************************************************/
3418struct city *create_city_virtual(struct player *pplayer,
3419 struct tile *ptile, const char *name)
3420{
3421 int i,len;
3422
3423 /* Make sure that contents of city structure are correctly initialized,
3424 * if you ever allocate it by some other mean than fc_calloc() */
3425 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3426
3427 fc_assert_ret_val(NULL != name, NULL); /* No unnamed cities! */
3428
3429 /* Do this early, so any logging later will have the city name */
3430 city_name_set(pcity, name);
3431
3432 pcity->tile = ptile;
3433 fc_assert_ret_val(NULL != pplayer, NULL); /* No unowned cities! */
3434 pcity->owner = pplayer;
3435 pcity->acquire_t = CACQ_FOUNDED;
3436
3437 if (is_server()) {
3438 pcity->original = pplayer;
3439 }
3440
3441 /* City structure was allocated with fc_calloc(), so contents are initially
3442 * zero. There is no need to initialize it a second time. */
3443
3444 /* Now set some useful default values. */
3445 pcity->capital = CAPITAL_NOT;
3446 city_size_set(pcity, 1);
3447 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3448 pcity->wlcb = WLCB_SMART;
3449
3451 pcity->bonus[o] = 100;
3452 pcity->abs_bonus[o] = 0;
3454
3455 pcity->turn_plague = -1; /* -1 = never */
3456 pcity->did_buy = FALSE;
3458 pcity->turn_founded = game.info.turn;
3459 pcity->turn_last_built = game.info.turn;
3460
3461 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3462
3463 /* pcity->ai.act_cache: worker activities on the city map */
3464
3465 /* Initialise improvements list */
3466 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3467 pcity->built[i].turn = I_NEVER;
3468 }
3469
3470 /* Set up the worklist */
3471 worklist_init(&pcity->worklist);
3472
3473 pcity->units_supported = unit_list_new();
3474 pcity->routes = trade_route_list_new();
3476
3477 if (is_server()) {
3478 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3479
3480 CALL_FUNC_EACH_AI(city_alloc, pcity);
3481 } else {
3484 pcity->client.info_units_present =
3486 /* collecting_info_units_supported set by fc_calloc().
3487 * collecting_info_units_present set by fc_calloc(). */
3488 }
3489
3491 pcity->counter_values = fc_malloc(sizeof(int) * len);
3492
3493 for (i = 0; i < len; i++) {
3495 }
3496
3497 return pcity;
3498}
3499
3500/**********************************************************************/
3504void destroy_city_virtual(struct city *pcity)
3505{
3506 CALL_FUNC_EACH_AI(city_free, pcity);
3507
3508 citizens_free(pcity);
3509
3510 /* Free worker tasks */
3511 while (worker_task_list_size(pcity->task_reqs) > 0) {
3512 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3513
3515
3516 free(ptask);
3517 }
3519
3520 /* Free rally points */
3522
3525 if (pcity->tile_cache != NULL) {
3526 free(pcity->tile_cache);
3527 }
3528
3529 if (pcity->cm_parameter) {
3530 free(pcity->cm_parameter);
3531 }
3532
3533 if (pcity->counter_values) {
3534 free(pcity->counter_values);
3535 }
3536
3537 if (!is_server()) {
3540 /* Handle a rare case where the game is freed in the middle of a
3541 * spy/diplomat investigate cycle. */
3544 }
3547 }
3548 }
3549
3550 free(pcity->name);
3551
3552 memset(pcity, 0, sizeof(*pcity)); /* ensure no pointers remain */
3553 free(pcity);
3554}
3555
3556/**********************************************************************/
3560bool city_exist(int id)
3561{
3562 /* Check if city exist in game */
3563 if (game_city_by_number(id)) {
3564 return TRUE;
3565 }
3566
3567 return FALSE;
3568}
3569
3570/**********************************************************************/
3577bool city_is_virtual(const struct city *pcity)
3578{
3579 if (!pcity) {
3580 return FALSE;
3581 }
3582
3583 return pcity != game_city_by_number(pcity->id);
3584}
3585
3586/**********************************************************************/
3589bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3590{
3591 return is_city_center(pcity, ptile);
3592}
3593
3594/**********************************************************************/
3597void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3598{
3599 return pcity->server.ais[ai_type_number(ai)];
3600}
3601
3602/**********************************************************************/
3605void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3606 void *data)
3607{
3608 pcity->server.ais[ai_type_number(ai)] = data;
3609}
3610
3611/**********************************************************************/
3614void city_rally_point_clear(struct city *pcity)
3615{
3616 /* Free rally points */
3617 if (pcity->rally_point.length > 0) {
3618 pcity->rally_point.length = 0;
3619 pcity->rally_point.persistent = FALSE;
3620 pcity->rally_point.vigilant = FALSE;
3621 free(pcity->rally_point.orders);
3622 pcity->rally_point.orders = NULL;
3623 }
3624}
3625
3626/**********************************************************************/
3630 struct city *pcity)
3631{
3632 struct unit_order *checked_orders;
3633
3634 if (NULL == pcity) {
3635 /* Probably lost. */
3636 log_verbose("handle_city_rally_point() bad city number %d.",
3637 packet->id);
3638 return;
3639 }
3640
3641 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3642 /* Shouldn't happen */
3643 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3644 packet->length, MAX_LEN_ROUTE);
3645 return;
3646 }
3647
3648 pcity->rally_point.length = packet->length;
3649
3650 if (packet->length == 0) {
3651 pcity->rally_point.vigilant = FALSE;
3652 pcity->rally_point.persistent = FALSE;
3653 if (pcity->rally_point.orders) {
3654 free(pcity->rally_point.orders);
3655 pcity->rally_point.orders = NULL;
3656 }
3657 } else {
3659 packet->length, packet->orders);
3660 if (!checked_orders) {
3661 pcity->rally_point.length = 0;
3662 log_error("invalid rally point orders for %s.",
3663 city_name_get(pcity));
3664 return;
3665 }
3666
3667 pcity->rally_point.persistent = packet->persistent;
3668 pcity->rally_point.vigilant = packet->vigilant;
3670 }
3671}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2306
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:479
#define action_enabler_list_iterate_end
Definition actions.h:439
#define action_by_result_iterate_end
Definition actions.h:483
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:437
#define action_id(_act_)
Definition actions.h:659
int ai_type_number(const struct ai_type *ai)
Definition ai.c:278
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
void citizens_free(struct city *pcity)
Definition citizens.c:58
#define citizens_foreign_iterate_end
Definition citizens.h:63
#define citizens_foreign_iterate(_pcity, _pslot, _nationality)
Definition citizens.h:58
bool base_city_celebrating(const struct city *pcity)
Definition city.c:1629
bool city_is_virtual(const struct city *pcity)
Definition city.c:3577
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:1957
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2535
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:662
bool city_exists_within_max_city_map(const struct tile *ptile, bool may_be_on_center)
Definition city.c:2102
static void citizen_content_buildings(struct city *pcity)
Definition city.c:2582
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3589
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1852
static bv_imprs caravan_helped_impr
Definition city.c:1763
bool is_friendly_city_near(const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2083
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:147
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:736
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1136
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2151
bool can_city_build_unit_later(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:965
int city_granary_size(int city_size)
Definition city.c:2123
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2187
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2778
static void city_tile_cache_update(struct city *pcity)
Definition city.c:2400
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3605
static void get_worked_tile_output(const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2315
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2703
static void city_support(struct city *pcity)
Definition city.c:3090
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2270
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Definition city.c:1006
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3216
int city_unit_unhappiness(struct unit *punit, int *free_unhappy)
Definition city.c:3040
void generate_city_map_indices(void)
Definition city.c:526
int city_build_slots(const struct city *pcity)
Definition city.c:2923
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:304
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
const char * city_style_name_translation(const int style)
Definition city.c:1748
void city_styles_free(void)
Definition city.c:3399
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2429
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:646
bool is_capital(const struct city *pcity)
Definition city.c:1571
void city_styles_alloc(int num)
Definition city.c:3384
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1392
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1040
void city_production_caravan_shields_init(void)
Definition city.c:1770
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3359
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1246
int city_airlift_max(const struct city *pcity)
Definition city.c:2933
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1478
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1456
struct output_type * get_output_type(Output_type_id output)
Definition city.c:637
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3376
int city_population(const struct city *pcity)
Definition city.c:1182
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1757
void city_size_add(struct city *pcity, int add)
Definition city.c:1155
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1056
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:726
bool city_is_occupied(const struct city *pcity)
Definition city.c:1657
void free_city_map_index(void)
Definition city.c:608
void city_refresh_from_main_map(struct city *pcity, bool *workers_map)
Definition city.c:3165
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:803
void add_tax_income(const struct player *pplayer, int trade, int *output)
Definition city.c:2236
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:853
bool city_tile_index_to_xy(int *city_map_x, int *city_map_y, int city_tile_index, int city_radius_sq)
Definition city.c:100
struct city * tile_non_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2058
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1588
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2177
bool city_map_includes_tile(const struct city *const pcity, const struct tile *map_tile)
Definition city.c:292
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2218
void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
Definition city.c:410
static int city_map_numtiles[CITY_MAP_MAX_RADIUS_SQ+1]
Definition city.c:67
bool city_rapture_grow(const struct city *pcity)
Definition city.c:1645
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:819
bool city_unhappy(const struct city *pcity)
Definition city.c:1618
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3322
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3418
void set_city_production(struct city *pcity)
Definition city.c:2944
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1671
static bv_unit_types caravan_helped_utype
Definition city.c:1764
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2203
bool city_celebrating(const struct city *pcity)
Definition city.c:1637
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1552
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:829
const char * get_output_identifier(Output_type_id output)
Definition city.c:618
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2861
const char * get_output_name(Output_type_id output)
Definition city.c:628
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2004
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1878
static int get_city_health(const struct city *pcity)
Definition city.c:2844
bool is_valid_city_coords(const int city_radius_sq, const int city_map_x, const int city_map_y)
Definition city.c:187
static void set_city_bonuses(struct city *pcity)
Definition city.c:2377
static void set_surpluses(struct city *pcity)
Definition city.c:2443
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2278
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2812
bool city_happy(const struct city *pcity)
Definition city.c:1606
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1171
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3345
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1375
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:136
bool can_city_build_direct(const struct city *pcity, const struct universal *target)
Definition city.c:988
struct city * tile_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2028
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2013
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:445
bool city_base_to_city_map(int *city_map_x, int *city_map_y, const struct city *const pcity, const struct tile *map_tile)
Definition city.c:280
void destroy_city_virtual(struct city *pcity)
Definition city.c:3504
int rs_max_city_radius_sq(void)
Definition city.c:158
bool city_tile_to_city_map(int *city_map_x, int *city_map_y, const int city_radius_sq, const struct tile *city_center, const struct tile *map_tile)
Definition city.c:263
citizens city_specialists(const struct city *pcity)
Definition city.c:3305
static char * citylog_map_line(int y, int city_radius_sq, int *city_map_data)
Definition city.c:368
void city_rally_point_receive(const struct packet_city_rally_point *packet, struct city *pcity)
Definition city.c:3629
static int cmp(int v1, int v2)
Definition city.c:324
#define CITYLOG_MAX_VAL
Definition city.c:367
void city_choose_build_default(struct city *pcity)
Definition city.c:1078
int city_style_by_translated_name(const char *s)
Definition city.c:1713
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2355
static const struct city struct citystyle * city_styles
Definition city.c:83
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3597
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1687
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2606
bool can_city_build_later(const struct city *pcity, const struct universal *target)
Definition city.c:1023
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1274
static int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
Definition city.c:64
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:122
bool is_gov_center(const struct city *pcity)
Definition city.c:1579
#define log_ca_s_init
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2572
int city_map_tiles(int city_radius_sq)
Definition city.c:170
static void unhappy_city_check(struct city *pcity)
Definition city.c:2751
bool can_city_build_unit_direct(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:902
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2043
bool is_unit_near_a_friendly_city(const struct unit *punit, int distance)
Definition city.c:2073
bool city_exist(int id)
Definition city.c:3560
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1447
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:716
int compare_iter_index(const void *a, const void *b)
Definition city.c:342
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:746
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1988
void city_rally_point_clear(struct city *pcity)
Definition city.c:3614
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:870
struct output_type output_types[O_LAST]
Definition city.c:87
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2914
static int get_trade_illness(const struct city *pcity)
Definition city.c:2824
bool city_can_change_build(const struct city *pcity)
Definition city.c:1070
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1213
int city_style_by_rule_name(const char *s)
Definition city.c:1730
static void citizen_base_mood(struct city *pcity)
Definition city.c:2496
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1703
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1192
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:945
static void citizen_happy_units(struct city *pcity)
Definition city.c:2655
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2484
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:699
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:256
@ UNHAPPY_PENALTY_NONE
Definition city.h:254
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:255
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, _index)
Definition city.h:201
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define CITY_MAP_MAX_SIZE
Definition city.h:94
#define city_tile_iterate_index_end
Definition city.h:209
@ CITIZEN_LAST
Definition city.h:272
@ CITIZEN_ANGRY
Definition city.h:271
@ CITIZEN_HAPPY
Definition city.h:268
@ CITIZEN_CONTENT
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:270
#define CITY_MAP_CENTER_RADIUS_SQ
Definition city.h:89
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:84
#define output_type_iterate(output)
Definition city.h:833
#define CITY_REL2ABS(_coor)
Definition city.h:115
#define city_owner(_pcity_)
Definition city.h:563
#define MAX_CITY_SIZE
Definition city.h:106
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:856
#define city_list_iterate_end
Definition city.h:510
#define I_DESTROYED
Definition city.h:248
#define I_NEVER
Definition city.h:247
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
citizen_feeling
Definition city.h:278
@ FEELING_EFFECT
Definition city.h:281
@ FEELING_LUXURY
Definition city.h:280
@ FEELING_FINAL
Definition city.h:284
@ FEELING_BASE
Definition city.h:279
@ FEELING_NATIONALITY
Definition city.h:282
@ FEELING_MARTIAL
Definition city.h:283
@ OLOSS_SIZE
Definition city.h:291
@ OLOSS_WASTE
Definition city.h:290
#define city_map_iterate_end
Definition city.h:177
production_class_type
Definition city.h:38
@ PCT_LAST
Definition city.h:42
@ PCT_UNIT
Definition city.h:39
@ PCT_NORMAL_IMPROVEMENT
Definition city.h:40
@ PCT_WONDER
Definition city.h:41
#define city_map_iterate(_radius_sq, _index, _x, _y)
Definition city.h:173
#define city_tile_iterate_end
Definition city.h:238
#define city_built_iterate(_pcity, _p)
Definition city.h:822
#define is_free_worked_index(city_tile_index)
Definition city.h:868
#define city_map_tiles_from_city(_pcity)
Definition city.h:127
#define CITY_ABS2REL(_coor)
Definition city.h:116
#define city_built_iterate_end
Definition city.h:828
#define output_type_iterate_end
Definition city.h:839
void cm_init_citymap(void)
Definition cm.c:314
char * incite_cost
Definition comments.c:74
#define MAX_LEN_ROUTE
Definition conn_types.h:38
struct counter * counter_by_index(int index, enum counter_target target)
Definition counters.c:183
int counters_get_city_counters_count(void)
Definition counters.c:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
void distribute(int number, unsigned groups, const unsigned *ratios, int *result)
Definition distribute.c:34
struct @21::@22 reqs
int get_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:940
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:984
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Definition effects.c:1008
int get_city_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:916
int effect_cumulative_max(enum effect_type type, struct universal *unis, size_t n_unis)
Definition effects.c:388
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:1035
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
static bool is_server(void)
unsigned char citizens
Definition fc_types.h:391
@ RPT_CERTAIN
Definition fc_types.h:704
@ RPT_POSSIBLE
Definition fc_types.h:703
int Specialist_type_id
Definition fc_types.h:378
@ CTGT_CITY
Definition fc_types.h:126
#define CITY_MAP_MAX_RADIUS
Definition fc_types.h:83
output_type_id
Definition fc_types.h:100
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
#define MAX_LEN_CITYNAME
Definition fc_types.h:67
enum output_type_id Output_type_id
Definition fc_types.h:381
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
#define Qn_(String)
Definition fcintl.h:89
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:107
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
struct city * owner
Definition citydlg.c:220
GType type
Definition repodlgs.c:1313
bool is_building_sellable(const struct impr_type *pimprove)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_warn(message,...)
Definition log.h:105
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_do_output_for_level(level)
Definition log.h:89
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_base(level, message,...)
Definition log.h:94
log_level
Definition log.h:28
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:419
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:614
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:940
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1073
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:391
#define NATIVE_WIDTH
Definition map.h:222
#define square_iterate_end
Definition map.h:394
#define NATIVE_HEIGHT
Definition map.h:223
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:233
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:465
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
struct city_list * cities
Definition packhand.c:119
int len
Definition packhand.c:127
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1459
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1493
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool req_vec_wants_type(const struct requirement_vector *reqs, enum universals_n kind)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct player *other_player, const struct requirement *req, enum req_problem_type prob_type)
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
static struct setting settings[]
Definition settings.c:1473
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
#define CLIP(lower, current, upper)
Definition shared.h:57
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
struct specialist * specialist_by_number(const Specialist_type_id id)
Definition specialist.c:100
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Definition specialist.c:217
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
#define DEFAULT_SPECIALIST
Definition specialist.h:43
int step
Definition specpq.h:92
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
Definition ai.h:50
int turn
Definition city.h:246
Definition city.h:320
struct worker_task_list * task_reqs
Definition city.h:412
struct tile_cache * tile_cache
Definition city.h:349
int turn_last_built
Definition city.h:387
int surplus[O_LAST]
Definition city.h:355
enum city_wl_cancel_behavior wlcb
Definition city.h:404
int food_stock
Definition city.h:367
struct built_status built[B_LAST]
Definition city.h:394
struct player * original
Definition city.h:324
int * counter_values
Definition city.h:408
int pollution
Definition city.h:369
int id
Definition city.h:326
int last_turns_shield_surplus
Definition city.h:392
enum capital_type capital
Definition city.h:328
int disbanded_shields
Definition city.h:391
int waste[O_LAST]
Definition city.h:356
int turn_plague
Definition city.h:374
struct unit_list * info_units_present
Definition city.h:474
bv_city_options city_options
Definition city.h:403
citizens unit_happy_upkeep
Definition city.h:339
int city_radius_sq
Definition city.h:375
bool was_happy
Definition city.h:381
struct player * owner
Definition city.h:323
enum city_acquire_type acquire_t
Definition city.h:329
int turn_founded
Definition city.h:386
int citizen_base[O_LAST]
Definition city.h:359
int caravan_shields
Definition city.h:390
bool did_buy
Definition city.h:379
struct unit_list * info_units_supported
Definition city.h:473
char * name
Definition city.h:321
void * ais[FREECIV_AI_MOD_LAST]
Definition city.h:453
struct trade_route_list * routes
Definition city.h:344
bool occupied
Definition city.h:460
int usage[O_LAST]
Definition city.h:360
struct worklist worklist
Definition city.h:401
int tile_cache_radius_sq
Definition city.h:352
int abs_bonus[O_LAST]
Definition city.h:364
struct universal production
Definition city.h:396
struct unit_order * orders
Definition city.h:422
struct city::@16 rally_point
struct unit_list * collecting_info_units_supported
Definition city.h:477
int bonus[O_LAST]
Definition city.h:363
bool vigilant
Definition city.h:421
int unhappy_penalty[O_LAST]
Definition city.h:357
citizens size
Definition city.h:332
int before_change_shields
Definition city.h:389
int style
Definition city.h:327
size_t length
Definition city.h:417
struct unit_list * collecting_info_units_present
Definition city.h:478
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:333
citizens specialists[SP_MAX]
Definition city.h:336
struct tile * tile
Definition city.h:322
int shield_stock
Definition city.h:368
int prod[O_LAST]
Definition city.h:358
struct city::@17::@19 server
struct cm_parameter * cm_parameter
Definition city.h:425
struct universal changed_from
Definition city.h:399
struct unit_list * units_supported
Definition city.h:406
int mgr_score_calc_turn
Definition city.h:432
int illness_trade
Definition city.h:370
bool persistent
Definition city.h:419
struct city::@17::@20 client
int rapture
Definition city.h:385
citizens martial_law
Definition city.h:338
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
struct government * government_during_revolution
Definition game.h:94
int def
Definition counters.h:34
enum impr_genus_id genus
Definition improvement.h:63
struct requirement_vector reqs
Definition improvement.h:58
int dist
Definition city.h:110
int dx
Definition city.h:110
int dy
Definition city.h:110
const char * id
Definition city.h:262
struct unit_order orders[MAX_LEN_ROUTE]
enum gold_upkeep_style gold_upkeep_style
int granary_food_ini[MAX_GRANARY_INIS]
int min_city_center_output[O_LAST]
struct city_list * cities
Definition player.h:279
struct unit_list * units
Definition player.h:280
struct player_economic economic
Definition player.h:282
const struct player * player
struct requirement_vector reqs
Definition specialist.h:38
int irrigation_food_incr
Definition terrain.h:221
int output[O_LAST]
Definition terrain.h:202
int mining_shield_incr
Definition terrain.h:224
int output[O_LAST]
Definition city.c:71
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
int city_slots
Definition unittype.h:552
int upkeep[O_LAST]
Definition unittype.h:538
Definition unit.h:138
int upkeep[O_LAST]
Definition unit.h:148
int homecity
Definition unit.h:146
enum universals_n kind
Definition fc_types.h:903
universals_u value
Definition fc_types.h:902
struct tile * ptile
Definition workertask.h:22
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define sz_strlcpy(dest, src)
Definition support.h:189
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:190
#define fc__fallthrough
Definition support.h:119
#define T_UNKNOWN
Definition terrain.h:57
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:291
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:271
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:88
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:103
#define tile_worked(_tile)
Definition tile.h:114
#define tile_resource(_tile)
Definition tile.h:102
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:110
#define tile_owner(_tile)
Definition tile.h:96
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
@ TRI_ACTIVE
Definition traderoutes.h:30
#define trade_routes_iterate_end
#define trade_partners_iterate_end
#define trade_routes_iterate(c, proute)
#define trade_partners_iterate(c, p)
trade_route_type
Definition traderoutes.h:37
const struct unit_type * utype
Definition fc_types.h:724
const struct impr_type * building
Definition fc_types.h:717
struct unit_order * create_unit_orders(const struct civ_map *nmap, int length, const struct unit_order *orders)
Definition unit.c:2830
bool unit_being_aggressive(const struct unit *punit)
Definition unit.c:1515
bool is_field_unit(const struct unit *punit)
Definition unit.c:416
bool is_martial_law_unit(const struct unit *punit)
Definition unit.c:318
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1725
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1357
#define unit_tile(_pu)
Definition unit.h:390
#define unit_owner(_pu)
Definition unit.h:389
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2271
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, bool consider_reg_impr_req)
Definition unittype.c:1968
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2613
bool utype_can_do_act_when_ustate(const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
Definition unittype.c:955
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1528
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2099
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1438
bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
Definition unittype.c:1017
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Definition unittype.c:181
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:766
#define utype_class(_t_)
Definition unittype.h:749
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
#define unit_type_iterate(_p)
Definition unittype.h:852
#define unit_type_iterate_end
Definition unittype.h:859
#define U_NOT_OBSOLETED
Definition unittype.h:528
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57