Changeset View
Standalone View
binaries/data/mods/public/simulation/ai/petra/tradeManager.js
Show All 29 Lines | |||||
m.TradeManager.prototype.assignTrader = function(ent) | m.TradeManager.prototype.assignTrader = function(ent) | ||||
{ | { | ||||
ent.setMetadata(PlayerID, "role", "trader"); | ent.setMetadata(PlayerID, "role", "trader"); | ||||
this.traders.updateEnt(ent); | this.traders.updateEnt(ent); | ||||
}; | }; | ||||
m.TradeManager.prototype.trainMoreTraders = function(gameState, queues) | m.TradeManager.prototype.trainMoreTraders = function(gameState, queues) | ||||
{ | { | ||||
if (!this.tradeRoute || queues.trader.hasQueuedUnits()) | if (!this.hasTradeRoute() || queues.trader.hasQueuedUnits()) | ||||
return; | return; | ||||
let numTraders = this.traders.length; | let numTraders = this.traders.length; | ||||
let numSeaTraders = this.traders.filter(API3.Filters.byClass("Ship")).length; | let numSeaTraders = this.traders.filter(API3.Filters.byClass("Ship")).length; | ||||
let numLandTraders = numTraders - numSeaTraders; | let numLandTraders = numTraders - numSeaTraders; | ||||
// add traders already in training | // add traders already in training | ||||
gameState.getOwnTrainingFacilities().forEach(function(ent) { | gameState.getOwnTrainingFacilities().forEach(function(ent) { | ||||
for (let item of ent.trainingQueue()) | for (let item of ent.trainingQueue()) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if (this.Config.debug > 0) | ||||
gameState.getPlayerCiv() + " but no template found."); | gameState.getPlayerCiv() + " but no template found."); | ||||
return; | return; | ||||
} | } | ||||
queues.trader.addPlan(new m.TrainingPlan(gameState, template, metadata, 1, 1)); | queues.trader.addPlan(new m.TrainingPlan(gameState, template, metadata, 1, 1)); | ||||
}; | }; | ||||
m.TradeManager.prototype.updateTrader = function(gameState, ent) | m.TradeManager.prototype.updateTrader = function(gameState, ent) | ||||
{ | { | ||||
if (!this.tradeRoute || !ent.isIdle() || !ent.position()) | if (!this.hasTradeRoute() || !ent.isIdle() || !ent.position()) | ||||
Sandarac: I'm just curious as to why you made this change. | |||||
Not Done Inline Actions:) i think the meaning is clearer than just testing if a variable is defined. Doesn't it make easier to understand what is required? mimo: :) i think the meaning is clearer than just testing if a variable is defined. Doesn't it make… | |||||
Not Done Inline ActionsYes, the meaning is clearer with this change :) Sandarac: Yes, the meaning is clearer with this change :) | |||||
return; | return; | ||||
if (ent.getMetadata(PlayerID, "transport") !== undefined) | if (ent.getMetadata(PlayerID, "transport") !== undefined) | ||||
return; | return; | ||||
Engine.ProfileStart("Trade Manager"); | Engine.ProfileStart("Trade Manager"); | ||||
let access = ent.hasClass("Ship") ? ent.getMetadata(PlayerID, "sea") : gameState.ai.accessibility.getAccessValue(ent.position()); | let access = ent.hasClass("Ship") ? ent.getMetadata(PlayerID, "sea") : gameState.ai.accessibility.getAccessValue(ent.position()); | ||||
let route = this.checkRoutes(gameState, access); | let route = this.checkRoutes(gameState, access); | ||||
if (!route) | if (!route) | ||||
▲ Show 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | m.TradeManager.prototype.isNewMarketWorth = function(expectedGain) | ||||
if (this.potentialTradeRoute && expectedGain < 2*this.potentialTradeRoute.gain && | if (this.potentialTradeRoute && expectedGain < 2*this.potentialTradeRoute.gain && | ||||
expectedGain < this.potentialTradeRoute.gain + 20) | expectedGain < this.potentialTradeRoute.gain + 20) | ||||
return false; | return false; | ||||
return true; | return true; | ||||
}; | }; | ||||
m.TradeManager.prototype.update = function(gameState, events, queues) | m.TradeManager.prototype.update = function(gameState, events, queues) | ||||
{ | { | ||||
if (gameState.ai.HQ.canBarter) | |||||
this.performBarter(gameState); | this.performBarter(gameState); | ||||
if (this.Config.difficulty <= 1) | |||||
return; | |||||
Not Done Inline ActionsYou have added the check for barterMarket for this variable in headquarters, but there is still an exact same check in the first few lines of performBarter? Sandarac: You have added the check for barterMarket for this variable in headquarters, but there is still… | |||||
Not Done Inline ActionsThe test in performBarter is a bit different: it transforms the entitycollection into an array and take the first entry as the barterer. I agree that the test that the length is non zero there is in principle not needed because of that test, that is currently just a sanity check, checking that the array built from a non-empty collection is indeed non-empty. But as canBarter is defined in headquarter.js and could be modified one day without paying attention to the fact that it is also used in tradeManager.js, i think it is safer to keep it. mimo: The test in performBarter is a bit different: it transforms the entitycollection into an array… | |||||
Not Done Inline ActionsAh, okay, I see. Sandarac: Ah, okay, I see. | |||||
if (this.routeProspection) | if (this.routeProspection) | ||||
this.prospectForNewMarket(gameState, queues); | this.prospectForNewMarket(gameState, queues); | ||||
let self = this; | let self = this; | ||||
if (this.checkEvents(gameState, events)) // true if one market was built or destroyed | if (this.checkEvents(gameState, events)) // true if one market was built or destroyed | ||||
{ | { | ||||
this.traders.forEach(function(ent) { self.checkTrader(gameState, ent); }); | this.traders.forEach(function(ent) { self.checkTrader(gameState, ent); }); | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |
I'm just curious as to why you made this change.