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