Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/ProductionQueue.js
Show All 24 Lines | ProductionQueue.prototype.Schema = | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='Technologies' a:help='Space-separated list of technology names that this building can research. When present, the special string \"{civ}\" will be automatically replaced either by the civ code of the building's owner if such a tech exists, or by \"generic\".'>" + | "<element name='Technologies' a:help='Space-separated list of technology names that this building can research. When present, the special string \"{civ}\" will be automatically replaced either by the civ code of the building's owner if such a tech exists, or by \"generic\".'>" + | ||||
"<attribute name='datatype'>" + | "<attribute name='datatype'>" + | ||||
"<value>tokens</value>" + | "<value>tokens</value>" + | ||||
"</attribute>" + | "</attribute>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<optional>" + | |||||
"<element name='Groups' a:help='Space-separated list of group template names that this entity can train. The special string \"{civ}\" will be automatically replaced by the civ code of the entity's owner, while the string \"{native}\" will be automatically replaced by the entity's civ code.'>" + | |||||
"<attribute name='datatype'>" + | |||||
"<value>tokens</value>" + | |||||
"</attribute>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='Composition' a:help='The data of which a group should exist. Or something...'>" + | |||||
"<interleave>" + | |||||
"<element name='Name'>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"<element name='Tooltip'>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"<element name='MutuallyExclusive' a:help='When true only one of the entries below will be produced, using the chances provided.'>" + | |||||
"<data type='boolean'/>" + | |||||
"</element>" + | |||||
"<element name='Icon'>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"<element name='Entries'>" + | |||||
"<oneOrMore>" + | |||||
"<element>" + | |||||
"<anyName/>" + | |||||
"<interleave>" + | |||||
"<element name='Template' a:help='The template that ought to be produced.'><text/></element>" + | |||||
"<optional>" + | |||||
"<element name='Amount' a:help='The amount of this template that ought to be produced. Defaults to 1.'><data type='positiveInteger'/></element>" + | |||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='Chance' a:help='The chance that this template is produced when MutuallyExclusive is set to true. The chance is the part of this value of the summed chances. Defaults to 1.'><data type='positiveInteger'/></element>" + | |||||
"</optional>" + | |||||
"</interleave>" + | |||||
"</element>" + | |||||
"</oneOrMore>" + | |||||
"</element>" + | |||||
"</interleave>" + | |||||
"</element>" + | |||||
"</optional>" + | |||||
"<element name='TechCostMultiplier' a:help='Multiplier to modify ressources cost and research time of technologies searched in this building.'>" + | "<element name='TechCostMultiplier' a:help='Multiplier to modify ressources cost and research time of technologies searched in this building.'>" + | ||||
Resources.BuildSchema("nonNegativeDecimal", ["time"]) + | Resources.BuildSchema("nonNegativeDecimal", ["time"]) + | ||||
"</element>"; | "</element>"; | ||||
ProductionQueue.prototype.Init = function() | ProductionQueue.prototype.Init = function() | ||||
{ | { | ||||
this.nextID = 1; | this.nextID = 1; | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | for (let templateName of entitiesList) | ||||
this.entitiesList.push(upgradeTemplate(templateName)); | this.entitiesList.push(upgradeTemplate(templateName)); | ||||
for (let item of this.queue) | for (let item of this.queue) | ||||
if (item.unitTemplate) | if (item.unitTemplate) | ||||
item.unitTemplate = upgradeTemplate(item.unitTemplate); | item.unitTemplate = upgradeTemplate(item.unitTemplate); | ||||
}; | }; | ||||
/* | /* | ||||
* Returns list of groups that can be trained by this building. | |||||
* @return {string[]} - As the title says. | |||||
*/ | |||||
ProductionQueue.prototype.GetGroupsList = function() | |||||
{ | |||||
return this.groupsList; | |||||
}; | |||||
/* | |||||
* Calculate the list of groups that can be trained by this entity. | |||||
*/ | |||||
ProductionQueue.prototype.CalculateGroupsList = function() | |||||
{ | |||||
this.groupsList = []; | |||||
if (!this.template.Groups) | |||||
return; | |||||
let string = this.template.Groups._string; | |||||
if (!string) | |||||
return; | |||||
// Replace the "{civ}" and "{native}" codes with the owner's civ ID and training entity's civ ID. | |||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | |||||
let cmpPlayer = QueryOwnerInterface(this.entity); | |||||
if (!cmpPlayer) | |||||
return; | |||||
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | |||||
if (cmpIdentity) | |||||
string = string.replace(/\{native\}/g, cmpIdentity.GetCiv()); | |||||
let groupsList = string.replace(/\{civ\}/g, cmpPlayer.GetCiv()).split(/\s+/); | |||||
// Filter out disabled and invalid entities. | |||||
let disabledEntities = cmpPlayer.GetDisabledTemplates(); | |||||
groupsList = groupsList.filter(group => !disabledEntities[group] );//&& cmpTemplateManager.TemplateExists(group)); | |||||
for (let groupName of groupsList) | |||||
this.groupsList.push(groupName); | |||||
}; | |||||
/* | |||||
* Returns list of technologies that can be researched by this building. | * Returns list of technologies that can be researched by this building. | ||||
*/ | */ | ||||
ProductionQueue.prototype.GetTechnologiesList = function() | ProductionQueue.prototype.GetTechnologiesList = function() | ||||
{ | { | ||||
if (!this.template.Technologies) | if (!this.template.Technologies) | ||||
return []; | return []; | ||||
var string = this.template.Technologies._string; | var string = this.template.Technologies._string; | ||||
▲ Show 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | ProductionQueue.prototype.OnOwnershipChanged = function(msg) | ||||
if (msg.from != INVALID_PLAYER) | if (msg.from != INVALID_PLAYER) | ||||
{ | { | ||||
// Unset flag that previous owner's training may be blocked | // Unset flag that previous owner's training may be blocked | ||||
var cmpPlayer = QueryPlayerIDInterface(msg.from); | var cmpPlayer = QueryPlayerIDInterface(msg.from); | ||||
if (cmpPlayer && this.queue.length > 0) | if (cmpPlayer && this.queue.length > 0) | ||||
cmpPlayer.UnBlockTraining(); | cmpPlayer.UnBlockTraining(); | ||||
} | } | ||||
if (msg.to != INVALID_PLAYER) | if (msg.to != INVALID_PLAYER) | ||||
{ | |||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
this.CalculateGroupsList(); | |||||
} | |||||
// Reset the production queue whenever the owner changes. | // Reset the production queue whenever the owner changes. | ||||
// (This should prevent players getting surprised when they capture | // (This should prevent players getting surprised when they capture | ||||
// an enemy building, and then loads of the enemy's civ's soldiers get | // an enemy building, and then loads of the enemy's civ's soldiers get | ||||
// created from it. Also it means we don't have to worry about | // created from it. Also it means we don't have to worry about | ||||
// updating the reserved pop slots.) | // updating the reserved pop slots.) | ||||
this.ResetQueue(); | this.ResetQueue(); | ||||
}; | }; | ||||
ProductionQueue.prototype.OnCivChanged = function() | ProductionQueue.prototype.OnCivChanged = function() | ||||
{ | { | ||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
this.CalculateGroupsList(); | |||||
}; | }; | ||||
ProductionQueue.prototype.OnDestroy = function() | ProductionQueue.prototype.OnDestroy = function() | ||||
{ | { | ||||
// Reset the queue to refund any resources | // Reset the queue to refund any resources | ||||
this.ResetQueue(); | this.ResetQueue(); | ||||
if (this.timer) | if (this.timer) | ||||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | if (msg.component == "Promotion") | ||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
}; | }; | ||||
ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg) | ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg) | ||||
{ | { | ||||
// if the disabled templates of the player is changed, | // if the disabled templates of the player is changed, | ||||
// update the entities list so that this is reflected there | // update the entities list so that this is reflected there | ||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
this.CalculateGroupsList(); | |||||
}; | }; | ||||
Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue); | Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue); |
Wildfire Games · Phabricator