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.14 by root, Sat Jul 3 02:19:10 2010 UTC vs.
Revision 1.35 by root, Sat Dec 1 20:22:13 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 * 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) 6 * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice)
6 * 7 *
7 * 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
8 * 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
9 * 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
10 * 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 Affero GNU General Public License 18 * 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 19 * and the GNU General Public License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>. 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#include <global.h> 25#include <global.h>
25#include <random_map.h> 26#include <rmg.h>
26#include <rproto.h> 27#include <rproto.h>
27 28
28void 29ecb_noinline void
29layout::alloc (int w, int h) 30layout::alloc (int w, int h)
30{ 31{
31 assert (sizeof (cell) == 1); 32 assert (sizeof (cell) == 1);
32 33
33 this->w = w; 34 this->w = w;
74layout::~layout () 75layout::~layout ()
75{ 76{
76 sfree ((char *)data, size); 77 sfree ((char *)data, size);
77} 78}
78 79
79void 80ecb_noinline void
80layout::fill (char fill) 81layout::fill (char fill)
81{ 82{
82 memset (data [0], fill, w * h); 83 //memset (data [0], fill, w * h); // only when contiguous :/
84 fill_rect (0, 0, w, h, fill);
83} 85}
84 86
85void 87ecb_noinline void
88layout::replace (char from, char to)
89{
90 for (int x = 0; x < w; ++x)
91 for (int y = 0; y < h; ++y)
92 if (data [x][y] == from)
93 data [x][y] = to;
94}
95
96ecb_noinline void
86layout::rect (int x1, int y1, int x2, int y2, char fill) 97layout::rect (int x1, int y1, int x2, int y2, char fill)
87{ 98{
88 --x2; 99 --x2;
89 100
90 memset (data [x1] + y1, fill, y2 - y1); 101 memset (data [x1] + y1, fill, y2 - y1);
92 103
93 while (++x1 < x2) 104 while (++x1 < x2)
94 data [x1][y1] = data [x1][y2 - 1] = fill; 105 data [x1][y1] = data [x1][y2 - 1] = fill;
95} 106}
96 107
97void 108ecb_noinline void
98layout::fill_rect (int x1, int y1, int x2, int y2, char fill) 109layout::fill_rect (int x1, int y1, int x2, int y2, char fill)
99{ 110{
100 for (; x1 < x2; ++x1) 111 for (; x1 < x2; ++x1)
101 memset (data [x1] + y1, fill, y2 - y1); 112 memset (data [x1] + y1, fill, y2 - y1);
102} 113}
103 114
115void
104void layout::border (char fill) 116layout::border (char fill)
105{ 117{
106 rect (0, 0, w, h, fill); 118 rect (0, 0, w, h, fill);
107} 119}
108 120
109void 121ecb_noinline void
110layout::fill_rand (int percent) 122layout::fill_rand (int percent)
111{ 123{
112 percent = lerp (percent, 0, 100, 0, 256); 124 percent = lerp (percent, 0, 100, 0, 256);
113 125
114 for (int x = w - 1; --x > 0; ) 126 for (int x = 0; x < w; ++x)
115 for (int y = h - 1; --y > 0; ) 127 for (int y = 0; y < h; ++y)
116 data [x][y] = rmg_rndm (256) > percent ? 0 : '#'; 128 data [x][y] = rmg_rndm (256) > percent ? 0 : '#';
117} 129}
118 130
119///////////////////////////////////////////////////////////////////////////// 131/////////////////////////////////////////////////////////////////////////////
120 132
121// erode by cellular automata 133// erode by cellular automata
122void 134ecb_noinline void
123layout::erode_1_2 (int c1, int c2, int repeat) 135layout::erode_1_2 (int c1, int c2, int repeat)
124{ 136{
125 layout neu (w, h); 137 layout neu (w, h);
126 138
127 while (repeat--) 139 while (repeat--)
141 { 0, -2, 0 }, { 0, -1, 1 }, { 0, 0, 1 }, { 0, 1, 1 }, { 0, 2, 0 }, 153 { 0, -2, 0 }, { 0, -1, 1 }, { 0, 0, 1 }, { 0, 1, 1 }, { 0, 2, 0 },
142 { 1, -2, 0 }, { 1, -1, 1 }, { 1, 0, 1 }, { 1, 1, 1 }, { 1, 2, 0 }, 154 { 1, -2, 0 }, { 1, -1, 1 }, { 1, 0, 1 }, { 1, 1, 1 }, { 1, 2, 0 },
143 { 2, -1, 0 }, { 2, 0, 0 }, { 2, 1, 0 }, 155 { 2, -1, 0 }, { 2, 0, 0 }, { 2, 1, 0 },
144 }; 156 };
145 157
146 for (int i = array_length (dds); i--; ) 158 for (int i = ecb_array_length (dds); i--; )
147 { 159 {
148 int nx = x + dds [i][0]; 160 int nx = x + dds [i][0];
149 int ny = y + dds [i][1]; 161 int ny = y + dds [i][1];
150 162
151 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !data [nx][ny]) 163 if (!IN_RANGE_EXC (nx, 0, w) || !IN_RANGE_EXC (ny, 0, h) || !data [nx][ny])
193///////////////////////////////////////////////////////////////////////////// 205/////////////////////////////////////////////////////////////////////////////
194// isolation remover - ensures single connected area 206// isolation remover - ensures single connected area
195 207
196typedef fixed_stack<point> pointlist; 208typedef fixed_stack<point> pointlist;
197 209
198static void noinline 210ecb_noinline static void
199push_flood_fill (layout &dist, pointlist &seeds, int x, int y) 211push_flood_fill (layout &dist, pointlist &seeds, int x, int y)
200{ 212{
201 if (dist [x][y]) 213 if (dist [x][y])
202 return; 214 return;
203 215
219 if (x > 0 && !dist [x - 1][y]) push_flood_fill (dist, seeds, x - 1, y); 231 if (x > 0 && !dist [x - 1][y]) push_flood_fill (dist, seeds, x - 1, y);
220 if (x < dist.w - 1 && !dist [x + 1][y]) push_flood_fill (dist, seeds, x + 1, y); 232 if (x < dist.w - 1 && !dist [x + 1][y]) push_flood_fill (dist, seeds, x + 1, y);
221 } 233 }
222} 234}
223 235
224static inline void 236static void inline
225make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d) 237make_tunnel (layout &dist, pointlist &seeds, int x, int y, U8 d, int perturb)
226{ 238{
227 for (;;) 239 for (;;)
228 { 240 {
229 point neigh[4]; 241 point neigh[4];
230 int ncnt = 0; 242 int ncnt = 0;
231 243
244 d += perturb > 1;
245
232 if (x > 0 && U8 (dist [x - 1][y]) <= d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y); 246 if (x > 0 && U8 (dist [x - 1][y]) < d && dist [x - 1][y] > 1) neigh [ncnt++] = point (x - 1, y);
233 if (x < dist.w - 1 && U8 (dist [x + 1][y]) <= d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y); 247 if (x < dist.w - 1 && U8 (dist [x + 1][y]) < d && dist [x + 1][y] > 1) neigh [ncnt++] = point (x + 1, y);
234 if (y > 0 && U8 (dist [x][y - 1]) <= d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1); 248 if (y > 0 && U8 (dist [x][y - 1]) < d && dist [x][y - 1] > 1) neigh [ncnt++] = point (x, y - 1);
235 if (y < dist.h - 1 && U8 (dist [x][y + 1]) <= d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); 249 if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1);
236 250
237 if (!ncnt) 251 if (!ncnt)
238 return; 252 return;
239 253
240 point &p = neigh [rmg_rndm (ncnt)]; 254 point p = neigh [perturb ? rmg_rndm (ncnt) : 0];
241 255
242 seeds.push (p); 256 seeds.push (p);
243 257
244 x = p.x; 258 x = p.x;
245 y = p.y; 259 y = p.y;
262 seeds.push (point (x, y)); 276 seeds.push (point (x, y));
263} 277}
264 278
265// isolation remover, works on a "distance" map 279// isolation remover, works on a "distance" map
266// the map must be initialised with 0 == rooms, 255 = walls 280// the map must be initialised with 0 == rooms, 255 = walls
267static void noinline 281ecb_noinline static void
268isolation_remover (layout &dist) 282isolation_remover (layout &dist, unsigned int perturb = 2)
269{ 283{
270 // dist contains 284 // dist contains
271 // 0 == invisited rooms 285 // 0 == invisited rooms
272 // 1 == visited rooms 286 // 1 == visited rooms
273 // 2+ shortest distance to random near room 287 // 2+ shortest distance to random near room
274 288
289 clamp_it (perturb, 0, 2);
290
275 // phase 1, find seed 291 // phase 1, find seed
276 int cnt = 0; 292 int cnt = 0;
277 int x, y; 293 int x, y;
278 294
279 for (int i = 0; i < dist.w; ++i) 295 for (int i = 0; i < dist.w; ++i)
297 seeds.push (point (x, y)); 313 seeds.push (point (x, y));
298 314
299 // phase 2, while we have seeds, if 315 // phase 2, while we have seeds, if
300 // seed is empty, floodfill, else grow 316 // seed is empty, floodfill, else grow
301 317
318 int rem_index = 0; // used to remove "somewhat ordered"
319
302 while (seeds.size) 320 while (seeds.size)
303 { 321 {
304 coroapi::cede_to_tick (); 322 coroapi::cede_to_tick ();
305 323
324 int i = perturb
325 ? rmg_rndm (max (0, seeds.size - 8), seeds.size - 1)
326 : rem_index ++ % seeds.size;
327
306 point p = seeds.remove (rmg_rndm (seeds.size)); 328 point p = seeds.remove (i);
307 329
308 x = p.x; 330 x = p.x;
309 y = p.y; 331 y = p.y;
310 332
311 if (!dist [x][y]) 333 if (!dist [x][y])
312 { 334 {
313 // found new isolated area, make tunnel 335 // found new isolated area, make tunnel
314 push_flood_fill (dist, seeds, x, y); 336 push_flood_fill (dist, seeds, x, y);
315 make_tunnel (dist, seeds, x, y, 255); 337 make_tunnel (dist, seeds, x, y, 254, perturb);
316 } 338 }
317 else 339 else
318 { 340 {
319 // nothing here, continue to expand 341 // nothing here, continue to expand
320 U8 d = U8 (dist [x][y]) + 1; 342 U8 d = U8 (dist [x][y]) + 1;
326 } 348 }
327 } 349 }
328} 350}
329 351
330void 352void
331layout::isolation_remover () 353layout::isolation_remover (int perturb)
332{ 354{
333 layout dist (w - 2, h - 2); // map without border 355 layout dist (w - 2, h - 2); // map without border
334 356
335 for (int x = 1; x < w - 1; ++x) 357 for (int x = 1; x < w - 1; ++x)
336 for (int y = 1; y < h - 1; ++y) 358 for (int y = 1; y < h - 1; ++y)
337 dist [x - 1][y - 1] = data [x][y] == '#' ? U8 (255) : 0; 359 dist [x - 1][y - 1] = data [x][y] == '#' ? U8 (255) : 0;
338 360
339 ::isolation_remover (dist); 361 ::isolation_remover (dist, perturb);
340 362
341 // now copy the tunnels over 363 // now copy the tunnels over
342 for (int x = 1; x < w - 1; ++x) 364 for (int x = 1; x < w - 1; ++x)
343 for (int y = 1; y < h - 1; ++y) 365 for (int y = 1; y < h - 1; ++y)
344 if (data [x][y] == '#' && dist [x - 1][y - 1] == 1) 366 if (data [x][y] == '#' && dist [x - 1][y - 1] == 1)
345 data [x][y] = 0; 367 data [x][y] = 0;
346} 368}
347 369
348///////////////////////////////////////////////////////////////////////////// 370/////////////////////////////////////////////////////////////////////////////
349 371
350// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
351void
352layout::gen_cave (int subtype)
353{
354 switch (subtype)
355 {
356 // a rough cave
357 case 0:
358 fill_rand (rmg_rndm (85, 97));
359 break;
360
361 // corridors
362 case 1:
363 fill_rand (rmg_rndm (5, 40));
364 erode_1_2 (5, 2, 10);
365 erode_1_2 (5, -1, 10);
366 erode_1_2 (5, 2, 1);
367 break;
368
369 // somewhat open, roundish
370 case 2:
371 fill_rand (45);
372 erode_1_2 (5, 0, 5);
373 erode_1_2 (5, 1, 1);
374 break;
375
376 // wide open, some room-like structures
377 case 3:
378 fill_rand (45);
379 erode_1_2 (5, 2, 4);
380 erode_1_2 (5, -1, 3);
381 break;
382 }
383
384 border ();
385 isolation_remover ();
386}
387
388/////////////////////////////////////////////////////////////////////////////
389
390//+GPL 372//+GPL
391 373
392/* puts doors at appropriate locations in a maze. */ 374/* puts doors at appropriate locations in a maze. */
393void 375void
394layout::doorify () 376layout::doorify ()
395{ 377{
396 int ndoors = w * h / 60; /* reasonable number of doors. */ 378 int ndoors = w * h / 60; /* reasonable number of doors. */
397 int doorlocs = 0; /* # of available doorlocations */
398 379
399 uint16 *doorlist_x = salloc<uint16> (w * h); 380 coroapi::cede_to_tick ();
400 uint16 *doorlist_y = salloc<uint16> (w * h); 381
382 fixed_stack<point> doorloc (w * h);
401 383
402 /* make a list of possible door locations */ 384 /* make a list of possible door locations */
403 for (int i = 1; i < w - 1; i++) 385 for (int i = 1; i < w - 1; i++)
404 for (int j = 1; j < h - 1; j++) 386 for (int j = 1; j < h - 1; j++)
405 { 387 {
406 int sindex = surround_flag (*this, i, j); 388 int sindex = surround_flag (*this, i, j);
407 389
408 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 390 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
409 { 391 doorloc.push (point (i, j));
410 doorlist_x [doorlocs] = i;
411 doorlist_y [doorlocs] = j;
412 doorlocs++;
413 }
414 } 392 }
415 393
416 while (ndoors > 0 && doorlocs > 0) 394 while (ndoors && doorloc.size)
417 { 395 {
418 int di = rmg_rndm (doorlocs); 396 point p = doorloc.remove (rmg_rndm (doorloc.size));
419 int i = doorlist_x [di]; 397
420 int j = doorlist_y [di];
421 int sindex = surround_flag (*this, i, j); 398 int sindex = surround_flag (*this, p.x, p.y);
422 399
423 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 400 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
424 { 401 {
425 data [i][j] = 'D'; 402 data [p.x][p.y] = 'D';
426 ndoors--; 403 --ndoors;
427 } 404 }
428
429 /* reduce the size of the list */
430 doorlocs--;
431 doorlist_x[di] = doorlist_x [doorlocs];
432 doorlist_y[di] = doorlist_y [doorlocs];
433 } 405 }
434
435 sfree (doorlist_x, w * h);
436 sfree (doorlist_y, w * h);
437} 406}
438 407
439/* takes a map and makes it symmetric: adjusts Xsize and 408/* takes a map and makes it symmetric: adjusts Xsize and
440 * Ysize to produce a symmetric map. 409 * Ysize to produce a symmetric map.
441 */ 410 */
499//-GPL 468//-GPL
500 469
501void 470void
502layout::rotate (int rotation) 471layout::rotate (int rotation)
503{ 472{
473 coroapi::cede_to_tick ();
474
504 switch (rotation & 3) 475 switch (rotation & 3)
505 { 476 {
506 case 2: /* a reflection */ 477 case 2: /* a reflection */
507 { 478 {
508 layout new_layout (w, h); 479 layout new_layout (w, h);
563 * 1 match on (i+1, j) 534 * 1 match on (i+1, j)
564 * 2 match on (i, j+1) 535 * 2 match on (i, j+1)
565 * 4 match on (i+1, j+1) 536 * 4 match on (i+1, j+1)
566 * and the possible combinations thereof. 537 * and the possible combinations thereof.
567 */ 538 */
568static int noinline 539ecb_noinline static int
569calc_pattern (char ch, layout &maze, int i, int j) 540calc_pattern (char ch, layout &maze, int i, int j)
570{ 541{
571 int pattern = 0; 542 int pattern = 0;
572 543
573 if (i + 1 < maze.w && maze[i + 1][j] == ch) 544 if (i + 1 < maze.w && maze[i + 1][j] == ch)
660{ 631{
661 layout new_layout (w * 2 - 1, h * 2 - 1); 632 layout new_layout (w * 2 - 1, h * 2 - 1);
662 633
663 new_layout.clear (); 634 new_layout.clear ();
664 635
636 coroapi::cede_to_tick ();
637
665 for (int i = 0; i < w; i++) 638 for (int i = 0; i < w; i++)
666 for (int j = 0; j < h; j++) 639 for (int j = 0; j < h; j++)
667 switch (data [i][j]) 640 switch (data [i][j])
668 { 641 {
669 case '#': expand_wall (new_layout, i, j, *this); break; 642 case '#': expand_wall (new_layout, i, j, *this); break;
670 case 'D': expand_door (new_layout, i, j, *this); break; 643 case 'D': expand_door (new_layout, i, j, *this); break;
671 default: expand_misc (new_layout, i, j, *this); break; 644 default: expand_misc (new_layout, i, j, *this); break;
672 } 645 }
673 646
674 swap (new_layout); 647 swap (new_layout);
675} 648}
751 724
752 return -1; 725 return -1;
753} 726}
754 727
755int 728int
756make_wall (char **maze, int x, int y, int dir) 729make_wall (layout &maze, int x, int y, int dir)
757{ 730{
758 maze[x][y] = 'D'; /* mark a door */ 731 maze[x][y] = 'D'; /* mark a door */
759 732
760 switch (dir) 733 switch (dir)
761 { 734 {
778 751
779void 752void
780layout::roomify () 753layout::roomify ()
781{ 754{
782 int tries = w * h / 30; 755 int tries = w * h / 30;
756
757 coroapi::cede_to_tick ();
783 758
784 for (int ti = 0; ti < tries; ti++) 759 for (int ti = 0; ti < tries; ti++)
785 { 760 {
786 /* starting location for looking at creating a door */ 761 /* starting location for looking at creating a door */
787 int dx = rmg_rndm (w); 762 int dx = rmg_rndm (w);
810 else 785 else
811 make_wall (*this, dx, dy, 1); 786 make_wall (*this, dx, dy, 1);
812 } 787 }
813} 788}
814 789
790//-GPL
791
815///////////////////////////////////////////////////////////////////////////// 792/////////////////////////////////////////////////////////////////////////////
793
794// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
795void
796layout::gen_cave (int subtype)
797{
798 switch (subtype)
799 {
800 // a rough cave
801 case 0:
802 fill_rand (rmg_rndm (85, 97));
803 break;
804
805 // corridors
806 case 1:
807 fill_rand (rmg_rndm (5, 40));
808 erode_1_2 (5, 2, 10);
809 erode_1_2 (5, -1, 10);
810 erode_1_2 (5, 2, 1);
811 break;
812
813 // somewhat open, some room-like structures
814 case 2:
815 fill_rand (45);
816 erode_1_2 (5, 2, 4);
817 erode_1_2 (5, -1, 3);
818 break;
819
820 // wide open, roundish
821 case 3:
822 fill_rand (45);
823 erode_1_2 (5, 0, 5);
824 erode_1_2 (5, 1, 1);
825 break;
826 }
827
828 border ();
829 isolation_remover (1);
830}
831
832void
833layout::gen_castle ()
834{
835 fill ('#');
836
837 for (int n = w * h / 30 + 1; n--; )
838 {
839 int rw = rmg_rndm (6, 10);
840 int rh = rmg_rndm (6, 10);
841
842 if (rw > w || rh > h)
843 continue;
844
845 int rx = rmg_rndm (0, w - rw);
846 int ry = rmg_rndm (0, h - rh);
847
848 rect (rx, ry, rx + rw, ry + rh, '#');
849 fill_rect (rx + 1, ry + 1, rx + rw - 1, ry + rh - 1, 0);
850 }
851
852 border ();
853 isolation_remover (0);
854}
855
856static void
857gen_mixed_ (layout &maze, random_map_params *RP)
858{
859 if (maze.w > maze.h && maze.w > 16)
860 {
861 int m = rmg_rndm (8, maze.w - 8);
862
863 layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP);
864 layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP);
865 }
866 else if (maze.h > 16)
867 {
868 int m = rmg_rndm (8, maze.h - 8);
869
870 layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP);
871 layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP);
872 }
873 else
874 {
875 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1;
876
877 if (RP->map_layout_style == LAYOUT_MULTIPLE)
878 ++RP->map_layout_style;
879
880 maze.generate (RP);
881 }
882
883 coroapi::cede_to_tick ();
884}
885
886// recursive subdivision with random sublayouts
887static void
888gen_mixed (layout &maze, random_map_params *RP)
889{
890 random_map_params &rp = *new random_map_params (RP);
891 gen_mixed_ (maze, &rp);
892 delete &rp;
893
894 maze.border ();
895
896 // exits currently do not work so well, as they
897 // are currently often found together, so nuke entrances
898 maze.replace ('<', ' ');
899
900 maze.isolation_remover (0);
901}
902
903//+GPL
816 904
817/* function selects the maze function and gives it whatever 905/* function selects the maze function and gives it whatever
818 arguments it needs. */ 906 arguments it needs. */
819void 907void
820layout::generate (random_map_params *RP) 908layout::generate (random_map_params *RP)
880 if (rmg_rndm (2)) 968 if (rmg_rndm (2))
881 doorify (); 969 doorify ();
882 970
883 break; 971 break;
884 972
973 case LAYOUT_CASTLE:
974 gen_castle ();
975
976 if (rmg_rndm (2))
977 doorify ();
978
979 break;
980
981 case LAYOUT_MULTIPLE:
982 gen_mixed (*this, RP);
983 break;
984
885 default: 985 default:
886 abort (); 986 abort ();
887 } 987 }
988}
888 989
889 /* rotate the maze randomly */ 990//-GPL
890 rotate (rmg_rndm (4));
891
892 symmetrize (RP->symmetry_used);
893 991
894#if 0 992#if 0
895 print ();//D 993static void
896#endif 994gen_village (layout &maze)
995{
996 maze.clear ();
997 maze.border ();
897 998
898 if (RP->expand2x) 999 for (int n = maze.w * maze.h / 200 + 1; n--; )
899 expand2x (); 1000 {
900} 1001 int rw = rmg_rndm (6, 10);
1002 int rh = rmg_rndm (6, 10);
901 1003
902//-GPL 1004 int rx = rmg_rndm (2, maze.w - rw - 2);
1005 int ry = rmg_rndm (2, maze.h - rh - 2);
903 1006
904#if 0 1007 maze.rect (rx, ry, rx + rw, ry + rh, '#');
1008 }
1009
1010 maze.border ();
1011 maze.isolation_remover (2);
1012}
1013
905static struct demo 1014static struct demo
906{ 1015{
907 demo () 1016 demo ()
908 { 1017 {
909 rmg_rndm.seed (time (0)); 1018 rmg_rndm.seed (time (0));
1019 extern void hack();hack ();
910 1020
911 for(int i=1;i<100;i++) 1021 for(int i=1;i<100;i++)
912 { 1022 {
913 layout maze (40, 25); 1023 layout maze (40, 30);
914 maze.fill_rand (85); 1024 maze.fill_rand (99);
915 maze.border (); 1025 maze.border ();
916 maze.isolation_remover (); 1026 maze.isolation_remover (2);
917 maze.print (); 1027 maze.print ();
918 } 1028 }
919 1029
920 exit (1); 1030 exit (1);
921 } 1031 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines