Freeciv-3.4
Loading...
Searching...
No Matches
city.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdlib.h>
19#include <string.h>
20#include <math.h> /* pow, sqrt, exp */
21
22/* utility */
23#include "distribute.h"
24#include "fcintl.h"
25#include "log.h"
26#include "mem.h"
27#include "support.h"
28
29/* common */
30#include "ai.h"
31#include "citizens.h"
32#include "counters.h"
33#include "effects.h"
34#include "game.h"
35#include "government.h"
36#include "improvement.h"
37#include "map.h"
38#include "movement.h"
39#include "packets.h"
40#include "specialist.h"
41#include "traderoutes.h"
42#include "unit.h"
43
44/* aicore */
45#include "cm.h"
46
47#include "city.h"
48
49/* Define this to add in extra (very slow) assertions for the city code. */
50#undef CITY_DEBUGGING
51
52static char *citylog_map_line(int y, int city_radius_sq, int *city_map_data);
53#ifdef FREECIV_DEBUG
54/* Only used for debugging */
55static void citylog_map_index(enum log_level level);
56static void citylog_map_radius_sq(enum log_level level);
57#endif /* FREECIV_DEBUG */
58
59/* Get city tile information using the city tile index. */
60static struct iter_index *city_map_index = nullptr;
61/* Get city tile information using the city tile coordinates. This is an
62 * [x][y] array of integer values corresponding to city_map_index. The
63 * coordinates x and y are in the range [0, CITY_MAP_MAX_SIZE] */
65
66/* Number of tiles of a city; depends on the squared city radius */
68
69/* Definitions and functions for the tile_cache */
70struct tile_cache {
72};
73
74static inline void city_tile_cache_update(const struct civ_map *nmap,
75 struct city *pcity);
76static inline int city_tile_cache_get_output(const struct city *pcity,
78 enum output_type_id o);
79
80static const struct city *nearest_gov_center(const struct city *pcity,
81 int *min_dist)
82 fc__attribute((nonnull (1, 2)));
83
84struct citystyle *city_styles = nullptr;
85
86/* One day these values may be read in from the ruleset. In the meantime
87 * they're just an easy way to access information about each output type. */
89 {O_FOOD, N_("Food"), "food", TRUE, UNHAPPY_PENALTY_SURPLUS},
90 {O_SHIELD, N_("Shield"), "shield", TRUE, UNHAPPY_PENALTY_SURPLUS},
91 {O_TRADE, N_("Trade"), "trade", TRUE, UNHAPPY_PENALTY_NONE},
92 {O_GOLD, N_("Gold"), "gold", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION},
93 {O_LUXURY, N_("Luxury"), "luxury", FALSE, UNHAPPY_PENALTY_NONE},
94 {O_SCIENCE, N_("Science"), "science", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION}
95};
96
97/**********************************************************************/
102 int city_tile_index, int city_radius_sq)
103{
106
107 /* tile indices are sorted from smallest to largest city radius */
108 if (city_tile_index < 0
109 || city_tile_index >= city_map_tiles(city_radius_sq)) {
110 return FALSE;
111 }
112
115
116 return TRUE;
117}
118
119/**********************************************************************/
124 int city_radius_sq)
125{
126 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, 0);
127 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, 0);
129 city_map_y), 0);
130
132}
133
134/**********************************************************************/
138{
139 /* A safe return value is only the minimal squared radius */
141
142 return pcity->city_radius_sq;
143}
144
145/**********************************************************************/
148void city_map_radius_sq_set(struct city *pcity, int radius_sq)
149{
152
153 pcity->city_radius_sq = radius_sq;
154}
155
156/**********************************************************************/
166
167/**********************************************************************/
171int city_map_tiles(int city_radius_sq)
172{
173 if (city_radius_sq == CITY_MAP_CENTER_RADIUS_SQ) {
174 /* special case: city center; first tile of the city map */
175 return 0;
176 }
177
178 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, -1);
179 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, -1);
180
181 return city_map_numtiles[city_radius_sq];
182}
183
184/**********************************************************************/
188bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
189 const int city_map_y)
190{
191 /* The city's valid positions are in a circle around the city center.
192 * Depending on the value for the squared city radius the circle will be:
193 *
194 * - rectangular (max radius = 5; max squared radius = 26)
195 *
196 * 0 1 2 3 4 5 6 7 8 9 10
197 *
198 * 0 26 25 26 -5
199 * 1 25 20 17 16 17 20 25 -4
200 * 2 25 18 13 10 9 10 13 18 25 -3
201 * 3 20 13 8 5 4 5 8 13 20 -2
202 * 4 26 17 10 5 2 1 2 5 10 17 26 -1
203 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
204 * 6 26 17 10 5 2 1 2 5 10 17 26 +1
205 * 7 20 13 8 5 4 5 8 13 20 +2
206 * 8 25 18 13 10 9 10 13 18 25 +3
207 * 9 25 20 17 16 17 20 25 +4
208 * 10 26 25 26 +5
209 *
210 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
211 *
212 * - hexagonal (max radius = 5; max squared radius = 26)
213 *
214 * 0 1 2 3 4 5 6 7 8 9 10
215 *
216 * 0 25 25 25 25 25 25 -5
217 * 1 25 16 16 16 16 16 25 -4
218 * 2 25 16 9 9 9 9 16 25 -3
219 * 3 25 16 9 4 4 4 9 16 25 -2
220 * 4 25 16 9 4 1 1 4 9 16 25 -1
221 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
222 * 6 25 16 9 4 1 1 4 9 16 25 +1
223 * 7 25 16 9 4 4 4 9 16 25 +2
224 * 8 25 16 9 9 9 9 16 25 +3
225 * 9 25 16 16 16 16 16 25 +4
226 * 10 25 25 25 25 25 25 +5
227 *
228 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
229 *
230 * The following tables show the tiles per city radii / squared city radii.
231 * '-' indicates no change compared to the previous value
232 *
233 * radius | 0 | 1 | | | 2 | | | | | 3
234 * radius_sq | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
235 * ------------------+----+----+----+----+----+----+----+----+----+----
236 * tiles rectangular | 5 | 9 | - | 13 | 21 | - | - | 25 | 29 | 37
237 * tiles hexagonal | 7 | - | - | 19 | - | - | - | - | 37 | -
238 *
239 * radius | | | | | | | 4 | | |
240 * radius_sq | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
241 * ------------------+----+----+----+----+----+----+----+----+----+----
242 * tiles rectangular | - | - | 45 | - | - | 49 | 57 | 61 | - | 69
243 * tiles hexagonal | - | - | - | - | - | 61 | - | - | - | -
244 *
245 * radius | | | | | | 5
246 * radius_sq | 21 | 22 | 23 | 24 | 25 | 26
247 * ------------------+----+----+----+----+----+----
248 * tiles rectangular | - | - | - | - | 81 | 89
249 * tiles hexagonal | - | - | - | - | 91 | -
250 *
251 * So radius_sq == 5 (radius == 2) corresponds to the "traditional"
252 * used city map.
253 */
256
257 return dist <= city_radius_sq;
258}
259
260/**********************************************************************/
265 const int city_radius_sq,
266 const struct tile *city_center,
267 const struct tile *map_tile)
268{
270
273
274 return is_valid_city_coords(city_radius_sq, *city_map_x, *city_map_y);
275}
276
277/**********************************************************************/
282 const struct city *const pcity,
283 const struct tile *map_tile)
284{
287 map_tile);
288}
289
290/**********************************************************************/
293bool city_map_includes_tile(const struct city *const pcity,
294 const struct tile *map_tile)
295{
296 int tmp_x, tmp_y;
297
299}
300
301/**********************************************************************/
305struct tile *city_map_to_tile(const struct civ_map *nmap,
306 const struct tile *city_center,
307 int city_radius_sq, int city_map_x,
308 int city_map_y)
309{
310 int tile_x, tile_y;
311
313 city_map_y), nullptr);
314
315 index_to_map_pos(&tile_x, &tile_y, tile_index(city_center));
318
320}
321
322/**********************************************************************/
325static int cmp(int v1, int v2)
326{
327 if (v1 == v2) {
328 return 0;
329 } else if (v1 > v2) {
330 return 1;
331 } else {
332 return -1;
333 }
334}
335
336/**********************************************************************/
343int compare_iter_index(const void *a, const void *b)
344{
345 const struct iter_index *index1 = a, *index2 = b;
346 int value;
347
348 value = cmp(index1->dist, index2->dist);
349 if (value != 0) {
350 return value;
351 }
352
353 value = cmp(index1->dx, index2->dx);
354 if (value != 0) {
355 return value;
356 }
357
358 value = cmp(index1->dy, index2->dy);
359 fc_assert(0 != value);
360 return value;
361}
362
363/**********************************************************************/
368#define CITYLOG_MAX_VAL 9999 /* maximal value displayed in the citylog */
369static char *citylog_map_line(int y, int city_radius_sq, int *city_map_data)
370{
371 int x, mindex;
372 static char citylog[128], tmp[8];
373
374 fc_assert_ret_val(city_map_data != nullptr, nullptr);
375
376 /* print y coordinates (absolute) */
377 fc_snprintf(citylog, sizeof(citylog), "%2d ", y);
378
379 /* print values */
380 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
381 if (is_valid_city_coords(city_radius_sq, x, y)) {
382 mindex = city_tile_xy_to_index(x, y, city_radius_sq);
383 /* show values between -10000 and +10000 */
386 fc_snprintf(tmp, sizeof(tmp), "%5d", city_map_data[mindex]);
388 } else {
389 fc_snprintf(tmp, sizeof(tmp), " ####");
391 }
392 } else {
393 fc_snprintf(tmp, sizeof(tmp), " ");
395 }
396 }
397
398 /* print y coordinates (relative) */
399 fc_snprintf(tmp, sizeof(tmp), " %+4d", CITY_ABS2REL(y));
401
402 return citylog;
403}
404#undef CITYLOG_MAX_VAL
405
406/**********************************************************************/
411void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
412{
413 int x, y;
414 char line[128], tmp[8];
415
417 return;
418 }
419
420 log_base(level, "(max squared city radius = %d)", CITY_MAP_MAX_RADIUS_SQ);
421
422 /* print x coordinates (absolute) */
423 fc_snprintf(line, sizeof(line), " ");
424 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
425 fc_snprintf(tmp, sizeof(tmp), "%+5d", x);
427 }
428 log_base(level, "%s", line);
429
430 for (y = 0; y < CITY_MAP_MAX_SIZE; y++) {
431 log_base(level, "%s", citylog_map_line(y, radius_sq, map_data));
432 }
433
434 /* print x coordinates (relative) */
435 fc_snprintf(line, sizeof(line), " ");
436 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
437 fc_snprintf(tmp, sizeof(tmp), "%+5d", CITY_ABS2REL(x));
439 }
440 log_base(level, "%s", line);
441}
442
443/**********************************************************************/
447{
448 int *city_map_data = nullptr;
449 const struct civ_map *nmap = &(wld.map);
450
451 fc_assert_ret(pcity != nullptr);
452
454 return;
455 }
456
458 sizeof(*city_map_data));
459
461 struct tile *ptile = city_map_to_tile(nmap,
464 x, y);
465 city_map_data[cindex] = (ptile && tile_worked(ptile) == pcity)
466 ? (is_free_worked_index(cindex) ? 2 : 1) : 0;
468
469 log_base(level, "[%s (%d)] workers map:", city_name_get(pcity), pcity->id);
472}
473
474#ifdef FREECIV_DEBUG
475/**********************************************************************/
478static void citylog_map_index(enum log_level level)
479{
480 int *city_map_data = nullptr;
481
483 return;
484 }
485
487 sizeof(*city_map_data));
488
490 city_map_data[cindex] = cindex;
492
493 log_debug("city map index:");
496}
497
498/**********************************************************************/
501static void citylog_map_radius_sq(enum log_level level)
502{
503 int *city_map_data = nullptr;
504
506 return;
507 }
508
510 sizeof(*city_map_data));
511
514 CITY_ABS2REL(y));
516
517 log_debug("city map squared radius:");
520}
521#endif /* FREECIV_DEBUG */
522
523/**********************************************************************/
528{
529 int i, dx, dy, city_x, city_y, dist, city_count_tiles = 0;
532
533 /* initialise map information for each city radii */
534 for (i = 0; i <= CITY_MAP_MAX_RADIUS_SQ; i++) {
535 city_map_numtiles[i] = 0; /* will be set below */
536 }
537
538 /* We don't use city-map iterators in this function because they may
539 * rely on the indices that have not yet been generated. Furthermore,
540 * we don't know the number of tiles within the city radius, so we need
541 * an temporary city_map_index array. Its content will be copied into
542 * the real array below. */
546
551
552 for (i = CITY_MAP_MAX_RADIUS_SQ; i >= 0; i--) {
553 if (dist <= i) {
554 /* increase number of tiles within this squared city radius */
556 }
557 }
558
560 }
561
562 /* Initialise city_map_xy. -1 defines a invalid city map positions. */
564 }
565 }
566
567 fc_assert(city_map_index == nullptr);
569
570 /* Copy the index numbers from city_map_index_tmp into city_map_index */
571 for (i = 0; i < city_count_tiles; i++) {
573 }
574
577
578 /* Set the static variable city_map_xy */
579 for (i = 0; i < city_count_tiles; i++) {
583 }
584
585#ifdef FREECIV_DEBUG
588
590 log_debug("radius_sq = %2d, tiles = %2d", i, city_map_tiles(i));
591 }
592
593 for (i = 0; i < city_count_tiles; i++) {
596 log_debug("[%2d]: (dx,dy) = (%+2d,%+2d), (x,y) = (%2d,%2d), "
597 "dist = %2d, check = %2d", i,
600 }
601#endif /* FREECIV_DEBUG */
602
604}
605
606/**********************************************************************/
610{
612}
613
614/**********************************************************************/
620{
621 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
622
623 return output_types[output].id;
624}
625
626/**********************************************************************/
631{
632 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
633
634 return _(output_types[output].name);
635}
636
637/**********************************************************************/
641{
642 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
643
644 return &output_types[output];
645}
646
647/**********************************************************************/
651{
653
654 for (o = 0; o < O_LAST; o++) {
655 if (fc_strcasecmp(output_types[o].id, id) == 0) {
656 return o;
657 }
658 }
659
660 return O_LAST;
661}
662
663/**********************************************************************/
667 const struct impr_type *pimprove)
668{
669 static char buffer[256];
670 const char *state = nullptr;
671
672 if (is_great_wonder(pimprove)) {
673 if (great_wonder_is_available(pimprove)) {
674 state = Q_("?wonder:W");
675 } else if (great_wonder_is_destroyed(pimprove)) {
676 state = Q_("?destroyed:D");
677 } else {
678 state = Q_("?built:B");
679 }
680 }
681 if (pcity) {
682 struct player *pplayer = city_owner(pcity);
683
684 if (improvement_obsolete(pplayer, pimprove, pcity)) {
685 state = Q_("?obsolete:O");
686 } else if (is_improvement_redundant(pcity, pimprove)) {
687 state = Q_("?redundant:*");
688 }
689 }
690
691 if (state) {
692 fc_snprintf(buffer, sizeof(buffer), "%s(%s)",
693 improvement_name_translation(pimprove), state);
694 return buffer;
695 } else {
696 return improvement_name_translation(pimprove);
697 }
698}
699
700/**********************************************************************/
704{
705 static char buffer[256];
706
707 switch (pcity->production.kind) {
708 case VUT_IMPROVEMENT:
709 return city_improvement_name_translation(pcity, pcity->production.value.building);
710 default:
711 /* fallthru */
712 break;
713 };
714 return universal_name_translation(&pcity->production, buffer, sizeof(buffer));
715}
716
717/**********************************************************************/
721 enum impr_genus_id genus)
722{
723 return VUT_IMPROVEMENT == pcity->production.kind
724 && (pcity->production.value.building->genus == genus);
725}
726
727/**********************************************************************/
731 enum impr_flag_id flag)
732{
733 return VUT_IMPROVEMENT == pcity->production.kind
734 && improvement_has_flag(pcity->production.value.building, flag);
735}
736
737/**********************************************************************/
741{
742 return universal_build_shield_cost(pcity, &pcity->production);
743}
744
745/**********************************************************************/
751 bool add_production, int *num_units)
752{
753 const struct unit_type *utype;
754 struct universal target;
756 int shields_left = pcity->shield_stock;
757 int unit_shield_cost, i;
758
759 fc_assert_ret_val(num_units != nullptr, FALSE);
760
761 (*num_units) = 0;
762
763 if (pcity->production.kind != VUT_UTYPE) {
764 /* Not a unit as the current production */
765 return FALSE;
766 }
767
768 utype = pcity->production.value.utype;
769 if (utype_pop_value(utype, pcity) != 0 || utype_has_flag(utype, UTYF_UNIQUE)) {
770 /* Unit with population cost or unique unit means that only one unit can
771 * be build */
772 (*num_units)++;
773 return FALSE;
774 }
775
776 if (add_production) {
777 shields_left += pcity->prod[O_SHIELD];
778 }
779
781
782 for (i = 0; i < build_slots; i++) {
784 /* Not enough shields */
785 break;
786 }
787
788 (*num_units)++;
790
791 if (worklist_length(&pcity->worklist) > i) {
792 (void) worklist_peek_ith(&pcity->worklist, &target, i);
793 if (target.kind != VUT_UTYPE
794 || utype_index(target.value.utype) != utype_index(utype)) {
795 /* Stop if there is a build target in the worklist not equal to the
796 * unit we build */
797 break;
798 }
799 }
800 }
801
802 return TRUE;
803}
804
805/************************************************************************/
809 const struct unit_type *punittype)
810{
812 nullptr, EFT_VETERAN_BUILD);
814
815 levels = CLIP(0, levels, max_levels);
816
817 return levels;
818}
819
820/**********************************************************************/
826{
828}
829
830/**********************************************************************/
835 const struct impr_type *pimprove,
836 const enum req_problem_type prob_type)
837{
839 prob_type)) {
840 return FALSE;
841 }
842
843 if (city_has_building(pcity, pimprove)) {
844 return FALSE;
845 }
846
847 return are_reqs_active(&(const struct req_context) {
848 .player = city_owner(pcity),
849 .city = pcity,
850 .tile = pcity->tile,
851 },
852 nullptr,
853 &(pimprove->reqs), prob_type);
854}
855
856/**********************************************************************/
861 const struct impr_type *pimprove,
862 const enum req_problem_type prob_type)
863{
865 prob_type)) {
866 return FALSE;
867 }
868 if (improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
869 return FALSE;
870 }
871
872 return TRUE;
873}
874
875/**********************************************************************/
880 const struct impr_type *pimprove)
881{
882 const struct req_context city_ctxt = {
884 .city = pcity,
885 .tile = city_tile(pcity),
886 };
887
888 /* Can the _player_ ever build this improvement? */
889 /* NOTE: It checks for obsoletion player-level. What aboult checking
890 * for it city-level? That may unlist from a worklist some things
891 * we'll be able to switch to after e.g. selling something else */
893 return FALSE;
894 }
895
896 /* Check for requirements that aren't met and that are unchanging (so
897 * they can never be met). */
899 if (is_req_preventing(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
900 return FALSE;
901 }
903
904 return TRUE;
905}
906
907/**********************************************************************/
912 const struct city *pcity,
913 const struct unit_type *punittype,
914 const enum req_problem_type prob_type)
915{
917 prob_type, FALSE)) {
918 return FALSE;
919 }
920
921 /* Check unit build requirements.
922 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
923 * Don't recheck those. Not only for optimization, but also not to override the
924 * special handling of tech requirements for barbarians */
925 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
927 &(const struct req_context) {
928 .player = city_owner(pcity),
929 .city = pcity,
930 .tile = city_tile(pcity),
931 .unittype = punittype,
932 },
933 nullptr,
934 &punittype->build_reqs, prob_type)) {
935 return FALSE;
936 }
937
938 /* You can't build naval units inland. */
941 pcity->tile)) {
942 return FALSE;
943 }
944
945 if (punittype->city_slots > 0
946 && city_unit_slots_available(pcity) < punittype->city_slots) {
947 return FALSE;
948 }
949
950 return TRUE;
951}
952
953/**********************************************************************/
958 const struct city *pcity,
959 const struct unit_type *punittype,
960 const enum req_problem_type prob_type)
961{
963 return FALSE;
964 }
965
966 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
967 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
968 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
970 prob_type, TRUE)) {
971 return FALSE;
972 }
973 }
974
975 return TRUE;
976}
977
978/**********************************************************************/
983 const struct city *pcity,
984 const struct unit_type *punittype)
985{
986 /* Can the _player_ ever build this unit? */
988 return FALSE;
989 }
990
991 /* Some units can be built only in certain cities -- for instance,
992 ships may be built only in cities adjacent to ocean. */
995 pcity->tile)) {
996 return FALSE;
997 }
998
999 return TRUE;
1000}
1001
1002/**********************************************************************/
1007 const struct city *pcity,
1008 const struct universal *target,
1009 const enum req_problem_type prob_type)
1010{
1011 switch (target->kind) {
1012 case VUT_UTYPE:
1014 prob_type);
1015 case VUT_IMPROVEMENT:
1017 prob_type);
1018 default:
1019 break;
1020 };
1021 return FALSE;
1022}
1023
1024/**********************************************************************/
1029 const struct city *pcity,
1030 const struct universal *target,
1031 const enum req_problem_type prob_type)
1032{
1033 switch (target->kind) {
1034 case VUT_UTYPE:
1035 return can_city_build_unit_now(nmap, pcity, target->value.utype,
1036 prob_type);
1037 case VUT_IMPROVEMENT:
1039 prob_type);
1040 default:
1041 break;
1042 };
1043 return FALSE;
1044}
1045
1046/**********************************************************************/
1050 const struct city *pcity,
1051 const struct universal *target)
1052{
1053 switch (target->kind) {
1054 case VUT_UTYPE:
1056 case VUT_IMPROVEMENT:
1058 default:
1059 break;
1060 };
1061 return FALSE;
1062}
1063
1064/**********************************************************************/
1068{
1070 int current;
1071
1072 current = 0;
1073 unit_list_iterate(pcity->units_supported, punit) {
1074 current += unit_type_get(punit)->city_slots;
1076
1077 return max - current;
1078}
1079
1080/**********************************************************************/
1085{
1086 return are_reqs_active(&(const struct req_context) {
1087 .player = city_owner(pcity),
1088 .city = pcity,
1089 },
1090 nullptr,
1092}
1093
1094/**********************************************************************/
1098{
1099 return !pcity->did_buy || pcity->shield_stock <= 0;
1100}
1101
1102/**********************************************************************/
1106{
1107 if (city_tile(pcity) == nullptr) {
1108 /* When a "dummy" city is created with no tile, then choosing a build
1109 * target could fail. This currently might happen during map editing.
1110 * FIXME: Assumes the first unit is always "valid", so check for
1111 * obsolete units elsewhere. */
1112 pcity->production.kind = VUT_UTYPE;
1113 pcity->production.value.utype = utype_by_number(0);
1114 } else {
1116
1117 if (u) {
1118 pcity->production.kind = VUT_UTYPE;
1119 pcity->production.value.utype = u;
1120 } else {
1121 bool found = FALSE;
1122
1123 /* Just pick the first available item. */
1124 improvement_iterate(pimprove) {
1126 RPT_CERTAIN)) {
1127 found = TRUE;
1128 pcity->production.kind = VUT_IMPROVEMENT;
1129 pcity->production.value.building = pimprove;
1130 break;
1131 }
1133
1134 if (!found) {
1137 RPT_CERTAIN)) {
1138#ifndef FREECIV_NDEBUG
1139 /* Later than this, 'found' is only needed in an fc_assert() */
1140 found = TRUE;
1141#endif /* FREECIV_NDEBUG */
1142 pcity->production.kind = VUT_UTYPE;
1143 pcity->production.value.utype = punittype;
1144 }
1146 }
1147
1148 fc_assert_msg(found, "No production found for city %s!",
1150 }
1151 }
1152}
1153
1154/**********************************************************************/
1157const char *city_name_get(const struct city *pcity)
1158{
1159 return (pcity->name != nullptr) ? pcity->name : "City missing a name";
1160}
1161
1162/**********************************************************************/
1165#define POLLUTION_EFT_NEARMAX -95
1166const char *city_name_getx(const struct city *pcity)
1167{
1168 bool spacer = FALSE;
1169 static char em_city_name[MAX_LEN_CITYNAME + 7];
1170
1171 em_city_name[0] = '\0';
1172
1174 sz_strlcat(em_city_name, "ₓ"); /* ₓ🞪⁻⁰… (alternatives)*/
1175 }
1176
1178
1179 if (get_city_bonus(pcity, EFT_AIRLIFT) > 0) {
1180 if (!spacer) {
1182 spacer = TRUE;
1183 }
1184 sz_strlcat(em_city_name, "🛧"); /* 🛧🛪 (alternatives)*/
1185 }
1186
1188 if (!spacer) {
1190 spacer = TRUE;
1191 }
1192 sz_strlcat(em_city_name, "♺"); /* ♺♻♳ (alternatives)*/
1193 }
1194
1195 return em_city_name;
1196}
1197
1198/**********************************************************************/
1201void city_name_set(struct city *pcity, const char *new_name)
1202{
1203 if (pcity->name != nullptr) {
1204 free(pcity->name);
1205 }
1206
1207 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1208 pcity->name = fc_strdup(new_name);
1209 } else {
1210 log_warn(_("City name \"%s\" too long"), new_name);
1212 sz_strlcpy(pcity->name, new_name);
1213 }
1214}
1215
1216/**********************************************************************/
1220void city_size_add(struct city *pcity, int add)
1221{
1223
1224 fc_assert_ret(pcity != nullptr);
1226
1227 /* Client sets size to zero to start stacking citizens in */
1228 fc_assert_ret(size > -add || (!is_server() && size == add));
1229
1230 city_size_set(pcity, size + add);
1231}
1232
1233/**********************************************************************/
1237{
1238 fc_assert_ret(pcity != nullptr);
1239
1240 /* Set city size. */
1241 pcity->size = size;
1242}
1243
1244/**********************************************************************/
1247int city_population(const struct city *pcity)
1248{
1249 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1250 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1251}
1252
1253/**********************************************************************/
1258{
1259 int gold_needed = 0;
1260
1261 if (pcity == nullptr) {
1262 return 0;
1263 }
1264
1265 city_built_iterate(pcity, pimprove) {
1266 gold_needed += city_improvement_upkeep(pcity, pimprove);
1268
1270
1271 return MAX(gold_needed, 0);
1272}
1273
1274/**********************************************************************/
1279{
1280 int gold_needed = 0;
1281
1282 if (pcity == nullptr || pcity->units_supported == nullptr) {
1283 return 0;
1284 }
1285
1286 unit_list_iterate(pcity->units_supported, punit) {
1287 gold_needed += punit->upkeep[O_GOLD];
1289
1290 return gold_needed;
1291}
1292
1293/**********************************************************************/
1296bool city_has_building(const struct city *pcity,
1297 const struct impr_type *pimprove)
1298{
1299 if (pimprove == nullptr) {
1300 /* Callers should ensure that any external data is tested with
1301 * valid_improvement_by_number() */
1302 return FALSE;
1303 }
1304
1305 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1306}
1307
1308/**********************************************************************/
1313 const struct impr_type *b)
1314{
1315 int upkeep;
1316
1317 if (b == nullptr) {
1318 return 0;
1319 }
1320 if (!is_building_sellable(b)) {
1321 return 0;
1322 }
1323
1324 upkeep = b->upkeep;
1326 return 0;
1327 }
1328
1329 return upkeep;
1330}
1331
1332/**********************************************************************/
1340int city_tile_output(const struct city *pcity, const struct tile *ptile,
1342{
1343 int prod;
1344 const struct req_context city_ctxt = {
1345 .player = pcity ? city_owner(pcity) : nullptr,
1346 .city = pcity,
1347 .tile = ptile,
1348 };
1349 struct terrain *pterrain = tile_terrain(ptile);
1350 const struct output_type *output = &output_types[otype];
1351
1352 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1353
1354 if (T_UNKNOWN == pterrain) {
1355 /* Special case for the client. The server doesn't allow unknown tiles
1356 * to be worked but we don't necessarily know what player is involved. */
1357 return 0;
1358 }
1359
1360 prod = pterrain->output[otype];
1361 if (tile_resource_is_valid(ptile)) {
1362 prod += tile_resource(ptile)->data.resource->output[otype];
1363 }
1364
1365 switch (otype) {
1366 case O_SHIELD:
1367 if (pterrain->mining_shield_incr != 0) {
1368 prod += pterrain->mining_shield_incr
1370 / 100;
1371 }
1372 break;
1373 case O_FOOD:
1374 if (pterrain->irrigation_food_incr != 0) {
1375 prod += pterrain->irrigation_food_incr
1376 * get_target_bonus_effects(nullptr, &city_ctxt, nullptr,
1377 EFT_IRRIGATION_PCT) / 100;
1378 }
1379 break;
1380 case O_TRADE:
1381 case O_GOLD:
1382 case O_SCIENCE:
1383 case O_LUXURY:
1384 case O_LAST:
1385 break;
1386 }
1387
1388 prod += tile_roads_output_incr(ptile, otype);
1389 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1390
1391 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1392 if (prod > 0) {
1393 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1395
1396 if (prod >= game.info.granularity) {
1397 prod += get_tile_output_bonus(pcity, ptile, output,
1399
1400 if (is_celebrating) {
1401 prod += get_tile_output_bonus(pcity, ptile, output,
1403 }
1404 }
1405
1406 prod += (prod
1407 * get_tile_output_bonus(pcity, ptile, output,
1409 / 100;
1410 if (penalty_limit > 0 && prod > penalty_limit) {
1411 if (prod <= game.info.granularity) {
1412 prod = 0;
1413 } else {
1414 prod -= game.info.granularity;
1415 }
1416 }
1417 }
1418
1419 prod -= (prod
1420 * get_tile_output_bonus(pcity, ptile, output,
1422 / 100;
1423
1424 if (pcity != nullptr && is_city_center(pcity, ptile)) {
1425 prod = MAX(prod, game.info.min_city_center_output[otype]);
1426 }
1427
1428 return prod;
1429}
1430
1431/**********************************************************************/
1441int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1443{
1445}
1446
1447/**********************************************************************/
1459 const struct city *pcity,
1460 const struct tile *ptile)
1461{
1462 struct player *powner = city_owner(pcity);
1464 struct player *towner;
1465
1466 if (ptile == nullptr) {
1467 return FALSE;
1468 }
1469
1471 return FALSE;
1472 }
1473
1474 if (restriction != nullptr
1475 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1476 return FALSE;
1477 }
1478
1479 towner = tile_owner(ptile);
1480 if (towner != nullptr && towner != powner
1481 && !gives_shared_tiles(towner, powner)) {
1482 return FALSE;
1483 }
1484 /* TODO: civ3-like option for borders */
1485
1486 if (tile_worked(ptile) != nullptr && tile_worked(ptile) != pcity) {
1487 return FALSE;
1488 }
1489
1490 if (powner == restriction
1491 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1492 return FALSE;
1493 }
1494
1495 if (!is_free_worked(pcity, ptile)
1496 && unit_occupies_tile(ptile, powner) != nullptr) {
1497 return FALSE;
1498 }
1499
1500 if (get_city_tile_output_bonus(pcity, ptile, nullptr, EFT_TILE_WORKABLE) <= 0) {
1501 return FALSE;
1502 }
1503
1504 return TRUE;
1505}
1506
1507/**********************************************************************/
1513bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1514{
1516}
1517
1518/**********************************************************************/
1523 const struct tile *ptile)
1524{
1525 /* citymindist minimum is 1, meaning adjacent is okay */
1526 int citymindist = game.info.citymindist;
1527
1528 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1529 if (tile_city(ptile1)) {
1530 return TRUE;
1531 }
1533
1534 return FALSE;
1535}
1536
1537/**********************************************************************/
1545 const struct tile *ptile,
1546 const struct unit *punit,
1547 bool hut_test)
1548{
1549 if (!city_can_be_built_tile_only(nmap, ptile)) {
1550 return FALSE;
1551 }
1552
1553 if (punit == nullptr) {
1554 /* The remaining checks tests if punit can found a city here */
1555 return TRUE;
1556 }
1557
1558 if (hut_test) {
1559 struct player *towner;
1560
1561 /* Huts can be found only from native tiles, owned by the unit owner.
1562 * Unlike actual city building, this behavior is not affected
1563 * by the ruleset. */
1564 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1565 return FALSE;
1566 }
1567
1568 towner = tile_owner(ptile);
1569
1570 if (towner == nullptr || towner == unit_owner(punit)) {
1571 return TRUE;
1572 }
1573
1574 return FALSE;
1575 }
1576
1579 /* This action can't be done by this unit type at all. */
1580 continue;
1581 }
1582
1583 /* Non native tile detection */
1584 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1585 /* The ruleset may allow founding cities on non native terrain. */
1588 /* Many rulesets allow land units to build land cities and sea units
1589 * to build ocean cities. Air units can build cities anywhere. */
1590 continue;
1591 }
1592
1593 /* Foreign tile detection. */
1594 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1595 /* The ruleset may allow founding cities on foreign terrain. */
1597 paction->id,
1598 DRO_FOREIGN, TRUE)) {
1599 /* Cannot steal borders by settling. This has to be settled by
1600 * force of arms. */
1601 continue;
1602 }
1603
1604 return TRUE;
1606
1607 return FALSE;
1608}
1609
1610/**********************************************************************/
1618 const struct tile *ptile)
1619{
1621 /* No cities on this terrain. */
1622 return FALSE;
1623 }
1624
1626 return FALSE;
1627 }
1628
1629 return TRUE;
1630}
1631
1632/**********************************************************************/
1636bool is_capital(const struct city *pcity)
1637{
1638 return pcity->capital != CAPITAL_NOT;
1639}
1640
1641/**********************************************************************/
1644bool is_gov_center(const struct city *pcity)
1645{
1646 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1647}
1648
1649/**********************************************************************/
1654 const struct unit_type *attacker)
1655{
1656 if (!attacker) {
1657 /* Any defense building will do */
1659 }
1660
1661 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1662 nullptr, EFT_DEFEND_BONUS) > 0;
1663}
1664
1665/**********************************************************************/
1671bool city_happy(const struct city *pcity)
1672{
1674 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1675 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1676 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1677}
1678
1679/**********************************************************************/
1683bool city_unhappy(const struct city *pcity)
1684{
1685 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1687 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1688}
1689
1690/**********************************************************************/
1695{
1696 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1697}
1698
1699/**********************************************************************/
1702bool city_celebrating(const struct city *pcity)
1703{
1705}
1706
1707/**********************************************************************/
1710bool city_rapture_grow(const struct city *pcity)
1711{
1712 /* .rapture is checked instead of city_celebrating() because this
1713 function is called after .was_happy was updated. */
1714 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1715 && (pcity->rapture % game.info.rapturedelay) == 0
1717}
1718
1719/**********************************************************************/
1722bool city_is_occupied(const struct city *pcity)
1723{
1724 if (is_server()) {
1725 /* The server sees the units inside the city. */
1726 return (unit_list_size(city_tile(pcity)->units) > 0);
1727 } else {
1728 /* The client gets the occupied property from the server. */
1729 return pcity->client.occupied;
1730 }
1731}
1732
1733/**********************************************************************/
1736struct city *city_list_find_number(struct city_list *This, int id)
1737{
1738 if (id != 0) {
1740 if (pcity->id == id) {
1741 return pcity;
1742 }
1744 }
1745
1746 return nullptr;
1747}
1748
1749/**********************************************************************/
1752struct city *city_list_find_name(struct city_list *This, const char *name)
1753{
1755 if (fc_strcasecmp(name, pcity->name) == 0) {
1756 return pcity;
1757 }
1759
1760 return nullptr;
1761}
1762
1763/**********************************************************************/
1768int city_name_compare(const void *p1, const void *p2)
1769{
1770 return fc_strcasecmp((*(const struct city **) p1)->name,
1771 (*(const struct city **) p2)->name);
1772}
1773
1774/**********************************************************************/
1779{
1780 int i;
1781
1782 for (i = 0; i < game.control.num_city_styles; i++) {
1783 if (0 == strcmp(city_style_name_translation(i), s)) {
1784 return i;
1785 }
1786 }
1787
1788 return -1;
1789}
1790
1791/**********************************************************************/
1795int city_style_by_rule_name(const char *s)
1796{
1797 const char *qs = Qn_(s);
1798 int i;
1799
1800 for (i = 0; i < game.control.num_city_styles; i++) {
1801 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1802 return i;
1803 }
1804 }
1805
1806 return -1;
1807}
1808
1809/**********************************************************************/
1814{
1816}
1817
1818/**********************************************************************/
1822const char *city_style_rule_name(const int style)
1823{
1825}
1826
1827/* Cache of what city production caravan shields are allowed to help. */
1830
1831/**********************************************************************/
1836{
1837 struct requirement prod_as_req;
1838
1839#define log_ca_s_init log_debug
1840
1841 /* Remove old data. */
1844
1845 /* Common for all production kinds. */
1847 prod_as_req.survives = FALSE;
1848 prod_as_req.present = TRUE;
1849
1850 /* Check improvements */
1851 prod_as_req.source.kind = VUT_IMPROVEMENT;
1852
1854 /* Check this improvement. */
1855 prod_as_req.source.value.building = itype;
1856
1859 enabler) {
1861 &(enabler->target_reqs))
1862 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1863 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1864 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1865 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1866 /* This improvement kind can receive caravan shields. */
1867
1869
1870 /* Move on to the next improvement */
1871 break;
1872 }
1874
1875 log_ca_s_init("Help Wonder: %s for %s",
1877 ? "possible" : "impossible"),
1880
1881 /* Check units. */
1882 prod_as_req.source.kind = VUT_UTYPE;
1883
1885 /* Check this utype. */
1886 prod_as_req.source.value.utype = putype;
1887
1890 enabler) {
1892 &(enabler->target_reqs))
1893 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1894 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1895 /* This unit type kind can receive caravan shields. */
1896
1898
1899 /* Move on to the next unit type */
1900 break;
1901 }
1903
1904 log_ca_s_init("Help Wonder: %s for %s",
1906 ? "possible" : "impossible"),
1909
1910#undef log_ca_s_init
1911}
1912
1913/**********************************************************************/
1918{
1919 switch (tgt->kind) {
1920 case VUT_IMPROVEMENT:
1923 case VUT_UTYPE:
1925 utype_index(tgt->value.utype));
1926 default:
1928 return FALSE;
1929 };
1930}
1931
1932/**********************************************************************/
1944 const struct universal *target)
1945{
1950
1951 switch (pcity->changed_from.kind) {
1952 case VUT_IMPROVEMENT:
1953 if (is_wonder(pcity->changed_from.value.building)) {
1955 } else {
1957 }
1958 break;
1959 case VUT_UTYPE:
1961 break;
1962 default:
1964 break;
1965 };
1966
1967 switch (target->kind) {
1968 case VUT_IMPROVEMENT:
1969 if (is_wonder(target->value.building)) {
1971 } else {
1973 }
1974 break;
1975 case VUT_UTYPE:
1977 break;
1978 default:
1980 break;
1981 };
1982
1983 /* Changing production is penalized under certain circumstances. */
1984 if (orig_class == new_class
1985 || orig_class == PCT_LAST) {
1986 /* There's never a penalty for building something of the same class. */
1987 unpenalized_shields = pcity->before_change_shields;
1988 } else if (city_built_last_turn(pcity)) {
1989 /* Surplus shields from the previous production won't be penalized if
1990 * you change production on the very next turn. But you can only use
1991 * up to the city's surplus amount of shields in this way. */
1992 unpenalized_shields = MIN(pcity->last_turns_shield_surplus,
1993 pcity->before_change_shields);
1994 penalized_shields = pcity->before_change_shields - unpenalized_shields;
1995 } else {
1996 /* Penalize 50% of the production. */
1997 penalized_shields = pcity->before_change_shields;
1998 }
1999
2000 /* Do not put penalty on these. It shouldn't matter whether you disband unit
2001 before or after changing production...*/
2002 unpenalized_shields += pcity->disbanded_shields;
2003
2004 /* Caravan shields are penalized (just as if you disbanded the caravan)
2005 * if you're not building a wonder. */
2007 unpenalized_shields += pcity->caravan_shields;
2008 } else {
2009 penalized_shields += pcity->caravan_shields;
2010 }
2011
2014
2016}
2017
2018/**********************************************************************/
2023 const struct universal *target,
2025{
2026 int city_shield_surplus = pcity->surplus[O_SHIELD];
2029 int cost = universal_build_shield_cost(pcity, target);
2030
2031 if (target->kind == VUT_IMPROVEMENT
2032 && is_great_wonder(target->value.building)
2034 return FC_INFINITY;
2035 }
2036
2038 return 1;
2039 } else if (city_shield_surplus > 0) {
2040 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
2041 } else {
2042 return FC_INFINITY;
2043 }
2044}
2045
2046/**********************************************************************/
2054{
2055 if (pcity->surplus[O_FOOD] > 0) {
2056 return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
2057 pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
2058 } else if (pcity->surplus[O_FOOD] < 0) {
2059 /* Turns before famine loss */
2060 return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
2061 } else {
2062 return FC_INFINITY;
2063 }
2064}
2065
2066/**********************************************************************/
2069bool city_can_grow_to(const struct city *pcity, int pop_size)
2070{
2073}
2074
2075/**********************************************************************/
2078struct city *tile_enemy_city(const struct tile *ptile,
2079 const struct player *pplayer)
2080{
2081 struct city *pcity = tile_city(ptile);
2082
2083 if (pcity != nullptr && pplayers_at_war(pplayer, city_owner(pcity))) {
2084 return pcity;
2085 }
2086
2087 return nullptr;
2088}
2089
2090/**********************************************************************/
2093struct city *tile_allied_city(const struct tile *ptile,
2094 const struct player *pplayer)
2095{
2096 struct city *pcity = tile_city(ptile);
2097
2098 if (pcity != nullptr && pplayers_allied(pplayer, city_owner(pcity))) {
2099 return pcity;
2100 }
2101
2102 return nullptr;
2103}
2104
2105/**********************************************************************/
2108struct city *tile_non_attack_city(const struct tile *ptile,
2109 const struct player *pplayer)
2110{
2111 struct city *pcity = tile_city(ptile);
2112
2113 if (pcity != nullptr && pplayers_non_attack(pplayer, city_owner(pcity))) {
2114 return pcity;
2115 }
2116
2117 return nullptr;
2118}
2119
2120/**********************************************************************/
2123struct city *tile_non_allied_city(const struct tile *ptile,
2124 const struct player *pplayer)
2125{
2126 struct city *pcity = tile_city(ptile);
2127
2128 if (pcity != nullptr && !pplayers_allied(pplayer, city_owner(pcity))) {
2129 return pcity;
2130 }
2131
2132 return nullptr;
2133}
2134
2135/**********************************************************************/
2139 const struct unit *punit,
2140 int distance)
2141{
2143 distance);
2144}
2145
2146/**********************************************************************/
2150 const struct player *owner,
2151 const struct tile *ptile,
2152 int distance)
2153{
2154 square_iterate(nmap, ptile, distance, ptile1) {
2155 struct city *pcity = tile_city(ptile1);
2156
2158 return TRUE;
2159 }
2161
2162 return FALSE;
2163}
2164
2165/**********************************************************************/
2170 const struct tile *ptile,
2171 bool may_be_on_center)
2172{
2174 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2175 if (tile_city(ptile1)) {
2176 return TRUE;
2177 }
2178 }
2180
2181 return FALSE;
2182}
2183
2184/**********************************************************************/
2189int city_granary_size(int city_size)
2190{
2193 int base_value;
2194
2195 /* If the city has no citizens, there is no granary. */
2196 if (city_size == 0) {
2197 return 0;
2198 }
2199
2200 /* Granary sizes for the first food_inis citizens are given directly.
2201 * After that we increase the granary size by food_inc per citizen. */
2202 if (city_size > food_inis) {
2203 base_value = game.info.granary_food_ini[food_inis - 1];
2204 base_value += food_inc * (city_size - food_inis);
2205 } else {
2206 base_value = game.info.granary_food_ini[city_size - 1];
2207 }
2208
2209 return MAX(base_value * game.info.foodbox / 100, 1);
2210}
2211
2212/**********************************************************************/
2217static int player_base_citizen_happiness(const struct player *pplayer)
2218{
2219 int cities = city_list_size(pplayer->cities);
2220 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2223
2224 if (basis + step <= 0) {
2225 /* Value of zero means effect is inactive */
2226 return content;
2227 }
2228
2229 if (cities > basis) {
2230 content--;
2231 if (step != 0) {
2232 /* the first penalty is at (basis + 1) cities;
2233 the next is at (basis + step + 1), _not_ (basis + step) */
2234 content -= (cities - basis - 1) / step;
2235 }
2236 }
2237 return content;
2238}
2239
2240/**********************************************************************/
2244{
2245 int content = player_base_citizen_happiness(pplayer);
2246
2247 return CLIP(0, content, MAX_CITY_SIZE);
2248}
2249
2250/**********************************************************************/
2254{
2255 if (!game.info.angrycitizen) {
2256 return 0;
2257 } else {
2258 /* Create angry citizens only if we have a negative number of possible
2259 * content citizens. This can happen when empires grow really big. */
2260 int content = player_base_citizen_happiness(pplayer);
2261
2262 return CLIP(0, -content, MAX_CITY_SIZE);
2263 }
2264}
2265
2266/**********************************************************************/
2270{
2271 struct output_type *output = &output_types[otype];
2272 int bonus1 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2274 int bonus2 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2276
2277 return MAX(bonus1 * bonus2 / 100, 0);
2278}
2279
2280/**********************************************************************/
2285{
2286 int tithes_bonus = 0;
2287
2289 return 0;
2290 }
2291
2294
2295 return tithes_bonus;
2296}
2297
2298/**********************************************************************/
2302void add_tax_income(const struct player *pplayer, int trade, int *output)
2303{
2304 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2305 unsigned rates[3];
2306 int result[3];
2307
2308 if (game.info.changable_tax) {
2309 rates[SCIENCE] = pplayer->economic.science;
2310 rates[LUXURY] = pplayer->economic.luxury;
2311 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2312 } else {
2316 }
2317
2318 /* ANARCHY */
2320 rates[SCIENCE] = 0;
2321 rates[LUXURY] = 100;
2322 rates[TAX] = 0;
2323 }
2324
2325 distribute(trade, 3, rates, result);
2326
2327 output[O_SCIENCE] += result[SCIENCE];
2328 output[O_GOLD] += result[TAX];
2329 output[O_LUXURY] += result[LUXURY];
2330}
2331
2332/**********************************************************************/
2337{
2338 return pcity->turn_last_built + 1 >= game.info.turn;
2339}
2340
2341/**********************************************************************/
2344static const struct city *nearest_gov_center(const struct city *pcity,
2345 int *min_dist)
2346{
2347 const struct city *gov_center = nullptr;
2348
2350
2351 /* Check the special case that city itself is gov center
2352 * before expensive iteration through all cities. */
2353 if (is_gov_center(pcity)) {
2354 *min_dist = 0;
2355 return pcity;
2356 } else {
2358 /* Do not recheck current city */
2359 if (gc != pcity && is_gov_center(gc)) {
2360 int dist = real_map_distance(gc->tile, pcity->tile);
2361
2362 if (dist < *min_dist) {
2363 gov_center = gc;
2364 *min_dist = dist;
2365 }
2366 }
2368 }
2369
2370 return gov_center;
2371}
2372
2373/**********************************************************************/
2381static inline void get_worked_tile_output(const struct civ_map *nmap,
2382 const struct city *pcity,
2383 int *output, bool *workers_map)
2384{
2385 bool is_worked;
2386#ifdef CITY_DEBUGGING
2388#endif
2389 struct tile *pcenter = city_tile(pcity);
2390
2391 memset(output, 0, O_LAST * sizeof(*output));
2392
2395 if (workers_map == nullptr) {
2396 struct city *pwork = tile_worked(ptile);
2397
2398 is_worked = (pwork != nullptr && pwork == pcity);
2399 } else {
2400 is_worked = workers_map[city_tile_index];
2401 }
2402
2403 if (is_worked) {
2405#ifdef CITY_DEBUGGING
2406 /* This assertion never fails, but it's so slow that we disable
2407 * it by default. */
2409 == city_tile_output(pcity, ptile, is_celebrating, o));
2410#endif /* CITY_DEBUGGING */
2413 }
2415}
2416
2417/**********************************************************************/
2421void add_specialist_output(const struct city *pcity, int *output)
2422{
2424 int count = pcity->specialists[sp];
2425
2428
2429 output[stat_index] += count * amount;
2432}
2433
2434/**********************************************************************/
2443static inline void set_city_bonuses(struct city *pcity)
2444{
2447 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2448 &output_types[o],
2450 /* Total bonus cannot be negative, as that could lead to unresolvable
2451 * negative balance. */
2452 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2454}
2455
2456/**********************************************************************/
2466static inline void city_tile_cache_update(const struct civ_map *nmap,
2467 struct city *pcity)
2468{
2470 int radius_sq = city_map_radius_sq_get(pcity);
2471
2472 /* Initialize tile_cache if needed */
2473 if (pcity->tile_cache == nullptr || pcity->tile_cache_radius_sq == -1
2474 || pcity->tile_cache_radius_sq != radius_sq) {
2475 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2476 city_map_tiles(radius_sq)
2477 * sizeof(*(pcity->tile_cache)));
2478 pcity->tile_cache_radius_sq = radius_sq;
2479 }
2480
2481 /* Any unreal tiles are skipped - these values should have been memset
2482 * to 0 when the city was created. */
2483 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2485 (pcity->tile_cache[city_tile_index]).output[o]
2489}
2490
2491/**********************************************************************/
2495static inline int city_tile_cache_get_output(const struct city *pcity,
2496 int city_tile_index,
2497 enum output_type_id o)
2498{
2499 fc_assert_ret_val(pcity->tile_cache_radius_sq
2502
2503 return (pcity->tile_cache[city_tile_index]).output[o];
2504}
2505
2506/**********************************************************************/
2509static void set_surpluses(struct city *pcity)
2510{
2512 int surplus = pcity->prod[o] - pcity->usage[o];
2513
2514 /* Add 'surplus' waste to 'usage'. */
2515 if (surplus > 0) {
2516 struct output_type *output = get_output_type(o);
2520
2521 if (waste_by_rel_dist > 0) {
2522 int min_dist;
2523 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2524
2525 if (gov_center == nullptr) {
2526 /* No gov center - no income */
2527 waste_level = 100;
2528 } else {
2529 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2531 }
2532 }
2533
2534 if (waste_level > 0) {
2535 if (waste_level < 100) {
2536 pcity->usage[o] += (surplus * waste_level / 100);
2537 } else {
2538 pcity->usage[o] = pcity->prod[o];
2539 }
2540 }
2541 }
2542
2543 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2545}
2546
2547/**********************************************************************/
2550static void happy_copy(struct city *pcity, enum citizen_feeling i)
2551{
2552 int c = 0;
2553
2554 for (; c < CITIZEN_LAST; c++) {
2555 pcity->feel[c][i] = pcity->feel[c][i - 1];
2556 }
2557}
2558
2559/**********************************************************************/
2562static void citizen_base_mood(struct city *pcity)
2563{
2564 struct player *pplayer = city_owner(pcity);
2565 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2566 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2567 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2568 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2571
2572 /* This is the number of citizens that may start out content, depending
2573 * on empire size and game's city unhappysize. This may be bigger than
2574 * the size of the city, since this is a potential. */
2576 /* Similarly, this is the potential number of angry citizens. */
2578
2579 /* Create content citizens. Take specialists from their ranks. */
2580 *content = MAX(0, MIN(size, base_content) - spes);
2581
2582 /* Create angry citizens. Specialists never become angry. */
2583 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2584 *angry = MIN(base_angry, size - spes);
2585
2586 /* Create unhappy citizens. In the beginning, all who are not content,
2587 * specialists or angry are unhappy. This is changed by luxuries and
2588 * buildings later. */
2589 *unhappy = (size - spes - *content - *angry);
2590
2591 /* No one is born happy. */
2592 *happy = 0;
2593}
2594
2595/**********************************************************************/
2601static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2602{
2603 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2604 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2605 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2606 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2607
2608 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2609 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2610 (*angry)--;
2611 (*unhappy)++;
2613 }
2614 while (*luxuries >= game.info.happy_cost && *content > 0) {
2615 /* Upgrade content to happy: costs HAPPY_COST each. */
2616 (*content)--;
2617 (*happy)++;
2619 }
2620 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2621 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2622 * double the cost. */
2623 (*unhappy)--;
2624 (*happy)++;
2625 *luxuries -= 2 * game.info.happy_cost;
2626 }
2627 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2628 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2629 (*unhappy)--;
2630 (*content)++;
2632 }
2633}
2634
2635/**********************************************************************/
2638static inline void citizen_happy_luxury(struct city *pcity)
2639{
2640 int x = pcity->prod[O_LUXURY];
2641
2643}
2644
2645/**********************************************************************/
2648static inline void citizen_content_buildings(struct city *pcity)
2649{
2650 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2651 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2652 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2654
2655 /* make people content (but not happy):
2656 get rid of angry first, then make unhappy content. */
2657 while (faces > 0 && *angry > 0) {
2658 (*angry)--;
2659 (*unhappy)++;
2660 faces--;
2661 }
2662 while (faces > 0 && *unhappy > 0) {
2663 (*unhappy)--;
2664 (*content)++;
2665 faces--;
2666 }
2667}
2668
2669/**********************************************************************/
2672static inline void citizen_happiness_nationality(struct city *pcity)
2673{
2677
2680
2681 if (pct > 0) {
2682 int enemies = 0;
2683 int unhappy_inc;
2684 struct player *owner = city_owner(pcity);
2685
2686 citizens_foreign_iterate(pcity, pslot, nationality) {
2688 enemies += nationality;
2689 }
2691
2692 unhappy_inc = enemies * pct / 100;
2693
2694 /* First make content => unhappy, then happy => unhappy,
2695 * then happy => content. No-one becomes angry. */
2696 while (unhappy_inc > 0 && *content > 0) {
2697 (*content)--;
2698 (*unhappy)++;
2699 unhappy_inc--;
2700 }
2701 while (unhappy_inc > 1 && *happy > 0) {
2702 (*happy)--;
2703 (*unhappy)++;
2704 unhappy_inc -= 2;
2705 }
2706 while (unhappy_inc > 0 && *happy > 0) {
2707 (*happy)--;
2708 (*content)++;
2709 unhappy_inc--;
2710 }
2711 }
2712 }
2713}
2714
2715/**********************************************************************/
2721static inline void citizen_happy_units(struct city *pcity)
2722{
2723 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2724 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2725 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2726 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2727 citizens amt = pcity->martial_law;
2728
2729 /* Pacify discontent citizens through martial law. First convert
2730 * angry => unhappy, then unhappy => content. */
2731 while (amt > 0 && *angry > 0) {
2732 (*angry)--;
2733 (*unhappy)++;
2734 amt--;
2735 }
2736 while (amt > 0 && *unhappy > 0) {
2737 (*unhappy)--;
2738 (*content)++;
2739 amt--;
2740 }
2741
2742 /* Now make citizens unhappier because of military units away from home.
2743 * First make content => unhappy, then happy => unhappy,
2744 * then happy => content. */
2745 amt = pcity->unit_happy_upkeep;
2746 while (amt > 0 && *content > 0) {
2747 (*content)--;
2748 (*unhappy)++;
2749 amt--;
2750 }
2751 while (amt > 1 && *happy > 0) {
2752 (*happy)--;
2753 (*unhappy)++;
2754 amt -= 2;
2755 }
2756 while (amt > 0 && *happy > 0) {
2757 (*happy)--;
2758 (*content)++;
2759 amt--;
2760 }
2761 /* Any remaining unhappiness is lost since angry citizens aren't created
2762 * here. */
2763 /* FIXME: Why not? - Per */
2764}
2765
2766/**********************************************************************/
2769static inline void citizen_happy_wonders(struct city *pcity)
2770{
2771 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2772 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2773 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2774 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2775 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2776
2777 /* First create happy citizens from content, then from unhappy
2778 * citizens; we cannot help angry citizens here. */
2779 while (bonus > 0 && *content > 0) {
2780 (*content)--;
2781 (*happy)++;
2782 bonus--;
2783 }
2784 while (bonus > 1 && *unhappy > 0) {
2785 (*unhappy)--;
2786 (*happy)++;
2787 bonus -= 2;
2788 }
2789 /* The rest falls through and lets unhappy people become content. */
2790
2792 *content += *unhappy + *angry;
2793 *unhappy = 0;
2794 *angry = 0;
2795 return;
2796 }
2797
2799
2800 /* get rid of angry first, then make unhappy content */
2801 while (bonus > 0 && *angry > 0) {
2802 (*angry)--;
2803 (*unhappy)++;
2804 bonus--;
2805 }
2806 while (bonus > 0 && *unhappy > 0) {
2807 (*unhappy)--;
2808 (*content)++;
2809 bonus--;
2810 }
2811}
2812
2813/**********************************************************************/
2817static inline void unhappy_city_check(struct city *pcity)
2818{
2819 if (city_unhappy(pcity)) {
2821 switch (output_types[o].unhappy_penalty) {
2823 pcity->unhappy_penalty[o] = 0;
2824 break;
2826 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2827 break;
2829 pcity->unhappy_penalty[o] = pcity->prod[o];
2830 break;
2831 }
2832
2833 pcity->prod[o] -= pcity->unhappy_penalty[o];
2835 } else {
2836 memset(pcity->unhappy_penalty, 0,
2837 O_LAST * sizeof(*pcity->unhappy_penalty));
2838 }
2839}
2840
2841/**********************************************************************/
2845 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2846{
2847 int prod, pop, mod;
2848
2849 /* Add one one pollution per shield, multiplied by the bonus. */
2851 prod = shield_total * MAX(prod, 0) / 100;
2852
2853 /* Add one pollution per citizen for baseline combined bonus (100%). */
2856 / 100;
2857 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2858
2859 /* Then there is base pollution (usually a negative number). */
2860 mod = game.info.base_pollution;
2861
2862 if (pollu_prod) {
2863 *pollu_prod = prod;
2864 }
2865 if (pollu_pop) {
2866 *pollu_pop = pop;
2867 }
2868 if (pollu_mod) {
2869 *pollu_mod = mod;
2870 }
2871 return MAX(prod + pop + mod, 0);
2872}
2873
2874/**********************************************************************/
2878int city_pollution(const struct city *pcity, int shield_total)
2879{
2881 nullptr, nullptr, nullptr);
2882}
2883
2884/**********************************************************************/
2891static int get_trade_illness(const struct city *pcity)
2892{
2893 float illness_trade = 0.0;
2894
2896 if (trade_city->turn_plague != -1
2897 && game.info.turn - trade_city->turn_plague < 5) {
2898 illness_trade += (float)game.info.illness_trade_infection
2899 * sqrt(1.0 * city_size_get(pcity)
2900 * city_size_get(trade_city)) / 100.0;
2901 }
2903
2904 return (int)illness_trade;
2905}
2906
2907/**********************************************************************/
2911static int get_city_health(const struct city *pcity)
2912{
2914}
2915
2916/**********************************************************************/
2928int city_illness_calc(const struct city *pcity, int *ill_base,
2929 int *ill_size, int *ill_trade, int *ill_pollution)
2930{
2931 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2933
2934 if (game.info.illness_on
2936 /* offset the city size by game.info.illness_min_size */
2938
2939 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2940 * 10.0 * game.info.illness_base_factor);
2941 if (is_server()) {
2942 /* On the server we recalculate the illness due to trade as we have
2943 * all the information */
2944 illness_trade = get_trade_illness(pcity);
2945 } else {
2946 /* On the client we have to rely on the value saved within the city
2947 * struct */
2948 illness_trade = pcity->illness_trade;
2949 }
2950
2951 illness_pollution = pcity->pollution
2953 }
2954
2955 illness_base = illness_size + illness_trade + illness_pollution;
2957
2958 /* returning other data */
2959 if (ill_size) {
2961 }
2962
2963 if (ill_trade) {
2964 *ill_trade = illness_trade;
2965 }
2966
2967 if (ill_pollution) {
2969 }
2970
2971 if (ill_base) {
2973 }
2974
2975 return CLIP(0, illness_base * illness_percent / 100 , 999);
2976}
2977
2978/**********************************************************************/
2982{
2983 /* Correctly handles special case turn_plague == -1 (never) */
2984 return (pcity->turn_plague == game.info.turn);
2985}
2986
2987/**********************************************************************/
2990int city_build_slots(const struct city *pcity)
2991{
2993}
2994
2995/**********************************************************************/
3000int city_airlift_max(const struct city *pcity)
3001{
3003}
3004
3005/**********************************************************************/
3011inline void set_city_production(struct city *pcity)
3012{
3013 int trade;
3014
3015 /* Calculate city production!
3016 *
3017 * This is a rather complicated process if we allow rules to become
3018 * more generalized. We can assume that there are no recursive dependency
3019 * loops, but there are some dependencies that do not follow strict
3020 * ordering. For instance corruption must be calculated before
3021 * trade taxes can be counted up, which must occur before the science bonus
3022 * is added on. But the calculation of corruption must include the
3023 * trade bonus. To do this without excessive special casing means that in
3024 * this case the bonuses are multiplied on twice (but only saved the second
3025 * time).
3026 */
3027
3029 pcity->prod[o] = pcity->citizen_base[o];
3031
3032 /* Add on special extra incomes: trade routes and tithes. */
3034 struct city *tcity = game_city_by_number(proute->partner);
3035 bool can_trade;
3036
3037 /* Partner city may have not yet been sent to the client, or
3038 * there's just a placeholder city with a placeholder owner
3039 * created for some tile->worked. */
3040 if (!is_server()
3041 && (tcity == nullptr
3042 || city_owner(tcity)->slot == nullptr)) {
3043 continue;
3044 }
3045
3046 fc_assert_action(tcity != nullptr, continue);
3047
3049
3050 if (!can_trade) {
3053
3054 if (settings->cancelling == TRI_ACTIVE) {
3055 can_trade = TRUE;
3056 }
3057 }
3058
3059 if (can_trade) {
3060 int value;
3061
3062 value =
3064 proute->value = trade_from_route(pcity, proute, value);
3065 pcity->prod[O_TRADE] += proute->value
3066 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3067 } else {
3068 proute->value = 0;
3069 }
3072
3073 /* Account for waste. Note that waste is calculated before tax income is
3074 * calculated, so if you had "science waste" it would not include taxed
3075 * science. However waste is calculated after the bonuses are multiplied
3076 * on, so shield waste will include shield bonuses. */
3078 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3079
3080 prod = MAX(prod, 0);
3081 pcity->waste[o] = city_waste(pcity, o, prod, nullptr);
3083
3084 /* Convert trade into science/luxury/gold, and add this on to whatever
3085 * science/luxury/gold is already there. */
3086 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3087 + pcity->abs_bonus[O_TRADE];
3088 trade = MAX(trade, 0);
3090 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3091 pcity->prod);
3092
3093 /* Add on effect bonuses and waste. Note that the waste calculation
3094 * (above) already includes the bonuses. */
3096 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3097
3098 prod = MAX(prod, 0);
3099 pcity->prod[o] = prod;
3100 pcity->prod[o] -= pcity->waste[o];
3102}
3103
3104/**********************************************************************/
3108 struct unit *punit, int *free_unhappy)
3109{
3110 struct city *pcity;
3111 const struct unit_type *ut;
3112 struct player *plr;
3113 int happy_cost;
3114
3115 if (punit == nullptr || free_unhappy == nullptr) {
3116 return 0;
3117 }
3118
3120 if (pcity == nullptr) {
3121 return 0;
3122 }
3123
3125 plr = unit_owner(punit);
3126 happy_cost = utype_happy_cost(ut, plr);
3127
3128 if (happy_cost <= 0) {
3129 return 0;
3130 }
3131
3133
3135 return 0;
3136 }
3137
3139 if (happy_cost <= 0) {
3140 return 0;
3141 }
3142
3143 if (*free_unhappy >= happy_cost) {
3144 *free_unhappy -= happy_cost;
3145 return 0;
3146 } else {
3147 happy_cost -= *free_unhappy;
3148 *free_unhappy = 0;
3149 }
3150
3151 return happy_cost;
3152}
3153
3154/**********************************************************************/
3158static inline void city_support(const struct civ_map *nmap,
3159 struct city *pcity)
3160{
3161 int free_unhappy;
3162 int max_mart_units;
3163
3164 /* Clear all usage values. */
3165 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3166 pcity->martial_law = 0;
3167 pcity->unit_happy_upkeep = 0;
3168
3169 /* Building and unit gold upkeep depends on the setting
3170 * 'game.info.gold_upkeep_style':
3171 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3172 * city.
3173 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3174 * The upkeep for units is paid by the nation.
3175 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3176 * nation. */
3178 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3179 switch (game.info.gold_upkeep_style) {
3180 case GOLD_UPKEEP_CITY:
3182 fc__fallthrough; /* No break */
3183 case GOLD_UPKEEP_MIXED:
3185 break;
3186 case GOLD_UPKEEP_NATION:
3187 /* nothing */
3188 break;
3189 }
3190 /* Food consumption by citizens. */
3192
3194 if (max_mart_units > 0) {
3196 int sel_count = 0;
3197 int i;
3198
3201 && unit_owner(punit) == city_owner(pcity)) {
3202 int current = get_target_bonus_effects(nullptr,
3203 &(const struct req_context) {
3204 .player = city_owner(pcity),
3205 .city = pcity,
3206 .tile = city_tile(pcity),
3207 .unit = punit,
3208 .unittype = unit_type_get(punit)
3209 },
3210 nullptr, EFT_MARTIAL_LAW_BY_UNIT);
3211 if (current > 0) {
3212 if (sel_count < max_mart_units) {
3213 best_units[sel_count++] = current;
3214 } else if (current > best_units[max_mart_units - 1]) {
3215 for (i = max_mart_units - 1; i >= 0 && current > best_units[i]; i--) {
3216 if (i + 1 < max_mart_units) {
3217 best_units[i + 1] = best_units[i];
3218 }
3219 }
3220
3221 best_units[i + 1] = current;
3222 }
3223 }
3224 }
3226
3227 pcity->martial_law = 0;
3228 for (i = 0; i < sel_count; i++) {
3229 pcity->martial_law += best_units[i];
3230 }
3231
3232 pcity->martial_law = MIN(pcity->martial_law, MAX_CITY_SIZE);
3233 }
3234
3236 unit_list_iterate(pcity->units_supported, punit) {
3237 pcity->unit_happy_upkeep += city_unit_unhappiness(nmap, punit, &free_unhappy);
3239 if (O_GOLD != o) {
3240 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3241 pcity->usage[o] += punit->upkeep[o];
3242 }
3245}
3246
3247/**********************************************************************/
3260 struct city *pcity, bool *workers_map)
3261{
3262 if (workers_map == nullptr) {
3263 /* Do a full refresh */
3264
3265 /* Calculate the bonus[] array values. */
3267 /* Calculate the tile_cache[] values. */
3269 /* Manage settlers, and units */
3271 }
3272
3273 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3274 get_worked_tile_output(nmap, pcity, pcity->citizen_base, workers_map);
3275 add_specialist_output(pcity, pcity->citizen_base);
3276
3279 /* Note that pollution is calculated before unhappy_city_check() makes
3280 * deductions for disorder; so a city in disorder still causes pollution */
3281 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3282
3284 citizen_happy_luxury(pcity); /* With our new found luxuries */
3285
3288
3291
3292 /* Martial law & unrest from units */
3295
3296 /* Building (including wonder) happiness effects */
3299
3302}
3303
3304/**********************************************************************/
3311int city_waste(const struct city *pcity, Output_type_id otype, int total,
3312 int *breakdown)
3313{
3314 int penalty_waste = 0;
3315 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3316 * corruption */
3317 int total_eft = total; /* Normal corruption calculated on total reduced by
3318 * possible size penalty */
3319 const struct output_type *output = get_output_type(otype);
3321 bool waste_all = FALSE;
3322
3323 if (otype == O_TRADE) {
3324 /* FIXME: special case for trade: it is affected by notradesize and
3325 * fulltradesize server settings.
3326 *
3327 * If notradesize and fulltradesize are equal then the city gets no
3328 * trade at that size. */
3329 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3330 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3331
3332 if (city_size_get(pcity) <= notradesize) {
3333 penalty_size = total_eft; /* Then no trade income. */
3334 } else if (city_size_get(pcity) >= fulltradesize) {
3335 penalty_size = 0;
3336 } else {
3337 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3338 / (fulltradesize - notradesize);
3339 }
3340 }
3341
3342 /* Apply corruption only to anything left after tradesize */
3344
3345 /* Distance-based waste.
3346 * Don't bother calculating if there's nothing left to lose. */
3347 if (total_eft > 0) {
3352 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3353 int min_dist;
3354 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3355
3356 if (gov_center == nullptr) {
3357 waste_all = TRUE; /* No gov center - no income */
3358 } else {
3360 if (waste_by_rel_dist > 0) {
3361 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3362 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3363 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3365 }
3366 }
3367 }
3368 }
3369
3370 if (waste_all) {
3372 } else {
3375
3376 /* Corruption/waste calculated only for the actually produced amount */
3377 if (waste_level > 0) {
3379 }
3380
3381 /* Bonus calculated only for the actually produced amount */
3383
3384 /* Clip */
3386 }
3387
3388 if (breakdown) {
3391 }
3392
3393 /* Add up total penalty */
3394 return penalty_waste + penalty_size;
3395}
3396
3397/**********************************************************************/
3402{
3403 citizens count = 0;
3404
3406 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3407 count += pcity->specialists[sp];
3409
3410 return count;
3411}
3412
3413/**********************************************************************/
3417{
3418 int count = 0;
3419
3421 count += pcity->specialists[sp];
3423
3424 return count;
3425}
3426
3427/**********************************************************************/
3433 const struct city *pcity)
3434{
3435 int best = DEFAULT_SPECIALIST;
3436 int val = get_specialist_output(pcity, best, otype);
3437
3441
3442 if (val2 > val) {
3443 best = i;
3444 val = val2;
3445 }
3446 }
3448
3449 return best;
3450}
3451
3452/**********************************************************************/
3456 const struct impr_type *pimprove)
3457{
3458 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3459
3460 if (is_server() && is_wonder(pimprove)) {
3461 /* Client just read the info from the packets. */
3462 wonder_built(pcity, pimprove);
3463 }
3464}
3465
3466/**********************************************************************/
3470 const struct impr_type *pimprove)
3471{
3472 log_debug("Improvement %s removed from city %s",
3473 improvement_rule_name(pimprove), pcity->name);
3474
3475 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3476
3477 if (is_server() && is_wonder(pimprove)) {
3478 /* Client just read the info from the packets. */
3479 wonder_destroyed(pcity, pimprove);
3480 }
3481}
3482
3483/**********************************************************************/
3487{
3488 return BV_ISSET(pcity->city_options, option);
3489}
3490
3491/**********************************************************************/
3495{
3496 int i;
3497
3498 city_styles = fc_calloc(num, sizeof(*city_styles));
3500
3501 for (i = 0; i < game.control.num_city_styles; i++) {
3503 }
3504}
3505
3506/**********************************************************************/
3510{
3511 int i;
3512
3513 for (i = 0; i < game.control.num_city_styles; i++) {
3515 }
3516
3518 city_styles = nullptr;
3520}
3521
3522/**********************************************************************/
3528struct city *create_city_virtual(struct player *pplayer,
3529 struct tile *ptile, const char *name)
3530{
3531 int i,len;
3532
3533 /* Make sure that contents of city structure are correctly initialized,
3534 * if you ever allocate it by some other mean than fc_calloc() */
3535 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3536
3537 fc_assert_ret_val(name != nullptr, nullptr); /* No unnamed cities! */
3538
3539 /* Do this early, so any logging later will have the city name */
3541
3542 pcity->tile = ptile;
3543
3544 fc_assert_ret_val(pplayer != nullptr, nullptr); /* No unowned cities! */
3545
3546 pcity->owner = pplayer;
3547 pcity->acquire_t = CACQ_FOUNDED;
3548
3549 if (is_server()) {
3550 pcity->original = pplayer;
3551 }
3552
3553 /* City structure was allocated with fc_calloc(), so contents are initially
3554 * zero. There is no need to initialize it a second time. */
3555
3556 /* Now set some useful default values. */
3557 pcity->capital = CAPITAL_NOT;
3558 city_size_set(pcity, 1);
3559 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3560 pcity->wlcb = WLCB_SMART;
3561
3563 pcity->bonus[o] = 100;
3564 pcity->abs_bonus[o] = 0;
3566
3567 pcity->turn_plague = -1; /* -1 = never */
3568 pcity->did_buy = FALSE;
3569 pcity->city_radius_sq = game.info.init_city_radius_sq;
3570 pcity->turn_founded = game.info.turn;
3571 pcity->turn_last_built = game.info.turn;
3572
3573 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3574
3575 /* pcity->ai.act_cache: worker activities on the city map */
3576
3577 /* Initialise improvements list */
3578 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3579 pcity->built[i].turn = I_NEVER;
3580 }
3581
3582 /* Set up the worklist */
3583 worklist_init(&pcity->worklist);
3584
3585 pcity->units_supported = unit_list_new();
3586 pcity->routes = trade_route_list_new();
3587 pcity->task_reqs = worker_task_list_new();
3588
3589 if (is_server()) {
3590 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3591
3592 CALL_FUNC_EACH_AI(city_alloc, pcity);
3593 } else {
3594 pcity->client.info_units_supported =
3596 pcity->client.info_units_present =
3598 /* collecting_info_units_supported set by fc_calloc().
3599 * collecting_info_units_present set by fc_calloc(). */
3600 }
3601
3603 pcity->counter_values = fc_malloc(sizeof(int) * len);
3604
3605 for (i = 0; i < len; i++) {
3606 pcity->counter_values[i] = counter_by_index(i, CTGT_CITY)->def;
3607 }
3608
3609 return pcity;
3610}
3611
3612/**********************************************************************/
3617{
3618 CALL_FUNC_EACH_AI(city_free, pcity);
3619
3621
3622 /* Free worker tasks */
3623 while (worker_task_list_size(pcity->task_reqs) > 0) {
3624 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3625
3626 worker_task_list_remove(pcity->task_reqs, ptask);
3627
3628 free(ptask);
3629 }
3630 worker_task_list_destroy(pcity->task_reqs);
3631
3632 /* Free rally points */
3634
3635 unit_list_destroy(pcity->units_supported);
3637 if (pcity->tile_cache != nullptr) {
3638 free(pcity->tile_cache);
3639 }
3640
3641 if (pcity->cm_parameter) {
3642 free(pcity->cm_parameter);
3643 }
3644
3645 if (pcity->counter_values) {
3646 free(pcity->counter_values);
3647 }
3648
3649 if (!is_server()) {
3650 unit_list_destroy(pcity->client.info_units_supported);
3651 unit_list_destroy(pcity->client.info_units_present);
3652 /* Handle a rare case where the game is freed in the middle of a
3653 * spy/diplomat investigate cycle. */
3654 if (pcity->client.collecting_info_units_supported != nullptr) {
3655 unit_list_destroy(pcity->client.collecting_info_units_supported);
3656 }
3657 if (pcity->client.collecting_info_units_present != nullptr) {
3658 unit_list_destroy(pcity->client.collecting_info_units_present);
3659 }
3660 }
3661
3662 free(pcity->name);
3663
3664 memset(pcity, 0, sizeof(*pcity)); /* Ensure no pointers remain */
3665 free(pcity);
3666}
3667
3668/**********************************************************************/
3672bool city_exist(int id)
3673{
3674 /* Check if city exist in game */
3675 if (game_city_by_number(id)) {
3676 return TRUE;
3677 }
3678
3679 return FALSE;
3680}
3681
3682/**********************************************************************/
3689bool city_is_virtual(const struct city *pcity)
3690{
3691 if (!pcity) {
3692 return FALSE;
3693 }
3694
3695 return pcity != game_city_by_number(pcity->id);
3696}
3697
3698/**********************************************************************/
3701bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3702{
3703 return is_city_center(pcity, ptile);
3704}
3705
3706/**********************************************************************/
3709void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3710{
3711 return pcity->server.ais[ai_type_number(ai)];
3712}
3713
3714/**********************************************************************/
3717void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3718 void *data)
3719{
3720 pcity->server.ais[ai_type_number(ai)] = data;
3721}
3722
3723/**********************************************************************/
3727{
3728 /* Free rally points */
3729 if (pcity->rally_point.length > 0) {
3730 pcity->rally_point.length = 0;
3731 pcity->rally_point.persistent = FALSE;
3732 pcity->rally_point.vigilant = FALSE;
3733 free(pcity->rally_point.orders);
3734 pcity->rally_point.orders = nullptr;
3735 }
3736}
3737
3738/**********************************************************************/
3742 struct city *pcity)
3743{
3744 struct unit_order *checked_orders;
3745 const struct civ_map *nmap = &(wld.map);
3746
3747 if (pcity == nullptr) {
3748 /* Probably lost. */
3749 log_verbose("handle_city_rally_point() bad city number %d.",
3750 packet->id);
3751 return;
3752 }
3753
3754 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3755 /* Shouldn't happen */
3756 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3757 packet->length, MAX_LEN_ROUTE);
3758 return;
3759 }
3760
3761 pcity->rally_point.length = packet->length;
3762
3763 if (packet->length == 0) {
3764 pcity->rally_point.vigilant = FALSE;
3765 pcity->rally_point.persistent = FALSE;
3766 if (pcity->rally_point.orders) {
3767 free(pcity->rally_point.orders);
3768 pcity->rally_point.orders = nullptr;
3769 }
3770 } else {
3772 packet->orders);
3773 if (!checked_orders) {
3774 pcity->rally_point.length = 0;
3775 log_error("invalid rally point orders for %s.",
3777 return;
3778 }
3779
3780 pcity->rally_point.persistent = packet->persistent;
3781 pcity->rally_point.vigilant = packet->vigilant;
3782 pcity->rally_point.orders = checked_orders;
3783 }
3784}
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:1694
bool city_is_virtual(const struct city *pcity)
Definition city.c:3689
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:2022
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2601
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:2648
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3701
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1917
static bv_imprs caravan_helped_impr
Definition city.c:1828
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:1201
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2217
#define POLLUTION_EFT_NEARMAX
Definition city.c:1165
const char * city_name_getx(const struct city *pcity)
Definition city.c:1166
int city_granary_size(int city_size)
Definition city.c:2189
static void get_worked_tile_output(const struct civ_map *nmap, const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2381
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2253
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2844
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3717
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2769
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2149
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2336
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1105
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3311
static void city_support(const struct civ_map *nmap, struct city *pcity)
Definition city.c:3158
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2990
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:1296
const char * city_style_name_translation(const int style)
Definition city.c:1813
void city_styles_free(void)
Definition city.c:3509
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2495
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:650
int city_superspecialists(const struct city *pcity)
Definition city.c:3416
bool is_capital(const struct city *pcity)
Definition city.c:1636
void city_styles_alloc(int num)
Definition city.c:3494
const char * city_name_get(const struct city *pcity)
Definition city.c:1157
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1458
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1067
void city_production_caravan_shields_init(void)
Definition city.c:1835
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3469
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1312
int city_airlift_max(const struct city *pcity)
Definition city.c:3000
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1522
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1049
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:3486
int city_population(const struct city *pcity)
Definition city.c:1247
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1822
void city_size_add(struct city *pcity, int add)
Definition city.c:1220
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1083
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:1722
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:2302
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:2123
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3107
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1653
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2243
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:2466
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2284
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2138
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:1710
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:1683
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3432
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3528
void set_city_production(struct city *pcity)
Definition city.c:3011
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:1736
static bv_unit_types caravan_helped_utype
Definition city.c:1829
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2269
bool city_celebrating(const struct city *pcity)
Definition city.c:1702
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1617
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:2928
const char * get_output_name(Output_type_id output)
Definition city.c:630
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target, const enum req_problem_type prob_type)
Definition city.c:1006
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2069
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1943
static int get_city_health(const struct city *pcity)
Definition city.c:2911
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:3259
static void set_city_bonuses(struct city *pcity)
Definition city.c:2443
static void set_surpluses(struct city *pcity)
Definition city.c:2509
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2344
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:911
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1544
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2878
bool city_happy(const struct city *pcity)
Definition city.c:1671
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1236
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3455
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1441
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:2093
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2078
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:3616
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target, const enum req_problem_type prob_type)
Definition city.c:1028
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:3401
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:3741
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:1778
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2421
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:957
static const struct city struct citystyle * city_styles
Definition city.c:84
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3709
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1752
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2672
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1340
static int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
Definition city.c:64
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:123
bool is_gov_center(const struct city *pcity)
Definition city.c:1644
#define log_ca_s_init
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2638
int city_map_tiles(int city_radius_sq)
Definition city.c:171
static void unhappy_city_check(struct city *pcity)
Definition city.c:2817
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2108
bool city_exist(int id)
Definition city.c:3672
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1513
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:2053
void city_rally_point_clear(struct city *pcity)
Definition city.c:3726
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:2169
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2981
static int get_trade_illness(const struct city *pcity)
Definition city.c:2891
bool city_can_change_build(const struct city *pcity)
Definition city.c:1097
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:982
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1278
int city_style_by_rule_name(const char *s)
Definition city.c:1795
static void citizen_base_mood(struct city *pcity)
Definition city.c:2562
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1768
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1257
static void citizen_happy_units(struct city *pcity)
Definition city.c:2721
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2550
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:853
#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:876
#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:842
#define is_free_worked_index(city_tile_index)
Definition city.h:888
#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:848
#define PCT_LAST
Definition city.h:41
#define output_type_iterate_end
Definition city.h:859
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:115
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
bool is_building_sellable(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_warn(message,...)
Definition log.h:106
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_do_output_for_level(level)
Definition log.h:90
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_base(level, message,...)
Definition log.h:95
log_level
Definition log.h:29
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:434
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:659
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:1085
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1222
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:397
#define square_iterate_end
Definition map.h:400
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:229
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:350
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:496
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
struct city_list * cities
Definition packhand.c:120
int len
Definition packhand.c:128
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1376
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1397
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1451
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:432
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1485
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
bool are_reqs_active(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, enum req_problem_type prob_type)
bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool req_vec_wants_type(const struct requirement_vector *reqs, enum universals_n kind)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
static struct setting settings[]
Definition settings.c:1494
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
#define CLIP(lower, current, upper)
Definition shared.h:57
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
#define MAX(x, y)
Definition shared.h:54
struct specialist * specialist_by_number(const Specialist_type_id id)
Definition specialist.c:110
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Definition specialist.c:270
#define specialist_type_iterate_end
Definition specialist.h:85
#define specialist_type_iterate(sp)
Definition specialist.h:79
#define normal_specialist_type_iterate(sp)
Definition specialist.h:89
#define super_specialist_type_iterate_end
Definition specialist.h:105
#define super_specialist_type_iterate(sp)
Definition specialist.h:99
#define DEFAULT_SPECIALIST
Definition specialist.h:43
#define normal_specialist_type_iterate_end
Definition specialist.h:95
int step
Definition specpq.h:92
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
Definition ai.h:50
Definition city.h:318
int surplus[O_LAST]
Definition city.h:353
bv_city_options city_options
Definition city.h:401
int style
Definition city.h:325
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
struct government * government_during_revolution
Definition game.h:94
int def
Definition counters.h:34
struct requirement_vector reqs
Definition improvement.h:58
int dist
Definition city.h:108
int dx
Definition city.h:108
int dy
Definition city.h:108
const char * id
Definition city.h:260
struct unit_order orders[MAX_LEN_ROUTE]
int granary_food_ini[MAX_GRANARY_INIS]
enum gold_upkeep_style gold_upkeep_style
int min_city_center_output[O_LAST]
struct city_list * cities
Definition player.h:281
struct unit_list * units
Definition player.h:282
struct player_economic economic
Definition player.h:284
const struct player * player
struct requirement_vector reqs
Definition specialist.h:38
int irrigation_food_incr
Definition terrain.h:114
int output[O_LAST]
Definition terrain.h:95
int mining_shield_incr
Definition terrain.h:117
int output[O_LAST]
Definition city.c:71
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
int city_slots
Definition unittype.h:559
int upkeep[O_LAST]
Definition unittype.h:545
Definition unit.h:140
int length
Definition unit.h:198
int upkeep[O_LAST]
Definition unit.h:150
bool occupied
Definition unit.h:222
int id
Definition unit.h:147
struct unit::@83 orders
bool vigilant
Definition unit.h:200
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:142
struct unit::@84::@86 client
enum unit_activity changed_from
Definition unit.h:171
void * ais[FREECIV_AI_MOD_LAST]
Definition unit.h:240
int homecity
Definition unit.h:148
const struct unit_type * utype
Definition unit.h:141
struct player * owner
Definition unit.h:145
enum universals_n kind
Definition fc_types.h:595
universals_u value
Definition fc_types.h:594
struct tile * ptile
Definition workertask.h:22
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define sz_strlcpy(dest, src)
Definition support.h:195
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
#define fc__fallthrough
Definition support.h:119
#define T_UNKNOWN
Definition terrain.h:62
#define terrain_has_flag(terr, flag)
Definition terrain.h:177
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:292
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:272
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:393
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:89
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:108
#define tile_worked(_tile)
Definition tile.h:119
#define tile_resource(_tile)
Definition tile.h:103
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:115
#define tile_owner(_tile)
Definition tile.h:97
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
@ TRI_ACTIVE
Definition traderoutes.h:30
#define trade_routes_iterate_end
#define trade_partners_iterate_end
#define trade_routes_iterate(c, proute)
#define trade_partners_iterate(c, p)
trade_route_type
Definition traderoutes.h:37
const struct unit_type * utype
Definition fc_types.h:536
const struct impr_type * building
Definition fc_types.h:529
struct unit_order * create_unit_orders(const struct civ_map *nmap, int length, const struct unit_order *orders)
Definition unit.c:2923
bool unit_being_aggressive(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:1576
bool is_field_unit(const struct unit *punit)
Definition unit.c:457
bool is_martial_law_unit(const struct unit *punit)
Definition unit.c:335
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1786
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1418
#define unit_tile(_pu)
Definition unit.h:408
#define unit_owner(_pu)
Definition unit.h:407
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2303
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2662
bool utype_can_do_act_when_ustate(const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
Definition unittype.c:980
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:114
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, const enum req_problem_type prob_type, bool consider_reg_impr_req)
Definition unittype.c:1995
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1554
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2130
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
Definition unittype.c:1042
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Definition unittype.c:206
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:865
#define unit_type_iterate_end
Definition unittype.h:872
#define U_NOT_OBSOLETED
Definition unittype.h:535
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT