private int GetBlockConnections(NaniteDeconstructionGrid deconstruct, IMySlimBlock currentBlock)
        {
            deconstruct.AddingList.Clear();
            deconstruct.AddingGridList.Clear();

            MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)currentBlock.GetObjectBuilder();
            MyCubeBlockDefinition     blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

            // Get real block max
            Vector3I Max = Vector3I.Zero;
            Vector3I Min = block.Min;

            ComputeMax(blockDefinition, block.BlockOrientation, ref Min, out Max);

            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Min.X, Max.Y, Max.Z), -Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Min.Y, Max.Z), -Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Max.Y, Min.Z), -Vector3I.UnitZ);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Max.X, Min.Y, Min.Z), Max, Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Max.Y, Min.Z), Max, Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Min.Y, Max.Z), Max, Vector3I.UnitZ);

            // Check if currentBlock is a connector of some kind, then follow it
            // AddConnectedGridBlock(deconstruct, currentBlock);

            return(deconstruct.AddingList.Count + deconstruct.AddingGridList.Count);
        }
        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 #3
0
        public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block)
        {
            int topGroupIndex     = 0;
            int topComponentIndex = 0;
            MyCubeBlockDefinition blockDefinition = null;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);
            if ((blockDefinition != null) && (block != null))
            {
                float integrity = block.IntegrityPercent * blockDefinition.MaxIntegrity;
                CalculateIndicesInternal(integrity, blockDefinition, ref topGroupIndex, ref topComponentIndex);
                if ((topGroupIndex < blockDefinition.Components.Length) && (topComponentIndex < blockDefinition.Components[topGroupIndex].Count))
                {
                    int amount = topComponentIndex;
                    if (integrity >= 1.525902E-05f)
                    {
                        amount++;
                    }
                    for (int i = 0; i < topGroupIndex; i++)
                    {
                        MyCubeBlockDefinition.Component component = blockDefinition.Components[i];
                        addToList.AddMaterial(component.Definition.Id, component.Count, component.Count, false);
                    }
                    MyDefinitionId myDefinitionId = blockDefinition.Components[topGroupIndex].Definition.Id;
                    addToList.AddMaterial(myDefinitionId, amount, amount, false);
                }
            }
        }
Beispiel #4
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute("Defense"),
                MyEnergyConstants.MAX_REQUIRED_POWER_SHIP_GRINDER,
                ComputeRequiredPower);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            m_entitiesInContact  = new Dictionary <MyEntity, int>();
            m_blocksToActivateOn = new HashSet <MySlimBlock>();
            m_tempBlocksBuffer   = new HashSet <MySlimBlock>();

            m_isActivated            = false;
            m_isActivatedOnSomething = false;
            m_wantsToActivate        = false;
            m_effectsSet             = false;

            m_shootHeatup     = 0;
            m_activateCounter = 0;

            m_defId = objectBuilder.GetId();
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(m_defId);

            var typedBuilder = objectBuilder as MyObjectBuilder_ShipToolBase;

            //each dimension of size needs to be scaled by grid size not only one
            float   inventoryVolume = def.Size.X * cubeGrid.GridSize * def.Size.Y * cubeGrid.GridSize * def.Size.Z * cubeGrid.GridSize * 0.5f;
            Vector3 inventorySize   = new Vector3(def.Size.X, def.Size.Y, def.Size.Z * 0.5f);

            if (this.GetInventory() == null) // could be already initialized as component
            {
                MyInventory inventory = new MyInventory(inventoryVolume, inventorySize, MyInventoryFlags.CanSend);
                Components.Add <MyInventoryBase>(inventory);
                inventory.Init(typedBuilder.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            SlimBlock.UsesDeformation  = false;
            SlimBlock.DeformationRatio = typedBuilder.DeformationRatio; // 3x times harder for destruction by high speed

            Enabled           = typedBuilder.Enabled;
            UseConveyorSystem = typedBuilder.UseConveyorSystem;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            LoadDummies();

            UpdateActivationState();

            IsWorkingChanged += MyShipToolBase_IsWorkingChanged;
            ResourceSink.Update();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_FRAME;
        }
Beispiel #5
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            base.Init(builder, cubeGrid);
            m_defId = builder.GetId();
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(m_defId) as MyShipDrillDefinition;

            m_blockLength    = def.Size.Z;
            m_cubeSideLength = MyDefinitionManager.Static.GetCubeSize(def.CubeSize);

            float   inventoryVolume = def.Size.X * def.Size.Y * def.Size.Z * m_cubeSideLength * m_cubeSideLength * m_cubeSideLength * 0.5f;
            Vector3 inventorySize   = new Vector3(def.Size.X, def.Size.Y, def.Size.Z * 0.5f);

            m_inventory            = new MyInventory(inventoryVolume, inventorySize, MyInventoryFlags.CanSend, this);
            m_inventory.Constraint = new MyInventoryConstraint(MySpaceTexts.ToolTipItemFilter_AnyOre)
                                     .AddObjectBuilderType(typeof(MyObjectBuilder_Ore));

            SlimBlock.UsesDeformation  = false;
            SlimBlock.DeformationRatio = def.DeformationRatio; // 3x times harder for destruction by high speed

            m_drillBase = new MyDrillBase(this,
                                          MyDrillConstants.DRILL_SHIP_DUST_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_DUST_STONES_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_SPARKS_EFFECT,
                                          new MyDrillSensorSphere(def.SensorRadius, def.SensorOffset),
                                          new MyDrillCutOut(def.SensorOffset, def.SensorRadius),
                                          HEAD_SLOWDOWN_TIME_IN_SECONDS,
                                          floatingObjectSpawnOffset: -0.4f,
                                          floatingObjectSpawnRadius: 0.4f,
                                          sounds: m_sounds,
                                          inventoryCollectionRatio: 0.7f
                                          );
            m_drillBase.OutputInventory = m_inventory;
            m_drillBase.IgnoredEntities.Add(this);
            m_drillBase.OnWorldPositionChanged(WorldMatrix);
            m_wantsToDrill   = false;
            m_wantsToCollect = false;
            AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase));

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Defense,
                false,
                ComputeMaxRequiredPower(),
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(PowerReceiver, this));

            var obDrill = (MyObjectBuilder_Drill)builder;

            m_inventory.Init(obDrill.Inventory);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            m_useConveyorSystem = obDrill.UseConveyorSystem;

            UpdateDetailedInfo();
        }
Beispiel #6
0
        public static void GetMountedComponents(Dictionary <MyDefinitionId, int> addToDictionary, MyObjectBuilder_CubeBlock block)
        {
            int topGroup     = 0;
            int topComponent = 0;

            MyCubeBlockDefinition blockDef = null;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDef);
            Debug.Assert(blockDef != null, "Could not find block definition");
            if (blockDef == null)
            {
                return;
            }

            Debug.Assert(block != null, "Getting mounted components of a null block");
            if (block == null)
            {
                return;
            }

            float integrity = block.IntegrityPercent * blockDef.MaxIntegrity;

            CalculateIndicesInternal(integrity, blockDef, ref topGroup, ref topComponent);

            Debug.Assert(topGroup < blockDef.Components.Count(), "Component group overflow in CalculateItemRequirements");
            if (topGroup >= blockDef.Components.Count())
            {
                return;
            }

            Debug.Assert(topComponent < blockDef.Components[topGroup].Count, "Component overflow in CalculateItemRequirements");
            if (topComponent >= blockDef.Components[topGroup].Count)
            {
                return;
            }

            int mountCount = topComponent;

            if (integrity >= MOUNT_THRESHOLD)
            {
                mountCount++;
            }

            MyDefinitionId componentId;
            int            count = 0;

            for (int group = 0; group < topGroup; ++group)
            {
                componentId = blockDef.Components[group].Definition.Id;
                count       = addToDictionary.GetValueOrDefault(componentId, 0);
                addToDictionary[componentId] = count + blockDef.Components[group].Count;
            }
            componentId = blockDef.Components[topGroup].Definition.Id;
            count       = addToDictionary.GetValueOrDefault(componentId, 0);
            addToDictionary[componentId] = count + mountCount;
        }
        private int GetBlockConnections(IMySlimBlock currentBlock)
        {
            if (currentBlock.CubeGrid.Closed)
            {
                return(0);
            }

            NaniteDeconstructionGrid deconstruct = new NaniteDeconstructionGrid(currentBlock.CubeGrid);

            deconstruct.AddingList.Clear();
            deconstruct.AddingGridList.Clear();

            MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)currentBlock.GetObjectBuilder();
            MyCubeBlockDefinition     blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

            // Get real block max
            Vector3I Max = Vector3I.Zero;
            Vector3I Min = block.Min;

            ComputeMax(blockDefinition, block.BlockOrientation, ref Min, out Max);

            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Min.X, Max.Y, Max.Z), -Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Min.Y, Max.Z), -Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Max.Y, Min.Z), -Vector3I.UnitZ);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Max.X, Min.Y, Min.Z), Max, Vector3I.UnitX);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Max.Y, Min.Z), Max, Vector3I.UnitY);
            AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Min.Y, Max.Z), Max, Vector3I.UnitZ);

            int additional = 0;

            if (currentBlock.FatBlock != null && currentBlock.FatBlock.BlockDefinition.SubtypeName.Contains("NaniteBeaconDeconstruct"))
            {
                additional += 10;
            }

            /*
             * if (currentBlock.FatBlock != null &&
             *      (currentBlock.FatBlock is IMyPistonBase ||
             *       currentBlock.FatBlock is IMyPistonTop ||
             *       currentBlock.FatBlock is IMyMotorRotor ||
             *       currentBlock.FatBlock is IMyMotorStator ||
             *       currentBlock.FatBlock is IMyMotorBase ||
             *       currentBlock.FatBlock is Ingame.IMyShipConnector))
             * {
             *  additional += 10;
             * }
             */

            AddConnectedGridBlock(deconstruct, currentBlock);

            return(deconstruct.AddingList.Count + deconstruct.AddingGridList.Count + additional);
        }
        public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block)
        {
            int topGroup     = 0;
            int topComponent = 0;

            MyCubeBlockDefinition blockDef = null;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDef);
            Debug.Assert(blockDef != null, "Could not find block definition");
            if (blockDef == null)
            {
                return;
            }

            Debug.Assert(block != null, "Getting mounted components of a null block");
            if (block == null)
            {
                return;
            }

            float integrity = block.IntegrityPercent * blockDef.MaxIntegrity;

            CalculateIndicesInternal(integrity, blockDef, ref topGroup, ref topComponent);

            Debug.Assert(topGroup < blockDef.Components.Count(), "Component group overflow in CalculateItemRequirements");
            if (topGroup >= blockDef.Components.Count())
            {
                return;
            }

            Debug.Assert(topComponent < blockDef.Components[topGroup].Count, "Component overflow in CalculateItemRequirements");
            if (topComponent >= blockDef.Components[topGroup].Count)
            {
                return;
            }

            int mountCount = topComponent;

            if (integrity >= MOUNT_THRESHOLD)
            {
                mountCount++;
            }

            MyDefinitionId componentId;

            for (int group = 0; group < topGroup; ++group)
            {
                MyCubeBlockDefinition.Component component = blockDef.Components[group];
                addToList.AddMaterial(component.Definition.Id, component.Count, component.Count, addToDisplayList: false);
            }
            componentId = blockDef.Components[topGroup].Definition.Id;
            addToList.AddMaterial(componentId, mountCount, mountCount, addToDisplayList: false);
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            m_entitiesInContact  = new Dictionary <MyEntity, int>();
            m_blocksToActivateOn = new HashSet <MySlimBlock>();
            m_tempBlocksBuffer   = new HashSet <MySlimBlock>();

            m_isActivated            = false;
            m_isActivatedOnSomething = false;
            m_wantsToActivate        = false;
            m_effectsSet             = false;

            m_shootHeatup     = 0;
            m_activateCounter = 0;

            m_defId = objectBuilder.GetId();
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(m_defId);

            var typedBuilder = objectBuilder as MyObjectBuilder_ShipToolBase;

            //each dimension of size needs to be scaled by grid size not only one
            float   inventoryVolume = def.Size.X * cubeGrid.GridSize * def.Size.Y * cubeGrid.GridSize * def.Size.Z * cubeGrid.GridSize * 0.5f;
            Vector3 inventorySize   = new Vector3(def.Size.X, def.Size.Y, def.Size.Z * 0.5f);

            m_inventory = new MyInventory(inventoryVolume, inventorySize, MyInventoryFlags.CanSend, this);
            m_inventory.Init(typedBuilder.Inventory);

            SlimBlock.UsesDeformation  = false;
            SlimBlock.DeformationRatio = typedBuilder.DeformationRatio; // 3x times harder for destruction by high speed

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Defense,
                false,
                MyEnergyConstants.MAX_REQUIRED_POWER_SHIP_GRINDER,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;

            Enabled           = typedBuilder.Enabled;
            UseConveyorSystem = typedBuilder.UseConveyorSystem;

            base.EnabledChanged += MyShipToolBase_EnabledChanged;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            LoadDummies();

            UpdateActivationState();
            PowerReceiver.Update();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_FRAME;
        }
Beispiel #10
0
        public virtual void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            //objectBuilder.PersistentFlags |= MyPersistentEntityFlags2.CastShadows;
            // Ensure that if we went from not serializing to serializing, we have a valid entity id.
            if (builder.EntityId == 0)
            {
                EntityId = MyEntityIdentifier.AllocateId();
            }
            else if (builder.EntityId != 0)
            {
                EntityId = builder.EntityId;
            }

            NumberInGrid        = cubeGrid.BlockCounter.GetNextNumber(builder.GetId());
            Render.ColorMaskHsv = builder.ColorMaskHSV;

            if (MyFakes.ENABLE_SUBBLOCKS)
            {
                if (builder.SubBlocks != null)
                {
                    foreach (var subblockInfo in builder.SubBlocks)
                    {
                        m_subBlockIds.Add(subblockInfo.SubGridName, new MySubBlockLoadInfo()
                        {
                            GridId = subblockInfo.SubGridId, SubBlockPosition = subblockInfo.SubBlockPosition
                        });
                    }

                    m_subBlocksLoaded = m_subBlockIds.Count > 0;

                    if (BlockDefinition.SubBlockDefinitions != null && BlockDefinition.SubBlockDefinitions.Count > 0 && m_subBlockIds.Count == 0)
                    {
                        m_subBlocksInitialized = true;
                        m_subBlocksLoaded      = true;
                    }

                    // Set update flag for InitSubBlocks
                    NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                }
            }

            Components.Deserialize(builder.ComponentContainer);

            base.Init(null);
            base.Render.PersistentFlags |= MyPersistentEntityFlags2.CastShadows;
            Init();
            AddDebugRenderComponent(new MyDebugRenderComponentCubeBlock(this));

            InitOwnership(builder);
        }
        public static ulong GetBattlePoints(MyObjectBuilder_CubeBlock block)
        {
            ulong pts = GetBattlePoints(block.GetId());

            MyObjectBuilder_CargoContainer cargoContainer = block as MyObjectBuilder_CargoContainer;

            if (cargoContainer != null && cargoContainer.Inventory != null)
            {
                foreach (var item in cargoContainer.Inventory.Items)
                {
                    if (item.PhysicalContent is MyObjectBuilder_BlockItem)
                    {
                        MyObjectBuilder_BlockItem blockItem = item.PhysicalContent as MyObjectBuilder_BlockItem;
                        pts += GetBattlePoints(blockItem.BlockDefId);
                    }
                }
            }

            return(pts);
        }
Beispiel #12
0
 private static MyObjectBuilder_CubeBlock ProcessLargeTurretBase(MyObjectBuilder_CubeBlock block, Options options, MyCubeSize size)
 {         // LargeTurretBase
     try
     {
         MyLargeTurretBaseDefinition myLargeTurret      = (MyLargeTurretBaseDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(block.GetId());
         List <BlockSideEnum>        mountPoints        = myLargeTurret.MountPoints.Select(myMountPoint => myMountPoint.GetObjectBuilder(myMountPoint.Normal).Side).ToList();
         List <WeaponInformation>    replacementOptions = LargeGridWeaponTurretBases.FindAll(x =>
                                                                                             //x.ModName != "Vanilla" &&
                                                                                             x.SubtypeId != block.SubtypeId &&
                                                                                             x.MountPoints.Intersect(mountPoints).Any() &&
                                                                                             x.SizeX == myLargeTurret.Size.X &&
                                                                                             x.SizeY == myLargeTurret.Size.Y &&
                                                                                             x.SizeZ <= myLargeTurret.Size.Z// + 1
                                                                                             );
         if (replacementOptions.Count == 0)
         {
             return(block);
         }
         block = CreateReplacementTurretBase(replacementOptions[Core.Random.Next(0, replacementOptions.Count)], block, size, myLargeTurret);
     }
     catch (Exception e)
     {
         Core.GeneralLog.WriteToLog("WeaponSwapper-ProcessLargeTurretBase", $"Exception!\t{e}");
     }
     return(block);
 }
Beispiel #13
0
        private Vector3I ComputeMax(MyObjectBuilder_CubeBlock cube)
        {
            MyCubeBlockDefinition definition = MyDefinitionManager.Static.GetCubeBlockDefinition(cube.GetId());
            Vector3I result = definition.Size - 1;
            MatrixI  matrix = new MatrixI(cube.BlockOrientation);

            Vector3I.TransformNormal(ref result, ref matrix, out result);
            Vector3I.Abs(ref result, out result);
            return(cube.Min + result);
        }
Beispiel #14
0
        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 (!Components.Has <MyInventoryBase>())
            {
                m_inventory = new MyInventory(m_cargoDefinition.InventorySize.Volume, m_cargoDefinition.InventorySize, MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive, this);
                if (MyFakes.ENABLE_MEDIEVAL_INVENTORY)
                {
                    Components.Add <MyInventoryBase>(m_inventory);
                }

                if (m_containerType != null && MyFakes.RANDOM_CARGO_PLACEMENT && (cargoBuilder.Inventory == null || cargoBuilder.Inventory.Items.Count == 0))
                {
                    SpawnRandomCargo();
                }
                else
                {
                    m_inventory.Init(cargoBuilder.Inventory);
                }
            }
            else
            {
                m_inventory = Components.Get <MyInventoryBase>() as MyInventory;
                Debug.Assert(m_inventory != null);
                //m_inventory.Owner = this;
            }

            if (MyPerGameSettings.InventoryMass)
            {
                m_inventory.ContentsChanged += Inventory_ContentsChanged;
            }

            m_conveyorEndpoint = new MyMultilineConveyorEndpoint(this);
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));
            UpdateIsWorking();
        }
        public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block)
        {
            int topGroup = 0;
            int topComponent = 0;

            MyCubeBlockDefinition blockDef = null;
            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDef);
            //Debug.Assert(blockDef != null, "Could not find block definition");
            if (blockDef == null) return;

            Debug.Assert(block!= null, "Getting mounted components of a null block");
            if (block == null) return;

            float integrity = block.IntegrityPercent * blockDef.MaxIntegrity;
            
            CalculateIndicesInternal(integrity, blockDef, ref topGroup, ref topComponent);

            Debug.Assert(topGroup < blockDef.Components.Length, "Component group overflow in CalculateItemRequirements");
            if (topGroup >= blockDef.Components.Length) return;

            Debug.Assert(topComponent < blockDef.Components[topGroup].Count, "Component overflow in CalculateItemRequirements");
            if (topComponent >= blockDef.Components[topGroup].Count) return;

            int mountCount = topComponent;
            if (integrity >= MOUNT_THRESHOLD)
                mountCount++;

            MyDefinitionId componentId;
            for (int group = 0; group < topGroup; ++group)
            {
                MyCubeBlockDefinition.Component component = blockDef.Components[group];
                addToList.AddMaterial(component.Definition.Id, component.Count, component.Count, addToDisplayList: false);
            }
            componentId = blockDef.Components[topGroup].Definition.Id;
            addToList.AddMaterial(componentId, mountCount, mountCount, addToDisplayList: false);
        }
        private bool CanBuildBlock(MyObjectBuilder_CubeBlock block, MyCubeGrid blockGrid, MyCubeBlock projector, MyCubeGrid projectorGrid, MyObjectBuilder_ProjectorBase projectorBuilder)
        {
            MyBlockOrientation blockOrientation = block.BlockOrientation;

            Matrix local;

            blockOrientation.GetMatrix(out local);
            var gridOrientation = GetGridOrientation(projectorBuilder);

            if (gridOrientation != Matrix.Identity)
            {
                var afterRotation = Matrix.Multiply(local, gridOrientation);
                blockOrientation = new MyBlockOrientation(ref afterRotation);
            }

            Quaternion blockOrientationQuat;

            blockOrientation.GetQuaternion(out blockOrientationQuat);

            Quaternion projQuat = Quaternion.Identity;

            projector.Orientation.GetQuaternion(out projQuat);
            blockOrientationQuat = Quaternion.Multiply(projQuat, blockOrientationQuat);

            MyCubeBlockDefinition blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

            // Get real block max
            Vector3I blockMax = Vector3I.Zero;
            Vector3I blockMin = block.Min;

            ComputeMax(blockDefinition, block.BlockOrientation, ref blockMin, out blockMax);
            var position = ComputePositionInGrid(new MatrixI(block.BlockOrientation), blockDefinition, blockMin);

            Vector3I projectedMin = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(block.Min));
            Vector3I projectedMax = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMax));
            Vector3I blockPos     = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(position));

            Vector3I min = new Vector3I(Math.Min(projectedMin.X, projectedMax.X), Math.Min(projectedMin.Y, projectedMax.Y), Math.Min(projectedMin.Z, projectedMax.Z));
            Vector3I max = new Vector3I(Math.Max(projectedMin.X, projectedMax.X), Math.Max(projectedMin.Y, projectedMax.Y), Math.Max(projectedMin.Z, projectedMax.Z));

            projectedMin = min;
            projectedMax = max;

            if (!projectorGrid.CanAddCubes(projectedMin, projectedMax))
            {
                IMySlimBlock slimBlock = (IMySlimBlock)blockGrid.GetCubeBlock(block.Min);
                if (slimBlock == null || slimBlock.FatBlock == null)
                {
                    return(false);
                }

                Logging.Instance.WriteLine(string.Format("Can not add block: {0}: {1} - {2} {3} {4} {5}", slimBlock.FatBlock.EntityId, blockDefinition.Id, projectedMin, projectedMax, blockMin, blockMax)); //, slimBlock.FatBlock.EntityId));
                return(false);
            }

            var  mountPoints = blockDefinition.GetBuildProgressModelMountPoints(1.0f);
            bool isConnected = MyCubeGrid.CheckConnectivity(projectorGrid, blockDefinition, mountPoints, ref blockOrientationQuat, ref blockPos);

            if (isConnected)
            {
                if (projectorGrid.GetCubeBlock(blockPos) == null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            m_conveyorSorterDefinition = (MyConveyorSorterDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                m_conveyorSorterDefinition.ResourceSinkGroup,
                BlockDefinition.PowerInput,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_ConveyorSorter ob = (MyObjectBuilder_ConveyorSorter)objectBuilder;

            DrainAll    = ob.DrainAll;
            IsWhitelist = ob.IsWhiteList;

            foreach (var id in ob.DefinitionIds)
            {
                m_inventoryConstraint.Add(id);
            }
            foreach (byte b in ob.DefinitionTypes)
            {
                Tuple <MyObjectBuilderType, StringBuilder> tuple;
                if (!CandidateTypes.TryGetValue(b, out tuple))
                {
                    Debug.Assert(false, "type not in dictionary");
                    continue;
                }
                m_inventoryConstraint.AddObjectBuilderType(tuple.Item1);
            }

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


            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(m_conveyorSorterDefinition.InventorySize.Volume, m_conveyorSorterDefinition.InventorySize, MyInventoryFlags.CanSend);
                Components.Add <MyInventoryBase>(inventory);
                inventory.Init(ob.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;


            ResourceSink.Update();
            UpdateText();
        }
Beispiel #18
0
        private static List <MyDefinitionId> GetWeaponAmmoList(MyObjectBuilder_CubeBlock cube)
        {
            List <MyDefinitionId> ammoSubTypeIds = new List <MyDefinitionId>();

            try
            {
                MyWeaponDefinition myWeapon = MyDefinitionManager.Static.GetWeaponDefinition(((MyWeaponBlockDefinition)
                                                                                              MyDefinitionManager.Static.GetCubeBlockDefinition(cube.GetId())).WeaponDefinitionId);
                if (myWeapon == null)
                {
                    return(ammoSubTypeIds);
                }
                ammoSubTypeIds.AddRange(myWeapon.AmmoMagazinesId);
            }
            catch (Exception e)
            {
                Core.GeneralLog.WriteToLog("GetWeaponAmmoList", $"Exception getting ammo list! {e}");
            }
            return(ammoSubTypeIds);
        }
Beispiel #19
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_ConveyorSorter ob = (MyObjectBuilder_ConveyorSorter)objectBuilder;

            DrainAll    = ob.DrainAll;
            IsWhitelist = ob.IsWhiteList;
            foreach (var id in ob.DefinitionIds)
            {
                m_inventoryConstraint.Add(id);
            }
            foreach (byte b in ob.DefinitionTypes)
            {
                Tuple <MyObjectBuilderType, StringBuilder> tuple;
                if (!CandidateTypes.TryGetValue(b, out tuple))
                {
                    Debug.Assert(false, "type not in dictionary");
                    continue;
                }
                m_inventoryConstraint.AddObjectBuilderType(tuple.Item1);
            }

            m_conveyorSorterDefinition = (MyConveyorSorterDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            m_inventory = new MyInventory(m_conveyorSorterDefinition.InventorySize.Volume, m_conveyorSorterDefinition.InventorySize, MyInventoryFlags.CanSend, this);
            m_inventory.Init(ob.Inventory);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;

            if (MyPerGameSettings.InventoryMass)
            {
                m_inventory.ContentsChanged += Inventory_ContentsChanged;
            }

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                m_conveyorSorterDefinition.ResourceSinkGroup,
                BlockDefinition.PowerInput,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += IsPoweredChanged;
            ResourceSink = sinkComp;
            ResourceSink.Update();
            UpdateText();
        }
Beispiel #20
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 #21
0
        public virtual void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            //objectBuilder.PersistentFlags |= MyPersistentEntityFlags2.CastShadows;
            // Ensure that if we went from not serializing to serializing, we have a valid entity id.
            if (builder.EntityId == 0)
            {
                EntityId = MyEntityIdentifier.AllocateId();
            }
            else if (builder.EntityId != 0)
            {
                EntityId = builder.EntityId;
            }

            NumberInGrid        = cubeGrid.BlockCounter.GetNextNumber(builder.GetId());
            Render.ColorMaskHsv = builder.ColorMaskHSV;

            if (BlockDefinition.ContainsComputer())
            {
                m_IDModule = new MyIDModule();

                if (MySession.Static.Settings.ResetOwnership && Sync.IsServer)
                {
                    m_IDModule.Owner     = 0;
                    m_IDModule.ShareMode = MyOwnershipShareModeEnum.None;
                }
                else
                {
                    if ((int)builder.ShareMode == -1)
                    {
                        builder.ShareMode = MyOwnershipShareModeEnum.None;
                    }

                    var ownerType = MyEntityIdentifier.GetIdObjectType(builder.Owner);
                    if (builder.Owner != 0 && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.NPC && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.SPAWN_GROUP)
                    {
                        System.Diagnostics.Debug.Assert(ownerType == MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, "Old save detected, reseting owner to Nobody, please resave.");

                        if (!Sync.Players.HasIdentity(builder.Owner))
                        {
                            builder.Owner = 0; //reset, it was old version
                        }
                    }

                    m_IDModule.Owner     = builder.Owner;
                    m_IDModule.ShareMode = builder.ShareMode;
                }
            }

            if (MyFakes.ENABLE_SUBBLOCKS)
            {
                if (builder.SubBlocks != null)
                {
                    foreach (var subblockInfo in builder.SubBlocks)
                    {
                        m_subBlockIds.Add(subblockInfo.SubGridName, new MySubBlockLoadInfo()
                        {
                            GridId = subblockInfo.SubGridId, SubBlockPosition = subblockInfo.SubBlockPosition
                        });
                    }

                    m_subBlocksLoaded = m_subBlockIds.Count > 0;

                    if (BlockDefinition.SubBlockDefinitions != null && BlockDefinition.SubBlockDefinitions.Count > 0 && m_subBlockIds.Count == 0)
                    {
                        m_subBlocksInitialized = true;
                        m_subBlocksLoaded      = true;
                    }

                    // Set update flag for InitSubBlocks
                    NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                }
            }


            base.Init(null);
            base.Render.PersistentFlags |= MyPersistentEntityFlags2.CastShadows;
            Init();
            AddDebugRenderComponent(new MyDebugRenderComponentCubeBlock(this));
        }
Beispiel #22
0
        private static List <MyDefinitionId> GetParachuteList(MyObjectBuilder_CubeBlock cube)
        {
            List <MyDefinitionId> parachuteIds = new List <MyDefinitionId>();

            try
            {
                MyParachuteDefinition parachuteDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(cube.GetId()) as MyParachuteDefinition;
                if (parachuteDefinition == null)
                {
                    return(parachuteIds);
                }
                parachuteIds.Add(parachuteDefinition.MaterialDefinitionId);
            }
            catch (Exception e)
            {
                Core.GeneralLog.WriteToLog("GetParachuteList", $"Exception getting parachute list! {e}");
            }
            return(parachuteIds);
        }
        public static ulong GetBattlePoints(MyObjectBuilder_CubeBlock block)
        {
            ulong pts = GetBattlePoints(block.GetId());

            MyObjectBuilder_CargoContainer cargoContainer = block as MyObjectBuilder_CargoContainer;
            if (cargoContainer != null && cargoContainer.Inventory != null)
            {
                foreach (var item in cargoContainer.Inventory.Items)
                {
                    if (item.PhysicalContent is MyObjectBuilder_BlockItem)
                    {
                        MyObjectBuilder_BlockItem blockItem = item.PhysicalContent as MyObjectBuilder_BlockItem;
                        pts += GetBattlePoints(blockItem.BlockDefId);
                    }
                }
            }

            return pts;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            m_conveyorSorterDefinition = (MyConveyorSorterDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                m_conveyorSorterDefinition.ResourceSinkGroup,
                BlockDefinition.PowerInput,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_ConveyorSorter ob = (MyObjectBuilder_ConveyorSorter)objectBuilder;
            DrainAll = ob.DrainAll;
            IsWhitelist = ob.IsWhiteList;

            foreach (var id in ob.DefinitionIds)
                m_inventoryConstraint.Add(id);
            foreach (byte b in ob.DefinitionTypes)
            {
                Tuple<MyObjectBuilderType, StringBuilder> tuple;
                if (!CandidateTypes.TryGetValue(b, out tuple))
                {
                    Debug.Assert(false, "type not in dictionary");
                    continue;
                }
                m_inventoryConstraint.AddObjectBuilderType(tuple.Item1);
            }

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

            
            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(m_conveyorSorterDefinition.InventorySize.Volume, m_conveyorSorterDefinition.InventorySize, MyInventoryFlags.CanSend);
                Components.Add<MyInventoryBase>(inventory);
                inventory.Init(ob.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;

			
			ResourceSink.Update();
            UpdateText();
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            //MyDebug.AssertDebug(objectBuilder.TypeId == typeof(MyObjectBuilder_ShipController));
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            m_enableFirstPerson = BlockDefinition.EnableFirstPerson || MySession.Static.Settings.Enable3rdPersonView == false;
            m_enableShipControl = BlockDefinition.EnableShipControl;
            m_enableBuilderCockpit = BlockDefinition.EnableBuilderCockpit;


            m_rechargeSocket = new MyRechargeSocket();

            MyObjectBuilder_ShipController shipControllerOb = (MyObjectBuilder_ShipController)objectBuilder;

            // No need for backward compatibility of selected weapon, we just leave it alone
            //            m_selectedGunType = shipControllerOb.SelectedGunType;
            m_selectedGunId = shipControllerOb.SelectedGunId;

            ControlThrusters = shipControllerOb.ControlThrusters;
            ControlWheels = shipControllerOb.ControlWheels;

            if (shipControllerOb.IsMainCockpit)
            {
                IsMainCockpit = true;
            }

			HorizonIndicatorEnabled = shipControllerOb.HorizonIndicatorEnabled;
            m_toolbar = new MyToolbar(ToolbarType);
            m_toolbar.Init(shipControllerOb.Toolbar, this);
            m_toolbar.ItemChanged += Toolbar_ItemChanged;

            m_buildToolbar = new MyToolbar(MyToolbarType.BuildCockpit);
            m_buildToolbar.Init(shipControllerOb.BuildToolbar, this);


            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            // TODO: Seems like overkill
            if (Sync.IsServer && false)
            {
                //Because of simulating thrusts
                NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
            }

			NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_baseIdleSound = BlockDefinition.PrimarySound;

            CubeGrid.OnGridSplit += CubeGrid_OnGridSplit;
            Components.ComponentAdded += OnComponentAdded;
            Components.ComponentRemoved += OnComponentRemoved;

            if(EntityThrustComponent != null)
            {
                m_dampenersEnabled.Value = EntityThrustComponent.Enabled;
            }
            UpdateShipInfo();
            if (BlockDefinition.GetInSound != null && BlockDefinition.GetInSound.Length > 0)
                GetInCockpitSound = new MySoundPair(BlockDefinition.GetInSound);
            if (BlockDefinition.GetOutSound != null && BlockDefinition.GetOutSound.Length > 0)
                GetOutOfCockpitSound = new MySoundPair(BlockDefinition.GetOutSound);
        }
Beispiel #26
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            PostBaseInit();

            //MyDebug.AssertDebug(objectBuilder.TypeId == typeof(MyObjectBuilder_Cockpit));
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());

            m_isLargeCockpit       = (def.CubeSize == MyCubeSize.Large);
            m_cockpitInteriorModel = BlockDefinition.InteriorModel;
            m_cockpitGlassModel    = BlockDefinition.GlassModel;

            NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME;

            MyObjectBuilder_Cockpit cockpitOb = (MyObjectBuilder_Cockpit)objectBuilder;

            if (cockpitOb.Pilot != null)
            {
                MyEntity    pilotEntity;
                MyCharacter pilot = null;
                if (MyEntities.TryGetEntityById(cockpitOb.Pilot.EntityId, out pilotEntity))
                { //Pilot already exists, can be the case after cube grid split
                    pilot = (MyCharacter)pilotEntity;
                    if (pilot.IsUsing is MyShipController && pilot.IsUsing != this)
                    {
                        System.Diagnostics.Debug.Assert(false, "Pilot already sits on another place!");
                        pilot = null;
                    }
                }
                else
                {
                    pilot = (MyCharacter)MyEntities.CreateFromObjectBuilder(cockpitOb.Pilot);
                }

                if (pilot != null)
                {
                    AttachPilot(pilot, storeOriginalPilotWorld: false, calledFromInit: true);
                    if (cockpitOb.PilotRelativeWorld.HasValue)
                    {
                        m_pilotRelativeWorld = cockpitOb.PilotRelativeWorld.Value.GetMatrix();
                    }
                    else
                    {
                        m_pilotRelativeWorld = null;
                    }

                    m_singleWeaponMode = cockpitOb.UseSingleWeaponMode;
                }

                IsInFirstPersonView = cockpitOb.IsInFirstPersonView;
            }

            if (cockpitOb.Autopilot != null)
            {
                MyAutopilotBase autopilot = MyAutopilotFactory.CreateAutopilot(cockpitOb.Autopilot);
                autopilot.Init(cockpitOb.Autopilot);
                AttachAutopilot(autopilot, updateSync: false);
            }

            m_pilotGunDefinition = cockpitOb.PilotGunDefinition;

            // backward compatibility check for automatic rifle without subtype
            if (m_pilotGunDefinition.HasValue)
            {
                if (m_pilotGunDefinition.Value.TypeId == typeof(MyObjectBuilder_AutomaticRifle) &&
                    string.IsNullOrEmpty(m_pilotGunDefinition.Value.SubtypeName))
                {
                    m_pilotGunDefinition = new MyDefinitionId(typeof(MyObjectBuilder_AutomaticRifle), "RifleGun");
                }
            }

            if (!string.IsNullOrEmpty(m_cockpitInteriorModel))
            {
                if (MyModels.GetModelOnlyDummies(m_cockpitInteriorModel).Dummies.ContainsKey("head"))
                {
                    m_headLocalPosition = MyModels.GetModelOnlyDummies(m_cockpitInteriorModel).Dummies["head"].Matrix.Translation;
                }
            }
            else
            {
                if (MyModels.GetModelOnlyDummies(BlockDefinition.Model).Dummies.ContainsKey("head"))
                {
                    m_headLocalPosition = MyModels.GetModelOnlyDummies(BlockDefinition.Model).Dummies["head"].Matrix.Translation;
                }
            }

            AddDebugRenderComponent(new Components.MyDebugRenderComponentCockpit(this));

            InitializeConveyorEndpoint();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            m_oxygenLevel = cockpitOb.OxygenLevel;
        }
Beispiel #27
0
        public virtual void Close()
        {
            //Logging.Instance.WriteLine(string.Format("Close"));

            int pos = 0;

            try
            {
                if (m_performanceFriendly)
                {
                    if (Sync.IsClient)
                    {
                        NaniteConstructionManager.ParticleManager.RemoveParticle(m_cubeEntityId, m_position);
                    }
                    else
                    {
                        m_constructionBlock.SendRemoveParticleEffect(m_cubeEntityId, m_position);
                    }

                    if (m_isGrinder && m_removed)
                    {
                        TransferRemainingComponents();
                        Logging.Instance.WriteLine(string.Format("GRINDING completed.  Target block: {0} - (EntityID: {1} Elapsed: {2})", m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.EntityId : 0, m_completeTime + m_waitTime));
                    }

                    m_completed = true;
                    return;
                }

                if (m_constructionBlock != null && m_constructionBlock.ConstructionBlock != null)
                {
                    var toolInventory = ((MyEntity)m_tool).GetInventory(0);

                    // Since grinding in creative gives no components.  Insert hack.
                    if (MyAPIGateway.Session.CreativeMode && m_tool is Sandbox.ModAPI.Ingame.IMyShipGrinder)
                    {
                        MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)m_targetBlock.GetObjectBuilder();
                        MyCubeBlockDefinition     blockDefinition;
                        if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition))
                        {
                            foreach (var item in blockDefinition.Components)
                            {
                                var inventoryItem = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(item.DeconstructItem.Id);
                                toolInventory.AddItems(item.Count, inventoryItem);
                            }
                        }
                    }

                    if (toolInventory.GetItemsCount() > 0)
                    {
                        TransferFromTarget((MyCubeBlock)m_tool);
                    }
                }

                m_completed = true;
                if (m_tool != null)
                {
                    m_tool.Enabled = false;
                }

                if (!m_toolEntity.Closed)
                {
                    m_toolEntity.Close();
                }
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("Close() {1}: {0}", ex.ToString(), pos));
            }
        }
Beispiel #28
0
        public void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid, MyCubeBlock fatBlock)
        {
            ProfilerShort.Begin("SlimBlock.Init(objectBuilder, ...)");
            Debug.Assert(cubeGrid != null);
            FatBlock = fatBlock;

            if (objectBuilder is MyObjectBuilder_CompoundCubeBlock)
                BlockDefinition = MyCompoundCubeBlock.GetCompoundCubeBlockDefinition();
            else if (!MyDefinitionManager.Static.TryGetCubeBlockDefinition(objectBuilder.GetId(), out BlockDefinition))
                {
                    //BlockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "StoneCube"));
                    ProfilerShort.End();
                    return;
                }

            m_componentStack = new MyComponentStack(BlockDefinition, objectBuilder.IntegrityPercent, objectBuilder.BuildPercent);

            if (MyCubeGridDefinitions.GetCubeRotationOptions(BlockDefinition) == MyRotationOptionsEnum.None)
            {
                objectBuilder.BlockOrientation = MyBlockOrientation.Identity;
            }

            DeformationRatio = BlockDefinition.DeformationRatio;
            Min = objectBuilder.Min;

            Orientation = objectBuilder.BlockOrientation;
            if (!Orientation.IsValid)
                Orientation = MyBlockOrientation.Identity;

            Debug.Assert(Orientation.IsValid, "Orientation of block is not valid.");

            CubeGrid = cubeGrid;
            ColorMaskHSV = objectBuilder.ColorMaskHSV;

            if (BlockDefinition.CubeDefinition != null)
            {
                //Ensure we have always only one distinct orientation use
                Orientation = MyCubeGridDefinitions.GetTopologyUniqueOrientation(BlockDefinition.CubeDefinition.CubeTopology, Orientation);
            }

            ComputeMax(BlockDefinition, Orientation, ref Min, out Max);
            Position = ComputePositionInGrid(new MatrixI(Orientation), BlockDefinition, Min);

            if (objectBuilder.MultiBlockId != 0 && objectBuilder.MultiBlockDefinition != null && objectBuilder.MultiBlockIndex != -1)
            {
                MultiBlockDefinition = MyDefinitionManager.Static.TryGetMultiBlockDefinition(objectBuilder.MultiBlockDefinition.Value);
                if (MultiBlockDefinition != null)
                {
                    MultiBlockId = objectBuilder.MultiBlockId;
                    MultiBlockIndex = objectBuilder.MultiBlockIndex;
                }
            }

            UpdateShowParts();

            if (FatBlock == null)
            {
                bool isRenderedAsModel = !String.IsNullOrEmpty(BlockDefinition.Model);
                bool showConstructionModel = BlockDefinition.BlockTopology == MyBlockTopology.Cube && !ShowParts;
                if (isRenderedAsModel || showConstructionModel)
                {
                    FatBlock = new MyCubeBlock();
                }
            }

            if (FatBlock != null)
            {
                ProfilerShort.Begin("FatBlock.Init(objectBuilder, ...)");
                FatBlock.SlimBlock = this;
                FatBlock.Init(objectBuilder, cubeGrid);
                ProfilerShort.End();
            }

            if (objectBuilder.ConstructionStockpile != null)
            {
                EnsureConstructionStockpileExists();
                m_stockpile.Init(objectBuilder.ConstructionStockpile);
            }
            else if (objectBuilder.ConstructionInventory != null) // Backwards compatibility
            {
                EnsureConstructionStockpileExists();
                m_stockpile.Init(objectBuilder.ConstructionInventory);
            }

            if (FatBlock == null || FatBlock.GetType() == typeof(MyCubeBlock))
                m_objectBuilder = new MyObjectBuilder_CubeBlock();

            if (MyFakes.SHOW_DAMAGE_EFFECTS && FatBlock != null && BlockDefinition.RatioEnoughForDamageEffect(BuildIntegrity / MaxIntegrity) == false && BlockDefinition.RatioEnoughForDamageEffect(Integrity / MaxIntegrity))
            {//start effect
                if (CurrentDamage > 0.01f)//fix for weird simple blocks having FatBlock - old save?
                {
                    FatBlock.SetDamageEffect(true);
                }

            }

            UpdateMaxDeformation();

            m_builtByID = objectBuilder.BuiltBy;

            ProfilerShort.End();
        }
Beispiel #29
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            this.m_conveyorSorterDefinition = (MyConveyorSorterDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            MyResourceSinkComponent component = new MyResourceSinkComponent(1);

            component.Init(this.m_conveyorSorterDefinition.ResourceSinkGroup, this.BlockDefinition.PowerInput, new Func <float>(this.UpdatePowerInput));
            component.IsPoweredChanged += new Action(this.IsPoweredChanged);
            base.ResourceSink           = component;
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_ConveyorSorter sorter = (MyObjectBuilder_ConveyorSorter)objectBuilder;

            this.m_drainAll.SetLocalValue(sorter.DrainAll);
            this.IsWhitelist = sorter.IsWhiteList;
            foreach (SerializableDefinitionId id in sorter.DefinitionIds)
            {
                this.m_inventoryConstraint.Add(id);
            }
            foreach (byte num in sorter.DefinitionTypes)
            {
                Tuple <MyObjectBuilderType, StringBuilder> tuple;
                if (CandidateTypes.TryGetValue(num, out tuple))
                {
                    this.m_inventoryConstraint.AddObjectBuilderType(tuple.Item1);
                }
            }
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                base.FixSingleInventory();
            }
            if (this.GetInventory(0) == null)
            {
                MyInventory inventory = new MyInventory(this.m_conveyorSorterDefinition.InventorySize.Volume, this.m_conveyorSorterDefinition.InventorySize, MyInventoryFlags.CanSend);
                base.Components.Add <MyInventoryBase>(inventory);
                inventory.Init(sorter.Inventory);
            }
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            base.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;
            base.ResourceSink.Update();
            this.UpdateText();
        }
Beispiel #30
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            m_defId = builder.GetId();
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(m_defId) as MyShipDrillDefinition;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                def.ResourceSinkGroup,
                ComputeMaxRequiredPower(),
                ComputeRequiredPower);
            ResourceSink = sinkComp;

            m_drillBase = new MyDrillBase(this,
                                          MyDrillConstants.DRILL_SHIP_DUST_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_DUST_STONES_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_SPARKS_EFFECT,
                                          new MyDrillSensorSphere(def.SensorRadius, def.SensorOffset),
                                          new MyDrillCutOut(def.SensorOffset, def.SensorRadius),
                                          HEAD_SLOWDOWN_TIME_IN_SECONDS, -0.4f, 0.4f, 1
                                          );

            base.Init(builder, cubeGrid);

            m_blockLength    = def.Size.Z;
            m_cubeSideLength = MyDefinitionManager.Static.GetCubeSize(def.CubeSize);

            float   inventoryVolume = def.Size.X * def.Size.Y * def.Size.Z * m_cubeSideLength * m_cubeSideLength * m_cubeSideLength * 0.5f;
            Vector3 inventorySize   = new Vector3(def.Size.X, def.Size.Y, def.Size.Z * 0.5f);

            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(inventoryVolume, inventorySize, MyInventoryFlags.CanSend);
                Components.Add <MyInventoryBase>(inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            this.GetInventory().Constraint = new MyInventoryConstraint(MySpaceTexts.ToolTipItemFilter_AnyOre)
                                             .AddObjectBuilderType(typeof(MyObjectBuilder_Ore));

            SlimBlock.UsesDeformation  = false;
            SlimBlock.DeformationRatio = def.DeformationRatio; // 3x times harder for destruction by high speed


            m_drillBase.OutputInventory = this.GetInventory();
            m_drillBase.IgnoredEntities.Add(this);
            m_drillBase.OnWorldPositionChanged(WorldMatrix);
            m_wantsToCollect = false;
            AddDebugRenderComponent(new MyDebugRenderCompomentDrawDrillBase(m_drillBase));


            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink.Update();

            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            var obDrill = (MyObjectBuilder_Drill)builder;

            this.GetInventory().Init(obDrill.Inventory);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            m_useConveyorSystem.Value = obDrill.UseConveyorSystem;

            UpdateDetailedInfo();

            m_wantsToDrill    = obDrill.Enabled;
            IsWorkingChanged += OnIsWorkingChanged;

            m_drillBase.m_drillMaterial = MyStringHash.GetOrCompute("ShipDrill");
            m_drillBase.m_idleSoundLoop = new MySoundPair("ToolShipDrillIdle");
        }
Beispiel #31
0
 private static void ProcessBattery(MyObjectBuilder_CubeBlock block, Options options, MyCubeSize size)
 {         // Doesn't need inventory processing, just set the current to the eventual max
     if (options.PowerDownGrid)
     {
         ((MyObjectBuilder_BatteryBlock)block).Enabled = false;
     }
     if (!options.Restock)
     {
         return;
     }
     try
     {
         ((MyObjectBuilder_BatteryBlock)block).CurrentStoredPower = ((MyBatteryBlockDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(block.GetId())).MaxStoredPower;
     }
     catch (Exception e)
     {
         Core.GeneralLog.WriteToLog("MyObjectBuilder_BatteryBlock", $"Exception! {e}");
     }
 }
Beispiel #32
0
        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)
            {
                Components.Add <MyInventoryBase>(new MyInventory(m_cargoDefinition.InventorySize.Volume, m_cargoDefinition.InventorySize, MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive, this));

                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();
        }
        private void CreateRemovalOrder(NaniteDeconstructionGrid deconstruct, IMySlimBlock startBlock)
        {
            IMySlimBlock currentBlock = startBlock;

            deconstruct.AddingList.Clear();
            deconstruct.GridsProcessed.Clear();

            while (true)
            {
                if (!deconstruct.GridsProcessed.Contains(currentBlock.CubeGrid))
                {
                    ((MyCubeGrid)currentBlock.CubeGrid).OnGridSplit += OnGridSplit;
                    deconstruct.GridsProcessed.Add(currentBlock.CubeGrid);
                }

                MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)currentBlock.GetObjectBuilder();
                MyCubeBlockDefinition     blockDefinition;
                MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

                // Get real block max
                Vector3I Max = Vector3I.Zero;
                Vector3I Min = block.Min;
                ComputeMax(blockDefinition, block.BlockOrientation, ref Min, out Max);

                AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Min.X, Max.Y, Max.Z), -Vector3I.UnitX);
                AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Min.Y, Max.Z), -Vector3I.UnitY);
                AddNeighbours(deconstruct, currentBlock, Min, new Vector3I(Max.X, Max.Y, Min.Z), -Vector3I.UnitZ);
                AddNeighbours(deconstruct, currentBlock, new Vector3I(Max.X, Min.Y, Min.Z), Max, Vector3I.UnitX);
                AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Max.Y, Min.Z), Max, Vector3I.UnitY);
                AddNeighbours(deconstruct, currentBlock, new Vector3I(Min.X, Min.Y, Max.Z), Max, Vector3I.UnitZ);

                // Check if currentBlock is a connector of some kind, then follow it
                AddConnectedGridBlock(deconstruct, currentBlock);

                // Add to removal list
                if (!deconstruct.RemoveList.Contains(currentBlock))
                {
                    deconstruct.RemoveList.AddStart(currentBlock);
                }

                if (deconstruct.AddingList.Count < 1 && deconstruct.AddingGridList.Count < 1)
                {
                    break;
                }

                if (deconstruct.AddingList.Count < 1 && deconstruct.AddingGridList.Count > 0)
                {
                    currentBlock = deconstruct.AddingGridList[0];
                    deconstruct.AddingGridList.Remove(currentBlock);
                    //deconstruct.TreePosition++;
                    //deconstruct.GridTree.Add(new Node<IMySlimBlock>(currentBlock));
                }
                else
                {
                    currentBlock = deconstruct.AddingList[0];
                    deconstruct.AddingList.Remove(currentBlock);
                }
            }

            // Find user defined priority blocks for deconstruction.
            FindPriorityBlocks(deconstruct, startBlock);

            Logging.Instance.WriteLine(string.Format("Block Count: {0}", deconstruct.RemoveList.Count));
            //Logging.Instance.WriteLine(string.Format("Grid Count: {0}", deconstruct.GridsProcessed.Count));
            //Logging.Instance.WriteLine(string.Format("Tree Size: {0}", deconstruct.GridTree.Sum(x => x.All.Count())));
        }
Beispiel #34
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            PostBaseInit();

            //MyDebug.AssertDebug(objectBuilder.TypeId == typeof(MyObjectBuilder_Cockpit));
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            m_isLargeCockpit = (def.CubeSize == MyCubeSize.Large);
            m_cockpitInteriorModel = BlockDefinition.InteriorModel;
            m_cockpitGlassModel = BlockDefinition.GlassModel;

            MyObjectBuilder_Cockpit cockpitOb = (MyObjectBuilder_Cockpit)objectBuilder;
            if (cockpitOb.Pilot != null)
            {
                MyEntity pilotEntity;
                MyCharacter pilot = null;
                if (MyEntities.TryGetEntityById(cockpitOb.Pilot.EntityId, out pilotEntity))
                { //Pilot already exists, can be the case after cube grid split
                    pilot = (MyCharacter)pilotEntity;
                    if (pilot.IsUsing is MyShipController && pilot.IsUsing != this)
                    {
                        Debug.Assert(false, "Pilot already sits on another place!");
                        pilot = null;
                    }
                }
                else
                {
                    pilot = (MyCharacter)MyEntities.CreateFromObjectBuilder(cockpitOb.Pilot);
                }

                if (pilot != null)
                {
                    m_savedPilot = pilot;
                    if (cockpitOb.PilotRelativeWorld.HasValue)
                        m_pilotRelativeWorld.Value = cockpitOb.PilotRelativeWorld.Value.GetMatrix();
                    else
                        m_pilotRelativeWorld.Value = null;

                    m_singleWeaponMode = cockpitOb.UseSingleWeaponMode;
                }

                IsInFirstPersonView = cockpitOb.IsInFirstPersonView;
            }

            if (cockpitOb.Autopilot != null)
            {
                MyAutopilotBase autopilot = MyAutopilotFactory.CreateAutopilot(cockpitOb.Autopilot);
                autopilot.Init(cockpitOb.Autopilot);
                AttachAutopilot(autopilot, updateSync: false);
            }

            m_pilotGunDefinition = cockpitOb.PilotGunDefinition;

            // backward compatibility check for automatic rifle without subtype
            if (m_pilotGunDefinition.HasValue)
            {
                if (m_pilotGunDefinition.Value.TypeId == typeof(MyObjectBuilder_AutomaticRifle)
                    && string.IsNullOrEmpty(m_pilotGunDefinition.Value.SubtypeName))
                    m_pilotGunDefinition = new MyDefinitionId(typeof(MyObjectBuilder_AutomaticRifle), "RifleGun");
            }

            if (!string.IsNullOrEmpty(m_cockpitInteriorModel))
            {

                if (VRage.Game.Models.MyModels.GetModelOnlyDummies(m_cockpitInteriorModel).Dummies.ContainsKey("head"))
                    m_headLocalPosition = VRage.Game.Models.MyModels.GetModelOnlyDummies(m_cockpitInteriorModel).Dummies["head"].Matrix.Translation;
            }
            else
            {
                if (VRage.Game.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model).Dummies.ContainsKey("head"))
                    m_headLocalPosition = VRage.Game.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model).Dummies["head"].Matrix.Translation;
            }

            AddDebugRenderComponent(new Components.MyDebugRenderComponentCockpit(this));

            InitializeConveyorEndpoint();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            OxygenFillLevel = cockpitOb.OxygenLevel;

            var sinkDataList = new List<MyResourceSinkInfo>
	        {
				new MyResourceSinkInfo {ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = 0, RequiredInputFunc = CalculateRequiredPowerInput },
				new MyResourceSinkInfo {ResourceTypeId = MyCharacterOxygenComponent.OxygenId, MaxRequiredInput = BlockDefinition.OxygenCapacity, RequiredInputFunc = ComputeRequiredGas},
	        };
            ResourceSink.Init(MyStringHash.GetOrCompute("Utility"), sinkDataList);
            ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged;
            m_lastGasInputUpdateTick = MySession.Static.ElapsedGameTime.Ticks;

            if (cockpitOb.AttachedPlayerId.HasValue == false && cockpitOb.Pilot != null && m_pilot!=null)
            {
                m_attachedCharacterIdSaved = m_pilot.EntityId;
            }
            else
            {
                m_attachedCharacterIdSaved = cockpitOb.AttachedPlayerId;
            }
            if (this.GetInventory() == null)
            {
                Vector3 inv = Vector3.One*1.0f;
                MyInventory inventory = new MyInventory(inv.Volume, inv, MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive);
                Components.Add<MyInventoryBase>(inventory);
            }

            m_defferAttach = true;
        }
Beispiel #35
0
        private static List <MyDefinitionId> GetReactorFuelList(MyObjectBuilder_CubeBlock cube)
        {
            List <MyDefinitionId> fuelIds = new List <MyDefinitionId>();

            try
            {
                MyReactorDefinition reactorDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(cube.GetId()) as MyReactorDefinition;
                if (reactorDefinition == null)
                {
                    return(fuelIds);
                }
                foreach (MyReactorDefinition.FuelInfo fuel in reactorDefinition.FuelInfos)
                {
                    Core.GeneralLog.WriteToLog("Definitions", $"FuelId:	{fuel.FuelId}");
                }
                fuelIds.Add(reactorDefinition.FuelInfos[0].FuelId);
            }
            catch (Exception e)
            {
                Core.GeneralLog.WriteToLog("GetReactorFuelList", $"Exception getting reactor fuel list! {e}");
            }
            return(fuelIds);
        }