summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-27 08:50:19 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-27 08:50:19 +0000
commit9cfcde86bb92957d658e51d1955777f8db73cff1 (patch)
tree6510f2e31ac973c2a4479037b295c588abc96638
parentcf748a307df35e7086db9ecc246a509a9312e708 (diff)
downloadcrawl-ref-9cfcde86bb92957d658e51d1955777f8db73cff1.tar.gz
crawl-ref-9cfcde86bb92957d658e51d1955777f8db73cff1.zip
Allow SHUFFLE: and SUBST: to be mixed freely; they will be applied in order of
declaration (used to be all shuffles first, then all substs). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1106 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/dat/splev.des8
-rw-r--r--crawl-ref/source/dat/vaults.des8
-rw-r--r--crawl-ref/source/mapdef.cc114
-rw-r--r--crawl-ref/source/mapdef.h46
4 files changed, 139 insertions, 37 deletions
diff --git a/crawl-ref/source/dat/splev.des b/crawl-ref/source/dat/splev.des
index 9ffc48b165..1b3df123bc 100644
--- a/crawl-ref/source/dat/splev.des
+++ b/crawl-ref/source/dat/splev.des
@@ -168,8 +168,8 @@
# SHUFFLE: 12/3w (i.e. list of slash-separated blocks of same size)
# will either do nothing or swap all "1" with "3" and then also
# swap "2" with "w" everywhere.
-# Several SHUFFLE: lines can be used, and the shuffles will be applied in
-# order.
+# Several SHUFFLE: lines can be used, and mixed with SUBST:, and the shuffles
+# and substitutions will be applied in order.
#
# SUBST:
# ------
@@ -194,8 +194,8 @@
#
# SUBST: w = wW
#
-# Multiple SUBST: lines can be used, and will be applied in order.
-# Substitutions are performed after any declared shuffles.
+# Multiple SUBST: lines can be used, and mixed with SHUFFLE:, and will be
+# applied in order.
#
# KFEAT:
# -----
diff --git a/crawl-ref/source/dat/vaults.des b/crawl-ref/source/dat/vaults.des
index 8a34132890..748e9130fd 100644
--- a/crawl-ref/source/dat/vaults.des
+++ b/crawl-ref/source/dat/vaults.des
@@ -168,8 +168,8 @@
# SHUFFLE: 12/3w (i.e. list of slash-separated blocks of same size)
# will either do nothing or swap all "1" with "3" and then also
# swap "2" with "w" everywhere.
-# Several SHUFFLE: lines can be used, and the shuffles will be applied in
-# order.
+# Several SHUFFLE: lines can be used, and mixed with SUBST:, and the shuffles
+# and substitutions will be applied in order.
#
# SUBST:
# ------
@@ -194,8 +194,8 @@
#
# SUBST: w = wW
#
-# Multiple SUBST: lines can be used, and will be applied in order.
-# Substitutions are performed after any declared shuffles.
+# Multiple SUBST: lines can be used, and mixed with SHUFFLE:, and will be
+# applied in order.
#
# KFEAT:
# -----
diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc
index b121b361fa..1989cd704d 100644
--- a/crawl-ref/source/mapdef.cc
+++ b/crawl-ref/source/mapdef.cc
@@ -83,6 +83,11 @@ int strip_number_tag(std::string &s, const std::string &tagprefix)
return atoi(argument.c_str());
}
+static int find_weight(std::string &s)
+{
+ return strip_number_tag(s, "weight:");
+}
+
static std::string split_key_item(const std::string &s,
int *key,
int *separator,
@@ -150,16 +155,62 @@ int level_range::span() const
return (deepest - shallowest);
}
-///////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+// map_transformer
+
+map_transformer::~map_transformer()
+{
+}
+
+////////////////////////////////////////////////////////////////////////
// map_lines
-//
map_lines::map_lines()
- : lines(), map_width(0), solid_north(false), solid_east(false),
- solid_south(false), solid_west(false), solid_checked(false)
+ : transforms(), lines(), map_width(0), solid_north(false),
+ solid_east(false), solid_south(false), solid_west(false),
+ solid_checked(false)
{
}
+map_lines::map_lines(const map_lines &map)
+{
+ init_from(map);
+}
+
+map_lines &map_lines::operator = (const map_lines &map)
+{
+ if (this != &map)
+ init_from(map);
+ return (*this);
+}
+
+map_lines::~map_lines()
+{
+ release_transforms();
+}
+
+void map_lines::init_from(const map_lines &map)
+{
+ release_transforms();
+ lines = map.lines;
+ map_width = map.map_width;
+ solid_north = map.solid_north;
+ solid_east = map.solid_east;
+ solid_south = map.solid_south;
+ solid_west = map.solid_west;
+ solid_checked = map.solid_checked;
+
+ for (int i = 0, size = map.transforms.size(); i < size; ++i)
+ transforms.push_back( map.transforms[i]->clone() );
+}
+
+void map_lines::release_transforms()
+{
+ for (int i = 0, size = transforms.size(); i < size; ++i)
+ delete transforms[i];
+ transforms.clear();
+}
+
const std::vector<std::string> &map_lines::get_lines() const
{
return (lines);
@@ -252,8 +303,7 @@ std::string map_lines::add_subst(const std::string &sub)
if (!err.empty())
return (err);
- substitutions.push_back(
- subst_spec( key, sep == ':', repl ) );
+ transforms.push_back( new subst_spec( key, sep == ':', repl ) );
return ("");
}
@@ -264,7 +314,7 @@ std::string map_lines::add_shuffle(const std::string &raws)
const std::string err = check_shuffle(s);
if (err.empty())
- shuffles.push_back(s);
+ transforms.push_back( new shuffle_spec(s) );
return (err);
}
@@ -336,8 +386,7 @@ bool map_lines::solid_borders(map_section_type border)
void map_lines::clear()
{
- substitutions.clear();
- shuffles.clear();
+ release_transforms();
lines.clear();
map_width = 0;
}
@@ -349,13 +398,10 @@ void map_lines::subst(std::string &s, subst_spec &spec)
s[pos++] = spec.value();
}
-void map_lines::subst()
+void map_lines::subst(subst_spec &spec)
{
- for (int i = 0, size = substitutions.size(); i < size; ++i)
- {
- for (int y = 0, ysize = lines.size(); y < ysize; ++y)
- subst(lines[y], substitutions[i]);
- }
+ for (int y = 0, ysize = lines.size(); y < ysize; ++y)
+ subst(lines[y], spec);
}
std::string map_lines::block_shuffle(const std::string &s)
@@ -414,10 +460,10 @@ void map_lines::resolve_shuffle(const std::string &shufflage)
}
}
-void map_lines::resolve_shuffles()
+void map_lines::apply_transforms()
{
- for (int i = 0, size = shuffles.size(); i < size; ++i)
- resolve_shuffle( shuffles[i] );
+ for (int i = 0, size = transforms.size(); i < size; ++i)
+ transforms[i]->apply_transform(*this);
}
void map_lines::normalise(char fillch)
@@ -729,8 +775,7 @@ void map_def::normalise()
void map_def::resolve()
{
- map.resolve_shuffles();
- map.subst();
+ map.apply_transforms();
}
void map_def::fixup()
@@ -856,7 +901,7 @@ mons_list::mons_spec_slot mons_list::parse_mons_spec(std::string spec)
for (int i = 0, ssize = specs.size(); i < ssize; ++i)
{
std::string s = specs[i];
- int weight = strip_number_tag(s, "weight:");
+ int weight = find_weight(s);
if (weight == TAG_UNFOUND || weight <= 0)
weight = 10;
@@ -1013,7 +1058,7 @@ item_spec item_list::parse_single_spec(std::string s)
item_spec result;
// If there's a colon, this must be a generation weight.
- int weight = strip_number_tag(s, "weight:");
+ int weight = find_weight(s);
if (weight != TAG_UNFOUND)
{
result.genweight = weight;
@@ -1171,6 +1216,29 @@ int subst_spec::value()
return (chosen);
}
+void subst_spec::apply_transform(map_lines &map)
+{
+ map.subst(*this);
+}
+
+map_transformer *subst_spec::clone() const
+{
+ return new subst_spec(*this);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// shuffle_spec
+
+void shuffle_spec::apply_transform(map_lines &map)
+{
+ map.resolve_shuffle(shuffle);
+}
+
+map_transformer *shuffle_spec::clone() const
+{
+ return new shuffle_spec(*this);
+}
+
//////////////////////////////////////////////////////////////////////////
// keyed_mapspec
@@ -1237,7 +1305,7 @@ feature_spec keyed_mapspec::parse_shop(std::string s, int weight)
feature_spec_list keyed_mapspec::parse_feature(const std::string &str)
{
std::string s = str;
- int weight = strip_number_tag(s, "weight:");
+ int weight = find_weight(s);
if (weight == TAG_UNFOUND || weight <= 0)
weight = 10;
trim_string(s);
diff --git a/crawl-ref/source/mapdef.h b/crawl-ref/source/mapdef.h
index 5c5ec9b810..c96d6df9bb 100644
--- a/crawl-ref/source/mapdef.h
+++ b/crawl-ref/source/mapdef.h
@@ -43,7 +43,16 @@ public:
typedef std::pair<int,int> glyph_weighted_replacement_t;
typedef std::vector<glyph_weighted_replacement_t> glyph_replacements_t;
-class subst_spec
+class map_lines;
+class map_transformer
+{
+public:
+ virtual ~map_transformer() = 0;
+ virtual void apply_transform(map_lines &map) = 0;
+ virtual map_transformer *clone() const = 0;
+};
+
+class subst_spec : public map_transformer
{
public:
subst_spec(int torepl, bool fix, const glyph_replacements_t &repls);
@@ -54,6 +63,9 @@ public:
}
int value();
+
+ void apply_transform(map_lines &map);
+ map_transformer *clone() const;
private:
int foo; // The thing to replace.
@@ -63,10 +75,27 @@ private:
glyph_replacements_t repl;
};
+struct shuffle_spec : public map_transformer
+{
+ std::string shuffle;
+
+ shuffle_spec(const std::string &spec)
+ : shuffle(spec)
+ {
+ }
+
+ void apply_transform(map_lines &map);
+ map_transformer *clone() const;
+};
+
class map_lines
{
public:
map_lines();
+ map_lines(const map_lines &);
+ ~map_lines();
+
+ map_lines &operator = (const map_lines &);
void add_line(const std::string &s);
std::string add_subst(const std::string &st);
@@ -81,9 +110,8 @@ public:
bool is_solid(int gly) const;
bool solid_borders(map_section_type border);
-
- void subst();
- void resolve_shuffles();
+
+ void apply_transforms();
// Make all lines the same length.
void normalise(char fillc = 'x');
@@ -98,8 +126,12 @@ public:
const std::vector<std::string> &get_lines() const;
private:
+ void init_from(const map_lines &map);
+ void release_transforms();
+
void resolve_shuffle(const std::string &shuffle);
void subst(std::string &s, subst_spec &spec);
+ void subst(subst_spec &);
void check_borders();
std::string shuffle(std::string s);
std::string block_shuffle(const std::string &s);
@@ -109,9 +141,11 @@ private:
std::string parse_glyph_replacements(std::string s,
glyph_replacements_t &gly);
+ friend class subst_spec;
+ friend class shuffle_spec;
+
private:
- std::vector<subst_spec> substitutions;
- std::vector<std::string> shuffles;
+ std::vector<map_transformer *> transforms;
std::vector<std::string> lines;
int map_width;
bool solid_north, solid_east, solid_south, solid_west;