1
0
forked from 0ad/0ad

use better technology script in guiInterface

This was SVN commit r13805.
This commit is contained in:
sanderd17 2013-09-07 15:23:03 +00:00
parent 24a4ceb89a
commit f588181004
3 changed files with 30 additions and 33 deletions

View File

@ -413,33 +413,30 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
var ret = {};
var cmpTechnologyManager = QueryPlayerIDInterface(player, IID_TechnologyManager);
var techMods = cmpTechnologyManager.GetTechModifications();
if (template.Armour)
{
ret.armour = {
"hack": GetTechModifiedProperty(techMods, template, "Armour/Hack", +template.Armour.Hack),
"pierce": GetTechModifiedProperty(techMods, template, "Armour/Pierce", +template.Armour.Pierce),
"crush": GetTechModifiedProperty(techMods, template, "Armour/Crush", +template.Armour.Crush),
};
}
"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),
};
}
if (template.Attack)
{
ret.attack = {};
for (var type in template.Attack)
{
ret.attack[type] = {
"hack": GetTechModifiedProperty(techMods, template, "Attack/"+type+"/Hack", +(template.Attack[type].Hack || 0)),
"pierce": GetTechModifiedProperty(techMods, template, "Attack/"+type+"/Pierce", +(template.Attack[type].Pierce || 0)),
"crush": GetTechModifiedProperty(techMods, template, "Attack/"+type+"/Crush", +(template.Attack[type].Crush || 0)),
"minRange": GetTechModifiedProperty(techMods, template, "Attack/"+type+"/MinRange", +(template.Attack[type].MinRange || 0)),
"maxRange": GetTechModifiedProperty(techMods, template, "Attack/"+type+"/MaxRange", +template.Attack[type].MaxRange),
"elevationBonus": GetTechModifiedProperty(techMods, template, "Attack/"+type+"/ElevationBonus", +(template.Attack[type].ElevationBonus || 0)),
"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),
};
}
}
}
}
if (template.BuildRestrictions)
{
@ -471,16 +468,16 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
if (template.Cost)
{
ret.cost = {};
if (template.Cost.Resources.food) ret.cost.food = GetTechModifiedProperty(techMods, template, "Cost/Resources/food", +template.Cost.Resources.food);
if (template.Cost.Resources.wood) ret.cost.wood = GetTechModifiedProperty(techMods, template, "Cost/Resources/wood", +template.Cost.Resources.wood);
if (template.Cost.Resources.stone) ret.cost.stone = GetTechModifiedProperty(techMods, template, "Cost/Resources/stone", +template.Cost.Resources.stone);
if (template.Cost.Resources.metal) ret.cost.metal = GetTechModifiedProperty(techMods, template, "Cost/Resources/metal", +template.Cost.Resources.metal);
if (template.Cost.Population) ret.cost.population = GetTechModifiedProperty(techMods, template, "Cost/Population", +template.Cost.Population);
if (template.Cost.PopulationBonus) ret.cost.populationBonus = GetTechModifiedProperty(techMods, template, "Cost/PopulationBonus", +template.Cost.PopulationBonus);
if (template.Cost.BuildTime) ret.cost.time = GetTechModifiedProperty(techMods, template, "Cost/BuildTime", +template.Cost.BuildTime);
}
if (template.Footprint)
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.Footprint)
{
ret.footprint = {"height": template.Footprint.Height};
@ -526,13 +523,13 @@ GuiInterface.prototype.GetTemplateData = function(player, extendedName)
{
ret.pack = {
"state": template.Pack.State,
"time": GetTechModifiedProperty(techMods, template, "Pack/Time", +template.Pack.Time),
"time": ApplyTechModificationsToTemplate("Pack/Time", +template.Pack.Time, player, template),
};
}
if (template.Health)
{
ret.health = Math.round(GetTechModifiedProperty(techMods, template, "Health/Max", +template.Health.Max));
ret.health = Math.round(ApplyTechModificationsToTemplate("Health/Max", +template.Health.Max, player, template));
}
if (template.Identity)

View File

@ -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, this.entity, template);
var buildTime = ApplyTechModificationsToTemplate("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], this.entity, template);
costs[r] = ApplyTechModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], cmpPlayer.GetPlayerID(), template);
totalCosts[r] = Math.floor(count * costs[r]);
}

View File

@ -20,9 +20,9 @@ function ApplyTechModificationsToPlayer(tech_type, current_value, player_entity)
return cmpTechMan.ApplyModifications(tech_type, current_value, player_entity);
}
function ApplyTechModificationsToTemplate(tech_type, current_value, owner_entity, template)
function ApplyTechModificationsToTemplate(tech_type, current_value, playerID, template)
{
var cmpTechMan = QueryOwnerInterface(owner_entity, IID_TechnologyManager);
var cmpTechMan = QueryPlayerIDInterface(playerID, IID_TechnologyManager);
if (!cmpTechMan)
return current_value;