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 compability) 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);
588bool city_happy(const struct city *pcity); /* generally use celebrating instead */
589bool city_unhappy(const struct city *pcity); /* anarchy??? */
590bool base_city_celebrating(const struct city *pcity);
591bool city_celebrating(const struct city *pcity); /* love the king ??? */
592bool city_rapture_grow(const struct city *pcity);
593bool city_is_occupied(const struct city *pcity);
594
595/* city related improvement and unit functions */
596
597int city_improvement_upkeep(const struct city *pcity,
598 const struct impr_type *pimprove);
599
600bool can_city_build_improvement_direct(const struct city *pcity,
601 const struct impr_type *pimprove);
602bool can_city_build_improvement_later(const struct city *pcity,
603 const struct impr_type *pimprove);
604bool can_city_build_improvement_now(const struct city *pcity,
605 const struct impr_type *pimprove);
606
607bool can_city_build_unit_direct(const struct city *pcity,
608 const struct unit_type *punittype);
609bool can_city_build_unit_later(const struct city *pcity,
610 const struct unit_type *punittype);
611bool can_city_build_unit_now(const struct city *pcity,
612 const struct unit_type *punittype);
613
614bool can_city_build_direct(const struct city *pcity,
615 const struct universal *target);
616bool can_city_build_later(const struct city *pcity,
617 const struct universal *target);
618bool can_city_build_now(const struct city *pcity,
619 const struct universal *target);
620
621int city_unit_slots_available(const struct city *pcity);
622bool city_can_use_specialist(const struct city *pcity,
624bool city_has_building(const struct city *pcity,
625 const struct impr_type *pimprove);
626bool is_capital(const struct city *pcity);
627bool is_gov_center(const struct city *pcity);
628bool city_got_defense_effect(const struct city *pcity,
629 const struct unit_type *attacker);
630
631int city_production_build_shield_cost(const struct city *pcity);
632bool city_production_build_units(const struct city *pcity,
633 bool add_production, int *num_units);
635 const struct unit_type *punittype);
636
637bool city_production_is_genus(const struct city *pcity,
638 enum impr_genus_id genus);
639bool city_production_has_flag(const struct city *pcity,
640 enum impr_flag_id flag);
641int city_production_turns_to_build(const struct city *pcity,
643
644bool city_production_gets_caravan_shields(const struct universal *tgt);
645
646int city_change_production_penalty(const struct city *pcity,
647 const struct universal *target);
648int city_turns_to_build(const struct city *pcity,
649 const struct universal *target,
651int city_turns_to_grow(const struct city *pcity);
652bool city_can_grow_to(const struct city *pcity, int pop_size);
653bool city_can_change_build(const struct city *pcity);
654
655void city_choose_build_default(struct city *pcity);
656
657/* textual representation of buildings */
658
659const char *city_improvement_name_translation(const struct city *pcity,
660 const struct impr_type *pimprove);
661const char *city_production_name_translation(const struct city *pcity);
662
663/* city map functions */
664bool is_valid_city_coords(const int city_radius_sq, const int city_map_x,
665 const int city_map_y);
666bool city_map_includes_tile(const struct city *const pcity,
667 const struct tile *map_tile);
669 const struct city *const pcity,
670 const struct tile *map_tile);
672 const int city_radius_sq,
673 const struct tile *city_center,
674 const struct tile *map_tile);
675
676struct tile *city_map_to_tile(const struct civ_map *nmap,
677 const struct tile *city_center,
678 int city_radius_sq, int city_map_x,
679 int city_map_y);
680
681/* Initialization functions */
682int compare_iter_index(const void *a, const void *b);
684void free_city_map_index(void);
686
687/* Output on spot */
688int city_tile_output(const struct city *pcity, const struct tile *ptile,
690int city_tile_output_now(const struct city *pcity, const struct tile *ptile,
692
694 const struct city *pcity,
695 const struct tile *ptile);
696bool city_can_work_tile(const struct city *pcity, const struct tile *ptile);
697
699 const struct tile *ptile);
700
701bool city_can_be_built_here(const struct tile *ptile,
702 const struct unit *punit,
703 bool hut_test);
704bool city_can_be_built_tile_only(const struct civ_map *nmap,
705 const struct tile *ptile);
706
707/* List functions */
708struct city *city_list_find_number(struct city_list *This, int id);
709struct city *city_list_find_name(struct city_list *This, const char *name);
710
711int city_name_compare(const void *p1, const void *p2);
712
713/* City style functions */
714const char *city_style_rule_name(const int style);
715const char *city_style_name_translation(const int style);
716
717int city_style_by_rule_name(const char *s);
718int city_style_by_translated_name(const char *s);
719
720struct city *tile_enemy_city(const struct tile *ptile,
721 const struct player *pplayer);
722
723/**********************************************************************/
726static inline bool is_enemy_city_tile(const struct tile *ptile,
727 const struct player *pplayer)
728{
729 return NULL != tile_enemy_city(ptile, pplayer);
730}
731
732struct city *tile_allied_city(const struct tile *ptile,
733 const struct player *pplayer);
734
735/**********************************************************************/
738static inline bool is_allied_city_tile(const struct tile *ptile,
739 const struct player *pplayer)
740{
741 return NULL != tile_allied_city(ptile, pplayer);
742}
743
744struct city *tile_non_attack_city(const struct tile *ptile,
745 const struct player *pplayer);
746
747/**********************************************************************/
750static inline bool is_non_attack_city_tile(const struct tile *ptile,
751 const struct player *pplayer)
752{
753 return NULL != tile_non_attack_city(ptile, pplayer);
754}
755
756struct city *tile_non_allied_city(const struct tile *ptile,
757 const struct player *pplayer);
758
759/**********************************************************************/
762static inline bool is_non_allied_city_tile(const struct tile *ptile,
763 const struct player *pplayer)
764{
765 return NULL != tile_non_allied_city(ptile, pplayer);
766}
767
768bool is_unit_near_a_friendly_city(const struct unit *punit,
769 int distance);
770bool is_friendly_city_near(const struct player *owner,
771 const struct tile *ptile,
772 int distance);
773bool city_exists_within_max_city_map(const struct tile *ptile,
774 bool may_be_on_center);
775
776/* Granary size as a function of city size */
777int city_granary_size(int city_size);
778
779void city_add_improvement(struct city *pcity,
780 const struct impr_type *pimprove);
781void city_remove_improvement(struct city *pcity,
782 const struct impr_type *pimprove);
783
784/* city update functions */
785void city_refresh_from_main_map(struct city *pcity, bool *workers_map);
786
787int city_waste(const struct city *pcity, Output_type_id otype, int total,
788 int *breakdown);
790 const struct city *pcity);
791int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype);
792bool city_built_last_turn(const struct city *pcity);
793
794/* city creation / destruction */
795struct city *create_city_virtual(struct player *pplayer,
796 struct tile *ptile, const char *name);
797void destroy_city_virtual(struct city *pcity);
798bool city_is_virtual(const struct city *pcity);
799
800/* misc */
801bool is_city_option_set(const struct city *pcity, enum city_options option);
802void city_styles_alloc(int num);
803void city_styles_free(void);
804
805void add_tax_income(const struct player *pplayer, int trade, int *output);
806int get_city_tithes_bonus(const struct city *pcity);
807int city_pollution_types(const struct city *pcity, int shield_total,
808 int *pollu_prod, int *pollu_pop, int *pollu_mod);
809int city_pollution(const struct city *pcity, int shield_total);
810int city_illness_calc(const struct city *pcity, int *ill_base,
811 int *ill_size, int *ill_trade, int *ill_pollution);
812bool city_had_recent_plague(const struct city *pcity);
813int city_build_slots(const struct city *pcity);
814int city_airlift_max(const struct city *pcity);
815
816bool city_exist(int id);
817
818/*
819 * Iterates over all improvements, skipping those not yet built in the
820 * given city.
821 */
822#define city_built_iterate(_pcity, _p) \
823 improvement_iterate(_p) { \
824 if ((_pcity)->built[improvement_index(_p)].turn <= I_NEVER) { \
825 continue; \
826 }
827
828#define city_built_iterate_end \
829 } improvement_iterate_end;
830
831
832/* Iterates over all output types in the game. */
833#define output_type_iterate(output) \
834{ \
835 Output_type_id output; \
836 \
837 for (output = 0; output < O_LAST; output++) {
838
839#define output_type_iterate_end \
840 } \
841}
842
843
844/* === */
845
846/**********************************************************************/
856static inline bool is_city_center(const struct city *pcity,
857 const struct tile *ptile)
858{
859 if (!pcity || !pcity->tile || !ptile) {
860 return FALSE;
861 }
862
863 return tile_index(city_tile(pcity)) == tile_index(ptile);
864}
865
866bool is_free_worked(const struct city *pcity, const struct tile *ptile);
867
868#define is_free_worked_index(city_tile_index) \
869 (CITY_MAP_CENTER_TILE_INDEX == city_tile_index)
870#define FREE_WORKED_TILES (1)
871
872void *city_ai_data(const struct city *pcity, const struct ai_type *ai);
873void city_set_ai_data(struct city *pcity, const struct ai_type *ai,
874 void *data);
875
876void city_rally_point_clear(struct city *pcity);
877void city_rally_point_receive(const struct packet_city_rally_point *packet,
878 struct city *pcity)
879 fc__attribute((nonnull (1)));
880
881#ifdef __cplusplus
882}
883#endif /* __cplusplus */
884
885#endif /* FC__CITY_H */
bool base_city_celebrating(const struct city *pcity)
Definition city.c:1629
static bool is_non_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:762
bool city_is_virtual(const struct city *pcity)
Definition city.c:3577
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:1957
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:662
bool city_exists_within_max_city_map(const struct tile *ptile, bool may_be_on_center)
Definition city.c:2102
bool is_free_worked(const struct city *pcity, const struct tile *ptile)
Definition city.c:3589
static bool is_non_attack_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:750
#define city_tile(_pcity_)
Definition city.h:564
bool city_production_gets_caravan_shields(const struct universal *tgt)
Definition city.c:1852
bool is_friendly_city_near(const struct player *owner, const struct tile *ptile, int distance)
Definition city.c:2083
void city_map_radius_sq_set(struct city *pcity, int radius_sq)
Definition city.c:147
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:736
void city_name_set(struct city *pcity, const char *new_name)
Definition city.c:1136
bool can_city_build_unit_later(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:965
static bool is_enemy_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:726
int city_granary_size(int city_size)
Definition city.c:2123
citizens player_angry_citizens(const struct player *pplayer)
Definition city.c:2187
int city_pollution_types(const struct city *pcity, int shield_total, int *pollu_prod, int *pollu_pop, int *pollu_mod)
Definition city.c:2778
void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data)
Definition city.c:3605
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 city_built_last_turn(const struct city *pcity)
Definition city.c:2270
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Definition city.c:1006
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:3216
int city_unit_unhappiness(struct unit *punit, int *free_unhappy)
Definition city.c:3040
void generate_city_map_indices(void)
Definition city.c:526
int city_build_slots(const struct city *pcity)
Definition city.c:2923
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:304
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1231
const char * city_style_name_translation(const int style)
Definition city.c:1748
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:3399
void city_rally_point_receive(const struct packet_city_rally_point *packet, struct city *pcity) fc__attribute((nonnull(1)))
Definition city.c:3629
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:646
bool is_capital(const struct city *pcity)
Definition city.c:1571
struct citystyle * city_styles
Definition city.c:83
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1246
void city_styles_alloc(int num)
Definition city.c:3384
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
bool base_city_can_work_tile(const struct player *restriction, const struct city *pcity, const struct tile *ptile)
Definition city.c:1392
int city_unit_slots_available(const struct city *pcity)
Definition city.c:1040
static bool is_allied_city_tile(const struct tile *ptile, const struct player *pplayer)
Definition city.h:738
void city_production_caravan_shields_init(void)
Definition city.c:1770
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3359
int city_airlift_max(const struct city *pcity)
Definition city.c:2933
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1478
bool citymindist_prevents_city_on_tile(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1456
struct output_type * get_output_type(Output_type_id output)
Definition city.c:637
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3376
int city_population(const struct city *pcity)
Definition city.c:1182
const char * city_style_rule_name(const int style)
Definition city.c:1757
void city_size_add(struct city *pcity, int add)
Definition city.c:1155
bool city_can_use_specialist(const struct city *pcity, Specialist_type_id type)
Definition city.c:1056
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Definition city.c:726
bool city_is_occupied(const struct city *pcity)
Definition city.c:1657
void free_city_map_index(void)
Definition city.c:608
void city_refresh_from_main_map(struct city *pcity, bool *workers_map)
Definition city.c:3165
int city_production_unit_veteran_level(struct city *pcity, const struct unit_type *punittype)
Definition city.c:803
void add_tax_income(const struct player *pplayer, int trade, int *output)
Definition city.c:2236
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:853
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:100
struct city * tile_non_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2058
bool city_got_defense_effect(const struct city *pcity, const struct unit_type *attacker)
Definition city.c:1588
citizens player_content_citizens(const struct player *pplayer)
Definition city.c:2177
bool city_map_includes_tile(const struct city *const pcity, const struct tile *map_tile)
Definition city.c:292
int get_city_tithes_bonus(const struct city *pcity)
Definition city.c:2218
void citylog_map_data(enum log_level level, int radius_sq, int *map_data)
Definition city.c:410
bool city_rapture_grow(const struct city *pcity)
Definition city.c:1645
static bool is_city_center(const struct city *pcity, const struct tile *ptile)
Definition city.h:856
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Definition city.c:819
bool city_unhappy(const struct city *pcity)
Definition city.c:1618
Specialist_type_id best_specialist(Output_type_id otype, const struct city *pcity)
Definition city.c:3322
struct city * create_city_virtual(struct player *pplayer, struct tile *ptile, const char *name)
Definition city.c:3418
void set_city_production(struct city *pcity)
Definition city.c:2944
struct city * city_list_find_number(struct city_list *This, int id)
Definition city.c:1671
int get_final_city_output_bonus(const struct city *pcity, Output_type_id otype)
Definition city.c:2203
bool city_celebrating(const struct city *pcity)
Definition city.c:1637
bool city_can_be_built_tile_only(const struct civ_map *nmap, const struct tile *ptile)
Definition city.c:1552
bool can_city_build_improvement_direct(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:829
const char * get_output_identifier(Output_type_id output)
Definition city.c:618
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2861
const char * get_output_name(Output_type_id output)
Definition city.c:628
bool city_can_grow_to(const struct city *pcity, int pop_size)
Definition city.c:2004
int city_change_production_penalty(const struct city *pcity, const struct universal *target)
Definition city.c:1878
bool is_valid_city_coords(const int city_radius_sq, const int city_map_x, const int city_map_y)
Definition city.c:187
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
int city_pollution(const struct city *pcity, int shield_total)
Definition city.c:2812
bool city_happy(const struct city *pcity)
Definition city.c:1606
void city_size_set(struct city *pcity, citizens size)
Definition city.c:1171
void city_add_improvement(struct city *pcity, const struct impr_type *pimprove)
Definition city.c:3345
int city_tile_output_now(const struct city *pcity, const struct tile *ptile, Output_type_id otype)
Definition city.c:1375
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:136
bool can_city_build_direct(const struct city *pcity, const struct universal *target)
Definition city.c:988
struct city * tile_allied_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2028
struct city * tile_enemy_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2013
void citylog_map_workers(enum log_level level, struct city *pcity)
Definition city.c:445
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:280
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:3504
int rs_max_city_radius_sq(void)
Definition city.c:158
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:263
citizens city_specialists(const struct city *pcity)
Definition city.c:3305
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
void city_choose_build_default(struct city *pcity)
Definition city.c:1078
int city_style_by_translated_name(const char *s)
Definition city.c:1713
void add_specialist_output(const struct city *pcity, int *output)
Definition city.c:2355
void * city_ai_data(const struct city *pcity, const struct ai_type *ai)
Definition city.c:3597
struct city * city_list_find_name(struct city_list *This, const char *name)
Definition city.c:1687
bool can_city_build_later(const struct city *pcity, const struct universal *target)
Definition city.c:1023
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1274
int city_tile_xy_to_index(int city_map_x, int city_map_y, int city_radius_sq)
Definition city.c:122
bool is_gov_center(const struct city *pcity)
Definition city.c:1579
int city_map_tiles(int city_radius_sq)
Definition city.c:170
bool can_city_build_unit_direct(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:902
struct city * tile_non_attack_city(const struct tile *ptile, const struct player *pplayer)
Definition city.c:2043
bool is_unit_near_a_friendly_city(const struct unit *punit, int distance)
Definition city.c:2073
bool city_exist(int id)
Definition city.c:3560
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1447
bool city_production_is_genus(const struct city *pcity, enum impr_genus_id genus)
Definition city.c:716
int compare_iter_index(const void *a, const void *b)
Definition city.c:342
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:746
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1988
void city_rally_point_clear(struct city *pcity)
Definition city.c:3614
struct output_type output_types[]
Definition city.c:87
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:870
bool city_had_recent_plague(const struct city *pcity)
Definition city.c:2914
bool city_can_change_build(const struct city *pcity)
Definition city.c:1070
int city_total_unit_gold_upkeep(const struct city *pcity)
Definition city.c:1213
int city_style_by_rule_name(const char *s)
Definition city.c:1730
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1703
int city_total_impr_gold_upkeep(const struct city *pcity)
Definition city.c:1192
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Definition city.c:945
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:699
char * incite_cost
Definition comments.c:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
unsigned char citizens
Definition fc_types.h:391
#define SP_MAX
Definition fc_types.h:412
int Specialist_type_id
Definition fc_types.h:378
#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:381
struct city * owner
Definition citydlg.c:220
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