1
0
forked from 0ad/0ad

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:
historic_bruno 2011-05-11 04:05:05 +00:00
parent cda5c5f5c9
commit 025a00340e
3 changed files with 41 additions and 11 deletions

View File

@ -139,6 +139,13 @@ GarrisonHolder.prototype.Eject = function(entity)
var entityIndex = this.entities.indexOf(entity); var entityIndex = this.entities.indexOf(entity);
this.spaceOccupied -= 1; this.spaceOccupied -= 1;
this.entities.splice(entityIndex, 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 cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint);
var pos = cmpFootprint.PickSpawnPoint(entity); var pos = cmpFootprint.PickSpawnPoint(entity);
if (pos.y < 0) if (pos.y < 0)
@ -147,7 +154,7 @@ GarrisonHolder.prototype.Eject = function(entity)
// What should we do here? // What should we do here?
// For now, just move the unit into the middle of the building where it'll probably get stuck // For now, just move the unit into the middle of the building where it'll probably get stuck
pos = cmpPosition.GetPosition(); 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); var cmpNewPosition = Engine.QueryInterface(entity, IID_Position);
@ -184,7 +191,6 @@ GarrisonHolder.prototype.OrderWalkToRallyPoint = function(entities)
*/ */
GarrisonHolder.prototype.Unload = function(entity) GarrisonHolder.prototype.Unload = function(entity)
{ {
var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint);
this.Eject(entity); this.Eject(entity);
this.OrderWalkToRallyPoint([entity]); this.OrderWalkToRallyPoint([entity]);
this.UpdateGarrisonFlag(); this.UpdateGarrisonFlag();

View File

@ -473,7 +473,9 @@ function isIdleWorker(ent, idleClass)
{ {
var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 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) GuiInterface.prototype.FindIdleWorker = function(player, data)

View File

@ -967,7 +967,17 @@ var UnitFsmSpec = {
}, },
"MoveCompleted": function() { "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() { "leave": function() {
@ -977,18 +987,16 @@ var UnitFsmSpec = {
"GARRISONED": { "GARRISONED": {
"enter": function() { "enter": function() {
var cmpGarrisonHolder = Engine.QueryInterface(this.order.data.target, IID_GarrisonHolder); this.isGarrisoned = true;
if (cmpGarrisonHolder) },
{
cmpGarrisonHolder.Garrison(this.entity); "Order.Ungarrison": function() {
}
if (this.FinishOrder()) if (this.FinishOrder())
return; return;
}, },
"leave": function() { "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.orderQueue = []; // current order is at the front of the list
this.order = undefined; // always == this.orderQueue[0] this.order = undefined; // always == this.orderQueue[0]
this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to
this.isGarrisoned = false;
this.isIdle = false; this.isIdle = false;
this.lastFormationName = "Line Closed"; this.lastFormationName = "Line Closed";
@ -1227,6 +1236,11 @@ UnitAI.prototype.IsIdle = function()
return this.isIdle; return this.isIdle;
}; };
UnitAI.prototype.IsGarrisoned = function()
{
return this.isGarrisoned;
};
UnitAI.prototype.OnCreate = function() UnitAI.prototype.OnCreate = function()
{ {
if (this.IsAnimal()) if (this.IsAnimal())
@ -1939,6 +1953,14 @@ UnitAI.prototype.Garrison = function(target, queued)
this.AddOrder("Garrison", { "target": 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) UnitAI.prototype.Gather = function(target, queued)
{ {
if (!this.CanGather(target)) if (!this.CanGather(target))