2014-11-04 21:53:25 +01:00
|
|
|
const VIS_HIDDEN = 0;
|
|
|
|
const VIS_FOGGED = 1;
|
|
|
|
const VIS_VISIBLE = 2;
|
|
|
|
|
|
|
|
function Visibility() {}
|
|
|
|
|
|
|
|
Visibility.prototype.Schema =
|
2014-12-05 19:33:59 +01:00
|
|
|
"<element name='RetainInFog'>" +
|
|
|
|
"<data type='boolean'/>" +
|
|
|
|
"</element>" +
|
|
|
|
"<element name='AlwaysVisible'>" +
|
|
|
|
"<data type='boolean'/>" +
|
2015-01-30 16:28:06 +01:00
|
|
|
"</element>" +
|
|
|
|
"<element name='Preview'>" +
|
|
|
|
"<data type='boolean'/>" +
|
2014-12-05 19:33:59 +01:00
|
|
|
"</element>";
|
2014-11-04 21:53:25 +01:00
|
|
|
|
|
|
|
Visibility.prototype.Init = function()
|
|
|
|
{
|
2015-01-30 16:28:06 +01:00
|
|
|
this.retainInFog = this.template.RetainInFog == "true";
|
|
|
|
this.alwaysVisible = this.template.AlwaysVisible == "true";
|
|
|
|
this.preview = this.template.Preview == "true";
|
2014-12-05 19:33:59 +01:00
|
|
|
|
2015-01-30 16:28:06 +01:00
|
|
|
this.activated = false;
|
|
|
|
|
|
|
|
if (this.preview)
|
|
|
|
this.activated = true;
|
2014-11-04 21:53:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-01-30 16:28:06 +01:00
|
|
|
* If this function returns true, the range manager will call the GetVisibility function
|
|
|
|
* instead of computing the visibility.
|
2014-11-04 21:53:25 +01:00
|
|
|
*/
|
2015-01-30 16:28:06 +01:00
|
|
|
Visibility.prototype.IsActivated = function()
|
2014-11-04 21:53:25 +01:00
|
|
|
{
|
2015-01-30 16:28:06 +01:00
|
|
|
return this.activated;
|
|
|
|
};
|
2014-11-04 21:53:25 +01:00
|
|
|
|
2015-01-30 16:28:06 +01:00
|
|
|
/**
|
|
|
|
* This function is called if IsActivated returns true.
|
|
|
|
* If so, the return value supersedes the visibility computed by the range manager.
|
|
|
|
* isVisible: true if the entity is in the vision range of a unit, false otherwise
|
|
|
|
* isExplored: true if the entity is in explored territory, false otherwise
|
|
|
|
*/
|
|
|
|
Visibility.prototype.GetVisibility = function(player, isVisible, isExplored)
|
|
|
|
{
|
|
|
|
if (!this.activated)
|
|
|
|
warn("The Visibility component was asked to provide a superseding visibility while not activated, this should not happen");
|
2014-11-04 21:53:25 +01:00
|
|
|
|
2015-01-30 16:28:06 +01:00
|
|
|
if (this.preview)
|
2014-11-04 21:53:25 +01:00
|
|
|
{
|
2015-01-30 16:28:06 +01:00
|
|
|
// For the owner only, mock the "RetainInFog" behaviour
|
2014-11-04 21:53:25 +01:00
|
|
|
|
2015-01-30 16:28:06 +01:00
|
|
|
let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
|
|
|
|
if (cmpOwnership && cmpOwnership.GetOwner() == player && isExplored)
|
|
|
|
return isVisible ? VIS_VISIBLE : VIS_FOGGED;
|
2014-11-04 21:53:25 +01:00
|
|
|
|
|
|
|
return VIS_HIDDEN;
|
|
|
|
}
|
|
|
|
|
2015-01-30 16:28:06 +01:00
|
|
|
return VIS_VISIBLE;
|
2014-11-04 21:53:25 +01:00
|
|
|
};
|
|
|
|
|
2014-12-05 19:33:59 +01:00
|
|
|
Visibility.prototype.GetRetainInFog = function()
|
|
|
|
{
|
2015-01-30 16:28:06 +01:00
|
|
|
return this.retainInFog;
|
2014-12-05 19:33:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Visibility.prototype.GetAlwaysVisible = function()
|
|
|
|
{
|
2015-01-30 16:28:06 +01:00
|
|
|
return this.alwaysVisible;
|
2014-12-05 19:33:59 +01:00
|
|
|
};
|
|
|
|
|
2014-11-04 21:53:25 +01:00
|
|
|
Engine.RegisterComponentType(IID_Visibility, "Visibility", Visibility);
|