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.9 by root, Sat Jan 27 02:19:37 2007 UTC vs.
Revision 1.13 by root, Mon Apr 14 22:41:17 2008 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 1994 Mark Wedel 5 * Copyright (©) 1994,2007 Mark Wedel
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 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
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The author can be reached via e-mail to mark@pyramid.com 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24
25 23
26/* The onion room generator: 24/* The onion room generator:
27Onion rooms are like this: 25Onion rooms are like this:
28 26
29char **map_gen_spiral(int xsize, int ysize, int option); 27char **map_gen_spiral(int xsize, int ysize, int option);
51 49
52#define MAX_FINE .454545 50#define MAX_FINE .454545
53 51
54extern 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);
55 53
56char ** 54void
57map_gen_spiral (int xsize, int ysize, int option) 55map_gen_spiral (Maze maze, int option)
58{ 56{
59 int i, j; 57 int i, j;
60 float parm = 0; 58 float parm = 0;
61 float x = 0, y = 0; 59 float x = 0, y = 0;
62 int ic, jc; 60 int ic, jc;
63 float SizeX, SizeY; 61 float SizeX, SizeY;
64 float xscale, yscale; 62 float xscale, yscale;
65 63
66 /* allocate that array, set it up */
67 char **maze = (char **) calloc (sizeof (char *), xsize);
68
69 for (i = 0; i < xsize; i++)
70 {
71 maze[i] = (char *) calloc (sizeof (char), ysize);
72 }
73
74 /* slightly easier to fill and then cut */ 64 /* slightly easier to fill and then cut */
75 for (i = 0; i < xsize; i++) 65 maze->clear ('#');
76 for (j = 0; j < ysize; j++) 66
77 maze[i][j] = '#'; 67 int xsize = maze->w;
68 int ysize = maze->h;
78 69
79 ic = xsize / 2; 70 ic = xsize / 2;
80 jc = ysize / 2; 71 jc = ysize / 2;
81 SizeX = xsize / 2 - 2; 72 SizeX = xsize / 2 - 2;
82 SizeY = ysize / 2 - 2; 73 SizeY = ysize / 2 - 2;
83 74
84 /* select random options if necessary */ 75 /* select random options if necessary */
85 if (option == 0) 76 if (option == 0)
86 {
87 option = rndm (MAX_SPIRAL_OPT); 77 option = rndm (MAX_SPIRAL_OPT);
88 }
89 78
90 /* the order in which these are evaluated matters */ 79 /* the order in which these are evaluated matters */
91 80
92 /* the following two are mutually exclusive. 81 /* the following two are mutually exclusive.
93 pick one if they're both set. */ 82 pick one if they're both set. */
128 /* cut out the spiral */ 117 /* cut out the spiral */
129 while ((fabs (x) < SizeX) && (fabs (y) < SizeY)) 118 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
130 { 119 {
131 x = parm * cos (parm) * xscale; 120 x = parm * cos (parm) * xscale;
132 y = parm * sin (parm) * yscale; 121 y = parm * sin (parm) * yscale;
133 maze[(int) (ic + x)][(int) (jc + y)] = '\0'; 122 maze[int (ic + x)][int (jc + y)] = '\0';
134 parm += 0.01; 123 parm += 0.01;
135 }; 124 }
136 125
137 maze[(int) (ic + x + 0.5)][(int) (jc + y + 0.5)] = '<'; 126 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
138
139 127
140 /* cut out the center in a 2x2 and place the center and downexit */ 128 /* cut out the center in a 2x2 and place the center and downexit */
141 maze[ic][jc + 1] = '>'; 129 maze[ic][jc + 1] = '>';
142 maze[ic][jc] = 'C'; 130 maze[ic][jc] = 'C';
143
144
145 return maze;
146} 131}
147 132
148/* the following function connects disjoint spirals which may 133/* the following function connects disjoint spirals which may
149 result from the symmetrization process. */ 134 result from the symmetrization process. */
150void 135void
224 i = 0; 209 i = 0;
225 j = 0; 210 j = 0;
226 } 211 }
227 } 212 }
228 } 213 }
229
230
231
232} 214}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines