--- deliantra/server/random_maps/random_map.C 2010/07/02 03:40:14 1.60 +++ deliantra/server/random_maps/random_map.C 2010/07/03 13:14:35 1.69 @@ -31,6 +31,92 @@ #define CEDE coroapi::cede_to_tick () +random_map_params::random_map_params () +{ + hv = newHV (); +} + +random_map_params::random_map_params (random_map_params *RP) +{ + *this = *RP; + + HV *copy = newHV (); + + hv_iterinit (hv); + + // does not work for utf-8 keys + while (HE *he = hv_iternext (hv)) + { + STRLEN klen; const char *key = HePV (he, klen); + hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he)); + } + + hv = copy; +} + +random_map_params::random_map_params (HV *hv) +{ + this->hv = (HV *)SvREFCNT_inc_NN ((SV *)hv); + + assign (wall_name, get_str ("wall_name")); + + xsize = get_iv ("xsize"); + ysize = get_iv ("ysize"); + expand2x = get_iv ("expand2x"); + layoutoptions1 = get_iv ("layoutoptions1"); + layoutoptions2 = get_iv ("layoutoptions2"); + layoutoptions3 = get_iv ("layoutoptions3"); + symmetry = get_iv ("symmetry"); + difficulty = get_iv ("difficulty"); + difficulty_given = get_iv ("difficulty_given"); + difficulty_increase = get_nv ("difficulty_increase"); + dungeon_level = get_iv ("dungeon_level"); + dungeon_depth = get_iv ("dungeon_depth"); + orientation = get_iv ("orientation"); + random_seed = get_uv ("random_seed"); + total_map_hp = get_nv ("total_map_hp"); // actually val64, but I am too lazy + symmetry_used = get_iv ("symmetry_used"); +} + +random_map_params::~random_map_params () +{ + SvREFCNT_dec (hv); +} + +shstr_tmp +random_map_params::as_shstr () const +{ + set ("xsize" , xsize); + set ("ysize" , ysize); + set ("layoutoptions1" , layoutoptions1); + set ("layoutoptions2" , layoutoptions2); + set ("layoutoptions3" , layoutoptions3); + set ("symmetry" , symmetry); + set ("dungeon_depth" , dungeon_depth); + set ("orientation" , orientation); + set ("random_seed" , (UV)random_seed); + set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); + set ("difficulty_increase", difficulty_increase); + set ("dungeon_level" , dungeon_level); + + dynbuf_text buf; + hv_iterinit (hv); + + // does not work for utf-8 keys + while (HE *he = hv_iternext (hv)) + { + STRLEN klen; const char *key = HePV (he, klen); + STRLEN vlen; const char *value = SvPVutf8 (HeVAL (he), vlen); + + buf.fadd (key, klen); + buf << ' '; + buf.fadd (value, vlen); + buf << '\n'; + } + + return shstr (buf); +} + noinline SV * random_map_params::get_sv (const char *option) const { @@ -102,82 +188,18 @@ set (option, newSVnv (value)); } -void -random_map_params::hv_clone () -{ - HV *copy = newHV (); - - hv_iterinit (hv); - - // does not work for utf-8 keys - while (HE *he = hv_iternext (hv)) - { - STRLEN klen; const char *key = HePV (he, klen); - hv_store (copy, key, klen, newSVsv (HeVAL (he)), HeHASH (he)); - } - - SvREFCNT_dec (hv); - hv = copy; -} - -shstr_tmp -random_map_params::as_shstr () const -{ - set ("xsize" , xsize); - set ("ysize" , ysize); - set ("monsterstyle" , monsterstyle); - set ("exit_on_final_map" , exit_on_final_map); - set ("layoutstyle" , layoutstyle); - set ("doorstyle" , doorstyle); - set ("final_map" , final_map); - set ("this_map" , this_map); - set ("expand2x" , expand2x); - set ("layoutoptions1" , layoutoptions1); - set ("layoutoptions2" , layoutoptions2); - set ("layoutoptions3" , layoutoptions3); - set ("symmetry" , symmetry); - set ("dungeon_depth" , dungeon_depth); - set ("orientation" , orientation); - set ("origin_x" , origin_x); - set ("origin_y" , origin_y); - set ("random_seed" , (UV)random_seed); - set ("difficulty" , difficulty && difficulty_given ? difficulty : 0); - set ("difficulty_increase", difficulty_increase); - set ("dungeon_level" , dungeon_level); - - dynbuf_text buf; - hv_iterinit (hv); - - // does not work for utf-8 keys - while (HE *he = hv_iternext (hv)) - { - STRLEN klen; const char *key = HePV (he, klen); - STRLEN vlen; const char *value = SvPVutf8 (HeVAL (he), vlen); - - buf.fadd (key, klen); - buf << ' '; - buf.fadd (value, vlen); - buf << '\n'; - } - - return shstr (buf); -} - -random_map_params::~random_map_params () -{ - SvREFCNT_dec (hv); -} - bool maptile::generate_random_map (random_map_params *RP) { RP->Xsize = RP->xsize; RP->Ysize = RP->ysize; + max_it (RP->dungeon_level, 1); + /* pick a random seed, or use the one from the input file */ RP->random_seed = RP->random_seed ? RP->random_seed + RP->dungeon_level - : time (0); + : pticks; // we run "single-threaded" rmg_rndm.seed (RP->random_seed); @@ -188,8 +210,8 @@ { RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ - if (RP->difficulty_increase > 0.001) - RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); + if (RP->difficulty_increase > 0.001f) + RP->difficulty = RP->dungeon_level * RP->difficulty_increase; if (RP->difficulty < 1) RP->difficulty = 1; @@ -223,55 +245,72 @@ RP->Ysize /= 2; } - if (strstr (RP->layoutstyle, "onion")) + const char *layoutstyle = RP->get_str ("layoutstyle", ""); + + if (strstr (layoutstyle, "onion")) RP->map_layout_style = LAYOUT_ONION; - else if (strstr (RP->layoutstyle, "maze")) + else if (strstr (layoutstyle, "maze")) RP->map_layout_style = LAYOUT_MAZE; - else if (strstr (RP->layoutstyle, "spiral")) + else if (strstr (layoutstyle, "spiral")) RP->map_layout_style = LAYOUT_SPIRAL; - else if (strstr (RP->layoutstyle, "rogue")) + else if (strstr (layoutstyle, "rogue")) RP->map_layout_style = LAYOUT_ROGUELIKE; - else if (strstr (RP->layoutstyle, "snake")) + else if (strstr (layoutstyle, "snake")) RP->map_layout_style = LAYOUT_SNAKE; - else if (strstr (RP->layoutstyle, "squarespiral")) + else if (strstr (layoutstyle, "squarespiral")) RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; - else if (strstr (RP->layoutstyle, "cave")) + else if (strstr (layoutstyle, "cave")) RP->map_layout_style = LAYOUT_CAVE; + else if (strstr (layoutstyle, "castle")) + RP->map_layout_style = LAYOUT_CASTLE; + else if (strstr (layoutstyle, "multiple")) + RP->map_layout_style = LAYOUT_MULTIPLE; else RP->map_layout_style = rmg_rndm (NROFLAYOUTS - 1) + 1; /* No style found - choose one randomly */ - Layout layout (RP->Xsize, RP->Ysize); - layout.generate (RP); + layout maze (RP->Xsize, RP->Ysize); + maze.generate (RP); + maze.rotate (rmg_rndm (4)); + maze.symmetrize (RP->symmetry_used); + + if (RP->expand2x) + maze.expand2x (); + +#if 0 + maze.print ();//D +#endif /* increment these for the current map */ ++RP->dungeon_level; - // need to patch RP becasue following code doesn't use the Layout object - RP->Xsize = layout.w; - RP->Ysize = layout.h; + // need to patch RP becasue following code doesn't use the layout object + RP->Xsize = maze.w; + RP->Ysize = maze.h; /* allocate the map and set the floor */ - make_map_floor (layout, RP->get_str ("floorstyle", ""), RP); + make_map_floor (maze, RP->get_str ("floorstyle", ""), RP); /* set region */ - default_region = RP->region; + default_region = region::find (RP->get_str ("region", 0)); CEDE; - place_specials_in_map (this, layout, RP); + place_specials_in_map (this, maze, RP); CEDE; - const char *wallstyle = RP->get_str ("wallstyle", 0); + const char *wallstyle = RP->get_str ("wallstyle", ""); /* create walls unless the wallstyle is "none" */ if (strcmp (wallstyle, "none")) { - make_map_walls (this, layout, wallstyle, RP->get_str ("miningstyle", ""), RP); + make_map_walls (this, maze, wallstyle, RP->get_str ("miningstyle", ""), RP); + + const char *doorstyle = RP->get_str ("doorstyle", ""); /* place doors unless doorstyle or wallstyle is "none" */ - if (strcmp (RP->doorstyle, "none")) - put_doors (this, layout, RP->doorstyle, RP); + if (strcmp (doorstyle, "none")) + put_doors (this, maze, doorstyle, RP); } CEDE; @@ -280,13 +319,15 @@ /* create exits unless the exitstyle is "none" */ if (strcmp (exitstyle, "none")) - place_exits (this, layout, exitstyle, RP->orientation, RP); + place_exits (this, maze, exitstyle, RP->orientation, RP); CEDE; + const char *monsterstyle = RP->get_str ("monsterstyle", ""); + /* create monsters unless the monsterstyle is "none" */ - if (strcmp (RP->monsterstyle, "none")) - place_monsters (this, RP->monsterstyle, RP->difficulty, RP); + if (strcmp (monsterstyle, "none")) + place_monsters (this, monsterstyle, RP->difficulty, RP); CEDE; @@ -298,7 +339,7 @@ const char *treasurestyle = RP->get_str ("treasurestyle", ""); /* create treasure unless the treasurestyle is "none" */ - place_treasure (this, layout, treasurestyle, RP->get_iv ("treasureoptions"), RP); + place_treasure (this, maze, treasurestyle, RP->get_iv ("treasureoptions"), RP); CEDE; @@ -306,7 +347,7 @@ /* create decor unless the decorstyle is "none" */ if (strcmp (decorstyle, "none")) - put_decor (this, layout, decorstyle, RP->get_iv ("decoroptions"), RP); + put_decor (this, maze, decorstyle, RP->get_iv ("decoroptions"), RP); CEDE; @@ -315,7 +356,7 @@ CEDE; - unblock_exits (this, layout, RP); + unblock_exits (this, maze, RP); msg = buf; in_memory = MAP_ACTIVE;