Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/ProductionQueue.js
Show All 23 Lines | "<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>" + | ||||
"<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>" + | ||||
"<optional>" + | |||||
"<element name='Autoproduce' a:help='Whether this entity will autoproduce.'>" + | |||||
"<empty/>" + | |||||
"</element>" + | |||||
"</optional>"; | |||||
ProductionQueue.prototype.ProgressInterval = 1000; | ProductionQueue.prototype.ProgressInterval = 1000; | ||||
ProductionQueue.prototype.MaxQueueSize = 16; | ProductionQueue.prototype.MaxQueueSize = 16; | ||||
ProductionQueue.prototype.Init = function() | ProductionQueue.prototype.Init = function() | ||||
{ | { | ||||
this.nextID = 1; | this.nextID = 1; | ||||
Show All 22 Lines | ProductionQueue.prototype.Init = function() | ||||
// "timeRemaining": 10000, // msecs | // "timeRemaining": 10000, // msecs | ||||
// } | // } | ||||
this.timer = undefined; // this.ProgressInterval msec timer, active while the queue is non-empty | this.timer = undefined; // this.ProgressInterval msec timer, active while the queue is non-empty | ||||
this.paused = false; | this.paused = false; | ||||
this.entityCache = []; | this.entityCache = []; | ||||
this.spawnNotified = false; | this.spawnNotified = false; | ||||
this.autoProduce = "Autoproduce" in this.template; | |||||
}; | }; | ||||
/* | /* | ||||
* Returns list of entities that can be trained by this building. | * Returns list of entities that can be trained by this building. | ||||
*/ | */ | ||||
ProductionQueue.prototype.GetEntitiesList = function() | ProductionQueue.prototype.GetEntitiesList = function() | ||||
{ | { | ||||
return this.entitiesList; | return this.entitiesList; | ||||
▲ Show 20 Lines • Show All 473 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
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. | ||||
let cmpPlayer = QueryPlayerIDInterface(msg.from); | let cmpPlayer = QueryPlayerIDInterface(msg.from); | ||||
if (cmpPlayer && this.queue.length) | if (cmpPlayer && this.queue.length) | ||||
cmpPlayer.UnBlockTraining(); | cmpPlayer.UnBlockTraining(); | ||||
} | } | ||||
if (msg.to != INVALID_PLAYER) | if (msg.to == INVALID_PLAYER) | ||||
this.autoProduce = false; | |||||
else | |||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
// 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(); | ||||
this.CheckAutoproduction(); | |||||
}; | }; | ||||
ProductionQueue.prototype.OnCivChanged = function() | ProductionQueue.prototype.OnCivChanged = function() | ||||
{ | { | ||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
}; | }; | ||||
ProductionQueue.prototype.OnDestroy = function() | ProductionQueue.prototype.OnDestroy = function() | ||||
▲ Show 20 Lines • Show All 258 Lines • ▼ Show 20 Lines | ProductionQueue.prototype.ProgressTimeout = function(data) | ||||
// If the queue's empty, delete the timer, else repeat it. | // If the queue's empty, delete the timer, else repeat it. | ||||
if (!this.queue.length) | if (!this.queue.length) | ||||
{ | { | ||||
this.timer = undefined; | this.timer = undefined; | ||||
// Unset flag that training is blocked. | // Unset flag that training is blocked. | ||||
// (This might happen when the player unqueues all batches.) | // (This might happen when the player unqueues all batches.) | ||||
cmpPlayer.UnBlockTraining(); | cmpPlayer.UnBlockTraining(); | ||||
this.CheckAutoproduction(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", this.ProgressInterval, data); | this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", this.ProgressInterval, data); | ||||
} | } | ||||
}; | }; | ||||
ProductionQueue.prototype.PauseProduction = function() | ProductionQueue.prototype.PauseProduction = function() | ||||
{ | { | ||||
this.timer = undefined; | this.timer = undefined; | ||||
this.paused = true; | this.paused = true; | ||||
}; | }; | ||||
ProductionQueue.prototype.UnpauseProduction = function() | ProductionQueue.prototype.UnpauseProduction = function() | ||||
{ | { | ||||
this.paused = false; | this.paused = false; | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", this.ProgressInterval, {}); | this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", this.ProgressInterval, {}); | ||||
}; | }; | ||||
/** | |||||
* Checks for autoproduction. And adds a (single) batch if applicable. | |||||
*/ | |||||
ProductionQueue.prototype.CheckAutoproduction = function() | |||||
{ | |||||
if (this.autoProduce) | |||||
this.AddBatch(pickRandom(this.entitiesList), "unit", 1); | |||||
}; | |||||
ProductionQueue.prototype.OnValueModification = function(msg) | ProductionQueue.prototype.OnValueModification = function(msg) | ||||
{ | { | ||||
// If the promotion requirements of units is changed, | // If the promotion requirements of units is changed, | ||||
// update the entities list so that automatically promoted units are shown | // update the entities list so that automatically promoted units are shown | ||||
// appropriately in the list. | // appropriately in the list. | ||||
if (msg.component == "Promotion") | if (msg.component == "Promotion") | ||||
this.CalculateEntitiesList(); | this.CalculateEntitiesList(); | ||||
}; | }; | ||||
Show All 9 Lines |
Wildfire Games · Phabricator