Fixed bad AO quad flipping in dark places, bosses spawning in dungeon walls, large creatues being uncompromisingly pedantic when trying to path towards targets

This commit is contained in:
Joshua Barretto 2020-04-17 00:07:29 +01:00
parent fd14223c33
commit 866fd1992e
4 changed files with 16 additions and 13 deletions

View File

@ -59,7 +59,7 @@ impl Route {
pub fn is_finished(&self) -> bool { self.next().is_none() }
pub fn traverse<V>(&mut self, vol: &V, pos: Vec3<f32>) -> Option<Vec3<f32>>
pub fn traverse<V>(&mut self, vol: &V, pos: Vec3<f32>, traversal_tolerance: f32) -> Option<Vec3<f32>>
where
V: BaseVol<Vox = Block> + ReadVol,
{
@ -68,7 +68,7 @@ impl Route {
None
} else {
let next_tgt = next.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0);
if ((pos - next_tgt) * Vec3::new(1.0, 1.0, 0.3)).magnitude_squared() < 1.0f32.powf(2.0)
if ((pos - next_tgt) * Vec3::new(1.0, 1.0, 0.3)).magnitude_squared() < traversal_tolerance.powf(2.0)
{
self.next_idx += 1;
}
@ -93,13 +93,14 @@ impl Chaser {
pos: Vec3<f32>,
tgt: Vec3<f32>,
min_dist: f32,
traversal_tolerance: f32,
) -> Option<Vec3<f32>>
where
V: BaseVol<Vox = Block> + ReadVol,
{
let pos_to_tgt = pos.distance(tgt);
if ((pos - tgt) * Vec3::new(1.0, 1.0, 0.3)).magnitude_squared() < min_dist.powf(2.0) {
if ((pos - tgt) * Vec3::new(1.0, 1.0, 0.15)).magnitude_squared() < min_dist.powf(2.0) {
return None;
}
@ -113,7 +114,7 @@ impl Chaser {
self.route = Route::default();
}
self.route.traverse(vol, pos)
self.route.traverse(vol, pos, traversal_tolerance)
}
} else {
None

View File

@ -1,5 +1,5 @@
use crate::{
comp::{self, agent::Activity, Agent, Alignment, Controller, MountState, Ori, Pos, Stats},
comp::{self, agent::Activity, Agent, Alignment, Controller, MountState, Ori, Scale, Pos, Stats},
path::Chaser,
state::Time,
sync::UidAllocator,
@ -23,6 +23,7 @@ impl<'a> System<'a> for Sys {
Entities<'a>,
ReadStorage<'a, Pos>,
ReadStorage<'a, Ori>,
ReadStorage<'a, Scale>,
ReadStorage<'a, Stats>,
ReadExpect<'a, TerrainGrid>,
ReadStorage<'a, Alignment>,
@ -39,6 +40,7 @@ impl<'a> System<'a> for Sys {
entities,
positions,
orientations,
scales,
stats,
terrain,
alignments,
@ -83,9 +85,11 @@ impl<'a> System<'a> for Sys {
const MAX_FOLLOW_DIST: f32 = 12.0;
const MAX_CHASE_DIST: f32 = 24.0;
const SEARCH_DIST: f32 = 30.0;
const SIGHT_DIST: f32 = 64.0;
const SIGHT_DIST: f32 = 128.0;
const MIN_ATTACK_DIST: f32 = 3.25;
let traversal_tolerance = scales.get(entity).map(|s| s.0).unwrap_or(1.0);
let mut do_idle = false;
let mut choose_target = false;
@ -143,7 +147,7 @@ impl<'a> System<'a> for Sys {
// Follow, or return to idle
if dist_sqrd > AVG_FOLLOW_DIST.powf(2.0) {
if let Some(bearing) =
chaser.chase(&*terrain, pos.0, tgt_pos.0, AVG_FOLLOW_DIST)
chaser.chase(&*terrain, pos.0, tgt_pos.0, AVG_FOLLOW_DIST, traversal_tolerance)
{
inputs.move_dir = Vec2::from(bearing)
.try_normalized()
@ -202,7 +206,7 @@ impl<'a> System<'a> for Sys {
// Long-range chase
if let Some(bearing) =
chaser.chase(&*terrain, pos.0, tgt_pos.0, 1.25)
chaser.chase(&*terrain, pos.0, tgt_pos.0, 1.25, traversal_tolerance)
{
inputs.move_dir = Vec2::from(bearing)
.try_normalized()

View File

@ -118,9 +118,7 @@ fn create_quad<P: Pipeline, F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32, f32) -> P
let ao_map = ao;
if ao[0].min(ao[2]).min(darkness[0]).min(darkness[2])
< ao[1].min(ao[3]).min(darkness[1]).min(darkness[3])
{
if ao[0].min(ao[2]) < ao[1].min(ao[3]) {
Quad::new(
vcons(origin + unit_y, norm, cols[3], darkness[3], ao_map[3]),
vcons(origin, norm, cols[0], darkness[0], ao_map[0]),

View File

@ -274,7 +274,7 @@ impl Floor {
};
let transition = |a: &Vec2<i32>, b: &Vec2<i32>| match self.tiles.get(*b) {
Some(Tile::Room) | Some(Tile::Tunnel) => 1.0,
Some(Tile::Solid) => ctx.rng.gen_range(1.0, 10.0),
Some(Tile::Solid) => 25.0,
Some(Tile::UpStair) | Some(Tile::DownStair) => 0.0,
_ => 100000.0,
};
@ -309,7 +309,7 @@ impl Floor {
if let Some(Tile::Room) = self.tiles.get(tile_pos) {
if tile_pos.x % 4 != 0 || tile_pos.y % 4 != 0 { continue; } // This is so bad
supplement.add_entity(EntityInfo {
pos: (origin + Vec3::from(self.tile_offset + tile_pos) * TILE_SIZE).map(|e| e as f32),
pos: (origin + Vec3::from(self.tile_offset + tile_pos) * TILE_SIZE + TILE_SIZE / 2).map(|e| e as f32),
kind: EntityKind::Boss,
});
}