mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-30 16:55:28 +00:00
Removed waypoints from routes, as they are not used there.
This commit is contained in:
parent
4da9564531
commit
7c610b5d41
@ -588,7 +588,8 @@ void game_display::set_game_mode(const tgame_mode game_mode)
|
||||
void game_display::draw_movement_info(const map_location& loc)
|
||||
{
|
||||
// Search if there is a waypoint here
|
||||
std::map<map_location, paths::route::waypoint>::iterator w = route_.waypoints.find(loc);
|
||||
std::map<map_location, marked_route::waypoint>::iterator w =
|
||||
route_.waypoints.find(loc);
|
||||
|
||||
// Don't use empty route or the first step (the unit will be there)
|
||||
if(w != route_.waypoints.end()
|
||||
@ -805,7 +806,7 @@ void game_display::invalidate_route()
|
||||
}
|
||||
}
|
||||
|
||||
void game_display::set_route(const paths::route* route)
|
||||
void game_display::set_route(const marked_route *route)
|
||||
{
|
||||
invalidate_route();
|
||||
|
||||
|
@ -115,10 +115,10 @@ public:
|
||||
|
||||
/**
|
||||
* Sets the route along which footsteps are drawn to show movement of a
|
||||
* unit. If NULL, no route is displayed. route does not have to remain
|
||||
* unit. If NULL, no route is displayed. @a route does not have to remain
|
||||
* valid after being set.
|
||||
*/
|
||||
void set_route(const paths::route* route);
|
||||
void set_route(const marked_route *route);
|
||||
|
||||
/** Function to float a label above a tile */
|
||||
void float_label(const map_location& loc, const std::string& text,
|
||||
@ -319,7 +319,7 @@ private:
|
||||
const SDL_Rect& calculate_energy_bar(surface surf);
|
||||
std::map<surface,SDL_Rect> energy_bar_rects_;
|
||||
|
||||
paths::route route_;
|
||||
marked_route route_;
|
||||
|
||||
const gamestatus& status_;
|
||||
|
||||
|
@ -1530,7 +1530,7 @@ private:
|
||||
{
|
||||
assert(ui != units_.end());
|
||||
|
||||
paths::route route = mousehandler.get_route(ui, target, teams_[team_num - 1]);
|
||||
marked_route route = mousehandler.get_route(ui, target, teams_[team_num - 1]);
|
||||
|
||||
if(route.steps.empty())
|
||||
return;
|
||||
|
@ -219,7 +219,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update)
|
||||
//unit is on our team, show path if the unit has one
|
||||
const map_location go_to = un->second.get_goto();
|
||||
if(map_.on_board(go_to)) {
|
||||
paths::route route = get_route(un, go_to, current_team());
|
||||
marked_route route = get_route(un, go_to, current_team());
|
||||
gui().set_route(&route);
|
||||
}
|
||||
over_route_ = true;
|
||||
@ -301,7 +301,7 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc)
|
||||
return res;
|
||||
}
|
||||
|
||||
paths::route mouse_handler::get_route(unit_map::const_iterator un, map_location go_to, team &team)
|
||||
marked_route mouse_handler::get_route(unit_map::const_iterator un, map_location go_to, team &team)
|
||||
{
|
||||
// The pathfinder will check unit visibility (fogged/stealthy).
|
||||
const shortest_path_calculator calc(un->second,team,units_,teams_,map_);
|
||||
@ -323,8 +323,7 @@ paths::route mouse_handler::get_route(unit_map::const_iterator un, map_location
|
||||
}
|
||||
}
|
||||
paths::route route = a_star_search(un->first, go_to, 10000.0, &calc, map_.w(), map_.h(), &allowed_teleports);
|
||||
route_turns_to_complete(un->second, route, viewing_team(), units_,teams_,map_);
|
||||
return route;
|
||||
return mark_route(route, un->second, viewing_team(), units_,teams_,map_);
|
||||
}
|
||||
|
||||
void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool browse)
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
void set_undo(const bool undo) { undo_ = undo; }
|
||||
|
||||
unit_map::iterator selected_unit();
|
||||
paths::route get_route(unit_map::const_iterator un, map_location go_to, team &team);
|
||||
marked_route get_route(unit_map::const_iterator un, map_location go_to, team &team);
|
||||
protected:
|
||||
/**
|
||||
* Due to the way this class is constructed we can assume that the
|
||||
@ -103,7 +103,7 @@ private:
|
||||
map_location previous_free_hex_;
|
||||
map_location selected_hex_;
|
||||
map_location next_unit_;
|
||||
paths::route current_route_;
|
||||
marked_route current_route_;
|
||||
paths current_paths_;
|
||||
bool enemy_paths_;
|
||||
int path_turns_;
|
||||
|
@ -297,11 +297,14 @@ paths::paths(gamemap const &map, unit_map const &units,
|
||||
see_all, ignore_units);
|
||||
}
|
||||
|
||||
int route_turns_to_complete(const unit& u, paths::route& rt, const team &viewing_team,
|
||||
const unit_map& units, const std::vector<team>& teams, const gamemap& map)
|
||||
marked_route mark_route(const paths::route &rt, const unit &u,
|
||||
const team &viewing_team, const unit_map &units,
|
||||
const std::vector<team> &teams, const gamemap &map)
|
||||
{
|
||||
if(rt.steps.empty())
|
||||
return 0;
|
||||
marked_route res;
|
||||
|
||||
if (rt.steps.empty()) return res;
|
||||
res.steps = rt.steps;
|
||||
|
||||
int turns = 0;
|
||||
int movement = u.movement_left();
|
||||
@ -329,14 +332,13 @@ int route_turns_to_complete(const unit& u, paths::route& rt, const team &viewing
|
||||
|
||||
bool invisible = u.invisible(*i,units,teams,false);
|
||||
|
||||
rt.waypoints[*i] = paths::route::waypoint(turns, zoc, capture, invisible);
|
||||
res.waypoints[*i] = marked_route::waypoint(turns, zoc, capture, invisible);
|
||||
|
||||
if (last_step) break; // finished and we used dummy move_cost
|
||||
|
||||
movement = u.total_movement();
|
||||
if(move_cost > movement) {
|
||||
rt.move_left = -1;
|
||||
return -1; //we can't reach destination
|
||||
return res; //we can't reach destination
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,12 +351,8 @@ int route_turns_to_complete(const unit& u, paths::route& rt, const team &viewing
|
||||
movement -= move_cost;
|
||||
}
|
||||
}
|
||||
if (turns == 1)
|
||||
rt.move_left = movement;
|
||||
else
|
||||
rt.move_left = 0;
|
||||
|
||||
return turns;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ -475,16 +473,6 @@ std::ostream& operator << (std::ostream& outstream, const paths::route& rt) {
|
||||
}
|
||||
outstream << '(' << loc << ')';
|
||||
}
|
||||
outstream << "\"\n\tmove_left=\"" << rt.move_left << "\"\n";
|
||||
typedef std::pair<map_location, paths::route::waypoint> loc_waypoint;
|
||||
foreach(loc_waypoint const& lw, rt.waypoints) {
|
||||
outstream << "\t[waypoint]\n\t\tx,y=\"" << lw.first
|
||||
<< "\"\n\t\tturns=\"" << lw.second.turns
|
||||
<< "\"\n\t\tzoc=\"" << (lw.second.zoc?"yes":"no")
|
||||
<< "\"\n\t\tcapture=\"" << (lw.second.capture?"yes":"no")
|
||||
<< "\"\n\t\tinvisible=\"" << (lw.second.invisible?"yes":"no")
|
||||
<< "\"\n\t[/waypoint]\n";
|
||||
}
|
||||
outstream << "[/route]";
|
||||
outstream << "\"\n\tmove_left=\"" << rt.move_left << "\"\n[/route]";
|
||||
return outstream;
|
||||
}
|
||||
|
@ -107,27 +107,35 @@ struct paths
|
||||
/** Structure which holds a single route between one location and another. */
|
||||
struct route
|
||||
{
|
||||
route() : steps(), move_left(0), waypoints() {}
|
||||
route() : steps(), move_left(0) {}
|
||||
std::vector<map_location> steps;
|
||||
int move_left; // movement unit will have left at end of the route.
|
||||
struct waypoint
|
||||
{
|
||||
waypoint(int turns_number = 0, bool in_zoc = false,
|
||||
bool do_capture = false, bool is_invisible = false)
|
||||
: turns(turns_number), zoc(in_zoc),
|
||||
capture(do_capture), invisible(is_invisible) {}
|
||||
int turns;
|
||||
bool zoc;
|
||||
bool capture;
|
||||
bool invisible;
|
||||
};
|
||||
std::map<map_location, waypoint> waypoints;
|
||||
};
|
||||
|
||||
typedef std::map<map_location,route> routes_map;
|
||||
routes_map routes;
|
||||
};
|
||||
|
||||
/** Structure which holds a single route and waypoints for special events. */
|
||||
struct marked_route
|
||||
{
|
||||
struct waypoint
|
||||
{
|
||||
waypoint(int turns_number = 0, bool in_zoc = false,
|
||||
bool do_capture = false, bool is_invisible = false)
|
||||
: turns(turns_number), zoc(in_zoc),
|
||||
capture(do_capture), invisible(is_invisible) {}
|
||||
int turns;
|
||||
bool zoc;
|
||||
bool capture;
|
||||
bool invisible;
|
||||
};
|
||||
typedef std::map<map_location, waypoint> waypoint_map;
|
||||
std::vector<map_location> steps;
|
||||
waypoint_map waypoints;
|
||||
};
|
||||
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const paths::route& rt);
|
||||
|
||||
paths::route a_star_search(map_location const &src, map_location const &dst,
|
||||
@ -136,14 +144,17 @@ paths::route a_star_search(map_location const &src, map_location const &dst,
|
||||
std::set<map_location> const *teleports = NULL);
|
||||
|
||||
/**
|
||||
* Function which, given a unit and a route the unit can move on,
|
||||
* Marks a route @a rt with waypoints assuming that a @unit u travels along it.
|
||||
|
||||
* Function which, given a unit @a u and a route @a rt the unit can move on,
|
||||
* will return the number of turns it will take the unit to traverse the route.
|
||||
* adds rt.turn_waypoints (and also one at "end of path").
|
||||
* move_left is updated, but to 0 if not reachable in more than 1 turn
|
||||
* and to -1 if never reachable.
|
||||
*/
|
||||
int route_turns_to_complete(const unit& u, paths::route& rt, const team &viewing_team,
|
||||
const unit_map& units, const std::vector<team>& teams, const gamemap& map);
|
||||
marked_route mark_route(const paths::route &rt, const unit &u,
|
||||
const team &viewing_team, const unit_map &units,
|
||||
const std::vector<team> &teams, const gamemap &map);
|
||||
|
||||
struct shortest_path_calculator : cost_calculator
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user