Ejemplo n.º 1
0
        public override void UpdateBeforeSimulation100()
        {
            if (!_isInit)
            {
                try {
                    _AllowAITargeting = true;
                    _PowerBasedOnMass = false;
                    _PowerMultiplier  = 1.0f;
                    _SmallGridDivisor = 8.0f;
                    loadXML();
                    saveXML();
                    var f_block = Container.Entity as IMyFunctionalBlock;
                    f_block.Enabled = false;
                    InitResourceSink();
                    _grid = m_block.CubeGrid as VRage.Game.ModAPI.IMyCubeGrid;
                    if (_grid.GridSizeEnum == (byte)0)
                    {
                        _SmallGridDivisor = 1f;
                    }
                    _mass  = _grid.Physics.Mass;
                    _power = 300f * _PowerMultiplier / _SmallGridDivisor;
                    if (_PowerBasedOnMass)
                    {
                        _power *= (_mass / 500000f);
                    }
                    m_block.RefreshCustomInfo();
                    _isInit = true;
                } catch (Exception ex) { return; }
            }

            if (_PowerBasedOnMass && _grid.Physics.Mass != _mass)
            {
                _mass  = _grid.Physics.Mass;
                _power = 300f * _PowerMultiplier * (_mass / 500000f) / _SmallGridDivisor;
                m_block.RefreshCustomInfo();
            }
            if (!IsWorking())
            {
                return;
            }
            if (firstRun)
            {
                firstRun = false;
            }
            _myGunList.Clear();
            List <IMySlimBlock> blockList = new List <IMySlimBlock>();

            _grid.GetBlocks(blockList);
            foreach (var block in blockList)
            {
                if (block.FatBlock is IMyUserControllableGun)
                {
                    var gun = block.FatBlock as IMyFunctionalBlock;
                    if (gun != null)
                    {
                        _myGunList.Add(gun);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private bool TryParseCmd(string s)
        {
            int start = s.IndexOf("[cmd:");

            if (start > 0)
            {
                int end = s.IndexOf(']', start);
                if (end > 0)
                {
                    int len = end - (start + 5);
                    if (len > 0)
                    {
                        string cmd = s.Substring(start + 5, len).TrimStart(' ', '/').TrimEnd().ToLower();
                        if (IsValid(cmd))
                        {
                            this.cmd = cmd;
                            fac      = null;
                            block.RefreshCustomInfo();
                            if (!fake)
                            {
                                MySession.Instance.Register(this.cmd, cmdBlock);
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
 private void OnAddedToScene(MyEntity entity)
 {
     if (entity != _thisEntity || _isSetup)
     {
         return;
     }
     _thisTerminal.AppendingCustomInfo += AppendingCustomInfo;
     _thisEntity.AddedToScene          -= OnAddedToScene;
     _thisTerminal.RefreshCustomInfo();
     _isSetup = true;
 }
Ejemplo n.º 4
0
        // CustomInfo methods


        public void UpdateCustomInfo(string text)
        {
            CustomInfo = text;

            // Prevent CustomInfo from getting too big
            if (CustomInfo.Length > 1000)
            {
                CustomInfo = CustomInfo.Substring(CustomInfo.Length - 1000);
            }

            tb.RefreshCustomInfo();
            var b = tb as IMyProgrammableBlock;

            b.Enabled = !b.Enabled;
            b.Enabled = !b.Enabled;
        }
Ejemplo n.º 5
0
        public static bool is_grid_control_available(IMyTerminalBlock controller)
        {
            var ship_controller = (MyShipController)controller;

            if (!ship_controller.ControlThrusters)
            {
                return(false);
            }

            IMyCubeGrid grid = controller.CubeGrid;

            if (((MyCubeGrid)grid).HasMainCockpit() && !ship_controller.IsMainCockpit)
            {
                return(false);
            }
            if (controller != _last_controller && (!sync_helper.running_on_server || screen_info.local_player != null))
            {
                controller.RefreshCustomInfo();
                _last_controller = controller;
            }
            if (!update_grid_flags(grid))
            {
                return(false);
            }
            return(_grid_handlers[grid].is_thrust_control_available);
        }
Ejemplo n.º 6
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();
            if (!_init)
            {
                Battery       = Entity as MyBatteryBlock;
                TerminalBlock = Entity as IMyTerminalBlock;
                Targets       = new List <Target>();

                TerminalBlock.AppendingCustomInfo += AppendingCustomInfo;
                Runtime = Run();
                _init   = true;
            }
            if (TerminalBlock.IsFunctional && (TerminalBlock as IMyFunctionalBlock).Enabled)
            {
                if (Runtime == null)
                {
                    return;
                }
                Runtime.MoveNext();
                if (Position == null || Targets.Count == 0)
                {
                    return;
                }
                Charge();
                TerminalBlock.RefreshCustomInfo();
            }
        }
Ejemplo n.º 7
0
        private static bool update_thruster_flags(IMyTerminalBlock thruster, bool use_remote_switches = false, bool use_remote_manual_throttle = false)
        {
            if (!(thruster is IMyThrust) || !_thruster_hosts.ContainsKey(thruster))
            {
                _current_thruster          = null;
                _current_thruster_settings = null;
                _current_active_control_on = _current_anti_slip_on = _current_disable_linear = _current_thrust_limiter_on = false;
                _manual_throttle           = 0;
                return(false);
            }
            if (thruster == _current_thruster && !use_remote_switches && !use_remote_manual_throttle)
            {
                return(true);
            }

            _current_thruster          = thruster;
            _current_thruster_settings = _thruster_settings[thruster];
            thruster.RefreshCustomInfo();
            if (!use_remote_switches)
            {
                _thruster_switches = parse_number(_current_thruster_settings, THRUSTER_MODE_FIELD_START, THRUSTER_MODE_FIELD_END);
            }
            else
            {
                store_number(_current_thruster_settings, _thruster_switches, THRUSTER_MODE_FIELD_START, THRUSTER_MODE_FIELD_END);
                thruster.Storage[_uuid] = _current_thruster_settings.ToString();
            }
            if (!use_remote_manual_throttle)
            {
                _manual_throttle = parse_number(_current_thruster_settings, MANUAL_THROTTLE_FIELD_START, MANUAL_THROTTLE_FIELD_END);
            }
            else
            {
                store_number(_current_thruster_settings, _manual_throttle, MANUAL_THROTTLE_FIELD_START, MANUAL_THROTTLE_FIELD_END);
                thruster.Storage[_uuid] = _current_thruster_settings.ToString();
            }
            _current_active_control_on = (_thruster_switches & STEERING) != 0;
            _current_anti_slip_on      = (_thruster_switches & THRUST_TRIM) != 0;
            _current_thrust_limiter_on = (_thruster_switches & THRUST_LIMIT) != 0;
            _current_disable_linear    = (_thruster_switches & LINEAR_OFF) != 0;

            if (use_remote_switches)
            {
                engine_control_unit host = _thruster_hosts[thruster];
                long thruster_entity_id  = thruster.EntityId;
                host.set_thruster_steering(thruster_entity_id, _current_active_control_on);
                host.set_thruster_trim(thruster_entity_id, _current_anti_slip_on);
                host.set_thruster_limiter(thruster_entity_id, _current_thrust_limiter_on);
                host.set_thruster_linear_input(thruster_entity_id, _current_disable_linear);
            }
            if (use_remote_manual_throttle)
            {
                _thruster_hosts[thruster].set_manual_throttle(thruster.EntityId, _manual_throttle / MANUAL_THROTTLE_SCALE);
            }

            return(true);
        }
Ejemplo n.º 8
0
        internal static void TerminalActionCameraDecrease(IMyTerminalBlock blk)
        {
            long valueLong;

            long.TryParse(blk.CustomData, out valueLong);
            var value = valueLong + 1 <= 7 ? valueLong + 1 : 1;

            blk.CustomData = value.ToString();
            blk.RefreshCustomInfo();
        }
Ejemplo n.º 9
0
        internal static void RequestBlockCamera(IMyTerminalBlock block, float newValue)
        {
            var  value      = Convert.ToInt64(newValue);
            var  customData = block.CustomData;
            long valueLong;

            if (string.IsNullOrEmpty(customData) || long.TryParse(block.CustomData, out valueLong))
            {
                block.CustomData = value.ToString();
                block.RefreshCustomInfo();
            }
        }
Ejemplo n.º 10
0
        public override void Setter(IMyTerminalBlock block, bool newState)
        {
            base.Setter(block, newState);
            var shield = block.GameLogic.GetAs <DefenseShields>();

            if (shield == null)
            {
                return;
            }
            shield.Sink.Update();
            block.RefreshCustomInfo();
        }
Ejemplo n.º 11
0
        public static void SetSelectedGrid(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> listItems)
        {
            //MyLog.Default.WriteLineAndConsole("Selected Item Changed to: "+listItems[0].Text);
            SelectedGrid = (MarketList)listItems[0].UserData;

            MyTerminalControlListBoxItem item = listItems[0];

            SelectedBoxItem = item;

            block.RefreshCustomInfo();
            UpdateGUI(block);
        }
Ejemplo n.º 12
0
 public override void Writer(IMyTerminalBlock block, StringBuilder builder)
 {
     try
     {
         builder.Clear();
         var distanceString = Getter(block).ToString("0") + "m";
         builder.Append(distanceString);
         block.RefreshCustomInfo();
     }
     catch
     {
     }
 }
Ejemplo n.º 13
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (m_functionalBlock.IsFunctional)
            {
                if (m_functionalBlock.Enabled)
                {
                    m_info.enabled = true;
                }
                else
                {
                    m_info.enabled = false;
                }
            }
            else
            {
                m_info.enabled = false;
            }

            updatePowerInput();

            findReceivers();

            calculateReceiverPower();

            m_info.currentInput = 0;

            if (m_receivers.Count == 0)
            {
                m_currentOutput = 0;
                m_resourceSink.SetRequiredInputByType(m_electricityDefinition, 0);
            }

            m_oldTransmittedPower = m_transmittedPower;

            m_terminalBlock.RefreshCustomInfo();

            m_infoReceivers      = 0;
            m_infoReceivingPower = 0f;

            // writing newest values into the save file
            m_saveInfo.ChannelTarget = m_channel;
            m_saveInfo.Sender        = m_sender;
            m_saveInfo.Power         = m_transmittedPower;

            m_ticks++;
        }
Ejemplo n.º 14
0
        public static void RefreshUI(IMyTerminalBlock block)
        {
            block.RefreshCustomInfo();

            MyCubeBlock cube = (MyCubeBlock)block;

            if (cube.IDModule == null || Constants.IsDedicated || MyAPIGateway.Gui.GetCurrentScreen != MyTerminalPageEnum.ControlPanel)
            {
                return;
            }

            MyOwnershipShareModeEnum shareMode = cube.IDModule.ShareMode;
            long ownerId = cube.IDModule.Owner;

            cube.ChangeOwner(ownerId, shareMode != MyOwnershipShareModeEnum.All ? MyOwnershipShareModeEnum.All : MyOwnershipShareModeEnum.Faction);
            cube.ChangeOwner(ownerId, shareMode);
        }
Ejemplo n.º 15
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();

            if (m_generator.IsWorking)
            {
                if (IsInVoxel(m_generator as Sandbox.ModAPI.IMyTerminalBlock))
                {
                    IMyInventory       inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory;
                    VRage.MyFixedPoint amount    = (VRage.MyFixedPoint)(2000 * (1 + (0.4 * m_generator.UpgradeValues["Productivity"])));
                    inventory.AddItems(amount, new MyObjectBuilder_Ore()
                    {
                        SubtypeName = "Stone"
                    });
                    terminalBlock.RefreshCustomInfo();
                }
            }
        }
Ejemplo n.º 16
0
        public override void UpdateBeforeSimulation100()
        {
            try
            {
                MyAPIGateway.Parallel.Start(() =>
                {
                    if (m_gasGenerator != null)
                    {
                        m_gasGenerator.UseConveyorSystem = false;
                    }
                    if (m_terminalBlock != null)
                    {
                        m_terminalBlock.ShowInInventory = false;
                    }

                    m_cosTheta    = 0;
                    m_speed       = 0;
                    m_amountAdded = 0;

                    if (m_functionalBlock != null && m_functionalBlock.IsWorking && m_functionalBlock.IsFunctional)
                    {
                        m_state = RamscoopState.Idle;

                        if (m_inventory != null && m_inventory.GetItemsCount() == 0)
                        {
                            DoWork();
                        }
                    }
                    else
                    {
                        m_state = RamscoopState.Disabled;
                    }

                    if (m_terminalBlock != null)
                    {
                        m_terminalBlock.RefreshCustomInfo();
                    }
                });
            }
            catch (Exception e)
            { Debug.HandleException(e); }
        }
Ejemplo n.º 17
0
        internal static void SetSelectedGrid(IMyTerminalBlock arg1, List <MyTerminalControlListBoxItem> newSelectedItems)
        {
            //We defined in terminal controls that only one item can be selected;
            SelectedBoxItem = -1;
            for (int i = 0; i < List.Count; i++)
            {
                MarketListing Offer = (MarketListing)List[i].UserData;
                if (newSelectedItems[0].UserData as MarketListing == Offer)
                {
                    SelectedBoxItem = i;
                    SelectedOffer   = Offer;
                    break;
                }
            }


            //Utils.Log("Set selected item");
            arg1.RefreshCustomInfo();
            UpdateGUI(arg1);
        }
Ejemplo n.º 18
0
        public override void UpdateBeforeSimulation()
        {
            if (IsWorking())
            {
                if (_range < _maxrange && _count == 30)
                {
                    _range += (_maxrange / 20f);
                    _tblock.SetEmissiveParts("Emissive0", Color.Green, (_range / _maxrange));
                }
                else
                {
                    _tblock.SetEmissiveParts("Emissive0", Color.Green, 1.0f);
                }
                if (!MyAPIGateway.Utilities.IsDedicated)
                {
                    showRange(_range);
                }
                else
                {
                    sendPoke(_range);
                }
                if (_count++ == 60)
                {
                    gridEffects();
                }
            }
            else if (_wasOn)
            {
                _tblock.SetEmissiveParts("Emissive0", Color.DarkRed, 0.20f);
                _range = 0f;
            }

            if (IsWorking() != _wasOn && _ublock.Components.TryGet(out _sink))
            {
                _sink.Update();
                _tblock.RefreshCustomInfo();
                _wasOn = IsWorking();
            }
        }
Ejemplo n.º 19
0
 private void OnRequiredInputChanged(MyDefinitionId unused1, MyResourceSinkComponent unused2, float unused3, float unused4)
 {
     _thisTerminalBlock.RefreshCustomInfo();
 }
        private void SolarPanel_MaxOutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source)
        {
            //is this possible?
            if (source?.Entity == null)
            {
                return;
            }

            //shouldn't happen, should always exist from the OnEntityCreate
            if (solarPanelData.ContainsKey(source.Entity.EntityId) == false)
            {
                return;
            }

            var data = solarPanelData[source.Entity.EntityId];

            //if the max output matches our current max output, or our original max output don't do anything
            if (data.CurrentMaxOutput == source.MaxOutput || data.OriginalMaxOutput == source.MaxOutput)
            {
                return;
            }

            IMyTerminalBlock terminalEntity = source.Entity as IMyTerminalBlock;

            if (terminalEntity == null)
            {
                return;
            }

            //set our new original max output then recalculate
            solarPanelData[source.Entity.EntityId].OriginalMaxOutput = source.MaxOutput;


            //did we change grids?
            if (terminalEntity.CubeGrid.EntityId != data.GridEntityId)
            {
                //check if we're static again
                data.IsStatic = terminalEntity.CubeGrid.IsStatic;

                //force a re-calculation of air density
                data.CurrentAirDensity = null;
            }

            if (data.CurrentAirDensity == null || data.IsStatic == false)
            {
                var      entityPosition = terminalEntity.GetPosition();
                float    airDensity     = 0f;
                MyPlanet closestPlanet  = MyGamePruningStructure.GetClosestPlanet(entityPosition);
                if (closestPlanet == null || closestPlanet.PositionComp.WorldAABB.Contains(entityPosition) == ContainmentType.Disjoint)
                {
                    airDensity = 0f;
                }
                else
                {
                    airDensity = closestPlanet.GetAirDensity(entityPosition);
                }

                if (data.CurrentAirDensity != airDensity)
                {
                    data.CurrentAirDensity = airDensity;
                    terminalEntity.RefreshCustomInfo();
                }
            }

            //update
            UpdatePower(source.Entity as IMySolarPanel, data);
        }
Ejemplo n.º 21
0
 private void ScanVoxelComplete()
 {
     m_block.RefreshCustomInfo();
     m_lastUpdate = DateTime.Now;
     m_busy       = false;
 }
Ejemplo n.º 22
0
 internal static void RequestDecoySubSystem(IMyTerminalBlock block, long newValue)
 {
     block.CustomData = newValue.ToString();
     block.RefreshCustomInfo();
 }
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();
            //MyAPIGateway.Utilities.ShowNotification ("YEP: " + m_subtypeName, 17);

            if (m_functionalBlock.IsFunctional)
            {
                if (m_functionalBlock.Enabled)
                {
                    m_info.enabled = true;
                }
                else
                {
                    m_info.enabled = false;
                }
            }
            else
            {
                m_info.enabled = false;
            }

            if (!m_sender)
            {
                if (m_currentRequiredInput != 0)
                {
                    m_resourceSink.SetRequiredInputByType(m_electricityDefinition, 0);
                    m_oldTransmittedPower  = 0;
                    m_currentRequiredInput = 0;
                }

                m_target = null;
            }
            else if (m_functionalBlock.Enabled && m_functionalBlock.IsFunctional)
            {
                if (m_target != null)
                {
                    if (m_target.functionalBlock == null)
                    {
                        m_target = null;
                    }
                    else
                    {
                        if (!m_target.functionalBlock.Enabled)
                        {
                            m_target = null;
                        }
                    }
                }

                if (m_ticks % 100 == 0)
                {
                    if (m_sender)
                    {
                        maintainConnection();
                    }

                    m_targetIdOld = m_targetId;
                }

                if (m_target != null)
                {
                    if (m_targetVisible)
                    {
                        m_currentOutput = m_resourceSink.CurrentInputByType(m_electricityDefinition);

                        m_powerToTransfer = m_currentOutput * m_powerMultiplicator;

                        var transmitterComponent = m_target.functionalBlock.GameLogic.GetAs <OpticalPowerTransmitter>();



                        if ((transmitterComponent.m_receivingPower + m_powerToTransfer) > m_target.strength)
                        {
                            m_powerToTransfer = m_target.strength - transmitterComponent.m_receivingPower;
                        }

                        transmitterComponent.m_receivingPower += m_powerToTransfer;
                        transmitterComponent.m_senders++;
                        //MyAPIGateway.Utilities.ShowNotification ("ADD: " + m_target.functionalBlock.CubeGrid.EntityId + ":" + powerToTransfer, 17, MyFontEnum.DarkBlue);
                        TransmissionManager.totalPowerPerGrid [m_target.functionalBlock.CubeGrid.EntityId] = TransmissionManager.totalPowerPerGrid [m_target.functionalBlock.CubeGrid.EntityId] + m_powerToTransfer;
                    }
                }
            }
            else
            {
                m_target = null;

                if (m_currentRequiredInput != 0)
                {
                    m_resourceSink.SetRequiredInputByType(m_electricityDefinition, 0);
                    m_oldTransmittedPower  = 0;
                    m_currentRequiredInput = 0;
                }
            }

            if (m_ticks % 100 == 0)
            {
                m_terminalBlock.RefreshCustomInfo();
            }

            if (m_sender)
            {
                m_saveInfo.ChannelTarget = m_targetId;
            }
            else
            {
                m_saveInfo.ChannelTarget = m_id;
            }

            m_saveInfo.Sender = m_sender;
            m_saveInfo.Power  = m_transmittedPower;

            m_receivingPower = 0f;
            m_senders        = 0;



            m_ticks++;
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Refresh custom info & raise properties changed.
 /// </summary>
 public static void UpdateCustomInfo(this IMyTerminalBlock block)
 {
     block.RefreshCustomInfo();
     ((MyTerminalBlock)block).RaisePropertiesChanged();
 }
Ejemplo n.º 25
0
        public static void GetForSaleGrids(IMyTerminalBlock block, List <MyTerminalControlListBoxItem> listItems, List <MyTerminalControlListBoxItem> selectedItems)
        {
            //We need to completley redo ALL this.

            try
            {
                foreach (MarketList grid in MarketGrids)
                {
                    //MyLog.Default.WriteLineAndConsole("Grid "+grid.Name+" is in the marked list grid out of "+MarketGrids.Count+" total grids");
                    if (!listItems.Any(x => x.Text == MyStringId.GetOrCompute(grid.Name)))
                    {
                        var dummy2 = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(grid.Name), MyStringId.GetOrCompute("PCU: " + grid.PCU), grid);
                        MyLog.Default.WriteLineAndConsole("Adding grid " + grid.Name + " to the block!");
                        listItems.Add(dummy2);
                    }
                }


                if (RemovedMarketGrids != null)
                {
                    try
                    {
                        var item = listItems.First(x => x.Text.String == RemovedMarketGrids.Name);
                        listItems.Remove(item);
                        MyLog.Default.WriteLineAndConsole("Removing grid from the block!");
                    }
                    catch
                    {
                        //Do freaking nothing. ffs
                    }



                    if (selectedItems.Count != 0 && selectedItems[0].Text.String == RemovedMarketGrids.Name)
                    {
                        selectedItems.Clear();
                    }



                    //Check to see if the selected item was our purchased item


                    RemovedMarketGrids = null;
                }



                //Reupdate selected items
                if (listItems.Count == 1)
                {
                    selectedItems.Clear();
                    selectedItems.Add(listItems[0]);
                    SelectedGrid = (MarketList)listItems[0].UserData;

                    MyTerminalControlListBoxItem item = listItems[0];
                    SelectedBoxItem = item;

                    block.RefreshCustomInfo();
                }
                else if (listItems.Count == 0)
                {
                    selectedItems.Clear();
                    block.RefreshCustomInfo();
                }
                else
                {
                    selectedItems.Clear();

                    if (listItems.Count == 0)
                    {
                        return;
                    }

                    selectedItems.Add(listItems.FirstOrDefault(x => x.Text == SelectedBoxItem.Text));
                }

                //var toList = new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(grid.CustomName), MyStringId.GetOrCompute(grid.CustomName), objectText);


                //Can you do this?? Check to see if your saved selected item is in the new list?

                //Clear the selected grid
                //SelectedGrid = null;
                //block.RefreshCustomInfo();
            }
            catch (Exception e)
            {
                //Temp Debug
                MyLog.Default.WriteLineAndConsole("Exception Thrown! \n" + e);
            }

            //UpdateGUI(block);
        }