mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-08 07:55:47 -07:00
Fixes some bugs in tech modifications relating to data types. Explicitly convert template data to numbers before calling ApplyModifications (using + operator).
This was SVN commit r11685.
This commit is contained in:
parent
7c93499c7d
commit
21caaa4573
7 changed files with 20 additions and 17 deletions
|
|
@ -138,8 +138,8 @@ Attack.prototype.GetTimers = function(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);
|
||||
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);
|
||||
|
||||
return { "prepare": prepare, "repeat": repeat, "recharge": repeat - prepare };
|
||||
};
|
||||
|
|
@ -154,7 +154,7 @@ Attack.prototype.GetAttackStrengths = function(type)
|
|||
{
|
||||
// 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);
|
||||
return cmpTechMan.ApplyModifications("Attack/" + type + "/" + damageType, +(self.template[type][damageType] || 0), self.entity);
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ Builder.prototype.GetRange = function()
|
|||
Builder.prototype.PerformBuilding = function(target)
|
||||
{
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
var rate = cmpTechMan.ApplyModifications("Builder/Rate", this.template.Rate, this.entity);
|
||||
var rate = cmpTechMan.ApplyModifications("Builder/Rate", +this.template.Rate, this.entity);
|
||||
|
||||
// If it's a foundation, then build it
|
||||
var cmpFoundation = Engine.QueryInterface(target, IID_Foundation);
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ BuildingAI.prototype.GetDefaultArrowCount = function()
|
|||
{
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
if (cmpTechMan)
|
||||
return cmpTechMan.ApplyModifications("BuildingAI/DefaultArrowCount", this.template.DefaultArrowCount, this.entity);
|
||||
return cmpTechMan.ApplyModifications("BuildingAI/DefaultArrowCount", +this.template.DefaultArrowCount, this.entity);
|
||||
else
|
||||
return +this.template.DefaultArrowCount;
|
||||
};
|
||||
|
|
@ -118,7 +118,7 @@ BuildingAI.prototype.GetGarrisonArrowMultiplier = function()
|
|||
{
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
if (cmpTechMan)
|
||||
return cmpTechMan.ApplyModifications("BuildingAI/GarrisonArrowMultiplier", this.template.GarrisonArrowMultiplier, this.entity);
|
||||
return cmpTechMan.ApplyModifications("BuildingAI/GarrisonArrowMultiplier", +this.template.GarrisonArrowMultiplier, this.entity);
|
||||
else
|
||||
return +this.template.GarrisonArrowMultiplier;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ GarrisonHolder.prototype.GetAllowedClassesList = function()
|
|||
GarrisonHolder.prototype.GetCapacity = function()
|
||||
{
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
return cmpTechMan.ApplyModifications("GarrisonHolder/Max", this.template.Max, this.entity);
|
||||
return cmpTechMan.ApplyModifications("GarrisonHolder/Max", +this.template.Max, this.entity);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -73,7 +73,7 @@ GarrisonHolder.prototype.GetCapacity = function()
|
|||
GarrisonHolder.prototype.GetHealRate = function()
|
||||
{
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
return cmpTechMan.ApplyModifications("GarrisonHolder/BuffHeal", this.template.BuffHeal, this.entity);
|
||||
return cmpTechMan.ApplyModifications("GarrisonHolder/BuffHeal", +this.template.BuffHeal, this.entity);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ 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 = cmpTechMan.ApplyModifications("Heal/Rate", +this.template.Rate, this.entity);
|
||||
return { "prepare": prepare, "repeat": repeat };
|
||||
};
|
||||
|
||||
Heal.prototype.GetRange = function()
|
||||
{
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
var max = cmpTechMan.ApplyModifications("Heal/Range", this.template.Range, this.entity);
|
||||
var max = cmpTechMan.ApplyModifications("Heal/Range", +this.template.Range, this.entity);
|
||||
var min = 0;
|
||||
return { "max": max, "min": min };
|
||||
};
|
||||
|
|
@ -78,7 +78,7 @@ Heal.prototype.PerformHeal = function(target)
|
|||
return;
|
||||
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
var targetState = cmpHealth.Increase(cmpTechMan.ApplyModifications("Heal/HP", this.template.HP, this.entity));
|
||||
var targetState = cmpHealth.Increase(cmpTechMan.ApplyModifications("Heal/HP", +this.template.HP, this.entity));
|
||||
|
||||
// Add XP
|
||||
var cmpLoot = Engine.QueryInterface(target, IID_Loot);
|
||||
|
|
|
|||
|
|
@ -130,11 +130,11 @@ ResourceGatherer.prototype.GetGatherRates = function()
|
|||
var ret = {};
|
||||
var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
||||
|
||||
var baseSpeed = cmpTechMan.ApplyModifications("ResourceGatherer/BaseSpeed", this.template.BaseSpeed, this.entity);
|
||||
var baseSpeed = cmpTechMan.ApplyModifications("ResourceGatherer/BaseSpeed", +this.template.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 = cmpTechMan.ApplyModifications("ResourceGatherer/Rates/" + r, +this.template.Rates[r], this.entity);
|
||||
ret[r] = rate * baseSpeed;
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ ResourceGatherer.prototype.GetCapacities = function()
|
|||
|
||||
for (var r in this.template.Capacities)
|
||||
{
|
||||
ret[r] = cmpTechMan.ApplyModifications("ResourceGatherer/Capacities/" + r, this.template.Capacities[r], this.entity);
|
||||
ret[r] = cmpTechMan.ApplyModifications("ResourceGatherer/Capacities/" + r, +this.template.Capacities[r], this.entity);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -279,6 +279,10 @@ TechnologyManager.prototype.clearModificationCache = function(ent)
|
|||
};
|
||||
|
||||
// Caching layer in front of ApplyModificationsWorker
|
||||
// Note: be careful with the type of curValue, if it should be a numerical
|
||||
// value and is derived from template data, you must convert the string
|
||||
// from the template to a number using the + operator, before calling
|
||||
// this function!
|
||||
TechnologyManager.prototype.ApplyModifications = function(valueName, curValue, ent)
|
||||
{
|
||||
if (!this.modificationCache[valueName])
|
||||
|
|
@ -293,7 +297,6 @@ TechnologyManager.prototype.ApplyModifications = function(valueName, curValue, e
|
|||
// The code to actually apply the modification
|
||||
TechnologyManager.prototype.ApplyModificationsWorker = function(valueName, curValue, ent)
|
||||
{
|
||||
|
||||
// Get all modifications to this value
|
||||
var modifications = this.modifications[valueName];
|
||||
if (!modifications) // no modifications so return the original value
|
||||
|
|
@ -303,7 +306,7 @@ TechnologyManager.prototype.ApplyModificationsWorker = function(valueName, curVa
|
|||
var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
|
||||
var classes = cmpIdentity.GetClassesList();
|
||||
|
||||
var retValue = +curValue;
|
||||
var retValue = curValue;
|
||||
|
||||
for (var i in modifications)
|
||||
{
|
||||
|
|
@ -329,7 +332,7 @@ TechnologyManager.prototype.ApplyModificationsWorker = function(valueName, curVa
|
|||
{
|
||||
// Nothing is cumulative so that ordering doesn't matter as much as possible
|
||||
if (modification.multiplier)
|
||||
retValue += (modification.multiplier - 1) * +curValue;
|
||||
retValue += (modification.multiplier - 1) * curValue;
|
||||
else if (modification.add)
|
||||
retValue += modification.add;
|
||||
else if (modification.replace) // This will depend on ordering because there is no choice
|
||||
|
|
|
|||
Loading…
Reference in a new issue