1
0
forked from 0ad/0ad

Store components to be miraged in cmpFogging.

Allows modders (and us) to just add an IID to the array and ensure the
`Mirage()`-function to exist in the respective component.

Differential revision: D3713
Comment by: @wraitii
This was SVN commit r25090.
This commit is contained in:
Freagarach 2021-03-20 16:14:35 +00:00
parent a4a7ef983e
commit 07908dfd8c
2 changed files with 23 additions and 59 deletions

View File

@ -8,6 +8,20 @@ Fogging.prototype.Schema =
"<a:help>Allows this entity to be replaced by mirage entities in the fog-of-war.</a:help>" +
"<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()
{
this.activated = false;
@ -106,33 +120,8 @@ Fogging.prototype.LoadMirage = function(player)
cmpMirageVisualActor.SetActorSeed(cmpParentVisualActor.GetActorSeed());
// Store valuable information into the mirage component (especially for the GUI).
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
if (cmpIdentity)
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);
for (let component of this.componentsToMirage)
cmpMirage.CopyComponent(component);
// 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]);

View File

@ -49,39 +49,14 @@ Mirage.prototype.Get = function(iid)
// ============================
// Parent entity data
Mirage.prototype.CopyCapturable = function(cmpCapturable)
/**
* @param {number} iid - The component to mirage.
*/
Mirage.prototype.CopyComponent = function(iid)
{
this.miragedIids.set(IID_Capturable, cmpCapturable.Mirage());
};
Mirage.prototype.CopyFoundation = function(cmpFoundation)
{
this.miragedIids.set(IID_Foundation, cmpFoundation.Mirage());
};
Mirage.prototype.CopyHealth = function(cmpHealth)
{
this.miragedIids.set(IID_Health, cmpHealth.Mirage());
};
Mirage.prototype.CopyIdentity = function(cmpIdentity)
{
this.miragedIids.set(IID_Identity, cmpIdentity.Mirage());
};
Mirage.prototype.CopyMarket = function(cmpMarket)
{
this.miragedIids.set(IID_Market, cmpMarket.Mirage(this.entity, this.player));
};
Mirage.prototype.CopyRepairable = function(cmpRepairable)
{
this.miragedIids.set(IID_Repairable, cmpRepairable.Mirage());
};
Mirage.prototype.CopyResourceSupply = function(cmpResourceSupply)
{
this.miragedIids.set(IID_ResourceSupply, cmpResourceSupply.Mirage());
let cmp = Engine.QueryInterface(this.parent, iid);
if (cmp)
this.miragedIids.set(iid, cmp.Mirage(this.entity, this.player));
};
// ============================