Freeciv-3.3
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/**********************************************************************/
903bool can_city_build_unit_direct(const struct city *pcity,
904 const struct unit_type *punittype)
905{
906 const struct civ_map *nmap = &(wld.map);
907
909 return FALSE;
910 }
911
912 /* Check unit build requirements.
913 * Above player level check already checked anything with range >= REQ_RANGE_PLAYER.
914 * Don't recheck those. Not only for optimization, but also not to override the
915 * special handling of tech requirements for barbarians */
916 if (!are_reqs_active_ranges(0, /* The lowest range; REQ_RANGE_LOCAL */
918 &(const struct req_context) {
919 .player = city_owner(pcity),
920 .city = pcity,
921 .tile = city_tile(pcity),
922 .unittype = punittype,
923 },
924 NULL,
925 &punittype->build_reqs, RPT_CERTAIN)) {
926 return FALSE;
927 }
928
929 /* You can't build naval units inland. */
932 pcity->tile)) {
933 return FALSE;
934 }
935
936 if (punittype->city_slots > 0
937 && city_unit_slots_available(pcity) < punittype->city_slots) {
938 return FALSE;
939 }
940
941 return TRUE;
942}
943
944/**********************************************************************/
948bool can_city_build_unit_now(const struct city *pcity,
949 const struct unit_type *punittype)
950{
952 return FALSE;
953 }
954 while ((punittype = punittype->obsoleted_by) != U_NOT_OBSOLETED) {
955 /* TODO: Decide if fulfilled impr_req is needed to make unit obsolete,
956 * i.e., should the 'consider_reg_impr_req' be TRUE or FALSE. */
958 return FALSE;
959 }
960 }
961 return TRUE;
962}
963
964/**********************************************************************/
968bool can_city_build_unit_later(const struct city *pcity,
969 const struct unit_type *punittype)
970{
971 const struct civ_map *nmap = &(wld.map);
972
973 /* Can the _player_ ever build this unit? */
975 return FALSE;
976 }
977
978 /* Some units can be built only in certain cities -- for instance,
979 ships may be built only in cities adjacent to ocean. */
982 pcity->tile)) {
983 return FALSE;
984 }
985
986 return TRUE;
987}
988
989/**********************************************************************/
993bool can_city_build_direct(const struct city *pcity,
994 const struct universal *target)
995{
996 switch (target->kind) {
997 case VUT_UTYPE:
998 return can_city_build_unit_direct(pcity, target->value.utype);
999 case VUT_IMPROVEMENT:
1000 return can_city_build_improvement_direct(pcity, target->value.building);
1001 default:
1002 break;
1003 };
1004 return FALSE;
1005}
1006
1007/**********************************************************************/
1011bool can_city_build_now(const struct city *pcity,
1012 const struct universal *target)
1013{
1014 switch (target->kind) {
1015 case VUT_UTYPE:
1016 return can_city_build_unit_now(pcity, target->value.utype);
1017 case VUT_IMPROVEMENT:
1018 return can_city_build_improvement_now(pcity, target->value.building);
1019 default:
1020 break;
1021 };
1022 return FALSE;
1023}
1024
1025/**********************************************************************/
1028bool can_city_build_later(const struct city *pcity,
1029 const struct universal *target)
1030{
1031 switch (target->kind) {
1032 case VUT_UTYPE:
1033 return can_city_build_unit_later(pcity, target->value.utype);
1034 case VUT_IMPROVEMENT:
1035 return can_city_build_improvement_later(pcity, target->value.building);
1036 default:
1037 break;
1038 };
1039 return FALSE;
1040}
1041
1042/**********************************************************************/
1045int city_unit_slots_available(const struct city *pcity)
1046{
1047 int max = get_city_bonus(pcity, EFT_UNIT_SLOTS);
1048 int current;
1049
1050 current = 0;
1052 current += unit_type_get(punit)->city_slots;
1054
1055 return max - current;
1056}
1057
1058/**********************************************************************/
1061bool city_can_use_specialist(const struct city *pcity,
1063{
1064 return are_reqs_active(&(const struct req_context) {
1065 .player = city_owner(pcity),
1066 .city = pcity,
1067 },
1068 NULL,
1070}
1071
1072/**********************************************************************/
1075bool city_can_change_build(const struct city *pcity)
1076{
1077 return !pcity->did_buy || pcity->shield_stock <= 0;
1078}
1079
1080/**********************************************************************/
1084{
1085 if (NULL == city_tile(pcity)) {
1086 /* When a "dummy" city is created with no tile, then choosing a build
1087 * target could fail. This currently might happen during map editing.
1088 * FIXME: assumes the first unit is always "valid", so check for
1089 * obsolete units elsewhere. */
1090 pcity->production.kind = VUT_UTYPE;
1092 } else {
1093 struct unit_type *u = best_role_unit(pcity, L_FIRSTBUILD);
1094
1095 if (u) {
1096 pcity->production.kind = VUT_UTYPE;
1097 pcity->production.value.utype = u;
1098 } else {
1099 bool found = FALSE;
1100
1101 /* Just pick the first available item. */
1102 improvement_iterate(pimprove) {
1103 if (can_city_build_improvement_direct(pcity, pimprove)) {
1104 found = TRUE;
1106 pcity->production.value.building = pimprove;
1107 break;
1108 }
1110
1111 if (!found) {
1114#ifndef FREECIV_NDEBUG
1115 /* Later than this, 'found' is only needed in an fc_assert() */
1116 found = TRUE;
1117#endif /* FREECIV_NDEBUG */
1118 pcity->production.kind = VUT_UTYPE;
1120 }
1122 }
1123
1124 fc_assert_msg(found, "No production found for city %s!",
1125 city_name_get(pcity));
1126 }
1127 }
1128}
1129
1130/**********************************************************************/
1133const char *city_name_get(const struct city *pcity)
1134{
1135 return (pcity->name != NULL) ? pcity->name : "City missing a name";
1136}
1137
1138/**********************************************************************/
1141void city_name_set(struct city *pcity, const char *new_name)
1142{
1143 if (pcity->name != NULL) {
1144 free(pcity->name);
1145 }
1146
1147 if (strlen(new_name) < MAX_LEN_CITYNAME) {
1148 pcity->name = fc_strdup(new_name);
1149 } else {
1150 log_warn(_("City name \"%s\" too long"), new_name);
1152 sz_strlcpy(pcity->name, new_name);
1153 }
1154}
1155
1156/**********************************************************************/
1160void city_size_add(struct city *pcity, int add)
1161{
1162 citizens size = city_size_get(pcity);
1163
1164 fc_assert_ret(pcity != NULL);
1166
1167 /* Client sets size to zero to start stacking citizens in */
1168 fc_assert_ret(size > -add || (!is_server() && size == add));
1169
1170 city_size_set(pcity, size + add);
1171}
1172
1173/**********************************************************************/
1176void city_size_set(struct city *pcity, citizens size)
1177{
1178 fc_assert_ret(pcity != NULL);
1179
1180 /* Set city size. */
1181 pcity->size = size;
1182}
1183
1184/**********************************************************************/
1187int city_population(const struct city *pcity)
1188{
1189 /* Sum_{i=1}^{n} i == n*(n+1)/2 */
1190 return city_size_get(pcity) * (city_size_get(pcity) + 1) * 5;
1191}
1192
1193/**********************************************************************/
1197int city_total_impr_gold_upkeep(const struct city *pcity)
1198{
1199 int gold_needed = 0;
1200
1201 if (pcity == NULL) {
1202 return 0;
1203 }
1204
1205 city_built_iterate(pcity, pimprove) {
1206 gold_needed += city_improvement_upkeep(pcity, pimprove);
1208
1209 gold_needed -= get_city_bonus(pcity, EFT_IMPR_UPKEEP_REDUCTION);
1210
1211 return MAX(gold_needed, 0);
1212}
1213
1214/**********************************************************************/
1218int city_total_unit_gold_upkeep(const struct city *pcity)
1219{
1220 int gold_needed = 0;
1221
1222 if (pcity == NULL || pcity->units_supported == NULL) {
1223 return 0;
1224 }
1225
1227 gold_needed += punit->upkeep[O_GOLD];
1229
1230 return gold_needed;
1231}
1232
1233/**********************************************************************/
1236bool city_has_building(const struct city *pcity,
1237 const struct impr_type *pimprove)
1238{
1239 if (NULL == pimprove) {
1240 /* Callers should ensure that any external data is tested with
1241 * valid_improvement_by_number() */
1242 return FALSE;
1243 }
1244 return (pcity->built[improvement_index(pimprove)].turn > I_NEVER);
1245}
1246
1247/**********************************************************************/
1251int city_improvement_upkeep(const struct city *pcity,
1252 const struct impr_type *b)
1253{
1254 int upkeep;
1255
1256 if (NULL == b) {
1257 return 0;
1258 }
1259 if (!is_building_sellable(b)) {
1260 return 0;
1261 }
1262
1263 upkeep = b->upkeep;
1264 if (upkeep <= get_building_bonus(pcity, b, EFT_UPKEEP_FREE)) {
1265 return 0;
1266 }
1267
1268 return upkeep;
1269}
1270
1271/**********************************************************************/
1279int city_tile_output(const struct city *pcity, const struct tile *ptile,
1281{
1282 int prod;
1283 const struct req_context city_ctxt = {
1284 .player = pcity ? city_owner(pcity) : NULL,
1285 .city = pcity,
1286 .tile = ptile,
1287 };
1288 struct terrain *pterrain = tile_terrain(ptile);
1289 const struct output_type *output = &output_types[otype];
1290
1291 fc_assert_ret_val(otype >= 0 && otype < O_LAST, 0);
1292
1293 if (T_UNKNOWN == pterrain) {
1294 /* Special case for the client. The server doesn't allow unknown tiles
1295 * to be worked but we don't necessarily know what player is involved. */
1296 return 0;
1297 }
1298
1299 prod = pterrain->output[otype];
1300 if (tile_resource_is_valid(ptile)) {
1301 prod += tile_resource(ptile)->data.resource->output[otype];
1302 }
1303
1304 switch (otype) {
1305 case O_SHIELD:
1306 if (pterrain->mining_shield_incr != 0) {
1307 prod += pterrain->mining_shield_incr
1309 / 100;
1310 }
1311 break;
1312 case O_FOOD:
1313 if (pterrain->irrigation_food_incr != 0) {
1314 prod += pterrain->irrigation_food_incr
1316 EFT_IRRIGATION_PCT) / 100;
1317 }
1318 break;
1319 case O_TRADE:
1320 case O_GOLD:
1321 case O_SCIENCE:
1322 case O_LUXURY:
1323 case O_LAST:
1324 break;
1325 }
1326
1327 prod += tile_roads_output_incr(ptile, otype);
1328 prod += (prod * tile_roads_output_bonus(ptile, otype) / 100);
1329
1330 prod += get_tile_output_bonus(pcity, ptile, output, EFT_OUTPUT_ADD_TILE);
1331 if (prod > 0) {
1332 int penalty_limit = get_tile_output_bonus(pcity, ptile, output,
1334
1335 if (prod >= game.info.granularity) {
1336 prod += get_tile_output_bonus(pcity, ptile, output,
1338
1339 if (is_celebrating) {
1340 prod += get_tile_output_bonus(pcity, ptile, output,
1342 }
1343 }
1344
1345 prod += (prod
1346 * get_tile_output_bonus(pcity, ptile, output,
1348 / 100;
1349 if (penalty_limit > 0 && prod > penalty_limit) {
1350 if (prod <= game.info.granularity) {
1351 prod = 0;
1352 } else {
1353 prod -= game.info.granularity;
1354 }
1355 }
1356 }
1357
1358 prod -= (prod
1359 * get_tile_output_bonus(pcity, ptile, output,
1361 / 100;
1362
1363 if (NULL != pcity && is_city_center(pcity, ptile)) {
1364 prod = MAX(prod, game.info.min_city_center_output[otype]);
1365 }
1366
1367 return prod;
1368}
1369
1370/**********************************************************************/
1380int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
1382{
1383 return city_tile_output(pcity, ptile, city_celebrating(pcity), otype);
1384}
1385
1386/**********************************************************************/
1398 const struct city *pcity,
1399 const struct tile *ptile)
1400{
1401 struct player *powner = city_owner(pcity);
1403 struct player *towner;
1404
1405 if (NULL == ptile) {
1406 return FALSE;
1407 }
1408
1409 if (!city_base_to_city_map(&city_map_x, &city_map_y, pcity, ptile)) {
1410 return FALSE;
1411 }
1412
1413 if (NULL != restriction
1414 && TILE_UNKNOWN == tile_get_known(ptile, restriction)) {
1415 return FALSE;
1416 }
1417
1418 towner = tile_owner(ptile);
1419 if (NULL != towner && towner != powner
1420 && !gives_shared_tiles(towner, powner)) {
1421 return FALSE;
1422 }
1423 /* TODO: civ3-like option for borders */
1424
1425 if (NULL != tile_worked(ptile) && tile_worked(ptile) != pcity) {
1426 return FALSE;
1427 }
1428
1429 if (powner == restriction
1430 && TILE_KNOWN_SEEN != tile_get_known(ptile, powner)) {
1431 return FALSE;
1432 }
1433
1434 if (!is_free_worked(pcity, ptile)
1435 && NULL != unit_occupies_tile(ptile, powner)) {
1436 return FALSE;
1437 }
1438
1439 if (get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) {
1440 return FALSE;
1441 }
1442
1443 return TRUE;
1444}
1445
1446/**********************************************************************/
1452bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
1453{
1454 return base_city_can_work_tile(city_owner(pcity), pcity, ptile);
1455}
1456
1457/**********************************************************************/
1462 const struct tile *ptile)
1463{
1464 /* citymindist minimum is 1, meaning adjacent is okay */
1465 int citymindist = game.info.citymindist;
1466
1467 square_iterate(nmap, ptile, citymindist - 1, ptile1) {
1468 if (tile_city(ptile1)) {
1469 return TRUE;
1470 }
1472
1473 return FALSE;
1474}
1475
1476/**********************************************************************/
1484 const struct tile *ptile,
1485 const struct unit *punit,
1486 bool hut_test)
1487{
1488 if (!city_can_be_built_tile_only(nmap, ptile)) {
1489 return FALSE;
1490 }
1491
1492 if (punit == NULL) {
1493 /* The remaining checks tests if punit can found a city here */
1494 return TRUE;
1495 }
1496
1497 if (hut_test) {
1498 struct player *towner;
1499
1500 /* Huts can be found only from native tiles, owned by the unit owner.
1501 * Unlike actual city building, this behavior is not affected
1502 * by the ruleset. */
1503 if (!can_unit_exist_at_tile(nmap, punit, ptile)) {
1504 return FALSE;
1505 }
1506
1507 towner = tile_owner(ptile);
1508
1509 if (towner == NULL || towner == unit_owner(punit)) {
1510 return TRUE;
1511 }
1512
1513 return FALSE;
1514 }
1515
1518 /* This action can't be done by this unit type at all. */
1519 continue;
1520 }
1521
1522 /* Non native tile detection */
1523 if (!can_unit_exist_at_tile(nmap, punit, ptile)
1524 /* The ruleset may allow founding cities on non native terrain. */
1527 /* Many rulesets allow land units to build land cities and sea units
1528 * to build ocean cities. Air units can build cities anywhere. */
1529 continue;
1530 }
1531
1532 /* Foreign tile detection. */
1533 if (tile_owner(ptile) && tile_owner(ptile) != unit_owner(punit)
1534 /* The ruleset may allow founding cities on foreign terrain. */
1536 paction->id,
1537 DRO_FOREIGN, TRUE)) {
1538 /* Cannot steal borders by settling. This has to be settled by
1539 * force of arms. */
1540 continue;
1541 }
1542
1543 return TRUE;
1545
1546 return FALSE;
1547}
1548
1549/**********************************************************************/
1557 const struct tile *ptile)
1558{
1560 /* No cities on this terrain. */
1561 return FALSE;
1562 }
1563
1565 return FALSE;
1566 }
1567
1568 return TRUE;
1569}
1570
1571/**********************************************************************/
1575bool is_capital(const struct city *pcity)
1576{
1577 return pcity->capital != CAPITAL_NOT;
1578}
1579
1580/**********************************************************************/
1583bool is_gov_center(const struct city *pcity)
1584{
1585 return (get_city_bonus(pcity, EFT_GOV_CENTER) > 0);
1586}
1587
1588/**********************************************************************/
1592bool city_got_defense_effect(const struct city *pcity,
1593 const struct unit_type *attacker)
1594{
1595 if (!attacker) {
1596 /* Any defense building will do */
1597 return get_city_bonus(pcity, EFT_DEFEND_BONUS) > 0;
1598 }
1599
1600 return get_unittype_bonus(city_owner(pcity), pcity->tile, attacker,
1601 NULL, EFT_DEFEND_BONUS) > 0;
1602}
1603
1604/**********************************************************************/
1610bool city_happy(const struct city *pcity)
1611{
1612 return (city_size_get(pcity) >= game.info.celebratesize
1613 && pcity->feel[CITIZEN_ANGRY][FEELING_FINAL] == 0
1614 && pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL] == 0
1615 && pcity->feel[CITIZEN_HAPPY][FEELING_FINAL] >= (city_size_get(pcity) + 1) / 2);
1616}
1617
1618/**********************************************************************/
1622bool city_unhappy(const struct city *pcity)
1623{
1624 return (pcity->feel[CITIZEN_HAPPY][FEELING_FINAL]
1626 + 2 * pcity->feel[CITIZEN_ANGRY][FEELING_FINAL]);
1627}
1628
1629/**********************************************************************/
1633bool base_city_celebrating(const struct city *pcity)
1634{
1635 return (city_size_get(pcity) >= game.info.celebratesize && pcity->was_happy);
1636}
1637
1638/**********************************************************************/
1641bool city_celebrating(const struct city *pcity)
1642{
1643 return base_city_celebrating(pcity) && city_happy(pcity);
1644}
1645
1646/**********************************************************************/
1649bool city_rapture_grow(const struct city *pcity)
1650{
1651 /* .rapture is checked instead of city_celebrating() because this
1652 function is called after .was_happy was updated. */
1653 return (pcity->rapture > 0 && pcity->surplus[O_FOOD] > 0
1654 && (pcity->rapture % game.info.rapturedelay) == 0
1655 && get_city_bonus(pcity, EFT_RAPTURE_GROW) > 0);
1656}
1657
1658/**********************************************************************/
1661bool city_is_occupied(const struct city *pcity)
1662{
1663 if (is_server()) {
1664 /* The server sees the units inside the city. */
1665 return (unit_list_size(city_tile(pcity)->units) > 0);
1666 } else {
1667 /* The client gets the occupied property from the server. */
1668 return pcity->client.occupied;
1669 }
1670}
1671
1672/**********************************************************************/
1675struct city *city_list_find_number(struct city_list *This, int id)
1676{
1677 if (id != 0) {
1678 city_list_iterate(This, pcity) {
1679 if (pcity->id == id) {
1680 return pcity;
1681 }
1683 }
1684
1685 return NULL;
1686}
1687
1688/**********************************************************************/
1691struct city *city_list_find_name(struct city_list *This, const char *name)
1692{
1693 city_list_iterate(This, pcity) {
1694 if (fc_strcasecmp(name, pcity->name) == 0) {
1695 return pcity;
1696 }
1698
1699 return NULL;
1700}
1701
1702/**********************************************************************/
1707int city_name_compare(const void *p1, const void *p2)
1708{
1709 return fc_strcasecmp((*(const struct city **) p1)->name,
1710 (*(const struct city **) p2)->name);
1711}
1712
1713/**********************************************************************/
1718{
1719 int i;
1720
1721 for (i = 0; i < game.control.num_city_styles; i++) {
1722 if (0 == strcmp(city_style_name_translation(i), s)) {
1723 return i;
1724 }
1725 }
1726
1727 return -1;
1728}
1729
1730/**********************************************************************/
1734int city_style_by_rule_name(const char *s)
1735{
1736 const char *qs = Qn_(s);
1737 int i;
1738
1739 for (i = 0; i < game.control.num_city_styles; i++) {
1740 if (0 == fc_strcasecmp(city_style_rule_name(i), qs)) {
1741 return i;
1742 }
1743 }
1744
1745 return -1;
1746}
1747
1748/**********************************************************************/
1753{
1755}
1756
1757/**********************************************************************/
1761const char *city_style_rule_name(const int style)
1762{
1764}
1765
1766/* Cache of what city production caravan shields are allowed to help. */
1769
1770/**********************************************************************/
1775{
1776 struct requirement prod_as_req;
1777
1778#define log_ca_s_init log_debug
1779
1780 /* Remove old data. */
1783
1784 /* Common for all production kinds. */
1786 prod_as_req.survives = FALSE;
1787 prod_as_req.present = TRUE;
1788
1789 /* Check improvements */
1790 prod_as_req.source.kind = VUT_IMPROVEMENT;
1791
1793 /* Check this improvement. */
1794 prod_as_req.source.value.building = itype;
1795
1798 enabler) {
1800 &(enabler->target_reqs))
1801 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTYPE)
1802 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCLASS)
1803 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UTFLAG)
1804 && !req_vec_wants_type(&(enabler->target_reqs), VUT_UCFLAG)) {
1805 /* This improvement kind can receive caravan shields. */
1806
1808
1809 /* Move on to the next improvement */
1810 break;
1811 }
1813
1814 log_ca_s_init("Help Wonder: %s for %s",
1816 ? "possible" : "impossible"),
1819
1820 /* Check units. */
1821 prod_as_req.source.kind = VUT_UTYPE;
1822
1824 /* Check this utype. */
1825 prod_as_req.source.value.utype = putype;
1826
1829 enabler) {
1831 &(enabler->target_reqs))
1832 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPROVEMENT)
1833 && !req_vec_wants_type(&(enabler->target_reqs), VUT_IMPR_GENUS)) {
1834 /* This unit type kind can receive caravan shields. */
1835
1837
1838 /* Move on to the next unit type */
1839 break;
1840 }
1842
1843 log_ca_s_init("Help Wonder: %s for %s",
1845 ? "possible" : "impossible"),
1848
1849#undef log_ca_s_init
1850}
1851
1852/**********************************************************************/
1857{
1858 switch (tgt->kind) {
1859 case VUT_IMPROVEMENT:
1862 case VUT_UTYPE:
1864 utype_index(tgt->value.utype));
1865 default:
1867 return FALSE;
1868 };
1869}
1870
1871/**********************************************************************/
1882int city_change_production_penalty(const struct city *pcity,
1883 const struct universal *target)
1884{
1889
1890 switch (pcity->changed_from.kind) {
1891 case VUT_IMPROVEMENT:
1892 if (is_wonder(pcity->changed_from.value.building)) {
1894 } else {
1896 }
1897 break;
1898 case VUT_UTYPE:
1900 break;
1901 default:
1903 break;
1904 };
1905
1906 switch (target->kind) {
1907 case VUT_IMPROVEMENT:
1908 if (is_wonder(target->value.building)) {
1910 } else {
1912 }
1913 break;
1914 case VUT_UTYPE:
1916 break;
1917 default:
1919 break;
1920 };
1921
1922 /* Changing production is penalized under certain circumstances. */
1923 if (orig_class == new_class
1924 || orig_class == PCT_LAST) {
1925 /* There's never a penalty for building something of the same class. */
1927 } else if (city_built_last_turn(pcity)) {
1928 /* Surplus shields from the previous production won't be penalized if
1929 * you change production on the very next turn. But you can only use
1930 * up to the city's surplus amount of shields in this way. */
1932 pcity->before_change_shields);
1934 } else {
1935 /* Penalize 50% of the production. */
1937 }
1938
1939 /* Do not put penalty on these. It shouldn't matter whether you disband unit
1940 before or after changing production...*/
1942
1943 /* Caravan shields are penalized (just as if you disbanded the caravan)
1944 * if you're not building a wonder. */
1947 } else {
1949 }
1950
1953
1955}
1956
1957/**********************************************************************/
1961int city_turns_to_build(const struct city *pcity,
1962 const struct universal *target,
1964{
1965 int city_shield_surplus = pcity->surplus[O_SHIELD];
1967 city_change_production_penalty(pcity, target) : 0;
1968 int cost = universal_build_shield_cost(pcity, target);
1969
1970 if (target->kind == VUT_IMPROVEMENT
1971 && is_great_wonder(target->value.building)
1973 return FC_INFINITY;
1974 }
1975
1977 return 1;
1978 } else if (city_shield_surplus > 0) {
1979 return (cost - city_shield_stock - 1) / city_shield_surplus + 1;
1980 } else {
1981 return FC_INFINITY;
1982 }
1983}
1984
1985/**********************************************************************/
1992int city_turns_to_grow(const struct city *pcity)
1993{
1994 if (pcity->surplus[O_FOOD] > 0) {
1995 return (city_granary_size(city_size_get(pcity)) - pcity->food_stock +
1996 pcity->surplus[O_FOOD] - 1) / pcity->surplus[O_FOOD];
1997 } else if (pcity->surplus[O_FOOD] < 0) {
1998 /* Turns before famine loss */
1999 return -1 + (pcity->food_stock / pcity->surplus[O_FOOD]);
2000 } else {
2001 return FC_INFINITY;
2002 }
2003}
2004
2005/**********************************************************************/
2008bool city_can_grow_to(const struct city *pcity, int pop_size)
2009{
2010 return (get_city_bonus(pcity, EFT_SIZE_UNLIMIT) > 0
2011 || pop_size <= get_city_bonus(pcity, EFT_SIZE_ADJ));
2012}
2013
2014/**********************************************************************/
2017struct city *tile_enemy_city(const struct tile *ptile,
2018 const struct player *pplayer)
2019{
2020 struct city *pcity = tile_city(ptile);
2021
2022 if (pcity != NULL && pplayers_at_war(pplayer, city_owner(pcity))) {
2023 return pcity;
2024 }
2025
2026 return NULL;
2027}
2028
2029/**********************************************************************/
2032struct city *tile_allied_city(const struct tile *ptile,
2033 const struct player *pplayer)
2034{
2035 struct city *pcity = tile_city(ptile);
2036
2037 if (pcity != NULL && pplayers_allied(pplayer, city_owner(pcity))) {
2038 return pcity;
2039 }
2040
2041 return NULL;
2042}
2043
2044/**********************************************************************/
2047struct city *tile_non_attack_city(const struct tile *ptile,
2048 const struct player *pplayer)
2049{
2050 struct city *pcity = tile_city(ptile);
2051
2052 if (pcity != NULL && pplayers_non_attack(pplayer, city_owner(pcity))) {
2053 return pcity;
2054 }
2055
2056 return NULL;
2057}
2058
2059/**********************************************************************/
2062struct city *tile_non_allied_city(const struct tile *ptile,
2063 const struct player *pplayer)
2064{
2065 struct city *pcity = tile_city(ptile);
2066
2067 if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) {
2068 return pcity;
2069 }
2070
2071 return NULL;
2072}
2073
2074/**********************************************************************/
2078 const struct unit *punit,
2079 int distance)
2080{
2082 distance);
2083}
2084
2085/**********************************************************************/
2089 const struct player *owner,
2090 const struct tile *ptile,
2091 int distance)
2092{
2093 square_iterate(nmap, ptile, distance, ptile1) {
2094 struct city *pcity = tile_city(ptile1);
2095
2096 if (pcity && pplayers_allied(owner, city_owner(pcity))) {
2097 return TRUE;
2098 }
2100
2101 return FALSE;
2102}
2103
2104/**********************************************************************/
2108bool city_exists_within_max_city_map(const struct tile *ptile,
2109 bool may_be_on_center)
2110{
2111 const struct civ_map *nmap = &(wld.map);
2112
2114 if (may_be_on_center || !same_pos(ptile, ptile1)) {
2115 if (tile_city(ptile1)) {
2116 return TRUE;
2117 }
2118 }
2120
2121 return FALSE;
2122}
2123
2124/**********************************************************************/
2129int city_granary_size(int city_size)
2130{
2133 int base_value;
2134
2135 /* If the city has no citizens, there is no granary. */
2136 if (city_size == 0) {
2137 return 0;
2138 }
2139
2140 /* Granary sizes for the first food_inis citizens are given directly.
2141 * After that we increase the granary size by food_inc per citizen. */
2142 if (city_size > food_inis) {
2143 base_value = game.info.granary_food_ini[food_inis - 1];
2144 base_value += food_inc * (city_size - food_inis);
2145 } else {
2146 base_value = game.info.granary_food_ini[city_size - 1];
2147 }
2148
2149 return MAX(base_value * game.info.foodbox / 100, 1);
2150}
2151
2152/**********************************************************************/
2157static int player_base_citizen_happiness(const struct player *pplayer)
2158{
2159 int cities = city_list_size(pplayer->cities);
2160 int content = get_player_bonus(pplayer, EFT_CITY_UNHAPPY_SIZE);
2163
2164 if (basis + step <= 0) {
2165 /* Value of zero means effect is inactive */
2166 return content;
2167 }
2168
2169 if (cities > basis) {
2170 content--;
2171 if (step != 0) {
2172 /* the first penalty is at (basis + 1) cities;
2173 the next is at (basis + step + 1), _not_ (basis + step) */
2174 content -= (cities - basis - 1) / step;
2175 }
2176 }
2177 return content;
2178}
2179
2180/**********************************************************************/
2184{
2185 int content = player_base_citizen_happiness(pplayer);
2186
2187 return CLIP(0, content, MAX_CITY_SIZE);
2188}
2189
2190/**********************************************************************/
2194{
2195 if (!game.info.angrycitizen) {
2196 return 0;
2197 } else {
2198 /* Create angry citizens only if we have a negative number of possible
2199 * content citizens. This can happen when empires grow really big. */
2200 int content = player_base_citizen_happiness(pplayer);
2201
2202 return CLIP(0, -content, MAX_CITY_SIZE);
2203 }
2204}
2205
2206/**********************************************************************/
2210{
2211 struct output_type *output = &output_types[otype];
2212 int bonus1 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
2214 int bonus2 = 100 + get_city_tile_output_bonus(pcity, NULL, output,
2216
2217 return MAX(bonus1 * bonus2 / 100, 0);
2218}
2219
2220/**********************************************************************/
2224int get_city_tithes_bonus(const struct city *pcity)
2225{
2226 int tithes_bonus = 0;
2227
2228 if (get_city_bonus(pcity, EFT_HAPPINESS_TO_GOLD) <= 0) {
2229 return 0;
2230 }
2231
2234
2235 return tithes_bonus;
2236}
2237
2238/**********************************************************************/
2242void add_tax_income(const struct player *pplayer, int trade, int *output)
2243{
2244 const int SCIENCE = 0, TAX = 1, LUXURY = 2;
2245 unsigned rates[3];
2246 int result[3];
2247
2248 if (game.info.changable_tax) {
2249 rates[SCIENCE] = pplayer->economic.science;
2250 rates[LUXURY] = pplayer->economic.luxury;
2251 rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];
2252 } else {
2256 }
2257
2258 /* ANARCHY */
2260 rates[SCIENCE] = 0;
2261 rates[LUXURY] = 100;
2262 rates[TAX] = 0;
2263 }
2264
2265 distribute(trade, 3, rates, result);
2266
2267 output[O_SCIENCE] += result[SCIENCE];
2268 output[O_GOLD] += result[TAX];
2269 output[O_LUXURY] += result[LUXURY];
2270}
2271
2272/**********************************************************************/
2276bool city_built_last_turn(const struct city *pcity)
2277{
2278 return pcity->turn_last_built + 1 >= game.info.turn;
2279}
2280
2281/**********************************************************************/
2284static const struct city *nearest_gov_center(const struct city *pcity,
2285 int *min_dist)
2286{
2287 const struct city *gov_center = NULL;
2288
2290
2291 /* Check the special case that city itself is gov center
2292 * before expensive iteration through all cities. */
2293 if (is_gov_center(pcity)) {
2294 *min_dist = 0;
2295 return pcity;
2296 } else {
2298 /* Do not recheck current city */
2299 if (gc != pcity && is_gov_center(gc)) {
2300 int dist = real_map_distance(gc->tile, pcity->tile);
2301
2302 if (dist < *min_dist) {
2303 gov_center = gc;
2304 *min_dist = dist;
2305 }
2306 }
2308 }
2309
2310 return gov_center;
2311}
2312
2313/**********************************************************************/
2321static inline void get_worked_tile_output(const struct city *pcity,
2322 int *output, bool *workers_map)
2323{
2324 bool is_worked;
2325#ifdef CITY_DEBUGGING
2327#endif
2328 struct tile *pcenter = city_tile(pcity);
2329 const struct civ_map *nmap = &(wld.map);
2330
2331 memset(output, 0, O_LAST * sizeof(*output));
2332
2335 if (workers_map == NULL) {
2336 struct city *pwork = tile_worked(ptile);
2337
2338 is_worked = (NULL != pwork && pwork == pcity);
2339 } else {
2340 is_worked = workers_map[city_tile_index];
2341 }
2342
2343 if (is_worked) {
2345#ifdef CITY_DEBUGGING
2346 /* This assertion never fails, but it's so slow that we disable
2347 * it by default. */
2349 == city_tile_output(pcity, ptile, is_celebrating, o));
2350#endif /* CITY_DEBUGGING */
2351 output[o] += city_tile_cache_get_output(pcity, city_tile_index, o);
2353 }
2355}
2356
2357/**********************************************************************/
2361void add_specialist_output(const struct city *pcity, int *output)
2362{
2364 int count = pcity->specialists[sp];
2365
2368
2369 output[stat_index] += count * amount;
2372}
2373
2374/**********************************************************************/
2383static inline void set_city_bonuses(struct city *pcity)
2384{
2386 pcity->bonus[o] = get_final_city_output_bonus(pcity, o);
2387 pcity->abs_bonus[o] = get_city_output_bonus(pcity,
2388 &output_types[o],
2390 /* Total bonus cannot be negative, as that could lead to unresolvable
2391 * negative balance. */
2392 pcity->abs_bonus[o] = MIN(pcity->abs_bonus[o], 0);
2394}
2395
2396/**********************************************************************/
2406static inline void city_tile_cache_update(const struct civ_map *nmap,
2407 struct city *pcity)
2408{
2410 int radius_sq = city_map_radius_sq_get(pcity);
2411
2412 /* Initialize tile_cache if needed */
2413 if (pcity->tile_cache == NULL || pcity->tile_cache_radius_sq == -1
2414 || pcity->tile_cache_radius_sq != radius_sq) {
2415 pcity->tile_cache = fc_realloc(pcity->tile_cache,
2416 city_map_tiles(radius_sq)
2417 * sizeof(*(pcity->tile_cache)));
2418 pcity->tile_cache_radius_sq = radius_sq;
2419 }
2420
2421 /* Any unreal tiles are skipped - these values should have been memset
2422 * to 0 when the city was created. */
2423 city_tile_iterate_index(nmap, radius_sq, pcity->tile, ptile, city_tile_index) {
2425 (pcity->tile_cache[city_tile_index]).output[o]
2426 = city_tile_output(pcity, ptile, is_celebrating, o);
2429}
2430
2431/**********************************************************************/
2435static inline int city_tile_cache_get_output(const struct city *pcity,
2436 int city_tile_index,
2437 enum output_type_id o)
2438{
2440 == city_map_radius_sq_get(pcity), 0);
2442
2443 return (pcity->tile_cache[city_tile_index]).output[o];
2444}
2445
2446/**********************************************************************/
2449static void set_surpluses(struct city *pcity)
2450{
2452 int surplus = pcity->prod[o] - pcity->usage[o];
2453
2454 /* Add 'surplus' waste to 'usage'. */
2455 if (surplus > 0) {
2456 struct output_type *output = get_output_type(o);
2460
2461 if (waste_by_rel_dist > 0) {
2462 int min_dist;
2463 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
2464
2465 if (gov_center == NULL) {
2466 /* No gov center - no income */
2467 waste_level = 100;
2468 } else {
2469 waste_level += waste_by_rel_dist * 50 * min_dist / 100
2471 }
2472 }
2473
2474 if (waste_level > 0) {
2475 if (waste_level < 100) {
2476 pcity->usage[o] += (surplus * waste_level / 100);
2477 } else {
2478 pcity->usage[o] = pcity->prod[o];
2479 }
2480 }
2481 }
2482
2483 pcity->surplus[o] = pcity->prod[o] - pcity->usage[o];
2485}
2486
2487/**********************************************************************/
2490static void happy_copy(struct city *pcity, enum citizen_feeling i)
2491{
2492 int c = 0;
2493
2494 for (; c < CITIZEN_LAST; c++) {
2495 pcity->feel[c][i] = pcity->feel[c][i - 1];
2496 }
2497}
2498
2499/**********************************************************************/
2502static void citizen_base_mood(struct city *pcity)
2503{
2504 struct player *pplayer = city_owner(pcity);
2505 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_BASE];
2506 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_BASE];
2507 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_BASE];
2508 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_BASE];
2509 citizens size = city_size_get(pcity);
2511
2512 /* This is the number of citizens that may start out content, depending
2513 * on empire size and game's city unhappysize. This may be bigger than
2514 * the size of the city, since this is a potential. */
2516 /* Similarly, this is the potential number of angry citizens. */
2518
2519 /* Create content citizens. Take specialists from their ranks. */
2520 *content = MAX(0, MIN(size, base_content) - spes);
2521
2522 /* Create angry citizens. Specialists never become angry. */
2523 fc_assert_action(base_content == 0 || base_angry == 0, *content = 0);
2524 *angry = MIN(base_angry, size - spes);
2525
2526 /* Create unhappy citizens. In the beginning, all who are not content,
2527 * specialists or angry are unhappy. This is changed by luxuries and
2528 * buildings later. */
2529 *unhappy = (size - spes - *content - *angry);
2530
2531 /* No one is born happy. */
2532 *happy = 0;
2533}
2534
2535/**********************************************************************/
2541static inline void citizen_luxury_happy(struct city *pcity, int *luxuries)
2542{
2543 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_LUXURY];
2544 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_LUXURY];
2545 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_LUXURY];
2546 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_LUXURY];
2547
2548 while (*luxuries >= game.info.happy_cost && *angry > 0) {
2549 /* Upgrade angry to unhappy: costs HAPPY_COST each. */
2550 (*angry)--;
2551 (*unhappy)++;
2553 }
2554 while (*luxuries >= game.info.happy_cost && *content > 0) {
2555 /* Upgrade content to happy: costs HAPPY_COST each. */
2556 (*content)--;
2557 (*happy)++;
2559 }
2560 while (*luxuries >= 2 * game.info.happy_cost && *unhappy > 0) {
2561 /* Upgrade unhappy to happy. Note this is a 2-level upgrade with
2562 * double the cost. */
2563 (*unhappy)--;
2564 (*happy)++;
2565 *luxuries -= 2 * game.info.happy_cost;
2566 }
2567 if (*luxuries >= game.info.happy_cost && *unhappy > 0) {
2568 /* Upgrade unhappy to content: costs HAPPY_COST each. */
2569 (*unhappy)--;
2570 (*content)++;
2572 }
2573}
2574
2575/**********************************************************************/
2578static inline void citizen_happy_luxury(struct city *pcity)
2579{
2580 int x = pcity->prod[O_LUXURY];
2581
2582 citizen_luxury_happy(pcity, &x);
2583}
2584
2585/**********************************************************************/
2588static inline void citizen_content_buildings(struct city *pcity)
2589{
2590 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_EFFECT];
2591 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_EFFECT];
2592 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_EFFECT];
2594
2595 /* make people content (but not happy):
2596 get rid of angry first, then make unhappy content. */
2597 while (faces > 0 && *angry > 0) {
2598 (*angry)--;
2599 (*unhappy)++;
2600 faces--;
2601 }
2602 while (faces > 0 && *unhappy > 0) {
2603 (*unhappy)--;
2604 (*content)++;
2605 faces--;
2606 }
2607}
2608
2609/**********************************************************************/
2612static inline void citizen_happiness_nationality(struct city *pcity)
2613{
2615 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_NATIONALITY];
2616 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_NATIONALITY];
2617
2620
2621 if (pct > 0) {
2622 int enemies = 0;
2623 int unhappy_inc;
2624 struct player *owner = city_owner(pcity);
2625
2626 citizens_foreign_iterate(pcity, pslot, nationality) {
2628 enemies += nationality;
2629 }
2631
2632 unhappy_inc = enemies * pct / 100;
2633
2634 /* First make content => unhappy, then happy => unhappy,
2635 * then happy => content. No-one becomes angry. */
2636 while (unhappy_inc > 0 && *content > 0) {
2637 (*content)--;
2638 (*unhappy)++;
2639 unhappy_inc--;
2640 }
2641 while (unhappy_inc > 1 && *happy > 0) {
2642 (*happy)--;
2643 (*unhappy)++;
2644 unhappy_inc -= 2;
2645 }
2646 while (unhappy_inc > 0 && *happy > 0) {
2647 (*happy)--;
2648 (*content)++;
2649 unhappy_inc--;
2650 }
2651 }
2652 }
2653}
2654
2655/**********************************************************************/
2661static inline void citizen_happy_units(struct city *pcity)
2662{
2663 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_MARTIAL];
2664 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_MARTIAL];
2665 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_MARTIAL];
2666 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_MARTIAL];
2667 citizens amt = pcity->martial_law;
2668
2669 /* Pacify discontent citizens through martial law. First convert
2670 * angry => unhappy, then unhappy => content. */
2671 while (amt > 0 && *angry > 0) {
2672 (*angry)--;
2673 (*unhappy)++;
2674 amt--;
2675 }
2676 while (amt > 0 && *unhappy > 0) {
2677 (*unhappy)--;
2678 (*content)++;
2679 amt--;
2680 }
2681
2682 /* Now make citizens unhappier because of military units away from home.
2683 * First make content => unhappy, then happy => unhappy,
2684 * then happy => content. */
2685 amt = pcity->unit_happy_upkeep;
2686 while (amt > 0 && *content > 0) {
2687 (*content)--;
2688 (*unhappy)++;
2689 amt--;
2690 }
2691 while (amt > 1 && *happy > 0) {
2692 (*happy)--;
2693 (*unhappy)++;
2694 amt -= 2;
2695 }
2696 while (amt > 0 && *happy > 0) {
2697 (*happy)--;
2698 (*content)++;
2699 amt--;
2700 }
2701 /* Any remaining unhappiness is lost since angry citizens aren't created
2702 * here. */
2703 /* FIXME: Why not? - Per */
2704}
2705
2706/**********************************************************************/
2709static inline void citizen_happy_wonders(struct city *pcity)
2710{
2711 citizens *happy = &pcity->feel[CITIZEN_HAPPY][FEELING_FINAL];
2712 citizens *content = &pcity->feel[CITIZEN_CONTENT][FEELING_FINAL];
2713 citizens *unhappy = &pcity->feel[CITIZEN_UNHAPPY][FEELING_FINAL];
2714 citizens *angry = &pcity->feel[CITIZEN_ANGRY][FEELING_FINAL];
2715 int bonus = get_city_bonus(pcity, EFT_MAKE_HAPPY);
2716
2717 /* First create happy citizens from content, then from unhappy
2718 * citizens; we cannot help angry citizens here. */
2719 while (bonus > 0 && *content > 0) {
2720 (*content)--;
2721 (*happy)++;
2722 bonus--;
2723 }
2724 while (bonus > 1 && *unhappy > 0) {
2725 (*unhappy)--;
2726 (*happy)++;
2727 bonus -= 2;
2728 }
2729 /* The rest falls through and lets unhappy people become content. */
2730
2731 if (get_city_bonus(pcity, EFT_NO_UNHAPPY) > 0) {
2732 *content += *unhappy + *angry;
2733 *unhappy = 0;
2734 *angry = 0;
2735 return;
2736 }
2737
2738 bonus += get_city_bonus(pcity, EFT_FORCE_CONTENT);
2739
2740 /* get rid of angry first, then make unhappy content */
2741 while (bonus > 0 && *angry > 0) {
2742 (*angry)--;
2743 (*unhappy)++;
2744 bonus--;
2745 }
2746 while (bonus > 0 && *unhappy > 0) {
2747 (*unhappy)--;
2748 (*content)++;
2749 bonus--;
2750 }
2751}
2752
2753/**********************************************************************/
2757static inline void unhappy_city_check(struct city *pcity)
2758{
2759 if (city_unhappy(pcity)) {
2761 switch (output_types[o].unhappy_penalty) {
2763 pcity->unhappy_penalty[o] = 0;
2764 break;
2766 pcity->unhappy_penalty[o] = MAX(pcity->prod[o] - pcity->usage[o], 0);
2767 break;
2769 pcity->unhappy_penalty[o] = pcity->prod[o];
2770 break;
2771 }
2772
2773 pcity->prod[o] -= pcity->unhappy_penalty[o];
2775 } else {
2776 memset(pcity->unhappy_penalty, 0,
2777 O_LAST * sizeof(*pcity->unhappy_penalty));
2778 }
2779}
2780
2781/**********************************************************************/
2784int city_pollution_types(const struct city *pcity, int shield_total,
2785 int *pollu_prod, int *pollu_pop, int *pollu_mod)
2786{
2787 int prod, pop, mod;
2788
2789 /* Add one one pollution per shield, multipled by the bonus. */
2790 prod = 100 + get_city_bonus(pcity, EFT_POLLU_PROD_PCT);
2791 prod = shield_total * MAX(prod, 0) / 100;
2792
2793 /* Add one pollution per citizen for baseline combined bonus (100%). */
2794 pop = (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT))
2795 * (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT_2))
2796 / 100;
2797 pop = (city_size_get(pcity) * MAX(pop, 0)) / 100;
2798
2799 /* Then there is base pollution (usually a negative number). */
2800 mod = game.info.base_pollution;
2801
2802 if (pollu_prod) {
2803 *pollu_prod = prod;
2804 }
2805 if (pollu_pop) {
2806 *pollu_pop = pop;
2807 }
2808 if (pollu_mod) {
2809 *pollu_mod = mod;
2810 }
2811 return MAX(prod + pop + mod, 0);
2812}
2813
2814/**********************************************************************/
2818int city_pollution(const struct city *pcity, int shield_total)
2819{
2821}
2822
2823/**********************************************************************/
2830static int get_trade_illness(const struct city *pcity)
2831{
2832 float illness_trade = 0.0;
2833
2835 if (trade_city->turn_plague != -1
2836 && game.info.turn - trade_city->turn_plague < 5) {
2837 illness_trade += (float)game.info.illness_trade_infection
2838 * sqrt(1.0 * city_size_get(pcity)
2839 * city_size_get(trade_city)) / 100.0;
2840 }
2842
2843 return (int)illness_trade;
2844}
2845
2846/**********************************************************************/
2850static int get_city_health(const struct city *pcity)
2851{
2852 return get_city_bonus(pcity, EFT_HEALTH_PCT);
2853}
2854
2855/**********************************************************************/
2867int city_illness_calc(const struct city *pcity, int *ill_base,
2868 int *ill_size, int *ill_trade, int *ill_pollution)
2869{
2870 int illness_size = 0, illness_trade = 0, illness_pollution = 0;
2872
2873 if (game.info.illness_on
2875 /* offset the city size by game.info.illness_min_size */
2877
2878 illness_size = (int)((1.0 - exp(- (float)use_size / 10.0))
2879 * 10.0 * game.info.illness_base_factor);
2880 if (is_server()) {
2881 /* on the server we recalculate the illness due to trade as we have
2882 * all informations */
2883 illness_trade = get_trade_illness(pcity);
2884 } else {
2885 /* on the client we have to rely on the value saved within the city
2886 * struct */
2887 illness_trade = pcity->illness_trade;
2888 }
2889
2892 }
2893
2894 illness_base = illness_size + illness_trade + illness_pollution;
2895 illness_percent = 100 - get_city_health(pcity);
2896
2897 /* returning other data */
2898 if (ill_size) {
2900 }
2901
2902 if (ill_trade) {
2903 *ill_trade = illness_trade;
2904 }
2905
2906 if (ill_pollution) {
2908 }
2909
2910 if (ill_base) {
2912 }
2913
2914 return CLIP(0, illness_base * illness_percent / 100 , 999);
2915}
2916
2917/**********************************************************************/
2920bool city_had_recent_plague(const struct city *pcity)
2921{
2922 /* Correctly handles special case turn_plague == -1 (never) */
2923 return (pcity->turn_plague == game.info.turn);
2924}
2925
2926/**********************************************************************/
2929int city_build_slots(const struct city *pcity)
2930{
2931 return get_city_bonus(pcity, EFT_CITY_BUILD_SLOTS);
2932}
2933
2934/**********************************************************************/
2939int city_airlift_max(const struct city *pcity)
2940{
2941 return get_city_bonus(pcity, EFT_AIRLIFT);
2942}
2943
2944/**********************************************************************/
2950inline void set_city_production(struct city *pcity)
2951{
2952 int trade;
2953
2954 /* Calculate city production!
2955 *
2956 * This is a rather complicated process if we allow rules to become
2957 * more generalized. We can assume that there are no recursive dependency
2958 * loops, but there are some dependencies that do not follow strict
2959 * ordering. For instance corruption must be calculated before
2960 * trade taxes can be counted up, which must occur before the science bonus
2961 * is added on. But the calculation of corruption must include the
2962 * trade bonus. To do this without excessive special casing means that in
2963 * this case the bonuses are multiplied on twice (but only saved the second
2964 * time).
2965 */
2966
2968 pcity->prod[o] = pcity->citizen_base[o];
2970
2971 /* Add on special extra incomes: trade routes and tithes. */
2973 struct city *tcity = game_city_by_number(proute->partner);
2974 bool can_trade;
2975
2976 /* Partner city may have not yet been sent to the client, or
2977 * there's just a placeholder city with a placeholder owner
2978 * created for some tile->worked. */
2979 if (!is_server()
2980 && (tcity == NULL
2981 || city_owner(tcity)->slot == NULL)) {
2982 continue;
2983 }
2984
2985 fc_assert_action(tcity != NULL, continue);
2986
2988
2989 if (!can_trade) {
2992
2993 if (settings->cancelling == TRI_ACTIVE) {
2994 can_trade = TRUE;
2995 }
2996 }
2997
2998 if (can_trade) {
2999 int value;
3000
3001 value =
3003 proute->value = trade_from_route(pcity, proute, value);
3004 pcity->prod[O_TRADE] += proute->value
3005 * (100 + get_city_bonus(pcity, EFT_TRADE_ROUTE_PCT)) / 100;
3006 } else {
3007 proute->value = 0;
3008 }
3010 pcity->prod[O_GOLD] += get_city_tithes_bonus(pcity);
3011
3012 /* Account for waste. Note that waste is calculated before tax income is
3013 * calculated, so if you had "science waste" it would not include taxed
3014 * science. However waste is calculated after the bonuses are multiplied
3015 * on, so shield waste will include shield bonuses. */
3017 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3018
3019 prod = MAX(prod, 0);
3020 pcity->waste[o] = city_waste(pcity, o, prod, NULL);
3022
3023 /* Convert trade into science/luxury/gold, and add this on to whatever
3024 * science/luxury/gold is already there. */
3025 trade = pcity->prod[O_TRADE] * pcity->bonus[O_TRADE] / 100
3026 + pcity->abs_bonus[O_TRADE];
3027 trade = MAX(trade, 0);
3029 trade - pcity->waste[O_TRADE] - pcity->usage[O_TRADE],
3030 pcity->prod);
3031
3032 /* Add on effect bonuses and waste. Note that the waste calculation
3033 * (above) already includes the bonuses. */
3035 int prod = pcity->prod[o] * pcity->bonus[o] / 100 + pcity->abs_bonus[o];
3036
3037 prod = MAX(prod, 0);
3038 pcity->prod[o] = prod;
3039 pcity->prod[o] -= pcity->waste[o];
3041}
3042
3043/**********************************************************************/
3047{
3048 struct city *pcity;
3049 const struct unit_type *ut;
3050 struct player *plr;
3051 int happy_cost;
3052
3053 if (!punit || !free_unhappy) {
3054 return 0;
3055 }
3056
3058 if (pcity == NULL) {
3059 return 0;
3060 }
3061
3063 plr = unit_owner(punit);
3064 happy_cost = utype_happy_cost(ut, plr);
3065
3066 if (happy_cost <= 0) {
3067 return 0;
3068 }
3069
3071
3073 return 0;
3074 }
3075
3076 happy_cost -= get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL_PER);
3077 if (happy_cost <= 0) {
3078 return 0;
3079 }
3080
3081 if (*free_unhappy >= happy_cost) {
3082 *free_unhappy -= happy_cost;
3083 return 0;
3084 } else {
3085 happy_cost -= *free_unhappy;
3086 *free_unhappy = 0;
3087 }
3088
3089 return happy_cost;
3090}
3091
3092/**********************************************************************/
3096static inline void city_support(struct city *pcity)
3097{
3099
3100 /* Clear all usage values. */
3101 memset(pcity->usage, 0, O_LAST * sizeof(*pcity->usage));
3102 pcity->martial_law = 0;
3103 pcity->unit_happy_upkeep = 0;
3104
3105 /* Building and unit gold upkeep depends on the setting
3106 * 'game.info.gold_upkeep_style':
3107 * GOLD_UPKEEP_CITY: The upkeep for buildings and units is paid by the
3108 * city.
3109 * GOLD_UPKEEP_MIXED: The upkeep for buildings is paid by the city.
3110 * The upkeep for units is paid by the nation.
3111 * GOLD_UPKEEP_NATION: The upkeep for buildings and units is paid by the
3112 * nation. */
3114 "Invalid gold_upkeep_style %d", game.info.gold_upkeep_style);
3115 switch (game.info.gold_upkeep_style) {
3116 case GOLD_UPKEEP_CITY:
3117 pcity->usage[O_GOLD] += city_total_unit_gold_upkeep(pcity);
3118 fc__fallthrough; /* No break */
3119 case GOLD_UPKEEP_MIXED:
3120 pcity->usage[O_GOLD] += city_total_impr_gold_upkeep(pcity);
3121 break;
3122 case GOLD_UPKEEP_NATION:
3123 /* nothing */
3124 break;
3125 }
3126 /* Food consumption by citizens. */
3127 pcity->usage[O_FOOD] += game.info.food_cost * city_size_get(pcity);
3128
3129 /* Military units in this city (need _not_ be home city) can make
3130 * unhappy citizens content */
3132 if (martial_law_each > 0) {
3133 int count = 0;
3135
3136 unit_list_iterate(pcity->tile->units, punit) {
3137 if ((count < martial_law_max || martial_law_max == 0)
3139 && unit_owner(punit) == city_owner(pcity)) {
3140 count++;
3141 }
3143
3144 pcity->martial_law = CLIP(0, count * martial_law_each, MAX_CITY_SIZE);
3145 }
3146
3151 if (O_GOLD != o) {
3152 /* O_GOLD is handled with "game.info.gold_upkeep_style", see over. */
3153 pcity->usage[o] += punit->upkeep[o];
3154 }
3157}
3158
3159/**********************************************************************/
3171void city_refresh_from_main_map(struct city *pcity, bool *workers_map)
3172{
3173 const struct civ_map *nmap = &(wld.map);
3174
3175 if (workers_map == NULL) {
3176 /* do a full refresh */
3177
3178 /* Calculate the bonus[] array values. */
3179 set_city_bonuses(pcity);
3180 /* Calculate the tile_cache[] values. */
3182 /* manage settlers, and units */
3183 city_support(pcity);
3184 }
3185
3186 /* Calculate output from citizens (uses city_tile_cache_get_output()). */
3187 get_worked_tile_output(pcity, pcity->citizen_base, workers_map);
3188 add_specialist_output(pcity, pcity->citizen_base);
3189
3190 set_city_production(pcity);
3191 citizen_base_mood(pcity);
3192 /* Note that pollution is calculated before unhappy_city_check() makes
3193 * deductions for disorder; so a city in disorder still causes pollution */
3194 pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
3195
3196 happy_copy(pcity, FEELING_LUXURY);
3197 citizen_happy_luxury(pcity); /* with our new found luxuries */
3198
3199 happy_copy(pcity, FEELING_EFFECT);
3201
3204
3205 /* Martial law & unrest from units */
3207 citizen_happy_units(pcity);
3208
3209 /* Building (including wonder) happiness effects */
3210 happy_copy(pcity, FEELING_FINAL);
3211 citizen_happy_wonders(pcity);
3212
3213 unhappy_city_check(pcity);
3214 set_surpluses(pcity);
3215}
3216
3217/**********************************************************************/
3224int city_waste(const struct city *pcity, Output_type_id otype, int total,
3225 int *breakdown)
3226{
3227 int penalty_waste = 0;
3228 int penalty_size = 0; /* Separate notradesize/fulltradesize from normal
3229 * corruption */
3230 int total_eft = total; /* Normal corruption calculated on total reduced by
3231 * possible size penalty */
3232 const struct output_type *output = get_output_type(otype);
3234 bool waste_all = FALSE;
3235
3236 if (otype == O_TRADE) {
3237 /* FIXME: special case for trade: it is affected by notradesize and
3238 * fulltradesize server settings.
3239 *
3240 * If notradesize and fulltradesize are equal then the city gets no
3241 * trade at that size. */
3242 int notradesize = MIN(game.info.notradesize, game.info.fulltradesize);
3243 int fulltradesize = MAX(game.info.notradesize, game.info.fulltradesize);
3244
3245 if (city_size_get(pcity) <= notradesize) {
3246 penalty_size = total_eft; /* Then no trade income. */
3247 } else if (city_size_get(pcity) >= fulltradesize) {
3248 penalty_size = 0;
3249 } else {
3250 penalty_size = total_eft * (fulltradesize - city_size_get(pcity))
3251 / (fulltradesize - notradesize);
3252 }
3253 }
3254
3255 /* Apply corruption only to anything left after tradesize */
3257
3258 /* Distance-based waste.
3259 * Don't bother calculating if there's nothing left to lose. */
3260 if (total_eft > 0) {
3261 int waste_by_dist = get_city_output_bonus(pcity, output,
3263 int waste_by_rel_dist = get_city_output_bonus(pcity, output,
3265 if (waste_by_dist > 0 || waste_by_rel_dist > 0) {
3266 int min_dist;
3267 const struct city *gov_center = nearest_gov_center(pcity, &min_dist);
3268
3269 if (gov_center == NULL) {
3270 waste_all = TRUE; /* No gov center - no income */
3271 } else {
3273 if (waste_by_rel_dist > 0) {
3274 /* Multiply by 50 as an "standard size" for which EFT_OUTPUT_WASTE_BY_DISTANCE
3275 * and EFT_OUTPUT_WASTE_BY_REL_DISTANCE would give same result. */
3276 waste_level += waste_by_rel_dist * 50 * min_dist / 100
3278 }
3279 }
3280 }
3281 }
3282
3283 if (waste_all) {
3285 } else {
3286 int waste_pct = get_city_output_bonus(pcity, output,
3288
3289 /* Corruption/waste calculated only for the actually produced amount */
3290 if (waste_level > 0) {
3292 }
3293
3294 /* Bonus calculated only for the actually produced amount */
3296
3297 /* Clip */
3299 }
3300
3301 if (breakdown) {
3304 }
3305
3306 /* Add up total penalty */
3307 return penalty_waste + penalty_size;
3308}
3309
3310/**********************************************************************/
3313citizens city_specialists(const struct city *pcity)
3314{
3315 citizens count = 0;
3316
3318 fc_assert_ret_val(MAX_CITY_SIZE - count > pcity->specialists[sp], 0);
3319 count += pcity->specialists[sp];
3321
3322 return count;
3323}
3324
3325/**********************************************************************/
3331 const struct city *pcity)
3332{
3333 int best = DEFAULT_SPECIALIST;
3334 int val = get_specialist_output(pcity, best, otype);
3335
3337 if (!pcity || city_can_use_specialist(pcity, i)) {
3338 int val2 = get_specialist_output(pcity, i, otype);
3339
3340 if (val2 > val) {
3341 best = i;
3342 val = val2;
3343 }
3344 }
3346
3347 return best;
3348}
3349
3350/**********************************************************************/
3353void city_add_improvement(struct city *pcity,
3354 const struct impr_type *pimprove)
3355{
3356 pcity->built[improvement_index(pimprove)].turn = game.info.turn; /*I_ACTIVE*/
3357
3358 if (is_server() && is_wonder(pimprove)) {
3359 /* Client just read the info from the packets. */
3360 wonder_built(pcity, pimprove);
3361 }
3362}
3363
3364/**********************************************************************/
3368 const struct impr_type *pimprove)
3369{
3370 log_debug("Improvement %s removed from city %s",
3371 improvement_rule_name(pimprove), pcity->name);
3372
3373 pcity->built[improvement_index(pimprove)].turn = I_DESTROYED;
3374
3375 if (is_server() && is_wonder(pimprove)) {
3376 /* Client just read the info from the packets. */
3377 wonder_destroyed(pcity, pimprove);
3378 }
3379}
3380
3381/**********************************************************************/
3384bool is_city_option_set(const struct city *pcity, enum city_options option)
3385{
3386 return BV_ISSET(pcity->city_options, option);
3387}
3388
3389/**********************************************************************/
3393{
3394 int i;
3395
3396 city_styles = fc_calloc(num, sizeof(*city_styles));
3398
3399 for (i = 0; i < game.control.num_city_styles; i++) {
3401 }
3402}
3403
3404/**********************************************************************/
3408{
3409 int i;
3410
3411 for (i = 0; i < game.control.num_city_styles; i++) {
3413 }
3414
3416 city_styles = NULL;
3418}
3419
3420/**********************************************************************/
3426struct city *create_city_virtual(struct player *pplayer,
3427 struct tile *ptile, const char *name)
3428{
3429 int i,len;
3430
3431 /* Make sure that contents of city structure are correctly initialized,
3432 * if you ever allocate it by some other mean than fc_calloc() */
3433 struct city *pcity = fc_calloc(1, sizeof(*pcity));
3434
3435 fc_assert_ret_val(NULL != name, NULL); /* No unnamed cities! */
3436
3437 /* Do this early, so any logging later will have the city name */
3438 city_name_set(pcity, name);
3439
3440 pcity->tile = ptile;
3441 fc_assert_ret_val(NULL != pplayer, NULL); /* No unowned cities! */
3442 pcity->owner = pplayer;
3443 pcity->acquire_t = CACQ_FOUNDED;
3444
3445 if (is_server()) {
3446 pcity->original = pplayer;
3447 }
3448
3449 /* City structure was allocated with fc_calloc(), so contents are initially
3450 * zero. There is no need to initialize it a second time. */
3451
3452 /* Now set some useful default values. */
3453 pcity->capital = CAPITAL_NOT;
3454 city_size_set(pcity, 1);
3455 pcity->specialists[DEFAULT_SPECIALIST] = 1;
3456 pcity->wlcb = WLCB_SMART;
3457
3459 pcity->bonus[o] = 100;
3460 pcity->abs_bonus[o] = 0;
3462
3463 pcity->turn_plague = -1; /* -1 = never */
3464 pcity->did_buy = FALSE;
3466 pcity->turn_founded = game.info.turn;
3467 pcity->turn_last_built = game.info.turn;
3468
3469 pcity->tile_cache_radius_sq = -1; /* -1 = tile_cache must be initialised */
3470
3471 /* pcity->ai.act_cache: worker activities on the city map */
3472
3473 /* Initialise improvements list */
3474 for (i = 0; i < ARRAY_SIZE(pcity->built); i++) {
3475 pcity->built[i].turn = I_NEVER;
3476 }
3477
3478 /* Set up the worklist */
3479 worklist_init(&pcity->worklist);
3480
3481 pcity->units_supported = unit_list_new();
3482 pcity->routes = trade_route_list_new();
3484
3485 if (is_server()) {
3486 pcity->server.mgr_score_calc_turn = -1; /* -1 = never */
3487
3488 CALL_FUNC_EACH_AI(city_alloc, pcity);
3489 } else {
3492 pcity->client.info_units_present =
3494 /* collecting_info_units_supported set by fc_calloc().
3495 * collecting_info_units_present set by fc_calloc(). */
3496 }
3497
3499 pcity->counter_values = fc_malloc(sizeof(int) * len);
3500
3501 for (i = 0; i < len; i++) {
3503 }
3504
3505 return pcity;
3506}
3507
3508/**********************************************************************/
3512void destroy_city_virtual(struct city *pcity)
3513{
3514 CALL_FUNC_EACH_AI(city_free, pcity);
3515
3516 citizens_free(pcity);
3517
3518 /* Free worker tasks */
3519 while (worker_task_list_size(pcity->task_reqs) > 0) {
3520 struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0);
3521
3523
3524 free(ptask);
3525 }
3527
3528 /* Free rally points */
3530
3533 if (pcity->tile_cache != NULL) {
3534 free(pcity->tile_cache);
3535 }
3536
3537 if (pcity->cm_parameter) {
3538 free(pcity->cm_parameter);
3539 }
3540
3541 if (pcity->counter_values) {
3542 free(pcity->counter_values);
3543 }
3544
3545 if (!is_server()) {
3548 /* Handle a rare case where the game is freed in the middle of a
3549 * spy/diplomat investigate cycle. */
3552 }
3555 }
3556 }
3557
3558 free(pcity->name);
3559
3560 memset(pcity, 0, sizeof(*pcity)); /* ensure no pointers remain */
3561 free(pcity);
3562}
3563
3564/**********************************************************************/
3568bool city_exist(int id)
3569{
3570 /* Check if city exist in game */
3571 if (game_city_by_number(id)) {
3572 return TRUE;
3573 }
3574
3575 return FALSE;
3576}
3577
3578/**********************************************************************/
3585bool city_is_virtual(const struct city *pcity)
3586{
3587 if (!pcity) {
3588 return FALSE;
3589 }
3590
3591 return pcity != game_city_by_number(pcity->id);
3592}
3593
3594/**********************************************************************/
3597bool is_free_worked(const struct city *pcity, const struct tile *ptile)
3598{
3599 return is_city_center(pcity, ptile);
3600}
3601
3602/**********************************************************************/
3605void *city_ai_data(const struct city *pcity, const struct ai_type *ai)
3606{
3607 return pcity->server.ais[ai_type_number(ai)];
3608}
3609
3610/**********************************************************************/
3613void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
3614 void *data)
3615{
3616 pcity->server.ais[ai_type_number(ai)] = data;
3617}
3618
3619/**********************************************************************/
3622void city_rally_point_clear(struct city *pcity)
3623{
3624 /* Free rally points */
3625 if (pcity->rally_point.length > 0) {
3626 pcity->rally_point.length = 0;
3627 pcity->rally_point.persistent = FALSE;
3628 pcity->rally_point.vigilant = FALSE;
3629 free(pcity->rally_point.orders);
3630 pcity->rally_point.orders = NULL;
3631 }
3632}
3633
3634/**********************************************************************/
3638 struct city *pcity)
3639{
3640 struct unit_order *checked_orders;
3641 const struct civ_map *nmap = &(wld.map);
3642
3643 if (NULL == pcity) {
3644 /* Probably lost. */
3645 log_verbose("handle_city_rally_point() bad city number %d.",
3646 packet->id);
3647 return;
3648 }
3649
3650 if (0 > packet->length || MAX_LEN_ROUTE < packet->length) {
3651 /* Shouldn't happen */
3652 log_error("city_rally_point_receive() invalid packet length %d (max %d)",
3653 packet->length, MAX_LEN_ROUTE);
3654 return;
3655 }
3656
3657 pcity->rally_point.length = packet->length;
3658
3659 if (packet->length == 0) {
3660 pcity->rally_point.vigilant = FALSE;
3661 pcity->rally_point.persistent = FALSE;
3662 if (pcity->rally_point.orders) {
3663 free(pcity->rally_point.orders);
3664 pcity->rally_point.orders = NULL;
3665 }
3666 } else {
3668 packet->orders);
3669 if (!checked_orders) {
3670 pcity->rally_point.length = 0;
3671 log_error("invalid rally point orders for %s.",
3672 city_name_get(pcity));
3673 return;
3674 }
3675
3676 pcity->rally_point.persistent = packet->persistent;
3677 pcity->rally_point.vigilant = packet->vigilant;
3679 }
3680}
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1529
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:236
#define action_enabler_list_iterate_end
Definition actions.h:185
#define action_by_result_iterate_end
Definition actions.h:240
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:183
#define action_id(_act_)
Definition actions.h:416
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:1633
bool city_is_virtual(const struct city *pcity)
Definition city.c:3585
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:1961
static void citizen_luxury_happy(struct city *pcity, int *luxuries)
Definition city.c:2541
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:663
bool city_exists_within_max_city_map(const struct tile *ptile, bool may_be_on_center)
Definition city.c:2108
static void citizen_content_buildings(struct city *pcity)
Definition city.c:2588
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3597
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1856
static bv_imprs caravan_helped_impr
Definition city.c:1767
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:1141
static int player_base_citizen_happiness(const struct player *pplayer)
Definition city.c:2157
bool can_city_build_unit_later(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:968
int city_granary_size(int city_size)
Definition city.c:2129
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2193
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2784
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3613
static void get_worked_tile_output(const struct city *pcity, int *output, bool *workers_map)
Definition city.c:2321
static void citizen_happy_wonders(struct city *pcity)
Definition city.c:2709
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2088
static void city_support(struct city *pcity)
Definition city.c:3096
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2276
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Definition city.c:1011
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3224
int city_unit_unhappiness(struct unit *punit, int *free_unhappy)
Definition city.c:3046
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2929
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:1236
const char * city_style_name_translation(const int style)
Definition city.c:1752
void city_styles_free(void)
Definition city.c:3407
static int city_tile_cache_get_output(const struct city *pcity, int city_tile_index, enum output_type_id o)
Definition city.c:2435
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:647
bool is_capital(const struct city *pcity)
Definition city.c:1575
void city_styles_alloc(int num)
Definition city.c:3392
const char * city_name_get(const struct city *pcity)
Definition city.c:1133
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1397
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1045
void city_production_caravan_shields_init(void)
Definition city.c:1774
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3367
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1251
int city_airlift_max(const struct city *pcity)
Definition city.c:2939
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1461
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:3384
int city_population(const struct city *pcity)
Definition city.c:1187
static struct iter_index * city_map_index
Definition city.c:60
const char * city_style_rule_name(const int style)
Definition city.c:1761
void city_size_add(struct city *pcity, int add)
Definition city.c:1160
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1061
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:1661
void free_city_map_index(void)
Definition city.c:609
void city_refresh_from_main_map(struct city *pcity, bool *workers_map)
Definition city.c:3171
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:2242
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:2062
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1592
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2183
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:2406
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2224
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2077
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:1649
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:1622
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3330
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3426
void set_city_production(struct city *pcity)
Definition city.c:2950
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1675
static bv_unit_types caravan_helped_utype
Definition city.c:1768
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2209
bool city_celebrating(const struct city *pcity)
Definition city.c:1641
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1556
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:2867
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:2008
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1882
static int get_city_health(const struct city *pcity)
Definition city.c:2850
bool is_valid_city_coords(const int city_radius_sq, const int city_map_x, const int city_map_y)
Definition city.c:188
static void set_city_bonuses(struct city *pcity)
Definition city.c:2383
static void set_surpluses(struct city *pcity)
Definition city.c:2449
static const struct city * nearest_gov_center(const struct city *pcity, int *min_dist) fc__attribute((nonnull(1
Definition city.c:2284
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:1483
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2818
bool city_happy(const struct city *pcity)
Definition city.c:1610
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1176
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3353
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1380
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
bool can_city_build_direct(const struct city *pcity, const struct universal *target)
Definition city.c:993
struct city * tile_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2032
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2017
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:3512
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:3313
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:3637
static int cmp(int v1, int v2)
Definition city.c:325
#define CITYLOG_MAX_VAL
Definition city.c:368
void city_choose_build_default(struct city *pcity)
Definition city.c:1083
int city_style_by_translated_name(const char *s)
Definition city.c:1717
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2361
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:3605
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1691
static void citizen_happiness_nationality(struct city *pcity)
Definition city.c:2612
bool can_city_build_later(const struct city *pcity, const struct universal *target)
Definition city.c:1028
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1279
static int city_map_xy[CITY_MAP_MAX_SIZE][CITY_MAP_MAX_SIZE]
Definition city.c:64
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:123
bool is_gov_center(const struct city *pcity)
Definition city.c:1583
#define log_ca_s_init
static void citizen_happy_luxury(struct city *pcity)
Definition city.c:2578
int city_map_tiles(int city_radius_sq)
Definition city.c:171
static void unhappy_city_check(struct city *pcity)
Definition city.c:2757
bool can_city_build_unit_direct(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:903
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2047
bool city_exist(int id)
Definition city.c:3568
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1452
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:1992
void city_rally_point_clear(struct city *pcity)
Definition city.c:3622
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_had_recent_plague(const struct city *pcity)
Definition city.c:2920
static int get_trade_illness(const struct city *pcity)
Definition city.c:2830
bool city_can_change_build(const struct city *pcity)
Definition city.c:1075
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1218
int city_style_by_rule_name(const char *s)
Definition city.c:1734
static void citizen_base_mood(struct city *pcity)
Definition city.c:2502
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1707
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1197
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:948
static void citizen_happy_units(struct city *pcity)
Definition city.c:2661
static void happy_copy(struct city *pcity, enum citizen_feeling i)
Definition city.c:2490
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:836
#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:859
#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:825
#define is_free_worked_index(city_tile_index)
Definition city.h:871
#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:831
#define output_type_iterate_end
Definition city.h:842
void cm_init_citymap(void)
Definition cm.c:314
char * incite_cost
Definition comments.c:74
#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:936
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:980
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Definition effects.c:1004
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:912
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
int effect_cumulative_max(enum effect_type type, struct universal *unis, size_t n_unis)
Definition effects.c:388
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:1031
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:824
static bool is_server(void)
unsigned char citizens
Definition fc_types.h:392
@ RPT_CERTAIN
Definition fc_types.h:678
@ RPT_POSSIBLE
Definition fc_types.h:677
int Specialist_type_id
Definition fc_types.h:379
@ 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:382
#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:61
struct world wld
Definition game.c:62
struct city * game_city_by_number(int id)
Definition game.c:106
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:425
int map_vector_to_sq_distance(int dx, int dy)
Definition map.c:620
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Definition map.c:950
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:636
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
Definition map.c:1087
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:377
#define square_iterate_end
Definition map.h:380
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:218
#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:318
bool is_native_near_tile(const struct civ_map *nmap, const struct unit_class *uclass, const struct tile *ptile)
Definition movement.c:464
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:1409
bool pplayers_non_attack(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1463
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:1497
int universal_build_shield_cost(const struct city *pcity, const struct universal *target)
bool are_reqs_active(const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
enum req_unchanging_status is_req_preventing(const struct req_context *context, const struct req_context *other_context, const struct requirement *req, enum req_problem_type prob_type)
bool are_reqs_active_ranges(const enum req_range min_range, const enum req_range max_range, const struct req_context *context, const struct req_context *other_context, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
bool req_vec_wants_type(const struct requirement_vector *reqs, enum universals_n kind)
bool does_req_contradicts_reqs(const struct requirement *req, const struct requirement_vector *vec)
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
static struct setting settings[]
Definition settings.c:1474
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:281
struct unit_list * units
Definition player.h:282
struct player_economic economic
Definition player.h:284
const struct player * player
struct requirement_vector reqs
Definition specialist.h:38
int irrigation_food_incr
Definition terrain.h:114
int output[O_LAST]
Definition terrain.h:95
int mining_shield_incr
Definition terrain.h:117
int output[O_LAST]
Definition city.c:71
Definition tile.h:50
struct unit_list * units
Definition tile.h:58
int city_slots
Definition unittype.h:559
int upkeep[O_LAST]
Definition unittype.h:545
Definition unit.h:140
int upkeep[O_LAST]
Definition unit.h:150
int homecity
Definition unit.h:148
enum universals_n kind
Definition fc_types.h:880
universals_u value
Definition fc_types.h:879
struct tile * ptile
Definition workertask.h:22
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define sz_strlcpy(dest, src)
Definition support.h:189
#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:190
#define fc__fallthrough
Definition support.h:119
#define T_UNKNOWN
Definition terrain.h:62
#define terrain_has_flag(terr, flag)
Definition terrain.h:176
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:89
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:104
#define tile_worked(_tile)
Definition tile.h:115
#define tile_resource(_tile)
Definition tile.h:103
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:111
#define tile_owner(_tile)
Definition tile.h:97
bool can_cities_trade(const struct city *pc1, const struct city *pc2)
enum trade_route_type cities_trade_route_type(const struct city *pcity1, const struct city *pcity2)
Definition traderoutes.c:58
int trade_base_between_cities(const struct city *pc1, const struct city *pc2)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
int trade_from_route(const struct city *pc1, const struct trade_route *route, int base)
@ TRI_ACTIVE
Definition traderoutes.h:30
#define trade_routes_iterate_end
#define trade_partners_iterate_end
#define trade_routes_iterate(c, proute)
#define trade_partners_iterate(c, p)
trade_route_type
Definition traderoutes.h:37
const struct unit_type * utype
Definition fc_types.h:698
const struct impr_type * building
Definition fc_types.h:691
struct unit_order * create_unit_orders(const struct civ_map *nmap, int length, const struct unit_order *orders)
Definition unit.c:2892
bool unit_being_aggressive(const struct unit *punit)
Definition unit.c:1556
bool is_field_unit(const struct unit *punit)
Definition unit.c:441
bool is_martial_law_unit(const struct unit *punit)
Definition unit.c:319
void unit_virtual_destroy(struct unit *punit)
Definition unit.c:1767
struct unit * unit_occupies_tile(const struct tile *ptile, const struct player *pplayer)
Definition unit.c:1398
#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:2613
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:773
#define utype_class(_t_)
Definition unittype.h:756
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define unit_type_iterate(_p)
Definition unittype.h:859
#define unit_type_iterate_end
Definition unittype.h:866
#define U_NOT_OBSOLETED
Definition unittype.h:535
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57
#define MAP_NATIVE_WIDTH
#define MAP_NATIVE_HEIGHT