fix the test when changing markets, fixes #3838

This was SVN commit r17918.
This commit is contained in:
mimo 2016-03-20 14:00:49 +00:00
parent 3025b4b8e3
commit 81948477df
2 changed files with 7 additions and 9 deletions

View File

@ -75,7 +75,7 @@ Trader.prototype.SetTargetMarket = function(target, source)
return false;
if (!cmpTargetIdentity.HasClass("Market") && !cmpTargetIdentity.HasClass("NavalMarket"))
return false;
var marketsChanged = true;
if (source)
{
// Establish a trade route with both markets in one go.
@ -98,7 +98,7 @@ Trader.prototype.SetTargetMarket = function(target, source)
// If we have only one market and target is different from it,
// set the target as second one
if (target == this.markets[0])
marketsChanged = false;
return false;
else
{
this.index = 0;
@ -113,12 +113,9 @@ Trader.prototype.SetTargetMarket = function(target, source)
this.index = 0;
this.markets = [target];
}
if (marketsChanged)
{
// Drop carried goods
this.goods.amount = null;
}
return marketsChanged;
// Drop carried goods if markets were changed
this.goods.amount = null;
return true;
};
Trader.prototype.GetFirstMarket = function()

View File

@ -5244,7 +5244,8 @@ UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket)
let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
cmpTrader.PerformTrade(currentMarket);
if (!cmpTrader.GetGoods().amount.traderGain)
let amount = cmpTrader.GetGoods().amount;
if (!amount || !amount.traderGain)
{
this.StopTrading();
return;