forked from 0ad/0ad
Remember the last market for back-to-order trading, fixes #2248
This was SVN commit r14088.
This commit is contained in:
parent
9ffe235b2f
commit
9b98585275
@ -31,7 +31,7 @@ Trader.prototype.Init = function()
|
||||
// Selected resource for trading
|
||||
this.preferredGoods = "metal";
|
||||
// Currently carried goods
|
||||
this.goods = { "type": null, "amount": null };
|
||||
this.goods = { "type": null, "amount": null, "origin": null };
|
||||
};
|
||||
|
||||
Trader.prototype.CalculateGain = function(firstMarket, secondMarket)
|
||||
@ -184,7 +184,7 @@ Trader.prototype.CanTrade = function(target)
|
||||
return true;
|
||||
};
|
||||
|
||||
Trader.prototype.PerformTrade = function()
|
||||
Trader.prototype.PerformTrade = function(currentMarket)
|
||||
{
|
||||
if (this.goods.amount && this.goods.amount.traderGain)
|
||||
{
|
||||
@ -220,6 +220,7 @@ Trader.prototype.PerformTrade = function()
|
||||
}
|
||||
this.goods.type = this.preferredGoods;
|
||||
this.goods.amount = this.gain;
|
||||
this.goods.origin = currentMarket;
|
||||
};
|
||||
|
||||
Trader.prototype.GetGoods = function()
|
||||
@ -227,6 +228,14 @@ Trader.prototype.GetGoods = function()
|
||||
return this.goods;
|
||||
};
|
||||
|
||||
Trader.prototype.GetNextMarket = function()
|
||||
{
|
||||
if (this.goods.amount && this.goods.origin == this.firstMarket)
|
||||
return this.secondMarket;
|
||||
else
|
||||
return this.firstMarket;
|
||||
};
|
||||
|
||||
Trader.prototype.StopTrading = function()
|
||||
{
|
||||
// Drop carried goods
|
||||
|
@ -573,10 +573,24 @@ var UnitFsmSpec = {
|
||||
},
|
||||
|
||||
"Order.Trade": function(msg) {
|
||||
if (this.MoveToMarket(this.order.data.firstMarket))
|
||||
// We must check if this trader has both markets in case it was a back-to-work order
|
||||
var cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
|
||||
if (!cmpTrader || ! cmpTrader.HasBothMarkets())
|
||||
{
|
||||
// We've started walking to the first market
|
||||
this.SetNextState("INDIVIDUAL.TRADE.APPROACHINGFIRSTMARKET");
|
||||
this.FinishOrder();
|
||||
return;
|
||||
}
|
||||
|
||||
var nextMarket = cmpTrader.GetNextMarket();
|
||||
if (nextMarket == this.order.data.firstMarket)
|
||||
var state = "INDIVIDUAL.TRADE.APPROACHINGFIRSTMARKET";
|
||||
else
|
||||
var state = "INDIVIDUAL.TRADE.APPROACHINGSECONDMARKET";
|
||||
|
||||
if (this.MoveToMarket(nextMarket))
|
||||
{
|
||||
// We've started walking to the next market
|
||||
this.SetNextState(state);
|
||||
}
|
||||
},
|
||||
|
||||
@ -4184,7 +4198,7 @@ UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket, nextM
|
||||
|
||||
if (this.CheckTargetRange(currentMarket, IID_Trader))
|
||||
{
|
||||
this.PerformTrade();
|
||||
this.PerformTrade(currentMarket);
|
||||
if (this.MoveToMarket(nextMarket))
|
||||
{
|
||||
// We've started walking to the next market
|
||||
@ -4198,10 +4212,10 @@ UnitAI.prototype.PerformTradeAndMoveToNextMarket = function(currentMarket, nextM
|
||||
}
|
||||
};
|
||||
|
||||
UnitAI.prototype.PerformTrade = function()
|
||||
UnitAI.prototype.PerformTrade = function(currentMarket)
|
||||
{
|
||||
var cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
|
||||
cmpTrader.PerformTrade();
|
||||
cmpTrader.PerformTrade(currentMarket);
|
||||
};
|
||||
|
||||
UnitAI.prototype.StopTrading = function()
|
||||
|
Loading…
Reference in New Issue
Block a user