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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines