2
0

AIState.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. class AIState
  10. {
  11. public:
  12. AIState(class AIComponent* owner)
  13. :mOwner(owner)
  14. { }
  15. // State-specific behavior
  16. virtual void Update(float deltaTime) = 0;
  17. virtual void OnEnter() = 0;
  18. virtual void OnExit() = 0;
  19. // Getter for string name of state
  20. virtual const char* GetName() const = 0;
  21. protected:
  22. class AIComponent* mOwner;
  23. };
  24. class AIPatrol : public AIState
  25. {
  26. public:
  27. AIPatrol(class AIComponent* owner)
  28. :AIState(owner)
  29. { }
  30. // Override with behaviors for this state
  31. void Update(float deltaTime) override;
  32. void OnEnter() override;
  33. void OnExit() override;
  34. const char* GetName() const override
  35. { return "Patrol"; }
  36. };
  37. class AIDeath : public AIState
  38. {
  39. public:
  40. AIDeath(class AIComponent* owner)
  41. :AIState(owner)
  42. { }
  43. void Update(float deltaTime) override;
  44. void OnEnter() override;
  45. void OnExit() override;
  46. const char* GetName() const override
  47. { return "Death"; }
  48. };
  49. class AIAttack : public AIState
  50. {
  51. public:
  52. AIAttack(class AIComponent* owner)
  53. :AIState(owner)
  54. { }
  55. void Update(float deltaTime) override;
  56. void OnEnter() override;
  57. void OnExit() override;
  58. const char* GetName() const override
  59. { return "Attack"; }
  60. };