Spawn dungeon entrances depending on the Site origin biome

This commit is contained in:
Snowram 2021-07-04 18:10:13 +02:00
parent 01a8f53ba3
commit 5dfef5a563
21 changed files with 95 additions and 70 deletions

View File

@ -1,48 +1,44 @@
#![enable(unwrap_newtypes)]
[
(
specifier: "world.structure.dungeon.jungle_temple.entrance.1",
center: (50, 40, 10)
),
(
specifier: "world.structure.dungeon.pillar_entrance.round.1",
center: (21, 17, 28)
),
(
specifier: "world.structure.dungeon.pillar_entrance.round.2",
center: (20, 28, 15)
),
(
specifier: "world.structure.dungeon.pillar_entrance.1",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.2",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.3",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.4",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.5",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.6",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.temperate_entrance.ruins_4",
center: (13, 11, 14)
),
(
specifier: "world.structure.dungeon.misc_entrance.tower-ruin",
center: (13, 16, 9)
),
]
#![enable(unwrap_newtypes)]
[
(
specifier: "world.structure.dungeon.pillar_entrance.round.1",
center: (21, 17, 28)
),
(
specifier: "world.structure.dungeon.pillar_entrance.round.2",
center: (20, 28, 15)
),
(
specifier: "world.structure.dungeon.pillar_entrance.1",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.2",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.3",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.4",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.5",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.pillar_entrance.6",
center: (18, 16, 17)
),
(
specifier: "world.structure.dungeon.temperate_entrance.ruins_4",
center: (13, 11, 14)
),
(
specifier: "world.structure.dungeon.misc_entrance.tower-ruin",
center: (13, 16, 9)
),
]

View File

@ -0,0 +1,8 @@
#![enable(unwrap_newtypes)]
[
(
specifier: "world.structure.dungeon.jungle_temple.entrance.1",
center: (50, 40, 10)
),
]

View File

@ -43,7 +43,7 @@ fn main() -> Result {
CanvasInfo::with_mock_canvas_info(index.as_index_ref(), world.sim(), |canvas| {
for plot in site.plots() {
if let PlotKind::Dungeon(dungeon) = plot.kind() {
let (prim_tree, fills) = dungeon.render_collect(&site);
let (prim_tree, fills) = dungeon.render_collect(&site, &canvas.land());
for (prim, fill) in fills {
let aabb = fill.get_bounds(&prim_tree, prim);

View File

@ -20,19 +20,21 @@ use std::{f32, ops::Range};
use vek::*;
lazy_static! {
static ref OAKS: AssetHandle<StructuresGroup> = Structure::load_group("oaks");
static ref OAK_STUMPS: AssetHandle<StructuresGroup> = Structure::load_group("oak_stumps");
static ref PINES: AssetHandle<StructuresGroup> = Structure::load_group("pines");
static ref PALMS: AssetHandle<StructuresGroup> = Structure::load_group("palms");
static ref ACACIAS: AssetHandle<StructuresGroup> = Structure::load_group("acacias");
static ref BAOBABS: AssetHandle<StructuresGroup> = Structure::load_group("baobabs");
static ref FRUIT_TREES: AssetHandle<StructuresGroup> = Structure::load_group("fruit_trees");
static ref BIRCHES: AssetHandle<StructuresGroup> = Structure::load_group("birch");
static ref OAKS: AssetHandle<StructuresGroup> = Structure::load_group("trees.oaks");
static ref OAK_STUMPS: AssetHandle<StructuresGroup> = Structure::load_group("trees.oak_stumps");
static ref PINES: AssetHandle<StructuresGroup> = Structure::load_group("trees.pines");
static ref PALMS: AssetHandle<StructuresGroup> = Structure::load_group("trees.palms");
static ref ACACIAS: AssetHandle<StructuresGroup> = Structure::load_group("trees.acacias");
static ref BAOBABS: AssetHandle<StructuresGroup> = Structure::load_group("trees.baobabs");
static ref FRUIT_TREES: AssetHandle<StructuresGroup> =
Structure::load_group("trees.fruit_trees");
static ref BIRCHES: AssetHandle<StructuresGroup> = Structure::load_group("trees.birch");
static ref MANGROVE_TREES: AssetHandle<StructuresGroup> =
Structure::load_group("mangrove_trees");
static ref QUIRKY: AssetHandle<StructuresGroup> = Structure::load_group("quirky");
static ref QUIRKY_DRY: AssetHandle<StructuresGroup> = Structure::load_group("quirky_dry");
static ref SWAMP_TREES: AssetHandle<StructuresGroup> = Structure::load_group("swamp_trees");
Structure::load_group("trees.mangrove_trees");
static ref QUIRKY: AssetHandle<StructuresGroup> = Structure::load_group("trees.quirky");
static ref QUIRKY_DRY: AssetHandle<StructuresGroup> = Structure::load_group("trees.quirky_dry");
static ref SWAMP_TREES: AssetHandle<StructuresGroup> =
Structure::load_group("trees.swamp_trees");
}
static MODEL_RAND: RandomPerm = RandomPerm::new(0xDB21C052);

View File

@ -270,15 +270,20 @@ pub trait Structure {
fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Id<Primitive>, Fill)>(
&self,
site: &Site,
land: &Land,
prim: F,
fill: G,
);
// Generate a primitive tree and fills for this structure
fn render_collect(&self, site: &Site) -> (Store<Primitive>, Vec<(Id<Primitive>, Fill)>) {
fn render_collect(
&self,
site: &Site,
land: &Land,
) -> (Store<Primitive>, Vec<(Id<Primitive>, Fill)>) {
let mut tree = Store::default();
let mut fills = Vec::new();
self.render(site, |p| tree.insert(p), |p, f| fills.push((p, f)));
self.render(site, land, |p| tree.insert(p), |p, f| fills.push((p, f)));
(tree, fills)
}
}

View File

@ -758,9 +758,9 @@ impl Site {
for plot in plots_to_render {
let (prim_tree, fills) = match &self.plots[plot].kind {
PlotKind::House(house) => house.render_collect(self),
PlotKind::Castle(castle) => castle.render_collect(self),
PlotKind::Dungeon(dungeon) => dungeon.render_collect(self),
PlotKind::House(house) => house.render_collect(self, &canvas.land()),
PlotKind::Castle(castle) => castle.render_collect(self, &canvas.land()),
PlotKind::Dungeon(dungeon) => dungeon.render_collect(self, &canvas.land()),
_ => continue,
};

View File

@ -46,6 +46,7 @@ impl Structure for Castle {
fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Id<Primitive>, Fill)>(
&self,
site: &Site,
_land: &Land,
mut prim: F,
mut fill: G,
) {

View File

@ -12,7 +12,9 @@ use common::{
comp::{self},
generation::{ChunkSupplement, EntityInfo},
store::{Id, Store},
terrain::{Block, BlockKind, SpriteKind, Structure, StructuresGroup, TerrainChunkSize},
terrain::{
BiomeKind, Block, BlockKind, SpriteKind, Structure, StructuresGroup, TerrainChunkSize,
},
vol::RectVolSize,
};
use core::{f32, hash::BuildHasherDefault};
@ -1364,17 +1366,27 @@ impl SiteStructure for Dungeon {
fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Id<Primitive>, Fill)>(
&self,
_site: &site2::Site,
land: &Land,
mut prim: F,
mut fill: G,
) {
let origin = (self.origin + Vec2::broadcast(TILE_SIZE / 2)).with_z(self.alt + ALT_OFFSET);
lazy_static! {
pub static ref ENTRANCES: AssetHandle<StructuresGroup> =
Structure::load_group("dungeon_entrances");
pub static ref JUNGLE: AssetHandle<StructuresGroup> =
Structure::load_group("dungeon_entrances.jungle");
pub static ref GRASSLAND: AssetHandle<StructuresGroup> =
Structure::load_group("dungeon_entrances.grassland");
}
let entrances = ENTRANCES.read();
let biome = land
.get_chunk_at(self.origin)
.map_or(BiomeKind::Void, |c| c.get_biome());
let entrances = match biome {
BiomeKind::Jungle => *JUNGLE,
_ => *GRASSLAND,
};
let entrances = entrances.read();
let entrance = entrances[self.seed as usize % entrances.len()].clone();
let entrance_prim = prim(Primitive::Prefab(entrance.clone()));

View File

@ -50,6 +50,7 @@ impl Structure for House {
fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Id<Primitive>, Fill)>(
&self,
site: &Site,
_land: &Land,
mut prim: F,
mut fill: G,
) {