#include "Base.h" #include "AIState.h" #include "AIStateMachine.h" namespace gameplay { AIState* AIState::_empty = NULL; AIState::AIState(const char* id) : _id(id), _listener(NULL) { addScriptEvent("enter", ""); addScriptEvent("exit", ""); addScriptEvent("update", "f"); } AIState::~AIState() { } AIState* AIState::create(const char* id) { return new AIState(id); } const char* AIState::getId() const { return _id.c_str(); } void AIState::setListener(Listener* listener) { _listener = listener; } void AIState::enter(AIStateMachine* stateMachine) { if (_listener) _listener->stateEnter(stateMachine->getAgent(), this); fireScriptEvent("enter", stateMachine->getAgent(), this); } void AIState::exit(AIStateMachine* stateMachine) { if (_listener) _listener->stateExit(stateMachine->getAgent(), this); fireScriptEvent("exit", stateMachine->getAgent(), this); } void AIState::update(AIStateMachine* stateMachine, float elapsedTime) { if (_listener) _listener->stateUpdate(stateMachine->getAgent(), this, elapsedTime); fireScriptEvent("update", stateMachine->getAgent(), this, elapsedTime); } AIState::Listener::~Listener() { } void AIState::Listener::stateEnter(AIAgent* agent, AIState* state) { } void AIState::Listener::stateExit(AIAgent* agent, AIState* state) { } void AIState::Listener::stateUpdate(AIAgent* agent, AIState* state, float elapsedTime) { } }