1
0
forked from 0ad/0ad

Fix ungarrisoning bug caused by promoting garrisoned entities. Fixes #2471.

This now uses the Autogarrsion order as both already work with an
already garrisoned entity.

This was SVN commit r14903.
This commit is contained in:
leper 2014-04-06 03:04:30 +00:00
parent fd4cd56224
commit fb1827bee7
3 changed files with 37 additions and 18 deletions

View File

@ -289,7 +289,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
"isGuarding": cmpUnitAI.IsGuardOf(),
};
// Add some information needed for ungarrisoning
if (cmpUnitAI.isGarrisoned && ret.player !== undefined)
if (cmpUnitAI.IsGarrisoned() && ret.player !== undefined)
ret.template = "p" + ret.player + "&" + ret.template;
}

View File

@ -37,7 +37,7 @@ Promotion.prototype.Promote = function(promotedTemplateName)
var cmpCurrentUnitPosition = Engine.QueryInterface(this.entity, IID_Position);
var cmpPromotedUnitPosition = Engine.QueryInterface(promotedUnitEntity, IID_Position);
if (cmpCurrentUnitPosition.IsInWorld())
{
{
var pos = cmpCurrentUnitPosition.GetPosition2D();
cmpPromotedUnitPosition.JumpTo(pos.x, pos.y);
}
@ -69,15 +69,32 @@ Promotion.prototype.Promote = function(promotedTemplateName)
var carriedResorces = cmpCurrentUnitResourceGatherer.GetCarryingStatus();
cmpPromotedUnitResourceGatherer.GiveResources(carriedResorces);
}
var cmpCurrentUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);
var cmpPromotedUnitAI = Engine.QueryInterface(promotedUnitEntity, IID_UnitAI);
cmpPromotedUnitAI.SetHeldPosition(cmpCurrentUnitAI.GetHeldPosition());
if (cmpCurrentUnitAI.GetStanceName())
cmpPromotedUnitAI.SwitchToStance(cmpCurrentUnitAI.GetStanceName());
cmpPromotedUnitAI.Cheer();
var orders = cmpCurrentUnitAI.GetOrders();
if (cmpCurrentUnitAI.IsGarrisoned())
{
if (orders.length > 0 && orders[0].type == "Garrison")
{
// Replace the garrison order by an autogarrison order,
// as we are already garrisoned and do not need to do
// any further checks (or else we should do them here).
orders.shift();
cmpPromotedUnitAI.Autogarrison();
}
else
warn("Promoted garrisoned entity with empty order queue.");
}
else
cmpPromotedUnitAI.Cheer();
cmpPromotedUnitAI.AddOrders(orders);
var workOrders = cmpCurrentUnitAI.GetWorkOrders();
cmpPromotedUnitAI.SetWorkOrders(workOrders);
cmpPromotedUnitAI.SetGuardOf(cmpCurrentUnitAI.IsGuardOf());

View File

@ -2750,7 +2750,7 @@ var UnitFsmSpec = {
if(this.order.data.target)
var target = this.order.data.target;
else
{
{
if(!this.alertGarrisoningTarget)
{
// We've been unable to find a target nearby, so give up
@ -2843,7 +2843,7 @@ var UnitFsmSpec = {
this.isGarrisoned = true;
return false;
},
"Order.Ungarrison": function() {
if (this.FinishOrder())
return;
@ -3608,10 +3608,11 @@ UnitAI.prototype.AddOrders = function(orders)
UnitAI.prototype.GetOrderData = function()
{
var orders = [];
for (var i in this.orderQueue) {
for (var i in this.orderQueue)
{
if (this.orderQueue[i].data)
orders.push(deepcopy(this.orderQueue[i].data));
}
}
return orders;
};
@ -3620,22 +3621,22 @@ UnitAI.prototype.UpdateWorkOrders = function(type)
// Under alert, remembered work orders won't be forgotten
if (this.IsUnderAlert())
return;
var isWorkType = function(type){
return (type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource");
};
// If we are being re-affected to a work order, forget the previous ones
if (isWorkType(type))
{
this.workOrders = [];
return;
}
// Then if we already have work orders, keep them
if (this.workOrders.length)
return;
// First if the unit is in a formation, get its workOrders from it
if (this.IsFormationMember())
{
@ -3665,10 +3666,10 @@ UnitAI.prototype.UpdateWorkOrders = function(type)
};
UnitAI.prototype.BackToWork = function()
{
{
if (this.workOrders.length == 0)
return false;
// Clear the order queue considering special orders not to avoid
if (this.order && this.order.type == "Cheering")
{
@ -3677,9 +3678,9 @@ UnitAI.prototype.BackToWork = function()
}
else
this.orderQueue = [];
this.AddOrders(this.workOrders);
// And if the unit is in a formation, remove it from the formation
if (this.IsFormationMember())
{
@ -3687,7 +3688,7 @@ UnitAI.prototype.BackToWork = function()
if (cmpFormation)
cmpFormation.RemoveMembers([this.entity]);
}
this.workOrders = [];
return true;
};
@ -4899,7 +4900,8 @@ UnitAI.prototype.Ungarrison = function()
};
/**
* Adds autogarrison order to the queue (only used by ProductionQueue for auto-garrisoning)
* Adds autogarrison order to the queue (only used by ProductionQueue for auto-garrisoning
* and Promotion when promoting already garrisoned entities).
*/
UnitAI.prototype.Autogarrison = function()
{