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.22 by root, Fri Jan 19 15:29:52 2007 UTC vs.
Revision 1.29 by root, Tue Apr 17 10:06:34 2007 UTC

29#include <room_gen.h> 29#include <room_gen.h>
30#include <random_map.h> 30#include <random_map.h>
31#include <rproto.h> 31#include <rproto.h>
32#include <sproto.h> 32#include <sproto.h>
33 33
34#define CEDE coroapi::cede (); rndm.seed (RP->random_seed + __LINE__); 34#define CEDE coroapi::cede_to_tick (); rndm.seed (RP->random_seed + __LINE__);
35 35
36void 36void
37dump_layout (char **layout, random_map_params *RP) 37dump_layout (char **layout, random_map_params *RP)
38{ 38{
39 { 39 {
59maptile::generate_random_map (random_map_params *RP) 59maptile::generate_random_map (random_map_params *RP)
60{ 60{
61 char **layout, buf[16384]; 61 char **layout, buf[16384];
62 int i; 62 int i;
63 63
64 RP->Xsize = RP->xsize;
65 RP->Ysize = RP->ysize;
66
64 /* pick a random seed, or use the one from the input file */ 67 /* pick a random seed, or use the one from the input file */
65 RP->random_seed = RP->random_seed 68 RP->random_seed = RP->random_seed
66 ? RP->random_seed + RP->dungeon_level 69 ? RP->random_seed + RP->dungeon_level
67 : time (0); 70 : time (0);
68 CEDE; 71 CEDE;
87 90
88 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 91 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
89 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; 92 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
90 93
91 if (RP->symmetry == SYMMETRY_RANDOM) 94 if (RP->symmetry == SYMMETRY_RANDOM)
92 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; 95 RP->symmetry_used = rndm (SYMMETRY_XY) + 1;
93 else 96 else
94 RP->symmetry_used = RP->symmetry; 97 RP->symmetry_used = RP->symmetry;
95 98
96 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) 99 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
97 RP->Ysize = RP->Ysize / 2 + 1; 100 RP->Ysize = RP->Ysize / 2 + 1;
101
98 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) 102 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
99 RP->Xsize = RP->Xsize / 2 + 1; 103 RP->Xsize = RP->Xsize / 2 + 1;
100 104
101 if (RP->expand2x > 0) 105 if (RP->expand2x > 0)
102 { 106 {
129 if (strstr (RP->layoutstyle, "squarespiral")) 133 if (strstr (RP->layoutstyle, "squarespiral"))
130 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; 134 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
131 135
132 /* No style found - choose one randomly */ 136 /* No style found - choose one randomly */
133 if (RP->map_layout_style == LAYOUT_NONE) 137 if (RP->map_layout_style == LAYOUT_NONE)
134 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; 138 RP->map_layout_style = rndm (NROFLAYOUTS - 1) + 1;
135 139
136 layout = layoutgen (RP); 140 layout = layoutgen (RP);
137 141
138#ifdef RMAP_DEBUG 142#ifdef RMAP_DEBUG
139 dump_layout (layout, RP); 143 dump_layout (layout, RP);
152 156
153 /* allocate the map and set the floor */ 157 /* allocate the map and set the floor */
154 make_map_floor (layout, RP->floorstyle, RP); 158 make_map_floor (layout, RP->floorstyle, RP);
155 159
156 /* set region */ 160 /* set region */
157 region = RP->region; 161 default_region = RP->region;
158 162
159 CEDE; 163 CEDE;
160 164
161 /* create walls unless the wallstyle is "none" */ 165 /* create walls unless the wallstyle is "none" */
162 if (strcmp (RP->wallstyle, "none")) 166 if (strcmp (RP->wallstyle, "none"))
164 make_map_walls (this, layout, RP->wallstyle, RP); 168 make_map_walls (this, layout, RP->wallstyle, RP);
165 169
166 /* place doors unless doorstyle or wallstyle is "none" */ 170 /* place doors unless doorstyle or wallstyle is "none" */
167 if (strcmp (RP->doorstyle, "none")) 171 if (strcmp (RP->doorstyle, "none"))
168 put_doors (this, layout, RP->doorstyle, RP); 172 put_doors (this, layout, RP->doorstyle, RP);
169
170 } 173 }
171 174
172 CEDE; 175 CEDE;
173 176
174 /* create exits unless the exitstyle is "none" */ 177 /* create exits unless the exitstyle is "none" */
447 for (ti = 0; ti < tries; ti++) 450 for (ti = 0; ti < tries; ti++)
448 { 451 {
449 int dx, dy; /* starting location for looking at creating a door */ 452 int dx, dy; /* starting location for looking at creating a door */
450 int cx, cy; /* results of checking on creating walls. */ 453 int cx, cy; /* results of checking on creating walls. */
451 454
452 dx = RANDOM () % RP->Xsize; 455 dx = rndm (RP->Xsize);
453 dy = RANDOM () % RP->Ysize; 456 dy = rndm (RP->Ysize);
457
454 cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ 458 cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */
455 cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ 459 cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */
456 if (cx == -1) 460 if (cx == -1)
457 { 461 {
458 if (cy != -1) 462 if (cy != -1)
459 make_wall (maze, dx, dy, 1); 463 make_wall (maze, dx, dy, 1);
464
460 continue; 465 continue;
461 } 466 }
467
462 if (cy == -1) 468 if (cy == -1)
463 { 469 {
464 make_wall (maze, dx, dy, 0); 470 make_wall (maze, dx, dy, 0);
465 continue; 471 continue;
466 } 472 }
473
467 if (cx < cy) 474 if (cx < cy)
468 make_wall (maze, dx, dy, 0); 475 make_wall (maze, dx, dy, 0);
469 else 476 else
470 make_wall (maze, dx, dy, 1); 477 make_wall (maze, dx, dy, 1);
471 } 478 }
617 while (ndoors > 0 && doorlocs > 0) 624 while (ndoors > 0 && doorlocs > 0)
618 { 625 {
619 int di; 626 int di;
620 int sindex; 627 int sindex;
621 628
622 di = RANDOM () % doorlocs; 629 di = rndm (doorlocs);
623 i = doorlist_x[di]; 630 i = doorlist_x[di];
624 j = doorlist_y[di]; 631 j = doorlist_y[di];
625 sindex = surround_flag (maze, i, j, RP); 632 sindex = surround_flag (maze, i, j, RP);
633
626 if (sindex == 3 || sindex == 12) /* these are possible door sindex */ 634 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
627 { 635 {
628 maze[i][j] = 'D'; 636 maze[i][j] = 'D';
629 ndoors--; 637 ndoors--;
630 } 638 }
639
631 /* reduce the size of the list */ 640 /* reduce the size of the list */
632 doorlocs--; 641 doorlocs--;
633 doorlist_x[di] = doorlist_x[doorlocs]; 642 doorlist_x[di] = doorlist_x[doorlocs];
634 doorlist_y[di] = doorlist_y[doorlocs]; 643 doorlist_y[di] = doorlist_y[doorlocs];
635 } 644 }
641void 650void
642write_map_parameters_to_string (char *buf, random_map_params *RP) 651write_map_parameters_to_string (char *buf, random_map_params *RP)
643{ 652{
644 char small_buf[16384]; 653 char small_buf[16384];
645 654
646 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 655 sprintf (buf, "xsize %d\nysize %d\n", RP->xsize, RP->ysize);
647 656
648 if (RP->wallstyle[0]) 657 if (RP->wallstyle[0])
649 { 658 {
650 sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); 659 sprintf (small_buf, "wallstyle %s\n", RP->wallstyle);
651 strcat (buf, small_buf); 660 strcat (buf, small_buf);
792 strcat (buf, small_buf); 801 strcat (buf, small_buf);
793 } 802 }
794 803
795 if (RP->random_seed) 804 if (RP->random_seed)
796 { 805 {
797 sprintf (small_buf, "random_seed %d\n", RP->random_seed); 806 sprintf (small_buf, "random_seed %u\n", RP->random_seed);
798 strcat (buf, small_buf); 807 strcat (buf, small_buf);
799 } 808 }
800 809
801 if (RP->custom) 810 if (RP->custom)
802 { 811 {
807 816
808void 817void
809write_parameters_to_string (char *buf, 818write_parameters_to_string (char *buf,
810 int xsize_n, 819 int xsize_n,
811 int ysize_n, 820 int ysize_n,
812 char *wallstyle_n, 821 const char *wallstyle_n,
813 char *floorstyle_n, 822 const char *floorstyle_n,
814 char *monsterstyle_n, 823 const char *monsterstyle_n,
815 char *treasurestyle_n, 824 const char *treasurestyle_n,
816 char *layoutstyle_n, 825 const char *layoutstyle_n,
817 char *decorstyle_n, 826 const char *decorstyle_n,
818 char *doorstyle_n, 827 const char *doorstyle_n,
819 char *exitstyle_n, 828 const char *exitstyle_n,
820 char *final_map_n, 829 const char *final_map_n,
821 char *exit_on_final_map_n, 830 const char *exit_on_final_map_n,
822 char *this_map_n, 831 const char *this_map_n,
823 int layoutoptions1_n, 832 int layoutoptions1_n,
824 int layoutoptions2_n, 833 int layoutoptions2_n,
825 int layoutoptions3_n, 834 int layoutoptions3_n,
826 int symmetry_n, 835 int symmetry_n,
827 int dungeon_depth_n, 836 int dungeon_depth_n,
828 int dungeon_level_n, 837 int dungeon_level_n,
829 int difficulty_n, 838 int difficulty_n,
830 int difficulty_given_n, 839 int difficulty_given_n,
831 int decoroptions_n, 840 int decoroptions_n,
832 int orientation_n, 841 int orientation_n,
833 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) 842 int origin_x_n,
843 int origin_y_n,
844 uint32_t random_seed_n,
845 int treasureoptions_n,
846 float difficulty_increase)
834{ 847{
835 char small_buf[16384]; 848 char small_buf[16384];
836 849
837 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); 850 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
838 851
974 } 987 }
975 988
976 if (random_seed_n) 989 if (random_seed_n)
977 { 990 {
978 /* Add one so that the next map is a bit different */ 991 /* Add one so that the next map is a bit different */
979 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); 992 sprintf (small_buf, "random_seed %u\n", random_seed_n + 1);
980 strcat (buf, small_buf); 993 strcat (buf, small_buf);
981 } 994 }
982 995
983 if (treasureoptions_n) 996 if (treasureoptions_n)
984 { 997 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines