ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.C
Revision: 1.30
Committed: Sun Jan 29 02:47:05 2017 UTC (7 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.29: +1 -1 lines
Log Message:
remove eol whitespace

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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 <rmg.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 void
46 map_gen_spiral (layout &maze, int option)
47 {
48 float parm = 0;
49 float x = 0, y = 0;
50 int ic, jc;
51 float SizeX, SizeY;
52 float xscale, yscale;
53
54 /* slightly easier to fill and then cut */
55 maze.fill ('#');
56
57 int xsize = maze.w;
58 int ysize = maze.h;
59
60 ic = xsize / 2;
61 jc = ysize / 2;
62 SizeX = xsize / 2 - 2;
63 SizeY = ysize / 2 - 2;
64
65 /* select random options if necessary */
66 if (option == 0)
67 option = rmg_rndm (MAX_SPIRAL_OPT);
68
69 /* the order in which these are evaluated matters */
70
71 /* the following two are mutually exclusive.
72 pick one if they're both set. */
73 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
74 {
75 /* unset REGULAR_SPIRAL half the time */
76 if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
77 option -= REGULAR_SPIRAL;
78 else
79 option -= FIT_SPIRAL;
80 }
81
82 xscale = yscale = MAX_FINE; /* fine spiral */
83
84 /* choose the spiral pitch */
85 if (!(option & FINE_SPIRAL))
86 {
87 float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
88
89 xscale = yscale = pitch;
90 }
91
92 if ((option & FIT_SPIRAL) && (xsize != ysize))
93 {
94 if (xsize > ysize)
95 xscale *= (float) xsize / (float) ysize;
96 else
97 yscale *= (float) ysize / (float) xsize;
98 }
99
100 if (option & REGULAR_SPIRAL)
101 {
102 float scale = min (xscale, yscale);
103
104 xscale = yscale = scale;
105 }
106
107 /* cut out the spiral */
108 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
109 {
110 x = parm * cos (parm) * xscale;
111 y = parm * sin (parm) * yscale;
112 maze[int (ic + x)][int (jc + y)] = '\0';
113 parm += 0.01;
114 }
115
116 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
117
118 /* cut out the center in a 2x2 and place the center and downexit */
119 maze[ic][jc + 1] = '>';
120 maze[ic][jc] = 'C';
121 }
122