ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/reader.l
Revision: 1.4
Committed: Sat Dec 30 18:45:28 2006 UTC (17 years, 4 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
State: FILE REMOVED
Log Message:
random maps are nphard

File Contents

# Content
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 1994 Mark Wedel
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The author can be reached via e-mail to mark@pyramid.com
22 */
23
24 %{
25
26 #include <global.h>
27 #include <loader.h>
28 #include <random_map.h>
29
30 #define LO_REPEAT 0
31 #define LO_LINEMODE 1
32 #define LO_NEWFILE 2
33 #define LO_NOREAD 3
34
35 int yyerror(char *s)
36 {
37 LOG(llevError, "%s: %s\n", s, yytext);
38 return -1;
39 }
40
41 #define YY_DECL int rmap_lex_read(RMParms *RP)
42
43 static char *rmap_yval();
44
45 static int rmap_lex_error;
46
47
48 #define IVAL atoi(rmap_yval())
49 #define FVAL atof(rmap_yval())
50
51 %}
52
53
54
55 S [ \t]+.+
56 WS [ \t]*
57
58 %x MESSAGE
59
60 /* Don't have to link with -lfl with this */
61 %option noyywrap
62
63 /* need yy_push_state, yy_pop_state */
64 %option stack
65
66 %%
67
68 %{
69 /* Declare some local variables */
70
71 rmap_lex_error=0;
72
73 %}
74
75
76
77
78 ^wallstyle{S} strcpy(RP->wallstyle,rmap_yval());
79 ^floorstyle{S} strcpy(RP->floorstyle,rmap_yval());
80 ^monsterstyle{S} strcpy(RP->monsterstyle,rmap_yval());
81 ^treasurestyle{S} strcpy(RP->treasurestyle,rmap_yval());
82 ^layoutstyle{S} strcpy(RP->layoutstyle,rmap_yval());
83 ^doorstyle{S} strcpy(RP->doorstyle,rmap_yval());
84 ^decorstyle{S} strcpy(RP->decorstyle,rmap_yval());
85 ^xsize{S} RP->Xsize = IVAL;
86 ^ysize{S} RP->Ysize = IVAL;
87 ^expand2x{S} RP->expand2x = IVAL;
88 ^layoutoptions1{S} RP->layoutoptions1 = IVAL;
89 ^layoutoptions2{S} RP->layoutoptions2 = IVAL;
90 ^layoutoptions3{S} RP->layoutoptions3 = IVAL;
91 ^symmetry{S} RP->symmetry = IVAL;
92 ^difficulty{S} RP->difficulty = IVAL;
93 ^difficulty_increase{S} RP->difficulty_increase = FVAL;
94 ^decoroptions{S} RP->decoroptions = IVAL;
95 ^exitstyle{S} strcpy(RP->exitstyle,rmap_yval());
96 ^dungeon_level{S} RP->dungeon_level = IVAL;
97 ^dungeon_depth{S} RP->dungeon_depth = IVAL;
98 ^final_map{S} strcpy(RP->final_map,rmap_yval());
99 ^orientation{S} RP-> orientation = IVAL;
100 ^origin_x{S} RP->origin_x = IVAL;
101 ^origin_y{S} RP-> origin_y = IVAL;
102 ^origin_map{S} strcpy(RP->origin_map,rmap_yval());
103 ^random_seed{S} RP->random_seed = IVAL;
104 ^treasureoptions{S} RP->treasureoptions = IVAL;
105 ^exit_on_final_map{S} strcpy(RP->exit_on_final_map,rmap_yval());
106
107 <*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */}
108 #.*\n {}
109
110 <<EOF>> {/* If we got an error, return the error. Otherwise, return that we got EOF */
111 if (rmap_lex_error!=0) return rmap_lex_error; else return LL_EOF;}
112 .* { yyerror( "Unrecognized string"); rmap_lex_error= -1; }
113 %%
114
115 /*int yyerror(char *s)
116 {
117 return -1;
118 }
119 */
120
121 /* Our save file syntax is very simple, so we can use a very simple
122 * processing mechanism here instead using something like bison
123 * This skips over the space and returns the value, or "" if no value
124 * is found.
125 */
126 static char *rmap_yval()
127 {
128 static char *em="";
129 char *cp;
130
131 cp=strchr(yytext,' ');
132 if (cp) return cp+1;
133 else return em;
134 }
135
136
137
138
139 int load_parameters(FILE *fp, int bufstate,RMParms *RP) {
140 int retval;
141 char inbuf[MAX_BUF];
142
143 if (bufstate==LO_NEWFILE || bufstate==LO_NOREAD) {
144 yy_delete_buffer(YY_CURRENT_BUFFER);
145 yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
146 if (bufstate==LO_NOREAD) return LL_NORMAL;
147 }
148 if (bufstate==LO_LINEMODE) {
149 YY_BUFFER_STATE yybufstate;
150 while (fgets(inbuf, MAX_BUF-3, fp)) {
151 yybufstate=yy_scan_string(inbuf);
152 retval=rmap_lex_read(RP);
153 yy_delete_buffer(yybufstate);
154 if (retval==LL_NORMAL) return retval;
155 }
156 return LL_EOF;
157 }
158
159 retval=rmap_lex_read(RP);
160 /* LOG(llevDebug," load completed, object=%s\n",op->name);*/
161 return retval;
162 }
163
164
165 /* This takes a buffer, scans it for variables, and sets those variables
166 * as appropriate in op.
167 *
168 * This function appears to be used in only 2 places - in crossedit to
169 * override values and in c_wiz to mutate values.
170 */
171 int set_random_map_variable(RMParms *rp,const char *buf) {
172 YY_BUFFER_STATE yybufstate;
173 int retval;
174
175 yybufstate=yy_scan_string(buf);
176 retval=rmap_lex_read(rp);
177 yy_delete_buffer(yybufstate);
178 return retval;
179 }