Freeciv21
Develop your civilization from humble roots to a global empire
citytools.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // common
16 #include "events.h" // enum event_type
17 #include "packets.h"
18 #include "unitlist.h"
19 #include "workertask.h"
20 
21 #define LOG_BUILD_TARGET LOG_DEBUG
22 
23 #define SPECLIST_TAG traderoute_packet
24 #define SPECLIST_TYPE struct packet_traderoute_info
25 #include "speclist.h"
26 #define traderoute_packet_list_iterate(ptrlist, ptr) \
27  TYPED_LIST_ITERATE(struct packet_traderoute_info, ptrlist, ptr)
28 #define traderoute_packet_list_iterate_end LIST_ITERATE_END
29 
30 int build_points_left(struct city *pcity);
31 
32 void transfer_city_units(struct player *pplayer, struct player *pvictim,
33  struct unit_list *units, struct city *pcity,
34  struct city *exclude_city, int kill_outside,
35  bool verbose);
36 bool transfer_city(struct player *ptaker, struct city *pcity,
37  int kill_outside, bool transfer_unit_verbose,
38  bool resolve_stack, bool raze, bool build_free);
39 struct city *find_closest_city(const struct tile *ptile,
40  const struct city *pexclcity,
41  const struct player *pplayer, bool only_ocean,
42  bool only_continent, bool only_known,
43  bool only_player, bool only_enemy,
44  const struct unit_class *pclass);
45 bool unit_conquer_city(struct unit *punit, struct city *pcity);
46 
47 bool send_city_suppression(bool now);
48 void send_city_info(struct player *dest, struct city *pcity);
49 void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest,
50  struct city *pcity, struct tile *ptile);
51 void send_all_known_cities(struct conn_list *dest);
52 void send_player_cities(struct player *pplayer);
53 void package_city(struct city *pcity, struct packet_city_info *packet,
54  struct traderoute_packet_list *routes, bool dipl_invest);
55 
56 void reality_check_city(struct player *pplayer, struct tile *ptile);
57 bool update_dumb_city(struct player *pplayer, struct city *pcity);
58 void refresh_dumb_city(struct city *pcity);
59 void remove_dumb_city(struct player *pplayer, struct tile *ptile);
60 
61 void city_build_free_buildings(struct city *pcity);
62 
63 void create_city(struct player *pplayer, struct tile *ptile,
64  const char *name, struct player *nationality);
65 void remove_city(struct city *pcity);
66 
67 struct trade_route *remove_trade_route(struct city *pc1,
68  struct trade_route *proute,
69  bool announce, bool source_gone);
70 
71 void city_illness_strike(struct city *pcity);
72 
73 void do_sell_building(struct player *pplayer, struct city *pcity,
74  struct impr_type *pimprove, const char *reason);
75 bool building_removed(struct city *pcity, const struct impr_type *pimprove,
76  const char *reason, struct unit *destroyer);
77 void building_lost(struct city *pcity, const struct impr_type *pimprove,
78  const char *reason, struct unit *destroyer);
79 void city_units_upkeep(const struct city *pcity);
80 
81 void change_build_target(struct player *pplayer, struct city *pcity,
82  struct universal *target, enum event_type event);
83 
84 bool is_allowed_city_name(struct player *pplayer, const char *cityname,
85  char *error_buf, size_t bufsz);
86 const char *city_name_suggestion(struct player *pplayer, struct tile *ptile);
87 
88 void city_freeze_workers(struct city *pcity);
89 void city_thaw_workers(struct city *pcity);
90 void city_freeze_workers_queue(struct city *pcity);
92 
93 // city map functions
94 void city_map_update_empty(struct city *pcity, struct tile *ptile);
95 void city_map_update_worker(struct city *pcity, struct tile *ptile);
96 
97 bool city_map_update_tile_frozen(struct tile *ptile);
98 bool city_map_update_tile_now(struct tile *ptile);
99 
100 void city_map_update_all(struct city *pcity);
101 void city_map_update_all_cities_for_player(struct player *pplayer);
102 
103 bool city_map_update_radius_sq(struct city *pcity);
104 
106 void city_refresh_vision(struct city *pcity);
107 void refresh_player_cities_vision(struct player *pplayer);
108 
109 void sync_cities();
110 
111 void clear_worker_task(struct city *pcity, struct worker_task *ptask);
112 void clear_worker_tasks(struct city *pcity);
113 void package_and_send_worker_tasks(struct city *pcity);
114 
115 int city_production_buy_gold_cost(const struct city *pcity);
116 
117 void city_did_prod_change(struct city *pcity);
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Change from worked to empty.
Definition: citytools.cpp:3079
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Remove the trade route between pc1 and pc2 (if one exists).
Definition: citytools.cpp:2791
void city_freeze_workers_queue(struct city *pcity)
Queue pending auto_arrange_workers() for later.
Definition: citytools.cpp:141
bool city_map_update_tile_now(struct tile *ptile)
Updates the worked status of a tile immediately.
Definition: citytools.cpp:3141
void package_and_send_worker_tasks(struct city *pcity)
Send city worker task to owner.
Definition: citytools.cpp:3433
int city_production_buy_gold_cost(const struct city *pcity)
Return the cost (gold) to buy the current city production.
Definition: citytools.cpp:3459
void city_did_prod_change(struct city *pcity)
City did something to change production.
Definition: citytools.cpp:3068
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Find the city closest to 'ptile'.
Definition: citytools.cpp:849
void send_city_info(struct player *dest, struct city *pcity)
A wrapper, accessing either broadcast_city_info() (dest == nullptr), or a convenience case of send_ci...
Definition: citytools.cpp:2295
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Updates a players knowledge about a city.
Definition: citytools.cpp:2637
void city_freeze_workers(struct city *pcity)
Freeze the workers (citizens on tiles) for the city.
Definition: citytools.cpp:118
void city_build_free_buildings(struct city *pcity)
Give to a new city the free (initial) buildings.
Definition: citytools.cpp:1433
void city_thaw_workers_queue()
Process the frozen workers.
Definition: citytools.cpp:171
void city_illness_strike(struct city *pcity)
Give the city a plague.
Definition: citytools.cpp:2829
const char * city_name_suggestion(struct player *pplayer, struct tile *ptile)
Come up with a default name when a new city is about to be built.
Definition: citytools.cpp:451
void refresh_dumb_city(struct city *pcity)
Update plrtile information about the city, and send out information to the clients if it has changed.
Definition: citytools.cpp:2163
void create_city(struct player *pplayer, struct tile *ptile, const char *name, struct player *nationality)
Creates real city.
Definition: citytools.cpp:1512
bool send_city_suppression(bool now)
Suppress sending cities during game_load() and end_phase()
Definition: citytools.cpp:2127
void refresh_player_cities_vision(struct player *pplayer)
Refresh the vision of all cities owned by a player, for empire-wide effects.
Definition: citytools.cpp:3277
bool city_map_update_radius_sq(struct city *pcity)
Updates the squared city radius.
Definition: citytools.cpp:3286
int build_points_left(struct city *pcity)
Calculate the remaining build points.
Definition: citytools.cpp:575
void change_build_target(struct player *pplayer, struct city *pcity, struct universal *target, enum event_type event)
Change the build target.
Definition: citytools.cpp:2986
bool building_removed(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Remove building from the city.
Definition: citytools.cpp:2861
void city_map_update_all_cities_for_player(struct player *pplayer)
Update worked map of all cities of given player.
Definition: citytools.cpp:3189
bool city_map_update_tile_frozen(struct tile *ptile)
Updates the worked status of a tile.
Definition: citytools.cpp:3133
void city_thaw_workers(struct city *pcity)
Thaw (unfreeze) the workers (citizens on tiles) for the city.
Definition: citytools.cpp:128
void remove_dumb_city(struct player *pplayer, struct tile *ptile)
Removes a dumb city.
Definition: citytools.cpp:2722
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Destroy the improvement in the city straight-out.
Definition: citytools.cpp:2878
bool unit_conquer_city(struct unit *punit, struct city *pcity)
Handle unit conquering a city.
Definition: citytools.cpp:1961
void clear_worker_task(struct city *pcity, struct worker_task *ptask)
Clear worker task from the city and inform owner.
Definition: citytools.cpp:3397
void city_units_upkeep(const struct city *pcity)
Recalculate the upkeep needed for all units supported by the city.
Definition: citytools.cpp:2927
void clear_worker_tasks(struct city *pcity)
Clear all worker tasks from the city and inform owner.
Definition: citytools.cpp:3423
bool is_allowed_city_name(struct player *pplayer, const char *cityname, char *error_buf, size_t bufsz)
Checks, if a city name is allowed for a player.
Definition: citytools.cpp:356
void city_landlocked_sell_coastal_improvements(struct tile *ptile)
For each city adjacent to ptile, check all the buildings in the city.
Definition: citytools.cpp:3210
void remove_city(struct city *pcity)
Remove a city from the game.
Definition: citytools.cpp:1676
void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason)
Sell the improvement from the city, and give the player the owner.
Definition: citytools.cpp:2849
void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, struct city *pcity, struct tile *ptile)
Send info about a city, as seen by pviewer, to dest (usually dest will be pviewer->connections).
Definition: citytools.cpp:2344
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Handles all transactions in relation to transferring a city.
Definition: citytools.cpp:1084
void package_city(struct city *pcity, struct packet_city_info *packet, struct traderoute_packet_list *routes, bool dipl_invest)
Fill city info packet with information about given city.
Definition: citytools.cpp:2438
void send_player_cities(struct player *pplayer)
Send information about all his/her cities to player.
Definition: citytools.cpp:2274
void city_map_update_all(struct city *pcity)
Called by auto_arrange_workers() and below.
Definition: citytools.cpp:3173
void transfer_city_units(struct player *pplayer, struct player *pvictim, struct unit_list *units, struct city *pcity, struct city *exclude_city, int kill_outside, bool verbose)
When a city is transferred (bought, incited, disbanded, civil war): Units in a transferred city are t...
Definition: citytools.cpp:708
void city_map_update_worker(struct city *pcity, struct tile *ptile)
Change from empty to worked.
Definition: citytools.cpp:3091
void sync_cities()
Make sure all players (clients) have up-to-date information about all their cities.
Definition: citytools.cpp:3150
void reality_check_city(struct player *pplayer, struct tile *ptile)
Removes outdated (nonexistant) cities from a player.
Definition: citytools.cpp:2704
void send_all_known_cities(struct conn_list *dest)
Send to each client information about the cities it knows about.
Definition: citytools.cpp:2248
void city_refresh_vision(struct city *pcity)
Refresh the city's vision.
Definition: citytools.cpp:3261
enum announce_type announce
enum event_type event
Definition: events.cpp:68
const char * name
Definition: inputfile.cpp:118
Definition: city.h:291
struct trade_route_list * routes
Definition: city.h:313
citizens * nationality
Definition: city.h:310
Definition: player.h:231
Definition: tile.h:42
Definition: unit.h:134