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.11 by root, Sun Jul 1 05:00:19 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines