Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / city.h
blob91eb2e1b9733cec9a71dabd2e71685c3986b055d
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.
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
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /* utility */
21 #include "bitvector.h"
22 #include "log.h"
24 /* common */
25 #include "fc_types.h"
26 #include "name_translation.h"
27 #include "improvement.h"
28 #include "traderoutes.h"
29 #include "unitlist.h"
30 #include "vision.h"
31 #include "workertask.h"
32 #include "worklist.h"
34 enum production_class_type {
35 PCT_UNIT,
36 PCT_NORMAL_IMPROVEMENT,
37 PCT_WONDER,
38 PCT_LAST
41 /* Various city options. These are stored by the server and can be
42 * toggled by the user. Each one defaults to off. Adding new ones
43 * will break network compatibility. If you want to reorder or remove
44 * an option remember to load the city option order from the savegame.
45 * It is stored in savefile.city_options_vector
47 * Used in the network protocol.
49 #define SPECENUM_NAME city_options
50 /* If building a settler at size 1 disbands the city */
51 #define SPECENUM_VALUE0 CITYO_DISBAND
52 #define SPECENUM_VALUE0NAME "Disband"
53 /* If new citizens are science specialists */
54 #define SPECENUM_VALUE1 CITYO_SCIENCE_SPECIALISTS
55 #define SPECENUM_VALUE1NAME "Sci_Specialists"
56 /* If new citizens are gold specialists */
57 #define SPECENUM_VALUE2 CITYO_GOLD_SPECIALISTS
58 #define SPECENUM_VALUE2NAME "Tax_Specialists"
59 #define SPECENUM_COUNT CITYO_LAST
60 #define SPECENUM_BITVECTOR bv_city_options
61 #include "specenum_gen.h"
63 /* Changing the max radius requires updating network capabilities and results
64 * in incompatible savefiles. */
65 #define CITY_MAP_MIN_RADIUS 0
66 #define CITY_MAP_DEFAULT_RADIUS 2
67 #define CITY_MAP_MAX_RADIUS 5
69 /* The city includes all tiles dx^2 + dy^2 <= CITY_MAP_*_RADIUS_SQ */
70 #define CITY_MAP_DEFAULT_RADIUS_SQ \
71 (CITY_MAP_DEFAULT_RADIUS * CITY_MAP_DEFAULT_RADIUS + 1)
72 #define CITY_MAP_MIN_RADIUS_SQ \
73 (CITY_MAP_MIN_RADIUS * CITY_MAP_MIN_RADIUS + 1)
74 #define CITY_MAP_MAX_RADIUS_SQ \
75 (CITY_MAP_MAX_RADIUS * CITY_MAP_MAX_RADIUS + 1)
76 /* the id for the city center */
77 #define CITY_MAP_CENTER_RADIUS_SQ -1
78 /* the tile index of the city center */
79 #define CITY_MAP_CENTER_TILE_INDEX 0
81 /* Maximum diameter of the workable city area. */
82 #define CITY_MAP_MAX_SIZE (CITY_MAP_MAX_RADIUS * 2 + 1)
84 #define INCITE_IMPOSSIBLE_COST (1000 * 1000 * 1000)
87 * Size of the biggest possible city.
89 * The constant may be changed since it isn't externally visible.
91 * The city size is saved as unsigned char. Therefore, MAX_CITY_SIZE should
92 * be below 255!
94 #define MAX_CITY_SIZE 0xFF
96 /* Iterate a city map, from the center (the city) outwards */
97 struct iter_index {
98 int dx, dy, dist;
101 /* City map coordinates are positive integers shifted by the maximum
102 * radius the game engine allows (not the current ruleset) */
103 #define CITY_REL2ABS(_coor) (_coor + CITY_MAP_MAX_RADIUS)
104 #define CITY_ABS2REL(_coor) (_coor - CITY_MAP_MAX_RADIUS)
106 bool city_tile_index_to_xy(int *city_map_x, int *city_map_y,
107 int city_tile_index, int city_radius_sq);
108 int city_tile_xy_to_index(int city_map_x, int city_map_y,
109 int city_radius_sq);
111 int rs_max_city_radius_sq(void);
112 int city_map_radius_sq_get(const struct city *pcity);
113 void city_map_radius_sq_set(struct city *pcity, int radius_sq);
114 int city_map_tiles(int city_radius_sq);
115 #define city_map_tiles_from_city(_pcity) \
116 city_map_tiles(city_map_radius_sq_get(_pcity))
118 void citylog_map_data(enum log_level level, int radius_sq, int *map_data);
119 void citylog_map_workers(enum log_level level, struct city *pcity);
121 /* Iterate over the tiles of a city map. Starting at a given city radius
122 * (the city center is _radius_sq_min = 0) outward to the tiles of
123 * _radius_sq_max. (_x, _y) will be the valid elements of
124 * [0, CITY_MAP_MAX_SIZE] taking into account the city radius. */
125 #define city_map_iterate_outwards_radius_sq_index(_radius_sq_min, \
126 _radius_sq_max, \
127 _index, _x, _y) \
129 fc_assert(_radius_sq_min <= _radius_sq_max); \
130 int _x = 0, _y = 0, _index; \
131 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
132 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
133 _radius_sq_max)) { \
134 _index = _x##_y##_index; \
135 _x##_y##_index++;
137 #define city_map_iterate_outwards_radius_sq_index_end \
141 /* Same as above, but don't set index */
142 #define city_map_iterate_outwards_radius_sq(_radius_sq_min, \
143 _radius_sq_max, \
144 _x, _y) \
146 fc_assert(_radius_sq_min <= _radius_sq_max); \
147 int _x = 0, _y = 0; \
148 int _x##_y##_index = city_map_tiles(_radius_sq_min); \
149 while (city_tile_index_to_xy(&_x, &_y, _x##_y##_index, \
150 _radius_sq_max)) { \
151 _x##_y##_index++;
153 #define city_map_iterate_outwards_radius_sq_end \
157 /* Iterate a city map. This iterates over all city positions in the city
158 * map starting at the city center (i.e., positions that are workable by
159 * the city) using the index (_index) and the coordinates (_x, _y). It
160 * is an abbreviation for city_map_iterate_outwards_radius_sq(_end). */
161 #define city_map_iterate(_radius_sq, _index, _x, _y) \
162 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
163 _radius_sq, _index, _x, _y)
165 #define city_map_iterate_end \
166 city_map_iterate_outwards_radius_sq_index_end
168 #define city_map_iterate_without_index(_radius_sq, _x, _y) \
169 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
170 _radius_sq, _x, _y)
172 #define city_map_iterate_without_index_end \
173 city_map_iterate_outwards_radius_sq_end
175 /* Iterate the tiles between two radii of a city map. */
176 #define city_map_iterate_radius_sq(_radius_sq_min, _radius_sq_max, \
177 _x, _y) \
178 city_map_iterate_outwards_radius_sq(_radius_sq_min, _radius_sq_max, \
179 _x, _y)
181 #define city_map_iterate_radius_sq_end \
182 city_map_iterate_outwards_radius_sq_end
184 /* Iterate a city map in checked real map coordinates.
185 * _radius_sq is the squared city radius.
186 * _city_tile is the center of the (possible) city.
187 * (_index) will be the city tile index in the intervall
188 * [0, city_map_tiles(_radius_sq)] */
189 #define city_tile_iterate_index(_radius_sq, _city_tile, _tile, \
190 _index) { \
191 city_map_iterate_outwards_radius_sq_index(CITY_MAP_CENTER_RADIUS_SQ, \
192 _radius_sq, _index, _x, _y) \
193 struct tile *_tile = city_map_to_tile(_city_tile, _radius_sq, \
194 _x, _y); \
195 if (NULL != _tile) {
197 #define city_tile_iterate_index_end \
199 } city_map_iterate_outwards_radius_sq_index_end;
201 /* simple extension to skip is_free_worked() tiles. */
202 #define city_tile_iterate_skip_free_worked(_radius_sq, _city_tile, \
203 _tile, _index, _x, _y) { \
204 city_map_iterate(_radius_sq, _index, _x, _y) { \
205 if (!is_free_worked_index(_index)) { \
206 struct tile *_tile = city_map_to_tile(_city_tile, _radius_sq, \
207 _x, _y); \
208 if (NULL != _tile) {
210 #define city_tile_iterate_skip_free_worked_end \
213 } city_map_iterate_end; \
216 /* Does the same thing as city_tile_iterate_index, but keeps the city
217 * coordinates hidden. */
218 #define city_tile_iterate(_radius_sq, _city_tile, _tile) { \
219 city_map_iterate_outwards_radius_sq(CITY_MAP_CENTER_RADIUS_SQ, \
220 _radius_sq, _x, _y) \
221 struct tile *_tile = city_map_to_tile(_city_tile, _radius_sq, \
222 _x, _y); \
223 if (NULL != _tile) {
225 #define city_tile_iterate_end \
227 } city_map_iterate_outwards_radius_sq_end;
229 /* Improvement status (for cities' lists of improvements)
230 * (replaced Impr_Status) */
232 struct built_status {
233 int turn; /* turn built, negative for old state */
234 #define I_NEVER (-1) /* Improvement never built */
235 #define I_DESTROYED (-2) /* Improvement built and destroyed */
238 /* How much this output type is penalized for unhappy cities: not at all,
239 * surplus knocked down to 0, or all production removed. */
240 enum output_unhappy_penalty {
241 UNHAPPY_PENALTY_NONE,
242 UNHAPPY_PENALTY_SURPLUS,
243 UNHAPPY_PENALTY_ALL_PRODUCTION
246 struct output_type {
247 int index;
248 const char *name; /* Untranslated name */
249 const char *id; /* Identifier string (for rulesets, etc.) */
250 bool harvested; /* Is this output type gathered by city workers? */
251 enum output_unhappy_penalty unhappy_penalty;
254 enum citizen_category {
255 CITIZEN_HAPPY,
256 CITIZEN_CONTENT,
257 CITIZEN_UNHAPPY,
258 CITIZEN_ANGRY,
259 CITIZEN_LAST,
260 CITIZEN_SPECIALIST = CITIZEN_LAST,
263 /* changing this order will break network compatibility,
264 * and clients that don't use the symbols. */
265 enum citizen_feeling {
266 FEELING_BASE, /* before any of the modifiers below */
267 FEELING_LUXURY, /* after luxury */
268 FEELING_EFFECT, /* after building effects */
269 FEELING_NATIONALITY, /* after citizen nationality effects */
270 FEELING_MARTIAL, /* after units enforce martial order */
271 FEELING_FINAL, /* after wonders (final result) */
272 FEELING_LAST
275 /* Ways city output can be lost. Not currently part of network protocol. */
276 enum output_loss {
277 OLOSS_WASTE, /* regular corruption or waste */
278 OLOSS_SIZE, /* notradesize/fulltradesize */
279 OLOSS_LAST
282 /* This enumerators are used at client side only (so changing it doesn't
283 * break the compability) to mark that the city need specific gui updates
284 * (e.g. city dialog, or city report). */
285 enum city_updates {
286 CU_NO_UPDATE = 0,
287 CU_UPDATE_REPORT = 1 << 0,
288 CU_UPDATE_DIALOG = 1 << 1,
289 CU_POPUP_DIALOG = 1 << 2
292 /* See city_build_here_test(). */
293 enum city_build_result {
294 CB_OK,
295 CB_BAD_CITY_TERRAIN,
296 CB_BAD_UNIT_TERRAIN,
297 CB_BAD_BORDERS,
298 CB_NO_MIN_DIST
301 struct tile_cache; /* defined and only used within city.c */
303 struct adv_city; /* defined in ./server/advisors/infracache.h */
305 struct city {
306 char name[MAX_LEN_CITYNAME];
307 struct tile *tile; /* May be NULL, should check! */
308 struct player *owner; /* Cannot be NULL. */
309 struct player *original; /* Cannot be NULL. */
310 int id;
311 int style;
313 /* the people */
314 citizens size;
315 citizens feel[CITIZEN_LAST][FEELING_LAST];
317 /* Specialists */
318 citizens specialists[SP_MAX];
320 citizens martial_law; /* Citizens pacified by martial law. */
321 citizens unit_happy_upkeep; /* Citizens angered by military action. */
323 citizens *nationality; /* Nationality of the citizens. */
325 /* trade routes */
326 struct trade_route_list *routes;
328 /* Tile output, regardless of if the tile is actually worked. It is used
329 * as cache for the output of the tiles within the city map.
330 * (see city_tile_cache_update() and city_tile_cache_get_output()) */
331 struct tile_cache *tile_cache;
332 /* The memory allocated for tile_cache is valid for this squared city
333 * radius. */
334 int tile_cache_radius_sq;
336 /* the productions */
337 int surplus[O_LAST]; /* Final surplus in each category. */
338 int waste[O_LAST]; /* Waste/corruption in each category. */
339 int unhappy_penalty[O_LAST]; /* Penalty from unhappy cities. */
340 int prod[O_LAST]; /* Production is total minus waste and penalty. */
341 int citizen_base[O_LAST]; /* Base production from citizens. */
342 int usage[O_LAST]; /* Amount of each resource being used. */
344 /* Cached values for CPU savings. */
345 int bonus[O_LAST];
347 /* the physics */
348 int food_stock;
349 int shield_stock;
350 int pollution; /* not saved */
351 int illness_trade; /* not saved; illness due to trade; it is
352 calculated within the server and send to
353 the clients as the clients do not have all
354 information about the trade cities */
355 int turn_plague; /* last turn with an illness in the city */
356 int city_radius_sq; /* current squared city radius */
358 /* turn states */
359 int airlift;
360 bool did_buy;
361 bool did_sell;
362 bool was_happy;
364 int anarchy; /* anarchy rounds count */
365 int rapture; /* rapture rounds count */
366 int turn_founded;
367 int turn_last_built;
369 int before_change_shields; /* If changed this turn, shields before penalty */
370 int caravan_shields; /* If caravan has helped city to build wonder. */
371 int disbanded_shields; /* If you disband unit in a city. Count them */
372 int last_turns_shield_surplus; /* The surplus we had last turn. */
374 struct built_status built[B_LAST];
376 struct universal production;
378 /* If changed this turn, what we changed from */
379 struct universal changed_from;
381 struct worklist worklist;
383 bv_city_options city_options;
385 struct unit_list *units_supported;
387 int history; /* Cumulative culture */
389 struct worker_task_list *task_reqs;
391 union {
392 struct {
393 /* Only used in the server (./ai/ and ./server/). */
395 float migration_score; /* updated by city_migration_score. */
396 int mgr_score_calc_turn; /* turn the migration score was calculated */
398 int illness;
400 int steal; /* diplomats steal once; for spies, gets harder */
402 /* If > 0, workers will not be rearranged until they are unfrozen. */
403 int workers_frozen;
405 /* If set, workers need to be arranged when the city is unfrozen.
406 * Set inside auto_arrange_workers() and city_freeze_workers_queue(). */
407 bool needs_arrange;
409 /* If set, city needs to be refreshed at a later time.
410 * Set inside city_refresh() and city_refresh_queue_add(). */
411 bool needs_refresh;
413 /* the city map is synced with the client. */
414 bool synced;
416 bool debug; /* not saved */
418 struct adv_city *adv;
419 void *ais[FREECIV_AI_MOD_LAST];
421 struct vision *vision;
422 } server;
424 struct {
425 /* Only used at the client (the server is omniscient; ./client/). */
426 bool occupied;
427 int walls;
428 bool happy;
429 bool unhappy;
430 int city_image;
431 int culture;
433 /* The color is an index into the city_colors array in mapview_common */
434 bool colored;
435 int color_index;
437 /* info for dipl/spy investigation */
438 struct unit_list *info_units_supported;
439 struct unit_list *info_units_present;
440 /* Before popup the city dialog, units go there. In normal process,
441 * these pointers are set to NULL. */
442 struct unit_list *collecting_info_units_supported;
443 struct unit_list *collecting_info_units_present;
445 /* Updates needed for the city. */
446 enum city_updates need_updates;
448 unsigned char first_citizen_index;
449 } client;
453 struct citystyle {
454 struct name_translation name;
455 char graphic[MAX_LEN_NAME];
456 char graphic_alt[MAX_LEN_NAME];
457 char citizens_graphic[MAX_LEN_NAME];
458 char citizens_graphic_alt[MAX_LEN_NAME];
459 struct requirement_vector reqs;
462 extern struct citystyle *city_styles;
463 extern const Output_type_id num_output_types;
464 extern struct output_type output_types[];
466 /* get 'struct city_list' and related functions: */
467 #define SPECLIST_TAG city
468 #define SPECLIST_TYPE struct city
469 #include "speclist.h"
471 #define city_list_iterate(citylist, pcity) \
472 TYPED_LIST_ITERATE(struct city, citylist, pcity)
473 #define city_list_iterate_end LIST_ITERATE_END
475 #define cities_iterate(pcity) \
477 players_iterate(pcity##_player) { \
478 city_list_iterate(pcity##_player->cities, pcity) {
480 #define cities_iterate_end \
481 } city_list_iterate_end; \
482 } players_iterate_end; \
485 #define city_list_iterate_safe(citylist, _city) \
487 int _city##_size = city_list_size(citylist); \
489 if (_city##_size > 0) { \
490 int _city##_numbers[_city##_size]; \
491 int _city##_index = 0; \
493 city_list_iterate(citylist, _city) { \
494 _city##_numbers[_city##_index++] = _city->id; \
495 } city_list_iterate_end; \
497 for (_city##_index = 0; \
498 _city##_index < _city##_size; \
499 _city##_index++) { \
500 struct city *_city = \
501 game_city_by_number(_city##_numbers[_city##_index]); \
503 if (NULL != _city) {
505 #define city_list_iterate_safe_end \
511 /* output type functions */
513 const char *get_output_identifier(Output_type_id output);
514 const char *get_output_name(Output_type_id output);
515 struct output_type *get_output_type(Output_type_id output);
516 Output_type_id output_type_by_identifier(const char *id);
517 void add_specialist_output(const struct city *pcity, int *output);
518 void set_city_production(struct city *pcity);
520 /* properties */
522 const char *city_name_get(const struct city *pcity);
523 struct player *city_owner(const struct city *pcity);
524 struct tile *city_tile(const struct city *pcity);
526 citizens city_size_get(const struct city *pcity);
527 void city_size_add(struct city *pcity, int add);
528 void city_size_set(struct city *pcity, citizens size);
530 citizens city_specialists(const struct city *pcity);
532 citizens player_content_citizens(const struct player *pplayer);
533 citizens player_angry_citizens(const struct player *pplayer);
535 int city_population(const struct city *pcity);
536 int city_total_impr_gold_upkeep(const struct city *pcity);
537 int city_total_unit_gold_upkeep(const struct city *pcity);
538 int city_unit_unhappiness(struct unit *punit, int *free_unhappy);
539 bool city_happy(const struct city *pcity); /* generally use celebrating instead */
540 bool city_unhappy(const struct city *pcity); /* anarchy??? */
541 bool base_city_celebrating(const struct city *pcity);
542 bool city_celebrating(const struct city *pcity); /* love the king ??? */
543 bool city_rapture_grow(const struct city *pcity);
544 bool city_is_occupied(const struct city *pcity);
546 /* city related improvement and unit functions */
548 int city_improvement_upkeep(const struct city *pcity,
549 const struct impr_type *pimprove);
551 bool can_city_build_improvement_direct(const struct city *pcity,
552 struct impr_type *pimprove);
553 bool can_city_build_improvement_later(const struct city *pcity,
554 struct impr_type *pimprove);
555 bool can_city_build_improvement_now(const struct city *pcity,
556 struct impr_type *pimprove);
558 bool can_city_build_unit_direct(const struct city *pcity,
559 const struct unit_type *punittype);
560 bool can_city_build_unit_later(const struct city *pcity,
561 const struct unit_type *punittype);
562 bool can_city_build_unit_now(const struct city *pcity,
563 const struct unit_type *punittype);
565 bool can_city_build_direct(const struct city *pcity,
566 const struct universal *target);
567 bool can_city_build_later(const struct city *pcity,
568 const struct universal *target);
569 bool can_city_build_now(const struct city *pcity,
570 const struct universal *target);
572 int city_unit_slots_available(const struct city *pcity);
573 bool city_can_use_specialist(const struct city *pcity,
574 Specialist_type_id type);
575 bool city_has_building(const struct city *pcity,
576 const struct impr_type *pimprove);
577 bool is_capital(const struct city *pcity);
578 bool is_gov_center(const struct city *pcity);
579 bool city_got_defense_effect(const struct city *pcity,
580 const struct unit_type *attacker);
582 int city_production_build_shield_cost(const struct city *pcity);
583 bool city_production_build_units(const struct city *pcity,
584 bool add_production, int *num_units);
585 int city_production_buy_gold_cost(const struct city *pcity);
587 bool city_production_has_flag(const struct city *pcity,
588 enum impr_flag_id flag);
589 int city_production_turns_to_build(const struct city *pcity,
590 bool include_shield_stock);
592 bool city_production_gets_caravan_shields(const struct universal *tgt);
594 int city_change_production_penalty(const struct city *pcity,
595 const struct universal *target);
596 int city_turns_to_build(const struct city *pcity,
597 const struct universal *target,
598 bool include_shield_stock);
599 int city_turns_to_grow(const struct city *pcity);
600 bool city_can_grow_to(const struct city *pcity, int pop_size);
601 bool city_can_change_build(const struct city *pcity);
603 void city_choose_build_default(struct city *pcity);
605 /* textual representation of buildings */
607 const char *city_improvement_name_translation(const struct city *pcity,
608 struct impr_type *pimprove);
609 const char *city_production_name_translation(const struct city *pcity);
611 /* city map functions */
612 bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
613 const int city_map_y);
614 bool city_base_to_city_map(int *city_map_x, int *city_map_y,
615 const struct city *const pcity,
616 const struct tile *map_tile);
617 bool city_tile_to_city_map(int *city_map_x, int *city_map_y,
618 const int city_radius_sq,
619 const struct tile *city_center,
620 const struct tile *map_tile);
622 struct tile *city_map_to_tile(const struct tile *city_center,
623 int city_radius_sq, int city_map_x,
624 int city_map_y);
626 /* Initialization functions */
627 int compare_iter_index(const void *a, const void *b);
628 void generate_city_map_indices(void);
629 void free_city_map_index(void);
630 void city_production_caravan_shields_init(void);
632 /* output on spot */
633 int city_tile_output(const struct city *pcity, const struct tile *ptile,
634 bool is_celebrating, Output_type_id otype);
635 int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
636 Output_type_id otype);
638 bool base_city_can_work_tile(const struct player *restriction,
639 const struct city *pcity,
640 const struct tile *ptile);
641 bool city_can_work_tile(const struct city *pcity, const struct tile *ptile);
643 bool city_can_be_built_here(const struct tile *ptile,
644 const struct unit *punit);
645 enum city_build_result city_build_here_test(const struct tile *ptile,
646 const struct unit *punit);
648 /* list functions */
649 struct city *city_list_find_number(struct city_list *This, int id);
650 struct city *city_list_find_name(struct city_list *This, const char *name);
652 int city_name_compare(const void *p1, const void *p2);
654 /* city style functions */
655 const char *city_style_rule_name(const int style);
656 const char *city_style_name_translation(const int style);
658 int city_style_by_rule_name(const char *s);
659 int city_style_by_translated_name(const char *s);
661 struct city *is_enemy_city_tile(const struct tile *ptile,
662 const struct player *pplayer);
663 struct city *is_allied_city_tile(const struct tile *ptile,
664 const struct player *pplayer);
665 struct city *is_non_attack_city_tile(const struct tile *ptile,
666 const struct player *pplayer);
667 struct city *is_non_allied_city_tile(const struct tile *ptile,
668 const struct player *pplayer);
670 bool is_unit_near_a_friendly_city(const struct unit *punit);
671 bool is_friendly_city_near(const struct player *owner,
672 const struct tile *ptile);
673 bool city_exists_within_max_city_map(const struct tile *ptile,
674 bool may_be_on_center);
676 /* granary size as a function of city size */
677 int city_granary_size(int city_size);
679 void city_add_improvement(struct city *pcity,
680 const struct impr_type *pimprove);
681 void city_remove_improvement(struct city *pcity,
682 const struct impr_type *pimprove);
684 /* city update functions */
685 void city_refresh_from_main_map(struct city *pcity, bool *workers_map);
687 int city_waste(const struct city *pcity, Output_type_id otype, int total,
688 int *breakdown);
689 Specialist_type_id best_specialist(Output_type_id otype,
690 const struct city *pcity);
691 int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype);
692 bool city_built_last_turn(const struct city *pcity);
694 /* city creation / destruction */
695 struct city *create_city_virtual(struct player *pplayer,
696 struct tile *ptile, const char *name);
697 void destroy_city_virtual(struct city *pcity);
698 bool city_is_virtual(const struct city *pcity);
700 /* misc */
701 bool is_city_option_set(const struct city *pcity, enum city_options option);
702 void city_styles_alloc(int num);
703 void city_styles_free(void);
705 void add_tax_income(const struct player *pplayer, int trade, int *output);
706 int get_city_tithes_bonus(const struct city *pcity);
707 int city_pollution_types(const struct city *pcity, int shield_total,
708 int *pollu_prod, int *pollu_pop, int *pollu_mod);
709 int city_pollution(const struct city *pcity, int shield_total);
710 int city_illness_calc(const struct city *pcity, int *ill_base,
711 int *ill_size, int *ill_trade, int *ill_pollution);
712 bool city_had_recent_plague(const struct city *pcity);
713 int city_build_slots(const struct city *pcity);
714 int city_airlift_max(const struct city *pcity);
716 bool city_exist(int id);
719 * Iterates over all improvements, skipping those not yet built in the
720 * given city.
722 #define city_built_iterate(_pcity, _p) \
723 improvement_iterate(_p) { \
724 if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
725 continue; \
728 #define city_built_iterate_end \
729 } improvement_iterate_end;
732 /* Iterates over all output types in the game. */
733 #define output_type_iterate(output) \
735 Output_type_id output; \
737 for (output = 0; output < O_LAST; output++) {
739 #define output_type_iterate_end \
744 /* === */
746 bool is_city_center(const struct city *pcity, const struct tile *ptile);
747 bool is_free_worked(const struct city *pcity, const struct tile *ptile);
749 #define is_free_worked_index(city_tile_index) \
750 (CITY_MAP_CENTER_TILE_INDEX == city_tile_index)
751 #define FREE_WORKED_TILES (1)
753 void *city_ai_data(const struct city *pcity, const struct ai_type *ai);
754 void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
755 void *data);
757 #ifdef __cplusplus
759 #endif /* __cplusplus */
761 #endif /* FC__CITY_H */