pub struct PlanExecutor {
pub state: ExecutorState,
pub max_depth: usize,
pub sim_time: f32,
pub replan_count: u32,
pub max_replans: u32,
pub history: Vec<String>,
/* private fields */
}Expand description
Drives execution of a GOAP plan, applying each action’s effects to the simulated world state, and replanning when the actual state diverges from the expected state.
§Replanning policy
After each action completes, the executor compares the observed world state (provided by the game) against the expected state (computed by applying planned effects). If they differ in any condition that the next action cares about, the executor discards the remainder of the plan and calls the planner again.
§Interruption
An external caller can call PlanExecutor::interrupt at any time. The
current step is marked Interrupted and the executor transitions to the
Interrupted state. The caller may then push a new goal and call
PlanExecutor::start to begin fresh.
Fields§
§state: ExecutorStateCurrent executor state.
max_depth: usizeMaximum plan depth for the A* search.
sim_time: f32Total simulation time elapsed.
replan_count: u32How many times the executor has replanned this goal.
max_replans: u32Maximum replanning attempts before giving up.
history: Vec<String>Log of completed action names in order.
Implementations§
Source§impl PlanExecutor
impl PlanExecutor
pub fn new(actions: Vec<Action>, max_depth: usize) -> Self
Sourcepub fn set_world_state(&mut self, state: WorldState)
pub fn set_world_state(&mut self, state: WorldState)
Set the initial world state.
Sourcepub fn update_bool(&mut self, key: &str, value: bool)
pub fn update_bool(&mut self, key: &str, value: bool)
Update a single bool condition in the simulated world state.
Sourcepub fn update_float(&mut self, key: &str, value: f32)
pub fn update_float(&mut self, key: &str, value: f32)
Update a single float condition in the simulated world state.
Sourcepub fn start(&mut self, goal: WorldState) -> Result<usize, PlanError>
pub fn start(&mut self, goal: WorldState) -> Result<usize, PlanError>
Push a new goal and (re)plan immediately.
Returns Ok(plan_length) on success or Err if no plan exists.
Sourcepub fn tick(
&mut self,
dt: f32,
observe_state: impl Fn(&WorldState) -> WorldState,
) -> Option<&str>
pub fn tick( &mut self, dt: f32, observe_state: impl Fn(&WorldState) -> WorldState, ) -> Option<&str>
Tick the executor by dt seconds.
observe_state should return the current observed world state,
incorporating any changes that happened outside the planner (e.g.
enemy died unexpectedly, health changed).
Returns the name of the action that should be executing this tick, or
None if idle/finished.
Sourcepub fn current_action(&self) -> Option<&str>
pub fn current_action(&self) -> Option<&str>
The name of the action currently executing, if any.
Sourcepub fn plan_names(&self) -> Vec<&str>
pub fn plan_names(&self) -> Vec<&str>
The full current plan as action names.
Sourcepub fn progress(&self) -> (usize, usize)
pub fn progress(&self) -> (usize, usize)
Progress through the current plan: (completed_steps, total_steps).
Sourcepub fn has_succeeded(&self) -> bool
pub fn has_succeeded(&self) -> bool
True if the executor has successfully completed its goal.
Sourcepub fn has_failed(&self) -> bool
pub fn has_failed(&self) -> bool
True if the executor has permanently failed.
Sourcepub fn world_state(&self) -> &WorldState
pub fn world_state(&self) -> &WorldState
Access the current simulated world state.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PlanExecutor
impl RefUnwindSafe for PlanExecutor
impl Send for PlanExecutor
impl Sync for PlanExecutor
impl Unpin for PlanExecutor
impl UnsafeUnpin for PlanExecutor
impl UnwindSafe for PlanExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.