forked from 0ad/0ad
Add template helper function. Fix some errors. Refs #1692.
This was SVN commit r13059.
This commit is contained in:
parent
ca41c22b71
commit
fd274a6e70
@ -194,12 +194,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 = ApplyTechModificationsToEntity("Cost/BuildTime", +template.Cost.BuildTime, template);
|
||||
var buildTime = ApplyTechModificationsToTemplate("Cost/BuildTime", +template.Cost.BuildTime, this.entity, template);
|
||||
var time = timeMult * buildTime;
|
||||
|
||||
for (var r in template.Cost.Resources)
|
||||
{
|
||||
costs[r] = ApplyTechModificationsToEntity("Cost/Resources/"+r, +template.Cost.Resources[r], template);
|
||||
costs[r] = ApplyTechModificationsToTemplate("Cost/Resources/"+r, +template.Cost.Resources[r], this.entity, template);
|
||||
totalCosts[r] = Math.floor(count * costs[r]);
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,35 @@
|
||||
// Little helper functions to make applying tehnology more covenient
|
||||
|
||||
function ApplyTechModificationsToEntity(tech_type, current_value, entity) {
|
||||
var cmpTechMan = QueryOwnerInterface(IID_TechnologyManager, entity);
|
||||
function ApplyTechModificationsToEntity(tech_type, current_value, entity)
|
||||
{
|
||||
var cmpTechMan = QueryOwnerInterface(entity, IID_TechnologyManager);
|
||||
|
||||
if (!cmpTechMan)
|
||||
return current_value;
|
||||
if (!cmpTechMan)
|
||||
return current_value;
|
||||
|
||||
return cmpTechMan.ApplyModifications(entity, tech_type, current_value);
|
||||
return cmpTechMan.ApplyModifications(tech_type, current_value, entity);
|
||||
}
|
||||
|
||||
function ApplyTechModificationsToPlayer(tech_type, current_value, player_entity) {
|
||||
var cmpTechMan = Engine.QueryInterface(IID_TechnologyManager, player_entity);
|
||||
function ApplyTechModificationsToPlayer(tech_type, current_value, player_entity)
|
||||
{
|
||||
var cmpTechMan = Engine.QueryInterface(player_entity, IID_TechnologyManager);
|
||||
|
||||
if (!cmpTechMan)
|
||||
return current_value;
|
||||
if (!cmpTechMan)
|
||||
return current_value;
|
||||
|
||||
return cmpTechMan.ApplyModifications(player_entity, tech_type, current_value);
|
||||
return cmpTechMan.ApplyModifications(tech_type, current_value, player_entity);
|
||||
}
|
||||
|
||||
function ApplyTechModificationsToTemplate(tech_type, current_value, owner_entity, template)
|
||||
{
|
||||
var cmpTechMan = QueryOwnerInterface(owner_entity, IID_TechnologyManager);
|
||||
|
||||
if (!cmpTechMan)
|
||||
return current_value;
|
||||
|
||||
return cmpTechMan.ApplyModificationsTemplate(tech_type, current_value, template);
|
||||
}
|
||||
|
||||
Engine.RegisterGlobal("ApplyTechModificationsToEntity", ApplyTechModificationsToEntity);
|
||||
Engine.RegisterGlobal("ApplyTechModificationsToPlayer", ApplyTechModificationsToPlayer);
|
||||
|
||||
Engine.RegisterGlobal("ApplyTechModificationsToTemplate", ApplyTechModificationsToTemplate);
|
||||
|
Loading…
Reference in New Issue
Block a user