mail[Wesnoth-commits] r44195 - in /trunk/src/whiteboard: action.hpp highlight_visitor.cpp mapbuilder_visitor.cpp move.cpp move.hpp side_actions.cpp


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

Header


Content

Posted by gabrielmorin on July 15, 2010 - 22:48:
Author: gabba
Date: Thu Jul 15 22:48:52 2010
New Revision: 44195

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44195&view=rev
Log:
Whiteboard: rely on starting position rather than direct unit reference to 
find unit owning an action. Part 1.

Modified:
    trunk/src/whiteboard/action.hpp
    trunk/src/whiteboard/highlight_visitor.cpp
    trunk/src/whiteboard/mapbuilder_visitor.cpp
    trunk/src/whiteboard/move.cpp
    trunk/src/whiteboard/move.hpp
    trunk/src/whiteboard/side_actions.cpp

Modified: trunk/src/whiteboard/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/action.hpp?rev=44195&r1=44194&r2=44195&view=diff
==============================================================================
--- trunk/src/whiteboard/action.hpp (original)
+++ trunk/src/whiteboard/action.hpp Thu Jul 15 22:48:52 2010
@@ -55,9 +55,9 @@
         */
        virtual bool is_numbering_hex(const map_location& hex) const = 0;
 
-       /** Return the unit targeted by this action. */
-       virtual unit& get_unit() = 0;
-       virtual unit const& get_unit() const = 0;
+       /** Return the unit targeted by this action. Null if unit doesn't 
exist. */
+       virtual unit* get_unit() = 0;
+       virtual unit const* get_unit() const = 0;
 
        /**
         * Indicates to an action whether its status is invalid, and whether 
it should change its

Modified: trunk/src/whiteboard/highlight_visitor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/highlight_visitor.cpp?rev=44195&r1=44194&r2=44195&view=diff
==============================================================================
--- trunk/src/whiteboard/highlight_visitor.cpp (original)
+++ trunk/src/whiteboard/highlight_visitor.cpp Thu Jul 15 22:48:52 2010
@@ -246,7 +246,7 @@
                action->accept(*this);
                if (action_ptr main = main_highlight_.lock())
                {
-                       owner_unit_ = &main->get_unit();
+                       owner_unit_ = main->get_unit();
                        break;
                }
        }

Modified: trunk/src/whiteboard/mapbuilder_visitor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/mapbuilder_visitor.cpp?rev=44195&r1=44194&r2=44195&view=diff
==============================================================================
--- trunk/src/whiteboard/mapbuilder_visitor.cpp (original)
+++ trunk/src/whiteboard/mapbuilder_visitor.cpp Thu Jul 15 22:48:52 2010
@@ -67,7 +67,7 @@
 
 void mapbuilder_visitor::visit_move(move_ptr move)
 {
-       if (excluded_units_.find(&move->get_unit()) == excluded_units_.end())
+       if (excluded_units_.find(move->get_unit()) == excluded_units_.end())
        {
                if(mode_ == BUILD_PLANNED_MAP)
                {

Modified: trunk/src/whiteboard/move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=44195&r1=44194&r2=44195&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Thu Jul 15 22:48:52 2010
@@ -31,11 +31,12 @@
 #include "team.hpp"
 #include "unit.hpp"
 #include "unit_display.hpp"
+#include "unit_map.hpp"
 
 
 std::ostream &operator<<(std::ostream &s, wb::move const& move)
 {
-       s << "Move for unit " << move.get_unit().name() << " [" << 
move.get_unit().underlying_id() << "] "
+       s << "Move for unit " << move.get_unit()->name() << " [" << 
move.get_unit()->underlying_id() << "] "
                << "from (" << move.get_source_hex() << ") to (" << 
move.get_dest_hex() << ")";
        return s;
 }
@@ -160,6 +161,19 @@
        return move_finished_completely;
 }
 
+unit* move::get_unit()
+{
+       unit_map::iterator it = resources::units->find(source_hex_);
+       if (it != resources::units->end())
+               return &*it;
+       else
+               return NULL;
+}
+unit const* move::get_unit() const
+{
+       return get_unit();
+}
+
 void move::apply_temp_modifier(unit_map& unit_map)
 {
        if (source_hex_ == dest_hex_)

Modified: trunk/src/whiteboard/move.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.hpp?rev=44195&r1=44194&r2=44195&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Thu Jul 15 22:48:52 2010
@@ -53,8 +53,9 @@
 
        virtual bool execute();
 
-       virtual unit& get_unit() { return unit_; }
-       virtual unit const& get_unit() const { return unit_; }
+       /** Return the unit targeted by this action. Null if unit doesn't 
exist. */
+       virtual unit* get_unit();
+       virtual unit const* get_unit() const;
 
 
        virtual arrow_ptr get_arrow() { return arrow_; }

Modified: trunk/src/whiteboard/side_actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.cpp?rev=44195&r1=44194&r2=44195&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Thu Jul 15 22:48:52 2010
@@ -168,7 +168,7 @@
 
        //Verify we're not moving an action out-of-order compared to other 
action of the same unit
        side_actions::iterator previous = position - 1;
-       if (&(*previous)->get_unit() == &(*position)->get_unit())
+       if ((*previous)->get_unit() == (*position)->get_unit())
                return end();
 
        action_ptr action = *position;
@@ -199,7 +199,7 @@
 
        //Verify we're not moving an action out-of-order compared to other 
action of the same unit
        side_actions::iterator previous = position + 1;
-       if (&(*previous)->get_unit() == &(*position)->get_unit())
+       if ((*previous)->get_unit() == (*position)->get_unit())
                return end();
 
        action_ptr action = *position;
@@ -262,7 +262,7 @@
                for (position = start_position; position != end(); ++position)
                {
                        action_ptr action = *position;
-                       if (&action->get_unit() == &unit)
+                       if (action->get_unit() == &unit)
                        {
                                return position;
                        }
@@ -284,7 +284,7 @@
                for (position = start_position; position != begin() - 1; 
--position)
                {
                        action_ptr action = *position;
-                       if (&action->get_unit() == &unit)
+                       if (action->get_unit() == &unit)
                        {
                                return position;
                        }




Related Messages


Powered by MHonArc, Updated Thu Jul 15 23:00:11 2010