Fixed phase detection in GUIInterface and added Armour and Attack tech modification.

This was SVN commit r11586.
This commit is contained in:
quantumstate
2012-04-20 19:47:01 +00:00
parent 755e407aeb
commit ed6e5bdaf0
4 changed files with 120 additions and 22 deletions
@@ -49,12 +49,45 @@ Armour.prototype.TakeDamage = function(hack, pierce, crush)
Armour.prototype.GetArmourStrengths = function()
{
// Convert attack values to numbers
return {
hack: +this.template.Hack,
pierce: +this.template.Pierce,
crush: +this.template.Crush
};
if (!this.armourCache)
{
// Work out the armour values with technology effects
var self = this;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var applyTechs = function(type)
{
var allComponent = cmpTechMan.ApplyModifications("Armour/All", +self.template[type], self.entity) - self.template[type];
return allComponent + cmpTechMan.ApplyModifications("Armour/" + type, +self.template[type], self.entity);
};
this.armourCache = {
hack: applyTechs("Hack"),
pierce: applyTechs("Pierce"),
crush: applyTechs("Crush")
};
}
return this.armourCache;
};
// Remove any cached template data which is based on technology data
Armour.prototype.OnTechnologyModificationChange = function(msg)
{
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
if (!cmpOwnership)
return;
var player = cmpOwnership.GetOwner();
if (msg.component === "Armour" && msg.player === player)
delete this.armourCache;
};
// Remove any cached template data which is based on technology data
Armour.prototype.OnOwnershipChanged = function(msg)
{
delete this.armourCache;
};
Engine.RegisterComponentType(IID_DamageReceiver, "Armour", Armour);
@@ -136,26 +136,91 @@ Attack.prototype.GetBestAttack = function()
Attack.prototype.GetTimers = function(type)
{
var prepare = +(this.template[type].PrepareTime || 0);
var repeat = +(this.template[type].RepeatTime || 1000);
return { "prepare": prepare, "repeat": repeat, "recharge": repeat - prepare };
if (!this.attackCache)
this.attackCache = {};
if (!this.attackCache.Timers)
this.attackCache.Timers = {};
if (!this.attackCache.Timers[type]){
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var prepare = cmpTechMan.ApplyModifications("Attack/" + type + "/PrepareTime", +(this.template[type].PrepareTime||0), this.entity);
var repeat = cmpTechMan.ApplyModifications("Attack/" + type + "/RepeatTime", +(this.template[type].RepeatTime||1000), this.entity);
this.attackCache.Timers[type] = { "prepare": prepare, "repeat": repeat, "recharge": repeat - prepare };
}
return this.attackCache.Timers[type];
};
Attack.prototype.GetAttackStrengths = function(type)
{
// Convert attack values to numbers, default 0 if unspecified
return {
hack: +(this.template[type].Hack || 0),
pierce: +(this.template[type].Pierce || 0),
crush: +(this.template[type].Crush || 0)
};
if (!this.attackCache)
this.attackCache = {};
if (!this.attackCache.Strengths)
this.attackCache.Strengths = {};
if (!this.attackCache.Strengths[type])
{
// Work out the attack values with technology effects
var self = this;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var applyTechs = function(damageType)
{
var allComponent = cmpTechMan.ApplyModifications("Attack/" + type + "/All", (+self.template[type][damageType] || 0), self.entity) - self.template[type][damageType];
return allComponent + cmpTechMan.ApplyModifications("Attack/" + type + "/" + damageType, (+self.template[type][damageType] || 0), self.entity);
};
this.attackCache.Strengths[type] = {
hack: applyTechs("Hack"),
pierce: applyTechs("Pierce"),
crush: applyTechs("Crush")
};
}
return this.attackCache.Strengths[type];
};
Attack.prototype.GetRange = function(type)
{
var max = +this.template[type].MaxRange;
var min = +(this.template[type].MinRange || 0);
return { "max": max, "min": min };
if (!this.attackCache)
this.attackCache = {};
if (!this.attackCache.Range)
this.attackCache.Range = {};
if (!this.attackCache.Range[type]){
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var max = cmpTechMan.ApplyModifications("Attack/" + type + "/MaxRange", +this.template[type].MaxRange, this.entity);
var min = cmpTechMan.ApplyModifications("Attack/" + type + "/MinRange", +this.template[type].MinRange, this.entity);
this.attackCache.Range[type] = { "max": max, "min": min };
}
return this.attackCache.Range[type];
};
// Remove any cached template data which is based on technology data
Attack.prototype.OnTechnologyModificationChange = function(msg)
{
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
if (!cmpOwnership)
return;
var player = cmpOwnership.GetOwner();
if (msg.component === "Attack" && msg.player === player)
delete this.attackCache;
};
// Remove any cached template data which is based on technology data
Attack.prototype.OnOwnershipChanged = function(msg)
{
delete this.attackCache;
};
// Calculate the attack damage multiplier against a target
@@ -53,11 +53,11 @@ GuiInterface.prototype.GetSimulationState = function(player)
// Work out what phase we are in
var cmpTechMan = Engine.QueryInterface(playerEnt, IID_TechnologyManager);
var phase = "";
if (cmpTechMan.IsTechnologyResearched("city"))
if (cmpTechMan.IsTechnologyResearched("city_phase"))
phase = "city";
else if (cmpTechMan.IsTechnologyResearched("town"))
else if (cmpTechMan.IsTechnologyResearched("town_phase"))
phase = "town";
else if (cmpTechMan.IsTechnologyResearched("village"))
else if (cmpTechMan.IsTechnologyResearched("village_phase"))
phase = "village";
// store player ally/enemy data as arrays
@@ -123,7 +123,7 @@ AddMock(101, IID_BuildLimits, {
});
AddMock(101, IID_TechnologyManager, {
IsTechnologyResearched: function(tech) { if (tech == "village") return true; else return false; },
IsTechnologyResearched: function(tech) { if (tech == "village_phase") return true; else return false; },
});
AddMock(101, IID_StatisticsTracker, {