Index: binaries/data/mods/public/simulation/components/Player.js
===================================================================
--- binaries/data/mods/public/simulation/components/Player.js
+++ binaries/data/mods/public/simulation/components/Player.js
@@ -1,25 +1,33 @@
function Player() {}
Player.prototype.Schema =
- "" +
- "" +
- "" +
- Resources.BuildSchema("positiveDecimal") +
- "" +
- "" +
- Resources.BuildSchema("positiveDecimal") +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "";
+ "" +
+ "" +
+ "" +
+ "" +
+ Resources.BuildSchema("positiveDecimal") +
+ "" +
+ "" +
+ Resources.BuildSchema("positiveDecimal") +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "";
/**
* Which units will be shown with special icons at the top.
@@ -43,6 +51,7 @@
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.sharedDropsites = false;
+ this.sharedLos = false;
this.formations = [];
this.startCam = undefined;
this.controlAllUnits = false;
@@ -56,16 +65,14 @@
this.disabledTemplates = {};
this.disabledTechnologies = {};
this.startingTechnologies = [];
- this.spyCostMultiplier = +this.template.SpyCostMultiplier;
- this.barterMultiplier = {
- "buy": clone(this.template.BarterMultiplier.Buy),
- "sell": clone(this.template.BarterMultiplier.Sell)
- };
+ this.spyCostMultiplier = +(this.template && this.template.SpyCostMultiplier || 1);
+ this.barterMultiplier = { "buy": {}, "sell": {} };
// Initial resources and trading goods probability in steps of 5
let resCodes = Resources.GetCodes();
let quotient = Math.floor(20 / resCodes.length);
let remainder = 20 % resCodes.length;
+ let hasBarterMultiplier = this.template && this.template.BarterMultiplier;
for (let i in resCodes)
{
let res = resCodes[i];
@@ -75,6 +82,8 @@
"goods": res,
"proba": 5 * (quotient + (+i < remainder ? 1 : 0))
});
+ this.barterMultiplier.buy[res] = +(hasBarterMultiplier && this.template.BarterMultiplier.Buy[res] || 1.0);
+ this.barterMultiplier.sell[res] = +(hasBarterMultiplier && this.template.BarterMultiplier.Sell[res] || 1.0);
}
};
@@ -131,7 +140,7 @@
// Try reserving num population slots. Returns 0 on success or number of missing slots otherwise.
Player.prototype.TryReservePopulationSlots = function(num)
{
- if (num != 0 && num > (this.GetPopulationLimit() - this.GetPopulationCount()))
+ if (num !== 0 && num > (this.GetPopulationLimit() - this.GetPopulationCount()))
return num - (this.GetPopulationLimit() - this.GetPopulationCount());
this.popUsed += num;
@@ -263,10 +272,10 @@
// Check if we can afford it all
var amountsNeeded = {};
for (var 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]);
- if (Object.keys(amountsNeeded).length == 0)
+ if (Object.keys(amountsNeeded).length === 0)
return undefined;
return amountsNeeded;
};
@@ -278,9 +287,9 @@
// If we don't have enough resources, send a notification to the player
if (amountsNeeded)
{
- var parameters = {};
- var i = 0;
- for (var type in amountsNeeded)
+ let parameters = {};
+ let i = 0;
+ for (let type in amountsNeeded)
{
++i;
parameters["resourceType"+i] = this.resourceNames[type];
@@ -320,7 +329,7 @@
return false;
}
- for (var type in amounts)
+ for (let type in amounts)
this.resourceCount[type] -= amounts[type];
return true;
@@ -535,12 +544,13 @@
if (!cmpRangeManager || !cmpTechnologyManager)
return;
- if (!cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech))
+ if (!this.template || !this.template.SharedLosTech || !cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech))
{
cmpRangeManager.SetSharedLos(this.playerID, [this.playerID]);
return;
}
+ this.sharedLos = true;
cmpRangeManager.SetSharedLos(this.playerID, this.GetMutualAllies());
};
@@ -576,9 +586,9 @@
Player.prototype.HasSharedLos = function()
{
- let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager);
- return cmpTechnologyManager && cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech);
+ return this.sharedLos;
};
+
Player.prototype.HasSharedDropsites = function()
{
return this.sharedDropsites;
@@ -689,7 +699,7 @@
*/
Player.prototype.IsNeutral = function(id)
{
- return this.diplomacy[id] == 0;
+ return this.diplomacy[id] === 0;
};
/**
@@ -746,9 +756,12 @@
Player.prototype.OnResearchFinished = function(msg)
{
- if (msg.tech == this.template.SharedLosTech)
+ if (!this.template)
+ return;
+
+ if (this.template.SharedLosTech && msg.tech == this.template.SharedLosTech)
this.UpdateSharedLos();
- else if (msg.tech == this.template.SharedDropsitesTech)
+ else if (this.template.SharedDropsitesTech && msg.tech == this.template.SharedDropsitesTech)
this.sharedDropsites = true;
};
Index: binaries/data/mods/public/simulation/components/tests/test_Player.js
===================================================================
--- binaries/data/mods/public/simulation/components/tests/test_Player.js
+++ binaries/data/mods/public/simulation/components/tests/test_Player.js
@@ -1,5 +1,5 @@
Resources = {
- "GetCodes": () => ["food", "metal", "stone", "wood"],
+ "GetCodes": () => ["food", "wood", "stone", "metal"],
"GetResource": () => ({}),
"BuildSchema": (type) => {
let schema = "";
@@ -65,11 +65,13 @@
TS_ASSERT_EQUALS(cmpPlayer.GetSpyCostMultiplier(), 1);
TS_ASSERT_UNEVAL_EQUALS(cmpPlayer.GetBarterMultiplier(), {
"buy": {
+ "food": 1.0,
"wood": 1.0,
"stone": 1.0,
"metal": 1.0
},
"sell": {
+ "food": 1.0,
"wood": 1.0,
"stone": 1.0,
"metal": 1.0
Index: binaries/data/mods/public/simulation/templates/special/player_gaia.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/special/player_gaia.xml
+++ binaries/data/mods/public/simulation/templates/special/player_gaia.xml
@@ -1,22 +1,4 @@
-
-
-
- 1.0
-
-
- 1.0
- 1.0
- 1.0
- 1.0
-
-
- 1.0
- 1.0
- 1.0
- 1.0
-
-
-
+