Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GarrisonHolder.js
Show First 20 Lines • Show All 178 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); | ||||
}; | }; | ||||
/** | /** | ||||
* @param {number} entity - The entity's id. | * @param {number} entity - The entity's id. | ||||
* @param {Object|undefined} visibleGarrisonPoint - The vgp object. | * @param {Object|undefined} visibleGarrisonPoint - The vgp object. | ||||
* @return {boolean} - Whether the unit is allowed be visible on that garrison point. | * @return {boolean} - Whether the unit is allowed be visible on that garrison point. | ||||
*/ | */ | ||||
GarrisonHolder.prototype.AllowedToVisibleGarrisoning = function(entity, visibleGarrisonPoint) | GarrisonHolder.prototype.AllowedToVisibleGarrisoning = function(entity, visibleGarrisonPoint) | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | "visible": { | ||||
[entity]: isVisiblyGarrisoned, | [entity]: isVisiblyGarrisoned, | ||||
} | } | ||||
}); | }); | ||||
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); | ||||
return true; | return true; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 70 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, { | Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { | ||||
"added": [], | "added": [], | ||||
"removed": [entity], | "removed": [entity], | ||||
"visible": visible | "visible": visible | ||||
}); | }); | ||||
return true; | return true; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 413 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This can be moved to cmpGarrisonable in a separate diff.