Ejemplo n.º 1
0
            private void ParseFromDetailedInfo(IMyReactor reactor)
            {
                string []    lines         = reactor.DetailedInfo.Split(new char [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                string [] [] dictionary    = new string [lines.Length] [];
                string       maxoutput     = "";
                string       currentoutput = "";

                for (int i = 0; i < lines.Length; i++)
                {
                    dictionary [i] = lines [i].Split(new string [] { ": " }, StringSplitOptions.None);

                    switch (dictionary [i] [0])
                    {
                    case "Max Output":
                        maxoutput = dictionary [i] [1];
                        break;

                    case "Current Output":
                        currentoutput = dictionary [i] [1];
                        break;
                    }
                }

                MaxWatts = GetWattValue(maxoutput);
                Watts    = GetWattValue(currentoutput);
            }
        // END
        // ============================================================================================================================

        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            block      = (IMyReactor)Entity;
            powerBlock = (IMyPowerProducer)block;

            NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
Ejemplo n.º 3
0
 public Reactor(string oBlockName)
 {
     m_oBlock = gts.GetBlockWithName(oBlockName) as IMyReactor;
     if (m_oBlock == null)
     {
         throw new Exception(oBlockName + " block not found, check name");
     }
     Init(m_oBlock);
 }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            try{
                Reactor      = Entity as IMyReactor;
                NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
            }catch (Exception exc) {
            }
        }
Ejemplo n.º 5
0
 public override void OnAddedToContainer()
 {
     if (MyAPIGateway.Utilities.IsDedicated)
     {
         return;
     }
     _reactor = (IMyReactor)Entity;
     _reactor.IsWorkingChanged += Reactor_IsWorkingChanged;
     Reactor_IsWorkingChanged(_reactor);
 }
        public override void Close()
        {
            if (block == null)
            {
                return;
            }

            block = null;

            NeedsUpdate = MyEntityUpdateEnum.NONE;
        }
Ejemplo n.º 7
0
        bool FuncTest(IMyReactor block)
        {
            //Small Reactor
            //Large Reactor
            //Interface name: IMyReactor
            //Parent: IMyFunctionalBlock
            //Fields:
            bool UseConveyorSystem = block.UseConveyorSystem;

            return(true);
        }
Ejemplo n.º 8
0
        double getCurrentReactorOutput()
        {
            double output = 0;

            foreach (var tb in reactorList)
            {
                IMyReactor r = tb as IMyReactor;
                output += r.CurrentOutput;
            }
            return(output);
        }
        List <IMyFunctionalBlock> Everything;    // Now this.... This is an Absolute Madness

        void GetNeededBlocks()
        {
            List <IMyFunctionalBlock> temp = new List <IMyFunctionalBlock>();

            GridTerminalSystem.GetBlocksOfType(temp);

            Power      = new List <IMyPowerProducer>();
            Batteries  = new List <IMyBatteryBlock>();
            Reactors   = new List <IMyReactor>();
            Producers  = new List <IMyProductionBlock>();
            Tanks      = new List <IMyGasTank>();
            Everything = new List <IMyFunctionalBlock>();

            foreach (IMyFunctionalBlock block in temp)
            {
                if (isOnThisGrid(block))
                {
                    Everything.Add(block);
                    if (block is IMyPowerProducer)
                    {
                        IMyPowerProducer power = (IMyPowerProducer)block;
                        Power.Add(power);
                        if (block is IMyBatteryBlock)
                        {
                            IMyBatteryBlock battery = (IMyBatteryBlock)block;
                            Batteries.Add(battery);
                        }
                        else
                        if (block is IMyReactor)
                        {
                            IMyReactor reactor = (IMyReactor)block;
                            Reactors.Add(reactor);
                        }
                    }
                    else
                    if (block is IMyProductionBlock)
                    {
                        IMyProductionBlock producer = (IMyProductionBlock)block;
                        Producers.Add(producer);
                    }
                    else
                    if (block is IMyGasTank)
                    {
                        IMyGasTank tank = (IMyGasTank)block;
                        if (tank.BlockDefinition.SubtypeName.Contains("HydrogenTank"))
                        {
                            Tanks.Add(tank);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            m_reactor = Entity as IMyReactor;
            m_parent  = Entity as VRage.Game.ModAPI.IMyCubeBlock;

            m_parent.UpgradeValues.Add("Power", 0f);

            m_objectBuilder = objectBuilder;

            m_parent.OnUpgradeValuesChanged += OnUpgradeValuesChanged;
        }
Ejemplo n.º 11
0
 public bool addReactor(IMyReactor _Reactor)
 {
     if (!reactors.Contains(_Reactor))
     {
         reactors.Add(_Reactor);
         MaxOutput     += (_Reactor.MaxOutput * MEGAWATT);
         CurrentOutput += (_Reactor.CurrentOutput * MEGAWATT);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 12
0
 public override void OnBeforeRemovedFromContainer()
 {
     if (MyAPIGateway.Utilities.IsDedicated)
     {
         return;
     }
     _reactor.IsWorkingChanged -= Reactor_IsWorkingChanged;
     _reactor = null;
     _effect?.Stop();
     if (_effect != null)
     {
         MyParticlesManager.RemoveParticleEffect(_effect);
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Status generatoru
        /// </summary>
        /// <returns></returns>
        public List <string> GetReactorStatus()
        {
            // definice
            List <string> status = new List <string>();

            //prochazeni bloku
            foreach (KeyValuePair <string, IMyReactor> block in Instance.GetByType <IMyReactor>())
            {
                //hodnoty
                IMyReactor reactor = block.Value as IMyReactor;
                float      actual  = reactor.CurrentOutput;
                float      maximum = reactor.MaxOutput;
                float      uranium = 0;
                //overeni funkcnosti
                if (reactor.IsFunctional && reactor.IsWorking)
                {
                    //overeni mnozstvi uranu
                    if (UraniumReference > 0)
                    {
                        // polozky inventare
                        List <MyInventoryItem> items = new List <MyInventoryItem>();
                        reactor.GetInventory(0).GetItems(items);
                        // vypocet mnozstvi uranu
                        if (items.Count > 0)
                        {
                            for (int j = 0; j < items.Count; j++)
                            {
                                if (items[j].Type.SubtypeId == "Uranium")
                                {
                                    uranium += (float)items[j].Amount;
                                }
                            }
                        }
                        // doplneni statusu do vystupu
                        status.Add(Formater.BarsWithPercent(Block.GetStatus(block.Value, uranium <= UraniumReference ? Status.UraniumIsLow : Status.Working), actual, maximum));
                    }
                    else
                    {
                        status.Add(Formater.BarsWithPercent(Block.GetStatus(block.Value, Status.UraniumIsEmpty), 0, maximum));
                    }
                }
                else
                {
                    status.Add(Formater.BarsWithPercent(Block.GetStatus(block.Value, Status.NotWorking), 0, maximum));
                }
            }
            // vraceni
            return(status);
        }
Ejemplo n.º 14
0
 void initReactors()
 {
     reactorList.Clear();
     maxReactorPower = -1;
     GridTerminalSystem.GetBlocksOfType <IMyReactor>(reactorList, localGridFilter);
     if (reactorList.Count > 0)
     {
         maxReactorPower = 0;
     }
     foreach (var tb in reactorList)
     {
         IMyReactor r = tb as IMyReactor;
         maxReactorPower += r.MaxOutput;
     }
 }
Ejemplo n.º 15
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            ModBlock = Entity as IMyReactor;

            MaxConsumptionPerTick = (MaxConsumptionPerTick / 60f) - (1 / 60 / 60 / 60 * ModBlock.MaxOutput);

            if (PhysicalFuelObject == null)
            {
                PhysicalFuelObject = new MyObjectBuilder_PhysicalObject();
                PhysicalFuelObject = new MyObjectBuilder_Ingot()
                {
                    SubtypeName = "Diesel"
                };
                DefinitionId = new MyDefinitionId(PhysicalFuelObject.TypeId, PhysicalFuelObject.SubtypeId);
            }

            ModBlock.CubeGrid.OnBlockAdded += BlockAdded;

            NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME;
        }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            this.Reactor = this.Entity as IMyReactor;
            this.Parent  = this.Entity as IMyCubeBlock;
            if (this.Parent == null)
            {
                return;
            }

            if (this.Parent.UpgradeValues.ContainsKey("Power"))
            {
                //Another mod is already doing our logic, skipping the setup
                return;
            }

            this.ObjectBuilder = objectBuilder;
            this.Parent.UpgradeValues.Add("Power", 0f);
            this.Parent.OnUpgradeValuesChanged += this.OnUpgradeValuesChanged;
        }
        void init()
        {
            List<IMyReactor> reactors = new List<IMyReactor>();
            GridTerminalSystem.GetBlocksOfType<IMyReactor>(reactors);
            for (int i = 0; i < reactors.Count; i++)
            {
                if (reactors[i].CustomData.Contains("stationReactor"))
                {
                    reactor = reactors[i];
                    break;
                }
            }

            reactorMonitors.Clear(); //Reset List

            //Pull all Panels
            List<IMyTextPanel> panels = new List<IMyTextPanel>();
            GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(panels);

            //Find Marked Panels
            for (int i = 0; i < panels.Count; i++)
            {
                if (panels[i].CustomData.Contains("reactorMonitor"))
                {
                    reactorMonitors.Add(panels[i]);
                }
            }

            //Configure LCDs
            for (int i = 0; i < reactorMonitors.Count; i++)
            {
                reactorMonitors[i].SetValue<Int64>("Font", 1147350002); //Set Font to Monospace
                reactorMonitors[i].SetValue<Color>("FontColor", new Color(255, 255, 255)); // set preset font colour
                reactorMonitors[i].SetValue<Single>("FontSize", (Single)1); // set font size
                reactorMonitors[i].SetValue<Color>("BackgroundColor", new Color(0, 0, 0)); // set BG 
                reactorMonitors[i].ShowPublicTextOnScreen();
            }
        }
Ejemplo n.º 18
0
            public static float GetReactorFuelLevel(IMyReactor reactor)
            {
                IMyInventory inventory = reactor.GetInventory(0);

                return((float)inventory.CurrentVolume / (float)inventory.MaxVolume);
            }
Ejemplo n.º 19
0
        public override void UpdateBeforeSimulation()
        {
            if (MyAPIGateway.Utilities.IsDedicated || MyAPIGateway.Session == null)
            {
                return;
            }

            IMyCockpit cockpit = MyAPIGateway.Session.Player?.Controller?.ControlledEntity?.Entity as IMyCockpit;

            if (cockpit == null)
            {
                JustGotInCockpit = true;
                return;
            }

            if (JustGotInCockpit)
            {
                JustGotInCockpit = false;
                slims.Clear();
                cockpit.CubeGrid.GetBlocks(slims, b => b.FatBlock != null && !b.FatBlock.BlockDefinition.IsNull() && FuelStorage.Contains(b.FatBlock.BlockDefinition.SubtypeId));
            }

            int          blockCount      = 0;
            double       consumptionRate = 0;
            MyFixedPoint total           = 0;
            MyFixedPoint current         = 0;

            foreach (IMySlimBlock slim in slims)
            {
                IMyCubeBlock block   = slim.FatBlock;
                IMyReactor   reactor = block as IMyReactor;
                IMyInventory inv     = block.GetInventory(0);
                if (!block.IsFunctional || !block.IsWorking || inv == null)
                {
                    continue;
                }

                switch (block.BlockDefinition.SubtypeId)
                {
                case "V8Engine":
                    consumptionRate += 0.06666666666666666666666666666667d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;

                case "V8EngineTurbo":
                    consumptionRate += 0.11666666666666666666666666666667d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;

                case "hmdieselgenerator3_Large":
                    consumptionRate += 0.05d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;

                case "hmdieselgenerator1_Large":
                    consumptionRate += 0.00833333333333333333333333333333d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;
                }

                blockCount++;
                total   += inv.MaxVolume;
                current += inv.CurrentVolume;
            }

            if (total > 0 && consumptionRate > 0)
            {
                double percent = (((double)current * 1000d) / ((double)total * 1000d) * 100d);
                double tick    = (((double)current * 1000d) / consumptionRate);

                MyAPIGateway.Utilities.ShowNotification($"Fuel: {percent.ToString("n0")}% {TimeSpan.FromMilliseconds((tick / 60d) * 1000d).ToString("g").Split('.')[0]}", 1);
            }
        }
Ejemplo n.º 20
0
 public Reactor(IMyTerminalBlock oBlock) : base(oBlock)
 {
     m_oBlock = (IMyReactor)oBlock;
 }
Ejemplo n.º 21
0
 public Reactor(IMyReactor oBlock) : base(oBlock)
 {
     m_oBlock = oBlock;
 }
Ejemplo n.º 22
0
 void Initialize()        // Handles the initialization of blocks. Is run at the end of each loop to ensure everything is there.
 {
     inventories.Clear(); // This must be done to avoid memory leaks.
     refineries.Clear();
     furnaces.Clear();
     assemblers.Clear();
     reactors.Clear();
     gasGenerators.Clear();
     gatlings.Clear();
     missileLaunchers.Clear();
     lcds.Clear();
     if (!Me.CustomName.ToLower().Contains(TAG.ToLower())) // If we have no tag at all.
     {
         Me.CustomName += " " + TAG;                       // Add a tag.
     }//
     else if (!Me.CustomName.Contains(TAG))                // We know we have a tag, but run this when the tag isn't exactly equal.
     {
         string customName = Me.CustomName;                // Replacing the incorrect tag with the proper version.
         int    index      = customName.ToLower().IndexOf(TAG.ToLower());
         customName    = customName.Remove(index, TAG.Length);
         customName    = customName.Insert(index, TAG);
         Me.CustomName = customName;
     }//
     GridTerminalSystem.SearchBlocksOfName(TAG, blocks);
     foreach (IMyTerminalBlock block in blocks)
     {
         if (!block.CustomName.Contains(TAG))// If the tag doesn't match up exactly, correct the tag.
         {
             string customName = block.CustomName;
             int    index      = customName.ToLower().IndexOf(TAG.ToLower());
             customName       = customName.Remove(index, TAG.Length);
             customName       = customName.Insert(index, TAG);
             block.CustomName = customName;
         }//
         IMyRefinery refinery = block as IMyRefinery;// This will return null if the block isn't a refinery block.
         if (refinery != null)
         {
             if (refinery.BlockDefinition.SubtypeId.Equals(FURNACE_TYPE_ID))// Both Refinieries and Arc Furnaces are refineries. Seperate them by subtype.
             {
                 furnaces.Add(refinery);
             }
             else
             {
                 refineries.Add(refinery);
             }
             continue;
         }//
         IMyAssembler assembler = block as IMyAssembler;
         if (assembler != null)
         {
             assemblers.Add(assembler);
             continue;
         }//
         IMyReactor reactor = block as IMyReactor;
         if (reactor != null)
         {
             reactors.Add(reactor);
             continue;
         }//
         IMyGasGenerator gasGenerator = block as IMyGasGenerator;
         if (gasGenerator != null)
         {
             gasGenerators.Add(gasGenerator);
             continue;
         }//
         IMyLargeGatlingTurret gatlingTurret = block as IMyLargeGatlingTurret;
         IMySmallGatlingGun    gatlingGun    = block as IMySmallGatlingGun;
         if ((gatlingTurret != null) | (gatlingGun != null))
         {
             gatlings.Add(block);
             continue;
         }//
         IMyLargeMissileTurret         missileTurret       = block as IMyLargeMissileTurret;
         IMySmallMissileLauncherReload smallLauncherReload = block as IMySmallMissileLauncherReload;
         if ((missileTurret != null) | (smallLauncherReload != null))
         {
             missileLaunchers.Add(block);
             continue;
         }//
         IMySmallMissileLauncher missileLauncher = block as IMySmallMissileLauncher;
         if ((missileLauncher != null) & (block.BlockDefinition.SubtypeId.Equals("LargeMissileLauncher")))
         {
             missileLaunchers.Add(block);
             continue;
         }//
         IMyProgrammableBlock programmableBlock = block as IMyProgrammableBlock;
         if (programmableBlock != null)
         {
             if (!programmableBlock.Equals(Me) & programmableBlock.IsWorking)                     // If the programmable block isn't the one running this instance and it is working.
             {
                 if (programmableBlock.CustomName.ToLower().Contains(CONNECTED_PB_TAG.ToLower())) // Check if it has the connected PB tag.
                 {
                     if (!programmableBlock.CustomName.Contains(CONNECTED_PB_TAG))
                     {
                         string customName = programmableBlock.CustomName;
                         int    index      = customName.ToLower().IndexOf(CONNECTED_PB_TAG.ToLower());
                         customName = customName.Remove(index, CONNECTED_PB_TAG.Length);
                         customName = customName.Insert(index, CONNECTED_PB_TAG);
                         programmableBlock.CustomName = customName;
                     }//
                     connectedPBs.Add(programmableBlock);
                     continue;
                 }    //
                 else // Assume this PB is running the same script.
                 {
                     if (programmableBlock.CubeGrid.EntityId == Me.CubeGrid.EntityId)
                     {
                         Echo("ERROR: MORE THAN ONE IAN ON ONE GRID");
                         active = false;// Both PBs will disable themselves and show an error.
                         continue;
                     }//
                     else if (programmableBlock.CubeGrid.GridSize > Me.CubeGrid.GridSize)// The PB with the biggest grid size will be dominant.
                     {
                         active = false;
                         continue;
                     }
                     active = true;// None of the exceptions have occured, so we are free to resume functioning. This will ensure IAN plays nice with it's double.
                     continue;
                 }//
             } //
         }     //
         IMyTextPanel panel = block as IMyTextPanel;
         if (panel != null)
         {
             lcds.Add(panel);
         }
     } //
 }     //
Ejemplo n.º 23
0
 public PowerInfo(IMyReactor reactor) : this(0, 0)
 {
     ParseFromDetailedInfo(reactor);
 }