forked from mirrors/0ad
Stop relying on the internal structure of the current Trader component.
Get the required information by returning it in the proper places. Also clean up some pointless modulo operations. This code is pulled out of the Silk Road code (refs #4314). Reviewed By: mimo Differential Revision: https://code.wildfiregames.com/D161 This was SVN commit r19243.
This commit is contained in:
@@ -164,15 +164,15 @@ Trader.prototype.CanTrade = function(target)
|
||||
|
||||
Trader.prototype.PerformTrade = function(currentMarket)
|
||||
{
|
||||
let previousMarket = this.markets[(this.index+this.markets.length) % this.markets.length];
|
||||
let previousMarket = this.markets[this.index];
|
||||
if (previousMarket != currentMarket) // Inconsistent markets
|
||||
{
|
||||
this.goods.amount = null;
|
||||
return;
|
||||
return INVALID_ENTITY;
|
||||
}
|
||||
|
||||
this.index = ++this.index % this.markets.length;
|
||||
let nextMarket = this.markets[(this.index+this.markets.length) % this.markets.length];
|
||||
let nextMarket = this.markets[this.index];
|
||||
|
||||
if (this.goods.amount && this.goods.amount.traderGain)
|
||||
{
|
||||
@@ -209,11 +209,13 @@ Trader.prototype.PerformTrade = function(currentMarket)
|
||||
|
||||
let cmpPlayer = QueryOwnerInterface(this.entity);
|
||||
if (!cmpPlayer)
|
||||
return;
|
||||
return INVALID_ENTITY;
|
||||
|
||||
this.goods.type = cmpPlayer.GetNextTradingGoods();
|
||||
this.goods.amount = this.CalculateGain(currentMarket, nextMarket);
|
||||
this.goods.origin = currentMarket;
|
||||
|
||||
return nextMarket;
|
||||
};
|
||||
|
||||
Trader.prototype.GetGoods = function()
|
||||
|
||||
@@ -5357,15 +5357,14 @@ UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket)
|
||||
}
|
||||
|
||||
let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
|
||||
cmpTrader.PerformTrade(currentMarket);
|
||||
let nextMarket = cmpTrader.PerformTrade(currentMarket);
|
||||
let amount = cmpTrader.GetGoods().amount;
|
||||
if (!amount || !amount.traderGain)
|
||||
if (!nextMarket || !amount || !amount.traderGain)
|
||||
{
|
||||
this.StopTrading();
|
||||
return;
|
||||
}
|
||||
|
||||
let nextMarket = cmpTrader.markets[cmpTrader.index];
|
||||
this.order.data.target = nextMarket;
|
||||
|
||||
if (this.order.data.route && this.order.data.route.length)
|
||||
|
||||
Reference in New Issue
Block a user