--- deliantra/server/random_maps/random_map.C 2006/12/30 18:45:28 1.11 +++ deliantra/server/random_maps/random_map.C 2007/01/06 14:42:30 1.17 @@ -1,6 +1,7 @@ /* 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 @@ -31,7 +32,7 @@ #include void -dump_layout (char **layout, random_map_params * RP) +dump_layout (char **layout, random_map_params *RP) { { int i, j; @@ -52,20 +53,15 @@ printf ("\n"); } -extern FILE *logfile; - maptile * -generate_random_map (const char *OutFileName, random_map_params * RP) +generate_random_map (const char *OutFileName, random_map_params *RP) { char **layout, buf[HUGE_BUF]; maptile *theMap; int i; /* pick a random seed, or use the one from the input file */ - if (RP->random_seed == 0) - RP->random_seed = time (0); - - SRANDOM (RP->random_seed); + SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0)); write_map_parameters_to_string (buf, RP); @@ -120,6 +116,7 @@ /* set region */ theMap->region = RP->region; + coroapi::cede (); /* create walls unless the wallstyle is "none" */ if (strcmp (RP->wallstyle, "none")) { @@ -131,38 +128,48 @@ } + coroapi::cede (); /* create exits unless the exitstyle is "none" */ if (strcmp (RP->exitstyle, "none")) place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); + coroapi::cede (); place_specials_in_map (theMap, layout, RP); + coroapi::cede (); /* create monsters unless the monsterstyle is "none" */ if (strcmp (RP->monsterstyle, "none")) place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); + coroapi::cede (); /* treasures needs to have a proper difficulty set for the map. */ theMap->difficulty = theMap->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); + coroapi::cede (); /* create decor unless the decorstyle is "none" */ if (strcmp (RP->decorstyle, "none")) put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); + coroapi::cede (); /* generate treasures, etc. */ theMap->fix_auto_apply (); + coroapi::cede (); 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,7 +177,7 @@ /* function selects the layout function and gives it whatever arguments it needs. */ char ** -layoutgen (random_map_params * RP) +layoutgen (random_map_params *RP) { char **maze = 0; int oxsize = RP->Xsize, oysize = RP->Ysize; @@ -285,7 +292,7 @@ /* takes a map and makes it symmetric: adjusts Xsize and Ysize to produce a symmetric map. */ char ** -symmetrize_layout (char **maze, int sym, random_map_params * RP) +symmetrize_layout (char **maze, int sym, random_map_params *RP) { int i, j; char **sym_maze; @@ -353,7 +360,7 @@ */ char ** -rotate_layout (char **maze, int rotation, random_map_params * RP) +rotate_layout (char **maze, int rotation, random_map_params *RP) { char **new_maze; int i, j; @@ -363,19 +370,19 @@ case 0: return maze; break; - case 2: /* a reflection */ + case 2: /* a reflection */ { char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); for (i = 0; i < RP->Xsize; i++) - { /* make a copy */ + { /* 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 */ + { /* 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]; @@ -394,13 +401,13 @@ { new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); } - if (rotation == 1) /* swap x and y */ + if (rotation == 1) /* 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]; if (rotation == 3) - { /* swap x and y */ + { /* 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]; @@ -424,7 +431,7 @@ /* take a layout and make some rooms in it. --works best on onions.*/ void -roomify_layout (char **maze, random_map_params * RP) +roomify_layout (char **maze, random_map_params *RP) { int tries = RP->Xsize * RP->Ysize / 30; int ti; @@ -461,7 +468,7 @@ here which ends up on other walls sensibly. */ int -can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) +can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP) { int i1; int length = 0; @@ -546,35 +553,34 @@ maze[x][y] = 'D'; /* mark a door */ switch (dir) { - case 0: /* horizontal */ - { - int i1; + case 0: /* horizontal */ + { + int i1; - for (i1 = x - 1; maze[i1][y] == 0; i1--) - maze[i1][y] = '#'; - for (i1 = x + 1; maze[i1][y] == 0; i1++) - maze[i1][y] = '#'; - break; - } - case 1: /* vertical */ - { - int i1; + for (i1 = x - 1; maze[i1][y] == 0; i1--) + maze[i1][y] = '#'; + for (i1 = x + 1; maze[i1][y] == 0; i1++) + maze[i1][y] = '#'; + break; + } + case 1: /* vertical */ + { + int i1; - for (i1 = y - 1; maze[x][i1] == 0; i1--) - maze[x][i1] = '#'; - for (i1 = y + 1; maze[x][i1] == 0; i1++) - maze[x][i1] = '#'; - break; - } + for (i1 = y - 1; maze[x][i1] == 0; i1--) + maze[x][i1] = '#'; + for (i1 = y + 1; maze[x][i1] == 0; i1++) + maze[x][i1] = '#'; + break; + } } return 0; } /* puts doors at appropriate locations in a layout. */ - void -doorify_layout (char **maze, random_map_params * RP) +doorify_layout (char **maze, random_map_params *RP) { int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ char *doorlist_x; @@ -599,6 +605,7 @@ doorlocs++; } } + while (ndoors > 0 && doorlocs > 0) { int di; @@ -618,15 +625,15 @@ 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, random_map_params * RP) +write_map_parameters_to_string (char *buf, random_map_params *RP) { - char small_buf[256]; + char small_buf[2048]; sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); @@ -678,9 +685,9 @@ strcat (buf, small_buf); } - if (RP->final_map[0]) + if (RP->final_map.length ()) { - sprintf (small_buf, "final_map %s\n", RP->final_map); + sprintf (small_buf, "final_map %s\n", &RP->final_map); strcat (buf, small_buf); } @@ -690,9 +697,9 @@ strcat (buf, small_buf); } - if (RP->this_map[0]) + if (RP->this_map.length ()) { - sprintf (small_buf, "origin_map %s\n", RP->this_map); + sprintf (small_buf, "origin_map %s\n", &RP->this_map); strcat (buf, small_buf); } @@ -708,14 +715,12 @@ strcat (buf, small_buf); } - if (RP->layoutoptions2) { sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); strcat (buf, small_buf); } - if (RP->layoutoptions3) { sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); @@ -728,7 +733,6 @@ strcat (buf, small_buf); } - if (RP->difficulty && RP->difficulty_given) { sprintf (small_buf, "difficulty %d\n", RP->difficulty); @@ -774,16 +778,15 @@ strcat (buf, small_buf); } - if (RP->random_seed) + if (RP->treasureoptions) { - /* Add one so that the next map is a bit different */ - sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); + sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); strcat (buf, small_buf); } - if (RP->treasureoptions) + if (RP->random_seed) { - sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); + sprintf (small_buf, "random_seed %d\n", RP->random_seed); strcat (buf, small_buf); } } @@ -815,8 +818,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[256]; + char small_buf[2048]; sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); @@ -892,7 +894,6 @@ strcat (buf, small_buf); } - if (layoutoptions2_n) { sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); @@ -970,8 +971,6 @@ sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); strcat (buf, small_buf); } - - } /* copy an object with an inventory... i.e., duplicate the inv too. */ @@ -982,9 +981,10 @@ src_ob->copy_to (dest_ob); - for (walk = src_ob->inv; walk != NULL; walk = walk->below) + for (walk = src_ob->inv; walk; walk = walk->below) { tmp = object::create (); + walk->copy_to (tmp); insert_ob_in_ob (tmp, dest_ob); }