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