Пример #1
0
    private void Maneuver(ZACommons commons, EventDriver eventDriver)
    {
        var velocity = velocimeter.GetAverageVelocity();

        if (velocity != null)
        {
            var shipControl = (ShipControlCommons)commons;
            cruiser.Cruise(shipControl, MANEUVERING_SPEED, (Vector3D)velocity,
                           enableBackward: false);
        }
    }
Пример #2
0
    public void Burn(ZACommons commons, EventDriver eventDriver)
    {
        if (ShouldAbort(commons, eventDriver, Modes.Burning, false))
        {
            return;
        }

        var shipControl = (ShipControlCommons)commons;

        var controller = GetShipController(shipControl);

        if (controller == null)
        {
            return;
        }
        var gravity = controller.GetNaturalGravity();

        if (gravity.LengthSquared() > 0.0)
        {
            // Override gyro, disable "bottom" thrusters
            shipControl.Reset(gyroOverride: true, thrusterEnable: true,
                              thrusterCondition: ThrusterCondition);
            shipControl.ThrustControl.Enable(Base6Directions.GetFlippedDirection(BrakeDirection), false);

            var down = shipControl.ShipBlockOrientation.TransformDirection(BrakeDirection);
            seeker.Init(shipControl,
                        shipUp: Base6Directions.GetPerpendicular(down),
                        shipForward: down);

            if (Autodrop)
            {
                // "forward" & "right"
                var forward = Base6Directions.GetPerpendicular(BrakeDirection);
                var right   = Base6Directions.GetCross(forward, BrakeDirection);
                // Actual orientations don't matter
                // Just as long as they're planar & perpendicular to down
                LongCruiser.Init(shipControl, localForward: forward);
                LatCruiser.Init(shipControl, localForward: right);
            }

            Mode = Modes.Gliding;
            eventDriver.Schedule(FramesPerRun, Glide);
        }
        else
        {
            cruiser.Cruise(shipControl, VTVLHELPER_BURN_SPEED,
                           condition: ThrusterCondition);

            eventDriver.Schedule(FramesPerRun, Burn);
        }
    }
Пример #3
0
    public void Mine(ZACommons commons, EventDriver eventDriver)
    {
        if (Mode != Modes.Mining)
        {
            return;
        }

        var shipControl = (ShipControlCommons)commons;

        var targetVector = GetTarget(shipControl, StartDirection);

        targetVector = Perturb(eventDriver.TimeSinceStart, targetVector);

        double yawPitchError;

        seeker.Seek(shipControl, targetVector, out yawPitchError);
        cruiser.Cruise(shipControl, TARGET_MINING_SPEED);

        eventDriver.Schedule(FramesPerRun, Mine);
    }
Пример #4
0
    private void AlignmentThrust(ShipControlCommons shipControl, Vector3D offset, Cruiser cruiser)
    {
        var velocity = shipControl.LinearVelocity;

        if (velocity != null)
        {
            // Project offset against reference direction
            var referenceDirection = GetReferenceVector(shipControl, cruiser.LocalForward);
            var referenceDistance  = Vector3D.Dot(offset, referenceDirection);
            var targetSpeed        = Math.Min(Math.Abs(referenceDistance) * VTVLHELPER_APPROACH_GAIN, VTVLHELPER_MAXIMUM_SPEED);
            targetSpeed *= Math.Sign(referenceDistance);

            cruiser.Cruise(shipControl, targetSpeed, (Vector3D)velocity);
        }
    }
Пример #5
0
    private void AlignmentThrust(ShipControlCommons shipControl, Vector3D offset, Cruiser cruiser)
    {
        var velocity = shipControl.LinearVelocity;

        if (velocity != null)
        {
            // Project offset against reference direction
            var referenceDirection = GetReferenceVector(shipControl, cruiser.LocalForward);
            var referenceDistance  = Vector3D.Dot(offset, referenceDirection);
            var targetSpeed        = Math.Min(Math.Abs(referenceDistance) * VTVLHELPER_APPROACH_GAIN, VTVLHELPER_MAXIMUM_SPEED);
            targetSpeed *= Math.Sign(referenceDistance);

            Func <IMyThrust, bool> AlignThrusterCondition = VTVLHELPER_USE_BRAKING_THRUSTER_SPEC_FOR_ALIGN ? ThrusterCondition : null;
            cruiser.Cruise(shipControl, targetSpeed, (Vector3D)velocity,
                           condition: AlignThrusterCondition);
        }
    }
Пример #6
0
    private void Thrust(ShipControlCommons shipControl, double distance,
                        Vector3D velocity, Cruiser cruiser)
    {
        if (Math.Abs(distance) < 1.0)
        {
            // Close enough
            var thrustControl = shipControl.ThrustControl;
            thrustControl.Enable(cruiser.LocalForward, true);
            thrustControl.Enable(cruiser.LocalBackward, true);
        }
        else
        {
            var targetSpeed = Math.Min(Math.Abs(distance) / AUTOPILOT_TTT_BUFFER,
                                       AutopilotSpeed);
            targetSpeed  = Math.Max(targetSpeed, AUTOPILOT_MIN_SPEED); // Avoid Zeno's paradox...
            targetSpeed *= Math.Sign(distance);

            cruiser.Cruise(shipControl, targetSpeed, velocity);
        }
    }
Пример #7
0
    public void Run(ZACommons commons, EventDriver eventDriver)
    {
        if (!AutopilotEngaged)
        {
            Reset(commons);
            return;
        }

        var shipControl = (ShipControlCommons)commons;

        var targetVector = AutopilotTarget - shipControl.ReferencePoint;
        var distance     = targetVector.Normalize();

        double yawPitchError;;
        var    gyroControl = seeker.Seek(shipControl, targetVector,
                                         out yawPitchError);

        var targetSpeed = Math.Min(distance / AUTOPILOT_TTT_BUFFER,
                                   AutopilotSpeed);

        targetSpeed = Math.Max(targetSpeed, AUTOPILOT_MIN_SPEED); // Avoid Zeno's paradox...

        cruiser.Cruise(shipControl, targetSpeed);

        if (distance < AUTOPILOT_DISENGAGE_DISTANCE)
        {
            Reset(commons);
            if (DoneAction != null)
            {
                DoneAction(commons, eventDriver);
            }
        }
        else
        {
            eventDriver.Schedule(FramesPerRun, Run);
        }
    }
Пример #8
0
    private void AlignmentThrust(ShipControlCommons shipControl, Vector3D offset, Cruiser cruiser)
    {
        var velocity = shipControl.LinearVelocity;
        if (velocity != null)
        {
            // Project offset against reference direction
            var referenceDirection = GetReferenceVector(shipControl, cruiser.LocalForward);
            var referenceDistance = Vector3D.Dot(offset, referenceDirection);
            var targetSpeed = Math.Min(Math.Abs(referenceDistance) * VTVLHELPER_APPROACH_GAIN, VTVLHELPER_MAXIMUM_SPEED);
            targetSpeed *= Math.Sign(referenceDistance);

            cruiser.Cruise(shipControl, targetSpeed, (Vector3D)velocity);
        }
    }
Пример #9
0
    private void Thrust(ShipControlCommons shipControl, double distance,
                        Vector3D velocity, Cruiser cruiser)
    {
        if (Math.Abs(distance) < 1.0)
        {
            // Close enough
            var thrustControl = shipControl.ThrustControl;
            thrustControl.Enable(cruiser.LocalForward, true);
            thrustControl.Enable(cruiser.LocalBackward, true);
        }
        else
        {
            var targetSpeed = Math.Min(Math.Abs(distance) / AUTOPILOT_TTT_BUFFER,
                                       AutopilotSpeed);
            targetSpeed = Math.Max(targetSpeed, AUTOPILOT_MIN_SPEED); // Avoid Zeno's paradox...
            targetSpeed *= Math.Sign(distance);

            cruiser.Cruise(shipControl, targetSpeed, velocity);
        }
    }