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. |
… | |
… | |
147 | } |
147 | } |
148 | |
148 | |
149 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
149 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
150 | (or vertical, dir == 1) |
150 | (or vertical, dir == 1) |
151 | here which ends up on other walls sensibly. */ |
151 | here which ends up on other walls sensibly. */ |
152 | int |
152 | static int |
153 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) |
153 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) |
154 | { |
154 | { |
155 | int i1; |
155 | int i1; |
156 | int length = 0; |
156 | int length = 0; |
157 | |
157 | |
… | |
… | |
230 | return -1; |
230 | return -1; |
231 | } |
231 | } |
232 | |
232 | |
233 | /* take a layout and make some rooms in it. |
233 | /* take a layout and make some rooms in it. |
234 | --works best on onions.*/ |
234 | --works best on onions.*/ |
235 | void |
235 | static void |
236 | roomify_layout (char **maze, random_map_params *RP) |
236 | roomify_layout (char **maze, random_map_params *RP) |
237 | { |
237 | { |
238 | int tries = RP->Xsize * RP->Ysize / 30; |
238 | int tries = RP->Xsize * RP->Ysize / 30; |
239 | int ti; |
239 | int ti; |
240 | |
240 | |
… | |
… | |
299 | |
299 | |
300 | return 0; |
300 | return 0; |
301 | } |
301 | } |
302 | |
302 | |
303 | /* puts doors at appropriate locations in a layout. */ |
303 | /* puts doors at appropriate locations in a layout. */ |
304 | void |
304 | static void |
305 | doorify_layout (char **maze, random_map_params *RP) |
305 | doorify_layout (char **maze, random_map_params *RP) |
306 | { |
306 | { |
307 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
307 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
308 | int doorlocs = 0; /* # of available doorlocations */ |
308 | int doorlocs = 0; /* # of available doorlocations */ |
309 | |
309 | |
… | |
… | |
358 | { |
358 | { |
359 | sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
359 | sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
360 | strcat (buf, small_buf); |
360 | strcat (buf, small_buf); |
361 | } |
361 | } |
362 | |
362 | |
|
|
363 | if (RP->miningstyle[0]) |
|
|
364 | { |
|
|
365 | sprintf (small_buf, "miningstyle %s\n", RP->miningstyle); |
|
|
366 | strcat (buf, small_buf); |
|
|
367 | } |
|
|
368 | |
363 | if (RP->floorstyle[0]) |
369 | if (RP->floorstyle[0]) |
364 | { |
370 | { |
365 | sprintf (small_buf, "floorstyle %s\n", RP->floorstyle); |
371 | sprintf (small_buf, "floorstyle %s\n", RP->floorstyle); |
366 | strcat (buf, small_buf); |
372 | strcat (buf, small_buf); |
367 | } |
373 | } |
… | |
… | |
454 | { |
460 | { |
455 | sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
461 | sprintf (small_buf, "difficulty %d\n", RP->difficulty); |
456 | strcat (buf, small_buf); |
462 | strcat (buf, small_buf); |
457 | } |
463 | } |
458 | |
464 | |
459 | if (RP->difficulty_increase != 1.0) |
465 | if (fabs (RP->difficulty_increase - 1.f) >= (1.f / 1024.f)) |
460 | { |
466 | { |
461 | sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); |
467 | sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase); |
462 | strcat (buf, small_buf); |
468 | strcat (buf, small_buf); |
463 | } |
469 | } |
464 | |
470 | |
… | |
… | |
512 | sprintf (small_buf, "custom %s\n", RP->custom); |
518 | sprintf (small_buf, "custom %s\n", RP->custom); |
513 | strcat (buf, small_buf); |
519 | strcat (buf, small_buf); |
514 | } |
520 | } |
515 | } |
521 | } |
516 | |
522 | |
517 | void |
|
|
518 | write_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 | } |
|
|
702 | |
|
|
703 | ///////////////////////////////////////////////////////////////////////////// |
523 | ///////////////////////////////////////////////////////////////////////////// |
704 | |
524 | |
705 | LayoutData::LayoutData (int w, int h) |
525 | LayoutData::LayoutData (int w, int h) |
706 | : w(w), h(h) |
526 | : w(w), h(h) |
707 | { |
527 | { |
… | |
… | |
733 | for (int j = 0; j < h; j++) col [0][j] = col [w - 1][j] = fill; |
553 | for (int j = 0; j < h; j++) col [0][j] = col [w - 1][j] = fill; |
734 | } |
554 | } |
735 | |
555 | |
736 | /* function selects the layout function and gives it whatever |
556 | /* function selects the layout function and gives it whatever |
737 | arguments it needs. */ |
557 | arguments it needs. */ |
738 | Layout |
558 | static Layout |
739 | layoutgen (random_map_params *RP) |
559 | layoutgen (random_map_params *RP) |
740 | { |
560 | { |
741 | Layout layout (RP); |
561 | Layout layout (RP); |
742 | |
562 | |
743 | switch (RP->map_layout_style) |
563 | switch (RP->map_layout_style) |
… | |
… | |
919 | CEDE; |
739 | CEDE; |
920 | |
740 | |
921 | /* create walls unless the wallstyle is "none" */ |
741 | /* create walls unless the wallstyle is "none" */ |
922 | if (strcmp (RP->wallstyle, "none")) |
742 | if (strcmp (RP->wallstyle, "none")) |
923 | { |
743 | { |
924 | make_map_walls (this, layout, RP->wallstyle, RP); |
744 | make_map_walls (this, layout, RP->wallstyle, RP->miningstyle, RP); |
925 | |
745 | |
926 | /* place doors unless doorstyle or wallstyle is "none" */ |
746 | /* place doors unless doorstyle or wallstyle is "none" */ |
927 | if (strcmp (RP->doorstyle, "none")) |
747 | if (strcmp (RP->doorstyle, "none")) |
928 | put_doors (this, layout, RP->doorstyle, RP); |
748 | put_doors (this, layout, RP->doorstyle, RP); |
929 | } |
749 | } |