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.15 by root, Sun Dec 31 20:48:27 2006 UTC

1
1/* 2/*
2 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
3 4
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
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;
56
57maptile * 56maptile *
58generate_random_map (const char *OutFileName, random_map_params * RP) 57generate_random_map (const char *OutFileName, random_map_params *RP)
59{ 58{
60 char **layout, buf[HUGE_BUF]; 59 char **layout, buf[HUGE_BUF];
61 maptile *theMap; 60 maptile *theMap;
62 int i; 61 int i;
63 62
64 /* pick a random seed, or use the one from the input file */ 63 /* pick a random seed, or use the one from the input file */
65 if (RP->random_seed == 0) 64 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 65
70 write_map_parameters_to_string (buf, RP); 66 write_map_parameters_to_string (buf, RP);
71 67
72 if (RP->difficulty == 0) 68 if (RP->difficulty == 0)
73 { 69 {
118 theMap->path = OutFileName; 114 theMap->path = OutFileName;
119 115
120 /* set region */ 116 /* set region */
121 theMap->region = RP->region; 117 theMap->region = RP->region;
122 118
119 coroapi::cede ();
123 /* create walls unless the wallstyle is "none" */ 120 /* create walls unless the wallstyle is "none" */
124 if (strcmp (RP->wallstyle, "none")) 121 if (strcmp (RP->wallstyle, "none"))
125 { 122 {
126 make_map_walls (theMap, layout, RP->wallstyle, RP); 123 make_map_walls (theMap, layout, RP->wallstyle, RP);
127 124
129 if (strcmp (RP->doorstyle, "none")) 126 if (strcmp (RP->doorstyle, "none"))
130 put_doors (theMap, layout, RP->doorstyle, RP); 127 put_doors (theMap, layout, RP->doorstyle, RP);
131 128
132 } 129 }
133 130
131 coroapi::cede ();
134 /* create exits unless the exitstyle is "none" */ 132 /* create exits unless the exitstyle is "none" */
135 if (strcmp (RP->exitstyle, "none")) 133 if (strcmp (RP->exitstyle, "none"))
136 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); 134 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP);
137 135
136 coroapi::cede ();
138 place_specials_in_map (theMap, layout, RP); 137 place_specials_in_map (theMap, layout, RP);
139 138
139 coroapi::cede ();
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 (theMap, RP->monsterstyle, RP->difficulty, RP);
143 143
144 coroapi::cede ();
144 /* treasures needs to have a proper difficulty set for the map. */ 145 /* treasures needs to have a proper difficulty set for the map. */
145 theMap->difficulty = theMap->estimate_difficulty (); 146 theMap->difficulty = theMap->estimate_difficulty ();
146 147
148 coroapi::cede ();
147 /* create treasure unless the treasurestyle is "none" */ 149 /* create treasure unless the treasurestyle is "none" */
148 if (strcmp (RP->treasurestyle, "none")) 150 if (strcmp (RP->treasurestyle, "none"))
149 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); 151 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP);
150 152
153 coroapi::cede ();
151 /* create decor unless the decorstyle is "none" */ 154 /* create decor unless the decorstyle is "none" */
152 if (strcmp (RP->decorstyle, "none")) 155 if (strcmp (RP->decorstyle, "none"))
153 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); 156 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP);
154 157
158 coroapi::cede ();
155 /* generate treasures, etc. */ 159 /* generate treasures, etc. */
156 theMap->fix_auto_apply (); 160 theMap->fix_auto_apply ();
157 161
162 coroapi::cede ();
158 unblock_exits (theMap, layout, RP); 163 unblock_exits (theMap, layout, RP);
159 164
160 /* free the layout */ 165 /* free the layout */
161 for (i = 0; i < RP->Xsize; i++) 166 for (i = 0; i < RP->Xsize; i++)
162 free (layout[i]); 167 free (layout[i]);
170} 175}
171 176
172/* function selects the layout function and gives it whatever 177/* function selects the layout function and gives it whatever
173 arguments it needs. */ 178 arguments it needs. */
174char ** 179char **
175layoutgen (random_map_params * RP) 180layoutgen (random_map_params *RP)
176{ 181{
177 char **maze = 0; 182 char **maze = 0;
178 int oxsize = RP->Xsize, oysize = RP->Ysize; 183 int oxsize = RP->Xsize, oysize = RP->Ysize;
179 184
180 if (RP->symmetry == SYMMETRY_RANDOM) 185 if (RP->symmetry == SYMMETRY_RANDOM)
285} 290}
286 291
287/* takes a map and makes it symmetric: adjusts Xsize and 292/* takes a map and makes it symmetric: adjusts Xsize and
288Ysize to produce a symmetric map. */ 293Ysize to produce a symmetric map. */
289char ** 294char **
290symmetrize_layout (char **maze, int sym, random_map_params * RP) 295symmetrize_layout (char **maze, int sym, random_map_params *RP)
291{ 296{
292 int i, j; 297 int i, j;
293 char **sym_maze; 298 char **sym_maze;
294 int Xsize_orig, Ysize_orig; 299 int Xsize_orig, Ysize_orig;
295 300
353 onion layouts, making them possibly centered on any wall. 358 onion layouts, making them possibly centered on any wall.
354 It'll modify Xsize and Ysize if they're swapped. 359 It'll modify Xsize and Ysize if they're swapped.
355*/ 360*/
356 361
357char ** 362char **
358rotate_layout (char **maze, int rotation, random_map_params * RP) 363rotate_layout (char **maze, int rotation, random_map_params *RP)
359{ 364{
360 char **new_maze; 365 char **new_maze;
361 int i, j; 366 int i, j;
362 367
363 switch (rotation) 368 switch (rotation)
364 { 369 {
365 case 0: 370 case 0:
366 return maze; 371 return maze;
367 break; 372 break;
368 case 2: /* a reflection */ 373 case 2: /* a reflection */
369 { 374 {
370 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); 375 char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize);
371 376
372 for (i = 0; i < RP->Xsize; i++) 377 for (i = 0; i < RP->Xsize; i++)
373 { /* make a copy */ 378 { /* make a copy */
374 for (j = 0; j < RP->Ysize; j++) 379 for (j = 0; j < RP->Ysize; j++)
375 { 380 {
376 newmaze[i * RP->Ysize + j] = maze[i][j]; 381 newmaze[i * RP->Ysize + j] = maze[i][j];
377 } 382 }
378 } 383 }
379 for (i = 0; i < RP->Xsize; i++) 384 for (i = 0; i < RP->Xsize; i++)
380 { /* copy a reflection back */ 385 { /* copy a reflection back */
381 for (j = 0; j < RP->Ysize; j++) 386 for (j = 0; j < RP->Ysize; j++)
382 { 387 {
383 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; 388 maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1];
384 } 389 }
385 } 390 }
394 new_maze = (char **) calloc (sizeof (char *), RP->Ysize); 399 new_maze = (char **) calloc (sizeof (char *), RP->Ysize);
395 for (i = 0; i < RP->Ysize; i++) 400 for (i = 0; i < RP->Ysize; i++)
396 { 401 {
397 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); 402 new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize);
398 } 403 }
399 if (rotation == 1) /* swap x and y */ 404 if (rotation == 1) /* swap x and y */
400 for (i = 0; i < RP->Xsize; i++) 405 for (i = 0; i < RP->Xsize; i++)
401 for (j = 0; j < RP->Ysize; j++) 406 for (j = 0; j < RP->Ysize; j++)
402 new_maze[j][i] = maze[i][j]; 407 new_maze[j][i] = maze[i][j];
403 408
404 if (rotation == 3) 409 if (rotation == 3)
405 { /* swap x and y */ 410 { /* swap x and y */
406 for (i = 0; i < RP->Xsize; i++) 411 for (i = 0; i < RP->Xsize; i++)
407 for (j = 0; j < RP->Ysize; j++) 412 for (j = 0; j < RP->Ysize; j++)
408 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; 413 new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1];
409 } 414 }
410 415
424} 429}
425 430
426/* take a layout and make some rooms in it. 431/* take a layout and make some rooms in it.
427 --works best on onions.*/ 432 --works best on onions.*/
428void 433void
429roomify_layout (char **maze, random_map_params * RP) 434roomify_layout (char **maze, random_map_params *RP)
430{ 435{
431 int tries = RP->Xsize * RP->Ysize / 30; 436 int tries = RP->Xsize * RP->Ysize / 30;
432 int ti; 437 int ti;
433 438
434 for (ti = 0; ti < tries; ti++) 439 for (ti = 0; ti < tries; ti++)
461/* checks the layout to see if I can stick a horizontal(dir = 0) wall 466/* checks the layout to see if I can stick a horizontal(dir = 0) wall
462 (or vertical, dir == 1) 467 (or vertical, dir == 1)
463 here which ends up on other walls sensibly. */ 468 here which ends up on other walls sensibly. */
464 469
465int 470int
466can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) 471can_make_wall (char **maze, int dx, int dy, int dir, random_map_params *RP)
467{ 472{
468 int i1; 473 int i1;
469 int length = 0; 474 int length = 0;
470 475
471 /* dont make walls if we're on the edge. */ 476 /* dont make walls if we're on the edge. */
546make_wall (char **maze, int x, int y, int dir) 551make_wall (char **maze, int x, int y, int dir)
547{ 552{
548 maze[x][y] = 'D'; /* mark a door */ 553 maze[x][y] = 'D'; /* mark a door */
549 switch (dir) 554 switch (dir)
550 { 555 {
551 case 0: /* horizontal */ 556 case 0: /* horizontal */
552 { 557 {
553 int i1; 558 int i1;
554 559
555 for (i1 = x - 1; maze[i1][y] == 0; i1--) 560 for (i1 = x - 1; maze[i1][y] == 0; i1--)
556 maze[i1][y] = '#'; 561 maze[i1][y] = '#';
557 for (i1 = x + 1; maze[i1][y] == 0; i1++) 562 for (i1 = x + 1; maze[i1][y] == 0; i1++)
558 maze[i1][y] = '#'; 563 maze[i1][y] = '#';
559 break; 564 break;
560 } 565 }
561 case 1: /* vertical */ 566 case 1: /* vertical */
562 { 567 {
563 int i1; 568 int i1;
564 569
565 for (i1 = y - 1; maze[x][i1] == 0; i1--) 570 for (i1 = y - 1; maze[x][i1] == 0; i1--)
566 maze[x][i1] = '#'; 571 maze[x][i1] = '#';
567 for (i1 = y + 1; maze[x][i1] == 0; i1++) 572 for (i1 = y + 1; maze[x][i1] == 0; i1++)
568 maze[x][i1] = '#'; 573 maze[x][i1] = '#';
569 break; 574 break;
570 } 575 }
571 } 576 }
572 577
573 return 0; 578 return 0;
574} 579}
575 580
576/* puts doors at appropriate locations in a layout. */ 581/* puts doors at appropriate locations in a layout. */
577void 582void
578doorify_layout (char **maze, random_map_params * RP) 583doorify_layout (char **maze, random_map_params *RP)
579{ 584{
580 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ 585 int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */
581 char *doorlist_x; 586 char *doorlist_x;
582 char *doorlist_y; 587 char *doorlist_y;
583 int doorlocs = 0; /* # of available doorlocations */ 588 int doorlocs = 0; /* # of available doorlocations */
624 free (doorlist_x); 629 free (doorlist_x);
625 free (doorlist_y); 630 free (doorlist_y);
626} 631}
627 632
628void 633void
629write_map_parameters_to_string (char *buf, random_map_params * RP) 634write_map_parameters_to_string (char *buf, random_map_params *RP)
630{ 635{
631 char small_buf[256]; 636 char small_buf[2048];
632 637
633 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 638 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
634 639
635 if (RP->wallstyle[0]) 640 if (RP->wallstyle[0])
636 { 641 {
678 { 683 {
679 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); 684 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
680 strcat (buf, small_buf); 685 strcat (buf, small_buf);
681 } 686 }
682 687
683 if (RP->final_map[0]) 688 if (RP->final_map.length ())
684 { 689 {
685 sprintf (small_buf, "final_map %s\n", RP->final_map); 690 sprintf (small_buf, "final_map %s\n", &RP->final_map);
686 strcat (buf, small_buf); 691 strcat (buf, small_buf);
687 } 692 }
688 693
689 if (RP->exit_on_final_map[0]) 694 if (RP->exit_on_final_map[0])
690 { 695 {
691 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map); 696 sprintf (small_buf, "exit_on_final_map %s\n", RP->exit_on_final_map);
692 strcat (buf, small_buf); 697 strcat (buf, small_buf);
693 } 698 }
694 699
695 if (RP->this_map[0]) 700 if (RP->this_map.length ())
696 { 701 {
697 sprintf (small_buf, "origin_map %s\n", RP->this_map); 702 sprintf (small_buf, "origin_map %s\n", &RP->this_map);
698 strcat (buf, small_buf); 703 strcat (buf, small_buf);
699 } 704 }
700 705
701 if (RP->expand2x) 706 if (RP->expand2x)
702 { 707 {
708 { 713 {
709 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); 714 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
710 strcat (buf, small_buf); 715 strcat (buf, small_buf);
711 } 716 }
712 717
713
714 if (RP->layoutoptions2) 718 if (RP->layoutoptions2)
715 { 719 {
716 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); 720 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
717 strcat (buf, small_buf); 721 strcat (buf, small_buf);
718 } 722 }
719 723
720
721 if (RP->layoutoptions3) 724 if (RP->layoutoptions3)
722 { 725 {
723 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); 726 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
724 strcat (buf, small_buf); 727 strcat (buf, small_buf);
725 } 728 }
727 if (RP->symmetry) 730 if (RP->symmetry)
728 { 731 {
729 sprintf (small_buf, "symmetry %d\n", RP->symmetry); 732 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
730 strcat (buf, small_buf); 733 strcat (buf, small_buf);
731 } 734 }
732
733 735
734 if (RP->difficulty && RP->difficulty_given) 736 if (RP->difficulty && RP->difficulty_given)
735 { 737 {
736 sprintf (small_buf, "difficulty %d\n", RP->difficulty); 738 sprintf (small_buf, "difficulty %d\n", RP->difficulty);
737 strcat (buf, small_buf); 739 strcat (buf, small_buf);
784 } 786 }
785 787
786 if (RP->treasureoptions) 788 if (RP->treasureoptions)
787 { 789 {
788 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); 790 sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions);
791 strcat (buf, small_buf);
792 }
793
794 if (RP->random_seed)
795 {
796 sprintf (small_buf, "random_seed %d\n", RP->random_seed);
789 strcat (buf, small_buf); 797 strcat (buf, small_buf);
790 } 798 }
791} 799}
792 800
793void 801void
815 int difficulty_given_n, 823 int difficulty_given_n,
816 int decoroptions_n, 824 int decoroptions_n,
817 int orientation_n, 825 int orientation_n,
818 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) 826 int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase)
819{ 827{
820
821 char small_buf[256]; 828 char small_buf[2048];
822 829
823 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); 830 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
824 831
825 if (wallstyle_n && wallstyle_n[0]) 832 if (wallstyle_n && wallstyle_n[0])
826 { 833 {
969 if (treasureoptions_n) 976 if (treasureoptions_n)
970 { 977 {
971 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); 978 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n);
972 strcat (buf, small_buf); 979 strcat (buf, small_buf);
973 } 980 }
974
975
976} 981}
977 982
978/* copy an object with an inventory... i.e., duplicate the inv too. */ 983/* copy an object with an inventory... i.e., duplicate the inv too. */
979void 984void
980copy_object_with_inv (object *src_ob, object *dest_ob) 985copy_object_with_inv (object *src_ob, object *dest_ob)
981{ 986{
982 object *walk, *tmp; 987 object *walk, *tmp;
983 988
984 src_ob->copy_to (dest_ob); 989 src_ob->copy_to (dest_ob);
985 990
986 for (walk = src_ob->inv; walk != NULL; walk = walk->below) 991 for (walk = src_ob->inv; walk; walk = walk->below)
987 { 992 {
988 tmp = object::create (); 993 tmp = object::create ();
994
989 walk->copy_to (tmp); 995 walk->copy_to (tmp);
990 insert_ob_in_ob (tmp, dest_ob); 996 insert_ob_in_ob (tmp, dest_ob);
991 } 997 }
992} 998}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines