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},
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 pub(crate) seed: u32,
105}
106
107impl Plot {
108 pub fn find_bounds(&self) -> Aabr<i32> {
109 self.tiles
110 .iter()
111 .fold(Aabr::new_empty(self.root_tile), |b, t| {
112 b.expanded_to_contain_point(*t)
113 })
114 }
115
116 pub fn z_range(&self) -> Option<Range<i32>> {
117 match &self.kind {
118 PlotKind::House(house) => Some(house.z_range()),
119 _ => None,
120 }
121 }
122
123 pub fn kind(&self) -> &PlotKind { &self.kind }
124
125 pub fn root_tile(&self) -> Vec2<i32> { self.root_tile }
126
127 pub fn tiles(&self) -> impl ExactSizeIterator<Item = Vec2<i32>> + '_ {
128 self.tiles.iter().copied()
129 }
130}
131
132#[derive(Debug, Clone)]
133pub enum PlotKindMeta<'plot> {
134 AirshipDock {
135 door_tile: Vec2<i32>,
136 center: Vec2<i32>,
137 docking_positions: &'plot Vec<Vec3<i32>>,
138 },
139 Workshop {
140 door_tile: Option<Vec2<i32>>,
141 },
142 House {
143 door_tile: Vec2<i32>,
144 },
145 Dungeon,
146}
147
148pub enum PlotKind {
149 House(House),
150 AirshipDock(AirshipDock),
151 GliderRing(GliderRing),
152 GliderPlatform(GliderPlatform),
153 GliderFinish(GliderFinish),
154 Tavern(Tavern),
155 CoastalAirshipDock(CoastalAirshipDock),
156 CoastalHouse(CoastalHouse),
157 CoastalWorkshop(CoastalWorkshop),
158 Workshop(Workshop),
159 DesertCityMultiPlot(DesertCityMultiPlot),
160 DesertCityTemple(DesertCityTemple),
161 DesertCityArena(DesertCityArena),
162 DesertCityAirshipDock(DesertCityAirshipDock),
163 SeaChapel(SeaChapel),
164 JungleRuin(JungleRuin),
165 Plaza(Plaza),
166 Castle(Castle),
167 Cultist(Cultist),
168 Road(Road),
169 Gnarling(GnarlingFortification),
170 Adlet(AdletStronghold),
171 Haniwa(Haniwa),
172 GiantTree(GiantTree),
173 CliffTower(CliffTower),
174 CliffTownAirshipDock(CliffTownAirshipDock),
175 Sahagin(Sahagin),
176 Citadel(Citadel),
177 SavannahAirshipDock(SavannahAirshipDock),
178 SavannahHut(SavannahHut),
179 SavannahWorkshop(SavannahWorkshop),
180 Barn(Barn),
181 Bridge(Bridge),
182 PirateHideout(PirateHideout),
183 RockCircle(RockCircle),
184 TrollCave(TrollCave),
185 Camp(Camp),
186 DwarvenMine(DwarvenMine),
187 TerracottaPalace(TerracottaPalace),
188 TerracottaHouse(TerracottaHouse),
189 TerracottaYard(TerracottaYard),
190 FarmField(FarmField),
191 VampireCastle(VampireCastle),
192 MyrmidonArena(MyrmidonArena),
193 MyrmidonHouse(MyrmidonHouse),
194}
195
196impl PlotKind {
197 pub fn render_ordering(&self) -> u32 {
198 match self {
199 PlotKind::Bridge(_) => 1,
200 PlotKind::Road(_) | PlotKind::Plaza(_) => 2,
201 _ => 0,
202 }
203 }
204
205 pub fn meta(&self) -> Option<PlotKindMeta<'_>> {
206 match self {
207 PlotKind::SavannahAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
208 door_tile: d.door_tile,
209 docking_positions: &d.docking_positions,
210 center: d.center,
211 }),
212 PlotKind::AirshipDock(d) => Some(PlotKindMeta::AirshipDock {
213 door_tile: d.door_tile,
214 docking_positions: &d.docking_positions,
215 center: d.center,
216 }),
217 PlotKind::CoastalAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
218 door_tile: d.door_tile,
219 docking_positions: &d.docking_positions,
220 center: d.center,
221 }),
222 PlotKind::DesertCityAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
223 door_tile: d.door_tile,
224 docking_positions: &d.docking_positions,
225 center: d.center,
226 }),
227 PlotKind::CliffTownAirshipDock(d) => Some(PlotKindMeta::AirshipDock {
228 door_tile: d.door_tile,
229 docking_positions: &d.docking_positions,
230 center: d.center,
231 }),
232 PlotKind::House(h) => Some(PlotKindMeta::House {
233 door_tile: h.door_tile,
234 }),
235 PlotKind::CoastalHouse(h) => Some(PlotKindMeta::House {
236 door_tile: h.door_tile,
237 }),
238 PlotKind::DesertCityTemple(h) => Some(PlotKindMeta::House {
239 door_tile: h.door_tile,
240 }),
241 PlotKind::Sahagin(_) => Some(PlotKindMeta::Dungeon),
242 PlotKind::SavannahHut(h) => Some(PlotKindMeta::House {
243 door_tile: h.door_tile,
244 }),
245 PlotKind::CoastalWorkshop(w) => Some(PlotKindMeta::Workshop {
246 door_tile: Some(w.door_tile),
247 }),
248 PlotKind::Workshop(_) => Some(PlotKindMeta::Workshop { door_tile: None }),
249 PlotKind::SavannahWorkshop(w) => Some(PlotKindMeta::Workshop {
250 door_tile: Some(w.door_tile),
251 }),
252 PlotKind::SeaChapel(_) => Some(PlotKindMeta::Dungeon),
253 PlotKind::Cultist(_) => Some(PlotKindMeta::Dungeon),
254 PlotKind::Gnarling(_) => Some(PlotKindMeta::Dungeon),
255 PlotKind::Adlet(_) => Some(PlotKindMeta::Dungeon),
256 PlotKind::Haniwa(_) => Some(PlotKindMeta::Dungeon),
257 PlotKind::DwarvenMine(_) => Some(PlotKindMeta::Dungeon),
258 PlotKind::TerracottaPalace(_) => Some(PlotKindMeta::Dungeon),
259 PlotKind::VampireCastle(_) => Some(PlotKindMeta::Dungeon),
260 PlotKind::MyrmidonArena(_) => Some(PlotKindMeta::Dungeon),
261 PlotKind::GliderRing(_)
262 | PlotKind::GliderPlatform(_)
263 | PlotKind::GliderFinish(_)
264 | PlotKind::Tavern(_)
265 | PlotKind::JungleRuin(_)
266 | PlotKind::DesertCityArena(_)
267 | PlotKind::DesertCityMultiPlot(_)
268 | PlotKind::Plaza(_)
269 | PlotKind::Castle(_)
270 | PlotKind::Road(_)
271 | PlotKind::GiantTree(_)
272 | PlotKind::CliffTower(_)
273 | PlotKind::Citadel(_)
274 | PlotKind::Barn(_)
275 | PlotKind::Bridge(_)
276 | PlotKind::PirateHideout(_)
277 | PlotKind::RockCircle(_)
278 | PlotKind::TrollCave(_)
279 | PlotKind::Camp(_)
280 | PlotKind::TerracottaHouse(_)
281 | PlotKind::TerracottaYard(_)
282 | PlotKind::FarmField(_)
283 | PlotKind::MyrmidonHouse(_) => None,
284 }
285 }
286}
287
288#[macro_export]
293macro_rules! foreach_plot {
294 ($p:expr, $x:ident => $y:expr $(,)?) => {
295 match $p {
296 PlotKind::House($x) => $y,
297 PlotKind::AirshipDock($x) => $y,
298 PlotKind::CoastalAirshipDock($x) => $y,
299 PlotKind::CoastalHouse($x) => $y,
300 PlotKind::CoastalWorkshop($x) => $y,
301 PlotKind::Workshop($x) => $y,
302 PlotKind::DesertCityAirshipDock($x) => $y,
303 PlotKind::DesertCityMultiPlot($x) => $y,
304 PlotKind::DesertCityTemple($x) => $y,
305 PlotKind::DesertCityArena($x) => $y,
306 PlotKind::SeaChapel($x) => $y,
307 PlotKind::JungleRuin($x) => $y,
308 PlotKind::Plaza($x) => $y,
309 PlotKind::Castle($x) => $y,
310 PlotKind::Road($x) => $y,
311 PlotKind::Gnarling($x) => $y,
312 PlotKind::Adlet($x) => $y,
313 PlotKind::GiantTree($x) => $y,
314 PlotKind::CliffTower($x) => $y,
315 PlotKind::CliffTownAirshipDock($x) => $y,
316 PlotKind::Citadel($x) => $y,
317 PlotKind::SavannahAirshipDock($x) => $y,
318 PlotKind::SavannahHut($x) => $y,
319 PlotKind::SavannahWorkshop($x) => $y,
320 PlotKind::Barn($x) => $y,
321 PlotKind::Bridge($x) => $y,
322 PlotKind::PirateHideout($x) => $y,
323 PlotKind::Tavern($x) => $y,
324 PlotKind::Cultist($x) => $y,
325 PlotKind::Haniwa($x) => $y,
326 PlotKind::Sahagin($x) => $y,
327 PlotKind::RockCircle($x) => $y,
328 PlotKind::TrollCave($x) => $y,
329 PlotKind::Camp($x) => $y,
330 PlotKind::DwarvenMine($x) => $y,
331 PlotKind::TerracottaPalace($x) => $y,
332 PlotKind::TerracottaHouse($x) => $y,
333 PlotKind::TerracottaYard($x) => $y,
334 PlotKind::FarmField($x) => $y,
335 PlotKind::VampireCastle($x) => $y,
336 PlotKind::GliderRing($x) => $y,
337 PlotKind::GliderPlatform($x) => $y,
338 PlotKind::GliderFinish($x) => $y,
339 PlotKind::MyrmidonArena($x) => $y,
340 PlotKind::MyrmidonHouse($x) => $y,
341 }
342 };
343}
344
345pub use foreach_plot;