Fixes garrisoned units being found as idle (even if they are, we can't select them, so skip them instead). Fixes #844.
Garrisoned units now remain in the GARRISONED state until explicitly ungarrisoned This was SVN commit r9498.
This commit is contained in:
parent
cda5c5f5c9
commit
025a00340e
@ -139,6 +139,13 @@ GarrisonHolder.prototype.Eject = function(entity)
|
||||
var entityIndex = this.entities.indexOf(entity);
|
||||
this.spaceOccupied -= 1;
|
||||
this.entities.splice(entityIndex, 1);
|
||||
|
||||
var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);
|
||||
if (cmpUnitAI)
|
||||
{
|
||||
cmpUnitAI.Ungarrison();
|
||||
}
|
||||
|
||||
var cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint);
|
||||
var pos = cmpFootprint.PickSpawnPoint(entity);
|
||||
if (pos.y < 0)
|
||||
@ -147,7 +154,7 @@ GarrisonHolder.prototype.Eject = function(entity)
|
||||
// What should we do here?
|
||||
// For now, just move the unit into the middle of the building where it'll probably get stuck
|
||||
pos = cmpPosition.GetPosition();
|
||||
warn("Can't find free space to spawn trained unit");
|
||||
warn("Can't find free space to ungarrison unit");
|
||||
}
|
||||
|
||||
var cmpNewPosition = Engine.QueryInterface(entity, IID_Position);
|
||||
@ -184,7 +191,6 @@ GarrisonHolder.prototype.OrderWalkToRallyPoint = function(entities)
|
||||
*/
|
||||
GarrisonHolder.prototype.Unload = function(entity)
|
||||
{
|
||||
var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint);
|
||||
this.Eject(entity);
|
||||
this.OrderWalkToRallyPoint([entity]);
|
||||
this.UpdateGarrisonFlag();
|
||||
|
@ -473,7 +473,9 @@ function isIdleWorker(ent, idleClass)
|
||||
{
|
||||
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
var cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
|
||||
return (cmpUnitAI && cmpIdentity && cmpUnitAI.IsIdle() && idleClass && cmpIdentity.HasClass(idleClass));
|
||||
|
||||
// TODO: Do something with garrisoned idle units
|
||||
return (cmpUnitAI && cmpIdentity && cmpUnitAI.IsIdle() && !cmpUnitAI.IsGarrisoned() && idleClass && cmpIdentity.HasClass(idleClass));
|
||||
}
|
||||
|
||||
GuiInterface.prototype.FindIdleWorker = function(player, data)
|
||||
|
@ -967,7 +967,17 @@ var UnitFsmSpec = {
|
||||
},
|
||||
|
||||
"MoveCompleted": function() {
|
||||
this.SetNextState("GARRISONED");
|
||||
var cmpGarrisonHolder = Engine.QueryInterface(this.order.data.target, IID_GarrisonHolder);
|
||||
if (cmpGarrisonHolder && cmpGarrisonHolder.Garrison(this.entity))
|
||||
{
|
||||
this.SetNextState("GARRISONED");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.FinishOrder())
|
||||
return;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
"leave": function() {
|
||||
@ -977,18 +987,16 @@ var UnitFsmSpec = {
|
||||
|
||||
"GARRISONED": {
|
||||
"enter": function() {
|
||||
var cmpGarrisonHolder = Engine.QueryInterface(this.order.data.target, IID_GarrisonHolder);
|
||||
if (cmpGarrisonHolder)
|
||||
{
|
||||
cmpGarrisonHolder.Garrison(this.entity);
|
||||
|
||||
}
|
||||
this.isGarrisoned = true;
|
||||
},
|
||||
|
||||
"Order.Ungarrison": function() {
|
||||
if (this.FinishOrder())
|
||||
return;
|
||||
},
|
||||
|
||||
"leave": function() {
|
||||
|
||||
this.isGarrisoned = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -1193,6 +1201,7 @@ UnitAI.prototype.Init = function()
|
||||
this.orderQueue = []; // current order is at the front of the list
|
||||
this.order = undefined; // always == this.orderQueue[0]
|
||||
this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to
|
||||
this.isGarrisoned = false;
|
||||
this.isIdle = false;
|
||||
this.lastFormationName = "Line Closed";
|
||||
|
||||
@ -1227,6 +1236,11 @@ UnitAI.prototype.IsIdle = function()
|
||||
return this.isIdle;
|
||||
};
|
||||
|
||||
UnitAI.prototype.IsGarrisoned = function()
|
||||
{
|
||||
return this.isGarrisoned;
|
||||
};
|
||||
|
||||
UnitAI.prototype.OnCreate = function()
|
||||
{
|
||||
if (this.IsAnimal())
|
||||
@ -1939,6 +1953,14 @@ UnitAI.prototype.Garrison = function(target, queued)
|
||||
this.AddOrder("Garrison", { "target": target }, queued);
|
||||
};
|
||||
|
||||
UnitAI.prototype.Ungarrison = function()
|
||||
{
|
||||
if (this.IsGarrisoned())
|
||||
{
|
||||
this.AddOrder("Ungarrison", null, false);
|
||||
}
|
||||
};
|
||||
|
||||
UnitAI.prototype.Gather = function(target, queued)
|
||||
{
|
||||
if (!this.CanGather(target))
|
||||
|
Loading…
Reference in New Issue
Block a user