ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.C
(Generate patch)

Comparing deliantra/server/random_maps/room_gen_spiral.C (file contents):
Revision 1.13 by root, Mon Apr 14 22:41:17 2008 UTC vs.
Revision 1.30 by root, Sun Jan 29 02:47:05 2017 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 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,2007 Mark Wedel 5 * Copyright (©) 1994 Mark Wedel
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* The onion room generator: 25/* The onion room generator:
25Onion rooms are like this: 26Onion rooms are like this:
26 27
27char **map_gen_spiral(int xsize, int ysize, int option); 28char **map_gen_spiral(int xsize, int ysize, int option);
29*/
28 30
29
30*/
31#include <global.h> 31#include <global.h>
32#include <random_map.h> 32#include <rmg.h>
33#include <rproto.h>
33 34
34#define RANDOM_OPTIONS 0 /* Pick random options below */ 35#define RANDOM_OPTIONS 0 /* Pick random options below */
35#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ 36#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */
36#define FINE_SPIRAL 2 /* uses the min. separation: most coiling */ 37#define FINE_SPIRAL 2 /* uses the min. separation: most coiling */
37#define FIT_SPIRAL 4 /* scale to a rectangular region, not square */ 38#define FIT_SPIRAL 4 /* scale to a rectangular region, not square */
38#define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */ 39#define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */
39#include <math.h>
40
41#ifndef MIN
42# define MIN(x,y) (((x)<(y))? (x):(y))
43#endif
44#ifndef MAX
45# define MAX(x,y) (((x)<(y))? (y):(x))
46#endif
47 40
48#define MINDIST 3 41#define MINDIST 3
49 42
50#define MAX_FINE .454545 43#define MAX_FINE .454545
51 44
52extern int surround_check (char **maze, int i, int j, int xsize, int ysize);
53
54void 45void
55map_gen_spiral (Maze maze, int option) 46map_gen_spiral (layout &maze, int option)
56{ 47{
57 int i, j;
58 float parm = 0; 48 float parm = 0;
59 float x = 0, y = 0; 49 float x = 0, y = 0;
60 int ic, jc; 50 int ic, jc;
61 float SizeX, SizeY; 51 float SizeX, SizeY;
62 float xscale, yscale; 52 float xscale, yscale;
63 53
64 /* slightly easier to fill and then cut */ 54 /* slightly easier to fill and then cut */
65 maze->clear ('#'); 55 maze.fill ('#');
66 56
67 int xsize = maze->w; 57 int xsize = maze.w;
68 int ysize = maze->h; 58 int ysize = maze.h;
69 59
70 ic = xsize / 2; 60 ic = xsize / 2;
71 jc = ysize / 2; 61 jc = ysize / 2;
72 SizeX = xsize / 2 - 2; 62 SizeX = xsize / 2 - 2;
73 SizeY = ysize / 2 - 2; 63 SizeY = ysize / 2 - 2;
74 64
75 /* select random options if necessary */ 65 /* select random options if necessary */
76 if (option == 0) 66 if (option == 0)
77 option = rndm (MAX_SPIRAL_OPT); 67 option = rmg_rndm (MAX_SPIRAL_OPT);
78 68
79 /* the order in which these are evaluated matters */ 69 /* the order in which these are evaluated matters */
80 70
81 /* the following two are mutually exclusive. 71 /* the following two are mutually exclusive.
82 pick one if they're both set. */ 72 pick one if they're both set. */
83 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL)) 73 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
84 { 74 {
85 /* unset REGULAR_SPIRAL half the time */ 75 /* unset REGULAR_SPIRAL half the time */
86 if (rndm (2) && (option & REGULAR_SPIRAL)) 76 if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
87 option -= REGULAR_SPIRAL; 77 option -= REGULAR_SPIRAL;
88 else 78 else
89 option -= FIT_SPIRAL; 79 option -= FIT_SPIRAL;
90 } 80 }
91 81
92 xscale = yscale = MAX_FINE; /* fine spiral */ 82 xscale = yscale = MAX_FINE; /* fine spiral */
93 83
94 /* choose the spiral pitch */ 84 /* choose the spiral pitch */
95 if (!(option & FINE_SPIRAL)) 85 if (!(option & FINE_SPIRAL))
96 { 86 {
97 float pitch = (rndm (5)) / 10. + 10. / 22.; 87 float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
98 88
99 xscale = yscale = pitch; 89 xscale = yscale = pitch;
100 } 90 }
101 91
102 if ((option & FIT_SPIRAL) && (xsize != ysize)) 92 if ((option & FIT_SPIRAL) && (xsize != ysize))
107 yscale *= (float) ysize / (float) xsize; 97 yscale *= (float) ysize / (float) xsize;
108 } 98 }
109 99
110 if (option & REGULAR_SPIRAL) 100 if (option & REGULAR_SPIRAL)
111 { 101 {
112 float scale = MIN (xscale, yscale); 102 float scale = min (xscale, yscale);
113 103
114 xscale = yscale = scale; 104 xscale = yscale = scale;
115 } 105 }
116 106
117 /* cut out the spiral */ 107 /* cut out the spiral */
128 /* cut out the center in a 2x2 and place the center and downexit */ 118 /* cut out the center in a 2x2 and place the center and downexit */
129 maze[ic][jc + 1] = '>'; 119 maze[ic][jc + 1] = '>';
130 maze[ic][jc] = 'C'; 120 maze[ic][jc] = 'C';
131} 121}
132 122
133/* the following function connects disjoint spirals which may
134 result from the symmetrization process. */
135void
136connect_spirals (int xsize, int ysize, int sym, char **layout)
137{
138
139 int i, j, ic = xsize / 2, jc = ysize / 2;
140
141 if (sym == SYMMETRY_X)
142 {
143 layout[ic][jc] = 0;
144 /* go left from map center */
145 for (i = ic - 1, j = jc; i > 0 && layout[i][j] == '#'; i--)
146 layout[i][j] = 0;
147 /* go right */
148 for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++)
149 layout[i][j] = 0;
150 }
151
152 if (sym == SYMMETRY_Y)
153 {
154
155 layout[ic][jc] = 0;
156 /* go up */
157 for (i = ic, j = jc - 1; j > 0 && layout[i][j] == '#'; j--)
158 layout[i][j] = 0;
159 /* go down */
160 for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++)
161 layout[i][j] = 0;
162 }
163
164 if (sym == SYMMETRY_XY)
165 {
166 /* go left from map center */
167 layout[ic][jc / 2] = 0;
168 layout[ic / 2][jc] = 0;
169 layout[ic][jc / 2 + jc] = 0;
170 layout[ic / 2 + ic][jc] = 0;
171 for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--)
172 {
173 layout[i][j + jc] = 0;
174 layout[i][j] = 0;
175 }
176 /* go right */
177 for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++)
178 {
179 layout[i][j + jc] = 0;
180 layout[i][j] = 0;
181 }
182 /* go up */
183 for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--)
184 {
185 layout[i][j] = 0;
186 layout[i + ic][j] = 0;
187 }
188 /* go down */
189 for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++)
190 {
191 layout[i][j] = 0;
192 layout[i + ic][j] = 0;
193 }
194
195 }
196
197 /* get rid of bad doors. */
198 for (i = 0; i < xsize; i++)
199 for (j = 0; j < ysize; j++)
200 {
201 if (layout[i][j] == 'D')
202 { /* remove bad door. */
203 int si = surround_check (layout, i, j, xsize, ysize);
204
205 if (si != 3 && si != 12)
206 {
207 layout[i][j] = 0;
208 /* back up and recheck any nearby doors */
209 i = 0;
210 j = 0;
211 }
212 }
213 }
214}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines