… | |
… | |
29 | #include <room_gen.h> |
29 | #include <room_gen.h> |
30 | #include <random_map.h> |
30 | #include <random_map.h> |
31 | #include <rproto.h> |
31 | #include <rproto.h> |
32 | #include <sproto.h> |
32 | #include <sproto.h> |
33 | |
33 | |
|
|
34 | #define CEDE coroapi::cede (); rndm.seed (RP->random_seed + __LINE__); |
|
|
35 | |
34 | void |
36 | void |
35 | dump_layout (char **layout, random_map_params *RP) |
37 | dump_layout (char **layout, random_map_params *RP) |
36 | { |
38 | { |
37 | { |
39 | { |
38 | int i, j; |
40 | int i, j; |
… | |
… | |
57 | maptile::generate_random_map (random_map_params *RP) |
59 | maptile::generate_random_map (random_map_params *RP) |
58 | { |
60 | { |
59 | char **layout, buf[16384]; |
61 | char **layout, buf[16384]; |
60 | int i; |
62 | int i; |
61 | |
63 | |
|
|
64 | RP->Xsize = RP->xsize; |
|
|
65 | RP->Ysize = RP->ysize; |
|
|
66 | |
62 | /* pick a random seed, or use the one from the input file */ |
67 | /* pick a random seed, or use the one from the input file */ |
63 | SRANDOM (RP->random_seed ? RP->random_seed + RP->dungeon_level : time (0)); |
68 | RP->random_seed = RP->random_seed |
|
|
69 | ? RP->random_seed + RP->dungeon_level |
|
|
70 | : time (0); |
|
|
71 | CEDE; |
64 | |
72 | |
65 | write_map_parameters_to_string (buf, RP); |
73 | write_map_parameters_to_string (buf, RP); |
66 | |
74 | |
67 | if (RP->difficulty == 0) |
75 | if (RP->difficulty == 0) |
68 | { |
76 | { |
… | |
… | |
81 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
89 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
82 | |
90 | |
83 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
91 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
84 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
92 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
85 | |
93 | |
|
|
94 | if (RP->symmetry == SYMMETRY_RANDOM) |
|
|
95 | RP->symmetry_used = rndm (SYMMETRY_XY) + 1; |
|
|
96 | else |
|
|
97 | RP->symmetry_used = RP->symmetry; |
|
|
98 | |
|
|
99 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
|
|
100 | RP->Ysize = RP->Ysize / 2 + 1; |
|
|
101 | |
|
|
102 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
|
|
103 | RP->Xsize = RP->Xsize / 2 + 1; |
|
|
104 | |
86 | if (RP->expand2x > 0) |
105 | if (RP->expand2x > 0) |
87 | { |
106 | { |
88 | RP->Xsize /= 2; |
107 | RP->Xsize /= 2; |
89 | RP->Ysize /= 2; |
108 | RP->Ysize /= 2; |
90 | } |
109 | } |
91 | |
110 | |
92 | layout = layoutgen (RP); |
|
|
93 | |
|
|
94 | #ifdef RMAP_DEBUG |
|
|
95 | dump_layout (layout, RP); |
|
|
96 | #endif |
|
|
97 | |
|
|
98 | /* increment these for the current map */ |
|
|
99 | RP->dungeon_level += 1; |
|
|
100 | /* allow constant-difficulty maps. */ |
|
|
101 | /* difficulty+=1; */ |
|
|
102 | |
|
|
103 | /* rotate the layout randomly */ |
|
|
104 | layout = rotate_layout (layout, rndm (4), RP); |
|
|
105 | #ifdef RMAP_DEBUG |
|
|
106 | dump_layout (layout, RP); |
|
|
107 | #endif |
|
|
108 | |
|
|
109 | /* allocate the map and set the floor */ |
|
|
110 | make_map_floor (layout, RP->floorstyle, RP); |
|
|
111 | |
|
|
112 | /* set region */ |
|
|
113 | region = RP->region; |
|
|
114 | |
|
|
115 | coroapi::cede (); |
|
|
116 | |
|
|
117 | /* create walls unless the wallstyle is "none" */ |
|
|
118 | if (strcmp (RP->wallstyle, "none")) |
|
|
119 | { |
|
|
120 | make_map_walls (this, layout, RP->wallstyle, RP); |
|
|
121 | |
|
|
122 | /* place doors unless doorstyle or wallstyle is "none" */ |
|
|
123 | if (strcmp (RP->doorstyle, "none")) |
|
|
124 | put_doors (this, layout, RP->doorstyle, RP); |
|
|
125 | |
|
|
126 | } |
|
|
127 | |
|
|
128 | coroapi::cede (); |
|
|
129 | |
|
|
130 | /* create exits unless the exitstyle is "none" */ |
|
|
131 | if (strcmp (RP->exitstyle, "none")) |
|
|
132 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
|
|
133 | |
|
|
134 | coroapi::cede (); |
|
|
135 | |
|
|
136 | place_specials_in_map (this, layout, RP); |
|
|
137 | |
|
|
138 | coroapi::cede (); |
|
|
139 | |
|
|
140 | /* create monsters unless the monsterstyle is "none" */ |
|
|
141 | if (strcmp (RP->monsterstyle, "none")) |
|
|
142 | place_monsters (this, RP->monsterstyle, RP->difficulty, RP); |
|
|
143 | |
|
|
144 | coroapi::cede (); |
|
|
145 | |
|
|
146 | /* treasures needs to have a proper difficulty set for the map. */ |
|
|
147 | difficulty = estimate_difficulty (); |
|
|
148 | |
|
|
149 | coroapi::cede (); |
|
|
150 | |
|
|
151 | /* create treasure unless the treasurestyle is "none" */ |
|
|
152 | if (strcmp (RP->treasurestyle, "none")) |
|
|
153 | place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); |
|
|
154 | |
|
|
155 | coroapi::cede (); |
|
|
156 | |
|
|
157 | /* create decor unless the decorstyle is "none" */ |
|
|
158 | if (strcmp (RP->decorstyle, "none")) |
|
|
159 | put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); |
|
|
160 | |
|
|
161 | coroapi::cede (); |
|
|
162 | |
|
|
163 | /* generate treasures, etc. */ |
|
|
164 | fix_auto_apply (); |
|
|
165 | |
|
|
166 | coroapi::cede (); |
|
|
167 | unblock_exits (this, layout, RP); |
|
|
168 | |
|
|
169 | /* free the layout */ |
|
|
170 | for (i = 0; i < RP->Xsize; i++) |
|
|
171 | free (layout[i]); |
|
|
172 | |
|
|
173 | free (layout); |
|
|
174 | |
|
|
175 | msg = strdup (buf); |
|
|
176 | in_memory = MAP_IN_MEMORY; |
|
|
177 | |
|
|
178 | return 1; |
|
|
179 | } |
|
|
180 | |
|
|
181 | /* function selects the layout function and gives it whatever |
|
|
182 | arguments it needs. */ |
|
|
183 | char ** |
|
|
184 | layoutgen (random_map_params *RP) |
|
|
185 | { |
|
|
186 | char **maze = 0; |
|
|
187 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
|
|
188 | |
|
|
189 | if (RP->symmetry == SYMMETRY_RANDOM) |
|
|
190 | RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; |
|
|
191 | else |
|
|
192 | RP->symmetry_used = RP->symmetry; |
|
|
193 | |
|
|
194 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
|
|
195 | RP->Ysize = RP->Ysize / 2 + 1; |
|
|
196 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
|
|
197 | RP->Xsize = RP->Xsize / 2 + 1; |
|
|
198 | |
|
|
199 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
|
|
200 | RP->Xsize = MIN_RANDOM_MAP_SIZE + rndm (5); |
|
|
201 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
|
|
202 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (5); |
|
|
203 | RP->map_layout_style = 0; |
111 | RP->map_layout_style = LAYOUT_NONE; |
204 | |
112 | |
205 | /* Redo this - there was a lot of redundant code of checking for preset |
113 | /* Redo this - there was a lot of redundant code of checking for preset |
206 | * layout style and then random layout style. Instead, figure out |
114 | * layout style and then random layout style. Instead, figure out |
207 | * the numeric layoutstyle, so there is only one area that actually |
115 | * the numeric layoutstyle, so there is only one area that actually |
208 | * calls the code to make the maps. |
116 | * calls the code to make the maps. |
… | |
… | |
223 | RP->map_layout_style = LAYOUT_SNAKE; |
131 | RP->map_layout_style = LAYOUT_SNAKE; |
224 | |
132 | |
225 | if (strstr (RP->layoutstyle, "squarespiral")) |
133 | if (strstr (RP->layoutstyle, "squarespiral")) |
226 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
134 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
227 | |
135 | |
228 | /* No style found - choose one ranomdly */ |
136 | /* No style found - choose one randomly */ |
229 | if (RP->map_layout_style == LAYOUT_NONE) |
137 | if (RP->map_layout_style == LAYOUT_NONE) |
230 | RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; |
138 | RP->map_layout_style = rndm (NROFLAYOUTS - 1) + 1; |
|
|
139 | |
|
|
140 | layout = layoutgen (RP); |
|
|
141 | |
|
|
142 | #ifdef RMAP_DEBUG |
|
|
143 | dump_layout (layout, RP); |
|
|
144 | #endif |
|
|
145 | |
|
|
146 | /* increment these for the current map */ |
|
|
147 | RP->dungeon_level += 1; |
|
|
148 | /* allow constant-difficulty maps. */ |
|
|
149 | /* difficulty+=1; */ |
|
|
150 | |
|
|
151 | /* rotate the layout randomly */ |
|
|
152 | layout = rotate_layout (layout, rndm (4), RP); |
|
|
153 | #ifdef RMAP_DEBUG |
|
|
154 | dump_layout (layout, RP); |
|
|
155 | #endif |
|
|
156 | |
|
|
157 | /* allocate the map and set the floor */ |
|
|
158 | make_map_floor (layout, RP->floorstyle, RP); |
|
|
159 | |
|
|
160 | /* set region */ |
|
|
161 | default_region = RP->region; |
|
|
162 | |
|
|
163 | CEDE; |
|
|
164 | |
|
|
165 | /* create walls unless the wallstyle is "none" */ |
|
|
166 | if (strcmp (RP->wallstyle, "none")) |
|
|
167 | { |
|
|
168 | make_map_walls (this, layout, RP->wallstyle, RP); |
|
|
169 | |
|
|
170 | /* place doors unless doorstyle or wallstyle is "none" */ |
|
|
171 | if (strcmp (RP->doorstyle, "none")) |
|
|
172 | put_doors (this, layout, RP->doorstyle, RP); |
|
|
173 | } |
|
|
174 | |
|
|
175 | CEDE; |
|
|
176 | |
|
|
177 | /* create exits unless the exitstyle is "none" */ |
|
|
178 | if (strcmp (RP->exitstyle, "none")) |
|
|
179 | place_exits (this, layout, RP->exitstyle, RP->orientation, RP); |
|
|
180 | |
|
|
181 | CEDE; |
|
|
182 | |
|
|
183 | place_specials_in_map (this, layout, RP); |
|
|
184 | |
|
|
185 | CEDE; |
|
|
186 | |
|
|
187 | /* create monsters unless the monsterstyle is "none" */ |
|
|
188 | if (strcmp (RP->monsterstyle, "none")) |
|
|
189 | place_monsters (this, RP->monsterstyle, RP->difficulty, RP); |
|
|
190 | |
|
|
191 | CEDE; |
|
|
192 | |
|
|
193 | /* treasures needs to have a proper difficulty set for the map. */ |
|
|
194 | difficulty = estimate_difficulty (); |
|
|
195 | |
|
|
196 | CEDE; |
|
|
197 | |
|
|
198 | /* create treasure unless the treasurestyle is "none" */ |
|
|
199 | if (strcmp (RP->treasurestyle, "none")) |
|
|
200 | place_treasure (this, layout, RP->treasurestyle, RP->treasureoptions, RP); |
|
|
201 | |
|
|
202 | CEDE; |
|
|
203 | |
|
|
204 | /* create decor unless the decorstyle is "none" */ |
|
|
205 | if (strcmp (RP->decorstyle, "none")) |
|
|
206 | put_decor (this, layout, RP->decorstyle, RP->decoroptions, RP); |
|
|
207 | |
|
|
208 | CEDE; |
|
|
209 | |
|
|
210 | /* generate treasures, etc. */ |
|
|
211 | fix_auto_apply (); |
|
|
212 | |
|
|
213 | CEDE; |
|
|
214 | |
|
|
215 | unblock_exits (this, layout, RP); |
|
|
216 | |
|
|
217 | /* free the layout */ |
|
|
218 | for (i = 0; i < RP->Xsize; i++) |
|
|
219 | free (layout[i]); |
|
|
220 | |
|
|
221 | free (layout); |
|
|
222 | |
|
|
223 | msg = strdup (buf); |
|
|
224 | in_memory = MAP_IN_MEMORY; |
|
|
225 | |
|
|
226 | CEDE; |
|
|
227 | |
|
|
228 | return 1; |
|
|
229 | } |
|
|
230 | |
|
|
231 | /* function selects the layout function and gives it whatever |
|
|
232 | arguments it needs. */ |
|
|
233 | char ** |
|
|
234 | layoutgen (random_map_params *RP) |
|
|
235 | { |
|
|
236 | char **maze = 0; |
|
|
237 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
231 | |
238 | |
232 | switch (RP->map_layout_style) |
239 | switch (RP->map_layout_style) |
233 | { |
240 | { |
234 | case LAYOUT_ONION: |
241 | case LAYOUT_ONION: |
235 | maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
242 | maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
… | |
… | |
443 | for (ti = 0; ti < tries; ti++) |
450 | for (ti = 0; ti < tries; ti++) |
444 | { |
451 | { |
445 | int dx, dy; /* starting location for looking at creating a door */ |
452 | int dx, dy; /* starting location for looking at creating a door */ |
446 | int cx, cy; /* results of checking on creating walls. */ |
453 | int cx, cy; /* results of checking on creating walls. */ |
447 | |
454 | |
448 | dx = RANDOM () % RP->Xsize; |
455 | dx = rndm (RP->Xsize); |
449 | dy = RANDOM () % RP->Ysize; |
456 | dy = rndm (RP->Ysize); |
|
|
457 | |
450 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
458 | cx = can_make_wall (maze, dx, dy, 0, RP); /* horizontal */ |
451 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
459 | cy = can_make_wall (maze, dx, dy, 1, RP); /* vertical */ |
452 | if (cx == -1) |
460 | if (cx == -1) |
453 | { |
461 | { |
454 | if (cy != -1) |
462 | if (cy != -1) |
455 | make_wall (maze, dx, dy, 1); |
463 | make_wall (maze, dx, dy, 1); |
|
|
464 | |
456 | continue; |
465 | continue; |
457 | } |
466 | } |
|
|
467 | |
458 | if (cy == -1) |
468 | if (cy == -1) |
459 | { |
469 | { |
460 | make_wall (maze, dx, dy, 0); |
470 | make_wall (maze, dx, dy, 0); |
461 | continue; |
471 | continue; |
462 | } |
472 | } |
|
|
473 | |
463 | if (cx < cy) |
474 | if (cx < cy) |
464 | make_wall (maze, dx, dy, 0); |
475 | make_wall (maze, dx, dy, 0); |
465 | else |
476 | else |
466 | make_wall (maze, dx, dy, 1); |
477 | make_wall (maze, dx, dy, 1); |
467 | } |
478 | } |
… | |
… | |
613 | while (ndoors > 0 && doorlocs > 0) |
624 | while (ndoors > 0 && doorlocs > 0) |
614 | { |
625 | { |
615 | int di; |
626 | int di; |
616 | int sindex; |
627 | int sindex; |
617 | |
628 | |
618 | di = RANDOM () % doorlocs; |
629 | di = rndm (doorlocs); |
619 | i = doorlist_x[di]; |
630 | i = doorlist_x[di]; |
620 | j = doorlist_y[di]; |
631 | j = doorlist_y[di]; |
621 | sindex = surround_flag (maze, i, j, RP); |
632 | sindex = surround_flag (maze, i, j, RP); |
|
|
633 | |
622 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
634 | if (sindex == 3 || sindex == 12) /* these are possible door sindex */ |
623 | { |
635 | { |
624 | maze[i][j] = 'D'; |
636 | maze[i][j] = 'D'; |
625 | ndoors--; |
637 | ndoors--; |
626 | } |
638 | } |
|
|
639 | |
627 | /* reduce the size of the list */ |
640 | /* reduce the size of the list */ |
628 | doorlocs--; |
641 | doorlocs--; |
629 | doorlist_x[di] = doorlist_x[doorlocs]; |
642 | doorlist_x[di] = doorlist_x[doorlocs]; |
630 | doorlist_y[di] = doorlist_y[doorlocs]; |
643 | doorlist_y[di] = doorlist_y[doorlocs]; |
631 | } |
644 | } |
… | |
… | |
637 | void |
650 | void |
638 | write_map_parameters_to_string (char *buf, random_map_params *RP) |
651 | write_map_parameters_to_string (char *buf, random_map_params *RP) |
639 | { |
652 | { |
640 | char small_buf[16384]; |
653 | char small_buf[16384]; |
641 | |
654 | |
642 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
655 | sprintf (buf, "xsize %d\nysize %d\n", RP->xsize, RP->ysize); |
643 | |
656 | |
644 | if (RP->wallstyle[0]) |
657 | if (RP->wallstyle[0]) |
645 | { |
658 | { |
646 | sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
659 | sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
647 | strcat (buf, small_buf); |
660 | strcat (buf, small_buf); |
… | |
… | |
788 | strcat (buf, small_buf); |
801 | strcat (buf, small_buf); |
789 | } |
802 | } |
790 | |
803 | |
791 | if (RP->random_seed) |
804 | if (RP->random_seed) |
792 | { |
805 | { |
793 | sprintf (small_buf, "random_seed %d\n", RP->random_seed); |
806 | sprintf (small_buf, "random_seed %u\n", RP->random_seed); |
794 | strcat (buf, small_buf); |
807 | strcat (buf, small_buf); |
795 | } |
808 | } |
796 | |
809 | |
797 | if (RP->custom) |
810 | if (RP->custom) |
798 | { |
811 | { |
… | |
… | |
824 | int dungeon_level_n, |
837 | int dungeon_level_n, |
825 | int difficulty_n, |
838 | int difficulty_n, |
826 | int difficulty_given_n, |
839 | int difficulty_given_n, |
827 | int decoroptions_n, |
840 | int decoroptions_n, |
828 | int orientation_n, |
841 | int orientation_n, |
829 | int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) |
842 | int origin_x_n, int origin_y_n, uint32_t random_seed_n, int treasureoptions_n, float difficulty_increase) |
830 | { |
843 | { |
831 | char small_buf[16384]; |
844 | char small_buf[16384]; |
832 | |
845 | |
833 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
846 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
834 | |
847 | |
… | |
… | |
970 | } |
983 | } |
971 | |
984 | |
972 | if (random_seed_n) |
985 | if (random_seed_n) |
973 | { |
986 | { |
974 | /* Add one so that the next map is a bit different */ |
987 | /* Add one so that the next map is a bit different */ |
975 | sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); |
988 | sprintf (small_buf, "random_seed %u\n", random_seed_n + 1); |
976 | strcat (buf, small_buf); |
989 | strcat (buf, small_buf); |
977 | } |
990 | } |
978 | |
991 | |
979 | if (treasureoptions_n) |
992 | if (treasureoptions_n) |
980 | { |
993 | { |