Freeciv-3.4
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 information using the city tile index. */
60static struct iter_index *city_map_index = nullptr;
61/* Get city tile information 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(const struct civ_map *nmap,
75 struct city *pcity);
76static inline int city_tile_cache_get_output(const struct city *pcity,
78 enum output_type_id o);
79
80static const struct city *nearest_gov_center(const struct city *pcity,
81 int *min_dist)
82 fc__attribute((nonnull (1, 2)));
83
84struct citystyle *city_styles = nullptr;
85
86/* One day these values may be read in from the ruleset. In the meantime
87 * they're just an easy way to access information about each output type. */
89 {O_FOOD, N_("Food"), "food", TRUE, UNHAPPY_PENALTY_SURPLUS},
90 {O_SHIELD, N_("Shield"), "shield", TRUE, UNHAPPY_PENALTY_SURPLUS},
91 {O_TRADE, N_("Trade"), "trade", TRUE, UNHAPPY_PENALTY_NONE},
92 {O_GOLD, N_("Gold"), "gold", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION},
93 {O_LUXURY, N_("Luxury"), "luxury", FALSE, UNHAPPY_PENALTY_NONE},
94 {O_SCIENCE, N_("Science"), "science", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION}
95};
96
97/**********************************************************************/
102 int city_tile_index, int city_radius_sq)
103{
106
107 /* tile indices are sorted from smallest to largest city radius */
108 if (city_tile_index < 0
109 || city_tile_index >= city_map_tiles(city_radius_sq)) {
110 return FALSE;
111 }
112
115
116 return TRUE;
117}
118
119/**********************************************************************/
124 int city_radius_sq)
125{
126 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, 0);
127 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, 0);
129 city_map_y), 0);
130
132}
133
134/**********************************************************************/
138{
139 /* A safe return value is only the minimal squared radius */
141
142 return pcity->city_radius_sq;
143}
144
145/**********************************************************************/
148void city_map_radius_sq_set(struct city *pcity, int radius_sq)
149{
152
153 pcity->city_radius_sq = radius_sq;
154}
155
156/**********************************************************************/
166
167/**********************************************************************/
171int city_map_tiles(int city_radius_sq)
172{
173 if (city_radius_sq == CITY_MAP_CENTER_RADIUS_SQ) {
174 /* special case: city center; first tile of the city map */
175 return 0;
176 }
177
178 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, -1);
179 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, -1);
180
181 return city_map_numtiles[city_radius_sq];
182}
183
184/**********************************************************************/
188bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
189 const int city_map_y)
190{
191 /* The city's valid positions are in a circle around the city center.
192 * Depending on the value for the squared city radius the circle will be:
193 *
194 * - rectangular (max radius = 5; max squared radius = 26)
195 *
196 * 0 1 2 3 4 5 6 7 8 9 10
197 *
198 * 0 26 25 26 -5
199 * 1 25 20 17 16 17 20 25 -4
200 * 2 25 18 13 10 9 10 13 18 25 -3
201 * 3 20 13 8 5 4 5 8 13 20 -2
202 * 4 26 17 10 5 2 1 2 5 10 17 26 -1
203 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
204 * 6 26 17 10 5 2 1 2 5 10 17 26 +1
205 * 7 20 13 8 5 4 5 8 13 20 +2
206 * 8 25 18 13 10 9 10 13 18 25 +3
207 * 9 25 20 17 16 17 20 25 +4
208 * 10 26 25 26 +5
209 *
210 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
211 *
212 * - hexagonal (max radius = 5; max squared radius = 26)
213 *
214 * 0 1 2 3 4 5 6 7 8 9 10
215 *
216 * 0 25 25 25 25 25 25 -5
217 * 1 25 16 16 16 16 16 25 -4
218 * 2 25 16 9 9 9 9 16 25 -3
219 * 3 25 16 9 4 4 4 9 16 25 -2
220 * 4 25 16 9 4 1 1 4 9 16 25 -1
221 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
222 * 6 25 16 9 4 1 1 4 9 16 25 +1
223 * 7 25 16 9 4 4 4 9 16 25 +2
224 * 8 25 16 9 9 9 9 16 25 +3
225 * 9 25 16 16 16 16 16 25 +4
226 * 10 25 25 25 25 25 25 +5
227 *
228 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
229 *
230 * The following tables show the tiles per city radii / squared city radii.
231 * '-' indicates no change compared to the previous value
232 *
233 * radius | 0 | 1 | | | 2 | | | | | 3
234 * radius_sq | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
235 * ------------------+----+----+----+----+----+----+----+----+----+----
236 * tiles rectangular | 5 | 9 | - | 13 | 21 | - | - | 25 | 29 | 37
237 * tiles hexagonal | 7 | - | - | 19 | - | - | - | - | 37 | -
238 *
239 * radius | | | | | | | 4 | | |
240 * radius_sq | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
241 * ------------------+----+----+----+----+----+----+----+----+----+----
242 * tiles rectangular | - | - | 45 | - | - | 49 | 57 | 61 | - | 69
243 * tiles hexagonal | - | - | - | - | - | 61 | - | - | - | -
244 *
245 * radius | | | | | | 5
246 * radius_sq | 21 | 22 | 23 | 24 | 25 | 26
247 * ------------------+----+----+----+----+----+----
248 * tiles rectangular | - | - | - | - | 81 | 89
249 * tiles hexagonal | - | - | - | - | 91 | -
250 *
251 * So radius_sq == 5 (radius == 2) corresponds to the "traditional"
252 * used city map.
253 */
256
257 return dist <= city_radius_sq;
258}
259
260/**********************************************************************/
265 const int city_radius_sq,
266 const struct tile *city_center,
267 const struct tile *map_tile)
268{
270
273
274 return is_valid_city_coords(city_radius_sq, *city_map_x, *city_map_y);
275}
276
277/**********************************************************************/
282 const struct city *const pcity,
283 const struct tile *map_tile)
284{
287 map_tile);
288}
289
290/**********************************************************************/
293bool city_map_includes_tile(const struct city *const pcity,
294 const struct tile *map_tile)
295{
296 int tmp_x, tmp_y;
297
299}
300
301/**********************************************************************/
305struct tile *city_map_to_tile(const struct civ_map *nmap,
306 const struct tile *city_center,
307 int city_radius_sq, int city_map_x,
308 int city_map_y)
309{
310 int tile_x, tile_y;
311
313 city_map_y), nullptr);
314
315 index_to_map_pos(&tile_x, &tile_y, tile_index(city_center));
318
320}
321
322/**********************************************************************/
325static int cmp(int v1, int v2)
326{
327 if (v1 == v2) {
328 return 0;
329 } else if (v1 > v2) {
330 return 1;
331 } else {
332 return -1;
333 }
334}
335
336/**********************************************************************/
343int compare_iter_index(const void *a, const void *b)
344{
345 const struct iter_index *index1 = a, *index2 = b;
346 int value;
347
348 value = cmp(index1->dist, index2->dist);
349 if (value != 0) {
350 return value;
351 }
352
353 value = cmp(index1->dx, index2->dx);
354 if (value != 0) {
355 return value;
356 }
357
358 value = cmp(index1->dy, index2->dy);
359 fc_assert(0 != value);
360 return value;
361}
362
363/**********************************************************************/
368#define CITYLOG_MAX_VAL 9999 /* maximal value displayed in the citylog */
369static char *citylog_map_line(int y, int city_radius_sq, int *city_map_data)
370{
371 int x, mindex;
372 static char citylog[128], tmp[8];
373
374 fc_assert_ret_val(city_map_data != nullptr, nullptr);
375
376 /* print y coordinates (absolute) */
377 fc_snprintf(citylog, sizeof(citylog), "%2d ", y);
378
379 /* print values */
380 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
381 if (is_valid_city_coords(city_radius_sq, x, y)) {
382 mindex = city_tile_xy_to_index(x, y, city_radius_sq);
383 /* show values between -10000 and +10000 */
386 fc_snprintf(tmp, sizeof(tmp), "%5d", city_map_data[mindex]);
388 } else {
389 fc_snprintf(tmp, sizeof(tmp), " ####");
391 }
392 } else {
393 fc_snprintf(tmp, sizeof(tmp), " ");
395 }
396 }
397
398 /* print y coordinates (relative) */
399 fc_snprintf(tmp, sizeof(tmp), " %+4d", CITY_ABS2REL(y));
401
402 return citylog;
403}
404#undef CITYLOG_MAX_VAL
405
406/**********************************************************************/
411void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
412{
413 int x, y;
414 char line[128], tmp[8];
415
417 return;
418 }
419
420 log_base(level, "(max squared city radius = %d)", CITY_MAP_MAX_RADIUS_SQ);
421
422 /* print x coordinates (absolute) */
423 fc_snprintf(line, sizeof(line), " ");
424 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
425 fc_snprintf(tmp, sizeof(tmp), "%+5d", x);
427 }
428 log_base(level, "%s", line);
429
430 for (y = 0; y < CITY_MAP_MAX_SIZE; y++) {
431 log_base(level, "%s", citylog_map_line(y, radius_sq, map_data));
432 }
433
434 /* print x coordinates (relative) */
435 fc_snprintf(line, sizeof(line), " ");
436 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
437 fc_snprintf(tmp, sizeof(tmp), "%+5d", CITY_ABS2REL(x));
439 }
440 log_base(level, "%s", line);
441}
442
443/**********************************************************************/
447{
448 int *city_map_data = nullptr;
449 const struct civ_map *nmap = &(wld.map);
450
451 fc_assert_ret(pcity != nullptr);
452
454 return;
455 }
456
458 sizeof(*city_map_data));
459
461 struct tile *ptile = city_map_to_tile(nmap,
464 x, y);
465 city_map_data[cindex] = (ptile && tile_worked(ptile) == pcity)
466 ? (is_free_worked_index(cindex) ? 2 : 1) : 0;
468
469 log_base(level, "[%s (%d)] workers map:", city_name_get(pcity), pcity->id);
472}
473
474#ifdef FREECIV_DEBUG
475/**********************************************************************/
478static void citylog_map_index(enum log_level level)
479{
480 int *city_map_data = nullptr;
481
483 return;
484 }
485
487 sizeof(*city_map_data));
488
490 city_map_data[cindex] = cindex;
492
493 log_debug("city map index:");
496}
497
498/**********************************************************************/
501static void citylog_map_radius_sq(enum log_level level)
502{
503 int *city_map_data = nullptr;
504
506 return;
507 }
508
510 sizeof(*city_map_data));
511
514 CITY_ABS2REL(y));
516
517 log_debug("city map squared radius:");
520}
521#endif /* FREECIV_DEBUG */
522
523/**********************************************************************/
528{
529 int i, dx, dy, city_x, city_y, dist, city_count_tiles = 0;
532
533 /* initialise map information for each city radii */
534 for (i = 0; i <= CITY_MAP_MAX_RADIUS_SQ; i++) {
535 city_map_numtiles[i] = 0; /* will be set below */
536 }
537
538 /* We don't use city-map iterators in this function because they may
539 * rely on the indices that have not yet been generated. Furthermore,
540 * we don't know the number of tiles within the city radius, so we need
541 * an temporary city_map_index array. Its content will be copied into
542 * the real array below. */
546
551
552 for (i = CITY_MAP_MAX_RADIUS_SQ; i >= 0; i--) {
553 if (dist <= i) {
554 /* increase number of tiles within this squared city radius */
556 }
557 }
558
560 }
561
562 /* Initialise city_map_xy. -1 defines a invalid city map positions. */
564 }
565 }
566
567 fc_assert(city_map_index == nullptr);
569
570 /* Copy the index numbers from city_map_index_tmp into city_map_index */
571 for (i = 0; i < city_count_tiles; i++) {
573 }
574
577
578 /* Set the static variable city_map_xy */
579 for (i = 0; i < city_count_tiles; i++) {
583 }
584
585#ifdef FREECIV_DEBUG
588
590 log_debug("radius_sq = %2d, tiles = %2d", i, city_map_tiles(i));
591 }
592
593 for (i = 0; i < city_count_tiles; i++) {
596 log_debug("[%2d]: (dx,dy) = (%+2d,%+2d), (x,y) = (%2d,%2d), "
597 "dist = %2d, check = %2d", i,
600 }
601#endif /* FREECIV_DEBUG */
602
604}
605
606/**********************************************************************/
610{
612}
613
614/**********************************************************************/
620{
621 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
622
623 return output_types[output].id;
624}
625
626/**********************************************************************/
631{
632 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
633
634 return _(output_types[output].name);
635}
636
637/**********************************************************************/
641{
642 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
643
644 return &output_types[output];
645}
646
647/**********************************************************************/
651{
653
654 for (o = 0; o < O_LAST; o++) {
655 if (fc_strcasecmp(output_types[o].id, id) == 0) {
656 return o;
657 }
658 }
659
660 return O_LAST;
661}
662
663/**********************************************************************/
667 const struct impr_type *pimprove)
668{
669 static char buffer[256];
670 const char *state = nullptr;
671
672 if (is_great_wonder(pimprove)) {
673 if (great_wonder_is_available(pimprove)) {
674 state = Q_("?wonder:W");
675 } else if (great_wonder_is_destroyed(pimprove)) {
676 state = Q_("?destroyed:D");
677 } else {
678 state = Q_("?built:B");
679 }
680 }
681 if (pcity) {
682 struct player *pplayer = city_owner(pcity);
683
684 if (improvement_obsolete(pplayer, pimprove, pcity)) {
685 state = Q_("?obsolete:O");
686 } else if (is_improvement_redundant(pcity, pimprove)) {
687 state = Q_("?redundant:*");
688 }
689 }
690
691 if (state) {
692 fc_snprintf(buffer, sizeof(buffer), "%s(%s)",
693 improvement_name_translation(pimprove), state);
694 return buffer;
695 } else {
696 return improvement_name_translation(pimprove);
697 }
698}
699
700/**********************************************************************/
704{
705 static char buffer[256];
706
707 switch (pcity->production.kind) {
708 case VUT_IMPROVEMENT:
709 return city_improvement_name_translation(pcity, pcity->production.value.building);
710 default:
711 /* fallthru */
712 break;
713 };
714 return universal_name_translation(&pcity->production, buffer, sizeof(buffer));
715}
716
717/**********************************************************************/
721 enum impr_genus_id genus)
722{
723 return VUT_IMPROVEMENT == pcity->production.kind
724 && (pcity->production.value.building->genus == genus);
725}
726
727/**********************************************************************/
731 enum impr_flag_id flag)
732{
733 return VUT_IMPROVEMENT == pcity->production.kind
734 && improvement_has_flag(pcity->production.value.building, flag);
735}
736
737/**********************************************************************/
741{
742 return universal_build_shield_cost(pcity, &pcity->production);
743}
744
745/**********************************************************************/
751 bool add_production, int *num_units)
752{
753 const struct unit_type *utype;
754 struct universal target;
756 int shields_left = pcity->shield_stock;
757 int unit_shield_cost, i;
758
759 fc_assert_ret_val(num_units != nullptr, FALSE);
760
761 (*num_units) = 0;
762
763 if (pcity->production.kind != VUT_UTYPE) {
764 /* Not a unit as the current production */
765 return FALSE;
766 }
767
768 utype = pcity->production.value.utype;
769 if (utype_pop_value(utype, pcity) != 0 || utype_has_flag(utype, UTYF_UNIQUE)) {
770 /* Unit with population cost or unique unit means that only one unit can
771 * be build */
772 (*num_units)++;
773 return FALSE;
774 }
775
776 if (add_production) {
777 shields_left += pcity->prod[O_SHIELD];
778 }
779
781
782 for (i = 0; i < build_slots; i++) {
784 /* Not enough shields */
785 break;
786 }
787
788 (*num_units)++;
790
791 if (worklist_length(&pcity->worklist) > i) {
792 (void) worklist_peek_ith(&pcity->worklist, &target, i);
793 if (target.kind != VUT_UTYPE
794 || utype_index(target.value.utype) != utype_index(utype)) {
795 /* Stop if there is a build target in the worklist not equal to the
796 * unit we build */
797 break;
798 }
799 }
800 }
801
802 return TRUE;
803}
804
805/************************************************************************/
809 const struct unit_type *punittype)
810{
812 nullptr, EFT_VETERAN_BUILD);
814
815 levels = CLIP(0, levels, max_levels);
816
817 return levels;
818}
819
820/**********************************************************************/
826{
828}
829
830/**********************************************************************/
835 const struct impr_type *pimprove,
836 const enum req_problem_type prob_type)
837{
839 prob_type)) {
840 return FALSE;
841 }
842
843 if (city_has_building(pcity, pimprove)) {
844 return FALSE;
845 }
846
847 return are_reqs_active(&(const struct req_context) {
848 .player = city_owner(pcity),
849 .city = pcity,
850 .tile = pcity->tile,
851 },
852 nullptr,
853 &(pimprove->reqs), prob_type);
854}
855
856/**********************************************************************/
861 const struct impr_type *pimprove,
862 const enum req_problem_type prob_type)
863{
865 prob_type)) {
866 return FALSE;
867 }
868 if (improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
869 return FALSE;
870 }
871
872 return TRUE;
873}
874
875/**********************************************************************/
880 const struct impr_type *pimprove)
881{
882 const struct req_context city_ctxt = {
884 .city = pcity,
885 .tile = city_tile(pcity),
886 };
887
888 /* Can the _player_ ever build this improvement? */
889 /* NOTE: It checks for obsoletion player-level. What aboult checking
890 * for it city-level? That may unlist from a worklist some things
891 * we'll be able to switch to after e.g. selling something else */
893 return FALSE;
894 }
895
896 /* Check for requirements that aren't met and that are unchanging (so
897 * they can never be met). */
899 if (is_req_preventing(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
900 return FALSE;
901 }
903
904 return TRUE;
905}
906
907/**********************************************************************/
912 const struct city *pcity,
913 const struct unit_type *punittype,
914 const enum req_problem_type prob_type)
915{
917 prob_type, FALSE)) {
918 return FALSE;
919 }
920
921 /* Check unit build requirements.
922 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
923 * Don't recheck those. Not only for optimization, but also not to override the
924 * special handling of tech requirements for barbarians */
925 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
927 &(const struct req_context) {
928 .player = city_owner(pcity),
929 .city = pcity,
930 .tile = city_tile(pcity),
931 .unittype = punittype,
932 },
933 nullptr,
934 &punittype->build_reqs, prob_type)) {
935 return FALSE;
936 }
937
938 /* You can't build naval units inland. */
941 pcity->tile)) {
942 return FALSE;
943 }
944
945 if (punittype->city_slots > 0
946 && city_unit_slots_available(pcity) < punittype->city_slots) {
947 return FALSE;
948 }
949
950 return TRUE;
951}
952
953/**********************************************************************/
958 const struct city *pcity,
959 const struct unit_type *punittype,
960 const enum req_problem_type prob_type)
961{
963 return FALSE;
964 }
965
966 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
967 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
968 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
970 prob_type, TRUE)) {
971 return FALSE;
972 }
973 }
974
975 return TRUE;
976}
977
978/**********************************************************************/
983 const struct city *pcity,
984 const struct unit_type *punittype)
985{
986 /* Can the _player_ ever build this unit? */
988 return FALSE;
989 }
990
991 /* Some units can be built only in certain cities -- for instance,
992 ships may be built only in cities adjacent to ocean. */
995 pcity->tile)) {
996 return FALSE;
997 }
998
999 return TRUE;
1000}
1001
1002/**********************************************************************/
1007 const struct city *pcity,
1008 const struct universal *target)
1009{
1010 switch (target->kind) {
1011 case VUT_UTYPE:
1013 RPT_CERTAIN);
1014 case VUT_IMPROVEMENT:
1016 RPT_CERTAIN);
1017 default:
1018 break;
1019 };
1020 return FALSE;
1021}
1022
1023/**********************************************************************/
1028 const struct city *pcity,
1029 const struct universal *target)
1030{
1031 switch (target->kind) {
1032 case VUT_UTYPE:
1033 return can_city_build_unit_now(nmap, pcity, target->value.utype,
1034 RPT_CERTAIN);
1035 case VUT_IMPROVEMENT:
1037 RPT_CERTAIN);
1038 default:
1039 break;
1040 };
1041 return FALSE;
1042}
1043
1044/**********************************************************************/
1048 const struct city *pcity,
1049 const struct universal *target)
1050{
1051 switch (target->kind) {
1052 case VUT_UTYPE:
1054 case VUT_IMPROVEMENT:
1056 default:
1057 break;
1058 };
1059 return FALSE;
1060}
1061
1062/**********************************************************************/
1066{
1068 int current;
1069
1070 current = 0;
1071 unit_list_iterate(pcity->units_supported, punit) {
1072 current += unit_type_get(punit)->city_slots;
1074
1075 return max - current;
1076}
1077
1078/**********************************************************************/
1083{
1084 return are_reqs_active(&(const struct req_context) {
1085 .player = city_owner(pcity),
1086 .city = pcity,
1087 },
1088 nullptr,
1090}
1091
1092/**********************************************************************/
1096{
1097 return !pcity->did_buy || pcity->shield_stock <= 0;
1098}
1099
1100/**********************************************************************/
1104{
1105 if (city_tile(pcity) == nullptr) {
1106 /* When a "dummy" city is created with no tile, then choosing a build
1107 * target could fail. This currently might happen during map editing.
1108 * FIXME: Assumes the first unit is always "valid", so check for
1109 * obsolete units elsewhere. */
1110 pcity->production.kind = VUT_UTYPE;
1111 pcity->production.value.utype = utype_by_number(0);
1112 } else {
1114
1115 if (u) {
1116 pcity->production.kind = VUT_UTYPE;
1117 pcity->production.value.utype = u;
1118 } else {
1119 bool found = FALSE;
1120
1121 /* Just pick the first available item. */
1122 improvement_iterate(pimprove) {
1124 RPT_CERTAIN)) {
1125 found = TRUE;
1126 pcity->production.kind = VUT_IMPROVEMENT;
1127 pcity->production.value.building = pimprove;
1128 break;
1129 }
1131
1132 if (!found) {
1135 RPT_CERTAIN)) {
1136#ifndef FREECIV_NDEBUG
1137 /* Later than this, 'found' is only needed in an fc_assert() */
1138 found = TRUE;
1139#endif /* FREECIV_NDEBUG */
1140 pcity->production.kind = VUT_UTYPE;
1141 pcity->production.value.utype = punittype;
1142 }
1144 }
1145
1146 fc_assert_msg(found, "No production found for city %s!",
1148 }
1149 }
1150}
1151
1152/**********************************************************************/
1155const char *city_name_get(const struct city *pcity)
1156{
1157 return (pcity->name != nullptr) ? pcity->name : "City missing a name";
1158}
1159
1160/**********************************************************************/
1163#define POLLUTION_EFT_NEARMAX -95
1164const char *city_name_getx(const struct city *pcity)
1165{
1166 bool spacer = FALSE;
1167 static char em_city_name[MAX_LEN_CITYNAME + 7];
1168
1169 em_city_name[0] = '\0';
1170
1172 sz_strlcat(em_city_name, "ₓ"); /* ₓ🞪⁻⁰… (alternatives)*/
1173 }
1174
1176
1177 if (get_city_bonus(pcity, EFT_AIRLIFT) > 0) {
1178 if (!spacer) {
1180 spacer = TRUE;
1181 }
1182 sz_strlcat(em_city_name, "🛧"); /* 🛧🛪 (alternatives)*/
1183 }
1184
1186 if (!spacer) {
1188 spacer = TRUE;
1189 }
1190 sz_strlcat(em_city_name, "♺"); /* ♺♻♳ (alternatives)*/
1191 }
1192
1193 return em_city_name;
1194}
1195
1196/**********************************************************************/
1199void city_name_set(struct city *pcity, const char *new_name)
1200{
1201 if (pcity->name != nullptr) {
1202 free(pcity->name);
1203 }
1204
1205 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1206 pcity->name = fc_strdup(new_name);
1207 } else {
1208 log_warn(_("City name \"%s\" too long"), new_name);
1210 sz_strlcpy(pcity->name, new_name);
1211 }
1212}
1213
1214/**********************************************************************/
1218void city_size_add(struct city *pcity, int add)
1219{
1221
1222 fc_assert_ret(pcity != nullptr);
1224
1225 /* Client sets size to zero to start stacking citizens in */
1226 fc_assert_ret(size > -add || (!is_server() && size == add));
1227
1228 city_size_set(pcity, size + add);
1229}
1230
1231/**********************************************************************/
1235{
1236 fc_assert_ret(pcity != nullptr);
1237
1238 /* Set city size. */
1239 pcity->size = size;
1240}
1241
1242/**********************************************************************/
1245int city_population(const struct city *pcity)
1246{
1247 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1248 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1249}
1250
1251/**********************************************************************/
1256{
1257 int gold_needed = 0;
1258
1259 if (pcity == nullptr) {
1260 return 0;
1261 }
1262
1263 city_built_iterate(pcity, pimprove) {
1264 gold_needed += city_improvement_upkeep(pcity, pimprove);
1266
1268
1269 return MAX(gold_needed, 0);
1270}
1271
1272/**********************************************************************/
1277{
1278 int gold_needed = 0;
1279
1280 if (pcity == nullptr || pcity->units_supported == nullptr) {
1281 return 0;
1282 }
1283
1284 unit_list_iterate(pcity->units_supported, punit) {
1285 gold_needed += punit->upkeep[O_GOLD];
1287
1288 return gold_needed;
1289}
1290
1291/**********************************************************************/
1294bool city_has_building(const struct city *pcity,
1295 const struct impr_type *pimprove)
1296{
1297 if (pimprove == nullptr) {
1298 /* Callers should ensure that any external data is tested with
1299 * valid_improvement_by_number() */
1300 return FALSE;
1301 }
1302
1303 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1304}
1305
1306/**********************************************************************/
1311 const struct impr_type *b)
1312{
1313 int upkeep;
1314
1315 if (b == nullptr) {
1316 return 0;
1317 }
1318 if (!is_building_sellable(b)) {
1319 return 0;
1320 }
1321
1322 upkeep = b->upkeep;
1324 return 0;
1325 }
1326
1327 return upkeep;
1328}
1329
1330/**********************************************************************/
1338int city_tile_output(const struct city *pcity, const struct tile *ptile,
1340{
1341 int prod;
1342 const struct req_context city_ctxt = {
1343 .player = pcity ? city_owner(pcity) : nullptr,
1344 .city = pcity,
1345 .tile = ptile,
1346 };
1347 struct terrain *pterrain = tile_terrain(ptile);
1348 const struct output_type *output = &output_types[otype];
1349
1350 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1351
1352 if (T_UNKNOWN == pterrain) {
1353 /* Special case for the client. The server doesn't allow unknown tiles
1354 * to be worked but we don't necessarily know what player is involved. */
1355 return 0;
1356 }
1357
1358 prod = pterrain->output[otype];
1359 if (tile_resource_is_valid(ptile)) {
1360 prod += tile_resource(ptile)->data.resource->output[otype];
1361 }
1362
1363 switch (otype) {
1364 case O_SHIELD:
1365 if (pterrain->mining_shield_incr != 0) {
1366 prod += pterrain->mining_shield_incr
1368 / 100;
1369 }
1370 break;
1371 case O_FOOD:
1372 if (pterrain->irrigation_food_incr != 0) {
1373 prod += pterrain->irrigation_food_incr
1374 * get_target_bonus_effects(nullptr, &city_ctxt, nullptr,
1375 EFT_IRRIGATION_PCT) / 100;
1376 }
1377 break;
1378 case O_TRADE:
1379 case O_GOLD:
1380 case O_SCIENCE:
1381 case O_LUXURY:
1382 case O_LAST:
1383 break;
1384 }
1385
1386 prod += tile_roads_output_incr(ptile, otype);
1387 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1388
1389 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1390 if (prod > 0) {
1391 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1393
1394 if (prod >= game.info.granularity) {
1395 prod += get_tile_output_bonus(pcity, ptile, output,
1397
1398 if (is_celebrating) {
1399 prod += get_tile_output_bonus(pcity, ptile, output,
1401 }
1402 }
1403
1404 prod += (prod
1405 * get_tile_output_bonus(pcity, ptile, output,
1407 / 100;
1408 if (penalty_limit > 0 && prod > penalty_limit) {
1409 if (prod <= game.info.granularity) {
1410 prod = 0;
1411 } else {
1412 prod -= game.info.granularity;
1413 }
1414 }
1415 }
1416
1417 prod -= (prod
1418 * get_tile_output_bonus(pcity, ptile, output,
1420 / 100;
1421
1422 if (pcity != nullptr && is_city_center(pcity, ptile)) {
1423 prod = MAX(prod, game.info.min_city_center_output[otype]);
1424 }
1425
1426 return prod;
1427}
1428
1429/**********************************************************************/
1439int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1441{
1443}
1444
1445/**********************************************************************/
1457 const struct city *pcity,
1458 const struct tile *ptile)
1459{
1460 struct player *powner = city_owner(pcity);
1462 struct player *towner;
1463
1464 if (ptile == nullptr) {
1465 return FALSE;
1466 }
1467
1469 return FALSE;
1470 }
1471
1472 if (restriction != nullptr
1473 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1474 return FALSE;
1475 }
1476
1477 towner = tile_owner(ptile);
1478 if (towner != nullptr && towner != powner
1479 && !gives_shared_tiles(towner, powner)) {
1480 return FALSE;
1481 }
1482 /* TODO: civ3-like option for borders */
1483
1484 if (tile_worked(ptile) != nullptr && tile_worked(ptile) != pcity) {
1485 return FALSE;
1486 }
1487
1488 if (powner == restriction
1489 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1490 return FALSE;
1491 }
1492
1493 if (!is_free_worked(pcity, ptile)
1494 && unit_occupies_tile(ptile, powner) != nullptr) {
1495 return FALSE;
1496 }
1497
1498 if (get_city_tile_output_bonus(pcity, ptile, nullptr, EFT_TILE_WORKABLE) <= 0) {
1499 return FALSE;
1500 }
1501
1502 return TRUE;
1503}
1504
1505/**********************************************************************/
1511bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1512{
1514}
1515
1516/**********************************************************************/
1521 const struct tile *ptile)
1522{
1523 /* citymindist minimum is 1, meaning adjacent is okay */
1524 int citymindist = game.info.citymindist;
1525
1526 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1527 if (tile_city(ptile1)) {
1528 return TRUE;
1529 }
1531
1532 return FALSE;
1533}
1534
1535/**********************************************************************/
1543 const struct tile *ptile,
1544 const struct unit *punit,
1545 bool hut_test)
1546{
1547 if (!city_can_be_built_tile_only(nmap, ptile)) {
1548 return FALSE;
1549 }
1550
1551 if (punit == nullptr) {
1552 /* The remaining checks tests if punit can found a city here */
1553 return TRUE;
1554 }
1555
1556 if (hut_test) {
1557 struct player *towner;
1558
1559 /* Huts can be found only from native tiles, owned by the unit owner.
1560 * Unlike actual city building, this behavior is not affected
1561 * by the ruleset. */
1562 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1563 return FALSE;
1564 }
1565
1566 towner = tile_owner(ptile);
1567
1568 if (towner == nullptr || towner == unit_owner(punit)) {
1569 return TRUE;
1570 }
1571
1572 return FALSE;
1573 }
1574
1577 /* This action can't be done by this unit type at all. */
1578 continue;
1579 }
1580
1581 /* Non native tile detection */
1582 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1583 /* The ruleset may allow founding cities on non native terrain. */
1586 /* Many rulesets allow land units to build land cities and sea units
1587 * to build ocean cities. Air units can build cities anywhere. */
1588 continue;
1589 }
1590
1591 /* Foreign tile detection. */
1592 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1593 /* The ruleset may allow founding cities on foreign terrain. */
1595 paction->id,
1596 DRO_FOREIGN, TRUE)) {
1597 /* Cannot steal borders by settling. This has to be settled by
1598 * force of arms. */
1599 continue;
1600 }
1601
1602 return TRUE;
1604
1605 return FALSE;
1606}
1607
1608/**********************************************************************/
1616 const struct tile *ptile)
1617{
1619 /* No cities on this terrain. */
1620 return FALSE;
1621 }
1622
1624 return FALSE;
1625 }
1626
1627 return TRUE;
1628}
1629
1630/**********************************************************************/
1634bool is_capital(const struct city *pcity)
1635{
1636 return pcity->capital != CAPITAL_NOT;
1637}
1638
1639/**********************************************************************/
1642bool is_gov_center(const struct city *pcity)
1643{
1644 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1645}
1646
1647/**********************************************************************/
1652 const struct unit_type *attacker)
1653{
1654 if (!attacker) {
1655 /* Any defense building will do */
1657 }
1658
1659 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1660 nullptr, EFT_DEFEND_BONUS) > 0;
1661}
1662
1663/**********************************************************************/
1669bool city_happy(const struct city *pcity)
1670{
1672 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1673 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1674 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1675}
1676
1677/**********************************************************************/
1681bool city_unhappy(const struct city *pcity)
1682{
1683 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1685 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1686}
1687
1688/**********************************************************************/
1693{
1694 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1695}
1696
1697/**********************************************************************/
1700bool city_celebrating(const struct city *pcity)
1701{
1703}
1704
1705/**********************************************************************/
1708bool city_rapture_grow(const struct city *pcity)
1709{
1710 /* .rapture is checked instead of city_celebrating() because this
1711 function is called after .was_happy was updated. */
1712 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1713 && (pcity->rapture % game.info.rapturedelay) == 0
1715}
1716
1717/**********************************************************************/
1720bool city_is_occupied(const struct city *pcity)
1721{
1722 if (is_server()) {
1723 /* The server sees the units inside the city. */
1724 return (unit_list_size(city_tile(pcity)->units) > 0);
1725 } else {
1726 /* The client gets the occupied property from the server. */
1727 return pcity->client.occupied;
1728 }
1729}
1730
1731/**********************************************************************/
1734struct city *city_list_find_number(struct city_list *This, int id)
1735{
1736 if (id != 0) {
1738 if (pcity->id == id) {
1739 return pcity;
1740 }
1742 }
1743
1744 return nullptr;
1745}
1746
1747/**********************************************************************/
1750struct city *city_list_find_name(struct city_list *This, const char *name)
1751{
1753 if (fc_strcasecmp(name, pcity->name) == 0) {
1754 return pcity;
1755 }
1757
1758 return nullptr;
1759}
1760
1761/**********************************************************************/
1766int city_name_compare(const void *p1, const void *p2)
1767{
1768 return fc_strcasecmp((*(const struct city **) p1)->name,
1769 (*(const struct city **) p2)->name);
1770}
1771
1772/**********************************************************************/
1777{
1778 int i;
1779
1780 for (i = 0; i < game.control.num_city_styles; i++) {
1781 if (0 == strcmp(city_style_name_translation(i), s)) {
1782 return i;
1783 }
1784 }
1785
1786 return -1;
1787}
1788
1789/**********************************************************************/
1793int city_style_by_rule_name(const char *s)
1794{
1795 const char *qs = Qn_(s);
1796 int i;
1797
1798 for (i = 0; i < game.control.num_city_styles; i++) {
1799 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1800 return i;
1801 }
1802 }
1803
1804 return -1;
1805}
1806
1807/**********************************************************************/
1812{
1814}
1815
1816/**********************************************************************/
1820const char *city_style_rule_name(const int style)
1821{
1823}
1824
1825/* Cache of what city production caravan shields are allowed to help. */
1828
1829/**********************************************************************/
1834{
1835 struct requirement prod_as_req;
1836
1837#define log_ca_s_init log_debug
1838
1839 /* Remove old data. */
1842
1843 /* Common for all production kinds. */
1845 prod_as_req.survives = FALSE;
1846 prod_as_req.present = TRUE;
1847
1848 /* Check improvements */
1849 prod_as_req.source.kind = VUT_IMPROVEMENT;
1850
1852 /* Check this improvement. */
1853 prod_as_req.source.value.building = itype;
1854
1857 enabler) {
1859 &(enabler->target_reqs))
1860 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1861 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1862 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1863 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1864 /* This improvement kind can receive caravan shields. */
1865
1867
1868 /* Move on to the next improvement */
1869 break;
1870 }
1872
1873 log_ca_s_init("Help Wonder: %s for %s",
1875 ? "possible" : "impossible"),
1878
1879 /* Check units. */
1880 prod_as_req.source.kind = VUT_UTYPE;
1881
1883 /* Check this utype. */
1884 prod_as_req.source.value.utype = putype;
1885
1888 enabler) {
1890 &(enabler->target_reqs))
1891 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1892 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1893 /* This unit type kind can receive caravan shields. */
1894
1896
1897 /* Move on to the next unit type */
1898 break;
1899 }
1901
1902 log_ca_s_init("Help Wonder: %s for %s",
1904 ? "possible" : "impossible"),
1907
1908#undef log_ca_s_init
1909}
1910
1911/**********************************************************************/
1916{
1917 switch (tgt->kind) {
1918 case VUT_IMPROVEMENT:
1921 case VUT_UTYPE:
1923 utype_index(tgt->value.utype));
1924 default:
1926 return FALSE;
1927 };
1928}
1929
1930/**********************************************************************/
1942 const struct universal *target)
1943{
1948
1949 switch (pcity->changed_from.kind) {
1950 case VUT_IMPROVEMENT:
1951 if (is_wonder(pcity->changed_from.value.building)) {
1953 } else {
1955 }
1956 break;
1957 case VUT_UTYPE:
1959 break;
1960 default:
1962 break;
1963 };
1964
1965 switch (target->kind) {
1966 case VUT_IMPROVEMENT:
1967 if (is_wonder(target->value.building)) {
1969 } else {
1971 }
1972 break;
1973 case VUT_UTYPE:
1975 break;
1976 default:
1978 break;
1979 };
1980
1981 /* Changing production is penalized under certain circumstances. */
1982 if (orig_class == new_class
1983 || orig_class == PCT_LAST) {
1984 /* There's never a penalty for building something of the same class. */
1985 unpenalized_shields = pcity->before_change_shields;
1986 } else if (city_built_last_turn(pcity)) {
1987 /* Surplus shields from the previous production won't be penalized if
1988 * you change production on the very next turn. But you can only use
1989 * up to the city's surplus amount of shields in this way. */
1990 unpenalized_shields = MIN(pcity->last_turns_shield_surplus,
1991 pcity->before_change_shields);
1992 penalized_shields = pcity->before_change_shields - unpenalized_shields;
1993 } else {
1994 /* Penalize 50% of the production. */
1995 penalized_shields = pcity->before_change_shields;
1996 }
1997
1998 /* Do not put penalty on these. It shouldn't matter whether you disband unit
1999 before or after changing production...*/
2000 unpenalized_shields += pcity->disbanded_shields;
2001
2002 /* Caravan shields are penalized (just as if you disbanded the caravan)
2003 * if you're not building a wonder. */
2005 unpenalized_shields += pcity->caravan_shields;
2006 } else {
2007 penalized_shields += pcity->caravan_shields;
2008 }
2009
2012
2014}
2015
2016/**********************************************************************/
2021 const struct universal *target,
2023{
2024 int city_shield_surplus = pcity->surplus[O_SHIELD];
2027 int cost = universal_build_shield_cost(pcity, target);
2028
2029 if (target->kind == VUT_IMPROVEMENT
2030 && is_great_wonder(target->value.building)
2032 return FC_INFINITY;
2033 }
2034
2036 return 1;
2037 } else if (city_shield_surplus > 0) {
2038 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
2039 } else {
2040 return FC_INFINITY;
2041 }
2042}
2043
2044/**********************************************************************/
2052{
2053 if (pcity->surplus[O_FOOD] > 0) {
2054 return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
2055 pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
2056 } else if (pcity->surplus[O_FOOD] < 0) {
2057 /* Turns before famine loss */
2058 return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
2059 } else {
2060 return FC_INFINITY;
2061 }
2062}
2063
2064/**********************************************************************/
2067bool city_can_grow_to(const struct city *pcity, int pop_size)
2068{
2071}
2072
2073/**********************************************************************/
2076struct city *tile_enemy_city(const struct tile *ptile,
2077 const struct player *pplayer)
2078{
2079 struct city *pcity = tile_city(ptile);
2080
2081 if (pcity != nullptr && pplayers_at_war(pplayer, city_owner(pcity))) {
2082 return pcity;
2083 }
2084
2085 return nullptr;
2086}
2087
2088/**********************************************************************/
2091struct city *tile_allied_city(const struct tile *ptile,
2092 const struct player *pplayer)
2093{
2094 struct city *pcity = tile_city(ptile);
2095
2096 if (pcity != nullptr && pplayers_allied(pplayer, city_owner(pcity))) {
2097 return pcity;
2098 }
2099
2100 return nullptr;
2101}
2102
2103/**********************************************************************/
2106struct city *tile_non_attack_city(const struct tile *ptile,
2107 const struct player *pplayer)
2108{
2109 struct city *pcity = tile_city(ptile);
2110
2111 if (pcity != nullptr && pplayers_non_attack(pplayer, city_owner(pcity))) {
2112 return pcity;
2113 }
2114
2115 return nullptr;
2116}
2117
2118/**********************************************************************/
2121struct city *tile_non_allied_city(const struct tile *ptile,
2122 const struct player *pplayer)
2123{
2124 struct city *pcity = tile_city(ptile);
2125
2126 if (pcity != nullptr && !pplayers_allied(pplayer, city_owner(pcity))) {
2127 return pcity;
2128 }
2129
2130 return nullptr;
2131}
2132
2133/**********************************************************************/
2137 const struct unit *punit,
2138 int distance)
2139{
2141 distance);
2142}
2143
2144/**********************************************************************/
2148 const struct player *owner,
2149 const struct tile *ptile,
2150 int distance)
2151{
2152 square_iterate(nmap, ptile, distance, ptile1) {
2153 struct city *pcity = tile_city(ptile1);
2154
2156 return TRUE;
2157 }
2159
2160 return FALSE;
2161}
2162
2163/**********************************************************************/
2168 const struct tile *ptile,
2169 bool may_be_on_center)
2170{
2172 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2173 if (tile_city(ptile1)) {
2174 return TRUE;
2175 }
2176 }
2178
2179 return FALSE;
2180}
2181
2182/**********************************************************************/
2187int city_granary_size(int city_size)
2188{
2191 int base_value;
2192
2193 /* If the city has no citizens, there is no granary. */
2194 if (city_size == 0) {
2195 return 0;
2196 }
2197
2198 /* Granary sizes for the first food_inis citizens are given directly.
2199 * After that we increase the granary size by food_inc per citizen. */
2200 if (city_size > food_inis) {
2201 base_value = game.info.granary_food_ini[food_inis - 1];
2202 base_value += food_inc * (city_size - food_inis);
2203 } else {
2204 base_value = game.info.granary_food_ini[city_size - 1];
2205 }
2206
2207 return MAX(base_value * game.info.foodbox / 100, 1);
2208}
2209
2210/**********************************************************************/
2215static int player_base_citizen_happiness(const struct player *pplayer)
2216{
2217 int cities = city_list_size(pplayer->cities);
2218 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2221
2222 if (basis + step <= 0) {
2223 /* Value of zero means effect is inactive */
2224 return content;
2225 }
2226
2227 if (cities > basis) {
2228 content--;
2229 if (step != 0) {
2230 /* the first penalty is at (basis + 1) cities;
2231 the next is at (basis + step + 1), _not_ (basis + step) */
2232 content -= (cities - basis - 1) / step;
2233 }
2234 }
2235 return content;
2236}
2237
2238/**********************************************************************/
2242{
2243 int content = player_base_citizen_happiness(pplayer);
2244
2245 return CLIP(0, content, MAX_CITY_SIZE);
2246}
2247
2248/**********************************************************************/
2252{
2253 if (!game.info.angrycitizen) {
2254 return 0;
2255 } else {
2256 /* Create angry citizens only if we have a negative number of possible
2257 * content citizens. This can happen when empires grow really big. */
2258 int content = player_base_citizen_happiness(pplayer);
2259
2260 return CLIP(0, -content, MAX_CITY_SIZE);
2261 }
2262}
2263
2264/**********************************************************************/
2268{
2269 struct output_type *output = &output_types[otype];
2270 int bonus1 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2272 int bonus2 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2274
2275 return MAX(bonus1 * bonus2 / 100, 0);
2276}
2277
2278/**********************************************************************/
2283{
2284 int tithes_bonus = 0;
2285
2287 return 0;
2288 }
2289
2292
2293 return tithes_bonus;
2294}
2295
2296/**********************************************************************/
2300void add_tax_income(const struct player *pplayer, int trade, int *output)
2301{
2302 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2303 unsigned rates[3];
2304 int result[3];
2305
2306 if (game.info.changable_tax) {
2307 rates[SCIENCE] = pplayer->economic.science;
2308 rates[LUXURY] = pplayer->economic.luxury;
2309 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2310 } else {
2314 }
2315
2316 /* ANARCHY */
2318 rates[SCIENCE] = 0;
2319 rates[LUXURY] = 100;
2320 rates[TAX] = 0;
2321 }
2322
2323 distribute(trade, 3, rates, result);
2324
2325 output[O_SCIENCE] += result[SCIENCE];
2326 output[O_GOLD] += result[TAX];
2327 output[O_LUXURY] += result[LUXURY];
2328}
2329
2330/**********************************************************************/
2335{
2336 return pcity->turn_last_built + 1 >= game.info.turn;
2337}
2338
2339/**********************************************************************/
2342static const struct city *nearest_gov_center(const struct city *pcity,
2343 int *min_dist)
2344{
2345 const struct city *gov_center = nullptr;
2346
2348
2349 /* Check the special case that city itself is gov center
2350 * before expensive iteration through all cities. */
2351 if (is_gov_center(pcity)) {
2352 *min_dist = 0;
2353 return pcity;
2354 } else {
2356 /* Do not recheck current city */
2357 if (gc != pcity && is_gov_center(gc)) {
2358 int dist = real_map_distance(gc->tile, pcity->tile);
2359
2360 if (dist < *min_dist) {
2361 gov_center = gc;
2362 *min_dist = dist;
2363 }
2364 }
2366 }
2367
2368 return gov_center;
2369}
2370
2371/**********************************************************************/
2379static inline void get_worked_tile_output(const struct civ_map *nmap,
2380 const struct city *pcity,
2381 int *output, bool *workers_map)
2382{
2383 bool is_worked;
2384#ifdef CITY_DEBUGGING
2386#endif
2387 struct tile *pcenter = city_tile(pcity);
2388
2389 memset(output, 0, O_LAST * sizeof(*output));
2390
2393 if (workers_map == nullptr) {
2394 struct city *pwork = tile_worked(ptile);
2395
2396 is_worked = (pwork != nullptr && pwork == pcity);
2397 } else {
2398 is_worked = workers_map[city_tile_index];
2399 }
2400
2401 if (is_worked) {
2403#ifdef CITY_DEBUGGING
2404 /* This assertion never fails, but it's so slow that we disable
2405 * it by default. */
2407 == city_tile_output(pcity, ptile, is_celebrating, o));
2408#endif /* CITY_DEBUGGING */
2411 }
2413}
2414
2415/**********************************************************************/
2419void add_specialist_output(const struct city *pcity, int *output)
2420{
2422 int count = pcity->specialists[sp];
2423
2426
2427 output[stat_index] += count * amount;
2430}
2431
2432/**********************************************************************/
2441static inline void set_city_bonuses(struct city *pcity)
2442{
2445 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2446 &output_types[o],
2448 /* Total bonus cannot be negative, as that could lead to unresolvable
2449 * negative balance. */
2450 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2452}
2453
2454/**********************************************************************/
2464static inline void city_tile_cache_update(const struct civ_map *nmap,
2465 struct city *pcity)
2466{
2468 int radius_sq = city_map_radius_sq_get(pcity);
2469
2470 /* Initialize tile_cache if needed */
2471 if (pcity->tile_cache == nullptr || pcity->tile_cache_radius_sq == -1
2472 || pcity->tile_cache_radius_sq != radius_sq) {
2473 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2474 city_map_tiles(radius_sq)
2475 * sizeof(*(pcity->tile_cache)));
2476 pcity->tile_cache_radius_sq = radius_sq;
2477 }
2478
2479 /* Any unreal tiles are skipped - these values should have been memset
2480 * to 0 when the city was created. */
2481 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2483 (pcity->tile_cache[city_tile_index]).output[o]
2487}
2488
2489/**********************************************************************/
2493static inline int city_tile_cache_get_output(const struct city *pcity,
2494 int city_tile_index,
2495 enum output_type_id o)
2496{
2497 fc_assert_ret_val(pcity->tile_cache_radius_sq
2500
2501 return (pcity->tile_cache[city_tile_index]).output[o];
2502}
2503
2504/**********************************************************************/
2507static void set_surpluses(struct city *pcity)
2508{
2510 int surplus = pcity->prod[o] - pcity->usage[o];
2511
2512 /* Add 'surplus' waste to 'usage'. */
2513 if (surplus > 0) {
2514 struct output_type *output = get_output_type(o);
2518
2519 if (waste_by_rel_dist > 0) {
2520 int min_dist;
2521 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2522
2523 if (gov_center == nullptr) {
2524 /* No gov center - no income */
2525 waste_level = 100;
2526 } else {
2527 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2529 }
2530 }
2531
2532 if (waste_level > 0) {
2533 if (waste_level < 100) {
2534 pcity->usage[o] += (surplus * waste_level / 100);
2535 } else {
2536 pcity->usage[o] = pcity->prod[o];
2537 }
2538 }
2539 }
2540
2541 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2543}
2544
2545/**********************************************************************/
2548static void happy_copy(struct city *pcity, enum citizen_feeling i)
2549{
2550 int c = 0;
2551
2552 for (; c < CITIZEN_LAST; c++) {
2553 pcity->feel[c][i] = pcity->feel[c][i - 1];
2554 }
2555}
2556
2557/**********************************************************************/
2560static void citizen_base_mood(struct city *pcity)
2561{
2562 struct player *pplayer = city_owner(pcity);
2563 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2564 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2565 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2566 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2569
2570 /* This is the number of citizens that may start out content, depending
2571 * on empire size and game's city unhappysize. This may be bigger than
2572 * the size of the city, since this is a potential. */
2574 /* Similarly, this is the potential number of angry citizens. */
2576
2577 /* Create content citizens. Take specialists from their ranks. */
2578 *content = MAX(0, MIN(size, base_content) - spes);
2579
2580 /* Create angry citizens. Specialists never become angry. */
2581 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2582 *angry = MIN(base_angry, size - spes);
2583
2584 /* Create unhappy citizens. In the beginning, all who are not content,
2585 * specialists or angry are unhappy. This is changed by luxuries and
2586 * buildings later. */
2587 *unhappy = (size - spes - *content - *angry);
2588
2589 /* No one is born happy. */
2590 *happy = 0;
2591}
2592
2593/**********************************************************************/
2599static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2600{
2601 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2602 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2603 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2604 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2605
2606 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2607 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2608 (*angry)--;
2609 (*unhappy)++;
2611 }
2612 while (*luxuries >= game.info.happy_cost && *content > 0) {
2613 /* Upgrade content to happy: costs HAPPY_COST each. */
2614 (*content)--;
2615 (*happy)++;
2617 }
2618 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2619 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2620 * double the cost. */
2621 (*unhappy)--;
2622 (*happy)++;
2623 *luxuries -= 2 * game.info.happy_cost;
2624 }
2625 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2626 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2627 (*unhappy)--;
2628 (*content)++;
2630 }
2631}
2632
2633/**********************************************************************/
2636static inline void citizen_happy_luxury(struct city *pcity)
2637{
2638 int x = pcity->prod[O_LUXURY];
2639
2641}
2642
2643/**********************************************************************/
2646static inline void citizen_content_buildings(struct city *pcity)
2647{
2648 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2649 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2650 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2652
2653 /* make people content (but not happy):
2654 get rid of angry first, then make unhappy content. */
2655 while (faces > 0 && *angry > 0) {
2656 (*angry)--;
2657 (*unhappy)++;
2658 faces--;
2659 }
2660 while (faces > 0 && *unhappy > 0) {
2661 (*unhappy)--;
2662 (*content)++;
2663 faces--;
2664 }
2665}
2666
2667/**********************************************************************/
2670static inline void citizen_happiness_nationality(struct city *pcity)
2671{
2675
2678
2679 if (pct > 0) {
2680 int enemies = 0;
2681 int unhappy_inc;
2682 struct player *owner = city_owner(pcity);
2683
2684 citizens_foreign_iterate(pcity, pslot, nationality) {
2686 enemies += nationality;
2687 }
2689
2690 unhappy_inc = enemies * pct / 100;
2691
2692 /* First make content => unhappy, then happy => unhappy,
2693 * then happy => content. No-one becomes angry. */
2694 while (unhappy_inc > 0 && *content > 0) {
2695 (*content)--;
2696 (*unhappy)++;
2697 unhappy_inc--;
2698 }
2699 while (unhappy_inc > 1 && *happy > 0) {
2700 (*happy)--;
2701 (*unhappy)++;
2702 unhappy_inc -= 2;
2703 }
2704 while (unhappy_inc > 0 && *happy > 0) {
2705 (*happy)--;
2706 (*content)++;
2707 unhappy_inc--;
2708 }
2709 }
2710 }
2711}
2712
2713/**********************************************************************/
2719static inline void citizen_happy_units(struct city *pcity)
2720{
2721 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2722 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2723 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2724 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2725 citizens amt = pcity->martial_law;
2726
2727 /* Pacify discontent citizens through martial law. First convert
2728 * angry => unhappy, then unhappy => content. */
2729 while (amt > 0 && *angry > 0) {
2730 (*angry)--;
2731 (*unhappy)++;
2732 amt--;
2733 }
2734 while (amt > 0 && *unhappy > 0) {
2735 (*unhappy)--;
2736 (*content)++;
2737 amt--;
2738 }
2739
2740 /* Now make citizens unhappier because of military units away from home.
2741 * First make content => unhappy, then happy => unhappy,
2742 * then happy => content. */
2743 amt = pcity->unit_happy_upkeep;
2744 while (amt > 0 && *content > 0) {
2745 (*content)--;
2746 (*unhappy)++;
2747 amt--;
2748 }
2749 while (amt > 1 && *happy > 0) {
2750 (*happy)--;
2751 (*unhappy)++;
2752 amt -= 2;
2753 }
2754 while (amt > 0 && *happy > 0) {
2755 (*happy)--;
2756 (*content)++;
2757 amt--;
2758 }
2759 /* Any remaining unhappiness is lost since angry citizens aren't created
2760 * here. */
2761 /* FIXME: Why not? - Per */
2762}
2763
2764/**********************************************************************/
2767static inline void citizen_happy_wonders(struct city *pcity)
2768{
2769 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2770 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2771 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2772 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2773 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2774
2775 /* First create happy citizens from content, then from unhappy
2776 * citizens; we cannot help angry citizens here. */
2777 while (bonus > 0 && *content > 0) {
2778 (*content)--;
2779 (*happy)++;
2780 bonus--;
2781 }
2782 while (bonus > 1 && *unhappy > 0) {
2783 (*unhappy)--;
2784 (*happy)++;
2785 bonus -= 2;
2786 }
2787 /* The rest falls through and lets unhappy people become content. */
2788
2790 *content += *unhappy + *angry;
2791 *unhappy = 0;
2792 *angry = 0;
2793 return;
2794 }
2795
2797
2798 /* get rid of angry first, then make unhappy content */
2799 while (bonus > 0 && *angry > 0) {
2800 (*angry)--;
2801 (*unhappy)++;
2802 bonus--;
2803 }
2804 while (bonus > 0 && *unhappy > 0) {
2805 (*unhappy)--;
2806 (*content)++;
2807 bonus--;
2808 }
2809}
2810
2811/**********************************************************************/
2815static inline void unhappy_city_check(struct city *pcity)
2816{
2817 if (city_unhappy(pcity)) {
2819 switch (output_types[o].unhappy_penalty) {
2821 pcity->unhappy_penalty[o] = 0;
2822 break;
2824 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2825 break;
2827 pcity->unhappy_penalty[o] = pcity->prod[o];
2828 break;
2829 }
2830
2831 pcity->prod[o] -= pcity->unhappy_penalty[o];
2833 } else {
2834 memset(pcity->unhappy_penalty, 0,
2835 O_LAST * sizeof(*pcity->unhappy_penalty));
2836 }
2837}
2838
2839/**********************************************************************/
2843 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2844{
2845 int prod, pop, mod;
2846
2847 /* Add one one pollution per shield, multiplied by the bonus. */
2849 prod = shield_total * MAX(prod, 0) / 100;
2850
2851 /* Add one pollution per citizen for baseline combined bonus (100%). */
2854 / 100;
2855 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2856
2857 /* Then there is base pollution (usually a negative number). */
2858 mod = game.info.base_pollution;
2859
2860 if (pollu_prod) {
2861 *pollu_prod = prod;
2862 }
2863 if (pollu_pop) {
2864 *pollu_pop = pop;
2865 }
2866 if (pollu_mod) {
2867 *pollu_mod = mod;
2868 }
2869 return MAX(prod + pop + mod, 0);
2870}
2871
2872/**********************************************************************/
2876int city_pollution(const struct city *pcity, int shield_total)
2877{
2879 nullptr, nullptr, nullptr);
2880}
2881
2882/**********************************************************************/
2889static int get_trade_illness(const struct city *pcity)
2890{
2891 float illness_trade = 0.0;
2892
2894 if (trade_city->turn_plague != -1
2895 && game.info.turn - trade_city->turn_plague < 5) {
2896 illness_trade += (float)game.info.illness_trade_infection
2897 * sqrt(1.0 * city_size_get(pcity)
2898 * city_size_get(trade_city)) / 100.0;
2899 }
2901
2902 return (int)illness_trade;
2903}
2904
2905/**********************************************************************/
2909static int get_city_health(const struct city *pcity)
2910{
2912}
2913
2914/**********************************************************************/
2926int city_illness_calc(const struct city *pcity, int *ill_base,
2927 int *ill_size, int *ill_trade, int *ill_pollution)
2928{
2929 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2931
2932 if (game.info.illness_on
2934 /* offset the city size by game.info.illness_min_size */
2936
2937 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2938 * 10.0 * game.info.illness_base_factor);
2939 if (is_server()) {
2940 /* On the server we recalculate the illness due to trade as we have
2941 * all the information */
2942 illness_trade = get_trade_illness(pcity);
2943 } else {
2944 /* On the client we have to rely on the value saved within the city
2945 * struct */
2946 illness_trade = pcity->illness_trade;
2947 }
2948
2949 illness_pollution = pcity->pollution
2951 }
2952
2953 illness_base = illness_size + illness_trade + illness_pollution;
2955
2956 /* returning other data */
2957 if (ill_size) {
2959 }
2960
2961 if (ill_trade) {
2962 *ill_trade = illness_trade;
2963 }
2964
2965 if (ill_pollution) {
2967 }
2968
2969 if (ill_base) {
2971 }
2972
2973 return CLIP(0, illness_base * illness_percent / 100 , 999);
2974}
2975
2976/**********************************************************************/
2980{
2981 /* Correctly handles special case turn_plague == -1 (never) */
2982 return (pcity->turn_plague == game.info.turn);
2983}
2984
2985/**********************************************************************/
2988int city_build_slots(const struct city *pcity)
2989{
2991}
2992
2993/**********************************************************************/
2998int city_airlift_max(const struct city *pcity)
2999{
3001}
3002
3003/**********************************************************************/
3009inline void set_city_production(struct city *pcity)
3010{
3011 int trade;
3012
3013 /* Calculate city production!
3014 *
3015 * This is a rather complicated process if we allow rules to become
3016 * more generalized. We can assume that there are no recursive dependency
3017 * loops, but there are some dependencies that do not follow strict
3018 * ordering. For instance corruption must be calculated before
3019 * trade taxes can be counted up, which must occur before the science bonus
3020 * is added on. But the calculation of corruption must include the
3021 * trade bonus. To do this without excessive special casing means that in
3022 * this case the bonuses are multiplied on twice (but only saved the second
3023 * time).
3024 */
3025
3027 pcity->prod[o] = pcity->citizen_base[o];
3029
3030 /* Add on special extra incomes: trade routes and tithes. */
3032 struct city *tcity = game_city_by_number(proute->partner);
3033 bool can_trade;
3034
3035 /* Partner city may have not yet been sent to the client, or
3036 * there's just a placeholder city with a placeholder owner
3037 * created for some tile->worked. */
3038 if (!is_server()
3039 && (tcity == nullptr
3040 || city_owner(tcity)->slot == nullptr)) {
3041 continue;
3042 }
3043
3044 fc_assert_action(tcity != nullptr, continue);
3045
3047
3048 if (!can_trade) {
3051
3052 if (settings->cancelling == TRI_ACTIVE) {
3053 can_trade = TRUE;
3054 }
3055 }
3056
3057 if (can_trade) {
3058 int value;
3059
3060 value =
3062 proute->value = trade_from_route(pcity, proute, value);
3063 pcity->prod[O_TRADE] += proute->value
3064 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3065 } else {
3066 proute->value = 0;
3067 }
3070
3071 /* Account for waste. Note that waste is calculated before tax income is
3072 * calculated, so if you had "science waste" it would not include taxed
3073 * science. However waste is calculated after the bonuses are multiplied
3074 * on, so shield waste will include shield bonuses. */
3076 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3077
3078 prod = MAX(prod, 0);
3079 pcity->waste[o] = city_waste(pcity, o, prod, nullptr);
3081
3082 /* Convert trade into science/luxury/gold, and add this on to whatever
3083 * science/luxury/gold is already there. */
3084 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3085 + pcity->abs_bonus[O_TRADE];
3086 trade = MAX(trade, 0);
3088 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3089 pcity->prod);
3090
3091 /* Add on effect bonuses and waste. Note that the waste calculation
3092 * (above) already includes the bonuses. */
3094 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3095
3096 prod = MAX(prod, 0);
3097 pcity->prod[o] = prod;
3098 pcity->prod[o] -= pcity->waste[o];
3100}
3101
3102/**********************************************************************/
3106 struct unit *punit, int *free_unhappy)
3107{
3108 struct city *pcity;
3109 const struct unit_type *ut;
3110 struct player *plr;
3111 int happy_cost;
3112
3113 if (punit == nullptr || free_unhappy == nullptr) {
3114 return 0;
3115 }
3116
3118 if (pcity == nullptr) {
3119 return 0;
3120 }
3121
3123 plr = unit_owner(punit);
3124 happy_cost = utype_happy_cost(ut, plr);
3125
3126 if (happy_cost <= 0) {
3127 return 0;
3128 }
3129
3131
3133 return 0;
3134 }
3135
3137 if (happy_cost <= 0) {
3138 return 0;
3139 }
3140
3141 if (*free_unhappy >= happy_cost) {
3142 *free_unhappy -= happy_cost;
3143 return 0;
3144 } else {
3145 happy_cost -= *free_unhappy;
3146 *free_unhappy = 0;
3147 }
3148
3149 return happy_cost;
3150}
3151
3152/**********************************************************************/
3156static inline void city_support(const struct civ_map *nmap,
3157 struct city *pcity)
3158{
3159 int free_unhappy;
3160 int max_mart_units;
3161
3162 /* Clear all usage values. */
3163 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3164 pcity->martial_law = 0;
3165 pcity->unit_happy_upkeep = 0;
3166
3167 /* Building and unit gold upkeep depends on the setting
3168 * 'game.info.gold_upkeep_style':
3169 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3170 * city.
3171 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3172 * The upkeep for units is paid by the nation.
3173 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3174 * nation. */
3176 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3177 switch (game.info.gold_upkeep_style) {
3178 case GOLD_UPKEEP_CITY:
3180 fc__fallthrough; /* No break */
3181 case GOLD_UPKEEP_MIXED:
3183 break;
3184 case GOLD_UPKEEP_NATION:
3185 /* nothing */
3186 break;
3187 }
3188 /* Food consumption by citizens. */
3190
3192 if (max_mart_units > 0) {
3194 int sel_count = 0;
3195 int i;
3196
3199 && unit_owner(punit) == city_owner(pcity)) {
3200 int current = get_target_bonus_effects(nullptr,
3201 &(const struct req_context) {
3202 .player = city_owner(pcity),
3203 .city = pcity,
3204 .tile = city_tile(pcity),
3205 .unit = punit,
3206 .unittype = unit_type_get(punit)
3207 },
3208 nullptr, EFT_MARTIAL_LAW_BY_UNIT);
3209 if (current > 0) {
3210 if (sel_count < max_mart_units) {
3211 best_units[sel_count++] = current;
3212 } else if (current > best_units[max_mart_units - 1]) {
3213 for (i = max_mart_units - 1; i >= 0 && current > best_units[i]; i--) {
3214 if (i + 1 < max_mart_units) {
3215 best_units[i + 1] = best_units[i];
3216 }
3217 }
3218
3219 best_units[i + 1] = current;
3220 }
3221 }
3222 }
3224
3225 pcity->martial_law = 0;
3226 for (i = 0; i < sel_count; i++) {
3227 pcity->martial_law += best_units[i];
3228 }
3229
3230 pcity->martial_law = MIN(pcity->martial_law, MAX_CITY_SIZE);
3231 }
3232
3234 unit_list_iterate(pcity->units_supported, punit) {
3235 pcity->unit_happy_upkeep += city_unit_unhappiness(nmap, punit, &free_unhappy);
3237 if (O_GOLD != o) {
3238 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3239 pcity->usage[o] += punit->upkeep[o];
3240 }
3243}
3244
3245/**********************************************************************/
3258 struct city *pcity, bool *workers_map)
3259{
3260 if (workers_map == nullptr) {
3261 /* Do a full refresh */
3262
3263 /* Calculate the bonus[] array values. */
3265 /* Calculate the tile_cache[] values. */
3267 /* Manage settlers, and units */
3269 }
3270
3271 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3272 get_worked_tile_output(nmap, pcity, pcity->citizen_base, workers_map);
3273 add_specialist_output(pcity, pcity->citizen_base);
3274
3277 /* Note that pollution is calculated before unhappy_city_check() makes
3278 * deductions for disorder; so a city in disorder still causes pollution */
3279 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3280
3282 citizen_happy_luxury(pcity); /* With our new found luxuries */
3283
3286
3289
3290 /* Martial law & unrest from units */
3293
3294 /* Building (including wonder) happiness effects */
3297
3300}
3301
3302/**********************************************************************/
3309int city_waste(const struct city *pcity, Output_type_id otype, int total,
3310 int *breakdown)
3311{
3312 int penalty_waste = 0;
3313 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3314 * corruption */
3315 int total_eft = total; /* Normal corruption calculated on total reduced by
3316 * possible size penalty */
3317 const struct output_type *output = get_output_type(otype);
3319 bool waste_all = FALSE;
3320
3321 if (otype == O_TRADE) {
3322 /* FIXME: special case for trade: it is affected by notradesize and
3323 * fulltradesize server settings.
3324 *
3325 * If notradesize and fulltradesize are equal then the city gets no
3326 * trade at that size. */
3327 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3328 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3329
3330 if (city_size_get(pcity) <= notradesize) {
3331 penalty_size = total_eft; /* Then no trade income. */
3332 } else if (city_size_get(pcity) >= fulltradesize) {
3333 penalty_size = 0;
3334 } else {
3335 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3336 / (fulltradesize - notradesize);
3337 }
3338 }
3339
3340 /* Apply corruption only to anything left after tradesize */
3342
3343 /* Distance-based waste.
3344 * Don't bother calculating if there's nothing left to lose. */
3345 if (total_eft > 0) {
3350 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3351 int min_dist;
3352 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3353
3354 if (gov_center == nullptr) {
3355 waste_all = TRUE; /* No gov center - no income */
3356 } else {
3358 if (waste_by_rel_dist > 0) {
3359 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3360 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3361 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3363 }
3364 }
3365 }
3366 }
3367
3368 if (waste_all) {
3370 } else {
3373
3374 /* Corruption/waste calculated only for the actually produced amount */
3375 if (waste_level > 0) {
3377 }
3378
3379 /* Bonus calculated only for the actually produced amount */
3381
3382 /* Clip */
3384 }
3385
3386 if (breakdown) {
3389 }
3390
3391 /* Add up total penalty */
3392 return penalty_waste + penalty_size;
3393}
3394
3395/**********************************************************************/
3400{
3401 citizens count = 0;
3402
3404 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3405 count += pcity->specialists[sp];
3407
3408 return count;
3409}
3410
3411/**********************************************************************/
3415{
3416 int count = 0;
3417
3419 count += pcity->specialists[sp];
3421
3422 return count;
3423}
3424
3425/**********************************************************************/
3431 const struct city *pcity)
3432{
3433 int best = DEFAULT_SPECIALIST;
3434 int val = get_specialist_output(pcity, best, otype);
3435
3439
3440 if (val2 > val) {
3441 best = i;
3442 val = val2;
3443 }
3444 }
3446
3447 return best;
3448}
3449
3450/**********************************************************************/
3454 const struct impr_type *pimprove)
3455{
3456 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3457
3458 if (is_server() && is_wonder(pimprove)) {
3459 /* Client just read the info from the packets. */
3460 wonder_built(pcity, pimprove);
3461 }
3462}
3463
3464/**********************************************************************/
3468 const struct impr_type *pimprove)
3469{
3470 log_debug("Improvement %s removed from city %s",
3471 improvement_rule_name(pimprove), pcity->name);
3472
3473 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3474
3475 if (is_server() && is_wonder(pimprove)) {
3476 /* Client just read the info from the packets. */
3477 wonder_destroyed(pcity, pimprove);
3478 }
3479}
3480
3481/**********************************************************************/
3485{
3486 return BV_ISSET(pcity->city_options, option);
3487}
3488
3489/**********************************************************************/
3493{
3494 int i;
3495
3496 city_styles = fc_calloc(num, sizeof(*city_styles));
3498
3499 for (i = 0; i < game.control.num_city_styles; i++) {
3501 }
3502}
3503
3504/**********************************************************************/
3508{
3509 int i;
3510
3511 for (i = 0; i < game.control.num_city_styles; i++) {
3513 }
3514
3516 city_styles = nullptr;
3518}
3519
3520/**********************************************************************/
3526struct city *create_city_virtual(struct player *pplayer,
3527 struct tile *ptile, const char *name)
3528{
3529 int i,len;
3530
3531 /* Make sure that contents of city structure are correctly initialized,
3532 * if you ever allocate it by some other mean than fc_calloc() */
3533 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3534
3535 fc_assert_ret_val(name != nullptr, nullptr); /* No unnamed cities! */
3536
3537 /* Do this early, so any logging later will have the city name */
3539
3540 pcity->tile = ptile;
3541
3542 fc_assert_ret_val(pplayer != nullptr, nullptr); /* No unowned cities! */
3543
3544 pcity->owner = pplayer;
3545 pcity->acquire_t = CACQ_FOUNDED;
3546
3547 if (is_server()) {
3548 pcity->original = pplayer;
3549 }
3550
3551 /* City structure was allocated with fc_calloc(), so contents are initially
3552 * zero. There is no need to initialize it a second time. */
3553
3554 /* Now set some useful default values. */
3555 pcity->capital = CAPITAL_NOT;
3556 city_size_set(pcity, 1);
3557 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3558 pcity->wlcb = WLCB_SMART;
3559
3561 pcity->bonus[o] = 100;
3562 pcity->abs_bonus[o] = 0;
3564
3565 pcity->turn_plague = -1; /* -1 = never */
3566 pcity->did_buy = FALSE;
3567 pcity->city_radius_sq = game.info.init_city_radius_sq;
3568 pcity->turn_founded = game.info.turn;
3569 pcity->turn_last_built = game.info.turn;
3570
3571 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3572
3573 /* pcity->ai.act_cache: worker activities on the city map */
3574
3575 /* Initialise improvements list */
3576 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3577 pcity->built[i].turn = I_NEVER;
3578 }
3579
3580 /* Set up the worklist */
3581 worklist_init(&pcity->worklist);
3582
3583 pcity->units_supported = unit_list_new();
3584 pcity->routes = trade_route_list_new();
3585 pcity->task_reqs = worker_task_list_new();
3586
3587 if (is_server()) {
3588 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3589
3590 CALL_FUNC_EACH_AI(city_alloc, pcity);
3591 } else {
3592 pcity->client.info_units_supported =
3594 pcity->client.info_units_present =
3596 /* collecting_info_units_supported set by fc_calloc().
3597 * collecting_info_units_present set by fc_calloc(). */
3598 }
3599
3601 pcity->counter_values = fc_malloc(sizeof(int) * len);
3602
3603 for (i = 0; i < len; i++) {
3604 pcity->counter_values[i] = counter_by_index(i, CTGT_CITY)->def;
3605 }
3606
3607 return pcity;
3608}
3609
3610/**********************************************************************/
3615{
3616 CALL_FUNC_EACH_AI(city_free, pcity);
3617
3619
3620 /* Free worker tasks */
3621 while (worker_task_list_size(pcity->task_reqs) > 0) {
3622 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3623
3624 worker_task_list_remove(pcity->task_reqs, ptask);
3625
3626 free(ptask);
3627 }
3628 worker_task_list_destroy(pcity->task_reqs);
3629
3630 /* Free rally points */
3632
3633 unit_list_destroy(pcity->units_supported);
3635 if (pcity->tile_cache != nullptr) {
3636 free(pcity->tile_cache);
3637 }
3638
3639 if (pcity->cm_parameter) {
3640 free(pcity->cm_parameter);
3641 }
3642
3643 if (pcity->counter_values) {
3644 free(pcity->counter_values);
3645 }
3646
3647 if (!is_server()) {
3648 unit_list_destroy(pcity->client.info_units_supported);
3649 unit_list_destroy(pcity->client.info_units_present);
3650 /* Handle a rare case where the game is freed in the middle of a
3651 * spy/diplomat investigate cycle. */
3652 if (pcity->client.collecting_info_units_supported != nullptr) {
3653 unit_list_destroy(pcity->client.collecting_info_units_supported);
3654 }
3655 if (pcity->client.collecting_info_units_present != nullptr) {
3656 unit_list_destroy(pcity->client.collecting_info_units_present);
3657 }
3658 }
3659
3660 free(pcity->name);
3661
3662 memset(pcity, 0, sizeof(*pcity)); /* Ensure no pointers remain */
3663 free(pcity);
3664}
3665
3666/**********************************************************************/
3670bool city_exist(int id)
3671{
3672 /* Check if city exist in game */
3673 if (game_city_by_number(id)) {
3674 return TRUE;
3675 }
3676
3677 return FALSE;
3678}
3679
3680/**********************************************************************/
3687bool city_is_virtual(const struct city *pcity)
3688{
3689 if (!pcity) {
3690 return FALSE;
3691 }
3692
3693 return pcity != game_city_by_number(pcity->id);
3694}
3695
3696/**********************************************************************/
3699bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3700{
3701 return is_city_center(pcity, ptile);
3702}
3703
3704/**********************************************************************/
3707void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3708{
3709 return pcity->server.ais[ai_type_number(ai)];
3710}
3711
3712/**********************************************************************/
3715void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3716 void *data)
3717{
3718 pcity->server.ais[ai_type_number(ai)] = data;
3719}
3720
3721/**********************************************************************/
3725{
3726 /* Free rally points */
3727 if (pcity->rally_point.length > 0) {
3728 pcity->rally_point.length = 0;
3729 pcity->rally_point.persistent = FALSE;
3730 pcity->rally_point.vigilant = FALSE;
3731 free(pcity->rally_point.orders);
3732 pcity->rally_point.orders = nullptr;
3733 }
3734}
3735
3736/**********************************************************************/
3740 struct city *pcity)
3741{
3742 struct unit_order *checked_orders;
3743 const struct civ_map *nmap = &(wld.map);
3744
3745 if (pcity == nullptr) {
3746 /* Probably lost. */
3747 log_verbose("handle_city_rally_point() bad city number %d.",
3748 packet->id);
3749 return;
3750 }
3751
3752 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3753 /* Shouldn't happen */
3754 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3755 packet->length, MAX_LEN_ROUTE);
3756 return;
3757 }
3758
3759 pcity->rally_point.length = packet->length;
3760
3761 if (packet->length == 0) {
3762 pcity->rally_point.vigilant = FALSE;
3763 pcity->rally_point.persistent = FALSE;
3764 if (pcity->rally_point.orders) {
3765 free(pcity->rally_point.orders);
3766 pcity->rally_point.orders = nullptr;
3767 }
3768 } else {
3770 packet->orders);
3771 if (!checked_orders) {
3772 pcity->rally_point.length = 0;
3773 log_error("invalid rally point orders for %s.",
3775 return;
3776 }
3777
3778 pcity->rally_point.persistent = packet->persistent;
3779 pcity->rally_point.vigilant = packet->vigilant;
3780 pcity->rally_point.orders = checked_orders;
3781 }
3782}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1580
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:245
#define action_enabler_list_iterate_end
Definition actions.h:194
#define action_by_result_iterate_end
Definition actions.h:249
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:192
#define action_id(_act_)
Definition actions.h:426
int ai_type_number(const struct ai_type *ai)
Definition ai.c:278
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:390
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
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:1692
bool city_is_virtual(const struct city *pcity)
Definition city.c:3687
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:2020
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2599
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:666
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:834
static void citizen_content_buildings(struct city *pcity)
Definition city.c:2646
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3699
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1915
static bv_imprs caravan_helped_impr
Definition city.c:1826
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:148
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:740
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1199
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2215
#define POLLUTION_EFT_NEARMAX
Definition city.c:1163
const char * city_name_getx(const struct city *pcity)
Definition city.c:1164
int city_granary_size(int city_size)
Definition city.c:2187
static void get_worked_tile_output(const struct civ_map *nmap, const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2379
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2251
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2842
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3715
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2767
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2147
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2334
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1103
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3309
static void city_support(const struct civ_map *nmap, struct city *pcity)
Definition city.c:3156
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2988
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:305
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1294
const char * city_style_name_translation(const int style)
Definition city.c:1811
void city_styles_free(void)
Definition city.c:3507
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2493
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:650
int city_superspecialists(const struct city *pcity)
Definition city.c:3414
bool is_capital(const struct city *pcity)
Definition city.c:1634
void city_styles_alloc(int num)
Definition city.c:3492
const char * city_name_get(const struct city *pcity)
Definition city.c:1155
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1065
void city_production_caravan_shields_init(void)
Definition city.c:1833
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3467
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1310
int city_airlift_max(const struct city *pcity)
Definition city.c:2998
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1520
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1047
struct output_type * get_output_type(Output_type_id output)
Definition city.c:640
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3484
int city_population(const struct city *pcity)
Definition city.c:1245
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1820
void city_size_add(struct city *pcity, int add)
Definition city.c:1218
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1081
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:730
bool city_is_occupied(const struct city *pcity)
Definition city.c:1720
void free_city_map_index(void)
Definition city.c:609
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:808
void add_tax_income(const struct player *pplayer, int trade, int *output)
Definition city.c:2300
bool city_tile_index_to_xy(int *city_map_x, int *city_map_y, int city_tile_index, int city_radius_sq)
Definition city.c:101
struct city * tile_non_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2121
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3105
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1651
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2241
bool city_map_includes_tile(const struct city *const pcity, const struct tile *map_tile)
Definition city.c:293
static void city_tile_cache_update(const struct civ_map *nmap, struct city *pcity)
Definition city.c:2464
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2282
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2136
void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
Definition city.c:411
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:1708
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:824
bool city_unhappy(const struct city *pcity)
Definition city.c:1681
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3430
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3526
void set_city_production(struct city *pcity)
Definition city.c:3009
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:860
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1734
static bv_unit_types caravan_helped_utype
Definition city.c:1827
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2267
bool city_celebrating(const struct city *pcity)
Definition city.c:1700
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1615
const char * get_output_identifier(Output_type_id output)
Definition city.c:619
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2926
const char * get_output_name(Output_type_id output)
Definition city.c:630
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2067
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1941
static int get_city_health(const struct city *pcity)
Definition city.c:2909
bool is_valid_city_coords(const int city_radius_sq, const int city_map_x, const int city_map_y)
Definition city.c:188
void city_refresh_from_main_map(const struct civ_map *nmap, struct city *pcity, bool *workers_map)
Definition city.c:3257
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1006
static void set_city_bonuses(struct city *pcity)
Definition city.c:2441
static void set_surpluses(struct city *pcity)
Definition city.c:2507
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2342
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:911
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1542
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2876
bool city_happy(const struct city *pcity)
Definition city.c:1669
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1234
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3453
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1439
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
struct city * tile_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2091
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2076
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:446
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:281
void destroy_city_virtual(struct city *pcity)
Definition city.c:3614
int rs_max_city_radius_sq(void)
Definition city.c:159
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:264
citizens city_specialists(const struct city *pcity)
Definition city.c:3399
static char * citylog_map_line(int y, int city_radius_sq, int *city_map_data)
Definition city.c:369
void city_rally_point_receive(const struct packet_city_rally_point *packet, struct city *pcity)
Definition city.c:3739
static int cmp(int v1, int v2)
Definition city.c:325
#define CITYLOG_MAX_VAL
Definition city.c:368
int city_style_by_translated_name(const char *s)
Definition city.c:1776
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2419
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:957
static const struct city struct citystyle * city_styles
Definition city.c:84
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3707
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1750
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2670
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1338
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:123
bool is_gov_center(const struct city *pcity)
Definition city.c:1642
#define log_ca_s_init
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1027
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2636
int city_map_tiles(int city_radius_sq)
Definition city.c:171
static void unhappy_city_check(struct city *pcity)
Definition city.c:2815
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2106
bool city_exist(int id)
Definition city.c:3670
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1511
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:720
int compare_iter_index(const void *a, const void *b)
Definition city.c:343
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:750
int city_turns_to_grow(const struct city *pcity)
Definition city.c:2051
void city_rally_point_clear(struct city *pcity)
Definition city.c:3724
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:879
struct output_type output_types[O_LAST]
Definition city.c:88
bool city_exists_within_max_city_map(const struct civ_map *nmap, const struct tile *ptile, bool may_be_on_center)
Definition city.c:2167
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2979
static int get_trade_illness(const struct city *pcity)
Definition city.c:2889
bool city_can_change_build(const struct city *pcity)
Definition city.c:1095
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:982
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1276
int city_style_by_rule_name(const char *s)
Definition city.c:1793
static void citizen_base_mood(struct city *pcity)
Definition city.c:2560
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1766
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1255
static void citizen_happy_units(struct city *pcity)
Definition city.c:2719
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2548
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:703
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:565
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:254
@ UNHAPPY_PENALTY_NONE
Definition city.h:252
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:253
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, _index)
Definition city.h:199
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:84
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
#define CITY_MAP_MAX_SIZE
Definition city.h:92
#define city_tile_iterate_index_end
Definition city.h:207
@ CITIZEN_LAST
Definition city.h:270
@ CITIZEN_ANGRY
Definition city.h:269
@ CITIZEN_HAPPY
Definition city.h:266
@ CITIZEN_CONTENT
Definition city.h:267
@ CITIZEN_UNHAPPY
Definition city.h:268
#define CITY_MAP_CENTER_RADIUS_SQ
Definition city.h:87
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:82
#define output_type_iterate(output)
Definition city.h:851
#define CITY_REL2ABS(_coor)
Definition city.h:113
#define city_owner(_pcity_)
Definition city.h:564
#define MAX_CITY_SIZE
Definition city.h:104
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:874
#define city_list_iterate_end
Definition city.h:510
#define I_DESTROYED
Definition city.h:246
#define I_NEVER
Definition city.h:245
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:228
citizen_feeling
Definition city.h:276
@ FEELING_EFFECT
Definition city.h:279
@ FEELING_LUXURY
Definition city.h:278
@ FEELING_FINAL
Definition city.h:282
@ FEELING_BASE
Definition city.h:277
@ FEELING_NATIONALITY
Definition city.h:280
@ FEELING_MARTIAL
Definition city.h:281
@ OLOSS_SIZE
Definition city.h:289
@ OLOSS_WASTE
Definition city.h:288
#define city_map_iterate_end
Definition city.h:175
#define city_map_iterate(_radius_sq, _index, _x, _y)
Definition city.h:171
#define city_tile_iterate_end
Definition city.h:236
#define city_built_iterate(_pcity, _p)
Definition city.h:840
#define is_free_worked_index(city_tile_index)
Definition city.h:886
#define city_map_tiles_from_city(_pcity)
Definition city.h:125
#define CITY_ABS2REL(_coor)
Definition city.h:114
#define city_built_iterate_end
Definition city.h:846
#define PCT_LAST
Definition city.h:41
#define output_type_iterate_end
Definition city.h:857
void cm_init_citymap(void)
Definition cm.c:314
char * incite_cost
Definition comments.c:77
#define MAX_LEN_ROUTE
Definition conn_types.h:38
struct counter * counter_by_index(int index, enum counter_target target)
Definition counters.c:186
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 const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
void distribute(int number, unsigned groups, const unsigned *ratios, int *result)
Definition distribute.c:34
struct @22::@23 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:938
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:983
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:913
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
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:1036
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
static bool is_server(void)
unsigned char citizens
Definition fc_types.h:249
req_problem_type
Definition fc_types.h:514
@ RPT_CERTAIN
Definition fc_types.h:516
@ RPT_POSSIBLE
Definition fc_types.h:515
int Specialist_type_id
Definition fc_types.h:236
@ CTGT_CITY
Definition fc_types.h:128
#define CITY_MAP_MAX_RADIUS
Definition fc_types.h:85
output_type_id
Definition fc_types.h:102
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
@ O_SCIENCE
Definition fc_types.h:103
@ O_LUXURY
Definition fc_types.h:103
@ O_GOLD
Definition fc_types.h:103
@ O_LAST
Definition fc_types.h:103
#define MAX_LEN_CITYNAME
Definition fc_types.h:69
enum output_type_id Output_type_id
Definition fc_types.h:239
#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:106
struct government * government_of_player(const struct player *pplayer)
Definition government.c:119
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
bool is_building_sellable(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)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove, const enum req_problem_type prob_type)
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:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_warn(message,...)
Definition log.h:106
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_do_output_for_level(level)
Definition log.h:90
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_base(level, message,...)
Definition log.h:95
log_level
Definition log.h:29
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:434
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:659
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:1085
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1222
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:397
#define square_iterate_end
Definition map.h:400
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:229
#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:350
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:496
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:120
int len
Definition packhand.c:128
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1376
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1397
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1451
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:432
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1485
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
bool are_reqs_active(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, enum req_problem_type prob_type)
bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, const struct req_context *other_context, 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)
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:1494
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:110
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Definition specialist.c:270
#define specialist_type_iterate_end
Definition specialist.h:85
#define specialist_type_iterate(sp)
Definition specialist.h:79
#define normal_specialist_type_iterate(sp)
Definition specialist.h:89
#define super_specialist_type_iterate_end
Definition specialist.h:105
#define super_specialist_type_iterate(sp)
Definition specialist.h:99
#define DEFAULT_SPECIALIST
Definition specialist.h:43
#define normal_specialist_type_iterate_end
Definition specialist.h:95
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
Definition city.h:318
int surplus[O_LAST]
Definition city.h:353
bv_city_options city_options
Definition city.h:401
int style
Definition city.h:325
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
struct requirement_vector reqs
Definition improvement.h:58
int dist
Definition city.h:108
int dx
Definition city.h:108
int dy
Definition city.h:108
const char * id
Definition city.h:260
struct unit_order orders[MAX_LEN_ROUTE]
int granary_food_ini[MAX_GRANARY_INIS]
enum gold_upkeep_style gold_upkeep_style
int min_city_center_output[O_LAST]
struct city_list * cities
Definition player.h:281
struct unit_list * units
Definition player.h:282
struct player_economic economic
Definition player.h:284
const struct player * player
struct requirement_vector reqs
Definition specialist.h:38
int irrigation_food_incr
Definition terrain.h:114
int output[O_LAST]
Definition terrain.h:95
int mining_shield_incr
Definition terrain.h:117
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:559
int upkeep[O_LAST]
Definition unittype.h:545
Definition unit.h:140
int length
Definition unit.h:198
int upkeep[O_LAST]
Definition unit.h:150
bool occupied
Definition unit.h:222
int id
Definition unit.h:147
struct unit::@83 orders
bool vigilant
Definition unit.h:200
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
struct unit::@84::@86 client
enum unit_activity changed_from
Definition unit.h:171
void * ais[FREECIV_AI_MOD_LAST]
Definition unit.h:240
int homecity
Definition unit.h:148
const struct unit_type * utype
Definition unit.h:141
struct player * owner
Definition unit.h:145
enum universals_n kind
Definition fc_types.h:595
universals_u value
Definition fc_types.h:594
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:960
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define sz_strlcpy(dest, src)
Definition support.h:195
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
#define fc__fallthrough
Definition support.h:119
#define T_UNKNOWN
Definition terrain.h:62
#define terrain_has_flag(terr, flag)
Definition terrain.h:177
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:292
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:272
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:393
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:89
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:108
#define tile_worked(_tile)
Definition tile.h:119
#define tile_resource(_tile)
Definition tile.h:103
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:115
#define tile_owner(_tile)
Definition tile.h:97
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:536
const struct impr_type * building
Definition fc_types.h:529
struct unit_order * create_unit_orders(const struct civ_map *nmap, int length, const struct unit_order *orders)
Definition unit.c:2923
bool unit_being_aggressive(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:1576
bool is_field_unit(const struct unit *punit)
Definition unit.c:457
bool is_martial_law_unit(const struct unit *punit)
Definition unit.c:335
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1786
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1418
#define unit_tile(_pu)
Definition unit.h:408
#define unit_owner(_pu)
Definition unit.h:407
#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:2303
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2662
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:980
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:114
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, const enum req_problem_type prob_type, bool consider_reg_impr_req)
Definition unittype.c:1995
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1554
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2130
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
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:1042
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Definition unittype.c:206
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:865
#define unit_type_iterate_end
Definition unittype.h:872
#define U_NOT_OBSOLETED
Definition unittype.h:535
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
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT