Differential D3792 Diff 17189 ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js
function Foundation() {} | function Foundation() {} | ||||
Foundation.prototype.Schema = | Foundation.prototype.Schema = | ||||
"<empty/>"; | "<element name='BuildTimeModifier' a:help='Effect for having multiple builders.'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | |||||
"</element>"; | |||||
Foundation.prototype.Init = function() | Foundation.prototype.Init = function() | ||||
{ | { | ||||
// Foundations are initially 'uncommitted' and do not block unit movement at all | // Foundations are initially 'uncommitted' and do not block unit movement at all | ||||
// (to prevent players exploiting free foundations to confuse enemy units). | // (to prevent players exploiting free foundations to confuse enemy units). | ||||
// The first builder to reach the uncommitted foundation will tell friendly units | // The first builder to reach the uncommitted foundation will tell friendly units | ||||
// and animals to move out of the way, then will commit the foundation and enable | // and animals to move out of the way, then will commit the foundation and enable | ||||
// its obstruction once there's nothing in the way. | // its obstruction once there's nothing in the way. | ||||
this.committed = false; | this.committed = false; | ||||
this.builders = new Map(); // Map of builder entities to their work per second | this.builders = new Map(); // Map of builder entities to their work per second | ||||
this.totalBuilderRate = 0; // Total amount of work the builders do each second | this.totalBuilderRate = 0; // Total amount of work the builders do each second | ||||
this.buildMultiplier = 1; // Multiplier for the amount of work builders do | this.buildMultiplier = 1; // Multiplier for the amount of work builders do | ||||
this.buildTimePenalty = 0.7; // Penalty for having multiple builders | |||||
this.buildTimeModifier = +this.template.BuildTimeModifier; | |||||
this.previewEntity = INVALID_ENTITY; | this.previewEntity = INVALID_ENTITY; | ||||
}; | }; | ||||
Foundation.prototype.Serialize = function() | Foundation.prototype.Serialize = function() | ||||
{ | { | ||||
let ret = Object.assign({}, this); | let ret = Object.assign({}, this); | ||||
ret.previewEntity = INVALID_ENTITY; | ret.previewEntity = INVALID_ENTITY; | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* The build multiplier is a penalty that is applied to each builder. | * The build multiplier is a penalty that is applied to each builder. | ||||
* For example, ten women build at a combined rate of 10^0.7 = 5.01 instead of 10. | * For example, ten women build at a combined rate of 10^0.7 = 5.01 instead of 10. | ||||
*/ | */ | ||||
Foundation.prototype.CalculateBuildMultiplier = function(num) | Foundation.prototype.CalculateBuildMultiplier = function(num) | ||||
{ | { | ||||
// Avoid division by zero, in particular 0/0 = NaN which isn't reliably serialized | // Avoid division by zero, in particular 0/0 = NaN which isn't reliably serialized | ||||
return num < 2 ? 1 : Math.pow(num, this.buildTimePenalty) / num; | return num < 2 ? 1 : Math.pow(num, this.buildTimeModifier) / num; | ||||
}; | }; | ||||
Foundation.prototype.SetBuildMultiplier = function() | Foundation.prototype.SetBuildMultiplier = function() | ||||
{ | { | ||||
this.buildMultiplier = this.CalculateBuildMultiplier(this.GetNumBuilders()); | this.buildMultiplier = this.CalculateBuildMultiplier(this.GetNumBuilders()); | ||||
}; | }; | ||||
Foundation.prototype.GetBuildTime = function() | Foundation.prototype.GetBuildTime = function() | ||||
▲ Show 20 Lines • Show All 207 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator