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.13 by root, Sun Dec 31 19:02:24 2006 UTC vs.
Revision 1.14 by root, Sun Dec 31 20:46:17 2006 UTC

51 } 51 }
52 } 52 }
53 printf ("\n"); 53 printf ("\n");
54} 54}
55 55
56extern FILE *logfile;
57
58maptile * 56maptile *
59generate_random_map (const char *OutFileName, random_map_params *RP) 57generate_random_map (const char *OutFileName, random_map_params *RP)
60{ 58{
61 char **layout, buf[HUGE_BUF]; 59 char **layout, buf[HUGE_BUF];
62 maptile *theMap; 60 maptile *theMap;
63 int i; 61 int i;
64 62
65 /* 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 */
66 if (RP->random_seed == 0) 64 SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0));
67 RP->random_seed = time (0);
68
69 SRANDOM (RP->random_seed);
70 65
71 write_map_parameters_to_string (buf, RP); 66 write_map_parameters_to_string (buf, RP);
72 67
73 if (RP->difficulty == 0) 68 if (RP->difficulty == 0)
74 { 69 {
119 theMap->path = OutFileName; 114 theMap->path = OutFileName;
120 115
121 /* set region */ 116 /* set region */
122 theMap->region = RP->region; 117 theMap->region = RP->region;
123 118
119 coroapi.cede ();
124 /* create walls unless the wallstyle is "none" */ 120 /* create walls unless the wallstyle is "none" */
125 if (strcmp (RP->wallstyle, "none")) 121 if (strcmp (RP->wallstyle, "none"))
126 { 122 {
127 make_map_walls (theMap, layout, RP->wallstyle, RP); 123 make_map_walls (theMap, layout, RP->wallstyle, RP);
128 124
130 if (strcmp (RP->doorstyle, "none")) 126 if (strcmp (RP->doorstyle, "none"))
131 put_doors (theMap, layout, RP->doorstyle, RP); 127 put_doors (theMap, layout, RP->doorstyle, RP);
132 128
133 } 129 }
134 130
131 coroapi.cede ();
135 /* create exits unless the exitstyle is "none" */ 132 /* create exits unless the exitstyle is "none" */
136 if (strcmp (RP->exitstyle, "none")) 133 if (strcmp (RP->exitstyle, "none"))
137 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP); 134 place_exits (theMap, layout, RP->exitstyle, RP->orientation, RP);
138 135
136 coroapi.cede ();
139 place_specials_in_map (theMap, layout, RP); 137 place_specials_in_map (theMap, layout, RP);
140 138
139 coroapi.cede ();
141 /* create monsters unless the monsterstyle is "none" */ 140 /* create monsters unless the monsterstyle is "none" */
142 if (strcmp (RP->monsterstyle, "none")) 141 if (strcmp (RP->monsterstyle, "none"))
143 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); 142 place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP);
144 143
144 coroapi.cede ();
145 /* treasures needs to have a proper difficulty set for the map. */ 145 /* treasures needs to have a proper difficulty set for the map. */
146 theMap->difficulty = theMap->estimate_difficulty (); 146 theMap->difficulty = theMap->estimate_difficulty ();
147 147
148 coroapi.cede ();
148 /* create treasure unless the treasurestyle is "none" */ 149 /* create treasure unless the treasurestyle is "none" */
149 if (strcmp (RP->treasurestyle, "none")) 150 if (strcmp (RP->treasurestyle, "none"))
150 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); 151 place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP);
151 152
153 coroapi.cede ();
152 /* create decor unless the decorstyle is "none" */ 154 /* create decor unless the decorstyle is "none" */
153 if (strcmp (RP->decorstyle, "none")) 155 if (strcmp (RP->decorstyle, "none"))
154 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); 156 put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP);
155 157
158 coroapi.cede ();
156 /* generate treasures, etc. */ 159 /* generate treasures, etc. */
157 theMap->fix_auto_apply (); 160 theMap->fix_auto_apply ();
158 161
162 coroapi.cede ();
159 unblock_exits (theMap, layout, RP); 163 unblock_exits (theMap, layout, RP);
160 164
161 /* free the layout */ 165 /* free the layout */
162 for (i = 0; i < RP->Xsize; i++) 166 for (i = 0; i < RP->Xsize; i++)
163 free (layout[i]); 167 free (layout[i]);
627} 631}
628 632
629void 633void
630write_map_parameters_to_string (char *buf, random_map_params *RP) 634write_map_parameters_to_string (char *buf, random_map_params *RP)
631{ 635{
632 char small_buf[256]; 636 char small_buf[2048];
633 637
634 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); 638 sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize);
635 639
636 if (RP->wallstyle[0]) 640 if (RP->wallstyle[0])
637 { 641 {
679 { 683 {
680 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle); 684 sprintf (small_buf, "exitstyle %s\n", RP->exitstyle);
681 strcat (buf, small_buf); 685 strcat (buf, small_buf);
682 } 686 }
683 687
684 if (RP->final_map[0]) 688 if (RP->final_map.length ())
685 { 689 {
686 sprintf (small_buf, "final_map %s\n", RP->final_map); 690 sprintf (small_buf, "final_map %s\n", &RP->final_map);
687 strcat (buf, small_buf); 691 strcat (buf, small_buf);
688 } 692 }
689 693
690 if (RP->exit_on_final_map[0]) 694 if (RP->exit_on_final_map[0])
691 { 695 {
692 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);
693 strcat (buf, small_buf); 697 strcat (buf, small_buf);
694 } 698 }
695 699
696 if (RP->this_map[0]) 700 if (RP->this_map.length ())
697 { 701 {
698 sprintf (small_buf, "origin_map %s\n", RP->this_map); 702 sprintf (small_buf, "origin_map %s\n", &RP->this_map);
699 strcat (buf, small_buf); 703 strcat (buf, small_buf);
700 } 704 }
701 705
702 if (RP->expand2x) 706 if (RP->expand2x)
703 { 707 {
709 { 713 {
710 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1); 714 sprintf (small_buf, "layoutoptions1 %d\n", RP->layoutoptions1);
711 strcat (buf, small_buf); 715 strcat (buf, small_buf);
712 } 716 }
713 717
714
715 if (RP->layoutoptions2) 718 if (RP->layoutoptions2)
716 { 719 {
717 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2); 720 sprintf (small_buf, "layoutoptions2 %d\n", RP->layoutoptions2);
718 strcat (buf, small_buf); 721 strcat (buf, small_buf);
719 } 722 }
720 723
721
722 if (RP->layoutoptions3) 724 if (RP->layoutoptions3)
723 { 725 {
724 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3); 726 sprintf (small_buf, "layoutoptions3 %d\n", RP->layoutoptions3);
725 strcat (buf, small_buf); 727 strcat (buf, small_buf);
726 } 728 }
728 if (RP->symmetry) 730 if (RP->symmetry)
729 { 731 {
730 sprintf (small_buf, "symmetry %d\n", RP->symmetry); 732 sprintf (small_buf, "symmetry %d\n", RP->symmetry);
731 strcat (buf, small_buf); 733 strcat (buf, small_buf);
732 } 734 }
733
734 735
735 if (RP->difficulty && RP->difficulty_given) 736 if (RP->difficulty && RP->difficulty_given)
736 { 737 {
737 sprintf (small_buf, "difficulty %d\n", RP->difficulty); 738 sprintf (small_buf, "difficulty %d\n", RP->difficulty);
738 strcat (buf, small_buf); 739 strcat (buf, small_buf);
785 } 786 }
786 787
787 if (RP->treasureoptions) 788 if (RP->treasureoptions)
788 { 789 {
789 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);
790 strcat (buf, small_buf); 797 strcat (buf, small_buf);
791 } 798 }
792} 799}
793 800
794void 801void
816 int difficulty_given_n, 823 int difficulty_given_n,
817 int decoroptions_n, 824 int decoroptions_n,
818 int orientation_n, 825 int orientation_n,
819 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)
820{ 827{
821
822 char small_buf[256]; 828 char small_buf[2048];
823 829
824 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); 830 sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n);
825 831
826 if (wallstyle_n && wallstyle_n[0]) 832 if (wallstyle_n && wallstyle_n[0])
827 { 833 {
970 if (treasureoptions_n) 976 if (treasureoptions_n)
971 { 977 {
972 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n); 978 sprintf (small_buf, "treasureoptions %d\n", treasureoptions_n);
973 strcat (buf, small_buf); 979 strcat (buf, small_buf);
974 } 980 }
975
976
977} 981}
978 982
979/* 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. */
980void 984void
981copy_object_with_inv (object *src_ob, object *dest_ob) 985copy_object_with_inv (object *src_ob, object *dest_ob)
982{ 986{
983 object *walk, *tmp; 987 object *walk, *tmp;
984 988
985 src_ob->copy_to (dest_ob); 989 src_ob->copy_to (dest_ob);
986 990
987 for (walk = src_ob->inv; walk != NULL; walk = walk->below) 991 for (walk = src_ob->inv; walk; walk = walk->below)
988 { 992 {
989 tmp = object::create (); 993 tmp = object::create ();
990 994
991 walk->copy_to (tmp); 995 walk->copy_to (tmp);
992 insert_ob_in_ob (tmp, dest_ob); 996 insert_ob_in_ob (tmp, dest_ob);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines