veloren_world/site/plot/
rock_circle.rs1use super::*;
2use crate::{
3 Land,
4 assets::AssetHandle,
5 site::generation::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 = "dyn-lib")]
35 #[unsafe(export_name = "as_dyn_structure_rockcircle")]
36 fn as_dyn_outer(&self) -> Option<(&dyn Structure, &'static str)> {
37 Some((Self::as_dyn_impl(self), "as_dyn_structure_rockcircle"))
38 }
39
40 fn render_inner(&self, _site: &Site, land: &Land, painter: &Painter) {
41 let center = self.bounds.center();
42 let base = land.get_alt_approx(center) as i32;
43 let mut rng = rand::rng();
44 let model_pos = center.with_z(base);
45 lazy_static! {
47 pub static ref MODEL: AssetHandle<StructuresGroup> =
48 PrefabStructure::load_group("site_structures.rock_circle.rock_circle");
49 }
50 let rng_val = RandomField::new(0).get(model_pos) % 10;
51 let model = MODEL.read();
52 let model = model[rng_val as usize % model.len()].clone();
53 painter
54 .prim(Primitive::Prefab(Box::new(model.clone())))
55 .translate(model_pos)
56 .fill(Fill::Prefab(Box::new(model), model_pos, rng_val));
57
58 if rng.random_range(0..=8) < 1 {
60 painter.spawn(
62 EntityInfo::at(center.with_z(base + 2).as_()).with_asset_expect(
63 "common.entity.wild.aggressive.dullahan",
64 &mut rng,
65 None,
66 ),
67 )
68 }
69 }
70}