mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 22:03:56 -07:00
Provide a TriggerHelper function to spawn garrisoned entities
Differential Revision: https://code.wildfiregames.com/D1146 This was SVN commit r20659.
This commit is contained in:
parent
a5a1909bd3
commit
e29dfb7000
1 changed files with 42 additions and 0 deletions
|
|
@ -79,6 +79,48 @@ TriggerHelper.SpawnUnits = function(source, template, count, owner)
|
|||
return entities;
|
||||
};
|
||||
|
||||
/**
|
||||
* Can be used to spawn garrisoned units inside a building/ship.
|
||||
*
|
||||
* @param entity Entity id of the garrison holder in which units will be garrisoned
|
||||
* @param template Name of the template
|
||||
* @param count Number of units to spawn
|
||||
* @param owner Player id of the owner of the new units. By default, the owner
|
||||
* of the garrisonholder entity.
|
||||
*/
|
||||
TriggerHelper.SpawnGarrisonedUnits = function(entity, template, count, owner)
|
||||
{
|
||||
let entities = [];
|
||||
let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder);
|
||||
|
||||
if (!cmpGarrisonHolder)
|
||||
{
|
||||
error("tried to create garrisoned entities inside a non-garrisonholder");
|
||||
return entities;
|
||||
}
|
||||
|
||||
if (owner == null)
|
||||
owner = TriggerHelper.GetOwner(entity);
|
||||
|
||||
for (let i = 0; i < count; ++i)
|
||||
{
|
||||
let ent = Engine.AddEntity(template);
|
||||
let cmpOwnership = Engine.QueryInterface(ent, IID_Ownership);
|
||||
if (cmpOwnership)
|
||||
cmpOwnership.SetOwner(owner);
|
||||
if (cmpGarrisonHolder.PerformGarrison(ent))
|
||||
{
|
||||
if (Engine.QueryInterface(ent, IID_UnitAI))
|
||||
Engine.QueryInterface(ent, IID_UnitAI).Autogarrison(entity);
|
||||
entities.push(ent);
|
||||
}
|
||||
else
|
||||
error("failed to garrison entity " + template + " inside " + entity);
|
||||
}
|
||||
|
||||
return entities;
|
||||
};
|
||||
|
||||
/**
|
||||
* Spawn units from all trigger points with this reference
|
||||
* If player is defined, only spaw units from the trigger points
|
||||
|
|
|
|||
Loading…
Reference in a new issue