remove the hardcoded gain in petra, fixes #3943, patch by LittleDev

This was SVN commit r18168.
This commit is contained in:
mimo 2016-05-14 12:04:44 +00:00
parent 0b8845eb4f
commit 721c47a9e8
6 changed files with 54 additions and 20 deletions

View File

@ -106,6 +106,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"},

View File

@ -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;
},

View File

@ -795,6 +795,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) && this.getTemplate(shipMechantTemplateName);
let supportTraderTemplate = !this.isDisabledTemplates(supportTraderTemplateName) && this.getTemplate(supportTraderTemplateName);
return {
"navalGainMultiplier": shipMerchantTemplate && shipMerchantTemplate.gainMultiplier(),
"landGainMultiplier": supportTraderTemplate && supportTraderTemplate.gainMultiplier()
};
};
return m;
}(API3);

View File

@ -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 =

View File

@ -1041,7 +1041,9 @@ m.HQ.prototype.findMarketLocation = function(gameState, template)
var width = this.territoryMap.width;
var cellSize = this.territoryMap.cellSize;
for (var j = 0; j < this.territoryMap.length; ++j)
let traderTemplatesGains = gameState.getTraderTemplatesGains();
for (let j = 0; j < this.territoryMap.length; ++j)
{
// do not try on the border of our territory
if (this.frontierMap.map[j] == 2)
@ -1049,35 +1051,41 @@ m.HQ.prototype.findMarketLocation = function(gameState, template)
if (this.basesMap.map[j] == 0) // only in our territory
continue;
// with enough room around to build the cc
var i = this.territoryMap.getNonObstructedTile(j, radius, obstructions);
let i = this.territoryMap.getNonObstructedTile(j, radius, obstructions);
if (i < 0)
continue;
var index = gameState.ai.accessibility.landPassMap[i];
let 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)];
let 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;
let dist = API3.SquareVectorDistance(market.position(), pos);
if (dist > maxDist)
maxDist = dist;
if (!gainMultiplier)
continue;
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;
}
@ -1087,8 +1095,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

View File

@ -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)