Ejemplo n.º 1
0
            bool TryLockInStator(double distance)
            {
                IMyMotorStator clamp = Reference as IMyMotorStator;

                clamp.Enabled   = true;
                clamp.RotorLock = true;
                clamp.Attach();
                return(clamp.IsAttached);
            }
Ejemplo n.º 2
0
            private IEnumerable <int> UnlockSchedule()
            {
                // Current state: Locked, in any position
                // Target state: Unlocked, in same position

                Motor.Attach();
                // Deactivate merge blocks and connectors
                MergeBlock1.Enabled = false;
                MergeBlock2.Enabled = false;
                Connector1.Enabled  = false;
                Connector2.Enabled  = false;
                // Increase distance to ship to avoid clang
                Motor.Displacement = -0.4f;
                // Wait for everything to settle
                yield return(20);

                // Wait for rotor head to finish extending
                while (Motor.Displacement < -0.15f)
                {
                    Motor.Displacement += 0.01f;
                    yield return(10);
                }
            }
        public void Update()
        {
            if (!setup)
            {
                setup           = true;
                Piston.Velocity = 0.2f;

                if (!Hummingbird.CheckHummingbirdComponents(ChasisMerge, ref hummingbirdConnector, ref turretRotor, ref PartScratchpad, ref status))
                {
                    return;
                }

                if (Hummingbird.CheckHummingbirdComponents(TurretMerge, ref hummingbirdConnector, ref turretRotor, ref PartScratchpad, ref status))
                {
                    turretRotor.Detach();
                    releaseStage    = 1;
                    Piston.Velocity = -0.2f;
                    return;
                }

                if (turretRotor != null)
                {
                    Hummingbird = Hummingbird.GetHummingbird(turretRotor, Host.Context.Terminal.GetBlockGroupWithName(Hummingbird.GroupName));
                    if (Hummingbird.Gats.Count == 0)
                    {
                        Hummingbird         = null;
                        TurretMerge.Enabled = true;
                        return;
                    }
                    releaseStage             = 20;
                    turretRotor.Displacement = 0.11f;
                    return;
                }
            }


            if (releaseStage > 1 && releaseStage < 20)
            {
                releaseStage++;
            }
            if (releaseStage == 5)
            {
            }
            else if (releaseStage == 7)
            {
            }
            else if (releaseStage == 8)
            {
                GridTerminalHelper.OtherMergeBlock(TurretMerge).Enabled = false;
                TurretMerge.Enabled = false;
            }
            else if (releaseStage == 9)
            {
                turretRotor.Attach();
            }
            else if (releaseStage == 10)
            {
                Piston.Velocity = 0.2f;
            }
            else if (releaseStage > 11 && Piston.CurrentPosition == Piston.MaxLimit)
            {
                turretRotor.Displacement = 0.11f;
                Hummingbird = Hummingbird.GetHummingbird(turretRotor, Host.Context.Terminal.GetBlockGroupWithName(Hummingbird.GroupName));
            }
        }
Ejemplo n.º 4
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (!setupError)
            {
                if ((updateSource & UpdateType.Update1) != 0)
                {
                    switch (reloadState)
                    {
                    case ReloadStates.RELOAD_COMPLETE:
                        // All done!
                        break;

                    case ReloadStates.RETRACTING_PLACER:
                        if (PlacerPiston.CurrentPosition == PlacerPiston.MinLimit)
                        {
                            Echo("Moving clip.");
                            reloadState = ReloadStates.MOVING_CLIP;
                            GridTerminalSystem.GetBlocksOfType <IMyWarhead>(warheads);
                        }
                        else
                        {
                            PlacerPiston.Retract();
                        }
                        break;

                    case ReloadStates.MOVING_CLIP:
                        var closestWarheadDistance = GetClosestDistance(warheads, PlacerRotor);
                        if (closestWarheadDistance < 0.5)
                        {
                            ClipPiston.Enabled = false;

                            Echo("Loading warhead.");
                            reloadState = ReloadStates.LOADING_WARHEAD;
                        }
                        else if (warheads.Count() == 0 && ClipPiston.CurrentPosition == ClipPiston.MaxLimit)
                        {
                            Echo("Out of warheads.");
                            reloadState = ReloadStates.RELOAD_COMPLETE;
                        }
                        else
                        {
                            ClipPiston.Enabled = true;
                            ClipPiston.Extend();
                        }
                        break;

                    case ReloadStates.LOADING_WARHEAD:
                        if (PlacerRotor.IsAttached)
                        {
                            var rotors = new List <IMyMotorStator>();
                            GridTerminalSystem.GetBlocksOfType <IMyMotorStator>(rotors, (IMyMotorStator x) => x.CubeGrid == ClipPiston.TopGrid && x.TopGrid == PlacerRotor.TopGrid);

                            if (rotors.Count() > 0)
                            {
                                var otherRotor = rotors.First();
                                otherRotor.Detach();
                            }

                            Echo("Extending placer.");
                            reloadState = ReloadStates.EXTENDING_PLACER;
                        }
                        else
                        {
                            Echo("Attaching.");
                            PlacerRotor.Attach();
                        }
                        break;

                    case ReloadStates.EXTENDING_PLACER:
                        if (PlacerPiston.CurrentPosition == PlacerPiston.MaxLimit)
                        {
                            Echo("Reload complete.");
                            reloadState = ReloadStates.RELOAD_COMPLETE;
                        }
                        else
                        {
                            PlacerPiston.Extend();
                        }
                        break;

                    default:
                        Echo("Encountered unexpected state while reloading.");
                        break;
                    }
                }
                else if (argument.ToLower() == "reload")
                {
                    Echo("Retracting placer piston.");
                    PlacerRotor.Detach();
                    reloadState = ReloadStates.RETRACTING_PLACER;
                }
                else if (argument.ToLower() == "fire")
                {
                    if (PlacerRotor.IsAttached)
                    {
                        Echo("Deploying payload.");
                        var viableWarheads = new List <IMyWarhead>();
                        GridTerminalSystem.GetBlocksOfType <IMyWarhead>(viableWarheads, (IMyWarhead x) => x.CubeGrid == PlacerRotor.TopGrid);
                        foreach (var warhead in viableWarheads)
                        {
                            warhead.DetonationTime = DetonationTime;
                            warhead.StartCountdown();
                        }

                        if (viableWarheads.Count() > 0)
                        {
                            countdown    = DetonationTime;
                            bombPosition = PlacerRotor.GetPosition();
                        }

                        PlacerRotor.Detach();
                        reloadState = ReloadStates.RETRACTING_PLACER;
                    }
                }
                else if (argument.ToLower().StartsWith("timer"))
                {
                    int.TryParse(argument.ToLower().Substring("timer".Length), out DetonationTime);
                }
            }
        }