1
0
forked from mirrors/0ad

Rename technology related files, methods and messages so their names represent the shared data flow between technologies and auras (and maybe future components). Implement the C++ part of auras through these generalised files. Fixes #2154

This was SVN commit r14001.
This commit is contained in:
sanderd17
2013-10-15 10:05:08 +00:00
parent a4ce8dac34
commit 5f5eedc513
34 changed files with 156 additions and 193 deletions
@@ -83,7 +83,7 @@ Armour.prototype.GetArmourStrengths = function()
// Work out the armour values with technology effects
var self = this;
var applyTechs = function(type, foundation)
var applyMods = function(type, foundation)
{
var strength;
if (foundation)
@@ -96,26 +96,24 @@ Armour.prototype.GetArmourStrengths = function()
strength = +self.template[type];
}
// All causes caching problems so disable it for now.
// var allComponent = ApplyTechModificationsToEntity("Armour/All", strength, self.entity) - self.template[type];
strength = ApplyTechModificationsToEntity("Armour/" + type, strength, self.entity);
strength = ApplyValueModificationsToEntity("Armour/" + type, strength, self.entity);
return strength;
};
if (Engine.QueryInterface(this.entity, IID_Foundation) && this.template.Foundation)
{
return {
hack: applyTechs("Hack", true),
pierce: applyTechs("Pierce", true),
crush: applyTechs("Crush", true)
hack: applyMods("Hack", true),
pierce: applyMods("Pierce", true),
crush: applyMods("Crush", true)
};
}
else
{
return {
hack: applyTechs("Hack"),
pierce: applyTechs("Pierce"),
crush: applyTechs("Crush")
hack: applyMods("Hack"),
pierce: applyMods("Pierce"),
crush: applyMods("Crush")
};
}
};
@@ -322,10 +322,10 @@ Attack.prototype.CompareEntitiesByPreference = function(a, b)
Attack.prototype.GetTimers = function(type)
{
var prepare = +(this.template[type].PrepareTime || 0);
prepare = ApplyTechModificationsToEntity("Attack/" + type + "/PrepareTime", prepare, this.entity);
prepare = ApplyValueModificationsToEntity("Attack/" + type + "/PrepareTime", prepare, this.entity);
var repeat = +(this.template[type].RepeatTime || 1000);
repeat = ApplyTechModificationsToEntity("Attack/" + type + "/RepeatTime", repeat, this.entity);
repeat = ApplyValueModificationsToEntity("Attack/" + type + "/RepeatTime", repeat, this.entity);
return { "prepare": prepare, "repeat": repeat, "recharge": repeat - prepare };
};
@@ -343,30 +343,28 @@ Attack.prototype.GetAttackStrengths = function(type)
splash = "/Splash";
}
var applyTechs = function(damageType)
var applyMods = function(damageType)
{
// All causes caching problems so disable it for now.
//var allComponent = ApplyTechModificationsToEntity("Attack/" + type + splash + "/All", +(template[damageType] || 0), self.entity) - self.template[type][damageType];
return ApplyTechModificationsToEntity("Attack/" + type + splash + "/" + damageType, +(template[damageType] || 0), self.entity);
return ApplyValueModificationsToEntity("Attack/" + type + splash + "/" + damageType, +(template[damageType] || 0), self.entity);
};
return {
hack: applyTechs("Hack"),
pierce: applyTechs("Pierce"),
crush: applyTechs("Crush")
hack: applyMods("Hack"),
pierce: applyMods("Pierce"),
crush: applyMods("Crush")
};
};
Attack.prototype.GetRange = function(type)
{
var max = +this.template[type].MaxRange;
max = ApplyTechModificationsToEntity("Attack/" + type + "/MaxRange", max, this.entity);
max = ApplyValueModificationsToEntity("Attack/" + type + "/MaxRange", max, this.entity);
var min = +(this.template[type].MinRange || 0);
min = ApplyTechModificationsToEntity("Attack/" + type + "/MinRange", min, this.entity);
min = ApplyValueModificationsToEntity("Attack/" + type + "/MinRange", min, this.entity);
var elevationBonus = +(this.template[type].ElevationBonus || 0);
elevationBonus = ApplyTechModificationsToEntity("Attack/" + type + "/ElevationBonus", elevationBonus, this.entity);
elevationBonus = ApplyValueModificationsToEntity("Attack/" + type + "/ElevationBonus", elevationBonus, this.entity);
return { "max": max, "min": min, "elevationBonus": elevationBonus};
};
@@ -438,7 +436,7 @@ Attack.prototype.PerformAttack = function(type, target)
var gravity = 9.81; // this affects the shape of the curve; assume it's constant for now
var spread = +this.template.Ranged.Spread;
spread = ApplyTechModificationsToEntity("Attack/Ranged/Spread", spread, this.entity);
spread = ApplyValueModificationsToEntity("Attack/Ranged/Spread", spread, this.entity);
//horizSpeed /= 2; gravity /= 2; // slow it down for testing
@@ -37,6 +37,7 @@ AuraManager.prototype.ApplyBonus = function(value, ent, data, key)
if (this.modifications[value][ent][key].length > 1)
return;
// first time added this aura
if (data.multiply)
this.modificationsCache[value][ent].multiply *= data.multiply;
@@ -45,12 +46,7 @@ AuraManager.prototype.ApplyBonus = function(value, ent, data, key)
this.modificationsCache[value][ent].add += data.add;
// post message to the entity to notify it about the change
// TODO MT_TechnologyModification expects a player ID, so we have to provide something.
// Use -1 until this is changed not to require one.
// This player info is not needed, as the message gets send to the correct entities immediately
// A better way of handling this would be to remove the player info from the message data.
var component = value.split("/")[0];
Engine.PostMessage(ent, MT_TechnologyModification, { "component": component, "player": -1 });
Engine.PostMessage(ent, MT_ValueModification, { "component": value.split("/")[0] });
};
AuraManager.prototype.ApplyTemplateBonus = function(value, player, classes, data, key)
@@ -78,10 +74,6 @@ AuraManager.prototype.ApplyTemplateBonus = function(value, player, classes, data
this.templateModificationsCache[value][player][c][key].add += data.add;
}
// post message to notify about the change
var component = value.split("/")[0];
Engine.BroadcastMessage(MT_TechnologyModification, { "component": component, "player": player});
};
AuraManager.prototype.RemoveBonus = function(value, ent, key)
@@ -106,12 +98,7 @@ AuraManager.prototype.RemoveBonus = function(value, ent, key)
this.modificationsCache[value][ent].multiply /= data.multiply;
// post message to the entity to notify it about the change
// TODO MT_TechnologyModification expects a player ID, so we have to provide something.
// Use -1 until this is changed not to require one.
// This player info is not needed, as the message gets send to the correct entities immediately
// A better way of handling this would be to remove the player info from the message data.
var component = value.split("/")[0];
Engine.PostMessage(ent, MT_TechnologyModification, { "component": component, "player": -1 });
Engine.PostMessage(ent, MT_ValueModification, { "component": value.split("/")[0] });
};
AuraManager.prototype.RemoveTemplateBonus = function(value, player, classes, key)
@@ -132,10 +119,6 @@ AuraManager.prototype.RemoveTemplateBonus = function(value, player, classes, key
this.templateModificationsCache[value][player][c][key].multiply = 1;
this.templateModificationsCache[value][player][c][key].add = 0;
}
// post message to notify about the change
var component = value.split("/")[0];
Engine.BroadcastMessage(MT_TechnologyModification, { "component": component, "player": player });
};
AuraManager.prototype.ApplyModifications = function(valueName, value, ent)
@@ -354,9 +354,9 @@ Auras.prototype.OnDiplomacyChanged = function(msg)
this.Clean();
};
Auras.prototype.OnTechnologyModification = function(msg)
Auras.prototype.OnValueModification = function(msg)
{
if (msg.component =="Auras")
if (msg.component == "Auras")
this.Clean();
};
@@ -271,7 +271,7 @@ BuildRestrictions.prototype.GetCategory = function()
BuildRestrictions.prototype.GetTerritories = function()
{
return ApplyTechModificationsToEntity("BuildRestrictions/Territory", this.territories, this.entity);
return ApplyValueModificationsToEntity("BuildRestrictions/Territory", this.territories, this.entity);
};
BuildRestrictions.prototype.HasTerritory = function(territory)
@@ -56,7 +56,7 @@ Builder.prototype.GetRange = function()
*/
Builder.prototype.PerformBuilding = function(target)
{
var rate = ApplyTechModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity);
var rate = ApplyValueModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity);
// If it's a foundation, then build it
var cmpFoundation = Engine.QueryInterface(target, IID_Foundation);
@@ -199,13 +199,13 @@ BuildingAI.prototype.OnRangeUpdate = function(msg)
BuildingAI.prototype.GetDefaultArrowCount = function()
{
var arrowCount = +this.template.DefaultArrowCount;
return ApplyTechModificationsToEntity("BuildingAI/DefaultArrowCount", arrowCount, this.entity);
return ApplyValueModificationsToEntity("BuildingAI/DefaultArrowCount", arrowCount, this.entity);
};
BuildingAI.prototype.GetGarrisonArrowMultiplier = function()
{
var arrowMult = +this.template.GarrisonArrowMultiplier;
return ApplyTechModificationsToEntity("BuildingAI/GarrisonArrowMultiplier", arrowMult, this.entity);
return ApplyValueModificationsToEntity("BuildingAI/GarrisonArrowMultiplier", arrowMult, this.entity);
};
BuildingAI.prototype.GetGarrisonArrowClasses = function()
@@ -51,7 +51,7 @@ Cost.prototype.GetBuildTime = function()
{
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
var buildTime = (+this.template.BuildTime) * cmpPlayer.cheatTimeMultiplier;
return ApplyTechModificationsToEntity("Cost/BuildTime", buildTime, this.entity);
return ApplyValueModificationsToEntity("Cost/BuildTime", buildTime, this.entity);
}
Cost.prototype.GetResourceCosts = function()
@@ -60,7 +60,7 @@ Cost.prototype.GetResourceCosts = function()
for (var r in this.template.Resources)
{
costs[r] = +this.template.Resources[r];
costs[r] = ApplyTechModificationsToEntity("Cost/Resources/"+r, costs[r], this.entity);
costs[r] = ApplyValueModificationsToEntity("Cost/Resources/"+r, costs[r], this.entity);
}
return costs;
};
@@ -18,7 +18,7 @@ EntityLimitsChanger.prototype.OnOwnershipChanged = function(msg)
{
this.changes = {};
for (var cat in this.template)
this.changes[cat] = ApplyTechModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
this.changes[cat] = ApplyValueModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
}
if (msg.from > -1)
@@ -38,7 +38,7 @@ EntityLimitsChanger.prototype.OnOwnershipChanged = function(msg)
}
}
EntityLimitsChanger.prototype.OnTechnologyModification = function(msg)
EntityLimitsChanger.prototype.OnValueModification = function(msg)
{
if (msg.component != "EntityLimitsChanger")
return;
@@ -50,7 +50,7 @@ EntityLimitsChanger.prototype.OnTechnologyModification = function(msg)
for (var cat in this.changes)
{
cmpEntityLimits.DecreaseLimit(cat, this.changes[cat]);
this.changes[cat] = ApplyTechModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
this.changes[cat] = ApplyValueModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
cmpEntityLimits.IncreaseLimit(cat, this.changes[cat]);
}
};
@@ -66,7 +66,7 @@ GarrisonHolder.prototype.GetAllowedClassesList = function()
*/
GarrisonHolder.prototype.GetCapacity = function()
{
return ApplyTechModificationsToEntity("GarrisonHolder/Max", +this.template.Max, this.entity);
return ApplyValueModificationsToEntity("GarrisonHolder/Max", +this.template.Max, this.entity);
};
/**
@@ -74,7 +74,7 @@ GarrisonHolder.prototype.GetCapacity = function()
*/
GarrisonHolder.prototype.GetHealRate = function()
{
return ApplyTechModificationsToEntity("GarrisonHolder/BuffHeal", +this.template.BuffHeal, this.entity);
return ApplyValueModificationsToEntity("GarrisonHolder/BuffHeal", +this.template.BuffHeal, this.entity);
};
GarrisonHolder.prototype.EjectEntitiesOnDestroy = function()
@@ -416,9 +416,9 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
if (template.Armour)
{
ret.armour = {
"hack": ApplyTechModificationsToTemplate("Armour/Hack", +template.Armour.Hack, player, template),
"pierce": ApplyTechModificationsToTemplate("Armour/Pierce", +template.Armour.Hack, player, template),
"crush": ApplyTechModificationsToTemplate("Armour/Crush", +template.Armour.Hack, player, template),
"hack": ApplyValueModificationsToTemplate("Armour/Hack", +template.Armour.Hack, player, template),
"pierce": ApplyValueModificationsToTemplate("Armour/Pierce", +template.Armour.Hack, player, template),
"crush": ApplyValueModificationsToTemplate("Armour/Crush", +template.Armour.Hack, player, template),
};
}
@@ -428,12 +428,12 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
for (var type in template.Attack)
{
ret.attack[type] = {
"hack": ApplyTechModificationsToTemplate("Attack/"+type+"/Hack", +(template.Attack[type].Hack || 0), player, template),
"pierce": ApplyTechModificationsToTemplate("Attack/"+type+"/Pierce", +(template.Attack[type].Pierce || 0), player, template),
"crush": ApplyTechModificationsToTemplate("Attack/"+type+"/Crush", +(template.Attack[type].Crush || 0), player, template),
"minRange": ApplyTechModificationsToTemplate("Attack/"+type+"/MinRange", +(template.Attack[type].MinRange || 0), player, template),
"maxRange": ApplyTechModificationsToTemplate("Attack/"+type+"/MaxRange", +template.Attack[type].MaxRange, player, template),
"elevationBonus": ApplyTechModificationsToTemplate("Attack/"+type+"/ElevationBonus", +(template.Attack[type].ElevationBonus || 0), player, template),
"hack": ApplyValueModificationsToTemplate("Attack/"+type+"/Hack", +(template.Attack[type].Hack || 0), player, template),
"pierce": ApplyValueModificationsToTemplate("Attack/"+type+"/Pierce", +(template.Attack[type].Pierce || 0), player, template),
"crush": ApplyValueModificationsToTemplate("Attack/"+type+"/Crush", +(template.Attack[type].Crush || 0), player, template),
"minRange": ApplyValueModificationsToTemplate("Attack/"+type+"/MinRange", +(template.Attack[type].MinRange || 0), player, template),
"maxRange": ApplyValueModificationsToTemplate("Attack/"+type+"/MaxRange", +template.Attack[type].MaxRange, player, template),
"elevationBonus": ApplyValueModificationsToTemplate("Attack/"+type+"/ElevationBonus", +(template.Attack[type].ElevationBonus || 0), player, template),
};
}
}
@@ -468,13 +468,13 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
if (template.Cost)
{
ret.cost = {};
if (template.Cost.Resources.food) ret.cost.food = ApplyTechModificationsToTemplate("Cost/Resources/food", +template.Cost.Resources.food, player, template);
if (template.Cost.Resources.wood) ret.cost.wood = ApplyTechModificationsToTemplate("Cost/Resources/wood", +template.Cost.Resources.wood, player, template);
if (template.Cost.Resources.stone) ret.cost.stone = ApplyTechModificationsToTemplate("Cost/Resources/stone", +template.Cost.Resources.stone, player, template);
if (template.Cost.Resources.metal) ret.cost.metal = ApplyTechModificationsToTemplate("Cost/Resources/metal", +template.Cost.Resources.metal, player, template);
if (template.Cost.Population) ret.cost.population = ApplyTechModificationsToTemplate("Cost/Population", +template.Cost.Population, player, template);
if (template.Cost.PopulationBonus) ret.cost.populationBonus = ApplyTechModificationsToTemplate("Cost/PopulationBonus", +template.Cost.PopulationBonus, player, template);
if (template.Cost.BuildTime) ret.cost.time = ApplyTechModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, player, template);
if (template.Cost.Resources.food) ret.cost.food = ApplyValueModificationsToTemplate("Cost/Resources/food", +template.Cost.Resources.food, player, template);
if (template.Cost.Resources.wood) ret.cost.wood = ApplyValueModificationsToTemplate("Cost/Resources/wood", +template.Cost.Resources.wood, player, template);
if (template.Cost.Resources.stone) ret.cost.stone = ApplyValueModificationsToTemplate("Cost/Resources/stone", +template.Cost.Resources.stone, player, template);
if (template.Cost.Resources.metal) ret.cost.metal = ApplyValueModificationsToTemplate("Cost/Resources/metal", +template.Cost.Resources.metal, player, template);
if (template.Cost.Population) ret.cost.population = ApplyValueModificationsToTemplate("Cost/Population", +template.Cost.Population, player, template);
if (template.Cost.PopulationBonus) ret.cost.populationBonus = ApplyValueModificationsToTemplate("Cost/PopulationBonus", +template.Cost.PopulationBonus, player, template);
if (template.Cost.BuildTime) ret.cost.time = ApplyValueModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, player, template);
}
if (template.Footprint)
@@ -523,13 +523,13 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
{
ret.pack = {
"state": template.Pack.State,
"time": ApplyTechModificationsToTemplate("Pack/Time", +template.Pack.Time, player, template),
"time": ApplyValueModificationsToTemplate("Pack/Time", +template.Pack.Time, player, template),
};
}
if (template.Health)
{
ret.health = Math.round(ApplyTechModificationsToTemplate("Health/Max", +template.Health.Max, player, template));
ret.health = Math.round(ApplyValueModificationsToTemplate("Health/Max", +template.Health.Max, player, template));
}
if (template.Identity)
@@ -42,7 +42,7 @@ Heal.prototype.GetTimers = function()
var prepare = 1000;
var repeat = +this.template.Rate;
repeat = ApplyTechModificationsToEntity("Heal/Rate", repeat, this.entity);
repeat = ApplyValueModificationsToEntity("Heal/Rate", repeat, this.entity);
return { "prepare": prepare, "repeat": repeat };
};
@@ -52,7 +52,7 @@ Heal.prototype.GetRange = function()
var min = 0;
var max = +this.template.Range;
max = ApplyTechModificationsToEntity("Heal/Range", max, this.entity);
max = ApplyValueModificationsToEntity("Heal/Range", max, this.entity);
return { "max": max, "min": min };
};
@@ -80,7 +80,7 @@ Heal.prototype.PerformHeal = function(target)
if (!cmpHealth)
return;
var targetState = cmpHealth.Increase(ApplyTechModificationsToEntity("Heal/HP", +this.template.HP, this.entity));
var targetState = cmpHealth.Increase(ApplyValueModificationsToEntity("Heal/HP", +this.template.HP, this.entity));
// Add XP
var cmpLoot = Engine.QueryInterface(target, IID_Loot);
@@ -327,25 +327,25 @@ Health.prototype.Repair = function(builderEnt, work)
}
};
Health.prototype.OnTechnologyModification = function(msg)
Health.prototype.OnValueModification = function(msg)
{
if (msg.component == "Health")
{
var oldMaxHitpoints = this.GetMaxHitpoints();
var newMaxHitpoints = Math.round(ApplyTechModificationsToEntity("Health/Max", +this.template.Max, this.entity));
if (oldMaxHitpoints != newMaxHitpoints)
{
var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
this.maxHitpoints = newMaxHitpoints;
this.SetHitpoints(newHitpoints);
}
if (msg.component != "Health")
return;
var oldRegenRate = this.regenRate;
this.regenRate = ApplyTechModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
if (this.regenRate != oldRegenRate)
this.CheckRegenTimer();
var oldMaxHitpoints = this.GetMaxHitpoints();
var newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));
if (oldMaxHitpoints != newMaxHitpoints)
{
var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
this.maxHitpoints = newMaxHitpoints;
this.SetHitpoints(newHitpoints);
}
var oldRegenRate = this.regenRate;
this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
if (this.regenRate != oldRegenRate)
this.CheckRegenTimer();
};
Health.prototype.OnHealthChanged = function()
@@ -95,7 +95,7 @@ Pack.prototype.CancelPack = function()
Pack.prototype.GetPackTime = function()
{
return ApplyTechModificationsToEntity("Pack/Time", +this.template.Time, this.entity);
return ApplyValueModificationsToEntity("Pack/Time", +this.template.Time, this.entity);
};
Pack.prototype.GetElapsedTime = function()
@@ -108,7 +108,7 @@ Player.prototype.SetMaxPopulation = function(max)
Player.prototype.GetMaxPopulation = function()
{
return Math.round(ApplyTechModificationsToPlayer("Player/MaxPopulation", this.maxPop, this.entity));
return Math.round(ApplyValueModificationsToPlayer("Player/MaxPopulation", this.maxPop, this.entity));
};
Player.prototype.SetGatherRateMultiplier = function(value)
@@ -200,12 +200,12 @@ ProductionQueue.prototype.AddBatch = function(templateName, type, count, metadat
// Obviously we don't have the entities yet, so we must use template data
var costs = {};
var totalCosts = {};
var buildTime = ApplyTechModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, cmpPlayer.GetPlayerID(), template);
var buildTime = ApplyValueModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, cmpPlayer.GetPlayerID(), template);
var time = timeMult * buildTime;
for (var r in template.Cost.Resources)
{
costs[r] = ApplyTechModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], cmpPlayer.GetPlayerID(), template);
costs[r] = ApplyValueModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], cmpPlayer.GetPlayerID(), template);
totalCosts[r] = Math.floor(count * costs[r]);
}
@@ -405,7 +405,7 @@ ProductionQueue.prototype.GetBatchTime = function(batchSize)
{
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
var batchTimeModifier = ApplyTechModificationsToEntity("ProductionQueue/BatchTimeModifier", +this.template.BatchTimeModifier, this.entity);
var batchTimeModifier = ApplyValueModificationsToEntity("ProductionQueue/BatchTimeModifier", +this.template.BatchTimeModifier, this.entity);
// TODO: work out what equation we should use here.
return Math.pow(batchSize, batchTimeModifier) * cmpPlayer.GetCheatTimeMultiplier();
@@ -15,7 +15,7 @@ Promotion.prototype.Init = function()
Promotion.prototype.GetRequiredXp = function()
{
return ApplyTechModificationsToEntity("Promotion/RequiredXp", +this.template.RequiredXp, this.entity);
return ApplyValueModificationsToEntity("Promotion/RequiredXp", +this.template.RequiredXp, this.entity);
};
Promotion.prototype.GetCurrentXp = function()
@@ -130,11 +130,11 @@ ResourceGatherer.prototype.GetGatherRates = function()
var ret = {};
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
var baseSpeed = ApplyTechModificationsToEntity("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity) * cmpPlayer.GetGatherRateMultiplier();
var baseSpeed = ApplyValueModificationsToEntity("ResourceGatherer/BaseSpeed", +this.template.BaseSpeed, this.entity) * cmpPlayer.GetGatherRateMultiplier();
for (var r in this.template.Rates)
{
var rate = ApplyTechModificationsToEntity("ResourceGatherer/Rates/" + r, +this.template.Rates[r], this.entity);
var rate = ApplyValueModificationsToEntity("ResourceGatherer/Rates/" + r, +this.template.Rates[r], this.entity);
ret[r] = rate * baseSpeed;
}
@@ -147,7 +147,7 @@ ResourceGatherer.prototype.GetCapacities = function()
for (var r in this.template.Capacities)
{
ret[r] = ApplyTechModificationsToEntity("ResourceGatherer/Capacities/" + r, +this.template.Capacities[r], this.entity);
ret[r] = ApplyValueModificationsToEntity("ResourceGatherer/Capacities/" + r, +this.template.Capacities[r], this.entity);
}
return ret;
@@ -80,7 +80,7 @@ ResourceSupply.prototype.GetGatherers = function()
ResourceSupply.prototype.GetDiminishingReturns = function()
{
if ("DiminishingReturns" in this.template)
return ApplyTechModificationsToEntity("ResourceSupply/DiminishingReturns", +this.template.DiminishingReturns, this.entity);
return ApplyValueModificationsToEntity("ResourceSupply/DiminishingReturns", +this.template.DiminishingReturns, this.entity);
return null;
};
@@ -219,8 +219,6 @@ TechnologyManager.prototype.OnGlobalOwnershipChanged = function (msg)
// we want it to maintain whatever technologies previously applied)
if (msg.from == -1)
{
var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
var playerID = cmpPlayer.GetPlayerID();
var modifiedComponents = {};
for (var name in this.modifications)
{
@@ -234,7 +232,7 @@ TechnologyManager.prototype.OnGlobalOwnershipChanged = function (msg)
// Send mesage(s) to the entity so it knows about researched techs
for (var component in modifiedComponents)
Engine.PostMessage(msg.entity, MT_TechnologyModification, { "component": component, "player": playerID });
Engine.PostMessage(msg.entity, MT_ValueModification, { "component": component });
}
}
if (msg.from == playerID)
@@ -331,15 +329,9 @@ TechnologyManager.prototype.ResearchTechnology = function (tech)
this.UpdateAutoResearch();
var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
var player = cmpPlayer.GetPlayerID();
// TODO: Handle technology broadcasting for autoresearch properly (some components might not be initialized currently)
if (player === undefined)
return;
for (var component in modifiedComponents){
Engine.BroadcastMessage(MT_TechnologyModification, { "component": component, "player": player });
}
for (var component in modifiedComponents)
Engine.BroadcastMessage(MT_ValueModification, { "component": component });
};
// Clears the cached data for an entity from the modifications cache
@@ -72,7 +72,7 @@ TerritoryDecay.prototype.Decay = function()
if (!cmpHealth)
return; // error
var decayRate = ApplyTechModificationsToEntity("TerritoryDecay/HealthDecayRate", +this.template.HealthDecayRate, this.entity);
var decayRate = ApplyValueModificationsToEntity("TerritoryDecay/HealthDecayRate", +this.template.HealthDecayRate, this.entity);
cmpHealth.Reduce(Math.round(decayRate));
};
@@ -0,0 +1,16 @@
function ValueModificationManager() {};
/*
* A component to give the C++ defined components access to all value modifying components
* via the helper script.
*/
ValueModificationManager.prototype.Schema =
"<a:component type='system'/><empty/>";
ValueModificationManager.prototype.ApplyModifications = function(valueName, currentValue, entity)
{
return ApplyValueModificationsToEntity(valueName, currentValue, entity);
};
Engine.RegisterComponentType(IID_ValueModificationManager, "ValueModificationManager", ValueModificationManager);
@@ -0,0 +1,2 @@
Engine.RegisterInterface("TechnologyManager");
@@ -36,10 +36,10 @@ function CalculateTraderGain(firstMarket, secondMarket, template, trader)
var ownerSecondMarket = Engine.QueryInterface(secondMarket, IID_Ownership).GetOwner();
if (ownerFirstMarket != ownerSecondMarket)
{
var internationalGain1 = ApplyTechModificationsToEntity("Trade/International", INTERNATIONAL_TRADING_ADDITION, firstMarket);
var internationalGain1 = ApplyValueModificationsToEntity("Trade/International", INTERNATIONAL_TRADING_ADDITION, firstMarket);
gain.market1Gain = Math.round(gain.traderGain * internationalGain1 / 100);
gain.market1Owner = ownerFirstMarket;
var internationalGain2 = ApplyTechModificationsToEntity("Trade/International", INTERNATIONAL_TRADING_ADDITION, secondMarket);
var internationalGain2 = ApplyValueModificationsToEntity("Trade/International", INTERNATIONAL_TRADING_ADDITION, secondMarket);
gain.market2Gain = Math.round(gain.traderGain * internationalGain2 / 100);
gain.market2Owner = ownerSecondMarket;
@@ -1,6 +1,6 @@
// Little helper functions to make applying tehnology more covenient
function ApplyTechModificationsToEntity(tech_type, current_value, entity)
function ApplyValueModificationsToEntity(tech_type, current_value, entity)
{
var cmpTechMan = QueryOwnerInterface(entity, IID_TechnologyManager);
if (cmpTechMan)
@@ -14,7 +14,7 @@ function ApplyTechModificationsToEntity(tech_type, current_value, entity)
return cmpAuraManager.ApplyModifications(tech_type, value, entity);
}
function ApplyTechModificationsToPlayer(tech_type, current_value, player_entity)
function ApplyValueModificationsToPlayer(tech_type, current_value, player_entity)
{
var cmpTechMan = Engine.QueryInterface(player_entity, IID_TechnologyManager);
@@ -24,7 +24,7 @@ function ApplyTechModificationsToPlayer(tech_type, current_value, player_entity)
return cmpTechMan.ApplyModifications(tech_type, current_value, player_entity);
}
function ApplyTechModificationsToTemplate(tech_type, current_value, playerID, template)
function ApplyValueModificationsToTemplate(tech_type, current_value, playerID, template)
{
var cmpTechMan = QueryPlayerIDInterface(playerID, IID_TechnologyManager);
if (cmpTechMan)
@@ -38,6 +38,6 @@ function ApplyTechModificationsToTemplate(tech_type, current_value, playerID, te
return cmpAuraManager.ApplyTemplateModifications(tech_type, value, playerID, template);
}
Engine.RegisterGlobal("ApplyTechModificationsToEntity", ApplyTechModificationsToEntity);
Engine.RegisterGlobal("ApplyTechModificationsToPlayer", ApplyTechModificationsToPlayer);
Engine.RegisterGlobal("ApplyTechModificationsToTemplate", ApplyTechModificationsToTemplate);
Engine.RegisterGlobal("ApplyValueModificationsToEntity", ApplyValueModificationsToEntity);
Engine.RegisterGlobal("ApplyValueModificationsToPlayer", ApplyValueModificationsToPlayer);
Engine.RegisterGlobal("ApplyValueModificationsToTemplate", ApplyValueModificationsToTemplate);
+5 -6
View File
@@ -366,20 +366,19 @@ public:
};
/**
* Sent by technology manager when a technology is researched that modifies a component.
* Sent by value modification manager when a value of a certain component is changed
*/
class CMessageTechnologyModification : public CMessage
class CMessageValueModification : public CMessage
{
public:
DEFAULT_MESSAGE_IMPL(TechnologyModification)
DEFAULT_MESSAGE_IMPL(ValueModification)
CMessageTechnologyModification(std::wstring component, player_id_t player) :
component(component), player(player)
CMessageValueModification(std::wstring component) :
component(component)
{
}
std::wstring component;
player_id_t player;
};
/**
+2 -1
View File
@@ -125,14 +125,15 @@ public:
LOGERROR(L"Can't find component type " L##name); \
componentManager.AddComponent(systemEntity, cid, noParam)
LOAD_SCRIPTED_COMPONENT("AuraManager");
LOAD_SCRIPTED_COMPONENT("AIInterface");
LOAD_SCRIPTED_COMPONENT("AuraManager");
LOAD_SCRIPTED_COMPONENT("Barter");
LOAD_SCRIPTED_COMPONENT("EndGameManager");
LOAD_SCRIPTED_COMPONENT("GuiInterface");
LOAD_SCRIPTED_COMPONENT("PlayerManager");
LOAD_SCRIPTED_COMPONENT("TechnologyTemplateManager");
LOAD_SCRIPTED_COMPONENT("Timer");
LOAD_SCRIPTED_COMPONENT("ValueModificationManager");
#undef LOAD_SCRIPTED_COMPONENT
+3 -3
View File
@@ -47,7 +47,7 @@ MESSAGE(RangeUpdate)
MESSAGE(TerrainChanged)
MESSAGE(TerritoriesChanged)
MESSAGE(PathResult)
MESSAGE(TechnologyModification)
MESSAGE(ValueModification)
MESSAGE(VisionRangeChanged)
MESSAGE(MinimapPing)
@@ -139,8 +139,8 @@ COMPONENT(SettlementScripted)
INTERFACE(SoundManager)
COMPONENT(SoundManager)
INTERFACE(TechnologyManager)
COMPONENT(TechnologyManagerScripted)
INTERFACE(ValueModificationManager)
COMPONENT(ValueModificationManagerScripted)
INTERFACE(TechnologyTemplateManager)
COMPONENT(TechnologyTemplateManagerScripted)
@@ -22,7 +22,7 @@
#include "simulation2/components/ICmpOwnership.h"
#include "simulation2/components/ICmpPlayerManager.h"
#include "simulation2/components/ICmpTechnologyManager.h"
#include "simulation2/components/ICmpValueModificationManager.h"
class CCmpTerritoryInfluence : public ICmpTerritoryInfluence
{
@@ -103,19 +103,8 @@ public:
{
u32 newRadius = m_Radius;
CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle());
if (cmpOwnership && cmpOwnership->GetOwner() != INVALID_PLAYER)
{
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
entity_id_t playerEnt = cmpPlayerManager->GetPlayerByID(cmpOwnership->GetOwner());
if (playerEnt != INVALID_ENTITY)
{
CmpPtr<ICmpTechnologyManager> cmpTechnologyManager(GetSimContext(), playerEnt);
if (cmpTechnologyManager)
newRadius = cmpTechnologyManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId());
}
}
CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId());
return newRadius;
}
@@ -66,7 +66,7 @@ public:
{
componentManager.SubscribeGloballyToMessageType(MT_OwnershipChanged);
componentManager.SubscribeGloballyToMessageType(MT_PositionChanged);
componentManager.SubscribeGloballyToMessageType(MT_TechnologyModification);
componentManager.SubscribeGloballyToMessageType(MT_ValueModification);
componentManager.SubscribeToMessageType(MT_TerrainChanged);
componentManager.SubscribeToMessageType(MT_Update);
componentManager.SubscribeToMessageType(MT_Interpolate);
@@ -165,9 +165,9 @@ public:
MakeDirtyIfRelevantEntity(msgData.entity);
break;
}
case MT_TechnologyModification:
case MT_ValueModification:
{
const CMessageTechnologyModification& msgData = static_cast<const CMessageTechnologyModification&> (msg);
const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg);
if (msgData.component == L"TerritoryInfluence")
MakeDirty();
break;
+12 -25
View File
@@ -23,14 +23,14 @@
#include "simulation2/MessageTypes.h"
#include "simulation2/components/ICmpOwnership.h"
#include "simulation2/components/ICmpPlayerManager.h"
#include "simulation2/components/ICmpTechnologyManager.h"
#include "simulation2/components/ICmpValueModificationManager.h"
class CCmpVision : public ICmpVision
{
public:
static void ClassInit(CComponentManager& componentManager)
{
componentManager.SubscribeGloballyToMessageType(MT_TechnologyModification);
componentManager.SubscribeGloballyToMessageType(MT_ValueModification);
}
DEFAULT_COMPONENT_ALLOCATOR(Vision)
@@ -80,33 +80,20 @@ public:
{
switch (msg.GetType())
{
case MT_TechnologyModification:
case MT_ValueModification:
{
const CMessageTechnologyModification& msgData = static_cast<const CMessageTechnologyModification&> (msg);
const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg);
if (msgData.component == L"Vision")
{
CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle());
if (cmpOwnership)
CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
entity_pos_t newRange = cmpValueModificationManager->ApplyModifications(L"Vision/Range", m_BaseRange, GetEntityId());
if (newRange != m_Range)
{
player_id_t owner = cmpOwnership->GetOwner();
if (owner != INVALID_PLAYER && owner == msgData.player)
{
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
entity_id_t playerEnt = cmpPlayerManager->GetPlayerByID(owner);
CmpPtr<ICmpTechnologyManager> cmpTechnologyManager(GetSimContext(), playerEnt);
if (playerEnt != INVALID_ENTITY && cmpTechnologyManager)
{
entity_pos_t newRange = cmpTechnologyManager->ApplyModifications(L"Vision/Range", m_BaseRange, GetEntityId());
if (newRange != m_Range)
{
// Update our vision range and broadcast message
entity_pos_t oldRange = m_Range;
m_Range = newRange;
CMessageVisionRangeChanged msg(GetEntityId(), oldRange, newRange);
GetSimContext().GetComponentManager().BroadcastMessage(msg);
}
}
}
// Update our vision range and broadcast message
entity_pos_t oldRange = m_Range;
m_Range = newRange;
CMessageVisionRangeChanged msg(GetEntityId(), oldRange, newRange);
GetSimContext().GetComponentManager().BroadcastMessage(msg);
}
}
break;
@@ -17,18 +17,18 @@
#include "precompiled.h"
#include "ICmpTechnologyManager.h"
#include "ICmpValueModificationManager.h"
#include "simulation2/system/InterfaceScripted.h"
#include "simulation2/scripting/ScriptComponent.h"
BEGIN_INTERFACE_WRAPPER(TechnologyManager)
END_INTERFACE_WRAPPER(TechnologyManager)
BEGIN_INTERFACE_WRAPPER(ValueModificationManager)
END_INTERFACE_WRAPPER(ValueModificationManager)
class CCmpTechnologyManagerScripted : public ICmpTechnologyManager
class CCmpValueModificationManagerScripted : public ICmpValueModificationManager
{
public:
DEFAULT_SCRIPT_WRAPPER(TechnologyManagerScripted)
DEFAULT_SCRIPT_WRAPPER(ValueModificationManagerScripted)
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity)
{
@@ -41,4 +41,4 @@ public:
}
};
REGISTER_COMPONENT_SCRIPT_WRAPPER(TechnologyManagerScripted)
REGISTER_COMPONENT_SCRIPT_WRAPPER(ValueModificationManagerScripted)
@@ -15,25 +15,25 @@
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_ICMPTECHNOLOGYMANAGER
#define INCLUDED_ICMPTECHNOLOGYMANAGER
#ifndef INCLUDED_ICMPVALUEMODIFICATIONMANAGER
#define INCLUDED_ICMPVALUEMODIFICATIONMANAGER
#include "simulation2/system/Interface.h"
#include "maths/Fixed.h"
/**
* Technology manager interface.
* value modification manager interface.
* (This interface only includes the functions needed by native code for accessing
* technology modification data, the associated logic is handled in scripts)
* value modification data, the associated logic is handled in scripts)
*/
class ICmpTechnologyManager : public IComponent
class ICmpValueModificationManager : public IComponent
{
public:
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) = 0;
virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) = 0;
DECLARE_INTERFACE_TYPE(TechnologyManager)
DECLARE_INTERFACE_TYPE(ValueModificationManager)
};
#endif // INCLUDED_ICMPTECHNOLOGYMANAGER
#endif // INCLUDED_ICMPVALUEMODIFICATIONMANAGER
@@ -300,20 +300,18 @@ CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface)
////////////////////////////////
jsval CMessageTechnologyModification::ToJSVal(ScriptInterface& scriptInterface) const
jsval CMessageValueModification::ToJSVal(ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
SET_MSG_PROPERTY(component);
SET_MSG_PROPERTY(player);
return OBJECT_TO_JSVAL(obj);
}
CMessage* CMessageTechnologyModification::FromJSVal(ScriptInterface& scriptInterface, jsval val)
CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface, jsval val)
{
FROMJSVAL_SETUP();
GET_MSG_PROPERTY(std::wstring, component);
GET_MSG_PROPERTY(player_id_t, player);
return new CMessageTechnologyModification(component, player);
return new CMessageValueModification(component);
}
////////////////////////////////