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.6 by pippijn, Sat Jan 6 14:42:30 2007 UTC vs.
Revision 1.15 by root, Sun May 4 14:12:37 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines