3 releases (breaking)
0.3.0 | Aug 11, 2024 |
---|---|
0.2.0 | Aug 11, 2024 |
0.1.0 | Jul 22, 2024 |
#1399 in Game dev
Used in bevy_dogoap
34KB
804 lines
dogoap
- Data-Oriented, Goal-Oriented Action Planning
GOAP implemented in data-oriented way to facilitate dynamically setting up states/actions/goals rather than statically
This is a standalone Rust library for doing GOAP declaratively.
Pseudo-example
Given a current state like this:
is_hungry = true
And with the following available actions:
eat_action = Mutator::set("is_hungry", false)
And with a goal like this:
is_hungry = false
The magical planner can figure out the best path of actions to reach that goal. In this case, the best plan is just one eat_action
which results in the is_hungry
state variable to be set to false
, a very simplistic example.
That's the basics. Of course, things get more interesting once we start to include preconditions, multiple actions and multiple state variables, and the planner needs to figure out the right way of reaching there.
Code / API example
This is the actual API of the library:
use dogoap::prelude::*;
let start = LocalState::new().with_datum("is_hungry", Datum::Bool(true));
let goal = Goal::new().with_req("is_hungry", Compare::Equals(Datum::Bool(false)));
let eat_action = Action {
key: "eat".to_string(),
preconditions: vec![],
effects: vec![Effect {
action: "eat".to_string(),
mutators: vec![Mutator::Set("is_hungry".to_string(), Datum::Bool(false))],
state: LocalState::new(),
cost: 1,
}],
};
let actions: Vec<Action> = vec![eat_action];
let plan = make_plan(&start, &actions[..], &goal);
print_plan(plan.unwrap());
Dependencies
~7MB
~122K SLoC