pub struct GlobalDungeonStructureGenerator<'a>(_, _);
Expand description

The structure and layout generator for the global dungeon.

To create instances of this struct use crate::api::dungeon_mode::GlobalDungeonData::get_builtin_dungeon_generator.

Implementations§

source§

impl<'a> GlobalDungeonStructureGenerator<'a>

source

pub fn generate_fixed_room( &mut self, fixed_room_id: FixedRoomId, properties: &floor_properties ) -> bool

Handles fixed room generation if the floor contains a fixed room.

source

pub fn flag_hallway_junctions(&mut self, x0: i32, y0: i32, x1: i32, y1: i32)

Sets the junction flag (bit 3 of the terrain flags) on any hallway junction tiles in some range [x0, x1), [y0, y1). This leaves tiles within rooms untouched.

source

pub fn create_hallway( &mut self, start_x: i32, start_y: i32, end_x: i32, end_y: i32, is_vertical: bool, middle_x: i32, middle_y: i32 )

Create a hallway between two points.

If the two points share no coordinates in common (meaning the line connecting them is diagonal), a “kinked” hallway is created, with the kink at a specified “middle” coordinate (in practice the grid cell boundary). For example, with a kinked horizontal hallway, there are two horizontal lines extending out from the endpoints, connected by a vertical line on the middle x coordinate.

If a hallway would intersect with an existing open tile (like an existing hallway), the hallway will only be created up to the point where it intersects with the open tile.

Arguments
  • start_x - The x coordinate of the start of the hallway.
  • start_y - The y coordinate of the start of the hallway.
  • end_x - The x coordinate of the end of the hallway.
  • end_y - The y coordinate of the end of the hallway.
  • is_vertical - vertical flag (true for vertical hallway, false for horizontal).
  • middle_x - Middle x coordinate for kinked horizontal hallways.
  • middle_y - Middle y coordinate for kinked vertical hallways.
source

pub fn finalize_junctions(&mut self)

Finalizes junction tiles by setting the junction flag (bit 3 of the terrain flags) and ensuring open terrain.

Note that this implementation is slightly buggy. This function scans tiles left-to-right, top-to-bottom, and identifies junctions as any open, non-hallway tile (room_index != 0xFF) adjacent to an open, hallway tile (room_index == 0xFF). This interacts poorly with hallway anchors (room_index == 0xFE). This function sets the room index of any hallway anchors to 0xFF within the same loop, so a hallway anchor may or may not be identified as a junction depending on the orientation of connected hallways.

For example, in the following configuration, the “o” tile would be marked as a junction because the neighboring hallway tile to its left comes earlier in iteration, while the “o” tile still has the room index 0xFE, causing the algorithm to mistake it for a room tile:

xxxxx
---ox
xxx|x
xxx|x

However, in the following configuration, the “o” tile would NOT be marked as a junction because it comes earlier in iteration than any of its neighboring hallway tiles, so its room index is set to 0xFF before it can be marked as a junction. This is actually the ONLY possible configuration where a hallway anchor will not be marked as a junction.

xxxxx
xo---
x|xxx
x|xxx
source

pub fn generate_maze_line( &mut self, x0: i32, y0: i32, x_min: i32, y_min: i32, x_max: i32, y_max: i32, use_secondary_terrain: bool, room: u8 )

Generate a “maze line” from a given starting point, within the given bounds.

A “maze line” is a random walk starting from (x0, y0). The random walk proceeds with a stride of 2 in a random direction, laying down obstacles as it goes. The random walk terminates when it gets trapped and there are no more neighboring tiles that are open and in-bounds.

source

pub fn is_next_to_hallway(&self, x: i32, y: i32) -> bool

Checks if a tile position is either in a hallway or next to one.

source

pub fn resolve_invalid_spawns(&mut self)

Resolve invalid spawn flags on tiles.

Spawn flags can be invalid due to terrain. For example, traps can’t spawn on obstacles. Spawn flags can also be invalid due to multiple being set on a single tile, in which case one will take precedence. For example, stair spawns trump trap spawns.

source

pub fn convert_secondary_terrain_to_chasms(&mut self)

Converts all secondary terrain tiles (water/lava) to chasms.

source

pub fn convert_walls_to_chasms(&mut self)

Converts all wall tiles to chasms.

source

pub fn ensure_impassable_tiles_are_walls(&mut self)

Ensures all tiles with the impassable flag are walls.

source

pub fn reset_floor(&mut self)

Resets the floor in preparation for a floor generation attempt.

Resets all tiles, resets the border to be impassable, and clears entity spawns.

source

pub fn generate_secondary_terrain_formations( &mut self, test_flag: u8, floor_props: &floor_properties )

Generate secondary terrain (water/lava) formations.

This includes “rivers” that flow from top-to-bottom (or bottom-to-top), as well as “lakes” both standalone and after rivers. Water/lava formations will never cut through rooms, but they can pass through rooms to the opposite side.

Rivers are generated by a top-down or bottom-up random walk that ends when existing secondary terrain is reached or the walk goes out of bounds. Some rivers also end prematurely in a lake. Lakes are a large collection of secondary terrain generated around a central point.

Arguments
  • test_flag - bit index to test in the floor properties room flag bitvector (formations are only generated if the bit is set)
  • floor_props - floor properties
source

pub fn stairs_are_always_reachable( &mut self, x_stairs: i32, y_stairs: i32, mark_unreachable: bool ) -> bool

Checks that the stairs are reachable from every walkable tile on the floor.

This runs a graph traversal algorithm that is very similar to breadth-first search (the order in which nodes are visited is slightly different), starting from the stairs. If any tile is walkable but wasn’t reached by the traversal algorithm, then the stairs must not be reachable from that tile.

If mark_unreachable is true, this function will instead always return true, but set a special bit on all walkable tiles that aren’t reachable from the stairs.

source

pub fn reset_inner_boundary_tile_rows(&mut self)

Reset the inner boundary tile rows (y == 1 and y == 30) to their initial state of all wall tiles, with impassable walls at the edges (x == 0 and x == 55).

source

pub fn get_hidden_stairs_type( &self, gen_info: &dungeon_generation_info, floor_props: &floor_properties ) -> Option<HiddenStairsType>

Gets the hidden stairs type for a given floor.

This function reads the floor properties and resolves any randomness into a concrete hidden stairs type.

Returns None if the game returns an invalid/unknown value.

source

pub fn reset_hidden_stairs_spawn(&mut self)

Resets hidden stairs spawn information for the floor. This includes the position on the floor generation status as well as the flag indicating whether the spawn was blocked.

source

pub fn spawn_stairs( &mut self, x: u8, y: u8, gen_info: &dungeon_generation_info, hidden_stairs_type: HiddenStairsType )

Spawn stairs at the given location.

If the hidden stairs type is something other than HIDDEN_STAIRS_NONE, hidden stairs of the specified type will be spawned instead of normal stairs.

If spawning normal stairs and the current floor is a rescue floor, the room containing the stairs will be converted into a Monster House.

If attempting to spawn hidden stairs but the spawn is blocked, the floor generation status’s hidden stairs spawn position will be updated, but it won’t be transferred to the dungeon generation info struct.

Trait Implementations§

source§

impl<'a> DungeonFloorGeneration for GlobalDungeonStructureGenerator<'a>

The game’s builtin dungeon generator.

source§

fn generate_floor( &mut self, _width: usize, _height: usize, _properties: &floor_properties ) -> &mut Self

Generate a dungeon floor.

This ignores all parameters at the moment and instead reads from the global dungeon struct directly.

This is the master function that generates the dungeon floor.

Very loosely speaking, this function first tries to generate a valid floor layout. Then it tries to spawn entities in a valid configuration. Finally, it performs cleanup and post-processing depending on the dungeon.

If a spawn configuration is invalid, the entire floor layout is scrapped and regenerated. If the generated floor layout is invalid 10 times in a row, or a valid spawn configuration isn’t generated within 10 attempts, the generation algorithm aborts and the default one-room Monster House floor is generated as a fallback.

If not changed by a patch, this function will use the game’s default built in generator and generate the floor based on the current global configuration for the floor.

source§

fn generate_layout( &mut self, layout: &mut Self::LayoutGenerator, properties: &floor_properties ) -> &mut Self

Width and height are ignored for most layouts.

source§

fn generate(self, _: &mut GlobalDungeonData<'_>)

This does nothing, this implementation will always update the global struct directly.

§

type EntityGenerator = GlobalDungeonEntityGenerator

§

type LayoutGenerator = BuiltinDungeonLayoutGenerators

source§

fn entities<F: FnOnce(&mut Self::EntityGenerator)>( &mut self, cb: F ) -> &mut Self

Generate entities, the callback will receive Self::EntityGenerator to generate them. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for GlobalDungeonStructureGenerator<'a>

§

impl<'a> !Send for GlobalDungeonStructureGenerator<'a>

§

impl<'a> !Sync for GlobalDungeonStructureGenerator<'a>

§

impl<'a> Unpin for GlobalDungeonStructureGenerator<'a>

§

impl<'a> !UnwindSafe for GlobalDungeonStructureGenerator<'a>

Blanket Implementations§

§

impl<T> Any for Twhere T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
§

impl<T> Borrow<T> for Twhere T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.