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.24 by root, Fri Jul 2 15:03:57 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* The onion room generator: 25/* The onion room generator:
49*/ 50*/
50 51
51 52
52#include <global.h> 53#include <global.h>
53#include <random_map.h> 54#include <random_map.h>
55#include <rproto.h>
54 56
55#ifndef MIN
56# define MIN(x,y) (((x)<(y))? (x):(y))
57#endif
58void centered_onion (char **maze, int xsize, int ysize, int option, int layers); 57static void 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); 58static void bottom_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); 59static void bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers);
61 60
62void draw_onion (char **maze, float *xlocations, float *ylocations, int layers); 61static void draw_onion (char **maze, float *xlocations, float *ylocations, int layers);
63void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options); 62static void make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options);
64 63
65Maze 64void
66map_gen_onion (int xsize, int ysize, int option, int layers) 65map_gen_onion (layout &maze, int option, int layers)
67{ 66{
68 int i, j; 67 int i, j;
69 68
70 Maze maze (xsize, ysize); 69 int xsize = maze.w;
70 int ysize = maze.h;
71
72 maze.clear ();
71 73
72 /* pick some random options if option = 0 */ 74 /* pick some random options if option = 0 */
73 if (option == 0) 75 if (option == 0)
74 { 76 {
75 switch (rndm (3)) 77 switch (rmg_rndm (3))
76 { 78 {
77 case 0: 79 case 0:
78 option |= RMOPT_CENTERED; 80 option |= RMOPT_CENTERED;
79 break; 81 break;
80 case 1: 82 case 1:
83 case 2: 85 case 2:
84 option |= RMOPT_BOTTOM_R; 86 option |= RMOPT_BOTTOM_R;
85 break; 87 break;
86 } 88 }
87 89
88 if (rndm (2)) option |= RMOPT_LINEAR; 90 if (rmg_rndm (2)) option |= RMOPT_LINEAR;
89 if (rndm (2)) option |= RMOPT_IRR_SPACE; 91 if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE;
90 } 92 }
91 93
92 /* write the outer walls, if appropriate. */ 94 /* write the outer walls, if appropriate. */
93 if (!(option & RMOPT_WALL_OFF)) 95 if (!(option & RMOPT_WALL_OFF))
94 { 96 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 97
99 if (option & RMOPT_WALLS_ONLY) 98 if (option & RMOPT_WALLS_ONLY)
100 return maze; 99 return;
101 100
102 /* pick off the mutually exclusive options */ 101 /* pick off the mutually exclusive options */
103 if (option & RMOPT_BOTTOM_R) 102 if (option & RMOPT_BOTTOM_R)
104 bottom_right_centered_onion (maze, xsize, ysize, option, layers); 103 bottom_right_centered_onion (maze, xsize, ysize, option, layers);
105 else if (option & RMOPT_BOTTOM_C) 104 else if (option & RMOPT_BOTTOM_C)
106 bottom_centered_onion (maze, xsize, ysize, option, layers); 105 bottom_centered_onion (maze, xsize, ysize, option, layers);
107 else if (option & RMOPT_CENTERED) 106 else if (option & RMOPT_CENTERED)
108 centered_onion (maze, xsize, ysize, option, layers); 107 centered_onion (maze, xsize, ysize, option, layers);
109
110 return maze;
111} 108}
112 109
113void 110static void
114centered_onion (char **maze, int xsize, int ysize, int option, int layers) 111centered_onion (char **maze, int xsize, int ysize, int option, int layers)
115{ 112{
116 int i, maxlayers; 113 int i, maxlayers;
117 114
118 maxlayers = (MIN (xsize, ysize) - 2) / 5; 115 maxlayers = (min (xsize, ysize) - 2) / 5;
119 116
120 if (!maxlayers) 117 if (!maxlayers)
121 return; /* map too small to onionize */ 118 return; /* map too small to onionize */
122 119
123 if (layers > maxlayers) 120 if (layers > maxlayers)
124 layers = maxlayers; 121 layers = maxlayers;
125 122
126 if (layers == 0) 123 if (layers == 0)
127 layers = rndm (maxlayers) + 1; 124 layers = rmg_rndm (maxlayers) + 1;
128 125
129 float *xlocations = salloc0<float> (2 * layers); 126 float *xlocations = salloc0<float> (2 * layers);
130 float *ylocations = salloc0<float> (2 * layers); 127 float *ylocations = salloc0<float> (2 * layers);
131 128
132 /* place all the walls */ 129 /* place all the walls */
142 for (i = 0; i < 2 * layers; i++) 139 for (i = 0; i < 2 * layers; i++)
143 { 140 {
144 float xpitch = 2, ypitch = 2; 141 float xpitch = 2, ypitch = 2;
145 142
146 if (x_spaces_available > 0) 143 if (x_spaces_available > 0)
147 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; 144 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
148 145
149 if (y_spaces_available > 0) 146 if (y_spaces_available > 0)
150 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; 147 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
151 148
152 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 149 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
153 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 150 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
154 x_spaces_available -= (int) (xpitch - 2); 151 x_spaces_available -= (int) (xpitch - 2);
155 y_spaces_available -= (int) (ypitch - 2); 152 y_spaces_available -= (int) (ypitch - 2);
180 177
181 sfree (xlocations, 2 * layers); 178 sfree (xlocations, 2 * layers);
182 sfree (ylocations, 2 * layers); 179 sfree (ylocations, 2 * layers);
183} 180}
184 181
185void 182static void
186bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers) 183bottom_centered_onion (char **maze, int xsize, int ysize, int option, int layers)
187{ 184{
188 int i, maxlayers; 185 int i, maxlayers;
189 186
190 maxlayers = (MIN (xsize, ysize) - 2) / 5; 187 maxlayers = (min (xsize, ysize) - 2) / 5;
191 188
192 if (!maxlayers) 189 if (!maxlayers)
193 return; /* map too small to onionize */ 190 return; /* map too small to onionize */
194 191
195 if (layers > maxlayers) 192 if (layers > maxlayers)
196 layers = maxlayers; 193 layers = maxlayers;
197 194
198 if (layers == 0) 195 if (layers == 0)
199 layers = rndm (maxlayers) + 1; 196 layers = rmg_rndm (maxlayers) + 1;
200 197
201 float *xlocations = salloc0<float> (2 * layers); 198 float *xlocations = salloc0<float> (2 * layers);
202 float *ylocations = salloc0<float> (2 * layers); 199 float *ylocations = salloc0<float> (2 * layers);
203 200
204 /* place all the walls */ 201 /* place all the walls */
214 for (i = 0; i < 2 * layers; i++) 211 for (i = 0; i < 2 * layers; i++)
215 { 212 {
216 float xpitch = 2, ypitch = 2; 213 float xpitch = 2, ypitch = 2;
217 214
218 if (x_spaces_available > 0) 215 if (x_spaces_available > 0)
219 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; 216 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
220 217
221 if (y_spaces_available > 0) 218 if (y_spaces_available > 0)
222 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; 219 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
223 220
224 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 221 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
225 222
226 if (i < layers) 223 if (i < layers)
227 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 224 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
261 258
262 sfree (xlocations, 2 * layers); 259 sfree (xlocations, 2 * layers);
263 sfree (ylocations, 2 * layers); 260 sfree (ylocations, 2 * layers);
264} 261}
265 262
266/* draw_boxes: draws the lines in the maze defining the onion layers */ 263/* draw_boxes: draws the lines in the maze defining the onion layers */
267void 264static void
268draw_onion (char **maze, float *xlocations, float *ylocations, int layers) 265draw_onion (char **maze, float *xlocations, float *ylocations, int layers)
269{ 266{
270 int i, j, l; 267 int i, j, l;
271 268
272 for (l = 0; l < layers; l++) 269 for (l = 0; l < layers; l++)
292 } 289 }
293 290
294 } 291 }
295} 292}
296 293
297void 294static void
298make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) 295make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options)
299{ 296{
300 int freedoms; /* number of different walls on which we could place a door */ 297 int freedoms; /* number of different walls on which we could place a door */
301 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ 298 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */
302 int l, x1 = 0, x2, y1 = 0, y2; 299 int l, x1 = 0, x2, y1 = 0, y2;
311 308
312 if (layers <= 0) 309 if (layers <= 0)
313 return; 310 return;
314 311
315 /* pick which wall will have a door. */ 312 /* pick which wall will have a door. */
316 which_wall = rndm (freedoms) + 1; 313 which_wall = rmg_rndm (freedoms) + 1;
317 for (l = 0; l < layers; l++) 314 for (l = 0; l < layers; l++)
318 { 315 {
319 if (options & RMOPT_LINEAR) 316 if (options & RMOPT_LINEAR)
320 { /* linear door placement. */ 317 { /* linear door placement. */
321 switch (which_wall) 318 switch (which_wall)
346 } 343 }
347 } 344 }
348 } 345 }
349 else 346 else
350 { /* random door placement. */ 347 { /* random door placement. */
351 which_wall = rndm (freedoms) + 1; 348 which_wall = rmg_rndm (freedoms) + 1;
352 switch (which_wall) 349 switch (which_wall)
353 { 350 {
354 case 1: 351 case 1:
355 { /* left hand wall */ 352 { /* left hand wall */
356 x1 = (int) xlocations[l]; 353 x1 = (int) xlocations[l];
357 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 354 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
358 if (y2 > 0) 355 if (y2 > 0)
359 y1 = (int) (ylocations[l] + rndm (y2) + 1); 356 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
360 else 357 else
361 y1 = (int) (ylocations[l] + 1); 358 y1 = (int) (ylocations[l] + 1);
362 break; 359 break;
363 } 360 }
364 case 2: 361 case 2:
365 { /* top wall placement */ 362 { /* top wall placement */
366 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 363 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
367 if (x2 > 0) 364 if (x2 > 0)
368 x1 = (int) (xlocations[l] + rndm (x2) + 1); 365 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
369 else 366 else
370 x1 = (int) (xlocations[l] + 1); 367 x1 = (int) (xlocations[l] + 1);
371 y1 = (int) ylocations[l]; 368 y1 = (int) ylocations[l];
372 break; 369 break;
373 } 370 }
374 case 3: 371 case 3:
375 { /* right wall placement */ 372 { /* right wall placement */
376 x1 = (int) xlocations[2 * layers - l - 1]; 373 x1 = (int) xlocations[2 * layers - l - 1];
377 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 374 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
378 if (y2 > 0) 375 if (y2 > 0)
379 y1 = (int) (ylocations[l] + rndm (y2) + 1); 376 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
380 else 377 else
381 y1 = (int) (ylocations[l] + 1); 378 y1 = (int) (ylocations[l] + 1);
382 379
383 break; 380 break;
384 } 381 }
385 case 4: 382 case 4:
386 { /* bottom wall placement */ 383 { /* bottom wall placement */
387 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 384 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
388 if (x2 > 0) 385 if (x2 > 0)
389 x1 = (int) (xlocations[l] + rndm (x2) + 1); 386 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
390 else 387 else
391 x1 = (int) (xlocations[l] + 1); 388 x1 = (int) (xlocations[l] + 1);
392 y1 = (int) ylocations[2 * layers - l - 1]; 389 y1 = (int) ylocations[2 * layers - l - 1];
393 break; 390 break;
394 } 391 }
408 y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; 405 y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2;
409 406
410 maze[x1][y1] = 'C'; 407 maze[x1][y1] = 'C';
411} 408}
412 409
413void 410static void
414bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers) 411bottom_right_centered_onion (char **maze, int xsize, int ysize, int option, int layers)
415{ 412{
416 int i, maxlayers; 413 int i, maxlayers;
417 414
418 maxlayers = (MIN (xsize, ysize) - 2) / 5; 415 maxlayers = (min (xsize, ysize) - 2) / 5;
419 416
420 if (!maxlayers) 417 if (!maxlayers)
421 return; /* map too small to onionize */ 418 return; /* map too small to onionize */
422 419
423 if (layers > maxlayers) 420 if (layers > maxlayers)
424 layers = maxlayers; 421 layers = maxlayers;
425 422
426 if (layers == 0) 423 if (layers == 0)
427 layers = rndm (maxlayers) + 1; 424 layers = rmg_rndm (maxlayers) + 1;
428 425
429 float *xlocations = salloc0<float> (2 * layers); 426 float *xlocations = salloc0<float> (2 * layers);
430 float *ylocations = salloc0<float> (2 * layers); 427 float *ylocations = salloc0<float> (2 * layers);
431 428
432 /* place all the walls */ 429 /* place all the walls */
443 for (i = 0; i < 2 * layers; i++) 440 for (i = 0; i < 2 * layers; i++)
444 { 441 {
445 float xpitch = 2, ypitch = 2; 442 float xpitch = 2, ypitch = 2;
446 443
447 if (x_spaces_available > 0) 444 if (x_spaces_available > 0)
448 xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; 445 xpitch = 2 + (rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available) + rmg_rndm (x_spaces_available)) / 3;
449 446
450 if (y_spaces_available > 0) 447 if (y_spaces_available > 0)
451 ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; 448 ypitch = 2 + (rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available) + rmg_rndm (y_spaces_available)) / 3;
452 449
453 if (i < layers) 450 if (i < layers)
454 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 451 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
455 else 452 else
456 xlocations[i] = xsize - 1; 453 xlocations[i] = xsize - 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines