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,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 1994,2007 Mark Wedel |
5 | * Copyright (©) 1994 Mark Wedel |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
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 | #include <global.h> |
31 | #include <global.h> |
32 | #include <random_map.h> |
32 | #include <random_map.h> |
|
|
33 | #include <rproto.h> |
33 | |
34 | |
34 | #define RANDOM_OPTIONS 0 /* Pick random options below */ |
35 | #define RANDOM_OPTIONS 0 /* Pick random options below */ |
35 | #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ |
36 | #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */ |
36 | #define FINE_SPIRAL 2 /* uses the min. separation: most coiling */ |
37 | #define FINE_SPIRAL 2 /* uses the min. separation: most coiling */ |
37 | #define FIT_SPIRAL 4 /* scale to a rectangular region, not square */ |
38 | #define FIT_SPIRAL 4 /* scale to a rectangular region, not square */ |
38 | #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 */ |
39 | #include <math.h> |
|
|
40 | |
|
|
41 | #ifndef MIN |
|
|
42 | # define MIN(x,y) (((x)<(y))? (x):(y)) |
|
|
43 | #endif |
|
|
44 | #ifndef MAX |
|
|
45 | # define MAX(x,y) (((x)<(y))? (y):(x)) |
|
|
46 | #endif |
|
|
47 | |
40 | |
48 | #define MINDIST 3 |
41 | #define MINDIST 3 |
49 | |
42 | |
50 | #define MAX_FINE .454545 |
43 | #define MAX_FINE .454545 |
51 | |
44 | |
52 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
45 | extern int surround_check (char **maze, int i, int j, int xsize, int ysize); |
53 | |
46 | |
54 | void |
47 | void |
55 | map_gen_spiral (Layout maze, int option) |
48 | map_gen_spiral (layout &maze, int option) |
56 | { |
49 | { |
57 | int i, j; |
50 | int i, j; |
58 | float parm = 0; |
51 | float parm = 0; |
59 | float x = 0, y = 0; |
52 | float x = 0, y = 0; |
60 | int ic, jc; |
53 | int ic, jc; |
61 | float SizeX, SizeY; |
54 | float SizeX, SizeY; |
62 | float xscale, yscale; |
55 | float xscale, yscale; |
63 | |
56 | |
64 | /* slightly easier to fill and then cut */ |
57 | /* slightly easier to fill and then cut */ |
65 | maze->clear ('#'); |
58 | maze.fill ('#'); |
66 | |
59 | |
67 | int xsize = maze->w; |
60 | int xsize = maze.w; |
68 | int ysize = maze->h; |
61 | int ysize = maze.h; |
69 | |
62 | |
70 | ic = xsize / 2; |
63 | ic = xsize / 2; |
71 | jc = ysize / 2; |
64 | jc = ysize / 2; |
72 | SizeX = xsize / 2 - 2; |
65 | SizeX = xsize / 2 - 2; |
73 | SizeY = ysize / 2 - 2; |
66 | SizeY = ysize / 2 - 2; |
… | |
… | |
107 | yscale *= (float) ysize / (float) xsize; |
100 | yscale *= (float) ysize / (float) xsize; |
108 | } |
101 | } |
109 | |
102 | |
110 | if (option & REGULAR_SPIRAL) |
103 | if (option & REGULAR_SPIRAL) |
111 | { |
104 | { |
112 | float scale = MIN (xscale, yscale); |
105 | float scale = min (xscale, yscale); |
113 | |
106 | |
114 | xscale = yscale = scale; |
107 | xscale = yscale = scale; |
115 | } |
108 | } |
116 | |
109 | |
117 | /* cut out the spiral */ |
110 | /* cut out the spiral */ |
… | |
… | |
128 | /* cut out the center in a 2x2 and place the center and downexit */ |
121 | /* cut out the center in a 2x2 and place the center and downexit */ |
129 | maze[ic][jc + 1] = '>'; |
122 | maze[ic][jc + 1] = '>'; |
130 | maze[ic][jc] = 'C'; |
123 | maze[ic][jc] = 'C'; |
131 | } |
124 | } |
132 | |
125 | |
133 | /* the following function connects disjoint spirals which may |
|
|
134 | result from the symmetrization process. */ |
|
|
135 | void |
|
|
136 | connect_spirals (int xsize, int ysize, int sym, char **layout) |
|
|
137 | { |
|
|
138 | int i, j, ic = xsize / 2, jc = ysize / 2; |
|
|
139 | |
|
|
140 | if (sym == SYMMETRY_X) |
|
|
141 | { |
|
|
142 | layout[ic][jc] = 0; |
|
|
143 | |
|
|
144 | /* go left from map center */ |
|
|
145 | for (i = ic - 1, j = jc; i > 0 && layout[i][j] == '#'; i--) |
|
|
146 | layout[i][j] = 0; |
|
|
147 | |
|
|
148 | /* go right */ |
|
|
149 | for (i = ic + 1, j = jc; i < xsize - 1 && layout[i][j] == '#'; i++) |
|
|
150 | layout[i][j] = 0; |
|
|
151 | } |
|
|
152 | |
|
|
153 | if (sym == SYMMETRY_Y) |
|
|
154 | { |
|
|
155 | layout[ic][jc] = 0; |
|
|
156 | |
|
|
157 | /* go up */ |
|
|
158 | for (i = ic, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
|
|
159 | layout[i][j] = 0; |
|
|
160 | |
|
|
161 | /* go down */ |
|
|
162 | for (i = ic, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
|
|
163 | layout[i][j] = 0; |
|
|
164 | } |
|
|
165 | |
|
|
166 | if (sym == SYMMETRY_XY) |
|
|
167 | { |
|
|
168 | /* go left from map center */ |
|
|
169 | layout[ic][jc / 2] = 0; |
|
|
170 | layout[ic / 2][jc] = 0; |
|
|
171 | layout[ic][jc / 2 + jc] = 0; |
|
|
172 | layout[ic / 2 + ic][jc] = 0; |
|
|
173 | |
|
|
174 | for (i = ic - 1, j = jc / 2; i > 0 && layout[i][j] == '#'; i--) |
|
|
175 | { |
|
|
176 | layout[i][j + jc] = 0; |
|
|
177 | layout[i][j] = 0; |
|
|
178 | } |
|
|
179 | |
|
|
180 | /* go right */ |
|
|
181 | for (i = ic + 1, j = jc / 2; i < xsize - 1 && layout[i][j] == '#'; i++) |
|
|
182 | { |
|
|
183 | layout[i][j + jc] = 0; |
|
|
184 | layout[i][j] = 0; |
|
|
185 | } |
|
|
186 | |
|
|
187 | /* go up */ |
|
|
188 | for (i = ic / 2, j = jc - 1; j > 0 && layout[i][j] == '#'; j--) |
|
|
189 | { |
|
|
190 | layout[i][j] = 0; |
|
|
191 | layout[i + ic][j] = 0; |
|
|
192 | } |
|
|
193 | |
|
|
194 | /* go down */ |
|
|
195 | for (i = ic / 2, j = jc + 1; j < ysize - 1 && layout[i][j] == '#'; j++) |
|
|
196 | { |
|
|
197 | layout[i][j] = 0; |
|
|
198 | layout[i + ic][j] = 0; |
|
|
199 | } |
|
|
200 | |
|
|
201 | } |
|
|
202 | |
|
|
203 | /* get rid of bad doors. */ |
|
|
204 | for (i = 0; i < xsize; i++) |
|
|
205 | for (j = 0; j < ysize; j++) |
|
|
206 | { |
|
|
207 | if (layout[i][j] == 'D') |
|
|
208 | { /* remove bad door. */ |
|
|
209 | int si = surround_check (layout, i, j, xsize, ysize); |
|
|
210 | |
|
|
211 | if (si != 3 && si != 12) |
|
|
212 | { |
|
|
213 | layout[i][j] = 0; |
|
|
214 | /* back up and recheck any nearby doors */ |
|
|
215 | i = 0; |
|
|
216 | j = 0; |
|
|
217 | } |
|
|
218 | } |
|
|
219 | } |
|
|
220 | } |
|
|
221 | |
|
|