Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Turretable.js
Show All 18 Lines | |||||
* @return {boolean} - Whether we're turreted. | * @return {boolean} - Whether we're turreted. | ||||
*/ | */ | ||||
Turretable.prototype.IsTurreted = function() | Turretable.prototype.IsTurreted = function() | ||||
{ | { | ||||
return !!this.holder; | return !!this.holder; | ||||
}; | }; | ||||
/** | /** | ||||
* @return {boolean} - Whether we can leave the turret point. | |||||
*/ | |||||
Turretable.prototype.IsEjectable = function() | |||||
{ | |||||
return this.ejectable; | |||||
}; | |||||
/** | |||||
* @param {number} target - The entity ID to check. | * @param {number} target - The entity ID to check. | ||||
* @return {boolean} - Whether we can occupy the turret. | * @return {boolean} - Whether we can occupy the turret. | ||||
*/ | */ | ||||
Turretable.prototype.CanOccupy = function(target) | Turretable.prototype.CanOccupy = function(target) | ||||
{ | { | ||||
if (this.holder) | if (this.holder) | ||||
return false; | return false; | ||||
let cmpTurretHolder = Engine.QueryInterface(target, IID_TurretHolder); | let cmpTurretHolder = Engine.QueryInterface(target, IID_TurretHolder); | ||||
return cmpTurretHolder && cmpTurretHolder.CanOccupy(this.entity); | return cmpTurretHolder && cmpTurretHolder.CanOccupy(this.entity); | ||||
}; | }; | ||||
/** | /** | ||||
* @param {number} target - The entity ID of the entity this entity is being turreted on. | * @param {number} target - The entity ID of the entity this entity is being turreted on. | ||||
* @param {string} turretPointName - Optionally the turret point name to occupy. | * @param {string} turretPointName - Optionally the turret point name to occupy. | ||||
* @param {boolean} ejectable - Whether we can leave this turret point (e.g. false for a tank turret). | |||||
* | |||||
* @return {boolean} - Whether occupying succeeded. | * @return {boolean} - Whether occupying succeeded. | ||||
*/ | */ | ||||
Turretable.prototype.OccupyTurret = function(target, turretPointName = "") | Turretable.prototype.OccupyTurret = function(target, turretPointName = "", ejectabe = true) | ||||
wraitii: typo | |||||
{ | { | ||||
if (!this.CanOccupy(target)) | if (!this.CanOccupy(target)) | ||||
return false; | return false; | ||||
let cmpTurretHolder = Engine.QueryInterface(target, IID_TurretHolder); | let cmpTurretHolder = Engine.QueryInterface(target, IID_TurretHolder); | ||||
if (!cmpTurretHolder || !cmpTurretHolder.OccupyNamedTurret(this.entity, turretPointName)) | if (!cmpTurretHolder || !cmpTurretHolder.OccupyNamedTurretPoint(this.entity, turretPointName)) | ||||
return false; | return false; | ||||
this.holder = target; | this.holder = target; | ||||
this.ejectable = ejectabe; | |||||
let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); | ||||
if (cmpUnitAI) | if (cmpUnitAI) | ||||
{ | { | ||||
cmpUnitAI.SetGarrisoned(); | cmpUnitAI.SetGarrisoned(); | ||||
cmpUnitAI.SetTurretStance(); | cmpUnitAI.SetTurretStance(); | ||||
} | } | ||||
Show All 18 Lines | |||||
* @param {boolean} forced - Optionally whether the leaving the turret is forced. | * @param {boolean} forced - Optionally whether the leaving the turret is forced. | ||||
* @return {boolean} - Whether leaving the turret succeeded. | * @return {boolean} - Whether leaving the turret succeeded. | ||||
*/ | */ | ||||
Turretable.prototype.LeaveTurret = function(forced = false) | Turretable.prototype.LeaveTurret = function(forced = false) | ||||
{ | { | ||||
if (!this.holder) | if (!this.holder) | ||||
return true; | return true; | ||||
if (!this.ejectable) | |||||
return false; | |||||
let pos = PositionHelper.GetSpawnPosition(this.holder, this.entity, forced); | let pos = PositionHelper.GetSpawnPosition(this.holder, this.entity, forced); | ||||
if (!pos) | if (!pos) | ||||
return false; | return false; | ||||
let cmpTurretHolder = Engine.QueryInterface(this.holder, IID_TurretHolder); | let cmpTurretHolder = Engine.QueryInterface(this.holder, IID_TurretHolder); | ||||
if (!cmpTurretHolder || !cmpTurretHolder.LeaveTurret(this.entity)) | if (!cmpTurretHolder || !cmpTurretHolder.LeaveTurretPoint(this.entity)) | ||||
return false; | return false; | ||||
let cmpUnitMotionEntity = Engine.QueryInterface(this.entity, IID_UnitMotion); | let cmpUnitMotionEntity = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
if (cmpUnitMotionEntity) | if (cmpUnitMotionEntity) | ||||
cmpUnitMotionEntity.SetFacePointAfterMove(true); | cmpUnitMotionEntity.SetFacePointAfterMove(true); | ||||
let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
if (cmpPosition) | if (cmpPosition) | ||||
{ | { | ||||
cmpPosition.SetTurretParent(INVALID_ENTITY, new Vector3D()); | |||||
cmpPosition.JumpTo(pos.x, pos.z); | cmpPosition.JumpTo(pos.x, pos.z); | ||||
cmpPosition.SetHeightOffset(0); | cmpPosition.SetHeightOffset(0); | ||||
} | } | ||||
let cmpHolderPosition = Engine.QueryInterface(this.holder, IID_Position); | let cmpHolderPosition = Engine.QueryInterface(this.holder, IID_Position); | ||||
if (cmpHolderPosition) | if (cmpHolderPosition) | ||||
cmpPosition.SetYRotation(cmpHolderPosition.GetPosition().horizAngleTo(pos)); | cmpPosition.SetYRotation(cmpHolderPosition.GetPosition().horizAngleTo(pos)); | ||||
Show All 15 Lines | Engine.PostMessage(this.entity, MT_TurretedStateChanged, { | ||||
"holderID": INVALID_ENTITY | "holderID": INVALID_ENTITY | ||||
}); | }); | ||||
let cmpRallyPoint = Engine.QueryInterface(this.holder, IID_RallyPoint); | let cmpRallyPoint = Engine.QueryInterface(this.holder, IID_RallyPoint); | ||||
if (cmpRallyPoint) | if (cmpRallyPoint) | ||||
cmpRallyPoint.OrderToRallyPoint(this.entity, ["occupy-turret"]); | cmpRallyPoint.OrderToRallyPoint(this.entity, ["occupy-turret"]); | ||||
delete this.holder; | delete this.holder; | ||||
delete this.ejectable; | |||||
return true; | return true; | ||||
}; | }; | ||||
Turretable.prototype.OnEntityRenamed = function(msg) | Turretable.prototype.OnEntityRenamed = function(msg) | ||||
{ | { | ||||
if (!this.holder) | if (!this.holder) | ||||
return; | return; | ||||
let cmpTurretHolder = Engine.QueryInterface(this.holder, IID_TurretHolder); | let cmpTurretHolder = Engine.QueryInterface(this.holder, IID_TurretHolder); | ||||
if (!cmpTurretHolder) | if (!cmpTurretHolder) | ||||
return; | return; | ||||
let holder = this.holder; | let holder = this.holder; | ||||
let currentPoint = cmpTurretHolder.GetOccupiedTurretName(this.entity); | let currentPoint = cmpTurretHolder.GetOccupiedTurretPointName(this.entity); | ||||
this.LeaveTurret(true); | this.LeaveTurret(true); | ||||
let cmpTurretableNew = Engine.QueryInterface(msg.newentity, IID_Turretable); | let cmpTurretableNew = Engine.QueryInterface(msg.newentity, IID_Turretable); | ||||
if (cmpTurretableNew) | if (cmpTurretableNew) | ||||
cmpTurretableNew.OccupyTurret(holder, currentPoint); | cmpTurretableNew.OccupyTurret(holder, currentPoint); | ||||
}; | }; | ||||
Turretable.prototype.OnOwnershipChanged = function(msg) | Turretable.prototype.OnOwnershipChanged = function(msg) | ||||
{ | { | ||||
Show All 10 Lines |
Wildfire Games · Phabricator
typo