Conversion to struct to please clippy

This commit is contained in:
Monty Marz 2020-11-21 13:33:52 +01:00 committed by Snowram
parent a939eac30d
commit 8235e94aa4
3 changed files with 144 additions and 135 deletions

View File

@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Made settings less likely to reset when the format changes - Made settings less likely to reset when the format changes
- Adjusted some keybindings - Adjusted some keybindings
- Consumables can now trigger multiple effects and buffs - Consumables can now trigger multiple effects and buffs
- Overhauled overworld spawns depending on chunk attributes
### Removed ### Removed

View File

@ -1569,13 +1569,8 @@ fn handle_debug_column(
let sampler = server.world.sample_columns(); let sampler = server.world.sample_columns();
let mut wpos = Vec2::new(0, 0); let mut wpos = Vec2::new(0, 0);
if let Ok((x, y)) = scan_fmt!(&args, &action.arg_fmt(), i32, i32) { if let Ok((x, y)) = scan_fmt!(&args, &action.arg_fmt(), i32, i32) {
//match server.state.read_component_copied::<comp::Pos>(target)
wpos = Vec2::new(x, y); wpos = Vec2::new(x, y);
} } else {
/* let chunk_pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| {
e / sz as i32
}); */
else {
match server.state.read_component_copied::<comp::Pos>(target) { match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => wpos = pos.0.xy().map(|x| x as i32), Some(pos) => wpos = pos.0.xy().map(|x| x as i32),
None => server.notify_client( None => server.notify_client(
@ -1585,7 +1580,6 @@ fn handle_debug_column(
} }
} }
let msg_generator = || { let msg_generator = || {
// let sim_chunk = sim.get(chunk_pos)?;
let alt = sim.get_interpolated(wpos, |chunk| chunk.alt)?; let alt = sim.get_interpolated(wpos, |chunk| chunk.alt)?;
let basement = sim.get_interpolated(wpos, |chunk| chunk.basement)?; let basement = sim.get_interpolated(wpos, |chunk| chunk.basement)?;
let water_alt = sim.get_interpolated(wpos, |chunk| chunk.water_alt)?; let water_alt = sim.get_interpolated(wpos, |chunk| chunk.water_alt)?;

View File

@ -26,15 +26,17 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
chunk: &SimChunk, chunk: &SimChunk,
supplement: &mut ChunkSupplement, supplement: &mut ChunkSupplement,
) { ) {
let scatter: &[( struct Entry<R> {
fn(Vec3<f32>, &mut R) -> EntityInfo, // Entity make_entity: fn(Vec3<f32>, &mut R) -> EntityInfo, // Entity
Range<usize>, // Group size range group_size: Range<usize>, // Group size range
bool, // Underwater? is_underwater: bool, // Underwater?
fn(&SimChunk, &ColumnSample) -> f32, // Density get_density: fn(&SimChunk, &ColumnSample) -> f32, // Density
)] = &[ }
let scatter: &[Entry<R>] = &[
// Tundra pack ennemies // Tundra pack ennemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 3) { .with_body(match rng.gen_range(0, 3) {
0 => quadruped_medium::Body::random_with( 0 => quadruped_medium::Body::random_with(
@ -55,26 +57,26 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..4, group_size: 1..4,
false, is_underwater: false,
|c, _col| close(c.temp, CONFIG.snow_temp, 0.3) * BASE_DENSITY * 1.0, get_density: |c, _col| close(c.temp, CONFIG.snow_temp, 0.3) * BASE_DENSITY * 1.0,
), },
// Tundra rare solitary ennemies // Tundra rare solitary ennemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body( .with_body(
biped_large::Body::random_with(rng, &biped_large::Species::Wendigo).into(), biped_large::Body::random_with(rng, &biped_large::Species::Wendigo).into(),
) )
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| close(c.temp, CONFIG.snow_temp, 0.15) * BASE_DENSITY * 0.1, get_density: |c, _col| close(c.temp, CONFIG.snow_temp, 0.15) * BASE_DENSITY * 0.1,
), },
// Taiga pack ennemies // Taiga pack ennemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body( .with_body(
quadruped_medium::Body::random_with(rng, &quadruped_medium::Species::Wolf) quadruped_medium::Body::random_with(rng, &quadruped_medium::Species::Wolf)
@ -82,15 +84,15 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
) )
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
3..8, group_size: 3..8,
false, is_underwater: false,
|c, col| { get_density: |c, col| {
close(c.temp, CONFIG.snow_temp + 0.2, 0.6) * col.tree_density * BASE_DENSITY * 1.0 close(c.temp, CONFIG.snow_temp + 0.2, 0.6) * col.tree_density * BASE_DENSITY * 1.0
}, },
), },
// Taiga pack wild // Taiga pack wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body( .with_body(
quadruped_medium::Body::random_with( quadruped_medium::Body::random_with(
@ -101,13 +103,13 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
) )
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..4, group_size: 1..4,
false, is_underwater: false,
|c, _col| close(c.temp, CONFIG.snow_temp + 0.2, 0.2) * BASE_DENSITY * 1.0, get_density: |c, _col| close(c.temp, CONFIG.snow_temp + 0.2, 0.2) * BASE_DENSITY * 1.0,
), },
// Taiga solitary wild // Taiga solitary wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 5) { .with_body(match rng.gen_range(0, 5) {
0 => { 0 => {
@ -130,13 +132,13 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| close(c.temp, CONFIG.snow_temp + 0.2, 0.6) * BASE_DENSITY * 5.0, get_density: |c, _col| close(c.temp, CONFIG.snow_temp + 0.2, 0.6) * BASE_DENSITY * 5.0,
), },
// Temperate pack ennemies // Temperate pack ennemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 2) { .with_body(match rng.gen_range(0, 2) {
0 => quadruped_medium::Body::random_with( 0 => quadruped_medium::Body::random_with(
@ -152,13 +154,13 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| close(c.temp, CONFIG.temperate_temp, 0.35) * BASE_DENSITY * 1.0, get_density: |c, _col| close(c.temp, CONFIG.temperate_temp, 0.35) * BASE_DENSITY * 1.0,
), },
// Temperate pack wild // Temperate pack wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 11) { .with_body(match rng.gen_range(0, 11) {
0 => quadruped_medium::Body::random_with( 0 => quadruped_medium::Body::random_with(
@ -212,19 +214,19 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..8, group_size: 1..8,
false, is_underwater: false,
|c, _col| { get_density: |c, _col| {
close(c.temp, CONFIG.temperate_temp, 0.5) close(c.temp, CONFIG.temperate_temp, 0.5)
* close(c.humidity, CONFIG.forest_hum, 0.4) * close(c.humidity, CONFIG.forest_hum, 0.4)
//* col.tree_density //* col.tree_density
* BASE_DENSITY * BASE_DENSITY
* 4.0 * 4.0
}, },
), },
// Temperate solitary wild // Temperate solitary wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 15) { .with_body(match rng.gen_range(0, 15) {
0 => quadruped_small::Body { 0 => quadruped_small::Body {
@ -297,18 +299,18 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| { get_density: |c, _col| {
close(c.temp, CONFIG.temperate_temp, 0.5) close(c.temp, CONFIG.temperate_temp, 0.5)
* BASE_DENSITY * BASE_DENSITY
* close(c.humidity, CONFIG.forest_hum, 0.4) * close(c.humidity, CONFIG.forest_hum, 0.4)
* 8.0 * 8.0
}, },
), },
// Rare temperate solitary enemies // Rare temperate solitary enemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 4) { .with_body(match rng.gen_range(0, 4) {
0 => { 0 => {
@ -324,13 +326,13 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| close(c.temp, CONFIG.temperate_temp, 0.8) * BASE_DENSITY * 0.1, get_density: |c, _col| close(c.temp, CONFIG.temperate_temp, 0.8) * BASE_DENSITY * 0.1,
), },
// Temperate river wildlife // Temperate river wildlife
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 3) { .with_body(match rng.gen_range(0, 3) {
0 => quadruped_small::Body::random_with( 0 => quadruped_small::Body::random_with(
@ -349,9 +351,9 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|_c, col| { get_density: |_c, col| {
close(col.temp, CONFIG.temperate_temp, 0.6) close(col.temp, CONFIG.temperate_temp, 0.6)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) { * if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.003 0.003
@ -359,10 +361,10 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
0.0 0.0
} }
}, },
), },
// Temperate river ennemies // Temperate river ennemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body( .with_body(
quadruped_low::Body::random_with(rng, &quadruped_low::Species::Hakulaq) quadruped_low::Body::random_with(rng, &quadruped_low::Species::Hakulaq)
@ -370,9 +372,9 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
) )
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|_c, col| { get_density: |_c, col| {
close(col.temp, CONFIG.temperate_temp, 0.6) close(col.temp, CONFIG.temperate_temp, 0.6)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) { * if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.0001 0.0001
@ -380,10 +382,10 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
0.0 0.0
} }
}, },
), },
// Tropical rock solitary ennemies // Tropical rock solitary ennemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body( .with_body(
quadruped_small::Body::random_with( quadruped_small::Body::random_with(
@ -394,13 +396,15 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
) )
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, col| close(c.temp, CONFIG.tropical_temp + 0.1, 0.5) * col.rock * BASE_DENSITY * 5.0, get_density: |c, col| {
), close(c.temp, CONFIG.tropical_temp + 0.1, 0.5) * col.rock * BASE_DENSITY * 5.0
},
},
// Jungle solitary ennemies // Jungle solitary ennemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 3) { .with_body(match rng.gen_range(0, 3) {
0 => { 0 => {
@ -420,18 +424,18 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| { get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp + 0.1, 0.4) close(c.temp, CONFIG.tropical_temp + 0.1, 0.4)
* close(c.humidity, CONFIG.jungle_hum, 0.3) * close(c.humidity, CONFIG.jungle_hum, 0.3)
* BASE_DENSITY * BASE_DENSITY
* 4.0 * 4.0
}, },
), },
// Jungle solitary wild // Jungle solitary wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 3) { .with_body(match rng.gen_range(0, 3) {
0 => bird_medium::Body::random_with(rng, &bird_medium::Species::Parrot) 0 => bird_medium::Body::random_with(rng, &bird_medium::Species::Parrot)
@ -447,18 +451,18 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| { get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp, 0.5) close(c.temp, CONFIG.tropical_temp, 0.5)
* close(c.humidity, CONFIG.jungle_hum, 0.3) * close(c.humidity, CONFIG.jungle_hum, 0.3)
* BASE_DENSITY * BASE_DENSITY
* 8.0 * 8.0
}, },
), },
// Tropical rare river enemy // Tropical rare river enemy
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 2) { .with_body(match rng.gen_range(0, 2) {
// WE GROW 'EM BIG 'ERE // WE GROW 'EM BIG 'ERE
@ -475,9 +479,9 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..3, group_size: 1..3,
false, is_underwater: false,
|_c, col| { get_density: |_c, col| {
close(col.temp, CONFIG.tropical_temp + 0.2, 0.5) close(col.temp, CONFIG.tropical_temp + 0.2, 0.5)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) { * if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.0002 0.0002
@ -485,10 +489,10 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
0.0 0.0
} }
}, },
), },
// Tropical rare river wild // Tropical rare river wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 3) { .with_body(match rng.gen_range(0, 3) {
0 => { 0 => {
@ -508,9 +512,9 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..3, group_size: 1..3,
false, is_underwater: false,
|_c, col| { get_density: |_c, col| {
close(col.temp, CONFIG.tropical_temp, 0.5) close(col.temp, CONFIG.tropical_temp, 0.5)
* if col.water_dist.map(|d| d < 10.0).unwrap_or(false) { * if col.water_dist.map(|d| d < 10.0).unwrap_or(false) {
0.001 0.001
@ -518,10 +522,10 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
0.0 0.0
} }
}, },
), },
// Tropical pack enemies // Tropical pack enemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 2) { .with_body(match rng.gen_range(0, 2) {
0 => quadruped_medium::Body::random_with( 0 => quadruped_medium::Body::random_with(
@ -537,18 +541,18 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..3, group_size: 1..3,
false, is_underwater: false,
|c, _col| { get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp + 0.1, 0.4) close(c.temp, CONFIG.tropical_temp + 0.1, 0.4)
* close(c.humidity, CONFIG.desert_hum, 0.4) * close(c.humidity, CONFIG.desert_hum, 0.4)
* BASE_DENSITY * BASE_DENSITY
* 2.0 * 2.0
}, },
), },
// Desert pack wild // Desert pack wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body( .with_body(
quadruped_medium::Body::random_with( quadruped_medium::Body::random_with(
@ -559,18 +563,18 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
) )
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
3..8, group_size: 3..8,
false, is_underwater: false,
|c, _col| { get_density: |c, _col| {
close(c.temp, CONFIG.tropical_temp + 0.1, 0.4) close(c.temp, CONFIG.tropical_temp + 0.1, 0.4)
* close(c.humidity, CONFIG.desert_hum, 0.4) * close(c.humidity, CONFIG.desert_hum, 0.4)
* BASE_DENSITY * BASE_DENSITY
* 1.0 * 1.0
}, },
), },
// Desert solitary enemies // Desert solitary enemies
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 2) { .with_body(match rng.gen_range(0, 2) {
0 => quadruped_medium::Body::random_with( 0 => quadruped_medium::Body::random_with(
@ -586,18 +590,18 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Enemy) .with_alignment(Alignment::Enemy)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| { get_density: |c, _col| {
close(c.temp, CONFIG.desert_temp + 0.2, 0.3) close(c.temp, CONFIG.desert_temp + 0.2, 0.3)
* close(c.humidity, CONFIG.desert_hum, 0.5) * close(c.humidity, CONFIG.desert_hum, 0.5)
* BASE_DENSITY * BASE_DENSITY
* 1.5 * 1.5
}, },
), },
// Desert solitary wild // Desert solitary wild
( Entry {
|pos, rng| { make_entity: |pos, rng| {
EntityInfo::at(pos) EntityInfo::at(pos)
.with_body(match rng.gen_range(0, 5) { .with_body(match rng.gen_range(0, 5) {
0 => quadruped_small::Body::random_with( 0 => quadruped_small::Body::random_with(
@ -627,10 +631,12 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
}) })
.with_alignment(Alignment::Wild) .with_alignment(Alignment::Wild)
}, },
1..2, group_size: 1..2,
false, is_underwater: false,
|c, _col| close(c.temp, CONFIG.desert_temp + 0.2, 0.3) * BASE_DENSITY * 5.0, get_density: |c, _col| {
), close(c.temp, CONFIG.desert_temp + 0.2, 0.3) * BASE_DENSITY * 5.0
},
},
]; ];
for y in 0..vol.size_xy().y as i32 { for y in 0..vol.size_xy().y as i32 {
@ -649,8 +655,16 @@ pub fn apply_wildlife_supplement<'a, R: Rng>(
let underwater = col_sample.water_level > col_sample.alt; let underwater = col_sample.water_level > col_sample.alt;
let entity_group = scatter.iter().enumerate().find_map( let entity_group = scatter.iter().enumerate().find_map(
|(_i, (make_entity, group_size, is_underwater, f))| { |(
let density = f(chunk, col_sample); _i,
Entry {
make_entity,
group_size,
is_underwater,
get_density,
},
)| {
let density = get_density(chunk, col_sample);
if density > 0.0 if density > 0.0
&& dynamic_rng.gen::<f32>() < density && dynamic_rng.gen::<f32>() < density
&& underwater == *is_underwater && underwater == *is_underwater