Scatter changes and fixes

This commit is contained in:
Michal Sroczynski 2023-08-02 09:19:16 +02:00 committed by Isse
parent 2c23781d22
commit 1301761445
3 changed files with 34 additions and 26 deletions

View File

@ -65,7 +65,7 @@ pub const CONFIG: Config = Config {
tropical_temp: 0.4,
desert_temp: 0.8,
// humidity
desert_hum: 0.15,
desert_hum: 0.0,
forest_hum: 0.5,
jungle_hum: 0.75,
// water

View File

@ -29,6 +29,7 @@ pub fn density_factor_by_altitude(lower_limit: f32, altitude: f32, upper_limit:
const MUSH_FACT: f32 = 1.0e-4; // To balance things around the mushroom spawning rate
const GRASS_FACT: f32 = 1.0e-3; // To balance things around the grass spawning rate
const TREE_FACT: f32 = 0.15e-3; // To balance things around the wood spawning rate
const DEPTH_WATER_NORM: f32 = 15.0; // Water depth at which regular underwater sprites start spawning
pub fn apply_scatter_to(canvas: &mut Canvas, _rng: &mut impl Rng, calendar: Option<&Calendar>) {
enum WaterMode {
@ -312,7 +313,7 @@ pub fn apply_scatter_to(canvas: &mut Canvas, _rng: &mut impl Rng, calendar: Opti
permit: |b| matches!(b, BlockKind::Grass),
f: |_, col| {
(
(col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0) * 0.75e-3,
(col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0) * TREE_FACT * 5.0,
None,
)
},
@ -324,7 +325,7 @@ pub fn apply_scatter_to(canvas: &mut Canvas, _rng: &mut impl Rng, calendar: Opti
permit: |b| matches!(b, BlockKind::Grass),
f: |_, col| {
(
(col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0) * 0.15e-3,
(col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0) * TREE_FACT,
None,
)
},
@ -335,39 +336,34 @@ pub fn apply_scatter_to(canvas: &mut Canvas, _rng: &mut impl Rng, calendar: Opti
permit: |b| matches!(b, BlockKind::Grass),
f: |_, col| {
(
close(col.temp, CONFIG.tropical_temp + 0.1, 0.3).min(close(
((close(col.temp, CONFIG.tropical_temp + 0.1, 0.3).min(close(
col.humidity,
CONFIG.jungle_hum,
0.4,
)) * (col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0)
* 0.15e-3,
None,
)
},
},
ScatterConfig {
kind: Ironwood,
water_mode: Ground,
permit: |b| matches!(b, BlockKind::Grass),
f: |_, col| {
(
close(col.temp, CONFIG.desert_temp, 0.25).min(close(
col.humidity,
CONFIG.desert_hum,
0.1,
)) * MUSH_FACT
* 0.5,
)) > 0.0) as i32) as f32
* (col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0)
* TREE_FACT
* 0.75,
None,
)
},
},
// This is just a placeholder for future biomes
// Currently Ironwood has been included in the world\src\site2\plot\giant_tree.rs
// ScatterConfig {
// kind: Ironwood,
// water_mode: Ground,
// permit: |b| matches!(b, BlockKind::Wood | BlockKind::Grass),
// f: |_, col| {
// },
// },
ScatterConfig {
kind: Frostwood,
water_mode: Ground,
permit: |b| matches!(b, BlockKind::Snow | BlockKind::Ice),
f: |_, col| {
(
(col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0) * 0.06e-3,
(col.tree_density * 1.25 - 0.25).powf(0.5).max(0.0) * TREE_FACT * 0.5,
None,
)
},
@ -606,7 +602,7 @@ pub fn apply_scatter_to(canvas: &mut Canvas, _rng: &mut impl Rng, calendar: Opti
CONFIG.desert_hum,
0.1,
)) * MUSH_FACT
* 0.25,
* 0.1,
None,
)
},

View File

@ -3,7 +3,7 @@ use crate::{
site::namegen::NameGen,
site2::{Fill, Painter, Site, Structure},
util::FastNoise,
Land, Sampler,
Land, Sampler, SpriteKind,
};
use common::{
generation::EntityInfo,
@ -120,7 +120,19 @@ impl Structure for GiantTree {
.fill(Fill::Block(Block::new(
BlockKind::Leaves,
leaf_col.map(|e| e as u8),
)))
)));
// Calculate direction of the branch
let branch_start = branch.get_line().start;
let branch_end = branch.get_line().end;
let branch_direction = (branch_end - branch_start).normalized();
// Generate a sprite at the surface of the leafy part of the branch
let displacement =
(branch_direction * branch.get_leaf_radius()).map(|e| e.round() as i32);
let pos = self.wpos + branch_end.as_() + displacement;
if rand::thread_rng().gen_range(0..100) < 7 {
painter.sprite(pos.map(|e| e as i32), SpriteKind::Ironwood);
}
}
true
} else {