Example #1
0
            private void SimpleLightControl()
            {
                int light_timer = program.MyProperty.sound_timer;

                if (light != null)
                {
                    light.ForEach(delegate(IMyLightingBlock block) {
                        string type = block.BlockDefinition.SubtypeName;
                        if (type.Contains("Rotating"))
                        {
                            if (State == StateMachine.Running && Sleep > 0 && (Sleep - light_timer <= 0))
                            {
                                block.ApplyAction("OnOff_On");
                            }
                            else
                            {
                                block.ApplyAction("OnOff_Off");
                            }
                        }
                        else
                        {
                            if (Sequence == ActionMachine.Sleep)
                            {
                                if (Sleep > 0 && (Sleep - light_timer <= 0))
                                {
                                    if (!blinkEnabled)
                                    {
                                        block.BlinkLength          = program.MyProperty.blink_length;
                                        block.BlinkIntervalSeconds = program.MyProperty.blink_interval_seconds;
                                        block.Color = program.MyProperty.GetColor("Airlock", "running_color");
                                    }
                                }
                                else
                                {
                                    block.BlinkIntervalSeconds = 0;
                                    block.Color  = program.MyProperty.GetColor("Airlock", "pressurised_color");
                                    blinkEnabled = false;
                                }
                            }
                            else
                            {
                                block.BlinkIntervalSeconds = 0;
                                if (openned)
                                {
                                    block.Color = program.MyProperty.GetColor("Airlock", "pressurised_color");
                                }
                                else
                                {
                                    block.Color = program.MyProperty.GetColor("Airlock", "depressurised_color");
                                }
                                blinkEnabled = false;
                            }
                            block.ApplyAction("OnOff_On");
                        }
                    });
                }
            }
Example #2
0
            private void SoundControl()
            {
                int sound_timer = program.MyProperty.sound_timer;

                if (sound != null)
                {
                    sound.ForEach(delegate(IMySoundBlock block)
                    {
                        block.ApplyAction("OnOff_On");
                        if (State == StateMachine.Running)
                        {
                            if (!soundEnabled && Sleep > 0 && (Sleep - sound_timer == 0))
                            {
                                block.Play();
                                soundEnabled = true;
                            }
                        }
                        else
                        {
                            block.Stop();
                            soundEnabled = false;
                        }
                    });
                }
            }
Example #3
0
 public void WriteText(string message, bool append)
 {
     message += "\n";
     drawingSurface.WriteText(message, append);
     control_lcds.ForEach(delegate(IMyTextPanel block)
     {
         block.WriteText(message, append);
     });
 }
Example #4
0
        private void Init()
        {
            MyProperty = new KProperty(this);
            MyProperty.Load();
            Stage          = 0;
            bottom_pistons = BlockSystem <IMyPistonBase> .SearchByGroup(this, "Foreuse Bottom Pistons");

            bottom_pistons.ForEach(delegate(IMyPistonBase block) {
                block.MinLimit = MyProperty.locker_position_min;
                block.MaxLimit = MyProperty.locker_position_max;
            });
            bottom_mergers = BlockSystem <IMyShipMergeBlock> .SearchByGroup(this, "Foreuse Bottom Mergers");

            top_pistons = BlockSystem <IMyPistonBase> .SearchByGroup(this, "Foreuse Top Pistons");

            top_pistons.ForEach(delegate(IMyPistonBase block) {
                block.MinLimit = MyProperty.locker_position_min;
                block.MaxLimit = MyProperty.locker_position_max;
            });
            top_mergers = BlockSystem <IMyShipMergeBlock> .SearchByGroup(this, "Foreuse Top Mergers");

            connector = BlockSystem <IMyShipConnector> .SearchByName(this, "Foreuse Connector Drills");

            levage_pistons = BlockSystem <IMyPistonBase> .SearchByGroup(this, "Foreuse Levage Pistons");

            levage_pistons.ForEach(delegate(IMyPistonBase block) {
                block.MinLimit = MyProperty.elevator_position_min;
                block.MaxLimit = MyProperty.elevator_position_max;
            });

            grinder_stator = BlockSystem <IMyMotorStator> .SearchByName(this, "Foreuse Grinder Stator");

            grinders = BlockSystem <IMyShipGrinder> .SearchByGroup(this, "Foreuse Grinders");

            welder_stator = BlockSystem <IMyMotorStator> .SearchByName(this, "Foreuse Welder Stator");

            welders = BlockSystem <IMyShipWelder> .SearchByGroup(this, "Foreuse Welders");

            projector = BlockSystem <IMyProjector> .SearchByName(this, "Foreuse Projector Drill");

            light = BlockSystem <IMyLightingBlock> .SearchByGroup(this, "Foreuse Rotating Light");

            drills = BlockSystem <IMyShipDrill> .SearchByGroup(this, "Foreuse Drills");

            control_lcds = BlockSystem <IMyTextPanel> .SearchByName(this, "Foreuse Control LCD");

            control_lcds.ForEach(delegate(IMyTextPanel block)
            {
                block.ContentType = ContentType.TEXT_AND_IMAGE;
            });

            SequenceBlocks = new List <int>()
            {
            };
        }
Example #5
0
 public void WriteText(string message, bool append)
 {
     message += "\n";
     if (control_lcds != null)
     {
         control_lcds.ForEach(delegate(IMyTextPanel block)
         {
             block.WriteText(message, append);
         });
     }
 }
Example #6
0
        private void UnRenamePrefix(string tag)
        {
            BlockSystem <IMyTerminalBlock> blocks = BlockSystem <IMyTerminalBlock> .SearchBlocks(this);

            blocks.ForEach(delegate(IMyTerminalBlock block)
            {
                if (block.CustomName.StartsWith(tag))
                {
                    block.CustomName = block.CustomName.Replace(tag + " ", "");
                }
            });
        }
Example #7
0
 public void SolarPower()
 {
     if (solar_panels != null && !solar_panels.IsEmpty)
     {
         power     = 0f;
         max_power = 0f;
         solar_panels.ForEach(delegate(IMySolarPanel block){
             power     += block.CurrentOutput;
             max_power += block.MaxOutput;
         });
     }
 }
Example #8
0
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                if (search)
                {
                    Search();
                }
                List <string> types = new List <string>();
                int           limit = 0;

                if (machine_refinery)
                {
                    types.Add("Refinery");
                    limit += 1;
                }
                if (machine_assembler)
                {
                    types.Add("Assembler");
                    limit += 1;
                }
                limit = 6 / limit;
                if (types.Count > 0)
                {
                    Style style = new Style()
                    {
                        Width   = 250,
                        Height  = 80,
                        Padding = new StylePadding(0),
                    };

                    foreach (string type in types)
                    {
                        int count = 0;
                        producers.List.Sort(new BlockComparer());
                        producers.ForEach(delegate(IMyProductionBlock block)
                        {
                            if (block.GetType().Name.Contains(type))
                            {
                                Vector2 position2 = position + new Vector2(style.Width * (count / limit), style.Height * (count - (count / limit) * limit));
                                List <Item> items = TraversalMachine(block);
                                DrawMachine(drawing, position2, block, items, style);
                                count += 1;
                            }
                        });
                        position += new Vector2(0, style.Height) * limit;
                    }
                }

                return(position);
            }
Example #9
0
        private void Prepare()
        {
            BlockFilter <IMyRefinery> filterRefinery = new BlockFilter <IMyRefinery>()
            {
                CubeGrid = Me.CubeGrid
            };

            refinery = BlockSystem <IMyRefinery> .SearchByFilter(this, filterRefinery);

            refinery.ForEach(delegate(IMyRefinery block)
            {
                block.UseConveyorSystem = false;
            });
            BlockFilter <IMyCargoContainer> filterContainer = new BlockFilter <IMyCargoContainer>()
            {
                Filter   = "Ore",
                CubeGrid = Me.CubeGrid
            };

            stock = BlockSystem <IMyCargoContainer> .SearchByFilter(this, filterContainer);
        }
Example #10
0
 private void DisplayControl()
 {
     if (control_panel != null)
     {
         airvent.ForEach(delegate(IMyAirVent block) {
             OxygenRate = block.GetOxygenLevel() * 100;
         });
         control_panel.ForEach(delegate(IMyTextPanel block)
         {
             string type = block.BlockDefinition.SubtypeName;
             if (type.Contains("Corner"))
             {
                 DrawSmallControl(block);
             }
             else
             {
                 DrawNormalControl(block);
             }
         });
     }
 }
Example #11
0
            public void Search()
            {
                BlockFilter <IMyDoor> block_filter_doors = BlockFilter <IMyDoor> .Create(program.Me, $"G:{GroupFilter}");

                doors = BlockSystem <IMyDoor> .SearchByFilter(program, block_filter_doors);

                BlockFilter <IMyAirVent> block_filter_airvent = BlockFilter <IMyAirVent> .Create(program.Me, $"G:{GroupFilter}");

                airvent = BlockSystem <IMyAirVent> .SearchByFilter(program, block_filter_airvent);

                BlockFilter <IMyTextPanel> block_filter_control = BlockFilter <IMyTextPanel> .Create(program.Me, $"G:{GroupFilter}");

                control_panel = BlockSystem <IMyTextPanel> .SearchByFilter(program, block_filter_control);

                BlockFilter <IMyLightingBlock> block_filter_light = BlockFilter <IMyLightingBlock> .Create(program.Me, $"G:{GroupFilter}");

                light = BlockSystem <IMyLightingBlock> .SearchByFilter(program, block_filter_light);

                BlockFilter <IMySoundBlock> block_filter_sound = BlockFilter <IMySoundBlock> .Create(program.Me, $"G:{GroupFilter}");

                sound = BlockSystem <IMySoundBlock> .SearchByFilter(program, block_filter_sound);

                if (control_panel != null)
                {
                    control_panel.ForEach(delegate(IMyTextPanel block)
                    {
                        block.ScriptBackgroundColor = Color.Black;
                    });
                }

                if (light != null)
                {
                    light.ForEach(delegate(IMyLightingBlock block)
                    {
                        block.Color = program.MyProperty.GetColor("Airlock", "running_color");
                    });
                    light.Off();
                }
            }
Example #12
0
            private Vector2 DisplayGauge(Drawing drawing, Vector2 position)
            {
                long volumes    = 0;
                long maxVolumes = 1;

                inventories.ForEach(delegate(IMyTerminalBlock block)
                {
                    for (int i = 0; i < block.InventoryCount; i++)
                    {
                        IMyInventory block_inventory = block.GetInventory(i);
                        long volume    = block_inventory.CurrentVolume.RawValue;
                        volumes       += volume;
                        long maxVolume = block_inventory.MaxVolume.RawValue;
                        maxVolumes    += maxVolume;
                        //drawingSurface.WriteText($"\nVolume:{volume}/{maxVolume}", true);
                    }
                });
                //drawingSurface.WriteText($"\nVolume:{volumes}/{maxVolumes}", true);
                StyleGauge style = new StyleGauge()
                {
                    Orientation = gaugeHorizontal ? SpriteOrientation.Horizontal : SpriteOrientation.Vertical,
                    Fullscreen  = gaugeFullscreen,
                    Width       = gaugeWidth,
                    Height      = gaugeHeight
                };

                drawing.DrawGauge(position, volumes, maxVolumes, style);
                if (gaugeHorizontal)
                {
                    position += new Vector2(0, gaugeHeight + topPadding);
                }
                else
                {
                    position += new Vector2(gaugeWidth + leftPadding, 0);
                }
                return(position);
            }
Example #13
0
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                if (search)
                {
                    Search();
                }

                float      width          = drills_size;
                float      padding        = 4f;
                float      x_min          = 0f;
                float      x_max          = 0f;
                float      y_min          = 0f;
                float      y_max          = 0f;
                bool       first          = true;
                Vector2    padding_screen = new Vector2(drills_padding_x, drills_padding_y);
                StyleGauge style          = new StyleGauge()
                {
                    Orientation     = SpriteOrientation.Horizontal,
                    Fullscreen      = false,
                    Width           = width,
                    Height          = width,
                    Padding         = new StylePadding(0),
                    Round           = false,
                    RotationOrScale = 0.5f,
                    Percent         = drills_size > 49 ? true : false
                };

                if (drills_info)
                {
                    drawing.AddSprite(new MySprite()
                    {
                        Type            = SpriteType.TEXT,
                        Data            = $"Drill Number:{drill_inventories.List.Count} ({filter})",
                        Size            = new Vector2(width, width),
                        Color           = Color.DimGray,
                        Position        = position + new Vector2(0, 0),
                        RotationOrScale = 0.5f,
                        FontId          = drawing.Font,
                        Alignment       = TextAlignment.LEFT
                    });
                    position += new Vector2(0, 20);
                }
                drill_inventories.ForEach(delegate(IMyShipDrill drill)
                {
                    switch (drills_orientation)
                    {
                    case "x":
                        if (first || drill.Position.Y < x_min)
                        {
                            x_min = drill.Position.Y;
                        }
                        if (first || drill.Position.Y > x_max)
                        {
                            x_max = drill.Position.Y;
                        }
                        if (first || drill.Position.Z < y_min)
                        {
                            y_min = drill.Position.Z;
                        }
                        if (first || drill.Position.Z > y_max)
                        {
                            y_max = drill.Position.Z;
                        }
                        break;

                    case "y":
                        if (first || drill.Position.X < x_min)
                        {
                            x_min = drill.Position.X;
                        }
                        if (first || drill.Position.X > x_max)
                        {
                            x_max = drill.Position.X;
                        }
                        if (first || drill.Position.Z < y_min)
                        {
                            y_min = drill.Position.Z;
                        }
                        if (first || drill.Position.Z > y_max)
                        {
                            y_max = drill.Position.Z;
                        }
                        break;

                    default:
                        if (first || drill.Position.X < x_min)
                        {
                            x_min = drill.Position.X;
                        }
                        if (first || drill.Position.X > x_max)
                        {
                            x_max = drill.Position.X;
                        }
                        if (first || drill.Position.Y < y_min)
                        {
                            y_min = drill.Position.Y;
                        }
                        if (first || drill.Position.Y > y_max)
                        {
                            y_max = drill.Position.Y;
                        }
                        break;
                    }
                    first = false;
                });
                //drawingSurface.WriteText($"X min:{x_min} Y min:{y_min}\n", false);
                drill_inventories.ForEach(delegate(IMyShipDrill drill)
                {
                    IMyInventory block_inventory = drill.GetInventory(0);
                    long volume    = block_inventory.CurrentVolume.RawValue;
                    long maxVolume = block_inventory.MaxVolume.RawValue;
                    float x        = 0;
                    float y        = 0;
                    switch (drills_orientation)
                    {
                    case "x":
                        x = Math.Abs(drill.Position.Y - x_min);
                        y = Math.Abs(drill.Position.Z - y_min);
                        break;

                    case "y":
                        x = Math.Abs(drill.Position.X - x_min);
                        y = Math.Abs(drill.Position.Z - y_min);
                        break;

                    default:
                        x = Math.Abs(drill.Position.X - x_min);
                        y = Math.Abs(drill.Position.Y - y_min);
                        break;
                    }
                    //drawingSurface.WriteText($"X:{x} Y:{y}\n", true);
                    if (drills_flip_x)
                    {
                        x = Math.Abs(x_max - x_min) - x;
                    }
                    if (drills_flip_y)
                    {
                        y = Math.Abs(y_max - y_min) - y;
                    }
                    //drawingSurface.WriteText($"Volume [{x},{y}]:{volume}/{maxVolume}\n", true);
                    Vector2 position_relative = drills_rotate ? new Vector2(y * (width + padding), x * (width + padding)) : new Vector2(x * (width + padding), y * (width + padding));

                    drawing.DrawGauge(position + position_relative + padding_screen, volume, maxVolume, style);
                });

                return(position);
            }
Example #14
0
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                List <string> types = new List <string>();

                if (tank_h2)
                {
                    types.Add("Hydrogen");
                }
                if (tank_o2)
                {
                    types.Add("Oxygen");
                }
                if (types.Count > 0)
                {
                    foreach (string type in types)
                    {
                        BlockSystem <IMyGasTank> tanks = BlockSystem <IMyGasTank> .SearchBlocks(DisplayLcd.program, block => block.BlockDefinition.SubtypeName.Contains(type));

                        float      volumes  = 0f;
                        float      capacity = 0f;
                        float      width    = 50f;
                        StyleGauge style    = new StyleGauge()
                        {
                            Orientation     = SpriteOrientation.Horizontal,
                            Fullscreen      = true,
                            Width           = width,
                            Height          = width,
                            Padding         = new StylePadding(0),
                            Round           = false,
                            RotationOrScale = 0.5f
                        };

                        MySprite text = new MySprite()
                        {
                            Type            = SpriteType.TEXT,
                            Color           = Color.DimGray,
                            Position        = position + new Vector2(0, 0),
                            RotationOrScale = 1f,
                            FontId          = drawing.Font,
                            Alignment       = TextAlignment.LEFT
                        };

                        tanks.ForEach(delegate(IMyGasTank block)
                        {
                            volumes  += (float)block.FilledRatio * block.Capacity;
                            capacity += block.Capacity;
                        });

                        drawing.DrawGauge(position, volumes, capacity, style);
                        position += new Vector2(0, 60);
                        switch (type)
                        {
                        case "Hydrogen":
                            text.Data = $"H2: {Math.Round(volumes, 2)}L / {Math.Round(capacity, 2)}L";
                            break;

                        case "Oxygen":
                            text.Data = $"O2: {Math.Round(volumes, 2)}L / {Math.Round(capacity, 2)}L";
                            break;
                        }
                        text.Position = position;
                        drawing.AddSprite(text);
                        position += new Vector2(0, 60);
                    }
                }
                return(position);
            }
Example #15
0
        void Running()
        {
            delta = max_power - last_power;
            switch (machine_state)
            {
            case StateMachine.Stopped:
                lat_stators.Off();
                lat_stators.Lock();
                lon_stators.Off();
                lon_stators.Lock();

                if (Math.Abs(delta) > MyProperty.Lat_Delta)
                {
                    machine_state = StateMachine.TrakingLat;
                    last_power    = 0;
                }
                break;

            case StateMachine.TrakingLat:
                if (Math.Abs(delta) < MyProperty.Lat_Delta)
                {
                    machine_state = StateMachine.TrakingLon;
                }
                else
                {
                    if (delta < 0)
                    {
                        lat_state = lat_state == StateLat.Forward ? StateLat.Backward : StateLat.Forward;
                    }

                    lat_stators.ForEach(delegate(IMyMotorStator block) {
                        if (lat_state == StateLat.Forward)
                        {
                            block.TargetVelocityRPM = MyProperty.Lat_Speed;
                        }
                        else
                        {
                            block.TargetVelocityRPM = -MyProperty.Lat_Speed;
                        }
                    });
                    lat_stators.On();
                    lat_stators.Unlock();
                }
                break;

            case StateMachine.TrakingLon:
                if (Math.Abs(delta) < MyProperty.Lat_Delta)
                {
                    machine_state = StateMachine.Stopped;
                }
                else
                {
                    if (delta < 0)
                    {
                        lon_state = lon_state == StateLon.Forward ? StateLon.Backward : StateLon.Forward;
                    }

                    float factor = 1f;
                    lon_stators.ForEach(delegate(IMyMotorStator block) {
                        if (lon_state == StateLon.Forward)
                        {
                            block.TargetVelocityRPM = MyProperty.Lat_Speed * factor;
                        }
                        else
                        {
                            block.TargetVelocityRPM = -MyProperty.Lat_Speed * factor;
                        }
                        factor *= -1f;
                    });
                    lon_stators.On();
                    lon_stators.Unlock();
                }
                break;

            default:
                if (Math.Abs(delta) < MyProperty.Lat_Delta)
                {
                    machine_state = StateMachine.Stopped;
                }
                else
                {
                    machine_state = StateMachine.TrakingLat;
                }
                break;
            }
            last_power = max_power;
        }
Example #16
0
        private void Staging(ActionMachine action)
        {
            bool  closed          = true;
            float position_target = 0f;
            float velocity        = 0f;

            switch (action)
            {
            case ActionMachine.LockBottom:
                velocity        = -MyProperty.locker_velocity;
                position_target = MyProperty.locker_position_min;

                bottom_mergers.On();
                bottom_pistons.Velocity(velocity);
                WriteText($"Bottom mergers: On", true);
                WriteText($"Velocity: {velocity}", true);
                WriteText($"Target Position={position_target}", true);
                closed = true;

                bottom_pistons.ForEach(delegate(IMyPistonBase block)
                {
                    WriteText($"Position={block.CurrentPosition}", true);
                });

                if (bottom_pistons.IsLessPosition(position_target))
                {
                    Stage++;
                }
                break;

            case ActionMachine.UnlockBottom:
                closed = true;
                top_mergers.ForEach(delegate(IMyShipMergeBlock block) {
                    if (!block.IsConnected)
                    {
                        closed = false;
                    }
                });
                if (!closed)
                {
                    WriteText($"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", true);
                    WriteText($"Security: Top mergers is Off", true);
                }
                else
                {
                    velocity        = MyProperty.locker_velocity;
                    position_target = MyProperty.locker_position_max;

                    bottom_mergers.Off();
                    bottom_pistons.Velocity(velocity);
                    WriteText($"Bottom mergers: Off", true);
                    WriteText($"Velocity: {velocity}", true);
                    WriteText($"Target Position={position_target}", true);
                    closed = true;

                    bottom_pistons.ForEach(delegate(IMyPistonBase block)
                    {
                        WriteText($"Position={block.CurrentPosition}", true);
                    });

                    if (bottom_pistons.IsMorePosition(position_target))
                    {
                        Stage++;
                    }
                }
                break;

            case ActionMachine.LockTop:
                velocity        = -MyProperty.locker_velocity;
                position_target = MyProperty.locker_position_min;

                top_mergers.On();
                top_pistons.Velocity(velocity);
                WriteText($"Bottom mergers: On", true);
                WriteText($"Velocity: {velocity}", true);
                WriteText($"Target Position={position_target}", true);
                closed = true;

                top_pistons.ForEach(delegate(IMyPistonBase block)
                {
                    WriteText($"Position={block.CurrentPosition}", true);
                });

                if (top_pistons.IsLessPosition(position_target))
                {
                    connector.Lock();
                    Stage++;
                }
                break;

            case ActionMachine.UnlockTop:
                closed = true;
                bottom_mergers.ForEach(delegate(IMyShipMergeBlock block) {
                    if (!block.IsConnected)
                    {
                        closed = false;
                    }
                });
                if (!closed)
                {
                    WriteText($"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", true);
                    WriteText($"Security: Bottom mergers is Off", true);
                }
                else
                {
                    velocity        = MyProperty.locker_velocity;
                    position_target = MyProperty.locker_position_max;

                    top_mergers.Off();
                    top_pistons.Velocity(velocity);
                    connector.Unlock();
                    WriteText($"Top mergers: Off", true);
                    WriteText($"Connector: Unlock", true);
                    WriteText($"Velocity: {velocity}", true);
                    WriteText($"Target Position={position_target}", true);
                    closed = true;

                    top_pistons.ForEach(delegate(IMyPistonBase block)
                    {
                        WriteText($"Position={block.CurrentPosition}", true);
                    });

                    if (top_pistons.IsMorePosition(position_target))
                    {
                        Stage++;
                    }
                }
                break;

            case ActionMachine.Down:
                levage_pistons.On();
                WriteText($"Piston Levage: On", true);

                velocity = MyProperty.elevator_velocity_min;
                if (Mode == ModeMachine.Up)
                {
                    velocity = MyProperty.elevator_velocity_max;
                }
                WriteText($"Piston Velocity: {velocity}", true);
                levage_pistons.Velocity(velocity);

                position_target = MyProperty.elevator_position_max;
                WriteText($"Target Position={position_target}", true);

                levage_pistons.ForEach(delegate(IMyPistonBase block)
                {
                    WriteText($"Position={block.CurrentPosition}", true);
                });

                //projector_count = projector.List[0].RemainingBlocks;
                if (levage_pistons.IsMorePosition(position_target))
                {
                    Stage++;
                }
                break;

            case ActionMachine.Up:
                levage_pistons.On();
                WriteText($"Piston Levage: On", true);

                velocity = -MyProperty.elevator_velocity_max;
                if (Mode == ModeMachine.Up)
                {
                    velocity = -MyProperty.elevator_velocity_min;
                }
                WriteText($"Piston Velocity: {velocity}", true);
                levage_pistons.Velocity(velocity);

                position_target = MyProperty.elevator_position_min;
                WriteText($"Target Position={position_target}", true);

                levage_pistons.ForEach(delegate(IMyPistonBase block)
                {
                    WriteText($"Position={block.CurrentPosition}", true);
                });
                //projector_count = projector.List[0].RemainingBlocks;
                if (levage_pistons.IsLessPosition(position_target + 0.1f))
                {
                    Stage++;
                }
                break;

            case ActionMachine.StartWelder:
                projector.On();
                welders.On();
                WriteText($"Welders: On", true);
                Stage++;
                break;

            case ActionMachine.StopWelder:
                welders.Off();
                projector.Off();
                WriteText($"Welders: Off", true);

                Stage++;
                break;

            case ActionMachine.StartGrinder:
                grinders.On();
                //projector.On();
                WriteText($"Grinders: On", true);

                Stage++;
                break;

            case ActionMachine.StopGrinder:
                grinders.Off();
                //projector.Off();
                WriteText($"Grinders: Off", true);

                Stage++;
                break;

            case ActionMachine.Terminated:
                Cycle -= 1;
                if (Cycle == 0)
                {
                    Mode = ModeMachine.Stop;
                }
                Stage = 0;
                break;

            case ActionMachine.Start:
                MyProperty.Load();
                light.On();
                drills.On();
                Stage++;
                break;

            case ActionMachine.Stop:
                projector.Off();
                light.Off();
                drills.Off();
                Stage++;
                break;
            }
        }
Example #17
0
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                BlockSystem <IMyTerminalBlock> producers = BlockSystem <IMyTerminalBlock> .SearchBlocks(DisplayLcd.program, block => block.Components.Has <MyResourceSourceComponent>());

                BlockSystem <IMyTerminalBlock> consummers = BlockSystem <IMyTerminalBlock> .SearchBlocks(DisplayLcd.program, block => block.Components.Has <MyResourceSinkComponent>());

                Dictionary <string, Power> outputs = new Dictionary <string, Power>();
                Power batteries_store = new Power()
                {
                    Type = "Batteries"
                };

                outputs.Add("all", new Power()
                {
                    Type = "All"
                });
                float      current_input = 0f;
                float      max_input     = 0f;
                float      width         = 30f;
                StyleGauge style         = new StyleGauge()
                {
                    Orientation     = SpriteOrientation.Horizontal,
                    Fullscreen      = true,
                    Width           = width,
                    Height          = width,
                    Padding         = new StylePadding(0),
                    Round           = false,
                    RotationOrScale = 0.5f
                };

                MySprite text = new MySprite()
                {
                    Type            = SpriteType.TEXT,
                    Color           = Color.DimGray,
                    Position        = position + new Vector2(0, 0),
                    RotationOrScale = .6f,
                    FontId          = drawing.Font,
                    Alignment       = TextAlignment.LEFT
                };

                producers.ForEach(delegate(IMyTerminalBlock block)
                {
                    string type = block.BlockDefinition.SubtypeName;
                    if (block is IMyBatteryBlock)
                    {
                        IMyBatteryBlock battery = (IMyBatteryBlock)block;
                        batteries_store.AddCurrent(battery.CurrentStoredPower);
                        batteries_store.AddMax(battery.MaxStoredPower);
                    }
                    else
                    {
                        MyResourceSourceComponent resourceSource;
                        block.Components.TryGet <MyResourceSourceComponent>(out resourceSource);
                        if (resourceSource != null)
                        {
                            ListReader <MyDefinitionId> myDefinitionIds = resourceSource.ResourceTypes;
                            if (myDefinitionIds.Contains(PowerDefinitionId))
                            {
                                Power global_output = outputs["all"];
                                global_output.AddCurrent(resourceSource.CurrentOutputByType(PowerDefinitionId));
                                global_output.AddMax(resourceSource.MaxOutputByType(PowerDefinitionId));

                                if (!outputs.ContainsKey(type))
                                {
                                    outputs.Add(type, new Power()
                                    {
                                        Type = type
                                    });
                                }
                                Power current_output = outputs[type];
                                current_output.AddCurrent(resourceSource.CurrentOutputByType(PowerDefinitionId));
                                current_output.AddMax(resourceSource.MaxOutputByType(PowerDefinitionId));
                            }
                        }
                    }
                });

                drawing.DrawGauge(position, outputs["all"].Current, outputs["all"].Max, style);

                foreach (KeyValuePair <string, Power> kvp in outputs)
                {
                    string title = kvp.Key;

                    position += new Vector2(0, 40);
                    if (kvp.Key.Equals("all"))
                    {
                        text.Data = $"Global Generator\n Out: {Math.Round(kvp.Value.Current, 2)}MW / {Math.Round(kvp.Value.Max, 2)}MW";
                    }
                    else
                    {
                        text.Data  = $"{title} (n={kvp.Value.Count})\n";
                        text.Data += $" Out: {Math.Round(kvp.Value.Current, 2)}MW / {Math.Round(kvp.Value.Max, 2)}MW";
                        text.Data += $" (Moy={kvp.Value.Moyen}MW)";
                    }
                    text.Position = position;
                    drawing.AddSprite(text);
                }

                position += new Vector2(0, 40);
                drawing.DrawGauge(position, batteries_store.Current, batteries_store.Max, style, true);
                position     += new Vector2(0, 40);
                text.Data     = $"Battery Store (n={batteries_store.Count})\n Store: {Math.Round(batteries_store.Current, 2)}MW / {Math.Round(batteries_store.Max, 2)}MW";
                text.Position = position;
                drawing.AddSprite(text);

                consummers.ForEach(delegate(IMyTerminalBlock block)
                {
                    if (block is IMyBatteryBlock)
                    {
                    }
                    else
                    {
                        MyResourceSinkComponent resourceSink;
                        block.Components.TryGet <MyResourceSinkComponent>(out resourceSink);
                        if (resourceSink != null)
                        {
                            ListReader <MyDefinitionId> myDefinitionIds = resourceSink.AcceptedResources;
                            if (myDefinitionIds.Contains(PowerDefinitionId))
                            {
                                max_input     += resourceSink.RequiredInputByType(PowerDefinitionId);
                                current_input += resourceSink.CurrentInputByType(PowerDefinitionId);
                            }
                        }
                    }
                });
                position += new Vector2(0, 40);
                drawing.DrawGauge(position, current_input, max_input, style, true);
                position     += new Vector2(0, 40);
                text.Data     = $"Power In: {Math.Round(current_input, 2)}MW / {Math.Round(max_input, 2)}MW";
                text.Position = position;
                drawing.AddSprite(text);

                return(position + new Vector2(0, 60));
            }
Example #18
0
            private void Staging(ActionMachine action)
            {
                bool state = true;

                switch (action)
                {
                case ActionMachine.Open:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        block.OpenDoor();
                        if (block.OpenRatio < 1 - Epsilon)
                        {
                            state = false;
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = true;
                    }
                    break;

                case ActionMachine.OpenInt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.OpenDoor();
                            if (block.OpenRatio < 1 - Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = true;
                    }
                    break;

                case ActionMachine.OpenExt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.OpenDoor();
                            if (block.OpenRatio < 1 - Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = true;
                    }
                    break;

                case ActionMachine.Close:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        block.CloseDoor();
                        if (block.OpenRatio > 0 + Epsilon)
                        {
                            state = false;
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = false;
                    }
                    break;

                case ActionMachine.CloseInt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.CloseDoor();
                            if (block.OpenRatio > 0 + Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = false;
                    }
                    break;

                case ActionMachine.CloseExt:
                    state = true;
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.CloseDoor();
                            if (block.OpenRatio > 0 + Epsilon)
                            {
                                state = false;
                            }
                        }
                    });
                    if (state)
                    {
                        Stage++;
                        openned = false;
                    }
                    break;

                case ActionMachine.Lock:
                    doors.ForEach(delegate(IMyDoor block) {
                        block.ApplyAction("OnOff_Off");
                    });
                    Stage++;
                    break;

                case ActionMachine.LockInt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.ApplyAction("OnOff_Off");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.LockExt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.ApplyAction("OnOff_Off");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.Unlock:
                    doors.ForEach(delegate(IMyDoor block) {
                        block.ApplyAction("OnOff_On");
                    });
                    Stage++;
                    break;

                case ActionMachine.UnlockInt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("int"))
                        {
                            block.ApplyAction("OnOff_On");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.UnlockExt:
                    doors.ForEach(delegate(IMyDoor block) {
                        if (block.CustomName.ToLower().Contains("ext"))
                        {
                            block.ApplyAction("OnOff_On");
                        }
                    });
                    Stage++;
                    break;

                case ActionMachine.Pressure:
                    airvent.ApplyAction("Depressurize_Off");
                    state = true;
                    airvent.ForEach(delegate(IMyAirVent block) {
                        VentStatus status = block.Status;
                        if (block.GetOxygenLevel() < 1 - Epsilon)
                        {
                            state = false;
                        }
                        WriteText($"Status:{status}", true);
                        WriteText($"Pressure:{block.GetOxygenLevel() * 100}", true);
                    });
                    if (state)
                    {
                        Stage++;
                    }
                    break;

                case ActionMachine.Depressure:
                    airvent.ApplyAction("Depressurize_On");
                    state = true;
                    airvent.ForEach(delegate(IMyAirVent block) {
                        VentStatus status = block.Status;
                        if (block.GetOxygenLevel() > 0 + Epsilon)
                        {
                            state = false;
                        }
                        WriteText($"Status:{status}", true);
                        WriteText($"Pressure:{block.GetOxygenLevel() * 100}", true);
                    });
                    if (state)
                    {
                        Stage++;
                    }
                    break;

                case ActionMachine.Sleep:
                    Sleep--;
                    WriteText($"Sleep:{Sleep}", true);
                    if (Sleep <= 0)
                    {
                        Stage++;
                    }
                    break;

                case ActionMachine.SleepInit:
                    Sleep = program.MyProperty.timer;
                    Stage++;
                    break;

                case ActionMachine.Start:
                    State = StateMachine.Running;
                    Stage++;
                    break;

                case ActionMachine.Stop:
                    State = StateMachine.Stop;
                    Sleep = 0;
                    Stage++;
                    break;

                case ActionMachine.Terminated:
                    Stage++;
                    break;

                case ActionMachine.TerminatedInt:
                    Stage++;
                    break;

                case ActionMachine.TerminatedExt:
                    Stage++;
                    break;
                }
            }
Example #19
0
            public Vector2 Draw(Drawing drawing, Vector2 position)
            {
                if (!enable)
                {
                    return(position);
                }
                if (search)
                {
                    Search();
                }

                float force = 0f;
                float mass  = 0f;

                if (!cockpit.IsEmpty)
                {
                    MyShipMass shipMass = cockpit.First.CalculateShipMass();
                    mass = shipMass.TotalMass;
                }
                string direction = "none";

                Dictionary <string, float> forces = new Dictionary <string, float>();

                thrusts_up.ForEach(delegate(IMyThrust block)
                {
                    direction = "Up";
                    if (forces.ContainsKey(direction))
                    {
                        forces[direction] += block.MaxThrust;
                    }
                    else
                    {
                        forces.Add(direction, block.MaxThrust);
                    }
                });
                thrusts_down.ForEach(delegate(IMyThrust block)
                {
                    direction = "Down";
                    if (forces.ContainsKey(direction))
                    {
                        forces[direction] += block.MaxThrust;
                    }
                    else
                    {
                        forces.Add(direction, block.MaxThrust);
                    }
                });
                thrusts_left.ForEach(delegate(IMyThrust block)
                {
                    direction = "Left";
                    if (forces.ContainsKey(direction))
                    {
                        forces[direction] += block.MaxThrust;
                    }
                    else
                    {
                        forces.Add(direction, block.MaxThrust);
                    }
                });
                thrusts_right.ForEach(delegate(IMyThrust block)
                {
                    direction = "Right";
                    if (forces.ContainsKey(direction))
                    {
                        forces[direction] += block.MaxThrust;
                    }
                    else
                    {
                        forces.Add(direction, block.MaxThrust);
                    }
                });
                thrusts_forward.ForEach(delegate(IMyThrust block)
                {
                    direction = "Forward";
                    if (forces.ContainsKey(direction))
                    {
                        forces[direction] += block.MaxThrust;
                    }
                    else
                    {
                        forces.Add(direction, block.MaxThrust);
                    }
                });
                thrusts_backward.ForEach(delegate(IMyThrust block)
                {
                    direction = "Backward";
                    if (forces.ContainsKey(direction))
                    {
                        forces[direction] += block.MaxThrust;
                    }
                    else
                    {
                        forces.Add(direction, block.MaxThrust);
                    }
                });
                MySprite text = new MySprite()
                {
                    Type            = SpriteType.TEXT,
                    Color           = Color.DimGray,
                    Position        = position + new Vector2(0, 0),
                    RotationOrScale = 1f,
                    FontId          = drawing.Font,
                    Alignment       = TextAlignment.LEFT
                };

                // Up
                force = 0f;
                forces.TryGetValue("Up", out force);
                text.Data = $"Up: {force / 1000}kN / {Math.Round(force / mass, 1)}m/s²";
                drawing.AddSprite(text);
                // Down
                position += new Vector2(0, 40);
                force     = 0f;
                forces.TryGetValue("Down", out force);
                text.Data     = $"Down: {force / 1000}kN / {Math.Round(force / mass, 1)}m/s²";
                text.Position = position;
                drawing.AddSprite(text);
                // Forward
                position += new Vector2(0, 40);
                force     = 0f;
                forces.TryGetValue("Forward", out force);
                text.Data     = $"Forward: {force / 1000}kN / {Math.Round(force / mass, 1)}m/s²";
                text.Position = position;
                drawing.AddSprite(text);
                // Backward
                position += new Vector2(0, 40);
                force     = 0f;
                forces.TryGetValue("Backward", out force);
                text.Data     = $"Backward: {force / 1000}kN / {Math.Round(force / mass, 1)}m/s²";
                text.Position = position;
                drawing.AddSprite(text);
                // Right
                position += new Vector2(0, 40);
                force     = 0f;
                forces.TryGetValue("Right", out force);
                text.Data     = $"Right: {force / 1000}kN / {Math.Round(force / mass, 1)}m/s²";
                text.Position = position;
                drawing.AddSprite(text);
                // Left
                position += new Vector2(0, 40);
                force     = 0f;
                forces.TryGetValue("Left", out force);
                text.Data     = $"Left: {force / 1000}kN / {Math.Round(force / mass, 1)}m/s²";
                text.Position = position;
                drawing.AddSprite(text);

                position += new Vector2(0, 40);

                return(position);
            }
Example #20
0
        private void Running()
        {
            int factor = pistonDown.List.Count + pistonUp.List.Count;

            if (stators.IsEmpty)
            {
                Prepare();
            }

            switch (phase)
            {
            case Phase.None:
                phase = Phase.PistonDown;
                break;

            case Phase.PistonDown:
                drills.On();
                pistonDown.ForEach(delegate(IMyPistonBase block) {
                    if (slowDown)
                    {
                        block.Velocity = SPEED_MIN / factor;
                    }
                    else
                    {
                        block.Velocity = SPEED_MAX / factor;
                    }
                });
                pistonUp.ForEach(delegate(IMyPistonBase block) {
                    if (slowDown)
                    {
                        block.Velocity = -SPEED_MIN / factor;
                    }
                    else
                    {
                        block.Velocity = -SPEED_MAX / factor;
                    }
                });
                pistonDown.On();
                pistonUp.On();
                if (pistonDown.IsPositionMax() && pistonUp.IsPositionMin())
                {
                    phase = Phase.PistonUp;
                }
                break;

            case Phase.PistonUp:
                slowDown = false;
                pistonDown.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = -SPEED_MAX;
                });
                pistonUp.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = SPEED_MAX;
                });
                pistonDown.On();
                pistonUp.On();
                if (pistonDown.IsPositionMin() && pistonUp.IsPositionMax())
                {
                    phase = Phase.Bras;
                }
                break;

            case Phase.Bras:
                if (brasOut && pistonRayon.IsPositionMax())
                {
                    targetAngle += deltaAngle;
                    brasOut      = false;
                    phase        = Phase.Rotor;
                }
                else if (!brasOut && pistonRayon.IsPositionMin())
                {
                    targetAngle += deltaAngle;
                    brasOut      = true;
                    phase        = Phase.Rotor;
                }
                else
                {
                    if (brasOut)
                    {
                        targetRayon += Math.Min(deltaRayon, 10f);
                        if (targetRayon > 10f)
                        {
                            targetRayon = 10f;
                        }
                        phase = Phase.BrasOut;
                    }
                    else
                    {
                        targetRayon -= Math.Min(deltaRayon, 10f);
                        if (targetRayon < 0f)
                        {
                            targetRayon = 0f;
                        }
                        phase = Phase.BrasIn;
                    }
                }
                break;

            case Phase.BrasIn:
                pistonRayon.On();
                pistonRayon.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = -SPEED_MAX;
                });
                if (pistonRayon.IsPosition(targetRayon))
                {
                    pistonRayon.Off();
                    phase = Phase.PistonDown;
                }
                break;

            case Phase.BrasOut:
                pistonRayon.On();
                pistonRayon.ForEach(delegate(IMyPistonBase block) {
                    block.Velocity = SPEED_MAX;
                });
                if (pistonRayon.IsPosition(targetRayon))
                {
                    pistonRayon.Off();
                    phase = Phase.PistonDown;
                }
                break;

            case Phase.Rotor:
                stators.ForEach(delegate(IMyMotorStator block) {
                    block.TargetVelocityRPM = ANGLE_RPM_MIN;
                });
                stators.Unlock();
                if (stators.IsPositionMax())
                {
                    stateMachine = StateMachine.Stopping;
                    phase        = Phase.None;
                }
                else if (stators.IsPosition(targetAngle))
                {
                    stators.Lock();
                    phase = Phase.PistonDown;
                }
                break;
            }
        }