summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/util/levcomp.ypp
diff options
context:
space:
mode:
authorDarshan Shaligram <dshaligram@users.sourceforge.net>2010-12-24 19:20:59 +0530
committerDarshan Shaligram <dshaligram@users.sourceforge.net>2010-12-24 22:10:37 +0530
commit9e6e6919463bcd6b30c34c430b3ac505c7330915 (patch)
treeb5cf86f90b9d7e22e18c72ee014338aa6d2c22a8 /crawl-ref/source/util/levcomp.ypp
parent6a36820c5d0be2b485dcb838e4b1f7ed44e0c734 (diff)
downloadcrawl-ref-9e6e6919463bcd6b30c34c430b3ac505c7330915.tar.gz
crawl-ref-9e6e6919463bcd6b30c34c430b3ac505c7330915.zip
Allow maps to specify different CHANCE and WEIGHT for different depth ranges (Zaba).
Diffstat (limited to 'crawl-ref/source/util/levcomp.ypp')
-rw-r--r--crawl-ref/source/util/levcomp.ypp92
1 files changed, 56 insertions, 36 deletions
diff --git a/crawl-ref/source/util/levcomp.ypp b/crawl-ref/source/util/levcomp.ypp
index 0bc3391be4..46bfd530f5 100644
--- a/crawl-ref/source/util/levcomp.ypp
+++ b/crawl-ref/source/util/levcomp.ypp
@@ -28,26 +28,14 @@ void yyerror(const char *e)
end(1);
}
-level_range set_range(const char *s, int start, int end)
-{
- try
- {
- lc_range.set(s, start, end);
- }
- catch (const std::string &err)
- {
- yyerror(err.c_str());
- }
- return (lc_range);
-}
-
%}
%union
{
int i;
+ double f;
const char *text;
- raw_range range;
+ map_chance_pair chance;
}
/* Two harmless shift/reduce conflicts */
@@ -59,10 +47,13 @@ level_range set_range(const char *s, int start, int end)
%token <i> LFLOORCOL LROCKCOL LFLOORTILE LROCKTILE FTILE RTILE TILE
%token <i> SUBVAULT FHEIGHT DESC
-%token <i> COMMA COLON PERC INTEGER CHARACTER
+%token <i> COMMA COLON PERC DASH CHARACTER
+%token <f> NUMBER
%token <text> STRING MAP_LINE MONSTER_NAME ITEM_INFO
%token <text> LUA_LINE
+%type <chance> chance_num
+%type <i> chance_roll
%%
@@ -111,6 +102,7 @@ level : name map_specs
std::string err =
lc_map.validate_map_def(lc_default_depths);
+ dump_map(lc_map);
if (!err.empty())
yyerror(err.c_str());
add_parsed_map(lc_map);
@@ -592,43 +584,71 @@ depth : DEPTH {}
}
;
-chance : CHANCE INTEGER COLON INTEGER PERC
+chance : CHANCE chance_specifiers { }
+ | CHANCE { }
+ ;
+
+chance_specifiers : chance_specifiers COMMA chance_specifier
+ | chance_specifier;
+
+chance_roll : NUMBER PERC
{
- lc_map.main.add(
- yylineno,
- make_stringf("chance(%d, %d)", $2, $4 * 100));
+ $$ = $1 * 100;
}
- |
- CHANCE INTEGER COLON INTEGER
+ | NUMBER
{
- lc_map.main.add(
- yylineno,
- make_stringf("chance(%d, %d)", $2, $4));
+ $$ = $1;
}
- |
- CHANCE INTEGER PERC
+
+chance_num : NUMBER COLON chance_roll
{
- lc_map.main.add(
- yylineno,
- make_stringf("chance(%d)", $2 * 100));
+ $$.priority = $1;
+ $$.chance = $3;
}
- |
- CHANCE INTEGER
+ | chance_roll
{
- lc_map.main.add(
- yylineno,
- make_stringf("chance(%d)", $2));
+ $$.priority = DEFAULT_CHANCE_PRIORITY;
+ $$.chance = $1;
}
;
-weight : WEIGHT INTEGER
+chance_specifier : chance_num STRING
+ {
+ lc_map.main.add(
+ yylineno,
+ make_stringf("depth_chance(\"%s\", %d, %d)",
+ quote_lua_string($2).c_str(),
+ $1.priority, $1.chance));
+ }
+ | chance_num
{
lc_map.main.add(
yylineno,
- make_stringf("weight(%d)", $2));
+ make_stringf("chance(%d, %d)",
+ $1.priority, $1.chance));
}
;
+weight : WEIGHT weight_specifiers;
+
+weight_specifiers : weight_specifiers COMMA weight_specifier
+ | weight_specifier;
+
+weight_specifier : NUMBER STRING
+ {
+ lc_map.main.add(
+ yylineno,
+ make_stringf("depth_weight(\"%s\", %d)",
+ quote_lua_string($2), $1));
+ }
+ | NUMBER
+ {
+ lc_map.main.add(
+ yylineno,
+ make_stringf("weight(%d)", $1));
+ }
+ ;
+
orientation : ORIENT {}
| ORIENT STRING
{