Changeset View
Standalone View
binaries/data/mods/public/simulation/helpers/TraderGain.js
Show All 31 Lines | if (!traderTemplate || !traderTemplate.GainMultiplier) | ||||
return null; | return null; | ||||
gainMultiplier = traderTemplate.GainMultiplier; | gainMultiplier = traderTemplate.GainMultiplier; | ||||
} | } | ||||
let gain = {}; | let gain = {}; | ||||
// Calculate ordinary Euclidean distance between markets. | // Calculate ordinary Euclidean distance between markets. | ||||
// We don't use pathfinder, because ordinary distance looks more fair. | // We don't use pathfinder, because ordinary distance looks more fair. | ||||
let distanceSq = firstMarketPosition.distanceToSquared(secondMarketPosition); | let distance = firstMarketPosition.distanceTo(secondMarketPosition); | ||||
// We calculate gain as square of distance to encourage trading between remote markets | let cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); | ||||
// We calculate gain as distance between markets | |||||
// and gainMultiplier corresponds to the gain for a 100m distance | // and gainMultiplier corresponds to the gain for a 100m distance | ||||
gain.traderGain = gainMultiplier * distanceSq / 10000; | gain.traderGain = gainMultiplier * 1024 * distance * Math.tanh(distance / cmpTerrain.GetMapSize()) / 10000; | ||||
mimo: The comment in the gainMultiplier Schema of the Trader is no more true, should be changed… | |||||
Not Done Inline Actions// We calculate gain as square of distance to encourage trading between remote markets // and gainMultiplier corresponds to the gain percentage from the income of given distance gain.traderGain = gainMultiplier * 1024 * distance * Math.tanh(distance / cmpTerrain.GetMapSize()) / 10000; Try again fatherbushido: ```
// We calculate gain as square of distance to encourage trading between remote markets
//… | |||||
Not Done Inline Actions// We calculate gain as distance between markets // and gainMultiplier corresponds to the gain for a 100m distance gain.traderGain = gainMultiplier * 1024 * distance * Math.tanh(distance / cmpTerrain.GetMapSize()) / 10000; Try again fatherbushido: ```
// We calculate gain as distance between markets
// and gainMultiplier corresponds to the… | |||||
gain.market1Owner = cmpMarket1Player.GetPlayerID(); | gain.market1Owner = cmpMarket1Player.GetPlayerID(); | ||||
Not Done Inline Actions"as a function of the distance" or something like that is general enough (and that function is the one mimo suggests to move in globalscripts). fatherbushido: "as a function of the distance" or something like that is general enough (and that function is… | |||||
gain.market2Owner = cmpMarket2Player.GetPlayerID(); | gain.market2Owner = cmpMarket2Player.GetPlayerID(); | ||||
Not Done Inline Actionsand ? mimo: and ? | |||||
Not Done Inline ActionsLittle leftover :) Grugnas: Little leftover :) | |||||
// If trader undefined, the trader owner is supposed to be the same as the first market | // If trader undefined, the trader owner is supposed to be the same as the first market | ||||
Not Done Inline ActionsThe normalisation of gainMultiplier on map sizes of 1024 is done by the sqrt(1024/size), so no need of the 1024 in line 28 which has no sense. mimo: The normalisation of gainMultiplier on map sizes of 1024 is done by the sqrt(1024/size), so no… | |||||
Not Done Inline ActionsI'll recheck the code asap, as long as i am not very familiar with this, i used the formula used in thr correct plot. Since the result seemed promising, i uploaded the patch Grugnas: I'll recheck the code asap, as long as i am not very familiar with this, i used the formula… | |||||
let cmpPlayer = trader ? QueryOwnerInterface(trader) : cmpMarket1Player; | let cmpPlayer = trader ? QueryOwnerInterface(trader) : cmpMarket1Player; | ||||
if (!cmpPlayer) | if (!cmpPlayer) | ||||
return null; | return null; | ||||
gain.traderOwner = cmpPlayer.GetPlayerID(); | gain.traderOwner = cmpPlayer.GetPlayerID(); | ||||
// Add potential player trade multipliers | // Add potential player trade multipliers | ||||
let playerBonus = cmpPlayer.GetTradeRateMultiplier(); | let playerBonus = cmpPlayer.GetTradeRateMultiplier(); | ||||
// If markets belong to different players, add gain from international trading | // If markets belong to different players, add gain from international trading | ||||
if (gain.market1Owner != gain.market2Owner) | if (gain.market1Owner != gain.market2Owner) | ||||
Show All 14 Lines |
The comment in the gainMultiplier Schema of the Trader is no more true, should be changed accordingly.