mail[Wesnoth-commits] r44520 - in /trunk/src/whiteboard: move.cpp move.hpp validate_visitor.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by gabrielmorin on July 22, 2010 - 05:11:
Author: gabba
Date: Thu Jul 22 05:11:17 2010
New Revision: 44520

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44520&view=rev
Log:
Whiteboard: Calculate new marked_route for move in validate_visitor.

Modified:
    trunk/src/whiteboard/move.cpp
    trunk/src/whiteboard/move.hpp
    trunk/src/whiteboard/validate_visitor.cpp

Modified: trunk/src/whiteboard/move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=44520&r1=44519&r2=44520&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Thu Jul 22 05:11:17 2010
@@ -84,25 +84,7 @@
        assert(unit_);
        unit_id_ = unit_->id();
 
-       if (get_source_hex().valid() && get_dest_hex().valid() && 
get_source_hex() != get_dest_hex())
-       {
-
-               // TODO: find a better treatment of movement points when 
defining moves out-of-turn
-               if(get_unit()->movement_left() - route_->move_cost < 0
-                               && resources::controller->current_side() == 
resources::screen->viewing_side()) {
-                       WRN_WB << "Move defined with insufficient movement 
left.\n";
-               }
-
-               // If unit finishes move in a village it captures, set the 
move cost to unit_.movement_left()
-                if (route_->marks[get_dest_hex()].capture)
-                {
-                        movement_cost_ = get_unit()->movement_left();
-                }
-                else
-                {
-                        movement_cost_ = route_->move_cost;
-                }
-       }
+       this->calculate_move_cost();
 }
 
 move::~move()
@@ -110,6 +92,7 @@
        //reminder: here we rely on the ~arrow destructor to invalidate
        //its whole path.
 }
+
 
 void move::accept(visitor& v)
 {
@@ -198,6 +181,7 @@
 void move::set_route(const pathfind::marked_route& route)
 {
        route_.reset(new pathfind::marked_route(route));
+       this->calculate_move_cost();
        arrow_->set_path(route_->steps);
 }
 
@@ -270,4 +254,29 @@
 //     }
 }
 
+void move::calculate_move_cost()
+{
+       assert(unit_);
+       assert(route_);
+       if (get_source_hex().valid() && get_dest_hex().valid() && 
get_source_hex() != get_dest_hex())
+       {
+
+               // TODO: find a better treatment of movement points when 
defining moves out-of-turn
+               if(get_unit()->movement_left() - route_->move_cost < 0
+                               && resources::controller->current_side() == 
resources::screen->viewing_side()) {
+                       WRN_WB << "Move defined with insufficient movement 
left.\n";
+               }
+
+               // If unit finishes move in a village it captures, set the 
move cost to unit_.movement_left()
+                if (route_->marks[get_dest_hex()].capture)
+                {
+                        movement_cost_ = get_unit()->movement_left();
+                }
+                else
+                {
+                        movement_cost_ = route_->move_cost;
+                }
+       }
+}
+
 } // end namespace wb

Modified: trunk/src/whiteboard/move.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.hpp?rev=44520&r1=44519&r2=44520&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Thu Jul 22 05:11:17 2010
@@ -77,6 +77,9 @@
        virtual bool is_valid() { return valid_; }
 
 protected:
+
+       void calculate_move_cost();
+
        unit* unit_;
        std::string unit_id_;
        boost::scoped_ptr<pathfind::marked_route> route_;

Modified: trunk/src/whiteboard/validate_visitor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/validate_visitor.cpp?rev=44520&r1=44519&r2=44520&view=diff
==============================================================================
--- trunk/src/whiteboard/validate_visitor.cpp (original)
+++ trunk/src/whiteboard/validate_visitor.cpp Thu Jul 22 05:11:17 2010
@@ -91,14 +91,14 @@
                if (move->valid_ && 
(resources::units->find(move->get_dest_hex()) != resources::units->end()))
                        move->set_valid(false);
 
-               pathfind::plain_route route;
+               pathfind::plain_route new_plain_route;
                if (move->valid_)
                {
                        pathfind::shortest_path_calculator 
path_calc(*move->get_unit(), get_current_team(), *resources::units,
                                        *resources::teams, 
*resources::game_map);
-                       route = 
pathfind::a_star_search(move->get_source_hex(),
+                       new_plain_route = 
pathfind::a_star_search(move->get_source_hex(),
                                        move->get_dest_hex(), 10000, 
&path_calc, resources::game_map->w(), resources::game_map->h());
-                       if (route.move_cost >= path_calc.getNoPathValue())
+                       if (new_plain_route.move_cost >= 
path_calc.getNoPathValue())
                        {
                                move->set_valid(false);
                        }
@@ -106,14 +106,15 @@
 
                if (move->valid_)
                {
-                       if ((!std::equal(route.steps.begin(), 
route.steps.end(), move->get_route().steps.begin()))
-                               || route.move_cost != 
move->get_route().move_cost)
+                       if ((!std::equal(new_plain_route.steps.begin(), 
new_plain_route.steps.end(), move->get_route().steps.begin()))
+                               || new_plain_route.move_cost != 
move->get_route().move_cost)
                        {
                                //new valid path differs from the previous 
one, replace
+                               //TODO: use something else than empty vector 
for waypoints?
+                               pathfind::marked_route new_marked_route =
+                                               
pathfind::mark_route(new_plain_route, std::vector<map_location>());
 
-                               //FIXME ASAP: assign this through a new 
move->set_route(const marked_route&) method!!!!!!!!
-                               move->arrow_->set_path(route.steps);
-                               move->movement_cost_ = route.move_cost;
+                               move->set_route(new_marked_route);
 
                                //TODO: Since this might lengthen the path, 
we probably need a special conflict state
                                // to warn the player that the initial path 
is no longer possible.




Related Messages


Powered by MHonArc, Updated Thu Jul 22 05:20:13 2010