ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.C
Revision: 1.23
Committed: Sun Jul 4 22:12:26 2010 UTC (13 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.22: +0 -2 lines
Log Message:
valgrind power

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.11 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.7 *
4 root 1.19 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.18 * Copyright (©) 1994 Mark Wedel
6     * Copyright (©) 1992 Frank Tore Johansen
7 pippijn 1.7 *
8 root 1.16 * 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 pippijn 1.7 *
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 root 1.10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 pippijn 1.7 * GNU General Public License for more details.
17     *
18 root 1.16 * 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 root 1.10 *
22 root 1.11 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.7 */
24 elmex 1.1
25     /* The onion room generator:
26     Onion rooms are like this:
27    
28     char **map_gen_spiral(int xsize, int ysize, int option);
29 root 1.14 */
30 elmex 1.1
31     #include <global.h>
32     #include <random_map.h>
33 root 1.17 #include <rproto.h>
34 elmex 1.1
35 root 1.2 #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 elmex 1.1
41     #define MINDIST 3
42    
43     #define MAX_FINE .454545
44    
45 root 1.13 void
46 root 1.22 map_gen_spiral (layout &maze, int option)
47 root 1.2 {
48     int i, j;
49     float parm = 0;
50     float x = 0, y = 0;
51     int ic, jc;
52     float SizeX, SizeY;
53     float xscale, yscale;
54 elmex 1.1
55 root 1.13 /* slightly easier to fill and then cut */
56 root 1.21 maze.fill ('#');
57 elmex 1.1
58 root 1.21 int xsize = maze.w;
59     int ysize = maze.h;
60 root 1.2
61     ic = xsize / 2;
62     jc = ysize / 2;
63     SizeX = xsize / 2 - 2;
64     SizeY = ysize / 2 - 2;
65 elmex 1.1
66     /* select random options if necessary */
67 root 1.2 if (option == 0)
68 root 1.15 option = rmg_rndm (MAX_SPIRAL_OPT);
69 elmex 1.1
70 root 1.2 /* the order in which these are evaluated matters */
71 elmex 1.1
72     /* the following two are mutually exclusive.
73     pick one if they're both set. */
74 root 1.2 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
75 elmex 1.1 {
76     /* unset REGULAR_SPIRAL half the time */
77 root 1.15 if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
78 elmex 1.1 option -= REGULAR_SPIRAL;
79     else
80     option -= FIT_SPIRAL;
81     }
82    
83 root 1.2 xscale = yscale = MAX_FINE; /* fine spiral */
84    
85 elmex 1.1 /* choose the spiral pitch */
86 root 1.2 if (!(option & FINE_SPIRAL))
87     {
88 root 1.15 float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
89 root 1.2
90     xscale = yscale = pitch;
91     }
92    
93     if ((option & FIT_SPIRAL) && (xsize != ysize))
94     {
95     if (xsize > ysize)
96     xscale *= (float) xsize / (float) ysize;
97     else
98     yscale *= (float) ysize / (float) xsize;
99     }
100    
101     if (option & REGULAR_SPIRAL)
102     {
103 root 1.17 float scale = min (xscale, yscale);
104 root 1.2
105     xscale = yscale = scale;
106     }
107 elmex 1.1
108     /* cut out the spiral */
109 root 1.2 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
110 elmex 1.1 {
111 root 1.2 x = parm * cos (parm) * xscale;
112     y = parm * sin (parm) * yscale;
113 root 1.12 maze[int (ic + x)][int (jc + y)] = '\0';
114 root 1.2 parm += 0.01;
115 root 1.13 }
116 root 1.2
117 root 1.12 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
118 elmex 1.1
119     /* cut out the center in a 2x2 and place the center and downexit */
120 root 1.2 maze[ic][jc + 1] = '>';
121     maze[ic][jc] = 'C';
122 elmex 1.1 }
123