Freeciv-3.2
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 informations using the city tile index. */
61/* Get city tile informations 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
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/**********************************************************************/
137int city_map_radius_sq_get(const struct city *pcity)
138{
139 /* a save 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{
286 city_map_radius_sq_get(pcity), pcity->tile,
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
298 return city_base_to_city_map(&tmp_x, &tmp_y, pcity, map_tile);
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), NULL);
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
375
376 /* print y coordinates (absolut) */
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 (relativ) */
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 (absolut) */
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 (relativ) */
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/**********************************************************************/
446void citylog_map_workers(enum log_level level, struct city *pcity)
447{
448 int *city_map_data = NULL;
449 const struct civ_map *nmap = &(wld.map);
450
451 fc_assert_ret(pcity != NULL);
452
454 return;
455 }
456
458 sizeof(*city_map_data));
459
460 city_map_iterate(city_map_radius_sq_get(pcity), cindex, x, y) {
461 struct tile *ptile = city_map_to_tile(nmap,
462 city_tile(pcity),
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 = NULL;
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 = NULL;
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
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, NULL);
622 return output_types[output].id;
623}
624
625/**********************************************************************/
630{
631 fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
632 return _(output_types[output].name);
633}
634
635/**********************************************************************/
639{
640 fc_assert_ret_val(output >= 0 && output < O_LAST, NULL);
641 return &output_types[output];
642}
643
644/**********************************************************************/
648{
650
651 for (o = 0; o < O_LAST; o++) {
652 if (fc_strcasecmp(output_types[o].id, id) == 0) {
653 return o;
654 }
655 }
656
657 return O_LAST;
658}
659
660/**********************************************************************/
663const char *city_improvement_name_translation(const struct city *pcity,
664 const struct impr_type *pimprove)
665{
666 static char buffer[256];
667 const char *state = NULL;
668
669 if (is_great_wonder(pimprove)) {
670 if (great_wonder_is_available(pimprove)) {
671 state = Q_("?wonder:W");
672 } else if (great_wonder_is_destroyed(pimprove)) {
673 state = Q_("?destroyed:D");
674 } else {
675 state = Q_("?built:B");
676 }
677 }
678 if (pcity) {
679 struct player *pplayer = city_owner(pcity);
680
681 if (improvement_obsolete(pplayer, pimprove, pcity)) {
682 state = Q_("?obsolete:O");
683 } else if (is_improvement_redundant(pcity, pimprove)) {
684 state = Q_("?redundant:*");
685 }
686 }
687
688 if (state) {
689 fc_snprintf(buffer, sizeof(buffer), "%s(%s)",
690 improvement_name_translation(pimprove), state);
691 return buffer;
692 } else {
693 return improvement_name_translation(pimprove);
694 }
695}
696
697/**********************************************************************/
700const char *city_production_name_translation(const struct city *pcity)
701{
702 static char buffer[256];
703
704 switch (pcity->production.kind) {
705 case VUT_IMPROVEMENT:
707 default:
708 /* fallthru */
709 break;
710 };
711 return universal_name_translation(&pcity->production, buffer, sizeof(buffer));
712}
713
714/**********************************************************************/
717bool city_production_is_genus(const struct city *pcity,
718 enum impr_genus_id genus)
719{
720 return VUT_IMPROVEMENT == pcity->production.kind
721 && (pcity->production.value.building->genus == genus);
722}
723
724/**********************************************************************/
727bool city_production_has_flag(const struct city *pcity,
728 enum impr_flag_id flag)
729{
730 return VUT_IMPROVEMENT == pcity->production.kind
732}
733
734/**********************************************************************/
738{
739 return universal_build_shield_cost(pcity, &pcity->production);
740}
741
742/**********************************************************************/
747bool city_production_build_units(const struct city *pcity,
748 bool add_production, int *num_units)
749{
750 const struct unit_type *utype;
751 struct universal target;
752 int build_slots = city_build_slots(pcity);
753 int shields_left = pcity->shield_stock;
754 int unit_shield_cost, i;
755
757 (*num_units) = 0;
758
759 if (pcity->production.kind != VUT_UTYPE) {
760 /* not a unit as the current production */
761 return FALSE;
762 }
763
764 utype = pcity->production.value.utype;
765 if (utype_pop_value(utype, pcity) != 0 || utype_has_flag(utype, UTYF_UNIQUE)) {
766 /* unit with population cost or unique unit means that only one unit can
767 * be build */
768 (*num_units)++;
769 return FALSE;
770 }
771
772 if (add_production) {
773 shields_left += pcity->prod[O_SHIELD];
774 }
775
777
778 for (i = 0; i < build_slots; i++) {
780 /* not enough shields */
781 break;
782 }
783
784 (*num_units)++;
786
787 if (worklist_length(&pcity->worklist) > i) {
788 (void) worklist_peek_ith(&pcity->worklist, &target, i);
789 if (target.kind != VUT_UTYPE
790 || utype_index(target.value.utype) != utype_index(utype)) {
791 /* stop if there is a build target in the worklist not equal to the
792 * unit we build */
793 break;
794 }
795 }
796 }
797
798 return TRUE;
799}
800
801/************************************************************************/
805 const struct unit_type *punittype)
806{
807 int levels = get_unittype_bonus(city_owner(pcity), pcity->tile, punittype,
810
811 levels = CLIP(0, levels, max_levels);
812
813 return levels;
814}
815
816/**********************************************************************/
820int city_production_turns_to_build(const struct city *pcity,
822{
824}
825
826/**********************************************************************/
831 const struct impr_type *pimprove)
832{
833 if (!can_player_build_improvement_direct(city_owner(pcity), pimprove)) {
834 return FALSE;
835 }
836
837 if (city_has_building(pcity, pimprove)) {
838 return FALSE;
839 }
840
841 return are_reqs_active(&(const struct req_context) {
842 .player = city_owner(pcity),
843 .city = pcity,
844 .tile = pcity->tile,
845 },
846 NULL,
847 &(pimprove->reqs), RPT_CERTAIN);
848}
849
850/**********************************************************************/
854bool can_city_build_improvement_now(const struct city *pcity,
855 const struct impr_type *pimprove)
856{
857 if (!can_city_build_improvement_direct(pcity, pimprove)) {
858 return FALSE;
859 }
860 if (improvement_obsolete(city_owner(pcity), pimprove, pcity)) {
861 return FALSE;
862 }
863
864 return TRUE;
865}
866
867/**********************************************************************/
871bool can_city_build_improvement_later(const struct city *pcity,
872 const struct impr_type *pimprove)
873{
874 const struct req_context city_ctxt = {
875 .player = city_owner(pcity),
876 .city = pcity,
877 .tile = city_tile(pcity),
878 };
879
880 /* Can the _player_ ever build this improvement? */
881 /* NOTE: It checks for obsoletion player-level. What aboult checking
882 * for it city-level? That may unlist from a worklist some things
883 * we'll be able to switch to after e.g. selling something else */
884 if (!can_player_build_improvement_later(city_owner(pcity), pimprove)) {
885 return FALSE;
886 }
887
888 /* Check for requirements that aren't met and that are unchanging (so
889 * they can never be met). */
892 return FALSE;
893 }
895
896 return TRUE;
897}
898
899/**********************************************************************/
904 const struct city *pcity,
905 const struct unit_type *punittype)
906{
908 return FALSE;
909 }
910
911 /* Check unit build requirements.
912 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
913 * Don't recheck those. Not only for optimization, but also not to override the
914 * special handling of tech requirements for barbarians */
915 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
917 &(const struct req_context) {
918 .player = city_owner(pcity),
919 .city = pcity,
920 .tile = city_tile(pcity),
921 .unittype = punittype,
922 },
923 NULL,
924 &punittype->build_reqs, RPT_CERTAIN)) {
925 return FALSE;
926 }
927
928 /* You can't build naval units inland. */
931 pcity->tile)) {
932 return FALSE;
933 }
934
935 if (punittype->city_slots > 0
936 && city_unit_slots_available(pcity) < punittype->city_slots) {
937 return FALSE;
938 }
939
940 return TRUE;
941}
942
943/**********************************************************************/
948 const struct city *pcity,
949 const struct unit_type *punittype)
950{
952 return FALSE;
953 }
954
955 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
956 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
957 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
959 return FALSE;
960 }
961 }
962
963 return TRUE;
964}
965
966/**********************************************************************/
971 const struct city *pcity,
972 const struct unit_type *punittype)
973{
974 /* Can the _player_ ever build this unit? */
976 return FALSE;
977 }
978
979 /* Some units can be built only in certain cities -- for instance,
980 ships may be built only in cities adjacent to ocean. */
983 pcity->tile)) {
984 return FALSE;
985 }
986
987 return TRUE;
988}
989
990/**********************************************************************/
995 const struct city *pcity,
996 const struct universal *target)
997{
998 switch (target->kind) {
999 case VUT_UTYPE:
1000 return can_city_build_unit_direct(nmap, pcity, target->value.utype);
1001 case VUT_IMPROVEMENT:
1002 return can_city_build_improvement_direct(pcity, target->value.building);
1003 default:
1004 break;
1005 };
1006 return FALSE;
1007}
1008
1009/**********************************************************************/
1014 const struct city *pcity,
1015 const struct universal *target)
1016{
1017 switch (target->kind) {
1018 case VUT_UTYPE:
1019 return can_city_build_unit_now(nmap, pcity, target->value.utype);
1020 case VUT_IMPROVEMENT:
1021 return can_city_build_improvement_now(pcity, target->value.building);
1022 default:
1023 break;
1024 };
1025 return FALSE;
1026}
1027
1028/**********************************************************************/
1032 const struct city *pcity,
1033 const struct universal *target)
1034{
1035 switch (target->kind) {
1036 case VUT_UTYPE:
1037 return can_city_build_unit_later(nmap, pcity, target->value.utype);
1038 case VUT_IMPROVEMENT:
1039 return can_city_build_improvement_later(pcity, target->value.building);
1040 default:
1041 break;
1042 };
1043 return FALSE;
1044}
1045
1046/**********************************************************************/
1049int city_unit_slots_available(const struct city *pcity)
1050{
1051 int max = get_city_bonus(pcity, EFT_UNIT_SLOTS);
1052 int current;
1053
1054 current = 0;
1056 current += unit_type_get(punit)->city_slots;
1058
1059 return max - current;
1060}
1061
1062/**********************************************************************/
1065bool city_can_use_specialist(const struct city *pcity,
1067{
1068 return are_reqs_active(&(const struct req_context) {
1069 .player = city_owner(pcity),
1070 .city = pcity,
1071 },
1072 NULL,
1074}
1075
1076/**********************************************************************/
1079bool city_can_change_build(const struct city *pcity)
1080{
1081 return !pcity->did_buy || pcity->shield_stock <= 0;
1082}
1083
1084/**********************************************************************/
1087void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
1088{
1089 if (NULL == city_tile(pcity)) {
1090 /* When a "dummy" city is created with no tile, then choosing a build
1091 * target could fail. This currently might happen during map editing.
1092 * FIXME: assumes the first unit is always "valid", so check for
1093 * obsolete units elsewhere. */
1094 pcity->production.kind = VUT_UTYPE;
1096 } else {
1097 struct unit_type *u = best_role_unit(pcity, L_FIRSTBUILD);
1098
1099 if (u) {
1100 pcity->production.kind = VUT_UTYPE;
1101 pcity->production.value.utype = u;
1102 } else {
1103 bool found = FALSE;
1104
1105 /* Just pick the first available item. */
1106 improvement_iterate(pimprove) {
1107 if (can_city_build_improvement_direct(pcity, pimprove)) {
1108 found = TRUE;
1110 pcity->production.value.building = pimprove;
1111 break;
1112 }
1114
1115 if (!found) {
1118#ifndef FREECIV_NDEBUG
1119 /* Later than this, 'found' is only needed in an fc_assert() */
1120 found = TRUE;
1121#endif /* FREECIV_NDEBUG */
1122 pcity->production.kind = VUT_UTYPE;
1124 }
1126 }
1127
1128 fc_assert_msg(found, "No production found for city %s!",
1129 city_name_get(pcity));
1130 }
1131 }
1132}
1133
1134/**********************************************************************/
1137const char *city_name_get(const struct city *pcity)
1138{
1139 return (pcity->name != NULL) ? pcity->name : "City missing a name";
1140}
1141
1142/**********************************************************************/
1145void city_name_set(struct city *pcity, const char *new_name)
1146{
1147 if (pcity->name != NULL) {
1148 free(pcity->name);
1149 }
1150
1151 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1152 pcity->name = fc_strdup(new_name);
1153 } else {
1154 log_warn(_("City name \"%s\" too long"), new_name);
1156 sz_strlcpy(pcity->name, new_name);
1157 }
1158}
1159
1160/**********************************************************************/
1164void city_size_add(struct city *pcity, int add)
1165{
1166 citizens size = city_size_get(pcity);
1167
1168 fc_assert_ret(pcity != NULL);
1170
1171 /* Client sets size to zero to start stacking citizens in */
1172 fc_assert_ret(size > -add || (!is_server() && size == add));
1173
1174 city_size_set(pcity, size + add);
1175}
1176
1177/**********************************************************************/
1180void city_size_set(struct city *pcity, citizens size)
1181{
1182 fc_assert_ret(pcity != NULL);
1183
1184 /* Set city size. */
1185 pcity->size = size;
1186}
1187
1188/**********************************************************************/
1191int city_population(const struct city *pcity)
1192{
1193 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1194 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1195}
1196
1197/**********************************************************************/
1201int city_total_impr_gold_upkeep(const struct city *pcity)
1202{
1203 int gold_needed = 0;
1204
1205 if (pcity == NULL) {
1206 return 0;
1207 }
1208
1209 city_built_iterate(pcity, pimprove) {
1210 gold_needed += city_improvement_upkeep(pcity, pimprove);
1212
1213 gold_needed -= get_city_bonus(pcity, EFT_IMPR_UPKEEP_REDUCTION);
1214
1215 return MAX(gold_needed, 0);
1216}
1217
1218/**********************************************************************/
1222int city_total_unit_gold_upkeep(const struct city *pcity)
1223{
1224 int gold_needed = 0;
1225
1226 if (pcity == NULL || pcity->units_supported == NULL) {
1227 return 0;
1228 }
1229
1231 gold_needed += punit->upkeep[O_GOLD];
1233
1234 return gold_needed;
1235}
1236
1237/**********************************************************************/
1240bool city_has_building(const struct city *pcity,
1241 const struct impr_type *pimprove)
1242{
1243 if (NULL == pimprove) {
1244 /* Callers should ensure that any external data is tested with
1245 * valid_improvement_by_number() */
1246 return FALSE;
1247 }
1248 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1249}
1250
1251/**********************************************************************/
1255int city_improvement_upkeep(const struct city *pcity,
1256 const struct impr_type *b)
1257{
1258 int upkeep;
1259
1260 if (NULL == b) {
1261 return 0;
1262 }
1263 if (!is_building_sellable(b)) {
1264 return 0;
1265 }
1266
1267 upkeep = b->upkeep;
1268 if (upkeep <= get_building_bonus(pcity, b, EFT_UPKEEP_FREE)) {
1269 return 0;
1270 }
1271
1272 return upkeep;
1273}
1274
1275/**********************************************************************/
1283int city_tile_output(const struct city *pcity, const struct tile *ptile,
1285{
1286 int prod;
1287 const struct req_context city_ctxt = {
1288 .player = pcity ? city_owner(pcity) : NULL,
1289 .city = pcity,
1290 .tile = ptile,
1291 };
1292 struct terrain *pterrain = tile_terrain(ptile);
1293 const struct output_type *output = &output_types[otype];
1294
1295 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1296
1297 if (T_UNKNOWN == pterrain) {
1298 /* Special case for the client. The server doesn't allow unknown tiles
1299 * to be worked but we don't necessarily know what player is involved. */
1300 return 0;
1301 }
1302
1303 prod = pterrain->output[otype];
1304 if (tile_resource_is_valid(ptile)) {
1305 prod += tile_resource(ptile)->data.resource->output[otype];
1306 }
1307
1308 switch (otype) {
1309 case O_SHIELD:
1310 if (pterrain->mining_shield_incr != 0) {
1311 prod += pterrain->mining_shield_incr
1313 / 100;
1314 }
1315 break;
1316 case O_FOOD:
1317 if (pterrain->irrigation_food_incr != 0) {
1318 prod += pterrain->irrigation_food_incr
1320 EFT_IRRIGATION_PCT) / 100;
1321 }
1322 break;
1323 case O_TRADE:
1324 case O_GOLD:
1325 case O_SCIENCE:
1326 case O_LUXURY:
1327 case O_LAST:
1328 break;
1329 }
1330
1331 prod += tile_roads_output_incr(ptile, otype);
1332 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1333
1334 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1335 if (prod > 0) {
1336 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1338
1339 if (prod >= game.info.granularity) {
1340 prod += get_tile_output_bonus(pcity, ptile, output,
1342
1343 if (is_celebrating) {
1344 prod += get_tile_output_bonus(pcity, ptile, output,
1346 }
1347 }
1348
1349 prod += (prod
1350 * get_tile_output_bonus(pcity, ptile, output,
1352 / 100;
1353 if (penalty_limit > 0 && prod > penalty_limit) {
1354 if (prod <= game.info.granularity) {
1355 prod = 0;
1356 } else {
1357 prod -= game.info.granularity;
1358 }
1359 }
1360 }
1361
1362 prod -= (prod
1363 * get_tile_output_bonus(pcity, ptile, output,
1365 / 100;
1366
1367 if (NULL != pcity && is_city_center(pcity, ptile)) {
1368 prod = MAX(prod, game.info.min_city_center_output[otype]);
1369 }
1370
1371 return prod;
1372}
1373
1374/**********************************************************************/
1384int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1386{
1387 return city_tile_output(pcity, ptile, city_celebrating(pcity), otype);
1388}
1389
1390/**********************************************************************/
1402 const struct city *pcity,
1403 const struct tile *ptile)
1404{
1405 struct player *powner = city_owner(pcity);
1407 struct player *towner;
1408
1409 if (NULL == ptile) {
1410 return FALSE;
1411 }
1412
1413 if (!city_base_to_city_map(&city_map_x, &city_map_y, pcity, ptile)) {
1414 return FALSE;
1415 }
1416
1417 if (NULL != restriction
1418 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1419 return FALSE;
1420 }
1421
1422 towner = tile_owner(ptile);
1423 if (NULL != towner && towner != powner
1424 && !gives_shared_tiles(towner, powner)) {
1425 return FALSE;
1426 }
1427 /* TODO: civ3-like option for borders */
1428
1429 if (NULL != tile_worked(ptile) && tile_worked(ptile) != pcity) {
1430 return FALSE;
1431 }
1432
1433 if (powner == restriction
1434 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1435 return FALSE;
1436 }
1437
1438 if (!is_free_worked(pcity, ptile)
1439 && NULL != unit_occupies_tile(ptile, powner)) {
1440 return FALSE;
1441 }
1442
1443 if (get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) {
1444 return FALSE;
1445 }
1446
1447 return TRUE;
1448}
1449
1450/**********************************************************************/
1456bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1457{
1458 return base_city_can_work_tile(city_owner(pcity), pcity, ptile);
1459}
1460
1461/**********************************************************************/
1466 const struct tile *ptile)
1467{
1468 /* citymindist minimum is 1, meaning adjacent is okay */
1469 int citymindist = game.info.citymindist;
1470
1471 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1472 if (tile_city(ptile1)) {
1473 return TRUE;
1474 }
1476
1477 return FALSE;
1478}
1479
1480/**********************************************************************/
1488 const struct tile *ptile,
1489 const struct unit *punit,
1490 bool hut_test)
1491{
1492 if (!city_can_be_built_tile_only(nmap, ptile)) {
1493 return FALSE;
1494 }
1495
1496 if (punit == NULL) {
1497 /* The remaining checks tests if punit can found a city here */
1498 return TRUE;
1499 }
1500
1501 if (hut_test) {
1502 struct player *towner;
1503
1504 /* Huts can be found only from native tiles, owned by the unit owner.
1505 * Unlike actual city building, this behavior is not affected
1506 * by the ruleset. */
1507 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1508 return FALSE;
1509 }
1510
1511 towner = tile_owner(ptile);
1512
1513 if (towner == NULL || towner == unit_owner(punit)) {
1514 return TRUE;
1515 }
1516
1517 return FALSE;
1518 }
1519
1522 /* This action can't be done by this unit type at all. */
1523 continue;
1524 }
1525
1526 /* Non native tile detection */
1527 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1528 /* The ruleset may allow founding cities on non native terrain. */
1531 /* Many rulesets allow land units to build land cities and sea units
1532 * to build ocean cities. Air units can build cities anywhere. */
1533 continue;
1534 }
1535
1536 /* Foreign tile detection. */
1537 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1538 /* The ruleset may allow founding cities on foreign terrain. */
1540 paction->id,
1541 DRO_FOREIGN, TRUE)) {
1542 /* Cannot steal borders by settling. This has to be settled by
1543 * force of arms. */
1544 continue;
1545 }
1546
1547 return TRUE;
1549
1550 return FALSE;
1551}
1552
1553/**********************************************************************/
1561 const struct tile *ptile)
1562{
1564 /* No cities on this terrain. */
1565 return FALSE;
1566 }
1567
1569 return FALSE;
1570 }
1571
1572 return TRUE;
1573}
1574
1575/**********************************************************************/
1579bool is_capital(const struct city *pcity)
1580{
1581 return pcity->capital != CAPITAL_NOT;
1582}
1583
1584/**********************************************************************/
1587bool is_gov_center(const struct city *pcity)
1588{
1589 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1590}
1591
1592/**********************************************************************/
1596bool city_got_defense_effect(const struct city *pcity,
1597 const struct unit_type *attacker)
1598{
1599 if (!attacker) {
1600 /* Any defense building will do */
1601 return get_city_bonus(pcity, EFT_DEFEND_BONUS) > 0;
1602 }
1603
1604 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1605 NULL, EFT_DEFEND_BONUS) > 0;
1606}
1607
1608/**********************************************************************/
1614bool city_happy(const struct city *pcity)
1615{
1616 return (city_size_get(pcity) >= game.info.celebratesize
1617 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1618 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1619 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1620}
1621
1622/**********************************************************************/
1626bool city_unhappy(const struct city *pcity)
1627{
1628 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1630 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1631}
1632
1633/**********************************************************************/
1637bool base_city_celebrating(const struct city *pcity)
1638{
1639 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1640}
1641
1642/**********************************************************************/
1645bool city_celebrating(const struct city *pcity)
1646{
1647 return base_city_celebrating(pcity) && city_happy(pcity);
1648}
1649
1650/**********************************************************************/
1653bool city_rapture_grow(const struct city *pcity)
1654{
1655 /* .rapture is checked instead of city_celebrating() because this
1656 function is called after .was_happy was updated. */
1657 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1658 && (pcity->rapture % game.info.rapturedelay) == 0
1659 && get_city_bonus(pcity, EFT_RAPTURE_GROW) > 0);
1660}
1661
1662/**********************************************************************/
1665bool city_is_occupied(const struct city *pcity)
1666{
1667 if (is_server()) {
1668 /* The server sees the units inside the city. */
1669 return (unit_list_size(city_tile(pcity)->units) > 0);
1670 } else {
1671 /* The client gets the occupied property from the server. */
1672 return pcity->client.occupied;
1673 }
1674}
1675
1676/**********************************************************************/
1679struct city *city_list_find_number(struct city_list *This, int id)
1680{
1681 if (id != 0) {
1682 city_list_iterate(This, pcity) {
1683 if (pcity->id == id) {
1684 return pcity;
1685 }
1687 }
1688
1689 return NULL;
1690}
1691
1692/**********************************************************************/
1695struct city *city_list_find_name(struct city_list *This, const char *name)
1696{
1697 city_list_iterate(This, pcity) {
1698 if (fc_strcasecmp(name, pcity->name) == 0) {
1699 return pcity;
1700 }
1702
1703 return NULL;
1704}
1705
1706/**********************************************************************/
1711int city_name_compare(const void *p1, const void *p2)
1712{
1713 return fc_strcasecmp((*(const struct city **) p1)->name,
1714 (*(const struct city **) p2)->name);
1715}
1716
1717/**********************************************************************/
1722{
1723 int i;
1724
1725 for (i = 0; i < game.control.num_city_styles; i++) {
1726 if (0 == strcmp(city_style_name_translation(i), s)) {
1727 return i;
1728 }
1729 }
1730
1731 return -1;
1732}
1733
1734/**********************************************************************/
1738int city_style_by_rule_name(const char *s)
1739{
1740 const char *qs = Qn_(s);
1741 int i;
1742
1743 for (i = 0; i < game.control.num_city_styles; i++) {
1744 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1745 return i;
1746 }
1747 }
1748
1749 return -1;
1750}
1751
1752/**********************************************************************/
1757{
1759}
1760
1761/**********************************************************************/
1765const char *city_style_rule_name(const int style)
1766{
1768}
1769
1770/* Cache of what city production caravan shields are allowed to help. */
1773
1774/**********************************************************************/
1779{
1780 struct requirement prod_as_req;
1781
1782#define log_ca_s_init log_debug
1783
1784 /* Remove old data. */
1787
1788 /* Common for all production kinds. */
1790 prod_as_req.survives = FALSE;
1791 prod_as_req.present = TRUE;
1792
1793 /* Check improvements */
1794 prod_as_req.source.kind = VUT_IMPROVEMENT;
1795
1797 /* Check this improvement. */
1798 prod_as_req.source.value.building = itype;
1799
1802 enabler) {
1804 &(enabler->target_reqs))
1805 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1806 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1807 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1808 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1809 /* This improvement kind can receive caravan shields. */
1810
1812
1813 /* Move on to the next improvement */
1814 break;
1815 }
1817
1818 log_ca_s_init("Help Wonder: %s for %s",
1820 ? "possible" : "impossible"),
1823
1824 /* Check units. */
1825 prod_as_req.source.kind = VUT_UTYPE;
1826
1828 /* Check this utype. */
1829 prod_as_req.source.value.utype = putype;
1830
1833 enabler) {
1835 &(enabler->target_reqs))
1836 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1837 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1838 /* This unit type kind can receive caravan shields. */
1839
1841
1842 /* Move on to the next unit type */
1843 break;
1844 }
1846
1847 log_ca_s_init("Help Wonder: %s for %s",
1849 ? "possible" : "impossible"),
1852
1853#undef log_ca_s_init
1854}
1855
1856/**********************************************************************/
1861{
1862 switch (tgt->kind) {
1863 case VUT_IMPROVEMENT:
1866 case VUT_UTYPE:
1868 utype_index(tgt->value.utype));
1869 default:
1871 return FALSE;
1872 };
1873}
1874
1875/**********************************************************************/
1886int city_change_production_penalty(const struct city *pcity,
1887 const struct universal *target)
1888{
1893
1894 switch (pcity->changed_from.kind) {
1895 case VUT_IMPROVEMENT:
1896 if (is_wonder(pcity->changed_from.value.building)) {
1898 } else {
1900 }
1901 break;
1902 case VUT_UTYPE:
1904 break;
1905 default:
1907 break;
1908 };
1909
1910 switch (target->kind) {
1911 case VUT_IMPROVEMENT:
1912 if (is_wonder(target->value.building)) {
1914 } else {
1916 }
1917 break;
1918 case VUT_UTYPE:
1920 break;
1921 default:
1923 break;
1924 };
1925
1926 /* Changing production is penalized under certain circumstances. */
1927 if (orig_class == new_class
1928 || orig_class == PCT_LAST) {
1929 /* There's never a penalty for building something of the same class. */
1931 } else if (city_built_last_turn(pcity)) {
1932 /* Surplus shields from the previous production won't be penalized if
1933 * you change production on the very next turn. But you can only use
1934 * up to the city's surplus amount of shields in this way. */
1936 pcity->before_change_shields);
1938 } else {
1939 /* Penalize 50% of the production. */
1941 }
1942
1943 /* Do not put penalty on these. It shouldn't matter whether you disband unit
1944 before or after changing production...*/
1946
1947 /* Caravan shields are penalized (just as if you disbanded the caravan)
1948 * if you're not building a wonder. */
1951 } else {
1953 }
1954
1957
1959}
1960
1961/**********************************************************************/
1965int city_turns_to_build(const struct city *pcity,
1966 const struct universal *target,
1968{
1969 int city_shield_surplus = pcity->surplus[O_SHIELD];
1971 city_change_production_penalty(pcity, target) : 0;
1972 int cost = universal_build_shield_cost(pcity, target);
1973
1974 if (target->kind == VUT_IMPROVEMENT
1975 && is_great_wonder(target->value.building)
1977 return FC_INFINITY;
1978 }
1979
1981 return 1;
1982 } else if (city_shield_surplus > 0) {
1983 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
1984 } else {
1985 return FC_INFINITY;
1986 }
1987}
1988
1989/**********************************************************************/
1996int city_turns_to_grow(const struct city *pcity)
1997{
1998 if (pcity->surplus[O_FOOD] > 0) {
1999 return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
2000 pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
2001 } else if (pcity->surplus[O_FOOD] < 0) {
2002 /* Turns before famine loss */
2003 return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
2004 } else {
2005 return FC_INFINITY;
2006 }
2007}
2008
2009/**********************************************************************/
2012bool city_can_grow_to(const struct city *pcity, int pop_size)
2013{
2014 return (get_city_bonus(pcity, EFT_SIZE_UNLIMIT) > 0
2015 || pop_size <= get_city_bonus(pcity, EFT_SIZE_ADJ));
2016}
2017
2018/**********************************************************************/
2021struct city *tile_enemy_city(const struct tile *ptile,
2022 const struct player *pplayer)
2023{
2024 struct city *pcity = tile_city(ptile);
2025
2026 if (pcity != NULL && pplayers_at_war(pplayer, city_owner(pcity))) {
2027 return pcity;
2028 }
2029
2030 return NULL;
2031}
2032
2033/**********************************************************************/
2036struct city *tile_allied_city(const struct tile *ptile,
2037 const struct player *pplayer)
2038{
2039 struct city *pcity = tile_city(ptile);
2040
2041 if (pcity != NULL && pplayers_allied(pplayer, city_owner(pcity))) {
2042 return pcity;
2043 }
2044
2045 return NULL;
2046}
2047
2048/**********************************************************************/
2051struct city *tile_non_attack_city(const struct tile *ptile,
2052 const struct player *pplayer)
2053{
2054 struct city *pcity = tile_city(ptile);
2055
2056 if (pcity != NULL && pplayers_non_attack(pplayer, city_owner(pcity))) {
2057 return pcity;
2058 }
2059
2060 return NULL;
2061}
2062
2063/**********************************************************************/
2066struct city *tile_non_allied_city(const struct tile *ptile,
2067 const struct player *pplayer)
2068{
2069 struct city *pcity = tile_city(ptile);
2070
2071 if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) {
2072 return pcity;
2073 }
2074
2075 return NULL;
2076}
2077
2078/**********************************************************************/
2082 const struct unit *punit,
2083 int distance)
2084{
2086 distance);
2087}
2088
2089/**********************************************************************/
2093 const struct player *owner,
2094 const struct tile *ptile,
2095 int distance)
2096{
2097 square_iterate(nmap, ptile, distance, ptile1) {
2098 struct city *pcity = tile_city(ptile1);
2099
2100 if (pcity && pplayers_allied(owner, city_owner(pcity))) {
2101 return TRUE;
2102 }
2104
2105 return FALSE;
2106}
2107
2108/**********************************************************************/
2113 const struct tile *ptile,
2114 bool may_be_on_center)
2115{
2117 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2118 if (tile_city(ptile1)) {
2119 return TRUE;
2120 }
2121 }
2123
2124 return FALSE;
2125}
2126
2127/**********************************************************************/
2132int city_granary_size(int city_size)
2133{
2136 int base_value;
2137
2138 /* If the city has no citizens, there is no granary. */
2139 if (city_size == 0) {
2140 return 0;
2141 }
2142
2143 /* Granary sizes for the first food_inis citizens are given directly.
2144 * After that we increase the granary size by food_inc per citizen. */
2145 if (city_size > food_inis) {
2146 base_value = game.info.granary_food_ini[food_inis - 1];
2147 base_value += food_inc * (city_size - food_inis);
2148 } else {
2149 base_value = game.info.granary_food_ini[city_size - 1];
2150 }
2151
2152 return MAX(base_value * game.info.foodbox / 100, 1);
2153}
2154
2155/**********************************************************************/
2160static int player_base_citizen_happiness(const struct player *pplayer)
2161{
2162 int cities = city_list_size(pplayer->cities);
2163 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2166
2167 if (basis + step <= 0) {
2168 /* Value of zero means effect is inactive */
2169 return content;
2170 }
2171
2172 if (cities > basis) {
2173 content--;
2174 if (step != 0) {
2175 /* the first penalty is at (basis + 1) cities;
2176 the next is at (basis + step + 1), _not_ (basis + step) */
2177 content -= (cities - basis - 1) / step;
2178 }
2179 }
2180 return content;
2181}
2182
2183/**********************************************************************/
2187{
2188 int content = player_base_citizen_happiness(pplayer);
2189
2190 return CLIP(0, content, MAX_CITY_SIZE);
2191}
2192
2193/**********************************************************************/
2197{
2198 if (!game.info.angrycitizen) {
2199 return 0;
2200 } else {
2201 /* Create angry citizens only if we have a negative number of possible
2202 * content citizens. This can happen when empires grow really big. */
2203 int content = player_base_citizen_happiness(pplayer);
2204
2205 return CLIP(0, -content, MAX_CITY_SIZE);
2206 }
2207}
2208
2209/**********************************************************************/
2213{
2214 struct output_type *output = &output_types[otype];
2215 int bonus1 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
2217 int bonus2 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
2219
2220 return MAX(bonus1 * bonus2 / 100, 0);
2221}
2222
2223/**********************************************************************/
2227int get_city_tithes_bonus(const struct city *pcity)
2228{
2229 int tithes_bonus = 0;
2230
2231 if (get_city_bonus(pcity, EFT_HAPPINESS_TO_GOLD) <= 0) {
2232 return 0;
2233 }
2234
2237
2238 return tithes_bonus;
2239}
2240
2241/**********************************************************************/
2245void add_tax_income(const struct player *pplayer, int trade, int *output)
2246{
2247 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2248 unsigned rates[3];
2249 int result[3];
2250
2251 if (game.info.changable_tax) {
2252 rates[SCIENCE] = pplayer->economic.science;
2253 rates[LUXURY] = pplayer->economic.luxury;
2254 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2255 } else {
2259 }
2260
2261 /* ANARCHY */
2263 rates[SCIENCE] = 0;
2264 rates[LUXURY] = 100;
2265 rates[TAX] = 0;
2266 }
2267
2268 distribute(trade, 3, rates, result);
2269
2270 output[O_SCIENCE] += result[SCIENCE];
2271 output[O_GOLD] += result[TAX];
2272 output[O_LUXURY] += result[LUXURY];
2273}
2274
2275/**********************************************************************/
2279bool city_built_last_turn(const struct city *pcity)
2280{
2281 return pcity->turn_last_built + 1 >= game.info.turn;
2282}
2283
2284/**********************************************************************/
2287static const struct city *nearest_gov_center(const struct city *pcity,
2288 int *min_dist)
2289{
2290 const struct city *gov_center = NULL;
2291
2293
2294 /* Check the special case that city itself is gov center
2295 * before expensive iteration through all cities. */
2296 if (is_gov_center(pcity)) {
2297 *min_dist = 0;
2298 return pcity;
2299 } else {
2301 /* Do not recheck current city */
2302 if (gc != pcity && is_gov_center(gc)) {
2303 int dist = real_map_distance(gc->tile, pcity->tile);
2304
2305 if (dist < *min_dist) {
2306 gov_center = gc;
2307 *min_dist = dist;
2308 }
2309 }
2311 }
2312
2313 return gov_center;
2314}
2315
2316/**********************************************************************/
2324static inline void get_worked_tile_output(const struct civ_map *nmap,
2325 const struct city *pcity,
2326 int *output, bool *workers_map)
2327{
2328 bool is_worked;
2329#ifdef CITY_DEBUGGING
2331#endif
2332 struct tile *pcenter = city_tile(pcity);
2333
2334 memset(output, 0, O_LAST * sizeof(*output));
2335
2338 if (workers_map == NULL) {
2339 struct city *pwork = tile_worked(ptile);
2340
2341 is_worked = (NULL != pwork && pwork == pcity);
2342 } else {
2343 is_worked = workers_map[city_tile_index];
2344 }
2345
2346 if (is_worked) {
2348#ifdef CITY_DEBUGGING
2349 /* This assertion never fails, but it's so slow that we disable
2350 * it by default. */
2352 == city_tile_output(pcity, ptile, is_celebrating, o));
2353#endif /* CITY_DEBUGGING */
2354 output[o] += city_tile_cache_get_output(pcity, city_tile_index, o);
2356 }
2358}
2359
2360/**********************************************************************/
2364void add_specialist_output(const struct city *pcity, int *output)
2365{
2367 int count = pcity->specialists[sp];
2368
2371
2372 output[stat_index] += count * amount;
2375}
2376
2377/**********************************************************************/
2386static inline void set_city_bonuses(struct city *pcity)
2387{
2389 pcity->bonus[o] = get_final_city_output_bonus(pcity, o);
2390 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2391 &output_types[o],
2393 /* Total bonus cannot be negative, as that could lead to unresolvable
2394 * negative balance. */
2395 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2397}
2398
2399/**********************************************************************/
2409static inline void city_tile_cache_update(const struct civ_map *nmap,
2410 struct city *pcity)
2411{
2413 int radius_sq = city_map_radius_sq_get(pcity);
2414
2415 /* Initialize tile_cache if needed */
2416 if (pcity->tile_cache == NULL || pcity->tile_cache_radius_sq == -1
2417 || pcity->tile_cache_radius_sq != radius_sq) {
2418 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2419 city_map_tiles(radius_sq)
2420 * sizeof(*(pcity->tile_cache)));
2421 pcity->tile_cache_radius_sq = radius_sq;
2422 }
2423
2424 /* Any unreal tiles are skipped - these values should have been memset
2425 * to 0 when the city was created. */
2426 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2428 (pcity->tile_cache[city_tile_index]).output[o]
2429 = city_tile_output(pcity, ptile, is_celebrating, o);
2432}
2433
2434/**********************************************************************/
2438static inline int city_tile_cache_get_output(const struct city *pcity,
2439 int city_tile_index,
2440 enum output_type_id o)
2441{
2443 == city_map_radius_sq_get(pcity), 0);
2445
2446 return (pcity->tile_cache[city_tile_index]).output[o];
2447}
2448
2449/**********************************************************************/
2452static void set_surpluses(struct city *pcity)
2453{
2455 int surplus = pcity->prod[o] - pcity->usage[o];
2456
2457 /* Add 'surplus' waste to 'usage'. */
2458 if (surplus > 0) {
2459 struct output_type *output = get_output_type(o);
2463
2464 if (waste_by_rel_dist > 0) {
2465 int min_dist;
2466 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2467
2468 if (gov_center == NULL) {
2469 /* No gov center - no income */
2470 waste_level = 100;
2471 } else {
2472 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2474 }
2475 }
2476
2477 if (waste_level > 0) {
2478 if (waste_level < 100) {
2479 pcity->usage[o] += (surplus * waste_level / 100);
2480 } else {
2481 pcity->usage[o] = pcity->prod[o];
2482 }
2483 }
2484 }
2485
2486 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2488}
2489
2490/**********************************************************************/
2493static void happy_copy(struct city *pcity, enum citizen_feeling i)
2494{
2495 int c = 0;
2496
2497 for (; c < CITIZEN_LAST; c++) {
2498 pcity->feel[c][i] = pcity->feel[c][i - 1];
2499 }
2500}
2501
2502/**********************************************************************/
2505static void citizen_base_mood(struct city *pcity)
2506{
2507 struct player *pplayer = city_owner(pcity);
2508 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2509 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2510 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2511 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2512 citizens size = city_size_get(pcity);
2514
2515 /* This is the number of citizens that may start out content, depending
2516 * on empire size and game's city unhappysize. This may be bigger than
2517 * the size of the city, since this is a potential. */
2519 /* Similarly, this is the potential number of angry citizens. */
2521
2522 /* Create content citizens. Take specialists from their ranks. */
2523 *content = MAX(0, MIN(size, base_content) - spes);
2524
2525 /* Create angry citizens. Specialists never become angry. */
2526 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2527 *angry = MIN(base_angry, size - spes);
2528
2529 /* Create unhappy citizens. In the beginning, all who are not content,
2530 * specialists or angry are unhappy. This is changed by luxuries and
2531 * buildings later. */
2532 *unhappy = (size - spes - *content - *angry);
2533
2534 /* No one is born happy. */
2535 *happy = 0;
2536}
2537
2538/**********************************************************************/
2544static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2545{
2546 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2547 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2548 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2549 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2550
2551 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2552 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2553 (*angry)--;
2554 (*unhappy)++;
2556 }
2557 while (*luxuries >= game.info.happy_cost && *content > 0) {
2558 /* Upgrade content to happy: costs HAPPY_COST each. */
2559 (*content)--;
2560 (*happy)++;
2562 }
2563 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2564 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2565 * double the cost. */
2566 (*unhappy)--;
2567 (*happy)++;
2568 *luxuries -= 2 * game.info.happy_cost;
2569 }
2570 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2571 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2572 (*unhappy)--;
2573 (*content)++;
2575 }
2576}
2577
2578/**********************************************************************/
2581static inline void citizen_happy_luxury(struct city *pcity)
2582{
2583 int x = pcity->prod[O_LUXURY];
2584
2585 citizen_luxury_happy(pcity, &x);
2586}
2587
2588/**********************************************************************/
2591static inline void citizen_content_buildings(struct city *pcity)
2592{
2593 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2594 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2595 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2597
2598 /* make people content (but not happy):
2599 get rid of angry first, then make unhappy content. */
2600 while (faces > 0 && *angry > 0) {
2601 (*angry)--;
2602 (*unhappy)++;
2603 faces--;
2604 }
2605 while (faces > 0 && *unhappy > 0) {
2606 (*unhappy)--;
2607 (*content)++;
2608 faces--;
2609 }
2610}
2611
2612/**********************************************************************/
2615static inline void citizen_happiness_nationality(struct city *pcity)
2616{
2618 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_NATIONALITY];
2619 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_NATIONALITY];
2620
2623
2624 if (pct > 0) {
2625 int enemies = 0;
2626 int unhappy_inc;
2627 struct player *owner = city_owner(pcity);
2628
2629 citizens_foreign_iterate(pcity, pslot, nationality) {
2631 enemies += nationality;
2632 }
2634
2635 unhappy_inc = enemies * pct / 100;
2636
2637 /* First make content => unhappy, then happy => unhappy,
2638 * then happy => content. No-one becomes angry. */
2639 while (unhappy_inc > 0 && *content > 0) {
2640 (*content)--;
2641 (*unhappy)++;
2642 unhappy_inc--;
2643 }
2644 while (unhappy_inc > 1 && *happy > 0) {
2645 (*happy)--;
2646 (*unhappy)++;
2647 unhappy_inc -= 2;
2648 }
2649 while (unhappy_inc > 0 && *happy > 0) {
2650 (*happy)--;
2651 (*content)++;
2652 unhappy_inc--;
2653 }
2654 }
2655 }
2656}
2657
2658/**********************************************************************/
2664static inline void citizen_happy_units(struct city *pcity)
2665{
2666 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2667 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2668 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2669 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2670 citizens amt = pcity->martial_law;
2671
2672 /* Pacify discontent citizens through martial law. First convert
2673 * angry => unhappy, then unhappy => content. */
2674 while (amt > 0 && *angry > 0) {
2675 (*angry)--;
2676 (*unhappy)++;
2677 amt--;
2678 }
2679 while (amt > 0 && *unhappy > 0) {
2680 (*unhappy)--;
2681 (*content)++;
2682 amt--;
2683 }
2684
2685 /* Now make citizens unhappier because of military units away from home.
2686 * First make content => unhappy, then happy => unhappy,
2687 * then happy => content. */
2688 amt = pcity->unit_happy_upkeep;
2689 while (amt > 0 && *content > 0) {
2690 (*content)--;
2691 (*unhappy)++;
2692 amt--;
2693 }
2694 while (amt > 1 && *happy > 0) {
2695 (*happy)--;
2696 (*unhappy)++;
2697 amt -= 2;
2698 }
2699 while (amt > 0 && *happy > 0) {
2700 (*happy)--;
2701 (*content)++;
2702 amt--;
2703 }
2704 /* Any remaining unhappiness is lost since angry citizens aren't created
2705 * here. */
2706 /* FIXME: Why not? - Per */
2707}
2708
2709/**********************************************************************/
2712static inline void citizen_happy_wonders(struct city *pcity)
2713{
2714 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2715 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2716 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2717 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2718 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2719
2720 /* First create happy citizens from content, then from unhappy
2721 * citizens; we cannot help angry citizens here. */
2722 while (bonus > 0 && *content > 0) {
2723 (*content)--;
2724 (*happy)++;
2725 bonus--;
2726 }
2727 while (bonus > 1 && *unhappy > 0) {
2728 (*unhappy)--;
2729 (*happy)++;
2730 bonus -= 2;
2731 }
2732 /* The rest falls through and lets unhappy people become content. */
2733
2734 if (get_city_bonus(pcity, EFT_NO_UNHAPPY) > 0) {
2735 *content += *unhappy + *angry;
2736 *unhappy = 0;
2737 *angry = 0;
2738 return;
2739 }
2740
2741 bonus += get_city_bonus(pcity, EFT_FORCE_CONTENT);
2742
2743 /* get rid of angry first, then make unhappy content */
2744 while (bonus > 0 && *angry > 0) {
2745 (*angry)--;
2746 (*unhappy)++;
2747 bonus--;
2748 }
2749 while (bonus > 0 && *unhappy > 0) {
2750 (*unhappy)--;
2751 (*content)++;
2752 bonus--;
2753 }
2754}
2755
2756/**********************************************************************/
2760static inline void unhappy_city_check(struct city *pcity)
2761{
2762 if (city_unhappy(pcity)) {
2764 switch (output_types[o].unhappy_penalty) {
2766 pcity->unhappy_penalty[o] = 0;
2767 break;
2769 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2770 break;
2772 pcity->unhappy_penalty[o] = pcity->prod[o];
2773 break;
2774 }
2775
2776 pcity->prod[o] -= pcity->unhappy_penalty[o];
2778 } else {
2779 memset(pcity->unhappy_penalty, 0,
2780 O_LAST * sizeof(*pcity->unhappy_penalty));
2781 }
2782}
2783
2784/**********************************************************************/
2787int city_pollution_types(const struct city *pcity, int shield_total,
2788 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2789{
2790 int prod, pop, mod;
2791
2792 /* Add one one pollution per shield, multipled by the bonus. */
2793 prod = 100 + get_city_bonus(pcity, EFT_POLLU_PROD_PCT);
2794 prod = shield_total * MAX(prod, 0) / 100;
2795
2796 /* Add one pollution per citizen for baseline combined bonus (100%). */
2797 pop = (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT))
2798 * (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT_2))
2799 / 100;
2800 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2801
2802 /* Then there is base pollution (usually a negative number). */
2803 mod = game.info.base_pollution;
2804
2805 if (pollu_prod) {
2806 *pollu_prod = prod;
2807 }
2808 if (pollu_pop) {
2809 *pollu_pop = pop;
2810 }
2811 if (pollu_mod) {
2812 *pollu_mod = mod;
2813 }
2814 return MAX(prod + pop + mod, 0);
2815}
2816
2817/**********************************************************************/
2821int city_pollution(const struct city *pcity, int shield_total)
2822{
2824}
2825
2826/**********************************************************************/
2833static int get_trade_illness(const struct city *pcity)
2834{
2835 float illness_trade = 0.0;
2836
2838 if (trade_city->turn_plague != -1
2839 && game.info.turn - trade_city->turn_plague < 5) {
2840 illness_trade += (float)game.info.illness_trade_infection
2841 * sqrt(1.0 * city_size_get(pcity)
2842 * city_size_get(trade_city)) / 100.0;
2843 }
2845
2846 return (int)illness_trade;
2847}
2848
2849/**********************************************************************/
2853static int get_city_health(const struct city *pcity)
2854{
2855 return get_city_bonus(pcity, EFT_HEALTH_PCT);
2856}
2857
2858/**********************************************************************/
2870int city_illness_calc(const struct city *pcity, int *ill_base,
2871 int *ill_size, int *ill_trade, int *ill_pollution)
2872{
2873 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2875
2876 if (game.info.illness_on
2878 /* offset the city size by game.info.illness_min_size */
2880
2881 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2882 * 10.0 * game.info.illness_base_factor);
2883 if (is_server()) {
2884 /* on the server we recalculate the illness due to trade as we have
2885 * all informations */
2886 illness_trade = get_trade_illness(pcity);
2887 } else {
2888 /* on the client we have to rely on the value saved within the city
2889 * struct */
2890 illness_trade = pcity->illness_trade;
2891 }
2892
2895 }
2896
2897 illness_base = illness_size + illness_trade + illness_pollution;
2898 illness_percent = 100 - get_city_health(pcity);
2899
2900 /* returning other data */
2901 if (ill_size) {
2903 }
2904
2905 if (ill_trade) {
2906 *ill_trade = illness_trade;
2907 }
2908
2909 if (ill_pollution) {
2911 }
2912
2913 if (ill_base) {
2915 }
2916
2917 return CLIP(0, illness_base * illness_percent / 100 , 999);
2918}
2919
2920/**********************************************************************/
2923bool city_had_recent_plague(const struct city *pcity)
2924{
2925 /* Correctly handles special case turn_plague == -1 (never) */
2926 return (pcity->turn_plague == game.info.turn);
2927}
2928
2929/**********************************************************************/
2932int city_build_slots(const struct city *pcity)
2933{
2934 return get_city_bonus(pcity, EFT_CITY_BUILD_SLOTS);
2935}
2936
2937/**********************************************************************/
2942int city_airlift_max(const struct city *pcity)
2943{
2944 return get_city_bonus(pcity, EFT_AIRLIFT);
2945}
2946
2947/**********************************************************************/
2953inline void set_city_production(struct city *pcity)
2954{
2955 int trade;
2956
2957 /* Calculate city production!
2958 *
2959 * This is a rather complicated process if we allow rules to become
2960 * more generalized. We can assume that there are no recursive dependency
2961 * loops, but there are some dependencies that do not follow strict
2962 * ordering. For instance corruption must be calculated before
2963 * trade taxes can be counted up, which must occur before the science bonus
2964 * is added on. But the calculation of corruption must include the
2965 * trade bonus. To do this without excessive special casing means that in
2966 * this case the bonuses are multiplied on twice (but only saved the second
2967 * time).
2968 */
2969
2971 pcity->prod[o] = pcity->citizen_base[o];
2973
2974 /* Add on special extra incomes: trade routes and tithes. */
2976 struct city *tcity = game_city_by_number(proute->partner);
2977 bool can_trade;
2978
2979 /* Partner city may have not yet been sent to the client, or
2980 * there's just a placeholder city with a placeholder owner
2981 * created for some tile->worked. */
2982 if (!is_server()
2983 && (tcity == NULL
2984 || city_owner(tcity)->slot == NULL)) {
2985 continue;
2986 }
2987
2988 fc_assert_action(tcity != NULL, continue);
2989
2991
2992 if (!can_trade) {
2995
2996 if (settings->cancelling == TRI_ACTIVE) {
2997 can_trade = TRUE;
2998 }
2999 }
3000
3001 if (can_trade) {
3002 int value;
3003
3004 value =
3006 proute->value = trade_from_route(pcity, proute, value);
3007 pcity->prod[O_TRADE] += proute->value
3008 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3009 } else {
3010 proute->value = 0;
3011 }
3013 pcity->prod[O_GOLD] += get_city_tithes_bonus(pcity);
3014
3015 /* Account for waste. Note that waste is calculated before tax income is
3016 * calculated, so if you had "science waste" it would not include taxed
3017 * science. However waste is calculated after the bonuses are multiplied
3018 * on, so shield waste will include shield bonuses. */
3020 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3021
3022 prod = MAX(prod, 0);
3023 pcity->waste[o] = city_waste(pcity, o, prod, NULL);
3025
3026 /* Convert trade into science/luxury/gold, and add this on to whatever
3027 * science/luxury/gold is already there. */
3028 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3029 + pcity->abs_bonus[O_TRADE];
3030 trade = MAX(trade, 0);
3032 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3033 pcity->prod);
3034
3035 /* Add on effect bonuses and waste. Note that the waste calculation
3036 * (above) already includes the bonuses. */
3038 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3039
3040 prod = MAX(prod, 0);
3041 pcity->prod[o] = prod;
3042 pcity->prod[o] -= pcity->waste[o];
3044}
3045
3046/**********************************************************************/
3050 struct unit *punit, int *free_unhappy)
3051{
3052 struct city *pcity;
3053 const struct unit_type *ut;
3054 struct player *plr;
3055 int happy_cost;
3056
3057 if (punit == NULL || free_unhappy == NULL) {
3058 return 0;
3059 }
3060
3062 if (pcity == NULL) {
3063 return 0;
3064 }
3065
3067 plr = unit_owner(punit);
3068 happy_cost = utype_happy_cost(ut, plr);
3069
3070 if (happy_cost <= 0) {
3071 return 0;
3072 }
3073
3075
3077 return 0;
3078 }
3079
3080 happy_cost -= get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL_PER);
3081 if (happy_cost <= 0) {
3082 return 0;
3083 }
3084
3085 if (*free_unhappy >= happy_cost) {
3086 *free_unhappy -= happy_cost;
3087 return 0;
3088 } else {
3089 happy_cost -= *free_unhappy;
3090 *free_unhappy = 0;
3091 }
3092
3093 return happy_cost;
3094}
3095
3096/**********************************************************************/
3100static inline void city_support(const struct civ_map *nmap,
3101 struct city *pcity)
3102{
3104
3105 /* Clear all usage values. */
3106 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3107 pcity->martial_law = 0;
3108 pcity->unit_happy_upkeep = 0;
3109
3110 /* Building and unit gold upkeep depends on the setting
3111 * 'game.info.gold_upkeep_style':
3112 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3113 * city.
3114 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3115 * The upkeep for units is paid by the nation.
3116 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3117 * nation. */
3119 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3120 switch (game.info.gold_upkeep_style) {
3121 case GOLD_UPKEEP_CITY:
3122 pcity->usage[O_GOLD] += city_total_unit_gold_upkeep(pcity);
3123 fc__fallthrough; /* No break */
3124 case GOLD_UPKEEP_MIXED:
3125 pcity->usage[O_GOLD] += city_total_impr_gold_upkeep(pcity);
3126 break;
3127 case GOLD_UPKEEP_NATION:
3128 /* nothing */
3129 break;
3130 }
3131 /* Food consumption by citizens. */
3132 pcity->usage[O_FOOD] += game.info.food_cost * city_size_get(pcity);
3133
3134 /* Military units in this city (need _not_ be home city) can make
3135 * unhappy citizens content */
3137 if (martial_law_each > 0) {
3138 int count = 0;
3140
3141 unit_list_iterate(pcity->tile->units, punit) {
3142 if ((count < martial_law_max || martial_law_max == 0)
3144 && unit_owner(punit) == city_owner(pcity)) {
3145 count++;
3146 }
3148
3149 pcity->martial_law = CLIP(0, count * martial_law_each, MAX_CITY_SIZE);
3150 }
3151
3156 if (O_GOLD != o) {
3157 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3158 pcity->usage[o] += punit->upkeep[o];
3159 }
3162}
3163
3164/**********************************************************************/
3177 struct city *pcity, bool *workers_map)
3178{
3179 if (workers_map == NULL) {
3180 /* do a full refresh */
3181
3182 /* Calculate the bonus[] array values. */
3183 set_city_bonuses(pcity);
3184 /* Calculate the tile_cache[] values. */
3186 /* manage settlers, and units */
3187 city_support(nmap, pcity);
3188 }
3189
3190 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3191 get_worked_tile_output(nmap, pcity, pcity->citizen_base, workers_map);
3192 add_specialist_output(pcity, pcity->citizen_base);
3193
3194 set_city_production(pcity);
3195 citizen_base_mood(pcity);
3196 /* Note that pollution is calculated before unhappy_city_check() makes
3197 * deductions for disorder; so a city in disorder still causes pollution */
3198 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3199
3200 happy_copy(pcity, FEELING_LUXURY);
3201 citizen_happy_luxury(pcity); /* With our new found luxuries */
3202
3203 happy_copy(pcity, FEELING_EFFECT);
3205
3208
3209 /* Martial law & unrest from units */
3211 citizen_happy_units(pcity);
3212
3213 /* Building (including wonder) happiness effects */
3214 happy_copy(pcity, FEELING_FINAL);
3215 citizen_happy_wonders(pcity);
3216
3217 unhappy_city_check(pcity);
3218 set_surpluses(pcity);
3219}
3220
3221/**********************************************************************/
3228int city_waste(const struct city *pcity, Output_type_id otype, int total,
3229 int *breakdown)
3230{
3231 int penalty_waste = 0;
3232 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3233 * corruption */
3234 int total_eft = total; /* Normal corruption calculated on total reduced by
3235 * possible size penalty */
3236 const struct output_type *output = get_output_type(otype);
3238 bool waste_all = FALSE;
3239
3240 if (otype == O_TRADE) {
3241 /* FIXME: special case for trade: it is affected by notradesize and
3242 * fulltradesize server settings.
3243 *
3244 * If notradesize and fulltradesize are equal then the city gets no
3245 * trade at that size. */
3246 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3247 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3248
3249 if (city_size_get(pcity) <= notradesize) {
3250 penalty_size = total_eft; /* Then no trade income. */
3251 } else if (city_size_get(pcity) >= fulltradesize) {
3252 penalty_size = 0;
3253 } else {
3254 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3255 / (fulltradesize - notradesize);
3256 }
3257 }
3258
3259 /* Apply corruption only to anything left after tradesize */
3261
3262 /* Distance-based waste.
3263 * Don't bother calculating if there's nothing left to lose. */
3264 if (total_eft > 0) {
3265 int waste_by_dist = get_city_output_bonus(pcity, output,
3267 int waste_by_rel_dist = get_city_output_bonus(pcity, output,
3269 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3270 int min_dist;
3271 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3272
3273 if (gov_center == NULL) {
3274 waste_all = TRUE; /* No gov center - no income */
3275 } else {
3277 if (waste_by_rel_dist > 0) {
3278 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3279 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3280 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3282 }
3283 }
3284 }
3285 }
3286
3287 if (waste_all) {
3289 } else {
3290 int waste_pct = get_city_output_bonus(pcity, output,
3292
3293 /* Corruption/waste calculated only for the actually produced amount */
3294 if (waste_level > 0) {
3296 }
3297
3298 /* Bonus calculated only for the actually produced amount */
3300
3301 /* Clip */
3303 }
3304
3305 if (breakdown) {
3308 }
3309
3310 /* Add up total penalty */
3311 return penalty_waste + penalty_size;
3312}
3313
3314/**********************************************************************/
3317citizens city_specialists(const struct city *pcity)
3318{
3319 citizens count = 0;
3320
3322 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3323 count += pcity->specialists[sp];
3325
3326 return count;
3327}
3328
3329/**********************************************************************/
3335 const struct city *pcity)
3336{
3337 int best = DEFAULT_SPECIALIST;
3338 int val = get_specialist_output(pcity, best, otype);
3339
3341 if (!pcity || city_can_use_specialist(pcity, i)) {
3342 int val2 = get_specialist_output(pcity, i, otype);
3343
3344 if (val2 > val) {
3345 best = i;
3346 val = val2;
3347 }
3348 }
3350
3351 return best;
3352}
3353
3354/**********************************************************************/
3357void city_add_improvement(struct city *pcity,
3358 const struct impr_type *pimprove)
3359{
3360 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3361
3362 if (is_server() && is_wonder(pimprove)) {
3363 /* Client just read the info from the packets. */
3364 wonder_built(pcity, pimprove);
3365 }
3366}
3367
3368/**********************************************************************/
3372 const struct impr_type *pimprove)
3373{
3374 log_debug("Improvement %s removed from city %s",
3375 improvement_rule_name(pimprove), pcity->name);
3376
3377 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3378
3379 if (is_server() && is_wonder(pimprove)) {
3380 /* Client just read the info from the packets. */
3381 wonder_destroyed(pcity, pimprove);
3382 }
3383}
3384
3385/**********************************************************************/
3388bool is_city_option_set(const struct city *pcity, enum city_options option)
3389{
3390 return BV_ISSET(pcity->city_options, option);
3391}
3392
3393/**********************************************************************/
3397{
3398 int i;
3399
3400 city_styles = fc_calloc(num, sizeof(*city_styles));
3402
3403 for (i = 0; i < game.control.num_city_styles; i++) {
3405 }
3406}
3407
3408/**********************************************************************/
3412{
3413 int i;
3414
3415 for (i = 0; i < game.control.num_city_styles; i++) {
3417 }
3418
3420 city_styles = NULL;
3422}
3423
3424/**********************************************************************/
3430struct city *create_city_virtual(struct player *pplayer,
3431 struct tile *ptile, const char *name)
3432{
3433 int i,len;
3434
3435 /* Make sure that contents of city structure are correctly initialized,
3436 * if you ever allocate it by some other mean than fc_calloc() */
3437 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3438
3439 fc_assert_ret_val(NULL != name, NULL); /* No unnamed cities! */
3440
3441 /* Do this early, so any logging later will have the city name */
3442 city_name_set(pcity, name);
3443
3444 pcity->tile = ptile;
3445 fc_assert_ret_val(NULL != pplayer, NULL); /* No unowned cities! */
3446 pcity->owner = pplayer;
3447 pcity->acquire_t = CACQ_FOUNDED;
3448
3449 if (is_server()) {
3450 pcity->original = pplayer;
3451 }
3452
3453 /* City structure was allocated with fc_calloc(), so contents are initially
3454 * zero. There is no need to initialize it a second time. */
3455
3456 /* Now set some useful default values. */
3457 pcity->capital = CAPITAL_NOT;
3458 city_size_set(pcity, 1);
3459 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3460 pcity->wlcb = WLCB_SMART;
3461
3463 pcity->bonus[o] = 100;
3464 pcity->abs_bonus[o] = 0;
3466
3467 pcity->turn_plague = -1; /* -1 = never */
3468 pcity->did_buy = FALSE;
3470 pcity->turn_founded = game.info.turn;
3471 pcity->turn_last_built = game.info.turn;
3472
3473 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3474
3475 /* pcity->ai.act_cache: worker activities on the city map */
3476
3477 /* Initialise improvements list */
3478 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3479 pcity->built[i].turn = I_NEVER;
3480 }
3481
3482 /* Set up the worklist */
3483 worklist_init(&pcity->worklist);
3484
3485 pcity->units_supported = unit_list_new();
3486 pcity->routes = trade_route_list_new();
3488
3489 if (is_server()) {
3490 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3491
3492 CALL_FUNC_EACH_AI(city_alloc, pcity);
3493 } else {
3496 pcity->client.info_units_present =
3498 /* collecting_info_units_supported set by fc_calloc().
3499 * collecting_info_units_present set by fc_calloc(). */
3500 }
3501
3503 pcity->counter_values = fc_malloc(sizeof(int) * len);
3504
3505 for (i = 0; i < len; i++) {
3507 }
3508
3509 return pcity;
3510}
3511
3512/**********************************************************************/
3516void destroy_city_virtual(struct city *pcity)
3517{
3518 CALL_FUNC_EACH_AI(city_free, pcity);
3519
3520 citizens_free(pcity);
3521
3522 /* Free worker tasks */
3523 while (worker_task_list_size(pcity->task_reqs) > 0) {
3524 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3525
3527
3528 free(ptask);
3529 }
3531
3532 /* Free rally points */
3534
3537 if (pcity->tile_cache != NULL) {
3538 free(pcity->tile_cache);
3539 }
3540
3541 if (pcity->cm_parameter) {
3542 free(pcity->cm_parameter);
3543 }
3544
3545 if (pcity->counter_values) {
3546 free(pcity->counter_values);
3547 }
3548
3549 if (!is_server()) {
3552 /* Handle a rare case where the game is freed in the middle of a
3553 * spy/diplomat investigate cycle. */
3556 }
3559 }
3560 }
3561
3562 free(pcity->name);
3563
3564 memset(pcity, 0, sizeof(*pcity)); /* ensure no pointers remain */
3565 free(pcity);
3566}
3567
3568/**********************************************************************/
3572bool city_exist(int id)
3573{
3574 /* Check if city exist in game */
3575 if (game_city_by_number(id)) {
3576 return TRUE;
3577 }
3578
3579 return FALSE;
3580}
3581
3582/**********************************************************************/
3589bool city_is_virtual(const struct city *pcity)
3590{
3591 if (!pcity) {
3592 return FALSE;
3593 }
3594
3595 return pcity != game_city_by_number(pcity->id);
3596}
3597
3598/**********************************************************************/
3601bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3602{
3603 return is_city_center(pcity, ptile);
3604}
3605
3606/**********************************************************************/
3609void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3610{
3611 return pcity->server.ais[ai_type_number(ai)];
3612}
3613
3614/**********************************************************************/
3617void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3618 void *data)
3619{
3620 pcity->server.ais[ai_type_number(ai)] = data;
3621}
3622
3623/**********************************************************************/
3626void city_rally_point_clear(struct city *pcity)
3627{
3628 /* Free rally points */
3629 if (pcity->rally_point.length > 0) {
3630 pcity->rally_point.length = 0;
3631 pcity->rally_point.persistent = FALSE;
3632 pcity->rally_point.vigilant = FALSE;
3633 free(pcity->rally_point.orders);
3634 pcity->rally_point.orders = NULL;
3635 }
3636}
3637
3638/**********************************************************************/
3642 struct city *pcity)
3643{
3644 struct unit_order *checked_orders;
3645 const struct civ_map *nmap = &(wld.map);
3646
3647 if (NULL == pcity) {
3648 /* Probably lost. */
3649 log_verbose("handle_city_rally_point() bad city number %d.",
3650 packet->id);
3651 return;
3652 }
3653
3654 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3655 /* Shouldn't happen */
3656 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3657 packet->length, MAX_LEN_ROUTE);
3658 return;
3659 }
3660
3661 pcity->rally_point.length = packet->length;
3662
3663 if (packet->length == 0) {
3664 pcity->rally_point.vigilant = FALSE;
3665 pcity->rally_point.persistent = FALSE;
3666 if (pcity->rally_point.orders) {
3667 free(pcity->rally_point.orders);
3668 pcity->rally_point.orders = NULL;
3669 }
3670 } else {
3672 packet->orders);
3673 if (!checked_orders) {
3674 pcity->rally_point.length = 0;
3675 log_error("invalid rally point orders for %s.",
3676 city_name_get(pcity));
3677 return;
3678 }
3679
3680 pcity->rally_point.persistent = packet->persistent;
3681 pcity->rally_point.vigilant = packet->vigilant;
3683 }
3684}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2315
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:481
#define action_enabler_list_iterate_end
Definition actions.h:441
#define action_by_result_iterate_end
Definition actions.h:485
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:439
#define action_id(_act_)
Definition actions.h:661
int ai_type_number(const struct ai_type *ai)
Definition ai.c:278
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
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:1637
bool city_is_virtual(const struct city *pcity)
Definition city.c:3589
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:1965
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2544
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:663
static void citizen_content_buildings(struct city *pcity)
Definition city.c:2591
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3601
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1860
static bv_imprs caravan_helped_impr
Definition city.c:1771
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:737
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1145
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2160
int city_granary_size(int city_size)
Definition city.c:2132
static void get_worked_tile_output(const struct civ_map *nmap, const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2324
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2196
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2787
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3617
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2712
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2092
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2279
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1087
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3228
static void city_support(const struct civ_map *nmap, struct city *pcity)
Definition city.c:3100
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2932
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:1240
const char * city_style_name_translation(const int style)
Definition city.c:1756
void city_styles_free(void)
Definition city.c:3411
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2438
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:647
bool is_capital(const struct city *pcity)
Definition city.c:1579
void city_styles_alloc(int num)
Definition city.c:3396
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1401
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1049
void city_production_caravan_shields_init(void)
Definition city.c:1778
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3371
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1255
int city_airlift_max(const struct city *pcity)
Definition city.c:2942
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1465
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1031
struct output_type * get_output_type(Output_type_id output)
Definition city.c:638
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3388
int city_population(const struct city *pcity)
Definition city.c:1191
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1765
void city_size_add(struct city *pcity, int add)
Definition city.c:1164
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1065
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:727
bool city_is_occupied(const struct city *pcity)
Definition city.c:1665
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:804
void add_tax_income(const struct player *pplayer, int trade, int *output)
Definition city.c:2245
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
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:2066
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3049
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1596
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2186
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:2409
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2227
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2081
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:1653
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:820
bool city_unhappy(const struct city *pcity)
Definition city.c:1626
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3334
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3430
void set_city_production(struct city *pcity)
Definition city.c:2953
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1679
static bv_unit_types caravan_helped_utype
Definition city.c:1772
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2212
bool city_celebrating(const struct city *pcity)
Definition city.c:1645
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1560
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:830
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:2870
const char * get_output_name(Output_type_id output)
Definition city.c:629
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2012
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1886
static int get_city_health(const struct city *pcity)
Definition city.c:2853
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:3176
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:994
static void set_city_bonuses(struct city *pcity)
Definition city.c:2386
static void set_surpluses(struct city *pcity)
Definition city.c:2452
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2287
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:1487
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2821
bool city_happy(const struct city *pcity)
Definition city.c:1614
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1180
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3357
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1384
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:2036
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2021
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:3516
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:3317
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:3641
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:1721
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2364
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:3609
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1695
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2615
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1283
static int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
Definition city.c:64
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:123
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:903
bool is_gov_center(const struct city *pcity)
Definition city.c:1587
#define log_ca_s_init
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1013
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2581
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:947
int city_map_tiles(int city_radius_sq)
Definition city.c:171
static void unhappy_city_check(struct city *pcity)
Definition city.c:2760
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2051
bool city_exist(int id)
Definition city.c:3572
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:717
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:747
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1996
void city_rally_point_clear(struct city *pcity)
Definition city.c:3626
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:871
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:2112
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2923
static int get_trade_illness(const struct city *pcity)
Definition city.c:2833
bool city_can_change_build(const struct city *pcity)
Definition city.c:1079
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:970
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1222
int city_style_by_rule_name(const char *s)
Definition city.c:1738
static void citizen_base_mood(struct city *pcity)
Definition city.c:2505
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1711
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1201
static void citizen_happy_units(struct city *pcity)
Definition city.c:2664
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2493
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:700
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_tile(_pcity_)
Definition city.h:564
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:256
@ UNHAPPY_PENALTY_NONE
Definition city.h:254
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:255
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, _index)
Definition city.h:201
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define CITY_MAP_MAX_SIZE
Definition city.h:94
#define city_tile_iterate_index_end
Definition city.h:209
@ CITIZEN_LAST
Definition city.h:272
@ CITIZEN_ANGRY
Definition city.h:271
@ CITIZEN_HAPPY
Definition city.h:268
@ CITIZEN_CONTENT
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:270
#define CITY_MAP_CENTER_RADIUS_SQ
Definition city.h:89
#define CITY_MAP_MIN_RADIUS_SQ
Definition city.h:84
#define output_type_iterate(output)
Definition city.h:845
#define CITY_REL2ABS(_coor)
Definition city.h:115
#define city_owner(_pcity_)
Definition city.h:563
#define MAX_CITY_SIZE
Definition city.h:106
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:868
#define city_list_iterate_end
Definition city.h:510
#define I_DESTROYED
Definition city.h:248
#define I_NEVER
Definition city.h:247
#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile)
Definition city.h:230
citizen_feeling
Definition city.h:278
@ FEELING_EFFECT
Definition city.h:281
@ FEELING_LUXURY
Definition city.h:280
@ FEELING_FINAL
Definition city.h:284
@ FEELING_BASE
Definition city.h:279
@ FEELING_NATIONALITY
Definition city.h:282
@ FEELING_MARTIAL
Definition city.h:283
@ OLOSS_SIZE
Definition city.h:291
@ OLOSS_WASTE
Definition city.h:290
#define city_map_iterate_end
Definition city.h:177
production_class_type
Definition city.h:38
@ PCT_LAST
Definition city.h:42
@ PCT_UNIT
Definition city.h:39
@ PCT_NORMAL_IMPROVEMENT
Definition city.h:40
@ PCT_WONDER
Definition city.h:41
#define city_map_iterate(_radius_sq, _index, _x, _y)
Definition city.h:173
#define city_tile_iterate_end
Definition city.h:238
#define city_built_iterate(_pcity, _p)
Definition city.h:834
#define is_free_worked_index(city_tile_index)
Definition city.h:880
#define city_map_tiles_from_city(_pcity)
Definition city.h:127
#define CITY_ABS2REL(_coor)
Definition city.h:116
#define city_built_iterate_end
Definition city.h:840
#define output_type_iterate_end
Definition city.h:851
void cm_init_citymap(void)
Definition cm.c:314
char * incite_cost
Definition comments.c:75
#define MAX_LEN_ROUTE
Definition conn_types.h:38
struct counter * counter_by_index(int index, enum counter_target target)
Definition counters.c:183
int counters_get_city_counters_count(void)
Definition counters.c:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
void distribute(int number, unsigned groups, const unsigned *ratios, int *result)
Definition distribute.c:34
struct @21::@22 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:940
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:984
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:916
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:1035
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
static bool is_server(void)
unsigned char citizens
Definition fc_types.h:388
@ RPT_CERTAIN
Definition fc_types.h:701
@ RPT_POSSIBLE
Definition fc_types.h:700
int Specialist_type_id
Definition fc_types.h:375
@ CTGT_CITY
Definition fc_types.h:126
#define CITY_MAP_MAX_RADIUS
Definition fc_types.h:83
output_type_id
Definition fc_types.h:100
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
#define MAX_LEN_CITYNAME
Definition fc_types.h:67
enum output_type_id Output_type_id
Definition fc_types.h:378
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
#define Qn_(String)
Definition fcintl.h:89
#define N_(String)
Definition fcintl.h:69
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:107
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
bool is_building_sellable(const struct impr_type *pimprove)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_warn(message,...)
Definition log.h:105
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_do_output_for_level(level)
Definition log.h:89
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_base(level, message,...)
Definition log.h:94
log_level
Definition log.h:28
@ LOG_DEBUG
Definition log.h:34
#define log_error(message,...)
Definition log.h:103
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Definition map.c:419
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:614
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:940
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:630
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1073
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:391
#define NATIVE_WIDTH
Definition map.h:222
#define square_iterate_end
Definition map.h:394
#define NATIVE_HEIGHT
Definition map.h:223
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:233
#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:319
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:465
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:119
int len
Definition packhand.c:127
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1388
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1459
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1493
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool are_reqs_active(const struct req_context *context, const struct player *other_player, 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)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct player *other_player, const struct requirement *req, enum req_problem_type prob_type)
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:1473
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:100
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Definition specialist.c:217
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
#define DEFAULT_SPECIALIST
Definition specialist.h:43
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
int turn
Definition city.h:246
Definition city.h:320
struct worker_task_list * task_reqs
Definition city.h:412
struct tile_cache * tile_cache
Definition city.h:349
int turn_last_built
Definition city.h:387
int surplus[O_LAST]
Definition city.h:355
enum city_wl_cancel_behavior wlcb
Definition city.h:404
int food_stock
Definition city.h:367
struct built_status built[B_LAST]
Definition city.h:394
struct player * original
Definition city.h:324
int * counter_values
Definition city.h:408
int pollution
Definition city.h:369
int id
Definition city.h:326
int last_turns_shield_surplus
Definition city.h:392
enum capital_type capital
Definition city.h:328
int disbanded_shields
Definition city.h:391
int waste[O_LAST]
Definition city.h:356
int turn_plague
Definition city.h:374
struct unit_list * info_units_present
Definition city.h:474
bv_city_options city_options
Definition city.h:403
citizens unit_happy_upkeep
Definition city.h:339
int city_radius_sq
Definition city.h:375
bool was_happy
Definition city.h:381
struct player * owner
Definition city.h:323
enum city_acquire_type acquire_t
Definition city.h:329
int turn_founded
Definition city.h:386
int citizen_base[O_LAST]
Definition city.h:359
int caravan_shields
Definition city.h:390
bool did_buy
Definition city.h:379
struct unit_list * info_units_supported
Definition city.h:473
char * name
Definition city.h:321
void * ais[FREECIV_AI_MOD_LAST]
Definition city.h:453
struct trade_route_list * routes
Definition city.h:344
bool occupied
Definition city.h:460
int usage[O_LAST]
Definition city.h:360
struct worklist worklist
Definition city.h:401
int tile_cache_radius_sq
Definition city.h:352
int abs_bonus[O_LAST]
Definition city.h:364
struct universal production
Definition city.h:396
struct unit_order * orders
Definition city.h:422
struct city::@16 rally_point
struct unit_list * collecting_info_units_supported
Definition city.h:477
int bonus[O_LAST]
Definition city.h:363
bool vigilant
Definition city.h:421
int unhappy_penalty[O_LAST]
Definition city.h:357
citizens size
Definition city.h:332
int before_change_shields
Definition city.h:389
int style
Definition city.h:327
size_t length
Definition city.h:417
struct unit_list * collecting_info_units_present
Definition city.h:478
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:333
citizens specialists[SP_MAX]
Definition city.h:336
struct tile * tile
Definition city.h:322
int shield_stock
Definition city.h:368
int prod[O_LAST]
Definition city.h:358
struct city::@17::@19 server
struct cm_parameter * cm_parameter
Definition city.h:425
struct universal changed_from
Definition city.h:399
struct unit_list * units_supported
Definition city.h:406
int mgr_score_calc_turn
Definition city.h:432
int illness_trade
Definition city.h:370
bool persistent
Definition city.h:419
struct city::@17::@20 client
int rapture
Definition city.h:385
citizens martial_law
Definition city.h:338
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
enum impr_genus_id genus
Definition improvement.h:63
struct requirement_vector reqs
Definition improvement.h:58
int dist
Definition city.h:110
int dx
Definition city.h:110
int dy
Definition city.h:110
const char * id
Definition city.h:262
struct unit_order orders[MAX_LEN_ROUTE]
enum gold_upkeep_style gold_upkeep_style
int granary_food_ini[MAX_GRANARY_INIS]
int min_city_center_output[O_LAST]
struct city_list * cities
Definition player.h:279
struct unit_list * units
Definition player.h:280
struct player_economic economic
Definition player.h:282
const struct player * player
struct requirement_vector reqs
Definition specialist.h:38
int irrigation_food_incr
Definition terrain.h:221
int output[O_LAST]
Definition terrain.h:202
int mining_shield_incr
Definition terrain.h:224
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:552
int upkeep[O_LAST]
Definition unittype.h:538
Definition unit.h:138
int upkeep[O_LAST]
Definition unit.h:148
int homecity
Definition unit.h:146
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
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:974
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#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:57
#define terrain_has_flag(terr, flag)
Definition terrain.h:283
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:291
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:271
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:88
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:103
#define tile_worked(_tile)
Definition tile.h:114
#define tile_resource(_tile)
Definition tile.h:102
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:110
#define tile_owner(_tile)
Definition tile.h:96
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:721
const struct impr_type * building
Definition fc_types.h:714
struct unit_order * create_unit_orders(const struct civ_map *nmap, int length, const struct unit_order *orders)
Definition unit.c:2834
bool unit_being_aggressive(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:1518
bool is_field_unit(const struct unit *punit)
Definition unit.c:414
bool is_martial_law_unit(const struct unit *punit)
Definition unit.c:316
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1729
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1360
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
#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:2271
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool can_player_build_unit_direct(const struct player *p, const struct unit_type *punittype, bool consider_reg_impr_req)
Definition unittype.c:1968
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2625
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:955
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
int utype_pop_value(const struct unit_type *punittype, const struct city *pcity)
Definition unittype.c:1528
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Definition unittype.c:2099
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1438
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:1017
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer)
Definition unittype.c:181
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:766
#define utype_class(_t_)
Definition unittype.h:749
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
#define unit_type_iterate(_p)
Definition unittype.h:855
#define unit_type_iterate_end
Definition unittype.h:862
#define U_NOT_OBSOLETED
Definition unittype.h:528
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