Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/UnitMotionFlying.js
Show First 20 Lines • Show All 235 Lines • ▼ Show 20 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 = range; | ||||
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 = range; | ||||
this.targetMaxRange = maxRange; | this.targetMaxRange = range; | ||||
return true; | return true; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.IsInPointRange = function(x, y, minRange, maxRange) | UnitMotionFlying.prototype.IsInPointRange = function(x, y, minRange, maxRange) | ||||
{ | { | ||||
var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); | ||||
var pos = cmpPosition.GetPosition2D(); | var pos = cmpPosition.GetPosition2D(); | ||||
Show All 11 Lines | UnitMotionFlying.prototype.IsInTargetRange = function(target, minRange, maxRange) | ||||
if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) | if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) | ||||
return false; | return false; | ||||
var targetPos = cmpTargetPosition.GetPosition2D(); | var targetPos = cmpTargetPosition.GetPosition2D(); | ||||
return this.IsInPointRange(targetPos.x, targetPos.y, minRange, maxRange); | return this.IsInPointRange(targetPos.x, targetPos.y, minRange, maxRange); | ||||
}; | }; | ||||
UnitMotionFlying.prototype.GetWalkSpeed = function() | UnitMotionFlying.prototype.GetSpeed = function() | ||||
{ | { | ||||
return +this.template.MaxSpeed; | return +this.template.MaxSpeed; | ||||
}; | }; | ||||
UnitMotionFlying.prototype.SetSpeed = function() | UnitMotionFlying.prototype.SetSpeed = function() | ||||
{ | { | ||||
// ignore this, the speed is always the walk speed | // ignore this, the speed is always the walk speed | ||||
}; | }; | ||||
Show All 13 Lines | 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.SetFacePointAfterMove = function() | ||||
{ | { | ||||
// Ignore this - angle is controlled by the target-seeking code instead | // Ignore this - angle is controlled by the target-seeking code instead | ||||
}; | }; | ||||
UnitMotionFlying.prototype.StopMoving = function() | UnitMotionFlying.prototype.DiscardMove = 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