ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.C
Revision: 1.29
Committed: Wed Nov 16 23:42:02 2016 UTC (7 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.28: +1 -1 lines
Log Message:
copyright update 2016

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.11 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.28 *
4 root 1.29 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.18 * Copyright (©) 1994 Mark Wedel
6     * Copyright (©) 1992 Frank Tore Johansen
7 root 1.28 *
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 root 1.28 *
13 pippijn 1.7 * 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 root 1.28 *
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.28 *
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 root 1.24 #include <rmg.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     float parm = 0;
49     float x = 0, y = 0;
50     int ic, jc;
51     float SizeX, SizeY;
52     float xscale, yscale;
53 elmex 1.1
54 root 1.13 /* slightly easier to fill and then cut */
55 root 1.21 maze.fill ('#');
56 elmex 1.1
57 root 1.21 int xsize = maze.w;
58     int ysize = maze.h;
59 root 1.2
60     ic = xsize / 2;
61     jc = ysize / 2;
62     SizeX = xsize / 2 - 2;
63     SizeY = ysize / 2 - 2;
64 elmex 1.1
65     /* select random options if necessary */
66 root 1.2 if (option == 0)
67 root 1.15 option = rmg_rndm (MAX_SPIRAL_OPT);
68 elmex 1.1
69 root 1.2 /* the order in which these are evaluated matters */
70 elmex 1.1
71     /* the following two are mutually exclusive.
72     pick one if they're both set. */
73 root 1.2 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
74 elmex 1.1 {
75     /* unset REGULAR_SPIRAL half the time */
76 root 1.15 if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
77 elmex 1.1 option -= REGULAR_SPIRAL;
78     else
79     option -= FIT_SPIRAL;
80     }
81    
82 root 1.2 xscale = yscale = MAX_FINE; /* fine spiral */
83    
84 elmex 1.1 /* choose the spiral pitch */
85 root 1.2 if (!(option & FINE_SPIRAL))
86     {
87 root 1.15 float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
88 root 1.2
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 root 1.17 float scale = min (xscale, yscale);
103 root 1.2
104     xscale = yscale = scale;
105     }
106 elmex 1.1
107     /* cut out the spiral */
108 root 1.2 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
109 elmex 1.1 {
110 root 1.2 x = parm * cos (parm) * xscale;
111     y = parm * sin (parm) * yscale;
112 root 1.12 maze[int (ic + x)][int (jc + y)] = '\0';
113 root 1.2 parm += 0.01;
114 root 1.13 }
115 root 1.2
116 root 1.12 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
117 elmex 1.1
118     /* cut out the center in a 2x2 and place the center and downexit */
119 root 1.2 maze[ic][jc + 1] = '>';
120     maze[ic][jc] = 'C';
121 elmex 1.1 }
122