Adds more checks for tech manager before using it. Refs #1377.

This was SVN commit r11751.
This commit is contained in:
historic_bruno 2012-05-04 22:51:14 +00:00
parent 32d2927449
commit 0463068947
7 changed files with 66 additions and 31 deletions

View File

@ -57,9 +57,14 @@ Armour.prototype.GetArmourStrengths = function()
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var applyTechs = function(type)
{
// All causes caching problems so disable it for now.
// var allComponent = cmpTechMan.ApplyModifications("Armour/All", +self.template[type], self.entity) - self.template[type];
return cmpTechMan.ApplyModifications("Armour/" + type, +self.template[type], self.entity);
var strength = +self.template[type];
if (cmpTechMan)
{
// All causes caching problems so disable it for now.
// var allComponent = cmpTechMan.ApplyModifications("Armour/All", strength, self.entity) - self.template[type];
strength = cmpTechMan.ApplyModifications("Armour/" + type, strength, self.entity);
}
return strength;
};
return {

View File

@ -269,11 +269,16 @@ Attack.prototype.CompareEntitiesByPreference = function(a, b)
Attack.prototype.GetTimers = function(type)
{
var prepare = +(this.template[type].PrepareTime || 0);
var repeat = +(this.template[type].RepeatTime || 1000);
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);
if (cmpTechMan)
{
prepare = cmpTechMan.ApplyModifications("Attack/" + type + "/PrepareTime", prepare, this.entity);
repeat = cmpTechMan.ApplyModifications("Attack/" + type + "/RepeatTime", repeat, this.entity);
}
return { "prepare": prepare, "repeat": repeat, "recharge": repeat - prepare };
};
@ -285,9 +290,14 @@ Attack.prototype.GetAttackStrengths = function(type)
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var applyTechs = function(damageType)
{
// All causes caching problems so disable it for now.
//var allComponent = cmpTechMan.ApplyModifications("Attack/" + type + "/All", (+self.template[type][damageType] || 0), self.entity) - self.template[type][damageType];
return cmpTechMan.ApplyModifications("Attack/" + type + "/" + damageType, +(self.template[type][damageType] || 0), self.entity);
var strength = +(self.template[type][damageType] || 0);
if (cmpTechMan)
{
// All causes caching problems so disable it for now.
//var allComponent = cmpTechMan.ApplyModifications("Attack/" + type + "/All", strength, self.entity) - self.template[type][damageType];
strength = cmpTechMan.ApplyModifications("Attack/" + type + "/" + damageType, strength, self.entity);
}
return strength;
};
return {

View File

@ -49,8 +49,10 @@ Builder.prototype.GetRange = function()
*/
Builder.prototype.PerformBuilding = function(target)
{
var rate = +this.template.Rate;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var rate = cmpTechMan.ApplyModifications("Builder/Rate", +this.template.Rate, this.entity);
if (cmpTechMan)
rate = cmpTechMan.ApplyModifications("Builder/Rate", rate, this.entity);
// If it's a foundation, then build it
var cmpFoundation = Engine.QueryInterface(target, IID_Foundation);

View File

@ -107,20 +107,20 @@ BuildingAI.prototype.OnRangeUpdate = function(msg)
BuildingAI.prototype.GetDefaultArrowCount = function()
{
var arrowCount = +this.template.DefaultArrowCount;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
if (cmpTechMan)
return cmpTechMan.ApplyModifications("BuildingAI/DefaultArrowCount", +this.template.DefaultArrowCount, this.entity);
else
return +this.template.DefaultArrowCount;
arrowCount = cmpTechMan.ApplyModifications("BuildingAI/DefaultArrowCount", arrowCount, this.entity);
return arrowCount;
};
BuildingAI.prototype.GetGarrisonArrowMultiplier = function()
{
var arrowMult = +this.template.GarrisonArrowMultiplier;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
if (cmpTechMan)
return cmpTechMan.ApplyModifications("BuildingAI/GarrisonArrowMultiplier", +this.template.GarrisonArrowMultiplier, this.entity);
else
return +this.template.GarrisonArrowMultiplier;
arrowMult = cmpTechMan.ApplyModifications("BuildingAI/GarrisonArrowMultiplier", arrowMult, this.entity);
return arrowMult;
};
/**

View File

@ -63,8 +63,11 @@ GarrisonHolder.prototype.GetAllowedClassesList = function()
*/
GarrisonHolder.prototype.GetCapacity = function()
{
var max = +this.template.Max;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
return cmpTechMan.ApplyModifications("GarrisonHolder/Max", +this.template.Max, this.entity);
if (cmpTechMan)
max = cmpTechMan.ApplyModifications("GarrisonHolder/Max", max, this.entity);
return max;
};
/**
@ -72,8 +75,11 @@ GarrisonHolder.prototype.GetCapacity = function()
*/
GarrisonHolder.prototype.GetHealRate = function()
{
var rate = +this.template.BuffHeal;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
return cmpTechMan.ApplyModifications("GarrisonHolder/BuffHeal", +this.template.BuffHeal, this.entity);
if (cmpTechMan)
rate = cmpTechMan.ApplyModifications("GarrisonHolder/BuffHeal", rate, this.entity);
return rate;
};
/**

View File

@ -39,9 +39,12 @@ Heal.prototype.Serialize = null; // we have no dynamic state to save
Heal.prototype.GetTimers = function()
{
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var prepare = 1000;
var repeat = cmpTechMan.ApplyModifications("Heal/Rate", +this.template.Rate, this.entity);
var repeat = +this.template.Rate;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
if (cmpTechMan)
repeat = cmpTechMan.ApplyModifications("Heal/Rate", repeat, this.entity);
return { "prepare": prepare, "repeat": repeat };
};
@ -81,8 +84,11 @@ Heal.prototype.PerformHeal = function(target)
if (!cmpHealth)
return;
var hp = +this.template.HP;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var targetState = cmpHealth.Increase(cmpTechMan.ApplyModifications("Heal/HP", +this.template.HP, this.entity));
if (cmpTechMan)
hp = cmpTechMan.ApplyModifications("Heal/HP", hp, this.entity);
var targetState = cmpHealth.Increase(hp);
// Add XP
var cmpLoot = Engine.QueryInterface(target, IID_Loot);

View File

@ -128,30 +128,36 @@ ResourceGatherer.prototype.GetLastCarriedType = function()
ResourceGatherer.prototype.GetGatherRates = function()
{
var ret = {};
var baseSpeed = +this.template.BaseSpeed;
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
var baseSpeed = cmpTechMan.ApplyModifications("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity);
if (cmpTechMan)
baseSpeed = cmpTechMan.ApplyModifications("ResourceGatherer/BaseSpeed", baseSpeed, this.entity);
for (var r in this.template.Rates)
{
var rate = cmpTechMan.ApplyModifications("ResourceGatherer/Rates/" + r, +this.template.Rates[r], this.entity);
var rate = +this.template.Rates[r]
if (cmpTechMan)
rate = cmpTechMan.ApplyModifications("ResourceGatherer/Rates/" + r, rate, this.entity);
ret[r] = rate * baseSpeed;
}
return ret;
};
ResourceGatherer.prototype.GetCapacities = function()
{
var ret = {};
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
for (var r in this.template.Capacities)
{
ret[r] = cmpTechMan.ApplyModifications("ResourceGatherer/Capacities/" + r, +this.template.Capacities[r], this.entity);
var capacity = +this.template.Capacities[r];
if (cmpTechMan)
capacity = cmpTechMan.ApplyModifications("ResourceGatherer/Capacities/" + r, capacity, this.entity);
ret[r] = capacity;
}
return ret;
};