summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/util/levcomp.ypp
blob: d5b0bb2c7f4146710f191bbb4cf029b56e89c177 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
%{

#include "AppHdr.h"
#include "libutil.h"
#include "levcomp.h"

int yylex();

extern int yylineno;

void yyerror(const char *e)
{
    fprintf(stderr, "%s:%d: %s\n", lc_desfile.c_str(), yylineno, e);
    // Bail bail bail.
    exit(1);
}

%}

%union
{
    int i;
    const char *text;
}

%token <i>      BRANCHDEF BRANCH DESC DEFAULT
%token <i>      DEFAULT_DEPTH SYMBOL TAGS
%token <i>      NAME DEPTH ORIENT PLACE CHANCE FLAGS MONS
%token <i>      ROOT_DEPTH ENTRY_MSG EXIT_MSG
%token <i>      ROCK_COLOUR FLOOR_COLOUR
%token <i>      ENCOMPASS FLOAT 
%token <i>      NORTH EAST SOUTH WEST
%token <i>      NORTHEAST SOUTHEAST SOUTHWEST NORTHWEST

%token <i>      LEVEL END PVAULT PMINIVAULT MONSTERS ENDMONSTERS

%token <i>      CHARACTER

%token <i>      NO_HMIRROR NO_VMIRROR NO_ROTATE

%token <i>      PANDEMONIC 
%token <i>      DASH COMMA QUOTE OPAREN CPAREN
%token <i>      INTEGER

%type  <i>      orient_name flagname

%token <text>   STRING MAP_LINE MONSTER_NAME
%token <text>   IDENTIFIER

%%

file            : definitions { }
                ;

definitions     : /* empty */               {}
                | definition definitions    {}
                ;

definition      : def       {}
                | level     {}
                ;

def             : defdepth
                ;

defdepth        : DEFAULT_DEPTH depth_range
                {
                    lc_default_depth = lc_range;
                }
                ;

level           : name metalines map_def metalines
                {
                    if (lc_map.orient == MAP_FLOAT
                        || lc_map.is_minivault())
                    {
                        if (lc_map.map.width() > GXM - MAPGEN_BORDER * 2
                            || lc_map.map.height() > GYM - MAPGEN_BORDER * 2)
                        {
                            char buf[300];
                            snprintf(buf, sizeof buf, 
                                 "%s is too big: %dx%d - max %dx%d",
                                 lc_map.is_minivault()? "Minivault" : "Float",
                                 lc_map.map.width(), lc_map.map.height(),
                                 GXM - MAPGEN_BORDER * 2,
                                 GYM - MAPGEN_BORDER * 2);
                            yyerror(buf);
                        }
                    }
                    else
                    {
                        if (lc_map.map.width() > GXM
                            || lc_map.map.height() > GYM)
                        {
                            char buf[300];
                            snprintf(buf, sizeof buf, 
                                 "Map is too big: %dx%d - max %dx%d",
                                 lc_map.map.width(), lc_map.map.height(),
                                 GXM, GYM);
                            yyerror(buf);
                        }
                    }

                    if (lc_map.map.height() == 0)
                        yyerror("Must define map.");

                    add_parsed_map( lc_map );
                }
                ;

name            : NAME STRING
                {
                    lc_map.init();
                    lc_map.depth = lc_default_depth;
                    lc_map.name = $2;
                }
                ;

metalines       : /* no metadata */
                | metaline metalines
                ;

metaline        : place
                | depth
                | chance
                | orientation
                | flags
                | mons
                | symbol
                | tags
                ;

tags            : TAGS tagstrings {}
                ;

tagstrings      : /* empty */
                | STRING tagstrings
                {
                    lc_map.tags += " ";
                    lc_map.tags += $1;
                    lc_map.tags += " ";
                }
                ;

symbol          : SYMBOL {}
                | SYMBOL STRING
                {
                    lc_map.random_symbols = $2;
                }
                ;

mons            : MONS {}
                | MONS mnames {}
                ;

mnames          : mname COMMA mnames
                | mname
                ;

mname           : MONSTER_NAME
                {
                    bool recognised = lc_map.mons.add_mons($1);
                    if (!recognised)
                    {
                        char buf[300];
                        snprintf(buf, sizeof buf, "unknown monster '%s'",
                                 $1);
                        yyerror(buf);
                    }
                }
                ;

place           : PLACE STRING
                {
                    lc_map.place = $2;
                }
                ;

depth           : DEPTH {}
                | DEPTH depth_range
                {
                    lc_map.depth = lc_range;
                }
                ;

depth_range     : INTEGER DASH INTEGER
                {
                    lc_range.set($1, $3);
                }

                | INTEGER
                {
                    lc_range.set($1);
                }
                ;

chance          : CHANCE INTEGER
                {
                    lc_map.chance = $2;
                }
                ;

orientation     : ORIENT {}
                | ORIENT orient_name
                {
                    lc_map.orient = (map_section_type) $2;
                }
                ;

orient_name     : ENCOMPASS     { $$ = MAP_ENCOMPASS; }
                | NORTH         { $$ = MAP_NORTH; }
                | EAST          { $$ = MAP_EAST; }
                | SOUTH         { $$ = MAP_SOUTH; }
                | WEST          { $$ = MAP_WEST; }
                | NORTHEAST     { $$ = MAP_NORTHEAST; }
                | SOUTHEAST     { $$ = MAP_SOUTHEAST; }
                | SOUTHWEST     { $$ = MAP_SOUTHWEST; }
                | NORTHWEST     { $$ = MAP_NORTHWEST; }
                | FLOAT         { $$ = MAP_FLOAT; }
                ;

flags           : FLAGS flagnames {}
                ;

flagnames       : /* empty */
                | flagname flagnames
                {
                    switch ($1) {
                    case NO_HMIRROR:
                        lc_map.flags &= ~MAPF_MIRROR_HORIZONTAL;
                        break;
                    case NO_VMIRROR:
                        lc_map.flags &= ~MAPF_MIRROR_VERTICAL;
                        break;
                    case NO_ROTATE:
                        lc_map.flags &= ~MAPF_ROTATE;
                        break;
                    }
                }
                ;

flagname        : NO_HMIRROR    { $$ = NO_HMIRROR; }
                | NO_VMIRROR    { $$ = NO_VMIRROR; }
                | NO_ROTATE     { $$ = NO_ROTATE;  }
                ;

map_def         : map_lines
                ;

map_lines       : map_line
                | map_line map_lines
                ;

map_line        : MAP_LINE
                {
                    lc_map.map.add_line($1);
                }
                ;

%%