whiteboard/mapbuilder.hpp

Go to the documentation of this file.
00001 /* $Id: mapbuilder.hpp 53007 2012-02-14 18:09:58Z mordante $ */
00002 /*
00003  Copyright (C) 2010 - 2012 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
00004  Part of the Battle for Wesnoth Project http://www.wesnoth.org
00005 
00006  This program is free software; you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010  This program is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY.
00012 
00013  See the COPYING file for more details.
00014  */
00015 
00016 /**
00017  * @file
00018  */
00019 
00020 #ifndef WB_MAPBUILDER_HPP_
00021 #define WB_MAPBUILDER_HPP_
00022 
00023 #include <boost/ptr_container/ptr_vector.hpp>
00024 
00025 #include "utility.hpp"
00026 #include "visitor.hpp"
00027 
00028 struct unit_movement_resetter;
00029 
00030 namespace wb
00031 {
00032 
00033 /**
00034  * Visitor that collects and applies unit_map modifications from the actions it visits
00035  * and reverts all changes on destruction.
00036  */
00037 class mapbuilder
00038     : private enable_visit_all<mapbuilder>
00039 {
00040     friend class enable_visit_all<mapbuilder>;
00041 
00042 public:
00043     mapbuilder(unit_map& unit_map);
00044     virtual ~mapbuilder();
00045 
00046     ///builds every team's actions as far into the future as possible, in the correct order
00047     void build_map();
00048 
00049 private:
00050     //"Inherited" from enable_visit_all
00051     bool process(size_t team_index, team&, side_actions&, side_actions::iterator);
00052     bool pre_visit_team(size_t turn, size_t team_index, team&, side_actions&);
00053     bool post_visit_team(size_t turn, size_t team_index, team&, side_actions&);
00054 
00055     bool process_helper(side_actions::iterator const&, action_ptr const&);
00056 
00057     //For validate_visitor to override
00058     virtual void validate(side_actions::iterator const&) {}
00059 
00060     //Does various preliminary actions on the unit map such as resetting moves for some units
00061     void pre_build();
00062 
00063     void restore_normal_map();
00064 
00065     unit_map& unit_map_;
00066 
00067     action_queue applied_actions_;
00068     action_queue applied_actions_this_turn_;
00069 
00070     //Used by pre_build()
00071     boost::ptr_vector<unit_movement_resetter> resetters_;
00072     boost::ptr_vector<temporary_unit_remover> removers_;
00073 
00074     //Used by visit()
00075     std::set<unit const*> acted_this_turn_;
00076 };
00077 
00078 }
00079 
00080 #endif /* WB_MAPBUILDER_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:15 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs