From 2eaf3c7e925df1c4a37ea884971dff9ab1e77f5b Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 3 Apr 2023 19:58:00 +0100 Subject: [PATCH] Spawn dogs and cats in towns --- assets/common/entity/wild/peaceful/dog.ron | 11 +++++++++++ world/src/site2/mod.rs | 21 +++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 assets/common/entity/wild/peaceful/dog.ron diff --git a/assets/common/entity/wild/peaceful/dog.ron b/assets/common/entity/wild/peaceful/dog.ron new file mode 100644 index 0000000000..df7bad54a9 --- /dev/null +++ b/assets/common/entity/wild/peaceful/dog.ron @@ -0,0 +1,11 @@ +#![enable(implicit_some)] +( + name: Automatic, + body: RandomWith("dog"), + alignment: Alignment(Wild), + loot: LootTable("common.loot_tables.creature.quad_small.generic"), + inventory: ( + loadout: FromBody, + ), + meta: [], +) diff --git a/world/src/site2/mod.rs b/world/src/site2/mod.rs index 9da82b9d44..2c0b9f3d2a 100644 --- a/world/src/site2/mod.rs +++ b/world/src/site2/mod.rs @@ -18,6 +18,8 @@ use crate::{ }; use common::{ astar::Astar, + comp::Alignment, + generation::EntityInfo, lottery::Lottery, spiral::Spiral2d, store::{Id, Store}, @@ -1076,9 +1078,10 @@ impl Site { self.origin + tile * TILE_SIZE as i32 + TILE_SIZE as i32 / 2 } - pub fn render_tile(&self, canvas: &mut Canvas, _dynamic_rng: &mut impl Rng, tpos: Vec2) { + pub fn render_tile(&self, canvas: &mut Canvas, dynamic_rng: &mut impl Rng, tpos: Vec2) { let tile = self.tiles.get(tpos); let twpos = self.tile_wpos(tpos); + let twpos_center = self.tile_center_wpos(tpos); let border = TILE_SIZE as i32; let cols = (-border..TILE_SIZE as i32 + border).flat_map(|y| { (-border..TILE_SIZE as i32 + border) @@ -1111,11 +1114,9 @@ impl Site { let sub_surface_color = canvas .col(wpos2d) .map_or(Rgb::zero(), |col| col.sub_surface_color * 0.5); - let mut underground = true; for z in -8..6 { canvas.map(Vec3::new(wpos2d.x, wpos2d.y, alt + z), |b| { if b.kind() == BlockKind::Snow { - underground = false; b.into_vacant() } else if b.is_filled() { if b.is_terrain() { @@ -1127,11 +1128,23 @@ impl Site { b } } else { - underground = false; b.into_vacant() } }) } + if wpos2d == twpos_center && dynamic_rng.gen_bool(0.01) { + let spec = [ + "common.entity.wild.peaceful.cat", + "common.entity.wild.peaceful.dog", + ] + .choose(dynamic_rng) + .unwrap(); + canvas.spawn( + EntityInfo::at(Vec3::new(wpos2d.x, wpos2d.y, alt).as_()) + .with_asset_expect(&spec, dynamic_rng) + .with_alignment(Alignment::Tame), + ); + } } }); },