Freeciv-3.3
Loading...
Searching...
No Matches
city.h
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#ifndef FC__CITY_H
14#define FC__CITY_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "bitvector.h"
22#include "log.h"
23
24/* common */
25#include "fc_types.h"
26#include "name_translation.h"
27#include "tile.h"
28#include "traderoutes.h"
29#include "workertask.h"
30#include "worklist.h"
31
32struct impr_type;
33struct unit;
34struct unit_list;
35struct vision;
37
38#include "city_enums_gen.h"
39
40#define PCT_LAST PCT_COUNT
41
42/* Various city options. These are stored by the server and can be
43 * toggled by the user. Each one defaults to off. Adding new ones
44 * will break network compatibility. If you want to reorder or remove
45 * an option remember to load the city option order from the savegame.
46 * It is stored in savefile.city_options_vector
47 *
48 * Used in the network protocol.
49 */
50#define SPECENUM_NAME city_options
51/* If unit production (e.g. settler) is allowed to disband a small city */
52#define SPECENUM_VALUE0 CITYO_DISBAND
53#define SPECENUM_VALUE0NAME "Disband"
54/* If new citizens are science specialists */
55#define SPECENUM_VALUE1 CITYO_SCIENCE_SPECIALISTS
56#define SPECENUM_VALUE1NAME "Sci_Specialists"
57/* If new citizens are gold specialists */
58#define SPECENUM_VALUE2 CITYO_GOLD_SPECIALISTS
59#define SPECENUM_VALUE2NAME "Tax_Specialists"
60#define SPECENUM_COUNT CITYO_LAST
61#define SPECENUM_BITVECTOR bv_city_options
62#include "specenum_gen.h"
63
64/* Used in savegames, and there's currently no order of the values
65 * stored in the savegame. Implement that before touching the values. */
66#define SPECENUM_NAME city_wl_cancel_behavior
67#define SPECENUM_VALUE0 WLCB_SMART
68 /* TRANS: Worklist Cancelling behavior
69 * (when something cannot be built right away) */
70#define SPECENUM_VALUE0NAME N_("?wlcb:Smart")
71#define SPECENUM_VALUE1 WLCB_ALWAYS_PURGE
72#define SPECENUM_VALUE1NAME N_("?wlcb:Always Purge")
73#define SPECENUM_VALUE2 WLCB_ALWAYS_POSTPONE
74#define SPECENUM_VALUE2NAME N_("?wlcb:Always Postpone")
75#define SPECENUM_COUNT WLCB_LAST
76#include "specenum_gen.h"
77
78/* The city includes all tiles dx^2 + dy^2 <= CITY_MAP_*_RADIUS_SQ */
79#define CITY_MAP_DEFAULT_RADIUS_SQ \
80 (CITY_MAP_DEFAULT_RADIUS * CITY_MAP_DEFAULT_RADIUS + 1)
81#define CITY_MAP_MIN_RADIUS_SQ \
82 (CITY_MAP_MIN_RADIUS * CITY_MAP_MIN_RADIUS + 1)
83#define CITY_MAP_MAX_RADIUS_SQ \
84 (CITY_MAP_MAX_RADIUS * CITY_MAP_MAX_RADIUS + 1)
85/* The id for the city center */
86#define CITY_MAP_CENTER_RADIUS_SQ -1
87/* The tile index of the city center */
88#define CITY_MAP_CENTER_TILE_INDEX 0
89
90/* Maximum diameter of the workable city area. */
91#define CITY_MAP_MAX_SIZE (CITY_MAP_MAX_RADIUS * 2 + 1)
92
93#define INCITE_IMPOSSIBLE_COST (1000 * 1000 * 1000)
94
95/*
96 * Size of the biggest possible city.
97 *
98 * The constant may be changed since it isn't externally visible.
99 *
100 * The city size is saved as unsigned char. Therefore, MAX_CITY_SIZE should
101 * be below 255!
102 */
103#define MAX_CITY_SIZE 0xFF
104
105/* Iterate a city map, from the center (the city) outwards */
107 int dx, dy, dist;
108};
109
110/* City map coordinates are positive integers shifted by the maximum
111 * radius the game engine allows (not the current ruleset) */
112#define CITY_REL2ABS(_coor) (_coor + CITY_MAP_MAX_RADIUS)
113#define CITY_ABS2REL(_coor) (_coor - CITY_MAP_MAX_RADIUS)
114
116 int city_tile_index, int city_radius_sq);
118 int city_radius_sq);
119
120int rs_max_city_radius_sq(void);
121int city_map_radius_sq_get(const struct city *pcity);
122void city_map_radius_sq_set(struct city *pcity, int radius_sq);
123int city_map_tiles(int city_radius_sq);
124#define city_map_tiles_from_city(_pcity) \
125 city_map_tiles(city_map_radius_sq_get(_pcity))
126
127void citylog_map_data(enum log_level level, int radius_sq, int *map_data);
128void citylog_map_workers(enum log_level level, struct city *pcity);
129
130/* Iterate over the tiles of a city map. Starting at a given city radius
131 * (the city center is _radius_sq_min = 0) outward to the tiles of
132 * _radius_sq_max. (_x, _y) will be the valid elements of
133 * [0, CITY_MAP_MAX_SIZE] taking into account the city radius. */
134#define city_map_iterate_outwards_radius_sq_index(_radius_sq_min, \
135 _radius_sq_max, \
136 _index, _x, _y) \
137{ \
138 fc_assert(_radius_sq_min <= _radius_sq_max); \
139 int _x = 0, _y = 0, _index; \
140 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
141 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
142 _radius_sq_max)) { \
143 _index = _x##_y##_index; \
144 _x##_y##_index++;
145
146#define city_map_iterate_outwards_radius_sq_index_end \
147 } \
148}
149
150 /* Same as above, but don't set index */
151#define city_map_iterate_outwards_radius_sq(_radius_sq_min, \
152 _radius_sq_max, \
153 _x, _y) \
154{ \
155 fc_assert(_radius_sq_min <= _radius_sq_max); \
156 int _x = 0, _y = 0; \
157 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
158 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
159 _radius_sq_max)) { \
160 _x##_y##_index++;
161
162#define city_map_iterate_outwards_radius_sq_end \
163 } \
164}
165
166/* Iterate a city map. This iterates over all city positions in the city
167 * map starting at the city center (i.e., positions that are workable by
168 * the city) using the index (_index) and the coordinates (_x, _y). It
169 * is an abbreviation for city_map_iterate_outwards_radius_sq(_end). */
170#define city_map_iterate(_radius_sq, _index, _x, _y) \
171 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
172 _radius_sq, _index, _x, _y)
173
174#define city_map_iterate_end \
175 city_map_iterate_outwards_radius_sq_index_end
176
177#define city_map_iterate_without_index(_radius_sq, _x, _y) \
178 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
179 _radius_sq, _x, _y)
180
181#define city_map_iterate_without_index_end \
182 city_map_iterate_outwards_radius_sq_end
183
184/* Iterate the tiles between two radii of a city map. */
185#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, \
186 _x, _y) \
187 city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, \
188 _x, _y)
189
190#define city_map_iterate_radius_sq_end \
191 city_map_iterate_outwards_radius_sq_end
192
193/* Iterate a city map in checked real map coordinates.
194 * _radius_sq is the squared city radius.
195 * _city_tile is the center of the (possible) city.
196 * (_index) will be the city tile index in the interval
197 * [0, city_map_tiles(_radius_sq)] */
198#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, \
199 _index) { \
200 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
201 _radius_sq, _index, _x, _y) \
202 struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
203 _x, _y); \
204 if (NULL != _tile) {
205
206#define city_tile_iterate_index_end \
207 } \
208 } city_map_iterate_outwards_radius_sq_index_end;
209
210/* simple extension to skip is_free_worked() tiles. */
211#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, \
212 _tile, _index, _x, _y) { \
213 city_map_iterate(_radius_sq, _index, _x, _y) { \
214 if (!is_free_worked_index(_index)) { \
215 struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
216 _x, _y); \
217 if (NULL != _tile) {
218
219#define city_tile_iterate_skip_free_worked_end \
220 } \
221 } \
222 } city_map_iterate_end; \
223}
224
225/* Does the same thing as city_tile_iterate_index(), but keeps the city
226 * coordinates hidden. */
227#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile) { \
228 const struct tile *_center##_tile = _city_tile; \
229 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
230 _radius_sq, _x, _y) \
231 struct tile *_tile = city_map_to_tile(_nmap, _center##_tile, _radius_sq, \
232 _x, _y); \
233 if (NULL != _tile) {
234
235#define city_tile_iterate_end \
236 } \
237 } city_map_iterate_outwards_radius_sq_end;
238
239/* Improvement status (for cities' lists of improvements)
240 * (replaced Impr_Status) */
241
243 int turn; /* turn built, negative for old state */
244#define I_NEVER (-1) /* Improvement never built */
245#define I_DESTROYED (-2) /* Improvement built and destroyed */
246};
247
248/* How much this output type is penalized for unhappy cities: not at all,
249 * surplus knocked down to 0, or all production removed. */
255
257 int index;
258 const char *name; /* Untranslated name */
259 const char *id; /* Identifier string (for rulesets, etc.) */
260 bool harvested; /* Is this output type gathered by city workers? */
262};
263
272
273/* changing this order will break network compatibility,
274 * and clients that don't use the symbols. */
276 FEELING_BASE, /* before any of the modifiers below */
277 FEELING_LUXURY, /* after luxury */
278 FEELING_EFFECT, /* after building effects */
279 FEELING_NATIONALITY, /* after citizen nationality effects */
280 FEELING_MARTIAL, /* after units enforce martial order */
281 FEELING_FINAL, /* after wonders (final result) */
284
285/* Ways city output can be lost. Not currently part of network protocol. */
287 OLOSS_WASTE, /* regular corruption or waste */
288 OLOSS_SIZE, /* notradesize/fulltradesize */
291
292/* This enumerators are used at client side only (so changing it doesn't
293 * break the compatibility) to mark that the city need specific gui updates
294 * (e.g. city dialog, or city report). */
301
307
308struct tile_cache; /* defined and only used within city.c */
309
310struct adv_city; /* defined in ./server/advisors/infracache.h */
311
312struct cm_parameter; /* defined in ./common/aicore/cm.h */
313
314#ifdef FREECIV_WEB
315#pragma pack(push, 1)
316#endif
317struct city {
318 char *name;
319 struct tile *tile; /* May be NULL, should check! */
320 struct player *owner; /* Cannot be NULL. */
321 struct player *original; /* Often NULL in client,
322 * can be NULL on server after player removal */
323 int id;
324 int style;
327
328 /* The people */
331
332 /* Specialists */
334
335 citizens martial_law; /* Citizens pacified by martial law. */
336 citizens unit_happy_upkeep; /* Citizens angered by military action. */
337
338 citizens *nationality; /* Nationality of the citizens. */
339
340 /* Trade routes */
342
343 /* Tile output, regardless of if the tile is actually worked. It is used
344 * as cache for the output of the tiles within the city map.
345 * (see city_tile_cache_update() and city_tile_cache_get_output()) */
347 /* The memory allocated for tile_cache is valid for this squared city
348 * radius. */
350
351 /* The productions */
352 int surplus[O_LAST]; /* Final surplus in each category. */
353 int waste[O_LAST]; /* Waste/corruption in each category. */
354 int unhappy_penalty[O_LAST]; /* Penalty from unhappy cities. */
355 int prod[O_LAST]; /* Production is total minus waste and penalty. */
356 int citizen_base[O_LAST]; /* Base production from citizens. */
357 int usage[O_LAST]; /* Amount of each resource being used. */
358
359 /* Cached values for CPU savings. */
362
363 /* The physics */
366 int pollution; /* not saved */
367 int illness_trade; /* not saved; illness due to trade; it is
368 calculated within the server and send to
369 the clients as the clients do not have all
370 information about the trade cities */
371 int turn_plague; /* last turn with an illness in the city */
372 int city_radius_sq; /* current squared city radius */
373
374 /* turn states */
380
381 int anarchy; /* anarchy rounds count */
382 int rapture; /* rapture rounds count */
385
386 int before_change_shields; /* If changed this turn, shields before penalty */
387 int caravan_shields; /* If caravan has helped city to build wonder. */
388 int disbanded_shields; /* If you disband unit in a city. Count them */
389 int last_turns_shield_surplus; /* The surplus we had last turn. */
390
392
394
395 /* If changed this turn, what we changed from */
397
399
402
403 struct unit_list *units_supported;
404
406
407 int history; /* Cumulative culture */
408
410
411 int steal; /* Diplomats steal once; for spies, gets harder */
412
413 struct {
414 size_t length;
415 /* If true, rally point is active until owner cancels or loses city. */
417 /* Orders should be cleared if an enemy is met. */
421
423
424 union {
425 struct {
426 /* Only used in the server (./ai/ and ./server/). */
427
428 float migration_score; /* updated by city_migration_score. */
429 int mgr_score_calc_turn; /* turn the migration score was calculated */
430
432
433 /* If > 0, workers will not be rearranged until they are unfrozen. */
435
436 /* If set, workers need to be arranged when the city is unfrozen.
437 * Set inside auto_arrange_workers() and city_freeze_workers_queue(). */
439
440 /* If set, city needs to be refreshed at a later time.
441 * Set inside city_refresh() and city_refresh_queue_add(). */
443
444 /* the city map is synced with the client. */
445 bool synced;
446
447 bool debug; /* not saved */
448
449 struct adv_city *adv;
451
452 struct vision *vision;
454
455 struct {
456 /* Only used at the client (the server is omniscient; ./client/). */
458 int walls;
459 bool happy;
464
465 /* The color is an index into the city_colors array in mapview_common */
468
469 /* info for dipl/spy investigation */
470 struct unit_list *info_units_supported;
471 struct unit_list *info_units_present;
472 /* Before popup the city dialog, units go there. In normal process,
473 * these pointers are set to NULL. */
476
477 /* Updates needed for the city. */
479
480 unsigned char first_citizen_index;
482 };
483};
484#ifdef FREECIV_WEB
485#pragma pack(pop)
486#endif
487
495
496extern struct citystyle *city_styles;
498extern struct output_type output_types[];
499
500/* get 'struct city_list' and related functions: */
501#define SPECLIST_TAG city
502#define SPECLIST_TYPE struct city
503#include "speclist.h"
504
505#define city_list_iterate(citylist, pcity) \
506 TYPED_LIST_ITERATE(struct city, citylist, pcity)
507#define city_list_iterate_end LIST_ITERATE_END
508
509#define cities_iterate(pcity) \
510{ \
511 players_iterate(pcity##_player) { \
512 city_list_iterate(pcity##_player->cities, pcity) {
513
514#define cities_iterate_end \
515 } city_list_iterate_end; \
516 } players_iterate_end; \
517}
518
519#define city_list_iterate_safe(citylist, _city) \
520{ \
521 struct city_list *_city##_cl = citylist; \
522 int _city##_size = city_list_size(_city##_cl); \
523 \
524 if (_city##_size > 0) { \
525 int _city##_numbers[_city##_size]; \
526 int _city##_index; \
527 \
528 _city##_size = 0; \
529 city_list_iterate(_city##_cl, _city) { \
530 _city##_numbers[_city##_size++] = _city->id; \
531 } city_list_iterate_end; \
532 \
533 for (_city##_index = 0; \
534 _city##_index < _city##_size; \
535 _city##_index++) { \
536 struct city *_city = \
537 game_city_by_number(_city##_numbers[_city##_index]); \
538 \
539 if (NULL != _city) {
540
541#define city_list_iterate_safe_end \
542 } \
543 } \
544 } \
545}
546
547/* Output type functions */
548
549const char *get_output_identifier(Output_type_id output);
550const char *get_output_name(Output_type_id output);
553void add_specialist_output(const struct city *pcity, int *output);
554void set_city_production(struct city *pcity);
555
556/* Properties */
557
558const char *city_name_get(const struct city *pcity);
559void city_name_set(struct city *pcity, const char *new_name);
560#define city_owner(_pcity_) (_pcity_)->owner
561#define city_tile(_pcity_) (_pcity_)->tile
562
563/**********************************************************************/
566static inline citizens city_size_get(const struct city *pcity)
567{
569
570 return pcity->size;
571}
572
573void city_size_add(struct city *pcity, int add);
574void city_size_set(struct city *pcity, citizens size);
575
576citizens city_specialists(const struct city *pcity);
577
578citizens player_content_citizens(const struct player *pplayer);
579citizens player_angry_citizens(const struct player *pplayer);
580
581int city_population(const struct city *pcity);
582int city_total_impr_gold_upkeep(const struct city *pcity);
583int city_total_unit_gold_upkeep(const struct city *pcity);
584int city_unit_unhappiness(const struct civ_map *nmap,
585 struct unit *punit, int *free_unhappy);
586bool city_happy(const struct city *pcity); /* Generally use celebrating instead */
587bool city_unhappy(const struct city *pcity); /* Anarchy??? */
588bool base_city_celebrating(const struct city *pcity);
589bool city_celebrating(const struct city *pcity); /* Love the king ??? */
590bool city_rapture_grow(const struct city *pcity);
591bool city_is_occupied(const struct city *pcity);
592
593/* City related improvement and unit functions */
594
595int city_improvement_upkeep(const struct city *pcity,
596 const struct impr_type *pimprove);
597
599 const struct impr_type *pimprove);
601 const struct impr_type *pimprove);
602bool can_city_build_improvement_now(const struct city *pcity,
603 const struct impr_type *pimprove);
604
605bool can_city_build_unit_direct(const struct civ_map *nmap,
606 const struct city *pcity,
607 const struct unit_type *punittype);
608bool can_city_build_unit_later(const struct civ_map *nmap,
609 const struct city *pcity,
610 const struct unit_type *punittype);
611bool can_city_build_unit_now(const struct civ_map *nmap,
612 const struct city *pcity,
613 const struct unit_type *punittype);
614
615bool can_city_build_direct(const struct civ_map *nmap,
616 const struct city *pcity,
617 const struct universal *target);
618bool can_city_build_later(const struct civ_map *nmap,
619 const struct city *pcity,
620 const struct universal *target);
621bool can_city_build_now(const struct civ_map *nmap,
622 const struct city *pcity,
623 const struct universal *target);
624
625int city_unit_slots_available(const struct city *pcity);
626bool city_can_use_specialist(const struct city *pcity,
628bool city_has_building(const struct city *pcity,
629 const struct impr_type *pimprove);
630bool is_capital(const struct city *pcity);
631bool is_gov_center(const struct city *pcity);
632bool city_got_defense_effect(const struct city *pcity,
633 const struct unit_type *attacker);
634
636bool city_production_build_units(const struct city *pcity,
637 bool add_production, int *num_units);
639 const struct unit_type *punittype);
640
641bool city_production_is_genus(const struct city *pcity,
642 enum impr_genus_id genus);
643bool city_production_has_flag(const struct city *pcity,
644 enum impr_flag_id flag);
647
648bool city_production_gets_caravan_shields(const struct universal *tgt);
649
651 const struct universal *target);
652int city_turns_to_build(const struct city *pcity,
653 const struct universal *target,
655int city_turns_to_grow(const struct city *pcity);
656bool city_can_grow_to(const struct city *pcity, int pop_size);
657bool city_can_change_build(const struct city *pcity);
658
659void city_choose_build_default(const struct civ_map *nmap, struct city *pcity);
660
661/* Textual representation of buildings */
662
663const char *city_improvement_name_translation(const struct city *pcity,
664 const struct impr_type *pimprove);
665const char *city_production_name_translation(const struct city *pcity);
666
667/* City map functions */
668bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
669 const int city_map_y);
670bool city_map_includes_tile(const struct city *const pcity,
671 const struct tile *map_tile);
673 const struct city *const pcity,
674 const struct tile *map_tile);
676 const int city_radius_sq,
677 const struct tile *city_center,
678 const struct tile *map_tile);
679
680struct tile *city_map_to_tile(const struct civ_map *nmap,
681 const struct tile *city_center,
682 int city_radius_sq, int city_map_x,
683 int city_map_y);
684
685/* Initialization functions */
686int compare_iter_index(const void *a, const void *b);
688void free_city_map_index(void);
690
691/* Output on spot */
692int city_tile_output(const struct city *pcity, const struct tile *ptile,
694int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
696
698 const struct city *pcity,
699 const struct tile *ptile);
700bool city_can_work_tile(const struct city *pcity, const struct tile *ptile);
701
703 const struct tile *ptile);
704
705bool city_can_be_built_here(const struct civ_map *nmap,
706 const struct tile *ptile,
707 const struct unit *punit,
708 bool hut_test);
709bool city_can_be_built_tile_only(const struct civ_map *nmap,
710 const struct tile *ptile);
711
712/* List functions */
713struct city *city_list_find_number(struct city_list *This, int id);
714struct city *city_list_find_name(struct city_list *This, const char *name);
715
716int city_name_compare(const void *p1, const void *p2);
717
718/* City style functions */
719const char *city_style_rule_name(const int style);
720const char *city_style_name_translation(const int style);
721
722int city_style_by_rule_name(const char *s);
723int city_style_by_translated_name(const char *s);
724
725struct city *tile_enemy_city(const struct tile *ptile,
726 const struct player *pplayer);
727
728/**********************************************************************/
731static inline bool is_enemy_city_tile(const struct tile *ptile,
732 const struct player *pplayer)
733{
734 return NULL != tile_enemy_city(ptile, pplayer);
735}
736
737struct city *tile_allied_city(const struct tile *ptile,
738 const struct player *pplayer);
739
740/**********************************************************************/
743static inline bool is_allied_city_tile(const struct tile *ptile,
744 const struct player *pplayer)
745{
746 return NULL != tile_allied_city(ptile, pplayer);
747}
748
749struct city *tile_non_attack_city(const struct tile *ptile,
750 const struct player *pplayer);
751
752/**********************************************************************/
755static inline bool is_non_attack_city_tile(const struct tile *ptile,
756 const struct player *pplayer)
757{
758 return NULL != tile_non_attack_city(ptile, pplayer);
759}
760
761struct city *tile_non_allied_city(const struct tile *ptile,
762 const struct player *pplayer);
763
764/**********************************************************************/
767static inline bool is_non_allied_city_tile(const struct tile *ptile,
768 const struct player *pplayer)
769{
770 return NULL != tile_non_allied_city(ptile, pplayer);
771}
772
773bool is_unit_near_a_friendly_city(const struct civ_map *nmap,
774 const struct unit *punit,
775 int distance);
776bool is_friendly_city_near(const struct civ_map *nmap,
777 const struct player *owner,
778 const struct tile *ptile,
779 int distance);
781 const struct tile *ptile,
782 bool may_be_on_center);
783
784/* Granary size as a function of city size */
785int city_granary_size(int city_size);
786
787void city_add_improvement(struct city *pcity,
788 const struct impr_type *pimprove);
790 const struct impr_type *pimprove);
791
792/* City update functions */
793void city_refresh_from_main_map(const struct civ_map *nmap,
794 struct city *pcity, bool *workers_map);
795
796int city_waste(const struct city *pcity, Output_type_id otype, int total,
797 int *breakdown);
799 const struct city *pcity);
801bool city_built_last_turn(const struct city *pcity);
802
803/* City creation / destruction */
804struct city *create_city_virtual(struct player *pplayer,
805 struct tile *ptile, const char *name);
806void destroy_city_virtual(struct city *pcity);
807bool city_is_virtual(const struct city *pcity);
808
809/* Misc */
810bool is_city_option_set(const struct city *pcity, enum city_options option);
811void city_styles_alloc(int num);
812void city_styles_free(void);
813
814void add_tax_income(const struct player *pplayer, int trade, int *output);
815int get_city_tithes_bonus(const struct city *pcity);
816int city_pollution_types(const struct city *pcity, int shield_total,
817 int *pollu_prod, int *pollu_pop, int *pollu_mod);
818int city_pollution(const struct city *pcity, int shield_total);
819int city_illness_calc(const struct city *pcity, int *ill_base,
820 int *ill_size, int *ill_trade, int *ill_pollution);
821bool city_had_recent_plague(const struct city *pcity);
822int city_build_slots(const struct city *pcity);
823int city_airlift_max(const struct city *pcity);
824
825bool city_exist(int id);
826
827/*
828 * Iterates over all improvements, skipping those not yet built in the
829 * given city.
830 */
831#define city_built_iterate(_pcity, _p) \
832 improvement_iterate(_p) { \
833 if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
834 continue; \
835 }
836
837#define city_built_iterate_end \
838 } improvement_iterate_end;
839
840
841/* Iterates over all output types in the game. */
842#define output_type_iterate(output) \
843{ \
844 Output_type_id output; \
845 \
846 for (output = 0; output < O_LAST; output++) {
847
848#define output_type_iterate_end \
849 } \
850}
851
852
853/* === */
854
855/**********************************************************************/
865static inline bool is_city_center(const struct city *pcity,
866 const struct tile *ptile)
867{
868 if (!pcity || !pcity->tile || !ptile) {
869 return FALSE;
870 }
871
872 return tile_index(city_tile(pcity)) == tile_index(ptile);
873}
874
875bool is_free_worked(const struct city *pcity, const struct tile *ptile);
876
877#define is_free_worked_index(city_tile_index) \
878 (CITY_MAP_CENTER_TILE_INDEX == city_tile_index)
879#define FREE_WORKED_TILES (1)
880
881void *city_ai_data(const struct city *pcity, const struct ai_type *ai);
882void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
883 void *data);
884
885void city_rally_point_clear(struct city *pcity);
886void city_rally_point_receive(const struct packet_city_rally_point *packet,
887 struct city *pcity)
888 fc__attribute((nonnull (1)));
889
890#ifdef __cplusplus
891}
892#endif /* __cplusplus */
893
894#endif /* FC__CITY_H */
bool base_city_celebrating(const struct city *pcity)
Definition city.c:1637
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:767
bool city_is_virtual(const struct city *pcity)
Definition city.c:3614
city_needs_arrange
Definition city.h:302
@ CNA_BROADCAST_PENDING
Definition city.h:305
@ CNA_NOT
Definition city.h:303
@ CNA_NORMAL
Definition city.h:304
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:1965
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:663
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3626
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:755
#define city_tile(_pcity_)
Definition city.h:561
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1860
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:148
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:737
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1145
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:731
int city_granary_size(int city_size)
Definition city.c:2132
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2196
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2787
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3642
output_unhappy_penalty
Definition city.h:250
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:253
@ UNHAPPY_PENALTY_NONE
Definition city.h:251
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:252
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2092
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2279
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1087
static citizens city_size_get(const struct city *pcity)
Definition city.h:566
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3253
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2932
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:305
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1240
const char * city_style_name_translation(const int style)
Definition city.c:1756
citizen_category
Definition city.h:264
@ CITIZEN_LAST
Definition city.h:269
@ CITIZEN_SPECIALIST
Definition city.h:270
@ CITIZEN_ANGRY
Definition city.h:268
@ CITIZEN_HAPPY
Definition city.h:265
@ CITIZEN_CONTENT
Definition city.h:266
@ CITIZEN_UNHAPPY
Definition city.h:267
void city_styles_free(void)
Definition city.c:3436
void city_rally_point_receive(const struct packet_city_rally_point *packet, struct city *pcity) fc__attribute((nonnull(1)))
Definition city.c:3666
city_updates
Definition city.h:295
@ CU_POPUP_DIALOG
Definition city.h:299
@ CU_UPDATE_REPORT
Definition city.h:297
@ CU_UPDATE_DIALOG
Definition city.h:298
@ CU_NO_UPDATE
Definition city.h:296
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:647
bool is_capital(const struct city *pcity)
Definition city.c:1579
struct citystyle * city_styles
Definition city.c:84
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1255
void city_styles_alloc(int num)
Definition city.c:3421
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1401
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1049
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:743
void city_production_caravan_shields_init(void)
Definition city.c:1778
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3396
int city_airlift_max(const struct city *pcity)
Definition city.c:2942
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1465
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1031
struct output_type * get_output_type(Output_type_id output)
Definition city.c:638
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3413
int city_population(const struct city *pcity)
Definition city.c:1191
const char * city_style_rule_name(const int style)
Definition city.c:1765
void city_size_add(struct city *pcity, int add)
Definition city.c:1164
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1065
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:727
bool city_is_occupied(const struct city *pcity)
Definition city.c:1665
void free_city_map_index(void)
Definition city.c:609
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:804
void add_tax_income(const struct player *pplayer, int trade, int *output)
Definition city.c:2245
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:854
bool city_tile_index_to_xy(int *city_map_x, int *city_map_y, int city_tile_index, int city_radius_sq)
Definition city.c:101
struct city * tile_non_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2066
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3049
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1596
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2186
bool city_map_includes_tile(const struct city *const pcity, const struct tile *map_tile)
Definition city.c:293
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2227
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2081
void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
Definition city.c:411
bool city_rapture_grow(const struct city *pcity)
Definition city.c:1653
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:865
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:820
bool city_unhappy(const struct city *pcity)
Definition city.c:1626
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3359
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3455
void set_city_production(struct city *pcity)
Definition city.c:2953
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1679
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2212
bool city_celebrating(const struct city *pcity)
Definition city.c:1645
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1560
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:830
const char * get_output_identifier(Output_type_id output)
Definition city.c:619
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2870
const char * get_output_name(Output_type_id output)
Definition city.c:629
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2012
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1886
bool is_valid_city_coords(const int city_radius_sq, const int city_map_x, const int city_map_y)
Definition city.c:188
void city_refresh_from_main_map(const struct civ_map *nmap, struct city *pcity, bool *workers_map)
Definition city.c:3201
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:994
citizen_feeling
Definition city.h:275
@ FEELING_EFFECT
Definition city.h:278
@ FEELING_LUXURY
Definition city.h:277
@ FEELING_FINAL
Definition city.h:281
@ FEELING_LAST
Definition city.h:282
@ FEELING_BASE
Definition city.h:276
@ FEELING_NATIONALITY
Definition city.h:279
@ FEELING_MARTIAL
Definition city.h:280
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1487
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2821
bool city_happy(const struct city *pcity)
Definition city.c:1614
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1180
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3382
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1384
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
struct city * tile_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2036
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2021
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:446
bool city_base_to_city_map(int *city_map_x, int *city_map_y, const struct city *const pcity, const struct tile *map_tile)
Definition city.c:281
output_loss
Definition city.h:286
@ OLOSS_SIZE
Definition city.h:288
@ OLOSS_WASTE
Definition city.h:287
@ OLOSS_LAST
Definition city.h:289
void destroy_city_virtual(struct city *pcity)
Definition city.c:3541
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:3342
const Output_type_id num_output_types
int city_style_by_translated_name(const char *s)
Definition city.c:1721
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2364
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3634
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1695
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1283
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:123
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:903
bool is_gov_center(const struct city *pcity)
Definition city.c:1587
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1013
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:947
int city_map_tiles(int city_radius_sq)
Definition city.c:171
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2051
bool city_exist(int id)
Definition city.c:3597
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:717
int compare_iter_index(const void *a, const void *b)
Definition city.c:343
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:747
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1996
void city_rally_point_clear(struct city *pcity)
Definition city.c:3651
struct output_type output_types[]
Definition city.c:88
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:871
bool city_exists_within_max_city_map(const struct civ_map *nmap, const struct tile *ptile, bool may_be_on_center)
Definition city.c:2112
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2923
bool city_can_change_build(const struct city *pcity)
Definition city.c:1079
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:970
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1222
int city_style_by_rule_name(const char *s)
Definition city.c:1738
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1711
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1201
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:700
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
unsigned char citizens
Definition fc_types.h:247
#define SP_MAX
Definition fc_types.h:267
int Specialist_type_id
Definition fc_types.h:234
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_LAST
Definition fc_types.h:101
enum output_type_id Output_type_id
Definition fc_types.h:237
struct city * owner
Definition citydlg.c:226
GType type
Definition repodlgs.c:1313
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_ret_val(condition, val)
Definition log.h:195
log_level
Definition log.h:29
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
size_t size
Definition specvec.h:72
Definition ai.h:50
int turn
Definition city.h:243
Definition city.h:317
struct worker_task_list * task_reqs
Definition city.h:409
struct tile_cache * tile_cache
Definition city.h:346
int color_index
Definition city.h:467
int turn_last_built
Definition city.h:384
int surplus[O_LAST]
Definition city.h:352
enum city_wl_cancel_behavior wlcb
Definition city.h:401
int food_stock
Definition city.h:364
struct built_status built[B_LAST]
Definition city.h:391
struct player * original
Definition city.h:321
int history
Definition city.h:407
int * counter_values
Definition city.h:405
int pollution
Definition city.h:366
bool did_sell
Definition city.h:377
int id
Definition city.h:323
int last_turns_shield_surplus
Definition city.h:389
enum capital_type capital
Definition city.h:325
int disbanded_shields
Definition city.h:388
int waste[O_LAST]
Definition city.h:353
int workers_frozen
Definition city.h:434
int turn_plague
Definition city.h:371
struct unit_list * info_units_present
Definition city.h:471
bv_city_options city_options
Definition city.h:400
citizens unit_happy_upkeep
Definition city.h:336
int city_radius_sq
Definition city.h:372
bool was_happy
Definition city.h:378
struct player * owner
Definition city.h:320
enum city_acquire_type acquire_t
Definition city.h:326
int turn_founded
Definition city.h:383
int airlift
Definition city.h:375
int citizen_base[O_LAST]
Definition city.h:356
int caravan_shields
Definition city.h:387
bool did_buy
Definition city.h:376
struct unit_list * info_units_supported
Definition city.h:470
char * name
Definition city.h:318
void * ais[FREECIV_AI_MOD_LAST]
Definition city.h:450
struct trade_route_list * routes
Definition city.h:341
int anarchy
Definition city.h:381
enum city_needs_arrange needs_arrange
Definition city.h:438
bool occupied
Definition city.h:457
int usage[O_LAST]
Definition city.h:357
int tile_cache_radius_sq
Definition city.h:349
int abs_bonus[O_LAST]
Definition city.h:361
struct universal production
Definition city.h:393
struct unit_order * orders
Definition city.h:419
int walls
Definition city.h:458
bool happy
Definition city.h:459
struct unit_list * collecting_info_units_supported
Definition city.h:474
struct city::@18::@20 server
int bonus[O_LAST]
Definition city.h:360
struct adv_city * adv
Definition city.h:449
citizens * nationality
Definition city.h:338
bool vigilant
Definition city.h:418
int steal
Definition city.h:411
int unhappy_penalty[O_LAST]
Definition city.h:354
citizens size
Definition city.h:329
unsigned char first_citizen_index
Definition city.h:480
int illness
Definition city.h:431
int before_change_shields
Definition city.h:386
int culture
Definition city.h:462
struct city::@17 rally_point
int style
Definition city.h:324
bool had_famine
Definition city.h:379
size_t length
Definition city.h:414
bool synced
Definition city.h:445
float migration_score
Definition city.h:428
bool needs_refresh
Definition city.h:442
struct unit_list * collecting_info_units_present
Definition city.h:475
int buy_cost
Definition city.h:463
struct city::@18::@21 client
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:330
citizens specialists[SP_MAX]
Definition city.h:333
struct tile * tile
Definition city.h:319
int shield_stock
Definition city.h:365
int prod[O_LAST]
Definition city.h:355
struct vision * vision
Definition city.h:452
struct cm_parameter * cm_parameter
Definition city.h:422
int city_image
Definition city.h:461
bool debug
Definition city.h:447
struct universal changed_from
Definition city.h:396
bool colored
Definition city.h:466
bool unhappy
Definition city.h:460
struct unit_list * units_supported
Definition city.h:403
int mgr_score_calc_turn
Definition city.h:429
int illness_trade
Definition city.h:367
enum city_updates need_updates
Definition city.h:478
bool persistent
Definition city.h:416
int rapture
Definition city.h:382
citizens martial_law
Definition city.h:335
struct requirement_vector reqs
Definition city.h:493
char citizens_graphic[MAX_LEN_NAME]
Definition city.h:492
char graphic_alt[MAX_LEN_NAME]
Definition city.h:491
struct name_translation name
Definition city.h:489
char graphic[MAX_LEN_NAME]
Definition city.h:490
int dist
Definition city.h:107
int dx
Definition city.h:107
int dy
Definition city.h:107
const char * id
Definition city.h:259
enum output_unhappy_penalty unhappy_penalty
Definition city.h:261
int index
Definition city.h:257
bool harvested
Definition city.h:260
const char * name
Definition city.h:258
Definition tile.h:50
Definition unit.h:140
struct tile * tile
Definition unit.h:142
#define fc__attribute(x)
Definition support.h:99
#define FALSE
Definition support.h:47
#define tile_index(_pt_)
Definition tile.h:89