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.13 by root, Fri Apr 11 21:09:53 2008 UTC vs.
Revision 1.16 by root, Sun May 4 14:12:37 2008 UTC

60void 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);
61 61
62void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); 62void draw_onion (char **maze, float *xlocations, float *ylocations, int layers);
63void 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);
64 64
65Maze 65void
66map_gen_onion (int xsize, int ysize, int option, int layers) 66map_gen_onion (Layout maze, int option, int layers)
67{ 67{
68 int i, j; 68 int i, j;
69 69
70 Maze maze (xsize, ysize); 70 int xsize = maze->w;
71 int ysize = maze->h;
72
73 maze->clear ();
71 74
72 /* pick some random options if option = 0 */ 75 /* pick some random options if option = 0 */
73 if (option == 0) 76 if (option == 0)
74 { 77 {
75 switch (rndm (3)) 78 switch (rmg_rndm (3))
76 { 79 {
77 case 0: 80 case 0:
78 option |= RMOPT_CENTERED; 81 option |= RMOPT_CENTERED;
79 break; 82 break;
80 case 1: 83 case 1:
83 case 2: 86 case 2:
84 option |= RMOPT_BOTTOM_R; 87 option |= RMOPT_BOTTOM_R;
85 break; 88 break;
86 } 89 }
87 90
88 if (rndm (2)) option |= RMOPT_LINEAR; 91 if (rmg_rndm (2)) option |= RMOPT_LINEAR;
89 if (rndm (2)) option |= RMOPT_IRR_SPACE; 92 if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE;
90 } 93 }
91 94
92 /* write the outer walls, if appropriate. */ 95 /* write the outer walls, if appropriate. */
93 if (!(option & RMOPT_WALL_OFF)) 96 if (!(option & RMOPT_WALL_OFF))
94 { 97 maze->border ();
95 for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#';
96 for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#';
97 };
98 98
99 if (option & RMOPT_WALLS_ONLY) 99 if (option & RMOPT_WALLS_ONLY)
100 return maze; 100 return;
101 101
102 /* pick off the mutually exclusive options */ 102 /* pick off the mutually exclusive options */
103 if (option & RMOPT_BOTTOM_R) 103 if (option & RMOPT_BOTTOM_R)
104 bottom_right_centered_onion (maze, xsize, ysize, option, layers); 104 bottom_right_centered_onion (maze, xsize, ysize, option, layers);
105 else if (option & RMOPT_BOTTOM_C) 105 else if (option & RMOPT_BOTTOM_C)
106 bottom_centered_onion (maze, xsize, ysize, option, layers); 106 bottom_centered_onion (maze, xsize, ysize, option, layers);
107 else if (option & RMOPT_CENTERED) 107 else if (option & RMOPT_CENTERED)
108 centered_onion (maze, xsize, ysize, option, layers); 108 centered_onion (maze, xsize, ysize, option, layers);
109
110 return maze;
111} 109}
112 110
113void 111void
114centered_onion (char **maze, int xsize, int ysize, int option, int layers) 112centered_onion (char **maze, int xsize, int ysize, int option, int layers)
115{ 113{
122 120
123 if (layers > maxlayers) 121 if (layers > maxlayers)
124 layers = maxlayers; 122 layers = maxlayers;
125 123
126 if (layers == 0) 124 if (layers == 0)
127 layers = rndm (maxlayers) + 1; 125 layers = rmg_rndm (maxlayers) + 1;
128 126
129 float *xlocations = salloc0<float> (2 * layers); 127 float *xlocations = salloc0<float> (2 * layers);
130 float *ylocations = salloc0<float> (2 * layers); 128 float *ylocations = salloc0<float> (2 * layers);
131 129
132 /* place all the walls */ 130 /* place all the walls */
142 for (i = 0; i < 2 * layers; i++) 140 for (i = 0; i < 2 * layers; i++)
143 { 141 {
144 float xpitch = 2, ypitch = 2; 142 float xpitch = 2, ypitch = 2;
145 143
146 if (x_spaces_available > 0) 144 if (x_spaces_available > 0)
147 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; 145 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
148 146
149 if (y_spaces_available > 0) 147 if (y_spaces_available > 0)
150 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; 148 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
151 149
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);
194 192
195 if (layers > maxlayers) 193 if (layers > maxlayers)
196 layers = maxlayers; 194 layers = maxlayers;
197 195
198 if (layers == 0) 196 if (layers == 0)
199 layers = rndm (maxlayers) + 1; 197 layers = rmg_rndm (maxlayers) + 1;
200 198
201 float *xlocations = salloc0<float> (2 * layers); 199 float *xlocations = salloc0<float> (2 * layers);
202 float *ylocations = salloc0<float> (2 * layers); 200 float *ylocations = salloc0<float> (2 * layers);
203 201
204 /* place all the walls */ 202 /* place all the walls */
214 for (i = 0; i < 2 * layers; i++) 212 for (i = 0; i < 2 * layers; i++)
215 { 213 {
216 float xpitch = 2, ypitch = 2; 214 float xpitch = 2, ypitch = 2;
217 215
218 if (x_spaces_available > 0) 216 if (x_spaces_available > 0)
219 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; 217 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
220 218
221 if (y_spaces_available > 0) 219 if (y_spaces_available > 0)
222 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; 220 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
223 221
224 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 222 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
225 223
226 if (i < layers) 224 if (i < layers)
227 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 225 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
311 309
312 if (layers <= 0) 310 if (layers <= 0)
313 return; 311 return;
314 312
315 /* pick which wall will have a door. */ 313 /* pick which wall will have a door. */
316 which_wall = rndm (freedoms) + 1; 314 which_wall = rmg_rndm (freedoms) + 1;
317 for (l = 0; l < layers; l++) 315 for (l = 0; l < layers; l++)
318 { 316 {
319 if (options & RMOPT_LINEAR) 317 if (options & RMOPT_LINEAR)
320 { /* linear door placement. */ 318 { /* linear door placement. */
321 switch (which_wall) 319 switch (which_wall)
346 } 344 }
347 } 345 }
348 } 346 }
349 else 347 else
350 { /* random door placement. */ 348 { /* random door placement. */
351 which_wall = rndm (freedoms) + 1; 349 which_wall = rmg_rndm (freedoms) + 1;
352 switch (which_wall) 350 switch (which_wall)
353 { 351 {
354 case 1: 352 case 1:
355 { /* left hand wall */ 353 { /* left hand wall */
356 x1 = (int) xlocations[l]; 354 x1 = (int) xlocations[l];
357 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 355 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
358 if (y2 > 0) 356 if (y2 > 0)
359 y1 = (int) (ylocations[l] + rndm (y2) + 1); 357 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
360 else 358 else
361 y1 = (int) (ylocations[l] + 1); 359 y1 = (int) (ylocations[l] + 1);
362 break; 360 break;
363 } 361 }
364 case 2: 362 case 2:
365 { /* top wall placement */ 363 { /* top wall placement */
366 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 364 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
367 if (x2 > 0) 365 if (x2 > 0)
368 x1 = (int) (xlocations[l] + rndm (x2) + 1); 366 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
369 else 367 else
370 x1 = (int) (xlocations[l] + 1); 368 x1 = (int) (xlocations[l] + 1);
371 y1 = (int) ylocations[l]; 369 y1 = (int) ylocations[l];
372 break; 370 break;
373 } 371 }
374 case 3: 372 case 3:
375 { /* right wall placement */ 373 { /* right wall placement */
376 x1 = (int) xlocations[2 * layers - l - 1]; 374 x1 = (int) xlocations[2 * layers - l - 1];
377 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 375 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
378 if (y2 > 0) 376 if (y2 > 0)
379 y1 = (int) (ylocations[l] + rndm (y2) + 1); 377 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
380 else 378 else
381 y1 = (int) (ylocations[l] + 1); 379 y1 = (int) (ylocations[l] + 1);
382 380
383 break; 381 break;
384 } 382 }
385 case 4: 383 case 4:
386 { /* bottom wall placement */ 384 { /* bottom wall placement */
387 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 385 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
388 if (x2 > 0) 386 if (x2 > 0)
389 x1 = (int) (xlocations[l] + rndm (x2) + 1); 387 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
390 else 388 else
391 x1 = (int) (xlocations[l] + 1); 389 x1 = (int) (xlocations[l] + 1);
392 y1 = (int) ylocations[2 * layers - l - 1]; 390 y1 = (int) ylocations[2 * layers - l - 1];
393 break; 391 break;
394 } 392 }
422 420
423 if (layers > maxlayers) 421 if (layers > maxlayers)
424 layers = maxlayers; 422 layers = maxlayers;
425 423
426 if (layers == 0) 424 if (layers == 0)
427 layers = rndm (maxlayers) + 1; 425 layers = rmg_rndm (maxlayers) + 1;
428 426
429 float *xlocations = salloc0<float> (2 * layers); 427 float *xlocations = salloc0<float> (2 * layers);
430 float *ylocations = salloc0<float> (2 * layers); 428 float *ylocations = salloc0<float> (2 * layers);
431 429
432 /* place all the walls */ 430 /* place all the walls */
443 for (i = 0; i < 2 * layers; i++) 441 for (i = 0; i < 2 * layers; i++)
444 { 442 {
445 float xpitch = 2, ypitch = 2; 443 float xpitch = 2, ypitch = 2;
446 444
447 if (x_spaces_available > 0) 445 if (x_spaces_available > 0)
448 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; 446 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
449 447
450 if (y_spaces_available > 0) 448 if (y_spaces_available > 0)
451 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; 449 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
452 450
453 if (i < layers) 451 if (i < layers)
454 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 452 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
455 else 453 else
456 xlocations[i] = xsize - 1; 454 xlocations[i] = xsize - 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines