AIState.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "Base.h"
  2. #include "AIState.h"
  3. #include "AIAgent.h"
  4. #include "AIStateMachine.h"
  5. #include "Node.h"
  6. namespace gameplay
  7. {
  8. AIState* AIState::_empty = NULL;
  9. AIState::AIState(const char* id)
  10. : _id(id), _listener(NULL)
  11. {
  12. }
  13. AIState::~AIState()
  14. {
  15. }
  16. AIState* AIState::create(const char* id)
  17. {
  18. return new AIState(id);
  19. }
  20. const char* AIState::getId() const
  21. {
  22. return _id.c_str();
  23. }
  24. void AIState::setListener(Listener* listener)
  25. {
  26. _listener = listener;
  27. }
  28. void AIState::enter(AIStateMachine* stateMachine)
  29. {
  30. if (_listener)
  31. _listener->stateEnter(stateMachine->getAgent(), this);
  32. Node* node = stateMachine->_agent->_node;
  33. if (node)
  34. node->fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(Node, stateEnter), node, this);
  35. }
  36. void AIState::exit(AIStateMachine* stateMachine)
  37. {
  38. if (_listener)
  39. _listener->stateExit(stateMachine->getAgent(), this);
  40. Node* node = stateMachine->_agent->_node;
  41. if (node)
  42. node->fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(Node, stateExit), node, this);
  43. }
  44. void AIState::update(AIStateMachine* stateMachine, float elapsedTime)
  45. {
  46. if (_listener)
  47. _listener->stateUpdate(stateMachine->getAgent(), this, elapsedTime);
  48. Node* node = stateMachine->_agent->_node;
  49. if (node)
  50. node->fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(Node, stateUpdate), node, this, elapsedTime);
  51. }
  52. AIState::Listener::~Listener()
  53. {
  54. }
  55. void AIState::Listener::stateEnter(AIAgent* agent, AIState* state)
  56. {
  57. }
  58. void AIState::Listener::stateExit(AIAgent* agent, AIState* state)
  59. {
  60. }
  61. void AIState::Listener::stateUpdate(AIAgent* agent, AIState* state, float elapsedTime)
  62. {
  63. }
  64. }