Skip to content

Commit

Permalink
unit_moves: Show the predicted unit moves, not the current ones
Browse files Browse the repository at this point in the history
This is consistent with the alignment, timeofday, and unit_weapons reports.
  • Loading branch information
jostephd committed May 24, 2019
1 parent 35d816b commit 7622dc3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/game_display.hpp
Expand Up @@ -114,6 +114,12 @@ class game_display : public display
* valid after being set.
*/
void set_route(const pathfind::marked_route *route);
/**
* Gets the route along which footsteps are drawn to show movement of a
* unit. If no route is currently being shown, the array get_route().steps
* will be empty.
*/
const pathfind::marked_route& get_route() { return route_; }

/** Function to float a label above a tile */
void float_label(const map_location& loc, const std::string& text, const color_t& color);
Expand Down
30 changes: 26 additions & 4 deletions src/reports.cpp
Expand Up @@ -23,6 +23,7 @@
#include "language.hpp"
#include "map/map.hpp"
#include "mouse_events.hpp"
#include "pathfind/pathfind.hpp"
#include "picture.hpp"
#include "reports.hpp"
#include "color.hpp"
Expand Down Expand Up @@ -648,7 +649,7 @@ REPORT_GENERATOR(selected_unit_vision, rc)
return unit_vision(u);
}

static config unit_moves(reports::context & rc, const unit* u)
static config unit_moves(reports::context & rc, const unit* u, bool is_visible_unit)
{
if (!u) return config();
std::ostringstream str, tooltip;
Expand Down Expand Up @@ -699,18 +700,39 @@ static config unit_moves(reports::context & rc, const unit* u)

int grey = 128 + static_cast<int>((255 - 128) * movement_frac);
color_t c = color_t(grey, grey, grey);
str << span_color(c) << u->movement_left() << '/' << u->total_movement() << naps;
int numerator = u->movement_left();
if(is_visible_unit) {
const pathfind::marked_route& route = game_display::get_singleton()->get_route();
if(route.steps.size() > 0) {
numerator -= route.move_cost;
if(numerator < 0) {
// Multi-turn move
// TODO: what to show in this case?
numerator = 0;
}

// If the route captures a village, assume that uses up all remaining MP.
const auto& end = route.marks.find(route.steps.back());
if(end != route.marks.end() && end->second.capture) {
numerator = 0;
}
} else {
// TODO: if the mouseover hex is unreachable (for example, a deep water hex
// and the current unit is a land unit), what to show?
}
}
str << span_color(c) << numerator << '/' << u->total_movement() << naps;
return text_report(str.str(), tooltip.str());
}
REPORT_GENERATOR(unit_moves, rc)
{
const unit *u = get_visible_unit(rc);
return unit_moves(rc, u);
return unit_moves(rc, u, true);
}
REPORT_GENERATOR(selected_unit_moves, rc)
{
const unit *u = get_selected_unit(rc);
return unit_moves(rc, u);
return unit_moves(rc, u, false);
}

static inline const color_t attack_info_percent_color(int resistance)
Expand Down

0 comments on commit 7622dc3

Please sign in to comment.