ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_onion.C
(Generate patch)

Comparing deliantra/server/random_maps/room_gen_onion.C (file contents):
Revision 1.2 by root, Tue Aug 29 08:01:36 2006 UTC vs.
Revision 1.16 by root, Sun May 4 14:12:37 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines