Author: sapient
Date: Wed Jul  9 08:47:45 2008
New Revision: 27869

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27869&view=rev
Log:
* new mode "insert" for [set_variables]
* fix various problems with [set_variables] (bug #11980 and bug #11981)

Modified:
    trunk/changelog
    trunk/src/game_events.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=27869&r1=27868&r2=27869&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Wed Jul  9 08:47:45 2008
@@ -26,12 +26,14 @@
    * When examining stored units, now the attacks, max_hitpoints, max_moves,
      and max_experience are the "real" values and can also be modified.
    * new attribute count= for [have_unit] and [have_location] conditionals
+   * new mode "insert" for [set_variables]
    * max_attacks in [unit] now also works for values bigger than 1
    * the "zoc" key works for [unit_type] too, and for [unit] accepts other
      boolean values than 1 and 0 (bug #11889).
    * new effect apply_to=type to transform the unit to a different type
    * remove redundant unit.value (use unit.cost instead)
    * preserve unit.role in next scenario (bugs #3697, #4124, and #11329)
+   * fix various problems with [set_variables] (bugs #11980 and #11981)
  * GUI improvements:
    * Rewrote the textbox history saving of the new widget library. This rewrite
      is incompatible with the old version, but since the library is still in

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=27869&r1=27868&r2=27869&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Wed Jul  9 08:47:45 2008
@@ -1293,37 +1293,45 @@
        {
                assert(state_of_game != NULL);
 
-               const std::string name = cfg["name"];
-
-               std::string mode = cfg["mode"]; //should be one of replace, 
extend, merge
-               if(mode!="append"&&mode!="merge")
-               {
-                       mode="replace";
-               }
-
-               const t_string to_variable = cfg["to_variable"];
+               const t_string& name = cfg["name"];
+               variable_info dest(name, true, variable_info::TYPE_CONTAINER);
+
+               std::string mode = cfg["mode"]; // replace, append, merge, or 
insert
+               if(mode == "extend") {
+                       mode = "append";
+               } else if(mode != "append" && mode != "merge" && mode != 
"insert") {
+                       mode = "replace";
+               }
+
                const vconfig::child_list values = cfg.get_children("value");
                const vconfig::child_list literals = 
cfg.get_children("literal");
                const vconfig::child_list split_elements = 
cfg.get_children("split");
 
-               std::vector<config> data;
-
-               if(!to_variable.empty())
+               config data;
+
+               if(cfg.has_attribute("to_variable"))
                {
-                       variable_info::array_range range = 
state_of_game->get_variable_cfgs(to_variable);
-                       for( ; range.first != range.second; ++range.first)
-                       {
-                               data.push_back(**range.first);
+                       variable_info tovar(cfg["to_variable"], false, 
variable_info::TYPE_CONTAINER);
+                       if(tovar.is_valid) {
+                               if(tovar.explicit_index) {
+                                       data.add_child(dest.key, 
tovar.as_container());
+                               } else {
+                                       variable_info::array_range range = 
tovar.as_array();
+                                       while(range.first != range.second)
+                                       {
+                                               data.add_child(dest.key, 
**range.first++);
+                                       }
+                               }
                        }
                } else if(!values.empty()) {
                        for(vconfig::child_list::const_iterator 
i=values.begin(); i!=values.end(); ++i)
                        {
-                               data.push_back((*i).get_parsed_config());
+                               data.add_child(dest.key, 
(*i).get_parsed_config());
                        }
                } else if(!literals.empty()) {
                        for(vconfig::child_list::const_iterator 
i=literals.begin(); i!=literals.end(); ++i)
                        {
-                               data.push_back(i->get_config());
+                               data.add_child(dest.key, i->get_config());
                        }
                } else if(!split_elements.empty()) {
                        const vconfig split_element=split_elements.front();
@@ -1354,44 +1362,39 @@
                                split_vector=utils::split(split_string, 
*separator, remove_empty ? utils::REMOVE_EMPTY | utils::STRIP_SPACES : 
utils::STRIP_SPACES);
                        }
 
-                       state_of_game->clear_variable_cfg(name);
                        for(std::vector<std::string>::iterator 
i=split_vector.begin(); i!=split_vector.end(); ++i)
                        {
-                               config item = config();
-                               item[key_name]=*i;
-                               data.push_back(item);
-                       }
-               }
-
+                               data.add_child(dest.key)[key_name]=*i;
+                       }
+               }
+               if(mode == "replace")
+               {
+                       if(dest.explicit_index) {
+                               dest.vars->remove_child(dest.key, dest.index);
+                       } else {
+                               dest.vars->clear_children(dest.key);
+                       }
+               }
                if(!data.empty())
                {
-                       if(mode == "replace")
-                       {
-                               state_of_game->clear_variable_cfg(name);
-                       }
                        if(mode == "merge")
                        {
-                               variable_info::array_range target = 
state_of_game->get_variable_cfgs(name);
-                               std::vector<config>::iterator i=data.begin();
-                               config::child_list::iterator j=target.first;
-                               while(i!=data.end())
-                               {
-                                       if(j!=target.second)
-                                       {
-                                               (*j)->merge_with(*i);
-                                               ++j;
-                                       } else {
-                                               
state_of_game->add_variable_cfg(name, *i);
-                                       }
-                                       ++i;
+                               if(dest.explicit_index) {
+                                       // merging multiple children into a 
single explicit index
+                                       // requires that they first be merged 
with each other
+                                       data.merge_children(dest.key);
+                                       
dest.as_container().merge_with(*data.child(dest.key));
+                               } else {
+                                       dest.vars->merge_with(data);
+                               }
+                       } else if(mode == "insert" || dest.explicit_index) {
+                               config::child_itors chitors = 
data.child_range(dest.key);
+                               while(chitors.first != chitors.second) {
+                                       dest.vars->add_child_at(dest.key, 
**chitors.first++, dest.index++);
                                }
                        } else {
-                               for(std::vector<config>::iterator 
i=data.begin(); i!=data.end(); ++i)
-                               {
-                                       state_of_game->add_variable_cfg(name, 
*i);
-                               }
-                       }
-                       return;
+                               dest.vars->append(data);
+                       }
                }
        }
 


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

Reply via email to