veloren_world/site2/plot/
pirate_hideout.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 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 = "use-dyn-lib")]
38 const UPDATE_FN: &'static [u8] = b"render_pirate_hideout\0";
39
40 #[cfg_attr(feature = "be-dyn-lib", export_name = "render_pirate_hideout")]
41 fn render_inner(&self, _site: &Site, land: &Land, painter: &Painter) {
42 let center = self.bounds.center();
43 let base = land.get_alt_approx(center) as i32;
44 let mut thread_rng = thread_rng();
45 let model_pos = center.with_z(base - 2);
46 lazy_static! {
48 pub static ref MODEL: AssetHandle<StructuresGroup> =
49 PrefabStructure::load_group("site_structures.pirate_hideout.pirate_hideout");
50 }
51 let rng = RandomField::new(0).get(model_pos) % 10;
52 let model = MODEL.read();
53 let model = model[rng as usize % model.len()].clone();
54 painter
55 .prim(Primitive::Prefab(Box::new(model.clone())))
56 .translate(model_pos)
57 .fill(Fill::Prefab(Box::new(model), model_pos, rng));
58
59 let npc_radius = 15;
61 let phi = TAU / 5.0;
62 for n in 1..=5 {
63 let npc_pos = Vec2::new(
64 center.x + (npc_radius as f32 * ((n as f32 * phi).cos())) as i32,
65 center.y + (npc_radius as f32 * ((n as f32 * phi).sin())) as i32,
66 );
67
68 match RandomField::new(0).get(npc_pos.with_z(base)) % 10 {
69 0 => painter.spawn(
71 EntityInfo::at(npc_pos.with_z(base).as_()).with_asset_expect(
72 "common.entity.wild.peaceful.rat",
73 &mut thread_rng,
74 None,
75 ),
76 ),
77 1 => painter.spawn(
79 EntityInfo::at(npc_pos.with_z(base).as_()).with_asset_expect(
80 "common.entity.wild.peaceful.parrot",
81 &mut thread_rng,
82 None,
83 ),
84 ),
85 _ => painter.spawn(
87 EntityInfo::at(npc_pos.with_z(base).as_()).with_asset_expect(
88 "common.entity.spot.pirate",
89 &mut thread_rng,
90 None,
91 ),
92 ),
93 }
94 }
95 }
96}