Makes AIProxy keep the garrisoned units array up to date. Fixes #1019

This was SVN commit r10531.
This commit is contained in:
Jonathan Waller 2011-11-13 23:23:58 +00:00
parent ade841efdd
commit 5ae93ddae7
3 changed files with 22 additions and 1 deletions

View File

@ -113,6 +113,14 @@ AIProxy.prototype.OnTrainingQueueChanged = function(msg)
this.changes.trainingQueue = cmpTrainingQueue.GetQueue();
}
AIProxy.prototype.OnGarrisonedUnitsChanged = function(msg)
{
this.NotifyChange();
var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder);
this.changes.garrisoned = cmpGarrisonHolder.GetEntities();
}
// TODO: event handlers for all the other things
AIProxy.prototype.GetFullRepresentation = function()

View File

@ -125,6 +125,7 @@ GarrisonHolder.prototype.Garrison = function(entity)
this.spaceOccupied += 1;
cmpPosition.MoveOutOfWorld();
this.UpdateGarrisonFlag();
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
return true;
}
return false;
@ -173,6 +174,8 @@ GarrisonHolder.prototype.Eject = function(entity, forced)
cmpNewPosition.JumpTo(pos.x, pos.z);
// TODO: what direction should they face in?
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
return true;
};
@ -271,7 +274,8 @@ GarrisonHolder.prototype.OnHealthChanged = function(msg)
cmpHealth.Kill();
}
}
this.entities = [];
this.entities = [];
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
}
else
{ // Building - force ejection
@ -360,6 +364,7 @@ GarrisonHolder.prototype.OnGlobalOwnershipChanged = function(msg)
if (cmpHealth && cmpHealth.GetHitpoints() == 0)
{
this.entities.splice(entityIndex, 1);
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
}
else
{
@ -375,6 +380,7 @@ GarrisonHolder.prototype.OnGlobalOwnershipChanged = function(msg)
cmpHealth.Kill();
}
this.entities.splice(entityIndex, 1);
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
}
else
{ // Building - force ejection
@ -393,7 +399,9 @@ GarrisonHolder.prototype.OnGlobalEntityRenamed = function(msg)
if (entityIndex != -1)
{
this.entities[entityIndex] = msg.newentity;
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {});
}
};
Engine.RegisterComponentType(IID_GarrisonHolder, "GarrisonHolder", GarrisonHolder);

View File

@ -1 +1,6 @@
Engine.RegisterInterface("GarrisonHolder");
// Message of the form { } (use GetEntities if you want the current details),
// sent to the current entity whenever the garrisoned units change.
Engine.RegisterMessageType("GarrisonedUnitsChanged");