Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Trader.js
// See helpers/TraderGain.js for the CalculateTaderGain() function which works out how many | // See helpers/TraderGain.js for the CalculateTaderGain() function which works out how many | ||||
// resources a trader gets | // resources a trader gets | ||||
// Additional gain for ships for each garrisoned trader, in percents | |||||
const GARRISONED_TRADER_ADDITION = 20; | |||||
function Trader() {} | function Trader() {} | ||||
Trader.prototype.Schema = | Trader.prototype.Schema = | ||||
"<a:help>Lets the unit generate resouces while moving between markets (or docks in case of water trading).</a:help>" + | "<a:help>Lets the unit generate resouces while moving between markets (or docks in case of water trading).</a:help>" + | ||||
"<a:example>" + | "<a:example>" + | ||||
"<GainMultiplier>0.75</GainMultiplier>" + | "<GainMultiplier>0.75</GainMultiplier>" + | ||||
"</a:example>" + | "</a:example>" + | ||||
"<element name='GainMultiplier' a:help='Trader gain for a 100m distance and mapSize = 1024'>" + | "<element name='GainMultiplier' a:help='Trader gain for a 100m distance and mapSize = 1024'>" + | ||||
"<ref name='positiveDecimal'/>" + | "<ref name='positiveDecimal'/>" + | ||||
"</element>"; | "</element>" + | ||||
"<optional>" + | |||||
"<element name='GainMultiplierPerGarrisonedTrader' a:help='Additional gain for garrisonable unit for each garrisoned trader (1.0 means 100%)'"> + | |||||
Freagarach: You should move the last `"`. | |||||
"<ref name='positiveDecimal'/>" + | |||||
"</element>" + | |||||
"</optional>"; | |||||
Not Done Inline Actionsmissing feature description elexis: missing feature description | |||||
Trader.prototype.Init = function() | Trader.prototype.Init = function() | ||||
{ | { | ||||
this.markets = []; | this.markets = []; | ||||
this.index = -1; | this.index = -1; | ||||
this.goods = { | this.goods = { | ||||
"type": null, | "type": null, | ||||
"amount": null, | "amount": null, | ||||
"origin": null | "origin": null | ||||
}; | }; | ||||
}; | }; | ||||
Trader.prototype.CalculateGain = function(currentMarket, nextMarket) | Trader.prototype.CalculateGain = function(currentMarket, nextMarket) | ||||
{ | { | ||||
let gain = CalculateTraderGain(currentMarket, nextMarket, this.template, this.entity); | let gain = CalculateTraderGain(currentMarket, nextMarket, this.template, this.entity); | ||||
if (!gain) // One of our markets must have been destroyed | if (!gain) // One of our markets must have been destroyed | ||||
return null; | return null; | ||||
// For ship increase gain for each garrisoned trader | // For garrisonable unit increase gain for each garrisoned trader | ||||
// Calculate this here to save passing unnecessary stuff into the CalculateTraderGain function | // Calculate this here to save passing unnecessary stuff into the CalculateTraderGain function | ||||
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | if (this.template.GainMultiplierPerGarrisonedTrader === undefined) | ||||
if (cmpIdentity && cmpIdentity.HasClass("Ship")) | return gain; | ||||
{ | |||||
let cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); | ||||
if (cmpGarrisonHolder) | if (!cmpGarrisonHolder) | ||||
{ | return gain; | ||||
let garrisonMultiplier = 1; | let garrisonMultiplier = 1; | ||||
let garrisonedTradersCount = 0; | let garrisonedTradersCount = 0; | ||||
for (let entity of cmpGarrisonHolder.GetEntities()) | for (let entity of cmpGarrisonHolder.GetEntities()) | ||||
{ | { | ||||
let cmpGarrisonedUnitTrader = Engine.QueryInterface(entity, IID_Trader); | let cmpGarrisonedUnitTrader = Engine.QueryInterface(entity, IID_Trader); | ||||
if (cmpGarrisonedUnitTrader) | if (cmpGarrisonedUnitTrader) | ||||
++garrisonedTradersCount; | ++garrisonedTradersCount; | ||||
} | } | ||||
garrisonMultiplier *= 1 + GARRISONED_TRADER_ADDITION * garrisonedTradersCount / 100; | garrisonMultiplier *= 1 + (+this.template.GainMultiplierPerGarrisonedTrader) * garrisonedTradersCount; | ||||
Not Done Inline ActionsOne can write garrisonedTradersCount * +this.template.GainMultiplierPerGarrisonedTrader to avoid the extra braces. Freagarach: One can write `garrisonedTradersCount * +this.template.GainMultiplierPerGarrisonedTrader` to… | |||||
if (gain.traderGain) | if (gain.traderGain) | ||||
gain.traderGain = Math.round(garrisonMultiplier * gain.traderGain); | gain.traderGain = Math.round(garrisonMultiplier * gain.traderGain); | ||||
if (gain.market1Gain) | if (gain.market1Gain) | ||||
gain.market1Gain = Math.round(garrisonMultiplier * gain.market1Gain); | gain.market1Gain = Math.round(garrisonMultiplier * gain.market1Gain); | ||||
if (gain.market2Gain) | if (gain.market2Gain) | ||||
gain.market2Gain = Math.round(garrisonMultiplier * gain.market2Gain); | gain.market2Gain = Math.round(garrisonMultiplier * gain.market2Gain); | ||||
} | |||||
} | |||||
return gain; | return gain; | ||||
}; | }; | ||||
// Set target as target market. | // Set target as target market. | ||||
// Return true if at least one of markets was changed. | // Return true if at least one of markets was changed. | ||||
Trader.prototype.SetTargetMarket = function(target, source) | Trader.prototype.SetTargetMarket = function(target, source) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
You should move the last ".