示例#1
0
        /// <summary>
        /// Gives the 'available' amount inventory + queued
        /// queueSize total amount of queued items indicator for workload
        /// </summary>
        private static int AvailableAmount(IMyProductionBlock productionBlock, VRage.Game.MyDefinitionId materialId, VRage.Game.MyDefinitionBase blueprintDefinition, out int queueSize)
        {
            var queue          = productionBlock.GetQueue();
            var inventory      = productionBlock.OutputInventory;
            var inventoryItems = inventory != null?inventory.GetItems() : null;

            var amount = 0;

            queueSize = 0;
            if (inventoryItems != null)
            {
                foreach (var item in inventoryItems)
                {
                    if (item.Content.TypeId == materialId.TypeId && item.Content.SubtypeId == materialId.SubtypeId)
                    {
                        amount += (int)item.Amount;
                    }
                }
            }

            if (queue != null)
            {
                foreach (var item in queue)
                {
                    queueSize += (int)item.Amount;
                    if (item.Blueprint.Id.Equals(blueprintDefinition.Id))
                    {
                        amount += (int)item.Amount;
                    }
                }
            }

            return(amount);
        }
        /// <summary>
        /// Gives the 'available' amount inventory + queued
        /// queueSize total amount of queued items indicator for workload
        /// </summary>
        private static int AvailableAmount(IMyProductionBlock productionBlock, VRage.Game.MyDefinitionId materialId, VRage.Game.MyDefinitionBase blueprintDefinition, out int queueSize)
        {
            var queue              = productionBlock.GetQueue();
            var inventory          = productionBlock.OutputInventory;
            var tempInventoryItems = new List <VRage.Game.ModAPI.Ingame.MyInventoryItem>();

            if (inventory != null)
            {
                inventory.GetItems(tempInventoryItems);
            }
            var amount = 0;

            queueSize = 0;
            foreach (var item in tempInventoryItems)
            {
                if ((VRage.Game.MyDefinitionId)item.Type == materialId)
                {
                    amount += (int)item.Amount;
                }
            }

            if (queue != null)
            {
                foreach (var item in queue)
                {
                    queueSize += (int)item.Amount;
                    if (item.Blueprint.Id.Equals(blueprintDefinition.Id))
                    {
                        amount += (int)item.Amount;
                    }
                }
            }

            return(amount);
        }
示例#3
0
            public void checkQueue()
            {
                MyDefinitionId ingots = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/StoneOreToIngotBasic");

                // no Ingots in queue?
                List <MyProductionItem> queue = new List <MyProductionItem>();

                production_.GetQueue(queue);
                foreach (var item in queue)
                {
                    if (item.BlueprintId == ingots && item.Amount > 0)
                    {
                        return;
                    }
                }

                // add Ingots to queue
                production_.InsertQueueItem(0, ingots, 2000d);
            }
            protected override void update()
            {
                for (;
                     blockIndex_ < Blocks.Count &&
                     App.Runtime.CurrentInstructionCount < Default.MaxInstructionCount;
                     blockIndex_++)
                {
                    IMyProductionBlock block = Blocks[blockIndex_] as IMyProductionBlock;

                    blocksOn_         += isOn(block) ? 1 : 0;
                    blocksFunctional_ += block.IsFunctional ? 1 : 0;

                    // get list of all items in the queue
                    List <MyProductionItem> queue = new List <MyProductionItem>();
                    block.GetQueue(queue);

                    long currentAmount = 0;

                    // rebuild current amount with current production state
                    foreach (var item in queue)
                    {
                        currentAmount       += (long)item.Amount;
                        currentQueuedItems_ += (long)item.Amount;
                        int index = items_.FindIndex((entry) => entry.BlueprintId == item.BlueprintId.ToString());
                        if (index >= 0)
                        {
                            items_[index].CurrentAmount += (long)item.Amount;
                        }
                        else
                        {
                            items_.Add(new ProductionItem(item));
                        }
                    }

                    currentPerBlock_[block.EntityId] = currentAmount;
                    maxPerBlock_[block.EntityId]     = currentAmount == 0 ? 0 : Math.Max(maxPerBlock_[block.EntityId], currentAmount);
                }

                UpdateFinished = blockIndex_ >= Blocks.Count;
            }
示例#5
0
 public void GetQueue(List <MyProductionItem> productionItems)
 {
     productionItems.Clear();
     block.GetQueue(productionItems);
 }
示例#6
0
            public List <Item> TraversalMachine(IMyProductionBlock block)
            {
                int         loop  = 0;
                List <Item> items = new List <Item>();

                Dictionary <string, double> last_amount;

                if (last_machine_amount.ContainsKey(block.EntityId))
                {
                    last_amount = last_machine_amount[block.EntityId];
                }
                else
                {
                    last_amount = new Dictionary <string, double>();
                    last_machine_amount.Add(block.EntityId, last_amount);
                }

                if (block is IMyAssembler)
                {
                    List <MyProductionItem> productionItems = new List <MyProductionItem>();
                    block.GetQueue(productionItems);
                    if (productionItems.Count > 0)
                    {
                        loop = 0;
                        foreach (MyProductionItem productionItem in productionItems)
                        {
                            if (loop >= max_loop)
                            {
                                break;
                            }
                            string         iName            = Util.GetName(productionItem);
                            string         iType            = Util.GetType(productionItem);
                            string         key              = String.Format("{0}_{1}", iType, iName);
                            MyDefinitionId itemDefinitionId = productionItem.BlueprintId;
                            double         amount           = 0;
                            Double.TryParse(productionItem.Amount.ToString(), out amount);

                            int variance = 2;
                            if (last_amount.ContainsKey(key))
                            {
                                if (last_amount[key] < amount)
                                {
                                    variance = 1;
                                }
                                if (last_amount[key] > amount)
                                {
                                    variance = 3;
                                }
                                last_amount[key] = amount;
                            }
                            else
                            {
                                variance = 1;
                                last_amount.Add(key, amount);
                            }

                            items.Add(new Item()
                            {
                                Name     = iName,
                                Type     = iType,
                                Amount   = amount,
                                Variance = variance
                            });
                            loop++;
                        }
                    }
                }
                else
                {
                    List <MyInventoryItem> inventoryItems = new List <MyInventoryItem>();
                    block.InputInventory.GetItems(inventoryItems);
                    if (inventoryItems.Count > 0)
                    {
                        loop = 0;
                        foreach (MyInventoryItem inventoryItem in inventoryItems)
                        {
                            if (loop >= max_loop)
                            {
                                break;
                            }
                            string iName  = Util.GetName(inventoryItem);
                            string iType  = Util.GetType(inventoryItem);
                            string key    = String.Format("{0}_{1}", iType, iName);
                            double amount = 0;
                            Double.TryParse(inventoryItem.Amount.ToString(), out amount);

                            int variance = 2;
                            if (last_amount.ContainsKey(key))
                            {
                                if (last_amount[key] < amount)
                                {
                                    variance = 1;
                                }
                                if (last_amount[key] > amount)
                                {
                                    variance = 3;
                                }
                                last_amount[key] = amount;
                            }
                            else
                            {
                                variance = 1;
                                last_amount.Add(key, amount);
                            }

                            items.Add(new Item()
                            {
                                Name     = iName,
                                Type     = iType,
                                Amount   = amount,
                                Variance = variance
                            });
                            loop++;
                        }
                    }
                }
                last_machine_amount[block.EntityId] = last_amount;
                return(items);
            }
示例#7
0
 public Production(IMyProductionBlock block)
 {
     IsProducing  = block.IsProducing;
     IsQueueEmpty = block.IsQueueEmpty;
     block.GetQueue(Queue);
 }
示例#8
0
        public void Make_inventory()
        {
            //first count blocks already in produktion,
            //if the amount is larger than the minimum, do nothing.
            //else build difference

            Dbg_panel("Make_inventory()");

            List <MyProductionItem> queue_list = new List <MyProductionItem>();

            assembler.GetQueue(queue_list);

            foreach (MyProductionItem queue_item in queue_list)
            {
                string       queue_item_name   = queue_item.BlueprintId.SubtypeName;
                MyFixedPoint queue_item_amount = queue_item.Amount;

                if (queue_item_name == "BulletproofGlass")
                {
                    bulletproof_glass_production_queue = queue_item_amount;
                }
                if (queue_item_name == "Canvas")
                {
                    canvas_production_queue = queue_item_amount;
                }
                if (queue_item_name == "ComputerComponent")
                {
                    computer_production_queue = queue_item_amount;
                }
                if (queue_item_name == "ConstructionComponent")
                {
                    construction_component_production_queue = queue_item_amount;
                }
                if (queue_item_name == "DetectorComponent")
                {
                    detector_components_production_queue = queue_item_amount;
                }
                if (queue_item_name == "Display")
                {
                    display_production_queue = queue_item_amount;
                }
                if (queue_item_name == "ExplosivesComponent")
                {
                    explosives_production_queue = queue_item_amount;
                }
                if (queue_item_name == "GirderComponent")
                {
                    girder_production_queue = queue_item_amount;
                }
                if (queue_item_name == "GravityGeneratorComponent")
                {
                    gravity_generator_components_production_queue = queue_item_amount;
                }
                if (queue_item_name == "InteriorPlate")
                {
                    interior_plate_production_queue = queue_item_amount;
                }
                if (queue_item_name == "LargeTube")
                {
                    large_steel_tube_production_queue = queue_item_amount;
                }
                if (queue_item_name == "MedicalComponent")
                {
                    medical_components_production_queue = queue_item_amount;
                }
                if (queue_item_name == "MetalGrid")
                {
                    metal_grid_production_queue = queue_item_amount;
                }
                if (queue_item_name == "MotorComponent")
                {
                    motor_production_queue = queue_item_amount;
                }
                if (queue_item_name == "PowerCell")
                {
                    power_cell_production_queue = queue_item_amount;
                }
                if (queue_item_name == "RadioCommunicationComponent")
                {
                    radio_communication_components_production_queue = queue_item_amount;
                }
                if (queue_item_name == "ReactorComponent")
                {
                    reactor_components_production_queue = queue_item_amount;
                }
                if (queue_item_name == "SmallTube")
                {
                    small_steel_tube_production_queue = queue_item_amount;
                }
                if (queue_item_name == "SolarCell")
                {
                    solar_cell_production_queue = queue_item_amount;
                }
                if (queue_item_name == "SteelPlate")
                {
                    steel_plate_production_queue = queue_item_amount;
                }
                if (queue_item_name == "Superconductor")
                {
                    superconductor_component_production_queue = queue_item_amount;
                }
                if (queue_item_name == "ThrustComponent")
                {
                    thruster_components_production_queue = queue_item_amount;
                }
            }

            Make_component(bulletproof_glass_min_count, bulletproof_glass_current_count, bulletproof_glass_production_queue, "MyObjectBuilder_BlueprintDefinition/BulletproofGlass");
            Make_component(canvas_min_count, canvas_current_count, canvas_production_queue, "MyObjectBuilder_BlueprintDefinition/Canvas");
            Make_component(computer_min_count, computer_current_count, computer_production_queue, "MyObjectBuilder_BlueprintDefinition/ComputerComponent");
            Make_component(construction_component_min_count, construction_component_current_count, construction_component_production_queue, "MyObjectBuilder_BlueprintDefinition/ConstructionComponent");
            Make_component(detector_components_min_count, detector_components_current_count, detector_components_production_queue, "MyObjectBuilder_BlueprintDefinition/DetectorComponent");
            Make_component(display_min_count, display_current_count, display_production_queue, "MyObjectBuilder_BlueprintDefinition/Display");
            Make_component(explosives_min_count, explosives_current_count, explosives_production_queue, "MyObjectBuilder_BlueprintDefinition/ExplosivesComponent");
            Make_component(girder_min_count, girder_current_count, girder_production_queue, "MyObjectBuilder_BlueprintDefinition/GirderComponent");
            Make_component(gravity_generator_components_min_count, gravity_generator_components_current_count, gravity_generator_components_production_queue, "MyObjectBuilder_BlueprintDefinition/GravityGeneratorComponent");
            Make_component(interior_plate_min_count, interior_plate_current_count, interior_plate_production_queue, "MyObjectBuilder_BlueprintDefinition/InteriorPlate");
            Make_component(large_steel_tube_min_count, large_steel_tube_current_count, large_steel_tube_production_queue, "MyObjectBuilder_BlueprintDefinition/LargeTube");
            Make_component(medical_components_min_count, medical_components_current_count, medical_components_production_queue, "MyObjectBuilder_BlueprintDefinition/MedicalComponent");
            Make_component(metal_grid_min_count, metal_grid_current_count, metal_grid_production_queue, "MyObjectBuilder_BlueprintDefinition/MetalGrid");
            Make_component(motor_min_count, motor_current_count, motor_production_queue, "MyObjectBuilder_BlueprintDefinition/MotorComponent");
            Make_component(power_cell_min_count, power_cell_current_count, power_cell_production_queue, "MyObjectBuilder_BlueprintDefinition/PowerCell");
            Make_component(radio_communication_components_min_count, radio_communication_components_current_count, radio_communication_components_production_queue, "MyObjectBuilder_BlueprintDefinition/RadioCommunicationComponent");
            Make_component(reactor_components_min_count, reactor_components_current_count, reactor_components_production_queue, "MyObjectBuilder_BlueprintDefinition/ReactorComponent");
            Make_component(small_steel_tube_min_count, small_steel_tube_current_count, small_steel_tube_production_queue, "MyObjectBuilder_BlueprintDefinition/SmallTube");
            Make_component(solar_cell_min_count, solar_cell_current_count, solar_cell_production_queue, "MyObjectBuilder_BlueprintDefinition/SolarCell");
            Make_component(steel_plate_min_count, steel_plate_current_count, steel_plate_production_queue, "MyObjectBuilder_BlueprintDefinition/SteelPlate");
            Make_component(superconductor_component_min_count, superconductor_component_current_count, superconductor_component_production_queue, "MyObjectBuilder_BlueprintDefinition/Superconductor");
            Make_component(thruster_components_min_count, thruster_components_current_count, thruster_components_production_queue, "MyObjectBuilder_BlueprintDefinition/ThrustComponent");
        }