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.14 by root, Mon Apr 14 22:41:17 2008 UTC vs.
Revision 1.22 by root, Fri Mar 26 01:04:44 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
65void 64void
66map_gen_onion (Maze maze, 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 int xsize = maze->w; 69 int xsize = maze->w;
71 int ysize = maze->h; 70 int ysize = maze->h;
73 maze->clear (); 72 maze->clear ();
74 73
75 /* pick some random options if option = 0 */ 74 /* pick some random options if option = 0 */
76 if (option == 0) 75 if (option == 0)
77 { 76 {
78 switch (rndm (3)) 77 switch (rmg_rndm (3))
79 { 78 {
80 case 0: 79 case 0:
81 option |= RMOPT_CENTERED; 80 option |= RMOPT_CENTERED;
82 break; 81 break;
83 case 1: 82 case 1:
86 case 2: 85 case 2:
87 option |= RMOPT_BOTTOM_R; 86 option |= RMOPT_BOTTOM_R;
88 break; 87 break;
89 } 88 }
90 89
91 if (rndm (2)) option |= RMOPT_LINEAR; 90 if (rmg_rndm (2)) option |= RMOPT_LINEAR;
92 if (rndm (2)) option |= RMOPT_IRR_SPACE; 91 if (rmg_rndm (2)) option |= RMOPT_IRR_SPACE;
93 } 92 }
94 93
95 /* write the outer walls, if appropriate. */ 94 /* write the outer walls, if appropriate. */
96 if (!(option & RMOPT_WALL_OFF)) 95 if (!(option & RMOPT_WALL_OFF))
97 maze->border (); 96 maze->border ();
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} 108}
110 109
111void 110static void
112centered_onion (char **maze, int xsize, int ysize, int option, int layers) 111centered_onion (char **maze, int xsize, int ysize, int option, int layers)
113{ 112{
114 int i, maxlayers; 113 int i, maxlayers;
115 114
116 maxlayers = (MIN (xsize, ysize) - 2) / 5; 115 maxlayers = (min (xsize, ysize) - 2) / 5;
117 116
118 if (!maxlayers) 117 if (!maxlayers)
119 return; /* map too small to onionize */ 118 return; /* map too small to onionize */
120 119
121 if (layers > maxlayers) 120 if (layers > maxlayers)
122 layers = maxlayers; 121 layers = maxlayers;
123 122
124 if (layers == 0) 123 if (layers == 0)
125 layers = rndm (maxlayers) + 1; 124 layers = rmg_rndm (maxlayers) + 1;
126 125
127 float *xlocations = salloc0<float> (2 * layers); 126 float *xlocations = salloc0<float> (2 * layers);
128 float *ylocations = salloc0<float> (2 * layers); 127 float *ylocations = salloc0<float> (2 * layers);
129 128
130 /* place all the walls */ 129 /* place all the walls */
140 for (i = 0; i < 2 * layers; i++) 139 for (i = 0; i < 2 * layers; i++)
141 { 140 {
142 float xpitch = 2, ypitch = 2; 141 float xpitch = 2, ypitch = 2;
143 142
144 if (x_spaces_available > 0) 143 if (x_spaces_available > 0)
145 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;
146 145
147 if (y_spaces_available > 0) 146 if (y_spaces_available > 0)
148 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;
149 148
150 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 149 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
151 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 150 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
152 x_spaces_available -= (int) (xpitch - 2); 151 x_spaces_available -= (int) (xpitch - 2);
153 y_spaces_available -= (int) (ypitch - 2); 152 y_spaces_available -= (int) (ypitch - 2);
178 177
179 sfree (xlocations, 2 * layers); 178 sfree (xlocations, 2 * layers);
180 sfree (ylocations, 2 * layers); 179 sfree (ylocations, 2 * layers);
181} 180}
182 181
183void 182static void
184bottom_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)
185{ 184{
186 int i, maxlayers; 185 int i, maxlayers;
187 186
188 maxlayers = (MIN (xsize, ysize) - 2) / 5; 187 maxlayers = (min (xsize, ysize) - 2) / 5;
189 188
190 if (!maxlayers) 189 if (!maxlayers)
191 return; /* map too small to onionize */ 190 return; /* map too small to onionize */
192 191
193 if (layers > maxlayers) 192 if (layers > maxlayers)
194 layers = maxlayers; 193 layers = maxlayers;
195 194
196 if (layers == 0) 195 if (layers == 0)
197 layers = rndm (maxlayers) + 1; 196 layers = rmg_rndm (maxlayers) + 1;
198 197
199 float *xlocations = salloc0<float> (2 * layers); 198 float *xlocations = salloc0<float> (2 * layers);
200 float *ylocations = salloc0<float> (2 * layers); 199 float *ylocations = salloc0<float> (2 * layers);
201 200
202 /* place all the walls */ 201 /* place all the walls */
212 for (i = 0; i < 2 * layers; i++) 211 for (i = 0; i < 2 * layers; i++)
213 { 212 {
214 float xpitch = 2, ypitch = 2; 213 float xpitch = 2, ypitch = 2;
215 214
216 if (x_spaces_available > 0) 215 if (x_spaces_available > 0)
217 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;
218 217
219 if (y_spaces_available > 0) 218 if (y_spaces_available > 0)
220 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;
221 220
222 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 221 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
223 222
224 if (i < layers) 223 if (i < layers)
225 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; 224 ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch;
259 258
260 sfree (xlocations, 2 * layers); 259 sfree (xlocations, 2 * layers);
261 sfree (ylocations, 2 * layers); 260 sfree (ylocations, 2 * layers);
262} 261}
263 262
264/* 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 */
265void 264static void
266draw_onion (char **maze, float *xlocations, float *ylocations, int layers) 265draw_onion (char **maze, float *xlocations, float *ylocations, int layers)
267{ 266{
268 int i, j, l; 267 int i, j, l;
269 268
270 for (l = 0; l < layers; l++) 269 for (l = 0; l < layers; l++)
290 } 289 }
291 290
292 } 291 }
293} 292}
294 293
295void 294static void
296make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options) 295make_doors (char **maze, float *xlocations, float *ylocations, int layers, int options)
297{ 296{
298 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 */
299 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */ 298 int which_wall; /* left, 1, top, 2, right, 3, bottom 4 */
300 int l, x1 = 0, x2, y1 = 0, y2; 299 int l, x1 = 0, x2, y1 = 0, y2;
309 308
310 if (layers <= 0) 309 if (layers <= 0)
311 return; 310 return;
312 311
313 /* pick which wall will have a door. */ 312 /* pick which wall will have a door. */
314 which_wall = rndm (freedoms) + 1; 313 which_wall = rmg_rndm (freedoms) + 1;
315 for (l = 0; l < layers; l++) 314 for (l = 0; l < layers; l++)
316 { 315 {
317 if (options & RMOPT_LINEAR) 316 if (options & RMOPT_LINEAR)
318 { /* linear door placement. */ 317 { /* linear door placement. */
319 switch (which_wall) 318 switch (which_wall)
344 } 343 }
345 } 344 }
346 } 345 }
347 else 346 else
348 { /* random door placement. */ 347 { /* random door placement. */
349 which_wall = rndm (freedoms) + 1; 348 which_wall = rmg_rndm (freedoms) + 1;
350 switch (which_wall) 349 switch (which_wall)
351 { 350 {
352 case 1: 351 case 1:
353 { /* left hand wall */ 352 { /* left hand wall */
354 x1 = (int) xlocations[l]; 353 x1 = (int) xlocations[l];
355 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); 354 y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1);
356 if (y2 > 0) 355 if (y2 > 0)
357 y1 = (int) (ylocations[l] + rndm (y2) + 1); 356 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
358 else 357 else
359 y1 = (int) (ylocations[l] + 1); 358 y1 = (int) (ylocations[l] + 1);
360 break; 359 break;
361 } 360 }
362 case 2: 361 case 2:
363 { /* top wall placement */ 362 { /* top wall placement */
364 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 363 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
365 if (x2 > 0) 364 if (x2 > 0)
366 x1 = (int) (xlocations[l] + rndm (x2) + 1); 365 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
367 else 366 else
368 x1 = (int) (xlocations[l] + 1); 367 x1 = (int) (xlocations[l] + 1);
369 y1 = (int) ylocations[l]; 368 y1 = (int) ylocations[l];
370 break; 369 break;
371 } 370 }
372 case 3: 371 case 3:
373 { /* right wall placement */ 372 { /* right wall placement */
374 x1 = (int) xlocations[2 * layers - l - 1]; 373 x1 = (int) xlocations[2 * layers - l - 1];
375 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; 374 y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1;
376 if (y2 > 0) 375 if (y2 > 0)
377 y1 = (int) (ylocations[l] + rndm (y2) + 1); 376 y1 = (int) (ylocations[l] + rmg_rndm (y2) + 1);
378 else 377 else
379 y1 = (int) (ylocations[l] + 1); 378 y1 = (int) (ylocations[l] + 1);
380 379
381 break; 380 break;
382 } 381 }
383 case 4: 382 case 4:
384 { /* bottom wall placement */ 383 { /* bottom wall placement */
385 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; 384 x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1;
386 if (x2 > 0) 385 if (x2 > 0)
387 x1 = (int) (xlocations[l] + rndm (x2) + 1); 386 x1 = (int) (xlocations[l] + rmg_rndm (x2) + 1);
388 else 387 else
389 x1 = (int) (xlocations[l] + 1); 388 x1 = (int) (xlocations[l] + 1);
390 y1 = (int) ylocations[2 * layers - l - 1]; 389 y1 = (int) ylocations[2 * layers - l - 1];
391 break; 390 break;
392 } 391 }
406 y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2; 405 y1 = (int) (ylocations[l] + ylocations[2 * layers - l - 1]) / 2;
407 406
408 maze[x1][y1] = 'C'; 407 maze[x1][y1] = 'C';
409} 408}
410 409
411void 410static void
412bottom_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)
413{ 412{
414 int i, maxlayers; 413 int i, maxlayers;
415 414
416 maxlayers = (MIN (xsize, ysize) - 2) / 5; 415 maxlayers = (min (xsize, ysize) - 2) / 5;
417 416
418 if (!maxlayers) 417 if (!maxlayers)
419 return; /* map too small to onionize */ 418 return; /* map too small to onionize */
420 419
421 if (layers > maxlayers) 420 if (layers > maxlayers)
422 layers = maxlayers; 421 layers = maxlayers;
423 422
424 if (layers == 0) 423 if (layers == 0)
425 layers = rndm (maxlayers) + 1; 424 layers = rmg_rndm (maxlayers) + 1;
426 425
427 float *xlocations = salloc0<float> (2 * layers); 426 float *xlocations = salloc0<float> (2 * layers);
428 float *ylocations = salloc0<float> (2 * layers); 427 float *ylocations = salloc0<float> (2 * layers);
429 428
430 /* place all the walls */ 429 /* place all the walls */
441 for (i = 0; i < 2 * layers; i++) 440 for (i = 0; i < 2 * layers; i++)
442 { 441 {
443 float xpitch = 2, ypitch = 2; 442 float xpitch = 2, ypitch = 2;
444 443
445 if (x_spaces_available > 0) 444 if (x_spaces_available > 0)
446 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;
447 446
448 if (y_spaces_available > 0) 447 if (y_spaces_available > 0)
449 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;
450 449
451 if (i < layers) 450 if (i < layers)
452 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; 451 xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch;
453 else 452 else
454 xlocations[i] = xsize - 1; 453 xlocations[i] = xsize - 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines