mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'aweinstock/fix-waypoint-2' into 'master'
Further improve handling of underground waypoints: See merge request veloren/veloren!2665
This commit is contained in:
commit
6fa3ac610b
@ -159,6 +159,10 @@ impl TerrainGrid {
|
|||||||
/// Find a location suitable for spawning an entity near the given
|
/// Find a location suitable for spawning an entity near the given
|
||||||
/// position (but in the same chunk).
|
/// position (but in the same chunk).
|
||||||
pub fn find_space(&self, pos: Vec3<i32>) -> Vec3<i32> {
|
pub fn find_space(&self, pos: Vec3<i32>) -> Vec3<i32> {
|
||||||
|
self.try_find_space(pos).unwrap_or(pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn try_find_space(&self, pos: Vec3<i32>) -> Option<Vec3<i32>> {
|
||||||
const SEARCH_DIST: i32 = 63;
|
const SEARCH_DIST: i32 = 63;
|
||||||
(0..SEARCH_DIST * 2 + 1)
|
(0..SEARCH_DIST * 2 + 1)
|
||||||
.map(|i| if i % 2 == 0 { i } else { -i } / 2)
|
.map(|i| if i % 2 == 0 { i } else { -i } / 2)
|
||||||
@ -171,7 +175,6 @@ impl TerrainGrid {
|
|||||||
.map_or(true, |b| !b.is_solid())
|
.map_or(true, |b| !b.is_solid())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unwrap_or(pos)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,11 @@ use crate::{
|
|||||||
SpawnPoint, Tick,
|
SpawnPoint, Tick,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
comp::{self, agent, bird_medium, Alignment, BehaviorCapability, ForceUpdate, Pos},
|
comp::{self, agent, bird_medium, Alignment, BehaviorCapability, ForceUpdate, Pos, Waypoint},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
generation::{get_npc_name, EntityInfo},
|
generation::{get_npc_name, EntityInfo},
|
||||||
npc::NPC_NAMES,
|
npc::NPC_NAMES,
|
||||||
|
resources::Time,
|
||||||
terrain::TerrainGrid,
|
terrain::TerrainGrid,
|
||||||
LoadoutBuilder, SkillSetBuilder,
|
LoadoutBuilder, SkillSetBuilder,
|
||||||
};
|
};
|
||||||
@ -104,6 +105,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
WriteStorage<'a, RepositionOnChunkLoad>,
|
WriteStorage<'a, RepositionOnChunkLoad>,
|
||||||
WriteStorage<'a, ForceUpdate>,
|
WriteStorage<'a, ForceUpdate>,
|
||||||
|
WriteStorage<'a, Waypoint>,
|
||||||
|
ReadExpect<'a, Time>,
|
||||||
);
|
);
|
||||||
|
|
||||||
const NAME: &'static str = "terrain";
|
const NAME: &'static str = "terrain";
|
||||||
@ -128,6 +131,8 @@ impl<'a> System<'a> for Sys {
|
|||||||
entities,
|
entities,
|
||||||
mut reposition_on_load,
|
mut reposition_on_load,
|
||||||
mut force_update,
|
mut force_update,
|
||||||
|
mut waypoints,
|
||||||
|
time,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
let mut server_emitter = server_event_bus.emitter();
|
let mut server_emitter = server_event_bus.emitter();
|
||||||
@ -330,11 +335,13 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
let chunk_pos = terrain.pos_key(pos.0.map(|e| e as i32));
|
let chunk_pos = terrain.pos_key(pos.0.map(|e| e as i32));
|
||||||
if let Some(chunk) = terrain.get_key(chunk_pos) {
|
if let Some(chunk) = terrain.get_key(chunk_pos) {
|
||||||
pos.0 = chunk
|
pos.0 = terrain
|
||||||
.find_accessible_pos(pos.0.xy().as_::<i32>(), false)
|
.try_find_space(pos.0.as_::<i32>())
|
||||||
.as_::<f32>();
|
.map(|x| x.as_::<f32>())
|
||||||
|
.unwrap_or_else(|| chunk.find_accessible_pos(pos.0.xy().as_::<i32>(), false));
|
||||||
repositioned.push(entity);
|
repositioned.push(entity);
|
||||||
let _ = force_update.insert(entity, ForceUpdate);
|
let _ = force_update.insert(entity, ForceUpdate);
|
||||||
|
let _ = waypoints.insert(entity, Waypoint::new(pos.0, *time));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for entity in repositioned {
|
for entity in repositioned {
|
||||||
|
Loading…
Reference in New Issue
Block a user