ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/random_map.C
Revision: 1.12
Committed: Sun Dec 31 17:17:23 2006 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.11: +4 -3 lines
Log Message:
many minor changes everywhere, random maps crash sometimes but design is in place

File Contents

# Content
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 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 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 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 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22 */
23
24 #include <time.h>
25 #include <stdio.h>
26 #include <global.h>
27 #include <maze_gen.h>
28 #include <room_gen.h>
29 #include <random_map.h>
30 #include <rproto.h>
31 #include <sproto.h>
32
33 void
34 dump_layout (char **layout, random_map_params * RP)
35 {
36 {
37 int i, j;
38
39 for (i = 0; i < RP->Xsize; i++)
40 {
41 for (j = 0; j < RP->Ysize; j++)
42 {
43 if (layout[i][j] == 0)
44 layout[i][j] = ' ';
45 printf ("%c", layout[i][j]);
46 if (layout[i][j] == ' ')
47 layout[i][j] = 0;
48 }
49 printf ("\n");
50 }
51 }
52 printf ("\n");
53 }
54
55 extern FILE *logfile;
56
57 maptile *
58 generate_random_map (const char *OutFileName, random_map_params * RP)
59 {
60 char **layout, buf[HUGE_BUF];
61 maptile *theMap;
62 int i;
63
64 /* pick a random seed, or use the one from the input file */
65 if (RP->random_seed == 0)
66 RP->random_seed = time (0);
67
68 SRANDOM (RP->random_seed);
69
70 write_map_parameters_to_string (buf, RP);
71
72 if (RP->difficulty == 0)
73 {
74 RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */
75
76 if (RP->difficulty_increase > 0.001)
77 RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase);
78
79 if (RP->difficulty < 1)
80 RP->difficulty = 1;
81 }
82 else
83 RP->difficulty_given = 1;
84
85 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
86 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5;
87
88 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
89 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5;
90
91 if (RP->expand2x > 0)
92 {
93 RP->Xsize /= 2;
94 RP->Ysize /= 2;
95 }
96
97 layout = layoutgen (RP);
98
99 #ifdef RMAP_DEBUG
100 dump_layout (layout, RP);
101 #endif
102
103 /* increment these for the current map */
104 RP->dungeon_level += 1;
105 /* allow constant-difficulty maps. */
106 /* difficulty+=1; */
107
108 /* rotate the layout randomly */
109 layout = rotate_layout (layout, RANDOM () % 4, RP);
110 #ifdef RMAP_DEBUG
111 dump_layout (layout, RP);
112 #endif
113
114 /* allocate the map and set the floor */
115 theMap = make_map_floor (layout, RP->floorstyle, RP);
116
117 /* set the name of the map. */
118 theMap->path = OutFileName;
119
120 /* set region */
121 theMap->region = RP->region;
122
123 /* create walls unless the wallstyle is "none" */
124 if (strcmp (RP->wallstyle, "none"))
125 {
126 make_map_walls (theMap, layout, RP->wallstyle, RP);
127
128 /* place doors unless doorstyle or wallstyle is "none" */
129 if (strcmp (RP->doorstyle, "none"))
130 put_doors (theMap, layout, RP->doorstyle, RP);
131
132 }
133
134 /* create exits unless the exitstyle is "none" */
135 if (strcmp (RP->exitstyle, "none"))
136 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP);
137
138 place_specials_in_map (theMap, layout, RP);
139
140 /* create monsters unless the monsterstyle is "none" */
141 if (strcmp (RP->monsterstyle, "none"))
142 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP);
143
144 /* treasures needs to have a proper difficulty set for the map. */
145 theMap->difficulty = theMap->estimate_difficulty ();
146
147 /* create treasure unless the treasurestyle is "none" */
148 if (strcmp (RP->treasurestyle, "none"))
149 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP);
150
151 /* create decor unless the decorstyle is "none" */
152 if (strcmp (RP->decorstyle, "none"))
153 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP);
154
155 /* generate treasures, etc. */
156 theMap->fix_auto_apply ();
157
158 unblock_exits (theMap, layout, RP);
159
160 /* free the layout */
161 for (i = 0; i < RP->Xsize; i++)
162 free (layout[i]);
163
164 free (layout);
165
166 theMap->msg = strdup (buf);
167 theMap->in_memory = MAP_IN_MEMORY;
168
169 return theMap;
170 }
171
172 /* function selects the layout function and gives it whatever
173 arguments it needs. */
174 char **
175 layoutgen (random_map_params * RP)
176 {
177 char **maze = 0;
178 int oxsize = RP->Xsize, oysize = RP->Ysize;
179
180 if (RP->symmetry == SYMMETRY_RANDOM)
181 RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1;
182 else
183 RP->symmetry_used = RP->symmetry;
184
185 if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY)
186 RP->Ysize = RP->Ysize / 2 + 1;
187 if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY)
188 RP->Xsize = RP->Xsize / 2 + 1;
189
190 if (RP->Xsize < MIN_RANDOM_MAP_SIZE)
191 RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5;
192 if (RP->Ysize < MIN_RANDOM_MAP_SIZE)
193 RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5;
194 RP->map_layout_style = 0;
195
196 /* Redo this - there was a lot of redundant code of checking for preset
197 * layout style and then random layout style. Instead, figure out
198 * the numeric layoutstyle, so there is only one area that actually
199 * calls the code to make the maps.
200 */
201 if (strstr (RP->layoutstyle, "onion"))
202 RP->map_layout_style = LAYOUT_ONION;
203
204 if (strstr (RP->layoutstyle, "maze"))
205 RP->map_layout_style = LAYOUT_MAZE;
206
207 if (strstr (RP->layoutstyle, "spiral"))
208 RP->map_layout_style = LAYOUT_SPIRAL;
209
210 if (strstr (RP->layoutstyle, "rogue"))
211 RP->map_layout_style = LAYOUT_ROGUELIKE;
212
213 if (strstr (RP->layoutstyle, "snake"))
214 RP->map_layout_style = LAYOUT_SNAKE;
215
216 if (strstr (RP->layoutstyle, "squarespiral"))
217 RP->map_layout_style = LAYOUT_SQUARE_SPIRAL;
218
219 /* No style found - choose one ranomdly */
220 if (RP->map_layout_style == LAYOUT_NONE)
221 RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1;
222
223 switch (RP->map_layout_style)
224 {
225 case LAYOUT_ONION:
226 maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2);
227 if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY))
228 roomify_layout (maze, RP);
229 break;
230
231 case LAYOUT_MAZE:
232 maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2);
233 if (!(RANDOM () % 2))
234 doorify_layout (maze, RP);
235 break;
236
237 case LAYOUT_SPIRAL:
238 maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1);
239 if (!(RANDOM () % 2))
240 doorify_layout (maze, RP);
241 break;
242
243 case LAYOUT_ROGUELIKE:
244 /* Don't put symmetry in rogue maps. There isn't much reason to
245 * do so in the first place (doesn't make it any more interesting),
246 * but more importantly, the symmetry code presumes we are symmetrizing
247 * spirals, or maps with lots of passages - making a symmetric rogue
248 * map fails because its likely that the passages the symmetry process
249 * creates may not connect the rooms.
250 */
251 RP->symmetry_used = SYMMETRY_NONE;
252 RP->Ysize = oysize;
253 RP->Xsize = oxsize;
254 maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1);
255 /* no doorifying... done already */
256 break;
257
258 case LAYOUT_SNAKE:
259 maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
260 if (RANDOM () % 2)
261 roomify_layout (maze, RP);
262 break;
263
264 case LAYOUT_SQUARE_SPIRAL:
265 maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1);
266 if (RANDOM () % 2)
267 roomify_layout (maze, RP);
268 break;
269 }
270
271 maze = symmetrize_layout (maze, RP->symmetry_used, RP);
272
273 #ifdef RMAP_DEBUG
274 dump_layout (maze, RP);
275 #endif
276
277 if (RP->expand2x)
278 {
279 maze = expand2x (maze, RP->Xsize, RP->Ysize);
280 RP->Xsize = RP->Xsize * 2 - 1;
281 RP->Ysize = RP->Ysize * 2 - 1;
282 }
283
284 return maze;
285 }
286
287 /* takes a map and makes it symmetric: adjusts Xsize and
288 Ysize to produce a symmetric map. */
289 char **
290 symmetrize_layout (char **maze, int sym, random_map_params * RP)
291 {
292 int i, j;
293 char **sym_maze;
294 int Xsize_orig, Ysize_orig;
295
296 Xsize_orig = RP->Xsize;
297 Ysize_orig = RP->Ysize;
298 RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */
299 if (sym == SYMMETRY_NONE)
300 {
301 RP->Xsize = Xsize_orig;
302 RP->Ysize = Ysize_orig;
303 return maze;
304 }
305 /* pick new sizes */
306 RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize);
307 RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize);
308
309 sym_maze = (char **) calloc (sizeof (char *), RP->Xsize);
310 for (i = 0; i < RP->Xsize; i++)
311 sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize);
312
313 if (sym == SYMMETRY_X)
314 for (i = 0; i < RP->Xsize / 2 + 1; i++)
315 for (j = 0; j < RP->Ysize; j++)
316 {
317 sym_maze[i][j] = maze[i][j];
318 sym_maze[RP->Xsize - i - 1][j] = maze[i][j];
319 };
320 if (sym == SYMMETRY_Y)
321 for (i = 0; i < RP->Xsize; i++)
322 for (j = 0; j < RP->Ysize / 2 + 1; j++)
323 {
324 sym_maze[i][j] = maze[i][j];
325 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
326 }
327 if (sym == SYMMETRY_XY)
328 for (i = 0; i < RP->Xsize / 2 + 1; i++)
329 for (j = 0; j < RP->Ysize / 2 + 1; j++)
330 {
331 sym_maze[i][j] = maze[i][j];
332 sym_maze[i][RP->Ysize - j - 1] = maze[i][j];
333 sym_maze[RP->Xsize - i - 1][j] = maze[i][j];
334 sym_maze[RP->Xsize - i - 1][RP->Ysize - j - 1] = maze[i][j];
335 }
336 /* delete the old maze */
337 for (i = 0; i < Xsize_orig; i++)
338 free (maze[i]);
339 free (maze);
340 /* reconnect disjointed spirals */
341 if (RP->map_layout_style == LAYOUT_SPIRAL)
342 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
343 /* reconnect disjointed nethackmazes: the routine for
344 spirals will do the trick? */
345 if (RP->map_layout_style == LAYOUT_ROGUELIKE)
346 connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze);
347
348 return sym_maze;
349 }
350
351
352 /* takes a map and rotates it. This completes the
353 onion layouts, making them possibly centered on any wall.
354 It'll modify Xsize and Ysize if they're swapped.
355 */
356
357 char **
358 rotate_layout (char **maze, int rotation, random_map_params * RP)
359 {
360 char **new_maze;
361 int i, j;
362
363 switch (rotation)
364 {
365 case 0:
366 return maze;
367 break;
368 case 2: /* a reflection */
369 {
370 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
371
372 for (i = 0; i < RP->Xsize; i++)
373 { /* make a copy */
374 for (j = 0; j < RP->Ysize; j++)
375 {
376 newmaze[i * RP->Ysize + j] = maze[i][j];
377 }
378 }
379 for (i = 0; i < RP->Xsize; i++)
380 { /* copy a reflection back */
381 for (j = 0; j < RP->Ysize; j++)
382 {
383 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
384 }
385 }
386 free (newmaze);
387 return maze;
388 break;
389 }
390 case 1:
391 case 3:
392 {
393 int swap;
394 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
395 for (i = 0; i < RP->Ysize; i++)
396 {
397 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
398 }
399 if (rotation == 1) /* swap x and y */
400 for (i = 0; i < RP->Xsize; i++)
401 for (j = 0; j < RP->Ysize; j++)
402 new_maze[j][i] = maze[i][j];
403
404 if (rotation == 3)
405 { /* swap x and y */
406 for (i = 0; i < RP->Xsize; i++)
407 for (j = 0; j < RP->Ysize; j++)
408 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1];
409 }
410
411 /* delete the old layout */
412 for (i = 0; i < RP->Xsize; i++)
413 free (maze[i]);
414 free (maze);
415
416 swap = RP->Ysize;
417 RP->Ysize = RP->Xsize;
418 RP->Xsize = swap;
419 return new_maze;
420 break;
421 }
422 }
423 return NULL;
424 }
425
426 /* take a layout and make some rooms in it.
427 --works best on onions.*/
428 void
429 roomify_layout (char **maze, random_map_params * RP)
430 {
431 int tries = RP->Xsize * RP->Ysize / 30;
432 int ti;
433
434 for (ti = 0; ti < tries; ti++)
435 {
436 int dx, dy; /* starting location for looking at creating a door */
437 int cx, cy; /* results of checking on creating walls. */
438
439 dx = RANDOM () % RP->Xsize;
440 dy = RANDOM () % RP->Ysize;
441 cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */
442 cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */
443 if (cx == -1)
444 {
445 if (cy != -1)
446 make_wall (maze, dx, dy, 1);
447 continue;
448 }
449 if (cy == -1)
450 {
451 make_wall (maze, dx, dy, 0);
452 continue;
453 }
454 if (cx < cy)
455 make_wall (maze, dx, dy, 0);
456 else
457 make_wall (maze, dx, dy, 1);
458 }
459 }
460
461 /* checks the layout to see if I can stick a horizontal(dir = 0) wall
462 (or vertical, dir == 1)
463 here which ends up on other walls sensibly. */
464
465 int
466 can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP)
467 {
468 int i1;
469 int length = 0;
470
471 /* dont make walls if we're on the edge. */
472 if (dx == 0 || dx == (RP->Xsize - 1) || dy == 0 || dy == (RP->Ysize - 1))
473 return -1;
474
475 /* don't make walls if we're ON a wall. */
476 if (maze[dx][dy] != 0)
477 return -1;
478
479 if (dir == 0) /* horizontal */
480 {
481 int y = dy;
482
483 for (i1 = dx - 1; i1 > 0; i1--)
484 {
485 int sindex = surround_flag2 (maze, i1, y, RP);
486
487 if (sindex == 1)
488 break;
489 if (sindex != 0)
490 return -1; /* can't make horiz. wall here */
491 if (maze[i1][y] != 0)
492 return -1; /* can't make horiz. wall here */
493 length++;
494 }
495
496 for (i1 = dx + 1; i1 < RP->Xsize - 1; i1++)
497 {
498 int sindex = surround_flag2 (maze, i1, y, RP);
499
500 if (sindex == 2)
501 break;
502 if (sindex != 0)
503 return -1; /* can't make horiz. wall here */
504 if (maze[i1][y] != 0)
505 return -1; /* can't make horiz. wall here */
506 length++;
507 }
508 return length;
509 }
510 else
511 { /* vertical */
512 int x = dx;
513
514 for (i1 = dy - 1; i1 > 0; i1--)
515 {
516 int sindex = surround_flag2 (maze, x, i1, RP);
517
518 if (sindex == 4)
519 break;
520 if (sindex != 0)
521 return -1; /* can't make vert. wall here */
522 if (maze[x][i1] != 0)
523 return -1; /* can't make horiz. wall here */
524 length++;
525 }
526
527 for (i1 = dy + 1; i1 < RP->Ysize - 1; i1++)
528 {
529 int sindex = surround_flag2 (maze, x, i1, RP);
530
531 if (sindex == 8)
532 break;
533 if (sindex != 0)
534 return -1; /* can't make verti. wall here */
535 if (maze[x][i1] != 0)
536 return -1; /* can't make horiz. wall here */
537 length++;
538 }
539 return length;
540 }
541 return -1;
542 }
543
544
545 int
546 make_wall (char **maze, int x, int y, int dir)
547 {
548 maze[x][y] = 'D'; /* mark a door */
549 switch (dir)
550 {
551 case 0: /* horizontal */
552 {
553 int i1;
554
555 for (i1 = x - 1; maze[i1][y] == 0; i1--)
556 maze[i1][y] = '#';
557 for (i1 = x + 1; maze[i1][y] == 0; i1++)
558 maze[i1][y] = '#';
559 break;
560 }
561 case 1: /* vertical */
562 {
563 int i1;
564
565 for (i1 = y - 1; maze[x][i1] == 0; i1--)
566 maze[x][i1] = '#';
567 for (i1 = y + 1; maze[x][i1] == 0; i1++)
568 maze[x][i1] = '#';
569 break;
570 }
571 }
572
573 return 0;
574 }
575
576 /* puts doors at appropriate locations in a layout. */
577 void
578 doorify_layout (char **maze, random_map_params * RP)
579 {
580 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
581 char *doorlist_x;
582 char *doorlist_y;
583 int doorlocs = 0; /* # of available doorlocations */
584 int i, j;
585
586 doorlist_x = (char *) malloc (sizeof (int) * RP->Xsize * RP->Ysize);
587 doorlist_y = (char *) malloc (sizeof (int) * RP->Xsize * RP->Ysize);
588
589
590 /* make a list of possible door locations */
591 for (i = 1; i < RP->Xsize - 1; i++)
592 for (j = 1; j < RP->Ysize - 1; j++)
593 {
594 int sindex = surround_flag (maze, i, j, RP);
595
596 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
597 {
598 doorlist_x[doorlocs] = i;
599 doorlist_y[doorlocs] = j;
600 doorlocs++;
601 }
602 }
603
604 while (ndoors > 0 && doorlocs > 0)
605 {
606 int di;
607 int sindex;
608
609 di = RANDOM () % doorlocs;
610 i = doorlist_x[di];
611 j = doorlist_y[di];
612 sindex = surround_flag (maze, i, j, RP);
613 if (sindex == 3 || sindex == 12) /* these are possible door sindex */
614 {
615 maze[i][j] = 'D';
616 ndoors--;
617 }
618 /* reduce the size of the list */
619 doorlocs--;
620 doorlist_x[di] = doorlist_x[doorlocs];
621 doorlist_y[di] = doorlist_y[doorlocs];
622 }
623
624 free (doorlist_x);
625 free (doorlist_y);
626 }
627
628 void
629 write_map_parameters_to_string (char *buf, random_map_params * RP)
630 {
631 char small_buf[256];
632
633 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
634
635 if (RP->wallstyle[0])
636 {
637 sprintf (small_buf, "wallstyle %s\n", RP->wallstyle);
638 strcat (buf, small_buf);
639 }
640
641 if (RP->floorstyle[0])
642 {
643 sprintf (small_buf, "floorstyle %s\n", RP->floorstyle);
644 strcat (buf, small_buf);
645 }
646
647 if (RP->monsterstyle[0])
648 {
649 sprintf (small_buf, "monsterstyle %s\n", RP->monsterstyle);
650 strcat (buf, small_buf);
651 }
652
653 if (RP->treasurestyle[0])
654 {
655 sprintf (small_buf, "treasurestyle %s\n", RP->treasurestyle);
656 strcat (buf, small_buf);
657 }
658
659 if (RP->layoutstyle[0])
660 {
661 sprintf (small_buf, "layoutstyle %s\n", RP->layoutstyle);
662 strcat (buf, small_buf);
663 }
664
665 if (RP->decorstyle[0])
666 {
667 sprintf (small_buf, "decorstyle %s\n", RP->decorstyle);
668 strcat (buf, small_buf);
669 }
670
671 if (RP->doorstyle[0])
672 {
673 sprintf (small_buf, "doorstyle %s\n", RP->doorstyle);
674 strcat (buf, small_buf);
675 }
676
677 if (RP->exitstyle[0])
678 {
679 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
680 strcat (buf, small_buf);
681 }
682
683 if (RP->final_map[0])
684 {
685 sprintf (small_buf, "final_map %s\n", RP->final_map);
686 strcat (buf, small_buf);
687 }
688
689 if (RP->exit_on_final_map[0])
690 {
691 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map);
692 strcat (buf, small_buf);
693 }
694
695 if (RP->this_map[0])
696 {
697 sprintf (small_buf, "origin_map %s\n", RP->this_map);
698 strcat (buf, small_buf);
699 }
700
701 if (RP->expand2x)
702 {
703 sprintf (small_buf, "expand2x %d\n", RP->expand2x);
704 strcat (buf, small_buf);
705 }
706
707 if (RP->layoutoptions1)
708 {
709 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
710 strcat (buf, small_buf);
711 }
712
713
714 if (RP->layoutoptions2)
715 {
716 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
717 strcat (buf, small_buf);
718 }
719
720
721 if (RP->layoutoptions3)
722 {
723 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
724 strcat (buf, small_buf);
725 }
726
727 if (RP->symmetry)
728 {
729 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
730 strcat (buf, small_buf);
731 }
732
733
734 if (RP->difficulty && RP->difficulty_given)
735 {
736 sprintf (small_buf, "difficulty %d\n", RP->difficulty);
737 strcat (buf, small_buf);
738 }
739
740 if (RP->difficulty_increase != 1.0)
741 {
742 sprintf (small_buf, "difficulty_increase %f\n", RP->difficulty_increase);
743 strcat (buf, small_buf);
744 }
745
746 sprintf (small_buf, "dungeon_level %d\n", RP->dungeon_level);
747 strcat (buf, small_buf);
748
749 if (RP->dungeon_depth)
750 {
751 sprintf (small_buf, "dungeon_depth %d\n", RP->dungeon_depth);
752 strcat (buf, small_buf);
753 }
754
755 if (RP->decoroptions)
756 {
757 sprintf (small_buf, "decoroptions %d\n", RP->decoroptions);
758 strcat (buf, small_buf);
759 }
760
761 if (RP->orientation)
762 {
763 sprintf (small_buf, "orientation %d\n", RP->orientation);
764 strcat (buf, small_buf);
765 }
766
767 if (RP->origin_x)
768 {
769 sprintf (small_buf, "origin_x %d\n", RP->origin_x);
770 strcat (buf, small_buf);
771 }
772
773 if (RP->origin_y)
774 {
775 sprintf (small_buf, "origin_y %d\n", RP->origin_y);
776 strcat (buf, small_buf);
777 }
778
779 if (RP->random_seed)
780 {
781 /* Add one so that the next map is a bit different */
782 sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1);
783 strcat (buf, small_buf);
784 }
785
786 if (RP->treasureoptions)
787 {
788 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
789 strcat (buf, small_buf);
790 }
791 }
792
793 void
794 write_parameters_to_string (char *buf,
795 int xsize_n,
796 int ysize_n,
797 char *wallstyle_n,
798 char *floorstyle_n,
799 char *monsterstyle_n,
800 char *treasurestyle_n,
801 char *layoutstyle_n,
802 char *decorstyle_n,
803 char *doorstyle_n,
804 char *exitstyle_n,
805 char *final_map_n,
806 char *exit_on_final_map_n,
807 char *this_map_n,
808 int layoutoptions1_n,
809 int layoutoptions2_n,
810 int layoutoptions3_n,
811 int symmetry_n,
812 int dungeon_depth_n,
813 int dungeon_level_n,
814 int difficulty_n,
815 int difficulty_given_n,
816 int decoroptions_n,
817 int orientation_n,
818 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase)
819 {
820
821 char small_buf[256];
822
823 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
824
825 if (wallstyle_n && wallstyle_n[0])
826 {
827 sprintf (small_buf, "wallstyle %s\n", wallstyle_n);
828 strcat (buf, small_buf);
829 }
830
831 if (floorstyle_n && floorstyle_n[0])
832 {
833 sprintf (small_buf, "floorstyle %s\n", floorstyle_n);
834 strcat (buf, small_buf);
835 }
836
837 if (monsterstyle_n && monsterstyle_n[0])
838 {
839 sprintf (small_buf, "monsterstyle %s\n", monsterstyle_n);
840 strcat (buf, small_buf);
841 }
842
843 if (treasurestyle_n && treasurestyle_n[0])
844 {
845 sprintf (small_buf, "treasurestyle %s\n", treasurestyle_n);
846 strcat (buf, small_buf);
847 }
848
849 if (layoutstyle_n && layoutstyle_n[0])
850 {
851 sprintf (small_buf, "layoutstyle %s\n", layoutstyle_n);
852 strcat (buf, small_buf);
853 }
854
855 if (decorstyle_n && decorstyle_n[0])
856 {
857 sprintf (small_buf, "decorstyle %s\n", decorstyle_n);
858 strcat (buf, small_buf);
859 }
860
861 if (doorstyle_n && doorstyle_n[0])
862 {
863 sprintf (small_buf, "doorstyle %s\n", doorstyle_n);
864 strcat (buf, small_buf);
865 }
866
867 if (exitstyle_n && exitstyle_n[0])
868 {
869 sprintf (small_buf, "exitstyle %s\n", exitstyle_n);
870 strcat (buf, small_buf);
871 }
872
873 if (final_map_n && final_map_n[0])
874 {
875 sprintf (small_buf, "final_map %s\n", final_map_n);
876 strcat (buf, small_buf);
877 }
878
879 if (exit_on_final_map_n && exit_on_final_map_n[0])
880 {
881 sprintf (small_buf, "exit_on_final_map %s\n", exit_on_final_map_n);
882 strcat (buf, small_buf);
883 }
884
885 if (this_map_n && this_map_n[0])
886 {
887 sprintf (small_buf, "origin_map %s\n", this_map_n);
888 strcat (buf, small_buf);
889 }
890
891 if (layoutoptions1_n)
892 {
893 sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n);
894 strcat (buf, small_buf);
895 }
896
897 if (layoutoptions2_n)
898 {
899 sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n);
900 strcat (buf, small_buf);
901 }
902
903
904 if (layoutoptions3_n)
905 {
906 sprintf (small_buf, "layoutoptions3 %d\n", layoutoptions3_n);
907 strcat (buf, small_buf);
908 }
909
910 if (symmetry_n)
911 {
912 sprintf (small_buf, "symmetry %d\n", symmetry_n);
913 strcat (buf, small_buf);
914 }
915
916
917 if (difficulty_n && difficulty_given_n)
918 {
919 sprintf (small_buf, "difficulty %d\n", difficulty_n);
920 strcat (buf, small_buf);
921 }
922
923 if (difficulty_increase > 0.001)
924 {
925 sprintf (small_buf, "difficulty_increase %f\n", difficulty_increase);
926 strcat (buf, small_buf);
927 }
928
929 sprintf (small_buf, "dungeon_level %d\n", dungeon_level_n);
930 strcat (buf, small_buf);
931
932 if (dungeon_depth_n)
933 {
934 sprintf (small_buf, "dungeon_depth %d\n", dungeon_depth_n);
935 strcat (buf, small_buf);
936 }
937
938 if (decoroptions_n)
939 {
940 sprintf (small_buf, "decoroptions %d\n", decoroptions_n);
941 strcat (buf, small_buf);
942 }
943
944 if (orientation_n)
945 {
946 sprintf (small_buf, "orientation %d\n", orientation_n);
947 strcat (buf, small_buf);
948 }
949
950 if (origin_x_n)
951 {
952 sprintf (small_buf, "origin_x %d\n", origin_x_n);
953 strcat (buf, small_buf);
954 }
955
956 if (origin_y_n)
957 {
958 sprintf (small_buf, "origin_y %d\n", origin_y_n);
959 strcat (buf, small_buf);
960 }
961
962 if (random_seed_n)
963 {
964 /* Add one so that the next map is a bit different */
965 sprintf (small_buf, "random_seed %d\n", random_seed_n + 1);
966 strcat (buf, small_buf);
967 }
968
969 if (treasureoptions_n)
970 {
971 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n);
972 strcat (buf, small_buf);
973 }
974
975
976 }
977
978 /* copy an object with an inventory... i.e., duplicate the inv too. */
979 void
980 copy_object_with_inv (object *src_ob, object *dest_ob)
981 {
982 object *walk, *tmp;
983
984 src_ob->copy_to (dest_ob);
985
986 for (walk = src_ob->inv; walk != NULL; walk = walk->below)
987 {
988 tmp = object::create ();
989 walk->copy_to (tmp);
990 insert_ob_in_ob (tmp, dest_ob);
991 }
992 }