Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GarrisonHolder.js
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | GarrisonHolder.prototype.IsAllowedToGarrison = function(entity) | ||||
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; | ||||
let cmpIdentity = Engine.QueryInterface(entity, IID_Identity); | let cmpIdentity = Engine.QueryInterface(entity, IID_Identity); | ||||
if (!cmpIdentity) | return cmpIdentity && | ||||
return false; | MatchesClassList(cmpIdentity.GetClassesList(), this.allowedClasses); | ||||
let entityClasses = cmpIdentity.GetClassesList(); | |||||
return MatchesClassList(entityClasses, this.allowedClasses) && !!Engine.QueryInterface(entity, IID_Garrisonable); | |||||
}; | }; | ||||
/** | /** | ||||
* @param {number} entity - The entityID to garrison. | * @param {number} entity - The entityID to garrison. | ||||
* @param {boolean} renamed - Whether the entity was renamed. | * @param {boolean} renamed - Whether the entity was renamed. | ||||
* | * | ||||
* @return {boolean} - Whether the entity was garrisoned. | * @return {boolean} - Whether the entity was garrisoned. | ||||
*/ | */ | ||||
GarrisonHolder.prototype.Garrison = function(entity, renamed = false) | GarrisonHolder.prototype.Garrison = function(entity, renamed = false) | ||||
{ | { | ||||
if (!this.IsAllowedToGarrison(entity)) | if (!this.IsAllowedToGarrison(entity)) | ||||
return false; | return false; | ||||
if (!this.HasEnoughHealth()) | if (!this.HasEnoughHealth()) | ||||
return false; | return false; | ||||
let cmpGarrisonable = Engine.QueryInterface(entity, IID_Garrisonable); | |||||
if (!cmpGarrisonable || !cmpGarrisonable.Garrison(this.entity)) | |||||
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, {}); | ||||
} | } | ||||
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); | ||||
let cmpPosition = Engine.QueryInterface(entity, IID_Position); | let cmpPosition = Engine.QueryInterface(entity, IID_Position); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
cmpPosition.MoveOutOfWorld(); | cmpPosition.MoveOutOfWorld(); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if (cmpEntPosition) | ||||
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, { | Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { | ||||
"added": [], | "added": [], | ||||
"removed": [entity], | "removed": [entity], | ||||
"renamed": renamed | "renamed": renamed | ||||
}); | }); | ||||
return true; | return true; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 408 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This can be moved to cmpGarrisonable in a separate diff.