veloren_world/site/plot/
pirate_hideout.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 std::f32::consts::TAU;
15use vek::*;
16
17pub struct PirateHideout {
18 bounds: Aabr<i32>,
19 pub(crate) alt: i32,
20}
21impl PirateHideout {
22 pub fn generate(land: &Land, _rng: &mut impl Rng, site: &Site, tile_aabr: Aabr<i32>) -> Self {
23 let bounds = Aabr {
24 min: site.tile_wpos(tile_aabr.min),
25 max: site.tile_wpos(tile_aabr.max),
26 };
27 Self {
28 bounds,
29 alt: land.get_alt_approx(site.tile_center_wpos((tile_aabr.max - tile_aabr.min) / 2))
30 as i32
31 + 2,
32 }
33 }
34}
35
36impl Structure for PirateHideout {
37 #[cfg(feature = "dyn-lib")]
38 #[unsafe(export_name = "as_dyn_structure_piratehideout")]
39 fn as_dyn_outer(&self) -> Option<(&dyn Structure, &'static str)> {
40 Some((Self::as_dyn_impl(self), "as_dyn_structure_piratehideout"))
41 }
42
43 fn render_inner(&self, _site: &Site, land: &Land, painter: &Painter) {
44 let center = self.bounds.center();
45 let base = land.get_alt_approx(center) as i32;
46 let mut rng = rand::rng();
47 let model_pos = center.with_z(base - 2);
48 lazy_static! {
50 pub static ref MODEL: AssetHandle<StructuresGroup> =
51 PrefabStructure::load_group("site_structures.pirate_hideout.pirate_hideout");
52 }
53 let rng_val = RandomField::new(0).get(model_pos) % 10;
54 let model = MODEL.read();
55 let model = model[rng_val as usize % model.len()].clone();
56 painter
57 .prim(Primitive::Prefab(Box::new(model.clone())))
58 .translate(model_pos)
59 .fill(Fill::Prefab(Box::new(model), model_pos, rng_val));
60
61 let npc_radius = 15;
63 let phi = TAU / 2.0;
64 for n in 1..=2 {
65 let npc_pos = Vec2::new(
66 center.x + (npc_radius as f32 * ((n as f32 * phi).cos())) as i32,
67 center.y + (npc_radius as f32 * ((n as f32 * phi).sin())) as i32,
68 );
69
70 match RandomField::new(0).get(npc_pos.with_z(base + 2)) % 2 {
71 0 => painter.spawn(
73 EntityInfo::at(npc_pos.with_z(base).as_()).with_asset_expect(
74 "common.entity.wild.peaceful.rat",
75 &mut rng,
76 None,
77 ),
78 ),
79 _ => painter.spawn(
81 EntityInfo::at(npc_pos.with_z(base).as_()).with_asset_expect(
82 "common.entity.wild.peaceful.parrot",
83 &mut rng,
84 None,
85 ),
86 ),
87 }
88 }
89 }
90}