ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.C
Revision: 1.21
Committed: Thu Jul 1 01:22:44 2010 UTC (13 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.20: +4 -93 lines
Log Message:
got rid of Layout, better memory management etc.

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 1994 Mark Wedel
6 * Copyright (©) 1992 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */
24
25 /* The onion room generator:
26 Onion rooms are like this:
27
28 char **map_gen_spiral(int xsize, int ysize, int option);
29 */
30
31 #include <global.h>
32 #include <random_map.h>
33 #include <rproto.h>
34
35 #define RANDOM_OPTIONS 0 /* Pick random options below */
36 #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */
37 #define FINE_SPIRAL 2 /* uses the min. separation: most coiling */
38 #define FIT_SPIRAL 4 /* scale to a rectangular region, not square */
39 #define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */
40
41 #define MINDIST 3
42
43 #define MAX_FINE .454545
44
45 extern int surround_check (char **maze, int i, int j, int xsize, int ysize);
46
47 void
48 map_gen_spiral (Layout &maze, int option)
49 {
50 int i, j;
51 float parm = 0;
52 float x = 0, y = 0;
53 int ic, jc;
54 float SizeX, SizeY;
55 float xscale, yscale;
56
57 /* slightly easier to fill and then cut */
58 maze.fill ('#');
59
60 int xsize = maze.w;
61 int ysize = maze.h;
62
63 ic = xsize / 2;
64 jc = ysize / 2;
65 SizeX = xsize / 2 - 2;
66 SizeY = ysize / 2 - 2;
67
68 /* select random options if necessary */
69 if (option == 0)
70 option = rmg_rndm (MAX_SPIRAL_OPT);
71
72 /* the order in which these are evaluated matters */
73
74 /* the following two are mutually exclusive.
75 pick one if they're both set. */
76 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
77 {
78 /* unset REGULAR_SPIRAL half the time */
79 if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
80 option -= REGULAR_SPIRAL;
81 else
82 option -= FIT_SPIRAL;
83 }
84
85 xscale = yscale = MAX_FINE; /* fine spiral */
86
87 /* choose the spiral pitch */
88 if (!(option & FINE_SPIRAL))
89 {
90 float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
91
92 xscale = yscale = pitch;
93 }
94
95 if ((option & FIT_SPIRAL) && (xsize != ysize))
96 {
97 if (xsize > ysize)
98 xscale *= (float) xsize / (float) ysize;
99 else
100 yscale *= (float) ysize / (float) xsize;
101 }
102
103 if (option & REGULAR_SPIRAL)
104 {
105 float scale = min (xscale, yscale);
106
107 xscale = yscale = scale;
108 }
109
110 /* cut out the spiral */
111 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
112 {
113 x = parm * cos (parm) * xscale;
114 y = parm * sin (parm) * yscale;
115 maze[int (ic + x)][int (jc + y)] = '\0';
116 parm += 0.01;
117 }
118
119 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
120
121 /* cut out the center in a 2x2 and place the center and downexit */
122 maze[ic][jc + 1] = '>';
123 maze[ic][jc] = 'C';
124 }
125