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.9 by root, Thu Dec 14 22:45:40 2006 UTC vs.
Revision 1.12 by root, Sun Dec 31 17:17:23 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines