private static void PrepBlocks(Random rand, MyIDModule owner, MyObjectBuilder_CubeGrid grid, GridComponents comps)
        {
            for (int i = grid.CubeBlocks.Count - 1; i >= 0; i--)
            {
                MyObjectBuilder_CubeBlock cubeBuilder = grid.CubeBlocks[i];
                if (cubeBuilder.EntityId == 0)
                {
                    if (!Utilities.RandomEntityId(rand, out cubeBuilder.EntityId))
                    {
                        grid.CubeBlocks.RemoveAtFast(i);
                        continue;
                    }
                }

                cubeBuilder.SetupForProjector();
                MyCubeBlockDefinition def = MyDefinitionManager.Static.GetCubeBlockDefinition(cubeBuilder);
                if (def == null)
                {
                    grid.CubeBlocks.RemoveAtFast(i);
                    continue;
                }

                if (comps != null)
                {
                    comps.Include(def);
                }

                cubeBuilder.Owner     = owner.Owner;
                cubeBuilder.BuiltBy   = owner.Owner;
                cubeBuilder.ShareMode = owner.ShareMode;

                // Since the cross grid entity ids are invalid, remove references to them.
                if (cubeBuilder is MyObjectBuilder_AttachableTopBlockBase)
                {
                    ((MyObjectBuilder_AttachableTopBlockBase)cubeBuilder).ParentEntityId = 0;
                }
                if (cubeBuilder is MyObjectBuilder_MechanicalConnectionBlock)
                {
                    ((MyObjectBuilder_MechanicalConnectionBlock)cubeBuilder).TopBlockId = null;
                }
                if (cubeBuilder is MyObjectBuilder_MotorBase)
                {
                    ((MyObjectBuilder_MotorBase)cubeBuilder).RotorEntityId = null;
                }


                if (cubeBuilder is MyObjectBuilder_FunctionalBlock)
                {
                    ((MyObjectBuilder_FunctionalBlock)cubeBuilder).Enabled = true;
                }
                if (cubeBuilder is MyObjectBuilder_BatteryBlock)
                {
                    MyBatteryBlockDefinition batDef = (MyBatteryBlockDefinition)def;
                    ((MyObjectBuilder_BatteryBlock)cubeBuilder).CurrentStoredPower = batDef.InitialStoredPowerRatio * batDef.MaxStoredPower;
                }
            }
        }
Exemplo n.º 2
0
        private static bool PrepBlocks(ulong activator, MyIDModule owner, MyObjectBuilder_CubeGrid grid, GridComponents comps)
        {
            foreach (MyObjectBuilder_CubeBlock cubeBuilder in grid.CubeBlocks)
            {
                if (cubeBuilder.EntityId == 0)
                {
                    if (!Constants.RandomEntityId(out cubeBuilder.EntityId))
                    {
                        return(false);
                    }
                }

                cubeBuilder.SetupForProjector();
                MyCubeBlockDefinition def = MyDefinitionManager.Static.GetCubeBlockDefinition(cubeBuilder);
                if (def == null)
                {
                    Constants.Notify(Constants.msgUnknownBlock, activator);
                    return(false);
                }

                if (comps != null)
                {
                    comps.Include(def);
                }

                cubeBuilder.Owner     = owner.Owner;
                cubeBuilder.BuiltBy   = owner.Owner;
                cubeBuilder.ShareMode = owner.ShareMode;

                // Since the cross grid entity ids are invalid, remove references to them.
                if (cubeBuilder is MyObjectBuilder_AttachableTopBlockBase)
                {
                    ((MyObjectBuilder_AttachableTopBlockBase)cubeBuilder).ParentEntityId = 0;
                }
                if (cubeBuilder is MyObjectBuilder_MechanicalConnectionBlock)
                {
                    ((MyObjectBuilder_MechanicalConnectionBlock)cubeBuilder).TopBlockId = null;
                }

                if (cubeBuilder is MyObjectBuilder_FunctionalBlock)
                {
                    ((MyObjectBuilder_FunctionalBlock)cubeBuilder).Enabled = true;
                }
                if (cubeBuilder is MyObjectBuilder_BatteryBlock)
                {
                    MyBatteryBlockDefinition batDef = (MyBatteryBlockDefinition)def;
                    ((MyObjectBuilder_BatteryBlock)cubeBuilder).CurrentStoredPower = batDef.InitialStoredPowerRatio * batDef.MaxStoredPower;
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            SyncObject = new MySyncBatteryBlock(this);

            MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_BatteryBlock));
            m_batteryBlockDefinition = BlockDefinition as MyBatteryBlockDefinition;
            MyDebug.AssertDebug(m_batteryBlockDefinition != null);

            var sourceDataList = new List <MyResourceSourceInfo>
            {
                new MyResourceSourceInfo {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId, DefinedOutput = m_batteryBlockDefinition.MaxPowerOutput, ProductionToCapacityMultiplier = 60 * 60
                }
            };

            SourceComp.Init(m_batteryBlockDefinition.ResourceSourceGroup, sourceDataList);
            SourceComp.HasCapacityRemainingChanged += (id, source) => UpdateIsWorking();

            MaxStoredPower = m_batteryBlockDefinition.MaxStoredPower;

            ResourceSink.Init(
                m_batteryBlockDefinition.ResourceSinkGroup,
                m_batteryBlockDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional && !SourceComp.ProductionEnabled && !m_isFull) ? ResourceSink.MaxRequiredInput : 0.0f);
            ResourceSink.Update();

            var obGenerator = (MyObjectBuilder_BatteryBlock)objectBuilder;

            CurrentStoredPower = obGenerator.CurrentStoredPower;
            SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, obGenerator.ProducerEnabled);
            SemiautoEnabled = obGenerator.SemiautoEnabled;

            UpdateMaxOutputAndEmissivity();

            UpdateText();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            this.IsWorkingChanged += MyBatteryBlock_IsWorkingChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            if (IsWorking)
            {
                OnStartWorking();
            }
        }
Exemplo n.º 4
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            SyncObject = new MySyncBatteryBlock(this);

            MyDebug.AssertDebug(BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_BatteryBlock));
            m_batteryBlockDefinition = BlockDefinition as MyBatteryBlockDefinition;
            MyDebug.AssertDebug(m_batteryBlockDefinition != null);

            MaxStoredPower = m_batteryBlockDefinition.MaxStoredPower;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.BatteryBlock,
                true,
                m_batteryBlockDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional && !ProducerEnabled && (CurrentPowerOutput == 0) && !m_isFull) ? PowerReceiver.MaxRequiredInput : 0.0f);
            PowerReceiver.Update();

            CurrentPowerOutput = 0;

            var obGenerator = (MyObjectBuilder_BatteryBlock)objectBuilder;

            CurrentStoredPower = obGenerator.CurrentStoredPower;
            ProducerEnabled    = obGenerator.ProducerEnabled;
            SemiautoEnabled    = obGenerator.SemiautoEnabled;

            RefreshRemainingCapacity();

            UpdateText();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            this.IsWorkingChanged += MyBatteryBlock_IsWorkingChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            if (IsWorking)
            {
                OnStartWorking();
            }
        }