diff --git a/binaries/data/mods/public/simulation/components/Market.js b/binaries/data/mods/public/simulation/components/Market.js index 09356bb5b2..60d5bc3c3f 100644 --- a/binaries/data/mods/public/simulation/components/Market.js +++ b/binaries/data/mods/public/simulation/components/Market.js @@ -10,6 +10,9 @@ Market.prototype.Schema = "" + "" + "" + + "" + + "" + + "" + ""; Market.prototype.Init = function() @@ -28,6 +31,11 @@ Market.prototype.RemoveTrader = function(ent) this.traders.delete(ent); }; +Market.prototype.GetInternationalBonus = function() +{ + return ApplyValueModificationsToEntity("Market/InternationalBonus", +this.template.InternationalBonus, this.entity); +} + Market.prototype.HasType = function(type) { return this.tradeType.has(type); diff --git a/binaries/data/mods/public/simulation/components/Trader.js b/binaries/data/mods/public/simulation/components/Trader.js index 67aaa394ca..5f4bd32901 100644 --- a/binaries/data/mods/public/simulation/components/Trader.js +++ b/binaries/data/mods/public/simulation/components/Trader.js @@ -12,10 +12,9 @@ function Trader() {} Trader.prototype.Schema = "Lets the unit generate resouces while moving between markets (or docks in case of water trading)." + "" + - "2.0" + - "1.0" + + "0.75" + "" + - "" + + "" + "" + ""; @@ -133,6 +132,11 @@ Trader.prototype.GetSecondMarket = function() return this.markets[1] || null; }; +Trader.prototype.GetTraderGainMultiplier = function() +{ + return ApplyValueModificationsToEntity("Trader/GainMultiplier", +this.template.GainMultiplier, this.entity); +} + Trader.prototype.HasBothMarkets = function() { return this.markets.length >= 2; diff --git a/binaries/data/mods/public/simulation/data/technologies/trade_commercial_treaty.json b/binaries/data/mods/public/simulation/data/technologies/trade_commercial_treaty.json new file mode 100644 index 0000000000..3239592e4e --- /dev/null +++ b/binaries/data/mods/public/simulation/data/technologies/trade_commercial_treaty.json @@ -0,0 +1,13 @@ +{ + "genericName": "Commercial Treaty", + "description": "Improve the international trading profit.", + "cost": { "food": 0, "wood": 0, "stone": 0, "metal": 100 }, + "requirements": { "tech": "phase_town" }, + "requirementsTooltip": "Unlocked in Town Phase.", + "icon": "sibylline_books.png", + "researchTime": 40, + "tooltip": "Market +10% International Bonus.", + "modifications": [{ "value": "Market/InternationalBonus", "add": 0.10 }], + "affects": ["Market"], + "soundComplete": "interface/alarm/alarm_upgradearmory.xml" +} diff --git a/binaries/data/mods/public/simulation/helpers/TraderGain.js b/binaries/data/mods/public/simulation/helpers/TraderGain.js index 875e8b5fb7..1bea5e2af7 100644 --- a/binaries/data/mods/public/simulation/helpers/TraderGain.js +++ b/binaries/data/mods/public/simulation/helpers/TraderGain.js @@ -1,67 +1,67 @@ -// This constant used to adjust gain value depending on distance -const DISTANCE_FACTOR = 1 / 115; - -// Additional gain (applying to each market) for trading performed between markets of different players, in percents -const INTERNATIONAL_TRADING_ADDITION = 25; - -// If trader undefined, the trader owner is supposed to be the same as the first market -function CalculateTraderGain(firstMarket, secondMarket, template, trader) +function CalculateTraderGain(firstMarket, secondMarket, traderTemplate, trader) { - var gain = {}; - - var cmpFirstMarketPosition = Engine.QueryInterface(firstMarket, IID_Position); - var cmpSecondMarketPosition = Engine.QueryInterface(secondMarket, IID_Position); - if (!cmpFirstMarketPosition || !cmpFirstMarketPosition.IsInWorld() || - !cmpSecondMarketPosition || !cmpSecondMarketPosition.IsInWorld()) + let cmpMarket1 = Engine.QueryInterface(firstMarket, IID_Market); + let cmpMarket2 = Engine.QueryInterface(secondMarket, IID_Market); + if (!cmpMarket1 || !cmpMarket2) return null; - var firstMarketPosition = cmpFirstMarketPosition.GetPosition2D(); - var secondMarketPosition = cmpSecondMarketPosition.GetPosition2D(); + + let cmpMarket1Player = QueryOwnerInterface(firstMarket); + let cmpMarket2Player = QueryOwnerInterface(secondMarket); + if (!cmpMarket1Player || !cmpMarket2Player) + return null; + + let cmpFirstMarketPosition = Engine.QueryInterface(firstMarket, IID_Position); + let cmpSecondMarketPosition = Engine.QueryInterface(secondMarket, IID_Position); + if (!cmpFirstMarketPosition || !cmpFirstMarketPosition.IsInWorld() || + !cmpSecondMarketPosition || !cmpSecondMarketPosition.IsInWorld()) + return null; + let firstMarketPosition = cmpFirstMarketPosition.GetPosition2D(); + let secondMarketPosition = cmpSecondMarketPosition.GetPosition2D(); + + let gainMultiplier; + if (trader) + { + let cmpTrader = Engine.QueryInterface(trader, IID_Trader); + if (!cmpTrader) + return null; + gainMultiplier = cmpTrader.GetTraderGainMultiplier(); + } + else //called from the gui, modifications already applied + { + if (!traderTemplate || !traderTemplate.GainMultiplier) + return null; + gainMultiplier = traderTemplate.GainMultiplier; + } + + let gain = {}; // Calculate ordinary Euclidean distance between markets. // We don't use pathfinder, because ordinary distance looks more fair. - var distance = firstMarketPosition.distanceTo(secondMarketPosition); + let distanceSq = firstMarketPosition.distanceToSquared(secondMarketPosition); // We calculate gain as square of distance to encourage trading between remote markets - gain.traderGain = Math.pow(distance * DISTANCE_FACTOR, 2); - if (template && template.GainMultiplier) - { - if (trader) - gain.traderGain *= ApplyValueModificationsToEntity("Trader/GainMultiplier", +template.GainMultiplier, trader); - else // called from the gui with modifications already applied - gain.traderGain *= template.GainMultiplier; - } + // and gainMultiplier corresponds to the gain for a 100m distance + gain.traderGain = distanceSq * gainMultiplier / 10000; + + gain.market1Owner = cmpMarket1Player.GetPlayerID(); + gain.market2Owner = cmpMarket2Player.GetPlayerID(); // If trader undefined, the trader owner is supposed to be the same as the first market - var cmpOwnership = trader ? Engine.QueryInterface(trader, IID_Ownership) : Engine.QueryInterface(firstMarket, IID_Ownership); - if (!cmpOwnership) + let cmpPlayer = trader ? QueryOwnerInterface(trader) : cmpMarket1Player; + if (!cmpPlayer) return null; - gain.traderOwner = cmpOwnership.GetOwner(); - + gain.traderOwner = cmpPlayer.GetPlayerID(); + // Add potential player trade multipliers + let playerBonus = cmpPlayer.GetTradeRateMultiplier(); // If markets belong to different players, add gain from international trading - var ownerFirstMarket = Engine.QueryInterface(firstMarket, IID_Ownership).GetOwner(); - var ownerSecondMarket = Engine.QueryInterface(secondMarket, IID_Ownership).GetOwner(); - if (ownerFirstMarket != ownerSecondMarket) + if (gain.market1Owner != gain.market2Owner) { - gain.market1Gain = gain.traderGain * ApplyValueModificationsToEntity("Trade/International", INTERNATIONAL_TRADING_ADDITION, firstMarket) / 100; - gain.market1Owner = ownerFirstMarket; - gain.market2Gain = gain.traderGain * ApplyValueModificationsToEntity("Trade/International", INTERNATIONAL_TRADING_ADDITION, secondMarket) / 100; - gain.market2Owner = ownerSecondMarket; - } - - // Add potential trade multipliers and roundings - var cmpPlayer = trader ? QueryOwnerInterface(trader) : QueryOwnerInterface(firstMarket); - if (cmpPlayer) - gain.traderGain *= cmpPlayer.GetTradeRateMultiplier(); - gain.traderGain = Math.round(gain.traderGain); - - if (ownerFirstMarket != ownerSecondMarket) - { - if ((cmpPlayer = QueryOwnerInterface(firstMarket))) - gain.market1Gain *= cmpPlayer.GetTradeRateMultiplier(); - gain.market1Gain = Math.round(gain.market1Gain); - - if ((cmpPlayer = QueryOwnerInterface(secondMarket))) - gain.market2Gain *= cmpPlayer.GetTradeRateMultiplier(); - gain.market2Gain = Math.round(gain.market2Gain); + let market1PlayerBonus = cmpMarket1Player.GetTradeRateMultiplier(); + let market2PlayerBonus = cmpMarket2Player.GetTradeRateMultiplier(); + let internationalBonus1 = cmpMarket1.GetInternationalBonus(); + let internationalBonus2 = cmpMarket2.GetInternationalBonus(); + gain.market1Gain = Math.round(gain.traderGain * internationalBonus1 * market1PlayerBonus); + gain.market2Gain = Math.round(gain.traderGain * internationalBonus2 * market2PlayerBonus); } + gain.traderGain = Math.round(gain.traderGain * playerBonus); return gain; } diff --git a/binaries/data/mods/public/simulation/templates/structures/cart_dock.xml b/binaries/data/mods/public/simulation/templates/structures/cart_dock.xml index 474f57029b..a3cb0c25c7 100644 --- a/binaries/data/mods/public/simulation/templates/structures/cart_dock.xml +++ b/binaries/data/mods/public/simulation/templates/structures/cart_dock.xml @@ -19,6 +19,9 @@ The Carthaginians were famous for their sea trade. Carthage itself had an entire harbor dedicated to nothing more than commercial sea trade. Construct fishing boats to gather meat and merchant ships to trade with other docks. + + 0.1 + diff --git a/binaries/data/mods/public/simulation/templates/structures/cart_market.xml b/binaries/data/mods/public/simulation/templates/structures/cart_market.xml index 348c17af0b..406ab1048d 100644 --- a/binaries/data/mods/public/simulation/templates/structures/cart_market.xml +++ b/binaries/data/mods/public/simulation/templates/structures/cart_market.xml @@ -12,6 +12,9 @@ Šūq Carthaginian markets were probably just big sheds or structures surrounding a ?market? area or in a wharf area of a port. + + 0.1 + diff --git a/binaries/data/mods/public/simulation/templates/template_formation.xml b/binaries/data/mods/public/simulation/templates/template_formation.xml index c310825e70..4745af2dff 100644 --- a/binaries/data/mods/public/simulation/templates/template_formation.xml +++ b/binaries/data/mods/public/simulation/templates/template_formation.xml @@ -41,6 +41,6 @@ large - 1.0 + 0.75 diff --git a/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml b/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml index 5373825be9..4e12888b78 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml @@ -34,6 +34,7 @@ land + 0.2 @@ -59,6 +60,7 @@ trade_convoys_armor trade_gain_01 trade_gain_02 + trade_commercial_treaty units/{civ}_support_trader diff --git a/binaries/data/mods/public/simulation/templates/template_structure_military_dock.xml b/binaries/data/mods/public/simulation/templates/template_structure_military_dock.xml index a27c0847ed..df2882b729 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_military_dock.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_military_dock.xml @@ -36,6 +36,7 @@ land naval + 0.2 diff --git a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml index 6885effbe3..7e6cce6d87 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_merchant.xml @@ -45,7 +45,7 @@ 6.0 - 1.0 + 0.75 passive diff --git a/binaries/data/mods/public/simulation/templates/template_unit_support_trader.xml b/binaries/data/mods/public/simulation/templates/template_unit_support_trader.xml index d514f96530..44b7f0e8cd 100644 --- a/binaries/data/mods/public/simulation/templates/template_unit_support_trader.xml +++ b/binaries/data/mods/public/simulation/templates/template_unit_support_trader.xml @@ -39,7 +39,7 @@ - 1.0 + 0.75 false diff --git a/binaries/data/mods/public/simulation/templates/units/cart_ship_merchant.xml b/binaries/data/mods/public/simulation/templates/units/cart_ship_merchant.xml index e8259146ec..6d4223d865 100644 --- a/binaries/data/mods/public/simulation/templates/units/cart_ship_merchant.xml +++ b/binaries/data/mods/public/simulation/templates/units/cart_ship_merchant.xml @@ -13,7 +13,7 @@ phase_village - 1.25 + 1.25 structures/carthaginians/merchant_ship.xml diff --git a/binaries/data/mods/public/simulation/templates/units/pers_support_trader.xml b/binaries/data/mods/public/simulation/templates/units/pers_support_trader.xml index ec4f0e32f6..09ad80289c 100644 --- a/binaries/data/mods/public/simulation/templates/units/pers_support_trader.xml +++ b/binaries/data/mods/public/simulation/templates/units/pers_support_trader.xml @@ -21,7 +21,7 @@ - 1.25 + 1.25 units/persians/trader.xml