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.7 by pippijn, Sat Jan 6 14:42:30 2007 UTC

1/*
2 * static char *room_gen_onion_c =
3 * "$Id: room_gen_onion.C,v 1.1 2006/08/13 17:16:03 elmex Exp $";
4 */
5 1
6/* 2/*
7 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
8 4
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
9 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 6 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen 7 Copyright (C) 1992 Frank Tore Johansen
11 8
12 This program is free software; you can redistribute it and/or modify 9 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 10 it under the terms of the GNU General Public License as published by
21 18
22 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software 20 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 22
26 The authors can be reached via e-mail at crossfire-devel@real-time.com 23 The authors can be reached via e-mail at <crossfire@schmorp.de>
27*/ 24*/
28 25
29 26
30/* The onion room generator: 27/* The onion room generator:
31Onion rooms are like this: 28Onion rooms are like this:
57 54
58#include <global.h> 55#include <global.h>
59#include <random_map.h> 56#include <random_map.h>
60 57
61#ifndef MIN 58#ifndef MIN
62#define MIN(x,y) (((x)<(y))? (x):(y)) 59# define MIN(x,y) (((x)<(y))? (x):(y))
63#endif 60#endif
64void centered_onion(char **maze, int xsize, int ysize, int option, int layers); 61void 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); 62void 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); 63void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers);
67 64
68 65
69void draw_onion(char **maze,float *xlocations,float *ylocations,int layers); 66void draw_onion (char **maze, float *xlocations, float *ylocations, int layers);
70void make_doors(char **maze,float *xlocations,float *ylocations,int layers,int options); 67void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options);
71 68
69char **
72char **map_gen_onion(int xsize, int ysize, int option, int layers) { 70map_gen_onion (int xsize, int ysize, int option, int layers)
71{
73 int i,j; 72 int i, j;
74 73
75 /* allocate that array, set it up */ 74 /* allocate that array, set it up */
76 char **maze = (char **)calloc(sizeof(char*),xsize); 75 char **maze = (char **) calloc (sizeof (char *), xsize);
76
77 for(i=0;i<xsize;i++) { 77 for (i = 0; i < xsize; i++)
78 {
78 maze[i] = (char *) calloc(sizeof(char),ysize); 79 maze[i] = (char *) calloc (sizeof (char), ysize);
79 } 80 }
80 81
81 /* pick some random options if option = 0 */ 82 /* pick some random options if option = 0 */
82 if(option == 0) { 83 if (option == 0)
84 {
83 switch(RANDOM()%3) { 85 switch (RANDOM () % 3)
84 case 0: 86 {
85 option |= OPT_CENTERED; 87 case 0:
86 break; 88 option |= RMOPT_CENTERED;
87 case 1: 89 break;
88 option |= OPT_BOTTOM_C; 90 case 1:
89 break; 91 option |= RMOPT_BOTTOM_C;
90 case 2: 92 break;
91 option |= OPT_BOTTOM_R; 93 case 2:
92 break; 94 option |= RMOPT_BOTTOM_R;
93 } 95 break;
94 if(RANDOM()%2) option |=OPT_LINEAR; 96 }
95 if(RANDOM()%2) option |=OPT_IRR_SPACE; 97 if (RANDOM () % 2)
98 option |= RMOPT_LINEAR;
99 if (RANDOM () % 2)
100 option |= RMOPT_IRR_SPACE;
96 } 101 }
97 102
98 /* write the outer walls, if appropriate. */ 103 /* write the outer walls, if appropriate. */
99 if(!(option & OPT_WALL_OFF )) { 104 if (!(option & RMOPT_WALL_OFF))
105 {
100 for(i=0;i<xsize;i++) 106 for (i = 0; i < xsize; i++)
101 maze[i][0] = maze[i][ysize-1] = '#'; 107 maze[i][0] = maze[i][ysize - 1] = '#';
102 for(j=0;j<ysize;j++) 108 for (j = 0; j < ysize; j++)
103 maze[0][j] = maze[xsize-1][j] = '#'; 109 maze[0][j] = maze[xsize - 1][j] = '#';
104 }; 110 };
105 111
106 if(option & OPT_WALLS_ONLY) return maze; 112 if (option & RMOPT_WALLS_ONLY)
113 return maze;
107 114
108 /* pick off the mutually exclusive options */ 115 /* pick off the mutually exclusive options */
109 if(option & OPT_BOTTOM_R) 116 if (option & RMOPT_BOTTOM_R)
110 bottom_right_centered_onion(maze,xsize,ysize,option,layers); 117 bottom_right_centered_onion (maze, xsize, ysize, option, layers);
111 else if(option & OPT_BOTTOM_C) 118 else if (option & RMOPT_BOTTOM_C)
112 bottom_centered_onion(maze,xsize,ysize,option,layers); 119 bottom_centered_onion (maze, xsize, ysize, option, layers);
113 else if(option & OPT_CENTERED) 120 else if (option & RMOPT_CENTERED)
114 centered_onion(maze,xsize,ysize,option,layers); 121 centered_onion (maze, xsize, ysize, option, layers);
115 122
116 return maze; 123 return maze;
117} 124}
118 125
126void
119void centered_onion(char **maze, int xsize, int ysize, int option, int layers) { 127centered_onion (char **maze, int xsize, int ysize, int option, int layers)
128{
120 int i,maxlayers; 129 int i, maxlayers;
121 float *xlocations; 130 float *xlocations;
122 float *ylocations; 131 float *ylocations;
123 132
124 maxlayers = (MIN(xsize,ysize)-2)/5; 133 maxlayers = (MIN (xsize, ysize) - 2) / 5;
125 if(!maxlayers) return; /* map too small to onionize */ 134 if (!maxlayers)
126 if(layers > maxlayers) layers = maxlayers; 135 return; /* map too small to onionize */
136 if (layers > maxlayers)
137 layers = maxlayers;
138 if (layers == 0)
127 if(layers == 0) layers = (RANDOM() % maxlayers)+1; 139 layers = (RANDOM () % maxlayers) + 1;
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 143
132 /* place all the walls */ 144 /* place all the walls */
133 if(option & OPT_IRR_SPACE) /* randomly spaced */ { 145 if (option & RMOPT_IRR_SPACE) /* randomly spaced */
146 {
134 int x_spaces_available, y_spaces_available; 147 int x_spaces_available, y_spaces_available;
148
135 /* the "extra" spaces available for spacing between layers */ 149 /* the "extra" spaces available for spacing between layers */
136 x_spaces_available = (xsize -2) - 6*layers +1; 150 x_spaces_available = (xsize - 2) - 6 * layers + 1;
137 y_spaces_available = (ysize -2) - 6*layers +1; 151 y_spaces_available = (ysize - 2) - 6 * layers + 1;
138 152
139 153
140 /* pick an initial random pitch */ 154 /* pick an initial random pitch */
141 for(i=0;i<2*layers;i++) { 155 for (i = 0; i < 2 * layers; i++)
142 float xpitch=2,ypitch=2; 156 {
157 float xpitch = 2, ypitch = 2;
158
143 if(x_spaces_available>0) 159 if (x_spaces_available > 0)
144 xpitch = 2 + (RANDOM()%x_spaces_available + 160 xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3;
145 RANDOM()%x_spaces_available +
146 RANDOM()%x_spaces_available)/3;
147 161
148 if(y_spaces_available>0) 162 if (y_spaces_available > 0)
149 ypitch = 2 + (RANDOM()%y_spaces_available + 163 ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3;
150 RANDOM()%y_spaces_available +
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 */
203 if (layers > maxlayers)
204 layers = maxlayers;
205 if (layers == 0)
186 if(layers == 0) layers = (RANDOM() % maxlayers)+1; 206 layers = (RANDOM () % 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++)
201 float xpitch=2,ypitch=2; 223 {
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 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % 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 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3;
209 RANDOM()%y_spaces_available +
210 RANDOM()%y_spaces_available)/3;
211 xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; 231 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
212 if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; 232 if (i < layers)
213 else ylocations[i] = ysize-1; 233 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
234 else
235 ylocations[i] = ysize - 1;
214 x_spaces_available-=(int)(xpitch -2); 236 x_spaces_available -= (int) (xpitch - 2);
215 y_spaces_available-=(int)(ypitch -2); 237 y_spaces_available -= (int) (ypitch - 2);
216 } 238 }
217 239
218 } 240 }
219 if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ 241 if (!(option & RMOPT_IRR_SPACE))
242 { /* evenly spaced */
220 float xpitch, ypitch; /* pitch of the onion layers */ 243 float xpitch, ypitch; /* pitch of the onion layers */
244
221 xpitch = (xsize-2.0)/(2.0*layers+1); 245 xpitch = (xsize - 2.0) / (2.0 * layers + 1);
222 ypitch = (ysize-2.0)/(layers+1); 246 ypitch = (ysize - 2.0) / (layers + 1);
223 xlocations[0] = xpitch; 247 xlocations[0] = xpitch;
224 ylocations[0] = ypitch; 248 ylocations[0] = ypitch;
225 for(i=1;i<2*layers;i++) { 249 for (i = 1; i < 2 * layers; i++)
250 {
226 xlocations[i] = xlocations[i-1] + xpitch; 251 xlocations[i] = xlocations[i - 1] + xpitch;
227 if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; 252 if (i < layers)
228 else ylocations[i]=ysize-1; 253 ylocations[i] = ylocations[i - 1] + ypitch;
229 } 254 else
230 } 255 ylocations[i] = ysize - 1;
256 }
231 257 }
258
232 /* draw all the onion boxes. */ 259 /* draw all the onion boxes. */
233 260
234 draw_onion(maze,xlocations,ylocations,layers); 261 draw_onion (maze, xlocations, ylocations, layers);
235 make_doors(maze,xlocations,ylocations,layers,option); 262 make_doors (maze, xlocations, ylocations, layers, option);
236 263
237} 264}
238 265
239 266
240/* draw_boxes: draws the lines in the maze defining the onion layers */ 267/* draw_boxes: draws the lines in the maze defining the onion layers */
241 268
269void
242void draw_onion(char **maze,float *xlocations,float *ylocations, int layers) { 270draw_onion (char **maze, float *xlocations, float *ylocations, int layers)
271{
243 int i,j,l; 272 int i, j, l;
244 273
245 for(l=0;l<layers;l++) { 274 for (l = 0; l < layers; l++)
275 {
246 int x1,x2,y1,y2; 276 int x1, x2, y1, y2;
277
247 /* horizontal segments */ 278 /* horizontal segments */
248 y1 = (int)ylocations[l]; 279 y1 = (int) ylocations[l];
249 y2 = (int)ylocations[2*layers -l-1]; 280 y2 = (int) ylocations[2 * layers - l - 1];
250 for(i=(int)xlocations[l];i<=(int)xlocations[2*layers -l -1];i++) { 281 for (i = (int) xlocations[l]; i <= (int) xlocations[2 * layers - l - 1]; i++)
282 {
251 maze[i][y1] = '#'; 283 maze[i][y1] = '#';
252 maze[i][y2] = '#'; 284 maze[i][y2] = '#';
253 } 285 }
254 286
255 /* vertical segments */ 287 /* vertical segments */
256 x1 = (int)xlocations[l]; 288 x1 = (int) xlocations[l];
257 x2 = (int)xlocations[2*layers-l-1]; 289 x2 = (int) xlocations[2 * layers - l - 1];
258 for(j=(int)ylocations[l];j<=(int)ylocations[2*layers -l -1];j++) { 290 for (j = (int) ylocations[l]; j <= (int) ylocations[2 * layers - l - 1]; j++)
291 {
259 maze[x1][j] = '#'; 292 maze[x1][j] = '#';
260 maze[x2][j] = '#'; 293 maze[x2][j] = '#';
261 } 294 }
262 295
263 } 296 }
264} 297}
265 298
299void
266void make_doors(char **maze, float *xlocations,float *ylocations,int layers,int options) { 300make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options)
301{
267 int freedoms; /* number of different walls on which we could place a door */ 302 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 */ 303 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */
269 int l,x1=0,x2,y1=0,y2; 304 int l, x1 = 0, x2, y1 = 0, y2;
305
270 freedoms = 4; /* centered */ 306 freedoms = 4; /* centered */
271 if(options & OPT_BOTTOM_C) freedoms=3; 307 if (options & RMOPT_BOTTOM_C)
308 freedoms = 3;
272 if(options & OPT_BOTTOM_R) freedoms=2; 309 if (options & RMOPT_BOTTOM_R)
310 freedoms = 2;
273 if(layers<= 0) return; 311 if (layers <= 0)
312 return;
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 = RANDOM () % 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 {
278 switch(which_wall) { 317 if (options & RMOPT_LINEAR)
279 case 1: { /* left hand wall */ 318 { /* linear door placement. */
280 x1 = (int)xlocations[l]; 319 switch (which_wall)
320 {
321 case 1:
322 { /* left hand wall */
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; 325 break;
283 } 326 }
284 case 2: { /* top wall placement */ 327 case 2:
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; 331 break;
288 } 332 }
289 case 3: { /* right wall placement */ 333 case 3:
290 x1 = (int)xlocations[2*layers-l-1]; 334 { /* right wall placement */
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; 337 break;
293 } 338 }
294 case 4: { /* bottom wall placement */ 339 case 4:
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];
297 break; 343 break;
298 } 344 }
299 } 345 }
300 } 346 }
301 else { /* random door placement. */ 347 else
348 { /* random door placement. */
302 which_wall=RANDOM()%freedoms + 1; 349 which_wall = RANDOM () % freedoms + 1;
303 switch(which_wall) { 350 switch (which_wall)
304 case 1: { /* left hand wall */ 351 {
305 x1 = (int)xlocations[l]; 352 case 1:
353 { /* left hand wall */
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);
307 if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); 356 if (y2 > 0)
308 else y1 = (int) (ylocations[l]+1); 357 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1);
309 break; 358 else
310 } 359 y1 = (int) (ylocations[l] + 1);
311 case 2: { /* top wall placement */ 360 break;
361 }
362 case 2:
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;
313 if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); 365 if (x2 > 0)
314 else x1 = (int) (xlocations[l]+1); 366 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1);
315 y1 = (int)ylocations[l]; 367 else
316 break; 368 x1 = (int) (xlocations[l] + 1);
317 } 369 y1 = (int) ylocations[l];
318 case 3: { /* right wall placement */ 370 break;
319 x1 = (int)xlocations[2*layers-l-1]; 371 }
372 case 3:
373 { /* right wall placement */
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;
321 if(y2 > 0) y1 = (int) (ylocations[l]+RANDOM() %y2 + 1); 376 if (y2 > 0)
322 else y1 = (int) (ylocations[l]+1); 377 y1 = (int) (ylocations[l] + RANDOM () % y2 + 1);
378 else
379 y1 = (int) (ylocations[l] + 1);
323 380
324 break; 381 break;
325 } 382 }
326 case 4: { /* bottom wall placement */ 383 case 4:
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;
328 if (x2 > 0) x1 = (int) (xlocations[l]+RANDOM()%x2 + 1); 386 if (x2 > 0)
329 else x1 = (int) (xlocations[l]+1); 387 x1 = (int) (xlocations[l] + RANDOM () % x2 + 1);
330 y1 = (int)ylocations[2*layers-l-1]; 388 else
331 break; 389 x1 = (int) (xlocations[l] + 1);
332 } 390 y1 = (int) ylocations[2 * layers - l - 1];
333 391 break;
334 } 392 }
335 } 393
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;
346 maze[x1][y1] = 'C'; 406 maze[x1][y1] = 'C';
347 407
348 /* not needed anymore */ 408 /* not needed anymore */
349 free(xlocations); 409 free (xlocations);
350 free(ylocations); 410 free (ylocations);
351
352}
353 411
412}
413
414void
354void bottom_right_centered_onion(char **maze, int xsize, int ysize, int option, int layers){ 415bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers)
416{
355 int i,maxlayers; 417 int i, maxlayers;
356 float *xlocations; 418 float *xlocations;
357 float *ylocations; 419 float *ylocations;
358 420
359 maxlayers = (MIN(xsize,ysize)-2)/5; 421 maxlayers = (MIN (xsize, ysize) - 2) / 5;
360 if(!maxlayers) return; /* map too small to onionize */ 422 if (!maxlayers)
361 if(layers > maxlayers) layers = maxlayers; 423 return; /* map too small to onionize */
424 if (layers > maxlayers)
425 layers = maxlayers;
426 if (layers == 0)
362 if(layers == 0) layers = (RANDOM() % maxlayers)+1; 427 layers = (RANDOM () % maxlayers) + 1;
363 xlocations = (float *) calloc(sizeof(float),2 * layers); 428 xlocations = (float *) calloc (sizeof (float), 2 * layers);
364 ylocations = (float *) calloc(sizeof(float),2 * layers); 429 ylocations = (float *) calloc (sizeof (float), 2 * layers);
365 430
366 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 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % 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 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3;
385 RANDOM()%y_spaces_available + 452 if (i < layers)
386 RANDOM()%y_spaces_available)/3; 453 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
387 if(i < layers) xlocations[i] = ( (i>0)?xlocations[i-1]:0) + xpitch; 454 else
388 else xlocations[i] = xsize-1; 455 xlocations[i] = xsize - 1;
389 456
390 if(i < layers) ylocations[i] = ( (i>0)?ylocations[i-1]:0) + ypitch; 457 if (i < layers)
391 else ylocations[i] = ysize-1; 458 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
459 else
460 ylocations[i] = ysize - 1;
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 464
396 } 465 }
397 if(!(option&OPT_IRR_SPACE)){ /* evenly spaced */ 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);
401 xlocations[0] = xpitch; 472 xlocations[0] = xpitch;
402 ylocations[0] = ypitch; 473 ylocations[0] = ypitch;
403 for(i=1;i<2*layers;i++) { 474 for (i = 1; i < 2 * layers; i++)
404 if(i < layers) xlocations[i] = xlocations[i-1] + xpitch; 475 {
405 else xlocations[i]=xsize-1; 476 if (i < layers)
406 if(i < layers) ylocations[i] = ylocations[i-1] + ypitch; 477 xlocations[i] = xlocations[i - 1] + xpitch;
407 else ylocations[i]=ysize-1; 478 else
408 } 479 xlocations[i] = xsize - 1;
409 } 480 if (i < layers)
481 ylocations[i] = ylocations[i - 1] + ypitch;
482 else
483 ylocations[i] = ysize - 1;
484 }
410 485 }
486
411 /* draw all the onion boxes. */ 487 /* draw all the onion boxes. */
412 488
413 draw_onion(maze,xlocations,ylocations,layers); 489 draw_onion (maze, xlocations, ylocations, layers);
414 make_doors(maze,xlocations,ylocations,layers,option); 490 make_doors (maze, xlocations, ylocations, layers, option);
415 491
416} 492}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines