Freeciv-3.2
Loading...
Searching...
No Matches
city.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__CITY_H
14#define FC__CITY_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "bitvector.h"
22#include "log.h"
23
24/* common */
25#include "fc_types.h"
26#include "name_translation.h"
27#include "tile.h"
28#include "traderoutes.h"
29#include "workertask.h"
30#include "worklist.h"
31
32struct impr_type;
33struct unit;
34struct unit_list;
35struct vision;
37
44
45/* Various city options. These are stored by the server and can be
46 * toggled by the user. Each one defaults to off. Adding new ones
47 * will break network compatibility. If you want to reorder or remove
48 * an option remember to load the city option order from the savegame.
49 * It is stored in savefile.city_options_vector
50 *
51 * Used in the network protocol.
52 */
53#define SPECENUM_NAME city_options
54/* If unit production (e.g. settler) is allowed to disband a small city */
55#define SPECENUM_VALUE0 CITYO_DISBAND
56#define SPECENUM_VALUE0NAME "Disband"
57/* If new citizens are science specialists */
58#define SPECENUM_VALUE1 CITYO_SCIENCE_SPECIALISTS
59#define SPECENUM_VALUE1NAME "Sci_Specialists"
60/* If new citizens are gold specialists */
61#define SPECENUM_VALUE2 CITYO_GOLD_SPECIALISTS
62#define SPECENUM_VALUE2NAME "Tax_Specialists"
63#define SPECENUM_COUNT CITYO_LAST
64#define SPECENUM_BITVECTOR bv_city_options
65#include "specenum_gen.h"
66
67/* Used in savegames, and there's currently no order of the values
68 * stored in the savegame. Implement that before touching the values. */
69#define SPECENUM_NAME city_wl_cancel_behavior
70#define SPECENUM_VALUE0 WLCB_SMART
71 /* TRANS: Worklist Cancelling behavior
72 * (when something cannot be built right away) */
73#define SPECENUM_VALUE0NAME N_("?wlcb:Smart")
74#define SPECENUM_VALUE1 WLCB_ALWAYS_PURGE
75#define SPECENUM_VALUE1NAME N_("?wlcb:Always Purge")
76#define SPECENUM_VALUE2 WLCB_ALWAYS_POSTPONE
77#define SPECENUM_VALUE2NAME N_("?wlcb:Always Postpone")
78#define SPECENUM_COUNT WLCB_LAST
79#include "specenum_gen.h"
80
81/* The city includes all tiles dx^2 + dy^2 <= CITY_MAP_*_RADIUS_SQ */
82#define CITY_MAP_DEFAULT_RADIUS_SQ \
83 (CITY_MAP_DEFAULT_RADIUS * CITY_MAP_DEFAULT_RADIUS + 1)
84#define CITY_MAP_MIN_RADIUS_SQ \
85 (CITY_MAP_MIN_RADIUS * CITY_MAP_MIN_RADIUS + 1)
86#define CITY_MAP_MAX_RADIUS_SQ \
87 (CITY_MAP_MAX_RADIUS * CITY_MAP_MAX_RADIUS + 1)
88/* The id for the city center */
89#define CITY_MAP_CENTER_RADIUS_SQ -1
90/* The tile index of the city center */
91#define CITY_MAP_CENTER_TILE_INDEX 0
92
93/* Maximum diameter of the workable city area. */
94#define CITY_MAP_MAX_SIZE (CITY_MAP_MAX_RADIUS * 2 + 1)
95
96#define INCITE_IMPOSSIBLE_COST (1000 * 1000 * 1000)
97
98/*
99 * Size of the biggest possible city.
100 *
101 * The constant may be changed since it isn't externally visible.
102 *
103 * The city size is saved as unsigned char. Therefore, MAX_CITY_SIZE should
104 * be below 255!
105 */
106#define MAX_CITY_SIZE 0xFF
107
108/* Iterate a city map, from the center (the city) outwards */
110 int dx, dy, dist;
111};
112
113/* City map coordinates are positive integers shifted by the maximum
114 * radius the game engine allows (not the current ruleset) */
115#define CITY_REL2ABS(_coor) (_coor + CITY_MAP_MAX_RADIUS)
116#define CITY_ABS2REL(_coor) (_coor - CITY_MAP_MAX_RADIUS)
117
119 int city_tile_index, int city_radius_sq);
121 int city_radius_sq);
122
123int rs_max_city_radius_sq(void);
124int city_map_radius_sq_get(const struct city *pcity);
125void city_map_radius_sq_set(struct city *pcity, int radius_sq);
126int city_map_tiles(int city_radius_sq);
127#define city_map_tiles_from_city(_pcity) \
128 city_map_tiles(city_map_radius_sq_get(_pcity))
129
130void citylog_map_data(enum log_level level, int radius_sq, int *map_data);
131void citylog_map_workers(enum log_level level, struct city *pcity);
132
133/* Iterate over the tiles of a city map. Starting at a given city radius
134 * (the city center is _radius_sq_min = 0) outward to the tiles of
135 * _radius_sq_max. (_x, _y) will be the valid elements of
136 * [0, CITY_MAP_MAX_SIZE] taking into account the city radius. */
137#define city_map_iterate_outwards_radius_sq_index(_radius_sq_min, \
138 _radius_sq_max, \
139 _index, _x, _y) \
140{ \
141 fc_assert(_radius_sq_min <= _radius_sq_max); \
142 int _x = 0, _y = 0, _index; \
143 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
144 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
145 _radius_sq_max)) { \
146 _index = _x##_y##_index; \
147 _x##_y##_index++;
148
149#define city_map_iterate_outwards_radius_sq_index_end \
150 } \
151}
152
153 /* Same as above, but don't set index */
154#define city_map_iterate_outwards_radius_sq(_radius_sq_min, \
155 _radius_sq_max, \
156 _x, _y) \
157{ \
158 fc_assert(_radius_sq_min <= _radius_sq_max); \
159 int _x = 0, _y = 0; \
160 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
161 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
162 _radius_sq_max)) { \
163 _x##_y##_index++;
164
165#define city_map_iterate_outwards_radius_sq_end \
166 } \
167}
168
169/* Iterate a city map. This iterates over all city positions in the city
170 * map starting at the city center (i.e., positions that are workable by
171 * the city) using the index (_index) and the coordinates (_x, _y). It
172 * is an abbreviation for city_map_iterate_outwards_radius_sq(_end). */
173#define city_map_iterate(_radius_sq, _index, _x, _y) \
174 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
175 _radius_sq, _index, _x, _y)
176
177#define city_map_iterate_end \
178 city_map_iterate_outwards_radius_sq_index_end
179
180#define city_map_iterate_without_index(_radius_sq, _x, _y) \
181 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
182 _radius_sq, _x, _y)
183
184#define city_map_iterate_without_index_end \
185 city_map_iterate_outwards_radius_sq_end
186
187/* Iterate the tiles between two radii of a city map. */
188#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, \
189 _x, _y) \
190 city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, \
191 _x, _y)
192
193#define city_map_iterate_radius_sq_end \
194 city_map_iterate_outwards_radius_sq_end
195
196/* Iterate a city map in checked real map coordinates.
197 * _radius_sq is the squared city radius.
198 * _city_tile is the center of the (possible) city.
199 * (_index) will be the city tile index in the interval
200 * [0, city_map_tiles(_radius_sq)] */
201#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, \
202 _index) { \
203 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
204 _radius_sq, _index, _x, _y) \
205 struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
206 _x, _y); \
207 if (NULL != _tile) {
208
209#define city_tile_iterate_index_end \
210 } \
211 } city_map_iterate_outwards_radius_sq_index_end;
212
213/* simple extension to skip is_free_worked() tiles. */
214#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, \
215 _tile, _index, _x, _y) { \
216 city_map_iterate(_radius_sq, _index, _x, _y) { \
217 if (!is_free_worked_index(_index)) { \
218 struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
219 _x, _y); \
220 if (NULL != _tile) {
221
222#define city_tile_iterate_skip_free_worked_end \
223 } \
224 } \
225 } city_map_iterate_end; \
226}
227
228/* Does the same thing as city_tile_iterate_index(), but keeps the city
229 * coordinates hidden. */
230#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile) { \
231 const struct tile *_center##_tile = _city_tile; \
232 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
233 _radius_sq, _x, _y) \
234 struct tile *_tile = city_map_to_tile(_nmap, _center##_tile, _radius_sq, \
235 _x, _y); \
236 if (NULL != _tile) {
237
238#define city_tile_iterate_end \
239 } \
240 } city_map_iterate_outwards_radius_sq_end;
241
242/* Improvement status (for cities' lists of improvements)
243 * (replaced Impr_Status) */
244
246 int turn; /* turn built, negative for old state */
247#define I_NEVER (-1) /* Improvement never built */
248#define I_DESTROYED (-2) /* Improvement built and destroyed */
249};
250
251/* How much this output type is penalized for unhappy cities: not at all,
252 * surplus knocked down to 0, or all production removed. */
258
260 int index;
261 const char *name; /* Untranslated name */
262 const char *id; /* Identifier string (for rulesets, etc.) */
263 bool harvested; /* Is this output type gathered by city workers? */
265};
266
275
276/* changing this order will break network compatibility,
277 * and clients that don't use the symbols. */
279 FEELING_BASE, /* before any of the modifiers below */
280 FEELING_LUXURY, /* after luxury */
281 FEELING_EFFECT, /* after building effects */
282 FEELING_NATIONALITY, /* after citizen nationality effects */
283 FEELING_MARTIAL, /* after units enforce martial order */
284 FEELING_FINAL, /* after wonders (final result) */
287
288/* Ways city output can be lost. Not currently part of network protocol. */
290 OLOSS_WASTE, /* regular corruption or waste */
291 OLOSS_SIZE, /* notradesize/fulltradesize */
294
295/* This enumerators are used at client side only (so changing it doesn't
296 * break the compatibility) to mark that the city need specific gui updates
297 * (e.g. city dialog, or city report). */
304
310
311struct tile_cache; /* defined and only used within city.c */
312
313struct adv_city; /* defined in ./server/advisors/infracache.h */
314
315struct cm_parameter; /* defined in ./common/aicore/cm.h */
316
317#ifdef FREECIV_WEB
318#pragma pack(push, 1)
319#endif
320struct city {
321 char *name;
322 struct tile *tile; /* May be NULL, should check! */
323 struct player *owner; /* Cannot be NULL. */
324 struct player *original; /* Often NULL in client,
325 * can be NULL on server after player removal */
326 int id;
327 int style;
330
331 /* The people */
334
335 /* Specialists */
337
338 citizens martial_law; /* Citizens pacified by martial law. */
339 citizens unit_happy_upkeep; /* Citizens angered by military action. */
340
341 citizens *nationality; /* Nationality of the citizens. */
342
343 /* Trade routes */
345
346 /* Tile output, regardless of if the tile is actually worked. It is used
347 * as cache for the output of the tiles within the city map.
348 * (see city_tile_cache_update() and city_tile_cache_get_output()) */
350 /* The memory allocated for tile_cache is valid for this squared city
351 * radius. */
353
354 /* the productions */
355 int surplus[O_LAST]; /* Final surplus in each category. */
356 int waste[O_LAST]; /* Waste/corruption in each category. */
357 int unhappy_penalty[O_LAST]; /* Penalty from unhappy cities. */
358 int prod[O_LAST]; /* Production is total minus waste and penalty. */
359 int citizen_base[O_LAST]; /* Base production from citizens. */
360 int usage[O_LAST]; /* Amount of each resource being used. */
361
362 /* Cached values for CPU savings. */
365
366 /* the physics */
369 int pollution; /* not saved */
370 int illness_trade; /* not saved; illness due to trade; it is
371 calculated within the server and send to
372 the clients as the clients do not have all
373 information about the trade cities */
374 int turn_plague; /* last turn with an illness in the city */
375 int city_radius_sq; /* current squared city radius */
376
377 /* turn states */
383
384 int anarchy; /* anarchy rounds count */
385 int rapture; /* rapture rounds count */
388
389 int before_change_shields; /* If changed this turn, shields before penalty */
390 int caravan_shields; /* If caravan has helped city to build wonder. */
391 int disbanded_shields; /* If you disband unit in a city. Count them */
392 int last_turns_shield_surplus; /* The surplus we had last turn. */
393
395
397
398 /* If changed this turn, what we changed from */
400
402
405
406 struct unit_list *units_supported;
407
409
410 int history; /* Cumulative culture */
411
413
414 int steal; /* Diplomats steal once; for spies, gets harder */
415
416 struct {
417 size_t length;
418 /* If true, rally point is active until owner cancels or loses city. */
420 /* Orders should be cleared if an enemy is met. */
424
426
427 union {
428 struct {
429 /* Only used in the server (./ai/ and ./server/). */
430
431 float migration_score; /* updated by city_migration_score. */
432 int mgr_score_calc_turn; /* turn the migration score was calculated */
433
435
436 /* If > 0, workers will not be rearranged until they are unfrozen. */
438
439 /* If set, workers need to be arranged when the city is unfrozen.
440 * Set inside auto_arrange_workers() and city_freeze_workers_queue(). */
442
443 /* If set, city needs to be refreshed at a later time.
444 * Set inside city_refresh() and city_refresh_queue_add(). */
446
447 /* the city map is synced with the client. */
448 bool synced;
449
450 bool debug; /* not saved */
451
452 struct adv_city *adv;
454
455 struct vision *vision;
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{
571 fc_assert_ret_val(pcity != NULL, 0);
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);
580
581citizens player_content_citizens(const struct player *pplayer);
582citizens player_angry_citizens(const struct player *pplayer);
583
584int city_population(const struct city *pcity);
585int city_total_impr_gold_upkeep(const struct city *pcity);
586int city_total_unit_gold_upkeep(const struct city *pcity);
587int city_unit_unhappiness(const struct civ_map *nmap,
588 struct unit *punit, int *free_unhappy);
589bool city_happy(const struct city *pcity); /* Generally use celebrating instead */
590bool city_unhappy(const struct city *pcity); /* Anarchy??? */
591bool base_city_celebrating(const struct city *pcity);
592bool city_celebrating(const struct city *pcity); /* Love the king ??? */
593bool city_rapture_grow(const struct city *pcity);
594bool city_is_occupied(const struct city *pcity);
595
596/* City related improvement and unit functions */
597
598int city_improvement_upkeep(const struct city *pcity,
599 const struct impr_type *pimprove);
600
601bool can_city_build_improvement_direct(const struct city *pcity,
602 const struct impr_type *pimprove);
603bool can_city_build_improvement_later(const struct city *pcity,
604 const struct impr_type *pimprove);
605bool can_city_build_improvement_now(const struct city *pcity,
606 const struct impr_type *pimprove);
607
608bool can_city_build_unit_direct(const struct civ_map *nmap,
609 const struct city *pcity,
610 const struct unit_type *punittype);
611bool can_city_build_unit_later(const struct civ_map *nmap,
612 const struct city *pcity,
613 const struct unit_type *punittype);
614bool can_city_build_unit_now(const struct civ_map *nmap,
615 const struct city *pcity,
616 const struct unit_type *punittype);
617
618bool can_city_build_direct(const struct civ_map *nmap,
619 const struct city *pcity,
620 const struct universal *target);
621bool can_city_build_later(const struct civ_map *nmap,
622 const struct city *pcity,
623 const struct universal *target);
624bool can_city_build_now(const struct civ_map *nmap,
625 const struct city *pcity,
626 const struct universal *target);
627
628int city_unit_slots_available(const struct city *pcity);
629bool city_can_use_specialist(const struct city *pcity,
631bool city_has_building(const struct city *pcity,
632 const struct impr_type *pimprove);
633bool is_capital(const struct city *pcity);
634bool is_gov_center(const struct city *pcity);
635bool city_got_defense_effect(const struct city *pcity,
636 const struct unit_type *attacker);
637
638int city_production_build_shield_cost(const struct city *pcity);
639bool city_production_build_units(const struct city *pcity,
640 bool add_production, int *num_units);
642 const struct unit_type *punittype);
643
644bool city_production_is_genus(const struct city *pcity,
645 enum impr_genus_id genus);
646bool city_production_has_flag(const struct city *pcity,
647 enum impr_flag_id flag);
648int city_production_turns_to_build(const struct city *pcity,
650
651bool city_production_gets_caravan_shields(const struct universal *tgt);
652
653int city_change_production_penalty(const struct city *pcity,
654 const struct universal *target);
655int city_turns_to_build(const struct city *pcity,
656 const struct universal *target,
658int city_turns_to_grow(const struct city *pcity);
659bool city_can_grow_to(const struct city *pcity, int pop_size);
660bool city_can_change_build(const struct city *pcity);
661
662void city_choose_build_default(const struct civ_map *nmap, struct city *pcity);
663
664/* Textual representation of buildings */
665
666const char *city_improvement_name_translation(const struct city *pcity,
667 const struct impr_type *pimprove);
668const char *city_production_name_translation(const struct city *pcity);
669
670/* City map functions */
671bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
672 const int city_map_y);
673bool city_map_includes_tile(const struct city *const pcity,
674 const struct tile *map_tile);
676 const struct city *const pcity,
677 const struct tile *map_tile);
679 const int city_radius_sq,
680 const struct tile *city_center,
681 const struct tile *map_tile);
682
683struct tile *city_map_to_tile(const struct civ_map *nmap,
684 const struct tile *city_center,
685 int city_radius_sq, int city_map_x,
686 int city_map_y);
687
688/* Initialization functions */
689int compare_iter_index(const void *a, const void *b);
691void free_city_map_index(void);
693
694/* Output on spot */
695int city_tile_output(const struct city *pcity, const struct tile *ptile,
697int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
699
701 const struct city *pcity,
702 const struct tile *ptile);
703bool city_can_work_tile(const struct city *pcity, const struct tile *ptile);
704
706 const struct tile *ptile);
707
708bool city_can_be_built_here(const struct civ_map *nmap,
709 const struct tile *ptile,
710 const struct unit *punit,
711 bool hut_test);
712bool city_can_be_built_tile_only(const struct civ_map *nmap,
713 const struct tile *ptile);
714
715/* List functions */
716struct city *city_list_find_number(struct city_list *This, int id);
717struct city *city_list_find_name(struct city_list *This, const char *name);
718
719int city_name_compare(const void *p1, const void *p2);
720
721/* City style functions */
722const char *city_style_rule_name(const int style);
723const char *city_style_name_translation(const int style);
724
725int city_style_by_rule_name(const char *s);
726int city_style_by_translated_name(const char *s);
727
728struct city *tile_enemy_city(const struct tile *ptile,
729 const struct player *pplayer);
730
731/**********************************************************************/
734static inline bool is_enemy_city_tile(const struct tile *ptile,
735 const struct player *pplayer)
736{
737 return NULL != tile_enemy_city(ptile, pplayer);
738}
739
740struct city *tile_allied_city(const struct tile *ptile,
741 const struct player *pplayer);
742
743/**********************************************************************/
746static inline bool is_allied_city_tile(const struct tile *ptile,
747 const struct player *pplayer)
748{
749 return NULL != tile_allied_city(ptile, pplayer);
750}
751
752struct city *tile_non_attack_city(const struct tile *ptile,
753 const struct player *pplayer);
754
755/**********************************************************************/
758static inline bool is_non_attack_city_tile(const struct tile *ptile,
759 const struct player *pplayer)
760{
761 return NULL != tile_non_attack_city(ptile, pplayer);
762}
763
764struct city *tile_non_allied_city(const struct tile *ptile,
765 const struct player *pplayer);
766
767/**********************************************************************/
770static inline bool is_non_allied_city_tile(const struct tile *ptile,
771 const struct player *pplayer)
772{
773 return NULL != tile_non_allied_city(ptile, pplayer);
774}
775
776bool is_unit_near_a_friendly_city(const struct civ_map *nmap,
777 const struct unit *punit,
778 int distance);
779bool is_friendly_city_near(const struct civ_map *nmap,
780 const struct player *owner,
781 const struct tile *ptile,
782 int distance);
784 const struct tile *ptile,
785 bool may_be_on_center);
786
787/* Granary size as a function of city size */
788int city_granary_size(int city_size);
789
790void city_add_improvement(struct city *pcity,
791 const struct impr_type *pimprove);
792void city_remove_improvement(struct city *pcity,
793 const struct impr_type *pimprove);
794
795/* City update functions */
796void city_refresh_from_main_map(const struct civ_map *nmap,
797 struct city *pcity, bool *workers_map);
798
799int city_waste(const struct city *pcity, Output_type_id otype, int total,
800 int *breakdown);
802 const struct city *pcity);
803int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype);
804bool city_built_last_turn(const struct city *pcity);
805
806/* City creation / destruction */
807struct city *create_city_virtual(struct player *pplayer,
808 struct tile *ptile, const char *name);
809void destroy_city_virtual(struct city *pcity);
810bool city_is_virtual(const struct city *pcity);
811
812/* Misc */
813bool is_city_option_set(const struct city *pcity, enum city_options option);
814void city_styles_alloc(int num);
815void city_styles_free(void);
816
817void add_tax_income(const struct player *pplayer, int trade, int *output);
818int get_city_tithes_bonus(const struct city *pcity);
819int city_pollution_types(const struct city *pcity, int shield_total,
820 int *pollu_prod, int *pollu_pop, int *pollu_mod);
821int city_pollution(const struct city *pcity, int shield_total);
822int city_illness_calc(const struct city *pcity, int *ill_base,
823 int *ill_size, int *ill_trade, int *ill_pollution);
824bool city_had_recent_plague(const struct city *pcity);
825int city_build_slots(const struct city *pcity);
826int city_airlift_max(const struct city *pcity);
827
828bool city_exist(int id);
829
830/*
831 * Iterates over all improvements, skipping those not yet built in the
832 * given city.
833 */
834#define city_built_iterate(_pcity, _p) \
835 improvement_iterate(_p) { \
836 if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
837 continue; \
838 }
839
840#define city_built_iterate_end \
841 } improvement_iterate_end;
842
843
844/* Iterates over all output types in the game. */
845#define output_type_iterate(output) \
846{ \
847 Output_type_id output; \
848 \
849 for (output = 0; output < O_LAST; output++) {
850
851#define output_type_iterate_end \
852 } \
853}
854
855
856/* === */
857
858/**********************************************************************/
868static inline bool is_city_center(const struct city *pcity,
869 const struct tile *ptile)
870{
871 if (!pcity || !pcity->tile || !ptile) {
872 return FALSE;
873 }
874
875 return tile_index(city_tile(pcity)) == tile_index(ptile);
876}
877
878bool is_free_worked(const struct city *pcity, const struct tile *ptile);
879
880#define is_free_worked_index(city_tile_index) \
881 (CITY_MAP_CENTER_TILE_INDEX == city_tile_index)
882#define FREE_WORKED_TILES (1)
883
884void *city_ai_data(const struct city *pcity, const struct ai_type *ai);
885void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
886 void *data);
887
888void city_rally_point_clear(struct city *pcity);
889void city_rally_point_receive(const struct packet_city_rally_point *packet,
890 struct city *pcity)
891 fc__attribute((nonnull (1)));
892
893#ifdef __cplusplus
894}
895#endif /* __cplusplus */
896
897#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:770
bool city_is_virtual(const struct city *pcity)
Definition city.c:3589
city_needs_arrange
Definition city.h:305
@ CNA_BROADCAST_PENDING
Definition city.h:308
@ CNA_NOT
Definition city.h:306
@ CNA_NORMAL
Definition city.h:307
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:3601
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:758
#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:734
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:3617
output_unhappy_penalty
Definition city.h:253
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:256
@ UNHAPPY_PENALTY_NONE
Definition city.h:254
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:255
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:3228
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:267
@ CITIZEN_LAST
Definition city.h:272
@ CITIZEN_SPECIALIST
Definition city.h:273
@ CITIZEN_ANGRY
Definition city.h:271
@ CITIZEN_HAPPY
Definition city.h:268
@ CITIZEN_CONTENT
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:270
void city_styles_free(void)
Definition city.c:3411
void city_rally_point_receive(const struct packet_city_rally_point *packet, struct city *pcity) fc__attribute((nonnull(1)))
Definition city.c:3641
city_updates
Definition city.h:298
@ CU_POPUP_DIALOG
Definition city.h:302
@ CU_UPDATE_REPORT
Definition city.h:300
@ CU_UPDATE_DIALOG
Definition city.h:301
@ CU_NO_UPDATE
Definition city.h:299
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:647
bool is_capital(const struct city *pcity)
Definition city.c:1579
struct citystyle * city_styles
Definition city.c:84
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1255
void city_styles_alloc(int num)
Definition city.c:3396
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1401
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1049
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:746
void city_production_caravan_shields_init(void)
Definition city.c:1778
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3371
int city_airlift_max(const struct city *pcity)
Definition city.c:2942
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1465
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1031
struct output_type * get_output_type(Output_type_id output)
Definition city.c:638
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3388
int city_population(const struct city *pcity)
Definition city.c:1191
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:868
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:820
bool city_unhappy(const struct city *pcity)
Definition city.c:1626
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3334
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3430
void set_city_production(struct city *pcity)
Definition city.c:2953
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1679
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:3176
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:278
@ FEELING_EFFECT
Definition city.h:281
@ FEELING_LUXURY
Definition city.h:280
@ FEELING_FINAL
Definition city.h:284
@ FEELING_LAST
Definition city.h:285
@ FEELING_BASE
Definition city.h:279
@ FEELING_NATIONALITY
Definition city.h:282
@ FEELING_MARTIAL
Definition city.h:283
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1487
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2821
bool city_happy(const struct city *pcity)
Definition city.c:1614
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1180
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3357
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1384
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
struct city * tile_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2036
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2021
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:446
bool city_base_to_city_map(int *city_map_x, int *city_map_y, const struct city *const pcity, const struct tile *map_tile)
Definition city.c:281
output_loss
Definition city.h:289
@ OLOSS_SIZE
Definition city.h:291
@ OLOSS_WASTE
Definition city.h:290
@ OLOSS_LAST
Definition city.h:292
void destroy_city_virtual(struct city *pcity)
Definition city.c:3516
int rs_max_city_radius_sq(void)
Definition city.c:159
bool city_tile_to_city_map(int *city_map_x, int *city_map_y, const int city_radius_sq, const struct tile *city_center, const struct tile *map_tile)
Definition city.c:264
citizens city_specialists(const struct city *pcity)
Definition city.c:3317
const Output_type_id num_output_types
production_class_type
Definition city.h:38
@ PCT_LAST
Definition city.h:42
@ PCT_UNIT
Definition city.h:39
@ PCT_NORMAL_IMPROVEMENT
Definition city.h:40
@ PCT_WONDER
Definition city.h:41
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:3609
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:3572
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:717
int compare_iter_index(const void *a, const void *b)
Definition city.c:343
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:747
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1996
void city_rally_point_clear(struct city *pcity)
Definition city.c:3626
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:75
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
unsigned char citizens
Definition fc_types.h:388
#define SP_MAX
Definition fc_types.h:409
int Specialist_type_id
Definition fc_types.h:375
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_LAST
Definition fc_types.h:101
enum output_type_id Output_type_id
Definition fc_types.h:378
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:194
log_level
Definition log.h:28
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:246
Definition city.h:320
struct worker_task_list * task_reqs
Definition city.h:412
struct tile_cache * tile_cache
Definition city.h:349
int color_index
Definition city.h:470
int turn_last_built
Definition city.h:387
int surplus[O_LAST]
Definition city.h:355
enum city_wl_cancel_behavior wlcb
Definition city.h:404
int food_stock
Definition city.h:367
struct built_status built[B_LAST]
Definition city.h:394
struct player * original
Definition city.h:324
int history
Definition city.h:410
int * counter_values
Definition city.h:408
int pollution
Definition city.h:369
bool did_sell
Definition city.h:380
int id
Definition city.h:326
int last_turns_shield_surplus
Definition city.h:392
enum capital_type capital
Definition city.h:328
int disbanded_shields
Definition city.h:391
int waste[O_LAST]
Definition city.h:356
int workers_frozen
Definition city.h:437
int turn_plague
Definition city.h:374
struct unit_list * info_units_present
Definition city.h:474
bv_city_options city_options
Definition city.h:403
citizens unit_happy_upkeep
Definition city.h:339
int city_radius_sq
Definition city.h:375
bool was_happy
Definition city.h:381
struct player * owner
Definition city.h:323
enum city_acquire_type acquire_t
Definition city.h:329
int turn_founded
Definition city.h:386
int airlift
Definition city.h:378
int citizen_base[O_LAST]
Definition city.h:359
int caravan_shields
Definition city.h:390
bool did_buy
Definition city.h:379
struct unit_list * info_units_supported
Definition city.h:473
char * name
Definition city.h:321
void * ais[FREECIV_AI_MOD_LAST]
Definition city.h:453
struct trade_route_list * routes
Definition city.h:344
int anarchy
Definition city.h:384
enum city_needs_arrange needs_arrange
Definition city.h:441
bool occupied
Definition city.h:460
int usage[O_LAST]
Definition city.h:360
int tile_cache_radius_sq
Definition city.h:352
int abs_bonus[O_LAST]
Definition city.h:364
struct universal production
Definition city.h:396
struct unit_order * orders
Definition city.h:422
int walls
Definition city.h:461
struct city::@16 rally_point
bool happy
Definition city.h:462
struct unit_list * collecting_info_units_supported
Definition city.h:477
int bonus[O_LAST]
Definition city.h:363
struct adv_city * adv
Definition city.h:452
citizens * nationality
Definition city.h:341
bool vigilant
Definition city.h:421
int steal
Definition city.h:414
int unhappy_penalty[O_LAST]
Definition city.h:357
citizens size
Definition city.h:332
unsigned char first_citizen_index
Definition city.h:483
int illness
Definition city.h:434
int before_change_shields
Definition city.h:389
int culture
Definition city.h:465
int style
Definition city.h:327
bool had_famine
Definition city.h:382
size_t length
Definition city.h:417
bool synced
Definition city.h:448
float migration_score
Definition city.h:431
bool needs_refresh
Definition city.h:445
struct unit_list * collecting_info_units_present
Definition city.h:478
int buy_cost
Definition city.h:466
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:333
citizens specialists[SP_MAX]
Definition city.h:336
struct tile * tile
Definition city.h:322
int shield_stock
Definition city.h:368
int prod[O_LAST]
Definition city.h:358
struct vision * vision
Definition city.h:455
struct city::@17::@19 server
struct cm_parameter * cm_parameter
Definition city.h:425
int city_image
Definition city.h:464
bool debug
Definition city.h:450
struct universal changed_from
Definition city.h:399
bool colored
Definition city.h:469
bool unhappy
Definition city.h:463
struct unit_list * units_supported
Definition city.h:406
int mgr_score_calc_turn
Definition city.h:432
int illness_trade
Definition city.h:370
enum city_updates need_updates
Definition city.h:481
bool persistent
Definition city.h:419
struct city::@17::@20 client
int rapture
Definition city.h:385
citizens martial_law
Definition city.h:338
struct 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:110
int dx
Definition city.h:110
int dy
Definition city.h:110
const char * id
Definition city.h:262
enum output_unhappy_penalty unhappy_penalty
Definition city.h:264
int index
Definition city.h:260
bool harvested
Definition city.h:263
const char * name
Definition city.h:261
Definition tile.h:50
Definition unit.h:138
#define fc__attribute(x)
Definition support.h:99
#define FALSE
Definition support.h:47
#define tile_index(_pt_)
Definition tile.h:88