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::*,
|
||||
},
|
||||
terrain::Block,
|
||||
util::Dir,
|
||||
vol::ReadVol,
|
||||
};
|
||||
use rand::Rng;
|
||||
@ -189,13 +190,7 @@ impl CharacterBehavior for Data {
|
||||
// Send server event to create npc
|
||||
output_events.emit_server(ServerEvent::CreateNpc {
|
||||
pos: comp::Pos(collision_vector - Vec3::unit_z() * obstacle_z),
|
||||
ori: crate::util::Dir::from_unnormalized(Vec3::new(
|
||||
rng.gen_range(-1.0..=1.0),
|
||||
rng.gen_range(-1.0..=1.0),
|
||||
0.0,
|
||||
))
|
||||
.map(comp::Ori::from)
|
||||
.unwrap_or_default(),
|
||||
ori: comp::Ori::from(Dir::random_2d(&mut rng)),
|
||||
npc: NpcBuilder::new(stats, body, comp::Alignment::Owned(*data.uid))
|
||||
.with_skill_set(skill_set)
|
||||
.with_health(health)
|
||||
|
@ -1,4 +1,5 @@
|
||||
use super::{Plane, Projection};
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::warn;
|
||||
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 {
|
||||
Self(slerp_normalized(from.0, to.0, factor))
|
||||
}
|
||||
|
@ -96,12 +96,6 @@ pub struct Brain {
|
||||
pub action: Box<dyn Action<(), !>>,
|
||||
}
|
||||
|
||||
// #[derive(Serialize, Deserialize, Default, Clone)]
|
||||
// pub struct Relations {
|
||||
// #[serde(skip)]
|
||||
// pub driver: Option<Actor>,
|
||||
// }
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Npc {
|
||||
pub uid: u64,
|
||||
@ -115,7 +109,6 @@ pub struct Npc {
|
||||
pub role: Role,
|
||||
pub home: Option<SiteId>,
|
||||
pub faction: Option<FactionId>,
|
||||
// pub relations: Relations,
|
||||
pub is_dead: bool,
|
||||
|
||||
/// The [`Report`]s that the NPC is aware of.
|
||||
@ -158,7 +151,6 @@ impl Clone for Npc {
|
||||
role: self.role.clone(),
|
||||
home: self.home,
|
||||
faction: self.faction,
|
||||
// relations: self.relations.clone(),
|
||||
is_dead: self.is_dead,
|
||||
known_reports: self.known_reports.clone(),
|
||||
body: self.body,
|
||||
@ -192,7 +184,6 @@ impl Npc {
|
||||
role,
|
||||
home: None,
|
||||
faction: None,
|
||||
// relations: Default::default(),
|
||||
is_dead: false,
|
||||
known_reports: Default::default(),
|
||||
chunk_pos: None,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
data::{npc::SimulationMode, Npc},
|
||||
event::{EventCtx, OnDeath, OnMountVolume, OnSetup, OnTick},
|
||||
event::{EventCtx, OnDeath, OnMountVolume, OnTick},
|
||||
RtState, Rule, RuleError,
|
||||
};
|
||||
use common::{
|
||||
@ -21,7 +21,6 @@ pub struct SimulateNpcs;
|
||||
|
||||
impl Rule for SimulateNpcs {
|
||||
fn start(rtstate: &mut RtState) -> Result<Self, RuleError> {
|
||||
rtstate.bind(on_setup);
|
||||
rtstate.bind(on_death);
|
||||
rtstate.bind(on_tick);
|
||||
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>) {
|
||||
let data = &mut *ctx.state.data_mut();
|
||||
|
||||
|
@ -32,6 +32,7 @@ use common::{
|
||||
rtsim::{Actor, RtSimEntity},
|
||||
slowjob::SlowJobPool,
|
||||
uid::{IdMaps, Uid},
|
||||
util::Dir,
|
||||
LoadoutBuilder, ViewDistances,
|
||||
};
|
||||
use common_net::{
|
||||
@ -785,13 +786,7 @@ impl StateExt for State {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for (pet, body, stats) in pets {
|
||||
let ori = common::util::Dir::from_unnormalized(Vec3::new(
|
||||
rng.gen_range(-1.0..=1.0),
|
||||
rng.gen_range(-1.0..=1.0),
|
||||
0.0,
|
||||
))
|
||||
.map(comp::Ori::from)
|
||||
.unwrap_or_default();
|
||||
let ori = comp::Ori::from(Dir::random_2d(&mut rng));
|
||||
let pet_entity = self
|
||||
.create_npc(
|
||||
player_pos,
|
||||
|
@ -2,7 +2,6 @@
|
||||
use crate::test_world::{IndexOwned, World};
|
||||
#[cfg(feature = "persistent_world")]
|
||||
use crate::TerrainPersistence;
|
||||
use rand::Rng;
|
||||
#[cfg(feature = "worldgen")]
|
||||
use world::{IndexOwned, World};
|
||||
|
||||
@ -22,6 +21,7 @@ use common::{
|
||||
resources::{Time, TimeOfDay},
|
||||
slowjob::SlowJobPool,
|
||||
terrain::TerrainGrid,
|
||||
util::Dir,
|
||||
SkillSetBuilder,
|
||||
};
|
||||
|
||||
@ -213,13 +213,7 @@ impl<'a> System<'a> for Sys {
|
||||
} => {
|
||||
server_emitter.emit(ServerEvent::CreateNpc {
|
||||
pos,
|
||||
ori: common::util::Dir::from_unnormalized(Vec3::new(
|
||||
rng.gen_range(-1.0..=1.0),
|
||||
rng.gen_range(-1.0..=1.0),
|
||||
0.0,
|
||||
))
|
||||
.map(comp::Ori::from)
|
||||
.unwrap_or_default(),
|
||||
ori: comp::Ori::from(Dir::random_2d(&mut rng)),
|
||||
npc: NpcBuilder::new(stats, body, alignment)
|
||||
.with_skill_set(skill_set)
|
||||
.with_health(health)
|
||||
|
Loading…
Reference in New Issue
Block a user