Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/GarrisonHolder.js
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | GarrisonHolder.prototype.Init = function() | ||||
this.timer = undefined; | this.timer = undefined; | ||||
this.allowGarrisoning = new Map(); | this.allowGarrisoning = new Map(); | ||||
this.visibleGarrisonPoints = []; | this.visibleGarrisonPoints = []; | ||||
if (this.template.VisibleGarrisonPoints) | if (this.template.VisibleGarrisonPoints) | ||||
{ | { | ||||
let points = this.template.VisibleGarrisonPoints; | let points = this.template.VisibleGarrisonPoints; | ||||
for (let point in points) | for (let point in points) | ||||
this.visibleGarrisonPoints.push({ | this.visibleGarrisonPoints.push({ | ||||
"name": point, | |||||
"offset": { | "offset": { | ||||
"x": +points[point].X, | "x": +points[point].X, | ||||
"y": +points[point].Y, | "y": +points[point].Y, | ||||
"z": +points[point].Z | "z": +points[point].Z | ||||
}, | }, | ||||
"angle": points[point].Angle ? +points[point].Angle * Math.PI / 180 : null, | "angle": points[point].Angle ? +points[point].Angle * Math.PI / 180 : null, | ||||
"entity": null | "entity": null | ||||
}); | }); | ||||
Show All 17 Lines | |||||
}; | }; | ||||
GarrisonHolder.prototype.GetEntities = function() | GarrisonHolder.prototype.GetEntities = function() | ||||
{ | { | ||||
return this.entities; | return this.entities; | ||||
}; | }; | ||||
/** | /** | ||||
* Get the visible garrison point an entity occupies. | |||||
* | |||||
* @param {number} entity - The entity ID of the entity to check. | |||||
* | |||||
bb: lowercase `s` afaik | |||||
* @return {String} - The name of the visibly garrison point this entity occupies. | |||||
*/ | |||||
GarrisonHolder.prototype.GetVisibleGarrisonPoint = function(entity) | |||||
{ | |||||
if (!this.visibleGarrisonPoints.length) | |||||
Not Done Inline ActionsWhy do we need this check? bb: Why do we need this check? | |||||
return ""; | |||||
Not Done Inline Actionsin case we can't find a vgp with the wanted condition, we will error out, no? bb: in case we can't find a vgp with the wanted condition, we will error out, no? | |||||
return this.visibleGarrisonPoints.find(vgp => vgp.entity == entity).name || ""; | |||||
}; | |||||
/** | |||||
* @return {Array} unit classes which can be garrisoned inside this | * @return {Array} unit classes which can be garrisoned inside this | ||||
* particular entity. Obtained from the entity's template. | * particular entity. Obtained from the entity's template. | ||||
*/ | */ | ||||
GarrisonHolder.prototype.GetAllowedClasses = function() | GarrisonHolder.prototype.GetAllowedClasses = function() | ||||
{ | { | ||||
return this.template.List._string; | return this.template.List._string; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 569 Lines • ▼ Show 20 Lines | GarrisonHolder.prototype.IsEjectable = function(entity) | ||||
let ejectableClasses = this.template.EjectClassesOnDestroy._string; | let ejectableClasses = this.template.EjectClassesOnDestroy._string; | ||||
let entityClasses = Engine.QueryInterface(entity, IID_Identity).GetClassesList(); | let entityClasses = Engine.QueryInterface(entity, IID_Identity).GetClassesList(); | ||||
return MatchesClassList(entityClasses, ejectableClasses); | return MatchesClassList(entityClasses, ejectableClasses); | ||||
}; | }; | ||||
/** | /** | ||||
* Sets the intitGarrison to the specified entities. Used by the mapreader. | |||||
* | |||||
* @param {number} entity - An entity ID to garrison on init. | |||||
*/ | |||||
GarrisonHolder.prototype.AddInitGarrisonEntity = function(entity) | |||||
{ | |||||
if (!this.initGarrison) | |||||
this.initGarrison = []; | |||||
this.initGarrison.push(entity); | |||||
}; | |||||
/** | |||||
* Initialise the garrisoned units. | * Initialise the garrisoned units. | ||||
*/ | */ | ||||
GarrisonHolder.prototype.OnGlobalInitGame = function(msg) | GarrisonHolder.prototype.OnGlobalInitGame = function(msg) | ||||
{ | { | ||||
if (!this.initGarrison) | if (!this.initGarrison || !this.initGarrison.length) | ||||
return; | return; | ||||
for (let ent of this.initGarrison) | for (let ent of this.initGarrison) | ||||
{ | { | ||||
let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
if (cmpUnitAI && cmpUnitAI.CanGarrison(this.entity) && this.Garrison(ent)) | if (cmpUnitAI && cmpUnitAI.CanGarrison(this.entity) && this.Garrison(ent)) | ||||
cmpUnitAI.Autogarrison(this.entity); | cmpUnitAI.Autogarrison(this.entity); | ||||
} | } | ||||
Show All 23 Lines |
Wildfire Games · Phabricator
lowercase s afaik