Differential D3628 Diff 16325 ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
Show First 20 Lines • Show All 694 Lines • ▼ Show 20 Lines | ProductionQueue.prototype.SpawnUnits = function(templateName, count, metadata) | ||||
let spawnedEnts = []; | let spawnedEnts = []; | ||||
// We need entities to test spawning, but we don't want to waste resources, | // We need entities to test spawning, but we don't want to waste resources, | ||||
// so only create them once and use as needed. | // so only create them once and use as needed. | ||||
if (!this.entityCache.length) | if (!this.entityCache.length) | ||||
for (let i = 0; i < count; ++i) | for (let i = 0; i < count; ++i) | ||||
this.entityCache.push(Engine.AddEntity(templateName)); | this.entityCache.push(Engine.AddEntity(templateName)); | ||||
let cmpAutoGarrison; | let autoGarrison; | ||||
if (cmpRallyPoint) | if (cmpRallyPoint) | ||||
{ | { | ||||
let data = cmpRallyPoint.GetData()[0]; | let data = cmpRallyPoint.GetData()[0]; | ||||
if (data && data.target && data.target == this.entity && data.command == "garrison") | if (data && data.target && data.target == this.entity && data.command == "garrison") | ||||
cmpAutoGarrison = Engine.QueryInterface(this.entity, IID_GarrisonHolder); | autoGarrison = true; | ||||
} | } | ||||
for (let i = 0; i < count; ++i) | for (let i = 0; i < count; ++i) | ||||
{ | { | ||||
let ent = this.entityCache[0]; | let ent = this.entityCache[0]; | ||||
let cmpNewOwnership = Engine.QueryInterface(ent, IID_Ownership); | let cmpNewOwnership = Engine.QueryInterface(ent, IID_Ownership); | ||||
let garrisoned = false; | let garrisoned = false; | ||||
if (cmpAutoGarrison) | if (autoGarrison) | ||||
{ | { | ||||
let cmpGarrisonable = Engine.QueryInterface(ent, IID_Garrisonable); | |||||
// Temporary owner affectation needed for GarrisonHolder checks. | // Temporary owner affectation needed for GarrisonHolder checks. | ||||
cmpNewOwnership.SetOwnerQuiet(cmpOwnership.GetOwner()); | cmpNewOwnership.SetOwnerQuiet(cmpOwnership.GetOwner()); | ||||
garrisoned = cmpAutoGarrison.Garrison(ent); | garrisoned = cmpGarrisonable && cmpGarrisonable.Autogarrison(this.entity); | ||||
cmpNewOwnership.SetOwnerQuiet(INVALID_PLAYER); | cmpNewOwnership.SetOwnerQuiet(INVALID_PLAYER); | ||||
} | } | ||||
if (garrisoned) | if (!garrisoned) | ||||
{ | |||||
let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | |||||
if (cmpUnitAI) | |||||
cmpUnitAI.Autogarrison(this.entity); | |||||
} | |||||
else | |||||
{ | { | ||||
let pos = cmpFootprint.PickSpawnPoint(ent); | let pos = cmpFootprint.PickSpawnPoint(ent); | ||||
if (pos.y < 0) | if (pos.y < 0) | ||||
break; | break; | ||||
let cmpNewPosition = Engine.QueryInterface(ent, IID_Position); | let cmpNewPosition = Engine.QueryInterface(ent, IID_Position); | ||||
cmpNewPosition.JumpTo(pos.x, pos.z); | cmpNewPosition.JumpTo(pos.x, pos.z); | ||||
Show All 21 Lines | for (let i = 0; i < count; ++i) | ||||
// Play a sound, but only for the first in the batch (to avoid nasty phasing effects). | // Play a sound, but only for the first in the batch (to avoid nasty phasing effects). | ||||
if (!createdEnts.length) | if (!createdEnts.length) | ||||
PlaySound("trained", ent); | PlaySound("trained", ent); | ||||
this.entityCache.shift(); | this.entityCache.shift(); | ||||
createdEnts.push(ent); | createdEnts.push(ent); | ||||
} | } | ||||
if (spawnedEnts.length && !cmpAutoGarrison) | if (spawnedEnts.length && !autoGarrison) | ||||
{ | { | ||||
// If a rally point is set, walk towards it (in formation) using a suitable command based on where the | // If a rally point is set, walk towards it (in formation) using a suitable command based on where the | ||||
// rally point is placed. | // rally point is placed. | ||||
if (cmpRallyPoint) | if (cmpRallyPoint) | ||||
{ | { | ||||
let rallyPos = cmpRallyPoint.GetPositions()[0]; | let rallyPos = cmpRallyPoint.GetPositions()[0]; | ||||
if (rallyPos) | if (rallyPos) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 224 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator