Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
citydlg_common.c File Reference
#include <stdarg.h>
#include "astring.h"
#include "fcintl.h"
#include "log.h"
#include "support.h"
#include "city.h"
#include "culture.h"
#include "game.h"
#include "specialist.h"
#include "unitlist.h"
#include "citydlg_g.h"
#include "mapview_g.h"
#include "citydlg_common.h"
#include "client_main.h"
#include "climap.h"
#include "control.h"
#include "mapview_common.h"
#include "options.h"
#include "tilespec.h"

Go to the source code of this file.

Data Structures

struct  city_sum
 

Macros

#define citydlg_iterate(pcity, ptile, pedge, pcorner, _x, _y)
 
#define citydlg_iterate_end
 

Functions

int get_citydlg_canvas_width (void)
 
int get_citydlg_canvas_height (void)
 
void generate_citydlg_dimensions (void)
 
bool city_to_canvas_pos (float *canvas_x, float *canvas_y, int city_x, int city_y, int city_radius_sq)
 
bool canvas_to_city_pos (int *city_x, int *city_y, int city_radius_sq, int canvas_x, int canvas_y)
 
void city_dialog_redraw_map (struct city *pcity, struct canvas *pcanvas)
 
charcity_production_cost_str (const struct city *pcity)
 
void get_city_dialog_production (struct city *pcity, char *buffer, size_t buffer_len)
 
void get_city_dialog_production_full (char *buffer, size_t buffer_len, struct universal *target, struct city *pcity)
 
void get_city_dialog_production_row (char *buf[], size_t column_size, struct universal *target, struct city *pcity)
 
static struct city_sumcity_sum_new (const char *format)
 
static void city_sum_add_real (struct city_sum *sum, double value, bool suppress_if_zero, const char *auxfmt, double aux, char *posdesc, char *negdesc)
 
static void fc__attribute ((__format__(__printf__, 6, 8)))
 
static void fc__attribute ((__format__(__printf__, 3, 4)))
 
static double city_sum_total (struct city_sum *sum)
 
static int city_sum_compare (double val1, double val2)
 
static void fc__attribute ((__format__(__printf__, 5, 6)))
 
void get_city_dialog_output_text (const struct city *pcity, Output_type_id otype, char *buf, size_t bufsz)
 
void get_city_dialog_illness_text (const struct city *pcity, char *buf, size_t bufsz)
 
void get_city_dialog_pollution_text (const struct city *pcity, char *buf, size_t bufsz)
 
void get_city_dialog_culture_text (const struct city *pcity, char *buf, size_t bufsz)
 
void get_city_dialog_airlift_text (const struct city *pcity, char *buf, size_t bufsz)
 
void get_city_dialog_airlift_value (const struct city *pcity, char *buf, size_t bufsz)
 
int get_city_citizen_types (struct city *pcity, enum citizen_feeling idx, enum citizen_category *categories)
 
void city_rotate_specialist (struct city *pcity, int citizen_index)
 
void activate_all_units (struct tile *ptile)
 
int city_change_production (struct city *pcity, struct universal *target)
 
int city_set_worklist (struct city *pcity, const struct worklist *pworklist)
 
void city_worklist_commit (struct city *pcity, struct worklist *pwl)
 
static bool base_city_queue_insert (struct city *pcity, int position, struct universal *item)
 
bool city_queue_insert (struct city *pcity, int position, struct universal *item)
 
bool city_queue_clear (struct city *pcity)
 
bool city_queue_insert_worklist (struct city *pcity, int position, const struct worklist *worklist)
 
void city_get_queue (struct city *pcity, struct worklist *pqueue)
 
bool city_set_queue (struct city *pcity, const struct worklist *pqueue)
 
bool city_can_buy (const struct city *pcity)
 
int city_sell_improvement (struct city *pcity, Impr_type_id sell_id)
 
int city_buy_production (struct city *pcity)
 
int city_change_specialist (struct city *pcity, Specialist_type_id from, Specialist_type_id to)
 
int city_toggle_worker (struct city *pcity, int city_x, int city_y)
 
int city_rename (struct city *pcity, const char *name)
 

Variables

static int citydlg_map_width
 
static int citydlg_map_height
 

Macro Definition Documentation

◆ citydlg_iterate

#define citydlg_iterate (   pcity,
  ptile,
  pedge,
  pcorner,
  _x,
  _y 
)
Value:
{ \
float _x##_0, _y##_0; \
int _tile_x, _tile_y; \
const int _x##_w = get_citydlg_canvas_width(); \
const int _y##_h = get_citydlg_canvas_height(); \
_x##_0 -= (_x##_w - tileset_tile_width(tileset)) / 2; \
log_debug("citydlg: %f,%f + %dx%d", \
_x##_0, _y##_0, _x##_w, _y##_h); \
ptile, pedge, pcorner, _x##_g, _y##_g, 1.0) { \
const int _x = _x##_g - _x##_0; \
const int _y = _y##_g - _y##_0; \
{
int get_citydlg_canvas_width(void)
int get_citydlg_canvas_height(void)
char * incite_cost
Definition comments.c:76
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 int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
Definition tile.h:50
#define tile_index(_pt_)
Definition tile.h:89
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779

Definition at line 158 of file citydlg_common.c.

◆ citydlg_iterate_end

#define citydlg_iterate_end
Value:
} \
}
#define gui_rect_iterate_coord_end

Definition at line 178 of file citydlg_common.c.

Function Documentation

◆ activate_all_units()

void activate_all_units ( struct tile ptile)

Activate all units on the given map tile.

Definition at line 1274 of file citydlg_common.c.

Referenced by adv_unit_select_all_callback().

◆ base_city_queue_insert()

static bool base_city_queue_insert ( struct city pcity,
int  position,
struct universal item 
)
static

Insert an item into the city's queue. This function will send new production requests to the server but will NOT send the new worklist to the server - the caller should call city_set_worklist() if the function returns TRUE.

Note that the queue DOES include the current production.

Definition at line 1375 of file citydlg_common.c.

Referenced by city_queue_insert(), and city_queue_insert_worklist().

◆ canvas_to_city_pos()

bool canvas_to_city_pos ( int city_x,
int city_y,
int  city_radius_sq,
int  canvas_x,
int  canvas_y 
)

Converts a citymap canvas position to a (cartesian) city coordinate position. Returns TRUE iff the city position is valid.

Definition at line 115 of file citydlg_common.c.

Referenced by button_down_citymap(), city_map::context_menu(), left_button_down_citymap(), city_map::mousePressEvent(), resource_map_city_dlg_callback(), and right_button_down_citymap().

◆ city_buy_production()

int city_buy_production ( struct city pcity)

◆ city_can_buy()

bool city_can_buy ( const struct city pcity)

◆ city_change_production()

int city_change_production ( struct city pcity,
struct universal target 
)

◆ city_change_specialist()

int city_change_specialist ( struct city pcity,
Specialist_type_id  from,
Specialist_type_id  to 
)

Change a specialist in the given city. Return the request ID.

Definition at line 1568 of file citydlg_common.c.

Referenced by apply_result_on_server(), and city_rotate_specialist().

◆ city_dialog_redraw_map()

void city_dialog_redraw_map ( struct city pcity,
struct canvas pcanvas 
)

Draw the full city map onto the canvas store. Works for both isometric and orthogonal views.

Definition at line 187 of file citydlg_common.c.

Referenced by city_dialog_update_map(), create_city_map(), and city_map::set_pixmap().

◆ city_get_queue()

void city_get_queue ( struct city pcity,
struct worklist pqueue 
)

◆ city_production_cost_str()

char * city_production_cost_str ( const struct city pcity)

Return a string describing the cost for the production of the city considering several build slots for units.

Definition at line 224 of file citydlg_common.c.

Referenced by cr_entry_building(), and get_city_dialog_production().

◆ city_queue_clear()

bool city_queue_clear ( struct city pcity)

Clear the queue (all entries except the first one since that can't be cleared).

Note that the queue DOES include the current production.

Definition at line 1435 of file citydlg_common.c.

◆ city_queue_insert()

bool city_queue_insert ( struct city pcity,
int  position,
struct universal item 
)

◆ city_queue_insert_worklist()

bool city_queue_insert_worklist ( struct city pcity,
int  position,
const struct worklist worklist 
)

Insert the worklist into the city's queue at the given position.

Note that the queue DOES include the current production.

Definition at line 1447 of file citydlg_common.c.

Referenced by append_worklist_foreach(), city_widget::display_list_menu(), and city_dialog::display_worklist_menu().

◆ city_rename()

int city_rename ( struct city pcity,
const char name 
)

Tell the server to rename the city. Return the request ID.

Definition at line 1610 of file citydlg_common.c.

Referenced by new_name_city_dlg_callback(), and rename_popup_callback().

◆ city_rotate_specialist()

void city_rotate_specialist ( struct city pcity,
int  citizen_index 
)

Rotate the given specialist citizen to the next type of citizen.

Definition at line 1246 of file citydlg_common.c.

Referenced by citizens_callback(), citizens_callback(), city_dlg_callback(), and city_label::mousePressEvent().

◆ city_sell_improvement()

int city_sell_improvement ( struct city pcity,
Impr_type_id  sell_id 
)

◆ city_set_queue()

bool city_set_queue ( struct city pcity,
const struct worklist pqueue 
)

◆ city_set_worklist()

int city_set_worklist ( struct city pcity,
const struct worklist pworklist 
)

Set the worklist for a given city. Return the request ID.

Note that the worklist does NOT include the current production.

Definition at line 1307 of file citydlg_common.c.

Referenced by city_queue_insert(), city_queue_insert_worklist(), city_set_queue(), city_worklist_commit(), city_dialog::clear_worklist(), clear_worklist_foreach_func(), city_widget::clear_worlist(), and ok_worklist_editor_callback().

◆ city_sum_add_real()

static void city_sum_add_real ( struct city_sum sum,
double  value,
bool  suppress_if_zero,
const char auxfmt,
double  aux,
char posdesc,
char negdesc 
)
static

Helper: add a new contribution to the city_sum. If 'posdesc'/'negdesc' and other properties match an existing entry, 'value' is added to the existing entry, else a new one is appended.

Definition at line 527 of file citydlg_common.c.

Referenced by fc__attribute(), and fc__attribute().

◆ city_sum_compare()

static int city_sum_compare ( double  val1,
double  val2 
)
inlinestatic

Compare two values, taking care of floating point comparison issues. -1: val1 < val2 0: val1 == val2 (approximately) +1: val1 > val2

Definition at line 680 of file citydlg_common.c.

Referenced by fc__attribute().

◆ city_sum_new()

static struct city_sum * city_sum_new ( const char format)
static

Create a new city_sum. 'format' is how to print each contribution, of the form "%+4.0f : %s" (the first item is the numeric value and must have a 'f' conversion spec; the second is the description).

Definition at line 511 of file citydlg_common.c.

Referenced by get_city_dialog_culture_text(), get_city_dialog_illness_text(), get_city_dialog_output_text(), and get_city_dialog_pollution_text().

◆ city_sum_total()

static double city_sum_total ( struct city_sum sum)
static

Return the net total accumulated in the sum so far.

Definition at line 662 of file citydlg_common.c.

Referenced by fc__attribute(), and get_city_dialog_output_text().

◆ city_to_canvas_pos()

bool city_to_canvas_pos ( float canvas_x,
float canvas_y,
int  city_x,
int  city_y,
int  city_radius_sq 
)

Converts a (cartesian) city position to citymap canvas coordinates. Returns TRUE if the city position is valid.

Definition at line 93 of file citydlg_common.c.

◆ city_toggle_worker()

int city_toggle_worker ( struct city pcity,
int  city_x,
int  city_y 
)

Toggle a worker<->specialist at the given city tile. Return the request ID.

Definition at line 1579 of file citydlg_common.c.

Referenced by button_down_citymap(), left_button_down_citymap(), city_map::mousePressEvent(), and resource_map_city_dlg_callback().

◆ city_worklist_commit()

void city_worklist_commit ( struct city pcity,
struct worklist pwl 
)

Commit the changes to the worklist for the city.

Definition at line 1315 of file citydlg_common.c.

◆ fc__attribute() [1/3]

static void fc__attribute ( (__format__(__printf__, 3, 4))  )
static

Add a new contribution to the city_sum (simple). Compared to city_sum_add_full():

  • description does not depend on net value
  • not suppressed if net value is zero (compare city_sum_add_nonzero())
  • no auxiliary number

Add a new contribution to the city_sum (simple). Compared to city_sum_add_full():

  • description does not depend on net value
  • suppressed if net value is zero (compare city_sum_add())
  • no auxiliary number

Definition at line 613 of file citydlg_common.c.

◆ fc__attribute() [2/3]

static void fc__attribute ( (__format__(__printf__, 5, 6))  )
static

Print out the sum, including total, and free the city_sum. totalfmt's first format string must be some kind of f, and first argument must be a double (if account_for_unknown). account_for_unknown is optional, as not every sum wants it (consider pollution's clipping).

Definition at line 699 of file citydlg_common.c.

◆ fc__attribute() [3/3]

static void fc__attribute ( (__format__(__printf__, 6, 8))  )
static

Add a new contribution to the city_sum (complex).

  • Allows different descriptions for net positive and negative contributions (posfmt/negfmt);
  • Allows specifying another auxiliary number which isn't significant for comparisons but will also be accumulated, and appended to the description when rendered (e.g. the 50% in "+11: Bonus from Marketplace+Luxury (+50%)")
  • Allows control over whether the item will be discarded if its net value is zero (suppress_if_zero).

Definition at line 576 of file citydlg_common.c.

◆ generate_citydlg_dimensions()

void generate_citydlg_dimensions ( void  )

Calculate the citydlg width and height.

Definition at line 67 of file citydlg_common.c.

Referenced by handle_map_info(), themespec_reread(), and tilespec_reread().

◆ get_city_citizen_types()

int get_city_citizen_types ( struct city pcity,
enum citizen_feeling  idx,
enum citizen_category categories 
)

Provide a list of all citizens in the city, in order. "index" should be the happiness index (currently [0..4]; 4 = final happiness). "citizens" should be an array large enough to hold all citizens (use MAX_CITY_SIZE to be on the safe side).

Definition at line 1208 of file citydlg_common.c.

Referenced by city_dialog_update_citizens(), city_rotate_specialist(), refresh_feeling_surface(), refresh_feeling_surface(), and city_dialog::update_citizens().

◆ get_city_dialog_airlift_text()

void get_city_dialog_airlift_text ( const struct city pcity,
char buf,
size_t  bufsz 
)

Return text describing airlift capacity.

Definition at line 1076 of file citydlg_common.c.

Referenced by show_info_popup(), show_info_popup(), and city_dialog::update_info_label().

◆ get_city_dialog_airlift_value()

void get_city_dialog_airlift_value ( const struct city pcity,
char buf,
size_t  bufsz 
)

Return airlift capacity.

Definition at line 1146 of file citydlg_common.c.

Referenced by city_dialog_update_information(), city_dialog_update_information(), and city_dialog::update_info_label().

◆ get_city_dialog_culture_text()

void get_city_dialog_culture_text ( const struct city pcity,
char buf,
size_t  bufsz 
)

Return text describing the culture output.

Definition at line 1026 of file citydlg_common.c.

Referenced by show_info_popup(), show_info_popup(), and city_dialog::update_info_label().

◆ get_city_dialog_illness_text()

void get_city_dialog_illness_text ( const struct city pcity,
char buf,
size_t  bufsz 
)

Return text describing the chance for a plague.

Definition at line 928 of file citydlg_common.c.

Referenced by show_info_popup(), show_info_popup(), and city_dialog::update_info_label().

◆ get_city_dialog_output_text()

void get_city_dialog_output_text ( const struct city pcity,
Output_type_id  otype,
char buf,
size_t  bufsz 
)

Return text describing the production output.

Definition at line 755 of file citydlg_common.c.

Referenced by show_info_popup(), show_info_popup(), and city_dialog::update_info_label().

◆ get_city_dialog_pollution_text()

void get_city_dialog_pollution_text ( const struct city pcity,
char buf,
size_t  bufsz 
)

Return text describing the pollution output.

Definition at line 1000 of file citydlg_common.c.

Referenced by show_info_popup(), show_info_popup(), and city_dialog::update_info_label().

◆ get_city_dialog_production()

void get_city_dialog_production ( struct city pcity,
char buffer,
size_t  buffer_len 
)

Find the city dialog city production text for the given city, and place it into the buffer. This will check the concise_city_production option. pcity may be NULL; in this case a filler string is returned.

Definition at line 260 of file citydlg_common.c.

Referenced by city_dialog_update_building(), and city_dialog::update_building().

◆ get_city_dialog_production_full()

void get_city_dialog_production_full ( char buffer,
size_t  buffer_len,
struct universal target,
struct city pcity 
)

Pretty sprints the info about a production (name, info, cost, turns to build) into a single text string.

This is very similar to get_city_dialog_production_row(); the difference is that instead of placing the data into an array of strings it all goes into one long string. This means it can be used by frontends that do not use a tabled structure, but it also gives less flexibility.

Definition at line 333 of file citydlg_common.c.

◆ get_city_dialog_production_row()

void get_city_dialog_production_row ( char buf[],
size_t  column_size,
struct universal target,
struct city pcity 
)

Pretty sprints the info about a production in 4 columns (name, info, cost, turns to build). The columns must each have a size of column_size bytes. City may be NULL.

Definition at line 378 of file citydlg_common.c.

Referenced by append_impr_or_unit_to_menu(), append_impr_or_unit_to_menu_item(), cell_render_func(), and city_widget::gen_production_labels().

◆ get_citydlg_canvas_height()

int get_citydlg_canvas_height ( void  )

◆ get_citydlg_canvas_width()

int get_citydlg_canvas_width ( void  )

Variable Documentation

◆ citydlg_map_height

int citydlg_map_height
static

Definition at line 46 of file citydlg_common.c.

Referenced by generate_citydlg_dimensions(), and get_citydlg_canvas_height().

◆ citydlg_map_width

int citydlg_map_width
static

Definition at line 46 of file citydlg_common.c.

Referenced by generate_citydlg_dimensions(), and get_citydlg_canvas_width().