From 862f907158311aa239b0a82fa4abb4a4e398861d Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 6 Jul 2007 08:34:09 +0000 Subject: [1748837] Fixed odd-looking messages when explore finds two or more identical features. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1769 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/mapdef.cc | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'crawl-ref/source/mapdef.cc') diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc index 65592df4b5..c80f243d60 100644 --- a/crawl-ref/source/mapdef.cc +++ b/crawl-ref/source/mapdef.cc @@ -1,7 +1,15 @@ +/* + * File: mapdef.cc + * Summary: Support code for Crawl des files. + * + * Modified for Crawl Reference by $Author: dshaligram $ on $Date: 2007-06-30T15:49:18.688054Z $ + */ + #include #include #include #include +#include #include "AppHdr.h" #include "branch.h" @@ -41,19 +49,6 @@ const char *map_section_name(int msect) return map_section_names[msect]; } -template -void scramble(V &v) -{ - V temp(v); - v.clear(); - while (!temp.empty()) - { - int i = random2(temp.size()); - v.push_back(temp[i]); - temp.erase(temp.begin() + i); - } -} - // Returns true if s contains tag 'tag', and strips out tag from s. bool strip_tag(std::string &s, const std::string &tag) { @@ -792,7 +787,7 @@ void map_lines::nsubst(nsubst_spec &spec) while ((pos = lines[y].find(spec.key, pos)) != std::string::npos) positions.push_back(coord_def(pos++, y)); } - scramble(positions); + std::random_shuffle(positions.begin(), positions.end(), random2); int pcount = 0; const int psize = positions.size(); @@ -824,17 +819,8 @@ int map_lines::apply_nsubst(std::vector &pos, std::string map_lines::block_shuffle(const std::string &s) { std::vector segs = split_string("/", s); - - std::vector shuffled; - for (int i = 0, size = segs.size(); i < size; ++i) - { - const int sel = random2(segs.size()); - - shuffled.push_back( segs[ sel ] ); - segs.erase( segs.begin() + sel ); - } - - return comma_separated_line(shuffled.begin(), shuffled.end(), "/", "/"); + std::random_shuffle(segs.begin(), segs.end(), random2); + return comma_separated_line(segs.begin(), segs.end(), "/", "/"); } std::string map_lines::shuffle(std::string s) -- cgit v1.2.3-54-g00ecf