Freeciv-3.4
Loading...
Searching...
No Matches
city.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdlib.h>
19#include <string.h>
20#include <math.h> /* pow, sqrt, exp */
21
22/* utility */
23#include "distribute.h"
24#include "fcintl.h"
25#include "log.h"
26#include "mem.h"
27#include "support.h"
28
29/* common */
30#include "ai.h"
31#include "citizens.h"
32#include "counters.h"
33#include "effects.h"
34#include "game.h"
35#include "government.h"
36#include "improvement.h"
37#include "map.h"
38#include "movement.h"
39#include "packets.h"
40#include "specialist.h"
41#include "traderoutes.h"
42#include "unit.h"
43
44/* aicore */
45#include "cm.h"
46
47#include "city.h"
48
49/* Define this to add in extra (very slow) assertions for the city code. */
50#undef CITY_DEBUGGING
51
52static char *citylog_map_line(int y, int city_radius_sq, int *city_map_data);
53#ifdef FREECIV_DEBUG
54/* Only used for debugging */
55static void citylog_map_index(enum log_level level);
56static void citylog_map_radius_sq(enum log_level level);
57#endif /* FREECIV_DEBUG */
58
59/* Get city tile information using the city tile index. */
60static struct iter_index *city_map_index = nullptr;
61/* Get city tile information using the city tile coordinates. This is an
62 * [x][y] array of integer values corresponding to city_map_index. The
63 * coordinates x and y are in the range [0, CITY_MAP_MAX_SIZE] */
65
66/* Number of tiles of a city; depends on the squared city radius */
68
69/* Definitions and functions for the tile_cache */
70struct tile_cache {
72};
73
74static inline void city_tile_cache_update(const struct civ_map *nmap,
75 struct city *pcity);
76static inline int city_tile_cache_get_output(const struct city *pcity,
78 enum output_type_id o);
79
80static const struct city *nearest_gov_center(const struct city *pcity,
81 int *min_dist)
82 fc__attribute((nonnull (1, 2)));
83
84struct citystyle *city_styles = nullptr;
85
86/* One day these values may be read in from the ruleset. In the meantime
87 * they're just an easy way to access information about each output type. */
89 {O_FOOD, N_("Food"), "food", TRUE, UNHAPPY_PENALTY_SURPLUS},
90 {O_SHIELD, N_("Shield"), "shield", TRUE, UNHAPPY_PENALTY_SURPLUS},
91 {O_TRADE, N_("Trade"), "trade", TRUE, UNHAPPY_PENALTY_NONE},
92 {O_GOLD, N_("Gold"), "gold", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION},
93 {O_LUXURY, N_("Luxury"), "luxury", FALSE, UNHAPPY_PENALTY_NONE},
94 {O_SCIENCE, N_("Science"), "science", FALSE, UNHAPPY_PENALTY_ALL_PRODUCTION}
95};
96
97/**********************************************************************/
102 int city_tile_index, int city_radius_sq)
103{
106
107 /* tile indices are sorted from smallest to largest city radius */
108 if (city_tile_index < 0
109 || city_tile_index >= city_map_tiles(city_radius_sq)) {
110 return FALSE;
111 }
112
115
116 return TRUE;
117}
118
119/**********************************************************************/
124 int city_radius_sq)
125{
126 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, 0);
127 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, 0);
129 city_map_y), 0);
130
132}
133
134/**********************************************************************/
138{
139 /* A safe return value is only the minimal squared radius */
141
142 return pcity->city_radius_sq;
143}
144
145/**********************************************************************/
148void city_map_radius_sq_set(struct city *pcity, int radius_sq)
149{
152
153 pcity->city_radius_sq = radius_sq;
154}
155
156/**********************************************************************/
166
167/**********************************************************************/
171int city_map_tiles(int city_radius_sq)
172{
173 if (city_radius_sq == CITY_MAP_CENTER_RADIUS_SQ) {
174 /* special case: city center; first tile of the city map */
175 return 0;
176 }
177
178 fc_assert_ret_val(city_radius_sq >= CITY_MAP_MIN_RADIUS_SQ, -1);
179 fc_assert_ret_val(city_radius_sq <= CITY_MAP_MAX_RADIUS_SQ, -1);
180
181 return city_map_numtiles[city_radius_sq];
182}
183
184/**********************************************************************/
188bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
189 const int city_map_y)
190{
191 /* The city's valid positions are in a circle around the city center.
192 * Depending on the value for the squared city radius the circle will be:
193 *
194 * - rectangular (max radius = 5; max squared radius = 26)
195 *
196 * 0 1 2 3 4 5 6 7 8 9 10
197 *
198 * 0 26 25 26 -5
199 * 1 25 20 17 16 17 20 25 -4
200 * 2 25 18 13 10 9 10 13 18 25 -3
201 * 3 20 13 8 5 4 5 8 13 20 -2
202 * 4 26 17 10 5 2 1 2 5 10 17 26 -1
203 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
204 * 6 26 17 10 5 2 1 2 5 10 17 26 +1
205 * 7 20 13 8 5 4 5 8 13 20 +2
206 * 8 25 18 13 10 9 10 13 18 25 +3
207 * 9 25 20 17 16 17 20 25 +4
208 * 10 26 25 26 +5
209 *
210 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
211 *
212 * - hexagonal (max radius = 5; max squared radius = 26)
213 *
214 * 0 1 2 3 4 5 6 7 8 9 10
215 *
216 * 0 25 25 25 25 25 25 -5
217 * 1 25 16 16 16 16 16 25 -4
218 * 2 25 16 9 9 9 9 16 25 -3
219 * 3 25 16 9 4 4 4 9 16 25 -2
220 * 4 25 16 9 4 1 1 4 9 16 25 -1
221 * 5 25 16 9 4 1 0 1 4 9 16 25 +0
222 * 6 25 16 9 4 1 1 4 9 16 25 +1
223 * 7 25 16 9 4 4 4 9 16 25 +2
224 * 8 25 16 9 9 9 9 16 25 +3
225 * 9 25 16 16 16 16 16 25 +4
226 * 10 25 25 25 25 25 25 +5
227 *
228 * -5 -4 -3 -2 -1 +0 +1 +2 +3 +4 +5
229 *
230 * The following tables show the tiles per city radii / squared city radii.
231 * '-' indicates no change compared to the previous value
232 *
233 * radius | 0 | 1 | | | 2 | | | | | 3
234 * radius_sq | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
235 * ------------------+----+----+----+----+----+----+----+----+----+----
236 * tiles rectangular | 5 | 9 | - | 13 | 21 | - | - | 25 | 29 | 37
237 * tiles hexagonal | 7 | - | - | 19 | - | - | - | - | 37 | -
238 *
239 * radius | | | | | | | 4 | | |
240 * radius_sq | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
241 * ------------------+----+----+----+----+----+----+----+----+----+----
242 * tiles rectangular | - | - | 45 | - | - | 49 | 57 | 61 | - | 69
243 * tiles hexagonal | - | - | - | - | - | 61 | - | - | - | -
244 *
245 * radius | | | | | | 5
246 * radius_sq | 21 | 22 | 23 | 24 | 25 | 26
247 * ------------------+----+----+----+----+----+----
248 * tiles rectangular | - | - | - | - | 81 | 89
249 * tiles hexagonal | - | - | - | - | 91 | -
250 *
251 * So radius_sq == 5 (radius == 2) corresponds to the "traditional"
252 * used city map.
253 */
256
257 return dist <= city_radius_sq;
258}
259
260/**********************************************************************/
265 const int city_radius_sq,
266 const struct tile *city_center,
267 const struct tile *map_tile)
268{
270
273
274 return is_valid_city_coords(city_radius_sq, *city_map_x, *city_map_y);
275}
276
277/**********************************************************************/
282 const struct city *const pcity,
283 const struct tile *map_tile)
284{
287 map_tile);
288}
289
290/**********************************************************************/
293bool city_map_includes_tile(const struct city *const pcity,
294 const struct tile *map_tile)
295{
296 int tmp_x, tmp_y;
297
299}
300
301/**********************************************************************/
305struct tile *city_map_to_tile(const struct civ_map *nmap,
306 const struct tile *city_center,
307 int city_radius_sq, int city_map_x,
308 int city_map_y)
309{
310 int tile_x, tile_y;
311
313 city_map_y), nullptr);
314
315 index_to_map_pos(&tile_x, &tile_y, tile_index(city_center));
318
320}
321
322/**********************************************************************/
325static int cmp(int v1, int v2)
326{
327 if (v1 == v2) {
328 return 0;
329 } else if (v1 > v2) {
330 return 1;
331 } else {
332 return -1;
333 }
334}
335
336/**********************************************************************/
343int compare_iter_index(const void *a, const void *b)
344{
345 const struct iter_index *index1 = a, *index2 = b;
346 int value;
347
348 value = cmp(index1->dist, index2->dist);
349 if (value != 0) {
350 return value;
351 }
352
353 value = cmp(index1->dx, index2->dx);
354 if (value != 0) {
355 return value;
356 }
357
358 value = cmp(index1->dy, index2->dy);
359 fc_assert(0 != value);
360 return value;
361}
362
363/**********************************************************************/
368#define CITYLOG_MAX_VAL 9999 /* maximal value displayed in the citylog */
369static char *citylog_map_line(int y, int city_radius_sq, int *city_map_data)
370{
371 int x, mindex;
372 static char citylog[128], tmp[8];
373
374 fc_assert_ret_val(city_map_data != nullptr, nullptr);
375
376 /* print y coordinates (absolute) */
377 fc_snprintf(citylog, sizeof(citylog), "%2d ", y);
378
379 /* print values */
380 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
381 if (is_valid_city_coords(city_radius_sq, x, y)) {
382 mindex = city_tile_xy_to_index(x, y, city_radius_sq);
383 /* show values between -10000 and +10000 */
386 fc_snprintf(tmp, sizeof(tmp), "%5d", city_map_data[mindex]);
388 } else {
389 fc_snprintf(tmp, sizeof(tmp), " ####");
391 }
392 } else {
393 fc_snprintf(tmp, sizeof(tmp), " ");
395 }
396 }
397
398 /* print y coordinates (relative) */
399 fc_snprintf(tmp, sizeof(tmp), " %+4d", CITY_ABS2REL(y));
401
402 return citylog;
403}
404#undef CITYLOG_MAX_VAL
405
406/**********************************************************************/
411void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
412{
413 int x, y;
414 char line[128], tmp[8];
415
417 return;
418 }
419
420 log_base(level, "(max squared city radius = %d)", CITY_MAP_MAX_RADIUS_SQ);
421
422 /* print x coordinates (absolute) */
423 fc_snprintf(line, sizeof(line), " ");
424 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
425 fc_snprintf(tmp, sizeof(tmp), "%+5d", x);
427 }
428 log_base(level, "%s", line);
429
430 for (y = 0; y < CITY_MAP_MAX_SIZE; y++) {
431 log_base(level, "%s", citylog_map_line(y, radius_sq, map_data));
432 }
433
434 /* print x coordinates (relative) */
435 fc_snprintf(line, sizeof(line), " ");
436 for (x = 0; x < CITY_MAP_MAX_SIZE; x++) {
437 fc_snprintf(tmp, sizeof(tmp), "%+5d", CITY_ABS2REL(x));
439 }
440 log_base(level, "%s", line);
441}
442
443/**********************************************************************/
447{
448 int *city_map_data = nullptr;
449 const struct civ_map *nmap = &(wld.map);
450
451 fc_assert_ret(pcity != nullptr);
452
454 return;
455 }
456
458 sizeof(*city_map_data));
459
461 struct tile *ptile = city_map_to_tile(nmap,
464 x, y);
465 city_map_data[cindex] = (ptile && tile_worked(ptile) == pcity)
466 ? (is_free_worked_index(cindex) ? 2 : 1) : 0;
468
469 log_base(level, "[%s (%d)] workers map:", city_name_get(pcity), pcity->id);
472}
473
474#ifdef FREECIV_DEBUG
475/**********************************************************************/
478static void citylog_map_index(enum log_level level)
479{
480 int *city_map_data = nullptr;
481
483 return;
484 }
485
487 sizeof(*city_map_data));
488
490 city_map_data[cindex] = cindex;
492
493 log_debug("city map index:");
496}
497
498/**********************************************************************/
501static void citylog_map_radius_sq(enum log_level level)
502{
503 int *city_map_data = nullptr;
504
506 return;
507 }
508
510 sizeof(*city_map_data));
511
514 CITY_ABS2REL(y));
516
517 log_debug("city map squared radius:");
520}
521#endif /* FREECIV_DEBUG */
522
523/**********************************************************************/
528{
529 int i, dx, dy, city_x, city_y, dist, city_count_tiles = 0;
532
533 /* initialise map information for each city radii */
534 for (i = 0; i <= CITY_MAP_MAX_RADIUS_SQ; i++) {
535 city_map_numtiles[i] = 0; /* will be set below */
536 }
537
538 /* We don't use city-map iterators in this function because they may
539 * rely on the indices that have not yet been generated. Furthermore,
540 * we don't know the number of tiles within the city radius, so we need
541 * an temporary city_map_index array. Its content will be copied into
542 * the real array below. */
546
551
552 for (i = CITY_MAP_MAX_RADIUS_SQ; i >= 0; i--) {
553 if (dist <= i) {
554 /* increase number of tiles within this squared city radius */
556 }
557 }
558
560 }
561
562 /* Initialise city_map_xy. -1 defines a invalid city map positions. */
564 }
565 }
566
567 fc_assert(city_map_index == nullptr);
569
570 /* Copy the index numbers from city_map_index_tmp into city_map_index */
571 for (i = 0; i < city_count_tiles; i++) {
573 }
574
577
578 /* Set the static variable city_map_xy */
579 for (i = 0; i < city_count_tiles; i++) {
583 }
584
585#ifdef FREECIV_DEBUG
588
590 log_debug("radius_sq = %2d, tiles = %2d", i, city_map_tiles(i));
591 }
592
593 for (i = 0; i < city_count_tiles; i++) {
596 log_debug("[%2d]: (dx,dy) = (%+2d,%+2d), (x,y) = (%2d,%2d), "
597 "dist = %2d, check = %2d", i,
600 }
601#endif /* FREECIV_DEBUG */
602
604}
605
606/**********************************************************************/
610{
612}
613
614/**********************************************************************/
620{
621 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
622
623 return output_types[output].id;
624}
625
626/**********************************************************************/
631{
632 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
633
634 return _(output_types[output].name);
635}
636
637/**********************************************************************/
641{
642 fc_assert_ret_val(output >= 0 && output < O_LAST, nullptr);
643
644 return &output_types[output];
645}
646
647/**********************************************************************/
651{
653
654 for (o = 0; o < O_LAST; o++) {
655 if (fc_strcasecmp(output_types[o].id, id) == 0) {
656 return o;
657 }
658 }
659
660 return O_LAST;
661}
662
663/**********************************************************************/
667 const struct impr_type *pimprove)
668{
669 static char buffer[256];
670 const char *state = nullptr;
671
672 if (is_great_wonder(pimprove)) {
673 if (great_wonder_is_available(pimprove)) {
674 state = Q_("?wonder:W");
675 } else if (great_wonder_is_destroyed(pimprove)) {
676 state = Q_("?destroyed:D");
677 } else {
678 state = Q_("?built:B");
679 }
680 }
681 if (pcity) {
682 struct player *pplayer = city_owner(pcity);
683
684 if (improvement_obsolete(pplayer, pimprove, pcity)) {
685 state = Q_("?obsolete:O");
686 } else if (is_improvement_redundant(pcity, pimprove)) {
687 state = Q_("?redundant:*");
688 }
689 }
690
691 if (state) {
692 fc_snprintf(buffer, sizeof(buffer), "%s(%s)",
693 improvement_name_translation(pimprove), state);
694 return buffer;
695 } else {
696 return improvement_name_translation(pimprove);
697 }
698}
699
700/**********************************************************************/
704{
705 static char buffer[256];
706
707 switch (pcity->production.kind) {
708 case VUT_IMPROVEMENT:
709 return city_improvement_name_translation(pcity, pcity->production.value.building);
710 default:
711 /* fallthru */
712 break;
713 };
714 return universal_name_translation(&pcity->production, buffer, sizeof(buffer));
715}
716
717/**********************************************************************/
721 enum impr_genus_id genus)
722{
723 return VUT_IMPROVEMENT == pcity->production.kind
724 && (pcity->production.value.building->genus == genus);
725}
726
727/**********************************************************************/
731 enum impr_flag_id flag)
732{
733 return VUT_IMPROVEMENT == pcity->production.kind
734 && improvement_has_flag(pcity->production.value.building, flag);
735}
736
737/**********************************************************************/
741{
742 return universal_build_shield_cost(pcity, &pcity->production);
743}
744
745/**********************************************************************/
751 bool add_production, int *num_units)
752{
753 const struct unit_type *utype;
754 struct universal target;
756 int shields_left = pcity->shield_stock;
757 int unit_shield_cost, i;
758
759 fc_assert_ret_val(num_units != nullptr, FALSE);
760
761 (*num_units) = 0;
762
763 if (pcity->production.kind != VUT_UTYPE) {
764 /* Not a unit as the current production */
765 return FALSE;
766 }
767
768 utype = pcity->production.value.utype;
769 if (utype_pop_value(utype, pcity) != 0 || utype_has_flag(utype, UTYF_UNIQUE)) {
770 /* Unit with population cost or unique unit means that only one unit can
771 * be build */
772 (*num_units)++;
773 return FALSE;
774 }
775
776 if (add_production) {
777 shields_left += pcity->prod[O_SHIELD];
778 }
779
781
782 for (i = 0; i < build_slots; i++) {
784 /* Not enough shields */
785 break;
786 }
787
788 (*num_units)++;
790
791 if (worklist_length(&pcity->worklist) > i) {
792 (void) worklist_peek_ith(&pcity->worklist, &target, i);
793 if (target.kind != VUT_UTYPE
794 || utype_index(target.value.utype) != utype_index(utype)) {
795 /* Stop if there is a build target in the worklist not equal to the
796 * unit we build */
797 break;
798 }
799 }
800 }
801
802 return TRUE;
803}
804
805/************************************************************************/
809 const struct unit_type *punittype)
810{
812 nullptr, EFT_VETERAN_BUILD);
814
815 levels = CLIP(0, levels, max_levels);
816
817 return levels;
818}
819
820/**********************************************************************/
826{
828}
829
830/**********************************************************************/
835 const struct impr_type *pimprove,
836 const enum req_problem_type prob_type)
837{
839 prob_type)) {
840 return FALSE;
841 }
842
843 if (city_has_building(pcity, pimprove)) {
844 return FALSE;
845 }
846
847 return are_reqs_active(&(const struct req_context) {
848 .player = city_owner(pcity),
849 .city = pcity,
850 .tile = pcity->tile,
851 },
852 nullptr,
853 &(pimprove->reqs), prob_type);
854}
855
856/**********************************************************************/
861 const struct impr_type *pimprove,
862 const enum req_problem_type prob_type)
863{
865 prob_type)) {
866 return FALSE;
867 }
868 if (improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
869 return FALSE;
870 }
871
872 return TRUE;
873}
874
875/**********************************************************************/
880 const struct impr_type *pimprove)
881{
882 const struct req_context city_ctxt = {
884 .city = pcity,
885 .tile = city_tile(pcity),
886 };
887
888 /* Can the _player_ ever build this improvement? */
889 /* NOTE: It checks for obsoletion player-level. What aboult checking
890 * for it city-level? That may unlist from a worklist some things
891 * we'll be able to switch to after e.g. selling something else */
893 return FALSE;
894 }
895
896 /* Check for requirements that aren't met and that are unchanging (so
897 * they can never be met). */
899 if (is_req_preventing(&city_ctxt, nullptr, preq, RPT_POSSIBLE)) {
900 return FALSE;
901 }
903
904 return TRUE;
905}
906
907/**********************************************************************/
912 const struct city *pcity,
913 const struct unit_type *punittype,
914 const enum req_problem_type prob_type)
915{
917 prob_type, FALSE)) {
918 return FALSE;
919 }
920
921 /* Check unit build requirements.
922 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
923 * Don't recheck those. Not only for optimization, but also not to override the
924 * special handling of tech requirements for barbarians */
925 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
927 &(const struct req_context) {
928 .player = city_owner(pcity),
929 .city = pcity,
930 .tile = city_tile(pcity),
931 .unittype = punittype,
932 },
933 nullptr,
934 &punittype->build_reqs, prob_type)) {
935 return FALSE;
936 }
937
938 /* You can't build naval units inland. */
941 pcity->tile)) {
942 return FALSE;
943 }
944
945 if (punittype->city_slots > 0
946 && city_unit_slots_available(pcity) < punittype->city_slots) {
947 return FALSE;
948 }
949
950 return TRUE;
951}
952
953/**********************************************************************/
958 const struct city *pcity,
959 const struct unit_type *punittype,
960 const enum req_problem_type prob_type)
961{
963 return FALSE;
964 }
965
966 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
967 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
968 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
970 prob_type, TRUE)) {
971 return FALSE;
972 }
973 }
974
975 return TRUE;
976}
977
978/**********************************************************************/
983 const struct city *pcity,
984 const struct unit_type *punittype)
985{
986 /* Can the _player_ ever build this unit? */
988 return FALSE;
989 }
990
991 /* Some units can be built only in certain cities -- for instance,
992 ships may be built only in cities adjacent to ocean. */
995 pcity->tile)) {
996 return FALSE;
997 }
998
999 return TRUE;
1000}
1001
1002/**********************************************************************/
1007 const struct city *pcity,
1008 const struct universal *target,
1009 const enum req_problem_type prob_type)
1010{
1011 switch (target->kind) {
1012 case VUT_UTYPE:
1014 prob_type);
1015 case VUT_IMPROVEMENT:
1017 prob_type);
1018 default:
1019 break;
1020 };
1021 return FALSE;
1022}
1023
1024/**********************************************************************/
1029 const struct city *pcity,
1030 const struct universal *target,
1031 const enum req_problem_type prob_type)
1032{
1033 switch (target->kind) {
1034 case VUT_UTYPE:
1035 return can_city_build_unit_now(nmap, pcity, target->value.utype,
1036 prob_type);
1037 case VUT_IMPROVEMENT:
1039 prob_type);
1040 default:
1041 break;
1042 };
1043 return FALSE;
1044}
1045
1046/**********************************************************************/
1050 const struct city *pcity,
1051 const struct universal *target)
1052{
1053 switch (target->kind) {
1054 case VUT_UTYPE:
1056 case VUT_IMPROVEMENT:
1058 default:
1059 break;
1060 };
1061 return FALSE;
1062}
1063
1064/**********************************************************************/
1068{
1070 int current;
1071
1072 current = 0;
1073 unit_list_iterate(pcity->units_supported, punit) {
1074 current += unit_type_get(punit)->city_slots;
1076
1077 return max - current;
1078}
1079
1080/**********************************************************************/
1085{
1086 return are_reqs_active(&(const struct req_context) {
1087 .player = city_owner(pcity),
1088 .city = pcity,
1089 },
1090 nullptr,
1092}
1093
1094/**********************************************************************/
1098{
1099 return !pcity->did_buy || pcity->shield_stock <= 0;
1100}
1101
1102/**********************************************************************/
1106{
1107 if (city_tile(pcity) == nullptr) {
1108 /* When a "dummy" city is created with no tile, then choosing a build
1109 * target could fail. This currently might happen during map editing.
1110 * FIXME: Assumes the first unit is always "valid", so check for
1111 * obsolete units elsewhere. */
1112 pcity->production.kind = VUT_UTYPE;
1113 pcity->production.value.utype = utype_by_number(0);
1114 } else {
1116
1117 if (u) {
1118 pcity->production.kind = VUT_UTYPE;
1119 pcity->production.value.utype = u;
1120 } else {
1121 bool found = FALSE;
1122
1123 /* Just pick the first available item. */
1124 improvement_iterate(pimprove) {
1126 RPT_CERTAIN)) {
1127 found = TRUE;
1128 pcity->production.kind = VUT_IMPROVEMENT;
1129 pcity->production.value.building = pimprove;
1130 break;
1131 }
1133
1134 if (!found) {
1137 RPT_CERTAIN)) {
1138#ifndef FREECIV_NDEBUG
1139 /* Later than this, 'found' is only needed in an fc_assert() */
1140 found = TRUE;
1141#endif /* FREECIV_NDEBUG */
1142 pcity->production.kind = VUT_UTYPE;
1143 pcity->production.value.utype = punittype;
1144 }
1146 }
1147
1148 fc_assert_msg(found, "No production found for city %s!",
1150 }
1151 }
1152}
1153
1154/**********************************************************************/
1157const char *city_name_get(const struct city *pcity)
1158{
1159 return (pcity->name != nullptr) ? pcity->name : "City missing a name";
1160}
1161
1162/**********************************************************************/
1165#define POLLUTION_EFT_NEARMAX -95
1166const char *city_name_getx(const struct city *pcity)
1167{
1168 bool spacer = FALSE;
1169 static char em_city_name[MAX_LEN_CITYNAME + 7];
1170
1171 em_city_name[0] = '\0';
1172
1174 sz_strlcat(em_city_name, "ₓ"); /* ₓ🞪⁻⁰… (alternatives)*/
1175 }
1176
1178
1179 if (get_city_bonus(pcity, EFT_AIRLIFT) > 0) {
1180 sz_strlcat(em_city_name, " 🛧"); /* 🛧🛪 (alternatives)*/
1181 spacer = TRUE;
1182 }
1183
1185 if (!spacer) {
1187 }
1188 sz_strlcat(em_city_name, "♺"); /* ♺♻♳ (alternatives)*/
1189 }
1190
1191 return em_city_name;
1192}
1193
1194/**********************************************************************/
1197void city_name_set(struct city *pcity, const char *new_name)
1198{
1199 if (pcity->name != nullptr) {
1200 free(pcity->name);
1201 }
1202
1203 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1204 pcity->name = fc_strdup(new_name);
1205 } else {
1206 log_warn(_("City name \"%s\" too long"), new_name);
1208 sz_strlcpy(pcity->name, new_name);
1209 }
1210}
1211
1212/**********************************************************************/
1216void city_size_add(struct city *pcity, int add)
1217{
1219
1220 fc_assert_ret(pcity != nullptr);
1222
1223 /* Client sets size to zero to start stacking citizens in */
1224 fc_assert_ret(size > -add || (!is_server() && size == add));
1225
1226 city_size_set(pcity, size + add);
1227}
1228
1229/**********************************************************************/
1233{
1234 fc_assert_ret(pcity != nullptr);
1235
1236 /* Set city size. */
1237 pcity->size = size;
1238}
1239
1240/**********************************************************************/
1243int city_population(const struct city *pcity)
1244{
1245 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1246 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1247}
1248
1249/**********************************************************************/
1254{
1255 int gold_needed = 0;
1256
1257 if (pcity == nullptr) {
1258 return 0;
1259 }
1260
1261 city_built_iterate(pcity, pimprove) {
1262 gold_needed += city_improvement_upkeep(pcity, pimprove);
1264
1266
1267 return MAX(gold_needed, 0);
1268}
1269
1270/**********************************************************************/
1275{
1276 int gold_needed = 0;
1277
1278 if (pcity == nullptr || pcity->units_supported == nullptr) {
1279 return 0;
1280 }
1281
1282 unit_list_iterate(pcity->units_supported, punit) {
1283 gold_needed += punit->upkeep[O_GOLD];
1285
1286 return gold_needed;
1287}
1288
1289/**********************************************************************/
1292bool city_has_building(const struct city *pcity,
1293 const struct impr_type *pimprove)
1294{
1295 if (pimprove == nullptr) {
1296 /* Callers should ensure that any external data is tested with
1297 * valid_improvement_by_number() */
1298 return FALSE;
1299 }
1300
1301 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1302}
1303
1304/**********************************************************************/
1309 const struct impr_type *b)
1310{
1311 int upkeep;
1312
1313 if (b == nullptr) {
1314 return 0;
1315 }
1316 if (!is_building_sellable(b)) {
1317 return 0;
1318 }
1319
1320 upkeep = b->upkeep;
1322 return 0;
1323 }
1324
1325 return upkeep;
1326}
1327
1328/**********************************************************************/
1336int city_tile_output(const struct city *pcity, const struct tile *ptile,
1338{
1339 int prod;
1340 const struct req_context city_ctxt = {
1341 .player = pcity ? city_owner(pcity) : nullptr,
1342 .city = pcity,
1343 .tile = ptile,
1344 };
1345 struct terrain *pterrain = tile_terrain(ptile);
1346 const struct output_type *output = &output_types[otype];
1347
1348 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1349
1350 if (T_UNKNOWN == pterrain) {
1351 /* Special case for the client. The server doesn't allow unknown tiles
1352 * to be worked but we don't necessarily know what player is involved. */
1353 return 0;
1354 }
1355
1356 prod = pterrain->output[otype];
1357 if (tile_resource_is_valid(ptile)) {
1358 prod += tile_resource(ptile)->data.resource->output[otype];
1359 }
1360
1361 switch (otype) {
1362 case O_SHIELD:
1363 if (pterrain->mining_shield_incr != 0) {
1364 prod += pterrain->mining_shield_incr
1366 / 100;
1367 }
1368 break;
1369 case O_FOOD:
1370 if (pterrain->irrigation_food_incr != 0) {
1371 prod += pterrain->irrigation_food_incr
1372 * get_target_bonus_effects(nullptr, &city_ctxt, nullptr,
1373 EFT_IRRIGATION_PCT) / 100;
1374 }
1375 break;
1376 case O_TRADE:
1377 case O_GOLD:
1378 case O_SCIENCE:
1379 case O_LUXURY:
1380 case O_LAST:
1381 break;
1382 }
1383
1384 prod += tile_roads_output_incr(ptile, otype);
1385 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1386
1387 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1388 if (prod > 0) {
1389 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1391
1392 if (prod >= game.info.granularity) {
1393 prod += get_tile_output_bonus(pcity, ptile, output,
1395
1396 if (is_celebrating) {
1397 prod += get_tile_output_bonus(pcity, ptile, output,
1399 }
1400 }
1401
1402 prod += (prod
1403 * get_tile_output_bonus(pcity, ptile, output,
1405 / 100;
1406 if (penalty_limit > 0 && prod > penalty_limit) {
1407 if (prod <= game.info.granularity) {
1408 prod = 0;
1409 } else {
1410 prod -= game.info.granularity;
1411 }
1412 }
1413 }
1414
1415 prod -= (prod
1416 * get_tile_output_bonus(pcity, ptile, output,
1418 / 100;
1419
1420 if (pcity != nullptr && is_city_center(pcity, ptile)) {
1421 prod = MAX(prod, game.info.min_city_center_output[otype]);
1422 }
1423
1424 return prod;
1425}
1426
1427/**********************************************************************/
1437int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1439{
1441}
1442
1443/**********************************************************************/
1455 const struct city *pcity,
1456 const struct tile *ptile)
1457{
1458 struct player *powner = city_owner(pcity);
1460 struct player *towner;
1461
1462 if (ptile == nullptr) {
1463 return FALSE;
1464 }
1465
1467 return FALSE;
1468 }
1469
1470 if (restriction != nullptr
1471 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1472 return FALSE;
1473 }
1474
1475 towner = tile_owner(ptile);
1476 if (towner != nullptr && towner != powner
1477 && !gives_shared_tiles(towner, powner)) {
1478 return FALSE;
1479 }
1480 /* TODO: civ3-like option for borders */
1481
1482 if (tile_worked(ptile) != nullptr && tile_worked(ptile) != pcity) {
1483 return FALSE;
1484 }
1485
1486 if (powner == restriction
1487 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1488 return FALSE;
1489 }
1490
1491 if (!is_free_worked(pcity, ptile)
1492 && unit_occupies_tile(ptile, powner) != nullptr) {
1493 return FALSE;
1494 }
1495
1496 if (get_city_tile_output_bonus(pcity, ptile, nullptr, EFT_TILE_WORKABLE) <= 0) {
1497 return FALSE;
1498 }
1499
1500 return TRUE;
1501}
1502
1503/**********************************************************************/
1509bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1510{
1512}
1513
1514/**********************************************************************/
1519 const struct tile *ptile)
1520{
1521 /* citymindist minimum is 1, meaning adjacent is okay */
1522 int citymindist = game.info.citymindist;
1523
1524 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1525 if (tile_city(ptile1)) {
1526 return TRUE;
1527 }
1529
1530 return FALSE;
1531}
1532
1533/**********************************************************************/
1541 const struct tile *ptile,
1542 const struct unit *punit,
1543 bool hut_test)
1544{
1545 if (!city_can_be_built_tile_only(nmap, ptile)) {
1546 return FALSE;
1547 }
1548
1549 if (punit == nullptr) {
1550 /* The remaining checks tests if punit can found a city here */
1551 return TRUE;
1552 }
1553
1554 if (hut_test) {
1555 struct player *towner;
1556
1557 /* Huts can be found only from native tiles, owned by the unit owner.
1558 * Unlike actual city building, this behavior is not affected
1559 * by the ruleset. */
1560 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1561 return FALSE;
1562 }
1563
1564 towner = tile_owner(ptile);
1565
1566 if (towner == nullptr || towner == unit_owner(punit)) {
1567 return TRUE;
1568 }
1569
1570 return FALSE;
1571 }
1572
1575 /* This action can't be done by this unit type at all. */
1576 continue;
1577 }
1578
1579 /* Non native tile detection */
1580 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1581 /* The ruleset may allow founding cities on non native terrain. */
1584 /* Many rulesets allow land units to build land cities and sea units
1585 * to build ocean cities. Air units can build cities anywhere. */
1586 continue;
1587 }
1588
1589 /* Foreign tile detection. */
1590 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1591 /* The ruleset may allow founding cities on foreign terrain. */
1593 paction->id,
1594 DRO_FOREIGN, TRUE)) {
1595 /* Cannot steal borders by settling. This has to be settled by
1596 * force of arms. */
1597 continue;
1598 }
1599
1600 return TRUE;
1602
1603 return FALSE;
1604}
1605
1606/**********************************************************************/
1614 const struct tile *ptile)
1615{
1617 /* No cities on this terrain. */
1618 return FALSE;
1619 }
1620
1622 return FALSE;
1623 }
1624
1625 return TRUE;
1626}
1627
1628/**********************************************************************/
1632bool is_capital(const struct city *pcity)
1633{
1634 return pcity->capital != CAPITAL_NOT;
1635}
1636
1637/**********************************************************************/
1640bool is_gov_center(const struct city *pcity)
1641{
1642 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1643}
1644
1645/**********************************************************************/
1650 const struct unit_type *attacker)
1651{
1652 if (!attacker) {
1653 /* Any defense building will do */
1655 }
1656
1657 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1658 nullptr, EFT_DEFEND_BONUS) > 0;
1659}
1660
1661/**********************************************************************/
1667bool city_happy(const struct city *pcity)
1668{
1670 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1671 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1672 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1673}
1674
1675/**********************************************************************/
1679bool city_unhappy(const struct city *pcity)
1680{
1681 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1683 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1684}
1685
1686/**********************************************************************/
1691{
1692 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1693}
1694
1695/**********************************************************************/
1698bool city_celebrating(const struct city *pcity)
1699{
1701}
1702
1703/**********************************************************************/
1706bool city_rapture_grow(const struct city *pcity)
1707{
1708 /* .rapture is checked instead of city_celebrating() because this
1709 function is called after .was_happy was updated. */
1710 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1711 && (pcity->rapture % game.info.rapturedelay) == 0
1713}
1714
1715/**********************************************************************/
1718bool city_is_occupied(const struct city *pcity)
1719{
1720 if (is_server()) {
1721 /* The server sees the units inside the city. */
1722 return (unit_list_size(city_tile(pcity)->units) > 0);
1723 } else {
1724 /* The client gets the occupied property from the server. */
1725 return pcity->client.occupied;
1726 }
1727}
1728
1729/**********************************************************************/
1732struct city *city_list_find_number(struct city_list *This, int id)
1733{
1734 if (id != 0) {
1736 if (pcity->id == id) {
1737 return pcity;
1738 }
1740 }
1741
1742 return nullptr;
1743}
1744
1745/**********************************************************************/
1748struct city *city_list_find_name(struct city_list *This, const char *name)
1749{
1751 if (fc_strcasecmp(name, pcity->name) == 0) {
1752 return pcity;
1753 }
1755
1756 return nullptr;
1757}
1758
1759/**********************************************************************/
1764int city_name_compare(const void *p1, const void *p2)
1765{
1766 return fc_strcasecmp((*(const struct city **) p1)->name,
1767 (*(const struct city **) p2)->name);
1768}
1769
1770/**********************************************************************/
1775{
1776 int i;
1777
1778 for (i = 0; i < game.control.num_city_styles; i++) {
1779 if (0 == strcmp(city_style_name_translation(i), s)) {
1780 return i;
1781 }
1782 }
1783
1784 return -1;
1785}
1786
1787/**********************************************************************/
1791int city_style_by_rule_name(const char *s)
1792{
1793 const char *qs = Qn_(s);
1794 int i;
1795
1796 for (i = 0; i < game.control.num_city_styles; i++) {
1797 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1798 return i;
1799 }
1800 }
1801
1802 return -1;
1803}
1804
1805/**********************************************************************/
1810{
1812}
1813
1814/**********************************************************************/
1818const char *city_style_rule_name(const int style)
1819{
1821}
1822
1823/* Cache of what city production caravan shields are allowed to help. */
1826
1827/**********************************************************************/
1832{
1833 struct requirement prod_as_req;
1834
1835#define log_ca_s_init log_debug
1836
1837 /* Remove old data. */
1840
1841 /* Common for all production kinds. */
1843 prod_as_req.survives = FALSE;
1844 prod_as_req.present = TRUE;
1845
1846 /* Check improvements */
1847 prod_as_req.source.kind = VUT_IMPROVEMENT;
1848
1850 /* Check this improvement. */
1851 prod_as_req.source.value.building = itype;
1852
1855 enabler) {
1857 &(enabler->target_reqs))
1858 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1859 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1860 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1861 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1862 /* This improvement kind can receive caravan shields. */
1863
1865
1866 /* Move on to the next improvement */
1867 break;
1868 }
1870
1871 log_ca_s_init("Help Wonder: %s for %s",
1873 ? "possible" : "impossible"),
1876
1877 /* Check units. */
1878 prod_as_req.source.kind = VUT_UTYPE;
1879
1881 /* Check this utype. */
1882 prod_as_req.source.value.utype = putype;
1883
1886 enabler) {
1888 &(enabler->target_reqs))
1889 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1890 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1891 /* This unit type kind can receive caravan shields. */
1892
1894
1895 /* Move on to the next unit type */
1896 break;
1897 }
1899
1900 log_ca_s_init("Help Wonder: %s for %s",
1902 ? "possible" : "impossible"),
1905
1906#undef log_ca_s_init
1907}
1908
1909/**********************************************************************/
1914{
1915 switch (tgt->kind) {
1916 case VUT_IMPROVEMENT:
1919 case VUT_UTYPE:
1921 utype_index(tgt->value.utype));
1922 default:
1924 return FALSE;
1925 };
1926}
1927
1928/**********************************************************************/
1940 const struct universal *target)
1941{
1946
1947 switch (pcity->changed_from.kind) {
1948 case VUT_IMPROVEMENT:
1949 if (is_wonder(pcity->changed_from.value.building)) {
1951 } else {
1953 }
1954 break;
1955 case VUT_UTYPE:
1957 break;
1958 default:
1960 break;
1961 };
1962
1963 switch (target->kind) {
1964 case VUT_IMPROVEMENT:
1965 if (is_wonder(target->value.building)) {
1967 } else {
1969 }
1970 break;
1971 case VUT_UTYPE:
1973 break;
1974 default:
1976 break;
1977 };
1978
1979 /* Changing production is penalized under certain circumstances. */
1980 if (orig_class == new_class
1981 || orig_class == PCT_LAST) {
1982 /* There's never a penalty for building something of the same class. */
1983 unpenalized_shields = pcity->before_change_shields;
1984 } else if (city_built_last_turn(pcity)) {
1985 /* Surplus shields from the previous production won't be penalized if
1986 * you change production on the very next turn. But you can only use
1987 * up to the city's surplus amount of shields in this way. */
1988 unpenalized_shields = MIN(pcity->last_turns_shield_surplus,
1989 pcity->before_change_shields);
1990 penalized_shields = pcity->before_change_shields - unpenalized_shields;
1991 } else {
1992 /* Penalize 50% of the production. */
1993 penalized_shields = pcity->before_change_shields;
1994 }
1995
1996 /* Do not put penalty on these. It shouldn't matter whether you disband unit
1997 before or after changing production...*/
1998 unpenalized_shields += pcity->disbanded_shields;
1999
2000 /* Caravan shields are penalized (just as if you disbanded the caravan)
2001 * if you're not building a wonder. */
2003 unpenalized_shields += pcity->caravan_shields;
2004 } else {
2005 penalized_shields += pcity->caravan_shields;
2006 }
2007
2010
2012}
2013
2014/**********************************************************************/
2019 const struct universal *target,
2021{
2022 int city_shield_surplus = pcity->surplus[O_SHIELD];
2025 int cost = universal_build_shield_cost(pcity, target);
2026
2027 if (target->kind == VUT_IMPROVEMENT
2028 && is_great_wonder(target->value.building)
2030 return FC_INFINITY;
2031 }
2032
2034 return 1;
2035 } else if (city_shield_surplus > 0) {
2036 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
2037 } else {
2038 return FC_INFINITY;
2039 }
2040}
2041
2042/**********************************************************************/
2050{
2051 int food_stock = pcity->food_stock;
2052 int surplus = pcity->surplus[O_FOOD];
2053 int granary_size = city_granary_size(city_size_get(pcity));
2054
2055 if (food_stock + surplus >= granary_size) {
2057 return 1;
2058 } else {
2059 return 0;
2060 }
2061 }
2062 if (surplus > 0) {
2063 /* It was possible for the numerator in this calculation to be
2064 * negative, e.g. the city just lost pop due to a disaster and now
2065 * the granary_size is smaller than the food_stock. In that case, the
2066 * returned value was wrong, so now we do that first test. */
2067 return (granary_size - food_stock + surplus - 1) / surplus;
2068 }
2069 if (surplus < 0) {
2070 /* Turns before famine loss */
2071 return -1 + (food_stock / surplus);
2072 }
2073 return FC_INFINITY;
2074}
2075
2076/**********************************************************************/
2079bool city_can_grow_to(const struct city *pcity, int pop_size)
2080{
2083}
2084
2085/**********************************************************************/
2088struct city *tile_enemy_city(const struct tile *ptile,
2089 const struct player *pplayer)
2090{
2091 struct city *pcity = tile_city(ptile);
2092
2093 if (pcity != nullptr && pplayers_at_war(pplayer, city_owner(pcity))) {
2094 return pcity;
2095 }
2096
2097 return nullptr;
2098}
2099
2100/**********************************************************************/
2103struct city *tile_allied_city(const struct tile *ptile,
2104 const struct player *pplayer)
2105{
2106 struct city *pcity = tile_city(ptile);
2107
2108 if (pcity != nullptr && pplayers_allied(pplayer, city_owner(pcity))) {
2109 return pcity;
2110 }
2111
2112 return nullptr;
2113}
2114
2115/**********************************************************************/
2118struct city *tile_non_attack_city(const struct tile *ptile,
2119 const struct player *pplayer)
2120{
2121 struct city *pcity = tile_city(ptile);
2122
2123 if (pcity != nullptr && pplayers_non_attack(pplayer, city_owner(pcity))) {
2124 return pcity;
2125 }
2126
2127 return nullptr;
2128}
2129
2130/**********************************************************************/
2133struct city *tile_non_allied_city(const struct tile *ptile,
2134 const struct player *pplayer)
2135{
2136 struct city *pcity = tile_city(ptile);
2137
2138 if (pcity != nullptr && !pplayers_allied(pplayer, city_owner(pcity))) {
2139 return pcity;
2140 }
2141
2142 return nullptr;
2143}
2144
2145/**********************************************************************/
2149 const struct unit *punit,
2150 int distance)
2151{
2153 distance);
2154}
2155
2156/**********************************************************************/
2160 const struct player *owner,
2161 const struct tile *ptile,
2162 int distance)
2163{
2164 square_iterate(nmap, ptile, distance, ptile1) {
2165 struct city *pcity = tile_city(ptile1);
2166
2168 return TRUE;
2169 }
2171
2172 return FALSE;
2173}
2174
2175/**********************************************************************/
2180 const struct tile *ptile,
2181 bool may_be_on_center)
2182{
2184 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2185 if (tile_city(ptile1)) {
2186 return TRUE;
2187 }
2188 }
2190
2191 return FALSE;
2192}
2193
2194/**********************************************************************/
2199int city_granary_size(int city_size)
2200{
2203 int base_value;
2204
2205 /* If the city has no citizens, there is no granary. */
2206 if (city_size == 0) {
2207 return 0;
2208 }
2209
2210 /* Granary sizes for the first food_inis citizens are given directly.
2211 * After that we increase the granary size by food_inc per citizen. */
2212 if (city_size > food_inis) {
2213 base_value = game.info.granary_food_ini[food_inis - 1];
2214 base_value += food_inc * (city_size - food_inis);
2215 } else {
2216 base_value = game.info.granary_food_ini[city_size - 1];
2217 }
2218
2219 return MAX(base_value * game.info.foodbox / 100, 1);
2220}
2221
2222/**********************************************************************/
2227static int player_base_citizen_happiness(const struct player *pplayer)
2228{
2229 int cities = city_list_size(pplayer->cities);
2230 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2233
2234 if (basis + step <= 0) {
2235 /* Value of zero means effect is inactive */
2236 return content;
2237 }
2238
2239 if (cities > basis) {
2240 content--;
2241 if (step != 0) {
2242 /* the first penalty is at (basis + 1) cities;
2243 the next is at (basis + step + 1), _not_ (basis + step) */
2244 content -= (cities - basis - 1) / step;
2245 }
2246 }
2247 return content;
2248}
2249
2250/**********************************************************************/
2254{
2255 int content = player_base_citizen_happiness(pplayer);
2256
2257 return CLIP(0, content, MAX_CITY_SIZE);
2258}
2259
2260/**********************************************************************/
2264{
2265 if (!game.info.angrycitizen) {
2266 return 0;
2267 } else {
2268 /* Create angry citizens only if we have a negative number of possible
2269 * content citizens. This can happen when empires grow really big. */
2270 int content = player_base_citizen_happiness(pplayer);
2271
2272 return CLIP(0, -content, MAX_CITY_SIZE);
2273 }
2274}
2275
2276/**********************************************************************/
2280{
2281 struct output_type *output = &output_types[otype];
2282 int bonus1 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2284 int bonus2 = 100 + get_city_tile_output_bonus(pcity, nullptr, output,
2286
2287 return MAX(bonus1 * bonus2 / 100, 0);
2288}
2289
2290/**********************************************************************/
2295{
2296 int tithes_bonus = 0;
2297
2299 return 0;
2300 }
2301
2304
2305 return tithes_bonus;
2306}
2307
2308/**********************************************************************/
2312void add_tax_income(const struct player *pplayer, int trade, int *output)
2313{
2314 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2315 unsigned rates[3];
2316 int result[3];
2317
2318 if (game.info.changable_tax) {
2319 rates[SCIENCE] = pplayer->economic.science;
2320 rates[LUXURY] = pplayer->economic.luxury;
2321 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2322 } else {
2326 }
2327
2328 /* ANARCHY */
2330 rates[SCIENCE] = 0;
2331 rates[LUXURY] = 100;
2332 rates[TAX] = 0;
2333 }
2334
2335 distribute(trade, 3, rates, result);
2336
2337 output[O_SCIENCE] += result[SCIENCE];
2338 output[O_GOLD] += result[TAX];
2339 output[O_LUXURY] += result[LUXURY];
2340}
2341
2342/**********************************************************************/
2347{
2348 return pcity->turn_last_built + 1 >= game.info.turn;
2349}
2350
2351/**********************************************************************/
2354static const struct city *nearest_gov_center(const struct city *pcity,
2355 int *min_dist)
2356{
2357 const struct city *gov_center = nullptr;
2358
2360
2361 /* Check the special case that city itself is gov center
2362 * before expensive iteration through all cities. */
2363 if (is_gov_center(pcity)) {
2364 *min_dist = 0;
2365 return pcity;
2366 } else {
2368 /* Do not recheck current city */
2369 if (gc != pcity && is_gov_center(gc)) {
2370 int dist = real_map_distance(gc->tile, pcity->tile);
2371
2372 if (dist < *min_dist) {
2373 gov_center = gc;
2374 *min_dist = dist;
2375 }
2376 }
2378 }
2379
2380 return gov_center;
2381}
2382
2383/**********************************************************************/
2391static inline void get_worked_tile_output(const struct civ_map *nmap,
2392 const struct city *pcity,
2393 int *output, bool *workers_map)
2394{
2395 bool is_worked;
2396#ifdef CITY_DEBUGGING
2398#endif
2399 struct tile *pcenter = city_tile(pcity);
2400
2401 memset(output, 0, O_LAST * sizeof(*output));
2402
2405 if (workers_map == nullptr) {
2406 struct city *pwork = tile_worked(ptile);
2407
2408 is_worked = (pwork != nullptr && pwork == pcity);
2409 } else {
2410 is_worked = workers_map[city_tile_index];
2411 }
2412
2413 if (is_worked) {
2415#ifdef CITY_DEBUGGING
2416 /* This assertion never fails, but it's so slow that we disable
2417 * it by default. */
2419 == city_tile_output(pcity, ptile, is_celebrating, o));
2420#endif /* CITY_DEBUGGING */
2423 }
2425}
2426
2427/**********************************************************************/
2431void add_specialist_output(const struct city *pcity, int *output)
2432{
2434 int count = pcity->specialists[sp];
2435
2438
2439 output[stat_index] += count * amount;
2442}
2443
2444/**********************************************************************/
2453static inline void set_city_bonuses(struct city *pcity)
2454{
2457 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2458 &output_types[o],
2460 /* Total bonus cannot be negative, as that could lead to unresolvable
2461 * negative balance. */
2462 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2464}
2465
2466/**********************************************************************/
2476static inline void city_tile_cache_update(const struct civ_map *nmap,
2477 struct city *pcity)
2478{
2480 int radius_sq = city_map_radius_sq_get(pcity);
2481
2482 /* Initialize tile_cache if needed */
2483 if (pcity->tile_cache == nullptr || pcity->tile_cache_radius_sq == -1
2484 || pcity->tile_cache_radius_sq != radius_sq) {
2485 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2486 city_map_tiles(radius_sq)
2487 * sizeof(*(pcity->tile_cache)));
2488 pcity->tile_cache_radius_sq = radius_sq;
2489 }
2490
2491 /* Any unreal tiles are skipped - these values should have been memset
2492 * to 0 when the city was created. */
2493 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2495 (pcity->tile_cache[city_tile_index]).output[o]
2499}
2500
2501/**********************************************************************/
2505static inline int city_tile_cache_get_output(const struct city *pcity,
2506 int city_tile_index,
2507 enum output_type_id o)
2508{
2509 fc_assert_ret_val(pcity->tile_cache_radius_sq
2512
2513 return (pcity->tile_cache[city_tile_index]).output[o];
2514}
2515
2516/**********************************************************************/
2519static void set_surpluses(struct city *pcity)
2520{
2522 int surplus = pcity->prod[o] - pcity->usage[o];
2523
2524 /* Add 'surplus' waste to 'usage'. */
2525 if (surplus > 0) {
2526 struct output_type *output = get_output_type(o);
2530
2531 if (waste_by_rel_dist > 0) {
2532 int min_dist;
2533 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2534
2535 if (gov_center == nullptr) {
2536 /* No gov center - no income */
2537 waste_level = 100;
2538 } else {
2539 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2541 }
2542 }
2543
2544 if (waste_level > 0) {
2545 if (waste_level < 100) {
2546 pcity->usage[o] += (surplus * waste_level / 100);
2547 } else {
2548 pcity->usage[o] = pcity->prod[o];
2549 }
2550 }
2551 }
2552
2553 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2555}
2556
2557/**********************************************************************/
2560static void happy_copy(struct city *pcity, enum citizen_feeling i)
2561{
2562 int c = 0;
2563
2564 for (; c < CITIZEN_LAST; c++) {
2565 pcity->feel[c][i] = pcity->feel[c][i - 1];
2566 }
2567}
2568
2569/**********************************************************************/
2572static void citizen_base_mood(struct city *pcity)
2573{
2574 struct player *pplayer = city_owner(pcity);
2575 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2576 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2577 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2578 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2581
2582 /* This is the number of citizens that may start out content, depending
2583 * on empire size and game's city unhappysize. This may be bigger than
2584 * the size of the city, since this is a potential. */
2586 /* Similarly, this is the potential number of angry citizens. */
2588
2589 /* Create content citizens. Take specialists from their ranks. */
2590 *content = MAX(0, MIN(size, base_content) - spes);
2591
2592 /* Create angry citizens. Specialists never become angry. */
2593 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2594 *angry = MIN(base_angry, size - spes);
2595
2596 /* Create unhappy citizens. In the beginning, all who are not content,
2597 * specialists or angry are unhappy. This is changed by luxuries and
2598 * buildings later. */
2599 *unhappy = (size - spes - *content - *angry);
2600
2601 /* No one is born happy. */
2602 *happy = 0;
2603}
2604
2605/**********************************************************************/
2611static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2612{
2613 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2614 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2615 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2616 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2617
2618 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2619 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2620 (*angry)--;
2621 (*unhappy)++;
2623 }
2624 while (*luxuries >= game.info.happy_cost && *content > 0) {
2625 /* Upgrade content to happy: costs HAPPY_COST each. */
2626 (*content)--;
2627 (*happy)++;
2629 }
2630 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2631 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2632 * double the cost. */
2633 (*unhappy)--;
2634 (*happy)++;
2635 *luxuries -= 2 * game.info.happy_cost;
2636 }
2637 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2638 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2639 (*unhappy)--;
2640 (*content)++;
2642 }
2643}
2644
2645/**********************************************************************/
2648static inline void citizen_happy_luxury(struct city *pcity)
2649{
2650 int x = pcity->prod[O_LUXURY];
2651
2653}
2654
2655/**********************************************************************/
2658static inline void citizen_content_buildings(struct city *pcity)
2659{
2660 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2661 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2662 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2664
2665 /* make people content (but not happy):
2666 get rid of angry first, then make unhappy content. */
2667 while (faces > 0 && *angry > 0) {
2668 (*angry)--;
2669 (*unhappy)++;
2670 faces--;
2671 }
2672 while (faces > 0 && *unhappy > 0) {
2673 (*unhappy)--;
2674 (*content)++;
2675 faces--;
2676 }
2677}
2678
2679/**********************************************************************/
2682static inline void citizen_happiness_nationality(struct city *pcity)
2683{
2687
2690
2691 if (pct > 0) {
2692 int enemies = 0;
2693 int unhappy_inc;
2694 struct player *owner = city_owner(pcity);
2695
2696 citizens_foreign_iterate(pcity, pslot, nationality) {
2698 enemies += nationality;
2699 }
2701
2702 unhappy_inc = enemies * pct / 100;
2703
2704 /* First make content => unhappy, then happy => unhappy,
2705 * then happy => content. No-one becomes angry. */
2706 while (unhappy_inc > 0 && *content > 0) {
2707 (*content)--;
2708 (*unhappy)++;
2709 unhappy_inc--;
2710 }
2711 while (unhappy_inc > 1 && *happy > 0) {
2712 (*happy)--;
2713 (*unhappy)++;
2714 unhappy_inc -= 2;
2715 }
2716 while (unhappy_inc > 0 && *happy > 0) {
2717 (*happy)--;
2718 (*content)++;
2719 unhappy_inc--;
2720 }
2721 }
2722 }
2723}
2724
2725/**********************************************************************/
2731static inline void citizen_happy_units(struct city *pcity)
2732{
2733 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2734 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2735 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2736 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2737 citizens amt = pcity->martial_law;
2738
2739 /* Pacify discontent citizens through martial law. First convert
2740 * angry => unhappy, then unhappy => content. */
2741 while (amt > 0 && *angry > 0) {
2742 (*angry)--;
2743 (*unhappy)++;
2744 amt--;
2745 }
2746 while (amt > 0 && *unhappy > 0) {
2747 (*unhappy)--;
2748 (*content)++;
2749 amt--;
2750 }
2751
2752 /* Now make citizens unhappier because of military units away from home.
2753 * First make content => unhappy, then happy => unhappy,
2754 * then happy => content. */
2755 amt = pcity->unit_happy_upkeep;
2756 while (amt > 0 && *content > 0) {
2757 (*content)--;
2758 (*unhappy)++;
2759 amt--;
2760 }
2761 while (amt > 1 && *happy > 0) {
2762 (*happy)--;
2763 (*unhappy)++;
2764 amt -= 2;
2765 }
2766 while (amt > 0 && *happy > 0) {
2767 (*happy)--;
2768 (*content)++;
2769 amt--;
2770 }
2771 /* Any remaining unhappiness is lost since angry citizens aren't created
2772 * here. */
2773 /* FIXME: Why not? - Per */
2774}
2775
2776/**********************************************************************/
2779static inline void citizen_happy_wonders(struct city *pcity)
2780{
2781 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2782 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2783 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2784 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2785 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2786
2787 /* First create happy citizens from content, then from unhappy
2788 * citizens; we cannot help angry citizens here. */
2789 while (bonus > 0 && *content > 0) {
2790 (*content)--;
2791 (*happy)++;
2792 bonus--;
2793 }
2794 while (bonus > 1 && *unhappy > 0) {
2795 (*unhappy)--;
2796 (*happy)++;
2797 bonus -= 2;
2798 }
2799 /* The rest falls through and lets unhappy people become content. */
2800
2802 *content += *unhappy + *angry;
2803 *unhappy = 0;
2804 *angry = 0;
2805 return;
2806 }
2807
2809
2810 /* get rid of angry first, then make unhappy content */
2811 while (bonus > 0 && *angry > 0) {
2812 (*angry)--;
2813 (*unhappy)++;
2814 bonus--;
2815 }
2816 while (bonus > 0 && *unhappy > 0) {
2817 (*unhappy)--;
2818 (*content)++;
2819 bonus--;
2820 }
2821}
2822
2823/**********************************************************************/
2827static inline void unhappy_city_check(struct city *pcity)
2828{
2829 if (city_unhappy(pcity)) {
2831 switch (output_types[o].unhappy_penalty) {
2833 pcity->unhappy_penalty[o] = 0;
2834 break;
2836 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2837 break;
2839 pcity->unhappy_penalty[o] = pcity->prod[o];
2840 break;
2841 }
2842
2843 pcity->prod[o] -= pcity->unhappy_penalty[o];
2845 } else {
2846 memset(pcity->unhappy_penalty, 0,
2847 O_LAST * sizeof(*pcity->unhappy_penalty));
2848 }
2849}
2850
2851/**********************************************************************/
2855 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2856{
2857 int prod, pop, mod;
2858
2859 /* Add one one pollution per shield, multiplied by the bonus. */
2861 prod = shield_total * MAX(prod, 0) / 100;
2862
2863 /* Add one pollution per citizen for baseline combined bonus (100%). */
2866 / 100;
2867 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2868
2869 /* Then there is base pollution (usually a negative number). */
2870 mod = game.info.base_pollution;
2871
2872 if (pollu_prod) {
2873 *pollu_prod = prod;
2874 }
2875 if (pollu_pop) {
2876 *pollu_pop = pop;
2877 }
2878 if (pollu_mod) {
2879 *pollu_mod = mod;
2880 }
2881 return MAX(prod + pop + mod, 0);
2882}
2883
2884/**********************************************************************/
2888int city_pollution(const struct city *pcity, int shield_total)
2889{
2891 nullptr, nullptr, nullptr);
2892}
2893
2894/**********************************************************************/
2901static int get_trade_illness(const struct city *pcity)
2902{
2903 float illness_trade = 0.0;
2904
2906 if (trade_city->turn_plague != -1
2907 && game.info.turn - trade_city->turn_plague < 5) {
2908 illness_trade += (float)game.info.illness_trade_infection
2909 * sqrt(1.0 * city_size_get(pcity)
2910 * city_size_get(trade_city)) / 100.0;
2911 }
2913
2914 return (int)illness_trade;
2915}
2916
2917/**********************************************************************/
2921static int get_city_health(const struct city *pcity)
2922{
2924}
2925
2926/**********************************************************************/
2938int city_illness_calc(const struct city *pcity, int *ill_base,
2939 int *ill_size, int *ill_trade, int *ill_pollution)
2940{
2941 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2943
2944 if (game.info.illness_on
2946 /* offset the city size by game.info.illness_min_size */
2948
2949 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2950 * 10.0 * game.info.illness_base_factor);
2951 if (is_server()) {
2952 /* On the server we recalculate the illness due to trade as we have
2953 * all the information */
2954 illness_trade = get_trade_illness(pcity);
2955 } else {
2956 /* On the client we have to rely on the value saved within the city
2957 * struct */
2958 illness_trade = pcity->illness_trade;
2959 }
2960
2961 illness_pollution = pcity->pollution
2963 }
2964
2965 illness_base = illness_size + illness_trade + illness_pollution;
2967
2968 /* returning other data */
2969 if (ill_size) {
2971 }
2972
2973 if (ill_trade) {
2974 *ill_trade = illness_trade;
2975 }
2976
2977 if (ill_pollution) {
2979 }
2980
2981 if (ill_base) {
2983 }
2984
2985 return CLIP(0, illness_base * illness_percent / 100 , 999);
2986}
2987
2988/**********************************************************************/
2992{
2993 /* Correctly handles special case turn_plague == -1 (never) */
2994 return (pcity->turn_plague == game.info.turn);
2995}
2996
2997/**********************************************************************/
3000int city_build_slots(const struct city *pcity)
3001{
3003}
3004
3005/**********************************************************************/
3010int city_airlift_max(const struct city *pcity)
3011{
3013}
3014
3015/**********************************************************************/
3021inline void set_city_production(struct city *pcity)
3022{
3023 int trade;
3024
3025 /* Calculate city production!
3026 *
3027 * This is a rather complicated process if we allow rules to become
3028 * more generalized. We can assume that there are no recursive dependency
3029 * loops, but there are some dependencies that do not follow strict
3030 * ordering. For instance corruption must be calculated before
3031 * trade taxes can be counted up, which must occur before the science bonus
3032 * is added on. But the calculation of corruption must include the
3033 * trade bonus. To do this without excessive special casing means that in
3034 * this case the bonuses are multiplied on twice (but only saved the second
3035 * time).
3036 */
3037
3039 pcity->prod[o] = pcity->citizen_base[o];
3041
3042 /* Add on special extra incomes: trade routes and tithes. */
3044 struct city *tcity = game_city_by_number(proute->partner);
3045 bool can_trade;
3046
3047 /* Partner city may have not yet been sent to the client, or
3048 * there's just a placeholder city with a placeholder owner
3049 * created for some tile->worked. */
3050 if (!is_server()
3051 && (tcity == nullptr
3052 || city_owner(tcity)->slot == nullptr)) {
3053 continue;
3054 }
3055
3056 fc_assert_action(tcity != nullptr, continue);
3057
3059
3060 if (!can_trade) {
3063
3064 if (settings->cancelling == TRI_ACTIVE) {
3065 can_trade = TRUE;
3066 }
3067 }
3068
3069 if (can_trade) {
3070 int value;
3071
3072 value =
3074 proute->value = trade_from_route(pcity, proute, value);
3075 pcity->prod[O_TRADE] += proute->value
3076 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3077 } else {
3078 proute->value = 0;
3079 }
3082
3083 /* Account for waste. Note that waste is calculated before tax income is
3084 * calculated, so if you had "science waste" it would not include taxed
3085 * science. However waste is calculated after the bonuses are multiplied
3086 * on, so shield waste will include shield bonuses. */
3088 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3089
3090 prod = MAX(prod, 0);
3091 pcity->waste[o] = city_waste(pcity, o, prod, nullptr);
3093
3094 /* Convert trade into science/luxury/gold, and add this on to whatever
3095 * science/luxury/gold is already there. */
3096 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3097 + pcity->abs_bonus[O_TRADE];
3098 trade = MAX(trade, 0);
3100 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3101 pcity->prod);
3102
3103 /* Add on effect bonuses and waste. Note that the waste calculation
3104 * (above) already includes the bonuses. */
3106 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3107
3108 prod = MAX(prod, 0);
3109 pcity->prod[o] = prod;
3110 pcity->prod[o] -= pcity->waste[o];
3112}
3113
3114/**********************************************************************/
3118 struct unit *punit, int *free_unhappy)
3119{
3120 struct city *pcity;
3121 const struct unit_type *ut;
3122 struct player *plr;
3123 int happy_cost;
3124
3125 if (punit == nullptr || free_unhappy == nullptr) {
3126 return 0;
3127 }
3128
3130 if (pcity == nullptr) {
3131 return 0;
3132 }
3133
3135 plr = unit_owner(punit);
3136 happy_cost = utype_happy_cost(ut, plr);
3137
3138 if (happy_cost <= 0) {
3139 return 0;
3140 }
3141
3143
3145 return 0;
3146 }
3147
3149 if (happy_cost <= 0) {
3150 return 0;
3151 }
3152
3153 if (*free_unhappy >= happy_cost) {
3154 *free_unhappy -= happy_cost;
3155 return 0;
3156 } else {
3157 happy_cost -= *free_unhappy;
3158 *free_unhappy = 0;
3159 }
3160
3161 return happy_cost;
3162}
3163
3164/**********************************************************************/
3168static inline void city_support(const struct civ_map *nmap,
3169 struct city *pcity)
3170{
3171 int free_unhappy;
3172 int max_mart_units;
3173
3174 /* Clear all usage values. */
3175 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3176 pcity->martial_law = 0;
3177 pcity->unit_happy_upkeep = 0;
3178
3179 /* Building and unit gold upkeep depends on the setting
3180 * 'game.info.gold_upkeep_style':
3181 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3182 * city.
3183 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3184 * The upkeep for units is paid by the nation.
3185 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3186 * nation. */
3188 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3189 switch (game.info.gold_upkeep_style) {
3190 case GOLD_UPKEEP_CITY:
3192 fc__fallthrough; /* No break */
3193 case GOLD_UPKEEP_MIXED:
3195 break;
3196 case GOLD_UPKEEP_NATION:
3197 /* nothing */
3198 break;
3199 }
3200 /* Food consumption by citizens. */
3202
3204 if (max_mart_units > 0) {
3206 int sel_count = 0;
3207 int i;
3208
3211 && unit_owner(punit) == city_owner(pcity)) {
3212 int current = get_target_bonus_effects(nullptr,
3213 &(const struct req_context) {
3214 .player = city_owner(pcity),
3215 .city = pcity,
3216 .tile = city_tile(pcity),
3217 .unit = punit,
3218 .unittype = unit_type_get(punit)
3219 },
3220 nullptr, EFT_MARTIAL_LAW_BY_UNIT);
3221 if (current > 0) {
3222 if (sel_count < max_mart_units) {
3223 best_units[sel_count++] = current;
3224 } else if (current > best_units[max_mart_units - 1]) {
3225 for (i = max_mart_units - 1; i >= 0 && current > best_units[i]; i--) {
3226 if (i + 1 < max_mart_units) {
3227 best_units[i + 1] = best_units[i];
3228 }
3229 }
3230
3231 best_units[i + 1] = current;
3232 }
3233 }
3234 }
3236
3237 pcity->martial_law = 0;
3238 for (i = 0; i < sel_count; i++) {
3239 pcity->martial_law += best_units[i];
3240 }
3241
3242 pcity->martial_law = MIN(pcity->martial_law, MAX_CITY_SIZE);
3243 }
3244
3246 unit_list_iterate(pcity->units_supported, punit) {
3247 pcity->unit_happy_upkeep += city_unit_unhappiness(nmap, punit, &free_unhappy);
3249 if (O_GOLD != o) {
3250 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3251 pcity->usage[o] += punit->upkeep[o];
3252 }
3255}
3256
3257/**********************************************************************/
3270 struct city *pcity, bool *workers_map)
3271{
3272 if (workers_map == nullptr) {
3273 /* Do a full refresh */
3274
3275 /* Calculate the bonus[] array values. */
3277 /* Calculate the tile_cache[] values. */
3279 /* Manage settlers, and units */
3281 }
3282
3283 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3284 get_worked_tile_output(nmap, pcity, pcity->citizen_base, workers_map);
3285 add_specialist_output(pcity, pcity->citizen_base);
3286
3289 /* Note that pollution is calculated before unhappy_city_check() makes
3290 * deductions for disorder; so a city in disorder still causes pollution */
3291 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3292
3294 citizen_happy_luxury(pcity); /* With our new found luxuries */
3295
3298
3301
3302 /* Martial law & unrest from units */
3305
3306 /* Building (including wonder) happiness effects */
3309
3312}
3313
3314/**********************************************************************/
3321int city_waste(const struct city *pcity, Output_type_id otype, int total,
3322 int *breakdown)
3323{
3324 int penalty_waste = 0;
3325 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3326 * corruption */
3327 int total_eft = total; /* Normal corruption calculated on total reduced by
3328 * possible size penalty */
3329 const struct output_type *output = get_output_type(otype);
3331 bool waste_all = FALSE;
3332
3333 if (otype == O_TRADE) {
3334 /* FIXME: special case for trade: it is affected by notradesize and
3335 * fulltradesize server settings.
3336 *
3337 * If notradesize and fulltradesize are equal then the city gets no
3338 * trade at that size. */
3339 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3340 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3341
3342 if (city_size_get(pcity) <= notradesize) {
3343 penalty_size = total_eft; /* Then no trade income. */
3344 } else if (city_size_get(pcity) >= fulltradesize) {
3345 penalty_size = 0;
3346 } else {
3347 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3348 / (fulltradesize - notradesize);
3349 }
3350 }
3351
3352 /* Apply corruption only to anything left after tradesize */
3354
3355 /* Distance-based waste.
3356 * Don't bother calculating if there's nothing left to lose. */
3357 if (total_eft > 0) {
3362 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3363 int min_dist;
3364 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3365
3366 if (gov_center == nullptr) {
3367 waste_all = TRUE; /* No gov center - no income */
3368 } else {
3370 if (waste_by_rel_dist > 0) {
3371 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3372 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3373 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3375 }
3376 }
3377 }
3378 }
3379
3380 if (waste_all) {
3382 } else {
3385
3386 /* Corruption/waste calculated only for the actually produced amount */
3387 if (waste_level > 0) {
3389 }
3390
3391 /* Bonus calculated only for the actually produced amount */
3393
3394 /* Clip */
3396 }
3397
3398 if (breakdown) {
3401 }
3402
3403 /* Add up total penalty */
3404 return penalty_waste + penalty_size;
3405}
3406
3407/**********************************************************************/
3412{
3413 citizens count = 0;
3414
3416 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3417 count += pcity->specialists[sp];
3419
3420 return count;
3421}
3422
3423/**********************************************************************/
3427{
3428 int count = 0;
3429
3431 count += pcity->specialists[sp];
3433
3434 return count;
3435}
3436
3437/**********************************************************************/
3443 const struct city *pcity)
3444{
3445 int best = DEFAULT_SPECIALIST;
3446 int val = get_specialist_output(pcity, best, otype);
3447
3451
3452 if (val2 > val) {
3453 best = i;
3454 val = val2;
3455 }
3456 }
3458
3459 return best;
3460}
3461
3462/**********************************************************************/
3466 const struct impr_type *pimprove)
3467{
3468 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3469
3470 if (is_server() && is_wonder(pimprove)) {
3471 /* Client just read the info from the packets. */
3472 wonder_built(pcity, pimprove);
3473 }
3474}
3475
3476/**********************************************************************/
3480 const struct impr_type *pimprove)
3481{
3482 log_debug("Improvement %s removed from city %s",
3483 improvement_rule_name(pimprove), pcity->name);
3484
3485 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3486
3487 if (is_server() && is_wonder(pimprove)) {
3488 /* Client just read the info from the packets. */
3489 wonder_destroyed(pcity, pimprove);
3490 }
3491}
3492
3493/**********************************************************************/
3497{
3498 return BV_ISSET(pcity->city_options, option);
3499}
3500
3501/**********************************************************************/
3505{
3506 int i;
3507
3508 city_styles = fc_calloc(num, sizeof(*city_styles));
3510
3511 for (i = 0; i < game.control.num_city_styles; i++) {
3513 }
3514}
3515
3516/**********************************************************************/
3520{
3521 int i;
3522
3523 for (i = 0; i < game.control.num_city_styles; i++) {
3525 }
3526
3528 city_styles = nullptr;
3530}
3531
3532/**********************************************************************/
3538struct city *create_city_virtual(struct player *pplayer,
3539 struct tile *ptile, const char *name)
3540{
3541 int i,len;
3542
3543 /* Make sure that contents of city structure are correctly initialized,
3544 * if you ever allocate it by some other mean than fc_calloc() */
3545 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3546
3547 fc_assert_ret_val(name != nullptr, nullptr); /* No unnamed cities! */
3548
3549 /* Do this early, so any logging later will have the city name */
3551
3552 pcity->tile = ptile;
3553
3554 fc_assert_ret_val(pplayer != nullptr, nullptr); /* No unowned cities! */
3555
3556 pcity->owner = pplayer;
3557 pcity->acquire_t = CACQ_FOUNDED;
3558
3559 if (is_server()) {
3560 pcity->original = pplayer;
3561 }
3562
3563 /* City structure was allocated with fc_calloc(), so contents are initially
3564 * zero. There is no need to initialize it a second time. */
3565
3566 /* Now set some useful default values. */
3567 pcity->capital = CAPITAL_NOT;
3568 city_size_set(pcity, 1);
3569 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3570 pcity->wlcb = WLCB_SMART;
3571
3573 pcity->bonus[o] = 100;
3574 pcity->abs_bonus[o] = 0;
3576
3577 pcity->turn_plague = -1; /* -1 = never */
3578 pcity->did_buy = FALSE;
3579 pcity->city_radius_sq = game.info.init_city_radius_sq;
3580 pcity->turn_founded = game.info.turn;
3581 pcity->turn_last_built = game.info.turn;
3582
3583 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3584
3585 /* pcity->ai.act_cache: worker activities on the city map */
3586
3587 /* Initialise improvements list */
3588 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3589 pcity->built[i].turn = I_NEVER;
3590 }
3591
3592 /* Set up the worklist */
3593 worklist_init(&pcity->worklist);
3594
3595 pcity->units_supported = unit_list_new();
3596 pcity->routes = trade_route_list_new();
3597 pcity->task_reqs = worker_task_list_new();
3598
3599 pcity->aarea = nullptr;
3600
3601 if (is_server()) {
3602 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3603
3604 CALL_FUNC_EACH_AI(city_alloc, pcity);
3605 } else {
3606 pcity->client.info_units_supported =
3608 pcity->client.info_units_present =
3610 /* collecting_info_units_supported set by fc_calloc().
3611 * collecting_info_units_present set by fc_calloc(). */
3612 }
3613
3615 pcity->counter_values = fc_malloc(sizeof(int) * len);
3616
3617 for (i = 0; i < len; i++) {
3618 pcity->counter_values[i] = counter_by_index(i, CTGT_CITY)->def;
3619 }
3620
3621 return pcity;
3622}
3623
3624/**********************************************************************/
3629{
3630 CALL_FUNC_EACH_AI(city_free, pcity);
3631
3633
3634 /* Free worker tasks */
3635 while (worker_task_list_size(pcity->task_reqs) > 0) {
3636 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3637
3638 worker_task_list_remove(pcity->task_reqs, ptask);
3639
3640 free(ptask);
3641 }
3642 worker_task_list_destroy(pcity->task_reqs);
3643
3644 /* Free rally points */
3646
3647 if (pcity->aarea != nullptr) {
3648 city_list_remove(pcity->aarea->cities, pcity);
3649 pcity->aarea = nullptr;
3650 }
3651
3652 unit_list_destroy(pcity->units_supported);
3654 if (pcity->tile_cache != nullptr) {
3655 free(pcity->tile_cache);
3656 }
3657
3658 if (pcity->cm_parameter) {
3659 free(pcity->cm_parameter);
3660 }
3661
3662 if (pcity->counter_values) {
3663 free(pcity->counter_values);
3664 }
3665
3666 if (!is_server()) {
3667 unit_list_destroy(pcity->client.info_units_supported);
3668 unit_list_destroy(pcity->client.info_units_present);
3669 /* Handle a rare case where the game is freed in the middle of a
3670 * spy/diplomat investigate cycle. */
3671 if (pcity->client.collecting_info_units_supported != nullptr) {
3672 unit_list_destroy(pcity->client.collecting_info_units_supported);
3673 }
3674 if (pcity->client.collecting_info_units_present != nullptr) {
3675 unit_list_destroy(pcity->client.collecting_info_units_present);
3676 }
3677 }
3678
3679 free(pcity->name);
3680
3681 memset(pcity, 0, sizeof(*pcity)); /* Ensure no pointers remain */
3682 free(pcity);
3683}
3684
3685/**********************************************************************/
3689bool city_exist(int id)
3690{
3691 /* Check if city exist in game */
3692 if (game_city_by_number(id)) {
3693 return TRUE;
3694 }
3695
3696 return FALSE;
3697}
3698
3699/**********************************************************************/
3706bool city_is_virtual(const struct city *pcity)
3707{
3708 if (!pcity) {
3709 return FALSE;
3710 }
3711
3712 return pcity != game_city_by_number(pcity->id);
3713}
3714
3715/**********************************************************************/
3718bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3719{
3720 return is_city_center(pcity, ptile);
3721}
3722
3723/**********************************************************************/
3726void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3727{
3728 return pcity->server.ais[ai_type_number(ai)];
3729}
3730
3731/**********************************************************************/
3734void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3735 void *data)
3736{
3737 pcity->server.ais[ai_type_number(ai)] = data;
3738}
3739
3740/**********************************************************************/
3744{
3745 /* Free rally points */
3746 if (pcity->rally_point.length > 0) {
3747 pcity->rally_point.length = 0;
3748 pcity->rally_point.persistent = FALSE;
3749 pcity->rally_point.vigilant = FALSE;
3750 free(pcity->rally_point.orders);
3751 pcity->rally_point.orders = nullptr;
3752 }
3753}
3754
3755/**********************************************************************/
3759 struct city *pcity)
3760{
3761 struct unit_order *checked_orders;
3762 const struct civ_map *nmap = &(wld.map);
3763
3764 if (pcity == nullptr) {
3765 /* Probably lost. */
3766 log_verbose("handle_city_rally_point() bad city number %d.",
3767 packet->id);
3768 return;
3769 }
3770
3771 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3772 /* Shouldn't happen */
3773 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3774 packet->length, MAX_LEN_ROUTE);
3775 return;
3776 }
3777
3778 pcity->rally_point.length = packet->length;
3779
3780 if (packet->length == 0) {
3781 pcity->rally_point.vigilant = FALSE;
3782 pcity->rally_point.persistent = FALSE;
3783 if (pcity->rally_point.orders) {
3784 free(pcity->rally_point.orders);
3785 pcity->rally_point.orders = nullptr;
3786 }
3787 } else {
3789 packet->orders);
3790 if (!checked_orders) {
3791 pcity->rally_point.length = 0;
3792 log_error("invalid rally point orders for %s.",
3794 return;
3795 }
3796
3797 pcity->rally_point.persistent = packet->persistent;
3798 pcity->rally_point.vigilant = packet->vigilant;
3799 pcity->rally_point.orders = checked_orders;
3800 }
3801}
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:1690
bool city_is_virtual(const struct city *pcity)
Definition city.c:3706
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:2018
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2611
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:666
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:834
static void citizen_content_buildings(struct city *pcity)
Definition city.c:2658
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3718
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1913
static bv_imprs caravan_helped_impr
Definition city.c:1824
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:1197
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2227
#define POLLUTION_EFT_NEARMAX
Definition city.c:1165
const char * city_name_getx(const struct city *pcity)
Definition city.c:1166
int city_granary_size(int city_size)
Definition city.c:2199
static void get_worked_tile_output(const struct civ_map *nmap, const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2391
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2263
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2854
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3734
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2779
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2159
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2346
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1105
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3321
static void city_support(const struct civ_map *nmap, struct city *pcity)
Definition city.c:3168
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:3000
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:1292
const char * city_style_name_translation(const int style)
Definition city.c:1809
void city_styles_free(void)
Definition city.c:3519
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2505
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:650
int city_superspecialists(const struct city *pcity)
Definition city.c:3426
bool is_capital(const struct city *pcity)
Definition city.c:1632
void city_styles_alloc(int num)
Definition city.c:3504
const char * city_name_get(const struct city *pcity)
Definition city.c:1157
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1454
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1067
void city_production_caravan_shields_init(void)
Definition city.c:1831
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3479
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1308
int city_airlift_max(const struct city *pcity)
Definition city.c:3010
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1518
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1049
struct output_type * get_output_type(Output_type_id output)
Definition city.c:640
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3496
int city_population(const struct city *pcity)
Definition city.c:1243
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1818
void city_size_add(struct city *pcity, int add)
Definition city.c:1216
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1083
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:730
bool city_is_occupied(const struct city *pcity)
Definition city.c:1718
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:2312
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:2133
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3117
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1649
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2253
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:2476
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2294
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2148
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:1706
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:1679
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3442
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3538
void set_city_production(struct city *pcity)
Definition city.c:3021
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:860
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1732
static bv_unit_types caravan_helped_utype
Definition city.c:1825
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2279
bool city_celebrating(const struct city *pcity)
Definition city.c:1698
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1613
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:2938
const char * get_output_name(Output_type_id output)
Definition city.c:630
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target, const enum req_problem_type prob_type)
Definition city.c:1006
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2079
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1939
static int get_city_health(const struct city *pcity)
Definition city.c:2921
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:3269
static void set_city_bonuses(struct city *pcity)
Definition city.c:2453
static void set_surpluses(struct city *pcity)
Definition city.c:2519
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2354
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:911
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1540
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2888
bool city_happy(const struct city *pcity)
Definition city.c:1667
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1232
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3465
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1437
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:2103
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2088
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:3628
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target, const enum req_problem_type prob_type)
Definition city.c:1028
int rs_max_city_radius_sq(void)
Definition city.c:159
bool city_tile_to_city_map(int *city_map_x, int *city_map_y, const int city_radius_sq, const struct tile *city_center, const struct tile *map_tile)
Definition city.c:264
citizens city_specialists(const struct city *pcity)
Definition city.c:3411
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:3758
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:1774
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2431
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:957
static const struct city struct citystyle * city_styles
Definition city.c:84
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3726
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1748
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2682
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1336
static int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
Definition city.c:64
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:123
bool is_gov_center(const struct city *pcity)
Definition city.c:1640
#define log_ca_s_init
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2648
int city_map_tiles(int city_radius_sq)
Definition city.c:171
static void unhappy_city_check(struct city *pcity)
Definition city.c:2827
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2118
bool city_exist(int id)
Definition city.c:3689
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1509
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:2049
void city_rally_point_clear(struct city *pcity)
Definition city.c:3743
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:879
struct output_type output_types[O_LAST]
Definition city.c:88
bool city_exists_within_max_city_map(const struct civ_map *nmap, const struct tile *ptile, bool may_be_on_center)
Definition city.c:2179
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2991
static int get_trade_illness(const struct city *pcity)
Definition city.c:2901
bool city_can_change_build(const struct city *pcity)
Definition city.c:1097
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:982
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1274
int city_style_by_rule_name(const char *s)
Definition city.c:1791
static void citizen_base_mood(struct city *pcity)
Definition city.c:2572
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1764
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1253
static void citizen_happy_units(struct city *pcity)
Definition city.c:2731
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2560
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:703
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:565
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:254
@ UNHAPPY_PENALTY_NONE
Definition city.h:252
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:253
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, _index)
Definition city.h:199
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:84
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
#define CITY_MAP_MAX_SIZE
Definition city.h:92
#define city_tile_iterate_index_end
Definition city.h:207
@ CITIZEN_LAST
Definition city.h:270
@ CITIZEN_ANGRY
Definition city.h:269
@ CITIZEN_HAPPY
Definition city.h:266
@ CITIZEN_CONTENT
Definition city.h:267
@ CITIZEN_UNHAPPY
Definition city.h:268
#define CITY_MAP_CENTER_RADIUS_SQ
Definition city.h:87
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:82
#define output_type_iterate(output)
Definition city.h:853
#define CITY_REL2ABS(_coor)
Definition city.h:113
#define city_owner(_pcity_)
Definition city.h:564
#define MAX_CITY_SIZE
Definition city.h:104
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:876
#define city_list_iterate_end
Definition city.h:510
#define I_DESTROYED
Definition city.h:246
#define I_NEVER
Definition city.h:245
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:228
citizen_feeling
Definition city.h:276
@ FEELING_EFFECT
Definition city.h:279
@ FEELING_LUXURY
Definition city.h:278
@ FEELING_FINAL
Definition city.h:282
@ FEELING_BASE
Definition city.h:277
@ FEELING_NATIONALITY
Definition city.h:280
@ FEELING_MARTIAL
Definition city.h:281
@ OLOSS_SIZE
Definition city.h:289
@ OLOSS_WASTE
Definition city.h:288
#define city_map_iterate_end
Definition city.h:175
#define city_map_iterate(_radius_sq, _index, _x, _y)
Definition city.h:171
#define city_tile_iterate_end
Definition city.h:236
#define city_built_iterate(_pcity, _p)
Definition city.h:842
#define is_free_worked_index(city_tile_index)
Definition city.h:888
#define city_map_tiles_from_city(_pcity)
Definition city.h:125
#define CITY_ABS2REL(_coor)
Definition city.h:114
#define city_built_iterate_end
Definition city.h:848
#define PCT_LAST
Definition city.h:41
#define output_type_iterate_end
Definition city.h:859
void cm_init_citymap(void)
Definition cm.c:314
char * incite_cost
Definition comments.c:77
#define MAX_LEN_ROUTE
Definition conn_types.h:38
struct counter * counter_by_index(int index, enum counter_target target)
Definition counters.c:186
int counters_get_city_counters_count(void)
Definition counters.c:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
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:77
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:73
void distribute(int number, unsigned groups, const unsigned *ratios, int *result)
Definition distribute.c:34
struct @22::@23 reqs
int get_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:938
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:983
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Definition effects.c:1008
int get_city_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:913
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
int effect_cumulative_max(enum effect_type type, struct universal *unis, size_t n_unis)
Definition effects.c:388
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:1036
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
static bool is_server(void)
unsigned char citizens
Definition fc_types.h:249
req_problem_type
Definition fc_types.h:514
@ RPT_CERTAIN
Definition fc_types.h:516
@ RPT_POSSIBLE
Definition fc_types.h:515
int Specialist_type_id
Definition fc_types.h:236
@ CTGT_CITY
Definition fc_types.h:128
#define CITY_MAP_MAX_RADIUS
Definition fc_types.h:85
output_type_id
Definition fc_types.h:102
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
@ O_SCIENCE
Definition fc_types.h:103
@ O_LUXURY
Definition fc_types.h:103
@ O_GOLD
Definition fc_types.h:103
@ O_LAST
Definition fc_types.h:103
#define MAX_LEN_CITYNAME
Definition fc_types.h:69
enum output_type_id Output_type_id
Definition fc_types.h:239
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
#define Qn_(String)
Definition fcintl.h:89
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:106
struct government * government_of_player(const struct player *pplayer)
Definition government.c:115
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
bool is_building_sellable(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_warn(message,...)
Definition log.h:106
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_do_output_for_level(level)
Definition log.h:90
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_base(level, message,...)
Definition log.h:95
log_level
Definition log.h:29
@ LOG_DEBUG
Definition log.h:35
#define log_error(message,...)
Definition log.h:104
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:434
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:659
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:1085
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:675
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1222
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:397
#define square_iterate_end
Definition map.h:400
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:229
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:350
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:496
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
struct city_list * cities
Definition packhand.c:121
int len
Definition packhand.c:129
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:139
int length
Definition unit.h:197
int upkeep[O_LAST]
Definition unit.h:149
bool occupied
Definition unit.h:221
int id
Definition unit.h:146
struct unit::@83 orders
bool vigilant
Definition unit.h:199
struct unit::@84::@87 server
struct tile * tile
Definition unit.h:141
struct unit::@84::@86 client
enum unit_activity changed_from
Definition unit.h:170
void * ais[FREECIV_AI_MOD_LAST]
Definition unit.h:239
int homecity
Definition unit.h:147
const struct unit_type * utype
Definition unit.h:140
struct player * owner
Definition unit.h:144
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:925
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:2924
bool unit_being_aggressive(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:1576
bool is_field_unit(const struct unit *punit)
Definition unit.c:457
bool is_martial_law_unit(const struct unit *punit)
Definition unit.c:335
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1787
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1418
#define unit_tile(_pu)
Definition unit.h:408
#define unit_owner(_pu)
Definition unit.h:407
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
struct unit_type * best_role_unit(const struct city *pcity, int role)
Definition unittype.c:2303
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:126
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2662
bool utype_can_do_act_when_ustate(const struct unit_type *punit_type, const action_id act_id, const enum ustate_prop prop, const bool is_there)
Definition unittype.c:980
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:114
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, const enum req_problem_type prob_type, bool consider_reg_impr_req)
Definition unittype.c:1995
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1554
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2130
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
bool can_utype_do_act_if_tgt_diplrel(const struct unit_type *punit_type, const action_id act_id, const int prop, const bool is_there)
Definition unittype.c:1042
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Definition unittype.c:206
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:865
#define unit_type_iterate_end
Definition unittype.h:872
#define U_NOT_OBSOLETED
Definition unittype.h:535
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT