Differential D3223 Diff 16124 ps/trunk/binaries/data/mods/public/simulation/components/GarrisonHolder.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/GarrisonHolder.js
Show First 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | GarrisonHolder.prototype.Garrison = function(entity, renamed = false) | ||||
if (!this.timer && this.GetHealRate() > 0) | if (!this.timer && this.GetHealRate() > 0) | ||||
{ | { | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); | this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); | ||||
} | } | ||||
this.entities.push(entity); | this.entities.push(entity); | ||||
this.UpdateGarrisonFlag(); | this.UpdateGarrisonFlag(); | ||||
let cmpProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); | |||||
if (cmpProductionQueue) | |||||
cmpProductionQueue.PauseProduction(); | |||||
let cmpAura = Engine.QueryInterface(entity, IID_Auras); | |||||
if (cmpAura && cmpAura.HasGarrisonAura()) | |||||
cmpAura.ApplyGarrisonAura(this.entity); | |||||
let cmpPosition = Engine.QueryInterface(entity, IID_Position); | |||||
if (cmpPosition) | |||||
cmpPosition.MoveOutOfWorld(); | |||||
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { | Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { | ||||
"added": [entity], | "added": [entity], | ||||
"removed": [], | "removed": [], | ||||
"renamed": renamed | "renamed": renamed | ||||
}); | }); | ||||
return true; | return true; | ||||
Show All 9 Lines | |||||
*/ | */ | ||||
GarrisonHolder.prototype.Eject = function(entity, forced, renamed = false) | GarrisonHolder.prototype.Eject = function(entity, forced, renamed = false) | ||||
{ | { | ||||
let entityIndex = this.entities.indexOf(entity); | let entityIndex = this.entities.indexOf(entity); | ||||
// Error: invalid entity ID, usually it's already been ejected | // Error: invalid entity ID, usually it's already been ejected | ||||
if (entityIndex == -1) | if (entityIndex == -1) | ||||
return false; | return false; | ||||
// Find spawning location | let cmpGarrisonable = Engine.QueryInterface(entity, IID_Garrisonable); | ||||
if (!cmpGarrisonable || !cmpGarrisonable.UnGarrison(forced)) | |||||
return false; | |||||
this.entities.splice(entityIndex, 1); | |||||
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { | |||||
"added": [], | |||||
"removed": [entity], | |||||
"renamed": renamed | |||||
}); | |||||
return true; | |||||
}; | |||||
/** | |||||
* @param {number} entity - EntityID to find the spawn position for. | |||||
* @param {boolean} forced - Optionally whether the spawning is forced. | |||||
* @return {Vector3D} - An appropriate spawning position. | |||||
*/ | |||||
GarrisonHolder.prototype.GetSpawnPosition = function(entity, forced) | |||||
{ | |||||
let cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint); | let cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint); | ||||
let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | ||||
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); | ||||
// If the garrisonHolder is a sinking ship, restrict the location to the intersection of both passabilities | // If the garrisonHolder is a sinking ship, restrict the location to the intersection of both passabilities | ||||
// TODO: should use passability classes to be more generic | // TODO: should use passability classes to be more generic | ||||
let pos; | let pos; | ||||
if ((!cmpHealth || cmpHealth.GetHitpoints() == 0) && cmpIdentity && cmpIdentity.HasClass("Ship")) | if ((!cmpHealth || cmpHealth.GetHitpoints() == 0) && cmpIdentity && cmpIdentity.HasClass("Ship")) | ||||
pos = cmpFootprint.PickSpawnPointBothPass(entity); | pos = cmpFootprint.PickSpawnPointBothPass(entity); | ||||
else | else | ||||
pos = cmpFootprint.PickSpawnPoint(entity); | pos = cmpFootprint.PickSpawnPoint(entity); | ||||
if (pos.y < 0) | if (pos.y < 0) | ||||
{ | { | ||||
// Error: couldn't find space satisfying the unit's passability criteria | // Error: couldn't find space satisfying the unit's passability criteria | ||||
if (!forced) | if (!forced) | ||||
return false; | return null; | ||||
// If ejection is forced, we need to continue, so use center of the building | // If ejection is forced, we need to continue, so use center of the building | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
pos = cmpPosition.GetPosition(); | pos = cmpPosition.GetPosition(); | ||||
} | } | ||||
return pos; | |||||
this.entities.splice(entityIndex, 1); | |||||
let cmpEntUnitAI = Engine.QueryInterface(entity, IID_UnitAI); | |||||
if (cmpEntUnitAI) | |||||
cmpEntUnitAI.Ungarrison(); | |||||
let cmpEntProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); | |||||
if (cmpEntProductionQueue) | |||||
cmpEntProductionQueue.UnpauseProduction(); | |||||
let cmpEntAura = Engine.QueryInterface(entity, IID_Auras); | |||||
if (cmpEntAura && cmpEntAura.HasGarrisonAura()) | |||||
cmpEntAura.RemoveGarrisonAura(this.entity); | |||||
let cmpEntPosition = Engine.QueryInterface(entity, IID_Position); | |||||
if (cmpEntPosition) | |||||
{ | |||||
cmpEntPosition.JumpTo(pos.x, pos.z); | |||||
cmpEntPosition.SetHeightOffset(0); | |||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | |||||
if (cmpPosition) | |||||
cmpEntPosition.SetYRotation(cmpPosition.GetPosition().horizAngleTo(pos)); | |||||
} | |||||
let cmpGarrisonable = Engine.QueryInterface(entity, IID_Garrisonable); | |||||
if (cmpGarrisonable) | |||||
cmpGarrisonable.UnGarrison(); | |||||
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { | |||||
"added": [], | |||||
"removed": [entity], | |||||
"renamed": renamed | |||||
}); | |||||
return true; | |||||
}; | }; | ||||
/** | /** | ||||
* Ejects units and orders them to move to the rally point. If an ejection | * Ejects units and orders them to move to the rally point. If an ejection | ||||
* with a given obstruction radius has failed, we won't try anymore to eject | * with a given obstruction radius has failed, we won't try anymore to eject | ||||
* entities with a bigger obstruction as that is compelled to also fail. | * entities with a bigger obstruction as that is compelled to also fail. | ||||
* @param {Array} entities - An array containing the ids of the entities to eject. | * @param {Array} entities - An array containing the ids of the entities to eject. | ||||
* @param {boolean} forced - Whether eject is forced (ie: if building is destroyed). | * @param {boolean} forced - Whether eject is forced (ie: if building is destroyed). | ||||
▲ Show 20 Lines • Show All 401 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator