From e9556c04aff81fcb4d01b67b03877a96c9bcd9e2 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 17 Feb 2023 17:51:23 +0200 Subject: [PATCH 25/25] mapview_common.[ch]: Improve Coding Style See osdn #47384 Signed-off-by: Marko Lindqvist --- client/mapview_common.c | 544 +++++++++++++++++++++------------------- client/mapview_common.h | 294 +++++++++++----------- 2 files changed, 427 insertions(+), 411 deletions(-) diff --git a/client/mapview_common.c b/client/mapview_common.c index be87c6dbee..0feb162934 100644 --- a/client/mapview_common.c +++ b/client/mapview_common.c @@ -166,7 +166,7 @@ struct animation struct animation_list *animations = NULL; /************************************************************************//** - Initialize animations system + Initialize animations system. ****************************************************************************/ void animations_init(void) { @@ -174,7 +174,7 @@ void animations_init(void) } /************************************************************************//** - Clean up animations system + Clean up animations system. ****************************************************************************/ void animations_free(void) { @@ -194,7 +194,7 @@ static void anim_timer_renew(void) } /************************************************************************//** - Add new animation to the queue + Add new animation to the queue. ****************************************************************************/ static void animation_add(struct animation *anim) { @@ -486,7 +486,7 @@ void refresh_tile_mapcanvas(struct tile *ptile, Refreshes a single unit on the map canvas. ****************************************************************************/ void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, - bool full_refresh, bool write_to_screen) + bool full_refresh, bool write_to_screen) { if (full_refresh && gui_options.draw_native) { queue_mapview_update(UPDATE_MAP_CANVAS_VISIBLE); @@ -504,7 +504,7 @@ void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, Refreshes a single city on the map canvas. If full_refresh is given then the citymap area and the city text will - also be refreshed. Otherwise only the base city sprite is refreshed. + also be refreshed. Otherwise only the base city sprite is refreshed. ****************************************************************************/ void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, bool full_refresh, bool write_to_screen) @@ -520,23 +520,23 @@ void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, } /************************************************************************//** - Translate from a cartesian system to the GUI system. This function works + Translate from a cartesian system to the GUI system. This function works on vectors, meaning it can be passed a (dx,dy) pair and will return the - change in GUI coordinates corresponding to this vector. It is thus more - general than map_to_gui_pos. + change in GUI coordinates corresponding to this vector. It is thus more + general than map_to_gui_pos(). Note that a gui_to_map_vector function is not possible, since the resulting map vector may differ based on the origin of the gui vector. ****************************************************************************/ void map_to_gui_vector(const struct tileset *t, float zoom, - float *gui_dx, float *gui_dy, int map_dx, int map_dy) + float *gui_dx, float *gui_dy, int map_dx, int map_dy) { if (tileset_is_isometric(t)) { /* * Convert the map coordinates to isometric GUI - * coordinates. We'll make tile map(0,0) be the origin, and + * coordinates. We'll make tile map(0,0) be the origin, and * transform like this: - * + * * 3 * 123 2 6 * 456 -> becomes -> 1 5 9 @@ -555,7 +555,7 @@ void map_to_gui_vector(const struct tileset *t, float zoom, Translate from map to gui coordinate systems. GUI coordinates are comparable to canvas coordinates but extend in all - directions. gui(0,0) == map(0,0). + directions. gui(0,0) == map(0,0). ****************************************************************************/ static void map_to_gui_pos(const struct tileset *t, float *gui_x, float *gui_y, int map_x, int map_y) @@ -566,9 +566,9 @@ static void map_to_gui_pos(const struct tileset *t, } /************************************************************************//** - Translate from gui to map coordinate systems. See map_to_gui_pos(). + Translate from gui to map coordinate systems. See map_to_gui_pos(). - Note that you lose some information in this conversion. If you convert + Note that you lose some information in this conversion. If you convert from a gui position to a map position and back, you will probably not get the same value you started with. ****************************************************************************/ @@ -613,7 +613,7 @@ static void gui_to_map_pos(const struct tileset *t, } else if (tileset_is_isometric(t)) { /* The basic operation here is a simple pi/4 rotation; however, we * have to first scale because the tiles have different width and - * height. Mathematically, this looks like + * height. Mathematically, this looks like * | 1/W 1/H | |x| |x`| * | | | | -> | | * |-1/W 1/H | |y| |y`| @@ -628,7 +628,7 @@ static void gui_to_map_pos(const struct tileset *t, * Here the division is proper mathematical floating point division. * * We have to subtract off a half-tile in the X direction before doing - * the transformation. This is because, although the origin of the tile + * the transformation. This is because, although the origin of the tile * is the top-left corner of the bounding box, after the transformation * the top corner of the diamond-shaped tile moves into this position. * @@ -641,7 +641,7 @@ static void gui_to_map_pos(const struct tileset *t, gui_x -= W / 2; *map_x = DIVIDE((int)(gui_x * H + gui_y * W), (int)(W * H)); *map_y = DIVIDE((int)(gui_y * W - gui_x * H), (int)(W * H)); - } else { /* tileset_is_isometric(t) */ + } else { /* tileset_is_isometric(t) */ /* We use DIVIDE so that we will get the correct result even * for negative coordinates. */ *map_x = DIVIDE((int)gui_x, (int)W); @@ -655,7 +655,7 @@ static void gui_to_map_pos(const struct tileset *t, visible mapview canvas. The result represents the upper left pixel (origin) of the bounding box of - the tile. Note that in iso-view this origin is not a part of the tile + the tile. Note that in iso-view this origin is not a part of the tile itself - so to make the operation reversible you would have to call canvas_to_map_pos on the center of the tile, not the origin. @@ -677,42 +677,42 @@ bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, struct tile *ptile) /* * First we wrap the coordinates to hopefully be within the mapview - * window. We do this by finding the position closest to the center + * window. We do this by finding the position closest to the center * of the window. */ /* TODO: Cache the value of this position */ base_canvas_to_map_pos(¢er_map_x, ¢er_map_y, - mapview.width / 2, - mapview.height / 2); + mapview.width / 2, + mapview.height / 2); index_to_map_pos(&tile_x, &tile_y, tile_index(ptile)); base_map_distance_vector(&dx, &dy, center_map_x, center_map_y, tile_x, tile_y); map_to_gui_pos(tileset, - canvas_x, canvas_y, center_map_x + dx, center_map_y + dy); + canvas_x, canvas_y, center_map_x + dx, center_map_y + dy); *canvas_x -= mapview.gui_x0; *canvas_y -= mapview.gui_y0; /* * Finally we clip. * - * This check is tailored to work for both iso-view and classic view. Note + * This check is tailored to work for both iso-view and classic view. Note * that (canvas_x, canvas_y) need not be aligned to a tile boundary, and * that the position is at the top-left of the NORMAL (not UNIT) tile. * This checks to see if _any part_ of the tile is present on the backing - * store. Even if it's not visible on the canvas, if it's present on the + * store. Even if it's not visible on the canvas, if it's present on the * backing store we need to draw it in case the canvas is resized. */ return (*canvas_x > -tileset_tile_width(tileset) * map_zoom - && *canvas_x < mapview.store_width - && *canvas_y > -tileset_tile_height(tileset) * map_zoom - && *canvas_y < (mapview.store_height - + (tileset_full_tile_height(tileset) + && *canvas_x < mapview.store_width + && *canvas_y > -tileset_tile_height(tileset) * map_zoom + && *canvas_y < (mapview.store_height + + (tileset_full_tile_height(tileset) - tileset_tile_height(tileset)) * map_zoom)); } /************************************************************************//** - Finds the map coordinates corresponding to pixel coordinates. The + Finds the map coordinates corresponding to pixel coordinates. The resulting position is unwrapped and may be unreal. ****************************************************************************/ static void base_canvas_to_map_pos(int *map_x, int *map_y, @@ -724,7 +724,7 @@ static void base_canvas_to_map_pos(int *map_x, int *map_y, } /************************************************************************//** - Finds the tile corresponding to pixel coordinates. Returns that tile, + Finds the tile corresponding to pixel coordinates. Returns that tile, or NULL if the position is off the map. ****************************************************************************/ struct tile *canvas_pos_to_tile(float canvas_x, float canvas_y) @@ -740,19 +740,20 @@ struct tile *canvas_pos_to_tile(float canvas_x, float canvas_y) } /************************************************************************//** - Finds the tile corresponding to pixel coordinates. Returns that tile, - or the one nearest is the position is off the map. Will never return NULL. + Finds the tile corresponding to pixel coordinates. Returns that tile, + or the one nearest is the position is off the map. Will never return NULL. ****************************************************************************/ struct tile *canvas_pos_to_nearest_tile(float canvas_x, float canvas_y) { int map_x, map_y; base_canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y); + return nearest_real_tile(&(wld.map), map_x, map_y); } /************************************************************************//** - Normalize (wrap) the GUI position. This is equivalent to a map wrapping, + Normalize (wrap) the GUI position. This is equivalent to a map wrapping, but in GUI coordinates so that pixel accuracy is preserved. ****************************************************************************/ static void normalize_gui_pos(const struct tileset *t, @@ -768,8 +769,8 @@ static void normalize_gui_pos(const struct tileset *t, diff_x = *gui_x - gui_x0; diff_y = *gui_y - gui_y0; - /* Perform wrapping without any realness check. It's important that - * we wrap even if the map position is unreal, which normalize_map_pos + /* Perform wrapping without any realness check. It's important that + * we wrap even if the map position is unreal, which normalize_map_pos() * doesn't necessarily do. */ MAP_TO_NATIVE_POS(&nat_x, &nat_y, map_x, map_y); if (current_wrap_has_flag(WRAP_X)) { @@ -801,12 +802,12 @@ static void gui_distance_vector(const struct tileset *t, int gui_x0_diff, gui_y0_diff, gui_x1_diff, gui_y1_diff; int map_dx, map_dy; - /* Make sure positions are canonical. Yes, this is the only way. */ + /* Make sure positions are canonical. Yes, this is the only way. */ normalize_gui_pos(t, &gui_x0, &gui_y0); normalize_gui_pos(t, &gui_x1, &gui_y1); /* Now we have to find the offset of each GUI position from its tile - * origin. This is complicated: it means converting to a map position and + * origin. This is complicated: it means converting to a map position and * then back to the GUI position to find the tile origin, then subtracting * to get the offset. */ gui_to_map_pos(t, &map_x0, &map_y0, gui_x0, gui_y0); @@ -832,7 +833,7 @@ static void gui_distance_vector(const struct tileset *t, } /************************************************************************//** - Move the GUI origin to the given normalized, clipped origin. This may + Move the GUI origin to the given normalized, clipped origin. This may be called many times when sliding the mapview. ****************************************************************************/ static void base_set_mapview_origin(float gui_x0, float gui_y0) @@ -843,27 +844,27 @@ static void base_set_mapview_origin(float gui_x0, float gui_y0) int common_x0, common_x1, common_y0, common_y1; int update_x0, update_x1, update_y0, update_y1; - /* Then update everything. This does some tricky math to avoid having - * to do unnecessary redraws in update_map_canvas. This makes for ugly + /* Then update everything. This does some tricky math to avoid having + * to do unnecessary redraws in update_map_canvas(). This makes for ugly * code but speeds up the mapview by a large factor. */ - /* We need to calculate the vector of movement of the mapview. So + /* We need to calculate the vector of movement of the mapview. So * we find the GUI distance vector and then use this to calculate - * the original mapview origin relative to the current position. Thus + * the original mapview origin relative to the current position. Thus * if we move one tile to the left, even if this causes GUI positions * to wrap the distance vector is only one tile. */ normalize_gui_pos(tileset, &gui_x0, &gui_y0); gui_distance_vector(tileset, &dx, &dy, - mapview.gui_x0, mapview.gui_y0, - gui_x0, gui_y0); + mapview.gui_x0, mapview.gui_y0, + gui_x0, gui_y0); old_gui_x0 = gui_x0 - dx; old_gui_y0 = gui_y0 - dy; mapview.gui_x0 = gui_x0; mapview.gui_y0 = gui_y0; - /* Find the overlapping area of the new and old mapview. This is - * done in GUI coordinates. Note that if the GUI coordinates wrap + /* Find the overlapping area of the new and old mapview. This is + * done in GUI coordinates. Note that if the GUI coordinates wrap * no overlap will be found. */ common_x0 = MAX(old_gui_x0, gui_x0); common_x1 = MIN(old_gui_x0, gui_x0) + width; @@ -872,9 +873,9 @@ static void base_set_mapview_origin(float gui_x0, float gui_y0) if (mapview.can_do_cached_drawing && !zoom_is_enabled() && common_x1 > common_x0 && common_y1 > common_y0) { - /* Do a partial redraw only. This means the area of overlap (a - * rectangle) is copied. Then the remaining areas (two rectangles) - * are updated through update_map_canvas. */ + /* Do a partial redraw only. This means the area of overlap (a + * rectangle) is copied. Then the remaining areas (two rectangles) + * are updated through update_map_canvas(). */ struct canvas *target = mapview.tmp_store; if (old_gui_x0 < gui_x0) { @@ -894,20 +895,20 @@ static void base_set_mapview_origin(float gui_x0, float gui_y0) dirty_all(); canvas_copy(target, mapview.store, - common_x0 - old_gui_x0, - common_y0 - old_gui_y0, - common_x0 - gui_x0, common_y0 - gui_y0, - common_x1 - common_x0, common_y1 - common_y0); + common_x0 - old_gui_x0, + common_y0 - old_gui_y0, + common_x0 - gui_x0, common_y0 - gui_y0, + common_x1 - common_x0, common_y1 - common_y0); mapview.tmp_store = mapview.store; mapview.store = target; if (update_y1 > update_y0) { update_map_canvas(0, update_y0 - gui_y0, - width, update_y1 - update_y0); + width, update_y1 - update_y0); } if (update_x1 > update_x0) { update_map_canvas(update_x0 - gui_x0, common_y0 - gui_y0, - update_x1 - update_x0, common_y1 - common_y0); + update_x1 - update_x0, common_y1 - common_y0); } } else { dirty_all(); @@ -915,6 +916,7 @@ static void base_set_mapview_origin(float gui_x0, float gui_y0) } center_tile_overviewcanvas(); + switch (hover_state) { case HOVER_GOTO: case HOVER_PATROL: @@ -925,7 +927,8 @@ static void base_set_mapview_origin(float gui_x0, float gui_y0) case HOVER_PARADROP: case HOVER_ACT_SEL_TGT: break; - }; + } + if (rectangle_active) { update_rect_at_mouse_pos(); } @@ -943,7 +946,7 @@ static bool calc_mapview_origin(float *gui_x0, float *gui_y0) /* Normalize (wrap) the mapview origin. */ normalize_gui_pos(tileset, gui_x0, gui_y0); - /* First wrap/clip the position. Wrapping is done in native positions + /* First wrap/clip the position. Wrapping is done in native positions * while clipping is done in scroll (native) positions. */ get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize); @@ -983,13 +986,13 @@ void set_mapview_origin(float gui_x0, float gui_y0) int frames = 0; /* We track the average FPS, which is used to predict how long the - * next draw will take. We start with a 100 FPS estimate - this + * next draw will take. We start with a 100 FPS estimate - this * value will quickly become irrelevant as the correct value is * calculated, but it's needed to give an estimate of the FPS for * the first draw. * * Note that the initial value shouldn't be larger than the sliding - * time, or we'll jump straight to the last frame. The FPS should + * time, or we'll jump straight to the last frame. The FPS should * therefore be a "high" estimate. */ static double total_frames = 0.01; static double total_time = 0.0001; @@ -1004,7 +1007,7 @@ void set_mapview_origin(float gui_x0, float gui_y0) double mytime; /* Get the current time, and add on the average 1/FPS, which is the - * expected time this frame will take. This is done so that the + * expected time this frame will take. This is done so that the * frame's position is calculated from the expected time when the * frame will complete, rather than the time when the frame drawing * is started. */ @@ -1027,7 +1030,7 @@ void set_mapview_origin(float gui_x0, float gui_y0) total_frames / total_time); /* A very small decay factor to make things more accurate when something - * changes (mapview size, tileset change, etc.). This gives a + * changes (mapview size, tileset change, etc.). This gives a * half-life of 68 slides. */ total_frames *= 0.99; total_time *= 0.99; @@ -1042,17 +1045,17 @@ void set_mapview_origin(float gui_x0, float gui_y0) /************************************************************************//** Return the scroll dimensions of the clipping window for the mapview window.. - Imagine the entire map in scroll coordinates. It is a rectangle. Now - imagine the mapview "window" sliding around through this rectangle. How - far can it slide? In most cases it has to be able to slide past the + Imagine the entire map in scroll coordinates. It is a rectangle. Now + imagine the mapview "window" sliding around through this rectangle. How + far can it slide? In most cases it has to be able to slide past the ends of the map rectangle so that it's capable of reaching the whole area. This function gives constraints on how far the window is allowed to - slide. xmin and ymin are the minimum values for the window origin. + slide. xmin and ymin are the minimum values for the window origin. xsize and ysize give the scroll dimensions of the mapview window. xmax and ymax give the maximum values that the bottom/left ends of the - window may reach. The constraints, therefore, are that: + window may reach. The constraints, therefore, are that: get_mapview_scroll_pos(&scroll_x, &scroll_y); xmin <= scroll_x < xmax - xsize @@ -1061,7 +1064,7 @@ void set_mapview_origin(float gui_x0, float gui_y0) This function should be used anywhere and everywhere that scrolling is constrained. - Note that scroll coordinates, not map coordinates, are used. Currently + Note that scroll coordinates, not map coordinates, are used. Currently these correspond to native coordinates. ****************************************************************************/ void get_mapview_scroll_window(float *xmin, float *ymin, @@ -1084,9 +1087,9 @@ void get_mapview_scroll_window(float *xmin, float *ymin, *ymax += tileset_tile_height(tileset) * map_zoom; /* To be able to center on positions near the edges, we have to be - * allowed to scroll all the way to those edges. To allow wrapping the + * allowed to scroll all the way to those edges. To allow wrapping the * clipping boundary needs to extend past the edge - a half-tile in - * iso-view or a full tile in non-iso view. The above math already has + * iso-view or a full tile in non-iso view. The above math already has * taken care of some of this so all that's left is to fix the corner * cases. */ if (current_wrap_has_flag(WRAP_X)) { @@ -1102,7 +1105,7 @@ void get_mapview_scroll_window(float *xmin, float *ymin, *ymin -= tileset_tile_height(tileset) * map_zoom; } } else { - /* Otherwise it's hard. Very hard. Impossible, in fact. This is just + /* Otherwise it's hard. Very hard. Impossible, in fact. This is just * an approximation - a huge bounding box. */ float gui_x1, gui_y1, gui_x2, gui_y2, gui_x3, gui_y3, gui_x4, gui_y4; int map_x, map_y; @@ -1126,7 +1129,7 @@ void get_mapview_scroll_window(float *xmin, float *ymin, *ymax = MAX(gui_y4, MAX(gui_y2, gui_y3)) + mapview.height / 2; } - /* Make sure the scroll window is big enough to hold the mapview. If + /* Make sure the scroll window is big enough to hold the mapview. If * not scrolling will be very ugly and the GUI may become confused. */ diff = *xsize - (*xmax - *xmin); if (diff > 0) { @@ -1145,8 +1148,8 @@ void get_mapview_scroll_window(float *xmin, float *ymin, } /************************************************************************//** - Find the scroll step for the mapview. This is the amount to scroll (in - scroll coordinates) on each "step". See also get_mapview_scroll_window. + Find the scroll step for the mapview. This is the amount to scroll (in + scroll coordinates) on each "step". See also get_mapview_scroll_window(). ****************************************************************************/ void get_mapview_scroll_step(int *xstep, int *ystep) { @@ -1221,7 +1224,7 @@ void center_tile_mapcanvas(struct tile *ptile) ****************************************************************************/ bool tile_visible_mapcanvas(struct tile *ptile) { - float dummy_x, dummy_y; /* well, it needs two pointers... */ + float dummy_x, dummy_y; /* Well, it needs two pointers... */ return tile_to_canvas_pos(&dummy_x, &dummy_y, ptile); } @@ -1243,9 +1246,9 @@ bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile) float xmin, ymin, xmax, ymax; int xsize, ysize, scroll_x, scroll_y; const int border_x = (tileset_is_isometric(tileset) ? tileset_tile_width(tileset) / 2 * map_zoom - : 2 * tileset_tile_width(tileset) * map_zoom); + : 2 * tileset_tile_width(tileset) * map_zoom); const int border_y = (tileset_is_isometric(tileset) ? tileset_tile_height(tileset) / 2 * map_zoom - : 2 * tileset_tile_height(tileset) * map_zoom); + : 2 * tileset_tile_height(tileset) * map_zoom); bool same = (tileset_is_isometric(tileset) == MAP_IS_ISOMETRIC); get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize); @@ -1258,7 +1261,7 @@ bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile) /* For each direction: if the tile is too close to the mapview border * in that direction, and scrolling can get us any closer to the - * border, then it's a border tile. We can only really check the + * border, then it's a border tile. We can only really check the * scrolling when the mapview window lines up with the map. */ if (canvas_x < border_x && (!same || scroll_x > xmin || current_wrap_has_flag(WRAP_X))) { @@ -1300,17 +1303,17 @@ void put_drawn_sprites(struct canvas *pcanvas, float zoom, canvas_put_sprite_fogged(pcanvas, canvas_x / zoom + pdrawn[i].offset_x, canvas_y / zoom + pdrawn[i].offset_y, - pdrawn[i].sprite, - TRUE, - canvas_x, canvas_y); + pdrawn[i].sprite, + TRUE, + canvas_x, canvas_y); } else { - /* We avoid calling canvas_put_sprite_fogged, even though it + /* We avoid calling canvas_put_sprite_fogged(), even though it * should be a valid thing to do, because gui-gtk-2.0 doesn't have * a full implementation. */ canvas_put_sprite_full(pcanvas, canvas_x / zoom + pdrawn[i].offset_x, canvas_y / zoom + pdrawn[i].offset_y, - pdrawn[i].sprite); + pdrawn[i].sprite); } } } @@ -1334,7 +1337,7 @@ void put_one_element(struct canvas *pcanvas, float zoom, ptile, pedge, pcorner, punit, pcity, citymode, putype); bool fog = (ptile && gui_options.draw_fog_of_war - && TILE_KNOWN_UNSEEN == client_tile_get_known(ptile)); + && TILE_KNOWN_UNSEEN == client_tile_get_known(ptile)); /*** Draw terrain and specials ***/ put_drawn_sprites(pcanvas, zoom, canvas_x, canvas_y, count, tile_sprs, fog); @@ -1369,7 +1372,7 @@ void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float } /************************************************************************//** - Draw the given city onto the canvas store at the given location. The + Draw the given city onto the canvas store at the given location. The area of drawing is tileset_full_tile_height(tileset) x tileset_full_tile_width(tileset). ****************************************************************************/ @@ -1379,8 +1382,8 @@ void put_city(struct city *pcity, struct canvas *pcanvas, float zoom, canvas_y += (tileset_full_tile_height(tileset) - tileset_tile_height(tileset)) * zoom; mapview_layer_iterate(layer) { put_one_element(pcanvas, zoom, layer, - NULL, NULL, NULL, NULL, pcity, - canvas_x, canvas_y, NULL, NULL); + NULL, NULL, NULL, NULL, pcity, + canvas_x, canvas_y, NULL, NULL); } mapview_layer_iterate_end; } @@ -1397,7 +1400,7 @@ void put_terrain(struct tile *ptile, struct canvas *pcanvas, float zoom, canvas_y += (tileset_full_tile_height(tileset) - tileset_tile_height(tileset)) * zoom; mapview_layer_iterate(layer) { put_one_element(pcanvas, zoom, layer, ptile, NULL, NULL, NULL, NULL, - canvas_x, canvas_y, NULL, NULL); + canvas_x, canvas_y, NULL, NULL); } mapview_layer_iterate_end; } @@ -1430,7 +1433,7 @@ void put_unit_city_overlays(struct unit *punit, /* * pcity->client.color_index is an index into the city_colors array. - * When toggle_city_color is called the city's coloration is toggled. When + * When toggle_city_color is called the city's coloration is toggled. When * a city is newly colored its color is taken from color_index and * color_index is moved forward one position. Each color in the array * tells what color the citymap will be drawn on the mapview. @@ -1442,8 +1445,8 @@ static int color_index = 0; /************************************************************************//** - Toggle the city color. This cycles through the possible colors for the - citymap as shown on the mapview. These colors are listed in the + Toggle the city color. This cycles through the possible colors for the + citymap as shown on the mapview. These colors are listed in the city_colors array; above. ****************************************************************************/ void toggle_city_color(struct city *pcity) @@ -1460,8 +1463,8 @@ void toggle_city_color(struct city *pcity) } /************************************************************************//** - Toggle the unit color. This cycles through the possible colors for the - citymap as shown on the mapview. These colors are listed in the + Toggle the unit color. This cycles through the possible colors for the + citymap as shown on the mapview. These colors are listed in the city_colors array; above. ****************************************************************************/ void toggle_unit_color(struct unit *punit) @@ -1503,16 +1506,16 @@ void put_nuke_mushroom_pixmaps(struct tile *ptile) anim->height = height * map_zoom; animation_add(anim); } else { - /* We can't count on the return value of tile_to_canvas_pos since the + /* We can't count on the return value of tile_to_canvas_pos() since the * sprite may span multiple tiles. */ (void) tile_to_canvas_pos(&canvas_x, &canvas_y, ptile); canvas_x += (tileset_tile_width(tileset) - width) / 2 * map_zoom; canvas_y += (tileset_tile_height(tileset) - height) / 2 * map_zoom; - /* Make sure everything is flushed and synced before proceeding. First + /* Make sure everything is flushed and synced before proceeding. First * we update everything to the store, but don't write this to screen. - * Then add the nuke graphic to the store. Finally flush everything to + * Then add the nuke graphic to the store. Finally flush everything to * the screen and wait 1 second. */ unqueue_mapview_updates(FALSE); @@ -1665,9 +1668,11 @@ static void draw_trade_routes(void) } cities_iterate_end; } else { struct player *pplayer = client_player(); + if (!pplayer) { return; } + city_list_iterate(pplayer->cities, pcity) { draw_trade_routes_for_city(pcity); } city_list_iterate_end; @@ -1678,8 +1683,8 @@ static void draw_trade_routes(void) Update (refresh) the map canvas starting at the given tile (in map coordinates) and with the given dimensions (also in map coordinates). - In non-iso view, this is easy. In iso view, we have to use the - Painter's Algorithm to draw the tiles in back first. When we draw + In non-iso view, this is easy. In iso view, we have to use the + Painter's Algorithm to draw the tiles in back first. When we draw a tile, we tell the GUI which part of the tile to draw - which is necessary unless we have an extra buffering step. @@ -1703,8 +1708,8 @@ void update_map_canvas(int canvas_x, int canvas_y, int width, int height) gui_x0 = mapview.gui_x0 + canvas_x; gui_y0 = mapview.gui_y0 + canvas_y; full = (canvas_x == 0 && canvas_y == 0 - && width == mapview.store_width - && height == mapview.store_height); + && width == mapview.store_width + && height == mapview.store_height); log_debug("update_map_canvas(pos=(%d,%d), size=(%d,%d))", canvas_x, canvas_y, width, height); @@ -1719,16 +1724,16 @@ void update_map_canvas(int canvas_x, int canvas_y, int width, int height) mapview.tmp_store = tmp; } - /* Clear the area. This is necessary since some parts of the rectangle - * may not actually have any tiles drawn on them. This will happen when + /* Clear the area. This is necessary since some parts of the rectangle + * may not actually have any tiles drawn on them. This will happen when * the mapview is large enough so that the tile is visible in multiple - * locations. In this case it will only be drawn in one place. + * locations. In this case it will only be drawn in one place. * * Of course it's necessary to draw to the whole area to cover up any old * drawing that was done there. */ canvas_put_rectangle(mapview.store, - get_color(tileset, COLOR_MAPVIEW_UNKNOWN), - canvas_x, canvas_y, width / map_zoom, height / map_zoom); + get_color(tileset, COLOR_MAPVIEW_UNKNOWN), + canvas_x, canvas_y, width / map_zoom, height / map_zoom); mapview_layer_iterate(layer) { if (layer == LAYER_TILELABEL) { @@ -1739,13 +1744,13 @@ void update_map_canvas(int canvas_x, int canvas_y, int width, int height) continue; } gui_rect_iterate_coord(gui_x0, gui_y0, width, - height + (tileset_is_isometric(tileset) - ? (tileset_tile_height(tileset) / 2 * map_zoom) : 0), - ptile, pedge, pcorner, gui_x, gui_y, map_zoom) { + height + (tileset_is_isometric(tileset) + ? (tileset_tile_height(tileset) / 2 * map_zoom) : 0), + ptile, pedge, pcorner, gui_x, gui_y, map_zoom) { const int cx = gui_x - mapview.gui_x0, cy = gui_y - mapview.gui_y0; if (ptile) { - put_one_tile(mapview.store, layer, ptile, cx, cy, NULL); + put_one_tile(mapview.store, layer, ptile, cx, cy, NULL); } else if (pedge) { put_one_element(mapview.store, map_zoom, layer, NULL, pedge, NULL, NULL, NULL, cx, cy, NULL, NULL); @@ -1753,7 +1758,7 @@ void update_map_canvas(int canvas_x, int canvas_y, int width, int height) put_one_element(mapview.store, map_zoom, layer, NULL, NULL, pcorner, NULL, NULL, cx, cy, NULL, NULL); } else { - /* This can happen, for instance for unreal tiles. */ + /* This can happen, for instance for unreal tiles. */ } } gui_rect_iterate_coord_end; } mapview_layer_iterate_end; @@ -1765,11 +1770,11 @@ void update_map_canvas(int canvas_x, int canvas_y, int width, int height) * we want it completely on top. * * Note that a pixel right on the border of a tile may actually contain a - * goto line from an adjacent tile. Thus we draw any extra goto lines + * goto line from an adjacent tile. Thus we draw any extra goto lines * from adjacent tiles (if they're close enough). */ gui_rect_iterate(gui_x0 - GOTO_WIDTH, gui_y0 - GOTO_WIDTH, - width + 2 * GOTO_WIDTH, height + 2 * GOTO_WIDTH, - ptile, pedge, pcorner, map_zoom) { + width + 2 * GOTO_WIDTH, height + 2 * GOTO_WIDTH, + ptile, pedge, pcorner, map_zoom) { if (!ptile) { continue; } @@ -1788,7 +1793,7 @@ void update_map_canvas(int canvas_x, int canvas_y, int width, int height) /* And copy store to tmp_store. */ canvas_copy(mapview.store, mapview.tmp_store, - canvas_x, canvas_y, canvas_x, canvas_y, width, height); + canvas_x, canvas_y, canvas_x, canvas_y, width, height); } dirty_rect(canvas_x, canvas_y, width, height); @@ -1802,11 +1807,11 @@ void update_map_canvas_visible(void) queue_mapview_update(UPDATE_MAP_CANVAS_VISIBLE); } -/* The maximum city description width and height. This gives the dimensions +/* The maximum city description width and height. This gives the dimensions * of a rectangle centered directly beneath the tile a city is on, that * contains the city description. * - * These values are increased when drawing is done. This may mean that + * These values are increased when drawing is done. This may mean that * the change (from increasing the value) won't take place until the * next redraw. */ static int max_desc_width = 0, max_desc_height = 0; @@ -1831,7 +1836,7 @@ void update_tile_label(struct tile *ptile) } /************************************************************************//** - Draw a "full" city bar for the city. This is a subcase of show_city_desc + Draw a "full" city bar for the city. This is a subcase of show_city_desc() (see that function for more info) for tilesets that have a full city bar. ****************************************************************************/ static void show_full_citybar(struct canvas *pcanvas, @@ -1896,7 +1901,8 @@ static void show_full_citybar(struct canvas *pcanvas, get_sprite_dimensions(bg, &bg_w, &bg_h); bg_w *= map_zoom; bg_h *= map_zoom; get_city_mapview_name_and_growth(pcity, name, sizeof(name), - growth, sizeof(growth), &growth_color, &production_color); + growth, sizeof(growth), &growth_color, + &production_color); if (gui_options.draw_city_names) { fc_snprintf(size, sizeof(size), "%d", city_size_get(pcity)); @@ -1911,9 +1917,9 @@ static void show_full_citybar(struct canvas *pcanvas, occupy = citybar->occupancy.p[count]; } else { if (pcity->client.occupied) { - occupy = citybar->occupied; + occupy = citybar->occupied; } else { - occupy = citybar->occupancy.p[0]; + occupy = citybar->occupancy.p[0]; } } @@ -1924,11 +1930,11 @@ static void show_full_citybar(struct canvas *pcanvas, occupy_rect.w *= map_zoom; occupy_rect.h *= map_zoom; width1 = (flag_rect.w + occupy_rect.w + name_rect.w - + 2 * border + size_rect.w); + + 2 * border + size_rect.w); height1 = MAX(flag_rect.h, - MAX(occupy_rect.h, - MAX(name_rect.h + border, - size_rect.h + border))); + MAX(occupy_rect.h, + MAX(name_rect.h + border, + size_rect.h + border))); } if (should_draw_lower_bar) { @@ -1983,7 +1989,7 @@ static void show_full_citybar(struct canvas *pcanvas, occupy_rect.y = canvas_y + (height1 - occupy_rect.h) / 2; name_rect.x = canvas_x + (flag_rect.w + occupy_rect.w - - name_rect.w - size_rect.w - border) / 2; + - name_rect.w - size_rect.w - border) / 2; name_rect.y = canvas_y + (height1 - name_rect.h) / 2; size_rect.x = canvas_x + (*width + 1) / 2 - size_rect.w - border / 2; @@ -2031,7 +2037,7 @@ static void show_full_citybar(struct canvas *pcanvas, for (y = 0; y < *height; y += bg_h) { canvas_put_sprite(pcanvas, (canvas_x - *width / 2 + x) / map_zoom, (canvas_y + y) / map_zoom, - bg, 0, 0, + bg, 0, 0, (*width - x) / map_zoom, (*height - y) / map_zoom); } } @@ -2048,9 +2054,9 @@ static void show_full_citybar(struct canvas *pcanvas, * In the meantime, don't compensate with '/ map_zoom' here, unlike * for canvas_put_sprite/text/rectangle */ canvas_put_line(pcanvas, owner_color, LINE_NORMAL, - (flag_rect.x + flag_rect.w) /* / map_zoom */ - 1, + (flag_rect.x + flag_rect.w) /* / map_zoom */ - 1, canvas_y /* / map_zoom */, - 0, height1 /* / map_zoom */); + 0, height1 /* / map_zoom */); canvas_put_sprite_full(pcanvas, occupy_rect.x / map_zoom, occupy_rect.y / map_zoom, occupy); @@ -2058,9 +2064,9 @@ static void show_full_citybar(struct canvas *pcanvas, FONT_CITY_NAME, get_color(tileset, COLOR_MAPVIEW_CITYTEXT), name); canvas_put_rectangle(pcanvas, owner_color, - (size_rect.x - border / 2) / map_zoom, + (size_rect.x - border / 2) / map_zoom, canvas_y / map_zoom, - (size_rect.w + border) / map_zoom, + (size_rect.w + border) / map_zoom, height1 / map_zoom); { /* Try to pick a color for city size text that contrasts with @@ -2111,34 +2117,34 @@ static void show_full_citybar(struct canvas *pcanvas, /* Draw the city bar's outline. */ /* XXX not scaling by map_zoom, see above */ canvas_put_line(pcanvas, owner_color, LINE_NORMAL, - (canvas_x - *width / 2) /* / map_zoom */, + (canvas_x - *width / 2) /* / map_zoom */, canvas_y /* / map_zoom */, - *width /* / map_zoom */, 0); + *width /* / map_zoom */, 0); canvas_put_line(pcanvas, owner_color, LINE_NORMAL, - (canvas_x - *width / 2) /* / map_zoom */, + (canvas_x - *width / 2) /* / map_zoom */, canvas_y /* / map_zoom */, - 0, *height /* / map_zoom */); + 0, *height /* / map_zoom */); canvas_put_line(pcanvas, owner_color, LINE_NORMAL, - (canvas_x - *width / 2) /* / map_zoom */, + (canvas_x - *width / 2) /* / map_zoom */, (canvas_y + *height) /* / map_zoom */ - 1, - *width /* / map_zoom */, 0); + *width /* / map_zoom */, 0); canvas_put_line(pcanvas, owner_color, LINE_NORMAL, - (canvas_x - *width / 2 + *width) /* / map_zoom */, + (canvas_x - *width / 2 + *width) /* / map_zoom */, canvas_y /* / map_zoom */, - 0, *height /* / map_zoom */); - + 0, *height /* / map_zoom */); + /* Draw the dividing line if we drew both the * upper and lower parts. */ if (gui_options.draw_city_names && should_draw_lower_bar) { canvas_put_line(pcanvas, owner_color, LINE_NORMAL, - (canvas_x - *width / 2) /* / map_zoom */, + (canvas_x - *width / 2) /* / map_zoom */, (canvas_y + height1) /* / map_zoom */ - 1, - *width /* / map_zoom */, 0); + *width /* / map_zoom */, 0); } } /************************************************************************//** - Draw a "small" city bar for the city. This is a subcase of show_city_desc + Draw a "small" city bar for the city. This is a subcase of show_city_desc() (see that function for more info) for tilesets that do not have a full city bar. ****************************************************************************/ @@ -2252,14 +2258,14 @@ static void show_small_citybar(struct canvas *pcanvas, } /************************************************************************//** - Draw a description for the given city. This description may include the + Draw a description for the given city. This description may include the name, turns-to-grow, production, and city turns-to-build (depending on client options). (canvas_x, canvas_y) gives the location on the given canvas at which to - draw the description. This is the location of the city itself so the - text must be drawn underneath it. pcity gives the city to be drawn, - while (*width, *height) should be set by show_city_desc to contain the + draw the description. This is the location of the city itself so the + text must be drawn underneath it. pcity gives the city to be drawn, + while (*width, *height) should be set by show_city_desc() to contain the width and height of the text block (centered directly underneath the city's tile). ****************************************************************************/ @@ -2278,9 +2284,9 @@ static void show_city_desc(struct canvas *pcanvas, Draw a label for the given tile. (canvas_x, canvas_y) gives the location on the given canvas at which to - draw the label. This is the location of the tile itself so the - text must be drawn underneath it. pcity gives the city to be drawn, - while (*width, *height) should be set by show_tile_label to contain the + draw the label. This is the location of the tile itself so the + text must be drawn underneath it. pcity gives the city to be drawn, + while (*width, *height) should be set by show_tile_label() to contain the width and height of the text block (centered directly underneath the city's tile). ****************************************************************************/ @@ -2324,8 +2330,8 @@ void show_city_descriptions(int canvas_base_x, int canvas_base_y, return; } - /* A city description is shown below the city. It has a specified - * maximum width and height (although these are only estimates). Thus + /* A city description is shown below the city. It has a specified + * maximum width and height (although these are only estimates). Thus * we need to update some tiles above the mapview and some to the left * and right. * @@ -2343,9 +2349,9 @@ void show_city_descriptions(int canvas_base_x, int canvas_base_y, * to each side of the mapview. */ gui_rect_iterate_coord(mapview.gui_x0 + canvas_base_x - dx / 2, - mapview.gui_y0 + canvas_base_y - dy, - width_base + dx, height_base + dy - offset_y, - ptile, pedge, pcorner, gui_x, gui_y, map_zoom) { + mapview.gui_y0 + canvas_base_y - dy, + width_base + dx, height_base + dy - offset_y, + ptile, pedge, pcorner, gui_x, gui_y, map_zoom) { const int canvas_x = gui_x - mapview.gui_x0; const int canvas_y = gui_y - mapview.gui_y0; @@ -2387,9 +2393,9 @@ void show_tile_labels(int canvas_base_x, int canvas_base_y, int new_max_width = max_label_width, new_max_height = max_label_height; gui_rect_iterate_coord(mapview.gui_x0 + canvas_base_x - dx / 2, - mapview.gui_y0 + canvas_base_y - dy, - width_base + dx, height_base + dy, - ptile, pedge, pcorner, gui_x, gui_y, map_zoom) { + mapview.gui_y0 + canvas_base_y - dy, + width_base + dx, height_base + dy, + ptile, pedge, pcorner, gui_x, gui_y, map_zoom) { const int canvas_x = gui_x - mapview.gui_x0; const int canvas_y = gui_y - mapview.gui_y0; @@ -2420,7 +2426,7 @@ void show_tile_labels(int canvas_base_x, int canvas_base_y, } /************************************************************************//** - Draw the goto route for the unit. Return TRUE if anything is drawn. + Draw the goto route for the unit. Return TRUE if anything is drawn. This duplicates drawing code that is run during the hover state. ****************************************************************************/ @@ -2447,7 +2453,7 @@ bool show_unit_orders(struct unit *punit) ptile = mapstep(&(wld.map), ptile, order->dir); if (!ptile) { /* This shouldn't happen unless the server gives us invalid - * data. To avoid disaster we need to break out of the + * data. To avoid disaster we need to break out of the * switch and the enclosing for loop. */ fc_assert(NULL != ptile); i = punit->orders.length; @@ -2465,7 +2471,7 @@ bool show_unit_orders(struct unit *punit) } /************************************************************************//** - Draw a goto line at the given location and direction. The line goes from + Draw a goto line at the given location and direction. The line goes from the source tile to the adjacent tile in the given direction. ****************************************************************************/ void draw_segment(struct tile *src_tile, enum direction8 dir) @@ -2485,20 +2491,20 @@ void draw_segment(struct tile *src_tile, enum direction8 dir) /* XXX: canvas_put_line doesn't currently take map_zoom into account * itself, but it probably should? If so this will need adjusting */ canvas_put_line(mapview.store, - get_color(tileset, COLOR_MAPVIEW_GOTO), LINE_GOTO, - canvas_x, canvas_y, canvas_dx, canvas_dy); + get_color(tileset, COLOR_MAPVIEW_GOTO), LINE_GOTO, + canvas_x, canvas_y, canvas_dx, canvas_dy); /* The actual area drawn will extend beyond the base rectangle, since * the goto lines have width. */ dirty_rect(MIN(canvas_x, canvas_x + canvas_dx) - GOTO_WIDTH, - MIN(canvas_y, canvas_y + canvas_dy) - GOTO_WIDTH, - ABS(canvas_dx) + 2 * GOTO_WIDTH, - ABS(canvas_dy) + 2 * GOTO_WIDTH); + MIN(canvas_y, canvas_y + canvas_dy) - GOTO_WIDTH, + ABS(canvas_dx) + 2 * GOTO_WIDTH, + ABS(canvas_dy) + 2 * GOTO_WIDTH); /* It is possible that the mapview wraps between the source and dest - * tiles. In this case they will not be next to each other; they'll be - * on the opposite sides of the screen. If this happens then the dest - * tile will not be updated. This is consistent with the mapview design + * tiles. In this case they will not be next to each other; they'll be + * on the opposite sides of the screen. If this happens then the dest + * tile will not be updated. This is consistent with the mapview design * which fails when the size of the mapview approaches that of the map. */ } @@ -2506,7 +2512,7 @@ void draw_segment(struct tile *src_tile, enum direction8 dir) This function is called to decrease a unit's HP smoothly in battle when combat_animation is turned on. ****************************************************************************/ -void decrease_unit_hp_smooth(struct unit *punit0, int hp0, +void decrease_unit_hp_smooth(struct unit *punit0, int hp0, struct unit *punit1, int hp1) { struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1); @@ -2648,7 +2654,7 @@ void move_unit_map_canvas(struct unit *punit, int tuw; int tuh; - /* only works for adjacent-square moves */ + /* Only works for adjacent-square moves */ if (dx < -1 || dx > 1 || dy < -1 || dy > 1 || (dx == 0 && dy == 0)) { return; } @@ -2726,7 +2732,7 @@ void move_unit_map_canvas(struct unit *punit, flush_dirty(); gui_flush(); - /* Restore the backup. It won't take effect until the next flush. */ + /* Restore the backup. It won't take effect until the next flush. */ canvas_copy(mapview.store, mapview.tmp_store, new_x, new_y, new_x, new_y, tuw, tuh); @@ -2771,47 +2777,47 @@ struct city *find_city_or_settler_near_tile(const struct tile *ptile, if (pcity && pcity->tile) { if (NULL == client.conn.playing || city_owner(pcity) == client.conn.playing) { - /* rule a */ + /* Rule a */ return pcity; } else { - /* rule b */ + /* Rule b */ return NULL; } } - /* rule e */ + /* Rule e */ closest_city = NULL; - /* check within maximum (squared) city radius */ + /* Check within maximum (squared) city radius */ city_tile_iterate(max_rad, ptile, tile1) { pcity = tile_city(tile1); if (pcity - && (NULL == client.conn.playing - || city_owner(pcity) == client.conn.playing) - && client_city_can_work_tile(pcity, tile1)) { + && (NULL == client.conn.playing + || city_owner(pcity) == client.conn.playing) + && client_city_can_work_tile(pcity, tile1)) { /* * Note, we must explicitly check if the tile is workable (with * city_can_work_tile() above), since it is possible that another * city (perhaps an UNSEEN city) may be working it! */ - + if (mapdeco_is_highlight_set(city_tile(pcity))) { - /* rule c */ - return pcity; + /* Rule c */ + return pcity; } if (!closest_city) { - closest_city = pcity; + closest_city = pcity; } } } city_tile_iterate_end; - /* rule d */ + /* Rule d */ if (closest_city || !punit) { return closest_city; } if (!game.scenario.prevent_new_cities) { - /* check within maximum (squared) city radius */ + /* Check within maximum (squared) city radius */ city_tile_iterate(max_rad, ptile, tile1) { unit_list_iterate(tile1->units, psettler) { if ((NULL == client.conn.playing @@ -2837,7 +2843,7 @@ struct city *find_city_or_settler_near_tile(const struct tile *ptile, } } - /* rule g */ + /* Rule g */ return NULL; } @@ -2942,9 +2948,9 @@ static bool callback_queued = FALSE; /* These values hold the tiles that need city, unit, or tile updates. * These different types of updates just tell what area need to be updated, - * not necessarily what's sitting on the tile. A city update covers the - * whole citymap area. A unit update covers just the "full" unit tile - * area. A tile update covers the base tile plus half a tile in each + * not necessarily what's sitting on the tile. A city update covers the + * whole citymap area. A unit update covers just the "full" unit tile + * area. A tile update covers the base tile plus half a tile in each * direction. */ struct tile_list *tile_updates[TILE_UPDATE_COUNT]; @@ -2972,19 +2978,19 @@ static void queue_add_callback(void) /************************************************************************//** This function, along with unqueue_mapview_update(), helps in updating - the mapview when a packet is received. Previously, we just called - update_map_canvas when (for instance) a city update was received. + the mapview when a packet is received. Previously, we just called + update_map_canvas() when (for instance) a city update was received. Not only would this often end up with a lot of duplicated work, but it would also draw over the city descriptions, which would then just - "disappear" from the mapview. The hack is to instead call + "disappear" from the mapview. The hack is to instead call queue_mapview_update in place of this update, and later (after all - packets have been read) call unqueue_mapview_update. The functions + packets have been read) call unqueue_mapview_update(). The functions don't track which areas of the screen need updating, rather when the unqueue is done we just update the whole visible mapqueue, and redraw the city descriptions. Using these functions, updates are done correctly, and are probably - faster too. But it's a bit of a hack to insert this code into the + faster too. But it's a bit of a hack to insert this code into the packet-handling code. ****************************************************************************/ void queue_mapview_update(enum update_type update) @@ -2996,11 +3002,11 @@ void queue_mapview_update(enum update_type update) } /************************************************************************//** - Queue this tile to be refreshed. The refresh will be done some time + Queue this tile to be refreshed. The refresh will be done some time soon thereafter, and grouped with other needed refreshes. - Note this should only be called for tiles. For cities or units use - queue_mapview_xxx_update instead. + Note this should only be called for tiles. For cities or units use + queue_mapview_xxx_update() instead. ****************************************************************************/ void queue_mapview_tile_update(struct tile *ptile, enum tile_update_type type) @@ -3019,18 +3025,18 @@ void queue_mapview_tile_update(struct tile *ptile, ****************************************************************************/ void unqueue_mapview_updates(bool write_to_screen) { - /* Calculate the area covered by each update type. The area array gives + /* Calculate the area covered by each update type. The area array gives * the offset from the tile origin as well as the width and height of the - * area to be updated. This is initialized each time when entering the + * area to be updated. This is initialized each time when entering the * function from the existing tileset variables. * * A TILE update covers the base tile (W x H) plus a half-tile in each * direction (for edge/corner graphics), making its area 2W x 2H. * - * A UNIT update covers a UW x UH area. This is centered horizontally + * A UNIT update covers a UW x UH area. This is centered horizontally * over the tile but extends up above the tile (e.g., units in iso-view). * - * A CITYMAP update covers the whole citymap of a tile. This includes + * A CITYMAP update covers the whole citymap of a tile. This includes * the citymap area itself plus an extra half-tile in each direction (for * edge/corner graphics). */ @@ -3064,8 +3070,8 @@ void unqueue_mapview_updates(bool write_to_screen) needed_updates); /* This code "pops" the lists of tile updates off of the static array and - * stores them locally. This allows further updates to be queued within - * the function itself (namely, within update_map_canvas). */ + * stores them locally. This allows further updates to be queued within + * the function itself (namely, within update_map_canvas() ). */ for (i = 0; i < TILE_UPDATE_COUNT; i++) { my_tile_updates[i] = tile_updates[i]; tile_updates[i] = NULL; @@ -3073,11 +3079,11 @@ void unqueue_mapview_updates(bool write_to_screen) if (!map_is_empty()) { if ((needed_updates & UPDATE_MAP_CANVAS_VISIBLE) - || (needed_updates & UPDATE_CITY_DESCRIPTIONS) + || (needed_updates & UPDATE_CITY_DESCRIPTIONS) || (needed_updates & UPDATE_TILE_LABELS)) { dirty_all(); update_map_canvas(0, 0, mapview.store_width, - mapview.store_height); + mapview.store_height); /* Have to update the overview too, since some tiles may have changed. */ refresh_overview_canvas(); } else { @@ -3090,31 +3096,31 @@ void unqueue_mapview_updates(bool write_to_screen) float xl, yt; int xr, yb; - (void) tile_to_canvas_pos(&xl, &yt, ptile); - - xl += area[i].dx; - yt += area[i].dy; - xr = xl + area[i].w; - yb = yt + area[i].h; - - if (xr > 0 && xl < mapview.width - && yb > 0 && yt < mapview.height) { - min_x = MIN(min_x, xl); - min_y = MIN(min_y, yt); - max_x = MAX(max_x, xr); - max_y = MAX(max_y, yb); - } - - /* FIXME: These overview updates should be batched as well. - * Right now they account for as much as 90% of the runtime of - * the unqueue. */ - overview_update_tile(ptile); - } tile_list_iterate_end; - } + (void) tile_to_canvas_pos(&xl, &yt, ptile); + + xl += area[i].dx; + yt += area[i].dy; + xr = xl + area[i].w; + yb = yt + area[i].h; + + if (xr > 0 && xl < mapview.width + && yb > 0 && yt < mapview.height) { + min_x = MIN(min_x, xl); + min_y = MIN(min_y, yt); + max_x = MAX(max_x, xr); + max_y = MAX(max_y, yb); + } + + /* FIXME: These overview updates should be batched as well. + * Right now they account for as much as 90% of the runtime of + * the unqueue. */ + overview_update_tile(ptile); + } tile_list_iterate_end; + } } if (min_x < max_x && min_y < max_y) { - update_map_canvas(min_x, min_y, max_x - min_x, max_y - min_y); + update_map_canvas(min_x, min_y, max_x - min_x, max_y - min_y); } } } @@ -3178,7 +3184,7 @@ void get_city_mapview_name_and_growth(struct city *pcity, } /************************************************************************//** - Returns TRUE if cached drawing is possible. If the mapview is too large + Returns TRUE if cached drawing is possible. If the mapview is too large we have to turn it off. ****************************************************************************/ static bool can_do_cached_drawing(void) @@ -3190,49 +3196,49 @@ static bool can_do_cached_drawing(void) /* If the mapview window is too large, cached drawing is not possible. * * BACKGROUND: cached drawing occurrs when the mapview is scrolled just - * a short distance. The majority of the mapview window can simply be - * copied while the newly visible areas must be drawn from scratch. This + * a short distance. The majority of the mapview window can simply be + * copied while the newly visible areas must be drawn from scratch. This * speeds up drawing significantly, especially when using the scrollbars * or mapview sliding. * * When the mapview is larger than the map, however, some tiles may become - * visible twice. In this case one instance of the tile will be drawn - * while all others are drawn black. When this happens the cached drawing + * visible twice. In this case one instance of the tile will be drawn + * while all others are drawn black. When this happens the cached drawing * system breaks since it assumes the mapview canvas is an "ideal" window - * over the map. So black tiles may be scrolled from the edges of the + * over the map. So black tiles may be scrolled from the edges of the * mapview into the center, while drawn tiles may be scrolled from the - * center of the mapview out to the edges. The result is very bad. + * center of the mapview out to the edges. The result is very bad. * - * There are a few different ways this could be solved. One way is simply - * to turn off cached drawing, which is what we do now. If the mapview - * window gets to be too large, the caching is disabled. Another would + * There are a few different ways this could be solved. One way is simply + * to turn off cached drawing, which is what we do now. If the mapview + * window gets to be too large, the caching is disabled. Another would * be to prevent the window from getting too large in the first place - * but because the window boundaries aren't at an even tile this would - * mean the entire map could never be shown. Yet another way would be + * mean the entire map could never be shown. Yet another way would be * to draw tiles more than once if they are visible in multiple locations * on the mapview. * * The logic below is complicated and determined in part by * trial-and-error. */ if (!current_wrap_has_flag(WRAP_X) && !current_wrap_has_flag(WRAP_Y)) { - /* An unwrapping map: no limitation. On an unwrapping map no tile can + /* An unwrapping map: no limitation. On an unwrapping map no tile can * be visible twice so there's no problem. */ return TRUE; } if (XOR(current_topo_has_flag(TF_ISO) || current_topo_has_flag(TF_HEX), - tileset_is_isometric(tileset))) { - /* Non-matching. In this case the mapview does not line up with the - * map's axis of wrapping. This will give very bad results for the + tileset_is_isometric(tileset))) { + /* Non-matching. In this case the mapview does not line up with the + * map's axis of wrapping. This will give very bad results for the * player! * We can never show more than half of the map. * - * We divide by 4 below because we have to divide by 2 twice. The + * We divide by 4 below because we have to divide by 2 twice. The * first division by 2 is because the square must be half the size - * of the (width+height). The second division by two is because for + * of the (width+height). The second division by two is because for * an iso-map, NATURAL_XXX has a scale of 2, whereas for iso-view * NORMAL_TILE_XXX has a scale of 2. */ return (w <= (NATURAL_WIDTH + NATURAL_HEIGHT) * W / 4 - && h <= (NATURAL_WIDTH + NATURAL_HEIGHT) * H / 4); + && h <= (NATURAL_WIDTH + NATURAL_HEIGHT) * H / 4); } else { /* Matching. */ const int isofactor = (tileset_is_isometric(tileset) ? 2 : 1); @@ -3241,11 +3247,11 @@ static bool can_do_cached_drawing(void) /* Now we can use the full width and height, with the exception of a small * area on each side. */ if (current_wrap_has_flag(WRAP_X) - && w > (NATURAL_WIDTH - isodiff) * W / isofactor) { + && w > (NATURAL_WIDTH - isodiff) * W / isofactor) { return FALSE; } if (current_wrap_has_flag(WRAP_Y) - && h > (NATURAL_HEIGHT - isodiff) * H / isofactor) { + && h > (NATURAL_HEIGHT - isodiff) * H / isofactor) { return FALSE; } return TRUE; @@ -3253,7 +3259,7 @@ static bool can_do_cached_drawing(void) } /************************************************************************//** - Called when we receive map dimensions. It initialized the mapview + Called when we receive map dimensions. It initialized the mapview decorations. ****************************************************************************/ void mapdeco_init(void) @@ -3569,7 +3575,7 @@ bool map_canvas_resized(int width, int height) /* Check for what's changed. */ tile_size_changed = (tile_width != old_tile_width - || tile_height != old_tile_height); + || tile_height != old_tile_height); size_changed = (width != old_width || height != old_height); /* If the tile size has changed, resize the canvas. */ @@ -3640,7 +3646,7 @@ void init_mapcanvas_and_overview(void) } /************************************************************************//** - Frees resources allocated for mapview and overview + Frees resources allocated for mapview and overview. ****************************************************************************/ void free_mapcanvas_and_overview(void) { @@ -3667,7 +3673,7 @@ void get_spaceship_dimensions(int *width, int *height) void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, const struct player *pplayer) { - int i, x, y; + int i, x, y; const struct player_spaceship *ship = &pplayer->spaceship; int w, h; struct sprite *spr; @@ -3685,8 +3691,8 @@ void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, const int k = i % 3; if ((k == 0 && j >= ship->habitation) - || (k == 1 && j >= ship->life_support) - || (k == 2 && j >= ship->solar_panels)) { + || (k == 1 && j >= ship->life_support) + || (k == 2 && j >= ship->solar_panels)) { continue; } x = modules_info[i].x * w / 4 - w / 2; @@ -3703,7 +3709,7 @@ void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, const int k = i % 2; if ((k == 0 && j >= ship->fuel) - || (k == 1 && j >= ship->propulsion)) { + || (k == 1 && j >= ship->propulsion)) { continue; } x = components_info[i].x * w / 4 - w / 2; @@ -3807,6 +3813,7 @@ static struct tile *link_mark_tile(const struct link_mark *pmark) return punit ? unit_tile(punit) : NULL; } } + return NULL; } @@ -3823,6 +3830,7 @@ static struct color *link_mark_color(const struct link_mark *pmark) case TLT_UNIT: return get_color(tileset, COLOR_MAPVIEW_UNIT_LINK); } + return NULL; } @@ -3849,19 +3857,27 @@ static void link_mark_draw(const struct link_mark *pmark) y_top = canvas_y + yd; y_bottom = canvas_y + height - yd; - /* XXX: canvas_put_line doesn't currently take map_zoom into account + /* XXX: canvas_put_line() doesn't currently take map_zoom into account * itself, but it probably should? If so these will need adjusting */ - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_top, xlen, 0); - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_top, 0, ylen); - - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_top, -xlen, 0); - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_top, 0, ylen); - - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_bottom, xlen, 0); - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_bottom, 0, -ylen); - - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_bottom, -xlen, 0); - canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_bottom, 0, -ylen); + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_top, + xlen, 0); + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_top, + 0, ylen); + + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_top, + -xlen, 0); + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_top, + 0, ylen); + + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_bottom, + xlen, 0); + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_left, y_bottom, + 0, -ylen); + + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_bottom, + -xlen, 0); + canvas_put_line(mapview.store, pcolor, LINE_TILE_FRAME, x_right, y_bottom, + 0, -ylen); } /************************************************************************//** diff --git a/client/mapview_common.h b/client/mapview_common.h index ab3e8c0f72..2f17cfdfed 100644 --- a/client/mapview_common.h +++ b/client/mapview_common.h @@ -31,14 +31,14 @@ extern "C" { #include "tilespec.h" -struct canvas_store; /* opaque type, real type is gui-dep */ +struct canvas_store; /* Opaque type, real type is gui-dep */ struct view { float gui_x0, gui_y0; - int width, height; /* Size in pixels. */ - int tile_width, tile_height; /* Size in tiles. Rounded up. */ + int width, height; /* Size in pixels. */ + int tile_width, tile_height; /* Size in tiles. Rounded up. */ int store_width, store_height; - bool can_do_cached_drawing; /* TRUE if cached drawing is possible. */ + bool can_do_cached_drawing; /* TRUE if cached drawing is possible. */ struct canvas *store, *tmp_store; }; @@ -64,7 +64,7 @@ void client_infratile_set(struct tile *ptile); extern struct view mapview; -/* HACK: Callers can set this to FALSE to disable sliding. It should be +/* HACK: Callers can set this to FALSE to disable sliding. It should be * reenabled afterwards. */ extern bool can_slide; @@ -82,12 +82,12 @@ extern bool can_slide; * These values may be negative. * * _t, _e, _c: the tile, edge, or corner that is being iterated, declared - * inside the macro. Usually, only one of them will be non-NULL at a time. + * inside the macro. Usually, only one of them will be non-NULL at a time. * These values may be passed directly to fill_sprite_array(). * * _x, _y: the canvas position of the current element, declared inside - * the macro. Each element is assumed to be tileset_tile_width(tileset) * - * tileset_tile_height(tileset) in size. If an element is larger, the + * the macro. Each element is assumed to be tileset_tile_width(tileset) * + * tileset_tile_height(tileset) in size. If an element is larger, the * caller needs to use a larger rectangle of iteration. * * The grid of iteration is rather complicated. For a picture of it see @@ -95,140 +95,140 @@ extern bool can_slide; * (originally newgrid.png in PR#12085). */ #define gui_rect_iterate(GRI_x0, GRI_y0, GRI_width, GRI_height, \ - _t, _e, _c, _zoom) \ -{ \ - int _x_##_0 = (GRI_x0), _y_##_0 = (GRI_y0); \ - int _x_##_w = (GRI_width), _y_##_h = (GRI_height); \ - \ - if (_x_##_w < 0) { \ - _x_##_0 += _x_##_w; \ - _x_##_w = -_x_##_w; \ - } \ - if (_y_##_h < 0) { \ - _y_##_0 += _y_##_h; \ - _y_##_h = -_y_##_h; \ - } \ - if (_x_##_w > 0 && _y_##_h > 0) { \ - struct tile_edge _t##_e; \ - struct tile_corner _t##_c; \ - int _t##_xi, _t##_yi, _t##_si, _t##_di; \ - const int _t##_r1 = (tileset_is_isometric(tileset) ? 2 : 1); \ - const int _t##_r2 = _t##_r1 * 2; /* double the ratio */ \ + _t, _e, _c, _zoom) \ +{ \ + int _x_##_0 = (GRI_x0), _y_##_0 = (GRI_y0); \ + int _x_##_w = (GRI_width), _y_##_h = (GRI_height); \ + \ + if (_x_##_w < 0) { \ + _x_##_0 += _x_##_w; \ + _x_##_w = -_x_##_w; \ + } \ + if (_y_##_h < 0) { \ + _y_##_0 += _y_##_h; \ + _y_##_h = -_y_##_h; \ + } \ + if (_x_##_w > 0 && _y_##_h > 0) { \ + struct tile_edge _t##_e; \ + struct tile_corner _t##_c; \ + int _t##_xi, _t##_yi, _t##_si, _t##_di; \ + const int _t##_r1 = (tileset_is_isometric(tileset) ? 2 : 1); \ + const int _t##_r2 = _t##_r1 * 2; /* Double the ratio */ \ const int _t##_w = tileset_tile_width(tileset) * _zoom; \ - const int _t##_h = tileset_tile_height(tileset) * _zoom; \ - /* Don't divide by _r2 yet, to avoid integer rounding errors. */ \ + const int _t##_h = tileset_tile_height(tileset) * _zoom; \ + /* Don't divide by _r2 yet, to avoid integer rounding errors. */ \ const int _t##_x0 = DIVIDE(_x_##_0 * _t##_r2, _t##_w) - _t##_r1 / 2;\ const int _t##_y0 = DIVIDE(_y_##_0 * _t##_r2, _t##_h) - _t##_r1 / 2;\ const int _t##_x1 = DIVIDE((_x_##_0 + _x_##_w) * _t##_r2 + _t##_w - 1,\ - _t##_w) + _t##_r1; \ + _t##_w) + _t##_r1; \ const int _t##_y1 = DIVIDE((_y_##_0 + _y_##_h) * _t##_r2 + _t##_h - 1,\ - _t##_h) + _t##_r1; \ - const int _t##_count = (_t##_x1 - _t##_x0) * (_t##_y1 - _t##_y0); \ - int _t##_index = 0; \ - \ - log_debug("Iterating over %d-%d x %d-%d rectangle.", \ - _t##_x1, _t##_x0, _t##_y1, _t##_y0); \ - for (; _t##_index < _t##_count; _t##_index++) { \ - struct tile *_t = NULL; \ - struct tile_edge *_e = NULL; \ - struct tile_corner *_c = NULL; \ - \ - _t##_xi = _t##_x0 + (_t##_index % (_t##_x1 - _t##_x0)); \ - _t##_yi = _t##_y0 + (_t##_index / (_t##_x1 - _t##_x0)); \ - _t##_si = _t##_xi + _t##_yi; \ - _t##_di = _t##_yi - _t##_xi; \ - if (2 == _t##_r1 /*tileset_is_isometric(tileset)*/) { \ - if ((_t##_xi + _t##_yi) % 2 != 0) { \ - continue; \ - } \ - if (_t##_xi % 2 == 0 && _t##_yi % 2 == 0) { \ - if ((_t##_xi + _t##_yi) % 4 == 0) { \ - /* Tile */ \ - _t = map_pos_to_tile(&(wld.map), _t##_si / 4 - 1, _t##_di / 4); \ - } else { \ - /* Corner */ \ - _c = &_t##_c; \ - _c->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \ - (_t##_di - 2) / 4); \ - _c->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \ - (_t##_di - 2) / 4); \ - _c->tile[2] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \ - (_t##_di + 2) / 4); \ - _c->tile[3] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \ - (_t##_di + 2) / 4); \ - if (tileset_hex_width(tileset) > 0) { \ - _e = &_t##_e; \ - _e->type = EDGE_UD; \ - _e->tile[0] = _c->tile[0]; \ - _e->tile[1] = _c->tile[2]; \ - } else if (tileset_hex_height(tileset) > 0) { \ - _e = &_t##_e; \ - _e->type = EDGE_LR; \ - _e->tile[0] = _c->tile[1]; \ - _e->tile[1] = _c->tile[3]; \ - } \ - } \ - } else { \ - /* Edge. */ \ - _e = &_t##_e; \ - if (_t##_si % 4 == 0) { \ - _e->type = EDGE_NS; \ - _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 4) / 4, \ - (_t##_di - 2) / 4); /*N*/ \ - _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 4) / 4, \ - (_t##_di + 2) / 4); /*S*/ \ - } else { \ - _e->type = EDGE_WE; \ - _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \ - _t##_di / 4); /*W*/ \ - _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \ - _t##_di / 4); /*E*/ \ - } \ - } \ - } else { \ - if (_t##_si % 2 == 0) { \ - if (_t##_xi % 2 == 0) { \ - /* Corner. */ \ - _c = &_t##_c; \ - _c->tile[0] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \ - _t##_yi / 2 - 1); /*NW*/ \ - _c->tile[1] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \ - _t##_yi / 2 - 1); /*NE*/ \ - _c->tile[2] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \ - _t##_yi / 2); /*SE*/ \ - _c->tile[3] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \ - _t##_yi / 2); /*SW*/ \ - } else { \ - /* Tile. */ \ - _t = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \ - (_t##_yi - 1) / 2); \ - } \ - } else { \ - /* Edge. */ \ - _e = &_t##_e; \ - if (_t##_yi % 2 == 0) { \ - _e->type = EDGE_NS; \ - _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \ - _t##_yi / 2 - 1); /*N*/ \ - _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \ - _t##_yi / 2); /*S*/ \ - } else { \ - _e->type = EDGE_WE; \ - _e->tile[0] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \ - (_t##_yi - 1) / 2); /*W*/ \ - _e->tile[1] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \ - (_t##_yi - 1) / 2); /*E*/ \ - } \ - } \ + _t##_h) + _t##_r1; \ + const int _t##_count = (_t##_x1 - _t##_x0) * (_t##_y1 - _t##_y0); \ + int _t##_index = 0; \ + \ + log_debug("Iterating over %d-%d x %d-%d rectangle.", \ + _t##_x1, _t##_x0, _t##_y1, _t##_y0); \ + for (; _t##_index < _t##_count; _t##_index++) { \ + struct tile *_t = NULL; \ + struct tile_edge *_e = NULL; \ + struct tile_corner *_c = NULL; \ + \ + _t##_xi = _t##_x0 + (_t##_index % (_t##_x1 - _t##_x0)); \ + _t##_yi = _t##_y0 + (_t##_index / (_t##_x1 - _t##_x0)); \ + _t##_si = _t##_xi + _t##_yi; \ + _t##_di = _t##_yi - _t##_xi; \ + if (2 == _t##_r1 /* tileset_is_isometric(tileset) */) { \ + if ((_t##_xi + _t##_yi) % 2 != 0) { \ + continue; \ + } \ + if (_t##_xi % 2 == 0 && _t##_yi % 2 == 0) { \ + if ((_t##_xi + _t##_yi) % 4 == 0) { \ + /* Tile */ \ + _t = map_pos_to_tile(&(wld.map), _t##_si / 4 - 1, _t##_di / 4); \ + } else { \ + /* Corner */ \ + _c = &_t##_c; \ + _c->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \ + (_t##_di - 2) / 4); \ + _c->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \ + (_t##_di - 2) / 4); \ + _c->tile[2] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \ + (_t##_di + 2) / 4); \ + _c->tile[3] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \ + (_t##_di + 2) / 4); \ + if (tileset_hex_width(tileset) > 0) { \ + _e = &_t##_e; \ + _e->type = EDGE_UD; \ + _e->tile[0] = _c->tile[0]; \ + _e->tile[1] = _c->tile[2]; \ + } else if (tileset_hex_height(tileset) > 0) { \ + _e = &_t##_e; \ + _e->type = EDGE_LR; \ + _e->tile[0] = _c->tile[1]; \ + _e->tile[1] = _c->tile[3]; \ + } \ + } \ + } else { \ + /* Edge. */ \ + _e = &_t##_e; \ + if (_t##_si % 4 == 0) { \ + _e->type = EDGE_NS; \ + _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 4) / 4, \ + (_t##_di - 2) / 4); /*N*/ \ + _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 4) / 4, \ + (_t##_di + 2) / 4); /*S*/ \ + } else { \ + _e->type = EDGE_WE; \ + _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_si - 6) / 4, \ + _t##_di / 4); /*W*/ \ + _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_si - 2) / 4, \ + _t##_di / 4); /*E*/ \ + } \ + } \ + } else { \ + if (_t##_si % 2 == 0) { \ + if (_t##_xi % 2 == 0) { \ + /* Corner. */ \ + _c = &_t##_c; \ + _c->tile[0] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \ + _t##_yi / 2 - 1); /*NW*/ \ + _c->tile[1] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \ + _t##_yi / 2 - 1); /*NE*/ \ + _c->tile[2] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \ + _t##_yi / 2); /*SE*/ \ + _c->tile[3] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \ + _t##_yi / 2); /*SW*/ \ + } else { \ + /* Tile. */ \ + _t = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \ + (_t##_yi - 1) / 2); \ + } \ + } else { \ + /* Edge. */ \ + _e = &_t##_e; \ + if (_t##_yi % 2 == 0) { \ + _e->type = EDGE_NS; \ + _e->tile[0] = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \ + _t##_yi / 2 - 1); /*N*/ \ + _e->tile[1] = map_pos_to_tile(&(wld.map), (_t##_xi - 1) / 2, \ + _t##_yi / 2); /*S*/ \ + } else { \ + _e->type = EDGE_WE; \ + _e->tile[0] = map_pos_to_tile(&(wld.map), _t##_xi / 2 - 1, \ + (_t##_yi - 1) / 2); /*W*/ \ + _e->tile[1] = map_pos_to_tile(&(wld.map), _t##_xi / 2, \ + (_t##_yi - 1) / 2); /*E*/ \ + } \ + } \ } -#define gui_rect_iterate_end \ - } \ - } \ +#define gui_rect_iterate_end \ + } \ + } \ } -#define gui_rect_iterate_coord(GRI_x0, GRI_y0, GRI_width, GRI_height, \ - _t, _e, _c, _x, _y, _zoom) \ +#define gui_rect_iterate_coord(GRI_x0, GRI_y0, GRI_width, GRI_height, \ + _t, _e, _c, _x, _y, _zoom) \ gui_rect_iterate(GRI_x0, GRI_y0, GRI_width, GRI_height, \ _t, _e, _c, _zoom) { \ int _x, _y; \ @@ -240,16 +240,16 @@ extern bool can_slide; } gui_rect_iterate_end void refresh_tile_mapcanvas(struct tile *ptile, - bool full_refresh, bool write_to_screen); + bool full_refresh, bool write_to_screen); void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile, - bool full_refresh, bool write_to_screen); + bool full_refresh, bool write_to_screen); void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile, - bool full_refresh, bool write_to_screen); + bool full_refresh, bool write_to_screen); void unqueue_mapview_updates(bool write_to_screen); void map_to_gui_vector(const struct tileset *t, float zoom, - float *gui_dx, float *gui_dy, int map_dx, int map_dy); + float *gui_dx, float *gui_dy, int map_dx, int map_dy); bool tile_to_canvas_pos(float *canvas_x, float *canvas_y, struct tile *ptile); struct tile *canvas_pos_to_tile(float canvas_x, float canvas_y); struct tile *canvas_pos_to_nearest_tile(float canvas_x, float canvas_y); @@ -315,23 +315,23 @@ bool show_unit_orders(struct unit *punit); void draw_segment(struct tile *ptile, enum direction8 dir); void undraw_segment(struct tile *ptile, enum direction8 dir); -void decrease_unit_hp_smooth(struct unit *punit0, int hp0, - struct unit *punit1, int hp1); +void decrease_unit_hp_smooth(struct unit *punit0, int hp0, + struct unit *punit1, int hp1); void move_unit_map_canvas(struct unit *punit, - struct tile *ptile, int dx, int dy); + struct tile *ptile, int dx, int dy); struct city *find_city_or_settler_near_tile(const struct tile *ptile, - struct unit **punit); + struct unit **punit); struct city *find_city_near_tile(const struct tile *ptile); void get_city_mapview_production(struct city *pcity, char *buf, size_t buf_len); void get_city_mapview_name_and_growth(struct city *pcity, - char *name_buffer, - size_t name_buffer_len, - char *growth_buffer, - size_t growth_buffer_len, - enum color_std *growth_color, + 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); void get_city_mapview_trade_routes(struct city *pcity, char *trade_routes_buffer, @@ -344,7 +344,7 @@ void free_mapcanvas_and_overview(void); void get_spaceship_dimensions(int *width, int *height); void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y, - const struct player *pplayer); + const struct player *pplayer); void link_marks_init(void); void link_marks_free(void); -- 2.39.1