Ejemplo n.º 1
0
        public Program()
        {
            m_MainCargoContainer  = GridTerminalSystem.GetBlockWithName(MainCargoName) as IMyCargoContainer;
            m_ToolsCargoContainer = GridTerminalSystem.GetBlockWithName(ToolsCargoName) as IMyCargoContainer;

            GridTerminalSystem.GetBlocksOfType(m_Assemblers, a => (a is IMyAssembler && a.CubeGrid == m_MainCargoContainer.CubeGrid));
            GridTerminalSystem.GetBlocksOfType(m_Refineries, a => (a is IMyRefinery && a.CubeGrid == m_MainCargoContainer.CubeGrid));

            m_MainAssembler    = m_Assemblers.First(a => a.CustomName == MainAssemblerName);
            m_MainGasGenerator = GridTerminalSystem.GetBlockWithName(MainGasGeneratorName) as IMyGasGenerator;

            m_FrontLcdOres       = GridTerminalSystem.GetBlockWithName(OresIngotsLcdName) as IMyTextSurface;
            m_FrontLcdComponents = GridTerminalSystem.GetBlockWithName(ComponentsLcdName) as IMyTextSurface;

            #region Лист заказов кроме стальных пластин
            m_OrderList = new List <MyItemType>();
            m_OrderList.Add(TypeInteriorPlate);
            m_OrderList.Add(TypeConstructionComponent);
            m_OrderList.Add(TypeMetalGrid);
            m_OrderList.Add(TypeComputer);
            m_OrderList.Add(TypeLargeTube);
            m_OrderList.Add(TypeSmallTube);
            m_OrderList.Add(TypeMotor);
            m_OrderList.Add(TypeDisplay);
            m_OrderList.Add(TypePowerCell);
            m_OrderList.Add(TypeGirder);
            m_OrderList.Add(TypeDetector);
            m_OrderList.Add(TypeRadioCommunication);
            m_OrderList.Add(TypeBulletproofGlass);
            #endregion

            Runtime.UpdateFrequency = UpdateFrequency.Update100;
        }
Ejemplo n.º 2
0
        /**
         * Locates all the Oxygen generator class blocks on the given grid,
         * then adds 2000 ice if there is room to do so.
         *
         * Only call on server.
         */
        public static void FillOxygenGenerators(IMyCubeGrid targetGrid)
        {
            List <IMySlimBlock> blockList = new List <IMySlimBlock>();

            targetGrid.GetBlocks(blockList, b => b.FatBlock is Sandbox.ModAPI.IMyGasGenerator);
            foreach (var block in blockList)
            {
                IMyGasGenerator gasGenerator = ((IMyGasGenerator)block.FatBlock);
                if (gasGenerator == null)
                {
                    continue;
                }

                MyDefinitionId definitionId = new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Ice");
                MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                    Amount  = AMOUNT_ICE_TO_ADD,
                    Content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId)
                };

                IMyInventory gasGeneratorInv = gasGenerator.GetInventory(0);
                if (!gasGeneratorInv.CanItemsBeAdded(AMOUNT_ICE_TO_ADD, definitionId))
                {
                    continue;
                }
                gasGeneratorInv.AddItems(AMOUNT_ICE_TO_ADD, inventoryItem.Content);
            }
        }
Ejemplo n.º 3
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);
            m_objectBuilder   = objectBuilder;
            m_gasGenerator    = Entity as IMyGasGenerator;
            m_terminalBlock   = Entity as IMyTerminalBlock;
            m_functionalBlock = Container.Entity as IMyFunctionalBlock;
            m_inventory       = (MyInventory)(Container.Entity as VRage.Game.Entity.MyEntity).GetInventoryBase();
            var subtype = m_functionalBlock.BlockDefinition.SubtypeId;

            if (m_functionalBlock.CubeGrid.GridSizeEnum == MyCubeSize.Small)
            {
                m_sizeFactor = SmallShipRate;
            }
            else
            {
                m_sizeFactor = LargeShipRate;
            }

            var ramscoopDefinition = MyDefinitionManager.Static.GetDefinition(new MyDefinitionId(typeof(MyObjectBuilder_OxygenGenerator), (Container.Entity as IMyFunctionalBlock).BlockDefinition.SubtypeId)) as MyOxygenGeneratorDefinition;

            m_IceToGasRatio = ramscoopDefinition.ProducedGases[0].IceToGasRatio;

            m_terminalBlock.AppendingCustomInfo += AppendingCustomInfo;
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
Ejemplo n.º 4
0
        private void tryMoveIce(IMyGasGenerator target)
        {
            //show("Attempting to move ice into "+target.CustomName);
            FoundItem item = findItem(new ItemProfile("ore/ice"));

            if (item != null)
            {
                MyFixedPoint amt = min(item.item.Amount, 1000);
                moveItem(item.source, target.GetInventory(), item.item, amt);
            }
            else
            {
                //show("Not found.");
            }
        }
Ejemplo n.º 5
0
        private void OnEntityCreate(MyEntity ent)
        {
            IMyGasGenerator generator = ent as IMyGasGenerator;

            if (generator == null)
            {
                return;
            }
            if (generator.BlockDefinition.SubtypeId != "MA_O2")
            {
                return;
            }
            OxyGen oxy = new OxyGen(generator);

            oxy.PruneMe      += CleanList;
            oxy.OnWriteToLog += WriteToLog;
            oxy.Report();
            _generators.Add(oxy);
        }
Ejemplo n.º 6
0
        public OxyGen(IMyGasGenerator thisGenerator)
        {
            Id                 = $"{Id} ({thisGenerator.EntityId})";
            _thisGenerator     = thisGenerator;
            _thisTerminalBlock = thisGenerator;
            _thisCubeBlock     = (MyCubeBlock)thisGenerator;
            _thisEntity        = (MyEntity)thisGenerator;
            _thisGenerator.OnUpgradeValuesChanged += OnUpgradeValuesChanged;
            _thisGenerator.AppendingCustomInfo    += AppendingCustomInfo;
            _thisEntity.AddedToScene    += OnAddedToScene;
            MySink.RequiredInputChanged += OnRequiredInputChanged;
            _thisGenerator.OnClose      += OnClose;
            _thisGenerator.AddUpgradeValue(Power, 1f);
            _thisGenerator.AddUpgradeValue(Yield, 1f);
            _thisGenerator.AddUpgradeValue(Speed, 1f);

            MyObjectBuilder_OxygenGenerator x = (MyObjectBuilder_OxygenGenerator)_thisGenerator.GetObjectBuilderCubeBlock();

            MyOxygenGeneratorDefinition def = MyDefinitionManager.Static.GetCubeBlockDefinition(x.GetId()) as MyOxygenGeneratorDefinition;

            if (def == null)
            {
                return;
            }
            foreach (MyOxygenGeneratorDefinition.MyGasGeneratorResourceInfo resource in def.ProducedGases)
            {
                if (resource.Id == _oxyDef)
                {
                    _baseOxyMaxOutput = KshDefaultMultiplier * resource.IceToGasRatio;
                }
                if (resource.Id == _hydroDef)
                {
                    _baseHydroMaxOutput = KshDefaultMultiplier * resource.IceToGasRatio;
                }
            }
        }
Ejemplo n.º 7
0
        public void Main()           //called each cycle
        //tick++;
        //if (tick%4 != 0)
        //	return;

        {
            tick++;
            bool cancel = false;

            foreach (IMyShipConnector conn in connectors)
            {
                if (conn.Enabled && conn.Status == MyShipConnectorStatus.Connected)
                {
                    if (shutdownWhenDockedTo(conn.DisplayName, conn.OtherConnector.DisplayName, conn.OtherConnector.CubeGrid.DisplayName))
                    {
                        cancel = true;
                        break;
                    }
                }
            }
            if (cancel)
            {
                Echo("Docked to dominant grid; not managing inventories.");
                return;
            }

            Echo("Managing " + refineryCount + " refineries, " + assemblers.Count + " assemblers, " + oxyGenerators.Count + " O2 gens, and " + cargo.Count + " cargo containers.");
            if (tick % 50 == 0)
            {
                cacheSources();
            }

            if (ENABLE_ORE_SORTING)
            {
                foreach (var entry in refineries)
                {
                    Refinery r = getRandom <Refinery>(entry.Value);
                    if (r != null && (r.refinery.Enabled || !SKIP_OFFLINE_REFINERIES))
                    {
                        ICollection <string> li = r.validOres;
                        if (ORE_PRIORITY.Length > 0)
                        {
                            li = applyPriorityRules(li);
                        }
                        foreach (string ore in li)
                        {
                            if (isOreValid(ore, r))
                            {
                                tryMoveOre(ore, r);
                            }
                        }
                        empty(r.refinery.OutputInventory);
                        if (!SKIP_OFFLINE_REFINERIES)
                        {
                            r.refinery.Enabled = r.hasWork();
                        }
                    }
                }

                IMyAssembler ass = getRandom <IMyAssembler>(assemblers);
                if (ass != null)
                {
                    empty(ass.Mode == MyAssemblerMode.Disassembly ? ass.InputInventory : ass.OutputInventory);
                    List <MyProductionItem> li = new List <MyProductionItem>();
                    ass.GetQueue(li);
                    ass.Enabled = li.Count > 0 || ass.CooperativeMode || ass.BlockDefinition.SubtypeName.ToLowerInvariant().Contains("survivalkit");
                }

                IMyGasGenerator gas = getRandom <IMyGasGenerator>(oxyGenerators);
                if (gas != null && (gas.Enabled || ENABLE_O2_GENS))
                {
                    tryMoveIce(gas);
                    if (ENABLE_O2_GENS)
                    {
                        gas.Enabled = true;                        // || gas.GetInventory().ItemCount > 0;
                    }
                }
            }
            if (MOVE_FROM_SMALL_TO_LARGE)
            {
                IMyCargoContainer box = getRandom <IMyCargoContainer>(cargo);
                if (box != null)
                {
                    if (box.GetInventory().ItemCount > 0 && box.BlockDefinition.SubtypeName.ToLowerInvariant().Contains("small"))
                    {
                        IMyInventory inv = box.GetInventory();
                        empty(inv, false);
                        //break;
                    }
                }
            }
            if (tick % 5 == 0)
            {
                bool flag = false;
                if (ejectionWatchers.Count > 0 && usedVolume / (float)maxCapacity >= EJECTION_THRESHOLD)
                {
                    foreach (ItemProfile p in ejectionWatchers)
                    {
                        float f = getItemFraction(p);
                        Echo("Item type " + p.ToString() + " represents " + f * 100 + "% of items.");
                        if (f >= EJECTION_THRESHOLD)
                        {
                            Echo("Ejecting excess.");
                            tryPrepareEjection(p);
                            flag = true;
                        }
                    }
                }
                if (!flag)
                {
                    Echo("No excess to eject.");
                    foreach (IMyShipConnector conn in ejectors)
                    {
                        conn.ThrowOut = false;
                    }
                }                /*
                                  * foreach (IMyShipConnector con in connectors) {
                                  *     if (con.Status == MyShipConnectorStatus.Connected) {
                                  *             FlowDirection flow = getActiveFlowDirection(con.CustomName, con.OtherConnector.CustomName, con.OtherConnector.CubeGrid.CustomName);
                                  *             if (flow != FlowDirection.INERT) {
                                  *
                                  *             }
                                  *     }
                                  * }*/
            }
        }
Ejemplo n.º 8
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);
         }
     } //
 }     //