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

Comparing deliantra/server/random_maps/random_map.C (file contents):
Revision 1.44 by root, Fri Nov 6 13:03:34 2009 UTC vs.
Revision 1.51 by root, Sat Jun 26 22:10:18 2010 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 (©) 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 (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
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.
32#define CEDE coroapi::cede_to_tick () 32#define CEDE coroapi::cede_to_tick ()
33 33
34static void symmetrize_layout (Layout maze, random_map_params *RP); 34static void symmetrize_layout (Layout maze, random_map_params *RP);
35static void rotate_layout (Layout maze, int rotation); 35static void rotate_layout (Layout maze, int rotation);
36 36
37const_utf8_string
38random_map_params::get_str (const_utf8_string option, const_utf8_string fallback) const
39{
40 SV **he = hv_fetch (hv, option, strlen (option), 0);
41
42 return he ? cfSvPVutf8_nolen (*he) : fallback;
43}
44
45IV
46random_map_params::get_iv (const char *option, IV fallback) const
47{
48 SV **he = hv_fetch (hv, option, strlen (option), 0);
49
50 return he ? SvIV (*he) : fallback;
51}
52
53random_map_params::~random_map_params ()
54{
55 SvREFCNT_dec (hv);
56}
57
37void 58void
38dump_layout (Layout layout) 59dump_layout (Layout layout)
39{ 60{
40 for (int j = 0; j < layout->h; j++) 61 for (int j = 0; j < layout->h; j++)
41 { 62 {
234 --works best on onions.*/ 255 --works best on onions.*/
235static void 256static void
236roomify_layout (char **maze, random_map_params *RP) 257roomify_layout (char **maze, random_map_params *RP)
237{ 258{
238 int tries = RP->Xsize * RP->Ysize / 30; 259 int tries = RP->Xsize * RP->Ysize / 30;
239 int ti;
240 260
241 for (ti = 0; ti < tries; ti++) 261 for (int ti = 0; ti < tries; ti++)
242 { 262 {
243 int dx, dy; /* starting location for looking at creating a door */ 263 /* 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); 264 int dx = rmg_rndm (RP->Xsize);
247 dy = rmg_rndm (RP->Ysize); 265 int dy = rmg_rndm (RP->Ysize);
248 266
267 /* results of checking on creating walls. */
249 cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ 268 int cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */
250 cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ 269 int cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */
270
251 if (cx == -1) 271 if (cx == -1)
252 { 272 {
253 if (cy != -1) 273 if (cy != -1)
254 make_wall (maze, dx, dy, 1); 274 make_wall (maze, dx, dy, 1);
255 275
271 291
272int 292int
273make_wall (char **maze, int x, int y, int dir) 293make_wall (char **maze, int x, int y, int dir)
274{ 294{
275 maze[x][y] = 'D'; /* mark a door */ 295 maze[x][y] = 'D'; /* mark a door */
296
276 switch (dir) 297 switch (dir)
277 { 298 {
278 case 0: /* horizontal */ 299 case 0: /* horizontal */
279 { 300 {
280 int i1;
281
282 for (i1 = x - 1; maze[i1][y] == 0; i1--) 301 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++) 302 for (int i1 = x + 1; maze[i1][y] == 0; ++i1) maze[i1][y] = '#';
285 maze[i1][y] = '#';
286 break; 303 break;
287 } 304 }
288 case 1: /* vertical */ 305 case 1: /* vertical */
289 { 306 {
290 int i1;
291
292 for (i1 = y - 1; maze[x][i1] == 0; i1--) 307 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++) 308 for (int i1 = y + 1; maze[x][i1] == 0; ++i1) maze[x][i1] = '#';
295 maze[x][i1] = '#';
296 break; 309 break;
297 } 310 }
298 } 311 }
299 312
300 return 0; 313 return 0;
346 sfree (doorlist_x, RP->Xsize * RP->Ysize); 359 sfree (doorlist_x, RP->Xsize * RP->Ysize);
347 sfree (doorlist_y, RP->Xsize * RP->Ysize); 360 sfree (doorlist_y, RP->Xsize * RP->Ysize);
348} 361}
349 362
350void 363void
351write_map_parameters_to_string (char *buf, random_map_params *RP) 364write_map_parameters_to_string (dynbuf_text &buf, random_map_params *RP)
352{ 365{
353 char small_buf[16384]; 366 hv_iterinit (RP->hv);
354 367
368 while (HE *he = hv_iternext (RP->hv))
369 buf << HePV (he, PL_na) << ' ' << cfSvPVutf8_nolen (HeVAL (he)) << '\n';
370
355 sprintf (buf, "xsize %d\nysize %d\n", RP->xsize, RP->ysize); 371 buf.printf ("xsize %d\nysize %d\n", RP->xsize, RP->ysize);
356 372
357 if (RP->wallstyle[0]) 373 if (RP->monsterstyle[0] ) buf.printf ("monsterstyle %s\n", RP->monsterstyle);
358 { 374 if (RP->treasurestyle[0] ) buf.printf ("treasurestyle %s\n", RP->treasurestyle);
359 sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); 375 if (RP->layoutstyle[0] ) buf.printf ("layoutstyle %s\n", RP->layoutstyle);
360 strcat (buf, small_buf); 376 if (RP->decorstyle[0] ) buf.printf ("decorstyle %s\n", RP->decorstyle);
361 } 377 if (RP->doorstyle[0] ) buf.printf ("doorstyle %s\n", RP->doorstyle);
362 378 if (RP->final_map.length () ) buf.printf ("final_map %s\n", &RP->final_map);
363 if (RP->floorstyle[0]) 379 if (RP->exit_on_final_map[0]) buf.printf ("exit_on_final_map %s\n", RP->exit_on_final_map);
364 { 380 if (RP->this_map.length () ) buf.printf ("origin_map %s\n", &RP->this_map);
365 sprintf (small_buf, "floorstyle %s\n", RP->floorstyle); 381 if (RP->expand2x ) buf.printf ("expand2x %d\n", RP->expand2x);
366 strcat (buf, small_buf); 382 if (RP->layoutoptions1 ) buf.printf ("layoutoptions1 %d\n", RP->layoutoptions1);
367 } 383 if (RP->layoutoptions2 ) buf.printf ("layoutoptions2 %d\n", RP->layoutoptions2);
368 384 if (RP->layoutoptions3 ) buf.printf ("layoutoptions3 %d\n", RP->layoutoptions3);
369 if (RP->monsterstyle[0]) 385 if (RP->symmetry ) buf.printf ("symmetry %d\n", RP->symmetry);
370 {
371 sprintf (small_buf, "monsterstyle %s\n", RP->monsterstyle);
372 strcat (buf, small_buf);
373 }
374
375 if (RP->treasurestyle[0])
376 {
377 sprintf (small_buf, "treasurestyle %s\n", RP->treasurestyle);
378 strcat (buf, small_buf);
379 }
380
381 if (RP->layoutstyle[0])
382 {
383 sprintf (small_buf, "layoutstyle %s\n", RP->layoutstyle);
384 strcat (buf, small_buf);
385 }
386
387 if (RP->decorstyle[0])
388 {
389 sprintf (small_buf, "decorstyle %s\n", RP->decorstyle);
390 strcat (buf, small_buf);
391 }
392
393 if (RP->doorstyle[0])
394 {
395 sprintf (small_buf, "doorstyle %s\n", RP->doorstyle);
396 strcat (buf, small_buf);
397 }
398
399 if (RP->exitstyle[0])
400 {
401 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
402 strcat (buf, small_buf);
403 }
404
405 if (RP->final_map.length ())
406 {
407 sprintf (small_buf, "final_map %s\n", &RP->final_map);
408 strcat (buf, small_buf);
409 }
410
411 if (RP->exit_on_final_map[0])
412 {
413 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map);
414 strcat (buf, small_buf);
415 }
416
417 if (RP->this_map.length ())
418 {
419 sprintf (small_buf, "origin_map %s\n", &RP->this_map);
420 strcat (buf, small_buf);
421 }
422
423 if (RP->expand2x)
424 {
425 sprintf (small_buf, "expand2x %d\n", RP->expand2x);
426 strcat (buf, small_buf);
427 }
428
429 if (RP->layoutoptions1)
430 {
431 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
432 strcat (buf, small_buf);
433 }
434
435 if (RP->layoutoptions2)
436 {
437 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
438 strcat (buf, small_buf);
439 }
440
441 if (RP->layoutoptions3)
442 {
443 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
444 strcat (buf, small_buf);
445 }
446
447 if (RP->symmetry)
448 {
449 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
450 strcat (buf, small_buf);
451 }
452 386
453 if (RP->difficulty && RP->difficulty_given) 387 if (RP->difficulty && RP->difficulty_given)
454 {
455 sprintf (small_buf, "difficulty %d\n", RP->difficulty); 388 buf.printf ("difficulty %d\n", RP->difficulty);
456 strcat (buf, small_buf);
457 }
458 389
459 if (RP->difficulty_increase != 1.0) 390 if (fabs (RP->difficulty_increase - 1.f) >= (1.f / 1024.f))
460 {
461 sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); 391 buf.printf ("difficulty_increase %f\n", RP->difficulty_increase);
462 strcat (buf, small_buf);
463 }
464 392
465 sprintf (small_buf, "dungeon_level %d\n", RP->dungeon_level); 393 buf.printf ("dungeon_level %d\n", RP->dungeon_level);
466 strcat (buf, small_buf);
467 394
468 if (RP->dungeon_depth) 395 if (RP->dungeon_depth ) buf.printf ("dungeon_depth %d\n", RP->dungeon_depth);
469 { 396 if (RP->decoroptions ) buf.printf ("decoroptions %d\n", RP->decoroptions);
470 sprintf (small_buf, "dungeon_depth %d\n", RP->dungeon_depth); 397 if (RP->orientation ) buf.printf ("orientation %d\n", RP->orientation);
471 strcat (buf, small_buf); 398 if (RP->origin_x ) buf.printf ("origin_x %d\n", RP->origin_x);
472 } 399 if (RP->origin_y ) buf.printf ("origin_y %d\n", RP->origin_y);
473 400 if (RP->treasureoptions ) buf.printf ("treasureoptions %d\n", RP->treasureoptions);
474 if (RP->decoroptions) 401 if (RP->random_seed ) buf.printf ("random_seed %u\n", RP->random_seed);
475 {
476 sprintf (small_buf, "decoroptions %d\n", RP->decoroptions);
477 strcat (buf, small_buf);
478 }
479
480 if (RP->orientation)
481 {
482 sprintf (small_buf, "orientation %d\n", RP->orientation);
483 strcat (buf, small_buf);
484 }
485
486 if (RP->origin_x)
487 {
488 sprintf (small_buf, "origin_x %d\n", RP->origin_x);
489 strcat (buf, small_buf);
490 }
491
492 if (RP->origin_y)
493 {
494 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
495 strcat (buf, small_buf);
496 }
497
498 if (RP->treasureoptions)
499 {
500 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
501 strcat (buf, small_buf);
502 }
503
504 if (RP->random_seed)
505 {
506 sprintf (small_buf, "random_seed %u\n", RP->random_seed);
507 strcat (buf, small_buf);
508 }
509
510 if (RP->custom)
511 {
512 sprintf (small_buf, "custom %s\n", RP->custom);
513 strcat (buf, small_buf);
514 }
515}
516
517void
518write_parameters_to_string (char *buf,
519 int xsize_n,
520 int ysize_n,
521 const char *wallstyle_n,
522 const char *floorstyle_n,
523 const char *monsterstyle_n,
524 const char *treasurestyle_n,
525 const char *layoutstyle_n,
526 const char *decorstyle_n,
527 const char *doorstyle_n,
528 const char *exitstyle_n,
529 const char *final_map_n,
530 const char *exit_on_final_map_n,
531 const char *this_map_n,
532 int layoutoptions1_n,
533 int layoutoptions2_n,
534 int layoutoptions3_n,
535 int symmetry_n,
536 int dungeon_depth_n,
537 int dungeon_level_n,
538 int difficulty_n,
539 int difficulty_given_n,
540 int decoroptions_n,
541 int orientation_n,
542 int origin_x_n,
543 int origin_y_n,
544 uint32_t random_seed_n,
545 int treasureoptions_n,
546 float difficulty_increase)
547{
548 char small_buf[16384];
549
550 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
551
552 if (wallstyle_n && wallstyle_n[0])
553 {
554 sprintf (small_buf, "wallstyle %s\n", wallstyle_n);
555 strcat (buf, small_buf);
556 }
557
558 if (floorstyle_n && floorstyle_n[0])
559 {
560 sprintf (small_buf, "floorstyle %s\n", floorstyle_n);
561 strcat (buf, small_buf);
562 }
563
564 if (monsterstyle_n && monsterstyle_n[0])
565 {
566 sprintf (small_buf, "monsterstyle %s\n", monsterstyle_n);
567 strcat (buf, small_buf);
568 }
569
570 if (treasurestyle_n && treasurestyle_n[0])
571 {
572 sprintf (small_buf, "treasurestyle %s\n", treasurestyle_n);
573 strcat (buf, small_buf);
574 }
575
576 if (layoutstyle_n && layoutstyle_n[0])
577 {
578 sprintf (small_buf, "layoutstyle %s\n", layoutstyle_n);
579 strcat (buf, small_buf);
580 }
581
582 if (decorstyle_n && decorstyle_n[0])
583 {
584 sprintf (small_buf, "decorstyle %s\n", decorstyle_n);
585 strcat (buf, small_buf);
586 }
587
588 if (doorstyle_n && doorstyle_n[0])
589 {
590 sprintf (small_buf, "doorstyle %s\n", doorstyle_n);
591 strcat (buf, small_buf);
592 }
593
594 if (exitstyle_n && exitstyle_n[0])
595 {
596 sprintf (small_buf, "exitstyle %s\n", exitstyle_n);
597 strcat (buf, small_buf);
598 }
599
600 if (final_map_n && final_map_n[0])
601 {
602 sprintf (small_buf, "final_map %s\n", final_map_n);
603 strcat (buf, small_buf);
604 }
605
606 if (exit_on_final_map_n && exit_on_final_map_n[0])
607 {
608 sprintf (small_buf, "exit_on_final_map %s\n", exit_on_final_map_n);
609 strcat (buf, small_buf);
610 }
611
612 if (this_map_n && this_map_n[0])
613 {
614 sprintf (small_buf, "origin_map %s\n", this_map_n);
615 strcat (buf, small_buf);
616 }
617
618 if (layoutoptions1_n)
619 {
620 sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n);
621 strcat (buf, small_buf);
622 }
623
624 if (layoutoptions2_n)
625 {
626 sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n);
627 strcat (buf, small_buf);
628 }
629
630
631 if (layoutoptions3_n)
632 {
633 sprintf (small_buf, "layoutoptions3 %d\n", layoutoptions3_n);
634 strcat (buf, small_buf);
635 }
636
637 if (symmetry_n)
638 {
639 sprintf (small_buf, "symmetry %d\n", symmetry_n);
640 strcat (buf, small_buf);
641 }
642
643
644 if (difficulty_n && difficulty_given_n)
645 {
646 sprintf (small_buf, "difficulty %d\n", difficulty_n);
647 strcat (buf, small_buf);
648 }
649
650 if (difficulty_increase > 0.001)
651 {
652 sprintf (small_buf, "difficulty_increase %f\n", difficulty_increase);
653 strcat (buf, small_buf);
654 }
655
656 sprintf (small_buf, "dungeon_level %d\n", dungeon_level_n);
657 strcat (buf, small_buf);
658
659 if (dungeon_depth_n)
660 {
661 sprintf (small_buf, "dungeon_depth %d\n", dungeon_depth_n);
662 strcat (buf, small_buf);
663 }
664
665 if (decoroptions_n)
666 {
667 sprintf (small_buf, "decoroptions %d\n", decoroptions_n);
668 strcat (buf, small_buf);
669 }
670
671 if (orientation_n)
672 {
673 sprintf (small_buf, "orientation %d\n", orientation_n);
674 strcat (buf, small_buf);
675 }
676
677 if (origin_x_n)
678 {
679 sprintf (small_buf, "origin_x %d\n", origin_x_n);
680 strcat (buf, small_buf);
681 }
682
683 if (origin_y_n)
684 {
685 sprintf (small_buf, "origin_y %d\n", origin_y_n);
686 strcat (buf, small_buf);
687 }
688
689 if (random_seed_n)
690 {
691 /* Add one so that the next map is a bit different */
692 sprintf (small_buf, "random_seed %u\n", random_seed_n + 1);
693 strcat (buf, small_buf);
694 }
695
696 if (treasureoptions_n)
697 {
698 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n);
699 strcat (buf, small_buf);
700 }
701} 402}
702 403
703///////////////////////////////////////////////////////////////////////////// 404/////////////////////////////////////////////////////////////////////////////
704 405
705LayoutData::LayoutData (int w, int h) 406LayoutData::LayoutData (int w, int h)
743 switch (RP->map_layout_style) 444 switch (RP->map_layout_style)
744 { 445 {
745 case LAYOUT_ONION: 446 case LAYOUT_ONION:
746 map_gen_onion (layout, RP->layoutoptions1, RP->layoutoptions2); 447 map_gen_onion (layout, RP->layoutoptions1, RP->layoutoptions2);
747 448
748 if (!(rmg_rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) 449 if (!(rmg_rndm (3)) && !(RP->layoutoptions1 & (RMOPT_WALLS_ONLY | RMOPT_WALL_OFF)))
749 roomify_layout (layout, RP); 450 roomify_layout (layout, RP);
750 451
751 break; 452 break;
752 453
753 case LAYOUT_MAZE: 454 case LAYOUT_MAZE:
815} 516}
816 517
817bool 518bool
818maptile::generate_random_map (random_map_params *RP) 519maptile::generate_random_map (random_map_params *RP)
819{ 520{
820 char buf[16384];
821 int i; 521 int i;
822 522
823 RP->Xsize = RP->xsize; 523 RP->Xsize = RP->xsize;
824 RP->Ysize = RP->ysize; 524 RP->Ysize = RP->ysize;
825 525
829 : time (0); 529 : time (0);
830 530
831 // we run "single-threaded" 531 // we run "single-threaded"
832 rmg_rndm.seed (RP->random_seed); 532 rmg_rndm.seed (RP->random_seed);
833 533
534 dynbuf_text buf;
834 write_map_parameters_to_string (buf, RP); 535 write_map_parameters_to_string (buf, RP);
835 536
836 if (RP->difficulty == 0) 537 if (RP->difficulty == 0)
837 { 538 {
838 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ 539 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
905 // need to patch RP becasue following code doesn't use the Layout object 606 // need to patch RP becasue following code doesn't use the Layout object
906 RP->Xsize = layout->w; 607 RP->Xsize = layout->w;
907 RP->Ysize = layout->h; 608 RP->Ysize = layout->h;
908 609
909 /* allocate the map and set the floor */ 610 /* allocate the map and set the floor */
910 make_map_floor (layout, RP->floorstyle, RP); 611 make_map_floor (layout, RP->get_str ("floorstyle", ""), RP);
911 612
912 /* set region */ 613 /* set region */
913 default_region = RP->region; 614 default_region = RP->region;
914 615
915 CEDE; 616 CEDE;
916 617
917 place_specials_in_map (this, layout, RP); 618 place_specials_in_map (this, layout, RP);
918 619
919 CEDE; 620 CEDE;
920 621
622 const char *wallstyle = RP->get_str ("wallstyle", 0);
623
921 /* create walls unless the wallstyle is "none" */ 624 /* create walls unless the wallstyle is "none" */
922 if (strcmp (RP->wallstyle, "none")) 625 if (strcmp (wallstyle, "none"))
923 { 626 {
924 make_map_walls (this, layout, RP->wallstyle, RP); 627 make_map_walls (this, layout, wallstyle, RP->get_str ("miningstyle", ""), RP);
925 628
926 /* place doors unless doorstyle or wallstyle is "none" */ 629 /* place doors unless doorstyle or wallstyle is "none" */
927 if (strcmp (RP->doorstyle, "none")) 630 if (strcmp (RP->doorstyle, "none"))
928 put_doors (this, layout, RP->doorstyle, RP); 631 put_doors (this, layout, RP->doorstyle, RP);
929 } 632 }
930 633
931 CEDE; 634 CEDE;
932 635
636 const char *exitstyle = RP->get_str ("exitstyle", "");
637
933 /* create exits unless the exitstyle is "none" */ 638 /* create exits unless the exitstyle is "none" */
934 if (strcmp (RP->exitstyle, "none")) 639 if (strcmp (exitstyle, "none"))
935 place_exits (this, layout, RP->exitstyle, RP->orientation, RP); 640 place_exits (this, layout, exitstyle, RP->orientation, RP);
936 641
937 CEDE; 642 CEDE;
938 643
939 /* create monsters unless the monsterstyle is "none" */ 644 /* create monsters unless the monsterstyle is "none" */
940 if (strcmp (RP->monsterstyle, "none")) 645 if (strcmp (RP->monsterstyle, "none"))
963 668
964 CEDE; 669 CEDE;
965 670
966 unblock_exits (this, layout, RP); 671 unblock_exits (this, layout, RP);
967 672
968 msg = strdup (buf); 673 msg = buf;
969 in_memory = MAP_ACTIVE; 674 in_memory = MAP_ACTIVE;
970 675
971 CEDE; 676 CEDE;
972 677
973 return 1; 678 return 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines