… | |
… | |
29 | #include <random_map.h> |
29 | #include <random_map.h> |
30 | #include <rproto.h> |
30 | #include <rproto.h> |
31 | #include <sproto.h> |
31 | #include <sproto.h> |
32 | |
32 | |
33 | void |
33 | void |
34 | dump_layout (char **layout, RMParms * RP) |
34 | dump_layout (char **layout, random_map_params * RP) |
35 | { |
35 | { |
36 | { |
36 | { |
37 | int i, j; |
37 | int i, j; |
38 | |
38 | |
39 | for (i = 0; i < RP->Xsize; i++) |
39 | for (i = 0; i < RP->Xsize; i++) |
… | |
… | |
49 | printf ("\n"); |
49 | printf ("\n"); |
50 | } |
50 | } |
51 | } |
51 | } |
52 | printf ("\n"); |
52 | printf ("\n"); |
53 | } |
53 | } |
54 | EXTERN FILE *logfile; |
54 | |
|
|
55 | extern FILE *logfile; |
|
|
56 | |
55 | maptile * |
57 | maptile * |
56 | generate_random_map (const char *OutFileName, RMParms * RP) |
58 | generate_random_map (const char *OutFileName, random_map_params * RP) |
57 | { |
59 | { |
58 | char **layout, buf[HUGE_BUF]; |
60 | char **layout, buf[HUGE_BUF]; |
59 | maptile *theMap; |
61 | maptile *theMap; |
60 | int i; |
62 | int i; |
61 | |
63 | |
… | |
… | |
68 | write_map_parameters_to_string (buf, RP); |
70 | write_map_parameters_to_string (buf, RP); |
69 | |
71 | |
70 | if (RP->difficulty == 0) |
72 | if (RP->difficulty == 0) |
71 | { |
73 | { |
72 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
74 | RP->difficulty = RP->dungeon_level; /* use this instead of a map difficulty */ |
|
|
75 | |
73 | if (RP->difficulty_increase > 0.001) |
76 | if (RP->difficulty_increase > 0.001) |
74 | { |
|
|
75 | RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
77 | RP->difficulty = (int) ((float) RP->dungeon_level * RP->difficulty_increase); |
|
|
78 | |
76 | if (RP->difficulty < 1) |
79 | if (RP->difficulty < 1) |
77 | RP->difficulty = 1; |
80 | RP->difficulty = 1; |
78 | } |
|
|
79 | } |
81 | } |
80 | else |
82 | else |
81 | RP->difficulty_given = 1; |
83 | RP->difficulty_given = 1; |
82 | |
84 | |
83 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
85 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
84 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
86 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
|
|
87 | |
85 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
88 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
86 | RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
89 | RP->Ysize = MIN_RANDOM_MAP_SIZE + RANDOM () % 25 + 5; |
87 | |
90 | |
88 | if (RP->expand2x > 0) |
91 | if (RP->expand2x > 0) |
89 | { |
92 | { |
… | |
… | |
110 | |
113 | |
111 | /* allocate the map and set the floor */ |
114 | /* allocate the map and set the floor */ |
112 | theMap = make_map_floor (layout, RP->floorstyle, RP); |
115 | theMap = make_map_floor (layout, RP->floorstyle, RP); |
113 | |
116 | |
114 | /* set the name of the map. */ |
117 | /* set the name of the map. */ |
115 | strcpy (theMap->path, OutFileName); |
118 | theMap->path = OutFileName; |
116 | |
119 | |
117 | /* set region */ |
120 | /* set region */ |
118 | theMap->region = RP->region; |
121 | theMap->region = RP->region; |
119 | |
122 | |
120 | /* create walls unless the wallstyle is "none" */ |
123 | /* create walls unless the wallstyle is "none" */ |
… | |
… | |
137 | /* create monsters unless the monsterstyle is "none" */ |
140 | /* create monsters unless the monsterstyle is "none" */ |
138 | if (strcmp (RP->monsterstyle, "none")) |
141 | if (strcmp (RP->monsterstyle, "none")) |
139 | place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); |
142 | place_monsters (theMap, RP->monsterstyle, RP->difficulty, RP); |
140 | |
143 | |
141 | /* treasures needs to have a proper difficulty set for the map. */ |
144 | /* treasures needs to have a proper difficulty set for the map. */ |
142 | theMap->difficulty = calculate_difficulty (theMap); |
145 | theMap->difficulty = theMap->estimate_difficulty (); |
143 | |
146 | |
144 | /* create treasure unless the treasurestyle is "none" */ |
147 | /* create treasure unless the treasurestyle is "none" */ |
145 | if (strcmp (RP->treasurestyle, "none")) |
148 | if (strcmp (RP->treasurestyle, "none")) |
146 | place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); |
149 | place_treasure (theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); |
147 | |
150 | |
148 | /* create decor unless the decorstyle is "none" */ |
151 | /* create decor unless the decorstyle is "none" */ |
149 | if (strcmp (RP->decorstyle, "none")) |
152 | if (strcmp (RP->decorstyle, "none")) |
150 | put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); |
153 | put_decor (theMap, layout, RP->decorstyle, RP->decoroptions, RP); |
151 | |
154 | |
152 | /* generate treasures, etc. */ |
155 | /* generate treasures, etc. */ |
153 | fix_auto_apply (theMap); |
156 | theMap->fix_auto_apply (); |
154 | |
157 | |
155 | unblock_exits (theMap, layout, RP); |
158 | unblock_exits (theMap, layout, RP); |
156 | |
159 | |
157 | /* free the layout */ |
160 | /* free the layout */ |
158 | for (i = 0; i < RP->Xsize; i++) |
161 | for (i = 0; i < RP->Xsize; i++) |
159 | free (layout[i]); |
162 | free (layout[i]); |
|
|
163 | |
160 | free (layout); |
164 | free (layout); |
161 | |
165 | |
162 | theMap->msg = strdup_local (buf); |
166 | theMap->msg = strdup (buf); |
|
|
167 | theMap->in_memory = MAP_IN_MEMORY; |
163 | |
168 | |
164 | return theMap; |
169 | return theMap; |
165 | } |
170 | } |
166 | |
|
|
167 | |
171 | |
168 | /* function selects the layout function and gives it whatever |
172 | /* function selects the layout function and gives it whatever |
169 | arguments it needs. */ |
173 | arguments it needs. */ |
170 | char ** |
174 | char ** |
171 | layoutgen (RMParms * RP) |
175 | layoutgen (random_map_params * RP) |
172 | { |
176 | { |
173 | char **maze = 0; |
177 | char **maze = 0; |
174 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
178 | int oxsize = RP->Xsize, oysize = RP->Ysize; |
175 | |
179 | |
176 | if (RP->symmetry == RANDOM_SYM) |
180 | if (RP->symmetry == SYMMETRY_RANDOM) |
177 | RP->symmetry_used = (RANDOM () % (XY_SYM)) + 1; |
181 | RP->symmetry_used = (RANDOM () % (SYMMETRY_XY)) + 1; |
178 | else |
182 | else |
179 | RP->symmetry_used = RP->symmetry; |
183 | RP->symmetry_used = RP->symmetry; |
180 | |
184 | |
181 | if (RP->symmetry_used == Y_SYM || RP->symmetry_used == XY_SYM) |
185 | if (RP->symmetry_used == SYMMETRY_Y || RP->symmetry_used == SYMMETRY_XY) |
182 | RP->Ysize = RP->Ysize / 2 + 1; |
186 | RP->Ysize = RP->Ysize / 2 + 1; |
183 | if (RP->symmetry_used == X_SYM || RP->symmetry_used == XY_SYM) |
187 | if (RP->symmetry_used == SYMMETRY_X || RP->symmetry_used == SYMMETRY_XY) |
184 | RP->Xsize = RP->Xsize / 2 + 1; |
188 | RP->Xsize = RP->Xsize / 2 + 1; |
185 | |
189 | |
186 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
190 | if (RP->Xsize < MIN_RANDOM_MAP_SIZE) |
187 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
191 | RP->Xsize = MIN_RANDOM_MAP_SIZE + RANDOM () % 5; |
188 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
192 | if (RP->Ysize < MIN_RANDOM_MAP_SIZE) |
… | |
… | |
193 | * layout style and then random layout style. Instead, figure out |
197 | * layout style and then random layout style. Instead, figure out |
194 | * the numeric layoutstyle, so there is only one area that actually |
198 | * the numeric layoutstyle, so there is only one area that actually |
195 | * calls the code to make the maps. |
199 | * calls the code to make the maps. |
196 | */ |
200 | */ |
197 | if (strstr (RP->layoutstyle, "onion")) |
201 | if (strstr (RP->layoutstyle, "onion")) |
198 | { |
|
|
199 | RP->map_layout_style = ONION_LAYOUT; |
202 | RP->map_layout_style = LAYOUT_ONION; |
200 | } |
|
|
201 | |
203 | |
202 | if (strstr (RP->layoutstyle, "maze")) |
204 | if (strstr (RP->layoutstyle, "maze")) |
203 | { |
|
|
204 | RP->map_layout_style = MAZE_LAYOUT; |
205 | RP->map_layout_style = LAYOUT_MAZE; |
205 | } |
|
|
206 | |
206 | |
207 | if (strstr (RP->layoutstyle, "spiral")) |
207 | if (strstr (RP->layoutstyle, "spiral")) |
208 | { |
|
|
209 | RP->map_layout_style = SPIRAL_LAYOUT; |
208 | RP->map_layout_style = LAYOUT_SPIRAL; |
210 | } |
|
|
211 | |
209 | |
212 | if (strstr (RP->layoutstyle, "rogue")) |
210 | if (strstr (RP->layoutstyle, "rogue")) |
213 | { |
|
|
214 | RP->map_layout_style = ROGUELIKE_LAYOUT; |
211 | RP->map_layout_style = LAYOUT_ROGUELIKE; |
215 | } |
|
|
216 | |
212 | |
217 | if (strstr (RP->layoutstyle, "snake")) |
213 | if (strstr (RP->layoutstyle, "snake")) |
218 | { |
|
|
219 | RP->map_layout_style = SNAKE_LAYOUT; |
214 | RP->map_layout_style = LAYOUT_SNAKE; |
220 | } |
|
|
221 | |
215 | |
222 | if (strstr (RP->layoutstyle, "squarespiral")) |
216 | if (strstr (RP->layoutstyle, "squarespiral")) |
223 | { |
|
|
224 | RP->map_layout_style = SQUARE_SPIRAL_LAYOUT; |
217 | RP->map_layout_style = LAYOUT_SQUARE_SPIRAL; |
225 | } |
218 | |
226 | /* No style found - choose one ranomdly */ |
219 | /* No style found - choose one ranomdly */ |
227 | if (RP->map_layout_style == 0) |
220 | if (RP->map_layout_style == LAYOUT_NONE) |
228 | { |
|
|
229 | RP->map_layout_style = (RANDOM () % NROFLAYOUTS) + 1; |
221 | RP->map_layout_style = (RANDOM () % (NROFLAYOUTS - 1)) + 1; |
230 | } |
|
|
231 | |
222 | |
232 | switch (RP->map_layout_style) |
223 | switch (RP->map_layout_style) |
233 | { |
224 | { |
234 | |
225 | case LAYOUT_ONION: |
235 | case ONION_LAYOUT: |
|
|
236 | maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
226 | maze = map_gen_onion (RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
237 | if (!(RANDOM () % 3) && !(RP->layoutoptions1 & OPT_WALLS_ONLY)) |
227 | if (!(RANDOM () % 3) && !(RP->layoutoptions1 & RMOPT_WALLS_ONLY)) |
238 | roomify_layout (maze, RP); |
228 | roomify_layout (maze, RP); |
239 | break; |
229 | break; |
240 | |
230 | |
241 | case MAZE_LAYOUT: |
231 | case LAYOUT_MAZE: |
242 | maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); |
232 | maze = maze_gen (RP->Xsize, RP->Ysize, RANDOM () % 2); |
243 | if (!(RANDOM () % 2)) |
233 | if (!(RANDOM () % 2)) |
244 | doorify_layout (maze, RP); |
234 | doorify_layout (maze, RP); |
245 | break; |
235 | break; |
246 | |
236 | |
247 | case SPIRAL_LAYOUT: |
237 | case LAYOUT_SPIRAL: |
248 | maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
238 | maze = map_gen_spiral (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
249 | if (!(RANDOM () % 2)) |
239 | if (!(RANDOM () % 2)) |
250 | doorify_layout (maze, RP); |
240 | doorify_layout (maze, RP); |
251 | break; |
241 | break; |
252 | |
242 | |
253 | case ROGUELIKE_LAYOUT: |
243 | case LAYOUT_ROGUELIKE: |
254 | /* Don't put symmetry in rogue maps. There isn't much reason to |
244 | /* Don't put symmetry in rogue maps. There isn't much reason to |
255 | * do so in the first place (doesn't make it any more interesting), |
245 | * do so in the first place (doesn't make it any more interesting), |
256 | * but more importantly, the symmetry code presumes we are symmetrizing |
246 | * but more importantly, the symmetry code presumes we are symmetrizing |
257 | * spirals, or maps with lots of passages - making a symmetric rogue |
247 | * spirals, or maps with lots of passages - making a symmetric rogue |
258 | * map fails because its likely that the passages the symmetry process |
248 | * map fails because its likely that the passages the symmetry process |
259 | * creates may not connect the rooms. |
249 | * creates may not connect the rooms. |
260 | */ |
250 | */ |
261 | RP->symmetry_used = NO_SYM; |
251 | RP->symmetry_used = SYMMETRY_NONE; |
262 | RP->Ysize = oysize; |
252 | RP->Ysize = oysize; |
263 | RP->Xsize = oxsize; |
253 | RP->Xsize = oxsize; |
264 | maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
254 | maze = roguelike_layout_gen (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
265 | /* no doorifying... done already */ |
255 | /* no doorifying... done already */ |
266 | break; |
256 | break; |
267 | |
257 | |
268 | case SNAKE_LAYOUT: |
258 | case LAYOUT_SNAKE: |
269 | maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
259 | maze = make_snake_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
270 | if (RANDOM () % 2) |
260 | if (RANDOM () % 2) |
271 | roomify_layout (maze, RP); |
261 | roomify_layout (maze, RP); |
272 | break; |
262 | break; |
273 | |
263 | |
274 | case SQUARE_SPIRAL_LAYOUT: |
264 | case LAYOUT_SQUARE_SPIRAL: |
275 | maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
265 | maze = make_square_spiral_layout (RP->Xsize, RP->Ysize, RP->layoutoptions1); |
276 | if (RANDOM () % 2) |
266 | if (RANDOM () % 2) |
277 | roomify_layout (maze, RP); |
267 | roomify_layout (maze, RP); |
278 | break; |
268 | break; |
279 | } |
269 | } |
280 | |
270 | |
281 | maze = symmetrize_layout (maze, RP->symmetry_used, RP); |
271 | maze = symmetrize_layout (maze, RP->symmetry_used, RP); |
|
|
272 | |
282 | #ifdef RMAP_DEBUG |
273 | #ifdef RMAP_DEBUG |
283 | dump_layout (maze, RP); |
274 | dump_layout (maze, RP); |
284 | #endif |
275 | #endif |
|
|
276 | |
285 | if (RP->expand2x) |
277 | if (RP->expand2x) |
286 | { |
278 | { |
287 | maze = expand2x (maze, RP->Xsize, RP->Ysize); |
279 | maze = expand2x (maze, RP->Xsize, RP->Ysize); |
288 | RP->Xsize = RP->Xsize * 2 - 1; |
280 | RP->Xsize = RP->Xsize * 2 - 1; |
289 | RP->Ysize = RP->Ysize * 2 - 1; |
281 | RP->Ysize = RP->Ysize * 2 - 1; |
290 | } |
282 | } |
|
|
283 | |
291 | return maze; |
284 | return maze; |
292 | } |
285 | } |
293 | |
|
|
294 | |
286 | |
295 | /* takes a map and makes it symmetric: adjusts Xsize and |
287 | /* takes a map and makes it symmetric: adjusts Xsize and |
296 | Ysize to produce a symmetric map. */ |
288 | Ysize to produce a symmetric map. */ |
297 | |
|
|
298 | char ** |
289 | char ** |
299 | symmetrize_layout (char **maze, int sym, RMParms * RP) |
290 | symmetrize_layout (char **maze, int sym, random_map_params * RP) |
300 | { |
291 | { |
301 | int i, j; |
292 | int i, j; |
302 | char **sym_maze; |
293 | char **sym_maze; |
303 | int Xsize_orig, Ysize_orig; |
294 | int Xsize_orig, Ysize_orig; |
304 | |
295 | |
305 | Xsize_orig = RP->Xsize; |
296 | Xsize_orig = RP->Xsize; |
306 | Ysize_orig = RP->Ysize; |
297 | Ysize_orig = RP->Ysize; |
307 | RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */ |
298 | RP->symmetry_used = sym; /* tell everyone else what sort of symmetry is used. */ |
308 | if (sym == NO_SYM) |
299 | if (sym == SYMMETRY_NONE) |
309 | { |
300 | { |
310 | RP->Xsize = Xsize_orig; |
301 | RP->Xsize = Xsize_orig; |
311 | RP->Ysize = Ysize_orig; |
302 | RP->Ysize = Ysize_orig; |
312 | return maze; |
303 | return maze; |
313 | } |
304 | } |
314 | /* pick new sizes */ |
305 | /* pick new sizes */ |
315 | RP->Xsize = ((sym == X_SYM || sym == XY_SYM) ? RP->Xsize * 2 - 3 : RP->Xsize); |
306 | RP->Xsize = ((sym == SYMMETRY_X || sym == SYMMETRY_XY) ? RP->Xsize * 2 - 3 : RP->Xsize); |
316 | RP->Ysize = ((sym == Y_SYM || sym == XY_SYM) ? RP->Ysize * 2 - 3 : RP->Ysize); |
307 | RP->Ysize = ((sym == SYMMETRY_Y || sym == SYMMETRY_XY) ? RP->Ysize * 2 - 3 : RP->Ysize); |
317 | |
308 | |
318 | sym_maze = (char **) calloc (sizeof (char *), RP->Xsize); |
309 | sym_maze = (char **) calloc (sizeof (char *), RP->Xsize); |
319 | for (i = 0; i < RP->Xsize; i++) |
310 | for (i = 0; i < RP->Xsize; i++) |
320 | sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize); |
311 | sym_maze[i] = (char *) calloc (sizeof (char), RP->Ysize); |
321 | |
312 | |
322 | if (sym == X_SYM) |
313 | if (sym == SYMMETRY_X) |
323 | for (i = 0; i < RP->Xsize / 2 + 1; i++) |
314 | for (i = 0; i < RP->Xsize / 2 + 1; i++) |
324 | for (j = 0; j < RP->Ysize; j++) |
315 | for (j = 0; j < RP->Ysize; j++) |
325 | { |
316 | { |
326 | sym_maze[i][j] = maze[i][j]; |
317 | sym_maze[i][j] = maze[i][j]; |
327 | sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; |
318 | sym_maze[RP->Xsize - i - 1][j] = maze[i][j]; |
328 | }; |
319 | }; |
329 | if (sym == Y_SYM) |
320 | if (sym == SYMMETRY_Y) |
330 | for (i = 0; i < RP->Xsize; i++) |
321 | for (i = 0; i < RP->Xsize; i++) |
331 | for (j = 0; j < RP->Ysize / 2 + 1; j++) |
322 | for (j = 0; j < RP->Ysize / 2 + 1; j++) |
332 | { |
323 | { |
333 | sym_maze[i][j] = maze[i][j]; |
324 | sym_maze[i][j] = maze[i][j]; |
334 | sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; |
325 | sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; |
335 | } |
326 | } |
336 | if (sym == XY_SYM) |
327 | if (sym == SYMMETRY_XY) |
337 | for (i = 0; i < RP->Xsize / 2 + 1; i++) |
328 | for (i = 0; i < RP->Xsize / 2 + 1; i++) |
338 | for (j = 0; j < RP->Ysize / 2 + 1; j++) |
329 | for (j = 0; j < RP->Ysize / 2 + 1; j++) |
339 | { |
330 | { |
340 | sym_maze[i][j] = maze[i][j]; |
331 | sym_maze[i][j] = maze[i][j]; |
341 | sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; |
332 | sym_maze[i][RP->Ysize - j - 1] = maze[i][j]; |
… | |
… | |
345 | /* delete the old maze */ |
336 | /* delete the old maze */ |
346 | for (i = 0; i < Xsize_orig; i++) |
337 | for (i = 0; i < Xsize_orig; i++) |
347 | free (maze[i]); |
338 | free (maze[i]); |
348 | free (maze); |
339 | free (maze); |
349 | /* reconnect disjointed spirals */ |
340 | /* reconnect disjointed spirals */ |
350 | if (RP->map_layout_style == SPIRAL_LAYOUT) |
341 | if (RP->map_layout_style == LAYOUT_SPIRAL) |
351 | connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); |
342 | connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); |
352 | /* reconnect disjointed nethackmazes: the routine for |
343 | /* reconnect disjointed nethackmazes: the routine for |
353 | spirals will do the trick? */ |
344 | spirals will do the trick? */ |
354 | if (RP->map_layout_style == ROGUELIKE_LAYOUT) |
345 | if (RP->map_layout_style == LAYOUT_ROGUELIKE) |
355 | connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); |
346 | connect_spirals (RP->Xsize, RP->Ysize, sym, sym_maze); |
356 | |
347 | |
357 | return sym_maze; |
348 | return sym_maze; |
358 | } |
349 | } |
359 | |
350 | |
… | |
… | |
362 | onion layouts, making them possibly centered on any wall. |
353 | onion layouts, making them possibly centered on any wall. |
363 | It'll modify Xsize and Ysize if they're swapped. |
354 | It'll modify Xsize and Ysize if they're swapped. |
364 | */ |
355 | */ |
365 | |
356 | |
366 | char ** |
357 | char ** |
367 | rotate_layout (char **maze, int rotation, RMParms * RP) |
358 | rotate_layout (char **maze, int rotation, random_map_params * RP) |
368 | { |
359 | { |
369 | char **new_maze; |
360 | char **new_maze; |
370 | int i, j; |
361 | int i, j; |
371 | |
362 | |
372 | switch (rotation) |
363 | switch (rotation) |
373 | { |
364 | { |
374 | case 0: |
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); |
375 | return maze; |
387 | return maze; |
376 | break; |
388 | break; |
377 | case 2: /* a reflection */ |
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++) |
378 | { |
396 | { |
379 | char *newmaze = (char *) malloc (sizeof (char) * RP->Xsize * RP->Ysize); |
397 | new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); |
380 | |
398 | } |
|
|
399 | if (rotation == 1) /* swap x and y */ |
381 | for (i = 0; i < RP->Xsize; i++) |
400 | for (i = 0; i < RP->Xsize; i++) |
382 | { /* make a copy */ |
|
|
383 | for (j = 0; j < RP->Ysize; j++) |
401 | for (j = 0; j < RP->Ysize; j++) |
384 | { |
|
|
385 | newmaze[i * RP->Ysize + j] = maze[i][j]; |
402 | new_maze[j][i] = maze[i][j]; |
386 | } |
403 | |
387 | } |
404 | if (rotation == 3) |
388 | for (i = 0; i < RP->Xsize; i++) |
405 | { /* swap x and y */ |
389 | { /* copy a reflection back */ |
|
|
390 | for (j = 0; j < RP->Ysize; j++) |
|
|
391 | { |
|
|
392 | maze[i][j] = newmaze[(RP->Xsize - i - 1) * RP->Ysize + RP->Ysize - j - 1]; |
|
|
393 | } |
|
|
394 | } |
|
|
395 | free (newmaze); |
|
|
396 | return maze; |
|
|
397 | break; |
|
|
398 | } |
|
|
399 | case 1: |
|
|
400 | case 3: |
|
|
401 | { |
|
|
402 | int swap; |
|
|
403 | new_maze = (char **) calloc (sizeof (char *), RP->Ysize); |
|
|
404 | for (i = 0; i < RP->Ysize; i++) |
|
|
405 | { |
|
|
406 | new_maze[i] = (char *) calloc (sizeof (char), RP->Xsize); |
|
|
407 | } |
|
|
408 | if (rotation == 1) /* swap x and y */ |
|
|
409 | for (i = 0; i < RP->Xsize; i++) |
406 | for (i = 0; i < RP->Xsize; i++) |
410 | for (j = 0; j < RP->Ysize; j++) |
407 | for (j = 0; j < RP->Ysize; j++) |
411 | new_maze[j][i] = maze[i][j]; |
|
|
412 | |
|
|
413 | if (rotation == 3) |
|
|
414 | { /* swap x and y */ |
|
|
415 | for (i = 0; i < RP->Xsize; i++) |
|
|
416 | for (j = 0; j < RP->Ysize; j++) |
|
|
417 | new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; |
408 | new_maze[j][i] = maze[RP->Xsize - i - 1][RP->Ysize - j - 1]; |
418 | } |
409 | } |
419 | |
410 | |
420 | /* delete the old layout */ |
411 | /* delete the old layout */ |
421 | for (i = 0; i < RP->Xsize; i++) |
412 | for (i = 0; i < RP->Xsize; i++) |
422 | free (maze[i]); |
413 | free (maze[i]); |
423 | free (maze); |
414 | free (maze); |
424 | |
415 | |
425 | swap = RP->Ysize; |
416 | swap = RP->Ysize; |
426 | RP->Ysize = RP->Xsize; |
417 | RP->Ysize = RP->Xsize; |
427 | RP->Xsize = swap; |
418 | RP->Xsize = swap; |
428 | return new_maze; |
419 | return new_maze; |
429 | break; |
420 | break; |
430 | } |
421 | } |
431 | } |
422 | } |
432 | return NULL; |
423 | return NULL; |
433 | } |
424 | } |
434 | |
425 | |
435 | /* take a layout and make some rooms in it. |
426 | /* take a layout and make some rooms in it. |
436 | --works best on onions.*/ |
427 | --works best on onions.*/ |
437 | void |
428 | void |
438 | roomify_layout (char **maze, RMParms * RP) |
429 | roomify_layout (char **maze, random_map_params * RP) |
439 | { |
430 | { |
440 | int tries = RP->Xsize * RP->Ysize / 30; |
431 | int tries = RP->Xsize * RP->Ysize / 30; |
441 | int ti; |
432 | int ti; |
442 | |
433 | |
443 | for (ti = 0; ti < tries; ti++) |
434 | for (ti = 0; ti < tries; ti++) |
… | |
… | |
470 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
461 | /* checks the layout to see if I can stick a horizontal(dir = 0) wall |
471 | (or vertical, dir == 1) |
462 | (or vertical, dir == 1) |
472 | here which ends up on other walls sensibly. */ |
463 | here which ends up on other walls sensibly. */ |
473 | |
464 | |
474 | int |
465 | int |
475 | can_make_wall (char **maze, int dx, int dy, int dir, RMParms * RP) |
466 | can_make_wall (char **maze, int dx, int dy, int dir, random_map_params * RP) |
476 | { |
467 | { |
477 | int i1; |
468 | int i1; |
478 | int length = 0; |
469 | int length = 0; |
479 | |
470 | |
480 | /* dont make walls if we're on the edge. */ |
471 | /* dont make walls if we're on the edge. */ |
… | |
… | |
581 | |
572 | |
582 | return 0; |
573 | return 0; |
583 | } |
574 | } |
584 | |
575 | |
585 | /* puts doors at appropriate locations in a layout. */ |
576 | /* puts doors at appropriate locations in a layout. */ |
586 | |
|
|
587 | void |
577 | void |
588 | doorify_layout (char **maze, RMParms * RP) |
578 | doorify_layout (char **maze, random_map_params * RP) |
589 | { |
579 | { |
590 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
580 | int ndoors = RP->Xsize * RP->Ysize / 60; /* reasonable number of doors. */ |
591 | char *doorlist_x; |
581 | char *doorlist_x; |
592 | char *doorlist_y; |
582 | char *doorlist_y; |
593 | int doorlocs = 0; /* # of available doorlocations */ |
583 | int doorlocs = 0; /* # of available doorlocations */ |
… | |
… | |
608 | doorlist_x[doorlocs] = i; |
598 | doorlist_x[doorlocs] = i; |
609 | doorlist_y[doorlocs] = j; |
599 | doorlist_y[doorlocs] = j; |
610 | doorlocs++; |
600 | doorlocs++; |
611 | } |
601 | } |
612 | } |
602 | } |
|
|
603 | |
613 | while (ndoors > 0 && doorlocs > 0) |
604 | while (ndoors > 0 && doorlocs > 0) |
614 | { |
605 | { |
615 | int di; |
606 | int di; |
616 | int sindex; |
607 | int sindex; |
617 | |
608 | |
… | |
… | |
627 | /* reduce the size of the list */ |
618 | /* reduce the size of the list */ |
628 | doorlocs--; |
619 | doorlocs--; |
629 | doorlist_x[di] = doorlist_x[doorlocs]; |
620 | doorlist_x[di] = doorlist_x[doorlocs]; |
630 | doorlist_y[di] = doorlist_y[doorlocs]; |
621 | doorlist_y[di] = doorlist_y[doorlocs]; |
631 | } |
622 | } |
|
|
623 | |
632 | free (doorlist_x); |
624 | free (doorlist_x); |
633 | free (doorlist_y); |
625 | free (doorlist_y); |
634 | } |
626 | } |
635 | |
627 | |
636 | |
|
|
637 | void |
628 | void |
638 | write_map_parameters_to_string (char *buf, RMParms * RP) |
629 | write_map_parameters_to_string (char *buf, random_map_params * RP) |
639 | { |
630 | { |
640 | |
|
|
641 | char small_buf[256]; |
631 | char small_buf[256]; |
642 | |
632 | |
643 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
633 | sprintf (buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
644 | |
634 | |
645 | if (RP->wallstyle[0]) |
635 | if (RP->wallstyle[0]) |
… | |
… | |
783 | if (RP->origin_y) |
773 | if (RP->origin_y) |
784 | { |
774 | { |
785 | sprintf (small_buf, "origin_y %d\n", RP->origin_y); |
775 | sprintf (small_buf, "origin_y %d\n", RP->origin_y); |
786 | strcat (buf, small_buf); |
776 | strcat (buf, small_buf); |
787 | } |
777 | } |
|
|
778 | |
788 | if (RP->random_seed) |
779 | if (RP->random_seed) |
789 | { |
780 | { |
790 | /* Add one so that the next map is a bit different */ |
781 | /* Add one so that the next map is a bit different */ |
791 | sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); |
782 | sprintf (small_buf, "random_seed %d\n", RP->random_seed + 1); |
792 | strcat (buf, small_buf); |
783 | strcat (buf, small_buf); |
… | |
… | |
795 | if (RP->treasureoptions) |
786 | if (RP->treasureoptions) |
796 | { |
787 | { |
797 | sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); |
788 | sprintf (small_buf, "treasureoptions %d\n", RP->treasureoptions); |
798 | strcat (buf, small_buf); |
789 | strcat (buf, small_buf); |
799 | } |
790 | } |
800 | |
|
|
801 | |
|
|
802 | } |
791 | } |
803 | |
792 | |
804 | void |
793 | void |
805 | write_parameters_to_string (char *buf, |
794 | write_parameters_to_string (char *buf, |
806 | int xsize_n, |
795 | int xsize_n, |
… | |
… | |
903 | { |
892 | { |
904 | sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); |
893 | sprintf (small_buf, "layoutoptions1 %d\n", layoutoptions1_n); |
905 | strcat (buf, small_buf); |
894 | strcat (buf, small_buf); |
906 | } |
895 | } |
907 | |
896 | |
908 | |
|
|
909 | if (layoutoptions2_n) |
897 | if (layoutoptions2_n) |
910 | { |
898 | { |
911 | sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); |
899 | sprintf (small_buf, "layoutoptions2 %d\n", layoutoptions2_n); |
912 | strcat (buf, small_buf); |
900 | strcat (buf, small_buf); |
913 | } |
901 | } |
… | |
… | |
968 | if (origin_y_n) |
956 | if (origin_y_n) |
969 | { |
957 | { |
970 | sprintf (small_buf, "origin_y %d\n", origin_y_n); |
958 | sprintf (small_buf, "origin_y %d\n", origin_y_n); |
971 | strcat (buf, small_buf); |
959 | strcat (buf, small_buf); |
972 | } |
960 | } |
|
|
961 | |
973 | if (random_seed_n) |
962 | if (random_seed_n) |
974 | { |
963 | { |
975 | /* Add one so that the next map is a bit different */ |
964 | /* Add one so that the next map is a bit different */ |
976 | sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); |
965 | sprintf (small_buf, "random_seed %d\n", random_seed_n + 1); |
977 | strcat (buf, small_buf); |
966 | strcat (buf, small_buf); |
… | |
… | |
990 | void |
979 | void |
991 | copy_object_with_inv (object *src_ob, object *dest_ob) |
980 | copy_object_with_inv (object *src_ob, object *dest_ob) |
992 | { |
981 | { |
993 | object *walk, *tmp; |
982 | object *walk, *tmp; |
994 | |
983 | |
995 | copy_object (src_ob, dest_ob); |
984 | src_ob->copy_to (dest_ob); |
996 | |
985 | |
997 | for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
986 | for (walk = src_ob->inv; walk != NULL; walk = walk->below) |
998 | { |
987 | { |
999 | tmp = get_object (); |
988 | tmp = object::create (); |
1000 | copy_object (walk, tmp); |
989 | walk->copy_to (tmp); |
1001 | insert_ob_in_ob (tmp, dest_ob); |
990 | insert_ob_in_ob (tmp, dest_ob); |
1002 | } |
991 | } |
1003 | } |
992 | } |