Advertisement
Guest User

Error [mod0000_mergedfiles]game\gameplay\focus\focus.ws(645)

a guest
Nov 8th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.66 KB | None | 0 0
  1. /***********************************************************************/
  2. /**     © 2015 CD PROJEKT S.A. All rights reserved.
  3. /**     THE WITCHER® is a trademark of CD PROJEKT S. A.
  4. /**     The Witcher game is based on the prose of Andrzej Sapkowski.
  5. /***********************************************************************/
  6. enum EFocusModeChooseEntityStrategy
  7. {
  8.     FMCES_ChooseNearest,
  9.     FMCES_ChooseMostIntense,
  10. }
  11.  
  12. import class CFocusActionComponent extends CComponent
  13. {
  14.     import var actionName : name;
  15. };
  16.  
  17. class W3FocusModeEffectIntensity
  18. {
  19.     var chooseEntityStrategy    : EFocusModeChooseEntityStrategy;
  20.     var bestEntity              : CEntity;
  21.     var bestDistance            : float;
  22.     var lastDistance            : float;
  23.     var bestIntensity           : float;
  24.     var lastIntensity           : float;
  25.        
  26.     public function Init( strategy : EFocusModeChooseEntityStrategy )
  27.     {
  28.         chooseEntityStrategy = strategy;
  29.         bestEntity = NULL;
  30.         bestDistance = 0.0f;
  31.         lastDistance = 0.0f;
  32.         bestIntensity = 0.0f;
  33.         lastIntensity = 0.0f;
  34.     }
  35.  
  36.     public function Update( entity : CEntity, distance : float, intensity : float )
  37.     {
  38.         if ( IsBestEntity( distance, intensity ) )
  39.         {
  40.             bestEntity = entity;
  41.             bestDistance = distance;
  42.             bestIntensity = intensity;
  43.         }      
  44.     }
  45.  
  46.     public function ForceUpdate( entity : CEntity, distance : float, intensity : float )
  47.     {
  48.         bestEntity = entity;
  49.         bestDistance = distance;
  50.         bestIntensity = intensity;
  51.     }
  52.  
  53.     public function ValueChanged() : bool
  54.     {
  55.         return ( bestIntensity != lastIntensity );
  56.     }
  57.  
  58.     public function GetValue( optional reset : bool ) : float
  59.     {
  60.         return lastIntensity;
  61.     }
  62.    
  63.     public function GetBestEntity() : CEntity
  64.     {
  65.         return bestEntity;
  66.     }
  67.    
  68.     public function Reset()
  69.     {
  70.         lastIntensity = bestIntensity;
  71.         bestIntensity = 0.0f;
  72.         bestDistance = 0.0f;
  73.         bestEntity = NULL; 
  74.     }
  75.    
  76.     function IsBestEntity( distance : float, intensity : float ) : bool
  77.     {
  78.         if ( !bestEntity )
  79.         {
  80.             return true;
  81.         }
  82.         if ( chooseEntityStrategy == FMCES_ChooseMostIntense )
  83.         {
  84.             return ( intensity > bestIntensity );
  85.         }
  86.         else
  87.         {
  88.             return ( distance < bestDistance );
  89.         }
  90.     }
  91. }
  92.  
  93. import class CFocusSoundParam extends CGameplayEntityParam
  94. {
  95.     import final function GetEventStart() : name;
  96.     import final function GetEventStop() : name;
  97.     import final function GetHearingAngle() : float;
  98.     import final function GetVisualEffectBoneName() : name;
  99. }
  100.  
  101. import class CFocusModeController extends IGameSystem
  102. {
  103.     import final function SetActive( active : bool );
  104.     import final function IsActive() : bool;
  105.     import final function GetIntensity() : float;
  106.     import final function EnableVisuals( enable : bool, optional desaturation : float , optional highlightBoos : float );
  107.     import final function SetFadeParameters( NearFadeDistance : float, FadeDistanceRange : float, dimmingTIme : Float, dimmingSpeed : Float );
  108.     import final function EnableExtendedVisuals( enable : bool, fadeTime : float );
  109.     import final function SetDimming( enable : bool );
  110.     import final function SetSoundClueEventNames( entity : CGameplayEntity, eventStart : name, eventStop : name, effectType : int ) : bool;
  111.     import final function ActivateScentClue( entity : CEntity, effectName : name, duration : float );
  112.     import final function DeactivateScentClue( entity : CEntity );
  113.    
  114.     saved var detectedCluesTags         : array< name >;
  115.  
  116.     var medallionIntensity              : W3FocusModeEffectIntensity;  
  117.     var dimmingClue                     : W3MonsterClue;
  118.  
  119.     var blockVibrations                 : bool;
  120.  
  121.     var focusAreaIntensity              : float;
  122.     default focusAreaIntensity          = 0.0f;
  123.  
  124.     const var effectFadeTime            : float;
  125.     default effectFadeTime              = 1.0f;
  126.  
  127.    
  128.    
  129.    
  130.     const var controllerVibrationFactor : float;
  131.     default controllerVibrationFactor   = 0.2f;
  132.     const var controllerVibrationDuration : float;
  133.     default controllerVibrationDuration = 0.5f;
  134.    
  135.    
  136.     var activationSoundTimer            : float;
  137.     const var activationSoundInterval   : float;
  138.     default activationSoundTimer        = 0.0f;
  139.     default activationSoundInterval     = 0.4f;
  140.  
  141.    
  142.     var fastFocusTimer                  : float;
  143.     var activateAfterFastFocus          : bool;
  144.     const var fastFocusDuration         : float;
  145.     default fastFocusTimer              = 0.0f;
  146.     default activateAfterFastFocus      = false;
  147.     default fastFocusDuration           = 0.0f;
  148.    
  149.    
  150.     private var isUnderwaterFocus       : bool;
  151.     default isUnderwaterFocus           = false;
  152.     private var isInCombat              : bool;
  153.     default isInCombat                  = false;
  154.     private var isNight                 : bool;
  155.     default isNight                     = false;
  156.    
  157.    
  158.     private var lastDarkPlaceCheck : float;
  159.     private const var DARK_PLACE_CHECK_INTERVAL : float;
  160.     default DARK_PLACE_CHECK_INTERVAL = 2.f;
  161.  
  162.     public function Activate()
  163.     {
  164.         //---=== modFriendlyHUD ===---
  165.         if( GetFHUDConfig().enableWitcherSensesModules )
  166.         {
  167.             ToggleWSModules( true, "WitcherSensesActive" );
  168.         }
  169.         //---=== modFriendlyHUD ===---
  170.         lastDarkPlaceCheck = DARK_PLACE_CHECK_INTERVAL;
  171.    
  172.         if ( !ActivateFastFocus( true ) )
  173.         {
  174.             ActivateInternal();
  175.         }
  176.     }
  177.    
  178.     public function GetBlockVibrations() : bool
  179.     {
  180.         return blockVibrations;
  181.     }
  182.    
  183.     public function SetBlockVibrations( newState : bool )
  184.     {
  185.         blockVibrations = newState;
  186.     }  
  187.    
  188.     function ActivateFastFocus( activate : bool ) : bool
  189.     {
  190.         activateAfterFastFocus = activate;
  191.         if ( activate && fastFocusDuration > 0.0f )
  192.         {
  193.            
  194.            
  195.             fastFocusTimer = fastFocusDuration;
  196.             return true;
  197.         }
  198.         return false;
  199.     }
  200.    
  201.     private function ActivateInternal()
  202.     {
  203.         if ( IsActive() || !CanUseFocusMode() )
  204.         {
  205.             return;
  206.         }
  207.        
  208.         SetActive( true );
  209.         EnableVisuals( true );
  210.         EnableExtendedVisuals( true, effectFadeTime );
  211.        
  212.         thePlayer.BlockAction( EIAB_Jump, 'focus' );
  213.         theTelemetry.LogWithName( TE_HERO_FOCUS_ON );
  214.    
  215.        
  216.         if ( theGame.GetEngineTimeAsSeconds() - activationSoundTimer > activationSoundInterval )
  217.         {
  218.             activationSoundTimer = theGame.GetEngineTimeAsSeconds();
  219.             theSound.SoundEvent( 'expl_focus_start' );         
  220.         }
  221.        
  222.         // FCR3 --
  223.         if( GetWitcherPlayer().IsInDarkPlace() && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  224.         //if( GetWitcherPlayer().IsInDarkPlace() && GetWitcherPlayer().IsMutationActive( EPMT_Mutation12 ) && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  225.         // -- FCR3
  226.         {
  227.             thePlayer.AddEffectDefault( EET_Mutation12Cat, thePlayer, "Mutation12 Senses", false );
  228.         }
  229.     }
  230.  
  231.     public function Deactivate()
  232.     {
  233.         var hud : CR4ScriptedHud;
  234.         var module : CR4HudModuleInteractions;
  235.         //---=== modFriendlyHUD ===---
  236.         if( GetFHUDConfig().enableWitcherSensesModules )
  237.         {
  238.             ToggleWSModules( false, "WitcherSensesActive" );
  239.         }
  240.         //---=== modFriendlyHUD ===---
  241.  
  242.         ActivateFastFocus( false );
  243.  
  244.         if ( !IsActive() )
  245.         {
  246.             return;
  247.         }
  248.         SetActive( false );
  249.         EnableVisuals( false );
  250.         EnableExtendedVisuals( false, effectFadeTime );
  251.        
  252.         if( isUnderwaterFocus )
  253.         {
  254.             isUnderwaterFocus = false;
  255.             if( isInCombat )
  256.             {
  257.                 theSound.LeaveGameState( ESGS_FocusUnderwaterCombat );
  258.             }
  259.             else
  260.             {
  261.                 theSound.LeaveGameState( ESGS_FocusUnderwater );
  262.             }
  263.         }
  264.         else
  265.         {
  266.             if( isNight )
  267.             {
  268.                 theSound.LeaveGameState( ESGS_FocusNight );
  269.             }
  270.             else
  271.             {
  272.                 theSound.LeaveGameState( ESGS_Focus );
  273.             }
  274.         }
  275.        
  276.         isInCombat = false;
  277.         isUnderwaterFocus = false;
  278.         isNight = false;
  279.  
  280.         thePlayer.UnblockAction( EIAB_Jump, 'focus' );
  281.         theTelemetry.LogWithName( TE_HERO_FOCUS_OFF );
  282.         theSound.SoundEvent( 'expl_focus_stop' );
  283.        
  284.        
  285.         if ( theGame.GetEngineTimeAsSeconds() - activationSoundTimer > activationSoundInterval )
  286.         {
  287.             activationSoundTimer = theGame.GetEngineTimeAsSeconds();
  288.             theSound.SoundEvent( 'expl_focus_stop_sfx' );
  289.         }      
  290.        
  291.         hud = ( CR4ScriptedHud )theGame.GetHud();
  292.         if ( hud )
  293.         {
  294.             module = (CR4HudModuleInteractions)hud.GetHudModule( "InteractionsModule" );
  295.             if ( module )
  296.             {
  297.                 module.RemoveAllFocusInteractionIcons();
  298.             }
  299.         }
  300.        
  301.         // FCR3 --
  302.         if( thePlayer.IsInCombat() && GetWitcherPlayer().IsInDarkPlace() )
  303.         {
  304.             //
  305.         }
  306.         else
  307.         {
  308.             //thePlayer.RemoveBuff( EET_Mutation12Cat );
  309.             if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  310.             {
  311.                 thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  312.             }
  313.             else
  314.             {
  315.                 if ( !thePlayer.HasBuff( EET_Cat ) )
  316.                 {
  317.                     DisableCatViewFx( 1.0f );
  318.                 }
  319.             }
  320.         }
  321.        
  322.         //  thePlayer.RemoveBuff( EET_Mutation12Cat );
  323.         // -- FCR3
  324.     }
  325.  
  326.     function CanUseFocusMode() : bool
  327.     {
  328.         var stateName : name;
  329.        
  330.         if ( theGame && theGame.IsDialogOrCutscenePlaying() )
  331.         {
  332.             return false;
  333.         }
  334.        
  335.         if ( thePlayer )
  336.         {
  337.             stateName = thePlayer.GetCurrentStateName();
  338.             return ( stateName == 'Exploration' || stateName == 'Swimming' || stateName == 'HorseRiding' || stateName == 'Sailing' || stateName == 'SailingPassive' ) && thePlayer.IsActionAllowed(EIAB_ExplorationFocus);     
  339.         }
  340.        
  341.         return false;
  342.     }
  343.  
  344.     function Init()
  345.     {
  346.         medallionIntensity = new W3FocusModeEffectIntensity in this;
  347.         medallionIntensity.Init( FMCES_ChooseNearest );
  348.         dimmingClue = NULL;
  349.         focusAreaIntensity = 0.0f;
  350.         activationSoundTimer = 0.f;
  351.     }
  352.  
  353.     function DeInit()
  354.     {
  355.         var i, size : int;
  356.        
  357.         delete medallionIntensity;
  358.         medallionIntensity = NULL;
  359.     }
  360.  
  361.     event OnGameStarted()
  362.     {
  363.         Init();
  364.         SetFadeParameters( 10.0, 30.0f, 16.0f, 40.0f );
  365.     }
  366.    
  367.     event OnGameEnded()
  368.     {
  369.         detectedCluesTags.Clear();
  370.         DeInit();
  371.     }
  372.  
  373.     event OnTick( timeDelta : float )
  374.     {  
  375.         var desiredAudioState : ESoundGameState;
  376.         var focusModeIntensity : float;
  377.        
  378.        
  379.         if ( fastFocusTimer > 0.0f )
  380.         {
  381.             fastFocusTimer -= timeDelta;
  382.             if ( fastFocusTimer < 0.0f )
  383.             {
  384.                 fastFocusTimer = 0.0f;
  385.                 if ( activateAfterFastFocus )
  386.                 {
  387.                     activateAfterFastFocus = false;
  388.                     ActivateInternal();
  389.                 }
  390.             }
  391.         }
  392.        
  393.         if( IsActive() )
  394.         {
  395.             if( CanUseFocusMode() )
  396.             {
  397.                 isInCombat = false;
  398.                 isUnderwaterFocus = thePlayer.OnIsCameraUnderwater();
  399.                 if( isUnderwaterFocus )
  400.                 {
  401.                     isInCombat = thePlayer.ShouldEnableCombatMusic();
  402.                     if( isInCombat )
  403.                     {
  404.                         desiredAudioState = ESGS_FocusUnderwaterCombat;
  405.                     }
  406.                     else
  407.                     {
  408.                         desiredAudioState = ESGS_FocusUnderwater;
  409.                     }
  410.                 }
  411.                 else
  412.                 {
  413.                     isNight = theGame.envMgr.IsNight();
  414.                     if( isNight )
  415.                     {
  416.                         desiredAudioState = ESGS_FocusNight;
  417.                     }
  418.                     else
  419.                     {
  420.                         desiredAudioState = ESGS_Focus;
  421.                     }
  422.                 }
  423.                
  424.                 if( theSound.GetCurrentGameState() != desiredAudioState )
  425.                 {
  426.                     theSound.EnterGameState( desiredAudioState );
  427.                 }
  428.                
  429.                 // FCR3 --
  430.                 //if( GetWitcherPlayer().IsMutationActive( EPMT_Mutation12 ) )
  431.                 //{
  432.                 // -- FCR3
  433.                     lastDarkPlaceCheck -= timeDelta;
  434.                     if( lastDarkPlaceCheck <= 0.f )
  435.                     {
  436.                         lastDarkPlaceCheck = DARK_PLACE_CHECK_INTERVAL;
  437.                    
  438.                         if( GetWitcherPlayer().IsInDarkPlace() && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  439.                         {
  440.                             thePlayer.AddEffectDefault( EET_Mutation12Cat, thePlayer, "Mutation12 Senses", false );
  441.                         }
  442.                         // FCR3 --
  443.                         /*
  444.                         else if( !GetWitcherPlayer().IsInDarkPlace() && thePlayer.HasBuff( EET_Mutation12Cat ) )
  445.                         {
  446.                             //thePlayer.RemoveBuff( EET_Mutation12Cat );
  447.                             thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat ); // FCR3
  448.                         }
  449.                         */
  450.                         else if( !GetWitcherPlayer().IsInDarkPlace() )
  451.                         {
  452.                             if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  453.                             {
  454.                                 thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  455.                             }
  456.                             else
  457.                             {
  458.                                 if ( !thePlayer.HasBuff( EET_Cat ) )
  459.                                 {
  460.                                     DisableCatViewFx( 1.0f );
  461.                                 }
  462.                         */
  463.                         else if( !GetWitcherPlayer().IsInDarkPlace() )
  464.                         {
  465.                             if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  466.                             {
  467.                                 thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  468.                             }
  469.                             else
  470.                             {
  471.                                 if ( !thePlayer.HasBuff( EET_Cat ) )
  472.                                 {
  473.                                     DisableCatViewFx( 1.0f );
  474.                                 }
  475.                             }
  476.                         }
  477.                         // -- FCR3
  478.                     }
  479.                 //}
  480.             }
  481.             else
  482.             {
  483.                 Deactivate();
  484.             }
  485.         }
  486.        
  487.         focusModeIntensity = GetIntensity();
  488.         UpdateMedallion( focusModeIntensity );
  489.     }
  490.  
  491.     public function SetDimmingForClue( clue : W3MonsterClue )
  492.     {
  493.         dimmingClue = clue;
  494.         SetDimming( true );
  495.     }
  496.    
  497.     event OnFocusModeDimmingFinished( timeDelta : float )
  498.     {      
  499.         if ( dimmingClue )
  500.         {
  501.             dimmingClue.OnDimmingFinished();
  502.             dimmingClue = NULL;
  503.         }
  504.     }
  505.    
  506.     function UseControllerVibration( focusModeIntensity : float ) : bool
  507.     {
  508.         return ( focusAreaIntensity > 0.0f && focusModeIntensity < 1.0f && controllerVibrationFactor > 0.0f && thePlayer.GetCurrentStateName() == 'Exploration' );
  509.     }
  510.    
  511.     function UpdateMedallion( focusModeIntensity : float )
  512.     {
  513.         var intensity : float;
  514.  
  515.         intensity = focusAreaIntensity;
  516.  
  517.        
  518.         if ( UseControllerVibration( focusModeIntensity ) )
  519.         {
  520.             theGame.VibrateController( 0, intensity * ( 1.0f - focusModeIntensity ) * controllerVibrationFactor, controllerVibrationDuration );
  521.            
  522.             focusAreaIntensity = 0.0f;
  523.         }
  524.  
  525.         if ( medallionIntensity )
  526.         {
  527.             if ( medallionIntensity.ValueChanged() )
  528.             {
  529.                 intensity = MaxF( intensity, medallionIntensity.GetValue() );
  530.             }
  531.             medallionIntensity.Reset();
  532.         }  
  533.  
  534.         GetWitcherPlayer().GetMedallion().SetInstantIntensity( intensity );
  535.         GetWitcherPlayer().GetMedallion().SetFocusModeFactor( 1.0f - focusModeIntensity );
  536.     }
  537.        
  538.     public function SetMedallionIntensity( entity : CEntity, distance : float, intensity : float )
  539.     {
  540.         if ( medallionIntensity )
  541.         {
  542.             medallionIntensity.Update( entity, distance, intensity );
  543.         }
  544.     }
  545.    
  546.     public function SetFocusAreaIntensity( intensity : float )
  547.     {
  548.         focusAreaIntensity = intensity;
  549.     }
  550.    
  551.     public function ReusableClueDetected( clue : W3MonsterClue )
  552.     {
  553.         var i, j    : int;
  554.         var tags    : array< name >;
  555.        
  556.         tags = clue.GetTags();
  557.         for ( i = 0; i < tags.Size(); i += 1 )
  558.         {
  559.             j = detectedCluesTags.FindFirst( tags[i] );
  560.             if ( j == -1 )
  561.             {
  562.                 detectedCluesTags.PushBack( tags[i] );
  563.                 theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnReusableClueUsed, SET_Unknown, tags[i] );
  564.             }
  565.         }
  566.     }
  567.    
  568.     public function WasReusableClueDetected( tag : name ) : bool
  569.     {
  570.         return detectedCluesTags.FindFirst( tag ) != -1;
  571.     }
  572.    
  573.     public function ResetClue( tag : name, removeFacts : bool, leaveVisible : bool )
  574.     {
  575.         var nodes   : array< CNode >;
  576.         var clue    : W3MonsterClue;
  577.         var i, size : int;
  578.        
  579.         if ( tag == '' )
  580.         {
  581.             LogQuest( "CFocusModeController.ResetClue: empty tag!");   
  582.             return;
  583.         }
  584.  
  585.         theGame.GetNodesByTag( tag, nodes );   
  586.         size = nodes.Size();   
  587.         for ( i = 0; i < size; i += 1 )
  588.         {
  589.             clue = (W3MonsterClue)nodes[i];    
  590.             if ( clue )
  591.             {
  592.                 clue.ResetClue( removeFacts, leaveVisible );
  593.             }
  594.         }
  595.        
  596.         i = detectedCluesTags.FindFirst( tag );
  597.         if ( i != -1 )
  598.         {
  599.             detectedCluesTags.Erase( i );
  600.         }
  601.     }              
  602.    
  603.     var focusInteractionsInterval : float; default focusInteractionsInterval = 0;
  604.  
  605.     public function UpdateFocusInteractions( deltaTime : float)
  606.     {
  607.         var entities : array< CGameplayEntity >;
  608.         var size : int;
  609.         var i : int;
  610.         var focusComponent : CFocusActionComponent;
  611.         var hud : CR4ScriptedHud;
  612.         var module : CR4HudModuleInteractions;
  613.         var actionName : name;     
  614.  
  615.         if ( IsActive() )
  616.         {
  617.             focusInteractionsInterval -= deltaTime;
  618.             if ( focusInteractionsInterval < 0 )
  619.             {
  620.                 hud = ( CR4ScriptedHud )theGame.GetHud();
  621.                 module = ( CR4HudModuleInteractions )hud.GetHudModule( "InteractionsModule" );
  622.                 module.InvalidateAllFocusInteractionIcons();
  623.                 focusInteractionsInterval = module.GetFocusInteractionUpdateInterval();
  624.  
  625.                 FindGameplayEntitiesInRange( entities, thePlayer, module.GetFocusInteractionRadius(), 1000 );
  626.                 size = entities.Size();
  627.                 for ( i = 0; i < size; i += 1 )
  628.                 {
  629.                     if ( entities[ i ].CanShowFocusInteractionIcon() )
  630.                     {
  631.                         actionName = entities[ i ].GetFocusActionName();
  632.                         if ( IsNameValid( actionName ) )
  633.                         {
  634.                             module.AddFocusInteractionIcon( entities[ i ], actionName );                           
  635.                         }
  636.                     }
  637.                 }
  638.             }
  639.         }
  640.     }
  641.  
  642. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement