mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Test spot entity spawning
This commit is contained in:
parent
d4e37f30b9
commit
28ee668dc0
12
assets/common/entity/spot/bandit_camp/saurok.ron
Normal file
12
assets/common/entity/spot/bandit_camp/saurok.ron
Normal file
@ -0,0 +1,12 @@
|
||||
EntityConfig (
|
||||
name: Some("Saurok Bandit"),
|
||||
body: Some(RandomWith("saurok_mighty")),
|
||||
|
||||
loot: Some(LootTable("common.loot_tables.creature.biped_large.saurok")),
|
||||
|
||||
main_tool: Some(Item("common.items.npc_weapons.bow.saurok_bow")),
|
||||
second_tool: None,
|
||||
|
||||
loadout_asset: None,
|
||||
skillset_asset: None,
|
||||
)
|
@ -8,6 +8,7 @@ use crate::{
|
||||
util::Grid,
|
||||
};
|
||||
use common::{
|
||||
generation::EntityInfo,
|
||||
terrain::{Block, Structure, TerrainChunk, TerrainChunkSize},
|
||||
vol::{ReadVol, RectVolSize, WriteVol},
|
||||
};
|
||||
@ -112,6 +113,7 @@ impl<'a> CanvasInfo<'a> {
|
||||
pub struct Canvas<'a> {
|
||||
pub(crate) info: CanvasInfo<'a>,
|
||||
pub(crate) chunk: &'a mut TerrainChunk,
|
||||
pub(crate) entities: Vec<EntityInfo>,
|
||||
}
|
||||
|
||||
impl<'a> Canvas<'a> {
|
||||
@ -205,6 +207,8 @@ impl<'a> Canvas<'a> {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn spawn(&mut self, entity: EntityInfo) { self.entities.push(entity); }
|
||||
}
|
||||
|
||||
impl<'a> Deref for Canvas<'a> {
|
||||
|
@ -3,7 +3,11 @@ use crate::{
|
||||
util::seed_expan,
|
||||
Canvas,
|
||||
};
|
||||
use common::terrain::{Block, BlockKind, Structure};
|
||||
use common::{
|
||||
comp,
|
||||
generation::EntityInfo,
|
||||
terrain::{Block, BlockKind, Structure},
|
||||
};
|
||||
use rand::prelude::*;
|
||||
use rand_chacha::ChaChaRng;
|
||||
use vek::*;
|
||||
@ -11,7 +15,7 @@ use vek::*;
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Spot {
|
||||
Camp,
|
||||
Hideout,
|
||||
BanditCamp,
|
||||
}
|
||||
|
||||
impl Spot {
|
||||
@ -24,7 +28,7 @@ impl Spot {
|
||||
false,
|
||||
);
|
||||
Self::generate_spots(
|
||||
Spot::Hideout,
|
||||
Spot::BanditCamp,
|
||||
world,
|
||||
10.0,
|
||||
|g, c| g < 0.25 && !c.near_cliffs() && !c.river.near_water(),
|
||||
@ -83,11 +87,36 @@ pub fn apply_spots_to(canvas: &mut Canvas, dynamic_rng: &mut impl Rng) {
|
||||
},
|
||||
);
|
||||
},
|
||||
Spot::Hideout => {
|
||||
Spot::BanditCamp => {
|
||||
let structures = Structure::load_group("dungeon_entrances").read();
|
||||
let structure = structures.choose(&mut rng).unwrap();
|
||||
let origin = spot_wpos.with_z(canvas.land().get_alt_approx(spot_wpos) as i32);
|
||||
canvas.blit_structure(origin, &structure, seed);
|
||||
|
||||
let spawn_radius = 12;
|
||||
let avg_num = 5.0;
|
||||
|
||||
canvas.foreach_col_area(
|
||||
Aabr {
|
||||
min: spot_wpos - spawn_radius,
|
||||
max: spot_wpos + spawn_radius,
|
||||
},
|
||||
|canvas, wpos2d, col| {
|
||||
if dynamic_rng.gen_bool(avg_num / (spawn_radius * 2).pow(2) as f64) {
|
||||
if let Some(z) = (-8..8).rev().map(|z| col.alt as i32 + z).find(|z| {
|
||||
canvas.get(wpos2d.with_z(z + 2)).is_fluid()
|
||||
&& canvas.get(wpos2d.with_z(z + 1)).is_fluid()
|
||||
&& canvas.get(wpos2d.with_z(z + 0)).is_solid()
|
||||
}) {
|
||||
canvas.spawn(
|
||||
EntityInfo::at(wpos2d.map(|e| e as f32 + 0.5).with_z(z as f32))
|
||||
.with_asset_expect("common.entity.spot.bandit_camp.saurok")
|
||||
.with_alignment(comp::Alignment::Enemy),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -367,6 +367,7 @@ impl World {
|
||||
chunk: sim_chunk,
|
||||
},
|
||||
chunk: &mut chunk,
|
||||
entities: Vec::new(),
|
||||
};
|
||||
|
||||
layer::apply_caves_to(&mut canvas, &mut dynamic_rng);
|
||||
@ -382,6 +383,10 @@ impl World {
|
||||
.iter()
|
||||
.for_each(|site| index.sites[*site].apply_to(&mut canvas, &mut dynamic_rng));
|
||||
|
||||
let mut supplement = ChunkSupplement {
|
||||
entities: canvas.entities,
|
||||
};
|
||||
|
||||
let gen_entity_pos = |dynamic_rng: &mut rand::rngs::ThreadRng| {
|
||||
let lpos2d = TerrainChunkSize::RECT_SIZE
|
||||
.map(|sz| dynamic_rng.gen::<u32>().rem_euclid(sz) as i32);
|
||||
@ -398,10 +403,6 @@ impl World {
|
||||
(Vec3::from(chunk_wpos2d) + lpos).map(|e: i32| e as f32) + 0.5
|
||||
};
|
||||
|
||||
let mut supplement = ChunkSupplement {
|
||||
entities: Vec::new(),
|
||||
};
|
||||
|
||||
if sim_chunk.contains_waypoint {
|
||||
supplement.add_entity(EntityInfo::at(gen_entity_pos(&mut dynamic_rng)).into_waypoint());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user