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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines