Beispiel #1
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            this.m_cargoDefinition = (MyCargoContainerDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            MyObjectBuilder_CargoContainer container = (MyObjectBuilder_CargoContainer)objectBuilder;

            this.m_containerType = container.ContainerType;
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                base.FixSingleInventory();
            }
            if (this.GetInventory(0) == null)
            {
                MyInventory component = new MyInventory(this.m_cargoDefinition.InventorySize.Volume, this.m_cargoDefinition.InventorySize, MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive);
                base.Components.Add <MyInventoryBase>(component);
                if (((this.m_containerType != null) && MyFakes.RANDOM_CARGO_PLACEMENT) && ((container.Inventory == null) || (container.Inventory.Items.Count == 0)))
                {
                    this.SpawnRandomCargo();
                }
            }
            if ((container.Inventory != null) && (container.Inventory.Items.Count > 0))
            {
                this.GetInventory(0).Init(container.Inventory);
            }
            this.GetInventory(0).SetFlags(MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive);
            this.m_conveyorEndpoint = new MyMultilineConveyorEndpoint(this);
            base.AddDebugRenderComponent(new MyDebugRenderComponentDrawConveyorEndpoint(this.m_conveyorEndpoint));
            base.UpdateIsWorking();
        }
Beispiel #2
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            m_cargoDefinition = (MyCargoContainerDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());

            m_inventory = new MyInventory(m_cargoDefinition.InventorySize.Volume, m_cargoDefinition.InventorySize, MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive, this);

            var cargoBuilder = (MyObjectBuilder_CargoContainer)objectBuilder;

            m_containerType = cargoBuilder.ContainerType;

            if (m_containerType != null && MyFakes.RANDOM_CARGO_PLACEMENT && (cargoBuilder.Inventory == null || cargoBuilder.Inventory.Items.Count == 0))
            {
                SpawnRandomCargo();
            }
            else
            {
                m_inventory.Init(cargoBuilder.Inventory);
            }
            if (MyPerGameSettings.InventoryMass)
            {
                m_inventory.ContentsChanged += Inventory_ContentsChanged;
            }

            m_conveyorEndpoint = new MyMultilineConveyorEndpoint(this);
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));
            UpdateIsWorking();
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            m_cargoDefinition = (MyCargoContainerDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            var cargoBuilder = (MyObjectBuilder_CargoContainer)objectBuilder;

            m_containerType = cargoBuilder.ContainerType;

            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

            // Backward compatibility - inventory component not defined in definition files and in entity container
            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(m_cargoDefinition.InventorySize.Volume, m_cargoDefinition.InventorySize, MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive);
                Components.Add <MyInventoryBase>(inventory);

                if (m_containerType != null && MyFakes.RANDOM_CARGO_PLACEMENT && (cargoBuilder.Inventory == null || cargoBuilder.Inventory.Items.Count == 0))
                {
                    SpawnRandomCargo();
                }
            }

            //Backward compatibility
            if (cargoBuilder.Inventory != null && cargoBuilder.Inventory.Items.Count > 0)
            {
                this.GetInventory().Init(cargoBuilder.Inventory);
            }

            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");
            this.GetInventory().SetFlags(MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive);
            m_conveyorEndpoint = new MyMultilineConveyorEndpoint(this);
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));
            UpdateIsWorking();
        }
Beispiel #4
0
        public Progression()
        {
            IEnumerable <MyBlueprintDefinitionBase> blues = MyDefinitionManager.Static.GetBlueprintDefinitions(); //System.Collections.Generic.IEnumerable

            foreach (MyBlueprintDefinitionBase blue in blues)
            {
                //BlockInformation blockInfo = new BlockInformation();
                //blockInfo.BlueprintId = blue.Id;
                //MyDefinitionId blockId = new MyDefinitionId();
                //blockInfo.Results = new HashSet<SerializableDefinitionId>();
                MyDefinitionId BlockId = new MyDefinitionId();
                MyDefinitionId.TryParse("MyObjectBuilder_" + blue.Id.SubtypeId.String, out BlockId);

                if (BlockId.TypeId.IsNull)
                {
                    continue;
                }
                MyCubeBlockDefinition cb = new MyCubeBlockDefinition();
                MyDefinitionManager.Static.TryGetDefinition <MyCubeBlockDefinition>(BlockId, out cb);
                HashSet <SerializableDefinitionId> results = new HashSet <SerializableDefinitionId>();

                String group      = "Default";
                float  efficiency = 0;
                String cubeSize   = cb.CubeSize.ToString();
                String _Type      = blue.Id.SubtypeId.String.Split('/')[0];
                string PairName   = cb.BlockPairName;

                MyThrustDefinition         thrust  = new MyThrustDefinition();
                MyReactorDefinition        reactor = new MyReactorDefinition();
                MyCargoContainerDefinition cargo   = new MyCargoContainerDefinition();
                float Cost = 0;
                if (MyDefinitionManager.Static.TryGetDefinition <MyThrustDefinition>(BlockId, out thrust))
                {
                    if (thrust.FuelConverter.FuelId.IsNull())
                    {
                        group = thrust.ThrusterType.String;
                    }
                    else
                    {
                        group = thrust.FuelConverter.FuelId.SubtypeName;
                    }
                    //Cost = thrust.ForceMagnitude;
                    efficiency = thrust.ForceMagnitude;//thrust.MaxPowerConsumption;
                }
                else if (MyDefinitionManager.Static.TryGetDefinition <MyReactorDefinition>(BlockId, out reactor))
                {
                    group = reactor.FuelId.SubtypeId.String;
                }
                else if (MyDefinitionManager.Static.TryGetDefinition <MyCargoContainerDefinition>(BlockId, out cargo))
                {
                    efficiency = cargo.InventorySize.Sum;
                }

                string resultCount = blue.DisplayNameText;
                SerializableDefinitionId SerializedBlueprintId = blue.Id;

                List <MyBlueprintDefinitionBase.Item> recipe = new List <MyBlueprintDefinitionBase.Item>();
                foreach (MyBlueprintDefinitionBase.Item item in blue.Results)
                {
                    results.Add(item.Id);
                }

                SerializableDefinitionId smallLargeBlockId = new SerializableDefinitionId();
                var dg = MyDefinitionManager.Static.TryGetDefinitionGroup(cb.BlockPairName);
                if (dg != null)
                {
                    if (dg.Large != null)
                    {
                        smallLargeBlockId = dg.Large.Id;
                    }
                    if (dg.Small != null)
                    {
                        smallLargeBlockId = dg.Small.Id;
                    }
                }

                //MyLog.Default.WriteLine($"Id {(SerializableDefinitionId)blue.Results[0].Id}");
                foreach (var item in blue.Prerequisites)
                {
                    Cost += item.Amount.RawValue;
                    recipe.Add(item);
                }
                MyLog.Default.WriteLine($"Cost {Cost}");
                if (BlockId != null)
                {
                    SerializableDefinitionId SerializedBlockId = BlockId;
                    ComponentsCosts.Add(BlockId, new BlockInformation(BlockId, SerializedBlockId, results, recipe, Cost, group, cubeSize, efficiency, _Type, smallLargeBlockId, PairName));
                }
            }

            List <BlockInformation> existingKey = new List <BlockInformation>();

            foreach (BlockInformation BI in ComponentsCosts.Values)
            {
                if (typeList.TryGetValue(BI.Type, out existingKey))
                {
                    existingKey.Add(BI);
                }
                else
                {
                    // Create if not exists in dictionary
                    List <BlockInformation> temp = new List <BlockInformation>();
                    temp.Add(BI);
                    typeList.Add(BI.Type, temp);
                }
            }

            foreach (List <BlockInformation> BIList in typeList.Values)
            {
                BIList.Sort((pair1, pair2) => pair1.BlueprintCost.CompareTo(pair2.BlueprintCost));
            }

            //Set Actual Positon on Each Block, so later we may get the current position out of the techtree
            PrepareCache();
            SetTechPos();
            CalculateLuck();
        }