ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/layout.C
(Generate patch)

Comparing deliantra/server/random_maps/layout.C (file contents):
Revision 1.9 by root, Fri Jul 2 17:18:04 2010 UTC vs.
Revision 1.31 by root, Wed Nov 16 23:42:02 2016 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 (©) 2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) Crossfire Development Team (restored, original file without copyright notice) 5 * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice)
6 * 6 *
7 * Deliantra is free software: you can redistribute it and/or modify it under 7 * Deliantra is free software: you can redistribute it and/or modify it under
8 * the terms of the Affero GNU General Public License as published by the 8 * the terms of the Affero GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your 9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version. 10 * option) any later version.
11 * 11 *
12 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the Affero GNU General Public License 17 * You should have received a copy of the Affero GNU General Public License
18 * and the GNU General Public License along with this program. If not, see 18 * and the GNU General Public License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>. 19 * <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <random_map.h> 25#include <rmg.h>
26#include <rproto.h> 26#include <rproto.h>
27 27
28void 28void noinline
29layout::alloc (int w, int h) 29layout::alloc (int w, int h)
30{ 30{
31 assert (sizeof (cell) == 1); 31 assert (sizeof (cell) == 1);
32 32
33 this->w = w; 33 this->w = w;
34 this->h = h; 34 this->h = h;
35 35
36 // we store the layout in a single contiguous memory layout 36 // we store the layout in a single contiguous memory layout
37 // first part consists of pointers to each column, followed 37 // first part consists of pointers to each column, followed
38 // by the actual columns (not rows!) 38 // by the actual columns (not rows!)
39 int size = (sizeof (cell *) + sizeof (cell) * h) * w; 39 size = (sizeof (cell *) + sizeof (cell) * h) * w;
40
41 data = (cell **)salloc<char> (size); 40 data = (cell **)salloc<char> (size);
42 41
43 cell *p = (cell *)(data + w); 42 cell *p = (cell *)(data + w);
44 43
45 for (int x = w; x--; ) 44 for (int x = 0; x < w; ++x)
46 data [x] = p + x * h; 45 data [x] = p + x * h;
47} 46}
48 47
49layout::layout (int w, int h) 48layout::layout (int w, int h)
50{ 49{
56 alloc (copy.w, copy.h); 55 alloc (copy.w, copy.h);
57 56
58 memcpy (data [0], copy.data [0], sizeof (cell) * h * w); 57 memcpy (data [0], copy.data [0], sizeof (cell) * h * w);
59} 58}
60 59
60layout::layout (layout &orig, int x1, int y1, int x2, int y2)
61{
62 w = x2 - x1;
63 h = y2 - y1;
64
65 // we only allocate space for the pointers
66 size = sizeof (cell *) * w;
67 data = (cell **)salloc<char> (size);
68
69 // and now we point back into the original layout
70 for (int x = 0; x < w; ++x)
71 data [x] = orig.data [x + x1] + y1;
72}
73
61layout::~layout () 74layout::~layout ()
62{ 75{
63 int size = (sizeof (cell *) + sizeof (cell) * h) * w;
64
65 sfree ((char *)data, size); 76 sfree ((char *)data, size);
66} 77}
67 78
68void 79void noinline
69layout::fill (char fill) 80layout::fill (char fill)
70{ 81{
71 memset (data [0], fill, w * h); 82 //memset (data [0], fill, w * h); // only when contiguous :/
83 fill_rect (0, 0, w, h, fill);
72} 84}
73 85
74void 86void noinline
87layout::replace (char from, char to)
88{
89 for (int x = 0; x < w; ++x)
90 for (int y = 0; y < h; ++y)
91 if (data [x][y] == from)
92 data [x][y] = to;
93}
94
95void noinline
75layout::rect (int x1, int y1, int x2, int y2, char fill) 96layout::rect (int x1, int y1, int x2, int y2, char fill)
97{
98 --x2;
99
100 memset (data [x1] + y1, fill, y2 - y1);
101 memset (data [x2] + y1, fill, y2 - y1);
102
103 while (++x1 < x2)
104 data [x1][y1] = data [x1][y2 - 1] = fill;
105}
106
107void noinline
108layout::fill_rect (int x1, int y1, int x2, int y2, char fill)
76{ 109{
77 for (; x1 < x2; ++x1) 110 for (; x1 < x2; ++x1)
78 memset (data [x1] + y1, fill, y2 - y1); 111 memset (data [x1] + y1, fill, y2 - y1);
79} 112}
80 113
81void layout::border (char fill)
82{
83 for (int i = 0; i < w; i++) data [i][0] = data [i][h - 1] = fill;
84 for (int j = 0; j < h; j++) data [0][j] = data [w - 1][j] = fill;
85}
86
87void 114void
115layout::border (char fill)
116{
117 rect (0, 0, w, h, fill);
118}
119
120void noinline
88layout::fill_rand (int percent) 121layout::fill_rand (int percent)
89{ 122{
90 percent = lerp (percent, 0, 100, 0, 256); 123 percent = lerp (percent, 0, 100, 0, 256);
91 124
92 for (int x = w - 1; --x > 0; ) 125 for (int x = 0; x < w; ++x)
93 for (int y = h - 1; --y > 0; ) 126 for (int y = 0; y < h; ++y)
94 data [x][y] = rmg_rndm (256) > percent ? 0 : '#'; 127 data [x][y] = rmg_rndm (256) > percent ? 0 : '#';
95} 128}
96 129
97///////////////////////////////////////////////////////////////////////////// 130/////////////////////////////////////////////////////////////////////////////
98 131
99// erode by cellular automata 132// erode by cellular automata
100void 133void noinline
101layout::erode_1_2 (int c1, int c2, int repeat) 134layout::erode_1_2 (int c1, int c2, int repeat)
102{ 135{
103 layout neu (w, h); 136 layout neu (w, h);
104 137
105 while (repeat--) 138 while (repeat--)
171///////////////////////////////////////////////////////////////////////////// 204/////////////////////////////////////////////////////////////////////////////
172// isolation remover - ensures single connected area 205// isolation remover - ensures single connected area
173 206
174typedef fixed_stack<point> pointlist; 207typedef fixed_stack<point> pointlist;
175 208
176static noinline void 209static void noinline
177push_flood_fill (layout &dist, pointlist &seeds, int x, int y) 210push_flood_fill (layout &dist, pointlist &seeds, int x, int y)
178{ 211{
179 if (dist [x][y]) 212 if (dist [x][y])
180 return; 213 return;
181 214
192 ++y; 225 ++y;
193 } 226 }
194 227
195 while (--y >= y0) 228 while (--y >= y0)
196 { 229 {
197 if (x > 0) push_flood_fill (dist, seeds, x - 1, y); 230 if (x > 0 && !dist [x - 1][y]) push_flood_fill (dist, seeds, x - 1, y);
198 if (x < dist.w - 1) push_flood_fill (dist, seeds, x + 1, y); 231 if (x < dist.w - 1 && !dist [x + 1][y]) push_flood_fill (dist, seeds, x + 1, y);
199 } 232 }
200} 233}
201 234
202static inline void 235static void inline
203make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d) 236make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d, int perturb)
204{ 237{
205 for (;;) 238 for (;;)
206 { 239 {
240 point neigh[4];
241 int ncnt = 0;
242
243 d += perturb > 1;
244
207 if (x > 1 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1) 245 if (x > 0 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y);
208 --x;
209 else if (x < dist.w - 2 && U8 (dist [x + 1][y]) < d && dist [x + 1][y] > 1) 246 if (x < dist.w - 1 && U8 (dist [x + 1][y]) < d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y);
210 ++x;
211 else if (y > 1 && U8 (dist [x][y - 1]) < d && dist [x][y - 1] > 1) 247 if (y > 0 && U8 (dist [x][y - 1]) < d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1);
212 --y;
213 else if (y < dist.h - 2 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) 248 if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1);
214 ++y; 249
215 else 250 if (!ncnt)
216 break; 251 return;
252
253 point p = neigh [perturb ? rmg_rndm (ncnt) : 0];
254
255 seeds.push (p);
256
257 x = p.x;
258 y = p.y;
217 259
218 d = dist [x][y]; 260 d = dist [x][y];
219 dist [x][y] = 1; 261 dist [x][y] = 1;
220 seeds.push (point (x, y));
221 } 262 }
222} 263}
223 264
224static void inline 265static void inline
225maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d) 266maybe_push (layout &dist, pointlist &seeds, int x, int y, U8 d)
232 return; 273 return;
233 274
234 seeds.push (point (x, y)); 275 seeds.push (point (x, y));
235} 276}
236 277
237void 278// isolation remover, works on a "distance" map
238layout::isolation_remover (bool dirty) 279// the map must be initialised with 0 == rooms, 255 = walls
280static void noinline
281isolation_remover (layout &dist, unsigned int perturb = 2)
239{ 282{
240 layout dist (w, h);
241
242 // dist contains 283 // dist contains
243 // 0 == invisited rooms 284 // 0 == invisited rooms
244 // 1 == visited rooms 285 // 1 == visited rooms
245 // 2+ shortest distance to random near room 286 // 2+ shortest distance to random near room
246 287
247 // phase 1, initialise dist array, find seed 288 clamp_it (perturb, 0, 2);
289
290 // phase 1, find seed
248 int cnt = 0; 291 int cnt = 0;
249 int x, y; 292 int x, y;
250 293
251 for (int i = 0; i < w; ++i) 294 for (int i = 0; i < dist.w; ++i)
252 for (int j = 0; j < h; ++j) 295 for (int j = 0; j < dist.h; ++j)
253 { 296 if (!dist [i][j] && !rmg_rndm (++cnt))
254 if (data [i][j] == '#')
255 dist [i][j] = U8 (255);
256 else
257 {
258 dist [i][j] = 0;
259 if (!rmg_rndm (++cnt))
260 x = i, y = j; 297 x = i, y = j;
261 }
262 }
263 298
264 if (!cnt) 299 if (!cnt)
265 { 300 {
266 // map is completely massive, this is not good, 301 // map is completely massive, this is not good,
267 // so make it empty instead. 302 // so make it empty instead.
268 clear (); 303 dist.fill (1);
269 border ();
270 return; 304 return;
271 } 305 }
272 306
273 fixed_stack<point> seeds (w * h * 5); 307 fixed_stack<point> seeds (dist.w * dist.h * 5);
274 308
275 // found first free space - picking the first one gives 309 // found first free space - picking the first one gives
276 // us a slight bias for tunnels, but usually you won't 310 // us a slight bias for tunnels, but usually you won't
277 // notice that in-game 311 // notice that in-game
278 seeds.push (point (x, y)); 312 seeds.push (point (x, y));
279 313
280 // phase 2, while we have seeds, if 314 // phase 2, while we have seeds, if
281 // seed is empty, floodfill, else grow 315 // seed is empty, floodfill, else grow
282 316
317 int rem_index = 0; // used to remove "somewhat ordered"
318
283 while (seeds.size) 319 while (seeds.size)
284 { 320 {
285 coroapi::cede_to_tick (); 321 coroapi::cede_to_tick ();
286 322
323 int i = perturb
324 ? rmg_rndm (max (0, seeds.size - 8), seeds.size - 1)
325 : rem_index ++ % seeds.size;
326
287 point p = seeds.remove (rmg_rndm (seeds.size)); 327 point p = seeds.remove (i);
288 328
289 x = p.x; 329 x = p.x;
290 y = p.y; 330 y = p.y;
291 331
292 if (!dist [x][y]) 332 if (!dist [x][y])
293 { 333 {
294 // found new isolated area, make tunnel 334 // found new isolated area, make tunnel
295 if (!dirty)
296 push_flood_fill (dist, seeds, x, y); 335 push_flood_fill (dist, seeds, x, y);
297
298 make_tunnel (dist, seeds, x, y, 255); 336 make_tunnel (dist, seeds, x, y, 254, perturb);
299
300 if (dirty)
301 push_flood_fill (dist, seeds, x, y);
302 } 337 }
303 else 338 else
304 { 339 {
305 // nothing here, continue to expand 340 // nothing here, continue to expand
306 U8 d = U8 (dist [x][y]) + 1; 341 U8 d = U8 (dist [x][y]) + 1;
309 if (x > 0) maybe_push (dist, seeds, x - 1, y, d); 344 if (x > 0) maybe_push (dist, seeds, x - 1, y, d);
310 if (y < dist.h - 1) maybe_push (dist, seeds, x, y + 1, d); 345 if (y < dist.h - 1) maybe_push (dist, seeds, x, y + 1, d);
311 if (y > 0) maybe_push (dist, seeds, x, y - 1, d); 346 if (y > 0) maybe_push (dist, seeds, x, y - 1, d);
312 } 347 }
313 } 348 }
349}
350
351void
352layout::isolation_remover (int perturb)
353{
354 layout dist (w - 2, h - 2); // map without border
355
356 for (int x = 1; x < w - 1; ++x)
357 for (int y = 1; y < h - 1; ++y)
358 dist [x - 1][y - 1] = data [x][y] == '#' ? U8 (255) : 0;
359
360 ::isolation_remover (dist, perturb);
314 361
315 // now copy the tunnels over 362 // now copy the tunnels over
316 for (int x = 0; x < w; ++x) 363 for (int x = 1; x < w - 1; ++x)
317 for (int y = 0; y < h; ++y) 364 for (int y = 1; y < h - 1; ++y)
318 if (data [x][y] == '#' && dist [x][y] == 1) 365 if (data [x][y] == '#' && dist [x - 1][y - 1] == 1)
319 data [x][y] = 0; 366 data [x][y] = 0;
320}
321
322/////////////////////////////////////////////////////////////////////////////
323
324// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
325void
326layout::gen_cave (int subtype)
327{
328 switch (subtype)
329 {
330 // a rough cave
331 case 0:
332 fill_rand (rmg_rndm (80, 95));
333 break;
334
335 // corridors
336 case 1:
337 fill_rand (rmg_rndm (5, 40));
338 erode_1_2 (5, 2, 10);
339 erode_1_2 (5, -1, 10);
340 erode_1_2 (5, 2, 1);
341 break;
342
343 // somewhat open, roundish
344 case 2:
345 fill_rand (45);
346 erode_1_2 (5, 0, 5);
347 erode_1_2 (5, 1, 1);
348 break;
349
350 // wide open, some room-like structures
351 case 3:
352 fill_rand (45);
353 erode_1_2 (5, 2, 4);
354 erode_1_2 (5, -1, 3);
355 break;
356 }
357
358 border ();
359 isolation_remover ();
360} 367}
361 368
362///////////////////////////////////////////////////////////////////////////// 369/////////////////////////////////////////////////////////////////////////////
363 370
364//+GPL 371//+GPL
366/* puts doors at appropriate locations in a maze. */ 373/* puts doors at appropriate locations in a maze. */
367void 374void
368layout::doorify () 375layout::doorify ()
369{ 376{
370 int ndoors = w * h / 60; /* reasonable number of doors. */ 377 int ndoors = w * h / 60; /* reasonable number of doors. */
371 int doorlocs = 0; /* # of available doorlocations */
372 378
373 uint16 *doorlist_x = salloc<uint16> (w * h); 379 coroapi::cede_to_tick ();
374 uint16 *doorlist_y = salloc<uint16> (w * h); 380
381 fixed_stack<point> doorloc (w * h);
375 382
376 /* make a list of possible door locations */ 383 /* make a list of possible door locations */
377 for (int i = 1; i < w - 1; i++) 384 for (int i = 1; i < w - 1; i++)
378 for (int j = 1; j < h - 1; j++) 385 for (int j = 1; j < h - 1; j++)
379 { 386 {
380 int sindex = surround_flag (*this, i, j); 387 int sindex = surround_flag (*this, i, j);
381 388
382 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 389 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
383 { 390 doorloc.push (point (i, j));
384 doorlist_x [doorlocs] = i;
385 doorlist_y [doorlocs] = j;
386 doorlocs++;
387 }
388 } 391 }
389 392
390 while (ndoors > 0 && doorlocs > 0) 393 while (ndoors && doorloc.size)
391 { 394 {
392 int di = rmg_rndm (doorlocs); 395 point p = doorloc.remove (rmg_rndm (doorloc.size));
393 int i = doorlist_x [di]; 396
394 int j = doorlist_y [di];
395 int sindex = surround_flag (*this, i, j); 397 int sindex = surround_flag (*this, p.x, p.y);
396 398
397 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 399 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
398 { 400 {
399 data [i][j] = 'D'; 401 data [p.x][p.y] = 'D';
400 ndoors--; 402 --ndoors;
401 } 403 }
402
403 /* reduce the size of the list */
404 doorlocs--;
405 doorlist_x[di] = doorlist_x [doorlocs];
406 doorlist_y[di] = doorlist_y [doorlocs];
407 } 404 }
408
409 sfree (doorlist_x, w * h);
410 sfree (doorlist_y, w * h);
411} 405}
412 406
413/* takes a map and makes it symmetric: adjusts Xsize and 407/* takes a map and makes it symmetric: adjusts Xsize and
414 * Ysize to produce a symmetric map. 408 * Ysize to produce a symmetric map.
415 */ 409 */
473//-GPL 467//-GPL
474 468
475void 469void
476layout::rotate (int rotation) 470layout::rotate (int rotation)
477{ 471{
472 coroapi::cede_to_tick ();
473
478 switch (rotation & 3) 474 switch (rotation & 3)
479 { 475 {
480 case 2: /* a reflection */ 476 case 2: /* a reflection */
481 { 477 {
482 layout new_layout (w, h); 478 layout new_layout (w, h);
634{ 630{
635 layout new_layout (w * 2 - 1, h * 2 - 1); 631 layout new_layout (w * 2 - 1, h * 2 - 1);
636 632
637 new_layout.clear (); 633 new_layout.clear ();
638 634
635 coroapi::cede_to_tick ();
636
639 for (int i = 0; i < w; i++) 637 for (int i = 0; i < w; i++)
640 for (int j = 0; j < h; j++) 638 for (int j = 0; j < h; j++)
641 switch (data [i][j]) 639 switch (data [i][j])
642 { 640 {
643 case '#': expand_wall (new_layout, i, j, *this); break; 641 case '#': expand_wall (new_layout, i, j, *this); break;
725 723
726 return -1; 724 return -1;
727} 725}
728 726
729int 727int
730make_wall (char **maze, int x, int y, int dir) 728make_wall (layout &maze, int x, int y, int dir)
731{ 729{
732 maze[x][y] = 'D'; /* mark a door */ 730 maze[x][y] = 'D'; /* mark a door */
733 731
734 switch (dir) 732 switch (dir)
735 { 733 {
752 750
753void 751void
754layout::roomify () 752layout::roomify ()
755{ 753{
756 int tries = w * h / 30; 754 int tries = w * h / 30;
755
756 coroapi::cede_to_tick ();
757 757
758 for (int ti = 0; ti < tries; ti++) 758 for (int ti = 0; ti < tries; ti++)
759 { 759 {
760 /* starting location for looking at creating a door */ 760 /* starting location for looking at creating a door */
761 int dx = rmg_rndm (w); 761 int dx = rmg_rndm (w);
784 else 784 else
785 make_wall (*this, dx, dy, 1); 785 make_wall (*this, dx, dy, 1);
786 } 786 }
787} 787}
788 788
789//-GPL
790
789///////////////////////////////////////////////////////////////////////////// 791/////////////////////////////////////////////////////////////////////////////
792
793// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
794void
795layout::gen_cave (int subtype)
796{
797 switch (subtype)
798 {
799 // a rough cave
800 case 0:
801 fill_rand (rmg_rndm (85, 97));
802 break;
803
804 // corridors
805 case 1:
806 fill_rand (rmg_rndm (5, 40));
807 erode_1_2 (5, 2, 10);
808 erode_1_2 (5, -1, 10);
809 erode_1_2 (5, 2, 1);
810 break;
811
812 // somewhat open, some room-like structures
813 case 2:
814 fill_rand (45);
815 erode_1_2 (5, 2, 4);
816 erode_1_2 (5, -1, 3);
817 break;
818
819 // wide open, roundish
820 case 3:
821 fill_rand (45);
822 erode_1_2 (5, 0, 5);
823 erode_1_2 (5, 1, 1);
824 break;
825 }
826
827 border ();
828 isolation_remover (1);
829}
830
831void
832layout::gen_castle ()
833{
834 fill ('#');
835
836 for (int n = w * h / 30 + 1; n--; )
837 {
838 int rw = rmg_rndm (6, 10);
839 int rh = rmg_rndm (6, 10);
840
841 if (rw > w || rh > h)
842 continue;
843
844 int rx = rmg_rndm (0, w - rw);
845 int ry = rmg_rndm (0, h - rh);
846
847 rect (rx, ry, rx + rw, ry + rh, '#');
848 fill_rect (rx + 1, ry + 1, rx + rw - 1, ry + rh - 1, 0);
849 }
850
851 border ();
852 isolation_remover (0);
853}
854
855static void
856gen_mixed_ (layout &maze, random_map_params *RP)
857{
858 if (maze.w > maze.h && maze.w > 16)
859 {
860 int m = rmg_rndm (8, maze.w - 8);
861
862 layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP);
863 layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP);
864 }
865 else if (maze.h > 16)
866 {
867 int m = rmg_rndm (8, maze.h - 8);
868
869 layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP);
870 layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP);
871 }
872 else
873 {
874 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1;
875
876 if (RP->map_layout_style == LAYOUT_MULTIPLE)
877 ++RP->map_layout_style;
878
879 maze.generate (RP);
880 }
881
882 coroapi::cede_to_tick ();
883}
884
885// recursive subdivision with random sublayouts
886static void
887gen_mixed (layout &maze, random_map_params *RP)
888{
889 random_map_params &rp = *new random_map_params (RP);
890 gen_mixed_ (maze, &rp);
891 delete &rp;
892
893 maze.border ();
894
895 // exits currently do not work so well, as they
896 // are currently often found together, so nuke entrances
897 maze.replace ('<', ' ');
898
899 maze.isolation_remover (0);
900}
901
902//+GPL
790 903
791/* function selects the maze function and gives it whatever 904/* function selects the maze function and gives it whatever
792 arguments it needs. */ 905 arguments it needs. */
793void 906void
794layout::generate (random_map_params *RP) 907layout::generate (random_map_params *RP)
854 if (rmg_rndm (2)) 967 if (rmg_rndm (2))
855 doorify (); 968 doorify ();
856 969
857 break; 970 break;
858 971
972 case LAYOUT_CASTLE:
973 gen_castle ();
974
975 if (rmg_rndm (2))
976 doorify ();
977
978 break;
979
980 case LAYOUT_MULTIPLE:
981 gen_mixed (*this, RP);
982 break;
983
859 default: 984 default:
860 abort (); 985 abort ();
861 } 986 }
987}
862 988
863 /* rotate the maze randomly */ 989//-GPL
864 rotate (rmg_rndm (4));
865
866 symmetrize (RP->symmetry_used);
867 990
868#if 0 991#if 0
869 print ();//D 992static void
870#endif 993gen_village (layout &maze)
994{
995 maze.clear ();
996 maze.border ();
871 997
872 if (RP->expand2x) 998 for (int n = maze.w * maze.h / 200 + 1; n--; )
873 expand2x (); 999 {
874} 1000 int rw = rmg_rndm (6, 10);
1001 int rh = rmg_rndm (6, 10);
875 1002
876//-GPL 1003 int rx = rmg_rndm (2, maze.w - rw - 2);
1004 int ry = rmg_rndm (2, maze.h - rh - 2);
877 1005
878#if 0 1006 maze.rect (rx, ry, rx + rw, ry + rh, '#');
1007 }
1008
1009 maze.border ();
1010 maze.isolation_remover (2);
1011}
1012
879static struct demo 1013static struct demo
880{ 1014{
881 demo () 1015 demo ()
882 { 1016 {
883 rmg_rndm.seed (time (0)); 1017 rmg_rndm.seed (time (0));
1018 extern void hack();hack ();
884 1019
885 for(int i=1;i<10;i) 1020 for(int i=1;i<100;i++)
886 { 1021 {
887 layout maze (10, 10); 1022 layout maze (40, 30);
888 maze.fill_rand (90); 1023 maze.fill_rand (99);
889 maze.border (); 1024 maze.border ();
890 maze.isolation_remover (); 1025 maze.isolation_remover (2);
891 maze.doorify ();
892 maze.symmetrize (rmg_rndm (2, 4));
893 maze.rotate (rmg_rndm (4));
894 maze.expand2x ();
895 maze.print (); 1026 maze.print ();
896 } 1027 }
897 1028
898 exit (1); 1029 exit (1);
899 } 1030 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines