… | |
… | |
23 | |
23 | |
24 | /* The onion room generator: |
24 | /* The onion room generator: |
25 | Onion rooms are like this: |
25 | Onion rooms are like this: |
26 | |
26 | |
27 | char **map_gen_spiral(int xsize, int ysize, int option); |
27 | char **map_gen_spiral(int xsize, int ysize, int option); |
28 | |
|
|
29 | |
|
|
30 | */ |
28 | */ |
|
|
29 | |
31 | #include <global.h> |
30 | #include <global.h> |
32 | #include <random_map.h> |
31 | #include <random_map.h> |
33 | |
32 | |
34 | #define RANDOM_OPTIONS 0 /* Pick random options below */ |
33 | #define RANDOM_OPTIONS 0 /* Pick random options below */ |
35 | #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ |
34 | #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ |
… | |
… | |
49 | |
48 | |
50 | #define MAX_FINE .454545 |
49 | #define MAX_FINE .454545 |
51 | |
50 | |
52 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
51 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
53 | |
52 | |
54 | Maze |
53 | void |
55 | map_gen_spiral (int xsize, int ysize, int option) |
54 | map_gen_spiral (Layout maze, int option) |
56 | { |
55 | { |
57 | int i, j; |
56 | int i, j; |
58 | float parm = 0; |
57 | float parm = 0; |
59 | float x = 0, y = 0; |
58 | float x = 0, y = 0; |
60 | int ic, jc; |
59 | int ic, jc; |
61 | float SizeX, SizeY; |
60 | float SizeX, SizeY; |
62 | float xscale, yscale; |
61 | float xscale, yscale; |
63 | |
62 | |
64 | Maze maze (xsize, ysize); |
|
|
65 | |
|
|
66 | /* slightly easier to fill and then cut */ |
63 | /* slightly easier to fill and then cut */ |
67 | for (i = 0; i < xsize; i++) |
64 | maze->clear ('#'); |
68 | for (j = 0; j < ysize; j++) |
65 | |
69 | maze[i][j] = '#'; |
66 | int xsize = maze->w; |
|
|
67 | int ysize = maze->h; |
70 | |
68 | |
71 | ic = xsize / 2; |
69 | ic = xsize / 2; |
72 | jc = ysize / 2; |
70 | jc = ysize / 2; |
73 | SizeX = xsize / 2 - 2; |
71 | SizeX = xsize / 2 - 2; |
74 | SizeY = ysize / 2 - 2; |
72 | SizeY = ysize / 2 - 2; |
75 | |
73 | |
76 | /* select random options if necessary */ |
74 | /* select random options if necessary */ |
77 | if (option == 0) |
75 | if (option == 0) |
78 | option = rndm (MAX_SPIRAL_OPT); |
76 | option = rmg_rndm (MAX_SPIRAL_OPT); |
79 | |
77 | |
80 | /* the order in which these are evaluated matters */ |
78 | /* the order in which these are evaluated matters */ |
81 | |
79 | |
82 | /* the following two are mutually exclusive. |
80 | /* the following two are mutually exclusive. |
83 | pick one if they're both set. */ |
81 | pick one if they're both set. */ |
84 | if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL)) |
82 | if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL)) |
85 | { |
83 | { |
86 | /* unset REGULAR_SPIRAL half the time */ |
84 | /* unset REGULAR_SPIRAL half the time */ |
87 | if (rndm (2) && (option & REGULAR_SPIRAL)) |
85 | if (rmg_rndm (2) && (option & REGULAR_SPIRAL)) |
88 | option -= REGULAR_SPIRAL; |
86 | option -= REGULAR_SPIRAL; |
89 | else |
87 | else |
90 | option -= FIT_SPIRAL; |
88 | option -= FIT_SPIRAL; |
91 | } |
89 | } |
92 | |
90 | |
93 | xscale = yscale = MAX_FINE; /* fine spiral */ |
91 | xscale = yscale = MAX_FINE; /* fine spiral */ |
94 | |
92 | |
95 | /* choose the spiral pitch */ |
93 | /* choose the spiral pitch */ |
96 | if (!(option & FINE_SPIRAL)) |
94 | if (!(option & FINE_SPIRAL)) |
97 | { |
95 | { |
98 | float pitch = (rndm (5)) / 10. + 10. / 22.; |
96 | float pitch = (rmg_rndm (5)) / 10. + 10. / 22.; |
99 | |
97 | |
100 | xscale = yscale = pitch; |
98 | xscale = yscale = pitch; |
101 | } |
99 | } |
102 | |
100 | |
103 | if ((option & FIT_SPIRAL) && (xsize != ysize)) |
101 | if ((option & FIT_SPIRAL) && (xsize != ysize)) |
… | |
… | |
120 | { |
118 | { |
121 | x = parm * cos (parm) * xscale; |
119 | x = parm * cos (parm) * xscale; |
122 | y = parm * sin (parm) * yscale; |
120 | y = parm * sin (parm) * yscale; |
123 | maze[int (ic + x)][int (jc + y)] = '\0'; |
121 | maze[int (ic + x)][int (jc + y)] = '\0'; |
124 | parm += 0.01; |
122 | parm += 0.01; |
125 | }; |
123 | } |
126 | |
124 | |
127 | maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<'; |
125 | maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<'; |
128 | |
126 | |
129 | /* cut out the center in a 2x2 and place the center and downexit */ |
127 | /* cut out the center in a 2x2 and place the center and downexit */ |
130 | maze[ic][jc + 1] = '>'; |
128 | maze[ic][jc + 1] = '>'; |
131 | maze[ic][jc] = 'C'; |
129 | maze[ic][jc] = 'C'; |
132 | |
|
|
133 | return maze; |
|
|
134 | } |
130 | } |
135 | |
131 | |
136 | /* the following function connects disjoint spirals which may |
132 | /* the following function connects disjoint spirals which may |
137 | result from the symmetrization process. */ |
133 | result from the symmetrization process. */ |
138 | void |
134 | void |
139 | connect_spirals (int xsize, int ysize, int sym, char **layout) |
135 | connect_spirals (int xsize, int ysize, int sym, char **layout) |
140 | { |
136 | { |
141 | |
|
|
142 | int i, j, ic = xsize / 2, jc = ysize / 2; |
137 | int i, j, ic = xsize / 2, jc = ysize / 2; |
143 | |
138 | |
144 | if (sym == SYMMETRY_X) |
139 | if (sym == SYMMETRY_X) |
145 | { |
140 | { |
146 | layout[ic][jc] = 0; |
141 | layout[ic][jc] = 0; |
|
|
142 | |
147 | /* go left from map center */ |
143 | /* go left from map center */ |
148 | for (i = ic - 1, j = jc; i > 0 && layout[i][j] == '#'; i--) |
144 | for (i = ic - 1, j = jc; i > 0 && layout[i][j] == '#'; i--) |
149 | layout[i][j] = 0; |
145 | layout[i][j] = 0; |
|
|
146 | |
150 | /* go right */ |
147 | /* go right */ |
151 | for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++) |
148 | for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++) |
152 | layout[i][j] = 0; |
149 | layout[i][j] = 0; |
153 | } |
150 | } |
154 | |
151 | |
155 | if (sym == SYMMETRY_Y) |
152 | if (sym == SYMMETRY_Y) |
156 | { |
153 | { |
157 | |
|
|
158 | layout[ic][jc] = 0; |
154 | layout[ic][jc] = 0; |
|
|
155 | |
159 | /* go up */ |
156 | /* go up */ |
160 | for (i = ic, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
157 | for (i = ic, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
161 | layout[i][j] = 0; |
158 | layout[i][j] = 0; |
|
|
159 | |
162 | /* go down */ |
160 | /* go down */ |
163 | for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
161 | for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
164 | layout[i][j] = 0; |
162 | layout[i][j] = 0; |
165 | } |
163 | } |
166 | |
164 | |
… | |
… | |
169 | /* go left from map center */ |
167 | /* go left from map center */ |
170 | layout[ic][jc / 2] = 0; |
168 | layout[ic][jc / 2] = 0; |
171 | layout[ic / 2][jc] = 0; |
169 | layout[ic / 2][jc] = 0; |
172 | layout[ic][jc / 2 + jc] = 0; |
170 | layout[ic][jc / 2 + jc] = 0; |
173 | layout[ic / 2 + ic][jc] = 0; |
171 | layout[ic / 2 + ic][jc] = 0; |
|
|
172 | |
174 | for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--) |
173 | for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--) |
175 | { |
174 | { |
176 | layout[i][j + jc] = 0; |
175 | layout[i][j + jc] = 0; |
177 | layout[i][j] = 0; |
176 | layout[i][j] = 0; |
178 | } |
177 | } |
|
|
178 | |
179 | /* go right */ |
179 | /* go right */ |
180 | for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++) |
180 | for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++) |
181 | { |
181 | { |
182 | layout[i][j + jc] = 0; |
182 | layout[i][j + jc] = 0; |
183 | layout[i][j] = 0; |
183 | layout[i][j] = 0; |
184 | } |
184 | } |
|
|
185 | |
185 | /* go up */ |
186 | /* go up */ |
186 | for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
187 | for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
187 | { |
188 | { |
188 | layout[i][j] = 0; |
189 | layout[i][j] = 0; |
189 | layout[i + ic][j] = 0; |
190 | layout[i + ic][j] = 0; |
190 | } |
191 | } |
|
|
192 | |
191 | /* go down */ |
193 | /* go down */ |
192 | for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
194 | for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
193 | { |
195 | { |
194 | layout[i][j] = 0; |
196 | layout[i][j] = 0; |
195 | layout[i + ic][j] = 0; |
197 | layout[i + ic][j] = 0; |
… | |
… | |
213 | j = 0; |
215 | j = 0; |
214 | } |
216 | } |
215 | } |
217 | } |
216 | } |
218 | } |
217 | } |
219 | } |
|
|
220 | |