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{
916 return FALSE;
917 }
918
919 /* Check unit build requirements.
920 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
921 * Don't recheck those. Not only for optimization, but also not to override the
922 * special handling of tech requirements for barbarians */
923 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
925 &(const struct req_context) {
926 .player = city_owner(pcity),
927 .city = pcity,
928 .tile = city_tile(pcity),
929 .unittype = punittype,
930 },
931 nullptr,
932 &punittype->build_reqs, RPT_CERTAIN)) {
933 return FALSE;
934 }
935
936 /* You can't build naval units inland. */
939 pcity->tile)) {
940 return FALSE;
941 }
942
943 if (punittype->city_slots > 0
944 && city_unit_slots_available(pcity) < punittype->city_slots) {
945 return FALSE;
946 }
947
948 return TRUE;
949}
950
951/**********************************************************************/
956 const struct city *pcity,
957 const struct unit_type *punittype)
958{
960 return FALSE;
961 }
962
963 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
964 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
965 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
967 return FALSE;
968 }
969 }
970
971 return TRUE;
972}
973
974/**********************************************************************/
979 const struct city *pcity,
980 const struct unit_type *punittype)
981{
982 /* Can the _player_ ever build this unit? */
984 return FALSE;
985 }
986
987 /* Some units can be built only in certain cities -- for instance,
988 ships may be built only in cities adjacent to ocean. */
991 pcity->tile)) {
992 return FALSE;
993 }
994
995 return TRUE;
996}
997
998/**********************************************************************/
1003 const struct city *pcity,
1004 const struct universal *target)
1005{
1006 switch (target->kind) {
1007 case VUT_UTYPE:
1009 case VUT_IMPROVEMENT:
1011 RPT_CERTAIN);
1012 default:
1013 break;
1014 };
1015 return FALSE;
1016}
1017
1018/**********************************************************************/
1023 const struct city *pcity,
1024 const struct universal *target)
1025{
1026 switch (target->kind) {
1027 case VUT_UTYPE:
1028 return can_city_build_unit_now(nmap, pcity, target->value.utype);
1029 case VUT_IMPROVEMENT:
1031 RPT_CERTAIN);
1032 default:
1033 break;
1034 };
1035 return FALSE;
1036}
1037
1038/**********************************************************************/
1042 const struct city *pcity,
1043 const struct universal *target)
1044{
1045 switch (target->kind) {
1046 case VUT_UTYPE:
1048 case VUT_IMPROVEMENT:
1050 default:
1051 break;
1052 };
1053 return FALSE;
1054}
1055
1056/**********************************************************************/
1060{
1062 int current;
1063
1064 current = 0;
1065 unit_list_iterate(pcity->units_supported, punit) {
1066 current += unit_type_get(punit)->city_slots;
1068
1069 return max - current;
1070}
1071
1072/**********************************************************************/
1077{
1078 return are_reqs_active(&(const struct req_context) {
1079 .player = city_owner(pcity),
1080 .city = pcity,
1081 },
1082 nullptr,
1084}
1085
1086/**********************************************************************/
1090{
1091 return !pcity->did_buy || pcity->shield_stock <= 0;
1092}
1093
1094/**********************************************************************/
1098{
1099 if (city_tile(pcity) == nullptr) {
1100 /* When a "dummy" city is created with no tile, then choosing a build
1101 * target could fail. This currently might happen during map editing.
1102 * FIXME: assumes the first unit is always "valid", so check for
1103 * obsolete units elsewhere. */
1104 pcity->production.kind = VUT_UTYPE;
1105 pcity->production.value.utype = utype_by_number(0);
1106 } else {
1108
1109 if (u) {
1110 pcity->production.kind = VUT_UTYPE;
1111 pcity->production.value.utype = u;
1112 } else {
1113 bool found = FALSE;
1114
1115 /* Just pick the first available item. */
1116 improvement_iterate(pimprove) {
1118 RPT_CERTAIN)) {
1119 found = TRUE;
1120 pcity->production.kind = VUT_IMPROVEMENT;
1121 pcity->production.value.building = pimprove;
1122 break;
1123 }
1125
1126 if (!found) {
1129#ifndef FREECIV_NDEBUG
1130 /* Later than this, 'found' is only needed in an fc_assert() */
1131 found = TRUE;
1132#endif /* FREECIV_NDEBUG */
1133 pcity->production.kind = VUT_UTYPE;
1134 pcity->production.value.utype = punittype;
1135 }
1137 }
1138
1139 fc_assert_msg(found, "No production found for city %s!",
1141 }
1142 }
1143}
1144
1145/**********************************************************************/
1148const char *city_name_get(const struct city *pcity)
1149{
1150 return (pcity->name != nullptr) ? pcity->name : "City missing a name";
1151}
1152
1153/**********************************************************************/
1156#define POLLUTION_EFT_NEARMAX -95
1157const char *city_name_getx(const struct city *pcity)
1158{
1159 bool spacer = FALSE;
1160 static char em_city_name[MAX_LEN_CITYNAME + 7];
1161
1162 em_city_name[0] = '\0';
1163
1165 sz_strlcat(em_city_name, "ₓ"); /* ₓ🞪⁻⁰… (alternatives)*/
1166 }
1167
1169
1170 if (get_city_bonus(pcity, EFT_AIRLIFT) > 0) {
1171 if (!spacer) {
1173 spacer = TRUE;
1174 }
1175 sz_strlcat(em_city_name, "🛧"); /* 🛧🛪 (alternatives)*/
1176 }
1177
1179 if (!spacer) {
1181 spacer = TRUE;
1182 }
1183 sz_strlcat(em_city_name, "♺"); /* ♺♻♳ (alternatives)*/
1184 }
1185
1186 return em_city_name;
1187}
1188
1189/**********************************************************************/
1192void city_name_set(struct city *pcity, const char *new_name)
1193{
1194 if (pcity->name != nullptr) {
1195 free(pcity->name);
1196 }
1197
1198 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1199 pcity->name = fc_strdup(new_name);
1200 } else {
1201 log_warn(_("City name \"%s\" too long"), new_name);
1203 sz_strlcpy(pcity->name, new_name);
1204 }
1205}
1206
1207/**********************************************************************/
1211void city_size_add(struct city *pcity, int add)
1212{
1214
1215 fc_assert_ret(pcity != nullptr);
1217
1218 /* Client sets size to zero to start stacking citizens in */
1219 fc_assert_ret(size > -add || (!is_server() && size == add));
1220
1221 city_size_set(pcity, size + add);
1222}
1223
1224/**********************************************************************/
1228{
1229 fc_assert_ret(pcity != nullptr);
1230
1231 /* Set city size. */
1232 pcity->size = size;
1233}
1234
1235/**********************************************************************/
1238int city_population(const struct city *pcity)
1239{
1240 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1241 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1242}
1243
1244/**********************************************************************/
1249{
1250 int gold_needed = 0;
1251
1252 if (pcity == nullptr) {
1253 return 0;
1254 }
1255
1256 city_built_iterate(pcity, pimprove) {
1257 gold_needed += city_improvement_upkeep(pcity, pimprove);
1259
1261
1262 return MAX(gold_needed, 0);
1263}
1264
1265/**********************************************************************/
1270{
1271 int gold_needed = 0;
1272
1273 if (pcity == nullptr || pcity->units_supported == nullptr) {
1274 return 0;
1275 }
1276
1277 unit_list_iterate(pcity->units_supported, punit) {
1278 gold_needed += punit->upkeep[O_GOLD];
1280
1281 return gold_needed;
1282}
1283
1284/**********************************************************************/
1287bool city_has_building(const struct city *pcity,
1288 const struct impr_type *pimprove)
1289{
1290 if (pimprove == nullptr) {
1291 /* Callers should ensure that any external data is tested with
1292 * valid_improvement_by_number() */
1293 return FALSE;
1294 }
1295
1296 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1297}
1298
1299/**********************************************************************/
1304 const struct impr_type *b)
1305{
1306 int upkeep;
1307
1308 if (b == nullptr) {
1309 return 0;
1310 }
1311 if (!is_building_sellable(b)) {
1312 return 0;
1313 }
1314
1315 upkeep = b->upkeep;
1317 return 0;
1318 }
1319
1320 return upkeep;
1321}
1322
1323/**********************************************************************/
1331int city_tile_output(const struct city *pcity, const struct tile *ptile,
1333{
1334 int prod;
1335 const struct req_context city_ctxt = {
1336 .player = pcity ? city_owner(pcity) : nullptr,
1337 .city = pcity,
1338 .tile = ptile,
1339 };
1340 struct terrain *pterrain = tile_terrain(ptile);
1341 const struct output_type *output = &output_types[otype];
1342
1343 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1344
1345 if (T_UNKNOWN == pterrain) {
1346 /* Special case for the client. The server doesn't allow unknown tiles
1347 * to be worked but we don't necessarily know what player is involved. */
1348 return 0;
1349 }
1350
1351 prod = pterrain->output[otype];
1352 if (tile_resource_is_valid(ptile)) {
1353 prod += tile_resource(ptile)->data.resource->output[otype];
1354 }
1355
1356 switch (otype) {
1357 case O_SHIELD:
1358 if (pterrain->mining_shield_incr != 0) {
1359 prod += pterrain->mining_shield_incr
1361 / 100;
1362 }
1363 break;
1364 case O_FOOD:
1365 if (pterrain->irrigation_food_incr != 0) {
1366 prod += pterrain->irrigation_food_incr
1367 * get_target_bonus_effects(nullptr, &city_ctxt, nullptr,
1368 EFT_IRRIGATION_PCT) / 100;
1369 }
1370 break;
1371 case O_TRADE:
1372 case O_GOLD:
1373 case O_SCIENCE:
1374 case O_LUXURY:
1375 case O_LAST:
1376 break;
1377 }
1378
1379 prod += tile_roads_output_incr(ptile, otype);
1380 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1381
1382 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1383 if (prod > 0) {
1384 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1386
1387 if (prod >= game.info.granularity) {
1388 prod += get_tile_output_bonus(pcity, ptile, output,
1390
1391 if (is_celebrating) {
1392 prod += get_tile_output_bonus(pcity, ptile, output,
1394 }
1395 }
1396
1397 prod += (prod
1398 * get_tile_output_bonus(pcity, ptile, output,
1400 / 100;
1401 if (penalty_limit > 0 && prod > penalty_limit) {
1402 if (prod <= game.info.granularity) {
1403 prod = 0;
1404 } else {
1405 prod -= game.info.granularity;
1406 }
1407 }
1408 }
1409
1410 prod -= (prod
1411 * get_tile_output_bonus(pcity, ptile, output,
1413 / 100;
1414
1415 if (pcity != nullptr && is_city_center(pcity, ptile)) {
1416 prod = MAX(prod, game.info.min_city_center_output[otype]);
1417 }
1418
1419 return prod;
1420}
1421
1422/**********************************************************************/
1432int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1434{
1436}
1437
1438/**********************************************************************/
1450 const struct city *pcity,
1451 const struct tile *ptile)
1452{
1453 struct player *powner = city_owner(pcity);
1455 struct player *towner;
1456
1457 if (ptile == nullptr) {
1458 return FALSE;
1459 }
1460
1462 return FALSE;
1463 }
1464
1465 if (restriction != nullptr
1466 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1467 return FALSE;
1468 }
1469
1470 towner = tile_owner(ptile);
1471 if (towner != nullptr && towner != powner
1472 && !gives_shared_tiles(towner, powner)) {
1473 return FALSE;
1474 }
1475 /* TODO: civ3-like option for borders */
1476
1477 if (tile_worked(ptile) != nullptr && tile_worked(ptile) != pcity) {
1478 return FALSE;
1479 }
1480
1481 if (powner == restriction
1482 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1483 return FALSE;
1484 }
1485
1486 if (!is_free_worked(pcity, ptile)
1487 && unit_occupies_tile(ptile, powner) != nullptr) {
1488 return FALSE;
1489 }
1490
1491 if (get_city_tile_output_bonus(pcity, ptile, nullptr, EFT_TILE_WORKABLE) <= 0) {
1492 return FALSE;
1493 }
1494
1495 return TRUE;
1496}
1497
1498/**********************************************************************/
1504bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1505{
1507}
1508
1509/**********************************************************************/
1514 const struct tile *ptile)
1515{
1516 /* citymindist minimum is 1, meaning adjacent is okay */
1517 int citymindist = game.info.citymindist;
1518
1519 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1520 if (tile_city(ptile1)) {
1521 return TRUE;
1522 }
1524
1525 return FALSE;
1526}
1527
1528/**********************************************************************/
1536 const struct tile *ptile,
1537 const struct unit *punit,
1538 bool hut_test)
1539{
1540 if (!city_can_be_built_tile_only(nmap, ptile)) {
1541 return FALSE;
1542 }
1543
1544 if (punit == nullptr) {
1545 /* The remaining checks tests if punit can found a city here */
1546 return TRUE;
1547 }
1548
1549 if (hut_test) {
1550 struct player *towner;
1551
1552 /* Huts can be found only from native tiles, owned by the unit owner.
1553 * Unlike actual city building, this behavior is not affected
1554 * by the ruleset. */
1555 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1556 return FALSE;
1557 }
1558
1559 towner = tile_owner(ptile);
1560
1561 if (towner == nullptr || towner == unit_owner(punit)) {
1562 return TRUE;
1563 }
1564
1565 return FALSE;
1566 }
1567
1570 /* This action can't be done by this unit type at all. */
1571 continue;
1572 }
1573
1574 /* Non native tile detection */
1575 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1576 /* The ruleset may allow founding cities on non native terrain. */
1579 /* Many rulesets allow land units to build land cities and sea units
1580 * to build ocean cities. Air units can build cities anywhere. */
1581 continue;
1582 }
1583
1584 /* Foreign tile detection. */
1585 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1586 /* The ruleset may allow founding cities on foreign terrain. */
1588 paction->id,
1589 DRO_FOREIGN, TRUE)) {
1590 /* Cannot steal borders by settling. This has to be settled by
1591 * force of arms. */
1592 continue;
1593 }
1594
1595 return TRUE;
1597
1598 return FALSE;
1599}
1600
1601/**********************************************************************/
1609 const struct tile *ptile)
1610{
1612 /* No cities on this terrain. */
1613 return FALSE;
1614 }
1615
1617 return FALSE;
1618 }
1619
1620 return TRUE;
1621}
1622
1623/**********************************************************************/
1627bool is_capital(const struct city *pcity)
1628{
1629 return pcity->capital != CAPITAL_NOT;
1630}
1631
1632/**********************************************************************/
1635bool is_gov_center(const struct city *pcity)
1636{
1637 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1638}
1639
1640/**********************************************************************/
1645 const struct unit_type *attacker)
1646{
1647 if (!attacker) {
1648 /* Any defense building will do */
1650 }
1651
1652 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1653 nullptr, EFT_DEFEND_BONUS) > 0;
1654}
1655
1656/**********************************************************************/
1662bool city_happy(const struct city *pcity)
1663{
1665 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1666 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1667 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1668}
1669
1670/**********************************************************************/
1674bool city_unhappy(const struct city *pcity)
1675{
1676 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1678 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1679}
1680
1681/**********************************************************************/
1686{
1687 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1688}
1689
1690/**********************************************************************/
1693bool city_celebrating(const struct city *pcity)
1694{
1696}
1697
1698/**********************************************************************/
1701bool city_rapture_grow(const struct city *pcity)
1702{
1703 /* .rapture is checked instead of city_celebrating() because this
1704 function is called after .was_happy was updated. */
1705 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1706 && (pcity->rapture % game.info.rapturedelay) == 0
1708}
1709
1710/**********************************************************************/
1713bool city_is_occupied(const struct city *pcity)
1714{
1715 if (is_server()) {
1716 /* The server sees the units inside the city. */
1717 return (unit_list_size(city_tile(pcity)->units) > 0);
1718 } else {
1719 /* The client gets the occupied property from the server. */
1720 return pcity->client.occupied;
1721 }
1722}
1723
1724/**********************************************************************/
1727struct city *city_list_find_number(struct city_list *This, int id)
1728{
1729 if (id != 0) {
1731 if (pcity->id == id) {
1732 return pcity;
1733 }
1735 }
1736
1737 return nullptr;
1738}
1739
1740/**********************************************************************/
1743struct city *city_list_find_name(struct city_list *This, const char *name)
1744{
1746 if (fc_strcasecmp(name, pcity->name) == 0) {
1747 return pcity;
1748 }
1750
1751 return nullptr;
1752}
1753
1754/**********************************************************************/
1759int city_name_compare(const void *p1, const void *p2)
1760{
1761 return fc_strcasecmp((*(const struct city **) p1)->name,
1762 (*(const struct city **) p2)->name);
1763}
1764
1765/**********************************************************************/
1770{
1771 int i;
1772
1773 for (i = 0; i < game.control.num_city_styles; i++) {
1774 if (0 == strcmp(city_style_name_translation(i), s)) {
1775 return i;
1776 }
1777 }
1778
1779 return -1;
1780}
1781
1782/**********************************************************************/
1786int city_style_by_rule_name(const char *s)
1787{
1788 const char *qs = Qn_(s);
1789 int i;
1790
1791 for (i = 0; i < game.control.num_city_styles; i++) {
1792 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1793 return i;
1794 }
1795 }
1796
1797 return -1;
1798}
1799
1800/**********************************************************************/
1805{
1807}
1808
1809/**********************************************************************/
1813const char *city_style_rule_name(const int style)
1814{
1816}
1817
1818/* Cache of what city production caravan shields are allowed to help. */
1821
1822/**********************************************************************/
1827{
1828 struct requirement prod_as_req;
1829
1830#define log_ca_s_init log_debug
1831
1832 /* Remove old data. */
1835
1836 /* Common for all production kinds. */
1838 prod_as_req.survives = FALSE;
1839 prod_as_req.present = TRUE;
1840
1841 /* Check improvements */
1842 prod_as_req.source.kind = VUT_IMPROVEMENT;
1843
1845 /* Check this improvement. */
1846 prod_as_req.source.value.building = itype;
1847
1850 enabler) {
1852 &(enabler->target_reqs))
1853 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1854 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1855 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1856 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1857 /* This improvement kind can receive caravan shields. */
1858
1860
1861 /* Move on to the next improvement */
1862 break;
1863 }
1865
1866 log_ca_s_init("Help Wonder: %s for %s",
1868 ? "possible" : "impossible"),
1871
1872 /* Check units. */
1873 prod_as_req.source.kind = VUT_UTYPE;
1874
1876 /* Check this utype. */
1877 prod_as_req.source.value.utype = putype;
1878
1881 enabler) {
1883 &(enabler->target_reqs))
1884 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1885 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1886 /* This unit type kind can receive caravan shields. */
1887
1889
1890 /* Move on to the next unit type */
1891 break;
1892 }
1894
1895 log_ca_s_init("Help Wonder: %s for %s",
1897 ? "possible" : "impossible"),
1900
1901#undef log_ca_s_init
1902}
1903
1904/**********************************************************************/
1909{
1910 switch (tgt->kind) {
1911 case VUT_IMPROVEMENT:
1914 case VUT_UTYPE:
1916 utype_index(tgt->value.utype));
1917 default:
1919 return FALSE;
1920 };
1921}
1922
1923/**********************************************************************/
1935 const struct universal *target)
1936{
1941
1942 switch (pcity->changed_from.kind) {
1943 case VUT_IMPROVEMENT:
1944 if (is_wonder(pcity->changed_from.value.building)) {
1946 } else {
1948 }
1949 break;
1950 case VUT_UTYPE:
1952 break;
1953 default:
1955 break;
1956 };
1957
1958 switch (target->kind) {
1959 case VUT_IMPROVEMENT:
1960 if (is_wonder(target->value.building)) {
1962 } else {
1964 }
1965 break;
1966 case VUT_UTYPE:
1968 break;
1969 default:
1971 break;
1972 };
1973
1974 /* Changing production is penalized under certain circumstances. */
1975 if (orig_class == new_class
1976 || orig_class == PCT_LAST) {
1977 /* There's never a penalty for building something of the same class. */
1978 unpenalized_shields = pcity->before_change_shields;
1979 } else if (city_built_last_turn(pcity)) {
1980 /* Surplus shields from the previous production won't be penalized if
1981 * you change production on the very next turn. But you can only use
1982 * up to the city's surplus amount of shields in this way. */
1983 unpenalized_shields = MIN(pcity->last_turns_shield_surplus,
1984 pcity->before_change_shields);
1985 penalized_shields = pcity->before_change_shields - unpenalized_shields;
1986 } else {
1987 /* Penalize 50% of the production. */
1988 penalized_shields = pcity->before_change_shields;
1989 }
1990
1991 /* Do not put penalty on these. It shouldn't matter whether you disband unit
1992 before or after changing production...*/
1993 unpenalized_shields += pcity->disbanded_shields;
1994
1995 /* Caravan shields are penalized (just as if you disbanded the caravan)
1996 * if you're not building a wonder. */
1998 unpenalized_shields += pcity->caravan_shields;
1999 } else {
2000 penalized_shields += pcity->caravan_shields;
2001 }
2002
2005
2007}
2008
2009/**********************************************************************/
2014 const struct universal *target,
2016{
2017 int city_shield_surplus = pcity->surplus[O_SHIELD];
2020 int cost = universal_build_shield_cost(pcity, target);
2021
2022 if (target->kind == VUT_IMPROVEMENT
2023 && is_great_wonder(target->value.building)
2025 return FC_INFINITY;
2026 }
2027
2029 return 1;
2030 } else if (city_shield_surplus > 0) {
2031 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
2032 } else {
2033 return FC_INFINITY;
2034 }
2035}
2036
2037/**********************************************************************/
2045{
2046 if (pcity->surplus[O_FOOD] > 0) {
2047 return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
2048 pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
2049 } else if (pcity->surplus[O_FOOD] < 0) {
2050 /* Turns before famine loss */
2051 return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
2052 } else {
2053 return FC_INFINITY;
2054 }
2055}
2056
2057/**********************************************************************/
2060bool city_can_grow_to(const struct city *pcity, int pop_size)
2061{
2064}
2065
2066/**********************************************************************/
2069struct city *tile_enemy_city(const struct tile *ptile,
2070 const struct player *pplayer)
2071{
2072 struct city *pcity = tile_city(ptile);
2073
2074 if (pcity != nullptr && pplayers_at_war(pplayer, city_owner(pcity))) {
2075 return pcity;
2076 }
2077
2078 return nullptr;
2079}
2080
2081/**********************************************************************/
2084struct city *tile_allied_city(const struct tile *ptile,
2085 const struct player *pplayer)
2086{
2087 struct city *pcity = tile_city(ptile);
2088
2089 if (pcity != nullptr && pplayers_allied(pplayer, city_owner(pcity))) {
2090 return pcity;
2091 }
2092
2093 return nullptr;
2094}
2095
2096/**********************************************************************/
2099struct city *tile_non_attack_city(const struct tile *ptile,
2100 const struct player *pplayer)
2101{
2102 struct city *pcity = tile_city(ptile);
2103
2104 if (pcity != nullptr && pplayers_non_attack(pplayer, city_owner(pcity))) {
2105 return pcity;
2106 }
2107
2108 return nullptr;
2109}
2110
2111/**********************************************************************/
2114struct city *tile_non_allied_city(const struct tile *ptile,
2115 const struct player *pplayer)
2116{
2117 struct city *pcity = tile_city(ptile);
2118
2119 if (pcity != nullptr && !pplayers_allied(pplayer, city_owner(pcity))) {
2120 return pcity;
2121 }
2122
2123 return nullptr;
2124}
2125
2126/**********************************************************************/
2130 const struct unit *punit,
2131 int distance)
2132{
2134 distance);
2135}
2136
2137/**********************************************************************/
2141 const struct player *owner,
2142 const struct tile *ptile,
2143 int distance)
2144{
2145 square_iterate(nmap, ptile, distance, ptile1) {
2146 struct city *pcity = tile_city(ptile1);
2147
2149 return TRUE;
2150 }
2152
2153 return FALSE;
2154}
2155
2156/**********************************************************************/
2161 const struct tile *ptile,
2162 bool may_be_on_center)
2163{
2165 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2166 if (tile_city(ptile1)) {
2167 return TRUE;
2168 }
2169 }
2171
2172 return FALSE;
2173}
2174
2175/**********************************************************************/
2180int city_granary_size(int city_size)
2181{
2184 int base_value;
2185
2186 /* If the city has no citizens, there is no granary. */
2187 if (city_size == 0) {
2188 return 0;
2189 }
2190
2191 /* Granary sizes for the first food_inis citizens are given directly.
2192 * After that we increase the granary size by food_inc per citizen. */
2193 if (city_size > food_inis) {
2194 base_value = game.info.granary_food_ini[food_inis - 1];
2195 base_value += food_inc * (city_size - food_inis);
2196 } else {
2197 base_value = game.info.granary_food_ini[city_size - 1];
2198 }
2199
2200 return MAX(base_value * game.info.foodbox / 100, 1);
2201}
2202
2203/**********************************************************************/
2208static int player_base_citizen_happiness(const struct player *pplayer)
2209{
2210 int cities = city_list_size(pplayer->cities);
2211 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2214
2215 if (basis + step <= 0) {
2216 /* Value of zero means effect is inactive */
2217 return content;
2218 }
2219
2220 if (cities > basis) {
2221 content--;
2222 if (step != 0) {
2223 /* the first penalty is at (basis + 1) cities;
2224 the next is at (basis + step + 1), _not_ (basis + step) */
2225 content -= (cities - basis - 1) / step;
2226 }
2227 }
2228 return content;
2229}
2230
2231/**********************************************************************/
2235{
2236 int content = player_base_citizen_happiness(pplayer);
2237
2238 return CLIP(0, content, MAX_CITY_SIZE);
2239}
2240
2241/**********************************************************************/
2245{
2246 if (!game.info.angrycitizen) {
2247 return 0;
2248 } else {
2249 /* Create angry citizens only if we have a negative number of possible
2250 * content citizens. This can happen when empires grow really big. */
2251 int content = player_base_citizen_happiness(pplayer);
2252
2253 return CLIP(0, -content, MAX_CITY_SIZE);
2254 }
2255}
2256
2257/**********************************************************************/
2261{
2262 struct output_type *output = &output_types[otype];
2263 int bonus1 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2265 int bonus2 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2267
2268 return MAX(bonus1 * bonus2 / 100, 0);
2269}
2270
2271/**********************************************************************/
2276{
2277 int tithes_bonus = 0;
2278
2280 return 0;
2281 }
2282
2285
2286 return tithes_bonus;
2287}
2288
2289/**********************************************************************/
2293void add_tax_income(const struct player *pplayer, int trade, int *output)
2294{
2295 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2296 unsigned rates[3];
2297 int result[3];
2298
2299 if (game.info.changable_tax) {
2300 rates[SCIENCE] = pplayer->economic.science;
2301 rates[LUXURY] = pplayer->economic.luxury;
2302 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2303 } else {
2307 }
2308
2309 /* ANARCHY */
2311 rates[SCIENCE] = 0;
2312 rates[LUXURY] = 100;
2313 rates[TAX] = 0;
2314 }
2315
2316 distribute(trade, 3, rates, result);
2317
2318 output[O_SCIENCE] += result[SCIENCE];
2319 output[O_GOLD] += result[TAX];
2320 output[O_LUXURY] += result[LUXURY];
2321}
2322
2323/**********************************************************************/
2328{
2329 return pcity->turn_last_built + 1 >= game.info.turn;
2330}
2331
2332/**********************************************************************/
2335static const struct city *nearest_gov_center(const struct city *pcity,
2336 int *min_dist)
2337{
2338 const struct city *gov_center = nullptr;
2339
2341
2342 /* Check the special case that city itself is gov center
2343 * before expensive iteration through all cities. */
2344 if (is_gov_center(pcity)) {
2345 *min_dist = 0;
2346 return pcity;
2347 } else {
2349 /* Do not recheck current city */
2350 if (gc != pcity && is_gov_center(gc)) {
2351 int dist = real_map_distance(gc->tile, pcity->tile);
2352
2353 if (dist < *min_dist) {
2354 gov_center = gc;
2355 *min_dist = dist;
2356 }
2357 }
2359 }
2360
2361 return gov_center;
2362}
2363
2364/**********************************************************************/
2372static inline void get_worked_tile_output(const struct civ_map *nmap,
2373 const struct city *pcity,
2374 int *output, bool *workers_map)
2375{
2376 bool is_worked;
2377#ifdef CITY_DEBUGGING
2379#endif
2380 struct tile *pcenter = city_tile(pcity);
2381
2382 memset(output, 0, O_LAST * sizeof(*output));
2383
2386 if (workers_map == nullptr) {
2387 struct city *pwork = tile_worked(ptile);
2388
2389 is_worked = (pwork != nullptr && pwork == pcity);
2390 } else {
2391 is_worked = workers_map[city_tile_index];
2392 }
2393
2394 if (is_worked) {
2396#ifdef CITY_DEBUGGING
2397 /* This assertion never fails, but it's so slow that we disable
2398 * it by default. */
2400 == city_tile_output(pcity, ptile, is_celebrating, o));
2401#endif /* CITY_DEBUGGING */
2404 }
2406}
2407
2408/**********************************************************************/
2412void add_specialist_output(const struct city *pcity, int *output)
2413{
2415 int count = pcity->specialists[sp];
2416
2419
2420 output[stat_index] += count * amount;
2423}
2424
2425/**********************************************************************/
2434static inline void set_city_bonuses(struct city *pcity)
2435{
2438 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2439 &output_types[o],
2441 /* Total bonus cannot be negative, as that could lead to unresolvable
2442 * negative balance. */
2443 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2445}
2446
2447/**********************************************************************/
2457static inline void city_tile_cache_update(const struct civ_map *nmap,
2458 struct city *pcity)
2459{
2461 int radius_sq = city_map_radius_sq_get(pcity);
2462
2463 /* Initialize tile_cache if needed */
2464 if (pcity->tile_cache == nullptr || pcity->tile_cache_radius_sq == -1
2465 || pcity->tile_cache_radius_sq != radius_sq) {
2466 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2467 city_map_tiles(radius_sq)
2468 * sizeof(*(pcity->tile_cache)));
2469 pcity->tile_cache_radius_sq = radius_sq;
2470 }
2471
2472 /* Any unreal tiles are skipped - these values should have been memset
2473 * to 0 when the city was created. */
2474 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2476 (pcity->tile_cache[city_tile_index]).output[o]
2480}
2481
2482/**********************************************************************/
2486static inline int city_tile_cache_get_output(const struct city *pcity,
2487 int city_tile_index,
2488 enum output_type_id o)
2489{
2490 fc_assert_ret_val(pcity->tile_cache_radius_sq
2493
2494 return (pcity->tile_cache[city_tile_index]).output[o];
2495}
2496
2497/**********************************************************************/
2500static void set_surpluses(struct city *pcity)
2501{
2503 int surplus = pcity->prod[o] - pcity->usage[o];
2504
2505 /* Add 'surplus' waste to 'usage'. */
2506 if (surplus > 0) {
2507 struct output_type *output = get_output_type(o);
2511
2512 if (waste_by_rel_dist > 0) {
2513 int min_dist;
2514 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2515
2516 if (gov_center == nullptr) {
2517 /* No gov center - no income */
2518 waste_level = 100;
2519 } else {
2520 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2522 }
2523 }
2524
2525 if (waste_level > 0) {
2526 if (waste_level < 100) {
2527 pcity->usage[o] += (surplus * waste_level / 100);
2528 } else {
2529 pcity->usage[o] = pcity->prod[o];
2530 }
2531 }
2532 }
2533
2534 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2536}
2537
2538/**********************************************************************/
2541static void happy_copy(struct city *pcity, enum citizen_feeling i)
2542{
2543 int c = 0;
2544
2545 for (; c < CITIZEN_LAST; c++) {
2546 pcity->feel[c][i] = pcity->feel[c][i - 1];
2547 }
2548}
2549
2550/**********************************************************************/
2553static void citizen_base_mood(struct city *pcity)
2554{
2555 struct player *pplayer = city_owner(pcity);
2556 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2557 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2558 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2559 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2562
2563 /* This is the number of citizens that may start out content, depending
2564 * on empire size and game's city unhappysize. This may be bigger than
2565 * the size of the city, since this is a potential. */
2567 /* Similarly, this is the potential number of angry citizens. */
2569
2570 /* Create content citizens. Take specialists from their ranks. */
2571 *content = MAX(0, MIN(size, base_content) - spes);
2572
2573 /* Create angry citizens. Specialists never become angry. */
2574 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2575 *angry = MIN(base_angry, size - spes);
2576
2577 /* Create unhappy citizens. In the beginning, all who are not content,
2578 * specialists or angry are unhappy. This is changed by luxuries and
2579 * buildings later. */
2580 *unhappy = (size - spes - *content - *angry);
2581
2582 /* No one is born happy. */
2583 *happy = 0;
2584}
2585
2586/**********************************************************************/
2592static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2593{
2594 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2595 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2596 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2597 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2598
2599 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2600 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2601 (*angry)--;
2602 (*unhappy)++;
2604 }
2605 while (*luxuries >= game.info.happy_cost && *content > 0) {
2606 /* Upgrade content to happy: costs HAPPY_COST each. */
2607 (*content)--;
2608 (*happy)++;
2610 }
2611 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2612 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2613 * double the cost. */
2614 (*unhappy)--;
2615 (*happy)++;
2616 *luxuries -= 2 * game.info.happy_cost;
2617 }
2618 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2619 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2620 (*unhappy)--;
2621 (*content)++;
2623 }
2624}
2625
2626/**********************************************************************/
2629static inline void citizen_happy_luxury(struct city *pcity)
2630{
2631 int x = pcity->prod[O_LUXURY];
2632
2634}
2635
2636/**********************************************************************/
2639static inline void citizen_content_buildings(struct city *pcity)
2640{
2641 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2642 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2643 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2645
2646 /* make people content (but not happy):
2647 get rid of angry first, then make unhappy content. */
2648 while (faces > 0 && *angry > 0) {
2649 (*angry)--;
2650 (*unhappy)++;
2651 faces--;
2652 }
2653 while (faces > 0 && *unhappy > 0) {
2654 (*unhappy)--;
2655 (*content)++;
2656 faces--;
2657 }
2658}
2659
2660/**********************************************************************/
2663static inline void citizen_happiness_nationality(struct city *pcity)
2664{
2668
2671
2672 if (pct > 0) {
2673 int enemies = 0;
2674 int unhappy_inc;
2675 struct player *owner = city_owner(pcity);
2676
2677 citizens_foreign_iterate(pcity, pslot, nationality) {
2679 enemies += nationality;
2680 }
2682
2683 unhappy_inc = enemies * pct / 100;
2684
2685 /* First make content => unhappy, then happy => unhappy,
2686 * then happy => content. No-one becomes angry. */
2687 while (unhappy_inc > 0 && *content > 0) {
2688 (*content)--;
2689 (*unhappy)++;
2690 unhappy_inc--;
2691 }
2692 while (unhappy_inc > 1 && *happy > 0) {
2693 (*happy)--;
2694 (*unhappy)++;
2695 unhappy_inc -= 2;
2696 }
2697 while (unhappy_inc > 0 && *happy > 0) {
2698 (*happy)--;
2699 (*content)++;
2700 unhappy_inc--;
2701 }
2702 }
2703 }
2704}
2705
2706/**********************************************************************/
2712static inline void citizen_happy_units(struct city *pcity)
2713{
2714 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2715 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2716 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2717 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2718 citizens amt = pcity->martial_law;
2719
2720 /* Pacify discontent citizens through martial law. First convert
2721 * angry => unhappy, then unhappy => content. */
2722 while (amt > 0 && *angry > 0) {
2723 (*angry)--;
2724 (*unhappy)++;
2725 amt--;
2726 }
2727 while (amt > 0 && *unhappy > 0) {
2728 (*unhappy)--;
2729 (*content)++;
2730 amt--;
2731 }
2732
2733 /* Now make citizens unhappier because of military units away from home.
2734 * First make content => unhappy, then happy => unhappy,
2735 * then happy => content. */
2736 amt = pcity->unit_happy_upkeep;
2737 while (amt > 0 && *content > 0) {
2738 (*content)--;
2739 (*unhappy)++;
2740 amt--;
2741 }
2742 while (amt > 1 && *happy > 0) {
2743 (*happy)--;
2744 (*unhappy)++;
2745 amt -= 2;
2746 }
2747 while (amt > 0 && *happy > 0) {
2748 (*happy)--;
2749 (*content)++;
2750 amt--;
2751 }
2752 /* Any remaining unhappiness is lost since angry citizens aren't created
2753 * here. */
2754 /* FIXME: Why not? - Per */
2755}
2756
2757/**********************************************************************/
2760static inline void citizen_happy_wonders(struct city *pcity)
2761{
2762 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2763 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2764 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2765 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2766 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2767
2768 /* First create happy citizens from content, then from unhappy
2769 * citizens; we cannot help angry citizens here. */
2770 while (bonus > 0 && *content > 0) {
2771 (*content)--;
2772 (*happy)++;
2773 bonus--;
2774 }
2775 while (bonus > 1 && *unhappy > 0) {
2776 (*unhappy)--;
2777 (*happy)++;
2778 bonus -= 2;
2779 }
2780 /* The rest falls through and lets unhappy people become content. */
2781
2783 *content += *unhappy + *angry;
2784 *unhappy = 0;
2785 *angry = 0;
2786 return;
2787 }
2788
2790
2791 /* get rid of angry first, then make unhappy content */
2792 while (bonus > 0 && *angry > 0) {
2793 (*angry)--;
2794 (*unhappy)++;
2795 bonus--;
2796 }
2797 while (bonus > 0 && *unhappy > 0) {
2798 (*unhappy)--;
2799 (*content)++;
2800 bonus--;
2801 }
2802}
2803
2804/**********************************************************************/
2808static inline void unhappy_city_check(struct city *pcity)
2809{
2810 if (city_unhappy(pcity)) {
2812 switch (output_types[o].unhappy_penalty) {
2814 pcity->unhappy_penalty[o] = 0;
2815 break;
2817 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2818 break;
2820 pcity->unhappy_penalty[o] = pcity->prod[o];
2821 break;
2822 }
2823
2824 pcity->prod[o] -= pcity->unhappy_penalty[o];
2826 } else {
2827 memset(pcity->unhappy_penalty, 0,
2828 O_LAST * sizeof(*pcity->unhappy_penalty));
2829 }
2830}
2831
2832/**********************************************************************/
2836 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2837{
2838 int prod, pop, mod;
2839
2840 /* Add one one pollution per shield, multiplied by the bonus. */
2842 prod = shield_total * MAX(prod, 0) / 100;
2843
2844 /* Add one pollution per citizen for baseline combined bonus (100%). */
2847 / 100;
2848 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2849
2850 /* Then there is base pollution (usually a negative number). */
2851 mod = game.info.base_pollution;
2852
2853 if (pollu_prod) {
2854 *pollu_prod = prod;
2855 }
2856 if (pollu_pop) {
2857 *pollu_pop = pop;
2858 }
2859 if (pollu_mod) {
2860 *pollu_mod = mod;
2861 }
2862 return MAX(prod + pop + mod, 0);
2863}
2864
2865/**********************************************************************/
2869int city_pollution(const struct city *pcity, int shield_total)
2870{
2872 nullptr, nullptr, nullptr);
2873}
2874
2875/**********************************************************************/
2882static int get_trade_illness(const struct city *pcity)
2883{
2884 float illness_trade = 0.0;
2885
2887 if (trade_city->turn_plague != -1
2888 && game.info.turn - trade_city->turn_plague < 5) {
2889 illness_trade += (float)game.info.illness_trade_infection
2890 * sqrt(1.0 * city_size_get(pcity)
2891 * city_size_get(trade_city)) / 100.0;
2892 }
2894
2895 return (int)illness_trade;
2896}
2897
2898/**********************************************************************/
2902static int get_city_health(const struct city *pcity)
2903{
2905}
2906
2907/**********************************************************************/
2919int city_illness_calc(const struct city *pcity, int *ill_base,
2920 int *ill_size, int *ill_trade, int *ill_pollution)
2921{
2922 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2924
2925 if (game.info.illness_on
2927 /* offset the city size by game.info.illness_min_size */
2929
2930 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2931 * 10.0 * game.info.illness_base_factor);
2932 if (is_server()) {
2933 /* On the server we recalculate the illness due to trade as we have
2934 * all the information */
2935 illness_trade = get_trade_illness(pcity);
2936 } else {
2937 /* On the client we have to rely on the value saved within the city
2938 * struct */
2939 illness_trade = pcity->illness_trade;
2940 }
2941
2942 illness_pollution = pcity->pollution
2944 }
2945
2946 illness_base = illness_size + illness_trade + illness_pollution;
2948
2949 /* returning other data */
2950 if (ill_size) {
2952 }
2953
2954 if (ill_trade) {
2955 *ill_trade = illness_trade;
2956 }
2957
2958 if (ill_pollution) {
2960 }
2961
2962 if (ill_base) {
2964 }
2965
2966 return CLIP(0, illness_base * illness_percent / 100 , 999);
2967}
2968
2969/**********************************************************************/
2973{
2974 /* Correctly handles special case turn_plague == -1 (never) */
2975 return (pcity->turn_plague == game.info.turn);
2976}
2977
2978/**********************************************************************/
2981int city_build_slots(const struct city *pcity)
2982{
2984}
2985
2986/**********************************************************************/
2991int city_airlift_max(const struct city *pcity)
2992{
2994}
2995
2996/**********************************************************************/
3002inline void set_city_production(struct city *pcity)
3003{
3004 int trade;
3005
3006 /* Calculate city production!
3007 *
3008 * This is a rather complicated process if we allow rules to become
3009 * more generalized. We can assume that there are no recursive dependency
3010 * loops, but there are some dependencies that do not follow strict
3011 * ordering. For instance corruption must be calculated before
3012 * trade taxes can be counted up, which must occur before the science bonus
3013 * is added on. But the calculation of corruption must include the
3014 * trade bonus. To do this without excessive special casing means that in
3015 * this case the bonuses are multiplied on twice (but only saved the second
3016 * time).
3017 */
3018
3020 pcity->prod[o] = pcity->citizen_base[o];
3022
3023 /* Add on special extra incomes: trade routes and tithes. */
3025 struct city *tcity = game_city_by_number(proute->partner);
3026 bool can_trade;
3027
3028 /* Partner city may have not yet been sent to the client, or
3029 * there's just a placeholder city with a placeholder owner
3030 * created for some tile->worked. */
3031 if (!is_server()
3032 && (tcity == nullptr
3033 || city_owner(tcity)->slot == nullptr)) {
3034 continue;
3035 }
3036
3037 fc_assert_action(tcity != nullptr, continue);
3038
3040
3041 if (!can_trade) {
3044
3045 if (settings->cancelling == TRI_ACTIVE) {
3046 can_trade = TRUE;
3047 }
3048 }
3049
3050 if (can_trade) {
3051 int value;
3052
3053 value =
3055 proute->value = trade_from_route(pcity, proute, value);
3056 pcity->prod[O_TRADE] += proute->value
3057 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3058 } else {
3059 proute->value = 0;
3060 }
3063
3064 /* Account for waste. Note that waste is calculated before tax income is
3065 * calculated, so if you had "science waste" it would not include taxed
3066 * science. However waste is calculated after the bonuses are multiplied
3067 * on, so shield waste will include shield bonuses. */
3069 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3070
3071 prod = MAX(prod, 0);
3072 pcity->waste[o] = city_waste(pcity, o, prod, nullptr);
3074
3075 /* Convert trade into science/luxury/gold, and add this on to whatever
3076 * science/luxury/gold is already there. */
3077 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3078 + pcity->abs_bonus[O_TRADE];
3079 trade = MAX(trade, 0);
3081 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3082 pcity->prod);
3083
3084 /* Add on effect bonuses and waste. Note that the waste calculation
3085 * (above) already includes the bonuses. */
3087 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3088
3089 prod = MAX(prod, 0);
3090 pcity->prod[o] = prod;
3091 pcity->prod[o] -= pcity->waste[o];
3093}
3094
3095/**********************************************************************/
3099 struct unit *punit, int *free_unhappy)
3100{
3101 struct city *pcity;
3102 const struct unit_type *ut;
3103 struct player *plr;
3104 int happy_cost;
3105
3106 if (punit == nullptr || free_unhappy == nullptr) {
3107 return 0;
3108 }
3109
3111 if (pcity == nullptr) {
3112 return 0;
3113 }
3114
3116 plr = unit_owner(punit);
3117 happy_cost = utype_happy_cost(ut, plr);
3118
3119 if (happy_cost <= 0) {
3120 return 0;
3121 }
3122
3124
3126 return 0;
3127 }
3128
3130 if (happy_cost <= 0) {
3131 return 0;
3132 }
3133
3134 if (*free_unhappy >= happy_cost) {
3135 *free_unhappy -= happy_cost;
3136 return 0;
3137 } else {
3138 happy_cost -= *free_unhappy;
3139 *free_unhappy = 0;
3140 }
3141
3142 return happy_cost;
3143}
3144
3145/**********************************************************************/
3149static inline void city_support(const struct civ_map *nmap,
3150 struct city *pcity)
3151{
3152 int free_unhappy;
3153 int max_mart_units;
3154
3155 /* Clear all usage values. */
3156 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3157 pcity->martial_law = 0;
3158 pcity->unit_happy_upkeep = 0;
3159
3160 /* Building and unit gold upkeep depends on the setting
3161 * 'game.info.gold_upkeep_style':
3162 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3163 * city.
3164 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3165 * The upkeep for units is paid by the nation.
3166 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3167 * nation. */
3169 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3170 switch (game.info.gold_upkeep_style) {
3171 case GOLD_UPKEEP_CITY:
3173 fc__fallthrough; /* No break */
3174 case GOLD_UPKEEP_MIXED:
3176 break;
3177 case GOLD_UPKEEP_NATION:
3178 /* nothing */
3179 break;
3180 }
3181 /* Food consumption by citizens. */
3183
3185 if (max_mart_units > 0) {
3187 int sel_count = 0;
3188 int i;
3189
3192 && unit_owner(punit) == city_owner(pcity)) {
3193 int current = get_target_bonus_effects(nullptr,
3194 &(const struct req_context) {
3195 .player = city_owner(pcity),
3196 .city = pcity,
3197 .tile = city_tile(pcity),
3198 .unit = punit,
3199 .unittype = unit_type_get(punit)
3200 },
3201 nullptr, EFT_MARTIAL_LAW_BY_UNIT);
3202 if (current > 0) {
3203 if (sel_count < max_mart_units) {
3204 best_units[sel_count++] = current;
3205 } else if (current > best_units[max_mart_units - 1]) {
3206 for (i = max_mart_units - 1; i >= 0 && current > best_units[i]; i--) {
3207 if (i + 1 < max_mart_units) {
3208 best_units[i + 1] = best_units[i];
3209 }
3210 }
3211
3212 best_units[i + 1] = current;
3213 }
3214 }
3215 }
3217
3218 pcity->martial_law = 0;
3219 for (i = 0; i < sel_count; i++) {
3220 pcity->martial_law += best_units[i];
3221 }
3222
3223 pcity->martial_law = MIN(pcity->martial_law, MAX_CITY_SIZE);
3224 }
3225
3227 unit_list_iterate(pcity->units_supported, punit) {
3228 pcity->unit_happy_upkeep += city_unit_unhappiness(nmap, punit, &free_unhappy);
3230 if (O_GOLD != o) {
3231 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3232 pcity->usage[o] += punit->upkeep[o];
3233 }
3236}
3237
3238/**********************************************************************/
3251 struct city *pcity, bool *workers_map)
3252{
3253 if (workers_map == nullptr) {
3254 /* Do a full refresh */
3255
3256 /* Calculate the bonus[] array values. */
3258 /* Calculate the tile_cache[] values. */
3260 /* Manage settlers, and units */
3262 }
3263
3264 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3265 get_worked_tile_output(nmap, pcity, pcity->citizen_base, workers_map);
3266 add_specialist_output(pcity, pcity->citizen_base);
3267
3270 /* Note that pollution is calculated before unhappy_city_check() makes
3271 * deductions for disorder; so a city in disorder still causes pollution */
3272 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3273
3275 citizen_happy_luxury(pcity); /* With our new found luxuries */
3276
3279
3282
3283 /* Martial law & unrest from units */
3286
3287 /* Building (including wonder) happiness effects */
3290
3293}
3294
3295/**********************************************************************/
3302int city_waste(const struct city *pcity, Output_type_id otype, int total,
3303 int *breakdown)
3304{
3305 int penalty_waste = 0;
3306 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3307 * corruption */
3308 int total_eft = total; /* Normal corruption calculated on total reduced by
3309 * possible size penalty */
3310 const struct output_type *output = get_output_type(otype);
3312 bool waste_all = FALSE;
3313
3314 if (otype == O_TRADE) {
3315 /* FIXME: special case for trade: it is affected by notradesize and
3316 * fulltradesize server settings.
3317 *
3318 * If notradesize and fulltradesize are equal then the city gets no
3319 * trade at that size. */
3320 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3321 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3322
3323 if (city_size_get(pcity) <= notradesize) {
3324 penalty_size = total_eft; /* Then no trade income. */
3325 } else if (city_size_get(pcity) >= fulltradesize) {
3326 penalty_size = 0;
3327 } else {
3328 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3329 / (fulltradesize - notradesize);
3330 }
3331 }
3332
3333 /* Apply corruption only to anything left after tradesize */
3335
3336 /* Distance-based waste.
3337 * Don't bother calculating if there's nothing left to lose. */
3338 if (total_eft > 0) {
3343 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3344 int min_dist;
3345 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3346
3347 if (gov_center == nullptr) {
3348 waste_all = TRUE; /* No gov center - no income */
3349 } else {
3351 if (waste_by_rel_dist > 0) {
3352 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3353 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3354 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3356 }
3357 }
3358 }
3359 }
3360
3361 if (waste_all) {
3363 } else {
3366
3367 /* Corruption/waste calculated only for the actually produced amount */
3368 if (waste_level > 0) {
3370 }
3371
3372 /* Bonus calculated only for the actually produced amount */
3374
3375 /* Clip */
3377 }
3378
3379 if (breakdown) {
3382 }
3383
3384 /* Add up total penalty */
3385 return penalty_waste + penalty_size;
3386}
3387
3388/**********************************************************************/
3393{
3394 citizens count = 0;
3395
3397 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3398 count += pcity->specialists[sp];
3400
3401 return count;
3402}
3403
3404/**********************************************************************/
3408{
3409 int count = 0;
3410
3412 count += pcity->specialists[sp];
3414
3415 return count;
3416}
3417
3418/**********************************************************************/
3424 const struct city *pcity)
3425{
3426 int best = DEFAULT_SPECIALIST;
3427 int val = get_specialist_output(pcity, best, otype);
3428
3432
3433 if (val2 > val) {
3434 best = i;
3435 val = val2;
3436 }
3437 }
3439
3440 return best;
3441}
3442
3443/**********************************************************************/
3447 const struct impr_type *pimprove)
3448{
3449 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3450
3451 if (is_server() && is_wonder(pimprove)) {
3452 /* Client just read the info from the packets. */
3453 wonder_built(pcity, pimprove);
3454 }
3455}
3456
3457/**********************************************************************/
3461 const struct impr_type *pimprove)
3462{
3463 log_debug("Improvement %s removed from city %s",
3464 improvement_rule_name(pimprove), pcity->name);
3465
3466 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3467
3468 if (is_server() && is_wonder(pimprove)) {
3469 /* Client just read the info from the packets. */
3470 wonder_destroyed(pcity, pimprove);
3471 }
3472}
3473
3474/**********************************************************************/
3478{
3479 return BV_ISSET(pcity->city_options, option);
3480}
3481
3482/**********************************************************************/
3486{
3487 int i;
3488
3489 city_styles = fc_calloc(num, sizeof(*city_styles));
3491
3492 for (i = 0; i < game.control.num_city_styles; i++) {
3494 }
3495}
3496
3497/**********************************************************************/
3501{
3502 int i;
3503
3504 for (i = 0; i < game.control.num_city_styles; i++) {
3506 }
3507
3509 city_styles = nullptr;
3511}
3512
3513/**********************************************************************/
3519struct city *create_city_virtual(struct player *pplayer,
3520 struct tile *ptile, const char *name)
3521{
3522 int i,len;
3523
3524 /* Make sure that contents of city structure are correctly initialized,
3525 * if you ever allocate it by some other mean than fc_calloc() */
3526 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3527
3528 fc_assert_ret_val(name != nullptr, nullptr); /* No unnamed cities! */
3529
3530 /* Do this early, so any logging later will have the city name */
3532
3533 pcity->tile = ptile;
3534
3535 fc_assert_ret_val(pplayer != nullptr, nullptr); /* No unowned cities! */
3536
3537 pcity->owner = pplayer;
3538 pcity->acquire_t = CACQ_FOUNDED;
3539
3540 if (is_server()) {
3541 pcity->original = pplayer;
3542 }
3543
3544 /* City structure was allocated with fc_calloc(), so contents are initially
3545 * zero. There is no need to initialize it a second time. */
3546
3547 /* Now set some useful default values. */
3548 pcity->capital = CAPITAL_NOT;
3549 city_size_set(pcity, 1);
3550 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3551 pcity->wlcb = WLCB_SMART;
3552
3554 pcity->bonus[o] = 100;
3555 pcity->abs_bonus[o] = 0;
3557
3558 pcity->turn_plague = -1; /* -1 = never */
3559 pcity->did_buy = FALSE;
3560 pcity->city_radius_sq = game.info.init_city_radius_sq;
3561 pcity->turn_founded = game.info.turn;
3562 pcity->turn_last_built = game.info.turn;
3563
3564 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3565
3566 /* pcity->ai.act_cache: worker activities on the city map */
3567
3568 /* Initialise improvements list */
3569 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3570 pcity->built[i].turn = I_NEVER;
3571 }
3572
3573 /* Set up the worklist */
3574 worklist_init(&pcity->worklist);
3575
3576 pcity->units_supported = unit_list_new();
3577 pcity->routes = trade_route_list_new();
3578 pcity->task_reqs = worker_task_list_new();
3579
3580 if (is_server()) {
3581 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3582
3583 CALL_FUNC_EACH_AI(city_alloc, pcity);
3584 } else {
3585 pcity->client.info_units_supported =
3587 pcity->client.info_units_present =
3589 /* collecting_info_units_supported set by fc_calloc().
3590 * collecting_info_units_present set by fc_calloc(). */
3591 }
3592
3594 pcity->counter_values = fc_malloc(sizeof(int) * len);
3595
3596 for (i = 0; i < len; i++) {
3597 pcity->counter_values[i] = counter_by_index(i, CTGT_CITY)->def;
3598 }
3599
3600 return pcity;
3601}
3602
3603/**********************************************************************/
3608{
3609 CALL_FUNC_EACH_AI(city_free, pcity);
3610
3612
3613 /* Free worker tasks */
3614 while (worker_task_list_size(pcity->task_reqs) > 0) {
3615 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3616
3617 worker_task_list_remove(pcity->task_reqs, ptask);
3618
3619 free(ptask);
3620 }
3621 worker_task_list_destroy(pcity->task_reqs);
3622
3623 /* Free rally points */
3625
3626 unit_list_destroy(pcity->units_supported);
3628 if (pcity->tile_cache != nullptr) {
3629 free(pcity->tile_cache);
3630 }
3631
3632 if (pcity->cm_parameter) {
3633 free(pcity->cm_parameter);
3634 }
3635
3636 if (pcity->counter_values) {
3637 free(pcity->counter_values);
3638 }
3639
3640 if (!is_server()) {
3641 unit_list_destroy(pcity->client.info_units_supported);
3642 unit_list_destroy(pcity->client.info_units_present);
3643 /* Handle a rare case where the game is freed in the middle of a
3644 * spy/diplomat investigate cycle. */
3645 if (pcity->client.collecting_info_units_supported != nullptr) {
3646 unit_list_destroy(pcity->client.collecting_info_units_supported);
3647 }
3648 if (pcity->client.collecting_info_units_present != nullptr) {
3649 unit_list_destroy(pcity->client.collecting_info_units_present);
3650 }
3651 }
3652
3653 free(pcity->name);
3654
3655 memset(pcity, 0, sizeof(*pcity)); /* Ensure no pointers remain */
3656 free(pcity);
3657}
3658
3659/**********************************************************************/
3663bool city_exist(int id)
3664{
3665 /* Check if city exist in game */
3666 if (game_city_by_number(id)) {
3667 return TRUE;
3668 }
3669
3670 return FALSE;
3671}
3672
3673/**********************************************************************/
3680bool city_is_virtual(const struct city *pcity)
3681{
3682 if (!pcity) {
3683 return FALSE;
3684 }
3685
3686 return pcity != game_city_by_number(pcity->id);
3687}
3688
3689/**********************************************************************/
3692bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3693{
3694 return is_city_center(pcity, ptile);
3695}
3696
3697/**********************************************************************/
3700void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3701{
3702 return pcity->server.ais[ai_type_number(ai)];
3703}
3704
3705/**********************************************************************/
3708void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3709 void *data)
3710{
3711 pcity->server.ais[ai_type_number(ai)] = data;
3712}
3713
3714/**********************************************************************/
3718{
3719 /* Free rally points */
3720 if (pcity->rally_point.length > 0) {
3721 pcity->rally_point.length = 0;
3722 pcity->rally_point.persistent = FALSE;
3723 pcity->rally_point.vigilant = FALSE;
3724 free(pcity->rally_point.orders);
3725 pcity->rally_point.orders = nullptr;
3726 }
3727}
3728
3729/**********************************************************************/
3733 struct city *pcity)
3734{
3735 struct unit_order *checked_orders;
3736 const struct civ_map *nmap = &(wld.map);
3737
3738 if (pcity == nullptr) {
3739 /* Probably lost. */
3740 log_verbose("handle_city_rally_point() bad city number %d.",
3741 packet->id);
3742 return;
3743 }
3744
3745 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3746 /* Shouldn't happen */
3747 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3748 packet->length, MAX_LEN_ROUTE);
3749 return;
3750 }
3751
3752 pcity->rally_point.length = packet->length;
3753
3754 if (packet->length == 0) {
3755 pcity->rally_point.vigilant = FALSE;
3756 pcity->rally_point.persistent = FALSE;
3757 if (pcity->rally_point.orders) {
3758 free(pcity->rally_point.orders);
3759 pcity->rally_point.orders = nullptr;
3760 }
3761 } else {
3763 packet->orders);
3764 if (!checked_orders) {
3765 pcity->rally_point.length = 0;
3766 log_error("invalid rally point orders for %s.",
3768 return;
3769 }
3770
3771 pcity->rally_point.persistent = packet->persistent;
3772 pcity->rally_point.vigilant = packet->vigilant;
3773 pcity->rally_point.orders = checked_orders;
3774 }
3775}
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:1685
bool city_is_virtual(const struct city *pcity)
Definition city.c:3680
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:2013
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2592
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:2639
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3692
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1908
static bv_imprs caravan_helped_impr
Definition city.c:1819
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:1192
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2208
#define POLLUTION_EFT_NEARMAX
Definition city.c:1156
const char * city_name_getx(const struct city *pcity)
Definition city.c:1157
int city_granary_size(int city_size)
Definition city.c:2180
static void get_worked_tile_output(const struct civ_map *nmap, const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2372
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2244
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2835
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3708
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2760
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2140
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2327
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1097
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3302
static void city_support(const struct civ_map *nmap, struct city *pcity)
Definition city.c:3149
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2981
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:1287
const char * city_style_name_translation(const int style)
Definition city.c:1804
void city_styles_free(void)
Definition city.c:3500
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2486
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:650
int city_superspecialists(const struct city *pcity)
Definition city.c:3407
bool is_capital(const struct city *pcity)
Definition city.c:1627
void city_styles_alloc(int num)
Definition city.c:3485
const char * city_name_get(const struct city *pcity)
Definition city.c:1148
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1449
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1059
void city_production_caravan_shields_init(void)
Definition city.c:1826
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3460
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1303
int city_airlift_max(const struct city *pcity)
Definition city.c:2991
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1513
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1041
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:3477
int city_population(const struct city *pcity)
Definition city.c:1238
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1813
void city_size_add(struct city *pcity, int add)
Definition city.c:1211
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1075
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:1713
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:2293
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:2114
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3098
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1644
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2234
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:2457
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2275
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2129
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:1701
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:1674
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3423
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3519
void set_city_production(struct city *pcity)
Definition city.c:3002
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:1727
static bv_unit_types caravan_helped_utype
Definition city.c:1820
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2260
bool city_celebrating(const struct city *pcity)
Definition city.c:1693
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1608
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:2919
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:2060
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1934
static int get_city_health(const struct city *pcity)
Definition city.c:2902
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:3250
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1002
static void set_city_bonuses(struct city *pcity)
Definition city.c:2434
static void set_surpluses(struct city *pcity)
Definition city.c:2500
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2335
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:1535
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2869
bool city_happy(const struct city *pcity)
Definition city.c:1662
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1227
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3446
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1432
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:2084
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2069
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:3607
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:3392
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:3732
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:1769
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2412
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:3700
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1743
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2663
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1331
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 can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:911
bool is_gov_center(const struct city *pcity)
Definition city.c:1635
#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:1022
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2629
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:955
int city_map_tiles(int city_radius_sq)
Definition city.c:171
static void unhappy_city_check(struct city *pcity)
Definition city.c:2808
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2099
bool city_exist(int id)
Definition city.c:3663
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1504
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:2044
void city_rally_point_clear(struct city *pcity)
Definition city.c:3717
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:2160
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2972
static int get_trade_illness(const struct city *pcity)
Definition city.c:2882
bool city_can_change_build(const struct city *pcity)
Definition city.c:1089
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:978
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1269
int city_style_by_rule_name(const char *s)
Definition city.c:1786
static void citizen_base_mood(struct city *pcity)
Definition city.c:2553
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1759
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1248
static void citizen_happy_units(struct city *pcity)
Definition city.c:2712
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2541
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:849
#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:872
#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:838
#define is_free_worked_index(city_tile_index)
Definition city.h:884
#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:844
#define PCT_LAST
Definition city.h:41
#define output_type_iterate_end
Definition city.h:855
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:116
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:2300
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, bool consider_reg_impr_req)
Definition unittype.c:1994
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2659
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
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:2127
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:863
#define unit_type_iterate_end
Definition unittype.h:870
#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