Biome improvements

This commit is contained in:
Joshua Barretto 2022-06-28 07:52:46 +01:00
parent c6564e2c59
commit 418839ee20

View File

@ -76,13 +76,14 @@ pub fn surface_entrances<'a>(land: &'a Land) -> impl Iterator<Item = Vec2<i32>>
.filter_map(|cell| { .filter_map(|cell| {
let tunnel = tunnels_below_from_cell(cell, 0, land)?; let tunnel = tunnels_below_from_cell(cell, 0, land)?;
// Hacky, moves the entrance position closer to the actual entrance // Hacky, moves the entrance position closer to the actual entrance
Some(Lerp::lerp(tunnel.a.wpos.xy(), tunnel.b.wpos.xy(), 0.25)) Some(Lerp::lerp(tunnel.a.wpos.xy(), tunnel.b.wpos.xy(), 0.125))
}) })
} }
struct Tunnel { struct Tunnel {
a: Node, a: Node,
b: Node, b: Node,
curve: f32,
} }
fn tunnels_at<'a>( fn tunnels_at<'a>(
@ -113,6 +114,9 @@ fn tunnels_at<'a>(
.map(move |(other_cell_pos, other_cell)| Tunnel { .map(move |(other_cell_pos, other_cell)| Tunnel {
a: current_cell, a: current_cell,
b: other_cell, b: other_cell,
curve: RandomField::new(13)
.get_f32(current_cell.wpos.xy().with_z(0))
.powf(0.25) as f32,
}) })
}) })
} }
@ -126,6 +130,7 @@ fn tunnels_below_from_cell(cell: Vec2<i32>, level: u32, land: &Land) -> Option<T
level + 1, level + 1,
land, land,
)?, )?,
curve: 0.0,
}) })
} }
@ -150,29 +155,25 @@ pub fn apply_caves_to(canvas: &mut Canvas, rng: &mut impl Rng) {
for level in 1..4 { for level in 1..4 {
let rand = RandomField::new(37 + level); let rand = RandomField::new(37 + level);
let tunnel_bounds = tunnels_at(wpos2d, level, &land) let tunnel_bounds = tunnels_at(wpos2d, level, &land)
.chain(tunnels_down_from(wpos2d, level, &land)) .chain(tunnels_down_from(wpos2d, level - 1, &land))
.filter_map(|tunnel| { .filter_map(|tunnel| {
let start = tunnel.a.wpos.xy().map(|e| e as f64 + 0.5); let start = tunnel.a.wpos.xy().map(|e| e as f64 + 0.5);
let end = tunnel.b.wpos.xy().map(|e| e as f64 + 0.5); let end = tunnel.b.wpos.xy().map(|e| e as f64 + 0.5);
let dist = LineSegment2 { start, end } let dist = LineSegment2 { start, end }
.distance_to_point(wpos2d.map(|e| e as f64 + 0.5)); .distance_to_point(wpos2d.map(|e| e as f64 + 0.5));
let curve = ( let curve_dir =
RandomField::new(13)
.get_f32(tunnel.a.wpos.xy().with_z(0))
.powf(0.25) as f64,
(RandomField::new(14).get_f32(tunnel.a.wpos.xy().with_z(0)) as f64 - 0.5) (RandomField::new(14).get_f32(tunnel.a.wpos.xy().with_z(0)) as f64 - 0.5)
.signum(), .signum();
);
if let Some((t, closest, _)) = quadratic_nearest_point( if let Some((t, closest, _)) = quadratic_nearest_point(
&river_spline_coeffs( &river_spline_coeffs(
start, start,
((end - start) * 0.5 ((end - start) * 0.5
+ ((end - start) * 0.5).rotated_z(PI / 2.0) + ((end - start) * 0.5).rotated_z(PI / 2.0)
* 4.0 * 6.0
* curve.0 * tunnel.curve as f64
* curve.1) * curve_dir)
.map(|e| e as f32), .map(|e| e as f32),
end, end,
), ),
@ -316,7 +317,7 @@ fn write_column(
let underground = ((col.alt as f32 - z_range.end as f32) / 80.0).clamped(0.0, 1.0); let underground = ((col.alt as f32 - z_range.end as f32) / 80.0).clamped(0.0, 1.0);
let mushroom_glow = let mushroom_glow =
underground * close(biome.humidity, 1.0, 0.6) * close(biome.temp, 0.25, 0.7); underground * close(biome.humidity, 1.0, 0.5) * close(biome.temp, 0.25, 0.7);
let dirt = if exposed { 0 } else { 1 }; let dirt = if exposed { 0 } else { 1 };
let bedrock = z_range.start + lava as i32; let bedrock = z_range.start + lava as i32;
@ -365,6 +366,24 @@ fn write_column(
SpriteKind::CavernGrassBlueShort, SpriteKind::CavernGrassBlueShort,
SpriteKind::CavernGrassBlueMedium, SpriteKind::CavernGrassBlueMedium,
SpriteKind::CavernGrassBlueLong, SpriteKind::CavernGrassBlueLong,
SpriteKind::Mushroom,
]
.choose(rng)
.unwrap(),
)
} else if rand.chance(
wpos2d.with_z(1),
close(biome.humidity, 1.0, 0.5) * close(biome.temp, 0.0, 1.25) * 0.05,
) {
Some(
*[
SpriteKind::JungleFern,
SpriteKind::JungleLeafyPlant,
SpriteKind::JungleRedGrass,
SpriteKind::Mushroom,
SpriteKind::EnsnaringVines,
SpriteKind::Fern,
SpriteKind::LeafyPlant,
] ]
.choose(rng) .choose(rng)
.unwrap(), .unwrap(),
@ -374,6 +393,39 @@ fn write_column(
close(biome.humidity, 0.0, 0.5) * biome.mineral * 0.005, close(biome.humidity, 0.0, 0.5) * biome.mineral * 0.005,
) { ) {
Some(SpriteKind::CrystalLow) Some(SpriteKind::CrystalLow)
} else if rand.chance(wpos2d.with_z(2), close(biome.temp, 1.5, 0.75) * 0.001) {
Some(SpriteKind::Pyrebloom)
} else if rand.chance(wpos2d.with_z(2), close(biome.mineral, 1.0, 0.5) * 0.001)
{
Some(
*[
SpriteKind::Velorite,
SpriteKind::VeloriteFrag,
SpriteKind::AmethystSmall,
SpriteKind::TopazSmall,
SpriteKind::DiamondSmall,
SpriteKind::RubySmall,
SpriteKind::EmeraldSmall,
SpriteKind::SapphireSmall,
]
.choose(rng)
.unwrap(),
)
} else if rand.chance(
wpos2d.with_z(2),
close(biome.humidity, 0.0, 0.65) * close(biome.temp, -0.25, 1.25) * 0.008,
) {
Some(
*[
SpriteKind::Bones,
SpriteKind::Stones,
SpriteKind::DeadBush,
SpriteKind::EnsnaringWeb,
SpriteKind::Mud,
]
.choose(rng)
.unwrap(),
)
} else { } else {
None None
} }
@ -385,9 +437,13 @@ fn write_column(
.then(|| { .then(|| {
if rand.chance(wpos2d.with_z(3), mushroom_glow * 0.02) { if rand.chance(wpos2d.with_z(3), mushroom_glow * 0.02) {
Some( Some(
*[SpriteKind::CavernMycelBlue, SpriteKind::CeilingMushroom] *[
.choose(rng) SpriteKind::CavernMycelBlue,
.unwrap(), SpriteKind::CeilingMushroom,
SpriteKind::Liana,
]
.choose(rng)
.unwrap(),
) )
} else if rand.chance(wpos2d.with_z(4), 0.0075) { } else if rand.chance(wpos2d.with_z(4), 0.0075) {
Some( Some(