flipping vaults

This commit is contained in:
Llywelwyn 2023-07-21 13:35:17 +01:00
parent d1f36499c2
commit 8a5600267c
2 changed files with 71 additions and 7 deletions

View file

@ -188,6 +188,31 @@ impl PrefabBuilder {
(rng.roll_dice(1, possible_vaults.len() as i32) - 1) as usize (rng.roll_dice(1, possible_vaults.len() as i32) - 1) as usize
}; };
let vault = possible_vaults[vault_idx]; let vault = possible_vaults[vault_idx];
// Decide if we want to flip the vault
let mut flip_x: bool = false;
let mut flip_y: bool = false;
match vault.can_flip {
// Equal chance at every orientation
Flipping::None => {}
Flipping::Horizontal => {
flip_x = rng.roll_dice(1, 2) == 1;
}
Flipping::Vertical => {
flip_y = rng.roll_dice(1, 2) == 1;
}
Flipping::Both => {
let roll = rng.roll_dice(1, 4);
match roll {
1 => {}
2 => flip_x = true,
3 => flip_y = true,
_ => {
flip_x = true;
flip_y = true;
}
}
}
}
// Make a list of all places the vault can fit // Make a list of all places the vault can fit
let mut vault_positions: Vec<Position> = Vec::new(); let mut vault_positions: Vec<Position> = Vec::new();
@ -248,7 +273,16 @@ impl PrefabBuilder {
let mut i = 0; let mut i = 0;
for tile_y in 0..vault.height { for tile_y in 0..vault.height {
for tile_x in 0..vault.width { for tile_x in 0..vault.width {
let idx = self.map.xy_idx(tile_x as i32 + chunk_x, tile_y as i32 + chunk_y); let mut x_: i32 = tile_x as i32;
let mut y_: i32 = tile_y as i32;
// Handle flipping
if flip_x {
x_ = vault.height as i32 - 1 - x_;
}
if flip_y {
y_ = vault.width as i32 - 1 - y_;
}
self.map.xy_idx(x_ + chunk_x, y_ as i32 + chunk_y);
self.char_to_map(string_vec[i], idx); self.char_to_map(string_vec[i], idx);
used_tiles.insert(idx); used_tiles.insert(idx);
i += 1; i += 1;
@ -348,6 +382,9 @@ impl PrefabBuilder {
for x in 0..layer.width { for x in 0..layer.width {
let cell = layer.get(x, y).unwrap(); let cell = layer.get(x, y).unwrap();
if x < self.map.width as usize && y < self.map.height as usize { if x < self.map.width as usize && y < self.map.height as usize {
// Saving these for later, for flipping the pref horizontally/vertically/both.
// let flipped_x = (self.map.width - 1) - x as i32;
// let flipped_y = (self.map.height - 1) - y as i32;
let idx = self.map.xy_idx(x as i32, y as i32); let idx = self.map.xy_idx(x as i32, y as i32);
// We're doing some nasty casting to make it easier to type things like '#' in the match // We're doing some nasty casting to make it easier to type things like '#' in the match
self.char_to_map(cell.ch as u8 as char, idx); self.char_to_map(cell.ch as u8 as char, idx);

View file

@ -1,16 +1,31 @@
#[allow(dead_code)] #[allow(dead_code)]
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
pub enum Flipping {
None,
Horizontal,
Vertical,
Both,
}
#[allow(dead_code)]
#[derive(PartialEq, Copy, Clone)]
pub struct PrefabVault { pub struct PrefabVault {
pub template: &'static str, pub template: &'static str,
pub width: usize, pub width: usize,
pub height: usize, pub height: usize,
pub first_depth: i32, pub first_depth: i32,
pub last_depth: i32, pub last_depth: i32,
pub can_flip: Flipping,
} }
#[allow(dead_code)] #[allow(dead_code)]
pub const CLASSIC_TRAP_5X5: PrefabVault = pub const CLASSIC_TRAP_5X5: PrefabVault = PrefabVault {
PrefabVault { template: CLASSIC_TRAP_5X5_V, width: 5, height: 5, first_depth: 0, last_depth: 100 }; template: CLASSIC_TRAP_5X5_V,
width: 5,
height: 5,
first_depth: 0,
last_depth: 100,
can_flip: Flipping::None,
};
#[allow(dead_code)] #[allow(dead_code)]
const CLASSIC_TRAP_5X5_V: &str = " const CLASSIC_TRAP_5X5_V: &str = "
@ -21,8 +36,14 @@ const CLASSIC_TRAP_5X5_V: &str = "
"; ";
#[allow(dead_code)] #[allow(dead_code)]
pub const GOBLINS_4X4: PrefabVault = pub const GOBLINS_4X4: PrefabVault = PrefabVault {
PrefabVault { template: GOBLINS_4X4_V, width: 4, height: 4, first_depth: 0, last_depth: 100 }; template: GOBLINS_4X4_V,
width: 4,
height: 4,
first_depth: 0,
last_depth: 100,
can_flip: Flipping::Both,
};
const GOBLINS_4X4_V: &str = " const GOBLINS_4X4_V: &str = "
#^   #^  
#G# #G#
@ -31,8 +52,14 @@ const GOBLINS_4X4_V: &str = "
"; ";
#[allow(dead_code)] #[allow(dead_code)]
pub const GOBLINS2_4X4: PrefabVault = pub const GOBLINS2_4X4: PrefabVault = PrefabVault {
PrefabVault { template: GOBLINS2_4X4_V, width: 4, height: 4, first_depth: 0, last_depth: 100 }; template: GOBLINS2_4X4_V,
width: 4,
height: 4,
first_depth: 0,
last_depth: 100,
can_flip: Flipping::Both,
};
const GOBLINS2_4X4_V: &str = " const GOBLINS2_4X4_V: &str = "
#^#g #^#g
G# # G# #