Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Action.cpp
Go to the documentation of this file.
1
2
3#include "Action.h"
4#include "WorldState.h"
5
6namespace Divide::goap
7{
8
9Action::Action() noexcept
10 : cost_( 0 )
11{
12}
13
14Action::Action(const string& name, I32 cost) : Action()
15{
16 // Because delegating constructors cannot initialize & delegate at the same time...
17 name_ = name;
18 cost_ = cost;
19}
20
21bool Action::eligibleFor(const WorldState& ws) const {
23 return false;
24 }
25
26 for (const auto& precond : preconditions_) {
27 try {
28 if (ws.vars_.at(precond.first) != precond.second) {
29 return false;
30 }
31 }
32 catch (const std::out_of_range&) {
33 return false;
34 }
35 }
36 return true;
37}
38
40 WorldState tmp(ws);
41 for (const auto& effect : effects_) {
42 tmp.setVariable(effect.first, effect.second);
43 }
44 return tmp;
45}
46
47} //namespace Divide::goap
operations preconditions_
Definition: Action.h:30
operations effects_
Definition: Action.h:33
virtual bool checkImplDependentCondition() const
Definition: Action.h:74
bool eligibleFor(const goap::WorldState &ws) const
Definition: Action.cpp:21
Action() noexcept
Definition: Action.cpp:9
WorldState actOn(const WorldState &ws) const
Definition: Action.cpp:39
int cost() const noexcept
Definition: Action.h:70
const string & name() const noexcept
Definition: Action.h:72
int32_t I32
void setVariable(const int var_id, const bool value)
Definition: WorldState.cpp:15
hashMap< I32, bool > vars_
Definition: WorldState.h:16