… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 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 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 3 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 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* The onion room generator: |
25 | /* The onion room generator: |
25 | Onion rooms are like this: |
26 | Onion rooms are like this: |
26 | |
27 | |
27 | char **map_gen_spiral(int xsize, int ysize, int option); |
28 | char **map_gen_spiral(int xsize, int ysize, int option); |
28 | |
|
|
29 | |
|
|
30 | */ |
29 | */ |
|
|
30 | |
31 | #include <global.h> |
31 | #include <global.h> |
32 | #include <random_map.h> |
32 | #include <random_map.h> |
33 | |
33 | |
34 | #define RANDOM_OPTIONS 0 /* Pick random options below */ |
34 | #define RANDOM_OPTIONS 0 /* Pick random options below */ |
35 | #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ |
35 | #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ |
… | |
… | |
49 | |
49 | |
50 | #define MAX_FINE .454545 |
50 | #define MAX_FINE .454545 |
51 | |
51 | |
52 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
52 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
53 | |
53 | |
54 | Maze |
54 | void |
55 | map_gen_spiral (int xsize, int ysize, int option) |
55 | map_gen_spiral (Layout maze, int option) |
56 | { |
56 | { |
57 | int i, j; |
57 | int i, j; |
58 | float parm = 0; |
58 | float parm = 0; |
59 | float x = 0, y = 0; |
59 | float x = 0, y = 0; |
60 | int ic, jc; |
60 | int ic, jc; |
61 | float SizeX, SizeY; |
61 | float SizeX, SizeY; |
62 | float xscale, yscale; |
62 | float xscale, yscale; |
63 | |
63 | |
64 | Maze maze (xsize, ysize); |
|
|
65 | |
|
|
66 | /* slightly easier to fill and then cut */ |
64 | /* slightly easier to fill and then cut */ |
67 | for (i = 0; i < xsize; i++) |
65 | maze->clear ('#'); |
68 | for (j = 0; j < ysize; j++) |
66 | |
69 | maze[i][j] = '#'; |
67 | int xsize = maze->w; |
|
|
68 | int ysize = maze->h; |
70 | |
69 | |
71 | ic = xsize / 2; |
70 | ic = xsize / 2; |
72 | jc = ysize / 2; |
71 | jc = ysize / 2; |
73 | SizeX = xsize / 2 - 2; |
72 | SizeX = xsize / 2 - 2; |
74 | SizeY = ysize / 2 - 2; |
73 | SizeY = ysize / 2 - 2; |
75 | |
74 | |
76 | /* select random options if necessary */ |
75 | /* select random options if necessary */ |
77 | if (option == 0) |
76 | if (option == 0) |
78 | option = rndm (MAX_SPIRAL_OPT); |
77 | option = rmg_rndm (MAX_SPIRAL_OPT); |
79 | |
78 | |
80 | /* the order in which these are evaluated matters */ |
79 | /* the order in which these are evaluated matters */ |
81 | |
80 | |
82 | /* the following two are mutually exclusive. |
81 | /* the following two are mutually exclusive. |
83 | pick one if they're both set. */ |
82 | pick one if they're both set. */ |
84 | if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL)) |
83 | if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL)) |
85 | { |
84 | { |
86 | /* unset REGULAR_SPIRAL half the time */ |
85 | /* unset REGULAR_SPIRAL half the time */ |
87 | if (rndm (2) && (option & REGULAR_SPIRAL)) |
86 | if (rmg_rndm (2) && (option & REGULAR_SPIRAL)) |
88 | option -= REGULAR_SPIRAL; |
87 | option -= REGULAR_SPIRAL; |
89 | else |
88 | else |
90 | option -= FIT_SPIRAL; |
89 | option -= FIT_SPIRAL; |
91 | } |
90 | } |
92 | |
91 | |
93 | xscale = yscale = MAX_FINE; /* fine spiral */ |
92 | xscale = yscale = MAX_FINE; /* fine spiral */ |
94 | |
93 | |
95 | /* choose the spiral pitch */ |
94 | /* choose the spiral pitch */ |
96 | if (!(option & FINE_SPIRAL)) |
95 | if (!(option & FINE_SPIRAL)) |
97 | { |
96 | { |
98 | float pitch = (rndm (5)) / 10. + 10. / 22.; |
97 | float pitch = (rmg_rndm (5)) / 10. + 10. / 22.; |
99 | |
98 | |
100 | xscale = yscale = pitch; |
99 | xscale = yscale = pitch; |
101 | } |
100 | } |
102 | |
101 | |
103 | if ((option & FIT_SPIRAL) && (xsize != ysize)) |
102 | if ((option & FIT_SPIRAL) && (xsize != ysize)) |
… | |
… | |
120 | { |
119 | { |
121 | x = parm * cos (parm) * xscale; |
120 | x = parm * cos (parm) * xscale; |
122 | y = parm * sin (parm) * yscale; |
121 | y = parm * sin (parm) * yscale; |
123 | maze[int (ic + x)][int (jc + y)] = '\0'; |
122 | maze[int (ic + x)][int (jc + y)] = '\0'; |
124 | parm += 0.01; |
123 | parm += 0.01; |
125 | }; |
124 | } |
126 | |
125 | |
127 | maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<'; |
126 | maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<'; |
128 | |
127 | |
129 | /* 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 */ |
130 | maze[ic][jc + 1] = '>'; |
129 | maze[ic][jc + 1] = '>'; |
131 | maze[ic][jc] = 'C'; |
130 | maze[ic][jc] = 'C'; |
132 | |
|
|
133 | return maze; |
|
|
134 | } |
131 | } |
135 | |
132 | |
136 | /* the following function connects disjoint spirals which may |
133 | /* the following function connects disjoint spirals which may |
137 | result from the symmetrization process. */ |
134 | result from the symmetrization process. */ |
138 | void |
135 | void |
139 | connect_spirals (int xsize, int ysize, int sym, char **layout) |
136 | connect_spirals (int xsize, int ysize, int sym, char **layout) |
140 | { |
137 | { |
141 | |
|
|
142 | int i, j, ic = xsize / 2, jc = ysize / 2; |
138 | int i, j, ic = xsize / 2, jc = ysize / 2; |
143 | |
139 | |
144 | if (sym == SYMMETRY_X) |
140 | if (sym == SYMMETRY_X) |
145 | { |
141 | { |
146 | layout[ic][jc] = 0; |
142 | layout[ic][jc] = 0; |
|
|
143 | |
147 | /* go left from map center */ |
144 | /* go left from map center */ |
148 | for (i = ic - 1, j = jc; i > 0 && layout[i][j] == '#'; i--) |
145 | for (i = ic - 1, j = jc; i > 0 && layout[i][j] == '#'; i--) |
149 | layout[i][j] = 0; |
146 | layout[i][j] = 0; |
|
|
147 | |
150 | /* go right */ |
148 | /* go right */ |
151 | for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++) |
149 | for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++) |
152 | layout[i][j] = 0; |
150 | layout[i][j] = 0; |
153 | } |
151 | } |
154 | |
152 | |
155 | if (sym == SYMMETRY_Y) |
153 | if (sym == SYMMETRY_Y) |
156 | { |
154 | { |
157 | |
|
|
158 | layout[ic][jc] = 0; |
155 | layout[ic][jc] = 0; |
|
|
156 | |
159 | /* go up */ |
157 | /* go up */ |
160 | for (i = ic, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
158 | for (i = ic, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
161 | layout[i][j] = 0; |
159 | layout[i][j] = 0; |
|
|
160 | |
162 | /* go down */ |
161 | /* go down */ |
163 | for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
162 | for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
164 | layout[i][j] = 0; |
163 | layout[i][j] = 0; |
165 | } |
164 | } |
166 | |
165 | |
… | |
… | |
169 | /* go left from map center */ |
168 | /* go left from map center */ |
170 | layout[ic][jc / 2] = 0; |
169 | layout[ic][jc / 2] = 0; |
171 | layout[ic / 2][jc] = 0; |
170 | layout[ic / 2][jc] = 0; |
172 | layout[ic][jc / 2 + jc] = 0; |
171 | layout[ic][jc / 2 + jc] = 0; |
173 | layout[ic / 2 + ic][jc] = 0; |
172 | layout[ic / 2 + ic][jc] = 0; |
|
|
173 | |
174 | for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--) |
174 | for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--) |
175 | { |
175 | { |
176 | layout[i][j + jc] = 0; |
176 | layout[i][j + jc] = 0; |
177 | layout[i][j] = 0; |
177 | layout[i][j] = 0; |
178 | } |
178 | } |
|
|
179 | |
179 | /* go right */ |
180 | /* go right */ |
180 | for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++) |
181 | for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++) |
181 | { |
182 | { |
182 | layout[i][j + jc] = 0; |
183 | layout[i][j + jc] = 0; |
183 | layout[i][j] = 0; |
184 | layout[i][j] = 0; |
184 | } |
185 | } |
|
|
186 | |
185 | /* go up */ |
187 | /* go up */ |
186 | for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
188 | for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
187 | { |
189 | { |
188 | layout[i][j] = 0; |
190 | layout[i][j] = 0; |
189 | layout[i + ic][j] = 0; |
191 | layout[i + ic][j] = 0; |
190 | } |
192 | } |
|
|
193 | |
191 | /* go down */ |
194 | /* go down */ |
192 | for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
195 | for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
193 | { |
196 | { |
194 | layout[i][j] = 0; |
197 | layout[i][j] = 0; |
195 | layout[i + ic][j] = 0; |
198 | layout[i + ic][j] = 0; |
… | |
… | |
213 | j = 0; |
216 | j = 0; |
214 | } |
217 | } |
215 | } |
218 | } |
216 | } |
219 | } |
217 | } |
220 | } |
|
|
221 | |