Freeciv-3.1
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 "improvement.h"
28#include "tile.h"
29#include "traderoutes.h"
30#include "unit.h"
31#include "unitlist.h"
32#include "vision.h"
33#include "workertask.h"
34#include "worklist.h"
35
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/* Changing the max radius requires updating network capabilities and results
68 * in incompatible savefiles. */
69#define CITY_MAP_MIN_RADIUS 0
70#define CITY_MAP_DEFAULT_RADIUS 2
71#define CITY_MAP_MAX_RADIUS 5
72
73/* The city includes all tiles dx^2 + dy^2 <= CITY_MAP_*_RADIUS_SQ */
74#define CITY_MAP_DEFAULT_RADIUS_SQ \
75 (CITY_MAP_DEFAULT_RADIUS * CITY_MAP_DEFAULT_RADIUS + 1)
76#define CITY_MAP_MIN_RADIUS_SQ \
77 (CITY_MAP_MIN_RADIUS * CITY_MAP_MIN_RADIUS + 1)
78#define CITY_MAP_MAX_RADIUS_SQ \
79 (CITY_MAP_MAX_RADIUS * CITY_MAP_MAX_RADIUS + 1)
80/* the id for the city center */
81#define CITY_MAP_CENTER_RADIUS_SQ -1
82/* the tile index of the city center */
83#define CITY_MAP_CENTER_TILE_INDEX 0
84
85/* Maximum diameter of the workable city area. */
86#define CITY_MAP_MAX_SIZE (CITY_MAP_MAX_RADIUS * 2 + 1)
87
88#define INCITE_IMPOSSIBLE_COST (1000 * 1000 * 1000)
89
90/*
91 * Size of the biggest possible city.
92 *
93 * The constant may be changed since it isn't externally visible.
94 *
95 * The city size is saved as unsigned char. Therefore, MAX_CITY_SIZE should
96 * be below 255!
97 */
98#define MAX_CITY_SIZE 0xFF
99
100/* Iterate a city map, from the center (the city) outwards */
102 int dx, dy, dist;
103};
104
105/* City map coordinates are positive integers shifted by the maximum
106 * radius the game engine allows (not the current ruleset) */
107#define CITY_REL2ABS(_coor) (_coor + CITY_MAP_MAX_RADIUS)
108#define CITY_ABS2REL(_coor) (_coor - CITY_MAP_MAX_RADIUS)
109
110bool city_tile_index_to_xy(int *city_map_x, int *city_map_y,
111 int city_tile_index, int city_radius_sq);
112int city_tile_xy_to_index(int city_map_x, int city_map_y,
113 int city_radius_sq);
114
115int rs_max_city_radius_sq(void);
116int city_map_radius_sq_get(const struct city *pcity);
117void city_map_radius_sq_set(struct city *pcity, int radius_sq);
118int city_map_tiles(int city_radius_sq);
119#define city_map_tiles_from_city(_pcity) \
120 city_map_tiles(city_map_radius_sq_get(_pcity))
121
122void citylog_map_data(enum log_level level, int radius_sq, int *map_data);
123void citylog_map_workers(enum log_level level, struct city *pcity);
124
125/* Iterate over the tiles of a city map. Starting at a given city radius
126 * (the city center is _radius_sq_min = 0) outward to the tiles of
127 * _radius_sq_max. (_x, _y) will be the valid elements of
128 * [0, CITY_MAP_MAX_SIZE] taking into account the city radius. */
129#define city_map_iterate_outwards_radius_sq_index(_radius_sq_min, \
130 _radius_sq_max, \
131 _index, _x, _y) \
132{ \
133 fc_assert(_radius_sq_min <= _radius_sq_max); \
134 int _x = 0, _y = 0, _index; \
135 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
136 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
137 _radius_sq_max)) { \
138 _index = _x##_y##_index; \
139 _x##_y##_index++;
140
141#define city_map_iterate_outwards_radius_sq_index_end \
142 } \
143}
144
145 /* Same as above, but don't set index */
146#define city_map_iterate_outwards_radius_sq(_radius_sq_min, \
147 _radius_sq_max, \
148 _x, _y) \
149{ \
150 fc_assert(_radius_sq_min <= _radius_sq_max); \
151 int _x = 0, _y = 0; \
152 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
153 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
154 _radius_sq_max)) { \
155 _x##_y##_index++;
156
157#define city_map_iterate_outwards_radius_sq_end \
158 } \
159}
160
161/* Iterate a city map. This iterates over all city positions in the city
162 * map starting at the city center (i.e., positions that are workable by
163 * the city) using the index (_index) and the coordinates (_x, _y). It
164 * is an abbreviation for city_map_iterate_outwards_radius_sq(_end). */
165#define city_map_iterate(_radius_sq, _index, _x, _y) \
166 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
167 _radius_sq, _index, _x, _y)
168
169#define city_map_iterate_end \
170 city_map_iterate_outwards_radius_sq_index_end
171
172#define city_map_iterate_without_index(_radius_sq, _x, _y) \
173 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
174 _radius_sq, _x, _y)
175
176#define city_map_iterate_without_index_end \
177 city_map_iterate_outwards_radius_sq_end
178
179/* Iterate the tiles between two radii of a city map. */
180#define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, \
181 _x, _y) \
182 city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, \
183 _x, _y)
184
185#define city_map_iterate_radius_sq_end \
186 city_map_iterate_outwards_radius_sq_end
187
188/* Iterate a city map in checked real map coordinates.
189 * _radius_sq is the squared city radius.
190 * _city_tile is the center of the (possible) city.
191 * (_index) will be the city tile index in the interval
192 * [0, city_map_tiles(_radius_sq)] */
193#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, \
194 _index) { \
195 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
196 _radius_sq, _index, _x, _y) \
197 struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
198 _x, _y); \
199 if (NULL != _tile) {
200
201#define city_tile_iterate_index_end \
202 } \
203 } city_map_iterate_outwards_radius_sq_index_end;
204
205/* simple extension to skip is_free_worked() tiles. */
206#define city_tile_iterate_skip_free_worked(_nmap, _radius_sq, _city_tile, \
207 _tile, _index, _x, _y) { \
208 city_map_iterate(_radius_sq, _index, _x, _y) { \
209 if (!is_free_worked_index(_index)) { \
210 struct tile *_tile = city_map_to_tile(_nmap, _city_tile, _radius_sq, \
211 _x, _y); \
212 if (NULL != _tile) {
213
214#define city_tile_iterate_skip_free_worked_end \
215 } \
216 } \
217 } city_map_iterate_end; \
218}
219
220/* Does the same thing as city_tile_iterate_index(), but keeps the city
221 * coordinates hidden. */
222#define city_tile_iterate(_nmap, _radius_sq, _city_tile, _tile) { \
223 const struct tile *_center##_tile = _city_tile; \
224 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
225 _radius_sq, _x, _y) \
226 struct tile *_tile = city_map_to_tile(_nmap, _center##_tile, _radius_sq, \
227 _x, _y); \
228 if (NULL != _tile) {
229
230#define city_tile_iterate_end \
231 } \
232 } city_map_iterate_outwards_radius_sq_end;
233
234/* Improvement status (for cities' lists of improvements)
235 * (replaced Impr_Status) */
236
238 int turn; /* turn built, negative for old state */
239#define I_NEVER (-1) /* Improvement never built */
240#define I_DESTROYED (-2) /* Improvement built and destroyed */
241};
242
243/* How much this output type is penalized for unhappy cities: not at all,
244 * surplus knocked down to 0, or all production removed. */
250
252 int index;
253 const char *name; /* Untranslated name */
254 const char *id; /* Identifier string (for rulesets, etc.) */
255 bool harvested; /* Is this output type gathered by city workers? */
257};
258
267
268/* changing this order will break network compatibility,
269 * and clients that don't use the symbols. */
271 FEELING_BASE, /* before any of the modifiers below */
272 FEELING_LUXURY, /* after luxury */
273 FEELING_EFFECT, /* after building effects */
274 FEELING_NATIONALITY, /* after citizen nationality effects */
275 FEELING_MARTIAL, /* after units enforce martial order */
276 FEELING_FINAL, /* after wonders (final result) */
279
280/* Ways city output can be lost. Not currently part of network protocol. */
282 OLOSS_WASTE, /* regular corruption or waste */
283 OLOSS_SIZE, /* notradesize/fulltradesize */
286
287/* This enumerators are used at client side only (so changing it doesn't
288 * break the compatibility) to mark that the city need specific gui updates
289 * (e.g. city dialog, or city report). */
296
302
303struct tile_cache; /* defined and only used within city.c */
304
305struct adv_city; /* defined in ./server/advisors/infracache.h */
306
307struct cm_parameter; /* defined in ./common/aicore/cm.h */
308
309struct city {
310 char *name;
311 struct tile *tile; /* May be NULL, should check! */
312 struct player *owner; /* Cannot be NULL. */
313 struct player *original; /* Often NULL in client,
314 * can be NULL on server after player removal */
315 int id;
316 int style;
317 enum capital_type capital;
318
319 /* the people */
322
323 /* Specialists */
325
326 citizens martial_law; /* Citizens pacified by martial law. */
327 citizens unit_happy_upkeep; /* Citizens angered by military action. */
328
329 citizens *nationality; /* Nationality of the citizens. */
330
331 /* trade routes */
332 struct trade_route_list *routes;
333
334 /* Tile output, regardless of if the tile is actually worked. It is used
335 * as cache for the output of the tiles within the city map.
336 * (see city_tile_cache_update() and city_tile_cache_get_output()) */
338 /* The memory allocated for tile_cache is valid for this squared city
339 * radius. */
341
342 /* the productions */
343 int surplus[O_LAST]; /* Final surplus in each category. */
344 int waste[O_LAST]; /* Waste/corruption in each category. */
345 int unhappy_penalty[O_LAST]; /* Penalty from unhappy cities. */
346 int prod[O_LAST]; /* Production is total minus waste and penalty. */
347 int citizen_base[O_LAST]; /* Base production from citizens. */
348 int usage[O_LAST]; /* Amount of each resource being used. */
349
350 /* Cached values for CPU savings. */
352
353 /* the physics */
356 int pollution; /* not saved */
357 int illness_trade; /* not saved; illness due to trade; it is
358 calculated within the server and send to
359 the clients as the clients do not have all
360 information about the trade cities */
361 int turn_plague; /* last turn with an illness in the city */
362 int city_radius_sq; /* current squared city radius */
363
364 /* turn states */
369
370 int anarchy; /* anarchy rounds count */
371 int rapture; /* rapture rounds count */
374
375 int before_change_shields; /* If changed this turn, shields before penalty */
376 int caravan_shields; /* If caravan has helped city to build wonder. */
377 int disbanded_shields; /* If you disband unit in a city. Count them */
378 int last_turns_shield_surplus; /* The surplus we had last turn. */
379
381
383
384 /* If changed this turn, what we changed from */
386
388
389 bv_city_options city_options;
390
391 struct unit_list *units_supported;
392
393 int history; /* Cumulative culture */
394
395 struct worker_task_list *task_reqs;
396
397 int steal; /* diplomats steal once; for spies, gets harder */
398
399 struct {
400 size_t length;
401 /* If true, rally point is active until owner cancels or loses city. */
403 /* Orders should be cleared if an enemy is met. */
407
409
410 union {
411 struct {
412 /* Only used in the server (./ai/ and ./server/). */
413
414 float migration_score; /* updated by city_migration_score. */
415 int mgr_score_calc_turn; /* turn the migration score was calculated */
416
418
419 /* If > 0, workers will not be rearranged until they are unfrozen. */
421
422 /* If set, workers need to be arranged when the city is unfrozen.
423 * Set inside auto_arrange_workers() and city_freeze_workers_queue(). */
425
426 /* If set, city needs to be refreshed at a later time.
427 * Set inside city_refresh() and city_refresh_queue_add(). */
429
430 /* the city map is synced with the client. */
431 bool synced;
432
433 bool debug; /* not saved */
434
435 struct adv_city *adv;
436 void *ais[FREECIV_AI_MOD_LAST];
437
438 struct vision *vision;
440
441 struct {
442 /* Only used at the client (the server is omniscient; ./client/). */
444 int walls;
445 bool happy;
450
451 /* The color is an index into the city_colors array in mapview_common */
454
455 /* info for dipl/spy investigation */
456 struct unit_list *info_units_supported;
457 struct unit_list *info_units_present;
458 /* Before popup the city dialog, units go there. In normal process,
459 * these pointers are set to NULL. */
462
463 /* Updates needed for the city. */
465
466 unsigned char first_citizen_index;
468 };
469};
470
478
479extern struct citystyle *city_styles;
481extern struct output_type output_types[];
482
483/* get 'struct city_list' and related functions: */
484#define SPECLIST_TAG city
485#define SPECLIST_TYPE struct city
486#include "speclist.h"
487
488#define city_list_iterate(citylist, pcity) \
489 TYPED_LIST_ITERATE(struct city, citylist, pcity)
490#define city_list_iterate_end LIST_ITERATE_END
491
492#define cities_iterate(pcity) \
493{ \
494 players_iterate(pcity##_player) { \
495 city_list_iterate(pcity##_player->cities, pcity) {
496
497#define cities_iterate_end \
498 } city_list_iterate_end; \
499 } players_iterate_end; \
500}
501
502#define city_list_iterate_safe(citylist, _city) \
503{ \
504 struct city_list *_city##_cl = citylist; \
505 int _city##_size = city_list_size(_city##_cl); \
506 \
507 if (_city##_size > 0) { \
508 int _city##_numbers[_city##_size]; \
509 int _city##_index; \
510 \
511 _city##_size = 0; \
512 city_list_iterate(_city##_cl, _city) { \
513 _city##_numbers[_city##_size++] = _city->id; \
514 } city_list_iterate_end; \
515 \
516 for (_city##_index = 0; \
517 _city##_index < _city##_size; \
518 _city##_index++) { \
519 struct city *_city = \
520 game_city_by_number(_city##_numbers[_city##_index]); \
521 \
522 if (NULL != _city) {
523
524#define city_list_iterate_safe_end \
525 } \
526 } \
527 } \
528}
529
530/* Output type functions */
531
532const char *get_output_identifier(Output_type_id output);
533const char *get_output_name(Output_type_id output);
536void add_specialist_output(const struct city *pcity, int *output);
537void set_city_production(struct city *pcity);
538
539/* Properties */
540
541const char *city_name_get(const struct city *pcity);
542void city_name_set(struct city *pcity, const char *new_name);
543#define city_owner(_pcity_) (_pcity_)->owner
544#define city_tile(_pcity_) (_pcity_)->tile
545
546/**********************************************************************/
549static inline citizens city_size_get(const struct city *pcity)
550{
551 fc_assert_ret_val(pcity != NULL, 0);
552
553 return pcity->size;
554}
555
556void city_size_add(struct city *pcity, int add);
557void city_size_set(struct city *pcity, citizens size);
558
559citizens city_specialists(const struct city *pcity);
560
561citizens player_content_citizens(const struct player *pplayer);
562citizens player_angry_citizens(const struct player *pplayer);
563
564int city_population(const struct city *pcity);
565int city_total_impr_gold_upkeep(const struct city *pcity);
566int city_total_unit_gold_upkeep(const struct city *pcity);
567int city_unit_unhappiness(const struct civ_map *nmap,
568 struct unit *punit, int *free_unhappy);
569bool city_happy(const struct city *pcity); /* Generally use celebrating instead */
570bool city_unhappy(const struct city *pcity); /* Anarchy??? */
571bool base_city_celebrating(const struct city *pcity);
572bool city_celebrating(const struct city *pcity); /* Love the king ??? */
573bool city_rapture_grow(const struct city *pcity);
574bool city_is_occupied(const struct city *pcity);
575
576/* City related improvement and unit functions */
577
578int city_improvement_upkeep(const struct city *pcity,
579 const struct impr_type *pimprove);
580
581bool can_city_build_improvement_direct(const struct city *pcity,
582 const struct impr_type *pimprove);
583bool can_city_build_improvement_later(const struct city *pcity,
584 const struct impr_type *pimprove);
585bool can_city_build_improvement_now(const struct city *pcity,
586 const struct impr_type *pimprove);
587
588bool can_city_build_unit_direct(const struct civ_map *nmap,
589 const struct city *pcity,
590 const struct unit_type *punittype);
591bool can_city_build_unit_later(const struct civ_map *nmap,
592 const struct city *pcity,
593 const struct unit_type *punittype);
594bool can_city_build_unit_now(const struct civ_map *nmap,
595 const struct city *pcity,
596 const struct unit_type *punittype);
597
598bool can_city_build_direct(const struct civ_map *nmap,
599 const struct city *pcity,
600 const struct universal *target);
601bool can_city_build_later(const struct civ_map *nmap,
602 const struct city *pcity,
603 const struct universal *target);
604bool can_city_build_now(const struct civ_map *nmap,
605 const struct city *pcity,
606 const struct universal *target);
607
608int city_unit_slots_available(const struct city *pcity);
609bool city_can_use_specialist(const struct city *pcity,
611bool city_has_building(const struct city *pcity,
612 const struct impr_type *pimprove);
613bool is_capital(const struct city *pcity);
614bool is_gov_center(const struct city *pcity);
615bool city_got_defense_effect(const struct city *pcity,
616 const struct unit_type *attacker);
617
618int city_production_build_shield_cost(const struct city *pcity);
619bool city_production_build_units(const struct city *pcity,
620 bool add_production, int *num_units);
622 const struct unit_type *punittype);
623
624bool city_production_has_flag(const struct city *pcity,
625 enum impr_flag_id flag);
626int city_production_turns_to_build(const struct city *pcity,
627 bool include_shield_stock);
628
629bool city_production_gets_caravan_shields(const struct universal *tgt);
630
631int city_change_production_penalty(const struct city *pcity,
632 const struct universal *target);
633int city_turns_to_build(const struct city *pcity,
634 const struct universal *target,
635 bool include_shield_stock);
636int city_turns_to_grow(const struct city *pcity);
637bool city_can_grow_to(const struct city *pcity, int pop_size);
638bool city_can_change_build(const struct city *pcity);
639
640void city_choose_build_default(const struct civ_map *nmap, struct city *pcity);
641
642/* Textual representation of buildings */
643
644const char *city_improvement_name_translation(const struct city *pcity,
645 const struct impr_type *pimprove);
646const char *city_production_name_translation(const struct city *pcity);
647
648/* City map functions */
649bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
650 const int city_map_y);
651bool city_map_includes_tile(const struct city *const pcity,
652 const struct tile *map_tile);
653bool city_base_to_city_map(int *city_map_x, int *city_map_y,
654 const struct city *const pcity,
655 const struct tile *map_tile);
656bool city_tile_to_city_map(int *city_map_x, int *city_map_y,
657 const int city_radius_sq,
658 const struct tile *city_center,
659 const struct tile *map_tile);
660
661struct tile *city_map_to_tile(const struct civ_map *nmap,
662 const struct tile *city_center,
663 int city_radius_sq, int city_map_x,
664 int city_map_y);
665
666/* Initialization functions */
667int compare_iter_index(const void *a, const void *b);
669void free_city_map_index(void);
671
672/* Output on spot */
673int city_tile_output(const struct city *pcity, const struct tile *ptile,
674 bool is_celebrating, Output_type_id otype);
675int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
676 Output_type_id otype);
677
678bool base_city_can_work_tile(const struct player *restriction,
679 const struct city *pcity,
680 const struct tile *ptile);
681bool city_can_work_tile(const struct city *pcity, const struct tile *ptile);
682
683bool citymindist_prevents_city_on_tile(const struct civ_map *nmap,
684 const struct tile *ptile);
685
686bool city_can_be_built_here(const struct civ_map *nmap,
687 const struct tile *ptile,
688 const struct unit *punit,
689 bool hut_test);
690bool city_can_be_built_tile_only(const struct civ_map *nmap,
691 const struct tile *ptile);
692
693/* List functions */
694struct city *city_list_find_number(struct city_list *This, int id);
695struct city *city_list_find_name(struct city_list *This, const char *name);
696
697int city_name_compare(const void *p1, const void *p2);
698
699/* City style functions */
700const char *city_style_rule_name(const int style);
701const char *city_style_name_translation(const int style);
702
703int city_style_by_rule_name(const char *s);
704int city_style_by_translated_name(const char *s);
705
706struct city *tile_enemy_city(const struct tile *ptile,
707 const struct player *pplayer);
708
709/**********************************************************************/
712static inline bool is_enemy_city_tile(const struct tile *ptile,
713 const struct player *pplayer)
714{
715 return NULL != tile_enemy_city(ptile, pplayer);
716}
717
718struct city *tile_allied_city(const struct tile *ptile,
719 const struct player *pplayer);
720
721/**********************************************************************/
724static inline bool is_allied_city_tile(const struct tile *ptile,
725 const struct player *pplayer)
726{
727 return NULL != tile_allied_city(ptile, pplayer);
728}
729
730struct city *tile_non_attack_city(const struct tile *ptile,
731 const struct player *pplayer);
732
733/**********************************************************************/
736static inline bool is_non_attack_city_tile(const struct tile *ptile,
737 const struct player *pplayer)
738{
739 return NULL != tile_non_attack_city(ptile, pplayer);
740}
741
742struct city *tile_non_allied_city(const struct tile *ptile,
743 const struct player *pplayer);
744
745/**********************************************************************/
748static inline bool is_non_allied_city_tile(const struct tile *ptile,
749 const struct player *pplayer)
750{
751 return NULL != tile_non_allied_city(ptile, pplayer);
752}
753
754bool is_unit_near_a_friendly_city(const struct civ_map *nmap,
755 const struct unit *punit);
756bool is_friendly_city_near(const struct civ_map *nmap,
757 const struct player *owner,
758 const struct tile *ptile);
759bool city_exists_within_max_city_map(const struct civ_map *nmap,
760 const struct tile *ptile,
761 bool may_be_on_center);
762
763/* Granary size as a function of city size */
764int city_granary_size(int city_size);
765
766void city_add_improvement(struct city *pcity,
767 const struct impr_type *pimprove);
768void city_remove_improvement(struct city *pcity,
769 const struct impr_type *pimprove);
770
771/* City update functions */
772void city_refresh_from_main_map(const struct civ_map *nmap,
773 struct city *pcity, bool *workers_map);
774
775int city_waste(const struct city *pcity, Output_type_id otype, int total,
776 int *breakdown);
778 const struct city *pcity);
779int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype);
780bool city_built_last_turn(const struct city *pcity);
781
782/* City creation / destruction */
783struct city *create_city_virtual(struct player *pplayer,
784 struct tile *ptile, const char *name);
785void destroy_city_virtual(struct city *pcity);
786bool city_is_virtual(const struct city *pcity);
787
788/* Misc */
789bool is_city_option_set(const struct city *pcity, enum city_options option);
790void city_styles_alloc(int num);
791void city_styles_free(void);
792
793void add_tax_income(const struct player *pplayer, int trade, int *output);
794int get_city_tithes_bonus(const struct city *pcity);
795int city_pollution_types(const struct city *pcity, int shield_total,
796 int *pollu_prod, int *pollu_pop, int *pollu_mod);
797int city_pollution(const struct city *pcity, int shield_total);
798int city_illness_calc(const struct city *pcity, int *ill_base,
799 int *ill_size, int *ill_trade, int *ill_pollution);
800bool city_had_recent_plague(const struct city *pcity);
801int city_build_slots(const struct city *pcity);
802int city_airlift_max(const struct city *pcity);
803
804bool city_exist(int id);
805
806/*
807 * Iterates over all improvements, skipping those not yet built in the
808 * given city.
809 */
810#define city_built_iterate(_pcity, _p) \
811 improvement_iterate(_p) { \
812 if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
813 continue; \
814 }
815
816#define city_built_iterate_end \
817 } improvement_iterate_end;
818
819
820/* Iterates over all output types in the game. */
821#define output_type_iterate(output) \
822{ \
823 Output_type_id output; \
824 \
825 for (output = 0; output < O_LAST; output++) {
826
827#define output_type_iterate_end \
828 } \
829}
830
831
832/* === */
833
834/**********************************************************************/
844static inline bool is_city_center(const struct city *pcity,
845 const struct tile *ptile)
846{
847 if (!pcity || !pcity->tile || !ptile) {
848 return FALSE;
849 }
850
851 return tile_index(city_tile(pcity)) == tile_index(ptile);
852}
853
854bool is_free_worked(const struct city *pcity, const struct tile *ptile);
855
856#define is_free_worked_index(city_tile_index) \
857 (CITY_MAP_CENTER_TILE_INDEX == city_tile_index)
858#define FREE_WORKED_TILES (1)
859
860void *city_ai_data(const struct city *pcity, const struct ai_type *ai);
861void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
862 void *data);
863
864void city_rally_point_clear(struct city *pcity);
865void city_rally_point_receive(const struct packet_city_rally_point *packet,
866 struct city *pcity)
867 fc__attribute((nonnull (1)));
868
869#ifdef __cplusplus
870}
871#endif /* __cplusplus */
872
873#endif /* FC__CITY_H */
bool base_city_celebrating(const struct city *pcity)
Definition city.c:1610
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:748
bool city_is_virtual(const struct city *pcity)
Definition city.c:3488
city_needs_arrange
Definition city.h:297
@ CNA_BROADCAST_PENDING
Definition city.h:300
@ CNA_NOT
Definition city.h:298
@ CNA_NORMAL
Definition city.h:299
int city_turns_to_build(const struct city *pcity, const struct universal *target, bool include_shield_stock)
Definition city.c:1938
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:658
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3500
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:736
#define city_tile(_pcity_)
Definition city.h:544
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1833
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:143
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:722
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1123
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:712
int city_granary_size(int city_size)
Definition city.c:2104
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2168
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2689
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3516
output_unhappy_penalty
Definition city.h:245
@ UNHAPPY_PENALTY_ALL_PRODUCTION
Definition city.h:248
@ UNHAPPY_PENALTY_NONE
Definition city.h:246
@ UNHAPPY_PENALTY_SURPLUS
Definition city.h:247
bool city_built_last_turn(const struct city *pcity)
Definition city.c:2251
void city_choose_build_default(const struct civ_map *nmap, struct city *pcity)
Definition city.c:1065
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
int city_waste(const struct city *pcity, Output_type_id otype, int total, int *breakdown)
Definition city.c:3122
void generate_city_map_indices(void)
Definition city.c:522
int city_build_slots(const struct city *pcity)
Definition city.c:2834
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:300
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1216
const char * city_style_name_translation(const int style)
Definition city.c:1729
citizen_category
Definition city.h:259
@ CITIZEN_LAST
Definition city.h:264
@ CITIZEN_SPECIALIST
Definition city.h:265
@ CITIZEN_ANGRY
Definition city.h:263
@ CITIZEN_HAPPY
Definition city.h:260
@ CITIZEN_CONTENT
Definition city.h:261
@ CITIZEN_UNHAPPY
Definition city.h:262
void city_styles_free(void)
Definition city.c:3324
void city_rally_point_receive(const struct packet_city_rally_point *packet, struct city *pcity) fc__attribute((nonnull(1)))
Definition city.c:3540
city_updates
Definition city.h:290
@ CU_POPUP_DIALOG
Definition city.h:294
@ CU_UPDATE_REPORT
Definition city.h:292
@ CU_UPDATE_DIALOG
Definition city.h:293
@ CU_NO_UPDATE
Definition city.h:291
Output_type_id output_type_by_identifier(const char *id)
Definition city.c:642
bool is_capital(const struct city *pcity)
Definition city.c:1552
struct citystyle * city_styles
Definition city.c:79
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
void city_styles_alloc(int num)
Definition city.c:3309
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1377
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1027
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:724
void city_production_caravan_shields_init(void)
Definition city.c:1751
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3284
int city_airlift_max(const struct city *pcity)
Definition city.c:2844
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1438
bool can_city_build_later(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1009
struct output_type * get_output_type(Output_type_id output)
Definition city.c:633
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3301
int city_population(const struct city *pcity)
Definition city.c:1169
const char * city_style_rule_name(const int style)
Definition city.c:1738
void city_size_add(struct city *pcity, int add)
Definition city.c:1142
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1043
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:712
bool city_is_occupied(const struct city *pcity)
Definition city.c:1638
void free_city_map_index(void)
Definition city.c:604
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:789
void add_tax_income(const struct player *pplayer, int trade, int *output)
Definition city.c:2217
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:839
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:96
struct city * tile_non_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2039
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:2943
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1569
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2158
bool city_map_includes_tile(const struct city *const pcity, const struct tile *map_tile)
Definition city.c:288
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2199
void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
Definition city.c:406
bool city_rapture_grow(const struct city *pcity)
Definition city.c:1626
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:844
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:805
bool city_unhappy(const struct city *pcity)
Definition city.c:1599
bool is_friendly_city_near(const struct civ_map *nmap, const struct player *owner, const struct tile *ptile)
Definition city.c:2065
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3247
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3343
void set_city_production(struct city *pcity)
Definition city.c:2855
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1652
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2184
bool city_celebrating(const struct city *pcity)
Definition city.c:1618
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1533
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:815
const char * get_output_identifier(Output_type_id output)
Definition city.c:614
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2772
const char * get_output_name(Output_type_id output)
Definition city.c:624
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:1985
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1859
bool is_valid_city_coords(const int city_radius_sq, const int city_map_x, const int city_map_y)
Definition city.c:183
void city_refresh_from_main_map(const struct civ_map *nmap, struct city *pcity, bool *workers_map)
Definition city.c:3070
bool can_city_build_direct(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:972
citizen_feeling
Definition city.h:270
@ FEELING_EFFECT
Definition city.h:273
@ FEELING_LUXURY
Definition city.h:272
@ FEELING_FINAL
Definition city.h:276
@ FEELING_LAST
Definition city.h:277
@ FEELING_BASE
Definition city.h:271
@ FEELING_NATIONALITY
Definition city.h:274
@ FEELING_MARTIAL
Definition city.h:275
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:1460
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2723
bool city_happy(const struct city *pcity)
Definition city.c:1587
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1158
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3270
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1360
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
struct city * tile_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2009
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:1994
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:441
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:276
output_loss
Definition city.h:281
@ OLOSS_SIZE
Definition city.h:283
@ OLOSS_WASTE
Definition city.h:282
@ OLOSS_LAST
Definition city.h:284
void destroy_city_virtual(struct city *pcity)
Definition city.c:3419
int rs_max_city_radius_sq(void)
Definition city.c:154
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:259
citizens city_specialists(const struct city *pcity)
Definition city.c:3230
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:1694
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2304
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3508
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1668
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1259
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:118
bool can_city_build_unit_direct(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:888
bool is_gov_center(const struct city *pcity)
Definition city.c:1560
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:991
bool can_city_build_unit_now(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:927
int city_map_tiles(int city_radius_sq)
Definition city.c:166
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2024
bool city_exist(int id)
Definition city.c:3471
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1429
int compare_iter_index(const void *a, const void *b)
Definition city.c:338
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:732
bool is_unit_near_a_friendly_city(const struct civ_map *nmap, const struct unit *punit)
Definition city.c:2055
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1969
void city_rally_point_clear(struct city *pcity)
Definition city.c:3525
struct output_type output_types[]
Definition city.c:83
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:856
bool city_exists_within_max_city_map(const struct civ_map *nmap, const struct tile *ptile, bool may_be_on_center)
Definition city.c:2084
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2825
bool city_can_change_build(const struct city *pcity)
Definition city.c:1057
bool can_city_build_unit_later(const struct civ_map *nmap, const struct city *pcity, const struct unit_type *punittype)
Definition city.c:948
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1198
int city_style_by_rule_name(const char *s)
Definition city.c:1711
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1684
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1179
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:695
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:73
unsigned char citizens
Definition fc_types.h:358
#define SP_MAX
Definition fc_types.h:379
int Specialist_type_id
Definition fc_types.h:345
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_LAST
Definition fc_types.h:91
enum output_type_id Output_type_id
Definition fc_types.h:348
struct city * owner
Definition citydlg.c:219
GType type
Definition repodlgs.c:1312
#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:183
size_t size
Definition specvec.h:72
Definition ai.h:50
int turn
Definition city.h:238
Definition city.h:309
struct worker_task_list * task_reqs
Definition city.h:395
struct tile_cache * tile_cache
Definition city.h:337
int color_index
Definition city.h:453
int turn_last_built
Definition city.h:373
int surplus[O_LAST]
Definition city.h:343
int food_stock
Definition city.h:354
struct built_status built[B_LAST]
Definition city.h:380
struct player * original
Definition city.h:313
int history
Definition city.h:393
int pollution
Definition city.h:356
bool did_sell
Definition city.h:367
int id
Definition city.h:315
int last_turns_shield_surplus
Definition city.h:378
enum capital_type capital
Definition city.h:317
int disbanded_shields
Definition city.h:377
int waste[O_LAST]
Definition city.h:344
int workers_frozen
Definition city.h:420
int turn_plague
Definition city.h:361
struct unit_list * info_units_present
Definition city.h:457
bv_city_options city_options
Definition city.h:389
citizens unit_happy_upkeep
Definition city.h:327
int city_radius_sq
Definition city.h:362
bool was_happy
Definition city.h:368
struct player * owner
Definition city.h:312
int turn_founded
Definition city.h:372
int airlift
Definition city.h:365
int citizen_base[O_LAST]
Definition city.h:347
int caravan_shields
Definition city.h:376
bool did_buy
Definition city.h:366
struct unit_list * info_units_supported
Definition city.h:456
char * name
Definition city.h:310
void * ais[FREECIV_AI_MOD_LAST]
Definition city.h:436
struct trade_route_list * routes
Definition city.h:332
int anarchy
Definition city.h:370
enum city_needs_arrange needs_arrange
Definition city.h:424
bool occupied
Definition city.h:443
int usage[O_LAST]
Definition city.h:348
int tile_cache_radius_sq
Definition city.h:340
struct universal production
Definition city.h:382
struct unit_order * orders
Definition city.h:405
int walls
Definition city.h:444
struct city::@16 rally_point
bool happy
Definition city.h:445
struct unit_list * collecting_info_units_supported
Definition city.h:460
int bonus[O_LAST]
Definition city.h:351
struct adv_city * adv
Definition city.h:435
citizens * nationality
Definition city.h:329
bool vigilant
Definition city.h:404
int steal
Definition city.h:397
int unhappy_penalty[O_LAST]
Definition city.h:345
citizens size
Definition city.h:320
unsigned char first_citizen_index
Definition city.h:466
int illness
Definition city.h:417
int before_change_shields
Definition city.h:375
int culture
Definition city.h:448
int style
Definition city.h:316
size_t length
Definition city.h:400
bool synced
Definition city.h:431
float migration_score
Definition city.h:414
bool needs_refresh
Definition city.h:428
struct unit_list * collecting_info_units_present
Definition city.h:461
int buy_cost
Definition city.h:449
citizens feel[CITIZEN_LAST][FEELING_LAST]
Definition city.h:321
citizens specialists[SP_MAX]
Definition city.h:324
struct tile * tile
Definition city.h:311
int shield_stock
Definition city.h:355
int prod[O_LAST]
Definition city.h:346
struct vision * vision
Definition city.h:438
struct city::@17::@19 server
struct cm_parameter * cm_parameter
Definition city.h:408
int city_image
Definition city.h:447
bool debug
Definition city.h:433
struct universal changed_from
Definition city.h:385
bool colored
Definition city.h:452
bool unhappy
Definition city.h:446
struct unit_list * units_supported
Definition city.h:391
int mgr_score_calc_turn
Definition city.h:415
int illness_trade
Definition city.h:357
enum city_updates need_updates
Definition city.h:464
bool persistent
Definition city.h:402
struct city::@17::@20 client
int rapture
Definition city.h:371
citizens martial_law
Definition city.h:326
struct requirement_vector reqs
Definition city.h:476
char citizens_graphic[MAX_LEN_NAME]
Definition city.h:475
char graphic_alt[MAX_LEN_NAME]
Definition city.h:474
struct name_translation name
Definition city.h:472
char graphic[MAX_LEN_NAME]
Definition city.h:473
int dist
Definition city.h:102
int dx
Definition city.h:102
int dy
Definition city.h:102
const char * id
Definition city.h:254
enum output_unhappy_penalty unhappy_penalty
Definition city.h:256
int index
Definition city.h:252
bool harvested
Definition city.h:255
const char * name
Definition city.h:253
Definition tile.h:49
Definition unit.h:138
#define fc__attribute(x)
Definition support.h:89
#define FALSE
Definition support.h:47
#define tile_index(_pt_)
Definition tile.h:87