--- deliantra/server/random_maps/random_map.C 2006/12/31 20:48:27 1.15 +++ deliantra/server/random_maps/random_map.C 2007/01/18 19:42:10 1.21 @@ -1,26 +1,26 @@ - /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2001 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The authors can be reached via e-mail at -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2001 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The authors can be reached via e-mail at + */ #include #include @@ -53,11 +53,10 @@ printf ("\n"); } -maptile * -generate_random_map (const char *OutFileName, random_map_params *RP) +bool +maptile::generate_random_map (random_map_params *RP) { - char **layout, buf[HUGE_BUF]; - maptile *theMap; + char **layout, buf[16384]; int i; /* pick a random seed, or use the one from the input file */ @@ -79,10 +78,10 @@ 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->expand2x > 0) { @@ -102,65 +101,70 @@ /* 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 /* allocate the map and set the floor */ - theMap = make_map_floor (layout, RP->floorstyle, RP); - - /* set the name of the map. */ - theMap->path = OutFileName; + make_map_floor (layout, RP->floorstyle, RP); /* set region */ - theMap->region = RP->region; + region = RP->region; coroapi::cede (); + /* create walls unless the wallstyle is "none" */ if (strcmp (RP->wallstyle, "none")) { - make_map_walls (theMap, layout, RP->wallstyle, RP); + make_map_walls (this, layout, RP->wallstyle, RP); /* place doors unless doorstyle or wallstyle is "none" */ if (strcmp (RP->doorstyle, "none")) - put_doors (theMap, layout, RP->doorstyle, RP); + put_doors (this, layout, RP->doorstyle, RP); } coroapi::cede (); + /* create exits unless the exitstyle is "none" */ if (strcmp (RP->exitstyle, "none")) - place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); + place_exits (this, layout, RP->exitstyle, RP->orientation, RP); coroapi::cede (); - place_specials_in_map (theMap, layout, RP); + + place_specials_in_map (this, layout, RP); coroapi::cede (); + /* create monsters unless the monsterstyle is "none" */ if (strcmp (RP->monsterstyle, "none")) - place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); + place_monsters (this, RP->monsterstyle, RP->difficulty, RP); coroapi::cede (); + /* treasures needs to have a proper difficulty set for the map. */ - theMap->difficulty = theMap->estimate_difficulty (); + difficulty = estimate_difficulty (); coroapi::cede (); + /* create treasure unless the treasurestyle is "none" */ if (strcmp (RP->treasurestyle, "none")) - place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); + place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); coroapi::cede (); + /* create decor unless the decorstyle is "none" */ if (strcmp (RP->decorstyle, "none")) - put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); + put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); coroapi::cede (); + /* generate treasures, etc. */ - theMap->fix_auto_apply (); + fix_auto_apply (); coroapi::cede (); - unblock_exits (theMap, layout, RP); + unblock_exits (this, layout, RP); /* free the layout */ for (i = 0; i < RP->Xsize; i++) @@ -168,10 +172,10 @@ free (layout); - theMap->msg = strdup (buf); - theMap->in_memory = MAP_IN_MEMORY; + msg = strdup (buf); + in_memory = MAP_IN_MEMORY; - return theMap; + return 1; } /* function selects the layout function and gives it whatever @@ -193,9 +197,9 @@ RP->Xsize = RP->Xsize / 2 + 1; if (RP->Xsize < MIN_RANDOM_MAP_SIZE) - RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; + RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (5); if (RP->Ysize < MIN_RANDOM_MAP_SIZE) - RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; + RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (5); RP->map_layout_style = 0; /* Redo this - there was a lot of redundant code of checking for preset @@ -229,19 +233,19 @@ { 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; @@ -262,13 +266,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; } @@ -633,7 +637,7 @@ void write_map_parameters_to_string (char *buf, random_map_params *RP) { - char small_buf[2048]; + char small_buf[16384]; sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); @@ -778,13 +782,6 @@ strcat (buf, small_buf); } - if (RP->random_seed) - { - /* Add one so that the next map is a bit different */ - sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); - strcat (buf, small_buf); - } - if (RP->treasureoptions) { sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); @@ -796,6 +793,12 @@ sprintf (small_buf, "random_seed %d\n", RP->random_seed); strcat (buf, small_buf); } + + if (RP->custom) + { + sprintf (small_buf, "custom %s\n", RP->custom); + strcat (buf, small_buf); + } } void @@ -825,7 +828,7 @@ int orientation_n, int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) { - char small_buf[2048]; + char small_buf[16384]; sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);