veloren_world/site2/plot/
rock_circle.rs1use super::*;
2use crate::{
3 Land,
4 assets::AssetHandle,
5 site2::gen::PrimitiveTransform,
6 util::{RandomField, sampler::Sampler},
7};
8use common::{
9 generation::EntityInfo,
10 terrain::{Structure as PrefabStructure, StructuresGroup},
11};
12use lazy_static::lazy_static;
13use rand::prelude::*;
14use vek::*;
15
16pub struct RockCircle {
17 bounds: Aabr<i32>,
18 pub(crate) alt: i32,
19}
20impl RockCircle {
21 pub fn generate(land: &Land, _rng: &mut impl Rng, site: &Site, tile_aabr: Aabr<i32>) -> Self {
22 let bounds = Aabr {
23 min: site.tile_wpos(tile_aabr.min),
24 max: site.tile_wpos(tile_aabr.max),
25 };
26 Self {
27 bounds,
28 alt: land.get_alt_approx(site.tile_center_wpos(tile_aabr.center())) as i32 + 2,
29 }
30 }
31}
32
33impl Structure for RockCircle {
34 #[cfg(feature = "use-dyn-lib")]
35 const UPDATE_FN: &'static [u8] = b"render_rock_circle\0";
36
37 #[cfg_attr(feature = "be-dyn-lib", export_name = "render_rock_circle")]
38 fn render_inner(&self, _site: &Site, land: &Land, painter: &Painter) {
39 let center = self.bounds.center();
40 let base = land.get_alt_approx(center) as i32;
41 let mut thread_rng = thread_rng();
42 let model_pos = center.with_z(base);
43 lazy_static! {
45 pub static ref MODEL: AssetHandle<StructuresGroup> =
46 PrefabStructure::load_group("site_structures.rock_circle.rock_circle");
47 }
48 let rng = RandomField::new(0).get(model_pos) % 10;
49 let model = MODEL.read();
50 let model = model[rng as usize % model.len()].clone();
51 painter
52 .prim(Primitive::Prefab(Box::new(model.clone())))
53 .translate(model_pos)
54 .fill(Fill::Prefab(Box::new(model), model_pos, rng));
55
56 if thread_rng.gen_range(0..=8) < 1 {
58 painter.spawn(
60 EntityInfo::at(center.with_z(base + 2).as_()).with_asset_expect(
61 "common.entity.wild.aggressive.dullahan",
62 &mut thread_rng,
63 None,
64 ),
65 )
66 }
67 }
68}