forked from 0ad/0ad
Makes AIProxy keep the garrisoned units array up to date. Fixes #1019
This was SVN commit r10531.
This commit is contained in:
parent
ade841efdd
commit
5ae93ddae7
@ -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()
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
@ -272,6 +275,7 @@ GarrisonHolder.prototype.OnHealthChanged = function(msg)
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user