ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.C
Revision: 1.31
Committed: Sat Nov 17 23:40:02 2018 UTC (5 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.30: +1 -0 lines
Log Message:
copyright update 2018

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.31 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 root 1.29 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 root 1.18 * Copyright (©) 1994 Mark Wedel
7     * Copyright (©) 1992 Frank Tore Johansen
8 root 1.28 *
9 root 1.16 * Deliantra is free software: you can redistribute it and/or modify it under
10     * the terms of the Affero GNU General Public License as published by the
11     * Free Software Foundation, either version 3 of the License, or (at your
12     * option) any later version.
13 root 1.28 *
14 pippijn 1.7 * This program is distributed in the hope that it will be useful,
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 root 1.10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 pippijn 1.7 * GNU General Public License for more details.
18 root 1.28 *
19 root 1.16 * You should have received a copy of the Affero GNU General Public License
20     * and the GNU General Public License along with this program. If not, see
21     * <http://www.gnu.org/licenses/>.
22 root 1.28 *
23 root 1.11 * The authors can be reached via e-mail to <support@deliantra.net>
24 pippijn 1.7 */
25 elmex 1.1
26     /* The onion room generator:
27     Onion rooms are like this:
28    
29     char **map_gen_spiral(int xsize, int ysize, int option);
30 root 1.14 */
31 elmex 1.1
32     #include <global.h>
33 root 1.24 #include <rmg.h>
34 root 1.17 #include <rproto.h>
35 elmex 1.1
36 root 1.2 #define RANDOM_OPTIONS 0 /* Pick random options below */
37     #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */
38     #define FINE_SPIRAL 2 /* uses the min. separation: most coiling */
39     #define FIT_SPIRAL 4 /* scale to a rectangular region, not square */
40     #define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */
41 elmex 1.1
42     #define MINDIST 3
43    
44     #define MAX_FINE .454545
45    
46 root 1.13 void
47 root 1.22 map_gen_spiral (layout &maze, int option)
48 root 1.2 {
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 root 1.30 /* the following two are mutually exclusive.
73 elmex 1.1 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