Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Player.js
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | Player.prototype.Init = function() | |||||||||||||
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 = {}; | |||||||||||||
this.resourceGatherers = {}; | ||||||||||||||
Freagarach: Per [[ https://trac.wildfiregames.com/wiki/Coding_Conventions | CC ]]. | ||||||||||||||
Done Inline ActionsMoreover, I think you could just store the gatherers per resource. The total gatherers can be computed when needed. Freagarach: Moreover, I think you could just store the gatherers per resource. The total gatherers can be… | ||||||||||||||
this.tradingGoods = []; // Goods for next trade-route and its probabilities * 100. | this.tradingGoods = []; // Goods for next trade-route and its probabilities * 100. | |||||||||||||
this.team = -1; // Team number of the player, players on the same team will always have ally diplomatic status. Also this is useful for team emblems, scoring, etc. | this.team = -1; // Team number of the player, players on the same team will always have ally diplomatic status. Also this is useful for team emblems, scoring, etc. | |||||||||||||
this.teamsLocked = false; | this.teamsLocked = false; | |||||||||||||
this.state = "active"; // Game state. One of "active", "defeated", "won". | this.state = "active"; // Game state. One of "active", "defeated", "won". | |||||||||||||
this.diplomacy = []; // Array of diplomatic stances for this player with respect to other players (including gaia and self). | this.diplomacy = []; // Array of diplomatic stances for this player with respect to other players (including gaia and self). | |||||||||||||
this.sharedDropsites = false; | this.sharedDropsites = false; | |||||||||||||
this.formations = []; | this.formations = []; | |||||||||||||
this.startCam = undefined; | this.startCam = undefined; | |||||||||||||
Show All 13 Lines | Player.prototype.Init = function() | |||||||||||||
}; | }; | |||||||||||||
// Initial resources. | // Initial resources. | |||||||||||||
let resCodes = Resources.GetCodes(); | let resCodes = Resources.GetCodes(); | |||||||||||||
for (let res of resCodes) | for (let res of resCodes) | |||||||||||||
{ | { | |||||||||||||
this.resourceCount[res] = 300; | this.resourceCount[res] = 300; | |||||||||||||
this.resourceNames[res] = Resources.GetResource(res).name; | this.resourceNames[res] = Resources.GetResource(res).name; | |||||||||||||
this.resourceGatherers[res] = 0; | ||||||||||||||
Done Inline ActionsUseless comment wraitii: Useless comment | ||||||||||||||
} | } | |||||||||||||
// Trading goods probability in steps of 5. | // Trading goods probability in steps of 5. | |||||||||||||
let resTradeCodes = Resources.GetTradableCodes(); | let resTradeCodes = Resources.GetTradableCodes(); | |||||||||||||
let quotient = Math.floor(20 / resTradeCodes.length); | let quotient = Math.floor(20 / resTradeCodes.length); | |||||||||||||
let remainder = 20 % resTradeCodes.length; | let remainder = 20 % resTradeCodes.length; | |||||||||||||
for (let i in resTradeCodes) | for (let i in resTradeCodes) | |||||||||||||
this.tradingGoods.push({ | this.tradingGoods.push({ | |||||||||||||
"goods": resTradeCodes[i], | "goods": resTradeCodes[i], | |||||||||||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | for (let res in resources) | |||||||||||||
this.resourceCount[res] = resources[res]; | this.resourceCount[res] = resources[res]; | |||||||||||||
}; | }; | |||||||||||||
Player.prototype.GetResourceCounts = function() | Player.prototype.GetResourceCounts = function() | |||||||||||||
{ | { | |||||||||||||
return this.resourceCount; | return this.resourceCount; | |||||||||||||
}; | }; | |||||||||||||
Player.prototype.GetResourceGatherers = function() | ||||||||||||||
{ | ||||||||||||||
return this.resourceGatherers; | ||||||||||||||
Done Inline Actionsplease var -> let Silier: please var -> let | ||||||||||||||
}; | ||||||||||||||
/** | ||||||||||||||
Done Inline Actions
(So we can generate docs automatically.) Freagarach: (So we can generate docs automatically.)
I personally prefer @params and @return except for… | ||||||||||||||
* @param {string} type - The type of resource to add the gaterer for. | ||||||||||||||
Done Inline ActionsThis line can be ditched. (The more clear function names are, the less documentation is necessary. And then those comments can't be wrong :) ) Freagarach: This line can be ditched. (The more clear function names are, the less documentation is… | ||||||||||||||
*/ | ||||||||||||||
Player.prototype.AddResourceGatherer = function(type) | ||||||||||||||
{ | ||||||||||||||
this.resourceGatherers[type]++; | ||||||||||||||
StanUnsubmitted Done Inline Actions
Stan: | ||||||||||||||
}; | ||||||||||||||
Done Inline ActionsI'd prefer AddResourceProducer above this. (Then the function name is no necessarily a complete representation of what is done, but is what is supposed to be done. (I hope this makes sense ^^ )) Freagarach: I'd prefer `AddResourceProducer` above this. (Then the function name is no necessarily a… | ||||||||||||||
/** | ||||||||||||||
* @param {string} type - The type of resource to remove the gaterer from. | ||||||||||||||
*/ | ||||||||||||||
Player.prototype.RemoveResourceGatherer = function(type) | ||||||||||||||
{ | ||||||||||||||
this.resourceGatherers[type]--; | ||||||||||||||
StanUnsubmitted Done Inline Actions
Stan: | ||||||||||||||
}; | ||||||||||||||
/** | /** | |||||||||||||
* Add resource of specified type to player. | * Add resource of specified type to player. | |||||||||||||
* @param {string} type - Generic type of resource. | * @param {string} type - Generic type of resource. | |||||||||||||
* @param {number} amount - Amount of resource, which should be added. | * @param {number} amount - Amount of resource, which should be added. | |||||||||||||
*/ | */ | |||||||||||||
Player.prototype.AddResource = function(type, amount) | Player.prototype.AddResource = function(type, amount) | |||||||||||||
{ | { | |||||||||||||
this.resourceCount[type] += +amount; | this.resourceCount[type] += +amount; | |||||||||||||
}; | }; | |||||||||||||
/** | /** | |||||||||||||
* Add resources to player. | * Add resources to player. | |||||||||||||
*/ | */ | |||||||||||||
Player.prototype.AddResources = function(amounts) | Player.prototype.AddResources = function(amounts) | |||||||||||||
{ | { | |||||||||||||
for (let type in amounts) | for (let type in amounts) | |||||||||||||
this.resourceCount[type] += +amounts[type]; | this.resourceCount[type] += +amounts[type]; | |||||||||||||
}; | }; | |||||||||||||
Player.prototype.GetNeededResources = function(amounts) | Player.prototype.GetNeededResources = function(amounts) | |||||||||||||
{ | { | |||||||||||||
// Check if we can afford it all. | // Check if we can afford it all. | |||||||||||||
let amountsNeeded = {}; | let amountsNeeded = {}; | |||||||||||||
Done Inline Actions
could you please rewrite this as early return (and remove braces of cource) Silier: could you please rewrite this as early return (and remove braces of cource) | ||||||||||||||
for (let type in amounts) | for (let type in amounts) | |||||||||||||
if (this.resourceCount[type] != undefined && amounts[type] > this.resourceCount[type]) | if (this.resourceCount[type] != undefined && amounts[type] > this.resourceCount[type]) | |||||||||||||
amountsNeeded[type] = amounts[type] - Math.floor(this.resourceCount[type]); | amountsNeeded[type] = amounts[type] - Math.floor(this.resourceCount[type]); | |||||||||||||
if (Object.keys(amountsNeeded).length == 0) | if (Object.keys(amountsNeeded).length == 0) | |||||||||||||
return undefined; | return undefined; | |||||||||||||
return amountsNeeded; | return amountsNeeded; | |||||||||||||
}; | }; | |||||||||||||
▲ Show 20 Lines • Show All 652 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Per CC.