Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Player.js
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Which units will be shown with special icons at the top. | * Which units will be shown with special icons at the top. | ||||
*/ | */ | ||||
var panelEntityClasses = "Hero Relic"; | var panelEntityClasses = "Hero Relic"; | ||||
Player.prototype.Init = function() | Player.prototype.Init = function() | ||||
{ | { | ||||
this.playerID = undefined; | this.playerID = undefined; | ||||
this.name = undefined; // Define defaults elsewhere (supporting other languages). | |||||
this.civ = undefined; | |||||
this.color = undefined; | this.color = undefined; | ||||
this.diplomacyColor = undefined; | this.diplomacyColor = undefined; | ||||
this.displayDiplomacyColor = false; | this.displayDiplomacyColor = false; | ||||
this.popUsed = 0; // Population of units owned or trained by this player. | this.popUsed = 0; // Population of units owned or trained by this player. | ||||
this.popBonuses = 0; // Sum of population bonuses of player's entities. | this.popBonuses = 0; // Sum of population bonuses of player's entities. | ||||
this.maxPop = 300; // Maximum population. | this.maxPop = 300; // Maximum population. | ||||
this.trainingBlocked = false; // Indicates whether any training queue is currently blocked. | this.trainingBlocked = false; // Indicates whether any training queue is currently blocked. | ||||
this.resourceCount = {}; | this.resourceCount = {}; | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | Player.prototype.SetPlayerID = function(id) | ||||
this.playerID = id; | this.playerID = id; | ||||
}; | }; | ||||
Player.prototype.GetPlayerID = function() | Player.prototype.GetPlayerID = function() | ||||
{ | { | ||||
return this.playerID; | return this.playerID; | ||||
}; | }; | ||||
Player.prototype.SetName = function(name) | |||||
{ | |||||
this.name = name; | |||||
}; | |||||
Player.prototype.GetName = function() | |||||
{ | |||||
return this.name; | |||||
}; | |||||
Player.prototype.SetCiv = function(civcode) | |||||
{ | |||||
let oldCiv = this.civ; | |||||
Lint: prefer-const: 'oldCiv' is never reassigned. Use 'const' instead. | |||||
this.civ = civcode; | |||||
// Normally, the civ is only set once. But in Atlas, map designers can change civs at any time. | |||||
if (oldCiv && this.playerID && oldCiv != civcode) | |||||
Engine.BroadcastMessage(MT_CivChanged, { | |||||
"player": this.playerID, | |||||
"from": oldCiv, | |||||
"to": civcode | |||||
}); | |||||
}; | |||||
Player.prototype.GetCiv = function() | |||||
{ | |||||
return this.civ; | |||||
}; | |||||
Player.prototype.SetColor = function(r, g, b) | Player.prototype.SetColor = function(r, g, b) | ||||
{ | { | ||||
let colorInitialized = !!this.color; | let colorInitialized = !!this.color; | ||||
this.color = { "r": r / 255, "g": g / 255, "b": b / 255, "a": 1 }; | this.color = { "r": r / 255, "g": g / 255, "b": b / 255, "a": 1 }; | ||||
// Used in Atlas. | // Used in Atlas. | ||||
if (colorInitialized) | if (colorInitialized) | ||||
▲ Show 20 Lines • Show All 622 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Do some map dependant initializations | * Do some map dependant initializations | ||||
*/ | */ | ||||
Player.prototype.OnGlobalInitGame = function(msg) | Player.prototype.OnGlobalInitGame = function(msg) | ||||
{ | { | ||||
// Replace the "{civ}" code with this civ ID. | // Replace the "{civ}" code with this civ ID. | ||||
let disabledTemplates = this.disabledTemplates; | let disabledTemplates = this.disabledTemplates; | ||||
this.disabledTemplates = {}; | this.disabledTemplates = {}; | ||||
const civ = Engine.QueryInterface(this.entity, IID_Identity).GetCiv(); | |||||
for (let template in disabledTemplates) | for (let template in disabledTemplates) | ||||
if (disabledTemplates[template]) | if (disabledTemplates[template]) | ||||
this.disabledTemplates[template.replace(/\{civ\}/g, civ)] = true; | this.disabledTemplates[template.replace(/\{civ\}/g, this.civ)] = true; | ||||
}; | }; | ||||
/** | /** | ||||
* Keep track of population effects of all entities that | * Keep track of population effects of all entities that | ||||
* become owned or unowned by this player. | * become owned or unowned by this player. | ||||
*/ | */ | ||||
Player.prototype.OnGlobalOwnershipChanged = function(msg) | Player.prototype.OnGlobalOwnershipChanged = function(msg) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 183 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
'oldCiv' is never reassigned. Use 'const' instead.