mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Factored out NPC AI
This commit is contained in:
parent
21f9bcb8e2
commit
ff7478eb01
@ -51,6 +51,7 @@ impl RtState {
|
||||
info!("Starting default rtsim rules...");
|
||||
self.start_rule::<rule::setup::Setup>();
|
||||
self.start_rule::<rule::simulate_npcs::SimulateNpcs>();
|
||||
self.start_rule::<rule::npc_ai::NpcAi>();
|
||||
}
|
||||
|
||||
pub fn start_rule<R: Rule>(&mut self) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
pub mod setup;
|
||||
pub mod simulate_npcs;
|
||||
pub mod npc_ai;
|
||||
|
||||
use std::fmt;
|
||||
use super::RtState;
|
||||
|
27
rtsim/src/rule/npc_ai.rs
Normal file
27
rtsim/src/rule/npc_ai.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use tracing::info;
|
||||
use vek::*;
|
||||
use crate::{
|
||||
data::npc::NpcMode,
|
||||
event::OnTick,
|
||||
RtState, Rule, RuleError,
|
||||
};
|
||||
|
||||
pub struct NpcAi;
|
||||
|
||||
impl Rule for NpcAi {
|
||||
fn start(rtstate: &mut RtState) -> Result<Self, RuleError> {
|
||||
|
||||
rtstate.bind::<Self, OnTick>(|ctx| {
|
||||
for npc in ctx.state
|
||||
.data_mut()
|
||||
.npcs
|
||||
.values_mut()
|
||||
{
|
||||
// TODO: Not this
|
||||
npc.target = Some((npc.wpos + Vec3::new(ctx.event.time.sin() as f32 * 16.0, ctx.event.time.cos() as f32 * 16.0, 0.0), 1.0));
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
@ -36,16 +36,6 @@ impl Rule for SimulateNpcs {
|
||||
.get_alt_approx(npc.wpos.xy().map(|e| e as i32))
|
||||
.unwrap_or(0.0);
|
||||
}
|
||||
|
||||
// Do some thinking. TODO: Not here!
|
||||
for npc in ctx.state
|
||||
.data_mut()
|
||||
.npcs
|
||||
.values_mut()
|
||||
{
|
||||
// TODO: Not this
|
||||
npc.target = Some((npc.wpos + Vec3::new(ctx.event.time.sin() as f32 * 16.0, ctx.event.time.cos() as f32 * 16.0, 0.0), 1.0));
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Self)
|
||||
|
Loading…
Reference in New Issue
Block a user