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, 5 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

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