Differential D2952 Diff 14052 ps/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | if (this.tradeRoute.sea) | ||||
{ | { | ||||
if (shipToSwitch.getMetadata(PlayerID, "transporter") === undefined) | if (shipToSwitch.getMetadata(PlayerID, "transporter") === undefined) | ||||
shipToSwitch.setMetadata(PlayerID, "role", "trader"); | shipToSwitch.setMetadata(PlayerID, "role", "trader"); | ||||
else | else | ||||
shipToSwitch.setMetadata(PlayerID, "role", "switchToTrader"); | shipToSwitch.setMetadata(PlayerID, "role", "switchToTrader"); | ||||
return; | return; | ||||
} | } | ||||
template = gameState.applyCiv("units/{civ}_ship_merchant"); | template = gameState.applyCiv("units/{civ}/ship_merchant"); | ||||
metadata.sea = this.tradeRoute.sea; | metadata.sea = this.tradeRoute.sea; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
template = gameState.applyCiv("units/{civ}_support_trader"); | template = gameState.applyCiv("units/{civ}/support_trader"); | ||||
if (!this.tradeRoute.source.hasClass("Naval")) | if (!this.tradeRoute.source.hasClass("Naval")) | ||||
metadata.base = this.tradeRoute.source.getMetadata(PlayerID, "base"); | metadata.base = this.tradeRoute.source.getMetadata(PlayerID, "base"); | ||||
else | else | ||||
metadata.base = this.tradeRoute.target.getMetadata(PlayerID, "base"); | metadata.base = this.tradeRoute.target.getMetadata(PlayerID, "base"); | ||||
} | } | ||||
if (!gameState.getTemplate(template)) | if (!gameState.getTemplate(template)) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | PETRA.TradeManager.prototype.checkEvents = function(gameState, events) | ||||
} | } | ||||
return false; | return false; | ||||
}; | }; | ||||
PETRA.TradeManager.prototype.activateProspection = function(gameState) | PETRA.TradeManager.prototype.activateProspection = function(gameState) | ||||
{ | { | ||||
this.routeProspection = true; | this.routeProspection = true; | ||||
gameState.ai.HQ.buildManager.setBuildable(gameState.applyCiv("structures/{civ}_market")); | gameState.ai.HQ.buildManager.setBuildable(gameState.applyCiv("structures/{civ}/market")); | ||||
gameState.ai.HQ.buildManager.setBuildable(gameState.applyCiv("structures/{civ}_dock")); | gameState.ai.HQ.buildManager.setBuildable(gameState.applyCiv("structures/{civ}/dock")); | ||||
}; | }; | ||||
/** | /** | ||||
* fills the best trade route in this.tradeRoute and the best potential route in this.potentialTradeRoute | * fills the best trade route in this.tradeRoute and the best potential route in this.potentialTradeRoute | ||||
* If an index is given, it returns the best route with this index or the best land route if index is a land index | * If an index is given, it returns the best route with this index or the best land route if index is a land index | ||||
*/ | */ | ||||
PETRA.TradeManager.prototype.checkRoutes = function(gameState, accessIndex) | PETRA.TradeManager.prototype.checkRoutes = function(gameState, accessIndex) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | if (!possibleRoute || | ||||
ent.stopMoving(); | ent.stopMoving(); | ||||
} | } | ||||
}; | }; | ||||
PETRA.TradeManager.prototype.prospectForNewMarket = function(gameState, queues) | PETRA.TradeManager.prototype.prospectForNewMarket = function(gameState, queues) | ||||
{ | { | ||||
if (queues.economicBuilding.hasQueuedUnitsWithClass("Trade") || queues.dock.hasQueuedUnitsWithClass("Trade")) | if (queues.economicBuilding.hasQueuedUnitsWithClass("Trade") || queues.dock.hasQueuedUnitsWithClass("Trade")) | ||||
return; | return; | ||||
if (!gameState.ai.HQ.canBuild(gameState, "structures/{civ}_market")) | if (!gameState.ai.HQ.canBuild(gameState, "structures/{civ}/market")) | ||||
return; | return; | ||||
if (!gameState.updatingCollection("OwnMarkets", API3.Filters.byClass("Trade"), gameState.getOwnStructures()).hasEntities() && | if (!gameState.updatingCollection("OwnMarkets", API3.Filters.byClass("Trade"), gameState.getOwnStructures()).hasEntities() && | ||||
!gameState.updatingCollection("diplo-ExclusiveAllyMarkets", API3.Filters.byClass("Trade"), gameState.getExclusiveAllyEntities()).hasEntities()) | !gameState.updatingCollection("diplo-ExclusiveAllyMarkets", API3.Filters.byClass("Trade"), gameState.getExclusiveAllyEntities()).hasEntities()) | ||||
return; | return; | ||||
let template = gameState.getTemplate(gameState.applyCiv("structures/{civ}_market")); | let template = gameState.getTemplate(gameState.applyCiv("structures/{civ}/market")); | ||||
if (!template) | if (!template) | ||||
return; | return; | ||||
this.checkRoutes(gameState); | this.checkRoutes(gameState); | ||||
let marketPos = gameState.ai.HQ.findMarketLocation(gameState, template); | let marketPos = gameState.ai.HQ.findMarketLocation(gameState, template); | ||||
if (!marketPos || marketPos[3] == 0) // marketPos[3] is the expected gain | if (!marketPos || marketPos[3] == 0) // marketPos[3] is the expected gain | ||||
{ // no position found | { // no position found | ||||
if (gameState.getOwnEntitiesByClass("Market", true).hasEntities()) | if (gameState.getOwnEntitiesByClass("Market", true).hasEntities()) | ||||
gameState.ai.HQ.buildManager.setUnbuildable(gameState, gameState.applyCiv("structures/{civ}_market")); | gameState.ai.HQ.buildManager.setUnbuildable(gameState, gameState.applyCiv("structures/{civ}/market")); | ||||
else | else | ||||
this.routeProspection = false; | this.routeProspection = false; | ||||
return; | return; | ||||
} | } | ||||
this.routeProspection = false; | this.routeProspection = false; | ||||
if (!this.isNewMarketWorth(marketPos[3])) | if (!this.isNewMarketWorth(marketPos[3])) | ||||
return; // position found, but not enough gain compared to our present route | return; // position found, but not enough gain compared to our present route | ||||
if (this.Config.debug > 1) | if (this.Config.debug > 1) | ||||
{ | { | ||||
if (this.potentialTradeRoute) | if (this.potentialTradeRoute) | ||||
API3.warn("turn " + gameState.ai.playedTurn + "we could have a new route with gain " + | API3.warn("turn " + gameState.ai.playedTurn + "we could have a new route with gain " + | ||||
marketPos[3] + " instead of the present " + this.potentialTradeRoute.gain); | marketPos[3] + " instead of the present " + this.potentialTradeRoute.gain); | ||||
else | else | ||||
API3.warn("turn " + gameState.ai.playedTurn + "we could have a first route with gain " + | API3.warn("turn " + gameState.ai.playedTurn + "we could have a first route with gain " + | ||||
marketPos[3]); | marketPos[3]); | ||||
} | } | ||||
if (!this.tradeRoute) | if (!this.tradeRoute) | ||||
gameState.ai.queueManager.changePriority("economicBuilding", 2 * this.Config.priorities.economicBuilding); | gameState.ai.queueManager.changePriority("economicBuilding", 2 * this.Config.priorities.economicBuilding); | ||||
let plan = new PETRA.ConstructionPlan(gameState, "structures/{civ}_market"); | let plan = new PETRA.ConstructionPlan(gameState, "structures/{civ}/market"); | ||||
if (!this.tradeRoute) | if (!this.tradeRoute) | ||||
plan.queueToReset = "economicBuilding"; | plan.queueToReset = "economicBuilding"; | ||||
queues.economicBuilding.addPlan(plan); | queues.economicBuilding.addPlan(plan); | ||||
}; | }; | ||||
PETRA.TradeManager.prototype.isNewMarketWorth = function(expectedGain) | PETRA.TradeManager.prototype.isNewMarketWorth = function(expectedGain) | ||||
{ | { | ||||
if (!Resources.GetTradableCodes().length) | if (!Resources.GetTradableCodes().length) | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator