Author: alink
Date: Wed Nov 25 03:54:08 2009
New Revision: 39946

URL: http://svn.gna.org/viewcvs/wesnoth?rev=39946&view=rev
Log:
Only record waypoints when using them for a move. This continues to save them 
for
multi-turns moves, but restore the "volatile" way as for the mousehover path.
This also restores the possibility to try waypoints for enemy paths.

Modified:
    trunk/src/actions.cpp
    trunk/src/menu_events.cpp
    trunk/src/mouse_events.cpp
    trunk/src/mouse_events.hpp

Modified: trunk/src/actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=39946&r1=39945&r2=39946&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Wed Nov 25 03:54:08 2009
@@ -2092,6 +2092,8 @@
                }
 
                moves_left -= cost;
+
+               // remove passed waypoints
                std::list<map_location>& waypoints = ui->second.waypoints();
                if(!waypoints.empty() && waypoints.front() == *step) {
                        waypoints.pop_front();

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=39946&r1=39945&r2=39946&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Wed Nov 25 03:54:08 2009
@@ -1603,7 +1603,7 @@
 {
        assert(ui != units_.end());
 
-       marked_route route = mousehandler.get_route(ui, target, teams_[side_num 
- 1]);
+       marked_route route = mousehandler.get_route(ui, target, 
ui->second.waypoints(), teams_[side_num - 1]);
 
        if(route.steps.empty())
                return;
@@ -1646,7 +1646,7 @@
                        if(fully_moved.count(current_loc))
                                continue;
 
-                       marked_route route = mousehandler.get_route(ui, 
goto_loc, teams_[side - 1]);
+                       marked_route route = mousehandler.get_route(ui, 
goto_loc, ui->second.waypoints(), teams_[side - 1]);
 
                        if(route.steps.size() <= 1) { // invalid path
                                fully_moved.insert(current_loc);

Modified: trunk/src/mouse_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.cpp?rev=39946&r1=39945&r2=39946&view=diff
==============================================================================
--- trunk/src/mouse_events.cpp (original)
+++ trunk/src/mouse_events.cpp Wed Nov 25 03:54:08 2009
@@ -60,6 +60,7 @@
        selected_hex_(),
        next_unit_(),
        current_route_(),
+       waypoints_(),
        current_paths_(),
        enemy_paths_(false),
        path_turns_(0),
@@ -211,10 +212,11 @@
                         map_.on_board(selected_hex_) && map_.on_board(new_hex))
                {
                        if(selected_unit != units_.end() && 
!selected_unit->second.incapacitated()) {
+                               // Show the route from selected unit to 
mouseover hex
                                // the movement_reset is active only if it's 
not the unit's turn
                                unit_movement_resetter 
move_reset(selected_unit->second,
                                                selected_unit->second.side() != 
side_num_);
-                               current_route_ = get_route(selected_unit, dest, 
viewing_team());
+                               current_route_ = get_route(selected_unit, dest, 
waypoints_, viewing_team());
                                if(!browse) {
                                        gui().set_route(&current_route_);
                                }
@@ -239,7 +241,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)) {
-                                       marked_route route = get_route(un, 
go_to, current_team());
+                                       marked_route route = get_route(un, 
go_to, un->second.waypoints(), current_team());
                                        gui().set_route(&route);
                                }
                                over_route_ = true;
@@ -323,16 +325,12 @@
 }
 
 void mouse_handler::add_waypoint(const map_location& loc) {
-       unit_map::iterator u = find_unit(selected_hex_);
-       if(u == units_.end() || u->second.side() != side_num_)
-               return;
-
-       std::list<map_location>& waypoints = u->second.waypoints();
-       std::list<map_location>::iterator i = std::find(waypoints.begin(), 
waypoints.end(), loc);
-       if(i != waypoints.end()){
-               waypoints.erase(i);
+       std::list<map_location>::iterator w = std::find(waypoints_.begin(), 
waypoints_.end(), loc);
+       //toggle between add a new one and remove an old one
+       if(w != waypoints_.end()){
+               waypoints_.erase(w);
        } else {
-               waypoints.push_back(loc);
+               waypoints_.push_back(loc);
        }
 
        // we need to update the route, simulate a mouse move for the moment
@@ -340,7 +338,7 @@
        mouse_motion(0,0, false, true);
 }
 
-marked_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, const std::list<map_location>& waypoints, team &team)
 {
        // The pathfinder will check unit visibility (fogged/stealthy).
        const shortest_path_calculator calc(un->second,team,units_,teams_,map_);
@@ -350,7 +348,7 @@
 
        plain_route route;
        
-       if (un->second.waypoints().empty()) {
+       if (waypoints.empty()) {
                // standard shortest path
                route = a_star_search(un->first, go_to, 10000.0, &calc, 
map_.w(), map_.h(), &allowed_teleports);
        } else {
@@ -359,13 +357,13 @@
                route.move_cost = 0;
 
                //copy waypoints and add first source and last destination
-               std::list<map_location> waypoints = un->second.waypoints();
-               waypoints.push_front(un->first);
-               waypoints.push_back(go_to);
-
-               std::list<map_location>::iterator src = waypoints.begin(),
-                       dst = ++waypoints.begin();
-               for(; dst != waypoints.end(); ++src,++dst){
+               std::list<map_location> waypts = waypoints;
+               waypts.push_front(un->first);
+               waypts.push_back(go_to);
+
+               std::list<map_location>::iterator src = waypts.begin(),
+                       dst = ++waypts.begin();
+               for(; dst != waypts.end(); ++src,++dst){
                        if (*src == *dst) continue;
                        plain_route inter_route = a_star_search(*src, *dst, 
10000.0, &calc, map_.w(), map_.h(), &allowed_teleports);
                        if(inter_route.steps.size()>=1) {
@@ -377,7 +375,7 @@
                }
        }
 
-       return mark_route(route, un->second.waypoints(), un->second, 
viewing_team(), units_,teams_,map_);
+       return mark_route(route, waypoints, un->second, viewing_team(), 
units_,teams_,map_);
 }
 
 void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool 
browse)
@@ -415,6 +413,7 @@
        if(u != units_.end() && !browse && selected_hex_ == hex && 
u->second.side() == side_num_) {
                u->second.set_goto(map_location());
                u->second.waypoints().clear();
+               waypoints_.clear();
        }
 
        unit_map::iterator clicked_u = find_unit(hex);
@@ -463,6 +462,9 @@
                                return false;
                        }
 
+                       //register the mouse-UI waypoints into the unit's 
waypoints
+                       u->second.waypoints() = waypoints_;
+
                        // move the unit without clearing fog (to avoid 
interruption)
                        //TODO: clear fog and interrupt+resume move
                        if(!move_unit_along_current_route(false, true)) {
@@ -494,6 +496,10 @@
                     current_route_.steps.front() == selected_hex_) {
 
                gui().unhighlight_reach();
+
+               //register the mouse-UI waypoints into the unit's waypoints
+               u->second.waypoints() = waypoints_;
+
                move_unit_along_current_route(check_shroud);
                // during the move, we may have selected another unit
                // (but without triggering a select event (command was disabled)
@@ -516,6 +522,7 @@
        gui().select_hex(hex);
        gui().clear_attack_indicator();
        gui().set_route(NULL);
+       waypoints_.clear();
        show_partial_move_ = false;
 
        unit_map::iterator u = find_unit(hex);

Modified: trunk/src/mouse_events.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mouse_events.hpp?rev=39946&r1=39945&r2=39946&view=diff
==============================================================================
--- trunk/src/mouse_events.hpp (original)
+++ trunk/src/mouse_events.hpp Wed Nov 25 03:54:08 2009
@@ -60,7 +60,7 @@
 
        void add_waypoint(const map_location& loc);
 
-       marked_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, 
const std::list<map_location>& waypoints, team &team);
 protected:
        /**
         * Due to the way this class is constructed we can assume that the
@@ -122,6 +122,7 @@
        map_location selected_hex_;
        map_location next_unit_;
        marked_route current_route_;
+       std::list<map_location> waypoints_;
        paths current_paths_;
        bool enemy_paths_;
        int path_turns_;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to