diff --git a/examples/thirst.rs b/examples/thirst.rs index 6225cadc81ce5956fb1e51c7def9d673b5638957..30c378e5e3c36b1c83dc7ca1d2e99a6232cc2911 100644 --- a/examples/thirst.rs +++ b/examples/thirst.rs @@ -98,6 +98,42 @@ fn drink_action_system( } } +#[derive(Debug, Clone)] +struct Idle; + +impl Idle { + fn build() -> IdleBuilder { + IdleBuilder + } +} + +#[derive(Debug, Clone)] +struct IdleBuilder; + +impl ActionBuilder for IdleBuilder { + fn build(&self, cmd: &mut Commands, action: Entity, _actor: Entity) { + cmd.entity(action).insert(Idle); + } +} + +fn idle_system(mut query: Query<&mut ActionState, With<Idle>>) { + for mut state in query.iter_mut() { + match *state { + ActionState::Requested => { + println!("Idling..."); + *state = ActionState::Executing; + } + ActionState::Cancelled => { + println!("Idling cancelled"); + *state = ActionState::Success; + } + ActionState::Executing => { + println!("Idled"); + } + _ => {} + } + } +} // Then, we have something called "Scorers". These are special components that // run in the background, calculating a "Score" value, which is what Big Brain // will use to pick which actions to execute. @@ -156,7 +192,8 @@ pub fn init_entities(mut cmd: Commands) { Thinker::build() .picker(FirstToScore { threshold: 80.0 }) // Note that what we pass in are _builders_, not components! - .when(Thirsty::build(), Drink::build()), + .when(Thirsty::build(), Drink::build()) + .otherwise(Idle::build()), ); } @@ -169,5 +206,6 @@ fn main() { .add_system(thirst_system.system()) .add_system(drink_action_system.system()) .add_system(thirsty_scorer_system.system()) + .add_system(idle_system.system()) .run(); } diff --git a/src/thinker.rs b/src/thinker.rs index 6c2929db98d925e459d6f39547c249a532d53b1f..aa5de2fa7ccadc6db1f511598ad82ed3ce8f04ea 100644 --- a/src/thinker.rs +++ b/src/thinker.rs @@ -243,7 +243,6 @@ pub fn thinker_system( // ...and then execute it (details below). exec_picked_action( &mut cmd, - thinker_ent, *actor, &mut thinker, &choice.action, @@ -254,7 +253,6 @@ pub fn thinker_system( let default_action_ent = default_action_ent.clone(); exec_picked_action( &mut cmd, - thinker_ent, *actor, &mut thinker, &default_action_ent, @@ -289,7 +287,6 @@ pub fn thinker_system( fn exec_picked_action( cmd: &mut Commands, - thinker_ent: Entity, actor: Entity, thinker: &mut Mut<Thinker>, picked_action: &ActionBuilderWrapper,