Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Fogging.js
const VIS_HIDDEN = 0; | const VIS_HIDDEN = 0; | ||||
const VIS_FOGGED = 1; | const VIS_FOGGED = 1; | ||||
const VIS_VISIBLE = 2; | const VIS_VISIBLE = 2; | ||||
function Fogging() {} | function Fogging() {} | ||||
Fogging.prototype.Schema = | Fogging.prototype.Schema = | ||||
"<a:help>Allows this entity to be replaced by mirage entities in the fog-of-war.</a:help>" + | "<a:help>Allows this entity to be replaced by mirage entities in the fog-of-war.</a:help>" + | ||||
"<empty/>"; | "<empty/>"; | ||||
/** | |||||
* The components that we want to mirage when present. | |||||
* Assumes that a function "Mirage()" is present. | |||||
*/ | |||||
Fogging.prototype.componentsToMirage = [ | |||||
IID_Capturable, | |||||
IID_Foundation, | |||||
IID_Health, | |||||
IID_Identity, | |||||
IID_Market, | |||||
IID_Repairable, | |||||
IID_ResourceSupply | |||||
]; | |||||
Fogging.prototype.Init = function() | Fogging.prototype.Init = function() | ||||
{ | { | ||||
this.activated = false; | this.activated = false; | ||||
this.mirages = []; | this.mirages = []; | ||||
this.miraged = []; | this.miraged = []; | ||||
this.seen = []; | this.seen = []; | ||||
let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers(); | let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers(); | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | if (!cmpParentVisualActor || !cmpMirageVisualActor) | ||||
error("Failed to copy the visual data of the fogged entity " + this.entity); | error("Failed to copy the visual data of the fogged entity " + this.entity); | ||||
return; | return; | ||||
} | } | ||||
cmpMirageVisualActor.RecomputeActorName(); | cmpMirageVisualActor.RecomputeActorName(); | ||||
cmpMirageVisualActor.SetActorSeed(cmpParentVisualActor.GetActorSeed()); | cmpMirageVisualActor.SetActorSeed(cmpParentVisualActor.GetActorSeed()); | ||||
// Store valuable information into the mirage component (especially for the GUI). | // Store valuable information into the mirage component (especially for the GUI). | ||||
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | for (let component of this.componentsToMirage) | ||||
if (cmpIdentity) | cmpMirage.CopyComponent(component); | ||||
cmpMirage.CopyIdentity(cmpIdentity); | |||||
let cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); | |||||
if (cmpFoundation) | |||||
cmpMirage.CopyFoundation(cmpFoundation); | |||||
let cmpRepairable = Engine.QueryInterface(this.entity, IID_Repairable); | |||||
if (cmpRepairable && !cmpFoundation) | |||||
cmpMirage.CopyRepairable(cmpRepairable); | |||||
let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | |||||
if (cmpHealth) | |||||
cmpMirage.CopyHealth(cmpHealth); | |||||
let cmpCapturable = Engine.QueryInterface(this.entity, IID_Capturable); | |||||
if (cmpCapturable) | |||||
cmpMirage.CopyCapturable(cmpCapturable); | |||||
let cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply); | |||||
if (cmpResourceSupply) | |||||
cmpMirage.CopyResourceSupply(cmpResourceSupply); | |||||
let cmpMarket = Engine.QueryInterface(this.entity, IID_Market); | |||||
if (cmpMarket) | |||||
cmpMirage.CopyMarket(cmpMarket); | |||||
// Notify the GUI the entity has been replaced by a mirage, in case it is selected at this moment. | // Notify the GUI the entity has been replaced by a mirage, in case it is selected at this moment. | ||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).AddMiragedEntity(player, this.entity, this.mirages[player]); | Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).AddMiragedEntity(player, this.entity, this.mirages[player]); | ||||
// Notify the range manager the visibility of this entity must be updated. | // Notify the range manager the visibility of this entity must be updated. | ||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).RequestVisibilityUpdate(this.entity); | Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).RequestVisibilityUpdate(this.entity); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator