mail[Wesnoth-commits] r33879 - in /trunk/src: cavegen.cpp cavegen.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on March 20, 2009 - 08:07:
Author: silene
Date: Fri Mar 20 08:07:03 2009
New Revision: 33879

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33879&view=rev
Log:
Removed config::child_list.

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

Modified: trunk/src/cavegen.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/cavegen.cpp?rev=33879&r1=33878&r2=33879&view=diff
==============================================================================
--- trunk/src/cavegen.cpp (original)
+++ trunk/src/cavegen.cpp Fri Mar 20 08:07:03 2009
@@ -20,10 +20,11 @@
 #include "global.hpp"
 
 #include "cavegen.hpp"
+#include "foreach.hpp"
 #include "log.hpp"
 #include "map.hpp"
 #include "pathfind.hpp"
-
+#include "util.hpp"
 
 #define LOG_NG LOG_STREAM(info, engine)
 
@@ -151,20 +152,20 @@
 
 void cave_map_generator::generate_chambers()
 {
-       const config::child_list& chambers = cfg_->get_children("chamber");
-       for(config::child_list::const_iterator i = chambers.begin(); i != 
chambers.end(); ++i) {
+       foreach (const config &ch, cfg_->child_range("chamber"))
+       {
                // If there is only a chance of the chamber appearing, deal 
with that here.
-               const std::string& chance = (**i)["chance"];
-               if(chance != "" && (rand()%100) < atoi(chance.c_str())) {
+               const std::string &chance = ch["chance"];
+               if (!chance.empty() && (rand() % 100) < atoi(chance.c_str())) 
{
                        continue;
                }
 
-               const std::string& xpos = (**i)["x"];
-               const std::string& ypos = (**i)["y"];
+               const std::string &xpos = ch["x"];
+               const std::string &ypos = ch["y"];
 
                size_t min_xpos = 0, min_ypos = 0, max_xpos = width_, 
max_ypos = height_;
 
-               if(xpos != "") {
+               if (!xpos.empty()) {
                        const std::vector<std::string>& items = 
utils::split(xpos, '-');
                        if(items.empty() == false) {
                                min_xpos = atoi(items.front().c_str()) - 1;
@@ -172,7 +173,7 @@
                        }
                }
 
-               if(ypos != "") {
+               if (!ypos.empty()) {
                        const std::vector<std::string>& items = 
utils::split(ypos, '-');
                        if(items.empty() == false) {
                                min_ypos = atoi(items.front().c_str()) - 1;
@@ -183,34 +184,25 @@
                const size_t x = translate_x(min_xpos + 
(rand()%(max_xpos-min_xpos)));
                const size_t y = translate_y(min_ypos + 
(rand()%(max_ypos-min_ypos)));
 
-               const std::string& size = (**i)["size"];
-               size_t chamber_size = 3;
-               if(size != "") {
-                       chamber_size = atoi(size.c_str());
-               }
-
-               const std::string& jagged = (**i)["jagged"];
-               size_t jagged_edges = 0;
-               if(jagged != "") {
-                       jagged_edges = atoi(jagged.c_str());
-               }
+               size_t chamber_size = lexical_cast_default(ch["size"], 3);
+               size_t jagged_edges = lexical_cast_default(ch["jagged"], 0);
 
                chamber new_chamber;
                new_chamber.center = map_location(x,y);
                
build_chamber(new_chamber.center,new_chamber.locs,chamber_size,jagged_edges);
 
-               new_chamber.items = (**i).child("items");
-
-               const std::string& id = (**i)["id"];
-               if(id != "") {
+               new_chamber.items = ch.child("items");
+
+               const std::string &id = ch["id"];
+               if (!id.empty()) {
                        chamber_ids_[id] = chambers_.size();
                }
 
                chambers_.push_back(new_chamber);
 
-               const config::child_list& passages = 
(**i).get_children("passage");
-               for(config::child_list::const_iterator p = passages.begin(); 
p != passages.end(); ++p) {
-                       const std::string& dst = (**p)["destination"];
+               foreach (const config &p, ch.child_range("passage"))
+               {
+                       const std::string &dst = p["destination"];
 
                        // Find the destination of this passage
                        const std::map<std::string,size_t>::const_iterator 
itor = chamber_ids_.find(dst);
@@ -219,7 +211,7 @@
 
                        assert(itor->second < chambers_.size());
 
-                       
passages_.push_back(passage(new_chamber.center,chambers_[itor->second].center,**p));
+                       passages_.push_back(passage(new_chamber.center, 
chambers_[itor->second].center, p));
                }
        }
 }

Modified: trunk/src/cavegen.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/cavegen.hpp?rev=33879&r1=33878&r2=33879&view=diff
==============================================================================
--- trunk/src/cavegen.hpp (original)
+++ trunk/src/cavegen.hpp Fri Mar 20 08:07:03 2009
@@ -50,7 +50,7 @@
 
                map_location center;
                std::set<map_location> locs;
-               config* items;
+               const config *items;
        };
 
        struct passage {




Related Messages


Powered by MHonArc, Updated Fri Mar 20 08:20:30 2009