* Place a level. First, find the possible places on a dungeon map * template. Next pick one. Then try to place the next level. If * successful, we're done. Otherwise, try another (and another) until * all possible places have been tried. If all possible places have * been exhausted, return false. */
| 663 | * been exhausted, return false. |
| 664 | */ |
| 665 | staticfn boolean |
| 666 | place_level(int proto_index, struct proto_dungeon *pd) |
| 667 | { |
| 668 | boolean map[MAXLEVEL + 1]; /* valid levels are 1..MAXLEVEL inclusive */ |
| 669 | s_level *lev; |
| 670 | int npossible; |
| 671 | #ifdef DDEBUG |
| 672 | int i; |
| 673 | #endif |
| 674 | |
| 675 | if (proto_index == pd->n_levs) |
| 676 | return TRUE; /* at end of proto levels */ |
| 677 | |
| 678 | lev = pd->final_lev[proto_index]; |
| 679 | |
| 680 | /* No level created for this prototype, goto next. */ |
| 681 | if (!lev) |
| 682 | return place_level(proto_index + 1, pd); |
| 683 | |
| 684 | npossible = possible_places(proto_index, map, pd); |
| 685 | |
| 686 | for (; npossible; --npossible) { |
| 687 | lev->dlevel.dlevel = pick_level(map, rn2(npossible)); |
| 688 | #ifdef DDEBUG |
| 689 | indent(proto_index - pd->start); |
| 690 | fprintf(stderr, "%s: trying %d [ ", lev->proto, lev->dlevel.dlevel); |
| 691 | for (i = 1; i <= MAXLEVEL; i++) |
| 692 | if (map[i]) |
| 693 | fprintf(stderr, "%d ", i); |
| 694 | fprintf(stderr, "]\n"); |
| 695 | #endif |
| 696 | if (place_level(proto_index + 1, pd)) |
| 697 | return TRUE; |
| 698 | map[lev->dlevel.dlevel] = FALSE; /* this choice didn't work */ |
| 699 | } |
| 700 | #ifdef DDEBUG |
| 701 | indent(proto_index - pd->start); |
| 702 | fprintf(stderr, "%s: failed\n", lev->proto); |
| 703 | #endif |
| 704 | return FALSE; |
| 705 | } |
| 706 | |
| 707 | static struct level_map { |
| 708 | const char *lev_name; |
no test coverage detected