MCPcopy Create free account
hub / github.com/crawl/crawl / generate_level

Function generate_level

crawl-ref/source/files.cc:1723–1811  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

1721 * exists. This can be checked by looking at whether the save chunk exists.
1722 */
1723bool 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;

Callers 2

_generate_portal_levelsFunction · 0.85
pregen_dungeonFunction · 0.85

Calls 15

_generic_level_resetFunction · 0.85
delete_all_cloudsFunction · 0.85
los_changedFunction · 0.85
tile_clear_flavourFunction · 0.85
_clear_env_mapFunction · 0.85
dprfFunction · 0.85
builderFunction · 0.85
level_vault_namesFunction · 0.85
show_update_emphasisFunction · 0.85
update_portal_entrancesFunction · 0.85
save_levelFunction · 0.85

Tested by

no test coverage detected