mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Site2 giant tree entity spawning
This commit is contained in:
parent
ff34891665
commit
3027597352
@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Improved site placement
|
- Improved site placement
|
||||||
- [Server] Kick clients who send messages on the wrong stream
|
- [Server] Kick clients who send messages on the wrong stream
|
||||||
- Reworked Merchant trade price calculation, Merchants offer more wares
|
- Reworked Merchant trade price calculation, Merchants offer more wares
|
||||||
|
- Enable new giant trees, changed what entities spawn at them
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -11,6 +11,6 @@
|
|||||||
paths: true,
|
paths: true,
|
||||||
spots: true,
|
spots: true,
|
||||||
site2_towns: true,
|
site2_towns: true,
|
||||||
site2_giant_trees: false,
|
site2_giant_trees: true,
|
||||||
wildlife_density: 1.0,
|
wildlife_density: 1.0,
|
||||||
)
|
)
|
||||||
|
@ -1029,7 +1029,7 @@ impl Site {
|
|||||||
let info = canvas.info();
|
let info = canvas.info();
|
||||||
|
|
||||||
for plot in plots_to_render {
|
for plot in plots_to_render {
|
||||||
let (prim_tree, fills, entities) = match &self.plots[plot].kind {
|
let (prim_tree, fills, mut entities) = match &self.plots[plot].kind {
|
||||||
PlotKind::House(house) => house.render_collect(self, canvas),
|
PlotKind::House(house) => house.render_collect(self, canvas),
|
||||||
PlotKind::Workshop(workshop) => workshop.render_collect(self, canvas),
|
PlotKind::Workshop(workshop) => workshop.render_collect(self, canvas),
|
||||||
PlotKind::Castle(castle) => castle.render_collect(self, canvas),
|
PlotKind::Castle(castle) => castle.render_collect(self, canvas),
|
||||||
@ -1040,9 +1040,14 @@ impl Site {
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
for entity in entities {
|
let mut spawn = |pos, last_block| {
|
||||||
canvas.spawn(entity);
|
if let Some(entity) = match &self.plots[plot].kind {
|
||||||
}
|
PlotKind::GiantTree(tree) => tree.entity_at(pos, &last_block, dynamic_rng),
|
||||||
|
_ => None,
|
||||||
|
} {
|
||||||
|
entities.push(entity);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for (prim, fill) in fills {
|
for (prim, fill) in fills {
|
||||||
for mut aabb in Fill::get_bounds_disjoint(&prim_tree, prim) {
|
for mut aabb in Fill::get_bounds_disjoint(&prim_tree, prim) {
|
||||||
@ -1062,19 +1067,31 @@ impl Site {
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let mut last_block = None;
|
||||||
for z in aabb.min.z..aabb.max.z {
|
for z in aabb.min.z..aabb.max.z {
|
||||||
let pos = Vec3::new(x, y, z);
|
let pos = Vec3::new(x, y, z);
|
||||||
|
|
||||||
canvas.map(pos, |block| {
|
canvas.map(pos, |block| {
|
||||||
fill.sample_at(&prim_tree, prim, pos, &info, block)
|
let current_block =
|
||||||
.unwrap_or(block)
|
fill.sample_at(&prim_tree, prim, pos, &info, block);
|
||||||
|
if let (Some(last_block), None) = (last_block, current_block) {
|
||||||
|
spawn(pos, last_block);
|
||||||
|
}
|
||||||
|
last_block = current_block;
|
||||||
|
current_block.unwrap_or(block)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if let Some(block) = last_block {
|
||||||
|
spawn(Vec3::new(x, y, aabb.max.z), block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for entity in entities {
|
||||||
|
canvas.spawn(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,10 @@ use crate::{
|
|||||||
util::FastNoise,
|
util::FastNoise,
|
||||||
Land, Sampler,
|
Land, Sampler,
|
||||||
};
|
};
|
||||||
use common::terrain::{Block, BlockKind};
|
use common::{
|
||||||
|
generation::EntityInfo,
|
||||||
|
terrain::{Block, BlockKind},
|
||||||
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -36,6 +39,43 @@ impl GiantTree {
|
|||||||
pub fn radius(&self) -> f32 { 100.0 }
|
pub fn radius(&self) -> f32 { 100.0 }
|
||||||
|
|
||||||
pub fn tree(&self) -> &ProceduralTree { &self.tree }
|
pub fn tree(&self) -> &ProceduralTree { &self.tree }
|
||||||
|
|
||||||
|
pub fn entity_at(
|
||||||
|
&self,
|
||||||
|
pos: Vec3<i32>,
|
||||||
|
above_block: &Block,
|
||||||
|
dynamic_rng: &mut impl Rng,
|
||||||
|
) -> Option<EntityInfo> {
|
||||||
|
if above_block.kind() == BlockKind::Leaves && dynamic_rng.gen_bool(0.001) {
|
||||||
|
let entity = EntityInfo::at(pos.as_());
|
||||||
|
match dynamic_rng.gen_range(0..=4) {
|
||||||
|
0 => {
|
||||||
|
Some(entity.with_asset_expect(
|
||||||
|
"common.entity.wild.aggressive.horn_beetle",
|
||||||
|
dynamic_rng,
|
||||||
|
))
|
||||||
|
},
|
||||||
|
1 => {
|
||||||
|
Some(entity.with_asset_expect(
|
||||||
|
"common.entity.wild.aggressive.stag_beetle",
|
||||||
|
dynamic_rng,
|
||||||
|
))
|
||||||
|
},
|
||||||
|
2 => Some(
|
||||||
|
entity.with_asset_expect("common.entity.wild.aggressive.deadwood", dynamic_rng),
|
||||||
|
),
|
||||||
|
3 => Some(
|
||||||
|
entity.with_asset_expect("common.entity.wild.aggressive.maneater", dynamic_rng),
|
||||||
|
),
|
||||||
|
4 => Some(
|
||||||
|
entity.with_asset_expect("common.entity.wild.peaceful.parrot", dynamic_rng),
|
||||||
|
),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Structure for GiantTree {
|
impl Structure for GiantTree {
|
||||||
|
Loading…
Reference in New Issue
Block a user