ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/random_map.C
(Generate patch)

Comparing deliantra/server/random_maps/random_map.C (file contents):
Revision 1.12 by root, Sun Dec 31 17:17:23 2006 UTC vs.
Revision 1.21 by root, Thu Jan 18 19:42:10 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <time.h> 25#include <time.h>
25#include <stdio.h> 26#include <stdio.h>
26#include <global.h> 27#include <global.h>
27#include <maze_gen.h> 28#include <maze_gen.h>
29#include <random_map.h> 30#include <random_map.h>
30#include <rproto.h> 31#include <rproto.h>
31#include <sproto.h> 32#include <sproto.h>
32 33
33void 34void
34dump_layout (char **layout, random_map_params * RP) 35dump_layout (char **layout, random_map_params *RP)
35{ 36{
36 { 37 {
37 int i, j; 38 int i, j;
38 39
39 for (i = 0; i < RP->Xsize; i++) 40 for (i = 0; i < RP->Xsize; i++)
50 } 51 }
51 } 52 }
52 printf ("\n"); 53 printf ("\n");
53} 54}
54 55
55extern FILE *logfile; 56bool
56 57maptile::generate_random_map (random_map_params *RP)
57maptile *
58generate_random_map (const char *OutFileName, random_map_params * RP)
59{ 58{
60 char **layout, buf[HUGE_BUF]; 59 char **layout, buf[16384];
61 maptile *theMap;
62 int i; 60 int i;
63 61
64 /* pick a random seed, or use the one from the input file */ 62 /* pick a random seed, or use the one from the input file */
65 if (RP->random_seed == 0) 63 SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0));
66 RP->random_seed = time (0);
67
68 SRANDOM (RP->random_seed);
69 64
70 write_map_parameters_to_string (buf, RP); 65 write_map_parameters_to_string (buf, RP);
71 66
72 if (RP->difficulty == 0) 67 if (RP->difficulty == 0)
73 { 68 {
81 } 76 }
82 else 77 else
83 RP->difficulty_given = 1; 78 RP->difficulty_given = 1;
84 79
85 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 80 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
86 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 81 RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
87 82
88 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 83 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
89 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; 84 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5;
90 85
91 if (RP->expand2x > 0) 86 if (RP->expand2x > 0)
92 { 87 {
93 RP->Xsize /= 2; 88 RP->Xsize /= 2;
94 RP->Ysize /= 2; 89 RP->Ysize /= 2;
104 RP->dungeon_level += 1; 99 RP->dungeon_level += 1;
105 /* allow constant-difficulty maps. */ 100 /* allow constant-difficulty maps. */
106 /* difficulty+=1; */ 101 /* difficulty+=1; */
107 102
108 /* rotate the layout randomly */ 103 /* rotate the layout randomly */
109 layout = rotate_layout (layout, RANDOM () % 4, RP); 104 layout = rotate_layout (layout, rndm (4), RP);
110#ifdef RMAP_DEBUG 105#ifdef RMAP_DEBUG
111 dump_layout (layout, RP); 106 dump_layout (layout, RP);
112#endif 107#endif
113 108
114 /* allocate the map and set the floor */ 109 /* allocate the map and set the floor */
115 theMap = make_map_floor (layout, RP->floorstyle, RP); 110 make_map_floor (layout, RP->floorstyle, RP);
116
117 /* set the name of the map. */
118 theMap->path = OutFileName;
119 111
120 /* set region */ 112 /* set region */
121 theMap->region = RP->region; 113 region = RP->region;
114
115 coroapi::cede ();
122 116
123 /* create walls unless the wallstyle is "none" */ 117 /* create walls unless the wallstyle is "none" */
124 if (strcmp (RP->wallstyle, "none")) 118 if (strcmp (RP->wallstyle, "none"))
125 { 119 {
126 make_map_walls (theMap, layout, RP->wallstyle, RP); 120 make_map_walls (this, layout, RP->wallstyle, RP);
127 121
128 /* place doors unless doorstyle or wallstyle is "none" */ 122 /* place doors unless doorstyle or wallstyle is "none" */
129 if (strcmp (RP->doorstyle, "none")) 123 if (strcmp (RP->doorstyle, "none"))
130 put_doors (theMap, layout, RP->doorstyle, RP); 124 put_doors (this, layout, RP->doorstyle, RP);
131 125
132 } 126 }
127
128 coroapi::cede ();
133 129
134 /* create exits unless the exitstyle is "none" */ 130 /* create exits unless the exitstyle is "none" */
135 if (strcmp (RP->exitstyle, "none")) 131 if (strcmp (RP->exitstyle, "none"))
136 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); 132 place_exits (this, layout, RP->exitstyle, RP->orientation, RP);
137 133
134 coroapi::cede ();
135
138 place_specials_in_map (theMap, layout, RP); 136 place_specials_in_map (this, layout, RP);
137
138 coroapi::cede ();
139 139
140 /* create monsters unless the monsterstyle is "none" */ 140 /* create monsters unless the monsterstyle is "none" */
141 if (strcmp (RP->monsterstyle, "none")) 141 if (strcmp (RP->monsterstyle, "none"))
142 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); 142 place_monsters (this, RP->monsterstyle, RP->difficulty, RP);
143
144 coroapi::cede ();
143 145
144 /* treasures needs to have a proper difficulty set for the map. */ 146 /* treasures needs to have a proper difficulty set for the map. */
145 theMap->difficulty = theMap->estimate_difficulty (); 147 difficulty = estimate_difficulty ();
148
149 coroapi::cede ();
146 150
147 /* create treasure unless the treasurestyle is "none" */ 151 /* create treasure unless the treasurestyle is "none" */
148 if (strcmp (RP->treasurestyle, "none")) 152 if (strcmp (RP->treasurestyle, "none"))
149 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); 153 place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP);
154
155 coroapi::cede ();
150 156
151 /* create decor unless the decorstyle is "none" */ 157 /* create decor unless the decorstyle is "none" */
152 if (strcmp (RP->decorstyle, "none")) 158 if (strcmp (RP->decorstyle, "none"))
153 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); 159 put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP);
160
161 coroapi::cede ();
154 162
155 /* generate treasures, etc. */ 163 /* generate treasures, etc. */
156 theMap->fix_auto_apply (); 164 fix_auto_apply ();
157 165
166 coroapi::cede ();
158 unblock_exits (theMap, layout, RP); 167 unblock_exits (this, layout, RP);
159 168
160 /* free the layout */ 169 /* free the layout */
161 for (i = 0; i < RP->Xsize; i++) 170 for (i = 0; i < RP->Xsize; i++)
162 free (layout[i]); 171 free (layout[i]);
163 172
164 free (layout); 173 free (layout);
165 174
166 theMap->msg = strdup (buf); 175 msg = strdup (buf);
167 theMap->in_memory = MAP_IN_MEMORY; 176 in_memory = MAP_IN_MEMORY;
168 177
169 return theMap; 178 return 1;
170} 179}
171 180
172/* function selects the layout function and gives it whatever 181/* function selects the layout function and gives it whatever
173 arguments it needs. */ 182 arguments it needs. */
174char ** 183char **
175layoutgen (random_map_params * RP) 184layoutgen (random_map_params *RP)
176{ 185{
177 char **maze = 0; 186 char **maze = 0;
178 int oxsize = RP->Xsize, oysize = RP->Ysize; 187 int oxsize = RP->Xsize, oysize = RP->Ysize;
179 188
180 if (RP->symmetry == SYMMETRY_RANDOM) 189 if (RP->symmetry == SYMMETRY_RANDOM)
186 RP->Ysize = RP->Ysize / 2 + 1; 195 RP->Ysize = RP->Ysize / 2 + 1;
187 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) 196 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
188 RP->Xsize = RP->Xsize / 2 + 1; 197 RP->Xsize = RP->Xsize / 2 + 1;
189 198
190 if (RP->Xsize < MIN_RANDOM_MAP_SIZE) 199 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
191 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 200 RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (5);
192 if (RP->Ysize < MIN_RANDOM_MAP_SIZE) 201 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
193 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; 202 RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (5);
194 RP->map_layout_style = 0; 203 RP->map_layout_style = 0;
195 204
196 /* Redo this - there was a lot of redundant code of checking for preset 205 /* Redo this - there was a lot of redundant code of checking for preset
197 * layout style and then random layout style. Instead, figure out 206 * layout style and then random layout style. Instead, figure out
198 * the numeric layoutstyle, so there is only one area that actually 207 * the numeric layoutstyle, so there is only one area that actually
222 231
223 switch (RP->map_layout_style) 232 switch (RP->map_layout_style)
224 { 233 {
225 case LAYOUT_ONION: 234 case LAYOUT_ONION:
226 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); 235 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2);
227 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) 236 if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY))
228 roomify_layout (maze, RP); 237 roomify_layout (maze, RP);
229 break; 238 break;
230 239
231 case LAYOUT_MAZE: 240 case LAYOUT_MAZE:
232 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); 241 maze = maze_gen (RP->Xsize, RP->Ysize, rndm (2));
233 if (!(RANDOM () % 2)) 242 if (!(rndm (2)))
234 doorify_layout (maze, RP); 243 doorify_layout (maze, RP);
235 break; 244 break;
236 245
237 case LAYOUT_SPIRAL: 246 case LAYOUT_SPIRAL:
238 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); 247 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1);
239 if (!(RANDOM () % 2)) 248 if (!(rndm (2)))
240 doorify_layout (maze, RP); 249 doorify_layout (maze, RP);
241 break; 250 break;
242 251
243 case LAYOUT_ROGUELIKE: 252 case LAYOUT_ROGUELIKE:
244 /* Don't put symmetry in rogue maps. There isn't much reason to 253 /* Don't put symmetry in rogue maps. There isn't much reason to
255 /* no doorifying... done already */ 264 /* no doorifying... done already */
256 break; 265 break;
257 266
258 case LAYOUT_SNAKE: 267 case LAYOUT_SNAKE:
259 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 268 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
260 if (RANDOM () % 2) 269 if (rndm (2))
261 roomify_layout (maze, RP); 270 roomify_layout (maze, RP);
262 break; 271 break;
263 272
264 case LAYOUT_SQUARE_SPIRAL: 273 case LAYOUT_SQUARE_SPIRAL:
265 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); 274 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
266 if (RANDOM () % 2) 275 if (rndm (2))
267 roomify_layout (maze, RP); 276 roomify_layout (maze, RP);
268 break; 277 break;
269 } 278 }
270 279
271 maze = symmetrize_layout (maze, RP->symmetry_used, RP); 280 maze = symmetrize_layout (maze, RP->symmetry_used, RP);
285} 294}
286 295
287/* takes a map and makes it symmetric: adjusts Xsize and 296/* takes a map and makes it symmetric: adjusts Xsize and
288Ysize to produce a symmetric map. */ 297Ysize to produce a symmetric map. */
289char ** 298char **
290symmetrize_layout (char **maze, int sym, random_map_params * RP) 299symmetrize_layout (char **maze, int sym, random_map_params *RP)
291{ 300{
292 int i, j; 301 int i, j;
293 char **sym_maze; 302 char **sym_maze;
294 int Xsize_orig, Ysize_orig; 303 int Xsize_orig, Ysize_orig;
295 304
353 onion layouts, making them possibly centered on any wall. 362 onion layouts, making them possibly centered on any wall.
354 It'll modify Xsize and Ysize if they're swapped. 363 It'll modify Xsize and Ysize if they're swapped.
355*/ 364*/
356 365
357char ** 366char **
358rotate_layout (char **maze, int rotation, random_map_params * RP) 367rotate_layout (char **maze, int rotation, random_map_params *RP)
359{ 368{
360 char **new_maze; 369 char **new_maze;
361 int i, j; 370 int i, j;
362 371
363 switch (rotation) 372 switch (rotation)
364 { 373 {
365 case 0: 374 case 0:
366 return maze; 375 return maze;
367 break; 376 break;
368 case 2: /* a reflection */ 377 case 2: /* a reflection */
369 { 378 {
370 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); 379 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
371 380
372 for (i = 0; i < RP->Xsize; i++) 381 for (i = 0; i < RP->Xsize; i++)
373 { /* make a copy */ 382 { /* make a copy */
374 for (j = 0; j < RP->Ysize; j++) 383 for (j = 0; j < RP->Ysize; j++)
375 { 384 {
376 newmaze[i * RP->Ysize + j] = maze[i][j]; 385 newmaze[i * RP->Ysize + j] = maze[i][j];
377 } 386 }
378 } 387 }
379 for (i = 0; i < RP->Xsize; i++) 388 for (i = 0; i < RP->Xsize; i++)
380 { /* copy a reflection back */ 389 { /* copy a reflection back */
381 for (j = 0; j < RP->Ysize; j++) 390 for (j = 0; j < RP->Ysize; j++)
382 { 391 {
383 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; 392 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
384 } 393 }
385 } 394 }
394 new_maze = (char **) calloc (sizeof (char *), RP->Ysize); 403 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
395 for (i = 0; i < RP->Ysize; i++) 404 for (i = 0; i < RP->Ysize; i++)
396 { 405 {
397 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); 406 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
398 } 407 }
399 if (rotation == 1) /* swap x and y */ 408 if (rotation == 1) /* swap x and y */
400 for (i = 0; i < RP->Xsize; i++) 409 for (i = 0; i < RP->Xsize; i++)
401 for (j = 0; j < RP->Ysize; j++) 410 for (j = 0; j < RP->Ysize; j++)
402 new_maze[j][i] = maze[i][j]; 411 new_maze[j][i] = maze[i][j];
403 412
404 if (rotation == 3) 413 if (rotation == 3)
405 { /* swap x and y */ 414 { /* swap x and y */
406 for (i = 0; i < RP->Xsize; i++) 415 for (i = 0; i < RP->Xsize; i++)
407 for (j = 0; j < RP->Ysize; j++) 416 for (j = 0; j < RP->Ysize; j++)
408 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; 417 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1];
409 } 418 }
410 419
424} 433}
425 434
426/* take a layout and make some rooms in it. 435/* take a layout and make some rooms in it.
427 --works best on onions.*/ 436 --works best on onions.*/
428void 437void
429roomify_layout (char **maze, random_map_params * RP) 438roomify_layout (char **maze, random_map_params *RP)
430{ 439{
431 int tries = RP->Xsize * RP->Ysize / 30; 440 int tries = RP->Xsize * RP->Ysize / 30;
432 int ti; 441 int ti;
433 442
434 for (ti = 0; ti < tries; ti++) 443 for (ti = 0; ti < tries; ti++)
461/* checks the layout to see if I can stick a horizontal(dir = 0) wall 470/* checks the layout to see if I can stick a horizontal(dir = 0) wall
462 (or vertical, dir == 1) 471 (or vertical, dir == 1)
463 here which ends up on other walls sensibly. */ 472 here which ends up on other walls sensibly. */
464 473
465int 474int
466can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) 475can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP)
467{ 476{
468 int i1; 477 int i1;
469 int length = 0; 478 int length = 0;
470 479
471 /* dont make walls if we're on the edge. */ 480 /* dont make walls if we're on the edge. */
546make_wall (char **maze, int x, int y, int dir) 555make_wall (char **maze, int x, int y, int dir)
547{ 556{
548 maze[x][y] = 'D'; /* mark a door */ 557 maze[x][y] = 'D'; /* mark a door */
549 switch (dir) 558 switch (dir)
550 { 559 {
551 case 0: /* horizontal */ 560 case 0: /* horizontal */
552 { 561 {
553 int i1; 562 int i1;
554 563
555 for (i1 = x - 1; maze[i1][y] == 0; i1--) 564 for (i1 = x - 1; maze[i1][y] == 0; i1--)
556 maze[i1][y] = '#'; 565 maze[i1][y] = '#';
557 for (i1 = x + 1; maze[i1][y] == 0; i1++) 566 for (i1 = x + 1; maze[i1][y] == 0; i1++)
558 maze[i1][y] = '#'; 567 maze[i1][y] = '#';
559 break; 568 break;
560 } 569 }
561 case 1: /* vertical */ 570 case 1: /* vertical */
562 { 571 {
563 int i1; 572 int i1;
564 573
565 for (i1 = y - 1; maze[x][i1] == 0; i1--) 574 for (i1 = y - 1; maze[x][i1] == 0; i1--)
566 maze[x][i1] = '#'; 575 maze[x][i1] = '#';
567 for (i1 = y + 1; maze[x][i1] == 0; i1++) 576 for (i1 = y + 1; maze[x][i1] == 0; i1++)
568 maze[x][i1] = '#'; 577 maze[x][i1] = '#';
569 break; 578 break;
570 } 579 }
571 } 580 }
572 581
573 return 0; 582 return 0;
574} 583}
575 584
576/* puts doors at appropriate locations in a layout. */ 585/* puts doors at appropriate locations in a layout. */
577void 586void
578doorify_layout (char **maze, random_map_params * RP) 587doorify_layout (char **maze, random_map_params *RP)
579{ 588{
580 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ 589 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
581 char *doorlist_x; 590 char *doorlist_x;
582 char *doorlist_y; 591 char *doorlist_y;
583 int doorlocs = 0; /* # of available doorlocations */ 592 int doorlocs = 0; /* # of available doorlocations */
624 free (doorlist_x); 633 free (doorlist_x);
625 free (doorlist_y); 634 free (doorlist_y);
626} 635}
627 636
628void 637void
629write_map_parameters_to_string (char *buf, random_map_params * RP) 638write_map_parameters_to_string (char *buf, random_map_params *RP)
630{ 639{
631 char small_buf[256]; 640 char small_buf[16384];
632 641
633 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 642 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
634 643
635 if (RP->wallstyle[0]) 644 if (RP->wallstyle[0])
636 { 645 {
678 { 687 {
679 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); 688 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
680 strcat (buf, small_buf); 689 strcat (buf, small_buf);
681 } 690 }
682 691
683 if (RP->final_map[0]) 692 if (RP->final_map.length ())
684 { 693 {
685 sprintf (small_buf, "final_map %s\n", RP->final_map); 694 sprintf (small_buf, "final_map %s\n", &RP->final_map);
686 strcat (buf, small_buf); 695 strcat (buf, small_buf);
687 } 696 }
688 697
689 if (RP->exit_on_final_map[0]) 698 if (RP->exit_on_final_map[0])
690 { 699 {
691 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map); 700 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map);
692 strcat (buf, small_buf); 701 strcat (buf, small_buf);
693 } 702 }
694 703
695 if (RP->this_map[0]) 704 if (RP->this_map.length ())
696 { 705 {
697 sprintf (small_buf, "origin_map %s\n", RP->this_map); 706 sprintf (small_buf, "origin_map %s\n", &RP->this_map);
698 strcat (buf, small_buf); 707 strcat (buf, small_buf);
699 } 708 }
700 709
701 if (RP->expand2x) 710 if (RP->expand2x)
702 { 711 {
708 { 717 {
709 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); 718 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
710 strcat (buf, small_buf); 719 strcat (buf, small_buf);
711 } 720 }
712 721
713
714 if (RP->layoutoptions2) 722 if (RP->layoutoptions2)
715 { 723 {
716 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); 724 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
717 strcat (buf, small_buf); 725 strcat (buf, small_buf);
718 } 726 }
719 727
720
721 if (RP->layoutoptions3) 728 if (RP->layoutoptions3)
722 { 729 {
723 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); 730 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
724 strcat (buf, small_buf); 731 strcat (buf, small_buf);
725 } 732 }
727 if (RP->symmetry) 734 if (RP->symmetry)
728 { 735 {
729 sprintf (small_buf, "symmetry %d\n", RP->symmetry); 736 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
730 strcat (buf, small_buf); 737 strcat (buf, small_buf);
731 } 738 }
732
733 739
734 if (RP->difficulty && RP->difficulty_given) 740 if (RP->difficulty && RP->difficulty_given)
735 { 741 {
736 sprintf (small_buf, "difficulty %d\n", RP->difficulty); 742 sprintf (small_buf, "difficulty %d\n", RP->difficulty);
737 strcat (buf, small_buf); 743 strcat (buf, small_buf);
774 { 780 {
775 sprintf (small_buf, "origin_y %d\n", RP->origin_y); 781 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
776 strcat (buf, small_buf); 782 strcat (buf, small_buf);
777 } 783 }
778 784
785 if (RP->treasureoptions)
786 {
787 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
788 strcat (buf, small_buf);
789 }
790
779 if (RP->random_seed) 791 if (RP->random_seed)
780 { 792 {
781 /* Add one so that the next map is a bit different */
782 sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); 793 sprintf (small_buf, "random_seed %d\n", RP->random_seed);
783 strcat (buf, small_buf); 794 strcat (buf, small_buf);
784 }
785
786 if (RP->treasureoptions)
787 { 795 }
788 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); 796
797 if (RP->custom)
798 {
799 sprintf (small_buf, "custom %s\n", RP->custom);
789 strcat (buf, small_buf); 800 strcat (buf, small_buf);
790 } 801 }
791} 802}
792 803
793void 804void
815 int difficulty_given_n, 826 int difficulty_given_n,
816 int decoroptions_n, 827 int decoroptions_n,
817 int orientation_n, 828 int orientation_n,
818 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) 829 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase)
819{ 830{
820
821 char small_buf[256]; 831 char small_buf[16384];
822 832
823 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); 833 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
824 834
825 if (wallstyle_n && wallstyle_n[0]) 835 if (wallstyle_n && wallstyle_n[0])
826 { 836 {
969 if (treasureoptions_n) 979 if (treasureoptions_n)
970 { 980 {
971 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); 981 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n);
972 strcat (buf, small_buf); 982 strcat (buf, small_buf);
973 } 983 }
974
975
976} 984}
977 985
978/* copy an object with an inventory... i.e., duplicate the inv too. */ 986/* copy an object with an inventory... i.e., duplicate the inv too. */
979void 987void
980copy_object_with_inv (object *src_ob, object *dest_ob) 988copy_object_with_inv (object *src_ob, object *dest_ob)
981{ 989{
982 object *walk, *tmp; 990 object *walk, *tmp;
983 991
984 src_ob->copy_to (dest_ob); 992 src_ob->copy_to (dest_ob);
985 993
986 for (walk = src_ob->inv; walk != NULL; walk = walk->below) 994 for (walk = src_ob->inv; walk; walk = walk->below)
987 { 995 {
988 tmp = object::create (); 996 tmp = object::create ();
997
989 walk->copy_to (tmp); 998 walk->copy_to (tmp);
990 insert_ob_in_ob (tmp, dest_ob); 999 insert_ob_in_ob (tmp, dest_ob);
991 } 1000 }
992} 1001}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines