mail[Wesnoth-commits] r43481 - in /trunk/src/whiteboard: action.hpp manager.cpp manager.hpp move.cpp move.hpp side_actions.cpp side_actions.hpp


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

Header


Content

Posted by gabrielmorin on June 16, 2010 - 06:27:
Author: gabba
Date: Wed Jun 16 06:27:49 2010
New Revision: 43481

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43481&view=rev
Log:
Whiteboard: initial test of action execution, by defining the same move twice

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

Modified: trunk/src/whiteboard/action.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/action.hpp?rev=43481&r1=43480&r2=43481&view=diff
==============================================================================
--- trunk/src/whiteboard/action.hpp (original)
+++ trunk/src/whiteboard/action.hpp Wed Jun 16 06:27:49 2010
@@ -52,6 +52,8 @@
        virtual ~action();
 
        virtual void accept(visitor& v) = 0;
+
+       virtual void execute() = 0;
 };
 
 } // end namespace wb

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=43481&r1=43480&r2=43481&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Wed Jun 16 06:27:49 2010
@@ -168,9 +168,19 @@
                action_ptr action = 
finder.find_first_action_of(*selected_unit_, 
get_current_side_actions().actions());
                if (action)
                {
-                       LOG_WB << "Previous action found for unit " << 
selected_unit_->name() << " [" << selected_unit_->id() << "]"
-                                       << ", erasing action.\n";
-                       get_current_side_actions().remove_action(action);
+                       //FIXME: temporary for testing: if move created twice 
on same hex, execute instead
+                       if 
(dynamic_cast<move*>(action.get())->get_arrow()->get_path().back()
+                                       == move_arrow_->get_path().back())
+                       {
+                               get_current_side_actions().execute(action);
+                               return;
+                       }
+                       else //erase move
+                       {
+                               LOG_WB << "Previous action found for unit " 
<< selected_unit_->name() << " [" << selected_unit_->id() << "]"
+                                               << ", erasing action.\n";
+                               
get_current_side_actions().remove_action(action);
+                       }
                }
        } // kill action shared_ptr by closing scope
 
@@ -187,4 +197,9 @@
        selected_unit_ = NULL;
 }
 
+void manager::execute_first()
+{
+       get_current_side_actions().execute_first();
+}
+
 } // end namespace wb

Modified: trunk/src/whiteboard/manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.hpp?rev=43481&r1=43480&r2=43481&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/manager.hpp Wed Jun 16 06:27:49 2010
@@ -81,6 +81,9 @@
      */
        void save_temp_move();
 
+       /** Executes first action in the queue for current side */
+       void execute_first();
+
 private:
        /**
         * Tracks whether the whiteboard is active.

Modified: trunk/src/whiteboard/move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=43481&r1=43480&r2=43481&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Wed Jun 16 06:27:49 2010
@@ -20,10 +20,14 @@
 
 #include "visitor.hpp"
 
+#include "actions.hpp"
 #include "arrow.hpp"
 #include "unit.hpp"
 #include "config.hpp"
+#include "play_controller.hpp"
+#include "replay.hpp"
 #include "resources.hpp"
+#include "team.hpp"
 #include "game_display.hpp"
 
 namespace wb {
@@ -49,9 +53,24 @@
        }
 }
 
+team& get_current_team()
+{
+       int current_side = resources::controller->current_side();
+       team& current_team = (*resources::teams)[current_side - 1];
+       return current_team;
+}
+
 void move::accept(visitor& v)
 {
        v.visit_move(shared_from_this());
+}
+
+void move::execute()
+{
+       static bool show_move = true;
+       map_location* next_unit = NULL; //FIXME: Not sure what to do with 
this variable as of now
+       ::move_unit(NULL, arrow_->get_path(), &recorder, 
resources::undo_stack, show_move, next_unit,
+                       get_current_team().auto_shroud_updates());
 }
 
 modifier_ptr 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=43481&r1=43480&r2=43481&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Wed Jun 16 06:27:49 2010
@@ -48,6 +48,8 @@
 
        virtual void accept(visitor& v);
 
+       virtual void execute();
+
        unit& get_unit() { return unit_; }
 
        boost::shared_ptr<arrow> 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=43481&r1=43480&r2=43481&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Wed Jun 16 06:27:49 2010
@@ -36,6 +36,21 @@
 const action_set& side_actions::actions() const
 {
        return actions_;
+}
+
+void side_actions::execute_first()
+{
+       actions_.front()->execute();
+       actions_.pop_front();
+       //TODO: Validate remaining actions here
+}
+
+void side_actions::execute(action_ptr action)
+{
+       assert(!actions_.empty());
+       action->execute();
+       remove_action(action);
+       //TODO: Validate remaining actions here
 }
 
 void side_actions::insert_move(unit& subject, const map_location& 
target_hex, size_t index, boost::shared_ptr<arrow> arrow,

Modified: trunk/src/whiteboard/side_actions.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.hpp?rev=43481&r1=43480&r2=43481&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.hpp (original)
+++ trunk/src/whiteboard/side_actions.hpp Wed Jun 16 06:27:49 2010
@@ -44,6 +44,18 @@
        virtual ~side_actions();
 
        const action_set& actions() const;
+
+       /**
+        * Executes the first action in the queue, and then deletes it.
+        * TODO: Validate all subsequent actions after doing this!
+        */
+       void execute_first();
+
+       /**
+        * Executes the specified action, if it exists in the queue.
+        * TODO: Validate all subsequent actions after doing this!
+        */
+       void execute(action_ptr action);
 
        /**
         * Returns the index for the first (executed earlier) action within 
the actions set.




Related Messages


Powered by MHonArc, Updated Wed Jun 16 06:40:18 2010