Author: boucman
Date: Tue Aug 21 23:27:06 2007
New Revision: 19707

URL: http://svn.gna.org/viewcvs/wesnoth?rev=19707&view=rev
Log:
 apllying patch 788 : ability to add and remove abilities via WML thx to 
joshudson

Modified:
    trunk/changelog
    trunk/data/core/macros/items.cfg
    trunk/src/unit.cpp
    trunk/src/unit.hpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=19707&r1=19706&r2=19707&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Tue Aug 21 23:27:06 2007
@@ -105,6 +105,7 @@
    * there's a new "Game Settings" window which shows the basic game settings
      for each player, accessible through the "More" button in the "Status 
Table"
  * WML engine:
+   * added effect types new_ability and remove_ability using [abilities] subkey
    * now [base_unit]id= inside [unit] can extend upon existing unit types
    * new tag [filter_radius] to allow greater control over radius expansion
      when using the standard location filter

Modified: trunk/data/core/macros/items.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/macros/items.cfg?rev=19707&r1=19706&r2=19707&view=diff
==============================================================================
--- trunk/data/core/macros/items.cfg (original)
+++ trunk/data/core/macros/items.cfg Tue Aug 21 23:27:06 2007
@@ -545,16 +545,12 @@
                 [/removeitem]
             [/then]
             [effect]
-                apply_to=attack
-                range=melee
-                set_type=arcane
-            [/effect]
-        [/object]
-        [message]
-            speaker=narrator
-            message= _ "Can't set abilities yet, sorry."
-            image=wesnoth-icon.png
-        [/message]
+                apply_to=new_ability
+               [abilities]
+                   {ABILITY_REGENERATES}
+               [/abilities]
+            [/effect]
+        [/object]
     [/event]
 #enddef
 

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=19707&r1=19706&r2=19707&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Tue Aug 21 23:27:06 2007
@@ -82,6 +82,7 @@
                movement_b_(o.movement_b_),
                defense_b_(o.defense_b_),
                resistance_b_(o.resistance_b_),
+               abilities_b_(o.abilities_b_),
 
                advances_to_(o.advances_to_),
                id_(unit_id_test(o.id_)),
@@ -757,6 +758,23 @@
        return false;
 }
 
+void unit::remove_ability_by_id(const std::string &ability)
+{
+       config* abil = cfg_.child("abilities");
+       if(abil) {
+               for(config::child_map::const_iterator i = 
abil->all_children().begin(); i != abil->all_children().end(); ++i) {
+                       int offset = 0;
+                       for(config::child_list::const_iterator j = 
i->second.begin(); j != i->second.end(); ++j, ++offset) {
+                               if((**j)["id"] == ability) {
+                                       abil->remove_child(i->first, offset);
+                                       return; /* Abilities are unique by id, 
so we won't find another. */
+                                               /* Besides, we just wrecked our 
iterator. Bye. */
+                               }
+                       }
+               }
+       }
+}
+
 bool unit::matches_filter(const vconfig& cfg, const gamemap::location& loc, 
bool use_flat_tod) const
 {
        bool matches = true;
@@ -1445,9 +1463,11 @@
        cfg.clear_children("movement_costs");
        cfg.clear_children("defense");
        cfg.clear_children("resistance");
+       cfg.clear_children("abilities");
        cfg.add_child("movement_costs",movement_b_);
        cfg.add_child("defense",defense_b_);
        cfg.add_child("resistance",resistance_b_);
+       cfg.add_child("abilities",abilities_b_);
        cfg["x"] = x;
        cfg["y"] = y;
        cfg["id"] = id();
@@ -2319,9 +2339,11 @@
        cfg_.clear_children("movement_costs");
        cfg_.clear_children("defense");
        cfg_.clear_children("resistance");
+       cfg_.clear_children("abilities");
        cfg_.add_child("movement_costs",movement_b_);
        cfg_.add_child("defense",defense_b_);
        cfg_.add_child("resistance",resistance_b_);
+       cfg_.add_child("abilities",abilities_b_);
 }
 void unit::backup_state()
 {
@@ -2343,6 +2365,11 @@
                resistance_b_ = *cfg_.child("resistance");
        } else {
                resistance_b_ = config();
+       }
+       if(cfg_.child("abilities")) {
+               abilities_b_ = *cfg_.child("abilities");
+       } else {
+               abilities_b_ = config();
        }
 }
 
@@ -2634,6 +2661,32 @@
                                        if(!zoc_value.empty()) {
                                                emit_zoc_ = 
lexical_cast_default<int>(zoc_value);
                                        }
+                               } else if (apply_to == "new_ability") {
+                                       config *ab_effect;
+                                       config *ab = cfg_.child("abilities");
+                                       if(!ab) {
+                                               ab = 
&cfg_.add_child("abilities");
+                                       }
+                                       ab_effect = 
(**i.first).child("abilities");
+                                       if (ab_effect) {
+                                               
for(config::child_map::const_iterator j = ab_effect->all_children().begin(); j 
!= ab_effect->all_children().end(); ++j) {
+                                                       for 
(config::child_list::const_iterator k = j->second.begin(); k != 
j->second.end(); ++k) {
+                                                               if 
(!has_ability_by_id((**k)["id"])) {
+                                                                       
ab->add_child(j->first, **k);
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               } else if (apply_to == "remove_ability") {
+                                       config *ab_effect = 
(**i.first).child("abilities");
+                                       config *ab = cfg_.child("abilities");
+                                       if (ab && ab_effect) {
+                                               
for(config::child_map::const_iterator j = ab_effect->all_children().begin(); j 
!= ab_effect->all_children().end(); ++j) {
+                                                       for 
(config::child_list::const_iterator k = j->second.begin(); k != 
j->second.end(); ++k) {
+                                                               
remove_ability_by_id((**k)["id"]);
+                                                       }
+                                               }
+                                       }
                                } else if (apply_to == "image_mod") {
                                        LOG_UT << "applying image_mod \n";
                                        std::string mod = 
(**i.first)["replace"];

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=19707&r1=19706&r2=19707&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Tue Aug 21 23:27:06 2007
@@ -314,11 +314,13 @@
 
        int movement_cost_internal(t_translation::t_letter terrain, int 
recurse_count=0) const;
        bool has_ability_by_id(const std::string& ability) const;
+       void remove_ability_by_id(const std::string& ability);
 
        config cfg_;
        config movement_b_;
        config defense_b_;
        config resistance_b_;
+               config abilities_b_;
 
        std::vector<std::string> advances_to_;
        std::string id_;


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

Reply via email to