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.16 by root, Sun May 4 14:12:37 2008 UTC vs.
Revision 1.25 by root, Sun Aug 22 20:23:06 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:
48 49
49*/ 50*/
50 51
51 52
52#include <global.h> 53#include <global.h>
53#include <random_map.h> 54#include <rmg.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 (Layout 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;
72 71
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 (rmg_rndm (3)) 77 switch (rmg_rndm (3))
92 if (rmg_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 ();
98 97
99 if (option & RMOPT_WALLS_ONLY) 98 if (option & RMOPT_WALLS_ONLY)
100 return; 99 return;
101 100
102 /* pick off the mutually exclusive options */ 101 /* pick off the mutually exclusive options */
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)
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)
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;
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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines