diff --git a/binaries/data/mods/public/gui/credits/texts/programming.json b/binaries/data/mods/public/gui/credits/texts/programming.json
index d0490d7..0f45fcd 100644
--- a/binaries/data/mods/public/gui/credits/texts/programming.json
+++ b/binaries/data/mods/public/gui/credits/texts/programming.json
@@ -102,6 +102,7 @@
 			{"nick": "kingbasil", "name": "Giannis Fafalios"},
 			{"nick": "lafferjm", "name": "Justin Lafferty"},
 			{"nick": "leper", "name": "Georg Kilzer"},
+			{"nick": "LittleDev"},
 			{"nick": "livingaftermidnight", "name": "Will Dull"},
 			{"nick": "Louhike"},
 			{"nick": "lsdh"},
diff --git a/binaries/data/mods/public/simulation/ai/common-api/entity.js b/binaries/data/mods/public/simulation/ai/common-api/entity.js
index d0fcac2..926b1c4 100644
--- a/binaries/data/mods/public/simulation/ai/common-api/entity.js
+++ b/binaries/data/mods/public/simulation/ai/common-api/entity.js
@@ -544,6 +544,12 @@ m.Template = m.Class({
 
 	visionRange: function() {
 		return +this.get("Vision/Range");
+	},
+
+	gainMultiplier: function() {
+		if (!this.get("Trader"))
+			return undefined;
+		return +this.get("Trader/GainMultiplier");
 	}
 });
 
@@ -912,7 +918,7 @@ m.Entity = m.Class({
 		return this;
 	},
 
-	 research: function(template) {
+	research: function(template) {
 		Engine.PostCommand(PlayerID,{ "type": "research", "entity": this.id(), "template": template });
 		return this;
 	},
diff --git a/binaries/data/mods/public/simulation/ai/common-api/gamestate.js b/binaries/data/mods/public/simulation/ai/common-api/gamestate.js
index f95b8b3..a1b69df 100644
--- a/binaries/data/mods/public/simulation/ai/common-api/gamestate.js
+++ b/binaries/data/mods/public/simulation/ai/common-api/gamestate.js
@@ -803,6 +803,18 @@ m.GameState.prototype.isEntityLimitReached = function(category)
 	return (this.playerData.entityCounts[category] >= this.playerData.entityLimits[category]);
 };
 
+m.GameState.prototype.getTraderTemplatesGains = function()
+{
+	let shipMechantTemplateName = this.applyCiv("units/{civ}_ship_merchant");
+	let supportTraderTemplateName = this.applyCiv("units/{civ}_support_trader");
+	let shipMerchantTemplate = (this.isDisabledTemplates(shipMechantTemplateName) ? undefined : this.getTemplate(shipMechantTemplateName));
+	let supportTraderTemplate = (this.isDisabledTemplates(supportTraderTemplateName) ? undefined : this.getTemplate(supportTraderTemplateName));
+	return {
+		"navalGainMultiplier" : (shipMerchantTemplate ? shipMerchantTemplate.gainMultiplier() : undefined),
+		"landGainMultiplier" : (supportTraderTemplate ? supportTraderTemplate.gainMultiplier() : undefined)
+	};
+};
+
 return m;
 
 }(API3);
diff --git a/binaries/data/mods/public/simulation/ai/petra/config.js b/binaries/data/mods/public/simulation/ai/petra/config.js
index e9ae59f..8770145 100644
--- a/binaries/data/mods/public/simulation/ai/petra/config.js
+++ b/binaries/data/mods/public/simulation/ai/petra/config.js
@@ -34,8 +34,6 @@ m.Config = function(difficulty)
 		"provisionFields" : 2
 	};
 
-	this.distUnitGain = 115*115;   // TODO  take it directly from helpers/TraderGain.js
-
 	// Note: attack settings are set directly in attack_plan.js
 	// defense
 	this.Defense =
diff --git a/binaries/data/mods/public/simulation/ai/petra/headquarters.js b/binaries/data/mods/public/simulation/ai/petra/headquarters.js
index 27e4d54..0be2980 100644
--- a/binaries/data/mods/public/simulation/ai/petra/headquarters.js
+++ b/binaries/data/mods/public/simulation/ai/petra/headquarters.js
@@ -1048,6 +1048,8 @@ m.HQ.prototype.findMarketLocation = function(gameState, template)
 	var width = this.territoryMap.width;
 	var cellSize = this.territoryMap.cellSize;
 
+	let traderTemplatesGains = gameState.getTraderTemplatesGains();
+
 	for (var j = 0; j < this.territoryMap.length; ++j)
 	{
 		// do not try on the border of our territory
@@ -1062,29 +1064,35 @@ m.HQ.prototype.findMarketLocation = function(gameState, template)
 		var index = gameState.ai.accessibility.landPassMap[i];
 		if (!this.landRegions[index])
 			continue;
-
 		var pos = [cellSize * (j%width+0.5), cellSize * (Math.floor(j/width)+0.5)];
 		// checking distances to other markets
-		var maxDist = 0;
+		let maxVal = 0;
+		let gainMultiplier;
 		for (let market of markets)
 		{
 			if (isNavalMarket && market.hasClass("NavalMarket"))
 			{
-				// TODO check that there are on the same sea. For the time being, we suppose it is true
+				if (this.navalManager.getDockIndex(gameState, market, true) !== gameState.ai.accessibility.getAccessValue(pos, true))
+					continue;
+				gainMultiplier = traderTemplatesGains.navalGainMultiplier;
 			}
-			else if (gameState.ai.accessibility.getAccessValue(market.position()) != index)
+			else if (gameState.ai.accessibility.getAccessValue(market.position()) === index)
+				gainMultiplier = traderTemplatesGains.landGainMultiplier;
+			else
+				continue;
+			if (gainMultiplier === undefined)
 				continue;
-			let dist = API3.SquareVectorDistance(market.position(), pos);
-			if (dist > maxDist)
-				maxDist = dist;
+			let val = API3.SquareVectorDistance(market.position(), pos) * gainMultiplier;
+			if (val > maxVal)
+				maxVal = val;
 		}
-		if (maxDist == 0)
+		if (maxVal === 0)
 			continue;
-		if (bestVal !== undefined && maxDist < bestVal)
+		if (bestVal !== undefined && maxVal < bestVal)
 			continue;
 		if (this.isDangerousLocation(gameState, pos, halfSize))
 			continue;
-		bestVal = maxDist;
+		bestVal = maxVal;
 		bestIdx = i;
 		bestJdx = j;
 	}
@@ -1094,8 +1102,7 @@ m.HQ.prototype.findMarketLocation = function(gameState, template)
 
 	if (bestVal === undefined)  // no constraints. For the time being, place it arbitrarily by the ConstructionPlan
 		return [-1, -1, -1, 0];
-
-	var expectedGain = Math.round(bestVal / this.Config.distUnitGain);
+	let expectedGain = Math.round(bestVal / 10000);
 	if (this.Config.debug > 1)
 		API3.warn("this would give a trading gain of " + expectedGain);
 	// do not keep it if gain is too small, except if this is our first BarterMarket
diff --git a/binaries/data/mods/public/simulation/ai/petra/tradeManager.js b/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
index fc510d8..1f14069 100644
--- a/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
+++ b/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
@@ -390,6 +390,9 @@ m.TradeManager.prototype.checkRoutes = function(gameState, accessIndex)
 	var potential = { "gain": 0 };
 	var bestIndex = { "gain": 0 };
 	var bestLand  = { "gain": 0 };
+
+	let traderTemplatesGains = gameState.getTraderTemplatesGains();
+
 	for (var m1 of market1)
 	{
 		if (!m1.position())
@@ -408,7 +411,14 @@ m.TradeManager.prototype.checkRoutes = function(gameState, accessIndex)
 			var sea = (sea1 && sea1 == sea2) ? sea1 : undefined;
 			if (!land && !sea)
 				continue;
-			var gain = Math.round(API3.SquareVectorDistance(m1.position(), m2.position()) / this.Config.distUnitGain);
+			let gainMultiplier;
+			if (land && traderTemplatesGains.landGainMultiplier)
+				gainMultiplier = traderTemplatesGains.landGainMultiplier;
+			else if (sea && traderTemplatesGains.navalGainMultiplier)
+				gainMultiplier = traderTemplatesGains.navalGainMultiplier;
+			else
+				continue;
+			let gain = Math.round(API3.SquareVectorDistance(m1.position(), m2.position()) * gainMultiplier / 10000);
 			if (gain < this.minimalGain)
 				continue;
 			if (m1.foundationProgress() === undefined && m2.foundationProgress() === undefined)
