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.11 by root, Thu Nov 8 19:43:25 2007 UTC vs.
Revision 1.15 by root, Sun May 4 14:12:37 2008 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 1994,2007 Mark Wedel 5 * Copyright (©) 1994,2007 Mark Wedel
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 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
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
23 23
24/* The onion room generator: 24/* The onion room generator:
25Onion rooms are like this: 25Onion rooms are like this:
26 26
27char **map_gen_spiral(int xsize, int ysize, int option); 27char **map_gen_spiral(int xsize, int ysize, int option);
28
29
30*/ 28*/
29
31#include <global.h> 30#include <global.h>
32#include <random_map.h> 31#include <random_map.h>
33 32
34#define RANDOM_OPTIONS 0 /* Pick random options below */ 33#define RANDOM_OPTIONS 0 /* Pick random options below */
35#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ 34#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */
49 48
50#define MAX_FINE .454545 49#define MAX_FINE .454545
51 50
52extern 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);
53 52
54char ** 53void
55map_gen_spiral (int xsize, int ysize, int option) 54map_gen_spiral (Layout maze, int option)
56{ 55{
57 int i, j; 56 int i, j;
58 float parm = 0; 57 float parm = 0;
59 float x = 0, y = 0; 58 float x = 0, y = 0;
60 int ic, jc; 59 int ic, jc;
61 float SizeX, SizeY; 60 float SizeX, SizeY;
62 float xscale, yscale; 61 float xscale, yscale;
63 62
64 /* allocate that array, set it up */
65 char **maze = (char **) calloc (sizeof (char *), xsize);
66
67 for (i = 0; i < xsize; i++)
68 {
69 maze[i] = (char *) calloc (sizeof (char), ysize);
70 }
71
72 /* slightly easier to fill and then cut */ 63 /* slightly easier to fill and then cut */
73 for (i = 0; i < xsize; i++) 64 maze->clear ('#');
74 for (j = 0; j < ysize; j++) 65
75 maze[i][j] = '#'; 66 int xsize = maze->w;
67 int ysize = maze->h;
76 68
77 ic = xsize / 2; 69 ic = xsize / 2;
78 jc = ysize / 2; 70 jc = ysize / 2;
79 SizeX = xsize / 2 - 2; 71 SizeX = xsize / 2 - 2;
80 SizeY = ysize / 2 - 2; 72 SizeY = ysize / 2 - 2;
81 73
82 /* select random options if necessary */ 74 /* select random options if necessary */
83 if (option == 0) 75 if (option == 0)
84 {
85 option = rndm (MAX_SPIRAL_OPT); 76 option = rmg_rndm (MAX_SPIRAL_OPT);
86 }
87 77
88 /* the order in which these are evaluated matters */ 78 /* the order in which these are evaluated matters */
89 79
90 /* the following two are mutually exclusive. 80 /* the following two are mutually exclusive.
91 pick one if they're both set. */ 81 pick one if they're both set. */
92 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL)) 82 if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
93 { 83 {
94 /* unset REGULAR_SPIRAL half the time */ 84 /* unset REGULAR_SPIRAL half the time */
95 if (rndm (2) && (option & REGULAR_SPIRAL)) 85 if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
96 option -= REGULAR_SPIRAL; 86 option -= REGULAR_SPIRAL;
97 else 87 else
98 option -= FIT_SPIRAL; 88 option -= FIT_SPIRAL;
99 } 89 }
100 90
101 xscale = yscale = MAX_FINE; /* fine spiral */ 91 xscale = yscale = MAX_FINE; /* fine spiral */
102 92
103 /* choose the spiral pitch */ 93 /* choose the spiral pitch */
104 if (!(option & FINE_SPIRAL)) 94 if (!(option & FINE_SPIRAL))
105 { 95 {
106 float pitch = (rndm (5)) / 10. + 10. / 22.; 96 float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
107 97
108 xscale = yscale = pitch; 98 xscale = yscale = pitch;
109 } 99 }
110 100
111 if ((option & FIT_SPIRAL) && (xsize != ysize)) 101 if ((option & FIT_SPIRAL) && (xsize != ysize))
126 /* cut out the spiral */ 116 /* cut out the spiral */
127 while ((fabs (x) < SizeX) && (fabs (y) < SizeY)) 117 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
128 { 118 {
129 x = parm * cos (parm) * xscale; 119 x = parm * cos (parm) * xscale;
130 y = parm * sin (parm) * yscale; 120 y = parm * sin (parm) * yscale;
131 maze[(int) (ic + x)][(int) (jc + y)] = '\0'; 121 maze[int (ic + x)][int (jc + y)] = '\0';
132 parm += 0.01; 122 parm += 0.01;
133 }; 123 }
134 124
135 maze[(int) (ic + x + 0.5)][(int) (jc + y + 0.5)] = '<'; 125 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
136
137 126
138 /* 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 */
139 maze[ic][jc + 1] = '>'; 128 maze[ic][jc + 1] = '>';
140 maze[ic][jc] = 'C'; 129 maze[ic][jc] = 'C';
141
142
143 return maze;
144} 130}
145 131
146/* the following function connects disjoint spirals which may 132/* the following function connects disjoint spirals which may
147 result from the symmetrization process. */ 133 result from the symmetrization process. */
148void 134void
149connect_spirals (int xsize, int ysize, int sym, char **layout) 135connect_spirals (int xsize, int ysize, int sym, char **layout)
150{ 136{
151
152 int i, j, ic = xsize / 2, jc = ysize / 2; 137 int i, j, ic = xsize / 2, jc = ysize / 2;
153 138
154 if (sym == SYMMETRY_X) 139 if (sym == SYMMETRY_X)
155 { 140 {
156 layout[ic][jc] = 0; 141 layout[ic][jc] = 0;
142
157 /* go left from map center */ 143 /* go left from map center */
158 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--)
159 layout[i][j] = 0; 145 layout[i][j] = 0;
146
160 /* go right */ 147 /* go right */
161 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++)
162 layout[i][j] = 0; 149 layout[i][j] = 0;
163 } 150 }
164 151
165 if (sym == SYMMETRY_Y) 152 if (sym == SYMMETRY_Y)
166 { 153 {
167
168 layout[ic][jc] = 0; 154 layout[ic][jc] = 0;
155
169 /* go up */ 156 /* go up */
170 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--)
171 layout[i][j] = 0; 158 layout[i][j] = 0;
159
172 /* go down */ 160 /* go down */
173 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++)
174 layout[i][j] = 0; 162 layout[i][j] = 0;
175 } 163 }
176 164
179 /* go left from map center */ 167 /* go left from map center */
180 layout[ic][jc / 2] = 0; 168 layout[ic][jc / 2] = 0;
181 layout[ic / 2][jc] = 0; 169 layout[ic / 2][jc] = 0;
182 layout[ic][jc / 2 + jc] = 0; 170 layout[ic][jc / 2 + jc] = 0;
183 layout[ic / 2 + ic][jc] = 0; 171 layout[ic / 2 + ic][jc] = 0;
172
184 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--)
185 { 174 {
186 layout[i][j + jc] = 0; 175 layout[i][j + jc] = 0;
187 layout[i][j] = 0; 176 layout[i][j] = 0;
188 } 177 }
178
189 /* go right */ 179 /* go right */
190 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++)
191 { 181 {
192 layout[i][j + jc] = 0; 182 layout[i][j + jc] = 0;
193 layout[i][j] = 0; 183 layout[i][j] = 0;
194 } 184 }
185
195 /* go up */ 186 /* go up */
196 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--)
197 { 188 {
198 layout[i][j] = 0; 189 layout[i][j] = 0;
199 layout[i + ic][j] = 0; 190 layout[i + ic][j] = 0;
200 } 191 }
192
201 /* go down */ 193 /* go down */
202 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++)
203 { 195 {
204 layout[i][j] = 0; 196 layout[i][j] = 0;
205 layout[i + ic][j] = 0; 197 layout[i + ic][j] = 0;
222 i = 0; 214 i = 0;
223 j = 0; 215 j = 0;
224 } 216 }
225 } 217 }
226 } 218 }
227
228
229
230} 219}
220

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines