show intermediate distance when sending a unit far away

This commit is contained in:
Jérémy Rosen 2006-05-08 08:56:36 +00:00
parent 6ecf3554f3
commit 0172033bda
4 changed files with 22 additions and 7 deletions

View file

@ -45,6 +45,7 @@ SVN trunk (1.1.2+svn):
* improvements to loadscreen progressbar
* new selection stlye for menu listboxes
* all flags are not synchrone anymore
* show intermediate distance when selecting multi-turn destinations
* multiplayer maps:
* added multiplayer maps: 8p Morituri
* revised multiplayer maps: Blitz, Charge, Cynsaun Battlefield, Den of Onis,

View file

@ -1611,9 +1611,11 @@ void display::draw_movement_info(const gamemap::location& loc, int xloc, int ylo
{
std::vector<gamemap::location>::const_iterator i =
std::find(route_.steps.begin(),route_.steps.end(),loc);
const bool show_time = (i+1 == route_.steps.end());
if(show_time == false) {
//if there isn't a match for "loc" in "route_.turn_waypoints", return.
std::map<gamemap::location, int>::iterator turn_waypoint_iter;
turn_waypoint_iter = route_.turn_waypoints.find(loc);
if(turn_waypoint_iter == route_.turn_waypoints.end()) {
return;
}
@ -1629,9 +1631,9 @@ void display::draw_movement_info(const gamemap::location& loc, int xloc, int ylo
}
#endif
if(route_.move_left > 0 && route_.move_left < 10) {
text << " (" << char('1' + route_.move_left) << ")";
int turns_to_reach = turn_waypoint_iter->second;
if(turns_to_reach > 0 && turns_to_reach < 10) {
text << " (" << char('0' + turns_to_reach) << ")";
}
const std::string& str = text.str();
@ -1872,6 +1874,7 @@ void display::set_route(const paths::route* route)
route_ = *route;
} else {
route_.steps.clear();
route_.turn_waypoints.clear();
}
invalidate_route();

View file

@ -468,7 +468,7 @@ paths::paths(gamemap const &map, gamestatus const &status,
ignore_zocs,allow_teleport,additional_turns,true,viewing_team);
}
int route_turns_to_complete(unit const &u, gamemap const &map, paths::route const &rt)
int route_turns_to_complete(unit const &u, gamemap const &map, paths::route &rt)
{
if(rt.steps.empty())
return 0;
@ -481,6 +481,7 @@ int route_turns_to_complete(unit const &u, gamemap const &map, paths::route cons
movement -= move_cost;
if (movement < 0) {
++turns;
rt.turn_waypoints.insert(std::make_pair(*(i-1), turns));
movement = u.total_movement() - move_cost;
if(movement < 0) {
return -1;
@ -488,6 +489,14 @@ int route_turns_to_complete(unit const &u, gamemap const &map, paths::route cons
}
}
//add "end-of-path" to waypoints.
if (turns > 0) {
rt.turn_waypoints.insert(std::make_pair(*(rt.steps.end()-1), turns+1));
}
else {
rt.turn_waypoints.insert(std::make_pair(*(rt.steps.end()-1), 0));
}
return turns;
}

View file

@ -90,6 +90,7 @@ struct paths
route() : move_left(0) {}
std::vector<gamemap::location> steps;
int move_left; //movement unit will have left at end of the route.
std::map<gamemap::location, int> turn_waypoints;
};
typedef std::map<gamemap::location,route> routes_map;
@ -103,8 +104,9 @@ paths::route a_star_search(gamemap::location const &src, gamemap::location const
//function which, given a unit and a route the unit can move on, will
//return the number of turns it will take the unit to traverse the route.
//adds "turn waypoints" to rt.turn_waypoints. note that "end of path" is also added.
int route_turns_to_complete(const unit& u, const gamemap& map,
const paths::route& rt);
paths::route& rt);
struct shortest_path_calculator : cost_calculator
{