22 #include <QCoreApplication>
23 #include <QElapsedTimer>
25 #include <QGlobalStatic>
27 #include <QLoggingCategory>
75 typedef QHash<const struct tile *, struct gotoline_counter *>
gotohash;
95 t.connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
96 t.start(milliseconds);
97 QCoreApplication::processEvents(QEventLoop::AllEvents, 20);
108 ptile, full_refresh);
119 punit, full_refresh);
133 pcity, full_refresh);
146 int map_dx,
int map_dy)
175 int map_x,
int map_y)
190 float gui_x,
float gui_y)
195 if (HH > 0 || HW > 0) {
200 int xmult, ymult, mod, compar;
204 x =
DIVIDE((
int) gui_x, (
int) W);
205 y =
DIVIDE((
int) gui_y, (
int) H);
212 xmult = (dx >= W / 2) ? -1 : 1;
213 ymult = (dy >= H / 2) ? -1 : 1;
214 dx = (dx >= W / 2) ? (W - 1 - dx) : dx;
215 dy = (dy >= H / 2) ? (H - 1 - dy) : dy;
219 compar = (dx - HW / 2) * (H / 2) - (H / 2 - 1 - dy) * (W / 2 - HW);
221 compar = (dy - HH / 2) * (W / 2) - (W / 2 - 1 - dx) * (H / 2 - HH);
223 mod = (compar < 0) ? -1 : 0;
225 *map_x = (x + y) + mod * (xmult + ymult) / 2;
226 *map_y = (y - x) + mod * (ymult - xmult) / 2;
257 *map_x =
DIVIDE((
int) (gui_x * H + gui_y * W), (
int) (W * H));
258 *map_y =
DIVIDE((
int) (gui_y * W - gui_x * H), (
int) (W * H));
262 *map_x =
DIVIDE((
int) gui_x, (
int) W);
263 *map_y =
DIVIDE((
int) gui_y, (
int) H);
291 int center_map_x, center_map_y, dx, dy, tile_x, tile_y;
375 int map_x, map_y,
nat_x,
nat_y, diff_x, diff_y;
376 float gui_x0, gui_y0;
382 diff_x = *gui_x - gui_x0;
383 diff_y = *gui_y - gui_y0;
409 float *gui_dy,
float gui_x0,
float gui_y0,
410 float gui_x1,
float gui_y1)
412 int map_x0, map_y0, map_x1, map_y1;
413 float gui_x0_base, gui_y0_base, gui_x1_base, gui_y1_base;
414 int gui_x0_diff, gui_y0_diff, gui_x1_diff, gui_y1_diff;
431 gui_x0_diff = gui_x0 - gui_x0_base;
432 gui_y0_diff = gui_y0 - gui_y0_base;
433 gui_x1_diff = gui_x1 - gui_x1_base;
434 gui_y1_diff = gui_y1 - gui_y1_base;
443 *gui_dx += gui_x1_diff - gui_x0_diff;
444 *gui_dy += gui_y1_diff - gui_y0_diff;
453 float old_gui_x0, old_gui_y0;
456 int common_x0, common_x1, common_y0, common_y1;
457 int update_x0, update_x1, update_y0, update_y1;
471 old_gui_x0 = gui_x0 - dx;
472 old_gui_y0 = gui_y0 - dy;
480 common_x0 =
MAX(old_gui_x0, gui_x0);
481 common_x1 =
MIN(old_gui_x0, gui_x0) + width;
482 common_y0 =
MAX(old_gui_y0, gui_y0);
483 common_y1 =
MIN(old_gui_y0, gui_y0) + height;
486 && common_y1 > common_y0) {
490 if (old_gui_x0 < gui_x0) {
491 update_x0 =
MAX(old_gui_x0 + width, gui_x0);
492 update_x1 = gui_x0 + width;
495 update_x1 =
MIN(old_gui_x0, gui_x0 + width);
497 if (old_gui_y0 < gui_y0) {
498 update_y0 =
MAX(old_gui_y0 + height, gui_y0);
499 update_y1 = gui_y0 + height;
502 update_y1 =
MIN(old_gui_y0, gui_y0 + height);
507 p.drawPixmap(common_x0 - gui_x0, common_y0 - gui_y0, *
mapview.
store,
508 common_x0 - old_gui_x0, common_y0 - old_gui_y0,
509 common_x1 - common_x0, common_y1 - common_y0);
513 if (update_y1 > update_y0) {
516 if (update_x1 > update_x0) {
518 update_x1 - update_x0, common_y1 - common_y0);
549 float xmin, ymin, xmax, ymax;
560 *gui_x0 =
CLIP(xmin, *gui_x0, xmax - xsize);
564 *gui_y0 =
CLIP(ymin, *gui_y0, ymax - ysize);
609 float *ymax,
int *xsize,
int *ysize)
647 float gui_x1, gui_y1, gui_x2, gui_y2, gui_x3, gui_y3, gui_x4, gui_y4;
671 diff = *xsize - (*xmax - *xmin);
674 *xmax += (diff + 1) / 2;
677 diff = *ysize - (*ymax - *ymin);
680 *ymax += (diff + 1) / 2;
683 log_debug(
"x: %f<-%d->%f; y: %f<-%f->%d", *xmin, *xsize, *xmax, *ymin,
710 float dummy_x, dummy_y;
728 float canvas_x, canvas_y;
729 float xmin, ymin, xmax, ymax;
730 int xsize, ysize, scroll_x, scroll_y;
751 if (canvas_x < border_x
755 if (canvas_y < border_y
760 && (!same || scroll_x + xsize < xmax
765 && (!same || scroll_y + ysize < ymax
777 const std::vector<drawn_sprite> &sprites,
bool fog,
781 for (
auto s : sprites) {
786 if (fog && s.foggable) {
788 QPixmap temp(s.sprite->size());
789 temp.fill(Qt::transparent);
792 p2.setCompositionMode(QPainter::CompositionMode_Source);
793 p2.drawPixmap(0, 0, *s.sprite);
794 p2.setCompositionMode(QPainter::CompositionMode_SourceAtop);
795 p2.fillRect(temp.rect(), QColor(0, 0, 0, 110));
798 p.drawPixmap(canvas_loc + s.offset, temp);
803 p.setCompositionMode(QPainter::CompositionMode_SourceOver);
805 p.drawPixmap(canvas_loc + s.offset, *s.sprite);
816 const std::unique_ptr<freeciv::layer> &layer,
819 const struct unit *punit,
const QPoint &canvas_loc)
821 bool city_unit =
false;
822 int dummy_x, dummy_y;
823 auto sprites = layer->fill_sprite_array(ptile, pedge, pcorner, punit);
843 const QPoint &canvas_loc)
845 auto loc = canvas_loc;
848 put_one_element(pcanvas, layer,
nullptr,
nullptr,
nullptr, punit, loc);
859 const QPoint &canvas_loc)
862 auto loc = canvas_loc;
865 put_one_element(pcanvas, layer, ptile,
nullptr,
nullptr,
nullptr, loc);
877 int canvas_x,
int canvas_y,
878 const int *upkeep_cost,
int happy_cost)
884 p.drawPixmap(canvas_x, canvas_y, *sprite);
892 p.drawPixmap(canvas_x, canvas_y, *sprite);
920 if (pcity->
client.colored) {
921 pcity->
client.colored =
false;
923 pcity->
client.colored =
true;
938 if (punit->
client.colored) {
939 punit->
client.colored =
false;
941 punit->
client.colored =
true;
954 float canvas_x, canvas_y;
971 p.drawPixmap(canvas_x, canvas_y, *mysprite);
973 dirty_rect(canvas_x, canvas_y, mysprite->width(), mysprite->height());
986 const std::unique_ptr<freeciv::layer> &layer,
987 const tile *ptile,
const QPoint &canvas_loc)
1010 const struct tile *ptile2,
1015 if (!ptile1 || !ptile2 || !
lines) {
1039 const struct tile *ptile2,
1040 enum color_std color)
1044 if (!ptile1 || !ptile2) {
1057 pen.setStyle(Qt::DashLine);
1058 pen.setDashOffset(4);
1064 for (
int i = 0; i < line_count; i++) {
1084 COLOR_MAPVIEW_TRADE_ROUTE_LINE);
1134 canvas_x =
MAX(canvas_x, 0);
1135 canvas_y =
MAX(canvas_y, 0);
1144 log_debug(
"update_map_canvas(pos=(%d,%d), size=(%d,%d))", canvas_x,
1145 canvas_y, width, height);
1163 p.fillRect(canvas_x, canvas_y, width, height,
1167 const auto rect = QRect(gui_x0, gui_y0, width,
1173 if (layer->type() == LAYER_TILELABEL) {
1176 if (layer->type() == LAYER_CITYBAR) {
1184 if (it.has_corner()) {
1188 if (it.has_edge()) {
1192 if (it.has_tile()) {
1207 const auto goto_rect =
1212 if (!it.has_tile()) {
1236 dirty_rect(canvas_x, canvas_y, width, height);
1313 #define COLOR_MAPVIEW_TILELABEL COLOR_MAPVIEW_CITYTEXT
1318 QPainter p(pcanvas);
1319 p.setFont(
get_font(FONT_TILE_LABEL));
1322 auto fm = p.fontMetrics();
1323 auto rect = fm.boundingRect(ptile->
label);
1325 p.drawText((canvas_x - rect.width() / 2), canvas_y + fm.ascent(),
1329 #undef COLOR_MAPVIEW_TILELABEL
1336 int width_base,
int height_base)
1361 const auto rect = QRect(
mapview.
gui_x0 + canvas_base_x - dx / 2,
1363 width_base + dx, height_base + dy - offset_y);
1368 if (it.has_tile() &&
tile_city(it.tile())) {
1369 int width = 0, height = 0;
1384 new_max_width =
MAX(width, new_max_width);
1385 new_max_height =
MAX(height, new_max_height);
1405 const auto rect = QRect(
mapview.
gui_x0 + canvas_base_x - dx / 2,
1407 width_base + dx, height_base + dy);
1412 if (it.has_tile() && it.tile()->label !=
nullptr) {
1415 log_debug(
"Drawing label %s.", it.tile()->label);
1422 log_debug(
"Re-queuing tile label %s drawing.", it.tile()->label);
1425 new_max_size = new_max_size.expandedTo(
size);
1440 float canvas_x, canvas_y, canvas_dx, canvas_dy;
1454 : COLOR_MAPVIEW_UNSAFE_GOTO),
1456 p.drawLine(canvas_x, canvas_y, canvas_x + canvas_dx, canvas_y + canvas_dy);
1478 struct unit *punit1,
int hp1)
1480 struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1);
1486 punit0->
hp =
MAX(punit0->
hp, hp0);
1487 punit1->
hp =
MAX(punit1->
hp, hp1);
1491 while (punit0->
hp > hp0 || punit1->
hp > hp1) {
1492 const int diff0 = punit0->
hp - hp0, diff1 = punit1->
hp - hp1;
1494 if (
fc_rand(diff0 + diff1) < diff0) {
1529 float canvas_x, canvas_y;
1538 const auto base_map =
1545 for (
const auto &sprite : anim) {
1550 p.drawPixmap(canvas_x, canvas_y, base_map);
1576 struct tile *dest_tile;
1577 int dest_x, dest_y, src_x, src_y;
1584 if (dx < -1 || dx > 1 || dy < -1 || dy > 1 || (dx == 0 && dy == 0)) {
1589 dest_x = src_x + dx;
1590 dest_y = src_y + dy;
1598 float start_x, start_y;
1599 float canvas_dx, canvas_dy;
1619 anim_timer->start();
1624 mytime =
MIN(anim_timer->elapsed(), timing_ms);
1626 auto new_x = start_x + (canvas_dx * mytime) / timing_ms;
1627 auto new_y = start_y + (canvas_dy * mytime) / timing_ms;
1629 if (new_x != prev_x || new_y != prev_y) {
1632 p.drawPixmap(new_x, new_y, *
mapview.
store, new_x, new_y, tuw, tuh);
1654 }
while (mytime < timing_ms);
1671 struct unit **punit)
1678 struct city *closest_city;
1680 struct unit *closest_settler =
nullptr, *best_settler =
nullptr;
1689 if (pcity && pcity->
tile) {
1701 closest_city =
nullptr;
1721 if (!closest_city) {
1722 closest_city = pcity;
1729 if (closest_city || !punit) {
1730 return closest_city;
1743 if (!closest_settler) {
1744 closest_settler = psettler;
1746 if (!best_settler && psettler->client.colored) {
1747 best_settler = psettler;
1757 *punit = best_settler;
1758 }
else if (closest_settler) {
1760 *punit = closest_settler;
1775 char *buffer,
int buffer_len)
1777 if (!pcity || !buffer || buffer_len < 1) {
1819 char *trade_routes_buffer,
1820 size_t trade_routes_buffer_len,
1821 enum color_std *pcolor)
1823 int num_trade_routes;
1826 if (!trade_routes_buffer || trade_routes_buffer_len <= 0) {
1831 trade_routes_buffer[0] =
'\0';
1833 *pcolor = COLOR_MAPVIEW_CITYTEXT;
1838 num_trade_routes = trade_route_list_size(pcity->
routes);
1841 fc_snprintf(trade_routes_buffer, trade_routes_buffer_len,
"%d/%d",
1842 num_trade_routes, max_routes);
1845 if (num_trade_routes == max_routes) {
1846 *pcolor = COLOR_MAPVIEW_TRADE_ROUTES_ALL_BUILT;
1847 }
else if (num_trade_routes == 0) {
1848 *pcolor = COLOR_MAPVIEW_TRADE_ROUTES_NO_BUILT;
1850 *pcolor = COLOR_MAPVIEW_TRADE_ROUTES_SOME_BUILT;
1885 auto rects = std::map<update_type, QRectF>();
1886 rects[update_type::tile_single] = QRectF(0, 0, width, height);
1887 rects[update_type::tile_full] =
1888 QRectF(-width / 2, -height / 2, 2 * width, 2 * height);
1889 rects[update_type::unit] =
1890 QRectF((width - unit_width) / 2, height - unit_height, unit_width,
1892 rects[update_type::city_description] =
1895 rects[update_type::city_map] =
1896 QRectF(-(city_width - width) / 2, -(city_height - height) / 2,
1897 city_width, city_height);
1898 rects[update_type::tile_label] =
1920 size_t name_buffer_len,
1921 char *growth_buffer,
1922 size_t growth_buffer_len,
1923 enum color_std *growth_color,
1924 enum color_std *production_color)
1928 *production_color = COLOR_MAPVIEW_CITYTEXT;
1934 fc_snprintf(growth_buffer, growth_buffer_len,
"X");
1936 fc_snprintf(growth_buffer, growth_buffer_len,
"-");
1940 fc_snprintf(growth_buffer, growth_buffer_len,
"%d", abs(turns));
1945 *growth_color = COLOR_MAPVIEW_CITYGROWTH_BLOCKED;
1947 *growth_color = COLOR_MAPVIEW_CITYTEXT;
1951 *production_color = COLOR_MAPVIEW_CITYPROD_NEGATIVE;
1954 growth_buffer[0] =
'\0';
1955 *growth_color = COLOR_MAPVIEW_CITYTEXT;
2052 for (
auto *a : qAsConst(*mapdeco_gotoline)) {
2066 return mapdeco_highlight_set->contains(ptile);
2080 changed = mapdeco_crosshair_set->contains(ptile);
2082 mapdeco_crosshair_set->remove(ptile);
2085 mapdeco_crosshair_set->insert(ptile);
2098 if (!mapdeco_crosshair_set || !ptile) {
2101 return mapdeco_crosshair_set->contains(ptile);
2110 for (
const auto *ptile : qAsConst(*mapdeco_crosshair_set)) {
2113 mapdeco_crosshair_set->clear();
2125 const struct tile *ptile_dest;
2128 if (!ptile || dir > direction8_max()) {
2136 if (!(pglc = mapdeco_gotoline->value(ptile,
nullptr))) {
2138 mapdeco_gotoline->insert(ptile, pglc);
2163 const struct tile *ptile;
2173 for (i = 0; ptile !=
nullptr && i < punit->
orders.
length; i++) {
2186 auto dir = direction8_invalid();
2204 if (!ptile || dir > direction8_max()) {
2208 if (!(pglc = mapdeco_gotoline->value(ptile,
nullptr))) {
2222 gotohash::const_iterator i = mapdeco_gotoline->constBegin();
2223 while (i != mapdeco_gotoline->constEnd()) {
2227 if (i.value()->line_count[dir] > 0
2228 || i.value()->line_danger_count[dir] > 0) {
2236 mapdeco_gotoline->clear();
2265 if (cache_resized) {
2277 if (cache_resized) {
2278 if (center_tile !=
nullptr) {
2336 #define SPECLIST_TAG link_mark
2337 #define SPECLIST_TYPE struct link_mark
2339 #define link_marks_iterate(pmark) \
2340 TYPED_LIST_ITERATE(struct link_mark, link_marks, pmark)
2341 #define link_marks_iterate_end LIST_ITERATE_END
2352 if (pmark->type ==
type && pmark->id ==
id) {
2386 switch (pmark->
type) {
2389 return pcity ? pcity->
tile :
nullptr;
2395 return punit ?
unit_tile(punit) :
nullptr;
2408 switch (pmark->
type) {
2428 int xd = width / 20, yd = height / 20;
2429 int xlen = width / 3, ylen = height / 3;
2430 float canvas_x, canvas_y;
2431 int x_left, x_right, y_top, y_bottom;
2439 x_left = canvas_x + xd;
2440 x_right = canvas_x + width - xd;
2441 y_top = canvas_y + yd;
2442 y_bottom = canvas_y + height - yd;
2445 p.setPen(QPen(color, 2));
2446 p.drawLine(x_left, y_top, x_left + xlen, y_top);
2447 p.drawLine(x_left, y_top, x_left, y_top + ylen);
2449 p.drawLine(x_right, y_top, x_right - xlen, y_top);
2450 p.drawLine(x_right, y_top, x_right, y_top + ylen);
2452 p.drawLine(x_left, y_bottom, x_left + xlen, y_bottom);
2453 p.drawLine(x_left, y_bottom, x_left, y_bottom - ylen);
2455 p.drawLine(x_right, y_bottom, x_right - xlen, y_bottom);
2456 p.drawLine(x_right, y_bottom, x_right, y_bottom - ylen);
2510 if (--pmark->turn_counter <= 0) {
2567 int tileset_topology;
2571 tileset_topology = TF_HEX | TF_ISO;
2574 tileset_topology = TF_HEX;
2576 tileset_topology = TF_ISO;
2578 tileset_topology = 0;
2581 if (tileset_topology & TF_HEX) {
2582 if ((topology_id & (TF_HEX | TF_ISO)) == tileset_topology) {
2590 if (topology_id & TF_HEX) {
2594 if ((topology_id & TF_ISO) != (tileset_topology & TF_ISO)) {
QFont get_font(client_font font)
Returns given font.
int rs_max_city_radius_sq()
Maximum city radius in this ruleset.
struct player * city_owner(const struct city *pcity)
Return the owner of the 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 city_can_be_built_here(const struct tile *ptile, const struct unit *punit)
Returns TRUE if the given unit can build a city at the given map coordinates.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Calculates the turns which are needed to build the requested production in the city.
bool city_base_to_city_map(int *city_map_x, int *city_map_y, const struct city *const pcity, const struct tile *map_tile)
Finds the city map coordinate for a given map position and a city.
int city_turns_to_grow(const struct city *pcity)
Calculates the turns which are needed for the city to grow.
#define cities_iterate_end
#define city_list_iterate(citylist, pcity)
#define cities_iterate(pcity)
#define city_tile_iterate(_radius_sq, _city_tile, _tile)
#define output_type_iterate(output)
#define city_list_iterate_end
#define city_tile_iterate_end
#define output_type_iterate_end
struct city * is_any_city_dialog_open()
int get_citydlg_canvas_height()
Return the height of the city dialog canvas.
int get_citydlg_canvas_width()
Return the width of the city dialog canvas.
bool city_can_buy(const struct city *pcity)
Return TRUE iff the city can buy.
Iterates over all map tiles that intersect with a rectangle in GUI coordinates.
bool next()
Iterates to the next item.
void update_all()
Requests an update of the whole (visible) map.
void update_tile_label(const tile *tile)
Registers a tile label for update.
void update_city_description(const city *city)
Registers a city label for update.
update_type
What kind of update should be performed.
void update(const city *city, bool full)
Registers a city for update.
static void invoke(_member_fct_ function, _args_ &&...args)
bool client_is_global_observer()
Returns whether client is global observer.
struct player * client_player()
Either controlling or observing.
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.
bool client_city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Returns TRUE when a tile is available to be worked, or the city itself is currently working the tile ...
void flush_dirty_overview()
This module contains various general - mostly highlevel - functions used throughout the client.
QColor get_color(const struct tileset *t, enum color_std stdcolor)
Return a pointer to the given "standard" color.
void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
Adjusts way combatants are displayed suitable for combat.
enum cursor_hover_state hover_state
bool editor_tile_is_selected(const struct tile *ptile)
Returns TRUE if the given tile is selected.
bool editor_is_active()
Returns TRUE if the client is in edit mode.
enum output_type_id Output_type_id
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
Return the tile for the given cartesian (map) position.
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
struct tile * nearest_real_tile(const struct civ_map *nmap, int x, int y)
Twiddle *x and *y to point to the nearest real tile, and ensure that the position is normalized.
void base_map_distance_vector(int *dx, int *dy, int x0dv, int y0dv, int x1dv, int y1dv)
Finds the difference between the two (unnormalized) positions, in cartesian (map) coordinates.
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Return the tile for the given index position.
bool base_get_direction_for_step(const struct civ_map *nmap, const struct tile *start_tile, const struct tile *end_tile, enum direction8 *dir)
Return TRUE and sets dir to the direction of the step if (end_x, end_y) can be reached from (start_x,...
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Step from the given tile in the given direction.
bool normalize_map_pos(const struct civ_map *nmap, int *x, int *y)
If the position is real, it will be normalized and TRUE will be returned.
#define current_topo_has_flag(flag)
#define adjc_dir_iterate(nmap, center_tile, itr_tile, dir_itr)
#define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y)
#define NATIVE_TO_MAP_POS(pmap_x, pmap_y, nat_x, nat_y)
#define adjc_dir_iterate_end
#define adjc_dir_base_iterate(nmap, center_tile, dir_itr)
#define adjc_dir_base_iterate_end
#define index_to_map_pos(pmap_x, pmap_y, mindex)
void update_rect_at_mouse_pos()
The Area Selection rectangle.
void create_line_at_mouse_pos()
Draw a goto or patrol line at the current mouse position.
void flush_dirty(void)
Flush all regions that have been previously marked as dirty.
void dirty_all(void)
Mark the entire screen area as "dirty" so that we can flush it later.
void dirty_rect(int canvas_x, int canvas_y, int pixel_width, int pixel_height)
Mark the rectangular region as "dirty" so that we know to flush it later.
void update_minimap(void)
Return a canvas that is the overview window.
void show_city_desc(QPixmap *pcanvas, int canvas_x, int canvas_y, struct city *pcity, int *width, int *height)
Draw a description for the given city.
client_options * gui_options
void overview_init()
Allocates overview resources.
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
Make user-friendly text for the source.
#define CLIP(lower, current, upper)
#define FC_WRAP(value, range)
struct city::@15::@18 client
struct trade_route_list * routes
struct universal production
struct packet_scenario_info scenario
int smooth_move_unit_msec
bool draw_city_trade_routes
int smooth_combat_step_msec
int line_danger_count[DIR8_MAGIC_MAX]
int line_count[DIR8_MAGIC_MAX]
Map link mark module: it makes link marks when a link is sent by chating, or restore a mark with clic...
struct city_list * cities
struct unit::@76::@78 client
bool can_do_cached_drawing
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-...
void fc_usleep(unsigned long usec)
Suspend execution for the specified number of microseconds.
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...
bool tile_virtual_check(const tile *vtile)
Check if the given tile is a virtual one or not.
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
#define tile_worked(_tile)
const QPixmap * get_nuke_explode_sprite(const struct tileset *t)
Return a sprite contining the single nuke graphic.
int tileset_hex_width(const struct tileset *t)
Return the hex_width of the current tileset.
int tileset_unit_width(const struct tileset *t)
Return the unit tile width of the current tileset.
int tileset_unit_height(const struct tileset *t)
Return the unit tile height of the current tileset.
const std::vector< std::unique_ptr< freeciv::layer > > & tileset_get_layers(const struct tileset *t)
const QPixmap * get_unit_upkeep_sprite(const struct tileset *t, Output_type_id otype, const struct unit *punit, const int *upkeep_cost)
Return a sprite for the upkeep of the unit - to be shown as an overlay on the unit in the city suppor...
int tileset_full_tile_height(const struct tileset *t)
Return the full tile height of the current tileset.
int tileset_citybar_offset_y(const struct tileset *t)
Return the offset from the origin of the city tile at which to place the city bar text.
Q_LOGGING_CATEGORY(tileset_category, "freeciv.tileset")
Functions for handling the tilespec files which describe the files and contents of tilesets.
const std::vector< QPixmap * > & get_unit_explode_animation(const struct tileset *t)
Return a sprite_vector containing the animation sprites for a unit explosion.
bool tileset_is_isometric(const struct tileset *t)
Return whether the current tileset is isometric.
int tileset_tile_height(const struct tileset *t)
Return the tile height of the current tileset.
int tileset_hex_height(const struct tileset *t)
Return the hex_height of the current tileset.
const QPixmap * get_unit_unhappy_sprite(const struct tileset *t, const struct unit *punit, int happy_cost)
Return a sprite for the unhappiness of the unit - to be shown as an overlay on the unit in the city s...
struct unit * get_drawable_unit(const struct tileset *t, const ::tile *ptile)
Find unit that we can display from given tile.
int tileset_tile_width(const struct tileset *t)
Return the tile width of the current tileset.
int tileset_tilelabel_offset_y(const struct tileset *t)
Return the offset from the origin of the tile at which to place the label text.
int max_trade_routes(const struct city *pcity)
Return current maximum number of trade routes city can have.
#define trade_partners_iterate_end
#define trade_partners_iterate(c, p)
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlle...
bool unit_has_orders(const struct unit *punit)
Return TRUE iff the unit is following client-side orders.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
static QColor link_mark_color(const struct link_mark *pmark)
Returns the color of the pointed mark.
void link_mark_restore(enum text_link_type type, int id)
Add a visible link for 1 turn.
static void base_canvas_to_map_pos(int *map_x, int *map_y, float canvas_x, float canvas_y)
Finds the map coordinates corresponding to pixel coordinates.
void put_nuke_mushroom_pixmaps(struct tile *ptile)
Animate the nuke explosion at map(x, y).
QHash< const struct tile *, struct gotoline_counter * > gotohash
static void normalize_gui_pos(const struct tileset *t, float *gui_x, float *gui_y)
Normalize (wrap) the GUI position.
bool tile_visible_mapcanvas(struct tile *ptile)
Return TRUE iff the given map position has a tile visible on the map canvas.
void link_marks_draw_all()
Draw all link marks.
static const int MAX_TRADE_ROUTE_DRAW_LINES
void mapdeco_init()
Called when we receive map dimensions.
void set_mapview_origin(float gui_x0, float gui_y0)
Change the mapview origin, clip it, and update everything.
void map_to_gui_vector(const struct tileset *t, float *gui_dx, float *gui_dy, int map_dx, int map_dy)
Translate from a cartesian system to the GUI system.
#define COLOR_MAPVIEW_TILELABEL
struct tile * canvas_pos_to_tile(float canvas_x, float canvas_y)
Finds the tile corresponding to pixel coordinates.
void mapdeco_set_crosshair(const struct tile *ptile, bool crosshair)
Marks the given tile as having a "crosshair" map decoration.
static int max_desc_width
static void link_mark_draw(const struct link_mark *pmark)
Print a link mark.
void init_mapcanvas_and_overview()
Sets up data for the mapview and overview.
static void draw_trade_routes_for_city(const struct city *pcity_src)
Draw all trade routes for the given city.
static bool calc_mapview_origin(float *gui_x0, float *gui_y0)
Adjust mapview origin values.
void put_drawn_sprites(QPixmap *pcanvas, const QPoint &canvas_loc, const std::vector< drawn_sprite > &sprites, bool fog, bool city_unit)
Draw an array of drawn sprites onto the canvas.
void anim_delay(int milliseconds)
void get_city_mapview_production(const city *pcity, char *buffer, size_t buffer_len)
Find the mapview city production text for the given city, and place it into the buffer.
void get_mapview_scroll_pos(int *scroll_x, int *scroll_y)
Find the current scroll position (origin) of the mapview.
void mapdeco_clear_crosshairs()
Clears all previous set tile crosshair decorations.
bool mapdeco_is_highlight_set(const struct tile *ptile)
Return TRUE if the given tile is highlighted.
void get_mapview_scroll_window(float *xmin, float *ymin, float *xmax, float *ymax, int *xsize, int *ysize)
Return the scroll dimensions of the clipping window for the mapview window.
bool mapdeco_is_gotoline_set(const struct tile *ptile, enum direction8 dir, bool *safe)
Returns TRUE if a goto line should be drawn from the given tile in the given direction.
struct tile * get_center_tile_mapcanvas()
Finds the current center tile of the mapcanvas.
struct city * find_city_or_settler_near_tile(const struct tile *ptile, struct unit **punit)
Find the "best" city/settlers to associate with the selected tile.
void move_unit_map_canvas(struct unit *punit, struct tile *src_tile, int dx, int dy)
Animates punit's "smooth" move from (x0, y0) to (x0+dx, y0+dy).
void get_city_mapview_name_and_growth(const city *pcity, char *name_buffer, size_t name_buffer_len, char *growth_buffer, size_t growth_buffer_len, enum color_std *growth_color, enum color_std *production_color)
Fill the two buffers which information about the city which is shown below it.
static void link_mark_destroy(struct link_mark *pmark)
Remove a link mark.
void refresh_tile_mapcanvas(const tile *ptile, bool full_refresh)
Refreshes a single tile on the map canvas.
void mapdeco_set_gotoroute(const struct unit *punit)
Set the map decorations for the given unit's goto route.
static void gui_to_map_pos(const struct tileset *t, int *map_x, int *map_y, float gui_x, float gui_y)
Translate from gui to map coordinate systems.
static void draw_trade_routes()
Draw trade routes between cities as lines on the main map canvas.
void show_city_descriptions(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
Show descriptions for all cities visible on the map canvas.
void mapdeco_add_gotoline(const struct tile *ptile, enum direction8 dir, bool safe)
Add a goto line from the given tile 'ptile' in the direction 'dir'.
void map_canvas_resized(int width, int height)
Called if the map in the GUI is resized.
void free_mapcanvas_and_overview()
Frees resources allocated for mapview and overview.
static bool can_do_cached_drawing()
Returns TRUE if cached drawing is possible.
void put_one_element(QPixmap *pcanvas, const std::unique_ptr< freeciv::layer > &layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const QPoint &canvas_loc)
Draw one layer of a tile, edge, corner, unit, and/or city onto the canvas at the given position.
static QSize max_label_size
static QSize show_tile_label(QPixmap *pcanvas, int canvas_x, int canvas_y, const tile *ptile)
Draw a label for the given tile.
void mapdeco_free()
Free all memory used for map decorations.
#define link_marks_iterate(pmark)
void draw_segment(const tile *src_tile, enum direction8 dir, bool safe)
Draw a goto line at the given location and direction.
void put_terrain(struct tile *ptile, QPixmap *pcanvas, const QPoint &canvas_loc)
Draw the given tile terrain onto the canvas store at the given location.
void link_marks_free()
Free the link marks.
void toggle_city_color(struct city *pcity)
Toggle the city color.
void update_map_canvas(int canvas_x, int canvas_y, int width, int height)
Update (refresh) the map canvas starting at the given tile (in map coordinates) and with the given di...
Q_GLOBAL_STATIC(QElapsedTimer, anim_timer)
#define link_marks_iterate_end
void link_marks_clear_all()
Clear all visible links.
static void base_set_mapview_origin(float gui_x0, float gui_y0)
Move the GUI origin to the given normalized, clipped origin.
void animate_unit_explosion(const tile *location)
Draws an explosion animation on the given sprite.
void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, bool full_refresh)
Refreshes a single city on the map canvas.
void update_city_description(struct city *pcity)
Update the city description for the given city.
void put_unit_city_overlays(const unit *punit, QPixmap *pcanvas, int canvas_x, int canvas_y, const int *upkeep_cost, int happy_cost)
Draw food, gold, and shield upkeep values on the unit.
static struct link_mark * link_mark_new(enum text_link_type type, int id, int turns)
Create a new link mark.
static int trade_route_to_canvas_lines(const struct tile *ptile1, const struct tile *ptile2, struct trade_route_line *lines)
Depending on where ptile1 and ptile2 are on the map canvas, a trade route line may need to be drawn a...
void map_to_gui_pos(const struct tileset *t, float *gui_x, float *gui_y, int map_x, int map_y)
Translate from map to gui coordinate systems.
void gui_distance_vector(const struct tileset *t, float *gui_dx, float *gui_dy, float gui_x0, float gui_y0, float gui_x1, float gui_y1)
Find the vector with minimum "real" distance between two GUI positions.
static struct tile * link_mark_tile(const struct link_mark *pmark)
Returns the location of the pointed mark.
void toggle_unit_color(struct unit *punit)
Toggle the unit color.
void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, bool full_refresh)
Refreshes a single unit on the map canvas.
static int max_desc_height
void link_mark_add_new(enum text_link_type type, int id)
Add a visible link for 2 turns.
static void draw_trade_route_line(const struct tile *ptile1, const struct tile *ptile2, enum color_std color)
Draw a colored trade route line from one tile to another.
void link_marks_decrease_turn_counters()
Clear all visible links.
bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, const tile *ptile)
Finds the canvas coordinates for a map position.
void update_tile_label(const tile *ptile)
Update the label for the given tile.
void link_marks_init()
Initialize the link marks.
static struct link_mark_list * link_marks
void decrease_unit_hp_smooth(struct unit *punit0, int hp0, struct unit *punit1, int hp1)
This function is called to decrease a unit's HP smoothly in battle when combat_animation is turned on...
void mapdeco_clear_gotoroutes()
Clear all goto line map decorations and queues mapview updates for the affected tiles.
bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile)
Return TRUE iff the given map position has a tile visible within the interior of the map canvas.
void get_city_mapview_trade_routes(const city *pcity, char *trade_routes_buffer, size_t trade_routes_buffer_len, enum color_std *pcolor)
Find the mapview city trade routes text for the given city, and place it into the buffer.
static struct link_mark * link_mark_find(enum text_link_type type, int id)
Find a link mark in the list.
enum topo_comp_lvl tileset_map_topo_compatible(int topology_id, struct tileset *tset)
Are the topology and tileset compatible?
static void append_city_buycost_string(const struct city *pcity, char *buffer, int buffer_len)
Append the buy cost of the current production of the given city to the already nullptr-terminated buf...
bool mapdeco_is_crosshair_set(const struct tile *ptile)
Returns TRUE if there is a "crosshair" decoration set at the given tile.
static void put_one_tile(QPixmap *pcanvas, const std::unique_ptr< freeciv::layer > &layer, const tile *ptile, const QPoint &canvas_loc)
Draw some or all of a tile onto the canvas.
void show_tile_labels(int canvas_base_x, int canvas_base_y, int width_base, int height_base)
Show labels for all tiles visible on the map canvas.
void update_map_canvas_visible()
Schedules an update of (only) the visible part of the map at the next unqueue_mapview_update().
struct tile * canvas_pos_to_nearest_tile(float canvas_x, float canvas_y)
Finds the tile corresponding to pixel coordinates.
std::map< freeciv::map_updates_handler::update_type, QRectF > update_rects()
Calculates the area covered by each update type.
void put_unit(const struct unit *punit, QPixmap *pcanvas, const QPoint &canvas_loc)
Draw the given unit onto the canvas store at the given location.
void unqueue_mapview_updates()
See comment in update_map_canvas_visible().
static void swap(struct reqtree *tree, int layer, int order1, int order2)
Swap positions of two nodes on the same layer.