… | |
… | |
29 | #include <rproto.h> |
29 | #include <rproto.h> |
30 | #include <sproto.h> |
30 | #include <sproto.h> |
31 | |
31 | |
32 | #define CEDE coroapi::cede_to_tick () |
32 | #define CEDE coroapi::cede_to_tick () |
33 | |
33 | |
34 | static void symmetrize_layout (Layout maze, random_map_params *RP); |
34 | static void symmetrize_layout (Layout &maze, random_map_params *RP); |
35 | static void rotate_layout (Layout maze, int rotation); |
35 | static void rotate_layout (Layout &maze, int rotation); |
|
|
36 | |
|
|
37 | noinline SV * |
|
|
38 | random_map_params::get_sv (const char *option) const |
|
|
39 | { |
|
|
40 | SV **he = hv_fetch (hv, option, strlen (option), 0); |
|
|
41 | |
|
|
42 | return he ? *he : 0; |
|
|
43 | } |
|
|
44 | |
|
|
45 | noinline const_utf8_string |
|
|
46 | random_map_params::get_str (const char *option, const_utf8_string fallback) const |
|
|
47 | { |
|
|
48 | SV *sv = get_sv (option); |
|
|
49 | return sv ? cfSvPVutf8_nolen (sv) : fallback; |
|
|
50 | } |
|
|
51 | |
|
|
52 | noinline IV |
|
|
53 | random_map_params::get_iv (const char *option, IV fallback) const |
|
|
54 | { |
|
|
55 | SV *sv = get_sv (option); |
|
|
56 | return sv ? SvIV (sv) : fallback; |
|
|
57 | } |
|
|
58 | |
|
|
59 | noinline UV |
|
|
60 | random_map_params::get_uv (const char *option, UV fallback) const |
|
|
61 | { |
|
|
62 | SV *sv = get_sv (option); |
|
|
63 | return sv ? SvUV (sv) : fallback; |
|
|
64 | } |
|
|
65 | |
|
|
66 | noinline NV |
|
|
67 | random_map_params::get_nv (const char *option, NV fallback) const |
|
|
68 | { |
|
|
69 | SV *sv = get_sv (option); |
|
|
70 | return sv ? SvNV (sv) : fallback; |
|
|
71 | } |
|
|
72 | |
|
|
73 | noinline void |
|
|
74 | random_map_params::set (const char *option, SV *value) const |
|
|
75 | { |
|
|
76 | int len = strlen (option); |
|
|
77 | |
|
|
78 | if (value) |
|
|
79 | hv_store (hv, option, len, value, 0); |
|
|
80 | else |
|
|
81 | hv_delete (hv, option, len, G_DISCARD); |
|
|
82 | } |
|
|
83 | |
|
|
84 | noinline void |
|
|
85 | random_map_params::set (const char *option, const_utf8_string value) const |
|
|
86 | { |
|
|
87 | set (option, value && *value ? newSVpvn_utf8 (value, strlen (value), 1) : 0); |
|
|
88 | } |
36 | |
89 | |
37 | void |
90 | void |
38 | dump_layout (Layout layout) |
91 | random_map_params::set (const char *option, IV value) const |
39 | { |
92 | { |
40 | for (int j = 0; j < layout->h; j++) |
93 | set (option, newSViv (value)); |
41 | { |
94 | } |
42 | for (int i = 0; i < layout->w; i++) |
|
|
43 | putc (layout[i][j] ? layout[i][j] : ' ', stdout); |
|
|
44 | |
95 | |
45 | putc ('\n', stdout); |
96 | void |
|
|
97 | random_map_params::set (const char *option, UV value) const |
|
|
98 | { |
|
|
99 | set (option, newSVuv (value)); |
|
|
100 | } |
|
|
101 | |
|
|
102 | void |
|
|
103 | random_map_params::set (const char *option, NV value) const |
|
|
104 | { |
|
|
105 | set (option, newSVnv (value)); |
|
|
106 | } |
|
|
107 | |
|
|
108 | void |
|
|
109 | random_map_params::hv_clone () |
|
|
110 | { |
|
|
111 | HV *copy = newHV (); |
|
|
112 | |
|
|
113 | hv_iterinit (hv); |
|
|
114 | |
|
|
115 | // does not work for utf-8 keys |
|
|
116 | while (HE *he = hv_iternext (hv)) |
46 | } |
117 | { |
|
|
118 | STRLEN klen; const char *key = HePV (he, klen); |
|
|
119 | hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he)); |
|
|
120 | } |
47 | |
121 | |
48 | putc ('\n', stdout); |
122 | SvREFCNT_dec (hv); |
|
|
123 | hv = copy; |
|
|
124 | } |
|
|
125 | |
|
|
126 | shstr_tmp |
|
|
127 | random_map_params::as_shstr () const |
|
|
128 | { |
|
|
129 | set ("xsize" , xsize); |
|
|
130 | set ("ysize" , ysize); |
|
|
131 | set ("monsterstyle" , monsterstyle); |
|
|
132 | set ("exit_on_final_map" , exit_on_final_map); |
|
|
133 | set ("layoutstyle" , layoutstyle); |
|
|
134 | set ("doorstyle" , doorstyle); |
|
|
135 | set ("final_map" , final_map); |
|
|
136 | set ("this_map" , this_map); |
|
|
137 | set ("expand2x" , expand2x); |
|
|
138 | set ("layoutoptions1" , layoutoptions1); |
|
|
139 | set ("layoutoptions2" , layoutoptions2); |
|
|
140 | set ("layoutoptions3" , layoutoptions3); |
|
|
141 | set ("symmetry" , symmetry); |
|
|
142 | set ("dungeon_depth" , dungeon_depth); |
|
|
143 | set ("orientation" , orientation); |
|
|
144 | set ("origin_x" , origin_x); |
|
|
145 | set ("origin_y" , origin_y); |
|
|
146 | set ("random_seed" , (UV)random_seed); |
|
|
147 | set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); |
|
|
148 | set ("difficulty_increase", difficulty_increase); |
|
|
149 | set ("dungeon_level" , dungeon_level); |
|
|
150 | |
|
|
151 | dynbuf_text buf; |
|
|
152 | hv_iterinit (hv); |
|
|
153 | |
|
|
154 | // does not work for utf-8 keys |
|
|
155 | while (HE *he = hv_iternext (hv)) |
|
|
156 | { |
|
|
157 | STRLEN klen; const char *key = HePV (he, klen); |
|
|
158 | STRLEN vlen; const char *value = SvPVutf8 (HeVAL (he), vlen); |
|
|
159 | |
|
|
160 | buf.fadd (key, klen); |
|
|
161 | buf << ' '; |
|
|
162 | buf.fadd (value, vlen); |
|
|
163 | buf << '\n'; |
|
|
164 | } |
|
|
165 | |
|
|
166 | return shstr (buf); |
|
|
167 | } |
|
|
168 | |
|
|
169 | random_map_params::~random_map_params () |
|
|
170 | { |
|
|
171 | SvREFCNT_dec (hv); |
49 | } |
172 | } |
50 | |
173 | |
51 | /* takes a map and makes it symmetric: adjusts Xsize and |
174 | /* takes a map and makes it symmetric: adjusts Xsize and |
52 | * Ysize to produce a symmetric map. |
175 | * Ysize to produce a symmetric map. |
53 | */ |
176 | */ |
54 | static void |
177 | static void |
55 | symmetrize_layout (Layout layout, random_map_params *RP) |
178 | symmetrize_layout (Layout &layout, random_map_params *RP) |
56 | { |
179 | { |
57 | if (RP->symmetry_used == SYMMETRY_NONE) |
180 | if (RP->symmetry_used == SYMMETRY_NONE) |
58 | return; |
181 | return; |
59 | |
182 | |
60 | Layout sym_layout ( |
183 | Layout sym_layout ( |
61 | RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY ? layout->w * 2 - 3 : layout->w, |
184 | RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY ? layout.w * 2 - 3 : layout.w, |
62 | RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY ? layout->h * 2 - 3 : layout->h |
185 | RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY ? layout.h * 2 - 3 : layout.h |
63 | ); |
186 | ); |
64 | |
187 | |
65 | if (RP->symmetry_used == SYMMETRY_X) |
188 | if (RP->symmetry_used == SYMMETRY_X) |
66 | for (int i = 0; i < sym_layout->w / 2 + 1; i++) |
189 | for (int i = 0; i < sym_layout.w / 2 + 1; i++) |
67 | for (int j = 0; j < sym_layout->h; j++) |
190 | for (int j = 0; j < sym_layout.h; j++) |
68 | { |
191 | { |
69 | sym_layout[i ][j] = |
192 | sym_layout[i ][j] = |
70 | sym_layout[sym_layout->w - i - 1][j] = layout[i][j]; |
193 | sym_layout[sym_layout.w - i - 1][j] = layout[i][j]; |
71 | } |
194 | } |
72 | |
195 | |
73 | if (RP->symmetry_used == SYMMETRY_Y) |
196 | if (RP->symmetry_used == SYMMETRY_Y) |
74 | for (int i = 0; i < sym_layout->w; i++) |
197 | for (int i = 0; i < sym_layout.w; i++) |
75 | for (int j = 0; j < sym_layout->h / 2 + 1; j++) |
198 | for (int j = 0; j < sym_layout.h / 2 + 1; j++) |
76 | { |
199 | { |
77 | sym_layout[i][j ] = |
200 | sym_layout[i][j ] = |
78 | sym_layout[i][sym_layout->h - j - 1] = layout[i][j]; |
201 | sym_layout[i][sym_layout.h - j - 1] = layout[i][j]; |
79 | } |
202 | } |
80 | |
203 | |
81 | if (RP->symmetry_used == SYMMETRY_XY) |
204 | if (RP->symmetry_used == SYMMETRY_XY) |
82 | for (int i = 0; i < sym_layout->w / 2 + 1; i++) |
205 | for (int i = 0; i < sym_layout.w / 2 + 1; i++) |
83 | for (int j = 0; j < sym_layout->h / 2 + 1; j++) |
206 | for (int j = 0; j < sym_layout.h / 2 + 1; j++) |
84 | { |
207 | { |
85 | sym_layout[i ][j ] = |
208 | sym_layout[i ][j ] = |
86 | sym_layout[i ][sym_layout->h - j - 1] = |
209 | sym_layout[i ][sym_layout.h - j - 1] = |
87 | sym_layout[sym_layout->w - i - 1][j ] = |
210 | sym_layout[sym_layout.w - i - 1][j ] = |
88 | sym_layout[sym_layout->w - i - 1][sym_layout->h - j - 1] = layout[i][j]; |
211 | sym_layout[sym_layout.w - i - 1][sym_layout.h - j - 1] = layout[i][j]; |
89 | } |
212 | } |
|
|
213 | |
|
|
214 | /* need to run the isolation remover for some layouts */ |
|
|
215 | switch (RP->map_layout_style) |
|
|
216 | { |
|
|
217 | case LAYOUT_ONION: |
|
|
218 | case LAYOUT_SNAKE: |
|
|
219 | case LAYOUT_SQUARE_SPIRAL: |
|
|
220 | // safe |
|
|
221 | break; |
|
|
222 | |
|
|
223 | default: |
|
|
224 | sym_layout.isolation_remover (); |
|
|
225 | break; |
|
|
226 | } |
90 | |
227 | |
91 | layout.swap (sym_layout); |
228 | layout.swap (sym_layout); |
92 | sym_layout.free (); |
|
|
93 | |
|
|
94 | /* reconnect disjointed spirals */ |
|
|
95 | /* reconnect disjointed nethacklayouts: the routine for |
|
|
96 | spirals will do the trick? */ |
|
|
97 | if (RP->map_layout_style == LAYOUT_SPIRAL |
|
|
98 | || RP->map_layout_style == LAYOUT_ROGUELIKE) |
|
|
99 | connect_spirals (layout->w, layout->h, RP->symmetry_used, layout); |
|
|
100 | } |
229 | } |
101 | |
230 | |
102 | /* takes a map and rotates it. This completes the |
231 | /* takes a map and rotates it. This completes the |
103 | onion layouts, making them possibly centered on any wall. |
232 | onion layouts, making them possibly centered on any wall. |
104 | It'll modify Xsize and Ysize if they're swapped. |
233 | It'll modify Xsize and Ysize if they're swapped. |
105 | */ |
234 | */ |
106 | static void |
235 | static void |
107 | rotate_layout (Layout layout, int rotation) |
236 | rotate_layout (Layout &layout, int rotation) |
108 | { |
237 | { |
109 | int w = layout->w; |
238 | int w = layout.w; |
110 | int h = layout->h; |
239 | int h = layout.h; |
111 | |
240 | |
112 | switch (rotation) |
241 | switch (rotation) |
113 | { |
242 | { |
114 | case 2: /* a reflection */ |
243 | case 2: /* a reflection */ |
115 | { |
244 | { |
… | |
… | |
118 | for (int i = 0; i < w; i++) /* copy a reflection back */ |
247 | for (int i = 0; i < w; i++) /* copy a reflection back */ |
119 | for (int j = 0; j < h; j++) |
248 | for (int j = 0; j < h; j++) |
120 | new_layout[i][j] = layout[w - i - 1][h - j - 1]; |
249 | new_layout[i][j] = layout[w - i - 1][h - j - 1]; |
121 | |
250 | |
122 | layout.swap (new_layout); |
251 | layout.swap (new_layout); |
123 | new_layout.free (); |
|
|
124 | } |
252 | } |
125 | break; |
253 | break; |
126 | |
254 | |
127 | case 1: |
255 | case 1: |
128 | case 3: |
256 | case 3: |
… | |
… | |
138 | for (int i = 0; i < w; i++) |
266 | for (int i = 0; i < w; i++) |
139 | for (int j = 0; j < h; j++) |
267 | for (int j = 0; j < h; j++) |
140 | new_layout[j][i] = layout[w - i - 1][h - j - 1]; |
268 | new_layout[j][i] = layout[w - i - 1][h - j - 1]; |
141 | |
269 | |
142 | layout.swap (new_layout); |
270 | layout.swap (new_layout); |
143 | new_layout.free (); |
|
|
144 | } |
271 | } |
145 | break; |
272 | break; |
146 | } |
273 | } |
147 | } |
274 | } |
148 | |
275 | |
… | |
… | |
234 | --works best on onions.*/ |
361 | --works best on onions.*/ |
235 | static void |
362 | static void |
236 | roomify_layout (char **maze, random_map_params *RP) |
363 | roomify_layout (char **maze, random_map_params *RP) |
237 | { |
364 | { |
238 | int tries = RP->Xsize * RP->Ysize / 30; |
365 | int tries = RP->Xsize * RP->Ysize / 30; |
239 | int ti; |
|
|
240 | |
366 | |
241 | for (ti = 0; ti < tries; ti++) |
367 | for (int ti = 0; ti < tries; ti++) |
242 | { |
368 | { |
243 | int dx, dy; /* starting location for looking at creating a door */ |
369 | /* starting location for looking at creating a door */ |
244 | int cx, cy; /* results of checking on creating walls. */ |
|
|
245 | |
|
|
246 | dx = rmg_rndm (RP->Xsize); |
370 | int dx = rmg_rndm (RP->Xsize); |
247 | dy = rmg_rndm (RP->Ysize); |
371 | int dy = rmg_rndm (RP->Ysize); |
248 | |
372 | |
|
|
373 | /* results of checking on creating walls. */ |
249 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
374 | int cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
250 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
375 | int cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
|
|
376 | |
251 | if (cx == -1) |
377 | if (cx == -1) |
252 | { |
378 | { |
253 | if (cy != -1) |
379 | if (cy != -1) |
254 | make_wall (maze, dx, dy, 1); |
380 | make_wall (maze, dx, dy, 1); |
255 | |
381 | |
… | |
… | |
271 | |
397 | |
272 | int |
398 | int |
273 | make_wall (char **maze, int x, int y, int dir) |
399 | make_wall (char **maze, int x, int y, int dir) |
274 | { |
400 | { |
275 | maze[x][y] = 'D'; /* mark a door */ |
401 | maze[x][y] = 'D'; /* mark a door */ |
|
|
402 | |
276 | switch (dir) |
403 | switch (dir) |
277 | { |
404 | { |
278 | case 0: /* horizontal */ |
405 | case 0: /* horizontal */ |
279 | { |
406 | { |
280 | int i1; |
|
|
281 | |
|
|
282 | for (i1 = x - 1; maze[i1][y] == 0; i1--) |
407 | for (int i1 = x - 1; maze[i1][y] == 0; --i1) maze[i1][y] = '#'; |
283 | maze[i1][y] = '#'; |
|
|
284 | for (i1 = x + 1; maze[i1][y] == 0; i1++) |
408 | for (int i1 = x + 1; maze[i1][y] == 0; ++i1) maze[i1][y] = '#'; |
285 | maze[i1][y] = '#'; |
|
|
286 | break; |
409 | break; |
287 | } |
410 | } |
288 | case 1: /* vertical */ |
411 | case 1: /* vertical */ |
289 | { |
412 | { |
290 | int i1; |
|
|
291 | |
|
|
292 | for (i1 = y - 1; maze[x][i1] == 0; i1--) |
413 | for (int i1 = y - 1; maze[x][i1] == 0; --i1) maze[x][i1] = '#'; |
293 | maze[x][i1] = '#'; |
|
|
294 | for (i1 = y + 1; maze[x][i1] == 0; i1++) |
414 | for (int i1 = y + 1; maze[x][i1] == 0; ++i1) maze[x][i1] = '#'; |
295 | maze[x][i1] = '#'; |
|
|
296 | break; |
415 | break; |
297 | } |
416 | } |
298 | } |
417 | } |
299 | |
418 | |
300 | return 0; |
419 | return 0; |
… | |
… | |
345 | |
464 | |
346 | sfree (doorlist_x, RP->Xsize * RP->Ysize); |
465 | sfree (doorlist_x, RP->Xsize * RP->Ysize); |
347 | sfree (doorlist_y, RP->Xsize * RP->Ysize); |
466 | sfree (doorlist_y, RP->Xsize * RP->Ysize); |
348 | } |
467 | } |
349 | |
468 | |
350 | void |
|
|
351 | write_map_parameters_to_string (char *buf, random_map_params *RP) |
|
|
352 | { |
|
|
353 | char small_buf[16384]; |
|
|
354 | |
|
|
355 | sprintf (buf, "xsize %d\nysize %d\n", RP->xsize, RP->ysize); |
|
|
356 | |
|
|
357 | if (RP->wallstyle[0]) |
|
|
358 | { |
|
|
359 | sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
|
|
360 | strcat (buf, small_buf); |
|
|
361 | } |
|
|
362 | |
|
|
363 | if (RP->miningstyle[0]) |
|
|
364 | { |
|
|
365 | sprintf (small_buf, "miningstyle %s\n", RP->miningstyle); |
|
|
366 | strcat (buf, small_buf); |
|
|
367 | } |
|
|
368 | |
|
|
369 | if (RP->floorstyle[0]) |
|
|
370 | { |
|
|
371 | sprintf (small_buf, "floorstyle %s\n", RP->floorstyle); |
|
|
372 | strcat (buf, small_buf); |
|
|
373 | } |
|
|
374 | |
|
|
375 | if (RP->monsterstyle[0]) |
|
|
376 | { |
|
|
377 | sprintf (small_buf, "monsterstyle %s\n", RP->monsterstyle); |
|
|
378 | strcat (buf, small_buf); |
|
|
379 | } |
|
|
380 | |
|
|
381 | if (RP->treasurestyle[0]) |
|
|
382 | { |
|
|
383 | sprintf (small_buf, "treasurestyle %s\n", RP->treasurestyle); |
|
|
384 | strcat (buf, small_buf); |
|
|
385 | } |
|
|
386 | |
|
|
387 | if (RP->layoutstyle[0]) |
|
|
388 | { |
|
|
389 | sprintf (small_buf, "layoutstyle %s\n", RP->layoutstyle); |
|
|
390 | strcat (buf, small_buf); |
|
|
391 | } |
|
|
392 | |
|
|
393 | if (RP->decorstyle[0]) |
|
|
394 | { |
|
|
395 | sprintf (small_buf, "decorstyle %s\n", RP->decorstyle); |
|
|
396 | strcat (buf, small_buf); |
|
|
397 | } |
|
|
398 | |
|
|
399 | if (RP->doorstyle[0]) |
|
|
400 | { |
|
|
401 | sprintf (small_buf, "doorstyle %s\n", RP->doorstyle); |
|
|
402 | strcat (buf, small_buf); |
|
|
403 | } |
|
|
404 | |
|
|
405 | if (RP->exitstyle[0]) |
|
|
406 | { |
|
|
407 | sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); |
|
|
408 | strcat (buf, small_buf); |
|
|
409 | } |
|
|
410 | |
|
|
411 | if (RP->final_map.length ()) |
|
|
412 | { |
|
|
413 | sprintf (small_buf, "final_map %s\n", &RP->final_map); |
|
|
414 | strcat (buf, small_buf); |
|
|
415 | } |
|
|
416 | |
|
|
417 | if (RP->exit_on_final_map[0]) |
|
|
418 | { |
|
|
419 | sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map); |
|
|
420 | strcat (buf, small_buf); |
|
|
421 | } |
|
|
422 | |
|
|
423 | if (RP->this_map.length ()) |
|
|
424 | { |
|
|
425 | sprintf (small_buf, "origin_map %s\n", &RP->this_map); |
|
|
426 | strcat (buf, small_buf); |
|
|
427 | } |
|
|
428 | |
|
|
429 | if (RP->expand2x) |
|
|
430 | { |
|
|
431 | sprintf (small_buf, "expand2x %d\n", RP->expand2x); |
|
|
432 | strcat (buf, small_buf); |
|
|
433 | } |
|
|
434 | |
|
|
435 | if (RP->layoutoptions1) |
|
|
436 | { |
|
|
437 | sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); |
|
|
438 | strcat (buf, small_buf); |
|
|
439 | } |
|
|
440 | |
|
|
441 | if (RP->layoutoptions2) |
|
|
442 | { |
|
|
443 | sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); |
|
|
444 | strcat (buf, small_buf); |
|
|
445 | } |
|
|
446 | |
|
|
447 | if (RP->layoutoptions3) |
|
|
448 | { |
|
|
449 | sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); |
|
|
450 | strcat (buf, small_buf); |
|
|
451 | } |
|
|
452 | |
|
|
453 | if (RP->symmetry) |
|
|
454 | { |
|
|
455 | sprintf (small_buf, "symmetry %d\n", RP->symmetry); |
|
|
456 | strcat (buf, small_buf); |
|
|
457 | } |
|
|
458 | |
|
|
459 | if (RP->difficulty && RP->difficulty_given) |
|
|
460 | { |
|
|
461 | sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
|
|
462 | strcat (buf, small_buf); |
|
|
463 | } |
|
|
464 | |
|
|
465 | if (fabs (RP->difficulty_increase - 1.f) >= (1.f / 1024.f)) |
|
|
466 | { |
|
|
467 | sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); |
|
|
468 | strcat (buf, small_buf); |
|
|
469 | } |
|
|
470 | |
|
|
471 | sprintf (small_buf, "dungeon_level %d\n", RP->dungeon_level); |
|
|
472 | strcat (buf, small_buf); |
|
|
473 | |
|
|
474 | if (RP->dungeon_depth) |
|
|
475 | { |
|
|
476 | sprintf (small_buf, "dungeon_depth %d\n", RP->dungeon_depth); |
|
|
477 | strcat (buf, small_buf); |
|
|
478 | } |
|
|
479 | |
|
|
480 | if (RP->decoroptions) |
|
|
481 | { |
|
|
482 | sprintf (small_buf, "decoroptions %d\n", RP->decoroptions); |
|
|
483 | strcat (buf, small_buf); |
|
|
484 | } |
|
|
485 | |
|
|
486 | if (RP->orientation) |
|
|
487 | { |
|
|
488 | sprintf (small_buf, "orientation %d\n", RP->orientation); |
|
|
489 | strcat (buf, small_buf); |
|
|
490 | } |
|
|
491 | |
|
|
492 | if (RP->origin_x) |
|
|
493 | { |
|
|
494 | sprintf (small_buf, "origin_x %d\n", RP->origin_x); |
|
|
495 | strcat (buf, small_buf); |
|
|
496 | } |
|
|
497 | |
|
|
498 | if (RP->origin_y) |
|
|
499 | { |
|
|
500 | sprintf (small_buf, "origin_y %d\n", RP->origin_y); |
|
|
501 | strcat (buf, small_buf); |
|
|
502 | } |
|
|
503 | |
|
|
504 | if (RP->treasureoptions) |
|
|
505 | { |
|
|
506 | sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); |
|
|
507 | strcat (buf, small_buf); |
|
|
508 | } |
|
|
509 | |
|
|
510 | if (RP->random_seed) |
|
|
511 | { |
|
|
512 | sprintf (small_buf, "random_seed %u\n", RP->random_seed); |
|
|
513 | strcat (buf, small_buf); |
|
|
514 | } |
|
|
515 | |
|
|
516 | if (RP->custom) |
|
|
517 | { |
|
|
518 | sprintf (small_buf, "custom %s\n", RP->custom); |
|
|
519 | strcat (buf, small_buf); |
|
|
520 | } |
|
|
521 | } |
|
|
522 | |
|
|
523 | ///////////////////////////////////////////////////////////////////////////// |
|
|
524 | |
|
|
525 | LayoutData::LayoutData (int w, int h) |
|
|
526 | : w(w), h(h) |
|
|
527 | { |
|
|
528 | int size = (sizeof (char *) + sizeof (char) * h) * w; |
|
|
529 | |
|
|
530 | col = (char **)salloc<char> (size); |
|
|
531 | |
|
|
532 | char *data = (char *)(col + w); |
|
|
533 | |
|
|
534 | for (int x = w; x--; ) |
|
|
535 | col [x] = data + x * h; |
|
|
536 | } |
|
|
537 | |
|
|
538 | LayoutData::~LayoutData () |
|
|
539 | { |
|
|
540 | int size = (sizeof (char *) + sizeof (char) * h) * w; |
|
|
541 | |
|
|
542 | sfree ((char *)col, size); |
|
|
543 | } |
|
|
544 | |
|
|
545 | void LayoutData::clear (char fill) |
|
|
546 | { |
|
|
547 | memset (col [0], fill, w * h); |
|
|
548 | } |
|
|
549 | |
|
|
550 | void LayoutData::border (char fill) |
|
|
551 | { |
|
|
552 | for (int i = 0; i < w; i++) col [i][0] = col [i][h - 1] = fill; |
|
|
553 | for (int j = 0; j < h; j++) col [0][j] = col [w - 1][j] = fill; |
|
|
554 | } |
|
|
555 | |
|
|
556 | /* function selects the layout function and gives it whatever |
469 | /* function selects the layout function and gives it whatever |
557 | arguments it needs. */ |
470 | arguments it needs. */ |
558 | static Layout |
471 | void |
559 | layoutgen (random_map_params *RP) |
472 | Layout::generate (random_map_params *RP) |
560 | { |
473 | { |
561 | Layout layout (RP); |
|
|
562 | |
|
|
563 | switch (RP->map_layout_style) |
474 | switch (RP->map_layout_style) |
564 | { |
475 | { |
565 | case LAYOUT_ONION: |
476 | case LAYOUT_ONION: |
566 | map_gen_onion (layout, RP->layoutoptions1, RP->layoutoptions2); |
477 | map_gen_onion (*this, RP->layoutoptions1, RP->layoutoptions2); |
567 | |
478 | |
568 | if (!(rmg_rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
479 | if (!(rmg_rndm (3)) && !(RP->layoutoptions1 & (RMOPT_WALLS_ONLY | RMOPT_WALL_OFF))) |
569 | roomify_layout (layout, RP); |
480 | roomify_layout (*this, RP); |
570 | |
481 | |
571 | break; |
482 | break; |
572 | |
483 | |
573 | case LAYOUT_MAZE: |
484 | case LAYOUT_MAZE: |
574 | maze_gen (layout, rmg_rndm (2)); |
485 | maze_gen (*this, RP->get_iv ("maze_type", rmg_rndm (4))); |
575 | |
486 | |
576 | if (!(rmg_rndm (2))) |
487 | if (!(rmg_rndm (2))) |
577 | doorify_layout (layout, RP); |
488 | doorify_layout (*this, RP); |
578 | |
489 | |
579 | break; |
490 | break; |
580 | |
491 | |
581 | case LAYOUT_SPIRAL: |
492 | case LAYOUT_SPIRAL: |
582 | map_gen_spiral (layout, RP->layoutoptions1); |
493 | map_gen_spiral (*this, RP->layoutoptions1); |
583 | |
494 | |
584 | if (!(rmg_rndm (2))) |
495 | if (!(rmg_rndm (2))) |
585 | doorify_layout (layout, RP); |
496 | doorify_layout (*this, RP); |
586 | |
497 | |
587 | break; |
498 | break; |
588 | |
499 | |
589 | case LAYOUT_ROGUELIKE: |
500 | case LAYOUT_ROGUELIKE: |
590 | /* Don't put symmetry in rogue maps. There isn't much reason to |
501 | /* Don't put symmetry in rogue maps. There isn't much reason to |
… | |
… | |
593 | * spirals, or maps with lots of passages - making a symmetric rogue |
504 | * spirals, or maps with lots of passages - making a symmetric rogue |
594 | * map fails because its likely that the passages the symmetry process |
505 | * map fails because its likely that the passages the symmetry process |
595 | * creates may not connect the rooms. |
506 | * creates may not connect the rooms. |
596 | */ |
507 | */ |
597 | RP->symmetry_used = SYMMETRY_NONE; |
508 | RP->symmetry_used = SYMMETRY_NONE; |
598 | roguelike_layout_gen (layout, RP->layoutoptions1); |
509 | roguelike_layout_gen (*this, RP->layoutoptions1); |
599 | /* no doorifying... done already */ |
510 | /* no doorifying... done already */ |
600 | break; |
511 | break; |
601 | |
512 | |
602 | case LAYOUT_SNAKE: |
513 | case LAYOUT_SNAKE: |
603 | make_snake_layout (layout, RP->layoutoptions1); |
514 | make_snake_layout (*this, RP->layoutoptions1); |
604 | |
515 | |
605 | if (rmg_rndm (2)) |
516 | if (rmg_rndm (2)) |
606 | roomify_layout (layout, RP); |
517 | roomify_layout (*this, RP); |
607 | |
518 | |
608 | break; |
519 | break; |
609 | |
520 | |
610 | case LAYOUT_SQUARE_SPIRAL: |
521 | case LAYOUT_SQUARE_SPIRAL: |
611 | make_square_spiral_layout (layout, RP->layoutoptions1); |
522 | make_square_spiral_layout (*this, RP->layoutoptions1); |
612 | |
523 | |
613 | if (rmg_rndm (2)) |
524 | if (rmg_rndm (2)) |
614 | roomify_layout (layout, RP); |
525 | roomify_layout (*this, RP); |
|
|
526 | |
|
|
527 | break; |
|
|
528 | |
|
|
529 | case LAYOUT_CAVE: |
|
|
530 | gen_cave (RP->get_iv ("cave_type", rmg_rndm (4))); |
|
|
531 | |
|
|
532 | if (!(rmg_rndm (2))) |
|
|
533 | doorify_layout (*this, RP); |
615 | |
534 | |
616 | break; |
535 | break; |
617 | |
536 | |
618 | default: |
537 | default: |
619 | abort (); |
538 | abort (); |
620 | } |
539 | } |
621 | |
540 | |
622 | /* rotate the layout randomly */ |
541 | /* rotate the layout randomly */ |
623 | rotate_layout (layout, rmg_rndm (4)); |
542 | rotate_layout (*this, rmg_rndm (4)); |
624 | |
543 | |
625 | symmetrize_layout (layout, RP); |
544 | symmetrize_layout (*this, RP); |
626 | |
545 | |
627 | #ifdef RMAP_DEBUG |
546 | #if 0 |
628 | dump_layout (layout); |
547 | print ();//D |
629 | #endif |
548 | #endif |
630 | |
549 | |
631 | if (RP->expand2x) |
550 | if (RP->expand2x) |
632 | expand2x (layout); |
551 | expand2x (*this); |
633 | |
|
|
634 | return layout; |
|
|
635 | } |
552 | } |
636 | |
553 | |
637 | bool |
554 | bool |
638 | maptile::generate_random_map (random_map_params *RP) |
555 | maptile::generate_random_map (random_map_params *RP) |
639 | { |
556 | { |
640 | char buf[16384]; |
|
|
641 | int i; |
|
|
642 | |
|
|
643 | RP->Xsize = RP->xsize; |
557 | RP->Xsize = RP->xsize; |
644 | RP->Ysize = RP->ysize; |
558 | RP->Ysize = RP->ysize; |
645 | |
559 | |
646 | /* pick a random seed, or use the one from the input file */ |
560 | /* pick a random seed, or use the one from the input file */ |
647 | RP->random_seed = RP->random_seed |
561 | RP->random_seed = RP->random_seed |
… | |
… | |
649 | : time (0); |
563 | : time (0); |
650 | |
564 | |
651 | // we run "single-threaded" |
565 | // we run "single-threaded" |
652 | rmg_rndm.seed (RP->random_seed); |
566 | rmg_rndm.seed (RP->random_seed); |
653 | |
567 | |
654 | write_map_parameters_to_string (buf, RP); |
568 | shstr buf = RP->as_shstr (); |
655 | |
569 | |
656 | if (RP->difficulty == 0) |
570 | if (RP->difficulty == 0) |
657 | { |
571 | { |
658 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
572 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
659 | |
573 | |
… | |
… | |
669 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
583 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
670 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
584 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
671 | |
585 | |
672 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
586 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
673 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
587 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rmg_rndm (25) + 5; |
|
|
588 | |
|
|
589 | min_it (RP->Xsize, MAX_RANDOM_MAP_SIZE); |
|
|
590 | min_it (RP->Ysize, MAX_RANDOM_MAP_SIZE); |
674 | |
591 | |
675 | if (RP->symmetry == SYMMETRY_RANDOM) |
592 | if (RP->symmetry == SYMMETRY_RANDOM) |
676 | RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1; |
593 | RP->symmetry_used = rmg_rndm (SYMMETRY_XY) + 1; |
677 | else |
594 | else |
678 | RP->symmetry_used = RP->symmetry; |
595 | RP->symmetry_used = RP->symmetry; |
… | |
… | |
687 | { |
604 | { |
688 | RP->Xsize /= 2; |
605 | RP->Xsize /= 2; |
689 | RP->Ysize /= 2; |
606 | RP->Ysize /= 2; |
690 | } |
607 | } |
691 | |
608 | |
692 | RP->map_layout_style = LAYOUT_NONE; |
|
|
693 | |
|
|
694 | /* Redo this - there was a lot of redundant code of checking for preset |
|
|
695 | * layout style and then random layout style. Instead, figure out |
|
|
696 | * the numeric layoutstyle, so there is only one area that actually |
|
|
697 | * calls the code to make the maps. |
|
|
698 | */ |
|
|
699 | if (strstr (RP->layoutstyle, "onion")) |
609 | if (strstr (RP->layoutstyle, "onion")) |
700 | RP->map_layout_style = LAYOUT_ONION; |
610 | RP->map_layout_style = LAYOUT_ONION; |
701 | else if (strstr (RP->layoutstyle, "maze")) |
611 | else if (strstr (RP->layoutstyle, "maze")) |
702 | RP->map_layout_style = LAYOUT_MAZE; |
612 | RP->map_layout_style = LAYOUT_MAZE; |
703 | else if (strstr (RP->layoutstyle, "spiral")) |
613 | else if (strstr (RP->layoutstyle, "spiral")) |
… | |
… | |
706 | RP->map_layout_style = LAYOUT_ROGUELIKE; |
616 | RP->map_layout_style = LAYOUT_ROGUELIKE; |
707 | else if (strstr (RP->layoutstyle, "snake")) |
617 | else if (strstr (RP->layoutstyle, "snake")) |
708 | RP->map_layout_style = LAYOUT_SNAKE; |
618 | RP->map_layout_style = LAYOUT_SNAKE; |
709 | else if (strstr (RP->layoutstyle, "squarespiral")) |
619 | else if (strstr (RP->layoutstyle, "squarespiral")) |
710 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
620 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
|
|
621 | else if (strstr (RP->layoutstyle, "cave")) |
711 | else if (RP->map_layout_style == LAYOUT_NONE) |
622 | RP->map_layout_style = LAYOUT_CAVE; |
|
|
623 | else |
712 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
624 | RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ |
713 | else |
|
|
714 | abort (); |
|
|
715 | |
625 | |
716 | Layout layout = layoutgen (RP); |
626 | Layout layout (RP->Xsize, RP->Ysize); |
717 | |
627 | layout.generate (RP); |
718 | #ifdef RMAP_DEBUG |
|
|
719 | dump_layout (layout); |
|
|
720 | #endif |
|
|
721 | |
628 | |
722 | /* increment these for the current map */ |
629 | /* increment these for the current map */ |
723 | ++RP->dungeon_level; |
630 | ++RP->dungeon_level; |
724 | |
631 | |
725 | // need to patch RP becasue following code doesn't use the Layout object |
632 | // need to patch RP becasue following code doesn't use the Layout object |
726 | RP->Xsize = layout->w; |
633 | RP->Xsize = layout.w; |
727 | RP->Ysize = layout->h; |
634 | RP->Ysize = layout.h; |
728 | |
635 | |
729 | /* allocate the map and set the floor */ |
636 | /* allocate the map and set the floor */ |
730 | make_map_floor (layout, RP->floorstyle, RP); |
637 | make_map_floor (layout, RP->get_str ("floorstyle", ""), RP); |
731 | |
638 | |
732 | /* set region */ |
639 | /* set region */ |
733 | default_region = RP->region; |
640 | default_region = RP->region; |
734 | |
641 | |
735 | CEDE; |
642 | CEDE; |
736 | |
643 | |
737 | place_specials_in_map (this, layout, RP); |
644 | place_specials_in_map (this, layout, RP); |
738 | |
645 | |
739 | CEDE; |
646 | CEDE; |
740 | |
647 | |
|
|
648 | const char *wallstyle = RP->get_str ("wallstyle", 0); |
|
|
649 | |
741 | /* create walls unless the wallstyle is "none" */ |
650 | /* create walls unless the wallstyle is "none" */ |
742 | if (strcmp (RP->wallstyle, "none")) |
651 | if (strcmp (wallstyle, "none")) |
743 | { |
652 | { |
744 | make_map_walls (this, layout, RP->wallstyle, RP->miningstyle, RP); |
653 | make_map_walls (this, layout, wallstyle, RP->get_str ("miningstyle", ""), RP); |
745 | |
654 | |
746 | /* place doors unless doorstyle or wallstyle is "none" */ |
655 | /* place doors unless doorstyle or wallstyle is "none" */ |
747 | if (strcmp (RP->doorstyle, "none")) |
656 | if (strcmp (RP->doorstyle, "none")) |
748 | put_doors (this, layout, RP->doorstyle, RP); |
657 | put_doors (this, layout, RP->doorstyle, RP); |
749 | } |
658 | } |
750 | |
659 | |
751 | CEDE; |
660 | CEDE; |
752 | |
661 | |
|
|
662 | const char *exitstyle = RP->get_str ("exitstyle", ""); |
|
|
663 | |
753 | /* create exits unless the exitstyle is "none" */ |
664 | /* create exits unless the exitstyle is "none" */ |
754 | if (strcmp (RP->exitstyle, "none")) |
665 | if (strcmp (exitstyle, "none")) |
755 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
666 | place_exits (this, layout, exitstyle, RP->orientation, RP); |
756 | |
667 | |
757 | CEDE; |
668 | CEDE; |
758 | |
669 | |
759 | /* create monsters unless the monsterstyle is "none" */ |
670 | /* create monsters unless the monsterstyle is "none" */ |
760 | if (strcmp (RP->monsterstyle, "none")) |
671 | if (strcmp (RP->monsterstyle, "none")) |
… | |
… | |
765 | /* treasures needs to have a proper difficulty set for the map. */ |
676 | /* treasures needs to have a proper difficulty set for the map. */ |
766 | difficulty = estimate_difficulty (); |
677 | difficulty = estimate_difficulty (); |
767 | |
678 | |
768 | CEDE; |
679 | CEDE; |
769 | |
680 | |
|
|
681 | const char *treasurestyle = RP->get_str ("treasurestyle", ""); |
|
|
682 | |
770 | /* create treasure unless the treasurestyle is "none" */ |
683 | /* create treasure unless the treasurestyle is "none" */ |
771 | place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); |
684 | place_treasure (this, layout, treasurestyle, RP->get_iv ("treasureoptions"), RP); |
772 | |
685 | |
773 | CEDE; |
686 | CEDE; |
|
|
687 | |
|
|
688 | const char *decorstyle = RP->get_str ("treasurestyle", ""); |
774 | |
689 | |
775 | /* create decor unless the decorstyle is "none" */ |
690 | /* create decor unless the decorstyle is "none" */ |
776 | if (strcmp (RP->decorstyle, "none")) |
691 | if (strcmp (decorstyle, "none")) |
777 | put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); |
692 | put_decor (this, layout, decorstyle, RP->get_iv ("decoroptions"), RP); |
778 | |
693 | |
779 | CEDE; |
694 | CEDE; |
780 | |
695 | |
781 | /* generate treasures, etc. */ |
696 | /* generate treasures, etc. */ |
782 | fix_auto_apply (); |
697 | fix_auto_apply (); |
783 | |
698 | |
784 | CEDE; |
699 | CEDE; |
785 | |
700 | |
786 | unblock_exits (this, layout, RP); |
701 | unblock_exits (this, layout, RP); |
787 | |
702 | |
788 | msg = strdup (buf); |
703 | msg = buf; |
789 | in_memory = MAP_ACTIVE; |
704 | in_memory = MAP_ACTIVE; |
790 | |
705 | |
791 | CEDE; |
706 | CEDE; |
792 | |
707 | |
793 | return 1; |
708 | return 1; |