39 lines
862 B
C++
39 lines
862 B
C++
#include <set>
|
|
#include "goap.h"
|
|
bool BaseAction::can_run(const ECS::Blackboard &state, bool debug)
|
|
{
|
|
return m_exec->_can_run(state, debug);
|
|
}
|
|
void BaseAction::_plan_effects(ECS::Blackboard &state)
|
|
{
|
|
state.clear_flag(m_exec->m_clear_bits);
|
|
state.set_flag(m_exec->m_set_bits);
|
|
}
|
|
bool BaseAction::is_active(const ECS::Blackboard &state)
|
|
{
|
|
return m_exec->is_active(state);
|
|
}
|
|
bool BaseAction::stop(ECS::Blackboard &state)
|
|
{
|
|
if (!is_active(state))
|
|
return false;
|
|
m_exec->_exit(state);
|
|
state._active.erase(m_exec.get());
|
|
return true;
|
|
}
|
|
int BaseAction::execute(ECS::Blackboard &state)
|
|
{
|
|
if (!is_active(state)) {
|
|
state._active.insert(m_exec.get());
|
|
m_exec->_enter(state);
|
|
}
|
|
int ret = m_exec->_execute(state);
|
|
if (ret == OK)
|
|
stop(state);
|
|
return ret;
|
|
}
|
|
int BaseAction::get_cost(const ECS::Blackboard &state) const
|
|
{
|
|
return m_exec->_get_cost(state);
|
|
}
|