AIState.cpp 1.5 KB

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