aiPlayer.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _AIPLAYER_H_ 25#define _AIPLAYER_H_ 26 27#ifndef _PLAYER_H_ 28#include "T3D/player.h" 29#endif 30 31#ifdef TORQUE_NAVIGATION_ENABLED 32#include "navigation/navPath.h" 33#include "navigation/navMesh.h" 34#include "navigation/coverPoint.h" 35#endif // TORQUE_NAVIGATION_ENABLED 36 37class AIPlayer : public Player { 38 39 typedef Player Parent; 40 41public: 42 enum MoveState { 43 ModeStop, // AI has stopped moving. 44 ModeMove, // AI is currently moving. 45 ModeStuck, // AI is stuck, but wants to move. 46 ModeSlowing, // AI is slowing down as it reaches it's destination. 47 }; 48 49private: 50 MoveState mMoveState; 51 F32 mMoveSpeed; 52 F32 mMoveTolerance; // Distance from destination before we stop 53 F32 mAttackRadius; // Distance to trigger weaponry calcs 54 Point3F mMoveDestination; // Destination for movement 55 Point3F mLastLocation; // For stuck check 56 F32 mMoveStuckTolerance; // Distance tolerance on stuck check 57 S32 mMoveStuckTestDelay; // The number of ticks to wait before checking if the AI is stuck 58 S32 mMoveStuckTestCountdown; // The current countdown until at AI starts to check if it is stuck 59 bool mMoveSlowdown; // Slowdown as we near the destination 60 61 SimObjectPtr<GameBase> mAimObject; // Object to point at, overrides location 62 bool mAimLocationSet; // Has an aim location been set? 63 Point3F mAimLocation; // Point to look at 64 bool mTargetInLOS; // Is target object visible? 65 66 Point3F mAimOffset; 67 68 // move triggers 69 bool mMoveTriggers[MaxTriggerKeys]; 70 71 // Utility Methods 72 void throwCallback( const char *name ); 73 74#ifdef TORQUE_NAVIGATION_ENABLED 75 /// Should we jump? 76 enum JumpStates { 77 None, ///< No, don't jump. 78 Now, ///< Jump immediately. 79 Ledge, ///< Jump when we walk off a ledge. 80 } mJump; 81 82 /// Stores information about a path. 83 struct PathData { 84 /// Pointer to path object. 85 SimObjectPtr<NavPath> path; 86 /// Do we own our path? If so, we will delete it when finished. 87 bool owned; 88 /// Path node we're at. 89 U32 index; 90 /// Default constructor. 91 PathData() : path(NULL) 92 { 93 owned = false; 94 index = 0; 95 } 96 }; 97 98 /// Path we are currently following. 99 PathData mPathData; 100 101 102 /// Get the current path we're following. 103 NavPath *getPath() { return mPathData.path; } 104 105 /// Stores information about our cover. 106 struct CoverData { 107 /// Pointer to a cover point. 108 SimObjectPtr<CoverPoint> cover; 109 /// Default constructor. 110 CoverData() : cover(NULL) {} 111 }; 112 113 /// Current cover we're trying to get to. 114 CoverData mCoverData; 115 116 117 /// Information about a target we're following. 118 struct FollowData { 119 /// Object to follow. 120 SimObjectPtr<SceneObject> object; 121 /// Distance at whcih to follow. 122 F32 radius; 123 Point3F lastPos; 124 /// Default constructor. 125 FollowData() : object(NULL) 126 { 127 radius = 5.0f; 128 lastPos = Point3F::Zero; 129 } 130 }; 131 132 /// Current object we're following. 133 FollowData mFollowData; 134 135 136 /// NavMesh we pathfind on. 137 SimObjectPtr<NavMesh> mNavMesh; 138 139 /// Move to the specified node in the current path. 140 void moveToNode(S32 node); 141#endif // TORQUE_NAVIGATION_ENABLED 142 143protected: 144 virtual void onReachDestination(); 145 virtual void onStuck(); 146 147public: 148 DECLARE_CONOBJECT( AIPlayer ); 149 150 AIPlayer(); 151 ~AIPlayer(); 152 153 static void initPersistFields(); 154 155 bool onAdd(); 156 void onRemove(); 157 158 virtual bool getAIMove( Move *move ); 159 virtual void updateMove(const Move *move); 160 /// Clear out the current path. 161 void clearPath(); 162 /// Stop searching for cover. 163 void clearCover(); 164 /// Stop following me! 165 void clearFollow(); 166 167 // Targeting and aiming sets/gets 168 void setAimObject( GameBase *targetObject ); 169 void setAimObject(GameBase *targetObject, const Point3F& offset); 170 GameBase* getAimObject() const { return mAimObject; } 171 void setAimLocation( const Point3F &location ); 172 Point3F getAimLocation() const { return mAimLocation; } 173 void clearAim(); 174 void getMuzzleVector(U32 imageSlot,VectorF* vec); 175 bool checkInLos(GameBase* target = NULL, bool _useMuzzle = false, bool _checkEnabled = false); 176 bool checkInFoV(GameBase* target = NULL, F32 camFov = 45.0f, bool _checkEnabled = false); 177 F32 getTargetDistance(GameBase* target, bool _checkEnabled); 178 179 // Movement sets/gets 180 void setMoveSpeed( const F32 speed ); 181 F32 getMoveSpeed() const { return mMoveSpeed; } 182 void setMoveTolerance( const F32 tolerance ); 183 F32 getMoveTolerance() const { return mMoveTolerance; } 184 void setMoveDestination( const Point3F &location, bool slowdown ); 185 Point3F getMoveDestination() const { return mMoveDestination; } 186 void stopMove(); 187 void setAiPose( S32 pose ); 188 S32 getAiPose(); 189 190 // Trigger sets/gets 191 void setMoveTrigger( U32 slot, const bool isSet = true ); 192 bool getMoveTrigger( U32 slot ) const; 193 void clearMoveTriggers(); 194 195#ifdef TORQUE_NAVIGATION_ENABLED 196 /// @name Pathfinding 197 /// @{ 198 199 enum NavSize { 200 Small, 201 Regular, 202 Large 203 } mNavSize; 204 void setNavSize(NavSize size) { mNavSize = size; updateNavMesh(); } 205 NavSize getNavSize() const { return mNavSize; } 206 207 bool setPathDestination(const Point3F &pos); 208 Point3F getPathDestination() const; 209 210 void followNavPath(NavPath *path); 211 void followObject(SceneObject *obj, F32 radius); 212 213 void repath(); 214 215 bool findCover(const Point3F &from, F32 radius); 216 217 NavMesh *findNavMesh() const; 218 void updateNavMesh(); 219 NavMesh *getNavMesh() const { return mNavMesh; } 220 221 /// Get cover we are moving to. 222 CoverPoint *getCover() { return mCoverData.cover; } 223 224 /// Types of link we can use. 225 LinkData mLinkTypes; 226 227 /// @} 228#endif // TORQUE_NAVIGATION_ENABLED 229}; 230 231#endif 232
