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

  1. // RAVEN BEGIN
  2. // bdube: note that this file is no longer merged with Doom3 updates
  3. //
  4. // MERGE_DATE 9/30/2004
  5.  
  6. #ifndef __GAME_WEAPON_H__
  7. #define __GAME_WEAPON_H__
  8.  
  9. /*
  10. ===============================================================================
  11.  
  12.     Player Weapon
  13.     
  14. ===============================================================================
  15. */
  16.  
  17. typedef enum {
  18.     WP_READY,
  19.     WP_OUTOFAMMO,
  20.     WP_RELOAD,
  21.     WP_HOLSTERED,
  22.     WP_RISING,
  23.     WP_LOWERING,
  24.     WP_FLASHLIGHT,
  25. } weaponStatus_t;
  26.  
  27. static const int MAX_WEAPONMODS    = 4;
  28. static const int MAX_AMMOTYPES    = 16;
  29.  
  30. class idPlayer;
  31. class idItem;
  32. class idAnimatedEntity;
  33. class idProjectile;
  34.  
  35. class rvViewWeapon : public idAnimatedEntity {
  36. public:
  37.  
  38.     CLASS_PROTOTYPE( rvViewWeapon );
  39.  
  40.                             rvViewWeapon( void );
  41.     virtual                    ~rvViewWeapon( void );
  42.  
  43.     // Init
  44.     void                    Spawn                        ( void );
  45.  
  46.     // save games
  47.     void                    Save                        ( idSaveGame *savefile ) const;                    // archives object for save game file
  48.     void                    Restore                        ( idRestoreGame *savefile );                    // unarchives object from save game file
  49.  
  50.  
  51.     // Weapon definition management
  52.     void                    Clear                        ( void );
  53.  
  54.     // GUIs
  55.     void                    PostGUIEvent                ( const char* event );
  56.  
  57.     virtual void            SetModel                    ( const char *modelname, int mods = 0 );
  58.     void                    SetPowerUpSkin                ( const char *name );
  59.     void                    UpdateSkin                    ( void );
  60.  
  61.     // State control/player interface
  62.     void                    Think                        ( void );
  63.  
  64.     // Visual presentation
  65.     void                    PresentWeapon                ( bool showViewModel );
  66.  
  67.     // Networking
  68.     virtual void            WriteToSnapshot                ( idBitMsgDelta &msg ) const;
  69.     virtual void            ReadFromSnapshot            ( const idBitMsgDelta &msg );
  70.     virtual bool            ClientReceiveEvent            ( int event, int time, const idBitMsg &msg );
  71.     virtual void            ClientPredictionThink        ( void );
  72.     virtual bool            ClientStale                    ( void );
  73.  
  74.     virtual void            ConvertLocalToWorldTransform( idVec3 &offset, idMat3 &axis );
  75.     virtual void            UpdateModelTransform        ( void );
  76.  
  77.     // Debugging
  78.     virtual void            GetDebugInfo                ( debugInfoProc_t proc, void* userData );
  79.  
  80.  
  81.     void                    SetSkin                        ( const char *skinname );
  82.     void                    SetSkin                        ( const idDeclSkin* skin );
  83.  
  84.     void                    SetOverlayShader            ( const idMaterial* material );
  85.  
  86.     virtual void            GetPosition                    ( idVec3& origin, idMat3& axis ) const;
  87.  
  88. private:
  89.  
  90.     idStrList                pendingGUIEvents;
  91.  
  92.     // effects
  93.     const idDeclSkin *        saveSkin;
  94.     const idDeclSkin *        invisSkin;
  95.     const idDeclSkin *        saveWorldSkin;
  96.     const idDeclSkin *        worldInvisSkin;
  97.     const idDeclSkin *        saveHandsSkin;
  98.     const idDeclSkin *        handsSkin;
  99.         
  100.     void                    Event_CallFunction            ( const char* function );
  101.     
  102.     friend        class rvWeapon;
  103.     rvWeapon*    weapon;
  104. };
  105.  
  106. class rvWeapon : public idClass {
  107. public:
  108.  
  109.     CLASS_PROTOTYPE( rvWeapon );
  110.  
  111.     rvWeapon( void );
  112.     virtual ~rvWeapon( void );
  113.     
  114.     enum {
  115.         WPLIGHT_MUZZLEFLASH,
  116.         WPLIGHT_MUZZLEFLASH_WORLD,
  117.         WPLIGHT_FLASHLIGHT,
  118.         WPLIGHT_FLASHLIGHT_WORLD,
  119.         WPLIGHT_GUI,
  120.         WPLIGHT_MAX
  121.     };
  122.  
  123.     enum {
  124.         EVENT_RELOAD = idEntity::EVENT_MAXEVENTS,
  125.         EVENT_ENDRELOAD,
  126.         EVENT_CHANGESKIN,
  127.         EVENT_MAXEVENTS
  128.     };
  129.     
  130.     void                Init                        ( idPlayer* _owner, const idDeclEntityDef* def, int weaponIndex, bool isStrogg = false );
  131.  
  132.     // Virtual overrides
  133.     void                Spawn                        ( void );
  134.     virtual void        Think                        ( void );
  135.     virtual void        CleanupWeapon                ( void ) {}
  136.     virtual void        WriteToSnapshot                ( idBitMsgDelta &msg ) const;
  137.     virtual void        ReadFromSnapshot            ( const idBitMsgDelta &msg );
  138.     virtual bool        ClientReceiveEvent            ( int event, int time, const idBitMsg &msg );
  139.     virtual void        ClientStale                    ( void );
  140.     virtual void        Attack                        ( bool altFire, int num_attacks, float spread, float fuseOffset, float power );
  141.     virtual void        GetDebugInfo                ( debugInfoProc_t proc, void* userData );
  142.  
  143. #ifdef _XENON
  144.     virtual bool        AllowAutoAim                ( void ) const { return true; }
  145. #endif
  146.  
  147.     void                Save                        ( idSaveGame *savefile ) const;
  148.     void                Restore                        ( idRestoreGame *savefile );
  149.     virtual void        PreSave                        ( void );
  150.     virtual void        PostSave                    ( void );
  151.  
  152.  
  153.     // Visual presentation
  154.     bool                BloodSplat                    ( float size );
  155.     void                MuzzleFlash                    ( void );
  156.     void                MuzzleRise                    ( idVec3 &origin, idMat3 &axis );
  157.     float                GetMuzzleFlashLightParm        ( int parm );
  158.     void                SetMuzzleFlashLightParm        ( int parm, float value );
  159.     void                GetAngleOffsets                ( int *average, float *scale, float *max );
  160.     void                GetTimeOffsets                ( float *time, float *scale );
  161.     bool                GetGlobalJointTransform        ( bool viewModel, const jointHandle_t jointHandle, idVec3 &origin, idMat3 &axis, const idVec3& offset = vec3_origin );
  162.  
  163.     // State control/player interface
  164.     void                LowerWeapon                    ( void );
  165.     void                RaiseWeapon                    ( void );
  166.     void                Raise                        ( void );
  167.     void                PutAway                        ( void );
  168.     void                Hide                        ( void );
  169.     void                Show                        ( void );
  170.     void                HideWorldModel                ( void );
  171.     void                ShowWorldModel                ( void );
  172.     void                SetFlashlight                ( bool on = true );
  173.     void                Flashlight                    ( void );
  174.     void                SetPushVelocity                ( const idVec3 &pushVelocity );
  175.     void                Reload                        ( void );
  176.     void                OwnerDied                    ( void );
  177.     void                BeginAttack                    ( void );
  178.     void                EndAttack                    ( void );
  179.     bool                IsReady                        ( void ) const;
  180.     bool                IsReloading                    ( void ) const;
  181.     bool                IsHolstered                    ( void ) const;
  182.     bool                ShowCrosshair                ( void ) const;
  183.     bool                CanDrop                        ( void ) const;
  184.     bool                CanZoom                        ( void ) const;
  185.     void                CancelReload                ( void );
  186.     void                SetStatus                    ( weaponStatus_t status );
  187.     bool                AutoReload                    ( void );
  188.     bool                IsHidden                    ( void ) const;
  189.     void                EjectBrass                    ( void );
  190.  
  191.     // Network helpers
  192.     void                NetReload                    ( void );
  193.     void                NetEndReload                ( void );
  194.     void                NetCatchup                    ( void );
  195.  
  196.     // Ammo
  197.     static int            GetAmmoIndexForName            ( const char *ammoname );
  198.     static const char*    GetAmmoNameForIndex            ( int index );
  199.     int                    GetAmmoType                    ( void ) const;
  200.     int                    AmmoAvailable                ( void ) const;
  201.     int                    AmmoInClip                    ( void ) const;
  202.     void                ResetAmmoClip                ( void );
  203.     int                    ClipSize                    ( void ) const;
  204.     int                    LowAmmo                        ( void ) const;
  205.     int                    AmmoRequired                ( void ) const;
  206.     void                AddToClip                    ( int amount );
  207.     void                UseAmmo                        ( int amount );
  208.     void                SetClip                        ( int amount );
  209.     int                    TotalAmmoCount                ( void ) const;
  210.  
  211.     // Attack
  212.     bool                PerformAttack                ( idVec3& muzzleOrigin, idMat3& muzzleAxis, float dmgPower );
  213.     void                LaunchProjectiles            ( idDict& dict, const idVec3& muzzleOrigin, const idMat3& muzzleAxis, int num_projectiles, float spread, float fuseOffset, float power );
  214.     void                Hitscan                        ( const idDict& dict, const idVec3& muzzleOrigin, const idMat3& muzzleAxis, int num_hitscans, float spread, float power );
  215.     void                AlertMonsters                ( void );
  216.  
  217.     // Mods
  218.     int                    GetMods                        ( void ) const;
  219.  
  220.     // Zoom
  221.     idUserInterface*    GetZoomGui                    ( void ) const;
  222.     float                GetZoomTime                    ( void ) const;
  223.     int                    GetZoomFov                    ( void ) const;
  224.  
  225.     rvViewWeapon*        GetViewModel                ( void ) const;
  226.     idAnimatedEntity*    GetWorldModel                ( void ) const;
  227.     idPlayer*            GetOwner                    ( void ) const;
  228.     const char *        GetIcon                        ( void ) const;
  229.     renderLight_t&        GetLight                    ( int light );
  230.     const idAngles&        GetViewModelAngles            ( void ) const;
  231.     const idVec3&        GetViewModelOffset            ( void ) const;
  232.  
  233.      static void            CacheWeapon                    ( const char *weaponName );
  234.     static void            SkipFromSnapshot            ( const idBitMsgDelta &msg );
  235.  
  236.     void                EnterCinematic                ( void );
  237.     void                ExitCinematic                ( void );
  238.  
  239. protected:
  240.  
  241.     virtual void        OnLaunchProjectile            ( idProjectile* proj );
  242.  
  243.     void                SetState                    ( const char *statename, int blendFrames );
  244.     void                PostState                    ( const char *statename, int blendFrames );
  245.     void                ExecuteState                ( const char *statename );
  246.  
  247.     void                PlayAnim                    ( int channel, const char *animname, int blendFrames );
  248.     void                PlayCycle                    ( int channel, const char *animname, int blendFrames );
  249.     bool                AnimDone                    ( int channel, int blendFrames );
  250.     bool                StartSound                    ( const char *soundName, const s_channelType channel, int soundShaderFlags, bool broadcast, int *length );
  251.     void                StopSound                    ( const s_channelType channel, bool broadcast );
  252.     rvClientEffect*        PlayEffect                    ( const char* effectName, jointHandle_t joint, bool loop = false, const idVec3& endOrigin = vec3_origin, bool broadcast = false );
  253.  
  254.     void                FindViewModelPositionStyle    ( idVec3& viewOffset, idAngles& viewAngles ) const;
  255.  
  256. public:
  257.  
  258.     void                InitLights                    ( void );
  259.     void                InitWorldModel                ( void );
  260.     void                InitViewModel                ( void );
  261.     void                InitDefs                    ( void );
  262.  
  263.     void                FreeLight                    ( int lightID );
  264.     void                UpdateLight                    ( int lightID );
  265.  
  266.     void                UpdateMuzzleFlash            ( void );
  267.     void                UpdateFlashlight            ( void );    
  268.  
  269.     void                UpdateGUI                    ( void );
  270.     void                UpdateCrosshairGUI            ( idUserInterface* gui ) const;
  271.  
  272.     idMat3                ForeshortenAxis                ( const idMat3& axis ) const;
  273.  
  274.     // Script state management
  275.     struct weaponStateFlags_s {
  276.         bool        attack                :1;
  277.         bool        reload                :1;
  278.         bool        netReload            :1;
  279.         bool        netEndReload        :1;
  280.         bool        raiseWeapon            :1;
  281.         bool        lowerWeapon            :1;
  282.         bool        flashlight            :1;
  283.         bool        zoom                :1;
  284.     } wsfl;        
  285.     
  286.     // Generic flags
  287.     struct weaponFlags_s {
  288.         bool        attackAltHitscan    :1;
  289.         bool        attackHitscan        :1;
  290.         bool        hide                :1;
  291.         bool        disabled            :1;
  292.         bool        hasBloodSplat        :1;
  293.         bool        silent_fire            :1;
  294.         bool        zoomHideCrosshair    :1;
  295.         bool        flashlightOn        :1;
  296.         bool        hasWindupAnim        :1;
  297.     } wfl;
  298.     
  299.     // joints from models
  300.     jointHandle_t                    barrelJointView;
  301.     jointHandle_t                    flashJointView;
  302.     jointHandle_t                    ejectJointView;
  303.     jointHandle_t                    guiLightJointView;
  304.     jointHandle_t                    flashlightJointView;
  305.  
  306.     jointHandle_t                    flashJointWorld;
  307.     jointHandle_t                    ejectJointWorld;
  308.     jointHandle_t                    flashlightJointWorld;
  309.     
  310.     weaponStatus_t                    status;
  311.     int                                lastAttack;
  312.  
  313.     // hiding weapon
  314.     int                                hideTime;
  315.      float                            hideDistance;
  316.      int                                hideStartTime;
  317.     float                            hideStart;
  318.     float                            hideEnd;
  319.     float                            hideOffset;
  320.  
  321.     // Attack
  322.     idVec3                            pushVelocity;
  323.     int                                kick_endtime;
  324.     int                                muzzle_kick_time;
  325.     int                                muzzle_kick_maxtime;
  326.     idAngles                        muzzle_kick_angles;
  327.     idVec3                            muzzle_kick_offset;
  328.     idVec3                            muzzleOrigin;
  329.     idMat3                            muzzleAxis;
  330.     float                            muzzleOffset;
  331.     idEntityPtr<idEntity>            projectileEnt;
  332.     idVec3                            ejectOffset;
  333.  
  334.     int                                fireRate;
  335.     int                                altFireRate;
  336.     float                            spread;
  337.     int                                nextAttackTime;
  338.  
  339.     // we maintain local copies of the projectile and brass dictionaries so they
  340.     // do not have to be copied across the DLL boundary when entities are spawned
  341.     idDict                            attackAltDict;
  342.     idDict                            attackDict;
  343.     idDict                            brassDict;
  344.  
  345.     // Melee
  346.     const idDeclEntityDef *            meleeDef;
  347.     float                            meleeDistance;
  348.  
  349.     // zoom
  350.     int                                zoomFov;                // variable zoom fov per weapon (-1 is no zoom)
  351.     idUserInterface*                zoomGui;                // whether or not to overlay a zoom scope
  352.     float                            zoomTime;                // time it takes to zoom in
  353.  
  354.     // lights
  355.     renderLight_t                    lights[WPLIGHT_MAX];
  356.     int                                lightHandles[WPLIGHT_MAX];
  357.     idVec3                            guiLightOffset;    
  358.     int                                muzzleFlashEnd;
  359.     int                                muzzleFlashTime;
  360.     idVec3                            muzzleFlashViewOffset;
  361.     bool                            flashlightOn;
  362.     idVec3                            flashlightViewOffset;    
  363.  
  364.     // ammo management
  365.     int                                ammoType;
  366.     int                                ammoRequired;        // amount of ammo to use each shot.  0 means weapon doesn't need ammo.
  367.     int                                clipSize;            // 0 means no reload
  368.     int                                ammoClip;
  369.     int                                lowAmmo;            // if ammo in clip hits this threshold, snd_
  370.     int                                maxAmmo;        
  371.  
  372.      // multiplayer
  373.      int                                clipPredictTime;
  374.  
  375.     // these are the player render view parms, which include bobbing
  376.     idVec3                            playerViewOrigin;
  377.     idMat3                            playerViewAxis;
  378.  
  379.  
  380.     // View Model
  381.     idVec3                            viewModelOrigin;
  382.     idMat3                            viewModelAxis;
  383.     idAngles                        viewModelAngles;
  384.     idVec3                            viewModelOffset;
  385.  
  386.     // weighting for viewmodel offsets 
  387.     int                                weaponAngleOffsetAverages;
  388.     float                            weaponAngleOffsetScale;
  389.     float                            weaponAngleOffsetMax;
  390.     float                            weaponOffsetTime;
  391.     float                            weaponOffsetScale;
  392.  
  393.     // General
  394.     idStr                            icon;
  395.     bool                            isStrogg;
  396.  
  397. public:
  398.  
  399.     idDict                            spawnArgs;
  400.  
  401. protected:
  402.  
  403.     idEntityPtr<rvViewWeapon>        viewModel;
  404.     idAnimator*                        viewAnimator;
  405.     idEntityPtr<idAnimatedEntity>    worldModel;
  406.     idAnimator*                        worldAnimator;
  407.     const idDeclEntityDef*            weaponDef;
  408.     idScriptObject*                    scriptObject;
  409.     idPlayer *                        owner;
  410.     int                                weaponIndex;
  411.     int                                mods;
  412.  
  413.     float                            viewModelForeshorten;
  414.  
  415.     rvStateThread                    stateThread;
  416.     int                                animDoneTime[ANIM_NumAnimChannels];
  417.  
  418. private:
  419.  
  420.     stateResult_t            State_Raise                ( const stateParms_t& parms );
  421.     stateResult_t            State_Lower                ( const stateParms_t& parms );
  422.     stateResult_t            State_ExitCinematic        ( const stateParms_t& parms );
  423.     stateResult_t            State_NetCatchup        ( const stateParms_t& parms );
  424.  
  425.     stateResult_t            Frame_EjectBrass        ( const stateParms_t& parms );    
  426.  
  427.     // store weapon index information for death messages
  428.     int                        methodOfDeath;
  429.  
  430.     // multiplayer hitscans
  431.     int                        hitscanAttackDef;
  432.  
  433.     CLASS_STATES_PROTOTYPE ( rvWeapon );
  434. };
  435.  
  436. ID_INLINE rvViewWeapon* rvWeapon::GetViewModel ( void ) const {
  437.     return viewModel.GetEntity();
  438. }
  439.  
  440. ID_INLINE idAnimatedEntity* rvWeapon::GetWorldModel ( void ) const {
  441.     return worldModel;
  442. }
  443.  
  444. ID_INLINE idPlayer* rvWeapon::GetOwner ( void ) const {
  445.     return owner;
  446. }
  447.  
  448. ID_INLINE const char* rvWeapon::GetIcon ( void ) const {
  449.     return icon;
  450. }
  451.  
  452. ID_INLINE renderLight_t& rvWeapon::GetLight ( int light ) {
  453.     assert ( light < WPLIGHT_MAX );
  454.     return lights[light];    
  455. }
  456.  
  457. ID_INLINE const idAngles& rvWeapon::GetViewModelAngles( void ) const {
  458.     return viewModelAngles;
  459. }
  460.  
  461. ID_INLINE const idVec3& rvWeapon::GetViewModelOffset ( void ) const {
  462.     return viewModelOffset;
  463. }
  464.  
  465. ID_INLINE int rvWeapon::GetZoomFov ( void ) const {
  466.     return zoomFov;
  467. }
  468.  
  469. ID_INLINE idUserInterface* rvWeapon::GetZoomGui ( void ) const {
  470.     return zoomGui;
  471. }
  472.  
  473. ID_INLINE float rvWeapon::GetZoomTime ( void ) const {
  474.     return zoomTime;
  475. }
  476.  
  477. ID_INLINE int rvWeapon::GetMods ( void ) const {
  478.     return mods;
  479. }
  480.  
  481. ID_INLINE void rvWeapon::PreSave ( void ) {
  482. }
  483.  
  484. ID_INLINE void rvWeapon::PostSave ( void ) {
  485. }
  486.  
  487.  
  488. #endif /* !__GAME_WEAPON_H__ */
  489.  
  490. // RAVEN END
  491.