GOAP now uses only bit operations to do its thing.
This commit is contained in:
parent
01525388ec
commit
3d8a2d4342
4 changed files with 54 additions and 41 deletions
16
goap.cpp
16
goap.cpp
|
@ -8,22 +8,12 @@ namespace ailol {
|
|||
}
|
||||
|
||||
bool Action::can_effect(GOAPState& state) {
|
||||
for(auto [name, setting] : preconds) {
|
||||
if(state[name] != setting) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ((state & positive_preconds) == positive_preconds) &&
|
||||
((state & negative_preconds) == ALL_ZERO);
|
||||
}
|
||||
|
||||
GOAPState Action::apply_effect(GOAPState& state) {
|
||||
// RCR SUGGEST: state = (state & ~write_mask) | effect
|
||||
auto state_cp = state;
|
||||
|
||||
for(auto [name, setting] : effects) {
|
||||
state_cp[name] = setting;
|
||||
}
|
||||
|
||||
return state_cp;
|
||||
return (state | positive_effects) & ~negative_effects;
|
||||
}
|
||||
|
||||
int distance_to_goal(GOAPState& from, GOAPState& to) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue