Make function properly local and fix variable names

This commit is contained in:
Gunter Labes 2025-03-15 20:51:37 +01:00
parent 470c0b8b0a
commit 07ef83131a
No known key found for this signature in database
GPG Key ID: C0C7B971CC910216

View File

@ -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<texture> 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::manager> 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<texture> footsteps_images(const map_location& loc, const pathfind::marked_route& route, const display_context* dc)
{
std::vector<texture> res;
if (route.steps.size() < 2) {
return res; // no real "route"
}
std::vector<map_location>::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<int>(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<texture> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_)
{
std::vector<texture> res;
if (route_.steps.size() < 2) {
return res; // no real "route"
}
std::vector<map_location>::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<int>(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();