home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / vehicle / VehicleDriver.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  6KB  |  186 lines

  1. //----------------------------------------------------------------
  2. // VehicleDriver.h
  3. //
  4. // Copyright 2002-2004 Raven Software
  5. //----------------------------------------------------------------
  6.  
  7. extern const idEventDef VD_ChoosePathTarget;
  8.  
  9. class rvVehicleDriver : public idActor {
  10.     friend class rvVehicleAI;
  11.     friend class rvVehicleMonster;
  12. public:
  13.  
  14.     CLASS_PROTOTYPE( rvVehicleDriver );
  15.  
  16.                             rvVehicleDriver                ( void );
  17.  
  18.     void                    Think                        ( void );
  19.     void                    Spawn                        ( void );
  20.  
  21.     static bool                IsValidTarget                ( const idEntity* ent );            // valid entity for looking or facing
  22.     static bool                IsValidPathNode                ( const idEntity* ent );            // valid entity for pathing
  23.     static bool                IsValidLeader                ( const idEntity* ent );            // valid entity to set as a leader
  24.  
  25.     static int                SortValid                    ( const void* a, const void* b );
  26.  
  27.     virtual void            Present                        ( void ) { }
  28.  
  29. protected:
  30.     void                    SimulateKeys                ( usercmd_t& cmd, float dotForward, float dotRight, float speed, float distance = 0 );
  31.     void                    SimulateButtons                ( usercmd_t& cmd );
  32.     void                    SimulateMouseMove            ( usercmd_t& cmd );
  33.  
  34.     bool                    GetTargetInfo                ( const idEntity* target, idVec3* targetOrigin, idVec3* dirToTarget, 
  35.                                                           float* dotForward, float* dotRight, float* distance ) const;
  36.     idEntity*                ChooseNextNode                ( idEntity* target );
  37.  
  38.     bool                    IsMoving                    ( void ) const { return isMoving && IsDriving();        }
  39.     bool                    IsDriving                    ( void ) const { return vehicleController.IsDriving();    }
  40.  
  41.     bool                    SetLeader                    ( idEntity* newLeader );
  42.     const idEntity*         GetLeader                    ( void ) const    { return leader;        }
  43.     void                    SetLeaderHint                ( int flags )    { leaderFlags = flags;    }
  44.     int                        GetLeaderHint                ( void ) const    { return leaderFlags;    }
  45.  
  46.     int                        SortTargetList                ( idEntity* ent ) const;
  47.     idEntity*                RandomValidTarget            ( idEntity* ent ) const;
  48.     int                        NumValidTargets                ( idEntity* ent ) const;
  49.     int                        NumTargets                    ( const idEntity* ent ) const;
  50.     idEntity*                GetTarget                    ( const idEntity* ent, int index ) const;
  51.  
  52.     void                    UpdateAutoCorrection        ( void );
  53.  
  54.     void                    Save                        ( idSaveGame *savefile ) const;
  55.     void                    Restore                        ( idRestoreGame *savefile );
  56.  
  57.     enum VD_PathingMode {
  58.         VDPM_Random        = 0,
  59.         VDPM_MoveTo        = 1,
  60.         VDPM_MoveAway    = 2,
  61.         VDPM_Custom        = 4,
  62.     };
  63.  
  64.  
  65.     void                    SetPathingMode                ( VD_PathingMode mode, const idVec3 & origin );
  66. //    CustomPathingFunc        SetPathingMode                ( VD_PathingMode mode, CustomPathingFunc cb );
  67.     idEntity *                SetPathingMode                ( VD_PathingMode mode, idEntity * );
  68.     VD_PathingMode             GetPathingMode                ( void ) const;
  69.     const idVec3 &             GetPathingOrigin            ( void ) const;
  70. //    CustomPathingFunc        GetPathingCustomCallback    ( void ) const;
  71.     idEntity *                GetPathingEntity            ( void ) const;
  72.  
  73. protected:
  74.     void                    Event_PostSpawn                ( void );
  75.     void                    Event_EnterVehicle            ( idEntity * vehicle );
  76.     void                    Event_ExitVehicle            ( bool force );
  77.     void                    Event_ScriptedMove            ( idEntity *target, float minDist, bool exitVehicle );
  78.     void                    Event_ScriptedDone            ( void );
  79.     void                    Event_ScriptedStop            ( void );
  80.     void                    Event_Trigger                ( idEntity *activator );
  81.     void                    Event_SetSpeed                ( float speed );
  82.     void                    Event_FireWeapon            ( float weapon_index, float time );
  83.     void                    Event_FaceEntity            ( const idEntity* entity );
  84.     void                    Event_LookAt                ( const idEntity* entity );
  85.     void                    Event_SetLeader                ( idEntity* newLeader );
  86.  
  87. //twhitaker: remove - begin
  88.     void                    Event_SetFollowOffset        ( const idVec3 &offset );
  89. //twhitaker: remove - end
  90.  
  91.     // Leader hints : a driver will send the following driving hints to it's leader
  92.     enum VD_LeaderHints {
  93.         VDLH_SlowDown    = 1,                            // Set when distance is too great
  94.         VDLH_Wait        = 2,                            // Set when there is no line of site
  95.         VDLH_Continue    = 0,                            // Default following behavior
  96.     };
  97.  
  98.     idStr & LeaderHintsString( int hints, idStr & out ) const {
  99.         switch ( hints ) {
  100.             case VDLH_SlowDown:        out = "SlowDown";    break;
  101.             case VDLH_Wait:            out = "Wait";        break;
  102.             default:                out = "Continue";    break;
  103.         }
  104.         return out;
  105.     }
  106.  
  107.     // Stores information about a path target
  108.     struct PathTargetInfo {
  109.         idEntityPtr<idEntity>        node;                // the target entity
  110.         float                        initialDistance;    // the distance to this entity when we first decide to move there
  111.         float                        minDistance;        // the range that specifies when this entity has been reached
  112.         float                        throttle;            // 0 -> 1 speed setting
  113.         bool                        exitVehicle;        // set to true to exit a vehicle when we reach this target
  114.     };
  115.  
  116.     struct PathNavigationData {
  117.         float                        dotForward;
  118.         float                        dotRight;
  119.     };
  120.  
  121.     // standard movement
  122.     PathTargetInfo                    pathTargetInfo;
  123.     PathTargetInfo                    lastPathTargetInfo;
  124.     float                            currentThrottle;
  125.  
  126.     // facing
  127.     idEntityPtr<const idEntity>        faceTarget;
  128.     idEntityPtr<const idEntity>        lookTarget;
  129.  
  130.     // following
  131.     idEntityPtr<rvVehicleDriver>    leader;                //TODO: twhitaker: see if I can make this an rvVehicle (so entities can follow player)
  132.     int                                leaderFlags;
  133.     float                            decelDistance;
  134.     float                            minDistance;
  135.     bool                            avoidingLeader;
  136.  
  137.     // firing
  138.     float                            fireEndTime;
  139.  
  140.     // event callbacks
  141.     rvScriptFuncUtility                func;
  142.  
  143.     // state
  144.     bool                            isMoving;
  145.  
  146.     VD_PathingMode                    pathingMode;
  147. //    idEntity *                        (* pathingCallback)( idEntity * );
  148.     idEntityPtr<idEntity>            pathingEntity;
  149.     idVec3                            pathingOrigin;
  150.  
  151.     float                            forwardThrustScale;
  152.     float                            rightThrustScale;
  153. };
  154.  
  155.  
  156. ID_INLINE void rvVehicleDriver::SetPathingMode( VD_PathingMode mode, const idVec3 & origin ) {
  157.     if ( mode != VDPM_Custom ) {
  158.         pathingMode        = mode;
  159.         pathingOrigin    = origin;
  160.     }
  161. }
  162.  
  163. ID_INLINE idEntity * rvVehicleDriver::SetPathingMode( VD_PathingMode mode, idEntity * entity ) {
  164.     if ( mode != VDPM_Custom ) {
  165.         return NULL;
  166.     }
  167.  
  168.     pathingMode            = mode;
  169.     idEntity * prev        = pathingEntity;
  170.     pathingEntity        = entity;
  171.     return prev;
  172. }
  173.  
  174. ID_INLINE rvVehicleDriver::VD_PathingMode rvVehicleDriver::GetPathingMode ( void ) const {
  175.     return pathingMode;
  176. }
  177.  
  178. ID_INLINE const idVec3 & rvVehicleDriver::GetPathingOrigin ( void ) const {
  179.     return pathingOrigin;
  180. }
  181.  
  182. ID_INLINE idEntity * rvVehicleDriver::GetPathingEntity ( void ) const {
  183.     return pathingEntity;
  184. }
  185.  
  186.