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.7 by pippijn, Mon Jan 15 21:06:19 2007 UTC vs.
Revision 1.30 by root, Sun Jan 29 02:47:05 2017 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development 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 (C) 1994 Mark Wedel 5 * Copyright (©) 1994 Mark Wedel
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * This program 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 2 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 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 17 *
22 * The author can be reached via e-mail to mark@pyramid.com 18 * 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 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24
25 24
26/* The onion room generator: 25/* The onion room generator:
27Onion rooms are like this: 26Onion rooms are like this:
28 27
29char **map_gen_spiral(int xsize, int ysize, int option); 28char **map_gen_spiral(int xsize, int ysize, int option);
29*/
30 30
31
32*/
33#include <global.h> 31#include <global.h>
34#include <random_map.h> 32#include <rmg.h>
33#include <rproto.h>
35 34
36#define RANDOM_OPTIONS 0 /* Pick random options below */ 35#define RANDOM_OPTIONS 0 /* Pick random options below */
37#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ 36#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */
38#define FINE_SPIRAL 2 /* uses the min. separation: most coiling */ 37#define FINE_SPIRAL 2 /* uses the min. separation: most coiling */
39#define FIT_SPIRAL 4 /* scale to a rectangular region, not square */ 38#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 */ 39#define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */
41#include <math.h>
42
43#ifndef MIN
44# define MIN(x,y) (((x)<(y))? (x):(y))
45#endif
46#ifndef MAX
47# define MAX(x,y) (((x)<(y))? (y):(x))
48#endif
49 40
50#define MINDIST 3 41#define MINDIST 3
51 42
52#define MAX_FINE .454545 43#define MAX_FINE .454545
53 44
54extern int surround_check (char **maze, int i, int j, int xsize, int ysize); 45void
55 46map_gen_spiral (layout &maze, int option)
56char **
57map_gen_spiral (int xsize, int ysize, int option)
58{ 47{
59 int i, j;
60 float parm = 0; 48 float parm = 0;
61 float x = 0, y = 0; 49 float x = 0, y = 0;
62 int ic, jc; 50 int ic, jc;
63 float SizeX, SizeY; 51 float SizeX, SizeY;
64 float xscale, yscale; 52 float xscale, yscale;
65 53
66 /* allocate that array, set it up */ 54 /* slightly easier to fill and then cut */
67 char **maze = (char **) calloc (sizeof (char *), xsize); 55 maze.fill ('#');
68 56
69 for (i = 0; i < xsize; i++) 57 int xsize = maze.w;
70 { 58 int ysize = maze.h;
71 maze[i] = (char *) calloc (sizeof (char), ysize);
72 }
73
74 /* slightly easier to fill and then cut */
75 for (i = 0; i < xsize; i++)
76 for (j = 0; j < ysize; j++)
77 maze[i][j] = '#';
78 59
79 ic = xsize / 2; 60 ic = xsize / 2;
80 jc = ysize / 2; 61 jc = ysize / 2;
81 SizeX = xsize / 2 - 2; 62 SizeX = xsize / 2 - 2;
82 SizeY = ysize / 2 - 2; 63 SizeY = ysize / 2 - 2;
83 64
84 /* select random options if necessary */ 65 /* select random options if necessary */
85 if (option == 0) 66 if (option == 0)
86 { 67 option = rmg_rndm (MAX_SPIRAL_OPT);
87 option = RANDOM () % MAX_SPIRAL_OPT;
88 }
89 68
90 /* the order in which these are evaluated matters */ 69 /* the order in which these are evaluated matters */
91 70
92 /* the following two are mutually exclusive. 71 /* the following two are mutually exclusive.
93 pick one if they're both set. */ 72 pick one if they're both set. */
94 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL)) 73 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
95 { 74 {
96 /* unset REGULAR_SPIRAL half the time */ 75 /* unset REGULAR_SPIRAL half the time */
97 if (RANDOM () % 2 && (option & REGULAR_SPIRAL)) 76 if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
98 option -= REGULAR_SPIRAL; 77 option -= REGULAR_SPIRAL;
99 else 78 else
100 option -= FIT_SPIRAL; 79 option -= FIT_SPIRAL;
101 } 80 }
102 81
103 xscale = yscale = MAX_FINE; /* fine spiral */ 82 xscale = yscale = MAX_FINE; /* fine spiral */
104 83
105 /* choose the spiral pitch */ 84 /* choose the spiral pitch */
106 if (!(option & FINE_SPIRAL)) 85 if (!(option & FINE_SPIRAL))
107 { 86 {
108 float pitch = (RANDOM () % 5) / 10. + 10. / 22.; 87 float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
109 88
110 xscale = yscale = pitch; 89 xscale = yscale = pitch;
111 } 90 }
112 91
113 if ((option & FIT_SPIRAL) && (xsize != ysize)) 92 if ((option & FIT_SPIRAL) && (xsize != ysize))
118 yscale *= (float) ysize / (float) xsize; 97 yscale *= (float) ysize / (float) xsize;
119 } 98 }
120 99
121 if (option & REGULAR_SPIRAL) 100 if (option & REGULAR_SPIRAL)
122 { 101 {
123 float scale = MIN (xscale, yscale); 102 float scale = min (xscale, yscale);
124 103
125 xscale = yscale = scale; 104 xscale = yscale = scale;
126 } 105 }
127 106
128 /* cut out the spiral */ 107 /* cut out the spiral */
129 while ((fabs (x) < SizeX) && (fabs (y) < SizeY)) 108 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
130 { 109 {
131 x = parm * cos (parm) * xscale; 110 x = parm * cos (parm) * xscale;
132 y = parm * sin (parm) * yscale; 111 y = parm * sin (parm) * yscale;
133 maze[(int) (ic + x)][(int) (jc + y)] = '\0'; 112 maze[int (ic + x)][int (jc + y)] = '\0';
134 parm += 0.01; 113 parm += 0.01;
135 }; 114 }
136 115
137 maze[(int) (ic + x + 0.5)][(int) (jc + y + 0.5)] = '<'; 116 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
138
139 117
140 /* 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 */
141 maze[ic][jc + 1] = '>'; 119 maze[ic][jc + 1] = '>';
142 maze[ic][jc] = 'C'; 120 maze[ic][jc] = 'C';
143
144
145 return maze;
146} 121}
147 122
148/* the following function connects disjoint spirals which may
149 result from the symmetrization process. */
150void
151connect_spirals (int xsize, int ysize, int sym, char **layout)
152{
153
154 int i, j, ic = xsize / 2, jc = ysize / 2;
155
156 if (sym == SYMMETRY_X)
157 {
158 layout[ic][jc] = 0;
159 /* go left from map center */
160 for (i = ic - 1, j = jc; i > 0 && layout[i][j] == '#'; i--)
161 layout[i][j] = 0;
162 /* go right */
163 for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++)
164 layout[i][j] = 0;
165 }
166
167 if (sym == SYMMETRY_Y)
168 {
169
170 layout[ic][jc] = 0;
171 /* go up */
172 for (i = ic, j = jc - 1; j > 0 && layout[i][j] == '#'; j--)
173 layout[i][j] = 0;
174 /* go down */
175 for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++)
176 layout[i][j] = 0;
177 }
178
179 if (sym == SYMMETRY_XY)
180 {
181 /* go left from map center */
182 layout[ic][jc / 2] = 0;
183 layout[ic / 2][jc] = 0;
184 layout[ic][jc / 2 + jc] = 0;
185 layout[ic / 2 + ic][jc] = 0;
186 for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--)
187 {
188 layout[i][j + jc] = 0;
189 layout[i][j] = 0;
190 }
191 /* go right */
192 for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++)
193 {
194 layout[i][j + jc] = 0;
195 layout[i][j] = 0;
196 }
197 /* go up */
198 for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--)
199 {
200 layout[i][j] = 0;
201 layout[i + ic][j] = 0;
202 }
203 /* go down */
204 for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++)
205 {
206 layout[i][j] = 0;
207 layout[i + ic][j] = 0;
208 }
209
210 }
211
212 /* get rid of bad doors. */
213 for (i = 0; i < xsize; i++)
214 for (j = 0; j < ysize; j++)
215 {
216 if (layout[i][j] == 'D')
217 { /* remove bad door. */
218 int si = surround_check (layout, i, j, xsize, ysize);
219
220 if (si != 3 && si != 12)
221 {
222 layout[i][j] = 0;
223 /* back up and recheck any nearby doors */
224 i = 0;
225 j = 0;
226 }
227 }
228 }
229
230
231
232}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines