* Ensure that the level given by `l` is generated. This does not do much in * the way of cleanup, and the caller must ensure the player ends up somewhere * sensible afterwards (this will not place the player, and will wipe out their * current location state if a level is built). Does not do anything if the * save already contains the relevant level. * * This function may generate multiple le
| 1721 | * exists. This can be checked by looking at whether the save chunk exists. |
| 1722 | */ |
| 1723 | bool generate_level(const level_id &l) |
| 1724 | { |
| 1725 | const string level_name = l.describe(); |
| 1726 | if (you.save->has_chunk(level_name)) |
| 1727 | return false; |
| 1728 | |
| 1729 | unwind_var<int> you_depth(you.depth, l.depth); |
| 1730 | unwind_var<branch_type> you_branch(you.where_are_you, l.branch); |
| 1731 | unwind_var<coord_def> you_saved_position(you.position); |
| 1732 | you.position.reset(); |
| 1733 | |
| 1734 | // simulate a reasonable stair to enter the level with |
| 1735 | const dungeon_feature_type stair_taken = |
| 1736 | you.depth == 1 |
| 1737 | ? (you.where_are_you == BRANCH_DUNGEON |
| 1738 | ? DNGN_UNSEEN |
| 1739 | : branches[you.where_are_you].entry_stairs) |
| 1740 | : DNGN_STONE_STAIRS_DOWN_I; |
| 1741 | |
| 1742 | unwind_var<dungeon_feature_type> stair(you.transit_stair, stair_taken); |
| 1743 | // TODO how necessary is this? |
| 1744 | unwind_bool ylev(you.entering_level, true); |
| 1745 | // n.b. crawl_state.generating_level is handled in builder |
| 1746 | |
| 1747 | _generic_level_reset(); |
| 1748 | delete_all_clouds(); |
| 1749 | los_changed(); // invalidate the los cache, which impacts monster placement |
| 1750 | |
| 1751 | // initialize env for builder |
| 1752 | env.turns_on_level = -1; |
| 1753 | tile_init_default_flavour(); |
| 1754 | tile_clear_flavour(); |
| 1755 | tile_env.names.clear(); |
| 1756 | _clear_env_map(); |
| 1757 | |
| 1758 | // finally -- everything is set up, call the builder. |
| 1759 | dprf("Generating new level for '%s'.", level_name.c_str()); |
| 1760 | if (!builder(true)) |
| 1761 | return false; |
| 1762 | |
| 1763 | auto &vault_list = you.vault_list[level_id::current()]; |
| 1764 | #ifdef DEBUG |
| 1765 | // places where a level can generate multiple times. |
| 1766 | // could add portals to this list for debugging purposes? |
| 1767 | if ( you.where_are_you == BRANCH_ABYSS |
| 1768 | || you.where_are_you == BRANCH_PANDEMONIUM |
| 1769 | || you.where_are_you == BRANCH_BAZAAR |
| 1770 | || you.where_are_you == BRANCH_ZIGGURAT) |
| 1771 | { |
| 1772 | vault_list.push_back("[gen]"); |
| 1773 | } |
| 1774 | #endif |
| 1775 | const auto &level_vaults = level_vault_names(); |
| 1776 | vault_list.insert(vault_list.end(), |
| 1777 | level_vaults.begin(), level_vaults.end()); |
| 1778 | |
| 1779 | // initialize env for a new level |
| 1780 | env.turns_on_level = 0; |
no test coverage detected