diff --git a/src/actions.rs b/src/actions.rs index 0e7ad6f318f483690aa4d36ae1532d642c79b779..c799eb12ee92d25212a13ebd61bd3236574551d0 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -92,6 +92,8 @@ pub trait ActionBuilder: std::fmt::Debug + Send + Sync { fn attach(&self, cmd: &mut Commands, actor: Entity) -> Entity { let action_ent = ActionEnt(cmd.spawn().id()); cmd.entity(action_ent.0) + .insert(Transform::default()) + .insert(GlobalTransform::default()) .insert(ActionState::new()) .insert(Actor(actor)); self.build(cmd, action_ent.0, actor); @@ -121,6 +123,8 @@ impl ActionBuilder for StepsBuilder { fn build(&self, cmd: &mut Commands, action: Entity, actor: Entity) { let child_action = self.steps[0].attach(cmd, actor); cmd.entity(action) + .insert(Transform::default()) + .insert(GlobalTransform::default()) .insert(Steps { active_step: 0, active_ent: ActionEnt(child_action), diff --git a/src/pickers.rs b/src/pickers.rs index c54bbea8a1c1ad7079fdb64a2a439e5f0757143d..3a39e47ac3ba8105eb3bef1140d89785367a1507 100644 --- a/src/pickers.rs +++ b/src/pickers.rs @@ -38,9 +38,9 @@ impl FirstToScore { } impl Picker for FirstToScore { - fn pick(&self, choices: &[Choice], utilities: &Query<&Score>) -> Option<Choice> { + fn pick(&self, choices: &[Choice], scores: &Query<&Score>) -> Option<Choice> { for choice in choices { - let value = choice.calculate(utilities); + let value = choice.calculate(scores); if value >= self.threshold { return Some(choice.clone()); } diff --git a/src/scorers.rs b/src/scorers.rs index c2c4cc5a71066cdda65acd18615b6e61e0d607b9..be31f35e685525c4eea3e7aea387bfb3c6f6fe50 100644 --- a/src/scorers.rs +++ b/src/scorers.rs @@ -66,6 +66,8 @@ pub trait ScorerBuilder: std::fmt::Debug + Sync + Send { fn attach(&self, cmd: &mut Commands, actor: Entity) -> Entity { let scorer_ent = cmd.spawn().id(); cmd.entity(scorer_ent) + .insert(Transform::default()) + .insert(GlobalTransform::default()) .insert(Score::default()) .insert(Actor(actor)); self.build(cmd, scorer_ent, actor); @@ -176,6 +178,8 @@ impl ScorerBuilder for AllOrNothingBuilder { .map(|scorer| scorer.attach(cmd, actor)) .collect(); cmd.entity(scorer) + .insert(Transform::default()) + .insert(GlobalTransform::default()) .insert(Score::default()) .push_children(&scorers[..]) .insert(AllOrNothing { @@ -256,7 +260,10 @@ impl ScorerBuilder for SumOfScorersBuilder { .iter() .map(|scorer| scorer.attach(cmd, actor)) .collect(); - cmd.entity(scorer).insert(AllOrNothing { + cmd.entity(scorer) + .insert(Transform::default()) + .insert(GlobalTransform::default()) + .insert(AllOrNothing { threshold: self.threshold, scorers: scorers.into_iter().map(ScorerEnt).collect(), }); diff --git a/src/thinker.rs b/src/thinker.rs index 84b0099d69e00a27d2bc2df181ff118e447b54c7..a8172e084d1c6a4caea507c03aa437e8487b22f7 100644 --- a/src/thinker.rs +++ b/src/thinker.rs @@ -118,13 +118,14 @@ impl ThinkerBuilder { impl ActionBuilder for ThinkerBuilder { fn build(&self, cmd: &mut Commands, action_ent: Entity, actor: Entity) { - println!("building thinker"); let choices = self .choices .iter() .map(|choice| choice.build(cmd, actor, action_ent)) .collect(); cmd.entity(action_ent) + .insert(Transform::default()) + .insert(GlobalTransform::default()) .insert(Thinker { // TODO: reasonable default?... picker: self @@ -190,7 +191,7 @@ pub fn thinker_system( mut cmd: Commands, mut iterations: Local<ThinkerIterations>, mut thinker_q: Query<(Entity, &Actor, &mut Thinker, &ActiveThinker)>, - utilities: Query<&Score>, + scores: Query<&Score>, mut action_states: Query<&mut actions::ActionState>, ) { let start = Instant::now(); @@ -229,7 +230,7 @@ pub fn thinker_system( } } ActionState::Requested | ActionState::Executing => { - if let Some(choice) = thinker.picker.pick(&thinker.choices, &utilities) { + if let Some(choice) = thinker.picker.pick(&thinker.choices, &scores) { // Think about what action we're supposed to be taking. We do this // every tick, because we might change our mind. // ...and then execute it (details below).