AINavigation.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _AINAVIGATION_H_
  23. #define _AINAVIGATION_H_
  24. #include "AIInfo.h"
  25. #include "navigation/navPath.h"
  26. #include "navigation/navMesh.h"
  27. class AIController;
  28. struct AINavigation
  29. {
  30. AIController* mControllerRef;
  31. AIController* getCtrl() { return mControllerRef; };
  32. AINavigation() = delete;
  33. AINavigation(AIController* controller);
  34. ~AINavigation();
  35. Point3F mMoveDestination;
  36. void setMoveDestination(const Point3F& location, bool slowdown);
  37. Point3F getMoveDestination() const { return mMoveDestination; };
  38. bool setPathDestination(const Point3F& pos, bool replace = false);
  39. Point3F getPathDestination() const;
  40. void onReachDestination();
  41. void followObject();
  42. void followObject(SceneObject* obj, F32 radius);
  43. void clearFollow();
  44. #ifdef TORQUE_NAVIGATION_ENABLED
  45. /// Stores information about a path.
  46. struct PathData {
  47. /// Pointer to path object.
  48. SimObjectPtr<NavPath> path;
  49. /// Do we own our path? If so, we will delete it when finished.
  50. bool owned;
  51. /// Path node we're at.
  52. U32 index;
  53. /// Default constructor.
  54. PathData() : path(NULL)
  55. {
  56. owned = false;
  57. index = 0;
  58. }
  59. };
  60. /// Should we jump?
  61. enum JumpStates {
  62. None, ///< No, don't jump.
  63. Now, ///< Jump immediately.
  64. Ledge, ///< Jump when we walk off a ledge.
  65. };
  66. enum NavSize {
  67. Small,
  68. Regular,
  69. Large
  70. } mNavSize;
  71. void setNavSize(NavSize size) { mNavSize = size; updateNavMesh(); }
  72. NavSize getNavSize() const { return mNavSize; }
  73. /// NavMesh we pathfind on.
  74. SimObjectPtr<NavMesh> mNavMesh;
  75. NavMesh* findNavMesh() const;
  76. void updateNavMesh();
  77. NavMesh* getNavMesh() const { return mNavMesh; }
  78. PathData mPathData;
  79. JumpStates mJump;
  80. /// Clear out the current path.
  81. void clearPath();
  82. void repath();
  83. /// Get the current path we're following.
  84. SimObjectPtr<NavPath> getPath() { return mPathData.path; };
  85. void followNavPath(NavPath* path);
  86. /// Move to the specified node in the current path.
  87. void moveToNode(S32 node);
  88. bool avoidObstacles();
  89. bool flock();
  90. #endif
  91. };
  92. #endif