Author: silene
Date: Sat May 2 10:46:16 2009
New Revision: 35408
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35408&view=rev
Log:
Removed waypoints from routes, as they are not used there.
Modified:
trunk/src/game_display.cpp
trunk/src/game_display.hpp
trunk/src/menu_events.cpp
trunk/src/mouse_events.cpp
trunk/src/mouse_events.hpp
trunk/src/pathfind.cpp
trunk/src/pathfind.hpp
Modified: trunk/src/game_display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_display.cpp?rev=35408&r1=35407&r2=35408&view=diff
==============================================================================
--- trunk/src/game_display.cpp (original)
+++ trunk/src/game_display.cpp Sat May 2 10:46:16 2009
@@ -588,7 +588,8 @@
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::set_route(const paths::route* route)
+void game_display::set_route(const marked_route *route)
{
invalidate_route();
Modified: trunk/src/game_display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_display.hpp?rev=35408&r1=35407&r2=35408&view=diff
==============================================================================
--- trunk/src/game_display.hpp (original)
+++ trunk/src/game_display.hpp Sat May 2 10:46:16 2009
@@ -115,10 +115,10 @@
/**
* 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 @@
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_;
Modified: trunk/src/menu_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=35408&r1=35407&r2=35408&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sat May 2 10:46:16 2009
@@ -1530,7 +1530,7 @@
{
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;
Modified: trunk/src/mouse_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=35408&r1=35407&r2=35408&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Sat May 2 10:46:16 2009
@@ -219,7 +219,7 @@
//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 @@
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 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)
Modified: trunk/src/mouse_events.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.hpp?rev=35408&r1=35407&r2=35408&view=diff
==============================================================================
--- trunk/src/mouse_events.hpp (original)
+++ trunk/src/mouse_events.hpp Sat May 2 10:46:16 2009
@@ -55,7 +55,7 @@
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 @@
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_;
Modified: trunk/src/pathfind.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.cpp?rev=35408&r1=35407&r2=35408&view=diff
==============================================================================
--- trunk/src/pathfind.cpp (original)
+++ trunk/src/pathfind.cpp Sat May 2 10:46:16 2009
@@ -297,11 +297,14 @@
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)
-{
- if(rt.steps.empty())
- return 0;
+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)
+{
+ 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 @@
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 @@
movement -= move_cost;
}
}
- if (turns == 1)
- rt.move_left = movement;
- else
- rt.move_left = 0;
-
- return turns;
+
+ return res;
}
@@ -475,16 +473,6 @@
}
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;
}
Modified: trunk/src/pathfind.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/pathfind.hpp?rev=35408&r1=35407&r2=35408&view=diff
==============================================================================
--- trunk/src/pathfind.hpp (original)
+++ trunk/src/pathfind.hpp Sat May 2 10:46:16 2009
@@ -107,26 +107,34 @@
/** 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);
@@ -136,14 +144,17 @@
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
{
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits