//----------------------------------------------------------------------------- // Copyright (c) 2012 GarageGames, LLC // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- #ifndef _AIPLAYER_H_ #define _AIPLAYER_H_ #ifndef _PLAYER_H_ #include "T3D/player.h" #endif class AIPlayer : public Player { typedef Player Parent; public: enum MoveState { ModeStop, // AI has stopped moving. ModeMove, // AI is currently moving. ModeStuck, // AI is stuck, but wants to move. ModeSlowing, // AI is slowing down as it reaches it's destination. }; private: MoveState mMoveState; F32 mMoveSpeed; F32 mMoveTolerance; // Distance from destination before we stop Point3F mMoveDestination; // Destination for movement Point3F mLastLocation; // For stuck check F32 mMoveStuckTolerance; // Distance tolerance on stuck check S32 mMoveStuckTestDelay; // The number of ticks to wait before checking if the AI is stuck S32 mMoveStuckTestCountdown; // The current countdown until at AI starts to check if it is stuck bool mMoveSlowdown; // Slowdown as we near the destination SimObjectPtr mAimObject; // Object to point at, overrides location bool mAimLocationSet; // Has an aim location been set? Point3F mAimLocation; // Point to look at bool mTargetInLOS; // Is target object visible? Point3F mAimOffset; // Utility Methods void throwCallback( const char *name ); public: DECLARE_CONOBJECT( AIPlayer ); AIPlayer(); ~AIPlayer(); static void initPersistFields(); bool onAdd(); virtual bool getAIMove( Move *move ); // Targeting and aiming sets/gets void setAimObject( GameBase *targetObject ); void setAimObject( GameBase *targetObject, Point3F offset ); GameBase* getAimObject() const { return mAimObject; } void setAimLocation( const Point3F &location ); Point3F getAimLocation() const { return mAimLocation; } void clearAim(); bool checkInLos(GameBase* target = NULL, bool _useMuzzle = false, bool _checkEnabled = false); bool checkInFoV(GameBase* target = NULL, F32 camFov = 45.0f, bool _checkEnabled = false); // Movement sets/gets void setMoveSpeed( const F32 speed ); F32 getMoveSpeed() const { return mMoveSpeed; } void setMoveTolerance( const F32 tolerance ); F32 getMoveTolerance() const { return mMoveTolerance; } void setMoveDestination( const Point3F &location, bool slowdown ); Point3F getMoveDestination() const { return mMoveDestination; } void stopMove(); }; #endif