… | |
… | |
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 | { |
… | |
… | |
76 | } |
84 | } |
77 | else |
85 | else |
78 | RP->difficulty_given = 1; |
86 | RP->difficulty_given = 1; |
79 | |
87 | |
80 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
88 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
81 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 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 + RANDOM () % 25 + 5; |
92 | RP->Ysize = MIN_RANDOM_MAP_SIZE + rndm (25) + 5; |
85 | |
|
|
86 | if (RP->expand2x > 0) |
|
|
87 | { |
|
|
88 | RP->Xsize /= 2; |
|
|
89 | RP->Ysize /= 2; |
|
|
90 | } |
|
|
91 | |
|
|
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, RANDOM () % 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 | |
93 | |
189 | if (RP->symmetry == SYMMETRY_RANDOM) |
94 | if (RP->symmetry == SYMMETRY_RANDOM) |
190 | RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; |
95 | RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; |
191 | else |
96 | else |
192 | RP->symmetry_used = RP->symmetry; |
97 | RP->symmetry_used = RP->symmetry; |
193 | |
98 | |
194 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
99 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
195 | RP->Ysize = RP->Ysize / 2 + 1; |
100 | RP->Ysize = RP->Ysize / 2 + 1; |
|
|
101 | |
196 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
102 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
197 | RP->Xsize = RP->Xsize / 2 + 1; |
103 | RP->Xsize = RP->Xsize / 2 + 1; |
198 | |
104 | |
199 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
105 | if (RP->expand2x > 0) |
200 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
106 | { |
201 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
107 | RP->Xsize /= 2; |
202 | RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
108 | RP->Ysize /= 2; |
|
|
109 | } |
|
|
110 | |
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 = (RANDOM () % (NROFLAYOUTS - 1)) + 1; |
231 | |
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 | 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; |
|
|
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); |
236 | if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
243 | if (!(rndm (3)) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
237 | roomify_layout (maze, RP); |
244 | roomify_layout (maze, RP); |
238 | break; |
245 | break; |
239 | |
246 | |
240 | case LAYOUT_MAZE: |
247 | case LAYOUT_MAZE: |
241 | maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); |
248 | maze = maze_gen (RP->Xsize, RP->Ysize, rndm (2)); |
242 | if (!(RANDOM () % 2)) |
249 | if (!(rndm (2))) |
243 | doorify_layout (maze, RP); |
250 | doorify_layout (maze, RP); |
244 | break; |
251 | break; |
245 | |
252 | |
246 | case LAYOUT_SPIRAL: |
253 | case LAYOUT_SPIRAL: |
247 | maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
254 | maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
248 | if (!(RANDOM () % 2)) |
255 | if (!(rndm (2))) |
249 | doorify_layout (maze, RP); |
256 | doorify_layout (maze, RP); |
250 | break; |
257 | break; |
251 | |
258 | |
252 | case LAYOUT_ROGUELIKE: |
259 | case LAYOUT_ROGUELIKE: |
253 | /* Don't put symmetry in rogue maps. There isn't much reason to |
260 | /* Don't put symmetry in rogue maps. There isn't much reason to |
… | |
… | |
264 | /* no doorifying... done already */ |
271 | /* no doorifying... done already */ |
265 | break; |
272 | break; |
266 | |
273 | |
267 | case LAYOUT_SNAKE: |
274 | case LAYOUT_SNAKE: |
268 | maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
275 | maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
269 | if (RANDOM () % 2) |
276 | if (rndm (2)) |
270 | roomify_layout (maze, RP); |
277 | roomify_layout (maze, RP); |
271 | break; |
278 | break; |
272 | |
279 | |
273 | case LAYOUT_SQUARE_SPIRAL: |
280 | case LAYOUT_SQUARE_SPIRAL: |
274 | maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
281 | maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
275 | if (RANDOM () % 2) |
282 | if (rndm (2)) |
276 | roomify_layout (maze, RP); |
283 | roomify_layout (maze, RP); |
277 | break; |
284 | break; |
278 | } |
285 | } |
279 | |
286 | |
280 | maze = symmetrize_layout (maze, RP->symmetry_used, RP); |
287 | maze = symmetrize_layout (maze, RP->symmetry_used, RP); |
… | |
… | |
637 | void |
644 | void |
638 | write_map_parameters_to_string (char *buf, random_map_params *RP) |
645 | write_map_parameters_to_string (char *buf, random_map_params *RP) |
639 | { |
646 | { |
640 | char small_buf[16384]; |
647 | char small_buf[16384]; |
641 | |
648 | |
642 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
649 | sprintf (buf, "xsize %d\nysize %d\n", RP->xsize, RP->ysize); |
643 | |
650 | |
644 | if (RP->wallstyle[0]) |
651 | if (RP->wallstyle[0]) |
645 | { |
652 | { |
646 | sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
653 | sprintf (small_buf, "wallstyle %s\n", RP->wallstyle); |
647 | strcat (buf, small_buf); |
654 | strcat (buf, small_buf); |
… | |
… | |
788 | strcat (buf, small_buf); |
795 | strcat (buf, small_buf); |
789 | } |
796 | } |
790 | |
797 | |
791 | if (RP->random_seed) |
798 | if (RP->random_seed) |
792 | { |
799 | { |
793 | sprintf (small_buf, "random_seed %d\n", RP->random_seed); |
800 | sprintf (small_buf, "random_seed %u\n", RP->random_seed); |
794 | strcat (buf, small_buf); |
801 | strcat (buf, small_buf); |
795 | } |
802 | } |
796 | |
803 | |
797 | if (RP->custom) |
804 | if (RP->custom) |
798 | { |
805 | { |
… | |
… | |
824 | int dungeon_level_n, |
831 | int dungeon_level_n, |
825 | int difficulty_n, |
832 | int difficulty_n, |
826 | int difficulty_given_n, |
833 | int difficulty_given_n, |
827 | int decoroptions_n, |
834 | int decoroptions_n, |
828 | int orientation_n, |
835 | int orientation_n, |
829 | int origin_x_n, int origin_y_n, int random_seed_n, int treasureoptions_n, float difficulty_increase) |
836 | int origin_x_n, int origin_y_n, uint32_t random_seed_n, int treasureoptions_n, float difficulty_increase) |
830 | { |
837 | { |
831 | char small_buf[16384]; |
838 | char small_buf[16384]; |
832 | |
839 | |
833 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
840 | sprintf (buf, "xsize %d\nysize %d\n", xsize_n, ysize_n); |
834 | |
841 | |
… | |
… | |
970 | } |
977 | } |
971 | |
978 | |
972 | if (random_seed_n) |
979 | if (random_seed_n) |
973 | { |
980 | { |
974 | /* Add one so that the next map is a bit different */ |
981 | /* Add one so that the next map is a bit different */ |
975 | sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); |
982 | sprintf (small_buf, "random_seed %u\n", random_seed_n + 1); |
976 | strcat (buf, small_buf); |
983 | strcat (buf, small_buf); |
977 | } |
984 | } |
978 | |
985 | |
979 | if (treasureoptions_n) |
986 | if (treasureoptions_n) |
980 | { |
987 | { |