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 (_tile != nullptr) {
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 (_tile != nullptr) {
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 (_tile != nullptr) {
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 nullptr, should check! */
321 struct player *owner; /* Cannot be nullptr. */
322 struct player *original; /* Often nullptr in client,
323 * can be nullptr 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 nullptr. */
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 (_city != nullptr) {
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);
562const char *city_name_getx(const struct city *pcity);
563void city_name_set(struct city *pcity, const char *new_name);
564#define city_owner(_pcity_) (_pcity_)->owner
565#define city_tile(_pcity_) (_pcity_)->tile
566
567/**********************************************************************/
570static inline citizens city_size_get(const struct city *pcity)
571{
572 fc_assert_ret_val(pcity != nullptr, 0);
573
574 return pcity->size;
575}
576
577void city_size_add(struct city *pcity, int add);
578void city_size_set(struct city *pcity, citizens size);
579
580citizens city_specialists(const struct city *pcity);
581int city_superspecialists(const struct city *pcity);
582
583citizens player_content_citizens(const struct player *pplayer);
584citizens player_angry_citizens(const struct player *pplayer);
585
586int city_population(const struct city *pcity);
587int city_total_impr_gold_upkeep(const struct city *pcity);
588int city_total_unit_gold_upkeep(const struct city *pcity);
589int city_unit_unhappiness(const struct civ_map *nmap,
590 struct unit *punit, int *free_unhappy);
591bool city_happy(const struct city *pcity); /* Generally use celebrating instead */
592bool city_unhappy(const struct city *pcity); /* Anarchy??? */
593bool base_city_celebrating(const struct city *pcity);
594bool city_celebrating(const struct city *pcity); /* Love the king ??? */
595bool city_rapture_grow(const struct city *pcity);
596bool city_is_occupied(const struct city *pcity);
597
598/* City related improvement and unit functions */
599
600int city_improvement_upkeep(const struct city *pcity,
601 const struct impr_type *pimprove);
602
604 const struct impr_type *pimprove,
605 const enum req_problem_type prob_type);
607 const struct impr_type *pimprove);
608bool can_city_build_improvement_now(const struct city *pcity,
609 const struct impr_type *pimprove,
610 const enum req_problem_type prob_type);
611
612bool can_city_build_unit_direct(const struct civ_map *nmap,
613 const struct city *pcity,
614 const struct unit_type *punittype,
615 const enum req_problem_type prob_type);
616bool can_city_build_unit_later(const struct civ_map *nmap,
617 const struct city *pcity,
618 const struct unit_type *punittype);
619bool can_city_build_unit_now(const struct civ_map *nmap,
620 const struct city *pcity,
621 const struct unit_type *punittype,
622 const enum req_problem_type prob_type);
623
624bool can_city_build_direct(const struct civ_map *nmap,
625 const struct city *pcity,
626 const struct universal *target);
627bool can_city_build_later(const struct civ_map *nmap,
628 const struct city *pcity,
629 const struct universal *target);
630bool can_city_build_now(const struct civ_map *nmap,
631 const struct city *pcity,
632 const struct universal *target);
633
634int city_unit_slots_available(const struct city *pcity);
635bool city_can_use_specialist(const struct city *pcity,
637bool city_has_building(const struct city *pcity,
638 const struct impr_type *pimprove);
639bool is_capital(const struct city *pcity);
640bool is_gov_center(const struct city *pcity);
641bool city_got_defense_effect(const struct city *pcity,
642 const struct unit_type *attacker);
643
645bool city_production_build_units(const struct city *pcity,
646 bool add_production, int *num_units);
648 const struct unit_type *punittype);
649
650bool city_production_is_genus(const struct city *pcity,
651 enum impr_genus_id genus);
652bool city_production_has_flag(const struct city *pcity,
653 enum impr_flag_id flag);
656
657bool city_production_gets_caravan_shields(const struct universal *tgt);
658
660 const struct universal *target);
661int city_turns_to_build(const struct city *pcity,
662 const struct universal *target,
664int city_turns_to_grow(const struct city *pcity);
665bool city_can_grow_to(const struct city *pcity, int pop_size);
666bool city_can_change_build(const struct city *pcity);
667
668void city_choose_build_default(const struct civ_map *nmap, struct city *pcity);
669
670/* Textual representation of buildings */
671
672const char *city_improvement_name_translation(const struct city *pcity,
673 const struct impr_type *pimprove);
674const char *city_production_name_translation(const struct city *pcity);
675
676/* City map functions */
677bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
678 const int city_map_y);
679bool city_map_includes_tile(const struct city *const pcity,
680 const struct tile *map_tile);
682 const struct city *const pcity,
683 const struct tile *map_tile);
685 const int city_radius_sq,
686 const struct tile *city_center,
687 const struct tile *map_tile);
688
689struct tile *city_map_to_tile(const struct civ_map *nmap,
690 const struct tile *city_center,
691 int city_radius_sq, int city_map_x,
692 int city_map_y);
693
694/* Initialization functions */
695int compare_iter_index(const void *a, const void *b);
697void free_city_map_index(void);
699
700/* Output on spot */
701int city_tile_output(const struct city *pcity, const struct tile *ptile,
703int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
705
707 const struct city *pcity,
708 const struct tile *ptile);
709bool city_can_work_tile(const struct city *pcity, const struct tile *ptile);
710
712 const struct tile *ptile);
713
714bool city_can_be_built_here(const struct civ_map *nmap,
715 const struct tile *ptile,
716 const struct unit *punit,
717 bool hut_test);
718bool city_can_be_built_tile_only(const struct civ_map *nmap,
719 const struct tile *ptile);
720
721/* List functions */
722struct city *city_list_find_number(struct city_list *This, int id);
723struct city *city_list_find_name(struct city_list *This, const char *name);
724
725int city_name_compare(const void *p1, const void *p2);
726
727/* City style functions */
728const char *city_style_rule_name(const int style);
729const char *city_style_name_translation(const int style);
730
731int city_style_by_rule_name(const char *s);
732int city_style_by_translated_name(const char *s);
733
734struct city *tile_enemy_city(const struct tile *ptile,
735 const struct player *pplayer);
736
737/**********************************************************************/
740static inline bool is_enemy_city_tile(const struct tile *ptile,
741 const struct player *pplayer)
742{
743 return tile_enemy_city(ptile, pplayer) != nullptr;
744}
745
746struct city *tile_allied_city(const struct tile *ptile,
747 const struct player *pplayer);
748
749/**********************************************************************/
752static inline bool is_allied_city_tile(const struct tile *ptile,
753 const struct player *pplayer)
754{
755 return tile_allied_city(ptile, pplayer) != nullptr;
756}
757
758struct city *tile_non_attack_city(const struct tile *ptile,
759 const struct player *pplayer);
760
761/**********************************************************************/
764static inline bool is_non_attack_city_tile(const struct tile *ptile,
765 const struct player *pplayer)
766{
767 return tile_non_attack_city(ptile, pplayer) != nullptr;
768}
769
770struct city *tile_non_allied_city(const struct tile *ptile,
771 const struct player *pplayer);
772
773/**********************************************************************/
776static inline bool is_non_allied_city_tile(const struct tile *ptile,
777 const struct player *pplayer)
778{
779 return tile_non_allied_city(ptile, pplayer) != nullptr;
780}
781
782bool is_unit_near_a_friendly_city(const struct civ_map *nmap,
783 const struct unit *punit,
784 int distance);
785bool is_friendly_city_near(const struct civ_map *nmap,
786 const struct player *owner,
787 const struct tile *ptile,
788 int distance);
790 const struct tile *ptile,
791 bool may_be_on_center);
792
793/* Granary size as a function of city size */
794int city_granary_size(int city_size);
795
796void city_add_improvement(struct city *pcity,
797 const struct impr_type *pimprove);
799 const struct impr_type *pimprove);
800
801/* City update functions */
802void city_refresh_from_main_map(const struct civ_map *nmap,
803 struct city *pcity, bool *workers_map);
804
805int city_waste(const struct city *pcity, Output_type_id otype, int total,
806 int *breakdown);
808 const struct city *pcity);
810bool city_built_last_turn(const struct city *pcity);
811
812/* City creation / destruction */
813struct city *create_city_virtual(struct player *pplayer,
814 struct tile *ptile, const char *name);
815void destroy_city_virtual(struct city *pcity);
816bool city_is_virtual(const struct city *pcity);
817
818/* Misc */
819bool is_city_option_set(const struct city *pcity, enum city_options option);
820void city_styles_alloc(int num);
821void city_styles_free(void);
822
823void add_tax_income(const struct player *pplayer, int trade, int *output);
824int get_city_tithes_bonus(const struct city *pcity);
825int city_pollution_types(const struct city *pcity, int shield_total,
826 int *pollu_prod, int *pollu_pop, int *pollu_mod);
827int city_pollution(const struct city *pcity, int shield_total);
828int city_illness_calc(const struct city *pcity, int *ill_base,
829 int *ill_size, int *ill_trade, int *ill_pollution);
830bool city_had_recent_plague(const struct city *pcity);
831int city_build_slots(const struct city *pcity);
832int city_airlift_max(const struct city *pcity);
833
834bool city_exist(int id);
835
836/*
837 * Iterates over all improvements, skipping those not yet built in the
838 * given city.
839 */
840#define city_built_iterate(_pcity, _p) \
841 improvement_iterate(_p) { \
842 if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
843 continue; \
844 }
845
846#define city_built_iterate_end \
847 } improvement_iterate_end;
848
849
850/* Iterates over all output types in the game. */
851#define output_type_iterate(output) \
852{ \
853 Output_type_id output; \
854 \
855 for (output = 0; output < O_LAST; output++) {
856
857#define output_type_iterate_end \
858 } \
859}
860
861
862/* === */
863
864/**********************************************************************/
874static inline bool is_city_center(const struct city *pcity,
875 const struct tile *ptile)
876{
877 if (!pcity || !pcity->tile || !ptile) {
878 return FALSE;
879 }
880
881 return tile_index(city_tile(pcity)) == tile_index(ptile);
882}
883
884bool is_free_worked(const struct city *pcity, const struct tile *ptile);
885
886#define is_free_worked_index(city_tile_index) \
887 (CITY_MAP_CENTER_TILE_INDEX == city_tile_index)
888#define FREE_WORKED_TILES (1)
889
890void *city_ai_data(const struct city *pcity, const struct ai_type *ai);
891void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
892 void *data);
893
894void city_rally_point_clear(struct city *pcity);
895void city_rally_point_receive(const struct packet_city_rally_point *packet,
896 struct city *pcity)
897 fc__attribute((nonnull (1)));
898
899#ifdef __cplusplus
900}
901#endif /* __cplusplus */
902
903#endif /* FC__CITY_H */
bool base_city_celebrating(const struct city *pcity)
Definition city.c:1692
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:776
bool city_is_virtual(const struct city *pcity)
Definition city.c:3687
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:2020
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:666
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:834
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3699
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:764
#define city_tile(_pcity_)
Definition city.h:565
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1915
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:148
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:740
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1199
const char * city_name_getx(const struct city *pcity)
Definition city.c:1164
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:740
int city_granary_size(int city_size)
Definition city.c:2187
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2251
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2842
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3715
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:2147
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2334
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1103
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3309
void generate_city_map_indices(void)
Definition city.c:527
int city_build_slots(const struct city *pcity)
Definition city.c:2988
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:1294
const char * city_style_name_translation(const int style)
Definition city.c:1811
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:3507
void city_rally_point_receive(const struct packet_city_rally_point *packet, struct city *pcity) fc__attribute((nonnull(1)))
Definition city.c:3739
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:650
int city_superspecialists(const struct city *pcity)
Definition city.c:3414
bool is_capital(const struct city *pcity)
Definition city.c:1634
struct citystyle * city_styles
Definition city.c:84
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1310
void city_styles_alloc(int num)
Definition city.c:3492
const char * city_name_get(const struct city *pcity)
Definition city.c:1155
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1065
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:752
void city_production_caravan_shields_init(void)
Definition city.c:1833
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3467
int city_airlift_max(const struct city *pcity)
Definition city.c:2998
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1520
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1047
struct output_type * get_output_type(Output_type_id output)
Definition city.c:640
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3484
int city_population(const struct city *pcity)
Definition city.c:1245
const char * city_style_rule_name(const int style)
Definition city.c:1820
void city_size_add(struct city *pcity, int add)
Definition city.c:1218
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1081
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:730
bool city_is_occupied(const struct city *pcity)
Definition city.c:1720
void free_city_map_index(void)
Definition city.c:609
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:808
void add_tax_income(const struct player *pplayer, int trade, int *output)
Definition city.c:2300
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:2121
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3105
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1651
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2241
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:2282
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit, int distance)
Definition city.c:2136
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:1708
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:874
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:824
bool city_unhappy(const struct city *pcity)
Definition city.c:1681
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3430
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3526
void set_city_production(struct city *pcity)
Definition city.c:3009
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition city.c:860
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1734
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2267
bool city_celebrating(const struct city *pcity)
Definition city.c:1700
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1615
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:2926
const char * get_output_name(Output_type_id output)
Definition city.c:630
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2067
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1941
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:3257
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1006
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 can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:911
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1542
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2876
bool city_happy(const struct city *pcity)
Definition city.c:1669
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1234
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3453
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1439
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:2091
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2076
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:3614
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:3399
const Output_type_id num_output_types
int city_style_by_translated_name(const char *s)
Definition city.c:1776
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2419
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype, const enum req_problem_type prob_type)
Definition city.c:957
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3707
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1750
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1338
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:123
bool is_gov_center(const struct city *pcity)
Definition city.c:1642
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1027
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:2106
bool city_exist(int id)
Definition city.c:3670
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1511
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:720
int compare_iter_index(const void *a, const void *b)
Definition city.c:343
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:750
int city_turns_to_grow(const struct city *pcity)
Definition city.c:2051
void city_rally_point_clear(struct city *pcity)
Definition city.c:3724
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:879
bool city_exists_within_max_city_map(const struct civ_map *nmap, const struct tile *ptile, bool may_be_on_center)
Definition city.c:2167
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2979
bool city_can_change_build(const struct city *pcity)
Definition city.c:1095
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:982
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1276
int city_style_by_rule_name(const char *s)
Definition city.c:1793
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1766
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1255
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:703
char * incite_cost
Definition comments.c:77
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * 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:249
req_problem_type
Definition fc_types.h:514
#define SP_MAX
Definition fc_types.h:269
int Specialist_type_id
Definition fc_types.h:236
#define MAX_LEN_NAME
Definition fc_types.h:68
@ O_LAST
Definition fc_types.h:103
enum output_type_id Output_type_id
Definition fc_types.h:239
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