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{
838 return FALSE;
839 }
840
841 if (city_has_building(pcity, pimprove)) {
842 return FALSE;
843 }
844
845 return are_reqs_active(&(const struct req_context) {
846 .player = city_owner(pcity),
847 .city = pcity,
848 .tile = pcity->tile,
849 },
850 nullptr,
851 &(pimprove->reqs), RPT_CERTAIN);
852}
853
854/**********************************************************************/
859 const struct impr_type *pimprove)
860{
862 return FALSE;
863 }
864 if (improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
865 return FALSE;
866 }
867
868 return TRUE;
869}
870
871/**********************************************************************/
876 const struct impr_type *pimprove)
877{
878 const struct req_context city_ctxt = {
880 .city = pcity,
881 .tile = city_tile(pcity),
882 };
883
884 /* Can the _player_ ever build this improvement? */
885 /* NOTE: It checks for obsoletion player-level. What aboult checking
886 * for it city-level? That may unlist from a worklist some things
887 * we'll be able to switch to after e.g. selling something else */
889 return FALSE;
890 }
891
892 /* Check for requirements that aren't met and that are unchanging (so
893 * they can never be met). */
895 if (is_req_preventing(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
896 return FALSE;
897 }
899
900 return TRUE;
901}
902
903/**********************************************************************/
908 const struct city *pcity,
909 const struct unit_type *punittype)
910{
912 return FALSE;
913 }
914
915 /* Check unit build requirements.
916 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
917 * Don't recheck those. Not only for optimization, but also not to override the
918 * special handling of tech requirements for barbarians */
919 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
921 &(const struct req_context) {
922 .player = city_owner(pcity),
923 .city = pcity,
924 .tile = city_tile(pcity),
925 .unittype = punittype,
926 },
927 nullptr,
928 &punittype->build_reqs, RPT_CERTAIN)) {
929 return FALSE;
930 }
931
932 /* You can't build naval units inland. */
935 pcity->tile)) {
936 return FALSE;
937 }
938
939 if (punittype->city_slots > 0
940 && city_unit_slots_available(pcity) < punittype->city_slots) {
941 return FALSE;
942 }
943
944 return TRUE;
945}
946
947/**********************************************************************/
952 const struct city *pcity,
953 const struct unit_type *punittype)
954{
956 return FALSE;
957 }
958
959 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
960 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
961 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
963 return FALSE;
964 }
965 }
966
967 return TRUE;
968}
969
970/**********************************************************************/
975 const struct city *pcity,
976 const struct unit_type *punittype)
977{
978 /* Can the _player_ ever build this unit? */
980 return FALSE;
981 }
982
983 /* Some units can be built only in certain cities -- for instance,
984 ships may be built only in cities adjacent to ocean. */
987 pcity->tile)) {
988 return FALSE;
989 }
990
991 return TRUE;
992}
993
994/**********************************************************************/
999 const struct city *pcity,
1000 const struct universal *target)
1001{
1002 switch (target->kind) {
1003 case VUT_UTYPE:
1005 case VUT_IMPROVEMENT:
1007 default:
1008 break;
1009 };
1010 return FALSE;
1011}
1012
1013/**********************************************************************/
1018 const struct city *pcity,
1019 const struct universal *target)
1020{
1021 switch (target->kind) {
1022 case VUT_UTYPE:
1023 return can_city_build_unit_now(nmap, pcity, target->value.utype);
1024 case VUT_IMPROVEMENT:
1026 default:
1027 break;
1028 };
1029 return FALSE;
1030}
1031
1032/**********************************************************************/
1036 const struct city *pcity,
1037 const struct universal *target)
1038{
1039 switch (target->kind) {
1040 case VUT_UTYPE:
1042 case VUT_IMPROVEMENT:
1044 default:
1045 break;
1046 };
1047 return FALSE;
1048}
1049
1050/**********************************************************************/
1054{
1056 int current;
1057
1058 current = 0;
1059 unit_list_iterate(pcity->units_supported, punit) {
1060 current += unit_type_get(punit)->city_slots;
1062
1063 return max - current;
1064}
1065
1066/**********************************************************************/
1071{
1072 return are_reqs_active(&(const struct req_context) {
1073 .player = city_owner(pcity),
1074 .city = pcity,
1075 },
1076 nullptr,
1078}
1079
1080/**********************************************************************/
1084{
1085 return !pcity->did_buy || pcity->shield_stock <= 0;
1086}
1087
1088/**********************************************************************/
1092{
1093 if (city_tile(pcity) == nullptr) {
1094 /* When a "dummy" city is created with no tile, then choosing a build
1095 * target could fail. This currently might happen during map editing.
1096 * FIXME: assumes the first unit is always "valid", so check for
1097 * obsolete units elsewhere. */
1098 pcity->production.kind = VUT_UTYPE;
1099 pcity->production.value.utype = utype_by_number(0);
1100 } else {
1102
1103 if (u) {
1104 pcity->production.kind = VUT_UTYPE;
1105 pcity->production.value.utype = u;
1106 } else {
1107 bool found = FALSE;
1108
1109 /* Just pick the first available item. */
1110 improvement_iterate(pimprove) {
1112 found = TRUE;
1113 pcity->production.kind = VUT_IMPROVEMENT;
1114 pcity->production.value.building = pimprove;
1115 break;
1116 }
1118
1119 if (!found) {
1122#ifndef FREECIV_NDEBUG
1123 /* Later than this, 'found' is only needed in an fc_assert() */
1124 found = TRUE;
1125#endif /* FREECIV_NDEBUG */
1126 pcity->production.kind = VUT_UTYPE;
1127 pcity->production.value.utype = punittype;
1128 }
1130 }
1131
1132 fc_assert_msg(found, "No production found for city %s!",
1134 }
1135 }
1136}
1137
1138/**********************************************************************/
1141const char *city_name_get(const struct city *pcity)
1142{
1143 return (pcity->name != nullptr) ? pcity->name : "City missing a name";
1144}
1145
1146/**********************************************************************/
1149#define POLLUTION_EFT_NEARMAX -95
1150const char *city_name_getx(const struct city *pcity)
1151{
1152 bool spacer = FALSE;
1153 static char em_city_name[MAX_LEN_CITYNAME + 7];
1154
1155 em_city_name[0] = '\0';
1156
1158 sz_strlcat(em_city_name, "ₓ"); /* ₓ🞪⁻⁰… (alternatives)*/
1159 }
1160
1162
1163 if (get_city_bonus(pcity, EFT_AIRLIFT) > 0) {
1164 if (!spacer) {
1166 spacer = TRUE;
1167 }
1168 sz_strlcat(em_city_name, "🛧"); /* 🛧🛪 (alternatives)*/
1169 }
1170
1172 if (!spacer) {
1174 spacer = TRUE;
1175 }
1176 sz_strlcat(em_city_name, "♺"); /* ♺♻♳ (alternatives)*/
1177 }
1178
1179 return em_city_name;
1180}
1181
1182/**********************************************************************/
1185void city_name_set(struct city *pcity, const char *new_name)
1186{
1187 if (pcity->name != nullptr) {
1188 free(pcity->name);
1189 }
1190
1191 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1192 pcity->name = fc_strdup(new_name);
1193 } else {
1194 log_warn(_("City name \"%s\" too long"), new_name);
1196 sz_strlcpy(pcity->name, new_name);
1197 }
1198}
1199
1200/**********************************************************************/
1204void city_size_add(struct city *pcity, int add)
1205{
1207
1208 fc_assert_ret(pcity != nullptr);
1210
1211 /* Client sets size to zero to start stacking citizens in */
1212 fc_assert_ret(size > -add || (!is_server() && size == add));
1213
1214 city_size_set(pcity, size + add);
1215}
1216
1217/**********************************************************************/
1221{
1222 fc_assert_ret(pcity != nullptr);
1223
1224 /* Set city size. */
1225 pcity->size = size;
1226}
1227
1228/**********************************************************************/
1231int city_population(const struct city *pcity)
1232{
1233 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1234 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1235}
1236
1237/**********************************************************************/
1242{
1243 int gold_needed = 0;
1244
1245 if (pcity == nullptr) {
1246 return 0;
1247 }
1248
1249 city_built_iterate(pcity, pimprove) {
1250 gold_needed += city_improvement_upkeep(pcity, pimprove);
1252
1254
1255 return MAX(gold_needed, 0);
1256}
1257
1258/**********************************************************************/
1263{
1264 int gold_needed = 0;
1265
1266 if (pcity == nullptr || pcity->units_supported == nullptr) {
1267 return 0;
1268 }
1269
1270 unit_list_iterate(pcity->units_supported, punit) {
1271 gold_needed += punit->upkeep[O_GOLD];
1273
1274 return gold_needed;
1275}
1276
1277/**********************************************************************/
1280bool city_has_building(const struct city *pcity,
1281 const struct impr_type *pimprove)
1282{
1283 if (pimprove == nullptr) {
1284 /* Callers should ensure that any external data is tested with
1285 * valid_improvement_by_number() */
1286 return FALSE;
1287 }
1288
1289 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1290}
1291
1292/**********************************************************************/
1297 const struct impr_type *b)
1298{
1299 int upkeep;
1300
1301 if (b == nullptr) {
1302 return 0;
1303 }
1304 if (!is_building_sellable(b)) {
1305 return 0;
1306 }
1307
1308 upkeep = b->upkeep;
1310 return 0;
1311 }
1312
1313 return upkeep;
1314}
1315
1316/**********************************************************************/
1324int city_tile_output(const struct city *pcity, const struct tile *ptile,
1326{
1327 int prod;
1328 const struct req_context city_ctxt = {
1329 .player = pcity ? city_owner(pcity) : nullptr,
1330 .city = pcity,
1331 .tile = ptile,
1332 };
1333 struct terrain *pterrain = tile_terrain(ptile);
1334 const struct output_type *output = &output_types[otype];
1335
1336 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1337
1338 if (T_UNKNOWN == pterrain) {
1339 /* Special case for the client. The server doesn't allow unknown tiles
1340 * to be worked but we don't necessarily know what player is involved. */
1341 return 0;
1342 }
1343
1344 prod = pterrain->output[otype];
1345 if (tile_resource_is_valid(ptile)) {
1346 prod += tile_resource(ptile)->data.resource->output[otype];
1347 }
1348
1349 switch (otype) {
1350 case O_SHIELD:
1351 if (pterrain->mining_shield_incr != 0) {
1352 prod += pterrain->mining_shield_incr
1354 / 100;
1355 }
1356 break;
1357 case O_FOOD:
1358 if (pterrain->irrigation_food_incr != 0) {
1359 prod += pterrain->irrigation_food_incr
1360 * get_target_bonus_effects(nullptr, &city_ctxt, nullptr,
1361 EFT_IRRIGATION_PCT) / 100;
1362 }
1363 break;
1364 case O_TRADE:
1365 case O_GOLD:
1366 case O_SCIENCE:
1367 case O_LUXURY:
1368 case O_LAST:
1369 break;
1370 }
1371
1372 prod += tile_roads_output_incr(ptile, otype);
1373 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1374
1375 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1376 if (prod > 0) {
1377 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1379
1380 if (prod >= game.info.granularity) {
1381 prod += get_tile_output_bonus(pcity, ptile, output,
1383
1384 if (is_celebrating) {
1385 prod += get_tile_output_bonus(pcity, ptile, output,
1387 }
1388 }
1389
1390 prod += (prod
1391 * get_tile_output_bonus(pcity, ptile, output,
1393 / 100;
1394 if (penalty_limit > 0 && prod > penalty_limit) {
1395 if (prod <= game.info.granularity) {
1396 prod = 0;
1397 } else {
1398 prod -= game.info.granularity;
1399 }
1400 }
1401 }
1402
1403 prod -= (prod
1404 * get_tile_output_bonus(pcity, ptile, output,
1406 / 100;
1407
1408 if (pcity != nullptr && is_city_center(pcity, ptile)) {
1409 prod = MAX(prod, game.info.min_city_center_output[otype]);
1410 }
1411
1412 return prod;
1413}
1414
1415/**********************************************************************/
1425int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1427{
1429}
1430
1431/**********************************************************************/
1443 const struct city *pcity,
1444 const struct tile *ptile)
1445{
1446 struct player *powner = city_owner(pcity);
1448 struct player *towner;
1449
1450 if (ptile == nullptr) {
1451 return FALSE;
1452 }
1453
1455 return FALSE;
1456 }
1457
1458 if (restriction != nullptr
1459 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1460 return FALSE;
1461 }
1462
1463 towner = tile_owner(ptile);
1464 if (towner != nullptr && towner != powner
1465 && !gives_shared_tiles(towner, powner)) {
1466 return FALSE;
1467 }
1468 /* TODO: civ3-like option for borders */
1469
1470 if (tile_worked(ptile) != nullptr && tile_worked(ptile) != pcity) {
1471 return FALSE;
1472 }
1473
1474 if (powner == restriction
1475 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1476 return FALSE;
1477 }
1478
1479 if (!is_free_worked(pcity, ptile)
1480 && unit_occupies_tile(ptile, powner) != nullptr) {
1481 return FALSE;
1482 }
1483
1484 if (get_city_tile_output_bonus(pcity, ptile, nullptr, EFT_TILE_WORKABLE) <= 0) {
1485 return FALSE;
1486 }
1487
1488 return TRUE;
1489}
1490
1491/**********************************************************************/
1497bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1498{
1500}
1501
1502/**********************************************************************/
1507 const struct tile *ptile)
1508{
1509 /* citymindist minimum is 1, meaning adjacent is okay */
1510 int citymindist = game.info.citymindist;
1511
1512 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1513 if (tile_city(ptile1)) {
1514 return TRUE;
1515 }
1517
1518 return FALSE;
1519}
1520
1521/**********************************************************************/
1529 const struct tile *ptile,
1530 const struct unit *punit,
1531 bool hut_test)
1532{
1533 if (!city_can_be_built_tile_only(nmap, ptile)) {
1534 return FALSE;
1535 }
1536
1537 if (punit == nullptr) {
1538 /* The remaining checks tests if punit can found a city here */
1539 return TRUE;
1540 }
1541
1542 if (hut_test) {
1543 struct player *towner;
1544
1545 /* Huts can be found only from native tiles, owned by the unit owner.
1546 * Unlike actual city building, this behavior is not affected
1547 * by the ruleset. */
1548 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1549 return FALSE;
1550 }
1551
1552 towner = tile_owner(ptile);
1553
1554 if (towner == nullptr || towner == unit_owner(punit)) {
1555 return TRUE;
1556 }
1557
1558 return FALSE;
1559 }
1560
1563 /* This action can't be done by this unit type at all. */
1564 continue;
1565 }
1566
1567 /* Non native tile detection */
1568 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1569 /* The ruleset may allow founding cities on non native terrain. */
1572 /* Many rulesets allow land units to build land cities and sea units
1573 * to build ocean cities. Air units can build cities anywhere. */
1574 continue;
1575 }
1576
1577 /* Foreign tile detection. */
1578 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1579 /* The ruleset may allow founding cities on foreign terrain. */
1581 paction->id,
1582 DRO_FOREIGN, TRUE)) {
1583 /* Cannot steal borders by settling. This has to be settled by
1584 * force of arms. */
1585 continue;
1586 }
1587
1588 return TRUE;
1590
1591 return FALSE;
1592}
1593
1594/**********************************************************************/
1602 const struct tile *ptile)
1603{
1605 /* No cities on this terrain. */
1606 return FALSE;
1607 }
1608
1610 return FALSE;
1611 }
1612
1613 return TRUE;
1614}
1615
1616/**********************************************************************/
1620bool is_capital(const struct city *pcity)
1621{
1622 return pcity->capital != CAPITAL_NOT;
1623}
1624
1625/**********************************************************************/
1628bool is_gov_center(const struct city *pcity)
1629{
1630 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1631}
1632
1633/**********************************************************************/
1638 const struct unit_type *attacker)
1639{
1640 if (!attacker) {
1641 /* Any defense building will do */
1643 }
1644
1645 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1646 nullptr, EFT_DEFEND_BONUS) > 0;
1647}
1648
1649/**********************************************************************/
1655bool city_happy(const struct city *pcity)
1656{
1658 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1659 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1660 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1661}
1662
1663/**********************************************************************/
1667bool city_unhappy(const struct city *pcity)
1668{
1669 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1671 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1672}
1673
1674/**********************************************************************/
1679{
1680 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1681}
1682
1683/**********************************************************************/
1686bool city_celebrating(const struct city *pcity)
1687{
1689}
1690
1691/**********************************************************************/
1694bool city_rapture_grow(const struct city *pcity)
1695{
1696 /* .rapture is checked instead of city_celebrating() because this
1697 function is called after .was_happy was updated. */
1698 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1699 && (pcity->rapture % game.info.rapturedelay) == 0
1701}
1702
1703/**********************************************************************/
1706bool city_is_occupied(const struct city *pcity)
1707{
1708 if (is_server()) {
1709 /* The server sees the units inside the city. */
1710 return (unit_list_size(city_tile(pcity)->units) > 0);
1711 } else {
1712 /* The client gets the occupied property from the server. */
1713 return pcity->client.occupied;
1714 }
1715}
1716
1717/**********************************************************************/
1720struct city *city_list_find_number(struct city_list *This, int id)
1721{
1722 if (id != 0) {
1724 if (pcity->id == id) {
1725 return pcity;
1726 }
1728 }
1729
1730 return nullptr;
1731}
1732
1733/**********************************************************************/
1736struct city *city_list_find_name(struct city_list *This, const char *name)
1737{
1739 if (fc_strcasecmp(name, pcity->name) == 0) {
1740 return pcity;
1741 }
1743
1744 return nullptr;
1745}
1746
1747/**********************************************************************/
1752int city_name_compare(const void *p1, const void *p2)
1753{
1754 return fc_strcasecmp((*(const struct city **) p1)->name,
1755 (*(const struct city **) p2)->name);
1756}
1757
1758/**********************************************************************/
1763{
1764 int i;
1765
1766 for (i = 0; i < game.control.num_city_styles; i++) {
1767 if (0 == strcmp(city_style_name_translation(i), s)) {
1768 return i;
1769 }
1770 }
1771
1772 return -1;
1773}
1774
1775/**********************************************************************/
1779int city_style_by_rule_name(const char *s)
1780{
1781 const char *qs = Qn_(s);
1782 int i;
1783
1784 for (i = 0; i < game.control.num_city_styles; i++) {
1785 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1786 return i;
1787 }
1788 }
1789
1790 return -1;
1791}
1792
1793/**********************************************************************/
1798{
1800}
1801
1802/**********************************************************************/
1806const char *city_style_rule_name(const int style)
1807{
1809}
1810
1811/* Cache of what city production caravan shields are allowed to help. */
1814
1815/**********************************************************************/
1820{
1821 struct requirement prod_as_req;
1822
1823#define log_ca_s_init log_debug
1824
1825 /* Remove old data. */
1828
1829 /* Common for all production kinds. */
1831 prod_as_req.survives = FALSE;
1832 prod_as_req.present = TRUE;
1833
1834 /* Check improvements */
1835 prod_as_req.source.kind = VUT_IMPROVEMENT;
1836
1838 /* Check this improvement. */
1839 prod_as_req.source.value.building = itype;
1840
1843 enabler) {
1845 &(enabler->target_reqs))
1846 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1847 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1848 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1849 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1850 /* This improvement kind can receive caravan shields. */
1851
1853
1854 /* Move on to the next improvement */
1855 break;
1856 }
1858
1859 log_ca_s_init("Help Wonder: %s for %s",
1861 ? "possible" : "impossible"),
1864
1865 /* Check units. */
1866 prod_as_req.source.kind = VUT_UTYPE;
1867
1869 /* Check this utype. */
1870 prod_as_req.source.value.utype = putype;
1871
1874 enabler) {
1876 &(enabler->target_reqs))
1877 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1878 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1879 /* This unit type kind can receive caravan shields. */
1880
1882
1883 /* Move on to the next unit type */
1884 break;
1885 }
1887
1888 log_ca_s_init("Help Wonder: %s for %s",
1890 ? "possible" : "impossible"),
1893
1894#undef log_ca_s_init
1895}
1896
1897/**********************************************************************/
1902{
1903 switch (tgt->kind) {
1904 case VUT_IMPROVEMENT:
1907 case VUT_UTYPE:
1909 utype_index(tgt->value.utype));
1910 default:
1912 return FALSE;
1913 };
1914}
1915
1916/**********************************************************************/
1928 const struct universal *target)
1929{
1934
1935 switch (pcity->changed_from.kind) {
1936 case VUT_IMPROVEMENT:
1937 if (is_wonder(pcity->changed_from.value.building)) {
1939 } else {
1941 }
1942 break;
1943 case VUT_UTYPE:
1945 break;
1946 default:
1948 break;
1949 };
1950
1951 switch (target->kind) {
1952 case VUT_IMPROVEMENT:
1953 if (is_wonder(target->value.building)) {
1955 } else {
1957 }
1958 break;
1959 case VUT_UTYPE:
1961 break;
1962 default:
1964 break;
1965 };
1966
1967 /* Changing production is penalized under certain circumstances. */
1968 if (orig_class == new_class
1969 || orig_class == PCT_LAST) {
1970 /* There's never a penalty for building something of the same class. */
1971 unpenalized_shields = pcity->before_change_shields;
1972 } else if (city_built_last_turn(pcity)) {
1973 /* Surplus shields from the previous production won't be penalized if
1974 * you change production on the very next turn. But you can only use
1975 * up to the city's surplus amount of shields in this way. */
1976 unpenalized_shields = MIN(pcity->last_turns_shield_surplus,
1977 pcity->before_change_shields);
1978 penalized_shields = pcity->before_change_shields - unpenalized_shields;
1979 } else {
1980 /* Penalize 50% of the production. */
1981 penalized_shields = pcity->before_change_shields;
1982 }
1983
1984 /* Do not put penalty on these. It shouldn't matter whether you disband unit
1985 before or after changing production...*/
1986 unpenalized_shields += pcity->disbanded_shields;
1987
1988 /* Caravan shields are penalized (just as if you disbanded the caravan)
1989 * if you're not building a wonder. */
1991 unpenalized_shields += pcity->caravan_shields;
1992 } else {
1993 penalized_shields += pcity->caravan_shields;
1994 }
1995
1998
2000}
2001
2002/**********************************************************************/
2007 const struct universal *target,
2009{
2010 int city_shield_surplus = pcity->surplus[O_SHIELD];
2013 int cost = universal_build_shield_cost(pcity, target);
2014
2015 if (target->kind == VUT_IMPROVEMENT
2016 && is_great_wonder(target->value.building)
2018 return FC_INFINITY;
2019 }
2020
2022 return 1;
2023 } else if (city_shield_surplus > 0) {
2024 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
2025 } else {
2026 return FC_INFINITY;
2027 }
2028}
2029
2030/**********************************************************************/
2038{
2039 if (pcity->surplus[O_FOOD] > 0) {
2040 return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
2041 pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
2042 } else if (pcity->surplus[O_FOOD] < 0) {
2043 /* Turns before famine loss */
2044 return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
2045 } else {
2046 return FC_INFINITY;
2047 }
2048}
2049
2050/**********************************************************************/
2053bool city_can_grow_to(const struct city *pcity, int pop_size)
2054{
2057}
2058
2059/**********************************************************************/
2062struct city *tile_enemy_city(const struct tile *ptile,
2063 const struct player *pplayer)
2064{
2065 struct city *pcity = tile_city(ptile);
2066
2067 if (pcity != nullptr && pplayers_at_war(pplayer, city_owner(pcity))) {
2068 return pcity;
2069 }
2070
2071 return nullptr;
2072}
2073
2074/**********************************************************************/
2077struct city *tile_allied_city(const struct tile *ptile,
2078 const struct player *pplayer)
2079{
2080 struct city *pcity = tile_city(ptile);
2081
2082 if (pcity != nullptr && pplayers_allied(pplayer, city_owner(pcity))) {
2083 return pcity;
2084 }
2085
2086 return nullptr;
2087}
2088
2089/**********************************************************************/
2092struct city *tile_non_attack_city(const struct tile *ptile,
2093 const struct player *pplayer)
2094{
2095 struct city *pcity = tile_city(ptile);
2096
2097 if (pcity != nullptr && pplayers_non_attack(pplayer, city_owner(pcity))) {
2098 return pcity;
2099 }
2100
2101 return nullptr;
2102}
2103
2104/**********************************************************************/
2107struct city *tile_non_allied_city(const struct tile *ptile,
2108 const struct player *pplayer)
2109{
2110 struct city *pcity = tile_city(ptile);
2111
2112 if (pcity != nullptr && !pplayers_allied(pplayer, city_owner(pcity))) {
2113 return pcity;
2114 }
2115
2116 return nullptr;
2117}
2118
2119/**********************************************************************/
2123 const struct unit *punit,
2124 int distance)
2125{
2127 distance);
2128}
2129
2130/**********************************************************************/
2134 const struct player *owner,
2135 const struct tile *ptile,
2136 int distance)
2137{
2138 square_iterate(nmap, ptile, distance, ptile1) {
2139 struct city *pcity = tile_city(ptile1);
2140
2142 return TRUE;
2143 }
2145
2146 return FALSE;
2147}
2148
2149/**********************************************************************/
2154 const struct tile *ptile,
2155 bool may_be_on_center)
2156{
2158 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2159 if (tile_city(ptile1)) {
2160 return TRUE;
2161 }
2162 }
2164
2165 return FALSE;
2166}
2167
2168/**********************************************************************/
2173int city_granary_size(int city_size)
2174{
2177 int base_value;
2178
2179 /* If the city has no citizens, there is no granary. */
2180 if (city_size == 0) {
2181 return 0;
2182 }
2183
2184 /* Granary sizes for the first food_inis citizens are given directly.
2185 * After that we increase the granary size by food_inc per citizen. */
2186 if (city_size > food_inis) {
2187 base_value = game.info.granary_food_ini[food_inis - 1];
2188 base_value += food_inc * (city_size - food_inis);
2189 } else {
2190 base_value = game.info.granary_food_ini[city_size - 1];
2191 }
2192
2193 return MAX(base_value * game.info.foodbox / 100, 1);
2194}
2195
2196/**********************************************************************/
2201static int player_base_citizen_happiness(const struct player *pplayer)
2202{
2203 int cities = city_list_size(pplayer->cities);
2204 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2207
2208 if (basis + step <= 0) {
2209 /* Value of zero means effect is inactive */
2210 return content;
2211 }
2212
2213 if (cities > basis) {
2214 content--;
2215 if (step != 0) {
2216 /* the first penalty is at (basis + 1) cities;
2217 the next is at (basis + step + 1), _not_ (basis + step) */
2218 content -= (cities - basis - 1) / step;
2219 }
2220 }
2221 return content;
2222}
2223
2224/**********************************************************************/
2228{
2229 int content = player_base_citizen_happiness(pplayer);
2230
2231 return CLIP(0, content, MAX_CITY_SIZE);
2232}
2233
2234/**********************************************************************/
2238{
2239 if (!game.info.angrycitizen) {
2240 return 0;
2241 } else {
2242 /* Create angry citizens only if we have a negative number of possible
2243 * content citizens. This can happen when empires grow really big. */
2244 int content = player_base_citizen_happiness(pplayer);
2245
2246 return CLIP(0, -content, MAX_CITY_SIZE);
2247 }
2248}
2249
2250/**********************************************************************/
2254{
2255 struct output_type *output = &output_types[otype];
2256 int bonus1 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2258 int bonus2 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2260
2261 return MAX(bonus1 * bonus2 / 100, 0);
2262}
2263
2264/**********************************************************************/
2269{
2270 int tithes_bonus = 0;
2271
2273 return 0;
2274 }
2275
2278
2279 return tithes_bonus;
2280}
2281
2282/**********************************************************************/
2286void add_tax_income(const struct player *pplayer, int trade, int *output)
2287{
2288 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2289 unsigned rates[3];
2290 int result[3];
2291
2292 if (game.info.changable_tax) {
2293 rates[SCIENCE] = pplayer->economic.science;
2294 rates[LUXURY] = pplayer->economic.luxury;
2295 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2296 } else {
2300 }
2301
2302 /* ANARCHY */
2304 rates[SCIENCE] = 0;
2305 rates[LUXURY] = 100;
2306 rates[TAX] = 0;
2307 }
2308
2309 distribute(trade, 3, rates, result);
2310
2311 output[O_SCIENCE] += result[SCIENCE];
2312 output[O_GOLD] += result[TAX];
2313 output[O_LUXURY] += result[LUXURY];
2314}
2315
2316/**********************************************************************/
2321{
2322 return pcity->turn_last_built + 1 >= game.info.turn;
2323}
2324
2325/**********************************************************************/
2328static const struct city *nearest_gov_center(const struct city *pcity,
2329 int *min_dist)
2330{
2331 const struct city *gov_center = nullptr;
2332
2334
2335 /* Check the special case that city itself is gov center
2336 * before expensive iteration through all cities. */
2337 if (is_gov_center(pcity)) {
2338 *min_dist = 0;
2339 return pcity;
2340 } else {
2342 /* Do not recheck current city */
2343 if (gc != pcity && is_gov_center(gc)) {
2344 int dist = real_map_distance(gc->tile, pcity->tile);
2345
2346 if (dist < *min_dist) {
2347 gov_center = gc;
2348 *min_dist = dist;
2349 }
2350 }
2352 }
2353
2354 return gov_center;
2355}
2356
2357/**********************************************************************/
2365static inline void get_worked_tile_output(const struct civ_map *nmap,
2366 const struct city *pcity,
2367 int *output, bool *workers_map)
2368{
2369 bool is_worked;
2370#ifdef CITY_DEBUGGING
2372#endif
2373 struct tile *pcenter = city_tile(pcity);
2374
2375 memset(output, 0, O_LAST * sizeof(*output));
2376
2379 if (workers_map == nullptr) {
2380 struct city *pwork = tile_worked(ptile);
2381
2382 is_worked = (pwork != nullptr && pwork == pcity);
2383 } else {
2384 is_worked = workers_map[city_tile_index];
2385 }
2386
2387 if (is_worked) {
2389#ifdef CITY_DEBUGGING
2390 /* This assertion never fails, but it's so slow that we disable
2391 * it by default. */
2393 == city_tile_output(pcity, ptile, is_celebrating, o));
2394#endif /* CITY_DEBUGGING */
2397 }
2399}
2400
2401/**********************************************************************/
2405void add_specialist_output(const struct city *pcity, int *output)
2406{
2408 int count = pcity->specialists[sp];
2409
2412
2413 output[stat_index] += count * amount;
2416}
2417
2418/**********************************************************************/
2427static inline void set_city_bonuses(struct city *pcity)
2428{
2431 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2432 &output_types[o],
2434 /* Total bonus cannot be negative, as that could lead to unresolvable
2435 * negative balance. */
2436 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2438}
2439
2440/**********************************************************************/
2450static inline void city_tile_cache_update(const struct civ_map *nmap,
2451 struct city *pcity)
2452{
2454 int radius_sq = city_map_radius_sq_get(pcity);
2455
2456 /* Initialize tile_cache if needed */
2457 if (pcity->tile_cache == nullptr || pcity->tile_cache_radius_sq == -1
2458 || pcity->tile_cache_radius_sq != radius_sq) {
2459 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2460 city_map_tiles(radius_sq)
2461 * sizeof(*(pcity->tile_cache)));
2462 pcity->tile_cache_radius_sq = radius_sq;
2463 }
2464
2465 /* Any unreal tiles are skipped - these values should have been memset
2466 * to 0 when the city was created. */
2467 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2469 (pcity->tile_cache[city_tile_index]).output[o]
2473}
2474
2475/**********************************************************************/
2479static inline int city_tile_cache_get_output(const struct city *pcity,
2480 int city_tile_index,
2481 enum output_type_id o)
2482{
2483 fc_assert_ret_val(pcity->tile_cache_radius_sq
2486
2487 return (pcity->tile_cache[city_tile_index]).output[o];
2488}
2489
2490/**********************************************************************/
2493static void set_surpluses(struct city *pcity)
2494{
2496 int surplus = pcity->prod[o] - pcity->usage[o];
2497
2498 /* Add 'surplus' waste to 'usage'. */
2499 if (surplus > 0) {
2500 struct output_type *output = get_output_type(o);
2504
2505 if (waste_by_rel_dist > 0) {
2506 int min_dist;
2507 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2508
2509 if (gov_center == nullptr) {
2510 /* No gov center - no income */
2511 waste_level = 100;
2512 } else {
2513 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2515 }
2516 }
2517
2518 if (waste_level > 0) {
2519 if (waste_level < 100) {
2520 pcity->usage[o] += (surplus * waste_level / 100);
2521 } else {
2522 pcity->usage[o] = pcity->prod[o];
2523 }
2524 }
2525 }
2526
2527 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2529}
2530
2531/**********************************************************************/
2534static void happy_copy(struct city *pcity, enum citizen_feeling i)
2535{
2536 int c = 0;
2537
2538 for (; c < CITIZEN_LAST; c++) {
2539 pcity->feel[c][i] = pcity->feel[c][i - 1];
2540 }
2541}
2542
2543/**********************************************************************/
2546static void citizen_base_mood(struct city *pcity)
2547{
2548 struct player *pplayer = city_owner(pcity);
2549 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2550 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2551 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2552 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2555
2556 /* This is the number of citizens that may start out content, depending
2557 * on empire size and game's city unhappysize. This may be bigger than
2558 * the size of the city, since this is a potential. */
2560 /* Similarly, this is the potential number of angry citizens. */
2562
2563 /* Create content citizens. Take specialists from their ranks. */
2564 *content = MAX(0, MIN(size, base_content) - spes);
2565
2566 /* Create angry citizens. Specialists never become angry. */
2567 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2568 *angry = MIN(base_angry, size - spes);
2569
2570 /* Create unhappy citizens. In the beginning, all who are not content,
2571 * specialists or angry are unhappy. This is changed by luxuries and
2572 * buildings later. */
2573 *unhappy = (size - spes - *content - *angry);
2574
2575 /* No one is born happy. */
2576 *happy = 0;
2577}
2578
2579/**********************************************************************/
2585static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2586{
2587 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2588 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2589 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2590 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2591
2592 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2593 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2594 (*angry)--;
2595 (*unhappy)++;
2597 }
2598 while (*luxuries >= game.info.happy_cost && *content > 0) {
2599 /* Upgrade content to happy: costs HAPPY_COST each. */
2600 (*content)--;
2601 (*happy)++;
2603 }
2604 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2605 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2606 * double the cost. */
2607 (*unhappy)--;
2608 (*happy)++;
2609 *luxuries -= 2 * game.info.happy_cost;
2610 }
2611 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2612 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2613 (*unhappy)--;
2614 (*content)++;
2616 }
2617}
2618
2619/**********************************************************************/
2622static inline void citizen_happy_luxury(struct city *pcity)
2623{
2624 int x = pcity->prod[O_LUXURY];
2625
2627}
2628
2629/**********************************************************************/
2632static inline void citizen_content_buildings(struct city *pcity)
2633{
2634 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2635 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2636 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2638
2639 /* make people content (but not happy):
2640 get rid of angry first, then make unhappy content. */
2641 while (faces > 0 && *angry > 0) {
2642 (*angry)--;
2643 (*unhappy)++;
2644 faces--;
2645 }
2646 while (faces > 0 && *unhappy > 0) {
2647 (*unhappy)--;
2648 (*content)++;
2649 faces--;
2650 }
2651}
2652
2653/**********************************************************************/
2656static inline void citizen_happiness_nationality(struct city *pcity)
2657{
2661
2664
2665 if (pct > 0) {
2666 int enemies = 0;
2667 int unhappy_inc;
2668 struct player *owner = city_owner(pcity);
2669
2670 citizens_foreign_iterate(pcity, pslot, nationality) {
2672 enemies += nationality;
2673 }
2675
2676 unhappy_inc = enemies * pct / 100;
2677
2678 /* First make content => unhappy, then happy => unhappy,
2679 * then happy => content. No-one becomes angry. */
2680 while (unhappy_inc > 0 && *content > 0) {
2681 (*content)--;
2682 (*unhappy)++;
2683 unhappy_inc--;
2684 }
2685 while (unhappy_inc > 1 && *happy > 0) {
2686 (*happy)--;
2687 (*unhappy)++;
2688 unhappy_inc -= 2;
2689 }
2690 while (unhappy_inc > 0 && *happy > 0) {
2691 (*happy)--;
2692 (*content)++;
2693 unhappy_inc--;
2694 }
2695 }
2696 }
2697}
2698
2699/**********************************************************************/
2705static inline void citizen_happy_units(struct city *pcity)
2706{
2707 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2708 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2709 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2710 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2711 citizens amt = pcity->martial_law;
2712
2713 /* Pacify discontent citizens through martial law. First convert
2714 * angry => unhappy, then unhappy => content. */
2715 while (amt > 0 && *angry > 0) {
2716 (*angry)--;
2717 (*unhappy)++;
2718 amt--;
2719 }
2720 while (amt > 0 && *unhappy > 0) {
2721 (*unhappy)--;
2722 (*content)++;
2723 amt--;
2724 }
2725
2726 /* Now make citizens unhappier because of military units away from home.
2727 * First make content => unhappy, then happy => unhappy,
2728 * then happy => content. */
2729 amt = pcity->unit_happy_upkeep;
2730 while (amt > 0 && *content > 0) {
2731 (*content)--;
2732 (*unhappy)++;
2733 amt--;
2734 }
2735 while (amt > 1 && *happy > 0) {
2736 (*happy)--;
2737 (*unhappy)++;
2738 amt -= 2;
2739 }
2740 while (amt > 0 && *happy > 0) {
2741 (*happy)--;
2742 (*content)++;
2743 amt--;
2744 }
2745 /* Any remaining unhappiness is lost since angry citizens aren't created
2746 * here. */
2747 /* FIXME: Why not? - Per */
2748}
2749
2750/**********************************************************************/
2753static inline void citizen_happy_wonders(struct city *pcity)
2754{
2755 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2756 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2757 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2758 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2759 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2760
2761 /* First create happy citizens from content, then from unhappy
2762 * citizens; we cannot help angry citizens here. */
2763 while (bonus > 0 && *content > 0) {
2764 (*content)--;
2765 (*happy)++;
2766 bonus--;
2767 }
2768 while (bonus > 1 && *unhappy > 0) {
2769 (*unhappy)--;
2770 (*happy)++;
2771 bonus -= 2;
2772 }
2773 /* The rest falls through and lets unhappy people become content. */
2774
2776 *content += *unhappy + *angry;
2777 *unhappy = 0;
2778 *angry = 0;
2779 return;
2780 }
2781
2783
2784 /* get rid of angry first, then make unhappy content */
2785 while (bonus > 0 && *angry > 0) {
2786 (*angry)--;
2787 (*unhappy)++;
2788 bonus--;
2789 }
2790 while (bonus > 0 && *unhappy > 0) {
2791 (*unhappy)--;
2792 (*content)++;
2793 bonus--;
2794 }
2795}
2796
2797/**********************************************************************/
2801static inline void unhappy_city_check(struct city *pcity)
2802{
2803 if (city_unhappy(pcity)) {
2805 switch (output_types[o].unhappy_penalty) {
2807 pcity->unhappy_penalty[o] = 0;
2808 break;
2810 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2811 break;
2813 pcity->unhappy_penalty[o] = pcity->prod[o];
2814 break;
2815 }
2816
2817 pcity->prod[o] -= pcity->unhappy_penalty[o];
2819 } else {
2820 memset(pcity->unhappy_penalty, 0,
2821 O_LAST * sizeof(*pcity->unhappy_penalty));
2822 }
2823}
2824
2825/**********************************************************************/
2829 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2830{
2831 int prod, pop, mod;
2832
2833 /* Add one one pollution per shield, multipled by the bonus. */
2835 prod = shield_total * MAX(prod, 0) / 100;
2836
2837 /* Add one pollution per citizen for baseline combined bonus (100%). */
2840 / 100;
2841 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2842
2843 /* Then there is base pollution (usually a negative number). */
2844 mod = game.info.base_pollution;
2845
2846 if (pollu_prod) {
2847 *pollu_prod = prod;
2848 }
2849 if (pollu_pop) {
2850 *pollu_pop = pop;
2851 }
2852 if (pollu_mod) {
2853 *pollu_mod = mod;
2854 }
2855 return MAX(prod + pop + mod, 0);
2856}
2857
2858/**********************************************************************/
2862int city_pollution(const struct city *pcity, int shield_total)
2863{
2865 nullptr, nullptr, nullptr);
2866}
2867
2868/**********************************************************************/
2875static int get_trade_illness(const struct city *pcity)
2876{
2877 float illness_trade = 0.0;
2878
2880 if (trade_city->turn_plague != -1
2881 && game.info.turn - trade_city->turn_plague < 5) {
2882 illness_trade += (float)game.info.illness_trade_infection
2883 * sqrt(1.0 * city_size_get(pcity)
2884 * city_size_get(trade_city)) / 100.0;
2885 }
2887
2888 return (int)illness_trade;
2889}
2890
2891/**********************************************************************/
2895static int get_city_health(const struct city *pcity)
2896{
2898}
2899
2900/**********************************************************************/
2912int city_illness_calc(const struct city *pcity, int *ill_base,
2913 int *ill_size, int *ill_trade, int *ill_pollution)
2914{
2915 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2917
2918 if (game.info.illness_on
2920 /* offset the city size by game.info.illness_min_size */
2922
2923 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2924 * 10.0 * game.info.illness_base_factor);
2925 if (is_server()) {
2926 /* On the server we recalculate the illness due to trade as we have
2927 * all the information */
2928 illness_trade = get_trade_illness(pcity);
2929 } else {
2930 /* On the client we have to rely on the value saved within the city
2931 * struct */
2932 illness_trade = pcity->illness_trade;
2933 }
2934
2935 illness_pollution = pcity->pollution
2937 }
2938
2939 illness_base = illness_size + illness_trade + illness_pollution;
2941
2942 /* returning other data */
2943 if (ill_size) {
2945 }
2946
2947 if (ill_trade) {
2948 *ill_trade = illness_trade;
2949 }
2950
2951 if (ill_pollution) {
2953 }
2954
2955 if (ill_base) {
2957 }
2958
2959 return CLIP(0, illness_base * illness_percent / 100 , 999);
2960}
2961
2962/**********************************************************************/
2966{
2967 /* Correctly handles special case turn_plague == -1 (never) */
2968 return (pcity->turn_plague == game.info.turn);
2969}
2970
2971/**********************************************************************/
2974int city_build_slots(const struct city *pcity)
2975{
2977}
2978
2979/**********************************************************************/
2984int city_airlift_max(const struct city *pcity)
2985{
2987}
2988
2989/**********************************************************************/
2995inline void set_city_production(struct city *pcity)
2996{
2997 int trade;
2998
2999 /* Calculate city production!
3000 *
3001 * This is a rather complicated process if we allow rules to become
3002 * more generalized. We can assume that there are no recursive dependency
3003 * loops, but there are some dependencies that do not follow strict
3004 * ordering. For instance corruption must be calculated before
3005 * trade taxes can be counted up, which must occur before the science bonus
3006 * is added on. But the calculation of corruption must include the
3007 * trade bonus. To do this without excessive special casing means that in
3008 * this case the bonuses are multiplied on twice (but only saved the second
3009 * time).
3010 */
3011
3013 pcity->prod[o] = pcity->citizen_base[o];
3015
3016 /* Add on special extra incomes: trade routes and tithes. */
3018 struct city *tcity = game_city_by_number(proute->partner);
3019 bool can_trade;
3020
3021 /* Partner city may have not yet been sent to the client, or
3022 * there's just a placeholder city with a placeholder owner
3023 * created for some tile->worked. */
3024 if (!is_server()
3025 && (tcity == nullptr
3026 || city_owner(tcity)->slot == nullptr)) {
3027 continue;
3028 }
3029
3030 fc_assert_action(tcity != nullptr, continue);
3031
3033
3034 if (!can_trade) {
3037
3038 if (settings->cancelling == TRI_ACTIVE) {
3039 can_trade = TRUE;
3040 }
3041 }
3042
3043 if (can_trade) {
3044 int value;
3045
3046 value =
3048 proute->value = trade_from_route(pcity, proute, value);
3049 pcity->prod[O_TRADE] += proute->value
3050 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3051 } else {
3052 proute->value = 0;
3053 }
3056
3057 /* Account for waste. Note that waste is calculated before tax income is
3058 * calculated, so if you had "science waste" it would not include taxed
3059 * science. However waste is calculated after the bonuses are multiplied
3060 * on, so shield waste will include shield bonuses. */
3062 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3063
3064 prod = MAX(prod, 0);
3065 pcity->waste[o] = city_waste(pcity, o, prod, nullptr);
3067
3068 /* Convert trade into science/luxury/gold, and add this on to whatever
3069 * science/luxury/gold is already there. */
3070 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3071 + pcity->abs_bonus[O_TRADE];
3072 trade = MAX(trade, 0);
3074 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3075 pcity->prod);
3076
3077 /* Add on effect bonuses and waste. Note that the waste calculation
3078 * (above) already includes the bonuses. */
3080 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3081
3082 prod = MAX(prod, 0);
3083 pcity->prod[o] = prod;
3084 pcity->prod[o] -= pcity->waste[o];
3086}
3087
3088/**********************************************************************/
3092 struct unit *punit, int *free_unhappy)
3093{
3094 struct city *pcity;
3095 const struct unit_type *ut;
3096 struct player *plr;
3097 int happy_cost;
3098
3099 if (punit == nullptr || free_unhappy == nullptr) {
3100 return 0;
3101 }
3102
3104 if (pcity == nullptr) {
3105 return 0;
3106 }
3107
3109 plr = unit_owner(punit);
3110 happy_cost = utype_happy_cost(ut, plr);
3111
3112 if (happy_cost <= 0) {
3113 return 0;
3114 }
3115
3117
3119 return 0;
3120 }
3121
3123 if (happy_cost <= 0) {
3124 return 0;
3125 }
3126
3127 if (*free_unhappy >= happy_cost) {
3128 *free_unhappy -= happy_cost;
3129 return 0;
3130 } else {
3131 happy_cost -= *free_unhappy;
3132 *free_unhappy = 0;
3133 }
3134
3135 return happy_cost;
3136}
3137
3138/**********************************************************************/
3142static inline void city_support(const struct civ_map *nmap,
3143 struct city *pcity)
3144{
3145 int free_unhappy;
3146 int max_mart_units;
3147
3148 /* Clear all usage values. */
3149 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3150 pcity->martial_law = 0;
3151 pcity->unit_happy_upkeep = 0;
3152
3153 /* Building and unit gold upkeep depends on the setting
3154 * 'game.info.gold_upkeep_style':
3155 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3156 * city.
3157 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3158 * The upkeep for units is paid by the nation.
3159 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3160 * nation. */
3162 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3163 switch (game.info.gold_upkeep_style) {
3164 case GOLD_UPKEEP_CITY:
3166 fc__fallthrough; /* No break */
3167 case GOLD_UPKEEP_MIXED:
3169 break;
3170 case GOLD_UPKEEP_NATION:
3171 /* nothing */
3172 break;
3173 }
3174 /* Food consumption by citizens. */
3176
3178 if (max_mart_units > 0) {
3180 int sel_count = 0;
3181 int i;
3182
3185 && unit_owner(punit) == city_owner(pcity)) {
3186 int current = get_target_bonus_effects(nullptr,
3187 &(const struct req_context) {
3188 .player = city_owner(pcity),
3189 .city = pcity,
3190 .tile = city_tile(pcity),
3191 .unit = punit,
3192 .unittype = unit_type_get(punit)
3193 },
3194 nullptr, EFT_MARTIAL_LAW_BY_UNIT);
3195 if (current > 0) {
3196 if (sel_count < max_mart_units) {
3197 best_units[sel_count++] = current;
3198 } else if (current > best_units[max_mart_units - 1]) {
3199 for (i = max_mart_units - 1; i >= 0 && current > best_units[i]; i--) {
3200 if (i + 1 < max_mart_units) {
3201 best_units[i + 1] = best_units[i];
3202 }
3203 }
3204
3205 best_units[i + 1] = current;
3206 }
3207 }
3208 }
3210
3211 pcity->martial_law = 0;
3212 for (i = 0; i < sel_count; i++) {
3213 pcity->martial_law += best_units[i];
3214 }
3215
3216 pcity->martial_law = MIN(pcity->martial_law, MAX_CITY_SIZE);
3217 }
3218
3220 unit_list_iterate(pcity->units_supported, punit) {
3221 pcity->unit_happy_upkeep += city_unit_unhappiness(nmap, punit, &free_unhappy);
3223 if (O_GOLD != o) {
3224 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3225 pcity->usage[o] += punit->upkeep[o];
3226 }
3229}
3230
3231/**********************************************************************/
3244 struct city *pcity, bool *workers_map)
3245{
3246 if (workers_map == nullptr) {
3247 /* Do a full refresh */
3248
3249 /* Calculate the bonus[] array values. */
3251 /* Calculate the tile_cache[] values. */
3253 /* Manage settlers, and units */
3255 }
3256
3257 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3258 get_worked_tile_output(nmap, pcity, pcity->citizen_base, workers_map);
3259 add_specialist_output(pcity, pcity->citizen_base);
3260
3263 /* Note that pollution is calculated before unhappy_city_check() makes
3264 * deductions for disorder; so a city in disorder still causes pollution */
3265 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3266
3268 citizen_happy_luxury(pcity); /* With our new found luxuries */
3269
3272
3275
3276 /* Martial law & unrest from units */
3279
3280 /* Building (including wonder) happiness effects */
3283
3286}
3287
3288/**********************************************************************/
3295int city_waste(const struct city *pcity, Output_type_id otype, int total,
3296 int *breakdown)
3297{
3298 int penalty_waste = 0;
3299 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3300 * corruption */
3301 int total_eft = total; /* Normal corruption calculated on total reduced by
3302 * possible size penalty */
3303 const struct output_type *output = get_output_type(otype);
3305 bool waste_all = FALSE;
3306
3307 if (otype == O_TRADE) {
3308 /* FIXME: special case for trade: it is affected by notradesize and
3309 * fulltradesize server settings.
3310 *
3311 * If notradesize and fulltradesize are equal then the city gets no
3312 * trade at that size. */
3313 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3314 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3315
3316 if (city_size_get(pcity) <= notradesize) {
3317 penalty_size = total_eft; /* Then no trade income. */
3318 } else if (city_size_get(pcity) >= fulltradesize) {
3319 penalty_size = 0;
3320 } else {
3321 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3322 / (fulltradesize - notradesize);
3323 }
3324 }
3325
3326 /* Apply corruption only to anything left after tradesize */
3328
3329 /* Distance-based waste.
3330 * Don't bother calculating if there's nothing left to lose. */
3331 if (total_eft > 0) {
3336 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3337 int min_dist;
3338 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3339
3340 if (gov_center == nullptr) {
3341 waste_all = TRUE; /* No gov center - no income */
3342 } else {
3344 if (waste_by_rel_dist > 0) {
3345 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3346 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3347 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3349 }
3350 }
3351 }
3352 }
3353
3354 if (waste_all) {
3356 } else {
3359
3360 /* Corruption/waste calculated only for the actually produced amount */
3361 if (waste_level > 0) {
3363 }
3364
3365 /* Bonus calculated only for the actually produced amount */
3367
3368 /* Clip */
3370 }
3371
3372 if (breakdown) {
3375 }
3376
3377 /* Add up total penalty */
3378 return penalty_waste + penalty_size;
3379}
3380
3381/**********************************************************************/
3386{
3387 citizens count = 0;
3388
3390 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3391 count += pcity->specialists[sp];
3393
3394 return count;
3395}
3396
3397/**********************************************************************/
3401{
3402 int count = 0;
3403
3405 count += pcity->specialists[sp];
3407
3408 return count;
3409}
3410
3411/**********************************************************************/
3417 const struct city *pcity)
3418{
3419 int best = DEFAULT_SPECIALIST;
3420 int val = get_specialist_output(pcity, best, otype);
3421
3425
3426 if (val2 > val) {
3427 best = i;
3428 val = val2;
3429 }
3430 }
3432
3433 return best;
3434}
3435
3436/**********************************************************************/
3440 const struct impr_type *pimprove)
3441{
3442 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3443
3444 if (is_server() && is_wonder(pimprove)) {
3445 /* Client just read the info from the packets. */
3446 wonder_built(pcity, pimprove);
3447 }
3448}
3449
3450/**********************************************************************/
3454 const struct impr_type *pimprove)
3455{
3456 log_debug("Improvement %s removed from city %s",
3457 improvement_rule_name(pimprove), pcity->name);
3458
3459 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3460
3461 if (is_server() && is_wonder(pimprove)) {
3462 /* Client just read the info from the packets. */
3463 wonder_destroyed(pcity, pimprove);
3464 }
3465}
3466
3467/**********************************************************************/
3471{
3472 return BV_ISSET(pcity->city_options, option);
3473}
3474
3475/**********************************************************************/
3479{
3480 int i;
3481
3482 city_styles = fc_calloc(num, sizeof(*city_styles));
3484
3485 for (i = 0; i < game.control.num_city_styles; i++) {
3487 }
3488}
3489
3490/**********************************************************************/
3494{
3495 int i;
3496
3497 for (i = 0; i < game.control.num_city_styles; i++) {
3499 }
3500
3502 city_styles = nullptr;
3504}
3505
3506/**********************************************************************/
3512struct city *create_city_virtual(struct player *pplayer,
3513 struct tile *ptile, const char *name)
3514{
3515 int i,len;
3516
3517 /* Make sure that contents of city structure are correctly initialized,
3518 * if you ever allocate it by some other mean than fc_calloc() */
3519 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3520
3521 fc_assert_ret_val(name != nullptr, nullptr); /* No unnamed cities! */
3522
3523 /* Do this early, so any logging later will have the city name */
3525
3526 pcity->tile = ptile;
3527
3528 fc_assert_ret_val(pplayer != nullptr, nullptr); /* No unowned cities! */
3529
3530 pcity->owner = pplayer;
3531 pcity->acquire_t = CACQ_FOUNDED;
3532
3533 if (is_server()) {
3534 pcity->original = pplayer;
3535 }
3536
3537 /* City structure was allocated with fc_calloc(), so contents are initially
3538 * zero. There is no need to initialize it a second time. */
3539
3540 /* Now set some useful default values. */
3541 pcity->capital = CAPITAL_NOT;
3542 city_size_set(pcity, 1);
3543 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3544 pcity->wlcb = WLCB_SMART;
3545
3547 pcity->bonus[o] = 100;
3548 pcity->abs_bonus[o] = 0;
3550
3551 pcity->turn_plague = -1; /* -1 = never */
3552 pcity->did_buy = FALSE;
3553 pcity->city_radius_sq = game.info.init_city_radius_sq;
3554 pcity->turn_founded = game.info.turn;
3555 pcity->turn_last_built = game.info.turn;
3556
3557 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3558
3559 /* pcity->ai.act_cache: worker activities on the city map */
3560
3561 /* Initialise improvements list */
3562 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3563 pcity->built[i].turn = I_NEVER;
3564 }
3565
3566 /* Set up the worklist */
3567 worklist_init(&pcity->worklist);
3568
3569 pcity->units_supported = unit_list_new();
3570 pcity->routes = trade_route_list_new();
3571 pcity->task_reqs = worker_task_list_new();
3572
3573 if (is_server()) {
3574 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3575
3576 CALL_FUNC_EACH_AI(city_alloc, pcity);
3577 } else {
3578 pcity->client.info_units_supported =
3580 pcity->client.info_units_present =
3582 /* collecting_info_units_supported set by fc_calloc().
3583 * collecting_info_units_present set by fc_calloc(). */
3584 }
3585
3587 pcity->counter_values = fc_malloc(sizeof(int) * len);
3588
3589 for (i = 0; i < len; i++) {
3590 pcity->counter_values[i] = counter_by_index(i, CTGT_CITY)->def;
3591 }
3592
3593 return pcity;
3594}
3595
3596/**********************************************************************/
3601{
3602 CALL_FUNC_EACH_AI(city_free, pcity);
3603
3605
3606 /* Free worker tasks */
3607 while (worker_task_list_size(pcity->task_reqs) > 0) {
3608 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3609
3610 worker_task_list_remove(pcity->task_reqs, ptask);
3611
3612 free(ptask);
3613 }
3614 worker_task_list_destroy(pcity->task_reqs);
3615
3616 /* Free rally points */
3618
3619 unit_list_destroy(pcity->units_supported);
3621 if (pcity->tile_cache != nullptr) {
3622 free(pcity->tile_cache);
3623 }
3624
3625 if (pcity->cm_parameter) {
3626 free(pcity->cm_parameter);
3627 }
3628
3629 if (pcity->counter_values) {
3630 free(pcity->counter_values);
3631 }
3632
3633 if (!is_server()) {
3634 unit_list_destroy(pcity->client.info_units_supported);
3635 unit_list_destroy(pcity->client.info_units_present);
3636 /* Handle a rare case where the game is freed in the middle of a
3637 * spy/diplomat investigate cycle. */
3638 if (pcity->client.collecting_info_units_supported != nullptr) {
3639 unit_list_destroy(pcity->client.collecting_info_units_supported);
3640 }
3641 if (pcity->client.collecting_info_units_present != nullptr) {
3642 unit_list_destroy(pcity->client.collecting_info_units_present);
3643 }
3644 }
3645
3646 free(pcity->name);
3647
3648 memset(pcity, 0, sizeof(*pcity)); /* Ensure no pointers remain */
3649 free(pcity);
3650}
3651
3652/**********************************************************************/
3656bool city_exist(int id)
3657{
3658 /* Check if city exist in game */
3659 if (game_city_by_number(id)) {
3660 return TRUE;
3661 }
3662
3663 return FALSE;
3664}
3665
3666/**********************************************************************/
3673bool city_is_virtual(const struct city *pcity)
3674{
3675 if (!pcity) {
3676 return FALSE;
3677 }
3678
3679 return pcity != game_city_by_number(pcity->id);
3680}
3681
3682/**********************************************************************/
3685bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3686{
3687 return is_city_center(pcity, ptile);
3688}
3689
3690/**********************************************************************/
3693void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3694{
3695 return pcity->server.ais[ai_type_number(ai)];
3696}
3697
3698/**********************************************************************/
3701void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3702 void *data)
3703{
3704 pcity->server.ais[ai_type_number(ai)] = data;
3705}
3706
3707/**********************************************************************/
3711{
3712 /* Free rally points */
3713 if (pcity->rally_point.length > 0) {
3714 pcity->rally_point.length = 0;
3715 pcity->rally_point.persistent = FALSE;
3716 pcity->rally_point.vigilant = FALSE;
3717 free(pcity->rally_point.orders);
3718 pcity->rally_point.orders = nullptr;
3719 }
3720}
3721
3722/**********************************************************************/
3726 struct city *pcity)
3727{
3728 struct unit_order *checked_orders;
3729 const struct civ_map *nmap = &(wld.map);
3730
3731 if (pcity == nullptr) {
3732 /* Probably lost. */
3733 log_verbose("handle_city_rally_point() bad city number %d.",
3734 packet->id);
3735 return;
3736 }
3737
3738 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3739 /* Shouldn't happen */
3740 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3741 packet->length, MAX_LEN_ROUTE);
3742 return;
3743 }
3744
3745 pcity->rally_point.length = packet->length;
3746
3747 if (packet->length == 0) {
3748 pcity->rally_point.vigilant = FALSE;
3749 pcity->rally_point.persistent = FALSE;
3750 if (pcity->rally_point.orders) {
3751 free(pcity->rally_point.orders);
3752 pcity->rally_point.orders = nullptr;
3753 }
3754 } else {
3756 packet->orders);
3757 if (!checked_orders) {
3758 pcity->rally_point.length = 0;
3759 log_error("invalid rally point orders for %s.",
3761 return;
3762 }
3763
3764 pcity->rally_point.persistent = packet->persistent;
3765 pcity->rally_point.vigilant = packet->vigilant;
3766 pcity->rally_point.orders = checked_orders;
3767 }
3768}
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:1678
bool city_is_virtual(const struct city *pcity)
Definition city.c:3673
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:2006
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2585
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:666
static void citizen_content_buildings(struct city *pcity)
Definition city.c:2632
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3685
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1901
static bv_imprs caravan_helped_impr
Definition city.c:1812
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:1185
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2201
#define POLLUTION_EFT_NEARMAX
Definition city.c:1149
const char * city_name_getx(const struct city *pcity)
Definition city.c:1150
int city_granary_size(int city_size)
Definition city.c:2173
static void get_worked_tile_output(const struct civ_map *nmap, const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2365
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2237
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2828
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3701
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2753
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2133
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2320
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1091
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3295
static void city_support(const struct civ_map *nmap, struct city *pcity)
Definition city.c:3142
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2974
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:1280
const char * city_style_name_translation(const int style)
Definition city.c:1797
void city_styles_free(void)
Definition city.c:3493
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2479
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:650
int city_superspecialists(const struct city *pcity)
Definition city.c:3400
bool is_capital(const struct city *pcity)
Definition city.c:1620
void city_styles_alloc(int num)
Definition city.c:3478
const char * city_name_get(const struct city *pcity)
Definition city.c:1141
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1442
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1053
void city_production_caravan_shields_init(void)
Definition city.c:1819
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3453
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1296
int city_airlift_max(const struct city *pcity)
Definition city.c:2984
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1506
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1035
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:3470
int city_population(const struct city *pcity)
Definition city.c:1231
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1806
void city_size_add(struct city *pcity, int add)
Definition city.c:1204
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1069
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:1706
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:2286
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:858
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:2107
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3091
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1637
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2227
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:2450
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2268
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2122
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:1694
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:1667
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3416
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3512
void set_city_production(struct city *pcity)
Definition city.c:2995
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1720
static bv_unit_types caravan_helped_utype
Definition city.c:1813
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2253
bool city_celebrating(const struct city *pcity)
Definition city.c:1686
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1601
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:834
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:2912
const char * get_output_name(Output_type_id output)
Definition city.c:630
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2053
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1927
static int get_city_health(const struct city *pcity)
Definition city.c:2895
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:3243
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:998
static void set_city_bonuses(struct city *pcity)
Definition city.c:2427
static void set_surpluses(struct city *pcity)
Definition city.c:2493
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2328
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:1528
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2862
bool city_happy(const struct city *pcity)
Definition city.c:1655
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1220
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3439
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1425
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:2077
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2062
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:3600
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:3385
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:3725
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:1762
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2405
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:3693
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1736
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2656
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1324
static int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
Definition city.c:64
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:123
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:907
bool is_gov_center(const struct city *pcity)
Definition city.c:1628
#define log_ca_s_init
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1017
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2622
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:951
int city_map_tiles(int city_radius_sq)
Definition city.c:171
static void unhappy_city_check(struct city *pcity)
Definition city.c:2801
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2092
bool city_exist(int id)
Definition city.c:3656
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1497
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:2037
void city_rally_point_clear(struct city *pcity)
Definition city.c:3710
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:875
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:2153
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2965
static int get_trade_illness(const struct city *pcity)
Definition city.c:2875
bool city_can_change_build(const struct city *pcity)
Definition city.c:1083
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:974
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1262
int city_style_by_rule_name(const char *s)
Definition city.c:1779
static void citizen_base_mood(struct city *pcity)
Definition city.c:2546
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1752
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1241
static void citizen_happy_units(struct city *pcity)
Definition city.c:2705
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2534
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:847
#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:870
#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:836
#define is_free_worked_index(city_tile_index)
Definition city.h:882
#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:842
#define PCT_LAST
Definition city.h:41
#define output_type_iterate_end
Definition city.h:853
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
@ 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:107
struct government * government_of_player(const struct player *pplayer)
Definition government.c:116
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
bool is_building_sellable(const struct impr_type *pimprove)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h: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:1076
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:1213
#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:2945
bool unit_being_aggressive(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:1582
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:1793
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1424
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
#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:2298
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, bool consider_reg_impr_req)
Definition unittype.c:1994
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2657
bool utype_can_do_act_when_ustate(const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
Definition unittype.c:980
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:114
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1554
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2125
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
Definition unittype.c:1042
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Definition unittype.c:206
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:863
#define unit_type_iterate_end
Definition unittype.h:870
#define U_NOT_OBSOLETED
Definition unittype.h:535
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT