1 | /* |
1 | /* |
2 | * static char *room_gen_onion_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * "$Id: room_gen_onion.C,v 1.2 2006/08/29 08:01:36 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | * the terms of the Affero GNU General Public License as published by the |
|
|
10 | * Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | * option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the Affero GNU General Public License |
|
|
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
4 | */ |
23 | */ |
5 | |
|
|
6 | /* |
|
|
7 | CrossFire, A Multiplayer game for X-windows |
|
|
8 | |
|
|
9 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
|
|
10 | Copyright (C) 1992 Frank Tore Johansen |
|
|
11 | |
|
|
12 | This program is free software; you can redistribute it and/or modify |
|
|
13 | it under the terms of the GNU General Public License as published by |
|
|
14 | the Free Software Foundation; either version 2 of the License, or |
|
|
15 | (at your option) any later version. |
|
|
16 | |
|
|
17 | This program is distributed in the hope that it will be useful, |
|
|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20 | GNU General Public License for more details. |
|
|
21 | |
|
|
22 | You should have received a copy of the GNU General Public License |
|
|
23 | along with this program; if not, write to the Free Software |
|
|
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
25 | |
|
|
26 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
27 | */ |
|
|
28 | |
|
|
29 | |
24 | |
30 | /* The onion room generator: |
25 | /* The onion room generator: |
31 | Onion rooms are like this: |
26 | Onion rooms are like this: |
32 | |
27 | |
33 | char **map_gen_onion(int xsize, int ysize, int option, int layers); |
28 | char **map_gen_onion(int xsize, int ysize, int option, int layers); |
… | |
… | |
54 | |
49 | |
55 | */ |
50 | */ |
56 | |
51 | |
57 | |
52 | |
58 | #include <global.h> |
53 | #include <global.h> |
59 | #include <random_map.h> |
54 | #include <rmg.h> |
|
|
55 | #include <rproto.h> |
60 | |
56 | |
61 | #ifndef MIN |
|
|
62 | #define MIN(x,y) (((x)<(y))? (x):(y)) |
|
|
63 | #endif |
|
|
64 | void centered_onion(char **maze, int xsize, int ysize, int option, int layers); |
57 | static void centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
65 | void bottom_centered_onion(char **maze, int xsize, int ysize, int option, int layers); |
58 | static void bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
66 | void bottom_right_centered_onion(char **maze, int xsize, int ysize, int option, int layers); |
59 | static void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers); |
67 | |
60 | |
68 | |
|
|
69 | void draw_onion(char **maze,float *xlocations,float *ylocations,int layers); |
61 | static void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); |
70 | void make_doors(char **maze,float *xlocations,float *ylocations,int layers,int options); |
62 | static void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); |
71 | |
63 | |
72 | char **map_gen_onion(int xsize, int ysize, int option, int layers) { |
64 | void |
|
|
65 | map_gen_onion (layout &maze, int option, int layers) |
|
|
66 | { |
73 | int i,j; |
67 | int i, j; |
74 | |
68 | |
75 | /* allocate that array, set it up */ |
69 | int xsize = maze.w; |
76 | char **maze = (char **)calloc(sizeof(char*),xsize); |
70 | int ysize = maze.h; |
77 | for(i=0;i<xsize;i++) { |
71 | |
78 | maze[i] = (char *) calloc(sizeof(char),ysize); |
72 | maze.clear (); |
79 | } |
|
|
80 | |
73 | |
81 | /* pick some random options if option = 0 */ |
74 | /* pick some random options if option = 0 */ |
82 | if(option == 0) { |
75 | if (option == 0) |
83 | switch(RANDOM()%3) { |
76 | { |
|
|
77 | switch (rmg_rndm (3)) |
|
|
78 | { |
84 | case 0: |
79 | case 0: |
85 | option |= OPT_CENTERED; |
80 | option |= RMOPT_CENTERED; |
86 | break; |
81 | break; |
87 | case 1: |
82 | case 1: |
88 | option |= OPT_BOTTOM_C; |
83 | option |= RMOPT_BOTTOM_C; |
89 | break; |
84 | break; |
90 | case 2: |
85 | case 2: |
91 | option |= OPT_BOTTOM_R; |
86 | option |= RMOPT_BOTTOM_R; |
92 | break; |
87 | break; |
93 | } |
88 | } |
94 | if(RANDOM()%2) option |=OPT_LINEAR; |
89 | |
95 | if(RANDOM()%2) option |=OPT_IRR_SPACE; |
90 | if (rmg_rndm (2)) option |= RMOPT_LINEAR; |
|
|
91 | if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE; |
96 | } |
92 | } |
97 | |
93 | |
98 | /* write the outer walls, if appropriate. */ |
94 | /* write the outer walls, if appropriate. */ |
99 | if(!(option & OPT_WALL_OFF )) { |
95 | if (!(option & RMOPT_WALL_OFF)) |
100 | for(i=0;i<xsize;i++) |
96 | maze.border (); |
101 | maze[i][0] = maze[i][ysize-1] = '#'; |
|
|
102 | for(j=0;j<ysize;j++) |
|
|
103 | maze[0][j] = maze[xsize-1][j] = '#'; |
|
|
104 | }; |
|
|
105 | |
97 | |
106 | if(option & OPT_WALLS_ONLY) return maze; |
98 | if (option & RMOPT_WALLS_ONLY) |
|
|
99 | return; |
107 | |
100 | |
108 | /* pick off the mutually exclusive options */ |
101 | /* pick off the mutually exclusive options */ |
109 | if(option & OPT_BOTTOM_R) |
102 | if (option & RMOPT_BOTTOM_R) |
110 | bottom_right_centered_onion(maze,xsize,ysize,option,layers); |
103 | bottom_right_centered_onion (maze, xsize, ysize, option, layers); |
111 | else if(option & OPT_BOTTOM_C) |
104 | else if (option & RMOPT_BOTTOM_C) |
112 | bottom_centered_onion(maze,xsize,ysize,option,layers); |
105 | bottom_centered_onion (maze, xsize, ysize, option, layers); |
113 | else if(option & OPT_CENTERED) |
106 | else if (option & RMOPT_CENTERED) |
114 | centered_onion(maze,xsize,ysize,option,layers); |
107 | centered_onion (maze, xsize, ysize, option, layers); |
115 | |
|
|
116 | return maze; |
|
|
117 | } |
108 | } |
118 | |
109 | |
|
|
110 | static void |
119 | void centered_onion(char **maze, int xsize, int ysize, int option, int layers) { |
111 | centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
|
|
112 | { |
120 | int i,maxlayers; |
113 | int i, maxlayers; |
121 | float *xlocations; |
|
|
122 | float *ylocations; |
|
|
123 | |
114 | |
124 | maxlayers = (MIN(xsize,ysize)-2)/5; |
115 | maxlayers = (min (xsize, ysize) - 2) / 5; |
125 | if(!maxlayers) return; /* map too small to onionize */ |
116 | |
126 | if(layers > maxlayers) layers = maxlayers; |
117 | if (!maxlayers) |
127 | if(layers == 0) layers = (RANDOM() % maxlayers)+1; |
118 | return; /* map too small to onionize */ |
128 | xlocations = (float *) calloc(sizeof(float),2 * layers); |
119 | |
129 | ylocations = (float *) calloc(sizeof(float),2 * layers); |
120 | if (layers > maxlayers) |
130 | |
121 | layers = maxlayers; |
131 | |
122 | |
|
|
123 | if (layers == 0) |
|
|
124 | layers = rmg_rndm (maxlayers) + 1; |
|
|
125 | |
|
|
126 | float *xlocations = salloc0<float> (2 * layers); |
|
|
127 | float *ylocations = salloc0<float> (2 * layers); |
|
|
128 | |
132 | /* place all the walls */ |
129 | /* place all the walls */ |
133 | if(option & OPT_IRR_SPACE) /* randomly spaced */ { |
130 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
|
|
131 | { |
134 | int x_spaces_available, y_spaces_available; |
132 | int x_spaces_available, y_spaces_available; |
|
|
133 | |
135 | /* the "extra" spaces available for spacing between layers */ |
134 | /* the "extra" spaces available for spacing between layers */ |
136 | x_spaces_available = (xsize -2) - 6*layers +1; |
135 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
137 | y_spaces_available = (ysize -2) - 6*layers +1; |
136 | y_spaces_available = (ysize - 2) - 6 * layers + 1; |
138 | |
137 | |
139 | |
|
|
140 | /* pick an initial random pitch */ |
138 | /* pick an initial random pitch */ |
141 | for(i=0;i<2*layers;i++) { |
139 | for (i = 0; i < 2 * layers; i++) |
|
|
140 | { |
142 | float xpitch=2,ypitch=2; |
141 | float xpitch = 2, ypitch = 2; |
|
|
142 | |
143 | if(x_spaces_available>0) |
143 | if (x_spaces_available > 0) |
144 | xpitch = 2 + (RANDOM()%x_spaces_available + |
144 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
145 | RANDOM()%x_spaces_available + |
|
|
146 | RANDOM()%x_spaces_available)/3; |
|
|
147 | |
145 | |
148 | if(y_spaces_available>0) |
146 | if (y_spaces_available > 0) |
149 | ypitch = 2 + (RANDOM()%y_spaces_available + |
147 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
150 | RANDOM()%y_spaces_available + |
148 | |
151 | RANDOM()%y_spaces_available)/3; |
|
|
152 | xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; |
149 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
153 | ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; |
150 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
154 | x_spaces_available-=(int) (xpitch -2); |
151 | x_spaces_available -= (int) (xpitch - 2); |
155 | y_spaces_available-=(int) (ypitch -2); |
152 | y_spaces_available -= (int) (ypitch - 2); |
156 | } |
153 | } |
157 | |
154 | |
158 | } |
155 | } |
159 | if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ |
156 | |
|
|
157 | if (!(option & RMOPT_IRR_SPACE)) |
|
|
158 | { /* evenly spaced */ |
160 | float xpitch, ypitch; /* pitch of the onion layers */ |
159 | float xpitch, ypitch; /* pitch of the onion layers */ |
|
|
160 | |
161 | xpitch = (xsize-2.0)/(2.0*layers+1); |
161 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
162 | ypitch = (ysize-2.0)/(2.0*layers+1); |
162 | ypitch = (ysize - 2.0) / (2.0 * layers + 1); |
|
|
163 | |
163 | xlocations[0] = xpitch; |
164 | xlocations[0] = xpitch; |
164 | ylocations[0] = ypitch; |
165 | ylocations[0] = ypitch; |
|
|
166 | |
165 | for(i=1;i<2*layers;i++) { |
167 | for (i = 1; i < 2 * layers; i++) |
|
|
168 | { |
166 | xlocations[i] = xlocations[i-1] + xpitch; |
169 | xlocations[i] = xlocations[i - 1] + xpitch; |
167 | ylocations[i] = ylocations[i-1] + ypitch; |
170 | ylocations[i] = ylocations[i - 1] + ypitch; |
168 | } |
171 | } |
169 | } |
|
|
170 | |
172 | } |
|
|
173 | |
171 | /* draw all the onion boxes. */ |
174 | /* draw all the onion boxes. */ |
172 | |
|
|
173 | draw_onion(maze,xlocations,ylocations,layers); |
175 | draw_onion (maze, xlocations, ylocations, layers); |
174 | make_doors(maze,xlocations,ylocations,layers,option); |
176 | make_doors (maze, xlocations, ylocations, layers, option); |
175 | |
|
|
176 | } |
|
|
177 | |
177 | |
|
|
178 | sfree (xlocations, 2 * layers); |
|
|
179 | sfree (ylocations, 2 * layers); |
|
|
180 | } |
|
|
181 | |
|
|
182 | static void |
178 | void bottom_centered_onion(char **maze, int xsize, int ysize, int option, int layers) { |
183 | bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
|
|
184 | { |
179 | int i,maxlayers; |
185 | int i, maxlayers; |
180 | float *xlocations; |
|
|
181 | float *ylocations; |
|
|
182 | |
186 | |
183 | maxlayers = (MIN(xsize,ysize)-2)/5; |
187 | maxlayers = (min (xsize, ysize) - 2) / 5; |
184 | if(!maxlayers) return; /* map too small to onionize */ |
188 | |
185 | if(layers > maxlayers) layers = maxlayers; |
189 | if (!maxlayers) |
186 | if(layers == 0) layers = (RANDOM() % maxlayers)+1; |
190 | return; /* map too small to onionize */ |
187 | xlocations = (float *) calloc(sizeof(float),2 * layers); |
191 | |
188 | ylocations = (float *) calloc(sizeof(float),2 * layers); |
192 | if (layers > maxlayers) |
189 | |
193 | layers = maxlayers; |
190 | |
194 | |
|
|
195 | if (layers == 0) |
|
|
196 | layers = rmg_rndm (maxlayers) + 1; |
|
|
197 | |
|
|
198 | float *xlocations = salloc0<float> (2 * layers); |
|
|
199 | float *ylocations = salloc0<float> (2 * layers); |
|
|
200 | |
191 | /* place all the walls */ |
201 | /* place all the walls */ |
192 | if(option & OPT_IRR_SPACE) /* randomly spaced */ { |
202 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
|
|
203 | { |
193 | int x_spaces_available, y_spaces_available; |
204 | int x_spaces_available, y_spaces_available; |
|
|
205 | |
194 | /* the "extra" spaces available for spacing between layers */ |
206 | /* the "extra" spaces available for spacing between layers */ |
195 | x_spaces_available = (xsize -2) - 6*layers +1; |
207 | x_spaces_available = (xsize - 2) - 6 * layers + 1; |
196 | y_spaces_available = (ysize -2) - 3*layers +1; |
208 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
197 | |
209 | |
198 | |
|
|
199 | /* pick an initial random pitch */ |
210 | /* pick an initial random pitch */ |
200 | for(i=0;i<2*layers;i++) { |
211 | for (i = 0; i < 2 * layers; i++) |
|
|
212 | { |
201 | float xpitch=2,ypitch=2; |
213 | float xpitch = 2, ypitch = 2; |
|
|
214 | |
202 | if(x_spaces_available>0) |
215 | if (x_spaces_available > 0) |
203 | xpitch = 2 + (RANDOM()%x_spaces_available + |
216 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
204 | RANDOM()%x_spaces_available + |
|
|
205 | RANDOM()%x_spaces_available)/3; |
|
|
206 | |
217 | |
207 | if(y_spaces_available>0) |
218 | if (y_spaces_available > 0) |
208 | ypitch = 2 + (RANDOM()%y_spaces_available + |
219 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
209 | RANDOM()%y_spaces_available + |
220 | |
210 | RANDOM()%y_spaces_available)/3; |
|
|
211 | xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; |
221 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
|
|
222 | |
|
|
223 | if (i < layers) |
212 | if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; |
224 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
|
|
225 | else |
213 | else ylocations[i] = ysize-1; |
226 | ylocations[i] = ysize - 1; |
|
|
227 | |
214 | x_spaces_available-=(int)(xpitch -2); |
228 | x_spaces_available -= (int) (xpitch - 2); |
215 | y_spaces_available-=(int)(ypitch -2); |
229 | y_spaces_available -= (int) (ypitch - 2); |
216 | } |
230 | } |
217 | |
|
|
218 | } |
231 | } |
219 | if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ |
232 | |
|
|
233 | if (!(option & RMOPT_IRR_SPACE)) |
|
|
234 | { /* evenly spaced */ |
220 | float xpitch, ypitch; /* pitch of the onion layers */ |
235 | float xpitch, ypitch; /* pitch of the onion layers */ |
|
|
236 | |
221 | xpitch = (xsize-2.0)/(2.0*layers+1); |
237 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
222 | ypitch = (ysize-2.0)/(layers+1); |
238 | ypitch = (ysize - 2.0) / (layers + 1); |
|
|
239 | |
223 | xlocations[0] = xpitch; |
240 | xlocations[0] = xpitch; |
224 | ylocations[0] = ypitch; |
241 | ylocations[0] = ypitch; |
|
|
242 | |
225 | for(i=1;i<2*layers;i++) { |
243 | for (i = 1; i < 2 * layers; i++) |
|
|
244 | { |
226 | xlocations[i] = xlocations[i-1] + xpitch; |
245 | xlocations[i] = xlocations[i - 1] + xpitch; |
|
|
246 | |
|
|
247 | if (i < layers) |
227 | if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; |
248 | ylocations[i] = ylocations[i - 1] + ypitch; |
|
|
249 | else |
228 | else ylocations[i]=ysize-1; |
250 | ylocations[i] = ysize - 1; |
229 | } |
251 | } |
230 | } |
|
|
231 | |
252 | } |
|
|
253 | |
232 | /* draw all the onion boxes. */ |
254 | /* draw all the onion boxes. */ |
233 | |
255 | |
234 | draw_onion(maze,xlocations,ylocations,layers); |
256 | draw_onion (maze, xlocations, ylocations, layers); |
235 | make_doors(maze,xlocations,ylocations,layers,option); |
257 | make_doors (maze, xlocations, ylocations, layers, option); |
236 | |
|
|
237 | } |
|
|
238 | |
258 | |
|
|
259 | sfree (xlocations, 2 * layers); |
|
|
260 | sfree (ylocations, 2 * layers); |
|
|
261 | } |
239 | |
262 | |
240 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
263 | /* draw_boxes: draws the lines in the maze defining the onion layers */ |
241 | |
264 | static void |
242 | void draw_onion(char **maze,float *xlocations,float *ylocations, int layers) { |
265 | draw_onion (char **maze, float *xlocations, float *ylocations, int layers) |
|
|
266 | { |
243 | int i,j,l; |
267 | int i, j, l; |
244 | |
268 | |
245 | for(l=0;l<layers;l++) { |
269 | for (l = 0; l < layers; l++) |
|
|
270 | { |
246 | int x1,x2,y1,y2; |
271 | int x1, x2, y1, y2; |
|
|
272 | |
247 | /* horizontal segments */ |
273 | /* horizontal segments */ |
248 | y1 = (int)ylocations[l]; |
274 | y1 = (int) ylocations[l]; |
249 | y2 = (int)ylocations[2*layers -l-1]; |
275 | y2 = (int) ylocations[2 * layers - l - 1]; |
250 | for(i=(int)xlocations[l];i<=(int)xlocations[2*layers -l -1];i++) { |
276 | for (i = (int) xlocations[l]; i <= (int) xlocations[2 * layers - l - 1]; i++) |
|
|
277 | { |
251 | maze[i][y1] = '#'; |
278 | maze[i][y1] = '#'; |
252 | maze[i][y2] = '#'; |
279 | maze[i][y2] = '#'; |
253 | } |
280 | } |
254 | |
281 | |
255 | /* vertical segments */ |
282 | /* vertical segments */ |
256 | x1 = (int)xlocations[l]; |
283 | x1 = (int) xlocations[l]; |
257 | x2 = (int)xlocations[2*layers-l-1]; |
284 | x2 = (int) xlocations[2 * layers - l - 1]; |
258 | for(j=(int)ylocations[l];j<=(int)ylocations[2*layers -l -1];j++) { |
285 | for (j = (int) ylocations[l]; j <= (int) ylocations[2 * layers - l - 1]; j++) |
|
|
286 | { |
259 | maze[x1][j] = '#'; |
287 | maze[x1][j] = '#'; |
260 | maze[x2][j] = '#'; |
288 | maze[x2][j] = '#'; |
261 | } |
289 | } |
262 | |
290 | |
263 | } |
291 | } |
264 | } |
292 | } |
265 | |
293 | |
|
|
294 | static void |
266 | void make_doors(char **maze, float *xlocations,float *ylocations,int layers,int options) { |
295 | make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) |
|
|
296 | { |
267 | int freedoms; /* number of different walls on which we could place a door */ |
297 | int freedoms; /* number of different walls on which we could place a door */ |
268 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
298 | int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ |
269 | int l,x1=0,x2,y1=0,y2; |
299 | int l, x1 = 0, x2, y1 = 0, y2; |
|
|
300 | |
270 | freedoms = 4; /* centered */ |
301 | freedoms = 4; /* centered */ |
|
|
302 | |
271 | if(options & OPT_BOTTOM_C) freedoms=3; |
303 | if (options & RMOPT_BOTTOM_C) |
|
|
304 | freedoms = 3; |
|
|
305 | |
272 | if(options & OPT_BOTTOM_R) freedoms=2; |
306 | if (options & RMOPT_BOTTOM_R) |
|
|
307 | freedoms = 2; |
|
|
308 | |
273 | if(layers<= 0) return; |
309 | if (layers <= 0) |
|
|
310 | return; |
|
|
311 | |
274 | /* pick which wall will have a door. */ |
312 | /* pick which wall will have a door. */ |
275 | which_wall = RANDOM() %freedoms + 1; |
313 | which_wall = rmg_rndm (freedoms) + 1; |
276 | for(l=0;l<layers;l++) { |
314 | for (l = 0; l < layers; l++) |
277 | if(options & OPT_LINEAR) { /* linear door placement. */ |
315 | { |
|
|
316 | if (options & RMOPT_LINEAR) |
|
|
317 | { /* linear door placement. */ |
278 | switch(which_wall) { |
318 | switch (which_wall) |
|
|
319 | { |
|
|
320 | case 1: |
279 | case 1: { /* left hand wall */ |
321 | { /* left hand wall */ |
280 | x1 = (int)xlocations[l]; |
322 | x1 = (int) xlocations[l]; |
281 | y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); |
323 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
282 | break; |
|
|
283 | } |
324 | break; |
|
|
325 | } |
|
|
326 | case 2: |
284 | case 2: { /* top wall placement */ |
327 | { /* top wall placement */ |
285 | x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); |
328 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
286 | y1 = (int)ylocations[l]; |
329 | y1 = (int) ylocations[l]; |
287 | break; |
|
|
288 | } |
330 | break; |
|
|
331 | } |
|
|
332 | case 3: |
289 | case 3: { /* right wall placement */ |
333 | { /* right wall placement */ |
290 | x1 = (int)xlocations[2*layers-l-1]; |
334 | x1 = (int) xlocations[2 * layers - l - 1]; |
291 | y1 = (int)( (ylocations[l] + ylocations[2*layers-l-1])/2); |
335 | y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); |
292 | break; |
|
|
293 | } |
336 | break; |
|
|
337 | } |
|
|
338 | case 4: |
294 | case 4: { /* bottom wall placement */ |
339 | { /* bottom wall placement */ |
295 | x1 = (int)( (xlocations[l] + xlocations[2*layers-l-1])/2); |
340 | x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); |
296 | y1 = (int)ylocations[2*layers -l -1]; |
341 | y1 = (int) ylocations[2 * layers - l - 1]; |
|
|
342 | break; |
297 | break; |
343 | } |
298 | } |
344 | } |
299 | } |
|
|
300 | } |
345 | } |
301 | else { /* random door placement. */ |
346 | else |
302 | which_wall=RANDOM()%freedoms + 1; |
347 | { /* random door placement. */ |
|
|
348 | which_wall = rmg_rndm (freedoms) + 1; |
303 | switch(which_wall) { |
349 | switch (which_wall) |
|
|
350 | { |
|
|
351 | case 1: |
304 | case 1: { /* left hand wall */ |
352 | { /* left hand wall */ |
305 | x1 = (int)xlocations[l]; |
353 | x1 = (int) xlocations[l]; |
306 | y2 = (int) (ylocations[2*layers-l-1]-ylocations[l]-1); |
354 | y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); |
|
|
355 | if (y2 > 0) |
307 | if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); |
356 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
|
|
357 | else |
308 | else y1 = (int) (ylocations[l]+1); |
358 | y1 = (int) (ylocations[l] + 1); |
309 | break; |
|
|
310 | } |
359 | break; |
|
|
360 | } |
|
|
361 | case 2: |
311 | case 2: { /* top wall placement */ |
362 | { /* top wall placement */ |
312 | x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; |
363 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
|
|
364 | if (x2 > 0) |
313 | if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); |
365 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
|
|
366 | else |
314 | else x1 = (int) (xlocations[l]+1); |
367 | x1 = (int) (xlocations[l] + 1); |
315 | y1 = (int)ylocations[l]; |
368 | y1 = (int) ylocations[l]; |
316 | break; |
|
|
317 | } |
369 | break; |
|
|
370 | } |
|
|
371 | case 3: |
318 | case 3: { /* right wall placement */ |
372 | { /* right wall placement */ |
319 | x1 = (int)xlocations[2*layers-l-1]; |
373 | x1 = (int) xlocations[2 * layers - l - 1]; |
320 | y2 = (int)( (-ylocations[l] + ylocations[2*layers-l-1]))-1; |
374 | y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; |
|
|
375 | if (y2 > 0) |
321 | if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); |
376 | y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1); |
|
|
377 | else |
322 | else y1 = (int) (ylocations[l]+1); |
378 | y1 = (int) (ylocations[l] + 1); |
323 | |
379 | |
324 | break; |
|
|
325 | } |
380 | break; |
|
|
381 | } |
|
|
382 | case 4: |
326 | case 4: { /* bottom wall placement */ |
383 | { /* bottom wall placement */ |
327 | x2 = (int)( (-xlocations[l] + xlocations[2*layers-l-1]))-1; |
384 | x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; |
|
|
385 | if (x2 > 0) |
328 | if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); |
386 | x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1); |
|
|
387 | else |
329 | else x1 = (int) (xlocations[l]+1); |
388 | x1 = (int) (xlocations[l] + 1); |
330 | y1 = (int)ylocations[2*layers-l-1]; |
389 | y1 = (int) ylocations[2 * layers - l - 1]; |
331 | break; |
|
|
332 | } |
390 | break; |
333 | |
391 | } |
|
|
392 | |
334 | } |
393 | } |
335 | } |
394 | } |
|
|
395 | |
336 | if(options & OPT_NO_DOORS) |
396 | if (options & RMOPT_NO_DOORS) |
337 | maze[x1][y1] = '#'; /* no door. */ |
397 | maze[x1][y1] = '#'; /* no door. */ |
338 | else |
398 | else |
339 | maze[x1][y1] = 'D'; /* write the door */ |
399 | maze[x1][y1] = 'D'; /* write the door */ |
340 | |
400 | |
341 | } |
401 | } |
342 | /* mark the center of the maze with a C */ |
402 | /* mark the center of the maze with a C */ |
343 | l = layers -1; |
403 | l = layers - 1; |
344 | x1 = (int) (xlocations[l] + xlocations[2*layers -l -1])/2; |
404 | x1 = (int) (xlocations[l] + xlocations[2 * layers - l - 1]) / 2; |
345 | y1 = (int) (ylocations[l] + ylocations[2*layers -l -1])/2; |
405 | y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; |
|
|
406 | |
346 | maze[x1][y1] = 'C'; |
407 | maze[x1][y1] = 'C'; |
347 | |
|
|
348 | /* not needed anymore */ |
|
|
349 | free(xlocations); |
|
|
350 | free(ylocations); |
|
|
351 | |
|
|
352 | } |
408 | } |
353 | |
409 | |
|
|
410 | static void |
354 | void bottom_right_centered_onion(char **maze, int xsize, int ysize, int option, int layers){ |
411 | bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) |
|
|
412 | { |
355 | int i,maxlayers; |
413 | int i, maxlayers; |
356 | float *xlocations; |
|
|
357 | float *ylocations; |
|
|
358 | |
414 | |
359 | maxlayers = (MIN(xsize,ysize)-2)/5; |
415 | maxlayers = (min (xsize, ysize) - 2) / 5; |
360 | if(!maxlayers) return; /* map too small to onionize */ |
416 | |
361 | if(layers > maxlayers) layers = maxlayers; |
417 | if (!maxlayers) |
362 | if(layers == 0) layers = (RANDOM() % maxlayers)+1; |
418 | return; /* map too small to onionize */ |
363 | xlocations = (float *) calloc(sizeof(float),2 * layers); |
419 | |
364 | ylocations = (float *) calloc(sizeof(float),2 * layers); |
420 | if (layers > maxlayers) |
365 | |
421 | layers = maxlayers; |
366 | |
422 | |
|
|
423 | if (layers == 0) |
|
|
424 | layers = rmg_rndm (maxlayers) + 1; |
|
|
425 | |
|
|
426 | float *xlocations = salloc0<float> (2 * layers); |
|
|
427 | float *ylocations = salloc0<float> (2 * layers); |
|
|
428 | |
367 | /* place all the walls */ |
429 | /* place all the walls */ |
368 | if(option & OPT_IRR_SPACE) /* randomly spaced */ { |
430 | if (option & RMOPT_IRR_SPACE) /* randomly spaced */ |
|
|
431 | { |
369 | int x_spaces_available, y_spaces_available; |
432 | int x_spaces_available, y_spaces_available; |
|
|
433 | |
370 | /* the "extra" spaces available for spacing between layers */ |
434 | /* the "extra" spaces available for spacing between layers */ |
371 | x_spaces_available = (xsize -2) - 3*layers +1; |
435 | x_spaces_available = (xsize - 2) - 3 * layers + 1; |
372 | y_spaces_available = (ysize -2) - 3*layers +1; |
436 | y_spaces_available = (ysize - 2) - 3 * layers + 1; |
373 | |
437 | |
374 | |
438 | |
375 | /* pick an initial random pitch */ |
439 | /* pick an initial random pitch */ |
376 | for(i=0;i<2*layers;i++) { |
440 | for (i = 0; i < 2 * layers; i++) |
|
|
441 | { |
377 | float xpitch=2,ypitch=2; |
442 | float xpitch = 2, ypitch = 2; |
|
|
443 | |
378 | if(x_spaces_available>0) |
444 | if (x_spaces_available > 0) |
379 | xpitch = 2 + (RANDOM()%x_spaces_available + |
445 | xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3; |
380 | RANDOM()%x_spaces_available + |
|
|
381 | RANDOM()%x_spaces_available)/3; |
|
|
382 | |
446 | |
383 | if(y_spaces_available>0) |
447 | if (y_spaces_available > 0) |
384 | ypitch = 2 + (RANDOM()%y_spaces_available + |
448 | ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3; |
385 | RANDOM()%y_spaces_available + |
449 | |
386 | RANDOM()%y_spaces_available)/3; |
450 | if (i < layers) |
387 | if(i < layers) xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; |
451 | xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; |
|
|
452 | else |
388 | else xlocations[i] = xsize-1; |
453 | xlocations[i] = xsize - 1; |
389 | |
454 | |
|
|
455 | if (i < layers) |
390 | if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; |
456 | ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; |
|
|
457 | else |
391 | else ylocations[i] = ysize-1; |
458 | ylocations[i] = ysize - 1; |
|
|
459 | |
392 | x_spaces_available-=(int)(xpitch -2); |
460 | x_spaces_available -= (int) (xpitch - 2); |
393 | y_spaces_available-=(int)(ypitch -2); |
461 | y_spaces_available -= (int) (ypitch - 2); |
394 | } |
462 | } |
395 | |
|
|
396 | } |
463 | } |
397 | if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ |
464 | |
|
|
465 | if (!(option & RMOPT_IRR_SPACE)) |
|
|
466 | { /* evenly spaced */ |
398 | float xpitch, ypitch; /* pitch of the onion layers */ |
467 | float xpitch, ypitch; /* pitch of the onion layers */ |
|
|
468 | |
399 | xpitch = (xsize-2.0)/(2.0*layers+1); |
469 | xpitch = (xsize - 2.0) / (2.0 * layers + 1); |
400 | ypitch = (ysize-2.0)/(layers+1); |
470 | ypitch = (ysize - 2.0) / (layers + 1); |
|
|
471 | |
401 | xlocations[0] = xpitch; |
472 | xlocations[0] = xpitch; |
402 | ylocations[0] = ypitch; |
473 | ylocations[0] = ypitch; |
|
|
474 | |
403 | for(i=1;i<2*layers;i++) { |
475 | for (i = 1; i < 2 * layers; i++) |
|
|
476 | { |
|
|
477 | if (i < layers) |
404 | if(i < layers) xlocations[i] = xlocations[i-1] + xpitch; |
478 | xlocations[i] = xlocations[i - 1] + xpitch; |
|
|
479 | else |
405 | else xlocations[i]=xsize-1; |
480 | xlocations[i] = xsize - 1; |
|
|
481 | |
|
|
482 | if (i < layers) |
406 | if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; |
483 | ylocations[i] = ylocations[i - 1] + ypitch; |
|
|
484 | else |
407 | else ylocations[i]=ysize-1; |
485 | ylocations[i] = ysize - 1; |
408 | } |
486 | } |
409 | } |
|
|
410 | |
487 | } |
|
|
488 | |
411 | /* draw all the onion boxes. */ |
489 | /* draw all the onion boxes. */ |
412 | |
490 | |
413 | draw_onion(maze,xlocations,ylocations,layers); |
491 | draw_onion (maze, xlocations, ylocations, layers); |
414 | make_doors(maze,xlocations,ylocations,layers,option); |
492 | make_doors (maze, xlocations, ylocations, layers, option); |
415 | |
493 | |
|
|
494 | sfree (xlocations, 2 * layers); |
|
|
495 | sfree (ylocations, 2 * layers); |
416 | } |
496 | } |
|
|
497 | |