Skip to main content

veloren_world/site/plot/
glider_platform.rs

1use super::*;
2use crate::{Land, site::generation::PrimitiveTransform};
3use common::terrain::BlockKind;
4use rand::prelude::*;
5use vek::*;
6
7/// Represents house data generated by the `generate()` method
8pub struct GliderPlatform {
9    /// Location of center of ring post
10    center: Vec2<i32>,
11    direction: Dir2,
12    /// Approximate altitude of the door tile
13    pub(crate) alt: i32,
14}
15
16impl GliderPlatform {
17    pub fn generate(
18        land: &Land,
19        _rng: &mut impl Rng,
20        _site: &Site,
21        wpos: Vec2<i32>,
22        direction: Dir2,
23    ) -> Self {
24        // FIXME this should be fed into this function
25        Self {
26            center: wpos,
27            direction,
28            alt: land.get_alt_approx(wpos) as i32,
29        }
30    }
31}
32
33impl Structure for GliderPlatform {
34    #[cfg(feature = "dyn-lib")]
35    #[unsafe(export_name = "as_dyn_structure_gliderplatform")]
36    fn as_dyn_outer(&self) -> Option<(&dyn Structure, &'static str)> {
37        Some((Self::as_dyn_impl(self), "as_dyn_structure_gliderplatform"))
38    }
39
40    fn render_inner(&self, _site: &Site, _land: &Land, painter: &Painter) {
41        let rotate_turns = match self.direction {
42            Dir2::X => 0,
43            Dir2::Y => 1,
44            Dir2::NegX => 2,
45            Dir2::NegY => 3,
46        };
47        let rotation_center = Vec3::new(self.center.x, self.center.y, self.alt);
48
49        let white = Fill::Brick(BlockKind::GlowingRock, Rgb::new(200, 200, 200), 24);
50        let wood = Fill::Brick(BlockKind::Wood, Rgb::new(55, 25, 8), 24);
51
52        let base = self.alt + 8;
53        // Base
54        let above_platform = painter.aabb(Aabb {
55            min: Vec2::new(self.center.x - 10, self.center.y - 4).with_z(base + 1),
56            max: Vec2::new(self.center.x + 15, self.center.y + 5).with_z(base + 10),
57        });
58
59        let platform = painter.aabb(Aabb {
60            min: Vec2::new(self.center.x - 10, self.center.y - 4).with_z(base),
61            max: Vec2::new(self.center.x + 15, self.center.y + 5).with_z(base + 1),
62        });
63        let stairs = painter.plane(
64            Aabr {
65                min: Vec2::new(self.center.x - 30, self.center.y - 4),
66                max: Vec2::new(self.center.x - 10, self.center.y + 5),
67            },
68            Vec3::new(self.center.x - 30, self.center.y - 4, base - 20),
69            Vec2::new(1.0, 0.0),
70        );
71        let leg_0 = painter.aabb(Aabb {
72            min: Vec2::new(self.center.x + 14, self.center.y - 4).with_z(base - 50),
73            max: Vec2::new(self.center.x + 15, self.center.y - 3).with_z(base),
74        });
75        let leg_1 = painter.aabb(Aabb {
76            min: Vec2::new(self.center.x - 10, self.center.y - 4).with_z(base - 50),
77            max: Vec2::new(self.center.x - 9, self.center.y - 3).with_z(base),
78        });
79        let leg_2 = painter.aabb(Aabb {
80            min: Vec2::new(self.center.x + 14, self.center.y + 4).with_z(base - 50),
81            max: Vec2::new(self.center.x + 15, self.center.y + 5).with_z(base),
82        });
83        let leg_3 = painter.aabb(Aabb {
84            min: Vec2::new(self.center.x - 10, self.center.y + 4).with_z(base - 50),
85            max: Vec2::new(self.center.x - 9, self.center.y + 5).with_z(base),
86        });
87        let arrow_shaft = painter.aabb(Aabb {
88            min: Vec2::new(self.center.x + 8, self.center.y + 0).with_z(base),
89            max: Vec2::new(self.center.x + 14, self.center.y + 1).with_z(base + 1),
90        });
91        let arrow_head_0 = painter.aabb(Aabb {
92            min: Vec2::new(self.center.x + 11, self.center.y - 2).with_z(base),
93            max: Vec2::new(self.center.x + 12, self.center.y + 3).with_z(base + 1),
94        });
95        let arrow_head_1 = painter.aabb(Aabb {
96            min: Vec2::new(self.center.x + 12, self.center.y - 1).with_z(base),
97            max: Vec2::new(self.center.x + 13, self.center.y + 2).with_z(base + 1),
98        });
99
100        let clears = [above_platform];
101        let wood_fills = [platform, stairs, leg_0, leg_1, leg_2, leg_3];
102        let white_fills = [arrow_shaft, arrow_head_0, arrow_head_1];
103
104        let fills = [
105            (&wood_fills as &[_], Some(wood)),
106            (&white_fills, Some(white.clone())),
107            (&clears, None),
108        ];
109        for (primitives, fill_color_maybe) in fills {
110            for prim in primitives {
111                if let Some(fill_color) = &fill_color_maybe {
112                    prim.rotate_z_90_about(rotate_turns, rotation_center)
113                        .fill(fill_color.clone());
114                } else {
115                    prim.rotate_z_90_about(rotate_turns, rotation_center)
116                        .clear();
117                }
118            }
119        }
120    }
121}