mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Remove dead code and factor out into Dir::random_2d
This commit is contained in:
parent
78120e4db5
commit
7856aac713
@ -15,6 +15,7 @@ use crate::{
|
|||||||
utils::*,
|
utils::*,
|
||||||
},
|
},
|
||||||
terrain::Block,
|
terrain::Block,
|
||||||
|
util::Dir,
|
||||||
vol::ReadVol,
|
vol::ReadVol,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
@ -189,13 +190,7 @@ impl CharacterBehavior for Data {
|
|||||||
// Send server event to create npc
|
// Send server event to create npc
|
||||||
output_events.emit_server(ServerEvent::CreateNpc {
|
output_events.emit_server(ServerEvent::CreateNpc {
|
||||||
pos: comp::Pos(collision_vector - Vec3::unit_z() * obstacle_z),
|
pos: comp::Pos(collision_vector - Vec3::unit_z() * obstacle_z),
|
||||||
ori: crate::util::Dir::from_unnormalized(Vec3::new(
|
ori: comp::Ori::from(Dir::random_2d(&mut rng)),
|
||||||
rng.gen_range(-1.0..=1.0),
|
|
||||||
rng.gen_range(-1.0..=1.0),
|
|
||||||
0.0,
|
|
||||||
))
|
|
||||||
.map(comp::Ori::from)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
npc: NpcBuilder::new(stats, body, comp::Alignment::Owned(*data.uid))
|
npc: NpcBuilder::new(stats, body, comp::Alignment::Owned(*data.uid))
|
||||||
.with_skill_set(skill_set)
|
.with_skill_set(skill_set)
|
||||||
.with_health(health)
|
.with_health(health)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use super::{Plane, Projection};
|
use super::{Plane, Projection};
|
||||||
|
use rand::Rng;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -79,6 +80,16 @@ impl Dir {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates a random direction that has a z component of 0
|
||||||
|
pub fn random_2d(rng: &mut impl Rng) -> Self {
|
||||||
|
Self::from_unnormalized(Vec3::new(
|
||||||
|
rng.gen_range(-1.0..=1.0),
|
||||||
|
rng.gen_range(-1.0..=1.0),
|
||||||
|
0.0,
|
||||||
|
))
|
||||||
|
.unwrap_or(Self::new(Vec3::unit_x()))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn slerp(from: Self, to: Self, factor: f32) -> Self {
|
pub fn slerp(from: Self, to: Self, factor: f32) -> Self {
|
||||||
Self(slerp_normalized(from.0, to.0, factor))
|
Self(slerp_normalized(from.0, to.0, factor))
|
||||||
}
|
}
|
||||||
|
@ -96,12 +96,6 @@ pub struct Brain {
|
|||||||
pub action: Box<dyn Action<(), !>>,
|
pub action: Box<dyn Action<(), !>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Serialize, Deserialize, Default, Clone)]
|
|
||||||
// pub struct Relations {
|
|
||||||
// #[serde(skip)]
|
|
||||||
// pub driver: Option<Actor>,
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Npc {
|
pub struct Npc {
|
||||||
pub uid: u64,
|
pub uid: u64,
|
||||||
@ -115,7 +109,6 @@ pub struct Npc {
|
|||||||
pub role: Role,
|
pub role: Role,
|
||||||
pub home: Option<SiteId>,
|
pub home: Option<SiteId>,
|
||||||
pub faction: Option<FactionId>,
|
pub faction: Option<FactionId>,
|
||||||
// pub relations: Relations,
|
|
||||||
pub is_dead: bool,
|
pub is_dead: bool,
|
||||||
|
|
||||||
/// The [`Report`]s that the NPC is aware of.
|
/// The [`Report`]s that the NPC is aware of.
|
||||||
@ -158,7 +151,6 @@ impl Clone for Npc {
|
|||||||
role: self.role.clone(),
|
role: self.role.clone(),
|
||||||
home: self.home,
|
home: self.home,
|
||||||
faction: self.faction,
|
faction: self.faction,
|
||||||
// relations: self.relations.clone(),
|
|
||||||
is_dead: self.is_dead,
|
is_dead: self.is_dead,
|
||||||
known_reports: self.known_reports.clone(),
|
known_reports: self.known_reports.clone(),
|
||||||
body: self.body,
|
body: self.body,
|
||||||
@ -192,7 +184,6 @@ impl Npc {
|
|||||||
role,
|
role,
|
||||||
home: None,
|
home: None,
|
||||||
faction: None,
|
faction: None,
|
||||||
// relations: Default::default(),
|
|
||||||
is_dead: false,
|
is_dead: false,
|
||||||
known_reports: Default::default(),
|
known_reports: Default::default(),
|
||||||
chunk_pos: None,
|
chunk_pos: None,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
data::{npc::SimulationMode, Npc},
|
data::{npc::SimulationMode, Npc},
|
||||||
event::{EventCtx, OnDeath, OnMountVolume, OnSetup, OnTick},
|
event::{EventCtx, OnDeath, OnMountVolume, OnTick},
|
||||||
RtState, Rule, RuleError,
|
RtState, Rule, RuleError,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
@ -21,7 +21,6 @@ pub struct SimulateNpcs;
|
|||||||
|
|
||||||
impl Rule for SimulateNpcs {
|
impl Rule for SimulateNpcs {
|
||||||
fn start(rtstate: &mut RtState) -> Result<Self, RuleError> {
|
fn start(rtstate: &mut RtState) -> Result<Self, RuleError> {
|
||||||
rtstate.bind(on_setup);
|
|
||||||
rtstate.bind(on_death);
|
rtstate.bind(on_death);
|
||||||
rtstate.bind(on_tick);
|
rtstate.bind(on_tick);
|
||||||
rtstate.bind(on_mount_volume);
|
rtstate.bind(on_mount_volume);
|
||||||
@ -30,31 +29,6 @@ impl Rule for SimulateNpcs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_setup(_ctx: EventCtx<SimulateNpcs, OnSetup>) {
|
|
||||||
/*
|
|
||||||
let data = &mut *ctx.state.data_mut();
|
|
||||||
// Add riders to vehicles
|
|
||||||
let riders = data
|
|
||||||
.npcs
|
|
||||||
.iter()
|
|
||||||
.filter_map(|(id, npc)| Some((id, npc.relations.riding?)))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for (npc_id, ride) in riders {
|
|
||||||
if let Some(mount) = data.npcs.get_mut(ride.npc) {
|
|
||||||
if ride.steering && let Some(actor) = mount.relations.driver.replace(Actor::Npc(npc_id)) {
|
|
||||||
error!("Replaced driver");
|
|
||||||
if let Actor::Npc(npc) = actor && let Some(npc) = data.npcs.get_mut(npc) {
|
|
||||||
npc.relations.riding = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data.npcs[npc_id].relations.riding = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_mount_volume(ctx: EventCtx<SimulateNpcs, OnMountVolume>) {
|
fn on_mount_volume(ctx: EventCtx<SimulateNpcs, OnMountVolume>) {
|
||||||
let data = &mut *ctx.state.data_mut();
|
let data = &mut *ctx.state.data_mut();
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ use common::{
|
|||||||
rtsim::{Actor, RtSimEntity},
|
rtsim::{Actor, RtSimEntity},
|
||||||
slowjob::SlowJobPool,
|
slowjob::SlowJobPool,
|
||||||
uid::{IdMaps, Uid},
|
uid::{IdMaps, Uid},
|
||||||
|
util::Dir,
|
||||||
LoadoutBuilder, ViewDistances,
|
LoadoutBuilder, ViewDistances,
|
||||||
};
|
};
|
||||||
use common_net::{
|
use common_net::{
|
||||||
@ -785,13 +786,7 @@ impl StateExt for State {
|
|||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
for (pet, body, stats) in pets {
|
for (pet, body, stats) in pets {
|
||||||
let ori = common::util::Dir::from_unnormalized(Vec3::new(
|
let ori = comp::Ori::from(Dir::random_2d(&mut rng));
|
||||||
rng.gen_range(-1.0..=1.0),
|
|
||||||
rng.gen_range(-1.0..=1.0),
|
|
||||||
0.0,
|
|
||||||
))
|
|
||||||
.map(comp::Ori::from)
|
|
||||||
.unwrap_or_default();
|
|
||||||
let pet_entity = self
|
let pet_entity = self
|
||||||
.create_npc(
|
.create_npc(
|
||||||
player_pos,
|
player_pos,
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
use crate::test_world::{IndexOwned, World};
|
use crate::test_world::{IndexOwned, World};
|
||||||
#[cfg(feature = "persistent_world")]
|
#[cfg(feature = "persistent_world")]
|
||||||
use crate::TerrainPersistence;
|
use crate::TerrainPersistence;
|
||||||
use rand::Rng;
|
|
||||||
#[cfg(feature = "worldgen")]
|
#[cfg(feature = "worldgen")]
|
||||||
use world::{IndexOwned, World};
|
use world::{IndexOwned, World};
|
||||||
|
|
||||||
@ -22,6 +21,7 @@ use common::{
|
|||||||
resources::{Time, TimeOfDay},
|
resources::{Time, TimeOfDay},
|
||||||
slowjob::SlowJobPool,
|
slowjob::SlowJobPool,
|
||||||
terrain::TerrainGrid,
|
terrain::TerrainGrid,
|
||||||
|
util::Dir,
|
||||||
SkillSetBuilder,
|
SkillSetBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -213,13 +213,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
} => {
|
} => {
|
||||||
server_emitter.emit(ServerEvent::CreateNpc {
|
server_emitter.emit(ServerEvent::CreateNpc {
|
||||||
pos,
|
pos,
|
||||||
ori: common::util::Dir::from_unnormalized(Vec3::new(
|
ori: comp::Ori::from(Dir::random_2d(&mut rng)),
|
||||||
rng.gen_range(-1.0..=1.0),
|
|
||||||
rng.gen_range(-1.0..=1.0),
|
|
||||||
0.0,
|
|
||||||
))
|
|
||||||
.map(comp::Ori::from)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
npc: NpcBuilder::new(stats, body, alignment)
|
npc: NpcBuilder::new(stats, body, alignment)
|
||||||
.with_skill_set(skill_set)
|
.with_skill_set(skill_set)
|
||||||
.with_health(health)
|
.with_health(health)
|
||||||
|
Loading…
Reference in New Issue
Block a user