--- deliantra/server/random_maps/random_map.C 2007/01/15 21:06:19 1.20 +++ deliantra/server/random_maps/random_map.C 2007/01/19 21:49:58 1.24 @@ -31,6 +31,8 @@ #include #include +#define CEDE coroapi::cede (); rndm.seed (RP->random_seed + __LINE__); + void dump_layout (char **layout, random_map_params *RP) { @@ -59,8 +61,14 @@ char **layout, buf[16384]; int i; + RP->Xsize = RP->xsize; + RP->Ysize = RP->ysize; + /* pick a random seed, or use the one from the input file */ - SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0)); + RP->random_seed = RP->random_seed + ? RP->random_seed + RP->dungeon_level + : time (0); + CEDE; write_map_parameters_to_string (buf, RP); @@ -78,10 +86,21 @@ RP->difficulty_given = 1; if (RP->Xsize < MIN_RANDOM_MAP_SIZE) - RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; + RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; if (RP->Ysize < MIN_RANDOM_MAP_SIZE) - RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; + RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; + + if (RP->symmetry == SYMMETRY_RANDOM) + RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; + else + RP->symmetry_used = RP->symmetry; + + if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) + RP->Ysize = RP->Ysize / 2 + 1; + + if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) + RP->Xsize = RP->Xsize / 2 + 1; if (RP->expand2x > 0) { @@ -89,6 +108,35 @@ RP->Ysize /= 2; } + RP->map_layout_style = LAYOUT_NONE; + + /* Redo this - there was a lot of redundant code of checking for preset + * layout style and then random layout style. Instead, figure out + * the numeric layoutstyle, so there is only one area that actually + * calls the code to make the maps. + */ + if (strstr (RP->layoutstyle, "onion")) + RP->map_layout_style = LAYOUT_ONION; + + if (strstr (RP->layoutstyle, "maze")) + RP->map_layout_style = LAYOUT_MAZE; + + if (strstr (RP->layoutstyle, "spiral")) + RP->map_layout_style = LAYOUT_SPIRAL; + + if (strstr (RP->layoutstyle, "rogue")) + RP->map_layout_style = LAYOUT_ROGUELIKE; + + if (strstr (RP->layoutstyle, "snake")) + RP->map_layout_style = LAYOUT_SNAKE; + + if (strstr (RP->layoutstyle, "squarespiral")) + RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; + + /* No style found - choose one randomly */ + if (RP->map_layout_style == LAYOUT_NONE) + RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; + layout = layoutgen (RP); #ifdef RMAP_DEBUG @@ -101,7 +149,7 @@ /* difficulty+=1; */ /* rotate the layout randomly */ - layout = rotate_layout (layout, RANDOM () % 4, RP); + layout = rotate_layout (layout, rndm (4), RP); #ifdef RMAP_DEBUG dump_layout (layout, RP); #endif @@ -112,7 +160,7 @@ /* set region */ region = RP->region; - coroapi::cede (); + CEDE; /* create walls unless the wallstyle is "none" */ if (strcmp (RP->wallstyle, "none")) @@ -122,48 +170,48 @@ /* place doors unless doorstyle or wallstyle is "none" */ if (strcmp (RP->doorstyle, "none")) put_doors (this, layout, RP->doorstyle, RP); - } - coroapi::cede (); + CEDE; /* create exits unless the exitstyle is "none" */ if (strcmp (RP->exitstyle, "none")) place_exits (this, layout, RP->exitstyle, RP->orientation, RP); - coroapi::cede (); + CEDE; place_specials_in_map (this, layout, RP); - coroapi::cede (); + CEDE; /* create monsters unless the monsterstyle is "none" */ if (strcmp (RP->monsterstyle, "none")) place_monsters (this, RP->monsterstyle, RP->difficulty, RP); - coroapi::cede (); + CEDE; /* treasures needs to have a proper difficulty set for the map. */ difficulty = estimate_difficulty (); - coroapi::cede (); + CEDE; /* create treasure unless the treasurestyle is "none" */ if (strcmp (RP->treasurestyle, "none")) place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); - coroapi::cede (); + CEDE; /* create decor unless the decorstyle is "none" */ if (strcmp (RP->decorstyle, "none")) put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); - coroapi::cede (); + CEDE; /* generate treasures, etc. */ fix_auto_apply (); - coroapi::cede (); + CEDE; + unblock_exits (this, layout, RP); /* free the layout */ @@ -175,6 +223,8 @@ msg = strdup (buf); in_memory = MAP_IN_MEMORY; + CEDE; + return 1; } @@ -186,66 +236,23 @@ char **maze = 0; int oxsize = RP->Xsize, oysize = RP->Ysize; - if (RP->symmetry == SYMMETRY_RANDOM) - RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; - else - RP->symmetry_used = RP->symmetry; - - if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) - RP->Ysize = RP->Ysize / 2 + 1; - if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) - RP->Xsize = RP->Xsize / 2 + 1; - - if (RP->Xsize < MIN_RANDOM_MAP_SIZE) - RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; - if (RP->Ysize < MIN_RANDOM_MAP_SIZE) - RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; - RP->map_layout_style = 0; - - /* Redo this - there was a lot of redundant code of checking for preset - * layout style and then random layout style. Instead, figure out - * the numeric layoutstyle, so there is only one area that actually - * calls the code to make the maps. - */ - if (strstr (RP->layoutstyle, "onion")) - RP->map_layout_style = LAYOUT_ONION; - - if (strstr (RP->layoutstyle, "maze")) - RP->map_layout_style = LAYOUT_MAZE; - - if (strstr (RP->layoutstyle, "spiral")) - RP->map_layout_style = LAYOUT_SPIRAL; - - if (strstr (RP->layoutstyle, "rogue")) - RP->map_layout_style = LAYOUT_ROGUELIKE; - - if (strstr (RP->layoutstyle, "snake")) - RP->map_layout_style = LAYOUT_SNAKE; - - if (strstr (RP->layoutstyle, "squarespiral")) - RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; - - /* No style found - choose one ranomdly */ - if (RP->map_layout_style == LAYOUT_NONE) - RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; - switch (RP->map_layout_style) { case LAYOUT_ONION: maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); - if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) + if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) roomify_layout (maze, RP); break; case LAYOUT_MAZE: - maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); - if (!(RANDOM () % 2)) + maze = maze_gen (RP->Xsize, RP->Ysize, rndm (2)); + if (!(rndm (2))) doorify_layout (maze, RP); break; case LAYOUT_SPIRAL: maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); - if (!(RANDOM () % 2)) + if (!(rndm (2))) doorify_layout (maze, RP); break; @@ -266,13 +273,13 @@ case LAYOUT_SNAKE: maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); - if (RANDOM () % 2) + if (rndm (2)) roomify_layout (maze, RP); break; case LAYOUT_SQUARE_SPIRAL: maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); - if (RANDOM () % 2) + if (rndm (2)) roomify_layout (maze, RP); break; } @@ -639,7 +646,7 @@ { char small_buf[16384]; - sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); + sprintf (buf, "xsize %d\nysize %d\n", RP->xsize, RP->ysize); if (RP->wallstyle[0]) {