Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GarrisonHolder.js
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | GarrisonHolder.prototype.IsAllowedToGarrison = function(ent) | ||||
if (!IsOwnedByMutualAllyOfEntity(ent, this.entity)) | if (!IsOwnedByMutualAllyOfEntity(ent, this.entity)) | ||||
return false; | return false; | ||||
let cmpIdentity = Engine.QueryInterface(ent, IID_Identity); | let cmpIdentity = Engine.QueryInterface(ent, IID_Identity); | ||||
if (!cmpIdentity) | if (!cmpIdentity) | ||||
return false; | return false; | ||||
let entityClasses = cmpIdentity.GetClassesList(); | let entityClasses = cmpIdentity.GetClassesList(); | ||||
return MatchesClassList(entityClasses, this.template.List._string) && !!Engine.QueryInterface(ent, IID_Garrisonable); | return MatchesClassList(entityClasses, this.template.List._string); | ||||
}; | }; | ||||
/** | /** | ||||
* Garrison a unit inside. The timer for AutoHeal is started here. | * Garrison a unit inside. The timer for AutoHeal is started here. | ||||
* @param {number} vgpEntity - The visual garrison point that will be used. | * @param {number} vgpEntity - The visual garrison point that will be used. | ||||
* If vgpEntity is given, this visualGarrisonPoint will be used for the entity. | * If vgpEntity is given, this visualGarrisonPoint will be used for the entity. | ||||
* @return {boolean} Whether the entity was garrisonned. | * @return {boolean} Whether the entity was garrisonned. | ||||
*/ | */ | ||||
Show All 40 Lines | GarrisonHolder.prototype.Garrison = function(entity, vgpEntity) | ||||
} | } | ||||
else | else | ||||
cmpPosition.MoveOutOfWorld(); | cmpPosition.MoveOutOfWorld(); | ||||
return true; | return true; | ||||
}; | }; | ||||
/** | /** | ||||
* @return {boolean} Whether the entity was garrisonned. | * @param {number} entity - The entity ID to garrison. | ||||
* @return {boolean} - Whether the entity was garrisoned. | |||||
*/ | */ | ||||
GarrisonHolder.prototype.PerformGarrison = function(entity) | GarrisonHolder.prototype.PerformGarrison = function(entity) | ||||
{ | { | ||||
if (!this.HasEnoughHealth()) | if (!this.HasEnoughHealth()) | ||||
return false; | return false; | ||||
// Check if the unit is allowed to be garrisoned inside the building | let cmpGarrisonable = Engine.QueryInterface(entity, IID_Garrisonable); | ||||
if (!cmpGarrisonable) | |||||
return false; | |||||
// Check if the unit is allowed to be garrisoned inside the building. | |||||
if (!this.IsAllowedToGarrison(entity)) | if (!this.IsAllowedToGarrison(entity)) | ||||
return false; | return false; | ||||
// Check the capacity | // Check the capacity. | ||||
let extraCount = 0; | let extraCount = 0; | ||||
let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | ||||
if (cmpGarrisonHolder) | if (cmpGarrisonHolder) | ||||
extraCount += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); | extraCount += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); | ||||
if (this.GetGarrisonedEntitiesCount() + extraCount >= this.GetCapacity()) | if (this.GetGarrisonedEntitiesCount() + extraCount >= this.GetCapacity()) | ||||
return false; | return 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, {}); | ||||
} | } | ||||
// Actual garrisoning happens here | // Actual garrisoning happens here. | ||||
cmpGarrisonable.Garrison(this.entity); | |||||
this.entities.push(entity); | this.entities.push(entity); | ||||
this.UpdateGarrisonFlag(); | this.UpdateGarrisonFlag(); | ||||
let cmpProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); | let cmpProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); | ||||
if (cmpProductionQueue) | if (cmpProductionQueue) | ||||
cmpProductionQueue.PauseProduction(); | cmpProductionQueue.PauseProduction(); | ||||
Freagarach: This can be moved to `cmpGarrisonable` in a separate diff. | |||||
Done Inline ActionsThis kind of stuff looks like it should go in Garrisonable.Garrison. wraitii: This kind of stuff looks like it should go in Garrisonable.Garrison. | |||||
Done Inline ActionsFreagarach: D3223. | |||||
let cmpAura = Engine.QueryInterface(entity, IID_Auras); | let cmpAura = Engine.QueryInterface(entity, IID_Auras); | ||||
if (cmpAura && cmpAura.HasGarrisonAura()) | if (cmpAura && cmpAura.HasGarrisonAura()) | ||||
cmpAura.ApplyGarrisonAura(this.entity); | cmpAura.ApplyGarrisonAura(this.entity); | ||||
Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added": [entity], "removed": [] }); | Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added": [entity], "removed": [] }); | ||||
return true; | return true; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | GarrisonHolder.prototype.Eject = function(entity, forced) | ||||
cmpEntPosition.JumpTo(pos.x, pos.z); | cmpEntPosition.JumpTo(pos.x, pos.z); | ||||
cmpEntPosition.SetHeightOffset(0); | cmpEntPosition.SetHeightOffset(0); | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
cmpEntPosition.SetYRotation(cmpPosition.GetPosition().horizAngleTo(pos)); | 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] }); | Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added": [], "removed": [entity] }); | ||||
return true; | 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 | ||||
▲ Show 20 Lines • Show All 374 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This can be moved to cmpGarrisonable in a separate diff.