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.17 by root, Sat Jul 3 13:14:35 2010 UTC vs.
Revision 1.21 by root, Sun Jul 4 01:01:42 2010 UTC

238 if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1); 238 if (y < dist.h - 1 && U8 (dist [x][y + 1]) < d && dist [x][y + 1] > 1) neigh [ncnt++] = point (x, y + 1);
239 239
240 if (!ncnt) 240 if (!ncnt)
241 return; 241 return;
242 242
243 point &p = neigh [perturb ? rmg_rndm (ncnt) : 0]; 243 point p = neigh [perturb ? rmg_rndm (ncnt) : 0];
244 244
245 seeds.push (p); 245 seeds.push (p);
246 246
247 x = p.x; 247 x = p.x;
248 y = p.y; 248 y = p.y;
273 // dist contains 273 // dist contains
274 // 0 == invisited rooms 274 // 0 == invisited rooms
275 // 1 == visited rooms 275 // 1 == visited rooms
276 // 2+ shortest distance to random near room 276 // 2+ shortest distance to random near room
277 277
278 max_it (perturb, 0); 278 clamp_it (perturb, 0, 2);
279 min_it (perturb, 2);
280 279
281 // phase 1, find seed 280 // phase 1, find seed
282 int cnt = 0; 281 int cnt = 0;
283 int x, y; 282 int x, y;
284 283
358/* puts doors at appropriate locations in a maze. */ 357/* puts doors at appropriate locations in a maze. */
359void 358void
360layout::doorify () 359layout::doorify ()
361{ 360{
362 int ndoors = w * h / 60; /* reasonable number of doors. */ 361 int ndoors = w * h / 60; /* reasonable number of doors. */
363 int doorlocs = 0; /* # of available doorlocations */
364 362
365 uint16 *doorlist_x = salloc<uint16> (w * h); 363 fixed_stack<point> doorloc (w * h);
366 uint16 *doorlist_y = salloc<uint16> (w * h);
367 364
368 /* make a list of possible door locations */ 365 /* make a list of possible door locations */
369 for (int i = 1; i < w - 1; i++) 366 for (int i = 1; i < w - 1; i++)
370 for (int j = 1; j < h - 1; j++) 367 for (int j = 1; j < h - 1; j++)
371 { 368 {
372 int sindex = surround_flag (*this, i, j); 369 int sindex = surround_flag (*this, i, j);
373 370
374 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 371 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
375 { 372 doorloc.push (point (i, j));
376 doorlist_x [doorlocs] = i;
377 doorlist_y [doorlocs] = j;
378 doorlocs++;
379 }
380 } 373 }
381 374
382 while (ndoors > 0 && doorlocs > 0) 375 while (ndoors && doorloc.size)
383 { 376 {
384 int di = rmg_rndm (doorlocs); 377 point p = doorloc.remove (rmg_rndm (doorloc.size));
385 int i = doorlist_x [di]; 378
386 int j = doorlist_y [di];
387 int sindex = surround_flag (*this, i, j); 379 int sindex = surround_flag (*this, p.x, p.y);
388 380
389 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 381 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
390 { 382 {
391 data [i][j] = 'D'; 383 data [p.x][p.y] = 'D';
392 ndoors--; 384 --ndoors;
393 } 385 }
394
395 /* reduce the size of the list */
396 doorlocs--;
397 doorlist_x[di] = doorlist_x [doorlocs];
398 doorlist_y[di] = doorlist_y [doorlocs];
399 } 386 }
400
401 sfree (doorlist_x, w * h);
402 sfree (doorlist_y, w * h);
403} 387}
404 388
405/* takes a map and makes it symmetric: adjusts Xsize and 389/* takes a map and makes it symmetric: adjusts Xsize and
406 * Ysize to produce a symmetric map. 390 * Ysize to produce a symmetric map.
407 */ 391 */
776 else 760 else
777 make_wall (*this, dx, dy, 1); 761 make_wall (*this, dx, dy, 1);
778 } 762 }
779} 763}
780 764
765//-GPL
766
781///////////////////////////////////////////////////////////////////////////// 767/////////////////////////////////////////////////////////////////////////////
782 768
783// inspired mostly by http://www.jimrandomh.org/misc/caves.txt 769// inspired mostly by http://www.jimrandomh.org/misc/caves.txt
784void 770void
785layout::gen_cave (int subtype) 771layout::gen_cave (int subtype)
797 erode_1_2 (5, 2, 10); 783 erode_1_2 (5, 2, 10);
798 erode_1_2 (5, -1, 10); 784 erode_1_2 (5, -1, 10);
799 erode_1_2 (5, 2, 1); 785 erode_1_2 (5, 2, 1);
800 break; 786 break;
801 787
802 // somewhat open, roundish 788 // somewhat open, some room-like structures
803 case 2: 789 case 2:
790 fill_rand (45);
791 erode_1_2 (5, 2, 4);
792 erode_1_2 (5, -1, 3);
793 break;
794
795 // wide open, roundish
796 case 3:
804 fill_rand (45); 797 fill_rand (45);
805 erode_1_2 (5, 0, 5); 798 erode_1_2 (5, 0, 5);
806 erode_1_2 (5, 1, 1); 799 erode_1_2 (5, 1, 1);
807 break; 800 break;
808
809 // wide open, some room-like structures
810 case 3:
811 fill_rand (45);
812 erode_1_2 (5, 2, 4);
813 erode_1_2 (5, -1, 3);
814 break;
815 } 801 }
816 802
817 border (); 803 border ();
818 isolation_remover (); 804 isolation_remover (1);
819} 805}
820 806
821void 807void
822layout::gen_castle () 808layout::gen_castle ()
823{ 809{
826 for (int n = w * h / 30 + 1; n--; ) 812 for (int n = w * h / 30 + 1; n--; )
827 { 813 {
828 int rw = rmg_rndm (6, 10); 814 int rw = rmg_rndm (6, 10);
829 int rh = rmg_rndm (6, 10); 815 int rh = rmg_rndm (6, 10);
830 816
817 if (rw > w || rh > h)
818 continue;
819
831 int rx = rmg_rndm (0, w - rw); 820 int rx = rmg_rndm (0, w - rw);
832 int ry = rmg_rndm (0, h - rh); 821 int ry = rmg_rndm (0, h - rh);
833 822
834 rect (rx, ry, rx + rw, ry + rh, '#'); 823 rect (rx, ry, rx + rw, ry + rh, '#');
835 fill_rect (rx + 1, ry + 1, rx + rw - 1, ry + rh - 1, 0); 824 fill_rect (rx + 1, ry + 1, rx + rw - 1, ry + rh - 1, 0);
838 border (); 827 border ();
839 isolation_remover (0); 828 isolation_remover (0);
840} 829}
841 830
842static void 831static void
843gen_mixed_ (layout &maze, random_map_params *RP, int dir) 832gen_mixed_ (layout &maze, random_map_params *RP)
844{ 833{
834 int dir;
835
845 if (maze.w < 20 && maze.h < 20 && !rmg_rndm (3)) 836 if (maze.w < 20 && maze.h < 20 && !rmg_rndm (3))
846 dir = 2; // stop recursion randomly 837 dir = 2; // stop recursion randomly
838 else
839 dir = maze.w > maze.h;
847 840
848 if (dir == 0 && maze.w > 16) 841 if (dir == 0 && maze.w > 16)
849 { 842 {
850 int m = rmg_rndm (8, maze.w - 8); 843 int m = rmg_rndm (8, maze.w - 8);
851 844
852 layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP, !dir); 845 layout m1 (maze, 0, 0, m , maze.h); gen_mixed_ (m1, RP);
853 layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); 846 layout m2 (maze, m, 0, maze.w, maze.h); gen_mixed_ (m2, RP);
854 } 847 }
855 else if (dir == 1 && maze.h > 16) 848 else if (dir == 1 && maze.h > 16)
856 { 849 {
857 int m = rmg_rndm (8, maze.h - 8); 850 int m = rmg_rndm (8, maze.h - 8);
858 851
859 layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP, !dir); 852 layout m1 (maze, 0, 0, maze.w, m ); gen_mixed_ (m1, RP);
860 layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP, !dir); 853 layout m2 (maze, 0, m, maze.w, maze.h); gen_mixed_ (m2, RP);
861 } 854 }
862 else 855 else
863 { 856 {
864 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1; 857 RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 2) + 1;
865 858
873// recursive subdivision with random sublayouts 866// recursive subdivision with random sublayouts
874static void 867static void
875gen_mixed (layout &maze, random_map_params *RP) 868gen_mixed (layout &maze, random_map_params *RP)
876{ 869{
877 random_map_params &rp = *new random_map_params (RP); 870 random_map_params &rp = *new random_map_params (RP);
878 gen_mixed_ (maze, &rp, rmg_rndm (2)); 871 gen_mixed_ (maze, &rp);
879 delete &rp; 872 delete &rp;
880 873
881 maze.border (); 874 maze.border ();
882 maze.isolation_remover (); 875 maze.isolation_remover (0);
883} 876}
877
878//+GPL
884 879
885/* function selects the maze function and gives it whatever 880/* function selects the maze function and gives it whatever
886 arguments it needs. */ 881 arguments it needs. */
887void 882void
888layout::generate (random_map_params *RP) 883layout::generate (random_map_params *RP)
968} 963}
969 964
970//-GPL 965//-GPL
971 966
972#if 0 967#if 0
968static void
969gen_village (layout &maze)
970{
971 maze.clear ();
972 maze.border ();
973
974 for (int n = maze.w * maze.h / 200 + 1; n--; )
975 {
976 int rw = rmg_rndm (6, 10);
977 int rh = rmg_rndm (6, 10);
978
979 int rx = rmg_rndm (2, maze.w - rw - 2);
980 int ry = rmg_rndm (2, maze.h - rh - 2);
981
982 maze.rect (rx, ry, rx + rw, ry + rh, '#');
983 }
984
985 maze.border ();
986 maze.isolation_remover (2);
987}
988
973static struct demo 989static struct demo
974{ 990{
975 demo () 991 demo ()
976 { 992 {
977 rmg_rndm.seed (time (0)); 993 rmg_rndm.seed (time (0));
978 994
979 for(int i=1;i<100;i++) 995 for(int i=1;i<100;i++)
980 { 996 {
981 layout maze (40, 25); 997 layout maze (40, 30);
982 maze.gen_castle (); 998 gen_village (maze);
983 maze.doorify (); 999 maze.doorify ();
984 maze.print (); 1000 maze.print ();
985 exit(0); 1001 exit(0);
986 } 1002 }
987 1003

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines