1
0
forked from 0ad/0ad

Fix CanAttack for mirages following 88549e77e1

CanAttack queries the miraged Resistance which did not exist, thus
failing.
This mirages Resistance explicitly (fixing parts of #5883)

Fixes 88549e77e1, reverts the mirage.xml change in 738b200dda

Refs #5883

Reported by: Asger_Spear
Differential Revision: https://code.wildfiregames.com/D4001
This was SVN commit r25517.
This commit is contained in:
wraitii 2021-05-22 10:56:40 +00:00
parent c535a282ac
commit 80a8c3827b
4 changed files with 39 additions and 2 deletions

View File

@ -19,6 +19,7 @@ Fogging.prototype.componentsToMirage = [
IID_Identity,
IID_Market,
IID_Repairable,
IID_Resistance,
IID_ResourceSupply
];

View File

@ -492,7 +492,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
}
}
let cmpResistance = Engine.QueryInterface(ent, IID_Resistance);
let cmpResistance = QueryMiragedInterface(ent, IID_Resistance);
if (cmpResistance)
ret.resistance = cmpResistance.GetResistanceOfForm(cmpFoundation ? "Foundation" : "Entity");

View File

@ -181,4 +181,41 @@ Resistance.prototype.OnOwnershipChanged = function(msg)
Engine.QueryInterface(attacker, IID_Attack)?.StopAttacking("TargetInvalidated");
};
function ResistanceMirage() {}
ResistanceMirage.prototype.Init = function(cmpResistance)
{
this.invulnerable = cmpResistance.invulnerable;
this.isFoundation = !!Engine.QueryInterface(cmpResistance.entity, IID_Foundation);
this.resistanceOfForm = {};
for (const entityForm in cmpResistance.template)
this.resistanceOfForm[entityForm] = cmpResistance.GetResistanceOfForm(entityForm);
};
ResistanceMirage.prototype.IsInvulnerable = Resistance.prototype.IsInvulnerable;
ResistanceMirage.prototype.GetEffectiveResistanceAgainst = function(entityForm)
{
return this.GetResistanceOfForm(this.isFoundation ? "Foundation" : "Entity");
};
ResistanceMirage.prototype.GetResistanceOfForm = function(entityForm)
{
return this.resistanceOfForm[entityForm] || {};
};
ResistanceMirage.prototype.GetFullResistance = function()
{
return this.resistanceOfForm;
};
Engine.RegisterGlobal("ResistanceMirage", ResistanceMirage);
Resistance.prototype.Mirage = function()
{
const mirage = new ResistanceMirage();
mirage.Init(this);
return mirage;
};
Engine.RegisterComponentType(IID_Resistance, "Resistance", Resistance);

View File

@ -24,7 +24,6 @@
<OverlayRenderer merge=""/>
<Ownership merge=""/>
<Position merge=""/>
<Resistance merge=""/>
<Selectable merge=""/>
<StatusBars merge=""/>
<Visibility merge=""/>