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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines