mail[Wesnoth-commits] r44843 - in /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 29, 2010 - 11:56:
Author: gabba
Date: Thu Jul 29 11:56:30 2010
New Revision: 44843

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44843&view=rev
Log:
Whiteboard: new recruit action and mechanism to create it. The visual 
component i.e. the fake unit is still missing.

Added:
    trunk/src/whiteboard/recruit.cpp
    trunk/src/whiteboard/recruit.hpp
Modified:
    trunk/src/CMakeLists.txt
    trunk/src/Makefile.am
    trunk/src/SConscript
    trunk/src/menu_events.cpp
    trunk/src/menu_events.hpp
    trunk/src/play_controller.hpp
    trunk/src/whiteboard/highlight_visitor.hpp
    trunk/src/whiteboard/manager.cpp
    trunk/src/whiteboard/manager.hpp
    trunk/src/whiteboard/mapbuilder_visitor.hpp
    trunk/src/whiteboard/side_actions.cpp
    trunk/src/whiteboard/side_actions.hpp
    trunk/src/whiteboard/typedefs.hpp
    trunk/src/whiteboard/validate_visitor.hpp
    trunk/src/whiteboard/visitor.hpp

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Thu Jul 29 11:56:30 2010
@@ -473,6 +473,7 @@
     whiteboard/move.cpp
     whiteboard/highlight_visitor.cpp
     whiteboard/mapbuilder_visitor.cpp
+    whiteboard/recruit.cpp
     whiteboard/side_actions.cpp
     whiteboard/validate_visitor.cpp
     whiteboard/visitor.cpp

Modified: trunk/src/Makefile.am
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Thu Jul 29 11:56:30 2010
@@ -291,6 +291,7 @@
        whiteboard/manager.cpp \
        whiteboard/highlight_visitor.cpp \
        whiteboard/mapbuilder_visitor.cpp \
+       whiteboard/recruit.cpp \
        whiteboard/side_actions.cpp \
        whiteboard/validate_visitor.cpp \
        whiteboard/visitor.cpp \

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Thu Jul 29 11:56:30 2010
@@ -271,6 +271,7 @@
     whiteboard/move.cpp
     whiteboard/highlight_visitor.cpp
     whiteboard/mapbuilder_visitor.cpp
+    whiteboard/recruit.cpp
     whiteboard/side_actions.cpp
     whiteboard/validate_visitor.cpp
     whiteboard/visitor.cpp

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Thu Jul 29 11:56:30 2010
@@ -723,7 +723,9 @@
        }
 
        if(recruit_res != -1) {
-               do_recruit(item_keys[recruit_res], side_num, last_hex);
+               if 
(!resources::whiteboard->save_recruit(item_keys[recruit_res], side_num, 
last_hex)) {
+                       do_recruit(item_keys[recruit_res], side_num, 
last_hex);
+               }
        }
 }
 

Modified: trunk/src/menu_events.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/menu_events.hpp (original)
+++ trunk/src/menu_events.hpp Thu Jul 29 11:56:30 2010
@@ -94,6 +94,7 @@
        { return const_cast<menu_handler *>(this)->current_unit(); }
        void move_unit_to_loc(const unit_map::const_iterator& ui, const 
map_location& target,
                bool continue_move, int side_num, mouse_handler 
&mousehandler);
+       void do_recruit(const std::string& name, int side_num, const 
map_location& last_hex);
        void do_speak();
        void do_search(const std::string& new_search);
        void do_command(const std::string &str);
@@ -110,7 +111,6 @@
        friend class console_handler;
 
        //void do_speak(const std::string& message, bool allies_only);
-       void do_recruit(const std::string& name, int side_num, const 
map_location& last_hex);
 //     std::vector<std::string> create_unit_table(const 
statistics::stats::str_int_map& m,unsigned int team);
        bool has_friends() const;
        bool clear_shroud(int side_num);

Modified: trunk/src/play_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/play_controller.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/play_controller.hpp (original)
+++ trunk/src/play_controller.hpp Thu Jul 29 11:56:30 2010
@@ -136,6 +136,7 @@
        bool is_skipping_replay() const { return skip_replay_;}
 
        events::mouse_handler& get_mouse_handler_base();
+       events::menu_handler& get_menu_handler() { return menu_handler_; }
 
 protected:
        void slice_before_scroll();

Modified: trunk/src/whiteboard/highlight_visitor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/highlight_visitor.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/highlight_visitor.hpp (original)
+++ trunk/src/whiteboard/highlight_visitor.hpp Thu Jul 29 11:56:30 2010
@@ -52,6 +52,7 @@
 
        virtual void visit_move(move_ptr move);
        virtual void visit_attack(attack_ptr attack);
+       virtual void visit_recruit(recruit_ptr) {}
 
 private:
 

Modified: trunk/src/whiteboard/manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.cpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.cpp (original)
+++ trunk/src/whiteboard/manager.cpp Thu Jul 29 11:56:30 2010
@@ -456,6 +456,26 @@
        }
 }
 
+bool manager::save_recruit(const std::string& name, int side_num, const 
map_location& recruit_hex)
+{
+       bool created_planned_recruit = false;
+
+       if (active_) {
+               if (side_num != resources::screen->viewing_side())
+               {
+                       LOG_WB <<"manager::save_recruit called for a 
different side than viewing side.\n";
+                       created_planned_recruit = false;
+               }
+               else
+               {
+                       viewer_actions()->queue_recruit(name, recruit_hex);
+                       created_planned_recruit = true;
+               }
+       }
+
+       return created_planned_recruit;
+}
+
 void manager::contextual_execute()
 {
        if (!(executing_actions_ || viewer_actions()->empty())

Modified: trunk/src/whiteboard/manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/manager.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/manager.hpp (original)
+++ trunk/src/whiteboard/manager.hpp Thu Jul 29 11:56:30 2010
@@ -106,6 +106,9 @@
 
        void save_temp_attack(const map_location& attack_from, const 
map_location& target_hex);
 
+       /// returns true if manager has saved a planned recruit
+       bool save_recruit(const std::string& name, int side_num, const 
map_location& recruit_hex);
+
        /** Executes first action in the queue for current side */
        void contextual_execute();
        /** Deletes last action in the queue for current side */

Modified: trunk/src/whiteboard/mapbuilder_visitor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/mapbuilder_visitor.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/mapbuilder_visitor.hpp (original)
+++ trunk/src/whiteboard/mapbuilder_visitor.hpp Thu Jul 29 11:56:30 2010
@@ -52,6 +52,7 @@
        /// Visitor pattern method, no need to call this directly
        virtual void visit_move(move_ptr move);
        virtual void visit_attack(attack_ptr attack);
+       virtual void visit_recruit(recruit_ptr) {}
 
 
 

Added: trunk/src/whiteboard/recruit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/recruit.cpp?rev=44843&view=auto
==============================================================================
--- trunk/src/whiteboard/recruit.cpp (added)
+++ trunk/src/whiteboard/recruit.cpp Thu Jul 29 11:56:30 2010
@@ -1,0 +1,100 @@
+/* $Id$ */
+/*
+ Copyright (C) 2010 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
+ Part of the Battle for Wesnoth Project http://www.wesnoth.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2
+ or at your option any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY.
+
+ See the COPYING file for more details.
+ */
+
+/**
+ * @file recruit.cpp
+ */
+
+#include "recruit.hpp"
+
+#include "visitor.hpp"
+
+#include "game_display.hpp"
+#include "menu_events.hpp"
+#include "play_controller.hpp"
+#include "resources.hpp"
+#include "unit.hpp"
+#include "unit_map.hpp"
+#include "unit_types.hpp"
+
+namespace wb
+{
+
+std::ostream& operator<<(std::ostream& s, recruit_ptr recruit)
+{
+       assert(recruit);
+       return recruit->print(s);
+}
+std::ostream& operator<<(std::ostream& s, recruit_const_ptr recruit)
+{
+       assert(recruit);
+       return recruit->print(s);
+}
+
+recruit::recruit(const std::string& unit_name, const map_location& 
recruit_hex):
+               unit_name_(unit_name),
+               recruit_hex_(recruit_hex),
+               valid_(true),
+               temp_cost_()
+{
+}
+
+recruit::~recruit()
+{
+}
+
+void recruit::accept(visitor& v)
+{
+       v.visit_recruit(shared_from_this());
+}
+
+bool recruit::execute()
+{
+       assert(valid_);
+       int side_num = resources::screen->viewing_side();
+       const std::set<std::string>& recruits = (*resources::teams)[side_num 
- 1].recruits();
+       if (recruits.find(unit_name_) != recruits.end())
+       {
+               
resources::controller->get_menu_handler().do_recruit(unit_name_, side_num, 
recruit_hex_);
+       }
+       else
+       {
+               LOG_WB << "Planned recruit impossible to execute since unit 
is not in recruit list anymore.\n";
+       }
+       return true;
+}
+
+void recruit::apply_temp_modifier(unit_map& unit_map)
+{
+       assert(valid_);
+       unit_type const* type = unit_types.find(unit_name_);
+       assert(type);
+       int side_num = resources::screen->viewing_side();
+       unit* temp_unit = new unit(type, side_num, true);
+
+       unit_map.add(recruit_hex_, *temp_unit);
+       //unit map takes ownership of temp_unit
+
+       temp_cost_ = type->cost();
+       //TODO: add cost to money spent on recruits, need variable in 
side_actions to track this.
+}
+
+void recruit::remove_temp_modifier(unit_map& unit_map)
+{
+       unit_map.extract(recruit_hex_);
+
+       //TODO: remove cost from money spent on recruits, need variable in 
side_actions to track this.
+}
+
+}

Added: trunk/src/whiteboard/recruit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/recruit.hpp?rev=44843&view=auto
==============================================================================
--- trunk/src/whiteboard/recruit.hpp (added)
+++ trunk/src/whiteboard/recruit.hpp Thu Jul 29 11:56:30 2010
@@ -1,0 +1,90 @@
+/* $Id$ */
+/*
+ Copyright (C) 2010 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
+ Part of the Battle for Wesnoth Project http://www.wesnoth.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2
+ or at your option any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY.
+
+ See the COPYING file for more details.
+ */
+
+/**
+ * @file recruit.hpp
+ */
+
+#ifndef WB_RECRUIT_HPP_
+#define WB_RECRUIT_HPP_
+
+
+#include "action.hpp"
+
+#include "typedefs.hpp"
+
+#include "map_location.hpp"
+
+#include <boost/enable_shared_from_this.hpp>
+
+namespace wb
+{
+
+/*
+ *
+ */
+class recruit: public wb::action, public 
boost::enable_shared_from_this<recruit>
+{
+public:
+       recruit(const std::string& unit_name, const map_location& 
recruit_hex);
+       virtual ~recruit();
+
+       friend class validate_visitor;
+       friend class highlight_visitor;
+
+       virtual std::ostream& print(std::ostream& s) const { return s; }
+
+       virtual void accept(visitor& v);
+
+       /** Returns true if the action has been completely executed and can 
be deleted */
+       virtual bool execute();
+
+       /** Applies temporarily the result of this action to the specified 
unit map. */
+       virtual void apply_temp_modifier(unit_map& unit_map);
+       /** Removes the result of this action from the specified unit map. */
+       virtual void remove_temp_modifier(unit_map& unit_map);
+
+       /** Gets called by display when drawing a hex, to allow actions to 
draw to the screen. */
+       virtual void draw_hex(const map_location&){ }
+
+       /**
+        * Indicates whether this hex is the preferred hex to draw the 
numbering for this action.
+        */
+       virtual bool is_numbering_hex(const map_location& hex) const { return 
hex == recruit_hex_; }
+
+       /** For recruit actions, always returns NULL. */
+       virtual unit* get_unit() const { return NULL; }
+
+       /**
+        * Indicates to an action whether its status is invalid, and whether 
it should change its
+        * display (and avoid any change to the game state) accordingly
+        */
+       virtual void set_valid(bool valid) { valid_ = valid; }
+       virtual bool is_valid() { return valid_; }
+
+
+protected:
+       std::string unit_name_;
+       map_location recruit_hex_;
+       bool valid_;
+
+       int temp_cost_;
+};
+
+std::ostream& operator<<(std::ostream& s, recruit_ptr recruit);
+std::ostream& operator<<(std::ostream& s, recruit_const_ptr recruit);
+
+}
+
+#endif /* WB_RECRUIT_HPP_ */

Modified: trunk/src/whiteboard/side_actions.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.cpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Thu Jul 29 11:56:30 2010
@@ -21,6 +21,7 @@
 #include "attack.hpp"
 #include "manager.hpp"
 #include "move.hpp"
+#include "recruit.hpp"
 #include "validate_visitor.hpp"
 
 #include "foreach.hpp"
@@ -137,16 +138,25 @@
 
 side_actions::iterator side_actions::queue_move(const 
pathfind::marked_route& route, arrow_ptr arrow, fake_unit_ptr fake_unit)
 {
-       action_ptr action(new move(route, arrow, fake_unit));
-       return queue_action(action);
+       move_ptr new_move;
+       new_move.reset(new move(route, arrow, fake_unit));
+       return queue_action(new_move);
 }
 
 side_actions::iterator side_actions::queue_attack(const map_location& 
target_hex, int weapon_choice,
                const pathfind::marked_route& route,
                arrow_ptr arrow, fake_unit_ptr fake_unit)
 {
-       action_ptr action(new attack(target_hex, weapon_choice, route, arrow, 
fake_unit));
-       return queue_action(action);
+       attack_ptr new_attack;
+       new_attack.reset(new attack(target_hex, weapon_choice, route, arrow, 
fake_unit));
+       return queue_action(new_attack);
+}
+
+side_actions::iterator side_actions::queue_recruit(const std::string& 
unit_name, const map_location& recruit_hex)
+{
+       recruit_ptr new_recruit;
+       new_recruit.reset(new recruit(unit_name, recruit_hex));
+       return queue_action(new_recruit);
 }
 
 side_actions::iterator side_actions::insert_action(iterator position, 
action_ptr action)

Modified: trunk/src/whiteboard/side_actions.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.hpp (original)
+++ trunk/src/whiteboard/side_actions.hpp Thu Jul 29 11:56:30 2010
@@ -104,6 +104,12 @@
                        arrow_ptr arrow, fake_unit_ptr fake_unit);
 
        /**
+        * Queues a recruit to be executed last
+        * @return The queued recruit's position
+        */
+       iterator queue_recruit(const std::string& unit_name, const 
map_location& recruit_hex);
+
+       /**
         * Inserts an action at the specified position. The begin() and end() 
functions might prove useful here.
         * @return The inserted action's position.
         */

Modified: trunk/src/whiteboard/typedefs.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/typedefs.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/typedefs.hpp (original)
+++ trunk/src/whiteboard/typedefs.hpp Thu Jul 29 11:56:30 2010
@@ -50,6 +50,7 @@
 class action;
 class move;
 class attack;
+class recruit;
 class side_actions;
 
 typedef boost::shared_ptr<arrow> arrow_ptr;
@@ -65,6 +66,8 @@
 typedef boost::shared_ptr<move const> move_const_ptr;
 typedef boost::shared_ptr<attack> attack_ptr;
 typedef boost::shared_ptr<attack const> attack_const_ptr;
+typedef boost::shared_ptr<recruit> recruit_ptr;
+typedef boost::shared_ptr<recruit const> recruit_const_ptr;
 
 } // end namespace wb
 

Modified: trunk/src/whiteboard/validate_visitor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/validate_visitor.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/validate_visitor.hpp (original)
+++ trunk/src/whiteboard/validate_visitor.hpp Thu Jul 29 11:56:30 2010
@@ -38,6 +38,7 @@
 
        virtual void visit_move(move_ptr move);
        virtual void visit_attack(attack_ptr attack);
+       virtual void visit_recruit(recruit_ptr) {}
 
 private:
        std::set<action_ptr> actions_to_erase_;

Modified: trunk/src/whiteboard/visitor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/visitor.hpp?rev=44843&r1=44842&r2=44843&view=diff
==============================================================================
--- trunk/src/whiteboard/visitor.hpp (original)
+++ trunk/src/whiteboard/visitor.hpp Thu Jul 29 11:56:30 2010
@@ -34,6 +34,7 @@
 
        virtual void visit_move(move_ptr move) = 0;
        virtual void visit_attack(attack_ptr attack) = 0;
+       virtual void visit_recruit(recruit_ptr recruit) = 0;
 };
 
 }




Related Messages


Powered by MHonArc, Updated Thu Jul 29 12:00:26 2010