Exemple #1
0
        private void DisplyAutopilotStatus()
        {
            //Log.DebugLog("Building autopilot list", "DisplyAutopilotStatus()", Logger.severity.TRACE);

            RelayStorage store = m_networkClient.GetStorage();

            if (store == null)
            {
                m_textPanel.WritePublicText("No network connection");
                return;
            }

            List <SortableAutopilot> autopilots = ResourcePool <List <SortableAutopilot> > .Get();

            Vector3D mypos = m_block.GetPosition();

            Registrar.ForEach <AutopilotTerminal>(ap => {
                IRelayPart relayPart;
                if (RelayClient.TryGetRelayPart((IMyCubeBlock)ap.m_block, out relayPart) && relayPart.GetStorage() == store && m_block.canControlBlock(ap.m_block))
                {
                    autopilots.Add(new SortableAutopilot(ap, mypos));
                }
            });

            autopilots.Sort();

            StringBuilder displayText = new StringBuilder();

            displayText.Append(timeString);
            displayText.Append(DateTime.Now.ToLongTimeString());
            displayText.AppendLine();
            int count = 0;

            foreach (SortableAutopilot ap in autopilots)
            {
                displayText.Append(tab);
                displayText.Append(ap.Autopilot.m_block.CubeGrid.DisplayName);
                displayText.Append(tab);
                displayText.Append(PrettySI.makePretty(ap.Distance));
                displayText.AppendLine("m");

                ap.Autopilot.AppendingCustomInfo(displayText);

                displayText.AppendLine();

                count++;
                if (count >= 5)
                {
                    break;
                }
            }

            autopilots.Clear();
            ResourcePool <List <SortableAutopilot> > .Return(autopilots);

            string displayString = displayText.ToString();

            //Log.DebugLog("Writing to panel: " + m_textPanel.DisplayNameText + ":\n\t" + displayString, "DisplyAutopilotStatus()", Logger.severity.TRACE);
            m_textPanel.WritePublicText(displayText.ToString());
        }
Exemple #2
0
        public ProgrammableBlock(IMyCubeBlock block)
            : base(block)
        {
            m_progBlock     = block as IMyProgrammableBlock;
            m_networkClient = new RelayClient(block, HandleMessage);

            Log.DebugLog("initialized");
            Registrar.Add(block, this);
        }
Exemple #3
0
        public TextPanel(IMyCubeBlock block)
            : base(block)
        {
            m_textPanel     = block as Ingame.IMyTextPanel;
            myTermBlock     = block as IMyTerminalBlock;
            m_networkClient = new RelayClient(block);
            Log.DebugLog("init: " + m_block.DisplayNameText);

            Registrar.Add(block, this);
        }
Exemple #4
0
        private void Update()
        {
            IMyEntity controlled = myPlayer.Controller.ControlledEntity as IMyEntity;

            if (controlled != m_controlled)
            {
                m_controlled = controlled;

                if (controlled is IMyCharacter)
                {
                    m_soundEmitter = null;
                    m_threat       = null;
                    RelayNode charNode;
                    if (!Registrar.TryGetValue(controlled, out charNode))
                    {
                        Log.DebugLog("Failed to get node for character: " + controlled.getBestName(), Logger.severity.WARNING);
                        m_storage = null;
                        return;
                    }
                    m_storage = () => charNode.Storage;
                    Log.DebugLog("now controlling a character", Logger.severity.DEBUG);
                }
                else if (controlled is IMyCubeBlock)
                {
                    IRelayPart shipClient = RelayClient.GetOrCreateRelayPart((IMyCubeBlock)controlled);
                    m_storage      = shipClient.GetStorage;
                    m_soundEmitter = new MyEntity3DSoundEmitter((MyEntity)controlled);
                    Log.DebugLog("now controlling a ship", Logger.severity.DEBUG);
                }
                else
                {
                    Log.TraceLog("player controlling incompatible entity: " + controlled.getBestName(), Logger.severity.TRACE);
                    m_storage      = null;
                    m_soundEmitter = null;
                    m_threat       = null;
                    return;
                }
            }
            else if (m_storage == null || m_storage.Invoke() == null)
            {
                Log.TraceLog("no storage", Logger.severity.TRACE);
                m_threat = null;
                return;
            }

            if (UserSettings.GetSetting(UserSettings.BoolSettingName.MissileWarning))
            {
                UpdateMissileThreat();
            }
            else
            {
                m_threat = null;
            }
        }
Exemple #5
0
        public Projector(IMyCubeBlock block)
        {
            if (Static == null)
            {
                throw new Exception("StaticVariables not loaded");
            }

            this.m_block     = (IMyProjector)block;
            this.m_netClient = new RelayClient(block);

            Registrar.Add(block, this);
        }
        public ProgrammableBlock(IMyCubeBlock block)
            : base(block)
        {
            m_logger = new Logger(GetType().Name, block);
            m_progBlock = block as Ingame.IMyProgrammableBlock;
            m_networkClient = new RelayClient(block, HandleMessage);

            byte index = 0;
            m_handleDetectedTerminal_ev = new EntityValue<bool>(block, index++, UpdateVisual);
            m_blockCountList_ev = new EntityStringBuilder(block, index++, () => {
                UpdateVisual();
                m_blockCountList_btl = new BlockTypeList(m_blockCountList_sb.ToString().LowerRemoveWhitespace().Split(','));
            });

            Registrar.Add(block, this);
        }
Exemple #7
0
        private static void GetStorage(long entityId, out IMyCubeBlock block, out RelayStorage storage)
        {
            IMyEntity entity;

            if (!MyAPIGateway.Entities.TryGetEntityById(entityId, out entity))
            {
                Logger.AlwaysLog("Failed to get entity id for " + entityId, Logger.severity.WARNING);
                block   = null;
                storage = null;
                return;
            }

            block = entity as IMyCubeBlock;
            if (block == null)
            {
                Logger.AlwaysLog("Entity is not a block: " + entityId, Logger.severity.WARNING);
                storage = null;
                return;
            }

            storage = RelayClient.GetOrCreateRelayPart(block).GetStorage();
        }
Exemple #8
0
        public Projector(IMyCubeBlock block)
        {
            this.m_logger = new Logger(GetType().Name, block);
            this.m_block = block;
            this.m_netClient = new RelayClient(block);

            byte index = 0;
            this.m_options = new EntityValue<Option>(block, index++, UpdateVisual);
            this.m_rangeDetection = new EntityValue<float>(block, index++, UpdateVisual, DefaultRangeDetection);
            this.m_radiusHolo = new EntityValue<float>(block, index++, UpdateVisual, DefaultRadiusHolo);
            this.m_sizeDistScale = new EntityValue<float>(block, index++, UpdateVisual, DefaultSizeScale);
            this.m_centreEntityId = new EntityValue<long>(block, index++, m_centreEntityId_AfterValueChanged);
            this.m_offset_ev = new EntityValue<Vector3>(block, index++, UpdateVisual, new Vector3(0f, 2.5f, 0f));

            Registrar.Add(block, this);
        }
Exemple #9
0
        /// <summary>
        /// Create an OreDetector for the given block.
        /// </summary>
        /// <param name="oreDetector">The ore detector block.</param>
        public OreDetector(IMyCubeBlock oreDetector)
        {
            this.m_logger = new Logger("OreDetector", oreDetector);
            this.Block = oreDetector;
            this.m_oreDetector = oreDetector as Ingame.IMyOreDetector;
            this.m_netClient = new RelayClient(oreDetector);

            float maxrange = 0f;
            MainLock.UsingShared(() => {
                var def = MyDefinitionManager.Static.GetCubeBlockDefinition(m_oreDetector.BlockDefinition) as MyOreDetectorDefinition;
                maxrange = def.MaximumRange;
            });
            m_maxRange = maxrange;

            Registrar.Add(Block, this);
        }