aiPlayer.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 _AIPLAYER_H_
  23. #define _AIPLAYER_H_
  24. #ifndef _PLAYER_H_
  25. #include "T3D/player.h"
  26. #endif
  27. class AIPlayer : public Player {
  28. typedef Player Parent;
  29. public:
  30. enum MoveState {
  31. ModeStop, // AI has stopped moving.
  32. ModeMove, // AI is currently moving.
  33. ModeStuck, // AI is stuck, but wants to move.
  34. ModeSlowing, // AI is slowing down as it reaches it's destination.
  35. };
  36. private:
  37. MoveState mMoveState;
  38. F32 mMoveSpeed;
  39. F32 mMoveTolerance; // Distance from destination before we stop
  40. Point3F mMoveDestination; // Destination for movement
  41. Point3F mLastLocation; // For stuck check
  42. F32 mMoveStuckTolerance; // Distance tolerance on stuck check
  43. S32 mMoveStuckTestDelay; // The number of ticks to wait before checking if the AI is stuck
  44. S32 mMoveStuckTestCountdown; // The current countdown until at AI starts to check if it is stuck
  45. bool mMoveSlowdown; // Slowdown as we near the destination
  46. SimObjectPtr<GameBase> mAimObject; // Object to point at, overrides location
  47. bool mAimLocationSet; // Has an aim location been set?
  48. Point3F mAimLocation; // Point to look at
  49. bool mTargetInLOS; // Is target object visible?
  50. Point3F mAimOffset;
  51. // Utility Methods
  52. void throwCallback( const char *name );
  53. public:
  54. DECLARE_CONOBJECT( AIPlayer );
  55. AIPlayer();
  56. ~AIPlayer();
  57. static void initPersistFields();
  58. bool onAdd();
  59. virtual bool getAIMove( Move *move );
  60. // Targeting and aiming sets/gets
  61. void setAimObject( GameBase *targetObject );
  62. void setAimObject( GameBase *targetObject, Point3F offset );
  63. GameBase* getAimObject() const { return mAimObject; }
  64. void setAimLocation( const Point3F &location );
  65. Point3F getAimLocation() const { return mAimLocation; }
  66. void clearAim();
  67. bool checkInLos(GameBase* target = NULL, bool _useMuzzle = false, bool _checkEnabled = false);
  68. bool checkInFoV(GameBase* target = NULL, F32 camFov = 45.0f, bool _checkEnabled = false);
  69. // Movement sets/gets
  70. void setMoveSpeed( const F32 speed );
  71. F32 getMoveSpeed() const { return mMoveSpeed; }
  72. void setMoveTolerance( const F32 tolerance );
  73. F32 getMoveTolerance() const { return mMoveTolerance; }
  74. void setMoveDestination( const Point3F &location, bool slowdown );
  75. Point3F getMoveDestination() const { return mMoveDestination; }
  76. void stopMove();
  77. };
  78. #endif