Update maze-generator.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Nolan Darilek 2022-03-21 09:14:44 -05:00
parent d56c6cc5c7
commit cc4b8751f4
2 changed files with 50 additions and 46 deletions

View File

@ -33,7 +33,7 @@ derive_more = "0.99"
futures-lite = "1"
gilrs = "0.8"
here_be_dragons = "0.1"
maze_generator = "1"
maze_generator = "2"
once_cell = "1"
pathfinding = "3"
rand = "0.8"

View File

@ -174,55 +174,59 @@ impl<D: Clone + Default> MapFilter<D> for GridBuilder {
fn modify_map(&self, _rng: &mut StdRng, map: &MapgenMap<D>) -> MapgenMap<D> {
let mut map = map.clone();
let mut generator = RbGenerator::new(None);
let maze = generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32);
let total_height = (self.room_height + 1) * self.height_in_rooms + 1;
let half_width = self.room_width / 2;
let half_height = self.room_height / 2;
for y in 0..self.height_in_rooms {
for x in 0..self.width_in_rooms {
let x_offset = x * (self.room_width + 1);
let y_offset = total_height - (y * (self.room_height + 1)) - self.room_height - 2;
let room = MRect::new_i32(
x_offset as i32 + 1,
y_offset as i32 + 1,
self.room_width as i32,
self.room_height as i32,
);
map.add_room(room);
let coords = maze_generator::prelude::Coordinates::new(x as i32, y as i32);
if let Some(field) = maze.get_field(&coords) {
use maze_generator::prelude::Direction::*;
if field.has_passage(&North) {
let x = x_offset + half_width;
let y = y_offset + self.room_height;
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&South) {
let x = x_offset + half_width;
let y = y_offset;
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&East) {
let x = x_offset + self.room_width;
let y = y_offset + half_height;
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&West) {
let x = x_offset;
let y = y_offset + half_height;
map.set_tile(x as usize, y as usize, Tile::floor());
if let Ok(maze) =
generator.generate(self.width_in_rooms as i32, self.height_in_rooms as i32)
{
let total_height = (self.room_height + 1) * self.height_in_rooms + 1;
let half_width = self.room_width / 2;
let half_height = self.room_height / 2;
for y in 0..self.height_in_rooms {
for x in 0..self.width_in_rooms {
let x_offset = x * (self.room_width + 1);
let y_offset =
total_height - (y * (self.room_height + 1)) - self.room_height - 2;
let room = MRect::new_i32(
x_offset as i32 + 1,
y_offset as i32 + 1,
self.room_width as i32,
self.room_height as i32,
);
map.add_room(room);
let coords = maze_generator::prelude::Coordinates::new(x as i32, y as i32);
if let Some(field) = maze.get_field(&coords) {
use maze_generator::prelude::Direction::*;
if field.has_passage(&North) {
let x = x_offset + half_width;
let y = y_offset + self.room_height;
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&South) {
let x = x_offset + half_width;
let y = y_offset;
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&East) {
let x = x_offset + self.room_width;
let y = y_offset + half_height;
map.set_tile(x as usize, y as usize, Tile::floor());
}
if field.has_passage(&West) {
let x = x_offset;
let y = y_offset + half_height;
map.set_tile(x as usize, y as usize, Tile::floor());
}
}
}
}
map.starting_point = Some(here_be_dragons::geometry::Point::new(
maze.start.x as usize + 1,
maze.start.y as usize + 1,
));
map.exit_point = Some(here_be_dragons::geometry::Point::new(
(maze.goal.x as usize) * self.room_width + half_width,
(maze.goal.y as usize) * self.room_height + half_height,
));
}
map.starting_point = Some(here_be_dragons::geometry::Point::new(
maze.start.x as usize + 1,
maze.start.y as usize + 1,
));
map.exit_point = Some(here_be_dragons::geometry::Point::new(
(maze.goal.x as usize) * self.room_width + half_width,
(maze.goal.y as usize) * self.room_height + half_height,
));
map
}
}