mail[Wesnoth-commits] r44419 - in /trunk/src/whiteboard: attack.hpp manager.cpp manager.hpp move.cpp move.hpp


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

Header


Content

Posted by gabrielmorin on July 20, 2010 - 09:52:
Author: gabba
Date: Tue Jul 20 09:51:59 2010
New Revision: 44419

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44419&view=rev
Log:
Whiteboard: Re-add a direct unit reference to attack/move, and find it from 
src hex in the constructor. Add find_future_unit() method to manager.

Modified:
    trunk/src/whiteboard/attack.hpp
    trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/manager.hpp
    trunk/src/whiteboard/move.cpp
    trunk/src/whiteboard/move.hpp

Modified: trunk/src/whiteboard/attack.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/attack.hpp?rev=44419&r1=44418&r2=44419&view=diff
==============================================================================
--- trunk/src/whiteboard/attack.hpp (original)
+++ trunk/src/whiteboard/attack.hpp Tue Jul 20 09:51:59 2010
@@ -35,6 +35,7 @@
        friend class highlight_visitor;
        friend std::ostream& operator<<(std::ostream& s, attack const& 
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 
map_location& source_hex, const map_location& dest_hex,
                        arrow_ptr arrow, fake_unit_ptr fake_unit);
        virtual ~attack();

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=44419&r1=44418&r2=44419&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Tue Jul 20 09:51:59 2010
@@ -41,9 +41,10 @@
        return side_actions;
 }
 
-static unit* find_unit(map_location hex)
+unit* manager::find_future_unit(map_location hex)
 {
        scoped_planned_unit_map planned_unit_map;
+       assert(has_planned_unit_map());
        unit_map::iterator it;
                if ((it = resources::units->find(hex)) != 
resources::units->end())
                        return &*it;
@@ -153,9 +154,8 @@
 
 void manager::validate_viewer_actions()
 {
-       executing_actions_ = true;
+       assert(!executing_actions_);
        viewer_actions()->validate_actions();
-       executing_actions_ = false;
 }
 
 void manager::set_planned_unit_map()
@@ -331,7 +331,7 @@
 {
        if (has_temp_move() && !executing_actions_)
        {
-               assert(!has_planned_unit_map());
+               scoped_planned_unit_map planned_unit_map;
 
                std::vector<map_location> steps;
                arrow_ptr move_arrow;
@@ -352,8 +352,6 @@
 {
        if (active_ && !executing_actions_)
        {
-               assert(!has_planned_unit_map());
-
                std::vector<map_location> steps;
                arrow_ptr move_arrow;
                fake_unit_ptr fake_unit;
@@ -378,12 +376,9 @@
 
                on_deselect_hex();
 
-               unit* attacking_unit;
-               {
-                       scoped_planned_unit_map planned_unit_map;
-                       attacking_unit = find_unit(source_hex);
-                       assert(attacking_unit);
-               }
+               unit* attacking_unit = find_future_unit(source_hex);
+               assert(attacking_unit);
+
 
                int weapon_choice = 
resources::controller->get_mouse_handler_base().show_attack_dialog(
                                        attacking_unit->get_location(), 
target_hex);
@@ -506,7 +501,7 @@
 
 unit* manager::selected_unit()
 {
-       return find_unit(selected_hex_);
+       return find_future_unit(selected_hex_);
 }
 
 scoped_planned_unit_map::scoped_planned_unit_map()

Modified: trunk/src/whiteboard/manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.hpp?rev=44419&r1=44418&r2=44419&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/manager.hpp Tue Jul 20 09:51:59 2010
@@ -68,6 +68,8 @@
        void set_planned_unit_map();
        void set_real_unit_map();
        bool has_planned_unit_map() const { return planned_unit_map_active_; }
+       ///Applies the future unit map and returns a pointer to the unit at 
hex, NULL if none
+       unit* find_future_unit(map_location hex);
 
        /**
         * Callback from the display when drawing hexes, to allow the 
whiteboard to

Modified: trunk/src/whiteboard/move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=44419&r1=44418&r2=44419&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Tue Jul 20 09:51:59 2010
@@ -19,6 +19,7 @@
 #include "move.hpp"
 
 #include "visitor.hpp"
+#include "manager.hpp"
 
 #include "actions.hpp"
 #include "arrow.hpp"
@@ -62,7 +63,8 @@
 
 move::move(const map_location& source_hex, const map_location& target_hex,
                arrow_ptr arrow, fake_unit_ptr fake_unit)
-: underlying_unit_id_(-1),
+: unit_(NULL),
+  unit_id_(),
   source_hex_(source_hex),
   dest_hex_(target_hex),
   movement_cost_(0),
@@ -70,7 +72,12 @@
   fake_unit_(fake_unit),
   valid_(true)
 {
-       if (source_hex_.valid() && dest_hex_.valid() && source_hex_ != 
dest_hex_ && get_unit())
+
+       unit_ = resources::whiteboard->find_future_unit(source_hex_);
+       assert(unit_);
+       unit_id_ = unit_->id();
+
+       if (source_hex_.valid() && dest_hex_.valid() && source_hex_ != 
dest_hex_)
        {
 
                // Calculate move cost
@@ -171,15 +178,6 @@
 
        arrow_->set_alpha(ALPHA_NORMAL);
        return move_finished_completely;
-}
-
-unit* move::get_unit() const
-{
-       unit_map::iterator it = resources::units->find(source_hex_);
-       if (it != resources::units->end())
-               return &*it;
-       else
-               return NULL;
 }
 
 void move::apply_temp_modifier(unit_map& unit_map)

Modified: trunk/src/whiteboard/move.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.hpp?rev=44419&r1=44418&r2=44419&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Tue Jul 20 09:51:59 2010
@@ -43,6 +43,7 @@
        static const std::string ARROW_STYLE_VALID;
        static const std::string ARROW_STYLE_INVALID;
 
+       ///Future unit map must be valid during construction, so that move 
can find its unit
        move(const map_location& source_hex, const map_location& target_hex, 
arrow_ptr arrow,
                        fake_unit_ptr fake_unit);
        virtual ~move();
@@ -54,7 +55,7 @@
        virtual bool execute();
 
        /** Return the unit targeted by this action. Null if unit doesn't 
exist. */
-       virtual unit* get_unit() const;
+       virtual unit* get_unit() const { return unit_; }
 
        virtual arrow_ptr get_arrow() { return arrow_; }
        virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
@@ -75,7 +76,8 @@
        virtual bool is_valid() { return valid_; }
 
 protected:
-       int underlying_unit_id_;
+       unit* unit_;
+       std::string unit_id_;
        map_location source_hex_;
        map_location dest_hex_;
        int movement_cost_;




Related Messages


Powered by MHonArc, Updated Tue Jul 20 10:00:13 2010