From 85ed5ad356ddfb3eaede098671816b252a28bb25 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 12 Aug 2020 14:51:21 +0100 Subject: [PATCH] Updated changelog, cleaned up warnings, minor fixes --- CHANGELOG.md | 7 +- common/src/astar.rs | 2 +- common/src/path.rs | 13 +--- common/src/sys/phys.rs | 5 +- voxygen/src/scene/terrain.rs | 10 +-- world/src/block/mod.rs | 2 +- world/src/civ/mod.rs | 2 +- world/src/column/mod.rs | 2 +- world/src/index.rs | 4 +- world/src/layer/mod.rs | 18 ++++-- world/src/sim/mod.rs | 1 - world/src/sim2/mod.rs | 18 +++--- world/src/site/castle/keep.rs | 20 ------ world/src/site/castle/mod.rs | 64 ++++++------------- world/src/site/economy.rs | 2 +- world/src/site/mod.rs | 3 +- .../settlement/building/archetype/house.rs | 8 +-- .../settlement/building/archetype/keep.rs | 4 +- world/src/site/settlement/mod.rs | 9 +-- world/src/site/settlement/town.rs | 2 +- world/src/util/mod.rs | 2 +- 21 files changed, 77 insertions(+), 121 deletions(-) delete mode 100644 world/src/site/castle/keep.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 06d7096ee9..10b75f920f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,10 +49,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Loading-Screen tips - Feeding animation for some animals - Power stat to weapons which affects weapon damage -- Add detection of entities under the cursor +- Add detection of entities under the cursor - Functional group-system with exp-sharing and disabled damage to group members - Some Campfire, fireball & bomb; particle, light & sound effects. - Added setting to change resolution +- Rare (unfinished) castles +- Caves with monsters and treasure +- Furniture and decals in towns ### Changed @@ -85,6 +88,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Dehardcoded many item variants - Tooltips avoid the mouse better and disappear when hovered - Improved social window functions and visuals +- Changed agent behaviour to allow fleeing +- Waypoints now spawn on dungeon staircases ### Removed diff --git a/common/src/astar.rs b/common/src/astar.rs index 35781f0317..79a523c4d1 100644 --- a/common/src/astar.rs +++ b/common/src/astar.rs @@ -121,7 +121,7 @@ impl Astar { { let iter_limit = self.max_iters.min(self.iter + iters); while self.iter < iter_limit { - if let Some(PathEntry { node, cost }) = self.potential_nodes.pop() { + if let Some(PathEntry { node, .. }) = self.potential_nodes.pop() { if satisfied(&node) { return PathResult::Path(self.reconstruct_path_to(node)); } else { diff --git a/common/src/path.rs b/common/src/path.rs index 510724b597..0c7f35479c 100644 --- a/common/src/path.rs +++ b/common/src/path.rs @@ -121,17 +121,8 @@ impl Route { .unwrap_or(false)) }); - let next0_tgt = next0.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0); - let next1_tgt = next1.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0); - let next_tgt = next0_tgt; - - // // Maybe skip a node (useful with traversing downhill) - // let closest_tgt = if next0_tgt.distance_squared(pos) < next1_tgt.distance_squared(pos) { - // next0_tgt - // } else { - // next1_tgt - // }; - let closest_tgt = next0_tgt.map2(pos, |tgt, pos| pos.clamped(tgt.floor(), tgt.ceil())); + let next_tgt = next0.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0); + let closest_tgt = next_tgt.map2(pos, |tgt, pos| pos.clamped(tgt.floor(), tgt.ceil())); // Determine whether we're close enough to the next to to consider it completed let dist_sqrd = pos.xy().distance_squared(closest_tgt.xy()); diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index cf0caf31bb..25855e6baa 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -94,7 +94,7 @@ impl<'a> System<'a> for Sys { let mut event_emitter = event_bus.emitter(); // Apply movement inputs - for (entity, scale, sticky, collider, mut pos, mut vel, _ori, _) in ( + for (entity, _scale, sticky, collider, mut pos, mut vel, _ori, _) in ( &entities, scales.maybe(), stickies.maybe(), @@ -113,7 +113,8 @@ impl<'a> System<'a> for Sys { continue; } - let scale = scale.map(|s| s.0).unwrap_or(1.0); + // TODO: Use this + //let scale = scale.map(|s| s.0).unwrap_or(1.0); let old_vel = *vel; // Integrate forces diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index d27badb9cd..f3d95593ad 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -3230,15 +3230,15 @@ impl Terrain { if let Some(models) = self.sprite_models.get(&kind) { renderer.render_sprites( if dist_sqrd < sprite_high_detail_distance.powf(2.0) { - &self.sprite_models[&kind][0] + &models[0] } else if dist_sqrd < sprite_hid_detail_distance.powf(2.0) { - &self.sprite_models[&kind][1] + &models[1] } else if dist_sqrd < sprite_mid_detail_distance.powf(2.0) { - &self.sprite_models[&kind][2] + &models[2] } else if dist_sqrd < sprite_low_detail_distance.powf(2.0) { - &self.sprite_models[&kind][3] + &models[3] } else { - &self.sprite_models[&kind][4] + &models[4] }, globals, &instances, diff --git a/world/src/block/mod.rs b/world/src/block/mod.rs index 152c4a5bba..5b12bb657c 100644 --- a/world/src/block/mod.rs +++ b/world/src/block/mod.rs @@ -9,7 +9,7 @@ use common::{ terrain::{structure::StructureBlock, Block, BlockKind, Structure}, vol::{ReadVol, Vox}, }; -use std::ops::{Add, Div, Mul, Neg}; +use std::ops::{Div, Mul}; use vek::*; pub struct BlockGen<'a> { diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index f569b8b054..fc686d8d03 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -264,7 +264,7 @@ impl Civs { 1 << ((to_next_idx as u8 + 4) % 8); } - for (i, loc) in path.iter().enumerate() { + for loc in path.iter() { let mut chunk = ctx.sim.get_mut(loc.0).unwrap(); let depth = loc.1 * 250.0 - 20.0; chunk.cave.1.alt = diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index 47c28a3bab..11b824b027 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -14,7 +14,7 @@ use roots::find_roots_cubic; use std::{ cmp::Reverse, f32, f64, - ops::{Add, Div, Mul, Neg, Sub}, + ops::{Add, Div, Mul, Sub}, }; use tracing::error; use vek::*; diff --git a/world/src/index.rs b/world/src/index.rs index 1c05427d5c..2b0e829c4f 100644 --- a/world/src/index.rs +++ b/world/src/index.rs @@ -1,6 +1,6 @@ use crate::site::Site; -use common::store::{Id, Store}; -use noise::{NoiseFn, Seedable, SuperSimplex}; +use common::store::Store; +use noise::{Seedable, SuperSimplex}; pub struct Index { pub seed: u32, diff --git a/world/src/layer/mod.rs b/world/src/layer/mod.rs index 1a334b6d63..6ab1036c3c 100644 --- a/world/src/layer/mod.rs +++ b/world/src/layer/mod.rs @@ -135,7 +135,7 @@ pub fn apply_paths_to<'a>( wpos2d: Vec2, mut get_column: impl FnMut(Vec2) -> Option<&'a ColumnSample<'a>>, vol: &mut (impl BaseVol + RectSizedVol + ReadVol + WriteVol), - index: &Index, + _index: &Index, ) { for y in 0..vol.size_xy().y as i32 { for x in 0..vol.size_xy().x as i32 { @@ -239,7 +239,7 @@ pub fn apply_caves_to<'a>( }; let surface_z = col_sample.riverless_alt.floor() as i32; - if let Some((cave_dist, cave_nearest, cave, _)) = col_sample + if let Some((cave_dist, _, cave, _)) = col_sample .cave .filter(|(dist, _, cave, _)| *dist < cave.width) { @@ -286,8 +286,11 @@ pub fn apply_caves_to<'a>( ); } + let cave_depth = (col_sample.alt - cave.alt).max(0.0); + let difficulty = cave_depth / 200.0; + // Scatter things in caves - if RandomField::new(index.seed).chance(wpos2d.into(), 0.001) + if RandomField::new(index.seed).chance(wpos2d.into(), 0.002 * difficulty) && cave_base < surface_z as i32 - 25 { let kind = *assets::load_expect::>("common.cave_scatter") @@ -324,7 +327,7 @@ pub fn apply_caves_supplement<'a>( }; let surface_z = col_sample.riverless_alt.floor() as i32; - if let Some((cave_dist, cave_nearest, cave, _)) = col_sample + if let Some((cave_dist, _, cave, _)) = col_sample .cave .filter(|(dist, _, cave, _)| *dist < cave.width) { @@ -332,14 +335,15 @@ pub fn apply_caves_supplement<'a>( // Relative units let cave_floor = 0.0 - 0.5 * (1.0 - cave_x.powf(2.0)).max(0.0).sqrt() * cave.width; - let cave_height = (1.0 - cave_x.powf(2.0)).max(0.0).sqrt() * cave.width; // Abs units let cave_base = (cave.alt + cave_floor) as i32; - let cave_roof = (cave.alt + cave_height) as i32; + + let cave_depth = (col_sample.alt - cave.alt).max(0.0); + let difficulty = cave_depth / 200.0; // Scatter things in caves - if RandomField::new(index.seed).chance(wpos2d.into(), 0.00005) + if RandomField::new(index.seed).chance(wpos2d.into(), 0.0001 * difficulty) && cave_base < surface_z as i32 - 40 { let entity = EntityInfo::at(Vec3::new( diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 92a1fe59fe..d8a3239e23 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -26,7 +26,6 @@ pub use self::{ use crate::{ all::ForestKind, civ::Place, - column::{ColumnGen, ColumnSample}, site::Site, util::{seed_expan, FastNoise, RandomField, StructureGen2d, LOCALITY, NEIGHBORS}, Index, CONFIG, diff --git a/world/src/sim2/mod.rs b/world/src/sim2/mod.rs index 3d07e8ad34..ffccc9516f 100644 --- a/world/src/sim2/mod.rs +++ b/world/src/sim2/mod.rs @@ -8,7 +8,7 @@ use crate::{ Index, }; use common::store::Id; -use tracing::{debug, info, warn}; +use tracing::debug; const MONTH: f32 = 30.0; const YEAR: f32 = 12.0 * MONTH; @@ -78,7 +78,7 @@ pub fn simulate(index: &mut Index, world: &mut WorldSim) { } } -pub fn tick(index: &mut Index, world: &mut WorldSim, dt: f32) { +pub fn tick(index: &mut Index, _world: &mut WorldSim, dt: f32) { for site in index.sites.ids() { tick_site_economy(index, site, dt); } @@ -137,8 +137,6 @@ pub fn tick_site_economy(index: &mut Index, site: Id, dt: f32) { // Note that values are used for workforce allocation and are not the same thing // as price let values = &mut site.economy.values; - let marginal_surplus = &site.economy.marginal_surplus; - let stocks = &site.economy.stocks; site.economy.surplus.iter().for_each(|(good, surplus)| { // Value rationalisation let val = 2.0f32.powf(1.0 - *surplus / demand[good]); @@ -151,12 +149,12 @@ pub fn tick_site_economy(index: &mut Index, site: Id, dt: f32) { }); // Update export targets based on relative values - let value_avg = values - .iter() - .map(|(_, v)| (*v).unwrap_or(0.0)) - .sum::() - .max(0.01) - / values.iter().filter(|(_, v)| v.is_some()).count() as f32; + // let value_avg = values + // .iter() + // .map(|(_, v)| (*v).unwrap_or(0.0)) + // .sum::() + // .max(0.01) + // / values.iter().filter(|(_, v)| v.is_some()).count() as f32; //let export_targets = &mut site.economy.export_targets; //let last_exports = &self.last_exports; // site.economy.values.iter().for_each(|(stock, value)| { diff --git a/world/src/site/castle/keep.rs b/world/src/site/castle/keep.rs deleted file mode 100644 index 2dff94facc..0000000000 --- a/world/src/site/castle/keep.rs +++ /dev/null @@ -1,20 +0,0 @@ -use vek::*; -use crate::{ - util::{attempt, Grid, RandomField, Sampler, CARDINALS, DIRS}, -}; - -pub struct Keep { - offset: Vec2, - cols: Grid, -} - -const KEEP_CELL_STOREY: i32 = 12; - -pub struct KeepCol { - z_offset: i32, - storeys: Vec, -} - -enum KeepCell { - Cube, -} diff --git a/world/src/site/castle/mod.rs b/world/src/site/castle/mod.rs index 5d600ece84..cc367448ed 100644 --- a/world/src/site/castle/mod.rs +++ b/world/src/site/castle/mod.rs @@ -1,35 +1,19 @@ -mod keep; - use super::SpawnRules; use crate::{ - block::block_from_structure, column::ColumnSample, sim::WorldSim, - site::{ - settlement::building::{ - archetype::keep::{Attr, Keep as KeepArchetype}, - Archetype, Branch, Ori, - }, - BlockMask, + site::settlement::building::{ + archetype::keep::{Attr, Keep as KeepArchetype}, + Archetype, Ori, }, - util::{attempt, Grid, RandomField, Sampler, CARDINALS, DIRS}, }; use common::{ - assets, - astar::Astar, - comp, - generation::{ChunkSupplement, EntityInfo}, - npc, - spiral::Spiral2d, - store::{Id, Store}, - terrain::{Block, BlockKind, Structure, TerrainChunkSize}, - vol::{BaseVol, ReadVol, RectSizedVol, RectVolSize, Vox, WriteVol}, + generation::ChunkSupplement, + terrain::{Block, BlockKind}, + vol::{BaseVol, ReadVol, RectSizedVol, Vox, WriteVol}, }; -use core::{f32, hash::BuildHasherDefault}; -use fxhash::FxHasher64; -use lazy_static::lazy_static; +use core::f32; use rand::prelude::*; -use std::sync::Arc; use vek::*; struct Keep { @@ -47,8 +31,7 @@ struct Tower { pub struct Castle { origin: Vec2, - alt: i32, - seed: u32, + //seed: u32, radius: i32, towers: Vec, keeps: Vec, @@ -57,8 +40,6 @@ pub struct Castle { flags: bool, evil: bool, - - keep: Option, } pub struct GenCtx<'a, R: Rng> { @@ -69,7 +50,7 @@ pub struct GenCtx<'a, R: Rng> { impl Castle { #[allow(clippy::let_and_return)] // TODO: Pending review in #587 pub fn generate(wpos: Vec2, sim: Option<&mut WorldSim>, rng: &mut impl Rng) -> Self { - let mut ctx = GenCtx { sim, rng }; + let ctx = GenCtx { sim, rng }; let boundary_towers = ctx.rng.gen_range(5, 10); let keep_count = ctx.rng.gen_range(1, 4); @@ -77,15 +58,15 @@ impl Castle { let radius = 150; - let mut this = Self { + let this = Self { origin: wpos, - alt: ctx - .sim - .as_ref() - .and_then(|sim| sim.get_alt_approx(wpos)) - .unwrap_or(0.0) as i32 - + 6, - seed: ctx.rng.gen(), + // alt: ctx + // .sim + // .as_ref() + // .and_then(|sim| sim.get_alt_approx(wpos)) + // .unwrap_or(0.0) as i32 + // + 6, + //seed: ctx.rng.gen(), radius, towers: (0..boundary_towers) @@ -150,8 +131,6 @@ impl Castle { } }) .collect(), - - keep: None, }; this @@ -231,7 +210,7 @@ impl Castle { } } - let (wall_dist, wall_pos, wall_alt, wall_ori, towers) = (0..self.towers.len()) + let (wall_dist, wall_pos, wall_alt, wall_ori, _towers) = (0..self.towers.len()) .map(|i| { let tower0 = &self.towers[i]; let tower1 = &self.towers[(i + 1) % self.towers.len()]; @@ -273,7 +252,6 @@ impl Castle { .min_by_key(|x| x.0) .unwrap(); let border_pos = (wall_pos - rpos).map(|e| e.abs()); - let wall_normal = (rpos - wall_pos).map(|e| e as f32); let wall_rpos = if wall_ori == Ori::East { rpos } else { @@ -428,10 +406,10 @@ impl Castle { #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn apply_supplement<'a>( &'a self, - rng: &mut impl Rng, - wpos2d: Vec2, + _rng: &mut impl Rng, + _wpos2d: Vec2, _get_column: impl FnMut(Vec2) -> Option<&'a ColumnSample<'a>>, - supplement: &mut ChunkSupplement, + _supplement: &mut ChunkSupplement, ) { // TODO } diff --git a/world/src/site/economy.rs b/world/src/site/economy.rs index f152560702..665ad52c1f 100644 --- a/world/src/site/economy.rs +++ b/world/src/site/economy.rs @@ -101,7 +101,7 @@ impl Economy { } pub fn replenish(&mut self, time: f32) { - use rand::Rng; + //use rand::Rng; for (i, (g, v)) in [ (Wheat, 50.0), (Logs, 20.0), diff --git a/world/src/site/mod.rs b/world/src/site/mod.rs index d32b8028b1..82c83b2183 100644 --- a/world/src/site/mod.rs +++ b/world/src/site/mod.rs @@ -14,10 +14,9 @@ use crate::column::ColumnSample; use common::{ generation::ChunkSupplement, terrain::Block, - vol::{BaseVol, ReadVol, RectSizedVol, Vox, WriteVol}, + vol::{BaseVol, ReadVol, RectSizedVol, WriteVol}, }; use rand::Rng; -use std::{fmt, sync::Arc}; use vek::*; pub struct SpawnRules { diff --git a/world/src/site/settlement/building/archetype/house.rs b/world/src/site/settlement/building/archetype/house.rs index cff969bd25..97c5a0186d 100644 --- a/world/src/site/settlement/building/archetype/house.rs +++ b/world/src/site/settlement/building/archetype/house.rs @@ -122,7 +122,7 @@ pub struct Attr { } impl Attr { - pub fn generate(rng: &mut R, locus: i32) -> Self { + pub fn generate(rng: &mut R, _locus: i32) -> Self { Self { central_supports: rng.gen(), storey_fill: match rng.gen_range(0, 2) { @@ -222,14 +222,14 @@ impl Archetype for House { #[allow(clippy::int_plus_one)] // TODO: Pending review in #587 fn draw( &self, - pos: Vec3, + _pos: Vec3, dist: i32, bound_offset: Vec2, center_offset: Vec2, z: i32, ori: Ori, locus: i32, - len: i32, + _len: i32, attr: &Self::Attr, ) -> BlockMask { let profile = Vec2::new(bound_offset.x, z); @@ -521,7 +521,7 @@ impl Archetype for House { { let ornament = match self.noise.get(Vec3::new(center_offset.x, center_offset.y, z + 100)) % 4 { 0 => BlockKind::HangingSign, - 1 | 2 => BlockKind::HangingBasket, + 1 | 2 | 3 => BlockKind::HangingBasket, _ => BlockKind::DungeonWallDecor, }; diff --git a/world/src/site/settlement/building/archetype/keep.rs b/world/src/site/settlement/building/archetype/keep.rs index a77df1c6ce..178cfaf4a6 100644 --- a/world/src/site/settlement/building/archetype/keep.rs +++ b/world/src/site/settlement/building/archetype/keep.rs @@ -82,13 +82,13 @@ impl Archetype for Keep { fn draw( &self, pos: Vec3, - dist: i32, + _dist: i32, bound_offset: Vec2, center_offset: Vec2, z: i32, ori: Ori, locus: i32, - len: i32, + _len: i32, attr: &Self::Attr, ) -> BlockMask { let profile = Vec2::new(bound_offset.x, z); diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index af141ff916..ea20a5df76 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -640,8 +640,8 @@ impl Settlement { Some(Plot::Dirt) => Some(Rgb::new(90, 70, 50)), Some(Plot::Grass) => Some(Rgb::new(100, 200, 0)), Some(Plot::Water) => Some(Rgb::new(100, 150, 250)), - Some(Plot::Town { district }) => None, - Some(Plot::Town { district }) => { + //Some(Plot::Town { district }) => None, + Some(Plot::Town { .. }) => { if let Some((_, path_nearest, _, _)) = col_sample.path { let path_dir = (path_nearest - wpos2d.map(|e| e as f32)) .rotated_z(f32::consts::PI / 2.0) @@ -662,7 +662,7 @@ impl Settlement { } } - Some(Rgb::new(100, 90, 75).map2(Rgb::iota(), |e: u8, i: i32| { + Some(Rgb::new(100, 105, 75).map2(Rgb::iota(), |e: u8, i: i32| { e.saturating_add( (self.noise.get(Vec3::new(wpos2d.x, wpos2d.y, i * 5)) % 1) as u8, @@ -744,7 +744,7 @@ impl Settlement { { let diff = (surface_z - land_surface_z).abs(); - for z in -8 - diff..3 + diff { + for z in -8 - diff..4 + diff { let pos = Vec3::new(offs.x, offs.y, surface_z + z); let block = vol.get(pos).ok().copied().unwrap_or(Block::empty()); @@ -1162,6 +1162,7 @@ impl Land { self.tiles.get(&pos).map(|tile| self.plots.get(tile.plot)) } + #[allow(dead_code)] pub fn plot_at_mut(&mut self, pos: Vec2) -> Option<&mut Plot> { self.tiles .get(&pos) diff --git a/world/src/site/settlement/town.rs b/world/src/site/settlement/town.rs index 6d6a082cd9..468408678b 100644 --- a/world/src/site/settlement/town.rs +++ b/world/src/site/settlement/town.rs @@ -1,5 +1,5 @@ use super::{GenCtx, AREA_SIZE}; -use common::store::{Id, Store}; +use common::store::Store; use rand::prelude::*; use vek::*; diff --git a/world/src/util/mod.rs b/world/src/util/mod.rs index 7ddc7e85e0..de31f42c71 100644 --- a/world/src/util/mod.rs +++ b/world/src/util/mod.rs @@ -20,7 +20,7 @@ pub use self::{ unit_chooser::UnitChooser, }; -use fxhash::{FxHasher32, FxHasher64}; +use fxhash::FxHasher32; use hashbrown::{HashMap, HashSet}; use std::hash::BuildHasherDefault; use vek::*;