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