Author: alink
Date: Mon Apr 20 23:58:45 2009
New Revision: 35088

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35088&view=rev
Log:
Add a key 'type_adv_tree' in [hide_help] to hide a whole advancement tree
Syntax: type_adv_tree=Peasant hides peasant, bowman, longbowman, spearman...
Also add an utility function to get the advancement tree of a unit_type.

Modified:
    trunk/src/unit_types.cpp
    trunk/src/unit_types.hpp

Modified: trunk/src/unit_types.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.cpp?rev=35088&r1=35087&r2=35088&view=diff
==============================================================================
--- trunk/src/unit_types.cpp (original)
+++ trunk/src/unit_types.cpp Mon Apr 20 23:58:45 2009
@@ -1099,6 +1099,28 @@
        }
 }
 
+static void advancement_tree_internal(const std::string id, 
std::set<std::string>& tree)
+{
+       unit_type_data::unit_type_map::const_iterator ut =
+                       unit_type_data::types().find_unit_type(id);
+       if (ut == unit_type_data::types().end())
+               return;
+
+       foreach(const std::string& adv, ut->second.advances_to()) {
+               if (tree.insert(adv).second) {
+                       // insertion succeed, expand the new type
+                       advancement_tree_internal(adv, tree);
+               }
+       }
+}
+
+std::set<std::string> unit_type::advancement_tree() const
+{
+       std::set<std::string> tree;
+       advancement_tree_internal(id_, tree);
+       return tree;
+}
+
 unit_type_data* unit_type_data::instance_ = NULL;
 
 unit_type_data::unit_type_data() :
@@ -1311,6 +1333,16 @@
 
        std::vector<std::string> types = utils::split(cfg["type"]);
        hide_help_type_.back().insert(types.begin(), types.end());
+
+       std::vector<std::string> trees = utils::split(cfg["type_adv_tree"]);
+       hide_help_type_.back().insert(trees.begin(), trees.end());
+       foreach(const std::string& t_id, trees) {
+               unit_type_map::iterator ut = types_.find(t_id);
+               if (ut != types_.end()) {
+                       std::set<std::string> adv_tree = 
ut->second.advancement_tree();
+                       hide_help_type_.back().insert(adv_tree.begin(), 
adv_tree.end());
+               }
+       }
 
        // we call recursively all the imbricated [not] tags
        read_hide_help(cfg.child("not"));

Modified: trunk/src/unit_types.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.hpp?rev=35088&r1=35087&r2=35088&view=diff
==============================================================================
--- trunk/src/unit_types.hpp (original)
+++ trunk/src/unit_types.hpp Mon Apr 20 23:58:45 2009
@@ -182,6 +182,10 @@
        /** Adds units that this unit advances from, for help file purposes. */
        void add_advancesfrom(const std::string& unit_id);
 
+       /** Get the advancement tree
+        *  Build a set of unit type's id of this unit type's advancement tree 
*/
+       std::set<std::string> advancement_tree() const;
+
        const unit_type& get_gender_unit_type(unit_race::GENDER gender) const;
        const unit_type& get_variation(const std::string& name) const;
        /** Info on the type of unit that the unit reanimates as. */


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to