forked from 0ad/0ad
allow maps to handle garrisoned units, fixes #2984
This was SVN commit r16147.
This commit is contained in:
parent
f2d71164e6
commit
702fb7344e
@ -53,6 +53,9 @@ GarrisonHolder.prototype.Schema =
|
||||
|
||||
/**
|
||||
* Initialize GarrisonHolder Component
|
||||
*
|
||||
* Garrisoning when loading a map is set in the script of the map, by setting initGarrison
|
||||
* which should contain the array of garrisoned entities
|
||||
*/
|
||||
GarrisonHolder.prototype.Init = function()
|
||||
{
|
||||
@ -296,7 +299,6 @@ GarrisonHolder.prototype.PerformGarrison = function(entity)
|
||||
*/
|
||||
GarrisonHolder.prototype.Eject = function(entity, forced)
|
||||
{
|
||||
|
||||
var entityIndex = this.entities.indexOf(entity);
|
||||
// Error: invalid entity ID, usually it's already been ejected
|
||||
if (entityIndex == -1)
|
||||
@ -632,6 +634,23 @@ GarrisonHolder.prototype.OnGlobalEntityRenamed = function(msg)
|
||||
this.Eject(msg.entity);
|
||||
this.Garrison(msg.newentity);
|
||||
}
|
||||
|
||||
if (!this.initGarrison)
|
||||
return;
|
||||
|
||||
// update the pre-game garrison because of SkirmishReplacement
|
||||
if (msg.entity == this.entity)
|
||||
{
|
||||
let cmpGarrisonHolder = Engine.QueryInterface(msg.newentity, IID_GarrisonHolder);
|
||||
if (cmpGarrisonHolder)
|
||||
cmpGarrisonHolder.initGarrison = this.initGarrison;
|
||||
}
|
||||
else
|
||||
{
|
||||
let entityIndex = this.initGarrison.indexOf(msg.entity);
|
||||
if (entityIndex != -1)
|
||||
this.initGarrison[entityIndex] = msg.newentity;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -697,5 +716,23 @@ GarrisonHolder.prototype.IsEjectable = function(entity)
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise the garrisoned units
|
||||
*/
|
||||
GarrisonHolder.prototype.OnGlobalInitGame = function(msg)
|
||||
{
|
||||
if (!this.initGarrison)
|
||||
return;
|
||||
|
||||
for (let ent of this.initGarrison)
|
||||
{
|
||||
let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
|
||||
if (!cmpUnitAI || !cmpUnitAI.CanGarrison(this.entity))
|
||||
continue;
|
||||
this.Garrison(ent);
|
||||
}
|
||||
this.initGarrison = undefined;
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_GarrisonHolder, "GarrisonHolder", GarrisonHolder);
|
||||
|
||||
|
@ -13,3 +13,6 @@ Engine.RegisterMessageType("DiplomacyChanged");
|
||||
// Message of the form { "to": receiver, "from": sender, "amounts": amounts }.
|
||||
// sent whenever a tribute is sent
|
||||
Engine.RegisterMessageType("TributeExchanged");
|
||||
|
||||
// Message sent by InitGame for component map-dependent initialization
|
||||
Engine.RegisterMessageType("InitGame");
|
||||
|
@ -27,6 +27,9 @@ function PreInitGame()
|
||||
|
||||
function InitGame(settings)
|
||||
{
|
||||
// Map dependent initialisations of components (i.e. garrisoned units)
|
||||
Engine.BroadcastMessage(MT_InitGame, {});
|
||||
|
||||
// No settings when loading a map in Atlas, so do nothing
|
||||
if (!settings)
|
||||
return;
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Entity parent="template_unit_mechanical_ship_trireme">
|
||||
<Identity>
|
||||
<Civ>skirm</Civ>
|
||||
</Identity>
|
||||
<SkirmishReplacer>
|
||||
<general>units/{civ}_ship_trireme</general>
|
||||
</SkirmishReplacer>
|
||||
<VisualActor>
|
||||
<Actor>structures/athenians/trireme.xml</Actor>
|
||||
</VisualActor>
|
||||
</Entity>
|
Loading…
Reference in New Issue
Block a user