Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Player.js
function Player() {} | function Player() {} | ||||
Player.prototype.Schema = | Player.prototype.Schema = | ||||
"<optional>" + | |||||
"<element name='BarterMultiplier' a:help='Multipliers for barter prices.'>" + | "<element name='BarterMultiplier' a:help='Multipliers for barter prices.'>" + | ||||
"<interleave>" + | "<interleave>" + | ||||
"<element name='Buy' a:help='Multipliers for the buy prices.'>" + | "<element name='Buy' a:help='Multipliers for the buy prices.'>" + | ||||
Resources.BuildSchema("positiveDecimal") + | Resources.BuildSchema("positiveDecimal") + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Sell' a:help='Multipliers for the sell prices.'>" + | "<element name='Sell' a:help='Multipliers for the sell prices.'>" + | ||||
Resources.BuildSchema("positiveDecimal") + | Resources.BuildSchema("positiveDecimal") + | ||||
"</element>" + | "</element>" + | ||||
"</interleave>" + | "</interleave>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='SharedLosTech' a:help='Allies will share los when this technology is researched. Leave empty to never share LOS.'>" + | "<element name='SharedLosTech' a:help='Allies will share los when this technology is researched. Leave empty to never share LOS.'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='SharedDropsitesTech' a:help='Allies will share dropsites when this technology is researched. Leave empty to never share dropsites.'>" + | "<element name='SharedDropsitesTech' a:help='Allies will share dropsites when this technology is researched. Leave empty to never share dropsites.'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='SpyCostMultiplier'>" + | "<element name='SpyCostMultiplier'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||
"</element>"; | "</element>" + | ||||
"</optional>"; | |||||
/** | /** | ||||
* 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() | ||||
{ | { | ||||
Show All 20 Lines | Player.prototype.Init = function() | ||||
this.tradeRateMultiplier = 1; | this.tradeRateMultiplier = 1; | ||||
this.cheatsEnabled = false; | this.cheatsEnabled = false; | ||||
this.cheatTimeMultiplier = 1; | this.cheatTimeMultiplier = 1; | ||||
this.panelEntities = []; | this.panelEntities = []; | ||||
this.resourceNames = {}; | this.resourceNames = {}; | ||||
this.disabledTemplates = {}; | this.disabledTemplates = {}; | ||||
this.disabledTechnologies = {}; | this.disabledTechnologies = {}; | ||||
this.startingTechnologies = []; | this.startingTechnologies = []; | ||||
this.spyCostMultiplier = +this.template.SpyCostMultiplier; | this.spyCostMultiplier = this.template && this.template.SpyCostMultiplier ? +(this.template.SpyCostMultiplier) : undefined; | ||||
mimo: wouldn't it be better to init to 1 instead of undefined so that all components will still work… | |||||
this.barterMultiplier = { | this.barterMultiplier = this.template && this.template.BarterMultiplier ? { | ||||
"buy": clone(this.template.BarterMultiplier.Buy), | "buy": clone(this.template.BarterMultiplier.Buy), | ||||
"sell": clone(this.template.BarterMultiplier.Sell) | "sell": clone(this.template.BarterMultiplier.Sell) | ||||
}; | } : undefined; | ||||
mimoUnsubmitted Done Inline Actionssame thing here, instead of undefined, having a loop on resCodes and putting all to 1 would avoid the changes you did in Barter code mimo: same thing here, instead of undefined, having a loop on resCodes and putting all to 1 would… | |||||
// Initial resources and trading goods probability in steps of 5 | // Initial resources and trading goods probability in steps of 5 | ||||
let resCodes = Resources.GetCodes(); | let resCodes = Resources.GetCodes(); | ||||
let quotient = Math.floor(20 / resCodes.length); | let quotient = Math.floor(20 / resCodes.length); | ||||
let remainder = 20 % resCodes.length; | let remainder = 20 % resCodes.length; | ||||
for (let i in resCodes) | for (let i in resCodes) | ||||
{ | { | ||||
let res = resCodes[i]; | let res = resCodes[i]; | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | |||||
Player.prototype.UpdateSharedLos = function() | Player.prototype.UpdateSharedLos = function() | ||||
{ | { | ||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager); | let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager); | ||||
if (!cmpRangeManager || !cmpTechnologyManager) | if (!cmpRangeManager || !cmpTechnologyManager) | ||||
return; | return; | ||||
if (!cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech)) | if (this.template && this.template.SharedLosTech && !cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech)) | ||||
{ | { | ||||
cmpRangeManager.SetSharedLos(this.playerID, [this.playerID]); | cmpRangeManager.SetSharedLos(this.playerID, [this.playerID]); | ||||
return; | return; | ||||
} | } | ||||
cmpRangeManager.SetSharedLos(this.playerID, this.GetMutualAllies()); | cmpRangeManager.SetSharedLos(this.playerID, this.GetMutualAllies()); | ||||
}; | }; | ||||
Show All 22 Lines | Player.prototype.SetStartingCamera = function(pos, rot) | ||||
this.startCam = { "position": pos, "rotation": rot }; | this.startCam = { "position": pos, "rotation": rot }; | ||||
}; | }; | ||||
Player.prototype.HasStartingCamera = function() | Player.prototype.HasStartingCamera = function() | ||||
{ | { | ||||
return this.startCam !== undefined; | return this.startCam !== undefined; | ||||
}; | }; | ||||
Player.prototype.HasSharedLos = function() | Player.prototype.HasSharedLos = function() | ||||
mimoUnsubmitted Done Inline ActionsI wonder if it would not be worth to cache it (as is done for this.sharedDropsites) mimo: I wonder if it would not be worth to cache it (as is done for this.sharedDropsites) | |||||
{ | { | ||||
if (!this.template || !this.template.SharedLosTech) | |||||
return false; | |||||
let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager); | let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager); | ||||
return cmpTechnologyManager && cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech); | return cmpTechnologyManager && cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech); | ||||
}; | }; | ||||
Player.prototype.HasSharedDropsites = function() | Player.prototype.HasSharedDropsites = function() | ||||
{ | { | ||||
return this.sharedDropsites; | return this.sharedDropsites; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | if (msg.to == this.playerID) | ||||
if (cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), panelEntityClasses)) | if (cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), panelEntityClasses)) | ||||
this.panelEntities.push(msg.entity); | this.panelEntities.push(msg.entity); | ||||
} | } | ||||
}; | }; | ||||
Player.prototype.OnResearchFinished = function(msg) | Player.prototype.OnResearchFinished = function(msg) | ||||
{ | { | ||||
if (!this.template) | |||||
return; | |||||
if (msg.tech == this.template.SharedLosTech) | if (msg.tech == this.template.SharedLosTech) | ||||
mimoUnsubmitted Done Inline Actionsif (this.template.SharedLosTech && msg.tech == this.template.SharedLosTech) ? mimo: if (this.template.SharedLosTech && msg.tech == this.template.SharedLosTech) ? | |||||
this.UpdateSharedLos(); | this.UpdateSharedLos(); | ||||
else if (msg.tech == this.template.SharedDropsitesTech) | else if (msg.tech == this.template.SharedDropsitesTech) | ||||
mimoUnsubmitted Done Inline Actionssame comment mimo: same comment | |||||
this.sharedDropsites = true; | this.sharedDropsites = true; | ||||
}; | }; | ||||
Player.prototype.OnDiplomacyChanged = function() | Player.prototype.OnDiplomacyChanged = function() | ||||
{ | { | ||||
this.UpdateSharedLos(); | this.UpdateSharedLos(); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
wouldn't it be better to init to 1 instead of undefined so that all components will still work as now (if we ever need to bribe a gaia unit)
+this.template.SpyCostMultiplier does not need the parenthesis