From 07ef83131ab1c2edbdb1683066961a70091bd0b3 Mon Sep 17 00:00:00 2001 From: Gunter Labes Date: Sat, 15 Mar 2025 20:51:37 +0100 Subject: [PATCH] Make function properly local and fix variable names --- src/game_display.cpp | 149 +++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 77 deletions(-) diff --git a/src/game_display.cpp b/src/game_display.cpp index 64d58c16711..081c0128ffd 100644 --- a/src/game_display.cpp +++ b/src/game_display.cpp @@ -52,13 +52,6 @@ static lg::log_domain log_display("display"); static lg::log_domain log_engine("engine"); #define ERR_NG LOG_STREAM(err, log_engine) -/** - * Function to return 2 half-hex footsteps images for the given location. - * Only loc is on the current route set by set_route. - * - * This function is only used internally by game_display so I have moved it out of the header into the compilaton unit. - */ -std::vector footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_); game_display::game_display(game_board& board, std::weak_ptr wb, @@ -223,7 +216,79 @@ const std::string mouseover_self_bot = "misc/hover-hex-bottom.png~RC(magenta>gre const std::string mouseover_ally_top = "misc/hover-hex-top.png~RC(magenta>lightblue)"; const std::string mouseover_ally_bot = "misc/hover-hex-bottom.png~RC(magenta>lightblue)"; + +/** + * Function to return 2 half-hex footsteps images for the given location. + * Only loc is on the current route set by set_route. + */ +std::vector footsteps_images(const map_location& loc, const pathfind::marked_route& route, const display_context* dc) +{ + std::vector res; + + if (route.steps.size() < 2) { + return res; // no real "route" + } + + std::vector::const_iterator i = + std::find(route.steps.begin(),route.steps.end(),loc); + + if( i == route.steps.end()) { + return res; // not on the route + } + + // Check which footsteps images of game_config we will use + int move_cost = 1; + const unit_map::const_iterator u = dc->units().find(route.steps.front()); + if(u != dc->units().end()) { + move_cost = u->movement_cost(dc->map().get_terrain(loc)); + } + int image_number = std::min(move_cost, game_config::foot_speed_prefix.size()); + if (image_number < 1) { + return res; // Invalid movement cost or no images + } + const std::string foot_speed_prefix = game_config::foot_speed_prefix[image_number-1]; + + texture teleport; + + // We draw 2 half-hex (with possibly different directions), + // but skip the first for the first step. + const int first_half = (i == route.steps.begin()) ? 1 : 0; + // and the second for the last step + const int second_half = (i+1 == route.steps.end()) ? 0 : 1; + + for (int h = first_half; h <= second_half; ++h) { + const std::string sense( h==0 ? "-in" : "-out" ); + + if (!tiles_adjacent(*(i+(h-1)), *(i+h))) { + std::string teleport_image = + h==0 ? game_config::foot_teleport_enter : game_config::foot_teleport_exit; + teleport = image::get_texture(teleport_image, image::HEXED); + continue; + } + + // In function of the half, use the incoming or outgoing direction + map_location::direction dir = (i+(h-1))->get_relative_dir(*(i+h)); + + std::string rotate; + if (dir > map_location::direction::south_east) { + // No image, take the opposite direction and do a 180 rotation + dir = i->get_opposite_direction(dir); + rotate = "~FL(horiz)~FL(vert)"; + } + + const std::string image = foot_speed_prefix + + sense + "-" + i->write_direction(dir) + + ".png" + rotate; + + res.push_back(image::get_texture(image, image::HEXED)); + } + + // we draw teleport image (if any) in last + if (teleport != nullptr) res.push_back(teleport); + + return res; } +} //anonymous namespace void game_display::draw_hex(const map_location& loc) { @@ -464,76 +529,6 @@ void game_display::draw_movement_info(const map_location& loc) } } -std::vector footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_) -{ - std::vector res; - - if (route_.steps.size() < 2) { - return res; // no real "route" - } - - std::vector::const_iterator i = - std::find(route_.steps.begin(),route_.steps.end(),loc); - - if( i == route_.steps.end()) { - return res; // not on the route - } - - // Check which footsteps images of game_config we will use - int move_cost = 1; - const unit_map::const_iterator u = dc_->units().find(route_.steps.front()); - if(u != dc_->units().end()) { - move_cost = u->movement_cost(dc_->map().get_terrain(loc)); - } - int image_number = std::min(move_cost, game_config::foot_speed_prefix.size()); - if (image_number < 1) { - return res; // Invalid movement cost or no images - } - const std::string foot_speed_prefix = game_config::foot_speed_prefix[image_number-1]; - - texture teleport; - - // We draw 2 half-hex (with possibly different directions), - // but skip the first for the first step. - const int first_half = (i == route_.steps.begin()) ? 1 : 0; - // and the second for the last step - const int second_half = (i+1 == route_.steps.end()) ? 0 : 1; - - for (int h = first_half; h <= second_half; ++h) { - const std::string sense( h==0 ? "-in" : "-out" ); - - if (!tiles_adjacent(*(i+(h-1)), *(i+h))) { - std::string teleport_image = - h==0 ? game_config::foot_teleport_enter : game_config::foot_teleport_exit; - teleport = image::get_texture(teleport_image, image::HEXED); - continue; - } - - // In function of the half, use the incoming or outgoing direction - map_location::direction dir = (i+(h-1))->get_relative_dir(*(i+h)); - - std::string rotate; - if (dir > map_location::direction::south_east) { - // No image, take the opposite direction and do a 180 rotation - dir = i->get_opposite_direction(dir); - rotate = "~FL(horiz)~FL(vert)"; - } - - const std::string image = foot_speed_prefix - + sense + "-" + i->write_direction(dir) - + ".png" + rotate; - - res.push_back(image::get_texture(image, image::HEXED)); - } - - // we draw teleport image (if any) in last - if (teleport != nullptr) res.push_back(teleport); - - return res; -} - - - void game_display::highlight_reach(const pathfind::paths &paths_list) { unhighlight_reach();