--- deliantra/server/random_maps/random_map.C 2006/12/14 22:45:40 1.9 +++ deliantra/server/random_maps/random_map.C 2006/12/31 17:17:23 1.12 @@ -31,7 +31,7 @@ #include void -dump_layout (char **layout, RMParms * RP) +dump_layout (char **layout, random_map_params * RP) { { int i, j; @@ -55,7 +55,7 @@ extern FILE *logfile; maptile * -generate_random_map (const char *OutFileName, RMParms * RP) +generate_random_map (const char *OutFileName, random_map_params * RP) { char **layout, buf[HUGE_BUF]; maptile *theMap; @@ -115,7 +115,7 @@ theMap = make_map_floor (layout, RP->floorstyle, RP); /* set the name of the map. */ - strcpy (theMap->path, OutFileName); + theMap->path = OutFileName; /* set region */ theMap->region = RP->region; @@ -142,7 +142,7 @@ place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); /* treasures needs to have a proper difficulty set for the map. */ - theMap->difficulty = calculate_difficulty (theMap); + theMap->difficulty = theMap->estimate_difficulty (); /* create treasure unless the treasurestyle is "none" */ if (strcmp (RP->treasurestyle, "none")) @@ -153,16 +153,18 @@ put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); /* generate treasures, etc. */ - fix_auto_apply (theMap); + theMap->fix_auto_apply (); unblock_exits (theMap, layout, RP); /* free the layout */ for (i = 0; i < RP->Xsize; i++) free (layout[i]); + free (layout); theMap->msg = strdup (buf); + theMap->in_memory = MAP_IN_MEMORY; return theMap; } @@ -170,19 +172,19 @@ /* function selects the layout function and gives it whatever arguments it needs. */ char ** -layoutgen (RMParms * RP) +layoutgen (random_map_params * RP) { char **maze = 0; int oxsize = RP->Xsize, oysize = RP->Ysize; - if (RP->symmetry == RANDOM_SYM) - RP->symmetry_used = (RANDOM () % (XY_SYM)) + 1; + if (RP->symmetry == SYMMETRY_RANDOM) + RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; else RP->symmetry_used = RP->symmetry; - if (RP->symmetry_used == Y_SYM || RP->symmetry_used == XY_SYM) + if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) RP->Ysize = RP->Ysize / 2 + 1; - if (RP->symmetry_used == X_SYM || RP->symmetry_used == XY_SYM) + if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) RP->Xsize = RP->Xsize / 2 + 1; if (RP->Xsize < MIN_RANDOM_MAP_SIZE) @@ -197,108 +199,95 @@ * calls the code to make the maps. */ if (strstr (RP->layoutstyle, "onion")) - { - RP->map_layout_style = ONION_LAYOUT; - } + RP->map_layout_style = LAYOUT_ONION; if (strstr (RP->layoutstyle, "maze")) - { - RP->map_layout_style = MAZE_LAYOUT; - } + RP->map_layout_style = LAYOUT_MAZE; if (strstr (RP->layoutstyle, "spiral")) - { - RP->map_layout_style = SPIRAL_LAYOUT; - } + RP->map_layout_style = LAYOUT_SPIRAL; if (strstr (RP->layoutstyle, "rogue")) - { - RP->map_layout_style = ROGUELIKE_LAYOUT; - } + RP->map_layout_style = LAYOUT_ROGUELIKE; if (strstr (RP->layoutstyle, "snake")) - { - RP->map_layout_style = SNAKE_LAYOUT; - } + RP->map_layout_style = LAYOUT_SNAKE; if (strstr (RP->layoutstyle, "squarespiral")) - { - RP->map_layout_style = SQUARE_SPIRAL_LAYOUT; - } + RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; + /* No style found - choose one ranomdly */ - if (RP->map_layout_style == 0) - { - RP->map_layout_style = (RANDOM () % NROFLAYOUTS) + 1; - } + if (RP->map_layout_style == LAYOUT_NONE) + RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; switch (RP->map_layout_style) { - - case ONION_LAYOUT: - maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); - if (!(RANDOM () % 3) && !(RP->layoutoptions1 & OPT_WALLS_ONLY)) - roomify_layout (maze, RP); - break; - - case MAZE_LAYOUT: - maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); - if (!(RANDOM () % 2)) - doorify_layout (maze, RP); - break; - - case SPIRAL_LAYOUT: - maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); - if (!(RANDOM () % 2)) - doorify_layout (maze, RP); - break; - - case ROGUELIKE_LAYOUT: - /* Don't put symmetry in rogue maps. There isn't much reason to - * do so in the first place (doesn't make it any more interesting), - * but more importantly, the symmetry code presumes we are symmetrizing - * spirals, or maps with lots of passages - making a symmetric rogue - * map fails because its likely that the passages the symmetry process - * creates may not connect the rooms. - */ - RP->symmetry_used = NO_SYM; - RP->Ysize = oysize; - RP->Xsize = oxsize; - maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); - /* no doorifying... done already */ - break; - - case SNAKE_LAYOUT: - maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); - if (RANDOM () % 2) - roomify_layout (maze, RP); - break; - - case SQUARE_SPIRAL_LAYOUT: - maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); - if (RANDOM () % 2) - roomify_layout (maze, RP); - break; + case LAYOUT_ONION: + maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); + if (!(RANDOM () % 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)) + doorify_layout (maze, RP); + break; + + case LAYOUT_SPIRAL: + maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); + if (!(RANDOM () % 2)) + doorify_layout (maze, RP); + break; + + case LAYOUT_ROGUELIKE: + /* Don't put symmetry in rogue maps. There isn't much reason to + * do so in the first place (doesn't make it any more interesting), + * but more importantly, the symmetry code presumes we are symmetrizing + * spirals, or maps with lots of passages - making a symmetric rogue + * map fails because its likely that the passages the symmetry process + * creates may not connect the rooms. + */ + RP->symmetry_used = SYMMETRY_NONE; + RP->Ysize = oysize; + RP->Xsize = oxsize; + maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); + /* no doorifying... done already */ + break; + + case LAYOUT_SNAKE: + maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); + if (RANDOM () % 2) + roomify_layout (maze, RP); + break; + + case LAYOUT_SQUARE_SPIRAL: + maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); + if (RANDOM () % 2) + roomify_layout (maze, RP); + break; } maze = symmetrize_layout (maze, RP->symmetry_used, RP); + #ifdef RMAP_DEBUG dump_layout (maze, RP); #endif + if (RP->expand2x) { maze = expand2x (maze, RP->Xsize, RP->Ysize); RP->Xsize = RP->Xsize * 2 - 1; RP->Ysize = RP->Ysize * 2 - 1; } + return maze; } - /* takes a map and makes it symmetric: adjusts Xsize and Ysize to produce a symmetric map. */ - char ** -symmetrize_layout (char **maze, int sym, RMParms * RP) +symmetrize_layout (char **maze, int sym, random_map_params * RP) { int i, j; char **sym_maze; @@ -307,35 +296,35 @@ Xsize_orig = RP->Xsize; Ysize_orig = RP->Ysize; RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */ - if (sym == NO_SYM) + if (sym == SYMMETRY_NONE) { RP->Xsize = Xsize_orig; RP->Ysize = Ysize_orig; return maze; } /* pick new sizes */ - RP->Xsize = ((sym == X_SYM || sym == XY_SYM) ? RP->Xsize * 2 - 3 : RP->Xsize); - RP->Ysize = ((sym == Y_SYM || sym == XY_SYM) ? RP->Ysize * 2 - 3 : RP->Ysize); + RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize); + RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize); sym_maze = (char **) calloc (sizeof (char *), RP->Xsize); for (i = 0; i < RP->Xsize; i++) sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize); - if (sym == X_SYM) + if (sym == SYMMETRY_X) for (i = 0; i < RP->Xsize / 2 + 1; i++) for (j = 0; j < RP->Ysize; j++) { sym_maze[i][j] = maze[i][j]; sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; }; - if (sym == Y_SYM) + if (sym == SYMMETRY_Y) for (i = 0; i < RP->Xsize; i++) for (j = 0; j < RP->Ysize / 2 + 1; j++) { sym_maze[i][j] = maze[i][j]; sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; } - if (sym == XY_SYM) + if (sym == SYMMETRY_XY) for (i = 0; i < RP->Xsize / 2 + 1; i++) for (j = 0; j < RP->Ysize / 2 + 1; j++) { @@ -349,11 +338,11 @@ free (maze[i]); free (maze); /* reconnect disjointed spirals */ - if (RP->map_layout_style == SPIRAL_LAYOUT) + if (RP->map_layout_style == LAYOUT_SPIRAL) connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); /* reconnect disjointed nethackmazes: the routine for spirals will do the trick? */ - if (RP->map_layout_style == ROGUELIKE_LAYOUT) + if (RP->map_layout_style == LAYOUT_ROGUELIKE) connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); return sym_maze; @@ -366,70 +355,70 @@ */ char ** -rotate_layout (char **maze, int rotation, RMParms * RP) +rotate_layout (char **maze, int rotation, random_map_params * RP) { char **new_maze; int i, j; switch (rotation) { - case 0: + case 0: + return maze; + break; + case 2: /* a reflection */ + { + char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); + + for (i = 0; i < RP->Xsize; i++) + { /* make a copy */ + for (j = 0; j < RP->Ysize; j++) + { + newmaze[i * RP->Ysize + j] = maze[i][j]; + } + } + for (i = 0; i < RP->Xsize; i++) + { /* copy a reflection back */ + for (j = 0; j < RP->Ysize; j++) + { + maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; + } + } + free (newmaze); return maze; break; - case 2: /* a reflection */ - { - char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); - - for (i = 0; i < RP->Xsize; i++) - { /* make a copy */ - for (j = 0; j < RP->Ysize; j++) - { - newmaze[i * RP->Ysize + j] = maze[i][j]; - } - } + } + case 1: + case 3: + { + int swap; + new_maze = (char **) calloc (sizeof (char *), RP->Ysize); + for (i = 0; i < RP->Ysize; i++) + { + new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); + } + if (rotation == 1) /* swap x and y */ for (i = 0; i < RP->Xsize; i++) - { /* copy a reflection back */ - for (j = 0; j < RP->Ysize; j++) - { - maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; - } - } - free (newmaze); - return maze; - break; - } - case 1: - case 3: - { - int swap; - new_maze = (char **) calloc (sizeof (char *), RP->Ysize); - for (i = 0; i < RP->Ysize; i++) - { - new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); - } - if (rotation == 1) /* swap x and y */ + for (j = 0; j < RP->Ysize; j++) + new_maze[j][i] = maze[i][j]; + + if (rotation == 3) + { /* swap x and y */ for (i = 0; i < RP->Xsize; i++) for (j = 0; j < RP->Ysize; j++) - new_maze[j][i] = maze[i][j]; + new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; + } - if (rotation == 3) - { /* swap x and y */ - for (i = 0; i < RP->Xsize; i++) - for (j = 0; j < RP->Ysize; j++) - new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; - } - - /* delete the old layout */ - for (i = 0; i < RP->Xsize; i++) - free (maze[i]); - free (maze); - - swap = RP->Ysize; - RP->Ysize = RP->Xsize; - RP->Xsize = swap; - return new_maze; - break; - } + /* delete the old layout */ + for (i = 0; i < RP->Xsize; i++) + free (maze[i]); + free (maze); + + swap = RP->Ysize; + RP->Ysize = RP->Xsize; + RP->Xsize = swap; + return new_maze; + break; + } } return NULL; } @@ -437,7 +426,7 @@ /* take a layout and make some rooms in it. --works best on onions.*/ void -roomify_layout (char **maze, RMParms * RP) +roomify_layout (char **maze, random_map_params * RP) { int tries = RP->Xsize * RP->Ysize / 30; int ti; @@ -474,7 +463,7 @@ here which ends up on other walls sensibly. */ int -can_make_wall (char **maze, int dx, int dy, int dir, RMParms * RP) +can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) { int i1; int length = 0; @@ -585,9 +574,8 @@ } /* puts doors at appropriate locations in a layout. */ - void -doorify_layout (char **maze, RMParms * RP) +doorify_layout (char **maze, random_map_params * RP) { int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ char *doorlist_x; @@ -612,6 +600,7 @@ doorlocs++; } } + while (ndoors > 0 && doorlocs > 0) { int di; @@ -631,15 +620,14 @@ doorlist_x[di] = doorlist_x[doorlocs]; doorlist_y[di] = doorlist_y[doorlocs]; } + free (doorlist_x); free (doorlist_y); } - void -write_map_parameters_to_string (char *buf, RMParms * RP) +write_map_parameters_to_string (char *buf, random_map_params * RP) { - char small_buf[256]; sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); @@ -787,6 +775,7 @@ sprintf (small_buf, "origin_y %d\n", RP->origin_y); strcat (buf, small_buf); } + if (RP->random_seed) { /* Add one so that the next map is a bit different */ @@ -799,8 +788,6 @@ sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); strcat (buf, small_buf); } - - } void @@ -907,7 +894,6 @@ strcat (buf, small_buf); } - if (layoutoptions2_n) { sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); @@ -972,6 +958,7 @@ sprintf (small_buf, "origin_y %d\n", origin_y_n); strcat (buf, small_buf); } + if (random_seed_n) { /* Add one so that the next map is a bit different */