LCOV - code coverage report
Current view: top level - simulation/components - Visibility.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 35 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 7 0.0 %

          Line data    Source code
       1           0 : const VIS_HIDDEN = 0;
       2           0 : const VIS_FOGGED = 1;
       3           0 : const VIS_VISIBLE = 2;
       4             : 
       5             : function Visibility() {}
       6             : 
       7           0 : Visibility.prototype.Schema =
       8             :         "<element name='RetainInFog'>" +
       9             :                 "<data type='boolean'/>" +
      10             :         "</element>" +
      11             :         "<element name='AlwaysVisible'>" +
      12             :                 "<data type='boolean'/>" +
      13             :         "</element>" +
      14             :         "<element name='Corpse'>" +
      15             :                 "<data type='boolean'/>" +
      16             :         "</element>" +
      17             :         "<element name='Preview'>" +
      18             :                 "<data type='boolean'/>" +
      19             :         "</element>";
      20             : 
      21           0 : Visibility.prototype.Init = function()
      22             : {
      23           0 :         this.retainInFog = this.template.RetainInFog == "true";
      24           0 :         this.alwaysVisible = this.template.AlwaysVisible == "true";
      25           0 :         this.corpse = this.template.Corpse == "true";
      26           0 :         this.preview = this.template.Preview == "true";
      27             : 
      28           0 :         this.activated = false;
      29             : 
      30           0 :         if (this.preview || this.corpse)
      31           0 :                 this.SetActivated(true);
      32             : };
      33             : 
      34             : /**
      35             :  * Sets the range manager scriptedVisibility flag for this entity.
      36             :  */
      37           0 : Visibility.prototype.SetActivated = function(status)
      38             : {
      39           0 :         let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
      40           0 :         cmpRangeManager.ActivateScriptedVisibility(this.entity, status);
      41             : 
      42           0 :         this.activated = status;
      43             : };
      44             : 
      45             : /**
      46             :  * This function is a fallback for some entities whose visibility status
      47             :  * cannot be cached by the range manager (especially local entities like previews).
      48             :  * Calling the scripts is expensive, so only call it if really needed.
      49             :  */
      50           0 : Visibility.prototype.IsActivated = function()
      51             : {
      52           0 :         return this.activated;
      53             : };
      54             : 
      55             : /**
      56             :  * This function is called if the range manager scriptedVisibility flag is set to true for this entity.
      57             :  * If so, the return value supersedes the visibility computed by the range manager.
      58             :  * isVisible: true if the entity is in the vision range of a unit, false otherwise
      59             :  * isExplored: true if the entity is in explored territory, false otherwise
      60             :  */
      61           0 : Visibility.prototype.GetVisibility = function(player, isVisible, isExplored)
      62             : {
      63           0 :         if (this.preview)
      64             :         {
      65             :                 // For the owner only, mock the "RetainInFog" behavior
      66           0 :                 let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
      67           0 :                 if (cmpOwnership && cmpOwnership.GetOwner() == player && isExplored)
      68           0 :                         return isVisible ? VIS_VISIBLE : VIS_FOGGED;
      69             : 
      70             :                 // For others, hide the preview
      71           0 :                 return VIS_HIDDEN;
      72             :         }
      73           0 :         else if (this.corpse)
      74             :         {
      75             :                 // For the owner only, mock the "RetainInFog" behavior
      76           0 :                 let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
      77           0 :                 if (cmpOwnership && cmpOwnership.GetOwner() == player && isExplored)
      78           0 :                         return isVisible ? VIS_VISIBLE : VIS_FOGGED;
      79             : 
      80             :                 // For others, regular displaying
      81           0 :                 return isVisible ? VIS_VISIBLE : VIS_HIDDEN;
      82             :         }
      83             : 
      84           0 :         return VIS_VISIBLE;
      85             : };
      86             : 
      87           0 : Visibility.prototype.GetRetainInFog = function()
      88             : {
      89           0 :         return this.retainInFog;
      90             : };
      91             : 
      92           0 : Visibility.prototype.GetAlwaysVisible = function()
      93             : {
      94           0 :         return this.alwaysVisible;
      95             : };
      96             : 
      97           0 : Engine.RegisterComponentType(IID_Visibility, "Visibility", Visibility);

Generated by: LCOV version 1.14