public void Prime(ZACommons commons, EventDriver eventDriver)
    {
        // Wake up batteries
        var batteryGroup = commons.GetBlockGroupWithName(StandardMissile.BATTERY_GROUP + MissileGroupSuffix);

        if (batteryGroup == null)
        {
            throw new Exception("Group missing: " + StandardMissile.BATTERY_GROUP + MissileGroupSuffix);
        }
        var systemsGroup = commons.GetBlockGroupWithName(StandardMissile.SYSTEMS_GROUP + MissileGroupSuffix);

        if (systemsGroup == null)
        {
            throw new Exception("Group missing: " + StandardMissile.SYSTEMS_GROUP + MissileGroupSuffix);
        }

        var batteries = ZACommons.GetBlocksOfType <IMyBatteryBlock>(batteryGroup.Blocks);

        batteries.ForEach(battery =>
        {
            battery.Enabled       = true;
            battery.OnlyDischarge = true;
        });

        // Activate flight systems
        ZACommons.EnableBlocks(systemsGroup.Blocks, true);

        eventDriver.Schedule(0.1 + ReleaseDelay, Release);
    }
Exemple #2
0
    public void Prime(ZACommons commons, EventDriver eventDriver)
    {
        // Wake up batteries
        var batteryGroup = commons.GetBlockGroupWithName(BATTERY_GROUP + MISSILE_GROUP_SUFFIX);

        if (batteryGroup == null)
        {
            throw new Exception("Group missing: " + BATTERY_GROUP + MISSILE_GROUP_SUFFIX);
        }
        var systemsGroup = commons.GetBlockGroupWithName(SYSTEMS_GROUP + MISSILE_GROUP_SUFFIX);

        if (systemsGroup == null)
        {
            throw new Exception("Group missing: " + SYSTEMS_GROUP + MISSILE_GROUP_SUFFIX);
        }

        var batteries = ZACommons.GetBlocksOfType <IMyBatteryBlock>(batteryGroup.Blocks);

        batteries.ForEach(battery =>
        {
            battery.SetValue <bool>("OnOff", true);
            battery.SetValue <bool>("Recharge", false);
            battery.SetValue <bool>("Discharge", true);
        });

        // Activate flight systems
        ZACommons.EnableBlocks(systemsGroup.Blocks, true);

        eventDriver.Schedule(1.0, Release);
    }
    public void Release(ZACommons commons, EventDriver eventDriver)
    {
        // Enable mass
        var group = commons.GetBlockGroupWithName(StandardMissile.MASS_GROUP + MissileGroupSuffix);

        if (group != null)
        {
            ZACommons.EnableBlocks(group.Blocks, true);
        }

        var releaseGroup = commons.GetBlockGroupWithName(StandardMissile.RELEASE_GROUP + MissileGroupSuffix);

        if (releaseGroup == null)
        {
            throw new Exception("Group missing: " + StandardMissile.RELEASE_GROUP + MissileGroupSuffix);
        }

        // Unlock any landing gear
        ZACommons.ForEachBlockOfType <IMyLandingGear>(releaseGroup.Blocks,
                                                      gear => gear.ApplyAction("Unlock"));
        // And then turn everything off (connectors, merge blocks, etc)
        ZACommons.EnableBlocks(releaseGroup.Blocks, false);

        // Initialize flight control
        var shipControl = (ShipControlCommons)commons;

        shipControl.Reset(gyroOverride: true, thrusterEnable: null);

        eventDriver.Schedule(0.1, Demass);
    }
    public void Prime(ZACommons commons, EventDriver eventDriver)
    {
        var relayBatteries = commons.GetBlockGroupWithName(BATTERY_GROUP);

        if (relayBatteries == null)
        {
            throw new Exception("Missing group: " + BATTERY_GROUP);
        }
        var relaySystems = commons.GetBlockGroupWithName(SYSTEMS_GROUP);

        if (relaySystems == null)
        {
            throw new Exception("Missing group: " + SYSTEMS_GROUP);
        }

        // Wake up batteries
        var batteries = ZACommons.GetBlocksOfType <IMyBatteryBlock>(relayBatteries.Blocks);

        ZACommons.EnableBlocks(batteries, true);
        ZACommons.SetBatteryRecharge(batteries, false);
        // And activate flight systems
        ZACommons.EnableBlocks(relaySystems.Blocks, true);

        eventDriver.Schedule(1.0, Release);
    }
    public void Run(ZACommons commons, EventDriver eventDriver)
    {
        if (Indexes.Count == 0)
        {
            return;
        }

        var newIndexes = new Dictionary <string, int>();

        foreach (var kv in Indexes)
        {
            var sequence = kv.Key;
            var index    = kv.Value;

            var blocks = GetSequenceBlocks(commons, sequence);
            if (blocks == null)
            {
                continue;
            }
            ZACommons.EnableBlocks(blocks, false);

            // TODO sort?
            index++;
            index %= blocks.Count;

            blocks[index].SetValue <bool>("OnOff", true);

            newIndexes.Add(sequence, index);
        }

        Indexes = newIndexes;

        eventDriver.Schedule(SEQUENCER_FRAMES_PER_RUN, Run);
    }
Exemple #6
0
    public void DockingAction(ZACommons commons, EventDriver eventDriver,
                              bool docked)
    {
        var wheels = ZACommons.GetBlocksOfType <IMyMotorSuspension>(commons.Blocks);

        ZACommons.EnableBlocks(wheels, !docked);
        if (!docked)
        {
            // Set suspension strength to configured value
            wheels.ForEach(wheel =>
            {
                wheel.SetValue <float>("Strength", UNDOCK_SUSPENSION_STRENGTH);
            });
        }
        else
        {
            // Apply handbrake
            var controllers = ZACommons.GetBlocksOfType <IMyShipController>(commons.Blocks);
            controllers.ForEach(controller =>
            {
                if (!((IMyShipController)controller).HandBrake)
                {
                    controller.SetValue <bool>("HandBrake", true);
                }
            });
        }
    }
Exemple #7
0
    public void Demass(ZACommons commons, EventDriver eventDriver)
    {
        var shipControl = (ShipControlCommons)commons;

        var deltaTime            = (eventDriver.TimeSinceStart - InitialTime).TotalSeconds;
        var launcherDelta        = LauncherVelocity * deltaTime;
        var distanceFromLauncher = (shipControl.ReferencePoint -
                                    (InitialPosition + launcherDelta)).LengthSquared();

        if (distanceFromLauncher < DemassDistance * DemassDistance)
        {
            // Not yet
            eventDriver.Schedule(TicksPerRun, Demass);
            return;
        }

        // Disable mass
        var group = commons.GetBlockGroupWithName(MASS_GROUP);

        if (group != null)
        {
            ZACommons.EnableBlocks(group.Blocks, false);
        }

        // Start roll
        shipControl.GyroControl.EnableOverride(true);
        shipControl.GyroControl.SetAxisVelocity(GyroControl.Roll,
                                                MathHelper.Pi);

        // All done
        if (PostLaunch != null)
        {
            PostLaunch(commons, eventDriver);
        }
    }
    public void Release(ZACommons commons, EventDriver eventDriver)
    {
        var relayRelease = commons.GetBlockGroupWithName(RELEASE_GROUP);

        if (relayRelease == null)
        {
            throw new Exception("Missing group: " + RELEASE_GROUP);
        }
        ZACommons.EnableBlocks(relayRelease.Blocks, false);

        eventDriver.Schedule(1.0, Burn);
    }
    public void Release(ZACommons commons, EventDriver eventDriver)
    {
        var releaseGroup = commons.GetBlockGroupWithName(StandardMissile.RELEASE_GROUP + MissileGroupSuffix);

        if (releaseGroup == null)
        {
            throw new Exception("Group missing: " + StandardMissile.RELEASE_GROUP + MissileGroupSuffix);
        }

        // Unlock any landing gear
        ZACommons.ForEachBlockOfType <IMyLandingGear>(releaseGroup.Blocks,
                                                      gear => gear.ApplyAction("Unlock"));
        // And then turn everything off (connectors, merge blocks, etc)
        ZACommons.EnableBlocks(releaseGroup.Blocks, false);

        eventDriver.Schedule(0.5, Burn);
    }
    public void HandleCommand(ZACommons commons, EventDriver eventDriver,
                              string argument)
    {
        argument = argument.Trim().ToLower();
        var parts = argument.Split(new char[] { ' ' }, 3);

        if (parts.Length < 3 || parts[0] != "sequence")
        {
            return;
        }
        var command  = parts[1];
        var sequence = parts[2];

        if (command == "start")
        {
            var blocks = GetSequenceBlocks(commons, sequence);
            if (blocks == null)
            {
                return;
            }

            ZACommons.EnableBlocks(blocks, false);
            blocks[0].SetValue <bool>("OnOff", true);

            var first = Indexes.Count == 0;
            if (!Indexes.ContainsKey(sequence))
            {
                Indexes.Add(sequence, 0);
            }
            if (first)
            {
                eventDriver.Schedule(SEQUENCER_FRAMES_PER_RUN, Run);
            }
        }
        else if (command == "stop")
        {
            var blocks = GetSequenceBlocks(commons, sequence);
            if (blocks != null)
            {
                ZACommons.EnableBlocks(blocks, true);
            }

            Indexes.Remove(sequence);
        }
    }
Exemple #11
0
    public void Release(ZACommons commons, EventDriver eventDriver)
    {
        var releaseGroup = commons.GetBlockGroupWithName(RELEASE_GROUP);

        if (releaseGroup == null)
        {
            throw new Exception("Group missing: " + RELEASE_GROUP);
        }

        // Get one last reading from launcher and determine velocity
        var launcherDelta = ((ShipControlCommons)commons).ReferencePoint -
                            InitialPosition;
        var deltaTime = (eventDriver.TimeSinceStart - InitialTime).TotalSeconds;

        LauncherVelocity = launcherDelta / deltaTime;

        // Turn release group off
        ZACommons.EnableBlocks(releaseGroup.Blocks, false);

        eventDriver.Schedule(1.0, Demass);
    }
    public void Demass(ZACommons commons, EventDriver eventDriver)
    {
        var shipControl = (ShipControlCommons)commons;

        var shipController = shipControl.ShipController;

        if (shipController == null || shipController.GetArtificialGravity().LengthSquared() == 0.0)
        {
            // Disable mass
            var group = commons.GetBlockGroupWithName(StandardMissile.MASS_GROUP + MissileGroupSuffix);
            if (group != null)
            {
                ZACommons.EnableBlocks(group.Blocks, false);
            }

            // All done (or remote is gone), begin arming sequence
            eventDriver.Schedule(0, Arm);
        }
        else
        {
            eventDriver.Schedule(1, Demass);
        }
    }
Exemple #13
0
    public void Release(ZACommons commons, EventDriver eventDriver)
    {
        // Enable mass
        var group = commons.GetBlockGroupWithName(MASS_GROUP);

        if (group != null)
        {
            ZACommons.EnableBlocks(group.Blocks, true);
        }

        var releaseGroup = commons.GetBlockGroupWithName(RELEASE_GROUP);

        if (releaseGroup == null)
        {
            throw new Exception("Group missing: " + RELEASE_GROUP);
        }

        // Get one last reading from launcher and determine velocity
        var launcherDelta = ((ShipControlCommons)commons).ReferencePoint -
                            InitialPosition;
        var deltaTime = (eventDriver.TimeSinceStart - InitialTime).TotalSeconds;

        LauncherVelocity = launcherDelta / deltaTime;

        // Turn release group off
        ZACommons.EnableBlocks(releaseGroup.Blocks, false);

        // Statistics
        AccelStartTime     = eventDriver.TimeSinceStart;
        AccelStartPosition = commons.Me.GetPosition();
        AccelLastPosition  = AccelStartPosition;
        AccelResults.Append(string.Format("CoM Distance: {0:F2} m\n", (AccelStartPosition - ((ShipControlCommons)commons).ReferencePoint).Length()));
        eventDriver.Schedule(TicksPerRun, AccelCheck);

        eventDriver.Schedule(1.0, Demass);
    }
Exemple #14
0
    public void HandleCommand(ZACommons commons, EventDriver eventDriver,
                              string argument, Action preUndock = null)
    {
        argument = argument.Trim().ToLower();
        if (argument == "smartundock")
        {
            if (preUndock != null)
            {
                preUndock();
            }

            // First, determine which connector we were connected through
            IMyShipConnector connected = null;
            var connectors             = ZACommons.GetBlocksOfType <IMyShipConnector>(commons.Blocks,
                                                                                      connector => connector.DefinitionDisplayNameText == "Connector"); // Avoid Ejectors
            for (var e = connectors.GetEnumerator(); e.MoveNext();)
            {
                var connector = (IMyShipConnector)e.Current;
                if (connector.IsLocked && connector.IsConnected)
                {
                    // Assume the first one as well
                    connected = connector;
                    break;
                }
            }

            UndockTarget   = null;
            UndockBackward = null;
            if (connected != null)
            {
                // Undock in the forward direction of the *other* connector
                var other         = connected.OtherConnector;
                var forward       = other.Orientation.TransformDirection(Base6Directions.Direction.Forward);
                var forwardPoint  = other.CubeGrid.GridIntegerToWorld(other.Position + Base6Directions.GetIntVector(forward));
                var forwardVector = Vector3D.Normalize(forwardPoint - other.GetPosition());
                // Determine target undock point
                var shipControl = (ShipControlCommons)commons;
                UndockTarget = shipControl.ReferencePoint + SMART_UNDOCK_DISTANCE * forwardVector;

                // And original orientation
                UndockForward = shipControl.ReferenceForward;
                UndockUp      = shipControl.ReferenceUp;

                // Schedule the autopilot
                UndockBackward = connected.Orientation.TransformDirection(Base6Directions.Direction.Backward);
                BeginUndock(commons, eventDriver);
                Mode = UNDOCKING;
                SaveMode(commons);
            }
            SaveUndockTarget(commons);

            // Next, physically undock
            for (var e = connectors.GetEnumerator(); e.MoveNext();)
            {
                var connector = (IMyShipConnector)e.Current;
                if (connector.IsLocked)
                {
                    connector.ApplyAction("Unlock");
                }
            }
            ZACommons.EnableBlocks(connectors, false);
            // Unlock landing gears as well
            var gears = ZACommons.GetBlocksOfType <IMyLandingGear>(commons.Blocks);
            gears.ForEach(block =>
            {
                var gear = (IMyLandingGear)block;
                if (gear.IsLocked)
                {
                    gear.ApplyAction("Unlock");
                }
            });

            // Disable connectors 1 second from now
            eventDriver.Schedule(1.0, (c, ed) =>
            {
                ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyShipConnector>(c.Blocks, connector => connector.DefinitionDisplayNameText == "Connector"),
                                       false);         // Avoid Ejectors
            });
        }
        else if (argument == "rtb")
        {
            // No target, no RTB
            if (UndockTarget == null)
            {
                return;
            }

            // Schedule the autopilot
            BeginReturn(commons, eventDriver);
            Mode = RETURNING;
            SaveMode(commons);
        }
        else if (argument == "smartreset")
        {
            autopilot.Reset(commons);
            ResetMode(commons);
        }
    }
Exemple #15
0
 public void UndockDisable(ZACommons commons, EventDriver eventDriver)
 {
     ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyShipConnector>(commons.Blocks, connector => connector.DefinitionDisplayNameText == "Connector"),
                            false);
 }
Exemple #16
0
    public void Run(ZACommons commons)
    {
        // Only care about power producers on this ship
        var producers = ZACommons.GetBlocksOfType <IMyTerminalBlock>(commons.Blocks,
                                                                     block => block is IMyPowerProducer);

        // Limit to functional batteries
        var batteries = ZACommons.GetBlocksOfType <IMyBatteryBlock>(producers,
                                                                    battery => battery.IsFunctional);

        if (batteries.Count == 0)
        {
            return;                       // Nothing to do if no batteries to manage
        }
        // All other power producers
        var otherProducers = ZACommons.GetBlocksOfType <IMyTerminalBlock>(producers,
                                                                          block => !(block is IMyBatteryBlock));

        var batteryDetails = GetPowerDetails <IMyBatteryBlock>(batteries);
        var otherDetails   = GetPowerDetails <IMyTerminalBlock>(otherProducers);

        var totalDetails = batteryDetails + otherDetails;

        //commons.Echo("Battery Load: " + batteryDetails.ToString());
        //commons.Echo("Other Load: " + otherDetails.ToString());
        //commons.Echo("Total Load: " + totalDetails.ToString());

        // First, the degenerate cases...
        if (totalDetails.MaxPowerOutput == 0.0f)
        {
            return;                                      // Don't think this is possible...
        }
        if (otherDetails.MaxPowerOutput == 0.0f)
        {
            // Nothing but our batteries. Just put all batteries online.
            ZACommons.EnableBlocks(batteries, true);
            ZACommons.SetBatteryRecharge(batteries, false);
            return;
        }

        var totalLoad = totalDetails.CurrentPowerOutput / totalDetails.MaxPowerOutput;

        // If total system load exceeds threshold, attempt to bring a battery online.
        if (totalLoad > POWER_MANAGER_HIGH_LOAD_THRESHOLD)
        {
            QuietTimer = TimeSpan.FromSeconds(0);

            // Sort by stored power descending
            batteries.Sort(batteryComparerDesc);

            // Bring the first recharging battery online, shut down all other recharging batteries
            // (just shutting them down would probably free up a lot of power... need
            // separate case?)
            var found = false;
            for (var e = batteries.GetEnumerator(); e.MoveNext();)
            {
                var battery = e.Current;

                if (battery.Enabled && battery.ProductionEnabled)
                {
                    continue;                                               // Battery is already online, don't touch it
                }
                if (!found)
                {
                    // Found the first one, bring it online
                    if (!battery.Enabled)
                    {
                        battery.GetActionWithName("OnOff_On").Apply(battery);
                    }
                    ZACommons.SetBatteryRecharge(battery, false);
                    found = true;
                }
                else
                {
                    // Shut it down
                    if (battery.Enabled)
                    {
                        battery.GetActionWithName("OnOff_Off").Apply(battery);
                    }
                }
            }
        }
        else if (totalLoad < POWER_MANAGER_LOW_LOAD_THRESHOLD)
        {
            QuietTimer += commons.Program.ElapsedTime;

            if (QuietTimer >= QuietTimeout)
            {
                // NB We don't reset QuietTimer, so we will trigger at next tick again
                // (assuming load is still low)

                // Sort from low to high
                batteries.Sort(batteryComparer);

                // Any batteries actively discharging?
                if (batteryDetails.CurrentPowerOutput > 0.0f)
                {
                    // Take a battery offline, starting with the least charged.
                    // Note, we cannot actually start recharging until they are all offline
                    DisableOneBattery(batteries, totalDetails);
                }
                else
                {
                    // All batteries are down, enable one for charging
                    // (repeat next tick until we break low threshold, in which case QuietTimer
                    // will reset)
                    // But first, check if it would put us over the threshold
                    var first         = batteries[0];                                               // Assume all the same
                    var wouldBeOutput = otherDetails.CurrentPowerOutput + first.DefinedPowerOutput; // Assume MaxPowerOutput = MaxPowerInput (not available to us)
                    //commons.Echo("Would-be Output: " + ZACommons.FormatPower(wouldBeOutput));
                    var wouldBeLoad = wouldBeOutput / otherDetails.MaxPowerOutput;
                    //commons.Echo("Would-be Load: " + wouldBeLoad);

                    if (wouldBeLoad <= POWER_MANAGER_HIGH_LOAD_THRESHOLD)
                    {
                        RechargeOneBattery(batteries);
                    }
                }
            }
        }
        else
        {
            QuietTimer = TimeSpan.FromSeconds(0);
        }
    }
Exemple #17
0
    public void Run(ZACommons commons, EventDriver eventDriver)
    {
        var tanks = ZACommons.GetBlocksOfType <IMyGasTank>(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 OxygenLevel.High:
                // Turn off all oxygen production
                generateOxygen = false;
                farmOxygen     = false;
                break;

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

            case OxygenLevel.Buffer:
                // Start producing oxygen
                generateOxygen = true;
                farmOxygen     = true;
                break;

            case OxygenLevel.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
                TimerBlockUtils.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 <IMyGasGenerator>(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 &&
                                                           vent.Depressurize &&
                                                           vent.CustomName.IndexOf("[Intake]", ZACommons.IGNORE_CASE) >= 0);

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

        eventDriver.Schedule(RunDelay, Run);
    }
    public void HandleCommand(ZACommons commons, EventDriver eventDriver,
                              string argument, Action preUndock = null)
    {
        argument = argument.Trim().ToLower();
        if (argument == "smartundock")
        {
            if (preUndock != null)
            {
                preUndock();
            }

            // First, determine which connector we were connected through
            IMyShipConnector connected = null;
            var connectors             = ZACommons.GetBlocksOfType <IMyShipConnector>(commons.Blocks,
                                                                                      connector => connector.DefinitionDisplayNameText == "Connector"); // Avoid Ejectors
            foreach (var connector in connectors)
            {
                if (connector.Status == MyShipConnectorStatus.Connected)
                {
                    // Assume the first one as well
                    connected = connector;
                    break;
                }
            }

            UndockTarget   = null;
            UndockBackward = null;
            Vector3D forwardVector = Vector3D.Zero;
            if (connected != null)
            {
                // Undock in the forward direction of the *other* connector
                var other = connected.OtherConnector;
                forwardVector  = other.WorldMatrix.Forward;
                UndockBackward = connected.Orientation.TransformDirection(Base6Directions.Direction.Backward);
            }

            // Next, physically undock
            foreach (var block in connectors)
            {
                var connector = (IMyShipConnector)block;
                if (connector.Status == MyShipConnectorStatus.Connected)
                {
                    connector.ApplyAction("Unlock");
                }
            }
            ZACommons.EnableBlocks(connectors, false);
            // Unlock landing gears as well
            var gears = ZACommons.GetBlocksOfType <IMyLandingGear>(commons.Blocks);
            gears.ForEach(gear =>
            {
                if (gear.IsLocked)
                {
                    gear.ApplyAction("Unlock");
                }
            });

            // Disable connectors 1 second from now
            eventDriver.Schedule(1.0, (c, ed) =>
            {
                ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyShipConnector>(c.Blocks, connector => connector.DefinitionDisplayNameText == "Connector"),
                                       false);         // Avoid Ejectors
            });

            if (connected != null)
            {
                eventDriver.Schedule(1.0, (c, ed) =>
                {
                    // Determine target undock point
                    var shipControl = (ShipControlCommons)c;
                    UndockTarget    = shipControl.ReferencePoint + SMART_UNDOCK_DISTANCE * forwardVector;

                    // And original orientation
                    UndockForward = shipControl.ReferenceForward;
                    UndockUp      = shipControl.ReferenceUp;

                    // Schedule the autopilot
                    BeginUndock(c, ed);
                    Mode = Modes.Undocking;
                    SaveMode(c);
                    SaveUndockTarget(c);
                });
            }
            else
            {
                SaveUndockTarget(commons);
            }
        }
        else if (argument == "rtb")
        {
            // No target, no RTB
            if (UndockTarget == null)
            {
                return;
            }

            // Schedule the autopilot
            BeginReturn(commons, eventDriver);
            Mode = Modes.Returning;
            SaveMode(commons);
        }
        else if (argument == "smartreset")
        {
            autopilot.Reset(commons);
            ResetMode(commons);
        }
    }
Exemple #19
0
    public void ManageShip(ZACommons commons, EventDriver eventDriver,
                           bool docked)
    {
        if (!docked)
        {
            for (var i = 0; i < DockingHandlers.Length; i++)
            {
                DockingHandlers[i].DockingAction(commons, eventDriver, false);
            }
        }

        ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyThrust>(commons.Blocks), !docked);
        ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyGyro>(commons.Blocks), !docked);
        var batteries = ZACommons.GetBlocksOfType <IMyBatteryBlock>(commons.Blocks);

        for (var e = batteries.GetEnumerator(); e.MoveNext();)
        {
            var battery = (IMyBatteryBlock)e.Current;
            battery.SetValue <bool>("Recharge", docked);
            battery.SetValue <bool>("Discharge", !docked);
        }
        if (!docked)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyReactor>(commons.Blocks), true);
        }

        if (TOUCH_ANTENNA)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyRadioAntenna>(commons.Blocks), !docked);
            // Now defaults to off in 01.124. Thanks, Keen!
            if (!docked)
            {
                eventDriver.Schedule(2, (c, ed) =>
                {
                    ZACommons.GetBlocksOfType <IMyRadioAntenna>(commons.Blocks).ForEach(antenna => antenna.SetValue <bool>("EnableBroadCast", true));
                });
            }
        }
        if (TOUCH_LANTENNA)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyLaserAntenna>(commons.Blocks), !docked);
        }
        if (TOUCH_BEACON)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyBeacon>(commons.Blocks), !docked);
        }
        if (TOUCH_LIGHTS)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyLightingBlock>(commons.Blocks), !docked);
        }
        // Disable tools if we just docked
        if (TOUCH_TOOLS && docked)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyShipToolBase>(commons.Blocks), false);
        }
        if (TOUCH_OXYGEN)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyOxygenGenerator>(commons.Blocks), !docked);
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyOxygenFarm>(commons.Blocks), !docked);
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyAirVent>(commons.Blocks,
                                                                          vent => ((IMyAirVent)vent).IsDepressurizing &&
                                                                          vent.CustomName.IndexOf("[Intake]", ZACommons.IGNORE_CASE) >= 0), !docked);
            var tanks = ZACommons.GetBlocksOfType <IMyOxygenTank>(commons.Blocks,
                                                                  tank => tank.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0);
            tanks.ForEach(tank => tank.SetValue <bool>("Stockpile", docked));
        }
        if (TOUCH_SENSORS)
        {
            ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMySensorBlock>(commons.Blocks), !docked);
        }

        if (docked)
        {
            for (var i = 0; i < DockingHandlers.Length; i++)
            {
                DockingHandlers[i].DockingAction(commons, eventDriver, true);
            }
        }

        IsDocked = docked;
        if (IsDocked)
        {
            eventDriver.Schedule(RunDelay, Sleep);
        }
    }
Exemple #20
0
 public void LowBattery(ZACommons commons, EventDriver eventDriver,
                        bool started)
 {
     // Enable/disable reactor according to state
     ZACommons.EnableBlocks(ZACommons.GetBlocksOfType <IMyReactor>(commons.Blocks), started);
 }