Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Garrisonable.js
Show All 39 Lines | |||||
* @return {number} - The entity ID of the entity this entity is garrisoned in. | * @return {number} - The entity ID of the entity this entity is garrisoned in. | ||||
*/ | */ | ||||
Garrisonable.prototype.HolderID = function() | Garrisonable.prototype.HolderID = function() | ||||
{ | { | ||||
return this.holder || INVALID_ENTITY; | return this.holder || INVALID_ENTITY; | ||||
}; | }; | ||||
/** | /** | ||||
* @return {boolean} - Whether this entity is garrisoned. | |||||
*/ | |||||
Garrisonable.prototype.IsGarrisoned = function() | |||||
{ | |||||
return !!this.holder; | |||||
}; | |||||
/** | |||||
* @param {number} - The entity ID to check. | * @param {number} - The entity ID to check. | ||||
* @return {boolean} - Whether we can garrison. | * @return {boolean} - Whether we can garrison. | ||||
*/ | */ | ||||
Garrisonable.prototype.CanGarrison = function(entity) | Garrisonable.prototype.CanGarrison = function(entity) | ||||
{ | { | ||||
let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | ||||
return cmpGarrisonHolder && cmpGarrisonHolder.IsAllowedToGarrison(this.entity); | return cmpGarrisonHolder && cmpGarrisonHolder.IsAllowedToGarrison(this.entity); | ||||
}; | }; | ||||
/** | /** | ||||
* @param {number} entity - The entity ID of the entity this entity is being garrisoned in. | * @param {number} entity - The entity ID of the entity this entity is being garrisoned in. | ||||
* @return {boolean} - Whether garrisoning succeeded. | * @return {boolean} - Whether garrisoning succeeded. | ||||
*/ | */ | ||||
Garrisonable.prototype.Garrison = function(entity, renamed = false) | Garrisonable.prototype.Garrison = function(entity, renamed = false) | ||||
{ | { | ||||
if (this.holder) | if (this.holder) | ||||
return false; | return false; | ||||
let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); | ||||
if (!cmpGarrisonHolder || !cmpGarrisonHolder.Garrison(this.entity)) | if (!cmpGarrisonHolder || !cmpGarrisonHolder.Garrison(this.entity)) | ||||
return false; | return false; | ||||
this.holder = entity; | this.holder = entity; | ||||
let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | |||||
if (cmpUnitAI) | |||||
cmpUnitAI.SetGarrisoned(); | |||||
let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); | let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); | ||||
if (cmpProductionQueue) | if (cmpProductionQueue) | ||||
cmpProductionQueue.PauseProduction(); | cmpProductionQueue.PauseProduction(); | ||||
let cmpAura = Engine.QueryInterface(this.entity, IID_Auras); | let cmpAura = Engine.QueryInterface(this.entity, IID_Auras); | ||||
if (cmpAura && cmpAura.HasGarrisonAura()) | if (cmpAura && cmpAura.HasGarrisonAura()) | ||||
cmpAura.ApplyGarrisonAura(entity); | cmpAura.ApplyGarrisonAura(entity); | ||||
Show All 31 Lines | |||||
* @param {boolean} forced - Optionally whether the spawning is forced. | * @param {boolean} forced - Optionally whether the spawning is forced. | ||||
* @param {boolean} renamed - Optionally whether the ungarrisoning is due to renaming. | * @param {boolean} renamed - Optionally whether the ungarrisoning is due to renaming. | ||||
* @return {boolean} - Whether the ungarrisoning succeeded. | * @return {boolean} - Whether the ungarrisoning succeeded. | ||||
*/ | */ | ||||
Garrisonable.prototype.UnGarrison = function(forced = false, renamed = false) | Garrisonable.prototype.UnGarrison = function(forced = false, renamed = false) | ||||
{ | { | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
{ | { | ||||
Stan: Maybe make it one function with a boolean param? | |||||
Done Inline ActionsI like to have explicit function names, but I can change this one if you think it is better? Freagarach: I like to have explicit function names, but I can change this one if you think it is better? | |||||
Done Inline ActionsI've personally sided with 'the duplication is acceptable here', make of that what you want :p wraitii: I've personally sided with 'the duplication is acceptable here', make of that what you want :p | |||||
let pos; | let pos; | ||||
let cmpGarrisonHolder = Engine.QueryInterface(this.holder, IID_GarrisonHolder); | let cmpGarrisonHolder = Engine.QueryInterface(this.holder, IID_GarrisonHolder); | ||||
if (cmpGarrisonHolder) | if (cmpGarrisonHolder) | ||||
pos = cmpGarrisonHolder.GetSpawnPosition(this.entity, forced); | pos = cmpGarrisonHolder.GetSpawnPosition(this.entity, forced); | ||||
if (!pos) | if (!pos) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Maybe make it one function with a boolean param?