Esempio n. 1
0
            public ArmController(MyIni ini, MyGridProgram p, CommandLine cmd, IMyShipController cont, WheelsController wCont, ISaveManager manager)
            {
                var rotors = new List <IMyMotorStator>();

                p.GridTerminalSystem.GetBlocksOfType(rotors, r => r.CubeGrid == p.Me.CubeGrid && r.DisplayNameText.Contains("Arm Rotor"));
                this.rotors = rotors.Select(r => new ArmRotor(r, r.WorldMatrix.Up.Dot(cont.WorldMatrix.Right) > 0)).ToList();
                var keys = new List <MyIniKey>();

                ini.GetKeys(SECTION, keys);
                this.pos               = keys.Where(k => !k.Name.StartsWith("$")).ToDictionary(k => k.Name, k => new ArmPos(ini.Get(k).ToString()));
                this.pos["$top"]       = new ArmPos(this.rotors[0].Max);
                this.pos["$mid"]       = new ArmPos(0.2f);
                this.pos["$bottom"]    = new ArmPos(this.rotors[0].Min);
                this.pos["$auto-high"] = new ArmPos(ArmPos.R_ELEVATION, 0);
                this.pos["$auto-low"]  = new ArmPos(ArmPos.L_ELEVATION, 0);
                var tools = new List <IMyFunctionalBlock>();

                p.GridTerminalSystem.GetBlocksOfType(tools, t => t.IsSameConstructAs(cont) && (t is IMyShipToolBase || t is IMyShipDrill));
                this.autoCont = new ArmAutoControl(ini, this.Angle, wCont, tools);

                cmd.RegisterCommand(new Command("arm-del", Command.Wrap(this.deletePosition), "Deletes a saved position of the arm", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-elevation", Command.Wrap(this.autoElevate), "Makes the arm elevate at the correct position", detailedHelp: @"First argument is elevation ('high'/'low'/float)
Second argument is angle", maxArgs: 2));
                cmd.RegisterCommand(new Command("arm-drill", Command.Wrap(this.drill), "Engages the drills and move slowly to position", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-recall", Command.Wrap(this.recallPosition), "Recalls a saved position of the arm", nArgs: 1));
                cmd.RegisterCommand(new Command("arm-save", Command.Wrap(this.savePosition), "Saves the current position of the arm", nArgs: 1));
                manager.Spawn(pc => this.updateRotors(cont), "arm-handle");
                manager.AddOnSave(this.save);
            }
Esempio n. 2
0
        public void IsolatedRun(Action work)
        {
            if (lastException == null)
            {
                try
                {
                    Current = this;
                    Log.NewFrame();

                    work();

                    Current = null;
                }
                catch (Exception e)
                {
                    lastException = e;
                }
            }

            if (lastException != null)
            {
                EchoException();
                return;
            }
        }
Esempio n. 3
0
 public LocustAttackTaskGenerator(MyGridProgram program, LocustCombatSystem combatSystem, IAutopilot autopilot, IAgentSubsystem agentSubsystem)
 {
     Program        = program;
     CombatSystem   = combatSystem;
     Autopilot      = autopilot;
     AgentSubsystem = agentSubsystem;
 }
Esempio n. 4
0
 public PrisonManager(MyGridProgram program)
 {
     this.program = program;
     this.grid    = program.GridTerminalSystem;
     this.me      = program.Me;
     Init();
 }
 public AutoAntennaRelaySlave(MyGridProgram p, String tagGroup) : base(p, tagGroup)
 {
     p.IGC.UnicastListener.SetMessageCallback(AutoAntennaRelayManager.TAG_ASK_CHANGE_RANGE);
     AddListener(AutoAntennaRelayManager.TAG_ASK_UPDATE_INFO, true);
     AddListener(AutoAntennaRelayManager.TAG_ASK_UPDATE_INFO_OPTIONNAL, true);
     SendMyInfo();
 }
Esempio n. 6
0
 internal Airlock(MyGridProgram p, string id)
 {
     caller    = p;
     shipGrid  = caller.Me.CubeGrid;
     airlockID = id;
     build();
 }
Esempio n. 7
0
 public AbstractSEClass(MyGridProgram p)
 {
     this.p      = p;
     this.LOGGER = Logger.GetDefaultInstance();
     this.config = new ConfigUtils(p.Me);
     BuildConfig();
 }
Esempio n. 8
0
 public static void InitDefaultInstance(MyGridProgram p)
 {
     if (DEFAULT_INSTANCE == null)
     {
         DEFAULT_INSTANCE = new Logger(p);
     }
 }
Esempio n. 9
0
        public void Reset(WaypointTask holdTask, WaypointTask approachTask, WaypointTask enterTask, WaypointTask closeTask, DockTask dockTask, MyTuple <IntelItemType, long> intelKey, MyGridProgram program, MyCubeSize dockSize, IMyTerminalBlock connector, IMyTerminalBlock indicator = null)
        {
            Reset();
            if (indicator != null)
            {
                Indicator = indicator;
                Connector = connector;
            }
            EnterHoldingPattern = holdTask;
            WaitForClearance    = new WaitTask();
            ApproachEntrance    = approachTask;
            ApproachDock        = enterTask;
            FinalAdjustToDock   = closeTask;
            DockTask            = dockTask;
            IntelKey            = intelKey;
            DockSize            = dockSize;
            Program             = program;

            closeTask.Destination.MaxSpeed = 0.5f;
            enterTask.Destination.MaxSpeed = 5;

            TaskQueue.Enqueue(EnterHoldingPattern);
            TaskQueue.Enqueue(WaitForClearance);
            TaskQueue.Enqueue(ApproachEntrance);
            TaskQueue.Enqueue(ApproachDock);
            TaskQueue.Enqueue(FinalAdjustToDock);
            TaskQueue.Enqueue(DockTask);
        }
Esempio n. 10
0
    public Thruster(IMyThrust t, MatrixD m, MyGridProgram argPg)
    {
        pg = argPg;
        th = t;
        double force = 0;

        if (t.DetailedInfo.Contains("Atmospheric"))
        {
            TYPE = ATM;
        }
        else if (t.DetailedInfo.Contains("Hydrogen"))
        {
            TYPE = HY;
        }
        else if (t.DetailedInfo.Contains("Thruster"))
        {
            TYPE = ION;
        }
        else
        {
        }
        force = t.MaxEffectiveThrust;

        FORCE = new Vector3D(0, 0, 0);
        if (t.WorldMatrix.Forward == m.Forward)
        {
            FORCE_DIM  = 2;
            FORCE_MULT = 1;
        }
        else if (t.WorldMatrix.Forward == m.Backward)
        {
            FORCE_DIM  = 2;
            FORCE_MULT = -1;
        }
        else if (t.WorldMatrix.Forward == m.Right)
        {
            FORCE_DIM  = 0;
            FORCE_MULT = -1;
        }
        else if (t.WorldMatrix.Forward == m.Left)
        {
            FORCE_DIM  = 0;
            FORCE_MULT = 1;
        }
        else if (t.WorldMatrix.Forward == m.Up)
        {
            FORCE_DIM  = 1;
            FORCE_MULT = -1;
        }
        else if (t.WorldMatrix.Forward == m.Down)
        {
            FORCE_DIM  = 1;
            FORCE_MULT = 1;
        }
        else
        {
            throw new Exception("Thruster(): invalid matrix");
        }
        FORCE.SetDim(FORCE_DIM, FORCE_MULT);
    }
Esempio n. 11
0
 public WriteLCD(MyGridProgram script, string lcdName)
 {
     _script = script;
     lcd1    = new StringBuilder();
     lcds    = new List <IMyTextPanel>();
     LCDBuild(lcdName);
 }
Esempio n. 12
0
//        bool cleared = false;

        public UndockSeperationTask(IAutopilot autopilotSubsystem, IDockingSubsystem dockingSubsystem, MyGridProgram program)
        {
            AutopilotSubsystem = autopilotSubsystem;
            DockingSubsystem   = dockingSubsystem;
            WaitTask           = new WaitTask();
            Program            = program;
        }
Esempio n. 13
0
 public DoorManager(MyGridProgram program, IProcessSpawner spawner, Action <string> logger)
 {
     this.logger      = logger;
     this.mainProcess = spawner.Spawn(this._handleDoors, "autodoors-main");
     this.Scan(program);
     this.mainProcess.Spawn(p => this.Scan(program), "scan", period: 431);
 }
Esempio n. 14
0
            public void Scan(MyGridProgram program)
            {
                this.doors.Clear();
                this.sases.Clear();

                program.GridTerminalSystem.GetBlocksOfType(this.tmpDoorList, d => d.CubeGrid == program.Me.CubeGrid && d.IsFunctional);
                foreach (IMyDoor door in this.tmpDoorList)
                {
                    var match = SAS_DOOR_RE.Match(door.DisplayNameText);
                    if (match != null)
                    {
                        IMyDoor otherDoor = this.tmpSases.GetValueOrDefault(match.Groups[1].Value);
                        if (otherDoor != null)
                        {
                            this.sases.Add(new Sas($"{match.Groups[1].Value})", door, otherDoor));
                            this.tmpSases.Remove(match.Groups[1].Value);
                        }
                        else
                        {
                            this.tmpSases.Add(match.Groups[1].Value, door);
                        }
                    }
                    else
                    {
                        this.doors.Add(door);
                    }
                }
                this.doors.AddRange(this.tmpSases.Values);
                this.logger?.Invoke($"Found {this.doors.Count} doors and {this.sases.Count} sases");

                this.tmpSases.Clear();
            }
Esempio n. 15
0
 public AutoAntennaRelayManager(MyGridProgram p, String tagGroup) : base(p, tagGroup)
 {
     p.Runtime.UpdateFrequency = UpdateFrequency.Update10;
     AddListener(TAG_INFO_MEMBER, true);
     WriteToChanel(TAG_ASK_UPDATE_INFO, "");
     members.Add(MyInfo.Id, MyInfo);
 }
Esempio n. 16
0
 internal Hangar(MyGridProgram p, string id)
 {
     caller   = p;
     shipGrid = caller.Me.CubeGrid;
     hangarID = id;
     build();
 }
Esempio n. 17
0
 public SetHomeTask(MyTuple <IntelItemType, long> intelKey, long myId, MyGridProgram program, IDockingSubsystem ds)
 {
     IntelKey         = intelKey;
     MyId             = myId;
     Program          = program;
     DockingSubsystem = ds;
 }
Esempio n. 18
0
        public static TBlock GetClosestBlockOfType <TBlock>(this MyGridProgram program) where TBlock : class, IMyCubeBlock
        {
            var blocks = GetAllBlocksOfType <TBlock>(program);

            if (blocks.Count == 0)
            {
                throw new InvalidOperationException($"No block of type {typeof(TBlock).Name} found!");
            }

            TBlock block      = null;
            var    distance   = double.MaxValue;
            var    myPosition = program.Me.GetPosition();

            foreach (var x in blocks)
            {
                var d = Vector3D.DistanceSquared(x.GetPosition(), myPosition);
                if (d < distance)
                {
                    block    = x;
                    distance = d;
                }
            }

            return(block);
        }
Esempio n. 19
0
        public MyAutoGyro(AutoGyroMode mode, MyGridProgram program, string RC_name)
        {
            Init();
            gyroMode = mode;
            if (program == null)
            {
                return;
            }
            GridTerminalSystem = program.GridTerminalSystem;
            Echo = program.Echo;
            Me   = program.Me;

            List <IMyRemoteControl> RCs = new List <IMyRemoteControl>();

            GridTerminalSystem.GetBlocksOfType(RCs, b => b.CustomName == RC_name);
            if (RCs.Count == 0)
            {
                Echo("No functional remote control blocks found.");
                return;
            }

            RC = RCs.First();

            UpdateGyroList();
        }
Esempio n. 20
0
 public Program()
 {
     PROGRAM = this;
     InitializeParsers();
     ParameterProcessorRegistry.InitializeProcessors();
     Runtime.UpdateFrequency = UPDATE_FREQUENCY;
 }
Esempio n. 21
0
        static List <MyIGCMessage> provideMessages(MyGridProgram program)
        {
            List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>();

            program.IGC.GetBroadcastListeners(listeners);
            return(listeners.Where(l => l.HasPendingMessage).Select(l => l.AcceptMessage()).ToList());
        }
Esempio n. 22
0
 internal GasSystem(string name, string blockName, float min, float max, MyGridProgram caller)
 {
     this.name = name;
     minFrac   = min;
     maxFrac   = max;
     caller.GridTerminalSystem.GetBlocksOfType <IMyGasTank>(tanks, b => b.CubeGrid == caller.Me.CubeGrid && b.CustomName.Contains(blockName) && !b.CustomName.Contains("Compress"));
     caller.GridTerminalSystem.GetBlocksOfType <IMyGasTank>(compressors, b => b.CubeGrid == caller.Me.CubeGrid && b.CustomName.Contains(blockName) && b.CustomName.Contains("Compress"));
 }
 public static new GraphicalStationMonitor GetInstance(MyGridProgram program)
 {
     if (_instance == null)
     {
         _instance = new GraphicalStationMonitor(program);
     }
     return(_instance);
 }
Esempio n. 24
0
 public ZACommons(MyGridProgram program, string shipGroup = null,
                  ZAStorage storage = null)
 {
     Program       = program;
     ShipGroupName = shipGroup;
     Storage       = storage;
     IsDirty       = false;
 }
Esempio n. 25
0
 public Goto(MyGridProgram argPg, Grid argG, Mover m, Aligner a)
 {
     pg      = argPg;
     g       = argG;
     mover   = m;
     aligner = a;
     rc      = new RemoteControl(g);
 }
Esempio n. 26
0
        public static List <TBlock> GetAllBlocksOfType <TBlock>(this MyGridProgram program) where TBlock : class
        {
            var blocks = new List <TBlock>();

            program.GridTerminalSystem.GetBlocksOfType(blocks);

            return(blocks);
        }
Esempio n. 27
0
 public ShipControlCommons(MyGridProgram program, UpdateType updateType,
                           ShipOrientation shipOrientation,
                           string shipGroup  = null,
                           ZAStorage storage = null)
     : base(program, updateType, shipGroup: shipGroup, storage: storage)
 {
     this.shipOrientation = shipOrientation;
 }
Esempio n. 28
0
                             public Program()
                             {
                                 // Set the update speed in milliseconds
                                 Runtime.UpdateFrequency = UpdateFrequency.Update1;

                                 // Get a reference to SELF, for debugging from other contexts
                                 PROGRAM = this;
                             }
Esempio n. 29
0
            public StateOfShip(MyGridProgram gridProg)
            {
                pgr = gridProg;

                LeftRight_thruster_Bship = new List <MyGravitonThruster>(12);
                UpDown_thruster_Bship    = new List <MyGravitonThruster>(12);
                BackForw_thruster_Bship  = new List <MyGravitonThruster>(12);
            }
Esempio n. 30
0
 public FileSystem(MyGridProgram gridProgram)
 {
     if (gridProgram == null)
     {
         throw new ArgumentNullException(nameof(gridProgram));
     }
     this.gridProgram = gridProgram;
 }
Esempio n. 31
0
 public ShipControlCommons(MyGridProgram program,
                           ShipOrientation shipOrientation,
                           string shipGroup = null,
                           ZAStorage storage = null)
     : base(program, shipGroup: shipGroup, storage: storage)
 {
     this.shipOrientation = shipOrientation;
     // Use own programmable block as reference point
     Reference = program.Me;
     ReferencePoint = Reference.GetPosition();
 }
Esempio n. 32
0
    public void Run(MyGridProgram program, string prefix)
    {
        prefix = prefix.Trim();

        // Get list of all blocks
        var blocks = new List<IMyTerminalBlock>();
        program.GridTerminalSystem.GetBlocks(blocks);

        var countsByType = new Dictionary<string, uint>();

        for (var e = blocks.GetEnumerator(); e.MoveNext();)
        {
            var block = e.Current;

            if (EXCLUDED_BLOCK_TYPES.Contains(block.DefinitionDisplayNameText)) continue;
            if (EXCLUDED_BLOCK_NAMES.Contains(block.CustomName)) continue;

            var builder = new StringBuilder();
            builder.Append(prefix);
            builder.Append(' ');
            builder.Append(block.DefinitionDisplayNameText);
            var genericName = builder.ToString();

            // If it starts with a generic prefixed name, look at it closer..
            if (block.CustomName == genericName)
            {
                // No need to check more
            }
            else if (block.CustomName.StartsWith(genericName + " "))
            {
                var rest = block.CustomName.Substring(genericName.Length + 1);
                // See if it's a simple number
                uint num;
                if (rest.Length > 0 && !uint.TryParse(rest, out num))
                {
                    // Can't parse it, must be customized
                    continue;
                }
            }
            else if (block.CustomName == prefix ||
                     block.CustomName.StartsWith(prefix + " "))
            {
                // Otherwise, if it already has the prefix, leave it alone
                continue;
            }
            
            uint count;
            if (!countsByType.TryGetValue(block.DefinitionDisplayNameText, out count))
            {
                count = 0;
            }
            count++;
            countsByType[block.DefinitionDisplayNameText] = count;

            if (count > 1)
            {
                builder.Append(' ');
                builder.Append(count);
            }

            block.SetCustomName(builder);
        }
    }