| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "global.h" |
| 24 |
|
| 25 |
#include <stdio.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <string.h> |
| 28 |
#include <sys/time.h> |
| 29 |
#include <time.h> |
| 30 |
|
| 31 |
#include "maze_gen.h" |
| 32 |
#include "random_map.h" |
| 33 |
#include "room_gen.h" |
| 34 |
#include "rproto.h" |
| 35 |
#include "sproto.h" |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
void dump_layout(char **layout, RMParms *RP) |
| 45 |
{ |
| 46 |
int i, j; |
| 47 |
|
| 48 |
for (i = 0; i < RP->Xsize; i++) { |
| 49 |
for (j = 0; j < RP->Ysize; j++) { |
| 50 |
if (layout[i][j] == 0) { |
| 51 |
layout[i][j] = ' '; |
| 52 |
} |
| 53 |
printf("%c", layout[i][j]); |
| 54 |
if (layout[i][j] == ' ') { |
| 55 |
layout[i][j] = 0; |
| 56 |
} |
| 57 |
} |
| 58 |
printf("\n"); |
| 59 |
} |
| 60 |
printf("\n"); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
mapstruct *generate_random_map(const char *OutFileName, RMParms *RP, char **use_layout) |
| 75 |
{ |
| 76 |
char **layout, *buf; |
| 77 |
mapstruct *theMap; |
| 78 |
int i; |
| 79 |
|
| 80 |
|
| 81 |
if (RP->random_seed == 0) { |
| 82 |
RP->random_seed = time(NULL); |
| 83 |
} |
| 84 |
|
| 85 |
SRANDOM(RP->random_seed); |
| 86 |
|
| 87 |
buf = stringbuffer_finish(write_map_parameters_to_string(RP)); |
| 88 |
|
| 89 |
if (RP->difficulty == 0) { |
| 90 |
RP->difficulty = RP->dungeon_level; |
| 91 |
if (RP->difficulty_increase > 0.001) { |
| 92 |
RP->difficulty = (int)((float)RP->dungeon_level*RP->difficulty_increase); |
| 93 |
if (RP->difficulty < 1) { |
| 94 |
RP->difficulty = 1; |
| 95 |
} |
| 96 |
} |
| 97 |
} else { |
| 98 |
RP->difficulty_given = 1; |
| 99 |
} |
| 100 |
|
| 101 |
if (!use_layout) { |
| 102 |
if (RP->Xsize < MIN_RANDOM_MAP_SIZE) { |
| 103 |
RP->Xsize = MIN_RANDOM_MAP_SIZE+RANDOM()%25+5; |
| 104 |
} |
| 105 |
if (RP->Ysize < MIN_RANDOM_MAP_SIZE) { |
| 106 |
RP->Ysize = MIN_RANDOM_MAP_SIZE+RANDOM()%25+5; |
| 107 |
} |
| 108 |
|
| 109 |
if (RP->expand2x > 0) { |
| 110 |
RP->Xsize /= 2; |
| 111 |
RP->Ysize /= 2; |
| 112 |
} |
| 113 |
|
| 114 |
layout = layoutgen(RP); |
| 115 |
|
| 116 |
#ifdef RMAP_DEBUG |
| 117 |
dump_layout(layout, RP); |
| 118 |
#endif |
| 119 |
|
| 120 |
|
| 121 |
layout = rotate_layout(layout, RANDOM()%4, RP); |
| 122 |
#ifdef RMAP_DEBUG |
| 123 |
dump_layout(layout, RP); |
| 124 |
#endif |
| 125 |
} else { |
| 126 |
layout = use_layout; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
RP->dungeon_level += 1; |
| 131 |
|
| 132 |
|
| 133 |
theMap = make_map_floor(layout, RP->floorstyle, RP); |
| 134 |
|
| 135 |
|
| 136 |
safe_strncpy(theMap->path, OutFileName, sizeof(theMap->path)); |
| 137 |
|
| 138 |
|
| 139 |
theMap->region = RP->region; |
| 140 |
|
| 141 |
|
| 142 |
if (strcmp(RP->wallstyle, "none")) { |
| 143 |
make_map_walls(theMap, layout, RP->wallstyle, RP); |
| 144 |
|
| 145 |
|
| 146 |
if (strcmp(RP->doorstyle, "none")) { |
| 147 |
put_doors(theMap, layout, RP->doorstyle, RP); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
if (strcmp(RP->exitstyle, "none")) { |
| 153 |
place_exits(theMap, layout, RP->exitstyle, RP->orientation, RP); |
| 154 |
} |
| 155 |
|
| 156 |
place_specials_in_map(theMap, layout, RP); |
| 157 |
|
| 158 |
|
| 159 |
if (strcmp(RP->monsterstyle, "none")) { |
| 160 |
place_monsters(theMap, RP->monsterstyle, RP->difficulty, RP); |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
theMap->difficulty = calculate_difficulty(theMap); |
| 165 |
|
| 166 |
|
| 167 |
if (strcmp(RP->treasurestyle, "none")) { |
| 168 |
place_treasure(theMap, layout, RP->treasurestyle, RP->treasureoptions, RP); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
if (strcmp(RP->decorstyle, "none")) { |
| 173 |
put_decor(theMap, layout, RP->decorstyle, RP->decoroptions, RP); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
apply_auto_fix(theMap); |
| 178 |
|
| 179 |
unblock_exits(theMap, layout, RP); |
| 180 |
|
| 181 |
|
| 182 |
if (!use_layout) { |
| 183 |
for (i = 0; i < RP->Xsize; i++) { |
| 184 |
free(layout[i]); |
| 185 |
} |
| 186 |
free(layout); |
| 187 |
} |
| 188 |
|
| 189 |
theMap->msg = buf; |
| 190 |
|
| 191 |
|
| 192 |
theMap->last_reset_time = seconds(); |
| 193 |
return theMap; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
char **layoutgen(RMParms *RP) |
| 209 |
{ |
| 210 |
char **maze = NULL; |
| 211 |
int oxsize = RP->Xsize, oysize = RP->Ysize; |
| 212 |
|
| 213 |
if (RP->symmetry == RANDOM_SYM) { |
| 214 |
RP->symmetry_used = (RANDOM()%(XY_SYM))+1; |
| 215 |
} else { |
| 216 |
RP->symmetry_used = RP->symmetry; |
| 217 |
} |
| 218 |
|
| 219 |
if (RP->symmetry_used == Y_SYM || RP->symmetry_used == XY_SYM) { |
| 220 |
RP->Ysize = RP->Ysize/2+1; |
| 221 |
} |
| 222 |
if (RP->symmetry_used == X_SYM || RP->symmetry_used == XY_SYM) { |
| 223 |
RP->Xsize = RP->Xsize/2+1; |
| 224 |
} |
| 225 |
|
| 226 |
if (RP->Xsize < MIN_RANDOM_MAP_SIZE) { |
| 227 |
RP->Xsize = MIN_RANDOM_MAP_SIZE+RANDOM()%5; |
| 228 |
} |
| 229 |
if (RP->Ysize < MIN_RANDOM_MAP_SIZE) { |
| 230 |
RP->Ysize = MIN_RANDOM_MAP_SIZE+RANDOM()%5; |
| 231 |
} |
| 232 |
RP->map_layout_style = 0; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
if (strstr(RP->layoutstyle, "onion")) { |
| 240 |
RP->map_layout_style = ONION_LAYOUT; |
| 241 |
} |
| 242 |
|
| 243 |
if (strstr(RP->layoutstyle, "maze")) { |
| 244 |
RP->map_layout_style = MAZE_LAYOUT; |
| 245 |
} |
| 246 |
|
| 247 |
if (strstr(RP->layoutstyle, "spiral")) { |
| 248 |
RP->map_layout_style = SPIRAL_LAYOUT; |
| 249 |
} |
| 250 |
|
| 251 |
if (strstr(RP->layoutstyle, "rogue")) { |
| 252 |
RP->map_layout_style = ROGUELIKE_LAYOUT; |
| 253 |
} |
| 254 |
|
| 255 |
if (strstr(RP->layoutstyle, "snake")) { |
| 256 |
RP->map_layout_style = SNAKE_LAYOUT; |
| 257 |
} |
| 258 |
|
| 259 |
if (strstr(RP->layoutstyle, "squarespiral")) { |
| 260 |
RP->map_layout_style = SQUARE_SPIRAL_LAYOUT; |
| 261 |
} |
| 262 |
|
| 263 |
if (RP->map_layout_style == 0) { |
| 264 |
RP->map_layout_style = (RANDOM()%NROFLAYOUTS)+1; |
| 265 |
} |
| 266 |
|
| 267 |
switch (RP->map_layout_style) { |
| 268 |
case ONION_LAYOUT: |
| 269 |
maze = map_gen_onion(RP->Xsize, RP->Ysize, RP->layoutoptions1, RP->layoutoptions2); |
| 270 |
if (!(RANDOM()%3) && !(RP->layoutoptions1&OPT_WALLS_ONLY)) { |
| 271 |
roomify_layout(maze, RP); |
| 272 |
} |
| 273 |
break; |
| 274 |
|
| 275 |
case MAZE_LAYOUT: |
| 276 |
maze = maze_gen(RP->Xsize, RP->Ysize, RANDOM()%2,0); |
| 277 |
if (!(RANDOM()%2)) { |
| 278 |
doorify_layout(maze, RP); |
| 279 |
} |
| 280 |
break; |
| 281 |
|
| 282 |
case SPIRAL_LAYOUT: |
| 283 |
maze = map_gen_spiral(RP->Xsize, RP->Ysize, RP->layoutoptions1,0); |
| 284 |
if (!(RANDOM()%2)) { |
| 285 |
doorify_layout(maze, RP); |
| 286 |
} |
| 287 |
break; |
| 288 |
|
| 289 |
case ROGUELIKE_LAYOUT: |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
RP->symmetry_used = NO_SYM; |
| 298 |
RP->Ysize = oysize; |
| 299 |
RP->Xsize = oxsize; |
| 300 |
maze = roguelike_layout_gen(RP->Xsize, RP->Ysize, RP->layoutoptions1, 0); |
| 301 |
|
| 302 |
break; |
| 303 |
|
| 304 |
case SNAKE_LAYOUT: |
| 305 |
maze = make_snake_layout(RP->Xsize, RP->Ysize,0,0); |
| 306 |
if (RANDOM()%2) { |
| 307 |
roomify_layout(maze, RP); |
| 308 |
} |
| 309 |
break; |
| 310 |
|
| 311 |
case SQUARE_SPIRAL_LAYOUT: |
| 312 |
maze = make_square_spiral_layout(RP->Xsize, RP->Ysize,0,0); |
| 313 |
if (RANDOM()%2) { |
| 314 |
roomify_layout(maze, RP); |
| 315 |
} |
| 316 |
break; |
| 317 |
} |
| 318 |
|
| 319 |
maze = symmetrize_layout(maze, RP->symmetry_used, RP); |
| 320 |
#ifdef RMAP_DEBUG |
| 321 |
dump_layout(maze, RP); |
| 322 |
#endif |
| 323 |
if (RP->expand2x) { |
| 324 |
maze = expand2x(maze, RP->Xsize, RP->Ysize); |
| 325 |
RP->Xsize = RP->Xsize*2-1; |
| 326 |
RP->Ysize = RP->Ysize*2-1; |
| 327 |
} |
| 328 |
return maze; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
char **symmetrize_layout(char **maze, int sym, RMParms *RP) |
| 344 |
{ |
| 345 |
int i, j; |
| 346 |
char **sym_maze; |
| 347 |
int Xsize_orig, Ysize_orig; |
| 348 |
|
| 349 |
Xsize_orig = RP->Xsize; |
| 350 |
Ysize_orig = RP->Ysize; |
| 351 |
RP->symmetry_used = sym; |
| 352 |
if (sym == NO_SYM) { |
| 353 |
RP->Xsize = Xsize_orig; |
| 354 |
RP->Ysize = Ysize_orig; |
| 355 |
return maze; |
| 356 |
} |
| 357 |
|
| 358 |
RP->Xsize = ((sym == X_SYM || sym == XY_SYM) ? RP->Xsize*2-3 : RP->Xsize); |
| 359 |
RP->Ysize = ((sym == Y_SYM || sym == XY_SYM) ? RP->Ysize*2-3 : RP->Ysize); |
| 360 |
|
| 361 |
sym_maze = (char **)calloc(sizeof(char *), RP->Xsize); |
| 362 |
for (i = 0; i < RP->Xsize; i++) { |
| 363 |
sym_maze[i] = (char *)calloc(sizeof(char), RP->Ysize); |
| 364 |
} |
| 365 |
|
| 366 |
if (sym == X_SYM) |
| 367 |
for (i = 0; i < RP->Xsize/2+1; i++) |
| 368 |
for (j = 0; j < RP->Ysize; j++) { |
| 369 |
sym_maze[i][j] = maze[i][j]; |
| 370 |
sym_maze[RP->Xsize-i-1][j] = maze[i][j]; |
| 371 |
}; |
| 372 |
if (sym == Y_SYM) |
| 373 |
for (i = 0; i < RP->Xsize; i++) |
| 374 |
for (j = 0; j < RP->Ysize/2+1; j++) { |
| 375 |
sym_maze[i][j] = maze[i][j]; |
| 376 |
sym_maze[i][RP->Ysize-j-1] = maze[i][j]; |
| 377 |
} |
| 378 |
if (sym == XY_SYM) |
| 379 |
for (i = 0; i < RP->Xsize/2+1; i++) |
| 380 |
for (j = 0; j < RP->Ysize/2+1; j++) { |
| 381 |
sym_maze[i][j] = maze[i][j]; |
| 382 |
sym_maze[i][RP->Ysize-j-1] = maze[i][j]; |
| 383 |
sym_maze[RP->Xsize-i-1][j] = maze[i][j]; |
| 384 |
sym_maze[RP->Xsize-i-1][RP->Ysize-j-1] = maze[i][j]; |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
for (i = 0; i < Xsize_orig; i++) { |
| 389 |
free(maze[i]); |
| 390 |
} |
| 391 |
free(maze); |
| 392 |
|
| 393 |
|
| 394 |
if (RP->map_layout_style == SPIRAL_LAYOUT) { |
| 395 |
connect_spirals(RP->Xsize, RP->Ysize, sym, sym_maze); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
if (RP->map_layout_style == ROGUELIKE_LAYOUT) { |
| 401 |
connect_spirals(RP->Xsize, RP->Ysize, sym, sym_maze); |
| 402 |
} |
| 403 |
|
| 404 |
return sym_maze; |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
char **rotate_layout(char **maze, int rotation, RMParms *RP) |
| 425 |
{ |
| 426 |
char **new_maze; |
| 427 |
int i, j; |
| 428 |
|
| 429 |
switch (rotation) { |
| 430 |
case 0: |
| 431 |
return maze; |
| 432 |
break; |
| 433 |
|
| 434 |
case 2: { |
| 435 |
char *new = malloc(sizeof(char)*RP->Xsize*RP->Ysize); |
| 436 |
|
| 437 |
for (i = 0; i < RP->Xsize; i++) { |
| 438 |
for (j = 0; j < RP->Ysize; j++) { |
| 439 |
new[i*RP->Ysize+j] = maze[i][j]; |
| 440 |
} |
| 441 |
} |
| 442 |
for (i = 0; i < RP->Xsize; i++) { |
| 443 |
for (j = 0; j < RP->Ysize; j++) { |
| 444 |
maze[i][j] = new[(RP->Xsize-i-1)*RP->Ysize+RP->Ysize-j-1]; |
| 445 |
} |
| 446 |
} |
| 447 |
free(new); |
| 448 |
return maze; |
| 449 |
break; |
| 450 |
} |
| 451 |
|
| 452 |
case 1: |
| 453 |
case 3: { |
| 454 |
int swap; |
| 455 |
|
| 456 |
new_maze = (char **)calloc(sizeof(char *), RP->Ysize); |
| 457 |
for (i = 0; i < RP->Ysize; i++) { |
| 458 |
new_maze[i] = (char *)calloc(sizeof(char), RP->Xsize); |
| 459 |
} |
| 460 |
if (rotation == 1) |
| 461 |
for (i = 0; i < RP->Xsize; i++) |
| 462 |
for (j = 0; j < RP->Ysize; j++) { |
| 463 |
new_maze[j][i] = maze[i][j]; |
| 464 |
} |
| 465 |
|
| 466 |
if (rotation == 3) { |
| 467 |
for (i = 0; i < RP->Xsize; i++) |
| 468 |
for (j = 0; j < RP->Ysize; j++) { |
| 469 |
new_maze[j][i] = maze[RP->Xsize-i-1][RP->Ysize-j-1]; |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
for (i = 0; i < RP->Xsize; i++) { |
| 475 |
free(maze[i]); |
| 476 |
} |
| 477 |
free(maze); |
| 478 |
|
| 479 |
swap = RP->Ysize; |
| 480 |
RP->Ysize = RP->Xsize; |
| 481 |
RP->Xsize = swap; |
| 482 |
return new_maze; |
| 483 |
break; |
| 484 |
} |
| 485 |
} |
| 486 |
return NULL; |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
void roomify_layout(char **maze, RMParms *RP) |
| 497 |
{ |
| 498 |
int tries = RP->Xsize*RP->Ysize/30; |
| 499 |
int ti; |
| 500 |
|
| 501 |
for (ti = 0; ti < tries; ti++) { |
| 502 |
int dx, dy; |
| 503 |
int cx, cy; |
| 504 |
|
| 505 |
dx = RANDOM()%RP->Xsize; |
| 506 |
dy = RANDOM()%RP->Ysize; |
| 507 |
cx = can_make_wall(maze, dx, dy, 0, RP); |
| 508 |
cy = can_make_wall(maze, dx, dy, 1, RP); |
| 509 |
if (cx == -1) { |
| 510 |
if (cy != -1) { |
| 511 |
make_wall(maze, dx, dy, 1); |
| 512 |
} |
| 513 |
continue; |
| 514 |
} |
| 515 |
if (cy == -1) { |
| 516 |
make_wall(maze, dx, dy, 0); |
| 517 |
continue; |
| 518 |
} |
| 519 |
if (cx < cy) { |
| 520 |
make_wall(maze, dx, dy, 0); |
| 521 |
} else { |
| 522 |
make_wall(maze, dx, dy, 1); |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
int can_make_wall(char **maze, int dx, int dy, int dir, RMParms *RP) |
| 545 |
{ |
| 546 |
int i1; |
| 547 |
int length = 0; |
| 548 |
|
| 549 |
|
| 550 |
if (dx == 0 || dx == (RP->Xsize-1) || dy == 0 || dy == (RP->Ysize-1)) { |
| 551 |
return -1; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
if (maze[dx][dy] != 0) { |
| 556 |
return -1; |
| 557 |
} |
| 558 |
|
| 559 |
if (dir == 0) { |
| 560 |
|
| 561 |
int y = dy; |
| 562 |
|
| 563 |
for (i1 = dx-1; i1 > 0; i1--) { |
| 564 |
int sindex = surround_flag2(maze, i1, y, RP); |
| 565 |
|
| 566 |
if (sindex == 1) { |
| 567 |
break; |
| 568 |
} |
| 569 |
if (sindex != 0) { |
| 570 |
return -1; |
| 571 |
} |
| 572 |
if (maze[i1][y] != 0) { |
| 573 |
return -1; |
| 574 |
} |
| 575 |
length++; |
| 576 |
} |
| 577 |
|
| 578 |
for (i1 = dx+1; i1 < RP->Xsize-1; i1++) { |
| 579 |
int sindex = surround_flag2(maze, i1, y, RP); |
| 580 |
|
| 581 |
if (sindex == 2) { |
| 582 |
break; |
| 583 |
} |
| 584 |
if (sindex != 0) { |
| 585 |
return -1; |
| 586 |
} |
| 587 |
if (maze[i1][y] != 0) { |
| 588 |
return -1; |
| 589 |
} |
| 590 |
length++; |
| 591 |
} |
| 592 |
return length; |
| 593 |
} else { |
| 594 |
|
| 595 |
int x = dx; |
| 596 |
|
| 597 |
for (i1 = dy-1; i1 > 0; i1--) { |
| 598 |
int sindex = surround_flag2(maze, x, i1, RP); |
| 599 |
|
| 600 |
if (sindex == 4) { |
| 601 |
break; |
| 602 |
} |
| 603 |
if (sindex != 0) { |
| 604 |
return -1; |
| 605 |
} |
| 606 |
if (maze[x][i1] != 0) { |
| 607 |
return -1; |
| 608 |
} |
| 609 |
length++; |
| 610 |
} |
| 611 |
|
| 612 |
for (i1 = dy+1; i1 < RP->Ysize-1; i1++) { |
| 613 |
int sindex = surround_flag2(maze, x, i1, RP); |
| 614 |
|
| 615 |
if (sindex == 8) { |
| 616 |
break; |
| 617 |
} |
| 618 |
if (sindex != 0) { |
| 619 |
return -1; |
| 620 |
} |
| 621 |
if (maze[x][i1] != 0) { |
| 622 |
return -1; |
| 623 |
} |
| 624 |
length++; |
| 625 |
} |
| 626 |
return length; |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
int make_wall(char **maze, int x, int y, int dir) |
| 645 |
{ |
| 646 |
maze[x][y] = 'D'; |
| 647 |
switch (dir) { |
| 648 |
case 0: { |
| 649 |
int i1; |
| 650 |
|
| 651 |
for (i1 = x-1; maze[i1][y] == 0; i1--) { |
| 652 |
maze[i1][y] = '#'; |
| 653 |
} |
| 654 |
for (i1 = x+1; maze[i1][y] == 0; i1++) { |
| 655 |
maze[i1][y] = '#'; |
| 656 |
} |
| 657 |
break; |
| 658 |
} |
| 659 |
|
| 660 |
case 1: { |
| 661 |
int i1; |
| 662 |
|
| 663 |
for (i1 = y-1; maze[x][i1] == 0; i1--) { |
| 664 |
maze[x][i1] = '#'; |
| 665 |
} |
| 666 |
for (i1 = y+1; maze[x][i1] == 0; i1++) { |
| 667 |
maze[x][i1] = '#'; |
| 668 |
} |
| 669 |
break; |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
return 0; |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
void doorify_layout(char **maze, RMParms *RP) |
| 684 |
{ |
| 685 |
int ndoors = RP->Xsize*RP->Ysize/60; |
| 686 |
int *doorlist_x; |
| 687 |
int *doorlist_y; |
| 688 |
int doorlocs = 0; |
| 689 |
int i, j; |
| 690 |
|
| 691 |
doorlist_x = malloc(sizeof(int)*RP->Xsize*RP->Ysize); |
| 692 |
doorlist_y = malloc(sizeof(int)*RP->Xsize*RP->Ysize); |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
for (i = 1; i < RP->Xsize-1; i++) |
| 697 |
for (j = 1; j < RP->Ysize-1; j++) { |
| 698 |
int sindex = surround_flag(maze, i, j, RP); |
| 699 |
if (sindex == 3 || sindex == 12) { |
| 700 |
|
| 701 |
doorlist_x[doorlocs] = i; |
| 702 |
doorlist_y[doorlocs] = j; |
| 703 |
doorlocs++; |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
while (ndoors > 0 && doorlocs > 0) { |
| 708 |
int di; |
| 709 |
int sindex; |
| 710 |
|
| 711 |
di = RANDOM()%doorlocs; |
| 712 |
i = doorlist_x[di]; |
| 713 |
j = doorlist_y[di]; |
| 714 |
sindex = surround_flag(maze, i, j, RP); |
| 715 |
if (sindex == 3 || sindex == 12) { |
| 716 |
maze[i][j] = 'D'; |
| 717 |
ndoors--; |
| 718 |
} |
| 719 |
|
| 720 |
doorlocs--; |
| 721 |
doorlist_x[di] = doorlist_x[doorlocs]; |
| 722 |
doorlist_y[di] = doorlist_y[doorlocs]; |
| 723 |
} |
| 724 |
free(doorlist_x); |
| 725 |
free(doorlist_y); |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
StringBuffer *write_map_parameters_to_string(const RMParms *RP) |
| 736 |
{ |
| 737 |
StringBuffer *buf; |
| 738 |
|
| 739 |
buf = stringbuffer_new(); |
| 740 |
stringbuffer_append_printf(buf, "xsize %d\nysize %d\n", RP->Xsize, RP->Ysize); |
| 741 |
|
| 742 |
if (RP->wallstyle[0]) { |
| 743 |
stringbuffer_append_printf(buf, "wallstyle %s\n", RP->wallstyle); |
| 744 |
} |
| 745 |
|
| 746 |
if (RP->floorstyle[0]) { |
| 747 |
stringbuffer_append_printf(buf, "floorstyle %s\n", RP->floorstyle); |
| 748 |
} |
| 749 |
|
| 750 |
if (RP->monsterstyle[0]) { |
| 751 |
stringbuffer_append_printf(buf, "monsterstyle %s\n", RP->monsterstyle); |
| 752 |
} |
| 753 |
|
| 754 |
if (RP->treasurestyle[0]) { |
| 755 |
stringbuffer_append_printf(buf, "treasurestyle %s\n", RP->treasurestyle); |
| 756 |
} |
| 757 |
|
| 758 |
if (RP->layoutstyle[0]) { |
| 759 |
stringbuffer_append_printf(buf, "layoutstyle %s\n", RP->layoutstyle); |
| 760 |
} |
| 761 |
|
| 762 |
if (RP->decorstyle[0]) { |
| 763 |
stringbuffer_append_printf(buf, "decorstyle %s\n", RP->decorstyle); |
| 764 |
} |
| 765 |
|
| 766 |
if (RP->doorstyle[0]) { |
| 767 |
stringbuffer_append_printf(buf, "doorstyle %s\n", RP->doorstyle); |
| 768 |
} |
| 769 |
|
| 770 |
if (RP->exitstyle[0]) { |
| 771 |
stringbuffer_append_printf(buf, "exitstyle %s\n", RP->exitstyle); |
| 772 |
} |
| 773 |
|
| 774 |
if (RP->cheststyle[0]) { |
| 775 |
stringbuffer_append_printf(buf, "cheststyle %s\n", RP->cheststyle); |
| 776 |
} |
| 777 |
|
| 778 |
if (RP->final_map[0]) { |
| 779 |
stringbuffer_append_printf(buf, "final_map %s\n", RP->final_map); |
| 780 |
} |
| 781 |
|
| 782 |
if (RP->final_exit_archetype[0]) { |
| 783 |
stringbuffer_append_printf(buf, "final_exit_archetype %s\n", RP->final_exit_archetype); |
| 784 |
} |
| 785 |
|
| 786 |
if (RP->exit_on_final_map[0]) { |
| 787 |
stringbuffer_append_printf(buf, "exit_on_final_map %s\n", RP->exit_on_final_map); |
| 788 |
} |
| 789 |
|
| 790 |
if (RP->this_map[0]) { |
| 791 |
stringbuffer_append_printf(buf, "origin_map %s\n", RP->this_map); |
| 792 |
} |
| 793 |
|
| 794 |
if (RP->expand2x) { |
| 795 |
stringbuffer_append_printf(buf, "expand2x %d\n", RP->expand2x); |
| 796 |
} |
| 797 |
|
| 798 |
if (RP->layoutoptions1) { |
| 799 |
stringbuffer_append_printf(buf, "layoutoptions1 %d\n", RP->layoutoptions1); |
| 800 |
} |
| 801 |
|
| 802 |
if (RP->layoutoptions2) { |
| 803 |
stringbuffer_append_printf(buf, "layoutoptions2 %d\n", RP->layoutoptions2); |
| 804 |
} |
| 805 |
|
| 806 |
if (RP->symmetry) { |
| 807 |
stringbuffer_append_printf(buf, "symmetry %d\n", RP->symmetry); |
| 808 |
} |
| 809 |
|
| 810 |
if (RP->difficulty && RP->difficulty_given) { |
| 811 |
stringbuffer_append_printf(buf, "difficulty %d\n", RP->difficulty); |
| 812 |
} |
| 813 |
|
| 814 |
if (RP->difficulty_increase != 1.0) { |
| 815 |
stringbuffer_append_printf(buf, "difficulty_increase %f\n", RP->difficulty_increase); |
| 816 |
} |
| 817 |
|
| 818 |
stringbuffer_append_printf(buf, "dungeon_level %d\n", RP->dungeon_level); |
| 819 |
|
| 820 |
if (RP->dungeon_depth) { |
| 821 |
stringbuffer_append_printf(buf, "dungeon_depth %d\n", RP->dungeon_depth); |
| 822 |
} |
| 823 |
|
| 824 |
if (RP->dungeon_name[0]) { |
| 825 |
stringbuffer_append_printf(buf, "dungeon_name %s\n", RP->dungeon_name); |
| 826 |
} |
| 827 |
|
| 828 |
if (RP->decoroptions) { |
| 829 |
stringbuffer_append_printf(buf, "decoroptions %d\n", RP->decoroptions); |
| 830 |
} |
| 831 |
|
| 832 |
if (RP->orientation) { |
| 833 |
stringbuffer_append_printf(buf, "orientation %d\n", RP->orientation); |
| 834 |
} |
| 835 |
|
| 836 |
if (RP->origin_x) { |
| 837 |
stringbuffer_append_printf(buf, "origin_x %d\n", RP->origin_x); |
| 838 |
} |
| 839 |
|
| 840 |
if (RP->origin_y) { |
| 841 |
stringbuffer_append_printf(buf, "origin_y %d\n", RP->origin_y); |
| 842 |
} |
| 843 |
if (RP->random_seed) { |
| 844 |
|
| 845 |
stringbuffer_append_printf(buf, "random_seed %d\n", RP->random_seed+1); |
| 846 |
} |
| 847 |
|
| 848 |
if (RP->treasureoptions) { |
| 849 |
stringbuffer_append_printf(buf, "treasureoptions %d\n", RP->treasureoptions); |
| 850 |
} |
| 851 |
|
| 852 |
if (RP->multiple_floors) { |
| 853 |
stringbuffer_append_printf(buf, "multiple_floors %d\n", RP->multiple_floors); |
| 854 |
} |
| 855 |
|
| 856 |
return buf; |
| 857 |
} |