Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitMotionFlying.js
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | UnitMotionFlying.prototype.OnUpdate = function(msg) | ||||
} | } | ||||
// If we're in range of the target then tell people that we've reached it | // If we're in range of the target then tell people that we've reached it | ||||
// (TODO: quantisation breaks this) | // (TODO: quantisation breaks this) | ||||
var distFromTarget = Math.euclidDistance2D(pos.x, pos.z, this.targetX, this.targetZ); | var distFromTarget = Math.euclidDistance2D(pos.x, pos.z, this.targetX, this.targetZ); | ||||
if (!this.reachedTarget && this.targetMinRange <= distFromTarget && distFromTarget <= this.targetMaxRange) | if (!this.reachedTarget && this.targetMinRange <= distFromTarget && distFromTarget <= this.targetMaxRange) | ||||
{ | { | ||||
this.reachedTarget = true; | this.reachedTarget = true; | ||||
Engine.PostMessage(this.entity, MT_MotionChanged, { "starting": false, "error": false }); | Engine.PostMessage(this.entity, MT_MovePaused, {}); | ||||
} | } | ||||
// If we're facing away from the target, and are still fairly close to it, | // If we're facing away from the target, and are still fairly close to it, | ||||
// then carry on going straight so we overshoot in a straight line | // then carry on going straight so we overshoot in a straight line | ||||
var isBehindTarget = ((this.targetX - pos.x) * Math.sin(angle) + (this.targetZ - pos.z) * Math.cos(angle) < 0); | var isBehindTarget = ((this.targetX - pos.x) * Math.sin(angle) + (this.targetZ - pos.z) * Math.cos(angle) < 0); | ||||
// Overshoot the target: carry on straight | // Overshoot the target: carry on straight | ||||
if (isBehindTarget && distFromTarget < this.template.MaxSpeed * this.template.OvershootTime) | if (isBehindTarget && distFromTarget < this.template.MaxSpeed * this.template.OvershootTime) | ||||
canTurn = false; | canTurn = false; | ||||
Show All 25 Lines | UnitMotionFlying.prototype.OnUpdate = function(msg) | ||||
pos.x += this.speed * turnLength * Math.sin(angle); | pos.x += this.speed * turnLength * Math.sin(angle); | ||||
pos.z += this.speed * turnLength * Math.cos(angle); | pos.z += this.speed * turnLength * Math.cos(angle); | ||||
cmpPosition.SetHeightFixed(pos.y); | cmpPosition.SetHeightFixed(pos.y); | ||||
cmpPosition.TurnTo(newangle); | cmpPosition.TurnTo(newangle); | ||||
cmpPosition.SetXZRotation(this.pitch, this.roll); | cmpPosition.SetXZRotation(this.pitch, this.roll); | ||||
cmpPosition.MoveTo(pos.x, pos.z); | cmpPosition.MoveTo(pos.x, pos.z); | ||||
}; | }; | ||||
UnitMotionFlying.prototype.MoveToPointRange = function(x, z, minRange, maxRange) | UnitMotionFlying.prototype.SetNewDestinationAsPosition = function(x, z, range) | ||||
{ | { | ||||
this.hasTarget = true; | this.hasTarget = true; | ||||
this.landing = false; | this.landing = false; | ||||
this.reachedTarget = false; | this.reachedTarget = false; | ||||
this.targetX = x; | this.targetX = x; | ||||
this.targetZ = z; | this.targetZ = z; | ||||
this.targetMinRange = minRange; | this.targetMinRange = 0; | ||||
this.targetMaxRange = maxRange; | this.targetMaxRange = range; | ||||
// we'll tell the visual actor to set our animation here. | |||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | |||||
if (cmpVisual) | |||||
cmpVisual.SetMovingSpeed(this.speed); | |||||
return true; | return true; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.MoveToTargetRange = function(target, minRange, maxRange) | UnitMotionFlying.prototype.SetNewDestinationAsEntity = function(target, range) | ||||
{ | { | ||||
var cmpTargetPosition = Engine.QueryInterface(target, IID_Position); | var cmpTargetPosition = Engine.QueryInterface(target, IID_Position); | ||||
if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) | if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) | ||||
return false; | return false; | ||||
// we'll tell the visual actor to set our animation here. | |||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | |||||
if (cmpVisual) | |||||
cmpVisual.SetMovingSpeed(this.speed); | |||||
var targetPos = cmpTargetPosition.GetPosition2D(); | var targetPos = cmpTargetPosition.GetPosition2D(); | ||||
this.hasTarget = true; | this.hasTarget = true; | ||||
this.reachedTarget = false; | this.reachedTarget = false; | ||||
this.targetX = targetPos.x; | this.targetX = targetPos.x; | ||||
this.targetZ = targetPos.y; | this.targetZ = targetPos.y; | ||||
this.targetMinRange = minRange; | this.targetMinRange = 0; | ||||
this.targetMaxRange = maxRange; | this.targetMaxRange = range; | ||||
return true; | return true; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.GetWalkSpeed = function() | UnitMotionFlying.prototype.GetWalkSpeed = function() | ||||
{ | { | ||||
return +this.template.MaxSpeed; | return +this.template.MaxSpeed; | ||||
}; | }; | ||||
Show All 13 Lines | UnitMotionFlying.prototype.GetCurrentSpeed = function() | ||||
return this.speed; | return this.speed; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.GetSpeedRatio = function() | UnitMotionFlying.prototype.GetSpeedRatio = function() | ||||
{ | { | ||||
return this.GetCurrentSpeed() / this.GetWalkSpeed(); | return this.GetCurrentSpeed() / this.GetWalkSpeed(); | ||||
} | } | ||||
UnitMotionFlying.prototype.GetPassabilityClassName = function() | UnitMotionFlying.prototype.IsTryingToMove = function() | ||||
{ | |||||
return this.template.PassabilityClass; | |||||
}; | |||||
UnitMotionFlying.prototype.GetPassabilityClass = function() | |||||
{ | { | ||||
return this.passabilityClass; | return false; | ||||
}; | } | ||||
UnitMotionFlying.prototype.FaceTowardsPoint = function(x, z) | UnitMotionFlying.prototype.FaceTowardsPoint = function(x, z) | ||||
{ | { | ||||
// Ignore this - angle is controlled by the target-seeking code instead | // Ignore this - angle is controlled by the target-seeking code instead | ||||
}; | }; | ||||
UnitMotionFlying.prototype.SetFacePointAfterMove = function() | UnitMotionFlying.prototype.DiscardMove = function() | ||||
{ | |||||
// Ignore this - angle is controlled by the target-seeking code instead | |||||
}; | |||||
UnitMotionFlying.prototype.StopMoving = function() | |||||
{ | { | ||||
//Invert | //Invert | ||||
if (!this.waterDeath) | if (!this.waterDeath) | ||||
this.landing = !this.landing; | this.landing = !this.landing; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.SetDebugOverlay = function(enabled) | UnitMotionFlying.prototype.SetDebugOverlay = function(enabled) | ||||
{ | { | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_UnitMotion, "UnitMotionFlying", UnitMotionFlying); | Engine.RegisterComponentType(IID_UnitMotion, "UnitMotionFlying", UnitMotionFlying); |
Wildfire Games · Phabricator