Struct eos_rs::api::dungeon_mode::dungeon_generator::game_builtin::GlobalDungeonStructureGenerator
source · 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>
impl<'a> GlobalDungeonStructureGenerator<'a>
sourcepub fn generate_fixed_room(
&mut self,
fixed_room_id: FixedRoomId,
properties: &floor_properties
) -> bool
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.
sourcepub fn flag_hallway_junctions(&mut self, x0: i32, y0: i32, x1: i32, y1: i32)
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.
sourcepub 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
)
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.
sourcepub fn finalize_junctions(&mut self)
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
sourcepub 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
)
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.
sourcepub fn is_next_to_hallway(&self, x: i32, y: i32) -> bool
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.
sourcepub fn resolve_invalid_spawns(&mut self)
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.
sourcepub fn convert_secondary_terrain_to_chasms(&mut self)
pub fn convert_secondary_terrain_to_chasms(&mut self)
Converts all secondary terrain tiles (water/lava) to chasms.
sourcepub fn convert_walls_to_chasms(&mut self)
pub fn convert_walls_to_chasms(&mut self)
Converts all wall tiles to chasms.
sourcepub fn ensure_impassable_tiles_are_walls(&mut self)
pub fn ensure_impassable_tiles_are_walls(&mut self)
Ensures all tiles with the impassable flag are walls.
sourcepub fn reset_floor(&mut self)
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.
sourcepub fn generate_secondary_terrain_formations(
&mut self,
test_flag: u8,
floor_props: &floor_properties
)
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
sourcepub fn stairs_are_always_reachable(
&mut self,
x_stairs: i32,
y_stairs: i32,
mark_unreachable: bool
) -> bool
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.
sourcepub fn reset_inner_boundary_tile_rows(&mut self)
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).
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.
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.
sourcepub fn spawn_stairs(
&mut self,
x: u8,
y: u8,
gen_info: &dungeon_generation_info,
hidden_stairs_type: HiddenStairsType
)
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>
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
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
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<'_>)
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
fn entities<F: FnOnce(&mut Self::EntityGenerator)>( &mut self, cb: F ) -> &mut Self
Self::EntityGenerator
to generate them. Read more