74 struct unit old_unit = *punit;
78 log_debug(
"removing unit %d, %s %s (%d %d) hcity %d", punit->
id,
106 if (
nullptr != pcity) {
119 if (
nullptr != pcity) {
138 struct city old_city = *pcity;
144 effect_update =
false;
148 effect_update =
true;
158 dialog && pcity->
id == dialog->id) {
170 const struct player *them)
177 return Q_(
"?embassy:Both");
179 return Q_(
"?embassy:Yes");
182 return Q_(
"?embassy:With Us");
185 return Q_(
"?embassy:Contact");
187 return Q_(
"?embassy:No Contact");
195 const struct player *them)
199 return Q_(
"?vision:Both");
201 return Q_(
"?vision:To Them");
204 return Q_(
"?vision:To Us");
218 switch (pclause->
type) {
231 fc_snprintf(buf, bufsiz,
_(
"The %s give an unknown city"),
238 PL_(
"The %s give %d gold",
"The %s give %d gold", pclause->
value),
242 fc_snprintf(buf, bufsiz,
_(
"The %s give their worldmap"),
249 case CLAUSE_CEASEFIRE:
250 fc_snprintf(buf, bufsiz,
_(
"The parties agree on a cease-fire"));
253 fc_snprintf(buf, bufsiz,
_(
"The parties agree on a peace"));
255 case CLAUSE_ALLIANCE:
256 fc_snprintf(buf, bufsiz,
_(
"The parties create an alliance"));
259 fc_snprintf(buf, bufsiz,
_(
"The %s give shared vision"),
281 int accum,
int level)
284 int numer = 20 * max;
289 CLIP(0, (
int) ((((
long) accum * numer) + (denom - 1)) / denom), max);
292 *rate =
DIVIDE(((
long) (current -
level) * numer) + (denom - 1), denom);
325 / (presearch->
client.researching_cost + 1));
448 return VUT_UTYPE == target.
kind
470 .kind = VUT_IMPROVEMENT};
483 target.
kind = VUT_UTYPE;
486 target.kind = VUT_IMPROVEMENT;
500 if (VUT_UTYPE == target->
kind) {
521 if (VUT_UTYPE == target->
kind) {
541 return VUT_IMPROVEMENT == target->
kind
550 if (VUT_UTYPE == target.
kind) {
572 static int fc_cmp(
const void *p1,
const void *p2)
574 const struct item *i1 =
static_cast<const item *
>(p1),
575 *i2 =
static_cast<const item *
>(p2);
597 struct item *items,
bool show_cost,
602 for (i = 0; i < num_targets; i++) {
605 struct item *pitem = &items[i];
608 pitem->
item = target;
610 if (VUT_UTYPE == target.
kind) {
618 if (pcity !=
nullptr) {
640 qsort(items, num_targets,
sizeof(
struct item),
fc_cmp);
649 struct city **selected_cities,
650 int num_selected_cities,
bool append_units,
651 bool append_wonders,
bool change_prod,
659 for (
id = first;
id < last;
id++) {
682 for (i = 0; i < num_selected_cities; i++) {
683 append |=
test_func(selected_cities[i], &target);
691 targets[items_used] = target;
711 bool can_eventually_build;
713 if (
nullptr != pcity) {
716 can_eventually_build =
718 }
else if (
nullptr != pplayer) {
721 can_eventually_build =
735 can_eventually_build =
false;
739 can_eventually_build =
true;
746 if ((advanced_tech && can_eventually_build)
747 || (!advanced_tech && can_build)) {
748 targets[cids_used].
kind = VUT_IMPROVEMENT;
758 bool can_eventually_build;
760 if (
nullptr != pcity) {
764 }
else if (
nullptr != pplayer) {
780 can_eventually_build =
false;
784 can_eventually_build =
true;
791 if ((advanced_tech && can_eventually_build)
792 || (!advanced_tech && can_build)) {
793 targets[cids_used].
kind = VUT_UTYPE;
815 targets[cids_used].
kind = VUT_IMPROVEMENT;
828 enum event_type
event,
int turn,
int phase,
int conn_id)
831 struct text_tag_list *tags;
833 bool fallback_needed =
false;
837 if (!event_type_is_valid(
event)) {
839 qDebug(
"Unknown event type %d!",
event);
846 &tags, conn_id != -1);
864 size_t userlen = qstrlen(username);
868 size_t playerlen = playername ? qstrlen(playername) : 0;
871 if (playername && playername[0] ==
'\0') {
872 playername =
nullptr;
875 if (username && username[0] ==
'\0') {
879 for (p = plain_text; *p !=
'\0'; p++) {
880 if (
nullptr != username && 0 ==
fc_strncasecmp(p, username, userlen)) {
887 if (ptag !=
nullptr) {
889 text_tag_list_append(tags, ptag);
891 }
else if (
nullptr != playername
894 TTT_COLOR, p - plain_text, p - plain_text + playerlen,
899 if (ptag !=
nullptr) {
901 text_tag_list_append(tags, ptag);
912 ||
event == E_MESSAGE_WALL) {
919 fallback_needed =
true;
931 fallback_needed =
true;
945 text_tag_list_destroy(tags);
958 va_start(ap, format);
988 pcity_near =
nullptr;
989 pcity_near_dist = -1;
995 if (pcity_near_dist == -1 || dist < pcity_near_dist
996 || (dist == pcity_near_dist
998 pcity_near = pcity_current;
999 pcity_near_dist = dist;
1008 *sq_dist = pcity_near_dist;
1030 value = pcity->
client.buy_cost;
1032 if (
city_owner(pcity)->economic.gold >= value) {
1041 PL_(
"%s costs %d gold",
"%s costs %d gold", value),
1046 PL_(
"%s and you only have %d gold.",
1047 "%s and you only have %d gold.",
1057 enum unit_activity activity,
1060 return std::any_of(units.begin(), units.end(), [&](
const auto unit) {
1061 return can_unit_do_connect(unit, activity, tgt);
1096 pplayer->
client.tile_vision[v] =
new QBitArray();
1121 pplayer->client.tile_vision[v]->resize(new_size);
1125 pplayer->tile_known->resize(new_size);
1136 char mi_map[MAPIMG_LAYER_COUNT + 1];
1137 enum mapimg_layer layer;
1146 fc_snprintf(str,
sizeof(str),
"zoom=%d:turns=0:format=%s",
1162 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
1163 layer = mapimg_layer_next(layer)) {
1165 mi_map[map_pos++] = mapimg_layer_name(layer)[0];
1168 mi_map[map_pos] =
'\0';
1176 log_debug(
"client map image definition: %s", str);
1197 const char *setting_str;
1199 if (poption ==
nullptr ||
option_type(poption) != OT_STRING
1213 enum ai_level lvl =
static_cast<ai_level
>(
game.
info.skill_level);
1217 if (
is_ai(pplayer) && pplayer->ai_common.skill_level != lvl) {
1218 return ai_level_invalid();
1224 return ai_level_invalid();
void output_window_event(const char *plain_text, const struct text_tag_list *tags)
Add a line of text to the output ("chatline") window from server event.
bool can_city_build_unit_later(const struct city *pcity, const struct unit_type *punittype)
Returns whether player can eventually build given unit in the city; returns FALSE if unit can never p...
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Return TRUE iff the city has this building in it.
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
void city_remove_improvement(struct city *pcity, const struct impr_type *pimprove)
Removes an improvement (and its effects) from a city.
struct tile * city_tile(const struct city *pcity)
Return the tile location of the city.
bool city_production_has_flag(const struct city *pcity, enum impr_flag_id flag)
Return TRUE when the current production has this flag.
bool can_city_build_improvement_now(const struct city *pcity, const struct impr_type *pimprove)
Return whether given city can build given building; returns FALSE if the building is obsolete.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Return the extended name of the building.
bool can_city_build_improvement_later(const struct city *pcity, const struct impr_type *pimprove)
Return whether player can eventually build given building in the city; returns FALSE if improvement c...
const char * city_production_name_translation(const struct city *pcity)
Return the extended name of the current production.
bool can_city_build_unit_now(const struct city *pcity, const struct unit_type *punittype)
Return whether given city can build given unit; returns FALSE if unit is obsolete.
#define cities_iterate_end
#define city_list_iterate(citylist, pcity)
#define cities_iterate(pcity)
#define city_list_iterate_end
#define city_built_iterate(_pcity, _p)
#define city_built_iterate_end
struct city * is_any_city_dialog_open()
void popdown_city_dialog()
Closes the city overlay.
int city_buy_production(struct city *pcity)
Buy the current production item in a given city.
void refresh_city_dialog(struct city *pcity)
void city_report_dialog_update()
void center_on_tile(tile *tile, bool animate=true)
Centers the view on a tile.
enum client_states client_state()
Return current client state.
bool client_has_player()
Either controlling or observing.
bool client_is_global_observer()
Returns whether client is global observer.
struct player * client_player()
Either controlling or observing.
bool client_is_observer()
Returns whether client is observer.
bool can_client_change_view()
Return TRUE if the client can change the view; i.e.
enum known_type client_tile_get_known(const struct tile *ptile)
A tile's "known" field is used by the server to store whether each player knows the tile.
static int target_get_section(struct universal target)
Return the numerical "section" of an item.
const char * get_vision_status(const struct player *me, const struct player *them)
Return a string indicating one nation's shaed vision status with another.
int collect_eventually_buildable_targets(struct universal *targets, struct city *pcity, bool advanced_tech)
Collect the cids of all targets which can be build by this city or in general.
void client_player_maps_reset()
Reset the private maps of all players.
bool city_unit_supported(const struct city *pcity, const struct universal *target)
Return TRUE if the city supports at least one unit of the given production type (returns FALSE if the...
cid cid_encode_building(const struct impr_type *pimprove)
Encode a CID for the target building.
void create_event(struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Creates a struct packet_generic_message packet and injects it via handle_chat_msg.
void client_player_init(struct player *pplayer)
Initialize a player on the client side.
const QPixmap * client_government_sprite()
Return the sprite for the government indicator.
void client_remove_city(struct city *pcity)
Remove city, client end version.
void client_unit_init_act_prob_cache(struct unit *punit)
Initialize the action probability cache.
void nuclear_winter_scaled(int *chance, int *rate, int max)
Return nuclear winter chance and rate of change, scaled to max.
bool mapimg_client_define()
Create a map image definition on the client.
void flush_dirty_overview()
This module contains various general - mostly highlevel - functions used throughout the client.
const QPixmap * client_research_sprite()
Return the sprite for the research indicator.
void cityrep_buy(struct city *pcity)
Called when the "Buy" button is pressed in the city report for every selected city.
void global_warming_scaled(int *chance, int *rate, int max)
Return global warming chance and rate of change, scaled to max.
struct nation_set * client_current_nation_set()
Returns the nation set in use.
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Takes an array of compound ids (cids).
static int fc_cmp(const void *p1, const void *p2)
Helper for name_and_sort_items().
cid cid_encode(struct universal target)
Encode a CID for the target production.
void client_remove_unit(struct unit *punit)
Remove unit, client end version.
bool can_units_do_connect(const std::vector< unit * > &units, enum unit_activity activity, struct extra_type *tgt)
Returns TRUE if any of the units can do the connect activity.
bool city_building_present(const struct city *pcity, const struct universal *target)
A TestCityFunc to tell whether the item is a building and is present.
int collect_already_built_targets(struct universal *targets, struct city *pcity)
Collect the cids of all improvements which are built in the given city.
void center_on_something()
Find something sensible to display.
struct city * get_nearest_city(const struct unit *punit, int *sq_dist)
Find city nearest to given unit and optionally return squared city distance Parameter sq_dist may be ...
struct universal cid_decode(cid id)
Decode the CID into a city_production structure.
enum ai_level server_ai_level()
Returns the current AI skill level on the server, if the same level is currently used for all current...
void unit_focus_set_status(struct player *pplayer)
Set focus status of all player units to FOCUS_AVAIL.
void handle_event(const char *featured_text, struct tile *ptile, enum event_type event, int turn, int phase, int conn_id)
Handles a chat or event message.
cid cid_encode_unit(const struct unit_type *punittype)
Encode a CID for the target unit type.
void client_diplomacy_clause_string(char *buf, int bufsiz, struct Clause *pclause)
Copy a string that describes the given clause into the return buffer.
const QPixmap * client_warming_sprite()
Return the sprite for the global-warming indicator.
const QPixmap * client_cooling_sprite()
Return the sprite for the global-cooling indicator.
static void catastrophe_scaled(int *chance, int *rate, int max, int current, int accum, int level)
Return global catastrophe chance and rate of change, scaled to some maximum (e.g.
bool city_unit_present(const struct city *pcity, const struct universal *target)
Return TRUE if the city has present at least one unit of the given production type (returns FALSE if ...
const char * get_embassy_status(const struct player *me, const struct player *them)
Return a string indicating one nation's embassy status with another.
int collect_production_targets(struct universal *targets, struct city **selected_cities, int num_selected_cities, bool append_units, bool append_wonders, bool change_prod, TestCityFunc test_func)
Return possible production targets for the current player's cities.
bool(* TestCityFunc)(const struct city *, const struct universal *)
std::vector< unit * > & get_units_in_focus()
Returns list of units currently in focus.
int get_num_units_in_focus()
Return the number of units currently in focus (0 or more).
struct unit * get_focus_unit_on_tile(const struct tile *ptile)
Return TRUE iff a unit on this tile is in focus.
void unit_focus_advance()
This function may be called from packhand.c, via unit_focus_update(), as a result of packets indicati...
void control_unit_killed(struct unit *punit)
Called when a unit is killed; this removes it from the control lists.
struct unit * head_of_units_in_focus()
Return head of focus units list.
void popup_notify_goto_dialog(const char *headline, const char *lines, const struct text_tag_list *tags, struct tile *ptile)
Popup a dialog to display information about an event that has a specific location.
#define PL_(String1, String2, n)
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Apply a tag to a text.
enum text_link_type text_tag_link_type(const struct text_tag *ptag)
Return the link target type suggested by this text tag.
size_t featured_text_to_plain_text(const char *featured_text, char *plain_text, size_t plain_text_len, struct text_tag_list **tags, bool replace_link_text)
Separate the text from the text features.
struct text_tag * text_tag_new(enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Returns a new text_tag or nullptr on error.
const struct ft_color ftc_client
const char * city_link(const struct city *pcity)
Get a text link to a city.
int text_tag_link_id(const struct text_tag *ptag)
Return the link target id suggested by this text tag (city id, tile index or unit id).
#define text_tag_list_iterate_end
#define text_tag_list_iterate(tags, ptag)
static bool ft_color_requested(const struct ft_color color)
void game_remove_unit(struct world *gworld, struct unit *punit)
In the server call wipe_unit(), and never this function directly.
void game_remove_city(struct world *gworld, struct city *pcity)
Remove city from game.
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
Government_type_id government_count()
Return the number of governments.
Impr_type_id improvement_count()
Return the number of improvements.
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
Whether player can eventually build given building somewhere – i.e., returns TRUE if building is avai...
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove)
Whether player can build given building somewhere immediately.
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
Impr_type_id improvement_number(const struct impr_type *pimprove)
Return the improvement index.
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
Returns the number of shields it takes to build this improvement.
bool is_wonder(const struct impr_type *pimprove)
Returns whether improvement is some kind of wonder.
bool is_great_wonder(const struct impr_type *pimprove)
Is this building a great wonder?
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Return TRUE if the impr has this flag otherwise FALSE.
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
bool is_small_wonder(const struct impr_type *pimprove)
Is this building a small wonder?
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Return squared distance between two tiles.
int map_num_tiles()
Returns the total number of (real) positions (or tiles) on the map.
struct tile * native_pos_to_tile(const struct civ_map *nmap, int nat_x, int nat_y)
Return the tile for the given native position.
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
#define iterate_outward_end
int mapimg_count()
Return the number of map image definitions.
struct mapdef * mapimg_isvalid(int id)
Check if a map image definition is valid.
bool mapimg_define(const char *maparg, bool check)
Define on map image.
bool mapimg_delete(int id)
Delete a map image definition.
void update_unit_info_label(const std::vector< unit * > &unit_list)
Update the information label which gives info on the current unit and the tile under the current unit...
void meswin_add(const char *message, const struct text_tag_list *tags, struct tile *ptile, enum event_type event, int turn, int phase)
Add a message.
struct nation_type * nation_of_city(const struct city *pcity)
Return the nation of the player who owns the city.
const char * nation_rule_name(const struct nation_type *pnation)
Return the (untranslated) rule name of the nation (adjective form).
struct nation_set * nation_set_by_setting_value(const char *setting)
Returns the nation set that would be selected by the given value of the 'nationset' server setting.
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
struct nation_type * nation_of_unit(const struct unit *punit)
Return the nation of the player who owns the unit.
const struct option_set * server_optset
const char * option_str_get(const struct option *poption)
Returns the current value of this string option.
client_options * gui_options
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Returns the option corresponding of the name in this option set.
enum option_type option_type(const struct option *poption)
Returns the type of the option.
int messages_where[E_COUNT]
Message Options:
void play_sound_for_event(enum event_type type)
Plays sound associated with event.
struct city_list * cities
pageGame * queen()
Return game instandce.
bool is_settable_ai_level(enum ai_level level)
Return is AI can be set to given level.
int player_index(const struct player *pplayer)
Return the player index.
struct city * player_primary_capital(const struct player *pplayer)
Locate the player's primary capital city, (nullptr Otherwise)
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Return TRUE iff the player can see units in the city.
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Check if pplayer has an embassy with pplayer2.
bool gives_shared_vision(const struct player *me, const struct player *them)
Return TRUE iff the player me gives shared vision to player them.
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
#define players_iterate_end
#define players_iterate(_pplayer)
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
struct setting_list * level[OLEVELS_NUM]
#define CLIP(lower, current, upper)
struct city::@15::@18 client
struct universal production
struct unit_list * units_supported
struct packet_game_info info
bool mapimg_layer[MAPIMG_LAYER_COUNT]
struct ft_color highlight_our_names
char username[MAX_LEN_NAME]
char descr[MAX_LEN_NAME+40]
Functions for handling the nations.
The base class for options.
struct city_list * cities
struct player::@65::@68 client
struct research::@71::@73 client
struct text_tag::@23::@25 color
struct unit::@76::@78 client
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Compare strings like strncmp(), but ignoring case.
#define sz_strlcpy(dest, src)
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
const char * advance_name_translation(const struct advance *padvance)
Return the (translated) name of the given advance/technology.
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
const QPixmap * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Return a sprite for the given citizen.
const QPixmap * get_indicator_sprite(const struct tileset *t, enum indicator_type indicator, int idx)
Returns a sprite for the given indicator with the given index.
const QPixmap * get_government_sprite(const struct tileset *t, const struct government *gov)
Return the sprite for the government.
#define NUM_TILES_PROGRESS
const struct unit_type * utype
const struct impr_type * building
int get_transporter_occupancy(const struct unit *ptrans)
Return how many units are in the transport.
bool unit_transport_unload(struct unit *pcargo)
Unload pcargo from ptrans.
struct unit_list * unit_transport_cargo(const struct unit *ptrans)
Returns the list of cargo units.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
struct unit_type * utype_by_number(const Unit_type_id id)
Return a pointer for the unit type struct for the given unit type id.
const char * utype_values_translation(const struct unit_type *punittype)
Return string with translated unit name and list of its values.
int utype_build_shield_cost(const struct city *pcity, const struct unit_type *punittype)
Returns the number of shields it takes to build this unit type.
Unit_type_id utype_count()
Return the number of unit types.
Unit_type_id utype_number(const struct unit_type *punittype)
Return the unit type index.
bool can_player_build_unit_later(const struct player *p, const struct unit_type *punittype)
Whether player can eventually build given unit somewhere – ie, returns TRUE if unit is available with...
bool can_player_build_unit_now(const struct player *p, const struct unit_type *punittype)
Whether player can build given unit somewhere; returns FALSE if unit is obsolete.
static bool utype_has_flag(const struct unit_type *punittype, int flag)
#define unit_type_iterate(_p)
#define unit_type_iterate_end
void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, bool full_refresh)
Refreshes a single city on the map canvas.
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh)
Refreshes a single unit on the map canvas.
void link_mark_add_new(enum text_link_type type, int id)
Add a visible link for 2 turns.
#define vision_layer_iterate(v)
#define vision_layer_iterate_end