Factored out NPC AI

This commit is contained in:
Joshua Barretto 2022-08-14 00:09:21 +01:00
parent 21f9bcb8e2
commit ff7478eb01
4 changed files with 29 additions and 10 deletions

View File

@ -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) {

View File

@ -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
View 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)
}
}

View File

@ -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)