veloren_world/site2/plot/
mod.rs

1mod adlet;
2mod airship_dock;
3mod barn;
4mod bridge;
5mod camp;
6mod castle;
7mod citadel;
8mod cliff_tower;
9mod cliff_town_airship_dock;
10mod coastal_airship_dock;
11mod coastal_house;
12mod coastal_workshop;
13mod cultist;
14mod desert_city_airship_dock;
15mod desert_city_arena;
16mod desert_city_multiplot;
17mod desert_city_temple;
18mod dwarven_mine;
19mod farm_field;
20mod giant_tree;
21mod glider_finish;
22mod glider_platform;
23mod glider_ring;
24mod gnarling;
25mod haniwa;
26mod house;
27mod jungle_ruin;
28mod myrmidon_arena;
29mod myrmidon_house;
30mod pirate_hideout;
31mod plaza;
32mod road;
33mod rock_circle;
34mod sahagin;
35mod savannah_airship_dock;
36mod savannah_hut;
37mod savannah_workshop;
38mod sea_chapel;
39pub mod tavern;
40mod terracotta_house;
41mod terracotta_palace;
42mod terracotta_yard;
43mod troll_cave;
44mod vampire_castle;
45mod workshop;
46
47pub use self::{
48    adlet::AdletStronghold,
49    airship_dock::AirshipDock,
50    barn::Barn,
51    bridge::Bridge,
52    camp::Camp,
53    castle::Castle,
54    citadel::Citadel,
55    cliff_tower::CliffTower,
56    cliff_town_airship_dock::CliffTownAirshipDock,
57    coastal_airship_dock::CoastalAirshipDock,
58    coastal_house::CoastalHouse,
59    coastal_workshop::CoastalWorkshop,
60    cultist::Cultist,
61    desert_city_airship_dock::DesertCityAirshipDock,
62    desert_city_arena::DesertCityArena,
63    desert_city_multiplot::DesertCityMultiPlot,
64    desert_city_temple::DesertCityTemple,
65    dwarven_mine::DwarvenMine,
66    farm_field::FarmField,
67    giant_tree::GiantTree,
68    glider_finish::GliderFinish,
69    glider_platform::GliderPlatform,
70    glider_ring::GliderRing,
71    gnarling::GnarlingFortification,
72    haniwa::Haniwa,
73    house::House,
74    jungle_ruin::JungleRuin,
75    myrmidon_arena::MyrmidonArena,
76    myrmidon_house::MyrmidonHouse,
77    pirate_hideout::PirateHideout,
78    plaza::Plaza,
79    road::{Road, RoadKind, RoadLights, RoadMaterial},
80    rock_circle::RockCircle,
81    sahagin::Sahagin,
82    savannah_airship_dock::SavannahAirshipDock,
83    savannah_hut::SavannahHut,
84    savannah_workshop::SavannahWorkshop,
85    sea_chapel::SeaChapel,
86    tavern::Tavern,
87    terracotta_house::TerracottaHouse,
88    terracotta_palace::TerracottaPalace,
89    terracotta_yard::TerracottaYard,
90    troll_cave::TrollCave,
91    vampire_castle::VampireCastle,
92    workshop::Workshop,
93};
94
95use super::*;
96use crate::util::DHashSet;
97use common::path::Path;
98use vek::*;
99
100pub struct Plot {
101    pub(crate) kind: PlotKind,
102    pub(crate) root_tile: Vec2<i32>,
103    pub(crate) tiles: DHashSet<Vec2<i32>>,
104}
105
106impl Plot {
107    pub fn find_bounds(&self) -> Aabr<i32> {
108        self.tiles
109            .iter()
110            .fold(Aabr::new_empty(self.root_tile), |b, t| {
111                b.expanded_to_contain_point(*t)
112            })
113    }
114
115    pub fn z_range(&self) -> Option<Range<i32>> {
116        match &self.kind {
117            PlotKind::House(house) => Some(house.z_range()),
118            _ => None,
119        }
120    }
121
122    pub fn kind(&self) -> &PlotKind { &self.kind }
123
124    pub fn root_tile(&self) -> Vec2<i32> { self.root_tile }
125
126    pub fn tiles(&self) -> impl ExactSizeIterator<Item = Vec2<i32>> + '_ {
127        self.tiles.iter().copied()
128    }
129}
130
131#[derive(Debug, Clone)]
132pub enum PlotKindMeta<'plot> {
133    AirshipDock {
134        door_tile: Vec2<i32>,
135        center: Vec2<i32>,
136        docking_positions: &'plot Vec<Vec3<i32>>,
137    },
138    Workshop {
139        door_tile: Option<Vec2<i32>>,
140    },
141    House {
142        door_tile: Vec2<i32>,
143    },
144    Other {
145        door_tile: Vec2<i32>,
146    },
147    Dungeon,
148}
149
150impl PlotKindMeta<'_> {
151    pub fn door_tile(&self) -> Option<Vec2<i32>> {
152        match self {
153            PlotKindMeta::AirshipDock { door_tile, .. }
154            | PlotKindMeta::House { door_tile }
155            | PlotKindMeta::Other { door_tile } => Some(*door_tile),
156            PlotKindMeta::Workshop { door_tile } => *door_tile,
157            PlotKindMeta::Dungeon => None,
158        }
159    }
160}
161
162pub enum PlotKind {
163    House(House),
164    AirshipDock(AirshipDock),
165    GliderRing(GliderRing),
166    GliderPlatform(GliderPlatform),
167    GliderFinish(GliderFinish),
168    Tavern(Tavern),
169    CoastalAirshipDock(CoastalAirshipDock),
170    CoastalHouse(CoastalHouse),
171    CoastalWorkshop(CoastalWorkshop),
172    Workshop(Workshop),
173    DesertCityMultiPlot(DesertCityMultiPlot),
174    DesertCityTemple(DesertCityTemple),
175    DesertCityArena(DesertCityArena),
176    DesertCityAirshipDock(DesertCityAirshipDock),
177    SeaChapel(SeaChapel),
178    JungleRuin(JungleRuin),
179    Plaza(Plaza),
180    Castle(Castle),
181    Cultist(Cultist),
182    Road(Road),
183    Gnarling(GnarlingFortification),
184    Adlet(AdletStronghold),
185    Haniwa(Haniwa),
186    GiantTree(GiantTree),
187    CliffTower(CliffTower),
188    CliffTownAirshipDock(CliffTownAirshipDock),
189    Sahagin(Sahagin),
190    Citadel(Citadel),
191    SavannahAirshipDock(SavannahAirshipDock),
192    SavannahHut(SavannahHut),
193    SavannahWorkshop(SavannahWorkshop),
194    Barn(Barn),
195    Bridge(Bridge),
196    PirateHideout(PirateHideout),
197    RockCircle(RockCircle),
198    TrollCave(TrollCave),
199    Camp(Camp),
200    DwarvenMine(DwarvenMine),
201    TerracottaPalace(TerracottaPalace),
202    TerracottaHouse(TerracottaHouse),
203    TerracottaYard(TerracottaYard),
204    FarmField(FarmField),
205    VampireCastle(VampireCastle),
206    MyrmidonArena(MyrmidonArena),
207    MyrmidonHouse(MyrmidonHouse),
208}
209
210impl PlotKind {
211    pub fn render_ordering(&self) -> u32 {
212        match self {
213            PlotKind::Bridge(_) => 1,
214            PlotKind::Road(_) | PlotKind::Plaza(_) => 2,
215            _ => 0,
216        }
217    }
218
219    pub fn meta(&self) -> Option<PlotKindMeta<'_>> {
220        match self {
221            PlotKind::SavannahAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
222                door_tile: d.door_tile,
223                docking_positions: &d.docking_positions,
224                center: d.center,
225            }),
226            PlotKind::AirshipDock(d) => Some(PlotKindMeta::AirshipDock {
227                door_tile: d.door_tile,
228                docking_positions: &d.docking_positions,
229                center: d.center,
230            }),
231            PlotKind::CoastalAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
232                door_tile: d.door_tile,
233                docking_positions: &d.docking_positions,
234                center: d.center,
235            }),
236            PlotKind::DesertCityAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
237                door_tile: d.door_tile,
238                docking_positions: &d.docking_positions,
239                center: d.center,
240            }),
241            PlotKind::CliffTownAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
242                door_tile: d.door_tile,
243                docking_positions: &d.docking_positions,
244                center: d.center,
245            }),
246            PlotKind::House(h) => Some(PlotKindMeta::House {
247                door_tile: h.door_tile,
248            }),
249            PlotKind::CoastalHouse(h) => Some(PlotKindMeta::House {
250                door_tile: h.door_tile,
251            }),
252            PlotKind::DesertCityTemple(h) => Some(PlotKindMeta::House {
253                door_tile: h.door_tile,
254            }),
255            PlotKind::Sahagin(_) => Some(PlotKindMeta::Dungeon),
256            PlotKind::SavannahHut(h) => Some(PlotKindMeta::House {
257                door_tile: h.door_tile,
258            }),
259            PlotKind::CoastalWorkshop(w) => Some(PlotKindMeta::Workshop {
260                door_tile: Some(w.door_tile),
261            }),
262            PlotKind::Workshop(_) => Some(PlotKindMeta::Workshop { door_tile: None }),
263            PlotKind::SavannahWorkshop(w) => Some(PlotKindMeta::Workshop {
264                door_tile: Some(w.door_tile),
265            }),
266            PlotKind::Tavern(t) => Some(PlotKindMeta::Other {
267                door_tile: t.door_tile,
268            }),
269            PlotKind::SeaChapel(_) => Some(PlotKindMeta::Dungeon),
270            PlotKind::Cultist(_) => Some(PlotKindMeta::Dungeon),
271            PlotKind::Gnarling(_) => Some(PlotKindMeta::Dungeon),
272            PlotKind::Adlet(_) => Some(PlotKindMeta::Dungeon),
273            PlotKind::Haniwa(_) => Some(PlotKindMeta::Dungeon),
274            PlotKind::DwarvenMine(_) => Some(PlotKindMeta::Dungeon),
275            PlotKind::TerracottaPalace(_) => Some(PlotKindMeta::Dungeon),
276            PlotKind::VampireCastle(_) => Some(PlotKindMeta::Dungeon),
277            PlotKind::MyrmidonArena(_) => Some(PlotKindMeta::Dungeon),
278            PlotKind::GliderRing(_)
279            | PlotKind::GliderPlatform(_)
280            | PlotKind::GliderFinish(_)
281            | PlotKind::JungleRuin(_)
282            | PlotKind::DesertCityArena(_)
283            | PlotKind::DesertCityMultiPlot(_)
284            | PlotKind::Plaza(_)
285            | PlotKind::Castle(_)
286            | PlotKind::Road(_)
287            | PlotKind::GiantTree(_)
288            | PlotKind::CliffTower(_)
289            | PlotKind::Citadel(_)
290            | PlotKind::Barn(_)
291            | PlotKind::Bridge(_)
292            | PlotKind::PirateHideout(_)
293            | PlotKind::RockCircle(_)
294            | PlotKind::TrollCave(_)
295            | PlotKind::Camp(_)
296            | PlotKind::TerracottaHouse(_)
297            | PlotKind::TerracottaYard(_)
298            | PlotKind::FarmField(_)
299            | PlotKind::MyrmidonHouse(_) => None,
300        }
301    }
302}
303
304/// # Syntax
305/// ```ignore
306/// foreach_plot!(expr, plot => plot.something())
307/// ```
308#[macro_export]
309macro_rules! foreach_plot {
310    ($p:expr, $x:ident => $y:expr $(,)?) => {
311        match $p {
312            PlotKind::House($x) => $y,
313            PlotKind::AirshipDock($x) => $y,
314            PlotKind::CoastalAirshipDock($x) => $y,
315            PlotKind::CoastalHouse($x) => $y,
316            PlotKind::CoastalWorkshop($x) => $y,
317            PlotKind::Workshop($x) => $y,
318            PlotKind::DesertCityAirshipDock($x) => $y,
319            PlotKind::DesertCityMultiPlot($x) => $y,
320            PlotKind::DesertCityTemple($x) => $y,
321            PlotKind::DesertCityArena($x) => $y,
322            PlotKind::SeaChapel($x) => $y,
323            PlotKind::JungleRuin($x) => $y,
324            PlotKind::Plaza($x) => $y,
325            PlotKind::Castle($x) => $y,
326            PlotKind::Road($x) => $y,
327            PlotKind::Gnarling($x) => $y,
328            PlotKind::Adlet($x) => $y,
329            PlotKind::GiantTree($x) => $y,
330            PlotKind::CliffTower($x) => $y,
331            PlotKind::CliffTownAirshipDock($x) => $y,
332            PlotKind::Citadel($x) => $y,
333            PlotKind::SavannahAirshipDock($x) => $y,
334            PlotKind::SavannahHut($x) => $y,
335            PlotKind::SavannahWorkshop($x) => $y,
336            PlotKind::Barn($x) => $y,
337            PlotKind::Bridge($x) => $y,
338            PlotKind::PirateHideout($x) => $y,
339            PlotKind::Tavern($x) => $y,
340            PlotKind::Cultist($x) => $y,
341            PlotKind::Haniwa($x) => $y,
342            PlotKind::Sahagin($x) => $y,
343            PlotKind::RockCircle($x) => $y,
344            PlotKind::TrollCave($x) => $y,
345            PlotKind::Camp($x) => $y,
346            PlotKind::DwarvenMine($x) => $y,
347            PlotKind::TerracottaPalace($x) => $y,
348            PlotKind::TerracottaHouse($x) => $y,
349            PlotKind::TerracottaYard($x) => $y,
350            PlotKind::FarmField($x) => $y,
351            PlotKind::VampireCastle($x) => $y,
352            PlotKind::GliderRing($x) => $y,
353            PlotKind::GliderPlatform($x) => $y,
354            PlotKind::GliderFinish($x) => $y,
355            PlotKind::MyrmidonArena($x) => $y,
356            PlotKind::MyrmidonHouse($x) => $y,
357        }
358    };
359}
360
361pub use foreach_plot;