Beispiel #1
0
    public void Approach(ZACommons commons, EventDriver eventDriver)
    {
        if (Mode != APPROACHING)
        {
            return;
        }

        var shipControl = (ShipControlCommons)commons;

        var controller = GetShipController(shipControl);

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

        if (gravity.LengthSquared() > 0.0)
        {
            double yawError, pitchError;
            seeker.Seek(shipControl, gravity, out yawError, out pitchError);

            // Shouldn't fail since we do gravity check above
            if (!controller.TryGetPlanetElevation(MyPlanetElevation.Surface, out Elevation))
            {
                Elevation = 0.0;
            }

            Distance = Elevation - TargetElevation;
            if (Elevation <= TargetElevation)
            {
                // All done. Re-enable thrusters and restore control.
                Reset(shipControl);

                ZACommons.StartTimerBlockWithName(commons.Blocks, VTVLHELPER_DROP_DONE);
            }
            else
            {
                var targetSpeed = Math.Min(Distance * VTVLHELPER_APPROACH_GAIN,
                                           VTVLHELPER_BRAKING_SPEED);
                targetSpeed = Math.Max(targetSpeed, MinimumSpeed);

                cruiser.Cruise(shipControl, eventDriver, targetSpeed,
                               condition: ThrusterCondition,
                               enableForward: false);

                // Keep on target
                Alignment(shipControl, controller);

                eventDriver.Schedule(FramesPerRun, Approach);
            }
        }
        else
        {
            // If we left gravity, just abort.
            Reset(shipControl);
        }
    }
Beispiel #2
0
    private void TriggerSafeMode(ZACommons commons, EventDriver eventDriver,
                                 string timerBlockName = SAFE_MODE_NAME)
    {
        Abandoned = true; // No need to trigger any other condition until reset

        for (var i = 0; i < SafeModeHandlers.Length; i++)
        {
            SafeModeHandlers[i].SafeMode(commons, eventDriver);
        }

        ZACommons.StartTimerBlockWithName(commons.Blocks, timerBlockName);
    }
Beispiel #3
0
    public void Run(ZACommons commons, EventDriver eventDriver)
    {
        if (!Triggered)
        {
            var turretGroup = commons.GetBlockGroupWithName(TURRET_DETECTOR_GROUP);
            if (turretGroup != null)
            {
                var turrets = ZACommons.GetBlocksOfType <IMyLargeTurretBase>(turretGroup.Blocks,
                                                                             block => block.CubeGrid == commons.Me.CubeGrid);
                for (var e = turrets.GetEnumerator(); e.MoveNext();)
                {
                    var        turret = e.Current as IMyLargeTurretBase;
                    TurretInfo info;
                    if (turretInfos.TryGetValue(turret, out info))
                    {
                        if (turret.Elevation != info.LastElevation ||
                            turret.Azimuth != info.LastAzimuth)
                        {
                            // Trigger
                            ZACommons.StartTimerBlockWithName(commons.Blocks,
                                                              TURRET_DETECTOR_TRIGGER_TIMER_BLOCK_NAME);
                            // And don't trigger again until reset
                            Triggered = true;
                            break;
                        }
                    }
                    else
                    {
                        // Unknown turret
                        // FIXME shouldn't hold references...
                        turretInfos.Add(turret, new TurretInfo(turret));
                    }
                }
            }
        }

        eventDriver.Schedule(RunDelay, Run);
    }
Beispiel #4
0
    public void Launch(ZACommons commons, EventDriver eventDriver)
    {
        if (Mode != LAUNCHING)
        {
            return;
        }

        var shipControl = (ShipControlCommons)commons;

        var controller = GetShipController(shipControl);

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

        if (gravity.LengthSquared() > 0.0)
        {
            double yawError, pitchError;
            seeker.Seek(shipControl, -gravity, out yawError, out pitchError);

            cruiser.Cruise(shipControl, eventDriver, VTVLHELPER_LAUNCH_SPEED,
                           condition: ThrusterCondition,
                           enableBackward: false);

            eventDriver.Schedule(FramesPerRun, Launch);
        }
        else
        {
            // Out of gravity
            Reset(shipControl);

            ZACommons.StartTimerBlockWithName(commons.Blocks, VTVLHELPER_LAUNCH_DONE);
        }
    }
Beispiel #5
0
    public void Run(ZACommons commons, EventDriver eventDriver)
    {
        var tanks = ZACommons.GetBlocksOfType <IMyOxygenTank>(commons.AllBlocks,
                                                              tank => tank.IsFunctional &&
                                                              tank.IsWorking &&
                                                              tank.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0);

        var currentState = GetOxygenState(tanks);

        // Only act on level transitions
        if (PreviousState != currentState)
        {
            PreviousState = currentState;

            // We need a tri-state variable, so... nullable
            bool?generateOxygen = null;
            bool?farmOxygen     = null;

            switch (currentState)
            {
            case OXYGEN_LEVEL_HIGH:
                // Turn off all oxygen production
                generateOxygen = false;
                farmOxygen     = false;
                break;

            case OXYGEN_LEVEL_NORMAL:
                // Do nothing (but keep farms up)
                farmOxygen = true;
                break;

            case OXYGEN_LEVEL_BUFFER:
                // Start producing oxygen
                generateOxygen = true;
                farmOxygen     = true;
                break;

            case OXYGEN_LEVEL_LOW:
                // Definitely start producing oxygen
                generateOxygen = true;
                farmOxygen     = true;
                // For now, it's intentional that we start timer blocks
                // on all grids... we'll see how it goes
                ZACommons.StartTimerBlockWithName(commons.AllBlocks, LOW_OXYGEN_NAME);
                break;
            }

            if (generateOxygen != null)
            {
                // Limit to this grid -- don't mess with any other ship's systems
                var generators =
                    ZACommons.GetBlocksOfType <IMyOxygenGenerator>(commons.Blocks,
                                                                   block => block.IsFunctional);
                ZACommons.EnableBlocks(generators, (bool)generateOxygen);
            }
            if (farmOxygen != null)
            {
                var farms =
                    ZACommons.GetBlocksOfType <IMyOxygenFarm>(commons.Blocks,
                                                              block => block.IsFunctional);

                // Farms don't implement IMyFunctionalBlock??
                ZACommons.EnableBlocks(farms, (bool)farmOxygen);

                // We'll count atmosphere intake vents too, since they're "free"
                var vents =
                    ZACommons.GetBlocksOfType <IMyAirVent>(commons.Blocks,
                                                           vent => vent.IsFunctional &&
                                                           ((IMyAirVent)vent).IsDepressurizing &&
                                                           vent.CustomName.IndexOf("[Intake]", ZACommons.IGNORE_CASE) >= 0);

                ZACommons.EnableBlocks(vents, (bool)farmOxygen);
            }
        }

        eventDriver.Schedule(RunDelay, Run);
    }