mail[Wesnoth-commits] r44515 - /trunk/src/whiteboard/


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

Header


Content

Posted by gabrielmorin on July 22, 2010 - 02:32:
Author: gabba
Date: Thu Jul 22 02:32:35 2010
New Revision: 44515

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44515&view=rev
Log:
Whiteboard: transform move/attack to use pathfind::marked_route internally, 
step 6, pretty much finished.

Modified:
    trunk/src/whiteboard/action.cpp
    trunk/src/whiteboard/action.hpp
    trunk/src/whiteboard/attack.cpp
    trunk/src/whiteboard/attack.hpp
    trunk/src/whiteboard/highlight_visitor.cpp
    trunk/src/whiteboard/move.cpp
    trunk/src/whiteboard/move.hpp
    trunk/src/whiteboard/validate_visitor.cpp

Modified: trunk/src/whiteboard/action.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/action.cpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/action.cpp (original)
+++ trunk/src/whiteboard/action.cpp Thu Jul 22 02:32:35 2010
@@ -22,6 +22,13 @@
 
 std::ostream& operator<<(std::ostream& s, action_ptr action)
 {
+       assert(action);
+       return action->print(s);
+}
+
+std::ostream& operator<<(std::ostream& s, action_const_ptr action)
+{
+       assert(action);
        return action->print(s);
 }
 

Modified: trunk/src/whiteboard/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/action.hpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/action.hpp (original)
+++ trunk/src/whiteboard/action.hpp Thu Jul 22 02:32:35 2010
@@ -33,7 +33,6 @@
 public:
        friend class validate_visitor;
        friend class highlight_visitor;
-       friend std::ostream& operator<<(std::ostream& s, action_ptr action);
 
        action();
        virtual ~action();
@@ -70,6 +69,7 @@
 };
 
 std::ostream& operator<<(std::ostream& s, action_ptr action);
+std::ostream& operator<<(std::ostream& s, action_const_ptr action);
 
 } // end namespace wb
 

Modified: trunk/src/whiteboard/attack.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/attack.cpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/attack.cpp (original)
+++ trunk/src/whiteboard/attack.cpp Thu Jul 22 02:32:35 2010
@@ -31,16 +31,20 @@
 
 std::ostream &operator<<(std::ostream &s, attack_ptr attack)
 {
-//     s << "Attack for unit " << attack->get_unit().name() << " [" << 
attack->get_unit().underlying_id() << "] "
-//                     << "moving from (" << attack->get_source_hex() << ") 
to (" << attack->get_dest_hex() << ") and attacking "
-//                     << attack->get_target_hex();
+       assert(attack);
+       return attack->print(s);
+}
 
+std::ostream &operator<<(std::ostream &s, attack_const_ptr attack)
+{
+       assert(attack);
        return attack->print(s);
 }
 
 std::ostream& attack::print(std::ostream& s) const
 {
-       s << boost::static_pointer_cast<wb::move>(shared_from_this()) << " 
and attacking (" << get_target_hex() << ")";
+       s << "Attack on (" << get_target_hex() << ") preceded by ";
+       move::print(s);
        return s;
 }
 
@@ -57,7 +61,7 @@
        if(resources::screen)
        {
                //invalidate dest and target hex so attack indicator is 
properly cleared
-               resources::screen->invalidate(dest_hex_);
+               resources::screen->invalidate(get_dest_hex());
                resources::screen->invalidate(target_hex_);
        }
 }
@@ -88,7 +92,7 @@
 
        if (execute_successful)
        {
-               
resources::controller->get_mouse_handler_base().attack_enemy(dest_hex_, 
target_hex_, weapon_choice_);
+               
resources::controller->get_mouse_handler_base().attack_enemy(get_dest_hex(), 
target_hex_, weapon_choice_);
                //only path that returns execute_successful = true
        }
        return execute_successful;
@@ -96,7 +100,7 @@
 
 void attack::draw_hex(const map_location& hex)
 {
-       if (hex == dest_hex_ || hex == target_hex_) //draw attack indicator
+       if (hex == get_dest_hex() || hex == target_hex_) //draw attack 
indicator
        {
                //TODO: replace this by either the use of transparency + 
LAYER_ATTACK_INDICATOR,
                //or a dedicated layer
@@ -104,15 +108,15 @@
 
                //calculate direction (valid for both hexes)
                std::string direction_text = map_location::write_direction(
-                               dest_hex_.get_relative_dir(target_hex_));
+                               get_dest_hex().get_relative_dir(target_hex_));
 
-               if (hex == dest_hex_) //add symbol to attacker hex
+               if (hex == get_dest_hex()) //add symbol to attacker hex
                {
-                       int xpos = 
resources::screen->get_location_x(dest_hex_);
-                       int ypos = 
resources::screen->get_location_y(dest_hex_);
+                       int xpos = 
resources::screen->get_location_x(get_dest_hex());
+                       int ypos = 
resources::screen->get_location_y(get_dest_hex());
 
                        //TODO: Give the whiteboard its own copy of the 
attack indicator, so it can have a different look.
-                       resources::screen->drawing_buffer_add(layer, 
dest_hex_, display::tblit(xpos, ypos,
+                       resources::screen->drawing_buffer_add(layer, 
get_dest_hex(), display::tblit(xpos, ypos,
                                        
image::get_image("misc/attack-indicator-src-" + direction_text + ".png", 
image::UNMASKED)));
                }
                else if (hex == target_hex_) //add symbol to defender hex

Modified: trunk/src/whiteboard/attack.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/attack.hpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/attack.hpp (original)
+++ trunk/src/whiteboard/attack.hpp Thu Jul 22 02:32:35 2010
@@ -33,7 +33,6 @@
 public:
        friend class validate_visitor;
        friend class highlight_visitor;
-       friend std::ostream& operator<<(std::ostream& s, attack_ptr attack);
 
        ///Future unit map must be valid during construction, so that attack 
can find its units
        attack(const map_location& target_hex, int weapon_choice, const 
pathfind::marked_route& route,
@@ -60,6 +59,7 @@
 
 /** Dumps an attack on a stream, for debug purposes. */
 std::ostream& operator<<(std::ostream &s, attack_ptr attack);
+std::ostream& operator<<(std::ostream &s, attack_const_ptr attack);
 
 } // end namespace wb
 

Modified: trunk/src/whiteboard/highlight_visitor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/highlight_visitor.cpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/highlight_visitor.cpp (original)
+++ trunk/src/whiteboard/highlight_visitor.cpp Thu Jul 22 02:32:35 2010
@@ -181,7 +181,7 @@
        switch (mode_)
        {
        case FIND_MAIN_HIGHLIGHT:
-               if (move->dest_hex_ == mouseover_hex_)
+               if (move->get_dest_hex() == mouseover_hex_)
                {
                        main_highlight_ = move;
                }

Modified: trunk/src/whiteboard/move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Thu Jul 22 02:32:35 2010
@@ -38,6 +38,13 @@
 
 std::ostream& operator<<(std::ostream &s, move_ptr move)
 {
+       assert(move);
+       return move->print(s);
+}
+
+std::ostream& operator<<(std::ostream &s, move_const_ptr move)
+{
+       assert(move);
        return move->print(s);
 }
 
@@ -66,35 +73,19 @@
 : unit_(NULL),
   unit_id_(),
   route_(new pathfind::marked_route(route)),
-  source_hex_(),
-  dest_hex_(),
   movement_cost_(0),
   arrow_(arrow),
   fake_unit_(fake_unit),
   valid_(true)
 {
-       if(!route_->steps.empty())
-       {
-               source_hex_ = route_->steps.front();
-               dest_hex_ = route_->steps.back();
-       }
-
-       unit_ = resources::whiteboard->find_future_unit(source_hex_);
+       assert(!route_->steps.empty());
+
+       unit_ = resources::whiteboard->find_future_unit(get_source_hex());
        assert(unit_);
        unit_id_ = unit_->id();
 
-       if (source_hex_.valid() && dest_hex_.valid() && source_hex_ != 
dest_hex_)
-       {
-
-//             // Calculate move cost
-//             pathfind::shortest_path_calculator path_calc(*get_unit(),
-//                             (*resources::teams)[get_unit()->side() - 1],
-//                             *resources::units,
-//                             *resources::teams,
-//                             *resources::game_map);
-//
-//             pathfind::plain_route route = 
pathfind::a_star_search(source_hex_,
-//                             dest_hex_, 10000, &path_calc, 
resources::game_map->w(), resources::game_map->h());
+       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
@@ -103,7 +94,7 @@
                }
 
                // If unit finishes move in a village it captures, set the 
move cost to unit_.movement_left()
-                if (route_->marks[dest_hex_].capture)
+                if (route_->marks[get_dest_hex()].capture)
                 {
                         movement_cost_ = get_unit()->movement_left();
                 }
@@ -130,7 +121,7 @@
        if (!valid_)
                return false;
 
-       if (source_hex_ == dest_hex_)
+       if (get_source_hex() == get_dest_hex())
                return true; //zero-hex move, probably used by attack subclass
 
        LOG_WB << "Executing: " << shared_from_this() << "\n";
@@ -157,7 +148,7 @@
        }
        else if (final_location.valid())
        {
-               LOG_WB << "Move finished at (" << final_location << ") 
instead of at (" << dest_hex_ << "), analysing\n";
+               LOG_WB << "Move finished at (" << final_location << ") 
instead of at (" << get_dest_hex() << "), analysing\n";
                arrow_path_t::const_iterator start_new_path;
                bool found = false;
                for (start_new_path = arrow_path.begin(); ((start_new_path != 
arrow_path.end()) && !found); ++start_new_path)
@@ -169,7 +160,7 @@
                }
                if (found)
                {
-                       source_hex_ = final_location;
+                       get_source_hex() = final_location;
                        --start_new_path; //since the for loop incremented 
the iterator once after we found the right one.
                        arrow_path_t new_path(start_new_path, 
arrow_path.end());
                        LOG_WB << "Setting new path for this move from (" << 
new_path.front()
@@ -192,9 +183,21 @@
        return move_finished_completely;
 }
 
+map_location move::get_source_hex() const
+{
+       assert(route_ && !route_->steps.empty());
+       return route_->steps.front();
+}
+
+map_location move::get_dest_hex() const
+{
+       assert(route_ && !route_->steps.empty());
+       return route_->steps.back();
+}
+
 void move::apply_temp_modifier(unit_map& unit_map)
 {
-       if (source_hex_ == dest_hex_)
+       if (get_source_hex() == get_dest_hex())
                return; //zero-hex move, probably used by attack subclass
 
        //TODO: deal with multi-turn moves, which may for instance end their 
first turn
@@ -203,12 +206,12 @@
        //TODO: we may need to change unit status here and change it back in 
remove_temp_modifier
 
        // Move the unit
-       unit_map::iterator unit_it = resources::units->find(source_hex_);
+       unit_map::iterator unit_it = resources::units->find(get_source_hex());
        assert(unit_it != resources::units->end());
        unit* unit = &*unit_it;
        DBG_WB << "Temporarily moving unit " << unit->name() << " [" << 
unit->underlying_id()
-                       << "] from (" << source_hex_ << ") to (" << dest_hex_ 
<<")\n";
-       unit_map.move(source_hex_, dest_hex_);
+                       << "] from (" << get_source_hex() << ") to (" << 
get_dest_hex() <<")\n";
+       unit_map.move(get_source_hex(), get_dest_hex());
 
        //Modify movement points accordingly
        DBG_WB <<"Changing movement points for unit " << unit->name() << " [" 
<< unit->underlying_id()
@@ -219,15 +222,15 @@
 
 void move::remove_temp_modifier(unit_map& unit_map)
 {
-       if (source_hex_ == dest_hex_)
+       if (get_source_hex() == get_dest_hex())
                return; //zero-hex move, probably used by attack subclass
 
-       unit_map::iterator unit_it = resources::units->find(dest_hex_);
+       unit_map::iterator unit_it = resources::units->find(get_dest_hex());
        assert(unit_it != resources::units->end());
        unit& unit = *unit_it;
 
        // Restore the unit to its original position
-       unit_map.move(dest_hex_, source_hex_);
+       unit_map.move(get_dest_hex(), get_source_hex());
 
        // Restore movement points
        unit.set_movement(unit.movement_left() + movement_cost_);
@@ -240,7 +243,7 @@
 
 bool move::is_numbering_hex(const map_location& hex) const
 {
-       return hex == dest_hex_;
+       return hex == get_dest_hex();
 }
 
 void move::set_valid(bool valid)

Modified: trunk/src/whiteboard/move.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.hpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Thu Jul 22 02:32:35 2010
@@ -34,7 +34,6 @@
 public:
        friend class validate_visitor;
        friend class highlight_visitor;
-       friend std::ostream& operator<<(std::ostream& s, move_ptr move);
 
        static const double ALPHA_HIGHLIGHT;
        static const double ALPHA_NORMAL;
@@ -55,10 +54,11 @@
        /** Return the unit targeted by this action. Null if unit doesn't 
exist. */
        virtual unit* get_unit() const { return unit_; }
 
+       virtual map_location get_source_hex() const;
+       virtual map_location get_dest_hex() const;
+
        virtual arrow_ptr get_arrow() { return arrow_; }
        virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
-       virtual map_location const& get_source_hex() const { return 
source_hex_; }
-       virtual map_location const& get_dest_hex() const { return dest_hex_; }
 
        /** Applies temporarily the result of this action to the specified 
unit map. */
        virtual void apply_temp_modifier(unit_map& unit_map);
@@ -77,8 +77,6 @@
        unit* unit_;
        std::string unit_id_;
        boost::scoped_ptr<pathfind::marked_route> route_;
-       map_location source_hex_;
-       map_location dest_hex_;
        int movement_cost_;
 
        arrow_ptr arrow_;
@@ -89,6 +87,7 @@
 
 /** Dumps an move on a stream, for debug purposes. */
 std::ostream &operator<<(std::ostream &s, move_ptr move);
+std::ostream &operator<<(std::ostream &s, move_const_ptr move);
 
 } // end namespace wb
 

Modified: trunk/src/whiteboard/validate_visitor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/validate_visitor.cpp?rev=44515&r1=44514&r2=44515&view=diff
==============================================================================
--- trunk/src/whiteboard/validate_visitor.cpp (original)
+++ trunk/src/whiteboard/validate_visitor.cpp Thu Jul 22 02:32:35 2010
@@ -74,21 +74,21 @@
 void validate_visitor::visit_move(move_ptr move)
 {
        //invalidate start and end hexes so number display is updated properly
-       resources::screen->invalidate(move->source_hex_);
-       resources::screen->invalidate(move->dest_hex_);
+       resources::screen->invalidate(move->get_source_hex());
+       resources::screen->invalidate(move->get_dest_hex());
 
-       if (!(move->source_hex_.valid() && move->dest_hex_.valid()))
+       if (!(move->get_source_hex().valid() && move->get_dest_hex().valid()))
                move->set_valid(false);
 
        //TODO: need to check if the unit in the source hex has the same 
underlying unit id as before,
        //i.e. that it's the same unit
-       if (move->valid_ && resources::units->find(move->source_hex_) == 
resources::units->end())
+       if (move->valid_ && resources::units->find(move->get_source_hex()) == 
resources::units->end())
                move->set_valid(false);
 
-       if (move->source_hex_ != move->dest_hex_) //allow for zero-hex, move, 
in which case we skip pathfinding
+       if (move->get_source_hex() != move->get_dest_hex()) //allow for 
zero-hex, move, in which case we skip pathfinding
        {
                //verify that the destination hex is free
-               if (move->valid_ && (resources::units->find(move->dest_hex_) 
!= resources::units->end()))
+               if (move->valid_ && 
(resources::units->find(move->get_dest_hex()) != resources::units->end()))
                        move->set_valid(false);
 
                pathfind::plain_route route;
@@ -96,8 +96,8 @@
                {
                        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->source_hex_,
-                                       move->dest_hex_, 10000, &path_calc, 
resources::game_map->w(), resources::game_map->h());
+                       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())
                        {
                                move->set_valid(false);
@@ -109,6 +109,8 @@
                        if (!std::equal(route.steps.begin(), 
route.steps.end(), move->arrow_->get_path().begin()))
                        {
                                //new valid path differs from the previous 
one, replace
+
+                               //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;
 
@@ -132,7 +134,7 @@
 void validate_visitor::visit_attack(attack_ptr attack)
 {
        //invalidate target hex to make sure attack indicators are updated
-       resources::screen->invalidate(attack->dest_hex_);
+       resources::screen->invalidate(attack->get_dest_hex());
        resources::screen->invalidate(attack->target_hex_);
 
        if (attack->target_hex_.valid())




Related Messages


Powered by MHonArc, Updated Thu Jul 22 03:20:23 2010